@haiyue/extensions 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -0
- package/dist/animation/Animation2DComponent.d.ts +18 -0
- package/dist/animation/Animation2DExtensionRegistry.d.ts +7 -0
- package/dist/animation/Animation2DRenderSystem.d.ts +6 -0
- package/dist/animation/Animation2DRuntime.d.ts +6 -2
- package/dist/animation/AnimationTextRasterizer.d.ts +4 -0
- package/dist/animation/AnimationVisual2D.d.ts +58 -2
- package/dist/animation/interaction/InteractionRuntime.d.ts +83 -0
- package/dist/animation/interaction/runtime-types.d.ts +257 -0
- package/dist/animation.d.ts +3 -1
- package/dist/animation.js +551 -59
- package/dist/animation3d.js +1 -1
- package/dist/canvas-text.js +1 -1
- package/dist/chunks/2d-ui-animation-2d.generated-FpziAeGJ.js +4 -0
- package/dist/chunks/2d-ui-indexed-sprite.generated-DmKR0CC3.js +4 -0
- package/dist/chunks/Animation2DStateMachine-BHcA6Cu3.js +18212 -0
- package/dist/chunks/{AnimationStateMachineController-BIcAh-sT.js → AnimationStateMachineController-4sKaqh9E.js} +2 -2
- package/dist/chunks/AnimationVisual2D-8y3qp0_U.js +230 -0
- package/dist/chunks/{RenderSystem2DBase-DDT61dAu.js → RenderSystem2DBase-CF2s00vg.js} +2 -2
- package/dist/controls/VirtualJoystickControls.d.ts +46 -0
- package/dist/controls/contracts.d.ts +91 -0
- package/dist/controls.d.ts +2 -0
- package/dist/controls.js +358 -0
- package/dist/deformable-animation/runtime/DeformableMesh2DRuntimeExtension.d.ts +11 -0
- package/dist/deformable-animation/runtime/DeformableMesh2DSampler.d.ts +11 -0
- package/dist/deformable-animation.d.ts +5 -0
- package/dist/deformable-animation.js +316 -0
- package/dist/experimental-indexed-sprite.d.ts +5 -0
- package/dist/experimental-indexed-sprite.js +482 -0
- package/dist/gltf-worker-runtime.js +9 -9
- package/dist/hya-state-machine.js +3 -2
- package/dist/index.js +1 -1
- package/dist/indexed-sprite/AtlasLayout.d.ts +2 -0
- package/dist/indexed-sprite/IndexedSpriteRenderer.d.ts +23 -0
- package/dist/indexed-sprite/contracts.d.ts +89 -0
- package/dist/internal/2d-ui-shader-artifact.js +232 -23
- package/dist/ray-tracing/acceleration/bvh.d.ts +37 -0
- package/dist/ray-tracing/acceleration/index.d.ts +6 -0
- package/dist/ray-tracing/acceleration/pack.d.ts +152 -0
- package/dist/ray-tracing/acceleration/query.d.ts +4 -0
- package/dist/ray-tracing/acceleration/runtime.d.ts +30 -0
- package/dist/ray-tracing/acceleration/tlas.d.ts +4 -0
- package/dist/ray-tracing/acceleration/types.d.ts +165 -0
- package/dist/ray-tracing/denoise/index.d.ts +3 -0
- package/dist/ray-tracing/denoise/layout.d.ts +9 -0
- package/dist/ray-tracing/denoise/runtime.d.ts +23 -0
- package/dist/ray-tracing/denoise/types.d.ts +28 -0
- package/dist/ray-tracing/hybrid/contract.d.ts +2 -0
- package/dist/ray-tracing/hybrid/index.d.ts +5 -0
- package/dist/ray-tracing/hybrid/layout.d.ts +17 -0
- package/dist/ray-tracing/hybrid/plan.d.ts +2 -0
- package/dist/ray-tracing/hybrid/runtime.d.ts +31 -0
- package/dist/ray-tracing/hybrid/shaders/hybrid-artifact.generated.d.ts +625 -0
- package/dist/ray-tracing/hybrid/types.d.ts +144 -0
- package/dist/ray-tracing/lifecycle/device-recovery.d.ts +31 -0
- package/dist/ray-tracing/lifecycle/index.d.ts +2 -0
- package/dist/ray-tracing/lifecycle/types.d.ts +37 -0
- package/dist/ray-tracing/material/index.d.ts +2 -0
- package/dist/ray-tracing/material/pack.d.ts +5 -0
- package/dist/ray-tracing/material/types.d.ts +63 -0
- package/dist/ray-tracing/reference/index.d.ts +122 -0
- package/dist/ray-tracing/renderer/index.d.ts +7 -0
- package/dist/ray-tracing/renderer/layout.d.ts +20 -0
- package/dist/ray-tracing/renderer/plan.d.ts +2 -0
- package/dist/ray-tracing/renderer/reference.d.ts +17 -0
- package/dist/ray-tracing/renderer/runtime.d.ts +39 -0
- package/dist/ray-tracing/renderer/scene.d.ts +4 -0
- package/dist/ray-tracing/renderer/types.d.ts +115 -0
- package/dist/ray-tracing/sampling/index.d.ts +8 -0
- package/dist/ray-tracing/sampling/layout.d.ts +12 -0
- package/dist/ray-tracing/sampling/plan.d.ts +5 -0
- package/dist/ray-tracing/sampling/revision.d.ts +15 -0
- package/dist/ray-tracing/sampling/runtime.d.ts +44 -0
- package/dist/ray-tracing/sampling/sequence.d.ts +2 -0
- package/dist/ray-tracing/sampling/types.d.ts +96 -0
- package/dist/ray-tracing/scene/index.d.ts +41 -0
- package/dist/ray-tracing/traversal/index.d.ts +4 -0
- package/dist/ray-tracing/traversal/layout.d.ts +16 -0
- package/dist/ray-tracing/traversal/plan.d.ts +2 -0
- package/dist/ray-tracing/traversal/runtime.d.ts +25 -0
- package/dist/ray-tracing/traversal/types.d.ts +79 -0
- package/dist/ray-tracing/worker/client.d.ts +25 -0
- package/dist/ray-tracing/worker/index.d.ts +5 -0
- package/dist/ray-tracing/worker/runtime.d.ts +11 -0
- package/dist/ray-tracing/worker/serialization.d.ts +16 -0
- package/dist/ray-tracing/worker/source.d.ts +1 -0
- package/dist/ray-tracing/worker/types.d.ts +91 -0
- package/dist/ray-tracing.d.ts +17 -0
- package/dist/ray-tracing.js +7666 -0
- package/dist/spine.js +1 -1
- package/dist/tilemap.js +1 -1
- package/package.json +26 -23
- package/dist/animation/Animation2DStateMachineVisualRuntime.d.ts +0 -27
- package/dist/animation/Particle2DDescriptorAdapter.d.ts +0 -5
- package/dist/animation3d/Animation3DResource.d.ts +0 -28
- package/dist/animation3d/hya/HyaAnimation3DStateMachineRuntime.d.ts +0 -65
- package/dist/animation3d/hya/index.d.ts +0 -4
- package/dist/animation3d/runtime/integration/Animation3DStateMachineMixerAdapter.d.ts +0 -81
- package/dist/animation3d/runtime/integration/Animation3DStateMachineMixerIntegration.d.ts +0 -39
- package/dist/animation3d/runtime/integration/index.d.ts +0 -2
- package/dist/animation3d/runtime/mixer/Action.d.ts +0 -150
- package/dist/animation3d/runtime/mixer/Animation3DMixerRuntimeStore.d.ts +0 -6
- package/dist/animation3d/runtime/mixer/Mixer.d.ts +0 -59
- package/dist/animation3d/runtime/mixer/PoseBuffer.d.ts +0 -1
- package/dist/animation3d/runtime/mixer/TrackSampler.d.ts +0 -24
- package/dist/animation3d/runtime/mixer/index.d.ts +0 -4
- package/dist/animation3d/runtime/state-machine/Animation3DBlendTreeWeights.d.ts +0 -1
- package/dist/animation3d/runtime/state-machine/Animation3DStateMachineCompiler.d.ts +0 -1
- package/dist/animation3d/runtime/state-machine/Animation3DStateMachineController.d.ts +0 -1
- package/dist/animation3d/runtime/state-machine/Animation3DStateMachineMixerPort.d.ts +0 -1
- package/dist/animation3d/runtime/state-machine/index.d.ts +0 -6
- package/dist/benchmark.d.ts +0 -30
- package/dist/chunks/2d-ui-animation-2d.generated-D4aHzFU2.js +0 -4
- package/dist/chunks/Animation2DStateMachine-9IonguNa.js +0 -3245
- package/dist/gltf/GltfAccessorReader.d.ts +0 -7
- package/dist/gltf/GltfDracoDecoder.d.ts +0 -4
- package/dist/gltf/GltfLoaderErrors.d.ts +0 -4
- package/dist/gltf/GltfMaterialDescriptor.d.ts +0 -23
- package/dist/gltf/GltfMaterialLoader.d.ts +0 -6
- package/dist/gltf-worker-runtime.d.ts +0 -7
- package/dist/plugins/pluginUtils.d.ts +0 -20
- package/dist/plugins.d.ts +0 -6
- package/dist/shaders/generated/2d-ui-artifact.generated.d.ts +0 -658
- package/dist/spine/Spine2DGpuRenderer.d.ts +0 -65
- package/dist/spine/Spine2DRuntime.d.ts +0 -103
- package/dist/spine/SpineAnimationBoneTimelines.d.ts +0 -8
- package/dist/spine/SpineFloatBuilder.d.ts +0 -15
- package/dist/spine/SpinePathConstraintSolver.d.ts +0 -32
- package/dist/spine/SpineSkeletonRuntime.d.ts +0 -185
- package/dist/spine/SpineSlotAnimation.d.ts +0 -17
- package/dist/spine/SpineTimelineRuntime.d.ts +0 -25
- package/dist/spine/SpineVertexBuilder.d.ts +0 -61
- package/dist/tilemap/Tilemap2DRenderer.d.ts +0 -24
- package/dist/utils/arrayAccess.d.ts +0 -4
- package/dist/utils/camera2d.d.ts +0 -12
- package/src/animation/Animation2DComponent.ts +0 -135
- package/src/animation/Animation2DExtensionRegistry.ts +0 -52
- package/src/animation/Animation2DRenderSystem.ts +0 -1026
- package/src/animation/Animation2DRuntime.ts +0 -1326
- package/src/animation/Animation2DStateMachine.ts +0 -39
- package/src/animation/Animation2DStateMachineComponent.ts +0 -228
- package/src/animation/Animation2DStateMachineRuntime.ts +0 -141
- package/src/animation/Animation2DStateMachineSystem.ts +0 -60
- package/src/animation/Animation2DStateMachineVisualRuntime.ts +0 -282
- package/src/animation/Animation2DSystem.ts +0 -72
- package/src/animation/AnimationAssetLoader.ts +0 -84
- package/src/animation/AnimationAudioClip.ts +0 -140
- package/src/animation/AnimationPathTessellator.ts +0 -691
- package/src/animation/AnimationTextRasterizer.ts +0 -340
- package/src/animation/AnimationVisual2D.ts +0 -153
- package/src/animation/HyaAnimation2DClipAdapter.ts +0 -845
- package/src/animation/Particle2DDescriptorAdapter.ts +0 -35
- package/src/animation/runtime/mixer/Action.ts +0 -876
- package/src/animation/runtime/mixer/Mixer.ts +0 -505
- package/src/animation/runtime/mixer/PoseBuffer.ts +0 -105
- package/src/animation/runtime/mixer/Sampler.ts +0 -252
- package/src/animation/runtime/mixer/Types.ts +0 -138
- package/src/animation/runtime/mixer/index.ts +0 -31
- package/src/animation-state-machine/AnimationStateMachine.ts +0 -146
- package/src/animation-state-machine/AnimationStateMachineChannels.ts +0 -116
- package/src/animation-state-machine/runtime/Animation2DStateMachineMixerAdapter.ts +0 -197
- package/src/animation-state-machine/runtime/AnimationStateMachineBlendTreeWeights.ts +0 -503
- package/src/animation-state-machine/runtime/AnimationStateMachineCompiler.ts +0 -763
- package/src/animation-state-machine/runtime/AnimationStateMachineController.ts +0 -987
- package/src/animation-state-machine/runtime/AnimationStateMachineMixerPort.ts +0 -54
- package/src/animation-state-machine/runtime/index.ts +0 -47
- package/src/animation.ts +0 -33
- package/src/animation3d/Animation3DAction.ts +0 -73
- package/src/animation3d/Animation3DBinding.ts +0 -116
- package/src/animation3d/Animation3DClip.ts +0 -22
- package/src/animation3d/Animation3DError.ts +0 -34
- package/src/animation3d/Animation3DMixer.ts +0 -82
- package/src/animation3d/Animation3DPose.ts +0 -100
- package/src/animation3d/Animation3DPoseBuffer.ts +0 -85
- package/src/animation3d/Animation3DResource.ts +0 -49
- package/src/animation3d/Animation3DStateMachine.ts +0 -126
- package/src/animation3d/Animation3DStateMachineRuntime.ts +0 -191
- package/src/animation3d/Animation3DTrack.ts +0 -29
- package/src/animation3d/hya/HyaAnimation3DRuntime.ts +0 -756
- package/src/animation3d/hya/HyaAnimation3DStateMachineRuntime.ts +0 -618
- package/src/animation3d/hya/HyaAnimation3DTypes.ts +0 -168
- package/src/animation3d/hya/index.ts +0 -10
- package/src/animation3d/index.ts +0 -76
- package/src/animation3d/runtime/integration/Animation3DStateMachineMixerAdapter.ts +0 -325
- package/src/animation3d/runtime/integration/Animation3DStateMachineMixerIntegration.ts +0 -158
- package/src/animation3d/runtime/integration/index.ts +0 -9
- package/src/animation3d/runtime/mixer/Action.ts +0 -833
- package/src/animation3d/runtime/mixer/Animation3DMixerRuntimeStore.ts +0 -26
- package/src/animation3d/runtime/mixer/Mixer.ts +0 -562
- package/src/animation3d/runtime/mixer/PoseBuffer.ts +0 -1
- package/src/animation3d/runtime/mixer/TrackSampler.ts +0 -399
- package/src/animation3d/runtime/mixer/index.ts +0 -8
- package/src/animation3d/runtime/state-machine/Animation3DBlendTreeWeights.ts +0 -4
- package/src/animation3d/runtime/state-machine/Animation3DStateMachineCompiler.ts +0 -1
- package/src/animation3d/runtime/state-machine/Animation3DStateMachineController.ts +0 -1
- package/src/animation3d/runtime/state-machine/Animation3DStateMachineMixerPort.ts +0 -1
- package/src/animation3d/runtime/state-machine/index.ts +0 -45
- package/src/animation3d.ts +0 -5
- package/src/benchmark.ts +0 -168
- package/src/canvas-text/CanvasText2DRenderSystem.ts +0 -292
- package/src/canvas-text/CanvasTextComponent.ts +0 -47
- package/src/canvas-text.ts +0 -4
- package/src/experimental-gltf-worker.ts +0 -18
- package/src/experimental-spine-worker.ts +0 -9
- package/src/gltf/GltfAccessorReader.ts +0 -271
- package/src/gltf/GltfAnimation3DAdapter.ts +0 -680
- package/src/gltf/GltfAnimationRuntime.ts +0 -392
- package/src/gltf/GltfAssetWorkerClient.ts +0 -136
- package/src/gltf/GltfCompatibilityReport.ts +0 -214
- package/src/gltf/GltfConservativeBounds.ts +0 -219
- package/src/gltf/GltfDracoDecoder.ts +0 -251
- package/src/gltf/GltfExtensionAdapter.ts +0 -340
- package/src/gltf/GltfLoaderContract.ts +0 -333
- package/src/gltf/GltfLoaderErrors.ts +0 -59
- package/src/gltf/GltfMaterialDescriptor.ts +0 -134
- package/src/gltf/GltfMaterialEncoder.ts +0 -173
- package/src/gltf/GltfMaterialLoader.ts +0 -293
- package/src/gltf/GltfModelComponent.ts +0 -115
- package/src/gltf/GltfModelSystem.ts +0 -208
- package/src/gltf/GltfPlugin.ts +0 -84
- package/src/gltf/GltfSchema.ts +0 -229
- package/src/gltf/GltfUvSemanticPlanner.ts +0 -166
- package/src/gltf/gltfLoader.ts +0 -910
- package/src/gltf-animation3d.ts +0 -10
- package/src/gltf-worker-runtime.ts +0 -10
- package/src/gltf.ts +0 -56
- package/src/grid/Grid2DComponent.ts +0 -69
- package/src/grid.ts +0 -2
- package/src/hya-state-machine.ts +0 -19
- package/src/index.ts +0 -2
- package/src/plugins/pluginUtils.ts +0 -50
- package/src/plugins.ts +0 -6
- package/src/shaders/generated/2d-ui-animation-2d.generated.wgsl +0 -242
- package/src/shaders/generated/2d-ui-artifact.generated.ts +0 -867
- package/src/shaders/generated/2d-ui-canvas-text-2d.generated.wgsl +0 -38
- package/src/shaders/generated/2d-ui-spine2d.generated.wgsl +0 -41
- package/src/shaders/generated/2d-ui-tilemap2d.generated.wgsl +0 -36
- package/src/spine/Spine2DComponent.ts +0 -168
- package/src/spine/Spine2DGpuRenderer.ts +0 -449
- package/src/spine/Spine2DRenderSystem.ts +0 -199
- package/src/spine/Spine2DRuntime.ts +0 -1529
- package/src/spine/SpineAnimationBoneTimelines.ts +0 -30
- package/src/spine/SpineAssetParser.ts +0 -20
- package/src/spine/SpineAssetWorkerClient.ts +0 -112
- package/src/spine/SpineAssetWorkerContract.ts +0 -4
- package/src/spine/SpineAtlasParser.ts +0 -127
- package/src/spine/SpineFloatBuilder.ts +0 -66
- package/src/spine/SpinePathConstraintSolver.ts +0 -582
- package/src/spine/SpinePlugin.ts +0 -76
- package/src/spine/SpineSkeletonRuntime.ts +0 -521
- package/src/spine/SpineSlotAnimation.ts +0 -195
- package/src/spine/SpineTimelineRuntime.ts +0 -453
- package/src/spine/SpineVertexBuilder.ts +0 -686
- package/src/spine.ts +0 -7
- package/src/tilemap/Tilemap2DComponent.ts +0 -232
- package/src/tilemap/Tilemap2DRenderSystem.ts +0 -58
- package/src/tilemap/Tilemap2DRenderer.ts +0 -289
- package/src/tilemap/TilemapPlugin.ts +0 -75
- package/src/tilemap.ts +0 -6
- package/src/tween/Tween2DComponent.ts +0 -83
- package/src/tween/Tween2DSystem.ts +0 -78
- package/src/tween.ts +0 -4
- package/src/types/earcut.d.ts +0 -7
- package/src/types/wgsl.d.ts +0 -4
- package/src/utils/RenderSystem2DBase.ts +0 -164
- package/src/utils/arrayAccess.ts +0 -17
- package/src/utils/camera2d.ts +0 -68
- package/src/utils/render2dGpu.ts +0 -132
- package/test/fixtures/gltf/animation-characterization.gltf +0 -344
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import { Component } from '@haiyue/engine';
|
|
2
|
-
import { UniqueCheckType } from '@haiyue/engine/ecs';
|
|
3
|
-
import { Easing, type EasingFunction } from '@haiyue/engine/tween';
|
|
4
|
-
|
|
5
|
-
export type Tween2DEasingName = keyof typeof Easing;
|
|
6
|
-
|
|
7
|
-
export interface Tween2DProperties {
|
|
8
|
-
x?: number;
|
|
9
|
-
y?: number;
|
|
10
|
-
rotation?: number;
|
|
11
|
-
scaleX?: number;
|
|
12
|
-
scaleY?: number;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export interface Tween2DComponentOptions {
|
|
16
|
-
from?: Tween2DProperties;
|
|
17
|
-
to?: Tween2DProperties;
|
|
18
|
-
duration?: number;
|
|
19
|
-
delay?: number;
|
|
20
|
-
easing?: Tween2DEasingName | EasingFunction | string;
|
|
21
|
-
removeOnComplete?: boolean;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export class Tween2DComponent extends Component {
|
|
25
|
-
static override UniqueCheckType = UniqueCheckType.SYMBOL | UniqueCheckType.REPLACE;
|
|
26
|
-
static override UniqueSymbol = Symbol.for('Tween2DComponent');
|
|
27
|
-
static editor = {
|
|
28
|
-
fields: {
|
|
29
|
-
from: { type: 'json', label: 'From JSON', rows: 4 },
|
|
30
|
-
to: { type: 'json', label: 'To JSON', rows: 4 },
|
|
31
|
-
duration: { type: 'number', label: 'Duration ms', min: 0, step: 16 },
|
|
32
|
-
delay: { type: 'number', label: 'Delay ms', min: 0, step: 16 },
|
|
33
|
-
easing: { type: 'text', label: 'Easing' },
|
|
34
|
-
removeOnComplete: { type: 'boolean', label: 'Remove On Complete' },
|
|
35
|
-
},
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
from: Tween2DProperties | null;
|
|
39
|
-
to: Tween2DProperties;
|
|
40
|
-
duration: number;
|
|
41
|
-
delay: number;
|
|
42
|
-
easing: Tween2DEasingName | EasingFunction | string;
|
|
43
|
-
removeOnComplete: boolean;
|
|
44
|
-
elapsed = 0;
|
|
45
|
-
started = false;
|
|
46
|
-
completed = false;
|
|
47
|
-
private _resolvedFrom: Tween2DProperties = {};
|
|
48
|
-
|
|
49
|
-
constructor(options: Tween2DComponentOptions = {}) {
|
|
50
|
-
super('Tween2DComponent');
|
|
51
|
-
this.from = options.from ? { ...options.from } : null;
|
|
52
|
-
this.to = { ...(options.to ?? {}) };
|
|
53
|
-
this.duration = Math.max(0, options.duration ?? 160);
|
|
54
|
-
this.delay = Math.max(0, options.delay ?? 0);
|
|
55
|
-
this.easing = options.easing ?? 'cubicOut';
|
|
56
|
-
this.removeOnComplete = options.removeOnComplete ?? true;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
resolveFrom(current: Tween2DProperties): Tween2DProperties {
|
|
60
|
-
if (this.started) return this._resolvedFrom;
|
|
61
|
-
this._resolvedFrom = {};
|
|
62
|
-
for (const key of Object.keys(this.to) as Array<keyof Tween2DProperties>) {
|
|
63
|
-
this._resolvedFrom[key] = this.from?.[key] ?? current[key] ?? 0;
|
|
64
|
-
}
|
|
65
|
-
return this._resolvedFrom;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
getEasingFunction(): EasingFunction {
|
|
69
|
-
if (typeof this.easing === 'function') return this.easing;
|
|
70
|
-
return Easing[this.easing as Tween2DEasingName] ?? Easing.linear;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
override clone(): Tween2DComponent {
|
|
74
|
-
return new Tween2DComponent({
|
|
75
|
-
...(this.from ? { from: { ...this.from } } : {}),
|
|
76
|
-
to: { ...this.to },
|
|
77
|
-
duration: this.duration,
|
|
78
|
-
delay: this.delay,
|
|
79
|
-
easing: this.easing,
|
|
80
|
-
removeOnComplete: this.removeOnComplete,
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
}
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { Entity, System, Transform2D, type World } from '@haiyue/engine';
|
|
2
|
-
import { Tween2DComponent, type Tween2DProperties } from './Tween2DComponent';
|
|
3
|
-
|
|
4
|
-
export interface Tween2DSystemOptions {
|
|
5
|
-
priority?: number;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
function lerp(from: number, to: number, t: number): number {
|
|
9
|
-
return from + (to - from) * t;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
function readTransform(transform: Transform2D, out: Required<Tween2DProperties>): Required<Tween2DProperties> {
|
|
13
|
-
out.x = transform.x;
|
|
14
|
-
out.y = transform.y;
|
|
15
|
-
out.rotation = transform.rotation;
|
|
16
|
-
out.scaleX = transform.scaleX;
|
|
17
|
-
out.scaleY = transform.scaleY;
|
|
18
|
-
return out;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export class Tween2DSystem extends System {
|
|
22
|
-
private readonly completedEntities: Entity[] = [];
|
|
23
|
-
private readonly transformScratch: Required<Tween2DProperties> = { x: 0, y: 0, rotation: 0, scaleX: 1, scaleY: 1 };
|
|
24
|
-
|
|
25
|
-
constructor(options: Tween2DSystemOptions = {}) {
|
|
26
|
-
super({ all: [Tween2DComponent, Transform2D] });
|
|
27
|
-
this.name = 'Tween2DSystem';
|
|
28
|
-
if (options.priority !== undefined) this.priority = options.priority;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
override update(world: World, _time: number, delta: number): this {
|
|
32
|
-
if (this.disabled) return this;
|
|
33
|
-
this.completedEntities.length = 0;
|
|
34
|
-
const entities = this.entitySet.get(world);
|
|
35
|
-
if (entities) {
|
|
36
|
-
for (const entity of entities) this.updateEntity(entity, delta);
|
|
37
|
-
}
|
|
38
|
-
for (const entity of this.completedEntities) {
|
|
39
|
-
const tween = entity.getComponent(Tween2DComponent);
|
|
40
|
-
if (tween?.completed && tween.removeOnComplete) entity.removeComponent(tween);
|
|
41
|
-
}
|
|
42
|
-
return this;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
private updateEntity(entity: Entity, delta: number): void {
|
|
46
|
-
const tween = entity.getComponent(Tween2DComponent);
|
|
47
|
-
const transform = entity.getComponent(Transform2D);
|
|
48
|
-
if (!tween || !transform || tween.completed) return;
|
|
49
|
-
|
|
50
|
-
tween.elapsed += delta;
|
|
51
|
-
if (tween.elapsed < tween.delay) return;
|
|
52
|
-
|
|
53
|
-
const from = tween.resolveFrom(readTransform(transform, this.transformScratch));
|
|
54
|
-
if (!tween.started) {
|
|
55
|
-
tween.started = true;
|
|
56
|
-
this.apply(transform, from, 0);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const duration = Math.max(1, tween.duration);
|
|
60
|
-
const raw = Math.min((tween.elapsed - tween.delay) / duration, 1);
|
|
61
|
-
const progress = tween.getEasingFunction()(raw);
|
|
62
|
-
this.apply(transform, from, progress, tween.to);
|
|
63
|
-
|
|
64
|
-
if (raw >= 1) {
|
|
65
|
-
tween.completed = true;
|
|
66
|
-
this.apply(transform, from, 1, tween.to);
|
|
67
|
-
if (tween.removeOnComplete) this.completedEntities.push(entity);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
private apply(transform: Transform2D, from: Tween2DProperties, progress: number, to: Tween2DProperties = from): void {
|
|
72
|
-
if (to.x !== undefined) transform.x = lerp(from.x ?? transform.x, to.x, progress);
|
|
73
|
-
if (to.y !== undefined) transform.y = lerp(from.y ?? transform.y, to.y, progress);
|
|
74
|
-
if (to.rotation !== undefined) transform.rotation = lerp(from.rotation ?? transform.rotation, to.rotation, progress);
|
|
75
|
-
if (to.scaleX !== undefined) transform.scaleX = lerp(from.scaleX ?? transform.scaleX, to.scaleX, progress);
|
|
76
|
-
if (to.scaleY !== undefined) transform.scaleY = lerp(from.scaleY ?? transform.scaleY, to.scaleY, progress);
|
|
77
|
-
}
|
|
78
|
-
}
|
package/src/tween.ts
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
export { Tween2DComponent } from './tween/Tween2DComponent';
|
|
2
|
-
export type { Tween2DComponentOptions, Tween2DEasingName, Tween2DProperties } from './tween/Tween2DComponent';
|
|
3
|
-
export { Tween2DSystem } from './tween/Tween2DSystem';
|
|
4
|
-
export type { Tween2DSystemOptions } from './tween/Tween2DSystem';
|
package/src/types/earcut.d.ts
DELETED
package/src/types/wgsl.d.ts
DELETED
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type EntityHierarchyDisabledCache,
|
|
3
|
-
type FrameData,
|
|
4
|
-
type IEngine,
|
|
5
|
-
type RenderCommandContext,
|
|
6
|
-
isEntityDisabledInHierarchyCached,
|
|
7
|
-
getExtensionGPUResourceTracker,
|
|
8
|
-
requireEngineDevice,
|
|
9
|
-
} from '@haiyue/engine/extension-authoring';
|
|
10
|
-
import { Camera2D } from '@haiyue/engine/components';
|
|
11
|
-
import { Entity, System, type SystemQuery, type World } from '@haiyue/engine/ecs';
|
|
12
|
-
import { compute2DViewProjection, write2DCameraBuffer } from './camera2d';
|
|
13
|
-
import { createObject2DGpu, destroyObject2DGpu, type Object2DGpu } from './render2dGpu';
|
|
14
|
-
|
|
15
|
-
export interface RenderSystem2DBaseOptions {
|
|
16
|
-
loadOp?: 'clear' | 'load';
|
|
17
|
-
priority?: number;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export abstract class RenderSystem2DBase extends System {
|
|
21
|
-
protected readonly engine: IEngine;
|
|
22
|
-
protected cameraEntity: Entity;
|
|
23
|
-
protected readonly disabledHierarchyCache: EntityHierarchyDisabledCache = new Map();
|
|
24
|
-
protected readonly liveEntityIds = new Set<number>();
|
|
25
|
-
|
|
26
|
-
loadOp: 'clear' | 'load';
|
|
27
|
-
readonly recoveryLabel: string;
|
|
28
|
-
readonly recoverySource: { kind: 'component-render-system'; system: string };
|
|
29
|
-
private readonly unregisterRecovery: (() => void) | null;
|
|
30
|
-
|
|
31
|
-
protected constructor(
|
|
32
|
-
rule: SystemQuery,
|
|
33
|
-
engine: IEngine,
|
|
34
|
-
cameraEntity: Entity,
|
|
35
|
-
options: RenderSystem2DBaseOptions = {},
|
|
36
|
-
name?: string,
|
|
37
|
-
) {
|
|
38
|
-
super(rule);
|
|
39
|
-
this.engine = engine;
|
|
40
|
-
this.cameraEntity = cameraEntity;
|
|
41
|
-
this.loadOp = options.loadOp ?? 'load';
|
|
42
|
-
if (name) this.name = name;
|
|
43
|
-
if (options.priority !== undefined) this.priority = options.priority;
|
|
44
|
-
this.recoveryLabel = `${name ?? this.constructor.name}:${this.id}`;
|
|
45
|
-
this.recoverySource = { kind: 'component-render-system', system: name ?? this.constructor.name };
|
|
46
|
-
this.unregisterRecovery = engine.registerDeviceRecoveryParticipant?.(this) ?? null;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
setCameraEntity(cameraEntity: Entity): this {
|
|
50
|
-
this.cameraEntity = cameraEntity;
|
|
51
|
-
return this;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
protected getCamera2D(context?: RenderCommandContext): Camera2D | null {
|
|
55
|
-
return this.getCameraEntity(context).getComponent(Camera2D);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
protected getFrameData(context: RenderCommandContext): FrameData {
|
|
59
|
-
const cameraEntity = this.getCameraEntity(context);
|
|
60
|
-
const frameData = context.frameData ?? cameraEntity.world?.frameData;
|
|
61
|
-
if (!frameData) throw new Error(`${this.name} requires frame data from its render context or camera usage.`);
|
|
62
|
-
return frameData;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
protected computeCameraViewProjection(camera: Camera2D, context?: RenderCommandContext): Float32Array {
|
|
66
|
-
if (context) {
|
|
67
|
-
return this.getFrameData(context).getCamera2D(
|
|
68
|
-
this.getCameraEntity(context),
|
|
69
|
-
camera,
|
|
70
|
-
context.view?.displayWidth ?? this.engine.displayWidth,
|
|
71
|
-
context.view?.displayHeight ?? this.engine.displayHeight,
|
|
72
|
-
).viewProjectionMatrix;
|
|
73
|
-
}
|
|
74
|
-
return compute2DViewProjection(this.engine, this.cameraEntity, camera);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
protected writeCameraBuffer(queue: GPUQueue, buffer: GPUBuffer, context?: RenderCommandContext): boolean {
|
|
78
|
-
const camera = this.getCamera2D(context);
|
|
79
|
-
if (!camera) return false;
|
|
80
|
-
write2DCameraBuffer(queue, buffer, this.computeCameraViewProjection(camera, context));
|
|
81
|
-
return true;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
protected getWorldMatrix2D(entity: Entity, context: RenderCommandContext): Float32Array {
|
|
85
|
-
return this.getFrameData(context).getWorldMatrix2D(entity);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
private getCameraEntity(context?: RenderCommandContext): Entity {
|
|
89
|
-
return context?.view?.camera.getComponent(Camera2D) ? context.view.camera : this.cameraEntity;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
protected isEntityRenderable(entity: Entity): boolean {
|
|
93
|
-
return !isEntityDisabledInHierarchyCached(entity, this.disabledHierarchyCache);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
protected beginLiveEntityTracking(): Set<number> {
|
|
97
|
-
this.liveEntityIds.clear();
|
|
98
|
-
this.disabledHierarchyCache.clear();
|
|
99
|
-
return this.liveEntityIds;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
protected markEntityLive(entity: Entity | number): void {
|
|
103
|
-
this.liveEntityIds.add(typeof entity === 'number' ? entity : entity.id);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
protected createObjectGpu(layout: GPUBindGroupLayout): Object2DGpu {
|
|
107
|
-
return createObject2DGpu(requireEngineDevice(this.engine), layout, getExtensionGPUResourceTracker(this.engine));
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
protected destroyObjectGpu(objectGpu: Object2DGpu): void {
|
|
111
|
-
destroyObject2DGpu(objectGpu);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
protected getOrCreateEntityGpu<T>(
|
|
115
|
-
cache: Map<number, T>,
|
|
116
|
-
entity: Entity,
|
|
117
|
-
create: () => T,
|
|
118
|
-
): T {
|
|
119
|
-
let gpu = cache.get(entity.id);
|
|
120
|
-
if (!gpu) {
|
|
121
|
-
gpu = create();
|
|
122
|
-
cache.set(entity.id, gpu);
|
|
123
|
-
}
|
|
124
|
-
return gpu;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
protected releaseEntityGpuEntriesNotIn<T>(
|
|
128
|
-
cache: Map<number, T>,
|
|
129
|
-
destroy: (gpu: T) => void,
|
|
130
|
-
liveEntities: ReadonlySet<number> = this.liveEntityIds,
|
|
131
|
-
): void {
|
|
132
|
-
for (const [entityId, gpu] of cache) {
|
|
133
|
-
if (!liveEntities.has(entityId)) {
|
|
134
|
-
destroy(gpu);
|
|
135
|
-
cache.delete(entityId);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
protected destroyEntityGpuEntries<T>(
|
|
141
|
-
cache: Map<number, T>,
|
|
142
|
-
destroy: (gpu: T) => void,
|
|
143
|
-
): void {
|
|
144
|
-
for (const gpu of cache.values()) destroy(gpu);
|
|
145
|
-
cache.clear();
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
suspendForDeviceLoss(): void {
|
|
149
|
-
this.releaseGpuResourcesForRecovery();
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
recoverGpuResource(_device: GPUDevice, signal: AbortSignal): void {
|
|
153
|
-
if (signal.aborted) throw signal.reason;
|
|
154
|
-
this.restoreGpuResourcesAfterRecovery();
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
override destroy(): this {
|
|
158
|
-
this.unregisterRecovery?.();
|
|
159
|
-
return super.destroy();
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
protected abstract releaseGpuResourcesForRecovery(): void;
|
|
163
|
-
protected restoreGpuResourcesAfterRecovery(): void {}
|
|
164
|
-
}
|
package/src/utils/arrayAccess.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/** Reads an element whose presence is an internal runtime invariant. */
|
|
2
|
-
export function requiredItemAt<T>(values: ArrayLike<T>, index: number, label: string): T {
|
|
3
|
-
const value = values[index];
|
|
4
|
-
if (value === undefined) {
|
|
5
|
-
throw new RangeError(`${label} is missing element ${index} (length ${values.length}).`);
|
|
6
|
-
}
|
|
7
|
-
return value;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
/** Reads a number whose presence is an internal runtime invariant. */
|
|
11
|
-
export function requiredNumberAt(values: ArrayLike<number>, index: number, label: string): number {
|
|
12
|
-
const value = values[index];
|
|
13
|
-
if (value === undefined || !Number.isFinite(value)) {
|
|
14
|
-
throw new RangeError(`${label} requires a finite value at ${index} (length ${values.length}).`);
|
|
15
|
-
}
|
|
16
|
-
return value;
|
|
17
|
-
}
|
package/src/utils/camera2d.ts
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { Camera2D, Entity, Transform2D } from '@haiyue/engine';
|
|
2
|
-
import { Transform3D } from '@haiyue/engine/components';
|
|
3
|
-
import { type IEngine } from '@haiyue/engine/core';
|
|
4
|
-
import { mat4 } from 'wgpu-matrix';
|
|
5
|
-
|
|
6
|
-
export interface Camera2DScratch {
|
|
7
|
-
viewMatrix: Float32Array;
|
|
8
|
-
viewProjMatrix: Float32Array;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export function createCamera2DScratch(): Camera2DScratch {
|
|
12
|
-
return {
|
|
13
|
-
viewMatrix: mat4.identity() as Float32Array,
|
|
14
|
-
viewProjMatrix: mat4.identity() as Float32Array,
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export function compute2DViewProjection(
|
|
19
|
-
engine: IEngine,
|
|
20
|
-
cameraEntity: Entity,
|
|
21
|
-
camera: Camera2D,
|
|
22
|
-
scratch: Camera2DScratch = createCamera2DScratch(),
|
|
23
|
-
): Float32Array {
|
|
24
|
-
camera.resize(engine.displayWidth, engine.displayHeight);
|
|
25
|
-
const transform = cameraEntity.getComponent(Transform3D);
|
|
26
|
-
if (!transform) return camera.projectionMatrix;
|
|
27
|
-
transform.updateWorldMatrix();
|
|
28
|
-
const viewMatrix = mat4.inverse(transform.worldMatrix, scratch.viewMatrix) as Float32Array;
|
|
29
|
-
return mat4.multiply(camera.projectionMatrix, viewMatrix, scratch.viewProjMatrix) as Float32Array;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export function write2DCameraBuffer(queue: GPUQueue, buffer: GPUBuffer, viewProj: Float32Array): void {
|
|
33
|
-
queue.writeBuffer(buffer, 0, viewProj.buffer as ArrayBuffer, viewProj.byteOffset, viewProj.byteLength);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export const IDENTITY_2D_WORLD_MATRIX = mat4.identity() as Float32Array;
|
|
37
|
-
|
|
38
|
-
export type WorldMatrix2DFrameCache = Map<Entity, Float32Array>;
|
|
39
|
-
|
|
40
|
-
export function get2DEntityWorldMatrix(entity: Entity, cache?: WorldMatrix2DFrameCache): Float32Array {
|
|
41
|
-
const cached = cache?.get(entity);
|
|
42
|
-
if (cached) return cached;
|
|
43
|
-
|
|
44
|
-
const transform2D = entity.getComponent(Transform2D);
|
|
45
|
-
if (transform2D) {
|
|
46
|
-
const parent = entity.parent as Entity | null;
|
|
47
|
-
const parentMatrix = parent ? get2DEntityWorldMatrix(parent, cache) : undefined;
|
|
48
|
-
const parentTransform2D = parent?.getComponent(Transform2D);
|
|
49
|
-
const parentTransform3D = parent?.getComponent(Transform3D);
|
|
50
|
-
transform2D.updateWorldMatrix(parentMatrix, parentTransform2D?.worldVersion ?? parentTransform3D?.worldVersion ?? 0);
|
|
51
|
-
cache?.set(entity, transform2D.worldMatrix);
|
|
52
|
-
return transform2D.worldMatrix;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const transform3D = entity.getComponent(Transform3D);
|
|
56
|
-
if (transform3D) {
|
|
57
|
-
const parent = entity.parent as Entity | null;
|
|
58
|
-
const parentMatrix = parent ? get2DEntityWorldMatrix(parent, cache) : undefined;
|
|
59
|
-
const parentTransform2D = parent?.getComponent(Transform2D);
|
|
60
|
-
const parentTransform3D = parent?.getComponent(Transform3D);
|
|
61
|
-
transform3D.updateWorldMatrix(parentMatrix, parentTransform2D?.worldVersion ?? parentTransform3D?.worldVersion ?? 0);
|
|
62
|
-
cache?.set(entity, transform3D.worldMatrix);
|
|
63
|
-
return transform3D.worldMatrix;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
cache?.set(entity, IDENTITY_2D_WORLD_MATRIX);
|
|
67
|
-
return IDENTITY_2D_WORLD_MATRIX;
|
|
68
|
-
}
|
package/src/utils/render2dGpu.ts
DELETED
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
import { estimateTextureBytes, type ExtensionGPUResourceTracker } from '@haiyue/engine/extension-authoring';
|
|
2
|
-
|
|
3
|
-
export interface Camera2DGpu {
|
|
4
|
-
layout: GPUBindGroupLayout;
|
|
5
|
-
buffer: GPUBuffer;
|
|
6
|
-
tracker?: ExtensionGPUResourceTracker;
|
|
7
|
-
bindGroup: GPUBindGroup;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export interface Object2DGpu {
|
|
11
|
-
buffer: GPUBuffer;
|
|
12
|
-
bindGroup: GPUBindGroup;
|
|
13
|
-
snapshot: Float32Array;
|
|
14
|
-
tracker?: ExtensionGPUResourceTracker;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export interface Texture2DGpu {
|
|
18
|
-
layout: GPUBindGroupLayout;
|
|
19
|
-
sampler: GPUSampler;
|
|
20
|
-
fallbackTexture: GPUTexture;
|
|
21
|
-
fallbackBindGroup: GPUBindGroup;
|
|
22
|
-
tracker?: ExtensionGPUResourceTracker;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export function createCamera2DLayout(device: GPUDevice): GPUBindGroupLayout {
|
|
26
|
-
return device.createBindGroupLayout({
|
|
27
|
-
entries: [{ binding: 0, visibility: GPUShaderStage.VERTEX, buffer: { type: 'uniform' } }],
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export function createCamera2DGpu(
|
|
32
|
-
device: GPUDevice,
|
|
33
|
-
tracker?: ExtensionGPUResourceTracker,
|
|
34
|
-
layout = createCamera2DLayout(device),
|
|
35
|
-
): Camera2DGpu {
|
|
36
|
-
const buffer = device.createBuffer({ size: 64, usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST });
|
|
37
|
-
tracker?.trackBuffer(buffer, 'render2d.cameraBuffer', 64);
|
|
38
|
-
const bindGroup = device.createBindGroup({
|
|
39
|
-
layout,
|
|
40
|
-
entries: [{ binding: 0, resource: { buffer } }],
|
|
41
|
-
});
|
|
42
|
-
return { layout, buffer, bindGroup, ...(tracker === undefined ? {} : { tracker }) };
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export function createObject2DLayout(device: GPUDevice): GPUBindGroupLayout {
|
|
46
|
-
return device.createBindGroupLayout({
|
|
47
|
-
entries: [{ binding: 0, visibility: GPUShaderStage.VERTEX, buffer: { type: 'uniform' } }],
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export function createObject2DGpu(device: GPUDevice, layout: GPUBindGroupLayout, tracker?: ExtensionGPUResourceTracker): Object2DGpu {
|
|
52
|
-
const buffer = device.createBuffer({ size: 64, usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST });
|
|
53
|
-
tracker?.trackBuffer(buffer, 'render2d.objectBuffer', 64);
|
|
54
|
-
return {
|
|
55
|
-
buffer,
|
|
56
|
-
bindGroup: device.createBindGroup({
|
|
57
|
-
layout,
|
|
58
|
-
entries: [{ binding: 0, resource: { buffer } }],
|
|
59
|
-
}),
|
|
60
|
-
snapshot: createMatrixSnapshot(),
|
|
61
|
-
...(tracker === undefined ? {} : { tracker }),
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export function createTexture2DGpu(device: GPUDevice, fallbackAlpha = 255, tracker?: ExtensionGPUResourceTracker): Texture2DGpu {
|
|
66
|
-
const layout = device.createBindGroupLayout({
|
|
67
|
-
entries: [
|
|
68
|
-
{ binding: 0, visibility: GPUShaderStage.FRAGMENT, texture: { sampleType: 'float' } },
|
|
69
|
-
{ binding: 1, visibility: GPUShaderStage.FRAGMENT, sampler: { type: 'filtering' } },
|
|
70
|
-
],
|
|
71
|
-
});
|
|
72
|
-
const sampler = device.createSampler({ magFilter: 'linear', minFilter: 'linear' });
|
|
73
|
-
const fallbackTexture = device.createTexture({
|
|
74
|
-
size: [1, 1],
|
|
75
|
-
format: 'rgba8unorm',
|
|
76
|
-
usage: GPUTextureUsage.TEXTURE_BINDING | GPUTextureUsage.COPY_DST,
|
|
77
|
-
});
|
|
78
|
-
tracker?.trackTexture(fallbackTexture, 'render2d.fallbackTexture', estimateTextureBytes([1, 1, 1], 'rgba8unorm'));
|
|
79
|
-
device.queue.writeTexture(
|
|
80
|
-
{ texture: fallbackTexture },
|
|
81
|
-
new Uint8Array([255, 255, 255, fallbackAlpha]),
|
|
82
|
-
{ bytesPerRow: 4 },
|
|
83
|
-
[1, 1],
|
|
84
|
-
);
|
|
85
|
-
const fallbackBindGroup = device.createBindGroup({
|
|
86
|
-
layout,
|
|
87
|
-
entries: [
|
|
88
|
-
{ binding: 0, resource: fallbackTexture.createView() },
|
|
89
|
-
{ binding: 1, resource: sampler },
|
|
90
|
-
],
|
|
91
|
-
});
|
|
92
|
-
return { layout, sampler, fallbackTexture, fallbackBindGroup, ...(tracker === undefined ? {} : { tracker }) };
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
export function writeFloatBuffer(queue: GPUQueue, buffer: GPUBuffer, data: Float32Array): void {
|
|
96
|
-
queue.writeBuffer(buffer, 0, data.buffer as ArrayBuffer, data.byteOffset, data.byteLength);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
export function matrixEquals(a: Float32Array, b: Float32Array): boolean {
|
|
100
|
-
for (let i = 0; i < 16; i++) {
|
|
101
|
-
if (a[i] !== b[i]) return false;
|
|
102
|
-
}
|
|
103
|
-
return true;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
export function createMatrixSnapshot(): Float32Array {
|
|
107
|
-
const snapshot = new Float32Array(16);
|
|
108
|
-
snapshot.fill(Number.NaN);
|
|
109
|
-
return snapshot;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
export function writeObjectMatrixIfChanged(queue: GPUQueue, gpu: Object2DGpu, matrix: Float32Array): boolean {
|
|
113
|
-
if (matrixEquals(gpu.snapshot, matrix)) return false;
|
|
114
|
-
writeFloatBuffer(queue, gpu.buffer, matrix);
|
|
115
|
-
gpu.snapshot.set(matrix);
|
|
116
|
-
return true;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
export function destroyCamera2DGpu(gpu: Camera2DGpu): void {
|
|
120
|
-
gpu.tracker?.untrackBuffer(gpu.buffer);
|
|
121
|
-
gpu.buffer.destroy();
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
export function destroyObject2DGpu(gpu: Object2DGpu): void {
|
|
125
|
-
gpu.tracker?.untrackBuffer(gpu.buffer);
|
|
126
|
-
gpu.buffer.destroy();
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
export function destroyTexture2DGpu(gpu: Texture2DGpu): void {
|
|
130
|
-
gpu.tracker?.untrackTexture(gpu.fallbackTexture);
|
|
131
|
-
gpu.fallbackTexture.destroy();
|
|
132
|
-
}
|