@luma.gl/gltf 9.2.5 → 9.3.0-alpha.10
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/dist/dist.dev.js +1362 -313
- package/dist/dist.min.js +98 -46
- package/dist/gltf/animations/animations.d.ts +16 -4
- package/dist/gltf/animations/animations.d.ts.map +1 -1
- package/dist/gltf/animations/interpolate.d.ts +4 -3
- package/dist/gltf/animations/interpolate.d.ts.map +1 -1
- package/dist/gltf/animations/interpolate.js +27 -36
- package/dist/gltf/animations/interpolate.js.map +1 -1
- package/dist/gltf/create-gltf-model.d.ts +15 -1
- package/dist/gltf/create-gltf-model.d.ts.map +1 -1
- package/dist/gltf/create-gltf-model.js +154 -48
- package/dist/gltf/create-gltf-model.js.map +1 -1
- package/dist/gltf/create-scenegraph-from-gltf.d.ts +39 -2
- package/dist/gltf/create-scenegraph-from-gltf.d.ts.map +1 -1
- package/dist/gltf/create-scenegraph-from-gltf.js +76 -6
- package/dist/gltf/create-scenegraph-from-gltf.js.map +1 -1
- package/dist/gltf/gltf-animator.d.ts +26 -0
- package/dist/gltf/gltf-animator.d.ts.map +1 -1
- package/dist/gltf/gltf-animator.js +22 -19
- package/dist/gltf/gltf-animator.js.map +1 -1
- package/dist/gltf/gltf-extension-support.d.ts +10 -0
- package/dist/gltf/gltf-extension-support.d.ts.map +1 -0
- package/dist/gltf/gltf-extension-support.js +173 -0
- package/dist/gltf/gltf-extension-support.js.map +1 -0
- package/dist/index.cjs +1302 -276
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/parsers/parse-gltf-animations.d.ts +1 -0
- package/dist/parsers/parse-gltf-animations.d.ts.map +1 -1
- package/dist/parsers/parse-gltf-animations.js +73 -28
- package/dist/parsers/parse-gltf-animations.js.map +1 -1
- package/dist/parsers/parse-gltf-lights.d.ts +5 -0
- package/dist/parsers/parse-gltf-lights.d.ts.map +1 -0
- package/dist/parsers/parse-gltf-lights.js +163 -0
- package/dist/parsers/parse-gltf-lights.js.map +1 -0
- package/dist/parsers/parse-gltf.d.ts +19 -2
- package/dist/parsers/parse-gltf.d.ts.map +1 -1
- package/dist/parsers/parse-gltf.js +101 -61
- package/dist/parsers/parse-gltf.js.map +1 -1
- package/dist/parsers/parse-pbr-material.d.ts +115 -2
- package/dist/parsers/parse-pbr-material.d.ts.map +1 -1
- package/dist/parsers/parse-pbr-material.js +570 -54
- package/dist/parsers/parse-pbr-material.js.map +1 -1
- package/dist/pbr/pbr-environment.d.ts +10 -4
- package/dist/pbr/pbr-environment.d.ts.map +1 -1
- package/dist/pbr/pbr-environment.js +18 -15
- package/dist/pbr/pbr-environment.js.map +1 -1
- package/dist/pbr/pbr-material.d.ts +13 -3
- package/dist/pbr/pbr-material.d.ts.map +1 -1
- package/dist/webgl-to-webgpu/convert-webgl-attribute.d.ts +12 -1
- package/dist/webgl-to-webgpu/convert-webgl-attribute.d.ts.map +1 -1
- package/dist/webgl-to-webgpu/convert-webgl-attribute.js +3 -0
- package/dist/webgl-to-webgpu/convert-webgl-attribute.js.map +1 -1
- package/dist/webgl-to-webgpu/convert-webgl-sampler.d.ts +11 -5
- package/dist/webgl-to-webgpu/convert-webgl-sampler.d.ts.map +1 -1
- package/dist/webgl-to-webgpu/convert-webgl-sampler.js +16 -12
- package/dist/webgl-to-webgpu/convert-webgl-sampler.js.map +1 -1
- package/dist/webgl-to-webgpu/convert-webgl-topology.d.ts +2 -9
- package/dist/webgl-to-webgpu/convert-webgl-topology.d.ts.map +1 -1
- package/dist/webgl-to-webgpu/convert-webgl-topology.js +2 -14
- package/dist/webgl-to-webgpu/convert-webgl-topology.js.map +1 -1
- package/dist/webgl-to-webgpu/gltf-webgl-constants.d.ts +27 -0
- package/dist/webgl-to-webgpu/gltf-webgl-constants.d.ts.map +1 -0
- package/dist/webgl-to-webgpu/gltf-webgl-constants.js +34 -0
- package/dist/webgl-to-webgpu/gltf-webgl-constants.js.map +1 -0
- package/package.json +8 -9
- package/src/gltf/animations/animations.ts +17 -5
- package/src/gltf/animations/interpolate.ts +49 -68
- package/src/gltf/create-gltf-model.ts +214 -48
- package/src/gltf/create-scenegraph-from-gltf.ts +134 -11
- package/src/gltf/gltf-animator.ts +34 -25
- package/src/gltf/gltf-extension-support.ts +214 -0
- package/src/index.ts +11 -2
- package/src/parsers/parse-gltf-animations.ts +94 -33
- package/src/parsers/parse-gltf-lights.ts +218 -0
- package/src/parsers/parse-gltf.ts +170 -90
- package/src/parsers/parse-pbr-material.ts +870 -80
- package/src/pbr/pbr-environment.ts +44 -21
- package/src/pbr/pbr-material.ts +18 -3
- package/src/webgl-to-webgpu/convert-webgl-attribute.ts +12 -1
- package/src/webgl-to-webgpu/convert-webgl-sampler.ts +38 -29
- package/src/webgl-to-webgpu/convert-webgl-topology.ts +2 -14
- package/src/webgl-to-webgpu/gltf-webgl-constants.ts +35 -0
- package/dist/utils/deep-copy.d.ts +0 -3
- package/dist/utils/deep-copy.d.ts.map +0 -1
- package/dist/utils/deep-copy.js +0 -21
- package/dist/utils/deep-copy.js.map +0 -1
- package/src/utils/deep-copy.ts +0 -22
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interpolate.js","sourceRoot":"","sources":["../../../src/gltf/animations/interpolate.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"interpolate.js","sourceRoot":"","sources":["../../../src/gltf/animations/interpolate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,EAAC,MAAM,eAAe,CAAC;AAClC,OAAO,EAAC,UAAU,EAAC,MAAM,eAAe,CAAC;AAIzC,iEAAiE;AACjE,SAAS,gBAAgB,CACvB,MAAiB,EACjB,IAAuB,EACvB,QAAkB;IAElB,QAAQ,IAAI,EAAE,CAAC;QACb,KAAK,aAAa;YAChB,OAAO,MAAM,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC,YAAY,E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CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;gBAClD,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC;IAC3C,CAAC;IACD,gBAAgB,CAAC,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;AACzC,CAAC;AAED,wEAAwE;AACxE,SAAS,eAAe,CAAC,MAAiB,EAAE,IAAuB,EAAE,KAAe;IAClF,gBAAgB,CAAC,MAAM,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;AACxC,CAAC"}
|
|
@@ -1,13 +1,27 @@
|
|
|
1
1
|
import { Device } from '@luma.gl/core';
|
|
2
|
-
import { Geometry, ModelNode, type ModelProps } from '@luma.gl/engine';
|
|
2
|
+
import { Geometry, Material, MaterialFactory, ModelNode, type ModelProps } from '@luma.gl/engine';
|
|
3
3
|
import { type ParsedPBRMaterial } from "../pbr/pbr-material.js";
|
|
4
|
+
/** Options used to instantiate a `ModelNode` for one glTF primitive. */
|
|
4
5
|
export type CreateGLTFModelOptions = {
|
|
6
|
+
/** Optional id assigned to the generated model. */
|
|
5
7
|
id?: string;
|
|
8
|
+
/** Vertex count override for non-indexed primitives. */
|
|
6
9
|
vertexCount?: number;
|
|
10
|
+
/** Geometry converted from the glTF primitive. */
|
|
7
11
|
geometry: Geometry;
|
|
12
|
+
/** Parsed PBR material state for the primitive. */
|
|
8
13
|
parsedPPBRMaterial: ParsedPBRMaterial;
|
|
14
|
+
/** Pre-created material aligned with the source glTF material entry, when available. */
|
|
15
|
+
material?: Material | null;
|
|
16
|
+
/** Additional model props merged into the generated model. */
|
|
9
17
|
modelOptions?: Partial<ModelProps>;
|
|
10
18
|
};
|
|
19
|
+
export type CreateGLTFMaterialOptions = {
|
|
20
|
+
id?: string;
|
|
21
|
+
parsedPPBRMaterial: ParsedPBRMaterial;
|
|
22
|
+
materialFactory?: MaterialFactory;
|
|
23
|
+
};
|
|
24
|
+
export declare function createGLTFMaterial(device: Device, options: CreateGLTFMaterialOptions): Material;
|
|
11
25
|
/** Creates a luma.gl Model from GLTF data*/
|
|
12
26
|
export declare function createGLTFModel(device: Device, options: CreateGLTFModelOptions): ModelNode;
|
|
13
27
|
//# sourceMappingURL=create-gltf-model.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-gltf-model.d.ts","sourceRoot":"","sources":["../../src/gltf/create-gltf-model.ts"],"names":[],"mappings":"AAIA,OAAO,
|
|
1
|
+
{"version":3,"file":"create-gltf-model.d.ts","sourceRoot":"","sources":["../../src/gltf/create-gltf-model.ts"],"names":[],"mappings":"AAIA,OAAO,EAEL,MAAM,EAOP,MAAM,eAAe,CAAC;AAGvB,OAAO,EACL,QAAQ,EACR,QAAQ,EACR,eAAe,EAEf,SAAS,EACT,KAAK,UAAU,EAChB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAC,KAAK,iBAAiB,EAAC,+BAA4B;AA2J3D,wEAAwE;AACxE,MAAM,MAAM,sBAAsB,GAAG;IACnC,mDAAmD;IACnD,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,wDAAwD;IACxD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,kDAAkD;IAClD,QAAQ,EAAE,QAAQ,CAAC;IACnB,mDAAmD;IACnD,kBAAkB,EAAE,iBAAiB,CAAC;IACtC,wFAAwF;IACxF,QAAQ,CAAC,EAAE,QAAQ,GAAG,IAAI,CAAC;IAC3B,8DAA8D;IAC9D,YAAY,CAAC,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC;CACpC,CAAC;AAEF,MAAM,MAAM,yBAAyB,GAAG;IACtC,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,kBAAkB,EAAE,iBAAiB,CAAC;IACtC,eAAe,CAAC,EAAE,eAAe,CAAC;CACnC,CAAC;AAEF,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,yBAAyB,GAAG,QAAQ,CAsB/F;AAED,4CAA4C;AAC5C,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,sBAAsB,GAAG,SAAS,CAyD1F"}
|
|
@@ -1,54 +1,93 @@
|
|
|
1
1
|
// luma.gl
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
|
-
import { log } from '@luma.gl/core';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
4
|
+
import { Buffer, Sampler, Texture, TextureView, log } from '@luma.gl/core';
|
|
5
|
+
import { DynamicTexture } from '@luma.gl/engine';
|
|
6
|
+
import { pbrMaterial, skin } from '@luma.gl/shadertools';
|
|
7
|
+
import { MaterialFactory, Model, ModelNode } from '@luma.gl/engine';
|
|
7
8
|
const SHADER = /* WGSL */ `
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
9
|
+
struct VertexInputs {
|
|
10
|
+
@location(0) positions: vec3f,
|
|
11
|
+
#ifdef HAS_NORMALS
|
|
12
|
+
@location(1) normals: vec3f,
|
|
13
|
+
#endif
|
|
14
|
+
#ifdef HAS_TANGENTS
|
|
15
|
+
@location(2) TANGENT: vec4f,
|
|
16
|
+
#endif
|
|
17
|
+
#ifdef HAS_UV
|
|
18
|
+
@location(3) texCoords: vec2f,
|
|
19
|
+
#endif
|
|
20
|
+
#ifdef HAS_SKIN
|
|
21
|
+
@location(4) JOINTS_0: vec4u,
|
|
22
|
+
@location(5) WEIGHTS_0: vec4f,
|
|
23
|
+
#endif
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
struct FragmentInputs {
|
|
27
|
+
@builtin(position) position: vec4f,
|
|
28
|
+
@location(0) pbrPosition: vec3f,
|
|
29
|
+
@location(1) pbrUV: vec2f,
|
|
30
|
+
@location(2) pbrNormal: vec3f,
|
|
31
|
+
#ifdef HAS_TANGENTS
|
|
32
|
+
@location(3) pbrTangent: vec4f,
|
|
33
|
+
#endif
|
|
34
|
+
};
|
|
22
35
|
|
|
23
36
|
@vertex
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
37
|
+
fn vertexMain(inputs: VertexInputs) -> FragmentInputs {
|
|
38
|
+
var outputs: FragmentInputs;
|
|
39
|
+
var position = vec4f(inputs.positions, 1.0);
|
|
40
|
+
var normal = vec3f(0.0, 0.0, 1.0);
|
|
41
|
+
var tangent = vec4f(1.0, 0.0, 0.0, 1.0);
|
|
42
|
+
var uv = vec2f(0.0, 0.0);
|
|
43
|
+
|
|
44
|
+
#ifdef HAS_NORMALS
|
|
45
|
+
normal = inputs.normals;
|
|
46
|
+
#endif
|
|
47
|
+
#ifdef HAS_UV
|
|
48
|
+
uv = inputs.texCoords;
|
|
49
|
+
#endif
|
|
50
|
+
#ifdef HAS_TANGENTS
|
|
51
|
+
tangent = inputs.TANGENT;
|
|
52
|
+
#endif
|
|
53
|
+
#ifdef HAS_SKIN
|
|
54
|
+
let skinMatrix = getSkinMatrix(inputs.WEIGHTS_0, inputs.JOINTS_0);
|
|
55
|
+
position = skinMatrix * position;
|
|
56
|
+
normal = normalize((skinMatrix * vec4f(normal, 0.0)).xyz);
|
|
57
|
+
#ifdef HAS_TANGENTS
|
|
58
|
+
tangent = vec4f(normalize((skinMatrix * vec4f(tangent.xyz, 0.0)).xyz), tangent.w);
|
|
59
|
+
#endif
|
|
60
|
+
#endif
|
|
61
|
+
|
|
62
|
+
let worldPosition = pbrProjection.modelMatrix * position;
|
|
63
|
+
|
|
64
|
+
#ifdef HAS_NORMALS
|
|
65
|
+
normal = normalize((pbrProjection.normalMatrix * vec4f(normal, 0.0)).xyz);
|
|
66
|
+
#endif
|
|
67
|
+
#ifdef HAS_TANGENTS
|
|
68
|
+
let worldTangent = normalize((pbrProjection.modelMatrix * vec4f(tangent.xyz, 0.0)).xyz);
|
|
69
|
+
outputs.pbrTangent = vec4f(worldTangent, tangent.w);
|
|
70
|
+
#endif
|
|
71
|
+
|
|
72
|
+
outputs.position = pbrProjection.modelViewProjectionMatrix * position;
|
|
73
|
+
outputs.pbrPosition = worldPosition.xyz / worldPosition.w;
|
|
74
|
+
outputs.pbrUV = uv;
|
|
75
|
+
outputs.pbrNormal = normal;
|
|
76
|
+
return outputs;
|
|
77
|
+
}
|
|
44
78
|
|
|
45
79
|
@fragment
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
80
|
+
fn fragmentMain(inputs: FragmentInputs) -> @location(0) vec4f {
|
|
81
|
+
fragmentInputs.pbr_vPosition = inputs.pbrPosition;
|
|
82
|
+
fragmentInputs.pbr_vUV = inputs.pbrUV;
|
|
83
|
+
fragmentInputs.pbr_vNormal = inputs.pbrNormal;
|
|
84
|
+
#ifdef HAS_TANGENTS
|
|
85
|
+
let tangent = normalize(inputs.pbrTangent.xyz);
|
|
86
|
+
let bitangent = normalize(cross(inputs.pbrNormal, tangent)) * inputs.pbrTangent.w;
|
|
87
|
+
fragmentInputs.pbr_vTBN = mat3x3f(tangent, bitangent, inputs.pbrNormal);
|
|
88
|
+
#endif
|
|
89
|
+
return pbr_filterColor(vec4f(1.0));
|
|
90
|
+
}
|
|
52
91
|
`;
|
|
53
92
|
// TODO rename attributes to POSITION/NORMAL etc
|
|
54
93
|
// See gpu-geometry.ts: getAttributeBuffersFromGeometry()
|
|
@@ -72,6 +111,11 @@ const vs = /* glsl */ `\
|
|
|
72
111
|
in vec2 texCoords;
|
|
73
112
|
#endif
|
|
74
113
|
|
|
114
|
+
#ifdef HAS_SKIN
|
|
115
|
+
in uvec4 JOINTS_0;
|
|
116
|
+
in vec4 WEIGHTS_0;
|
|
117
|
+
#endif
|
|
118
|
+
|
|
75
119
|
void main(void) {
|
|
76
120
|
vec4 _NORMAL = vec4(0.);
|
|
77
121
|
vec4 _TANGENT = vec4(0.);
|
|
@@ -89,8 +133,17 @@ const vs = /* glsl */ `\
|
|
|
89
133
|
_TEXCOORD_0 = texCoords;
|
|
90
134
|
#endif
|
|
91
135
|
|
|
92
|
-
|
|
93
|
-
|
|
136
|
+
vec4 pos = positions;
|
|
137
|
+
|
|
138
|
+
#ifdef HAS_SKIN
|
|
139
|
+
mat4 skinMat = getSkinMatrix(WEIGHTS_0, JOINTS_0);
|
|
140
|
+
pos = skinMat * pos;
|
|
141
|
+
_NORMAL = skinMat * _NORMAL;
|
|
142
|
+
_TANGENT = vec4((skinMat * vec4(_TANGENT.xyz, 0.)).xyz, _TANGENT.w);
|
|
143
|
+
#endif
|
|
144
|
+
|
|
145
|
+
pbr_setPositionNormalTangentUV(pos, _NORMAL, _TANGENT, _TEXCOORD_0);
|
|
146
|
+
gl_Position = pbrProjection.modelViewProjectionMatrix * pos;
|
|
94
147
|
}
|
|
95
148
|
`;
|
|
96
149
|
const fs = /* glsl */ `\
|
|
@@ -102,6 +155,21 @@ const fs = /* glsl */ `\
|
|
|
102
155
|
fragmentColor = pbr_filterColor(vec4(1.0));
|
|
103
156
|
}
|
|
104
157
|
`;
|
|
158
|
+
export function createGLTFMaterial(device, options) {
|
|
159
|
+
const materialFactory = options.materialFactory || new MaterialFactory(device, { modules: [pbrMaterial] });
|
|
160
|
+
const pbrMaterialProps = { ...options.parsedPPBRMaterial.uniforms };
|
|
161
|
+
delete pbrMaterialProps.camera;
|
|
162
|
+
const materialBindings = Object.fromEntries(Object.entries({
|
|
163
|
+
...pbrMaterialProps,
|
|
164
|
+
...options.parsedPPBRMaterial.bindings
|
|
165
|
+
}).filter(([name, value]) => materialFactory.ownsBinding(name) && isMaterialBindingResource(value)));
|
|
166
|
+
const material = materialFactory.createMaterial({
|
|
167
|
+
id: options.id,
|
|
168
|
+
bindings: materialBindings
|
|
169
|
+
});
|
|
170
|
+
material.setProps({ pbrMaterial: pbrMaterialProps });
|
|
171
|
+
return material;
|
|
172
|
+
}
|
|
105
173
|
/** Creates a luma.gl Model from GLTF data*/
|
|
106
174
|
export function createGLTFModel(device, options) {
|
|
107
175
|
const { id, geometry, parsedPPBRMaterial, vertexCount, modelOptions = {} } = options;
|
|
@@ -126,19 +194,57 @@ export function createGLTFModel(device, options) {
|
|
|
126
194
|
geometry,
|
|
127
195
|
topology: geometry.topology,
|
|
128
196
|
vertexCount,
|
|
129
|
-
modules: [pbrMaterial],
|
|
197
|
+
modules: [pbrMaterial, skin],
|
|
130
198
|
...modelOptions,
|
|
131
199
|
defines: { ...parsedPPBRMaterial.defines, ...modelOptions.defines },
|
|
132
200
|
parameters: { ...parameters, ...parsedPPBRMaterial.parameters, ...modelOptions.parameters }
|
|
133
201
|
};
|
|
202
|
+
const material = options.material ||
|
|
203
|
+
createGLTFMaterial(device, {
|
|
204
|
+
id: id ? `${id}-material` : undefined,
|
|
205
|
+
parsedPPBRMaterial
|
|
206
|
+
});
|
|
207
|
+
modelProps.material = material;
|
|
134
208
|
const model = new Model(device, modelProps);
|
|
135
|
-
const
|
|
209
|
+
const sceneShaderInputValues = {
|
|
136
210
|
...parsedPPBRMaterial.uniforms,
|
|
137
211
|
...modelOptions.uniforms,
|
|
138
212
|
...parsedPPBRMaterial.bindings,
|
|
139
213
|
...modelOptions.bindings
|
|
140
214
|
};
|
|
141
|
-
model.shaderInputs.
|
|
215
|
+
const sceneShaderInputProps = getSceneShaderInputProps(model.shaderInputs.getModules(), material, sceneShaderInputValues);
|
|
216
|
+
model.shaderInputs.setProps(sceneShaderInputProps);
|
|
142
217
|
return new ModelNode({ managedResources, model });
|
|
143
218
|
}
|
|
219
|
+
function isMaterialBindingResource(value) {
|
|
220
|
+
return (value instanceof Buffer ||
|
|
221
|
+
value instanceof DynamicTexture ||
|
|
222
|
+
value instanceof Sampler ||
|
|
223
|
+
value instanceof Texture ||
|
|
224
|
+
value instanceof TextureView);
|
|
225
|
+
}
|
|
226
|
+
function getSceneShaderInputProps(modules, material, shaderInputValues) {
|
|
227
|
+
const propertyToModuleNameMap = new Map();
|
|
228
|
+
for (const module of modules) {
|
|
229
|
+
for (const uniformName of Object.keys(module.uniformTypes || {})) {
|
|
230
|
+
propertyToModuleNameMap.set(uniformName, module.name);
|
|
231
|
+
}
|
|
232
|
+
for (const binding of module.bindingLayout || []) {
|
|
233
|
+
propertyToModuleNameMap.set(binding.name, module.name);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
const sceneShaderInputProps = {};
|
|
237
|
+
for (const [propertyName, value] of Object.entries(shaderInputValues)) {
|
|
238
|
+
if (value === undefined) {
|
|
239
|
+
continue;
|
|
240
|
+
}
|
|
241
|
+
const moduleName = propertyToModuleNameMap.get(propertyName);
|
|
242
|
+
if (!moduleName || material.ownsModule(moduleName)) {
|
|
243
|
+
continue;
|
|
244
|
+
}
|
|
245
|
+
sceneShaderInputProps[moduleName] ||= {};
|
|
246
|
+
sceneShaderInputProps[moduleName][propertyName] = value;
|
|
247
|
+
}
|
|
248
|
+
return sceneShaderInputProps;
|
|
249
|
+
}
|
|
144
250
|
//# sourceMappingURL=create-gltf-model.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-gltf-model.js","sourceRoot":"","sources":["../../src/gltf/create-gltf-model.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAEpC,OAAO,
|
|
1
|
+
{"version":3,"file":"create-gltf-model.js","sour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M,CAAC,YAAY,IAAI,EAAE,CAAC,EAAE,CAAC;YACjE,uBAAuB,CAAC,GAAG,CAAC,WAAW,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC;QACxD,CAAC;QACD,KAAK,MAAM,OAAO,IAAI,MAAM,CAAC,aAAa,IAAI,EAAE,EAAE,CAAC;YACjD,uBAAuB,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC;QACzD,CAAC;IACH,CAAC;IAED,MAAM,qBAAqB,GAA4C,EAAE,CAAC;IAC1E,KAAK,MAAM,CAAC,YAAY,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,iBAAiB,CAAC,EAAE,CAAC;QACtE,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YACxB,SAAS;QACX,CAAC;QAED,MAAM,UAAU,GAAG,uBAAuB,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;QAC7D,IAAI,CAAC,UAAU,IAAI,QAAQ,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;YACnD,SAAS;QACX,CAAC;QAED,qBAAqB,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC;QACzC,qBAAqB,CAAC,UAAU,CAAC,CAAC,YAAY,CAAC,GAAG,KAAK,CAAC;IAC1D,CAAC;IAED,OAAO,qBAAqB,CAAC;AAC/B,CAAC"}
|
|
@@ -1,10 +1,47 @@
|
|
|
1
1
|
import { Device } from '@luma.gl/core';
|
|
2
|
-
import { GroupNode } from '@luma.gl/engine';
|
|
2
|
+
import { GroupNode, Material } from '@luma.gl/engine';
|
|
3
3
|
import { GLTFPostprocessed } from '@loaders.gl/gltf';
|
|
4
|
+
import { Light } from '@luma.gl/shadertools';
|
|
4
5
|
import { type ParseGLTFOptions } from "../parsers/parse-gltf.js";
|
|
5
6
|
import { GLTFAnimator } from "./gltf-animator.js";
|
|
6
|
-
|
|
7
|
+
import { type GLTFExtensionSupport } from "./gltf-extension-support.js";
|
|
8
|
+
export type GLTFScenegraphBounds = {
|
|
9
|
+
/** World-space axis-aligned bounds for the scene or model. */
|
|
10
|
+
bounds: [[number, number, number], [number, number, number]] | null;
|
|
11
|
+
/** World-space center of the bounds. */
|
|
12
|
+
center: [number, number, number];
|
|
13
|
+
/** World-space bounds size on each axis. */
|
|
14
|
+
size: [number, number, number];
|
|
15
|
+
/** Half of the world-space bounds diagonal, clamped to a small practical minimum. */
|
|
16
|
+
radius: number;
|
|
17
|
+
/** Suggested orbit distance for a 60-degree field of view camera. */
|
|
18
|
+
recommendedOrbitDistance: number;
|
|
19
|
+
};
|
|
20
|
+
/** Scenegraph bundle returned from a parsed glTF asset. */
|
|
21
|
+
export type GLTFScenegraphs = {
|
|
22
|
+
/** Scene roots produced from the glTF scenes array. */
|
|
7
23
|
scenes: GroupNode[];
|
|
24
|
+
/** Materials aligned with the source glTF `materials` array. */
|
|
25
|
+
materials: Material[];
|
|
26
|
+
/** Animation controller for glTF animations. */
|
|
8
27
|
animator: GLTFAnimator;
|
|
28
|
+
/** Parsed punctual lights from the asset. */
|
|
29
|
+
lights: Light[];
|
|
30
|
+
/** Extensions reported by the asset and whether luma.gl supports them. */
|
|
31
|
+
extensionSupport: Map<string, GLTFExtensionSupport>;
|
|
32
|
+
/** Camera-friendly bounds for each scene in `scenes`, in matching order. */
|
|
33
|
+
sceneBounds: GLTFScenegraphBounds[];
|
|
34
|
+
/** Combined camera-friendly bounds for the entire loaded asset. */
|
|
35
|
+
modelBounds: GLTFScenegraphBounds;
|
|
36
|
+
/** Map from glTF mesh ids to generated mesh group nodes. */
|
|
37
|
+
gltfMeshIdToNodeMap: Map<string, GroupNode>;
|
|
38
|
+
/** Map from glTF node indices to generated scenegraph nodes. */
|
|
39
|
+
gltfNodeIndexToNodeMap: Map<number, GroupNode>;
|
|
40
|
+
/** Map from glTF node ids to generated scenegraph nodes. */
|
|
41
|
+
gltfNodeIdToNodeMap: Map<string, GroupNode>;
|
|
42
|
+
/** Original post-processed glTF document. */
|
|
43
|
+
gltf: GLTFPostprocessed;
|
|
9
44
|
};
|
|
45
|
+
/** Converts a post-processed glTF asset into luma.gl scenegraph nodes and animation helpers. */
|
|
46
|
+
export declare function createScenegraphsFromGLTF(device: Device, gltf: GLTFPostprocessed, options?: ParseGLTFOptions): GLTFScenegraphs;
|
|
10
47
|
//# sourceMappingURL=create-scenegraph-from-gltf.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-scenegraph-from-gltf.d.ts","sourceRoot":"","sources":["../../src/gltf/create-scenegraph-from-gltf.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,MAAM,EAAC,MAAM,eAAe,CAAC;AACrC,OAAO,EAAC,SAAS,EAAC,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"create-scenegraph-from-gltf.d.ts","sourceRoot":"","sources":["../../src/gltf/create-scenegraph-from-gltf.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,MAAM,EAAC,MAAM,eAAe,CAAC;AACrC,OAAO,EAAC,SAAS,EAAE,QAAQ,EAAC,MAAM,iBAAiB,CAAC;AACpD,OAAO,EAAC,iBAAiB,EAAC,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAC,KAAK,EAAC,MAAM,sBAAsB,CAAC;AAC3C,OAAO,EAAY,KAAK,gBAAgB,EAAC,iCAA8B;AAEvE,OAAO,EAAC,YAAY,EAAC,2BAAwB;AAE7C,OAAO,EAA0B,KAAK,oBAAoB,EAAC,oCAAiC;AAE5F,MAAM,MAAM,oBAAoB,GAAG;IACjC,8DAA8D;IAC9D,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,GAAG,IAAI,CAAC;IACpE,wCAAwC;IACxC,MAAM,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,4CAA4C;IAC5C,IAAI,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/B,qFAAqF;IACrF,MAAM,EAAE,MAAM,CAAC;IACf,qEAAqE;IACrE,wBAAwB,EAAE,MAAM,CAAC;CAClC,CAAC;AAEF,2DAA2D;AAC3D,MAAM,MAAM,eAAe,GAAG;IAC5B,uDAAuD;IACvD,MAAM,EAAE,SAAS,EAAE,CAAC;IACpB,gEAAgE;IAChE,SAAS,EAAE,QAAQ,EAAE,CAAC;IACtB,gDAAgD;IAChD,QAAQ,EAAE,YAAY,CAAC;IACvB,6CAA6C;IAC7C,MAAM,EAAE,KAAK,EAAE,CAAC;IAChB,0EAA0E;IAC1E,gBAAgB,EAAE,GAAG,CAAC,MAAM,EAAE,oBAAoB,CAAC,CAAC;IACpD,4EAA4E;IAC5E,WAAW,EAAE,oBAAoB,EAAE,CAAC;IACpC,mEAAmE;IACnE,WAAW,EAAE,oBAAoB,CAAC;IAElC,4DAA4D;IAC5D,mBAAmB,EAAE,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IAC5C,gEAAgE;IAChE,sBAAsB,EAAE,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IAC/C,4DAA4D;IAC5D,mBAAmB,EAAE,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IAE5C,6CAA6C;IAC7C,IAAI,EAAE,iBAAiB,CAAC;CACzB,CAAC;AAEF,gGAAgG;AAChG,wBAAgB,yBAAyB,CACvC,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,iBAAiB,EACvB,OAAO,CAAC,EAAE,gBAAgB,GACzB,eAAe,CAwBjB"}
|
|
@@ -2,15 +2,85 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
import { parseGLTF } from "../parsers/parse-gltf.js";
|
|
5
|
+
import { parseGLTFLights } from "../parsers/parse-gltf-lights.js";
|
|
5
6
|
import { GLTFAnimator } from "./gltf-animator.js";
|
|
6
7
|
import { parseGLTFAnimations } from "../parsers/parse-gltf-animations.js";
|
|
7
|
-
import {
|
|
8
|
+
import { getGLTFExtensionSupport } from "./gltf-extension-support.js";
|
|
9
|
+
/** Converts a post-processed glTF asset into luma.gl scenegraph nodes and animation helpers. */
|
|
8
10
|
export function createScenegraphsFromGLTF(device, gltf, options) {
|
|
9
|
-
|
|
10
|
-
const scenes = parseGLTF(device, gltf, options);
|
|
11
|
-
// Note: There is a nasty dependency on injected nodes in the glTF
|
|
11
|
+
const { scenes, materials, gltfMeshIdToNodeMap, gltfNodeIdToNodeMap, gltfNodeIndexToNodeMap } = parseGLTF(device, gltf, options);
|
|
12
12
|
const animations = parseGLTFAnimations(gltf);
|
|
13
|
-
const animator = new GLTFAnimator({ animations });
|
|
14
|
-
|
|
13
|
+
const animator = new GLTFAnimator({ animations, gltfNodeIdToNodeMap });
|
|
14
|
+
const lights = parseGLTFLights(gltf);
|
|
15
|
+
const extensionSupport = getGLTFExtensionSupport(gltf);
|
|
16
|
+
const sceneBounds = scenes.map(scene => getScenegraphBounds(scene.getBounds()));
|
|
17
|
+
const modelBounds = getCombinedScenegraphBounds(sceneBounds);
|
|
18
|
+
return {
|
|
19
|
+
scenes,
|
|
20
|
+
materials,
|
|
21
|
+
animator,
|
|
22
|
+
lights,
|
|
23
|
+
extensionSupport,
|
|
24
|
+
sceneBounds,
|
|
25
|
+
modelBounds,
|
|
26
|
+
gltfMeshIdToNodeMap,
|
|
27
|
+
gltfNodeIdToNodeMap,
|
|
28
|
+
gltfNodeIndexToNodeMap,
|
|
29
|
+
gltf
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
function getScenegraphBounds(bounds) {
|
|
33
|
+
if (!bounds) {
|
|
34
|
+
return {
|
|
35
|
+
bounds: null,
|
|
36
|
+
center: [0, 0, 0],
|
|
37
|
+
size: [0, 0, 0],
|
|
38
|
+
radius: 0.5,
|
|
39
|
+
recommendedOrbitDistance: 1
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
const normalizedBounds = [
|
|
43
|
+
[bounds[0][0], bounds[0][1], bounds[0][2]],
|
|
44
|
+
[bounds[1][0], bounds[1][1], bounds[1][2]]
|
|
45
|
+
];
|
|
46
|
+
const size = [
|
|
47
|
+
normalizedBounds[1][0] - normalizedBounds[0][0],
|
|
48
|
+
normalizedBounds[1][1] - normalizedBounds[0][1],
|
|
49
|
+
normalizedBounds[1][2] - normalizedBounds[0][2]
|
|
50
|
+
];
|
|
51
|
+
const center = [
|
|
52
|
+
normalizedBounds[0][0] + size[0] * 0.5,
|
|
53
|
+
normalizedBounds[0][1] + size[1] * 0.5,
|
|
54
|
+
normalizedBounds[0][2] + size[2] * 0.5
|
|
55
|
+
];
|
|
56
|
+
const maxHalfExtent = Math.max(size[0], size[1], size[2]) * 0.5;
|
|
57
|
+
const radius = Math.max(0.5 * Math.hypot(size[0], size[1], size[2]), 0.001);
|
|
58
|
+
return {
|
|
59
|
+
bounds: normalizedBounds,
|
|
60
|
+
center,
|
|
61
|
+
size,
|
|
62
|
+
radius,
|
|
63
|
+
recommendedOrbitDistance: Math.max((Math.max(maxHalfExtent, 0.001) / Math.tan(Math.PI / 6)) * 1.15, radius * 1.1)
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
function getCombinedScenegraphBounds(sceneBounds) {
|
|
67
|
+
let combinedBounds = null;
|
|
68
|
+
for (const sceneBoundInfo of sceneBounds) {
|
|
69
|
+
if (!sceneBoundInfo.bounds) {
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
if (!combinedBounds) {
|
|
73
|
+
combinedBounds = [
|
|
74
|
+
[...sceneBoundInfo.bounds[0]],
|
|
75
|
+
[...sceneBoundInfo.bounds[1]]
|
|
76
|
+
];
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
for (let axis = 0; axis < 3; axis++) {
|
|
80
|
+
combinedBounds[0][axis] = Math.min(combinedBounds[0][axis], sceneBoundInfo.bounds[0][axis]);
|
|
81
|
+
combinedBounds[1][axis] = Math.max(combinedBounds[1][axis], sceneBoundInfo.bounds[1][axis]);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return getScenegraphBounds(combinedBounds);
|
|
15
85
|
}
|
|
16
86
|
//# sourceMappingURL=create-scenegraph-from-gltf.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-scenegraph-from-gltf.js","sourceRoot":"","sources":["../../src/gltf/create-scenegraph-from-gltf.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;
|
|
1
|
+
{"version":3,"file":"create-scenegraph-from-gltf.js","sourceRoot":"","sources":["../../src/gltf/create-scenegraph-from-gltf.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAMpC,OAAO,EAAC,SAAS,EAAwB,iCAA8B;AACvE,OAAO,EAAC,eAAe,EAAC,wCAAqC;AAC7D,OAAO,EAAC,YAAY,EAAC,2BAAwB;AAC7C,OAAO,EAAC,mBAAmB,EAAC,4CAAyC;AACrE,OAAO,EAAC,uBAAuB,EAA4B,oCAAiC;AA2C5F,gGAAgG;AAChG,MAAM,UAAU,yBAAyB,CACvC,MAAc,EACd,IAAuB,EACvB,OAA0B;IAE1B,MAAM,EAAC,MAAM,EAAE,SAAS,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,sBAAsB,EAAC,GACzF,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;IAEnC,MAAM,UAAU,GAAG,mBAAmB,CAAC,IAAI,CAAC,CAAC;IAC7C,MAAM,QAAQ,GAAG,IAAI,YAAY,CAAC,EAAC,UAAU,EAAE,mBAAmB,EAAC,CAAC,CAAC;IACrE,MAAM,MAAM,GAAG,eAAe,CAAC,IAAI,CAAC,CAAC;IACrC,MAAM,gBAAgB,GAAG,uBAAuB,CAAC,IAAI,CAAC,CAAC;IACvD,MAAM,WA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AM,EAAE,CAAC;YAC3B,SAAS;QACX,CAAC;QAED,IAAI,CAAC,cAAc,EAAE,CAAC;YACpB,cAAc,GAAG;gBACf,CAAC,GAAG,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC,CAA6B;gBACzD,CAAC,GAAG,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC,CAA6B;aAC1D,CAAC;YACF,SAAS;QACX,CAAC;QAED,KAAK,IAAI,IAAI,GAAG,CAAC,EAAE,IAAI,GAAG,CAAC,EAAE,IAAI,EAAE,EAAE,CAAC;YACpC,cAAc,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;YAC5F,cAAc,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;QAC9F,CAAC;IACH,CAAC;IAED,OAAO,mBAAmB,CAAC,cAAc,CAAC,CAAC;AAC7C,CAAC"}
|
|
@@ -1,27 +1,53 @@
|
|
|
1
|
+
import { GroupNode } from '@luma.gl/engine';
|
|
1
2
|
import { GLTFAnimation } from "./animations/animations.js";
|
|
3
|
+
/** Construction props for a single glTF animation controller. */
|
|
2
4
|
type GLTFSingleAnimatorProps = {
|
|
5
|
+
/** Animation data to evaluate. */
|
|
3
6
|
animation: GLTFAnimation;
|
|
7
|
+
/** Mapping from glTF node ids to scenegraph nodes. */
|
|
8
|
+
gltfNodeIdToNodeMap: Map<string, GroupNode>;
|
|
9
|
+
/** Start time in seconds. */
|
|
4
10
|
startTime?: number;
|
|
11
|
+
/** Whether playback is active. */
|
|
5
12
|
playing?: boolean;
|
|
13
|
+
/** Playback speed multiplier. */
|
|
6
14
|
speed?: number;
|
|
7
15
|
};
|
|
16
|
+
/** Evaluates one glTF animation against the generated scenegraph. */
|
|
8
17
|
declare class GLTFSingleAnimator {
|
|
18
|
+
/** Animation definition being played. */
|
|
9
19
|
animation: GLTFAnimation;
|
|
20
|
+
/** Target scenegraph lookup table. */
|
|
21
|
+
gltfNodeIdToNodeMap: Map<string, GroupNode>;
|
|
22
|
+
/** Playback start time in seconds. */
|
|
10
23
|
startTime: number;
|
|
24
|
+
/** Whether playback is currently enabled. */
|
|
11
25
|
playing: boolean;
|
|
26
|
+
/** Playback speed multiplier. */
|
|
12
27
|
speed: number;
|
|
28
|
+
/** Creates a single-animation controller. */
|
|
13
29
|
constructor(props: GLTFSingleAnimatorProps);
|
|
30
|
+
/** Advances the animation to the supplied wall-clock time in milliseconds. */
|
|
14
31
|
setTime(timeMs: number): void;
|
|
15
32
|
}
|
|
33
|
+
/** Construction props for {@link GLTFAnimator}. */
|
|
16
34
|
export type GLTFAnimatorProps = {
|
|
35
|
+
/** Parsed animations from the source glTF. */
|
|
17
36
|
animations: GLTFAnimation[];
|
|
37
|
+
/** Mapping from glTF node ids to scenegraph nodes. */
|
|
38
|
+
gltfNodeIdToNodeMap: Map<string, GroupNode>;
|
|
18
39
|
};
|
|
40
|
+
/** Coordinates playback of every animation found in a glTF scene. */
|
|
19
41
|
export declare class GLTFAnimator {
|
|
42
|
+
/** Individual animation controllers. */
|
|
20
43
|
animations: GLTFSingleAnimator[];
|
|
44
|
+
/** Creates an animator for the supplied glTF scenegraph. */
|
|
21
45
|
constructor(props: GLTFAnimatorProps);
|
|
22
46
|
/** @deprecated Use .setTime(). Will be removed (deck.gl is using this) */
|
|
23
47
|
animate(time: number): void;
|
|
48
|
+
/** Advances every animation to the supplied wall-clock time in milliseconds. */
|
|
24
49
|
setTime(time: number): void;
|
|
50
|
+
/** Returns the per-animation controllers managed by this animator. */
|
|
25
51
|
getAnimations(): GLTFSingleAnimator[];
|
|
26
52
|
}
|
|
27
53
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gltf-animator.d.ts","sourceRoot":"","sources":["../../src/gltf/gltf-animator.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"gltf-animator.d.ts","sourceRoot":"","sources":["../../src/gltf/gltf-animator.ts"],"names":[],"mappings":"AAKA,OAAO,EAAC,SAAS,EAAC,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAC,aAAa,EAAC,mCAAgC;AAGtD,iEAAiE;AACjE,KAAK,uBAAuB,GAAG;IAC7B,kCAAkC;IAClC,SAAS,EAAE,aAAa,CAAC;IACzB,sDAAsD;IACtD,mBAAmB,EAAE,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IAC5C,6BAA6B;IAC7B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,kCAAkC;IAClC,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,iCAAiC;IACjC,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,qEAAqE;AACrE,cAAM,kBAAkB;IACtB,yCAAyC;IACzC,SAAS,EAAE,aAAa,CAAC;IACzB,sCAAsC;IACtC,mBAAmB,EAAE,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IAC5C,sCAAsC;IACtC,SAAS,EAAE,MAAM,CAAK;IACtB,6CAA6C;IAC7C,OAAO,EAAE,OAAO,CAAQ;IACxB,iCAAiC;IACjC,KAAK,EAAE,MAAM,CAAK;IAElB,6CAA6C;gBACjC,KAAK,EAAE,uBAAuB;IAO1C,8EAA8E;IAC9E,OAAO,CAAC,MAAM,EAAE,MAAM;CAiBvB;AAED,mDAAmD;AACnD,MAAM,MAAM,iBAAiB,GAAG;IAC9B,8CAA8C;IAC9C,UAAU,EAAE,aAAa,EAAE,CAAC;IAC5B,sDAAsD;IACtD,mBAAmB,EAAE,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;CAC7C,CAAC;AAEF,qEAAqE;AACrE,qBAAa,YAAY;IACvB,wCAAwC;IACxC,UAAU,EAAE,kBAAkB,EAAE,CAAC;IAEjC,4DAA4D;gBAChD,KAAK,EAAE,iBAAiB;IAUpC,0EAA0E;IAC1E,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAK3B,gFAAgF;IAChF,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAI3B,sEAAsE;IACtE,aAAa;CAGd"}
|
|
@@ -2,36 +2,52 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
import { log } from '@luma.gl/core';
|
|
5
|
-
import { Matrix4 } from '@math.gl/core';
|
|
6
5
|
import { interpolate } from "./animations/interpolate.js";
|
|
6
|
+
/** Evaluates one glTF animation against the generated scenegraph. */
|
|
7
7
|
class GLTFSingleAnimator {
|
|
8
|
+
/** Animation definition being played. */
|
|
8
9
|
animation;
|
|
10
|
+
/** Target scenegraph lookup table. */
|
|
11
|
+
gltfNodeIdToNodeMap;
|
|
12
|
+
/** Playback start time in seconds. */
|
|
9
13
|
startTime = 0;
|
|
14
|
+
/** Whether playback is currently enabled. */
|
|
10
15
|
playing = true;
|
|
16
|
+
/** Playback speed multiplier. */
|
|
11
17
|
speed = 1;
|
|
18
|
+
/** Creates a single-animation controller. */
|
|
12
19
|
constructor(props) {
|
|
13
20
|
this.animation = props.animation;
|
|
21
|
+
this.gltfNodeIdToNodeMap = props.gltfNodeIdToNodeMap;
|
|
14
22
|
this.animation.name ||= 'unnamed';
|
|
15
23
|
Object.assign(this, props);
|
|
16
24
|
}
|
|
25
|
+
/** Advances the animation to the supplied wall-clock time in milliseconds. */
|
|
17
26
|
setTime(timeMs) {
|
|
18
27
|
if (!this.playing) {
|
|
19
28
|
return;
|
|
20
29
|
}
|
|
21
30
|
const absTime = timeMs / 1000;
|
|
22
31
|
const time = (absTime - this.startTime) * this.speed;
|
|
23
|
-
this.animation.channels.forEach(({ sampler,
|
|
24
|
-
|
|
25
|
-
|
|
32
|
+
this.animation.channels.forEach(({ sampler, targetNodeId, path }) => {
|
|
33
|
+
const targetNode = this.gltfNodeIdToNodeMap.get(targetNodeId);
|
|
34
|
+
if (!targetNode) {
|
|
35
|
+
throw new Error(`Cannot find animation target node ${targetNodeId}`);
|
|
36
|
+
}
|
|
37
|
+
interpolate(time, sampler, targetNode, path);
|
|
26
38
|
});
|
|
27
39
|
}
|
|
28
40
|
}
|
|
41
|
+
/** Coordinates playback of every animation found in a glTF scene. */
|
|
29
42
|
export class GLTFAnimator {
|
|
43
|
+
/** Individual animation controllers. */
|
|
30
44
|
animations;
|
|
45
|
+
/** Creates an animator for the supplied glTF scenegraph. */
|
|
31
46
|
constructor(props) {
|
|
32
47
|
this.animations = props.animations.map((animation, index) => {
|
|
33
48
|
const name = animation.name || `Animation-${index}`;
|
|
34
49
|
return new GLTFSingleAnimator({
|
|
50
|
+
gltfNodeIdToNodeMap: props.gltfNodeIdToNodeMap,
|
|
35
51
|
animation: { name, channels: animation.channels }
|
|
36
52
|
});
|
|
37
53
|
});
|
|
@@ -41,26 +57,13 @@ export class GLTFAnimator {
|
|
|
41
57
|
log.warn('GLTFAnimator#animate is deprecated. Use GLTFAnimator#setTime instead')();
|
|
42
58
|
this.setTime(time);
|
|
43
59
|
}
|
|
60
|
+
/** Advances every animation to the supplied wall-clock time in milliseconds. */
|
|
44
61
|
setTime(time) {
|
|
45
62
|
this.animations.forEach(animation => animation.setTime(time));
|
|
46
63
|
}
|
|
64
|
+
/** Returns the per-animation controllers managed by this animator. */
|
|
47
65
|
getAnimations() {
|
|
48
66
|
return this.animations;
|
|
49
67
|
}
|
|
50
68
|
}
|
|
51
|
-
// TODO: share with GLTFInstantiator
|
|
52
|
-
const scratchMatrix = new Matrix4();
|
|
53
|
-
function applyTranslationRotationScale(gltfNode, node) {
|
|
54
|
-
node.matrix.identity();
|
|
55
|
-
if (gltfNode.translation) {
|
|
56
|
-
node.matrix.translate(gltfNode.translation);
|
|
57
|
-
}
|
|
58
|
-
if (gltfNode.rotation) {
|
|
59
|
-
const rotationMatrix = scratchMatrix.fromQuaternion(gltfNode.rotation);
|
|
60
|
-
node.matrix.multiplyRight(rotationMatrix);
|
|
61
|
-
}
|
|
62
|
-
if (gltfNode.scale) {
|
|
63
|
-
node.matrix.scale(gltfNode.scale);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
69
|
//# sourceMappingURL=gltf-animator.js.map
|