@luma.gl/engine 9.4.0-alpha.4 → 9.4.0-beta.1
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/LICENSE +5 -1
- package/dist/animation/animation-clip.d.ts +18 -0
- package/dist/animation/animation-clip.d.ts.map +1 -0
- package/dist/animation/animation-clip.js +15 -0
- package/dist/animation/animation-clip.js.map +1 -0
- package/dist/animation/animation-interpolation.d.ts +18 -0
- package/dist/animation/animation-interpolation.d.ts.map +1 -0
- package/dist/animation/animation-interpolation.js +101 -0
- package/dist/animation/animation-interpolation.js.map +1 -0
- package/dist/animation/animation-mixer.d.ts +88 -0
- package/dist/animation/animation-mixer.d.ts.map +1 -0
- package/dist/animation/animation-mixer.js +287 -0
- package/dist/animation/animation-mixer.js.map +1 -0
- package/dist/animation/animation-track.d.ts +42 -0
- package/dist/animation/animation-track.d.ts.map +1 -0
- package/dist/animation/animation-track.js +34 -0
- package/dist/animation/animation-track.js.map +1 -0
- package/dist/animation/animator.js +1 -1
- package/dist/animation/animator.js.map +1 -1
- package/dist/animation/key-frames.js +1 -1
- package/dist/animation/key-frames.js.map +1 -1
- package/dist/animation/morph-targets.d.ts +15 -0
- package/dist/animation/morph-targets.d.ts.map +1 -0
- package/dist/animation/morph-targets.js +151 -0
- package/dist/animation/morph-targets.js.map +1 -0
- package/dist/animation/skin.d.ts +18 -0
- package/dist/animation/skin.d.ts.map +1 -0
- package/dist/animation/skin.js +30 -0
- package/dist/animation/skin.js.map +1 -0
- package/dist/animation/timeline.js +1 -1
- package/dist/animation/timeline.js.map +1 -1
- package/dist/animation-loop/animation-loop-template.js +1 -1
- package/dist/animation-loop/animation-loop-template.js.map +1 -1
- package/dist/animation-loop/animation-loop.d.ts +5 -4
- package/dist/animation-loop/animation-loop.d.ts.map +1 -1
- package/dist/animation-loop/animation-loop.js +3 -3
- package/dist/animation-loop/animation-loop.js.map +1 -1
- package/dist/animation-loop/animation-props.d.ts +1 -1
- package/dist/animation-loop/animation-props.js +1 -1
- package/dist/animation-loop/animation-props.js.map +1 -1
- package/dist/animation-loop/make-animation-loop.d.ts +1 -1
- package/dist/animation-loop/make-animation-loop.d.ts.map +1 -1
- package/dist/animation-loop/make-animation-loop.js +6 -3
- package/dist/animation-loop/make-animation-loop.js.map +1 -1
- package/dist/animation-loop/request-animation-frame.js +1 -1
- package/dist/animation-loop/request-animation-frame.js.map +1 -1
- package/dist/application-utils/load-file.js +1 -1
- package/dist/application-utils/load-file.js.map +1 -1
- package/dist/application-utils/random.js +1 -1
- package/dist/application-utils/random.js.map +1 -1
- package/dist/compute/buffer-transform.d.ts +1 -1
- package/dist/compute/buffer-transform.d.ts.map +1 -1
- package/dist/compute/buffer-transform.js +1 -1
- package/dist/compute/buffer-transform.js.map +1 -1
- package/dist/compute/computation.d.ts +1 -1
- package/dist/compute/computation.d.ts.map +1 -1
- package/dist/compute/computation.js +11 -6
- package/dist/compute/computation.js.map +1 -1
- package/dist/compute/swap.js +1 -1
- package/dist/compute/swap.js.map +1 -1
- package/dist/compute/texture-transform.js +1 -1
- package/dist/compute/texture-transform.js.map +1 -1
- package/dist/controls/orbit-controls.d.ts +61 -0
- package/dist/controls/orbit-controls.d.ts.map +1 -0
- package/dist/controls/orbit-controls.js +179 -0
- package/dist/controls/orbit-controls.js.map +1 -0
- package/dist/debug/copy-texture-to-image.js +1 -1
- package/dist/debug/copy-texture-to-image.js.map +1 -1
- package/dist/debug/debug-framebuffer.js +1 -1
- package/dist/debug/debug-framebuffer.js.map +1 -1
- package/dist/debug/debug-shader-layout.js +1 -1
- package/dist/debug/debug-shader-layout.js.map +1 -1
- package/dist/debug/pixel-data-utils.js +1 -1
- package/dist/debug/pixel-data-utils.js.map +1 -1
- package/dist/dist.dev.js +7588 -6260
- package/dist/dist.min.js +31 -31
- package/dist/dynamic-buffer/dynamic-buffer.js +1 -1
- package/dist/dynamic-buffer/dynamic-buffer.js.map +1 -1
- package/dist/dynamic-texture/dynamic-texture.d.ts.map +1 -1
- package/dist/dynamic-texture/dynamic-texture.js +3 -2
- package/dist/dynamic-texture/dynamic-texture.js.map +1 -1
- package/dist/dynamic-texture/texture-binding-source.js +1 -1
- package/dist/dynamic-texture/texture-binding-source.js.map +1 -1
- package/dist/dynamic-texture/texture-data.js +1 -1
- package/dist/dynamic-texture/texture-data.js.map +1 -1
- package/dist/dynamic-texture/video-texture.js +1 -1
- package/dist/dynamic-texture/video-texture.js.map +1 -1
- package/dist/geometries/cone-geometry.js +1 -1
- package/dist/geometries/cone-geometry.js.map +1 -1
- package/dist/geometries/cube-geometry.js +1 -1
- package/dist/geometries/cube-geometry.js.map +1 -1
- package/dist/geometries/cylinder-geometry.js +1 -1
- package/dist/geometries/cylinder-geometry.js.map +1 -1
- package/dist/geometries/ico-sphere-geometry.js +1 -1
- package/dist/geometries/ico-sphere-geometry.js.map +1 -1
- package/dist/geometry/geometry-table.js +1 -1
- package/dist/geometry/geometry-table.js.map +1 -1
- package/dist/geometry/geometry-utils.js +1 -1
- package/dist/geometry/geometry-utils.js.map +1 -1
- package/dist/geometry/geometry.js +1 -1
- package/dist/geometry/geometry.js.map +1 -1
- package/dist/geometry/gpu-geometry.js +1 -1
- package/dist/geometry/gpu-geometry.js.map +1 -1
- package/dist/geometry/mesh-simplification.d.ts +29 -0
- package/dist/geometry/mesh-simplification.d.ts.map +1 -0
- package/dist/geometry/mesh-simplification.js +402 -0
- package/dist/geometry/mesh-simplification.js.map +1 -0
- package/dist/index.cjs +9858 -1420
- package/dist/index.cjs.map +3 -4
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -1
- package/dist/index.js.map +1 -1
- package/dist/material/material-factory.js +1 -1
- package/dist/material/material-factory.js.map +1 -1
- package/dist/material/material.js +1 -1
- package/dist/material/material.js.map +1 -1
- package/dist/model/model.d.ts +1 -1
- package/dist/model/model.d.ts.map +1 -1
- package/dist/model/model.js +35 -10
- package/dist/model/model.js.map +1 -1
- package/dist/model/split-uniforms-and-bindings.js +1 -1
- package/dist/model/split-uniforms-and-bindings.js.map +1 -1
- package/dist/models/billboard-texture-model.js +1 -1
- package/dist/models/billboard-texture-model.js.map +1 -1
- package/dist/models/billboard-texture-module.js +1 -1
- package/dist/models/billboard-texture-module.js.map +1 -1
- package/dist/models/clip-space.js +1 -1
- package/dist/models/clip-space.js.map +1 -1
- package/dist/models/directional-light-model.js +1 -1
- package/dist/models/directional-light-model.js.map +1 -1
- package/dist/models/light-model-utils.js +1 -1
- package/dist/models/light-model-utils.js.map +1 -1
- package/dist/models/point-light-model.js +1 -1
- package/dist/models/point-light-model.js.map +1 -1
- package/dist/models/spot-light-model.js +1 -1
- package/dist/models/spot-light-model.js.map +1 -1
- package/dist/modules/picking/color-picking.js +1 -1
- package/dist/modules/picking/color-picking.js.map +1 -1
- package/dist/modules/picking/index-color-picking.js +1 -1
- package/dist/modules/picking/index-color-picking.js.map +1 -1
- package/dist/modules/picking/index-picking.js +1 -1
- package/dist/modules/picking/index-picking.js.map +1 -1
- package/dist/modules/picking/legacy-color-picking.js +1 -1
- package/dist/modules/picking/legacy-color-picking.js.map +1 -1
- package/dist/modules/picking/legacy-picking-manager.js +1 -1
- package/dist/modules/picking/legacy-picking-manager.js.map +1 -1
- package/dist/modules/picking/picking-manager.js +1 -1
- package/dist/modules/picking/picking-manager.js.map +1 -1
- package/dist/modules/picking/picking-uniforms.js +1 -1
- package/dist/modules/picking/picking-uniforms.js.map +1 -1
- package/dist/modules/picking/picking.js +1 -1
- package/dist/modules/picking/picking.js.map +1 -1
- package/dist/passes/get-fragment-shader.js +1 -1
- package/dist/passes/get-fragment-shader.js.map +1 -1
- package/dist/passes/shader-pass-renderer.d.ts +19 -1
- package/dist/passes/shader-pass-renderer.d.ts.map +1 -1
- package/dist/passes/shader-pass-renderer.js +180 -11
- package/dist/passes/shader-pass-renderer.js.map +1 -1
- package/dist/passes/texture-transform-module.js +1 -1
- package/dist/passes/texture-transform-module.js.map +1 -1
- package/dist/scenegraph/group-node.d.ts.map +1 -1
- package/dist/scenegraph/group-node.js +7 -1
- package/dist/scenegraph/group-node.js.map +1 -1
- package/dist/scenegraph/model-node.js +1 -1
- package/dist/scenegraph/model-node.js.map +1 -1
- package/dist/scenegraph/scenegraph-bounds.js +1 -1
- package/dist/scenegraph/scenegraph-bounds.js.map +1 -1
- package/dist/scenegraph/scenegraph-node.js +4 -4
- package/dist/scenegraph/scenegraph-node.js.map +1 -1
- package/dist/shader-inputs.js +1 -1
- package/dist/shader-inputs.js.map +1 -1
- package/dist/utils/buffer-layout-helper.js +1 -1
- package/dist/utils/buffer-layout-helper.js.map +1 -1
- package/dist/utils/buffer-layout-order.js +1 -1
- package/dist/utils/buffer-layout-order.js.map +1 -1
- package/dist/utils/deep-equal.js +1 -1
- package/dist/utils/deep-equal.js.map +1 -1
- package/dist/utils/shader-module-utils.js +1 -1
- package/dist/utils/shader-module-utils.js.map +1 -1
- package/dist/utils/uid.js +1 -1
- package/dist/utils/uid.js.map +1 -1
- package/package.json +2 -2
- package/src/animation/animation-clip.ts +28 -0
- package/src/animation/animation-interpolation.ts +175 -0
- package/src/animation/animation-mixer.ts +370 -0
- package/src/animation/animation-track.ts +70 -0
- package/src/animation/animator.ts +1 -1
- package/src/animation/key-frames.ts +1 -1
- package/src/animation/morph-targets.ts +191 -0
- package/src/animation/skin.ts +50 -0
- package/src/animation/timeline.ts +1 -1
- package/src/animation-loop/animation-loop-template.ts +1 -1
- package/src/animation-loop/animation-loop.ts +8 -7
- package/src/animation-loop/animation-props.ts +2 -2
- package/src/animation-loop/make-animation-loop.ts +8 -5
- package/src/animation-loop/request-animation-frame.ts +1 -1
- package/src/application-utils/load-file.ts +1 -1
- package/src/application-utils/random.ts +1 -1
- package/src/compute/buffer-transform.ts +2 -2
- package/src/compute/computation.ts +22 -8
- package/src/compute/swap.ts +1 -1
- package/src/compute/texture-transform.ts +1 -1
- package/src/controls/orbit-controls.ts +248 -0
- package/src/debug/copy-texture-to-image.ts +1 -1
- package/src/debug/debug-framebuffer.ts +1 -1
- package/src/debug/debug-shader-layout.ts +1 -1
- package/src/debug/pixel-data-utils.ts +1 -1
- package/src/dynamic-buffer/dynamic-buffer.ts +1 -1
- package/src/dynamic-texture/dynamic-texture.ts +3 -2
- package/src/dynamic-texture/texture-binding-source.ts +1 -1
- package/src/dynamic-texture/texture-data.ts +1 -1
- package/src/dynamic-texture/video-texture.ts +1 -1
- package/src/geometries/cone-geometry.ts +1 -1
- package/src/geometries/cube-geometry.ts +1 -1
- package/src/geometries/cylinder-geometry.ts +1 -1
- package/src/geometries/ico-sphere-geometry.ts +1 -1
- package/src/geometry/geometry-table.ts +1 -1
- package/src/geometry/geometry-utils.ts +1 -1
- package/src/geometry/geometry.ts +1 -1
- package/src/geometry/gpu-geometry.ts +1 -1
- package/src/geometry/mesh-simplification.ts +554 -0
- package/src/index.ts +31 -1
- package/src/material/material-factory.ts +1 -1
- package/src/material/material.ts +1 -1
- package/src/model/model.ts +67 -12
- package/src/model/split-uniforms-and-bindings.ts +1 -1
- package/src/models/billboard-texture-model.ts +1 -1
- package/src/models/billboard-texture-module.ts +1 -1
- package/src/models/clip-space.ts +1 -1
- package/src/models/directional-light-model.ts +1 -1
- package/src/models/light-model-utils.ts +1 -1
- package/src/models/point-light-model.ts +1 -1
- package/src/models/spot-light-model.ts +1 -1
- package/src/modules/picking/color-picking.ts +1 -1
- package/src/modules/picking/index-color-picking.ts +1 -1
- package/src/modules/picking/index-picking.ts +1 -1
- package/src/modules/picking/legacy-color-picking.ts +1 -1
- package/src/modules/picking/legacy-picking-manager.ts +1 -1
- package/src/modules/picking/picking-manager.ts +1 -1
- package/src/modules/picking/picking-uniforms.ts +1 -1
- package/src/modules/picking/picking.ts +1 -1
- package/src/passes/get-fragment-shader.ts +1 -1
- package/src/passes/shader-pass-renderer.ts +246 -14
- package/src/passes/texture-transform-module.ts +1 -1
- package/src/scenegraph/group-node.ts +8 -1
- package/src/scenegraph/model-node.ts +1 -1
- package/src/scenegraph/scenegraph-bounds.ts +1 -1
- package/src/scenegraph/scenegraph-node.ts +4 -4
- package/src/shader-inputs.ts +1 -1
- package/src/utils/buffer-layout-helper.ts +1 -1
- package/src/utils/buffer-layout-order.ts +1 -1
- package/src/utils/deep-equal.ts +1 -1
- package/src/utils/shader-module-utils.ts +1 -1
- package/src/utils/uid.ts +1 -1
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
evaluateAnimationSampler,
|
|
7
|
+
type AnimationInterpolation,
|
|
8
|
+
type AnimationSampler,
|
|
9
|
+
type AnimationValueType
|
|
10
|
+
} from './animation-interpolation';
|
|
11
|
+
|
|
12
|
+
/** Read/write connection between an animation track and an application property. */
|
|
13
|
+
export type AnimationBinding = {
|
|
14
|
+
/** Stable identity used to blend tracks that address the same property. */
|
|
15
|
+
id?: string;
|
|
16
|
+
/** Reads the unanimated property value when an action has less than full influence. */
|
|
17
|
+
getValue?: () => readonly number[];
|
|
18
|
+
/** Applies an interpolated or blended property value. */
|
|
19
|
+
setValue: (value: number[]) => void;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/** Construction properties for a reusable keyframe track. */
|
|
23
|
+
export type AnimationTrackProps = {
|
|
24
|
+
/** Application-visible track name. */
|
|
25
|
+
name?: string;
|
|
26
|
+
/** Keyframe times, in seconds. */
|
|
27
|
+
times: readonly number[];
|
|
28
|
+
/** Keyframe values, including glTF-compatible cubic spline tangent triples. */
|
|
29
|
+
values: readonly (readonly number[])[];
|
|
30
|
+
/** Interpolation between adjacent keyframes. */
|
|
31
|
+
interpolation?: AnimationInterpolation;
|
|
32
|
+
/** Value interpretation used during interpolation and blending. */
|
|
33
|
+
valueType?: AnimationValueType;
|
|
34
|
+
/** Target property updated when the track is played. */
|
|
35
|
+
binding: AnimationBinding;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
/** A typed, target-bound keyframe sequence shared by all scene formats. */
|
|
39
|
+
export class AnimationTrack {
|
|
40
|
+
readonly name: string;
|
|
41
|
+
readonly times: readonly number[];
|
|
42
|
+
readonly values: readonly (readonly number[])[];
|
|
43
|
+
readonly interpolation: AnimationInterpolation;
|
|
44
|
+
readonly valueType: AnimationValueType;
|
|
45
|
+
readonly binding: AnimationBinding;
|
|
46
|
+
|
|
47
|
+
constructor(props: AnimationTrackProps) {
|
|
48
|
+
this.name = props.name || props.binding.id || 'unnamed';
|
|
49
|
+
this.times = props.times;
|
|
50
|
+
this.values = props.values;
|
|
51
|
+
this.interpolation = props.interpolation || 'LINEAR';
|
|
52
|
+
this.valueType = props.valueType || 'vector';
|
|
53
|
+
this.binding = props.binding;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Last keyframe time, in seconds. */
|
|
57
|
+
get duration(): number {
|
|
58
|
+
return this.times[this.times.length - 1] || 0;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** glTF-compatible read-only view of this track's keyframe data. */
|
|
62
|
+
get sampler(): AnimationSampler {
|
|
63
|
+
return {input: this.times, output: this.values, interpolation: this.interpolation};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** Evaluates the track at an already-resolved clip time, in seconds. */
|
|
67
|
+
evaluate(time: number): number[] | null {
|
|
68
|
+
return evaluateAnimationSampler(time, this.sampler, this.valueType);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
import {Geometry, type GeometryAttribute} from '../geometry/geometry';
|
|
6
|
+
import {makeInterleavedGeometry} from '../geometry/geometry-utils';
|
|
7
|
+
import type {Model} from '../model/model';
|
|
8
|
+
|
|
9
|
+
/** Portable vertex attributes supported by glTF-style morph target deformation. */
|
|
10
|
+
export type MorphTargetAttributes = {
|
|
11
|
+
POSITION?: Float32Array;
|
|
12
|
+
NORMAL?: Float32Array;
|
|
13
|
+
TANGENT?: Float32Array;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
/** Decodes one immutable vertex attribute into its shader-facing floating-point values. */
|
|
17
|
+
export function decodeMorphTargetAttribute(attribute: GeometryAttribute): Float32Array {
|
|
18
|
+
const values = attribute.value;
|
|
19
|
+
if (values instanceof Float32Array) {
|
|
20
|
+
return values;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const decoded = new Float32Array(values.length);
|
|
24
|
+
const maximum = getNormalizedAttributeMaximum(values);
|
|
25
|
+
const signed =
|
|
26
|
+
values instanceof Int8Array || values instanceof Int16Array || values instanceof Int32Array;
|
|
27
|
+
for (let componentIndex = 0; componentIndex < values.length; componentIndex++) {
|
|
28
|
+
const value = Number(values[componentIndex]);
|
|
29
|
+
decoded[componentIndex] =
|
|
30
|
+
attribute['normalized'] && maximum
|
|
31
|
+
? signed
|
|
32
|
+
? Math.max(value / maximum, -1)
|
|
33
|
+
: value / maximum
|
|
34
|
+
: value;
|
|
35
|
+
}
|
|
36
|
+
return decoded;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Applies weighted morph deltas without modifying the immutable source vertex attributes. */
|
|
40
|
+
export function applyMorphTargets(
|
|
41
|
+
baseAttributes: Readonly<MorphTargetAttributes>,
|
|
42
|
+
targets: readonly Readonly<MorphTargetAttributes>[],
|
|
43
|
+
weights: readonly number[]
|
|
44
|
+
): MorphTargetAttributes {
|
|
45
|
+
const result: MorphTargetAttributes = {};
|
|
46
|
+
|
|
47
|
+
for (const attributeName of ['POSITION', 'NORMAL', 'TANGENT'] as const) {
|
|
48
|
+
const baseValues = baseAttributes[attributeName];
|
|
49
|
+
if (!baseValues) {
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const values = new Float32Array(baseValues);
|
|
54
|
+
const componentCount = attributeName === 'TANGENT' ? 4 : 3;
|
|
55
|
+
const vertexCount = Math.floor(baseValues.length / componentCount);
|
|
56
|
+
|
|
57
|
+
for (
|
|
58
|
+
let targetIndex = 0;
|
|
59
|
+
targetIndex < Math.min(targets.length, weights.length);
|
|
60
|
+
targetIndex++
|
|
61
|
+
) {
|
|
62
|
+
const weight = weights[targetIndex];
|
|
63
|
+
const targetValues = targets[targetIndex][attributeName];
|
|
64
|
+
if (!weight || !targetValues) {
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const targetComponentCount =
|
|
69
|
+
attributeName === 'TANGENT' && targetValues.length === vertexCount * 4 ? 4 : 3;
|
|
70
|
+
for (let vertexIndex = 0; vertexIndex < vertexCount; vertexIndex++) {
|
|
71
|
+
const destinationOffset = vertexIndex * componentCount;
|
|
72
|
+
const sourceOffset = vertexIndex * targetComponentCount;
|
|
73
|
+
for (let componentIndex = 0; componentIndex < 3; componentIndex++) {
|
|
74
|
+
values[destinationOffset + componentIndex] +=
|
|
75
|
+
(targetValues[sourceOffset + componentIndex] || 0) * weight;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (attributeName !== 'POSITION') {
|
|
81
|
+
normalizeMorphDirections(values, componentCount);
|
|
82
|
+
}
|
|
83
|
+
result[attributeName] = values;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return result;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** Rewrites an existing model vertex buffer while preserving its canonical interleaved layout. */
|
|
90
|
+
export function updateMorphTargetBuffers(
|
|
91
|
+
model: Model,
|
|
92
|
+
geometry: Geometry,
|
|
93
|
+
targets: readonly Readonly<MorphTargetAttributes>[],
|
|
94
|
+
weights: readonly number[]
|
|
95
|
+
): void {
|
|
96
|
+
const baseAttributes: MorphTargetAttributes = {};
|
|
97
|
+
for (const attributeName of ['POSITION', 'NORMAL', 'TANGENT'] as const) {
|
|
98
|
+
const attribute = geometry.attributes[attributeName];
|
|
99
|
+
if (attribute) {
|
|
100
|
+
baseAttributes[attributeName] = decodeMorphTargetAttribute(attribute);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const morphedAttributes = applyMorphTargets(baseAttributes, targets, weights);
|
|
105
|
+
const attributes: Record<string, GeometryAttribute> = {};
|
|
106
|
+
for (const [attributeName, attribute] of Object.entries(geometry.attributes)) {
|
|
107
|
+
if (attribute) {
|
|
108
|
+
attributes[attributeName] = attribute;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
for (const attributeName of ['POSITION', 'NORMAL', 'TANGENT'] as const) {
|
|
112
|
+
const values = morphedAttributes[attributeName];
|
|
113
|
+
const source = attributes[attributeName];
|
|
114
|
+
if (values && source) {
|
|
115
|
+
attributes[attributeName] = {...source, value: encodeMorphTargetAttribute(source, values)};
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const morphedGeometry = new Geometry({
|
|
120
|
+
id: geometry.id,
|
|
121
|
+
topology: geometry.topology || 'triangle-list',
|
|
122
|
+
vertexCount: geometry.vertexCount,
|
|
123
|
+
indices: geometry.indices,
|
|
124
|
+
attributes,
|
|
125
|
+
bufferLayout: geometry.bufferLayout
|
|
126
|
+
});
|
|
127
|
+
const interleaved = makeInterleavedGeometry(morphedGeometry);
|
|
128
|
+
const packedValues = interleaved.attributes['geometry']?.value;
|
|
129
|
+
const packedBuffer =
|
|
130
|
+
model._gpuGeometry?.attributes['geometry'] || model.bufferAttributes['geometry'];
|
|
131
|
+
if (packedValues && packedBuffer) {
|
|
132
|
+
packedBuffer.write(packedValues);
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
for (const attributeName of ['POSITION', 'NORMAL', 'TANGENT'] as const) {
|
|
137
|
+
const values = morphedAttributes[attributeName];
|
|
138
|
+
if (values) {
|
|
139
|
+
const shaderAttributeName =
|
|
140
|
+
attributeName === 'POSITION'
|
|
141
|
+
? 'positions'
|
|
142
|
+
: attributeName === 'NORMAL'
|
|
143
|
+
? 'normals'
|
|
144
|
+
: 'TANGENT';
|
|
145
|
+
model.bufferAttributes[shaderAttributeName]?.write(values);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function encodeMorphTargetAttribute(
|
|
151
|
+
attribute: GeometryAttribute,
|
|
152
|
+
values: Float32Array
|
|
153
|
+
): GeometryAttribute['value'] {
|
|
154
|
+
if (attribute.value instanceof Float32Array) {
|
|
155
|
+
return values;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const encoded = attribute.value.slice();
|
|
159
|
+
const maximum = getNormalizedAttributeMaximum(encoded);
|
|
160
|
+
const signed =
|
|
161
|
+
encoded instanceof Int8Array || encoded instanceof Int16Array || encoded instanceof Int32Array;
|
|
162
|
+
for (let componentIndex = 0; componentIndex < values.length; componentIndex++) {
|
|
163
|
+
const value = values[componentIndex];
|
|
164
|
+
encoded[componentIndex] =
|
|
165
|
+
attribute['normalized'] && maximum
|
|
166
|
+
? Math.round(Math.max(signed ? -1 : 0, Math.min(1, value)) * maximum)
|
|
167
|
+
: value;
|
|
168
|
+
}
|
|
169
|
+
return encoded;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function getNormalizedAttributeMaximum(values: GeometryAttribute['value']): number {
|
|
173
|
+
if (values instanceof Int8Array) return 127;
|
|
174
|
+
if (values instanceof Uint8Array || values instanceof Uint8ClampedArray) return 255;
|
|
175
|
+
if (values instanceof Int16Array) return 32767;
|
|
176
|
+
if (values instanceof Uint16Array) return 65535;
|
|
177
|
+
if (values instanceof Int32Array) return 2147483647;
|
|
178
|
+
if (values instanceof Uint32Array) return 4294967295;
|
|
179
|
+
return 0;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function normalizeMorphDirections(values: Float32Array, componentCount: number): void {
|
|
183
|
+
for (let offset = 0; offset < values.length; offset += componentCount) {
|
|
184
|
+
const length = Math.hypot(values[offset], values[offset + 1], values[offset + 2]);
|
|
185
|
+
if (length > 0) {
|
|
186
|
+
values[offset] /= length;
|
|
187
|
+
values[offset + 1] /= length;
|
|
188
|
+
values[offset + 2] /= length;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
import {Matrix4, type NumericArray} from '@math.gl/core';
|
|
6
|
+
|
|
7
|
+
import type {GroupNode} from '../scenegraph/group-node';
|
|
8
|
+
|
|
9
|
+
/** Format-independent inputs for evaluating a skinned mesh's joint palette. */
|
|
10
|
+
export type SkinJointMatricesProps = {
|
|
11
|
+
/** Joints in their authored palette order. */
|
|
12
|
+
joints: readonly GroupNode[];
|
|
13
|
+
/** Animated scenegraph node that owns the skinned mesh. */
|
|
14
|
+
meshNode?: GroupNode;
|
|
15
|
+
/** World transforms collected once for the animated scene hierarchy. */
|
|
16
|
+
worldMatrices: ReadonlyMap<GroupNode, Readonly<NumericArray>>;
|
|
17
|
+
/** Optional column-major inverse bind matrix for each joint. */
|
|
18
|
+
inverseBindMatrices?: ArrayLike<number>;
|
|
19
|
+
/** Existing output storage that can be reused across animation frames. */
|
|
20
|
+
target?: Float32Array;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/** Evaluates joint matrices in mesh-local space without owning a skeleton or GPU resources. */
|
|
24
|
+
export function updateSkinJointMatrices(props: SkinJointMatricesProps): Float32Array {
|
|
25
|
+
const {joints, meshNode, worldMatrices, inverseBindMatrices, target} = props;
|
|
26
|
+
const matrixCount = joints.length;
|
|
27
|
+
const jointMatrices =
|
|
28
|
+
target && target.length === matrixCount * 16 ? target : new Float32Array(matrixCount * 16);
|
|
29
|
+
const meshWorldMatrix = meshNode ? worldMatrices.get(meshNode) || meshNode.matrix : undefined;
|
|
30
|
+
const inverseMeshMatrix = meshWorldMatrix ? new Matrix4(meshWorldMatrix).invert() : null;
|
|
31
|
+
|
|
32
|
+
for (let jointIndex = 0; jointIndex < matrixCount; jointIndex++) {
|
|
33
|
+
const jointNode = joints[jointIndex];
|
|
34
|
+
const jointWorldMatrix = worldMatrices.get(jointNode) || jointNode.matrix;
|
|
35
|
+
const jointMatrix = inverseMeshMatrix
|
|
36
|
+
? new Matrix4(inverseMeshMatrix).multiplyRight(jointWorldMatrix)
|
|
37
|
+
: new Matrix4(jointWorldMatrix);
|
|
38
|
+
const offset = jointIndex * 16;
|
|
39
|
+
if (inverseBindMatrices && inverseBindMatrices.length >= offset + 16) {
|
|
40
|
+
const inverseBindMatrix = new Matrix4();
|
|
41
|
+
for (let componentIndex = 0; componentIndex < 16; componentIndex++) {
|
|
42
|
+
inverseBindMatrix[componentIndex] = inverseBindMatrices[offset + componentIndex];
|
|
43
|
+
}
|
|
44
|
+
jointMatrix.multiplyRight(inverseBindMatrix);
|
|
45
|
+
}
|
|
46
|
+
jointMatrices.set(jointMatrix, offset);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return jointMatrices;
|
|
50
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// luma.gl
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
|
-
// Copyright (c) vis.gl contributors
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
5
|
import {luma, Device} from '@luma.gl/core';
|
|
6
6
|
import {
|
|
@@ -14,10 +14,10 @@ import {Stats, Stat} from '@probe.gl/stats';
|
|
|
14
14
|
let statIdCounter = 0;
|
|
15
15
|
const ANIMATION_LOOP_STATS = 'Animation Loop';
|
|
16
16
|
|
|
17
|
-
/** Experimental
|
|
17
|
+
/** Experimental 9.4 callback shape for browser or custom animation frames. */
|
|
18
18
|
export type AnimationFrameCallback = (time: DOMHighResTimeStamp, animationFrame?: unknown) => void;
|
|
19
19
|
|
|
20
|
-
/** Experimental
|
|
20
|
+
/** Experimental 9.4 work-in-progress animation frame source. */
|
|
21
21
|
export interface AnimationFrameProvider {
|
|
22
22
|
requestAnimationFrame(callback: AnimationFrameCallback): number;
|
|
23
23
|
cancelAnimationFrame(animationFrameId: number): void;
|
|
@@ -34,6 +34,7 @@ export type AnimationLoopProps = {
|
|
|
34
34
|
|
|
35
35
|
onAddHTML?: (div: HTMLDivElement) => string; // innerHTML
|
|
36
36
|
onInitialize?: (animationProps: AnimationProps) => Promise<unknown>;
|
|
37
|
+
/** Encode a frame. Return false when no GPU work was encoded to skip device submission. */
|
|
37
38
|
onRender?: (animationProps: AnimationProps) => unknown;
|
|
38
39
|
onFinalize?: (animationProps: AnimationProps) => void;
|
|
39
40
|
onError?: (reason: Error) => void;
|
|
@@ -42,14 +43,14 @@ export type AnimationLoopProps = {
|
|
|
42
43
|
|
|
43
44
|
// view parameters - TODO move to CanvasContext?
|
|
44
45
|
autoResizeViewport?: boolean;
|
|
45
|
-
/** Experimental
|
|
46
|
+
/** Experimental 9.4 work-in-progress frame source. */
|
|
46
47
|
animationFrameProvider?: AnimationFrameProvider;
|
|
47
48
|
};
|
|
48
49
|
|
|
49
50
|
export type MutableAnimationLoopProps = {
|
|
50
51
|
// view parameters
|
|
51
52
|
autoResizeViewport?: boolean;
|
|
52
|
-
/** Experimental
|
|
53
|
+
/** Experimental 9.4 work-in-progress frame source. */
|
|
53
54
|
animationFrameProvider?: AnimationFrameProvider;
|
|
54
55
|
};
|
|
55
56
|
|
|
@@ -371,11 +372,11 @@ export class AnimationLoop {
|
|
|
371
372
|
}
|
|
372
373
|
|
|
373
374
|
// call callback
|
|
374
|
-
this.props.onRender(this._getAnimationProps());
|
|
375
|
+
const renderResult = this.props.onRender(this._getAnimationProps());
|
|
375
376
|
// end callback
|
|
376
377
|
|
|
377
378
|
// Submit commands (necessary on WebGPU).
|
|
378
|
-
if (this.device) {
|
|
379
|
+
if (this.device && renderResult !== false) {
|
|
379
380
|
this.device.submit();
|
|
380
381
|
}
|
|
381
382
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// luma.gl
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
|
-
// Copyright (c) vis.gl contributors
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
5
|
import {CanvasContext, Device} from '@luma.gl/core';
|
|
6
6
|
import {Timeline} from '../animation/timeline';
|
|
@@ -29,7 +29,7 @@ export type AnimationProps = {
|
|
|
29
29
|
timeline: Timeline | null;
|
|
30
30
|
|
|
31
31
|
// Experimental
|
|
32
|
-
/** Experimental
|
|
32
|
+
/** Experimental 9.4 work-in-progress frame payload from a custom animation frame provider. */
|
|
33
33
|
animationFrame: unknown | null;
|
|
34
34
|
_mousePosition?: [number, number] | null; // [offsetX, offsetY],
|
|
35
35
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// luma.gl
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
|
-
// Copyright (c) vis.gl contributors
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
5
|
import {luma, Adapter, Device} from '@luma.gl/core';
|
|
6
6
|
import {AnimationLoopTemplate} from './animation-loop-template';
|
|
@@ -18,7 +18,7 @@ export type MakeAnimationLoopProps = Omit<
|
|
|
18
18
|
onAfterRender?: (
|
|
19
19
|
animationProps: AnimationProps,
|
|
20
20
|
animationLoopTemplate: AnimationLoopTemplate | null
|
|
21
|
-
) =>
|
|
21
|
+
) => unknown;
|
|
22
22
|
};
|
|
23
23
|
|
|
24
24
|
/** Animation loop created from a template, with access to the active template instance. */
|
|
@@ -68,9 +68,12 @@ export function makeAnimationLoop(
|
|
|
68
68
|
}
|
|
69
69
|
},
|
|
70
70
|
|
|
71
|
-
onRender(animationProps: AnimationProps):
|
|
72
|
-
renderLoop?.onRender(animationProps);
|
|
73
|
-
props?.onAfterRender?.(animationProps, renderLoop);
|
|
71
|
+
onRender(animationProps: AnimationProps): unknown {
|
|
72
|
+
const renderResult = renderLoop?.onRender(animationProps);
|
|
73
|
+
const afterRenderResult = props?.onAfterRender?.(animationProps, renderLoop);
|
|
74
|
+
return props?.onAfterRender
|
|
75
|
+
? renderResult !== false || afterRenderResult !== false
|
|
76
|
+
: renderResult;
|
|
74
77
|
},
|
|
75
78
|
|
|
76
79
|
onFinalize(animationProps: AnimationProps): void {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// luma.gl
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
|
-
// Copyright (c) vis.gl contributors
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
5
|
import {Device, Buffer, BufferRange, TransformFeedback, RenderPassProps} from '@luma.gl/core';
|
|
6
6
|
import {getPassthroughFS} from '@luma.gl/shadertools';
|
|
@@ -23,7 +23,7 @@ export type BufferTransformProps = Omit<ModelProps, 'fs'> & {
|
|
|
23
23
|
feedbackBufferMode?: 'interleaved' | 'separate';
|
|
24
24
|
/** A list of named outputs corresponding to shader declarations (varyings in WebGL) */
|
|
25
25
|
outputs?: string[];
|
|
26
|
-
/** @deprecated Use run({outputBuffers}) instead - Map of output buffers that the shaders will write results of computations to */
|
|
26
|
+
/** @deprecated Use `run({outputBuffers})` instead - Map of output buffers that the shaders will write results of computations to */
|
|
27
27
|
feedbackBuffers?: Record<string, Buffer | BufferRange>;
|
|
28
28
|
};
|
|
29
29
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// luma.gl
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
|
-
// Copyright (c) vis.gl contributors
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
5
|
import {
|
|
6
6
|
type DeviceFeature,
|
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
PipelineFactory,
|
|
16
16
|
ShaderFactory,
|
|
17
17
|
UniformStore,
|
|
18
|
+
assert,
|
|
18
19
|
log,
|
|
19
20
|
dataTypeDecoder
|
|
20
21
|
} from '@luma.gl/core';
|
|
@@ -24,7 +25,8 @@ import {
|
|
|
24
25
|
type PlatformInfo,
|
|
25
26
|
mergeShaderPluginModules,
|
|
26
27
|
resolveShaderPlugins,
|
|
27
|
-
ShaderAssembler
|
|
28
|
+
ShaderAssembler,
|
|
29
|
+
WGSLShaderAssembler
|
|
28
30
|
} from '@luma.gl/shadertools';
|
|
29
31
|
import {type TypedArray, isNumericArray} from '@math.gl/types';
|
|
30
32
|
import {ShaderInputs} from '../shader-inputs';
|
|
@@ -62,7 +64,7 @@ export type ComputationProps = Omit<ComputePipelineProps, 'shader'> & {
|
|
|
62
64
|
pipelineFactory?: PipelineFactory;
|
|
63
65
|
/** Factory used to create a {@link Shader}. Defaults to {@link Device} default factory. */
|
|
64
66
|
shaderFactory?: ShaderFactory;
|
|
65
|
-
/**
|
|
67
|
+
/** WGSL shader assembler. Defaults to the shared WGSL shader assembler. */
|
|
66
68
|
shaderAssembler?: ShaderAssembler;
|
|
67
69
|
};
|
|
68
70
|
|
|
@@ -91,7 +93,7 @@ export class Computation {
|
|
|
91
93
|
|
|
92
94
|
pipelineFactory: undefined!,
|
|
93
95
|
shaderFactory: undefined!,
|
|
94
|
-
shaderAssembler: ShaderAssembler.getDefaultShaderAssembler(),
|
|
96
|
+
shaderAssembler: ShaderAssembler.getDefaultShaderAssembler('wgsl'),
|
|
95
97
|
|
|
96
98
|
debugShaders: undefined!
|
|
97
99
|
};
|
|
@@ -173,20 +175,32 @@ export class Computation {
|
|
|
173
175
|
props.pipelineFactory || PipelineFactory.getDefaultPipelineFactory(this.device);
|
|
174
176
|
this.shaderFactory = props.shaderFactory || ShaderFactory.getDefaultShaderFactory(this.device);
|
|
175
177
|
|
|
176
|
-
const
|
|
178
|
+
const shaderAssembler = this.props.shaderAssembler;
|
|
179
|
+
// Compute shaders require an assembler with WGSL-specific hooks and binding state.
|
|
180
|
+
assert(shaderAssembler instanceof WGSLShaderAssembler);
|
|
181
|
+
const {
|
|
182
|
+
source,
|
|
183
|
+
getUniforms,
|
|
184
|
+
shaderLayout: assembledShaderLayout
|
|
185
|
+
} = shaderAssembler.assembleWGSLShader({
|
|
177
186
|
platformInfo,
|
|
178
187
|
...this.props,
|
|
179
188
|
modules,
|
|
180
189
|
defines,
|
|
190
|
+
scanVertexAttributes: false,
|
|
181
191
|
pluginInjections: resolvedPlugins.injections
|
|
182
192
|
});
|
|
183
193
|
|
|
184
194
|
this.source = source;
|
|
185
195
|
// @ts-ignore
|
|
186
196
|
this._getModuleUniforms = getUniforms;
|
|
187
|
-
const inferredShaderLayout =
|
|
188
|
-
|
|
189
|
-
|
|
197
|
+
const inferredShaderLayout =
|
|
198
|
+
assembledShaderLayout ??
|
|
199
|
+
(
|
|
200
|
+
device as Device & {
|
|
201
|
+
getShaderLayout?: (source: string, options?: {scanVertexAttributes?: boolean}) => any;
|
|
202
|
+
}
|
|
203
|
+
).getShaderLayout?.(this.source, {scanVertexAttributes: false});
|
|
190
204
|
this.props.shaderLayout =
|
|
191
205
|
mergeShaderModuleBindingsIntoLayout(
|
|
192
206
|
this.props.shaderLayout || inferredShaderLayout || null,
|
package/src/compute/swap.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// luma.gl
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
|
-
// Copyright (c) vis.gl contributors
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
5
|
import type {BufferProps, FramebufferProps} from '@luma.gl/core';
|
|
6
6
|
import {Device, Resource, Buffer, Framebuffer, Texture} from '@luma.gl/core';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// luma.gl
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
|
-
// Copyright (c) vis.gl contributors
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
5
|
import {Buffer, Device, Framebuffer, RenderPassProps, Sampler, Texture} from '@luma.gl/core';
|
|
6
6
|
import {getPassthroughFS} from '@luma.gl/shadertools';
|