@luma.gl/gltf 9.3.0-alpha.4 → 9.3.0-alpha.6
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 +397 -220
- 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 +6 -0
- package/dist/gltf/create-gltf-model.d.ts.map +1 -1
- package/dist/gltf/create-gltf-model.js +96 -44
- package/dist/gltf/create-gltf-model.js.map +1 -1
- package/dist/gltf/create-scenegraph-from-gltf.d.ts +15 -1
- package/dist/gltf/create-scenegraph-from-gltf.d.ts.map +1 -1
- package/dist/gltf/create-scenegraph-from-gltf.js +12 -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/index.cjs +378 -210
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +1 -2
- package/dist/index.d.ts.map +1 -1
- 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 +46 -23
- package/dist/parsers/parse-gltf-animations.js.map +1 -1
- package/dist/parsers/parse-gltf-lights.d.ts.map +1 -1
- package/dist/parsers/parse-gltf-lights.js +40 -12
- package/dist/parsers/parse-gltf-lights.js.map +1 -1
- package/dist/parsers/parse-gltf.d.ts +16 -1
- package/dist/parsers/parse-gltf.d.ts.map +1 -1
- package/dist/parsers/parse-gltf.js +65 -57
- package/dist/parsers/parse-gltf.js.map +1 -1
- package/dist/parsers/parse-pbr-material.d.ts +46 -1
- package/dist/parsers/parse-pbr-material.d.ts.map +1 -1
- package/dist/parsers/parse-pbr-material.js +137 -13
- package/dist/parsers/parse-pbr-material.js.map +1 -1
- package/dist/pbr/pbr-environment.d.ts +6 -0
- package/dist/pbr/pbr-environment.d.ts.map +1 -1
- package/dist/pbr/pbr-environment.js +1 -0
- package/dist/pbr/pbr-environment.js.map +1 -1
- package/dist/pbr/pbr-material.d.ts +5 -0
- 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 +6 -0
- package/dist/webgl-to-webgpu/convert-webgl-sampler.d.ts.map +1 -1
- package/dist/webgl-to-webgpu/convert-webgl-sampler.js +4 -0
- package/dist/webgl-to-webgpu/convert-webgl-sampler.js.map +1 -1
- package/dist/webgl-to-webgpu/convert-webgl-topology.d.ts +2 -0
- package/dist/webgl-to-webgpu/convert-webgl-topology.d.ts.map +1 -1
- package/dist/webgl-to-webgpu/convert-webgl-topology.js +2 -0
- package/dist/webgl-to-webgpu/convert-webgl-topology.js.map +1 -1
- package/package.json +5 -5
- package/src/gltf/animations/animations.ts +17 -5
- package/src/gltf/animations/interpolate.ts +49 -68
- package/src/gltf/create-gltf-model.ts +101 -43
- package/src/gltf/create-scenegraph-from-gltf.ts +39 -11
- package/src/gltf/gltf-animator.ts +34 -25
- package/src/index.ts +1 -2
- package/src/parsers/parse-gltf-animations.ts +63 -26
- package/src/parsers/parse-gltf-lights.ts +51 -13
- package/src/parsers/parse-gltf.ts +90 -77
- package/src/parsers/parse-pbr-material.ts +204 -14
- package/src/pbr/pbr-environment.ts +10 -0
- package/src/pbr/pbr-material.ts +5 -0
- package/src/webgl-to-webgpu/convert-webgl-attribute.ts +12 -1
- package/src/webgl-to-webgpu/convert-webgl-sampler.ts +9 -0
- package/src/webgl-to-webgpu/convert-webgl-topology.ts +2 -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":"create-gltf-model.d.ts","sourceRoot":"","sources":["../../src/gltf/create-gltf-model.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,MAAM,EAAqC,MAAM,eAAe,CAAC;AAEzE,OAAO,EAAC,QAAQ,EAAS,SAAS,EAAE,KAAK,UAAU,EAAC,MAAM,iBAAiB,CAAC;AAC5E,OAAO,EAAC,KAAK,iBAAiB,EAAC,+BAA4B;
|
|
1
|
+
{"version":3,"file":"create-gltf-model.d.ts","sourceRoot":"","sources":["../../src/gltf/create-gltf-model.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,MAAM,EAAqC,MAAM,eAAe,CAAC;AAEzE,OAAO,EAAC,QAAQ,EAAS,SAAS,EAAE,KAAK,UAAU,EAAC,MAAM,iBAAiB,CAAC;AAC5E,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,8DAA8D;IAC9D,YAAY,CAAC,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC;CACpC,CAAC;AAEF,4CAA4C;AAC5C,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,sBAAsB,GAAG,SAAS,CA6C1F"}
|
|
@@ -2,53 +2,91 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
import { log } from '@luma.gl/core';
|
|
5
|
-
import { pbrMaterial } from '@luma.gl/shadertools';
|
|
5
|
+
import { pbrMaterial, skin } from '@luma.gl/shadertools';
|
|
6
6
|
import { Model, ModelNode } from '@luma.gl/engine';
|
|
7
7
|
const SHADER = /* WGSL */ `
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
8
|
+
struct VertexInputs {
|
|
9
|
+
@location(0) positions: vec3f,
|
|
10
|
+
#ifdef HAS_NORMALS
|
|
11
|
+
@location(1) normals: vec3f,
|
|
12
|
+
#endif
|
|
13
|
+
#ifdef HAS_TANGENTS
|
|
14
|
+
@location(2) TANGENT: vec4f,
|
|
15
|
+
#endif
|
|
16
|
+
#ifdef HAS_UV
|
|
17
|
+
@location(3) texCoords: vec2f,
|
|
18
|
+
#endif
|
|
19
|
+
#ifdef HAS_SKIN
|
|
20
|
+
@location(4) JOINTS_0: vec4u,
|
|
21
|
+
@location(5) WEIGHTS_0: vec4f,
|
|
22
|
+
#endif
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
struct FragmentInputs {
|
|
26
|
+
@builtin(position) position: vec4f,
|
|
27
|
+
@location(0) pbrPosition: vec3f,
|
|
28
|
+
@location(1) pbrUV: vec2f,
|
|
29
|
+
@location(2) pbrNormal: vec3f,
|
|
30
|
+
#ifdef HAS_TANGENTS
|
|
31
|
+
@location(3) pbrTangent: vec4f,
|
|
32
|
+
#endif
|
|
33
|
+
};
|
|
22
34
|
|
|
23
35
|
@vertex
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
36
|
+
fn vertexMain(inputs: VertexInputs) -> FragmentInputs {
|
|
37
|
+
var outputs: FragmentInputs;
|
|
38
|
+
var position = vec4f(inputs.positions, 1.0);
|
|
39
|
+
var normal = vec3f(0.0, 0.0, 1.0);
|
|
40
|
+
var tangent = vec4f(1.0, 0.0, 0.0, 1.0);
|
|
41
|
+
var uv = vec2f(0.0, 0.0);
|
|
42
|
+
|
|
43
|
+
#ifdef HAS_NORMALS
|
|
44
|
+
normal = inputs.normals;
|
|
45
|
+
#endif
|
|
46
|
+
#ifdef HAS_UV
|
|
47
|
+
uv = inputs.texCoords;
|
|
48
|
+
#endif
|
|
49
|
+
#ifdef HAS_TANGENTS
|
|
50
|
+
tangent = inputs.TANGENT;
|
|
51
|
+
#endif
|
|
52
|
+
#ifdef HAS_SKIN
|
|
53
|
+
let skinMatrix = getSkinMatrix(inputs.WEIGHTS_0, inputs.JOINTS_0);
|
|
54
|
+
position = skinMatrix * position;
|
|
55
|
+
normal = normalize((skinMatrix * vec4f(normal, 0.0)).xyz);
|
|
56
|
+
#ifdef HAS_TANGENTS
|
|
57
|
+
tangent = vec4f(normalize((skinMatrix * vec4f(tangent.xyz, 0.0)).xyz), tangent.w);
|
|
58
|
+
#endif
|
|
59
|
+
#endif
|
|
60
|
+
|
|
61
|
+
let worldPosition = pbrProjection.modelMatrix * position;
|
|
62
|
+
|
|
63
|
+
#ifdef HAS_NORMALS
|
|
64
|
+
normal = normalize((pbrProjection.normalMatrix * vec4f(normal, 0.0)).xyz);
|
|
65
|
+
#endif
|
|
66
|
+
#ifdef HAS_TANGENTS
|
|
67
|
+
let worldTangent = normalize((pbrProjection.modelMatrix * vec4f(tangent.xyz, 0.0)).xyz);
|
|
68
|
+
outputs.pbrTangent = vec4f(worldTangent, tangent.w);
|
|
69
|
+
#endif
|
|
70
|
+
|
|
71
|
+
outputs.position = pbrProjection.modelViewProjectionMatrix * position;
|
|
72
|
+
outputs.pbrPosition = worldPosition.xyz / worldPosition.w;
|
|
73
|
+
outputs.pbrUV = uv;
|
|
74
|
+
outputs.pbrNormal = normal;
|
|
75
|
+
return outputs;
|
|
76
|
+
}
|
|
44
77
|
|
|
45
78
|
@fragment
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
79
|
+
fn fragmentMain(inputs: FragmentInputs) -> @location(0) vec4f {
|
|
80
|
+
fragmentInputs.pbr_vPosition = inputs.pbrPosition;
|
|
81
|
+
fragmentInputs.pbr_vUV = inputs.pbrUV;
|
|
82
|
+
fragmentInputs.pbr_vNormal = inputs.pbrNormal;
|
|
83
|
+
#ifdef HAS_TANGENTS
|
|
84
|
+
let tangent = normalize(inputs.pbrTangent.xyz);
|
|
85
|
+
let bitangent = normalize(cross(inputs.pbrNormal, tangent)) * inputs.pbrTangent.w;
|
|
86
|
+
fragmentInputs.pbr_vTBN = mat3x3f(tangent, bitangent, inputs.pbrNormal);
|
|
87
|
+
#endif
|
|
88
|
+
return pbr_filterColor(vec4f(1.0));
|
|
89
|
+
}
|
|
52
90
|
`;
|
|
53
91
|
// TODO rename attributes to POSITION/NORMAL etc
|
|
54
92
|
// See gpu-geometry.ts: getAttributeBuffersFromGeometry()
|
|
@@ -72,6 +110,11 @@ const vs = /* glsl */ `\
|
|
|
72
110
|
in vec2 texCoords;
|
|
73
111
|
#endif
|
|
74
112
|
|
|
113
|
+
#ifdef HAS_SKIN
|
|
114
|
+
in uvec4 JOINTS_0;
|
|
115
|
+
in vec4 WEIGHTS_0;
|
|
116
|
+
#endif
|
|
117
|
+
|
|
75
118
|
void main(void) {
|
|
76
119
|
vec4 _NORMAL = vec4(0.);
|
|
77
120
|
vec4 _TANGENT = vec4(0.);
|
|
@@ -89,8 +132,17 @@ const vs = /* glsl */ `\
|
|
|
89
132
|
_TEXCOORD_0 = texCoords;
|
|
90
133
|
#endif
|
|
91
134
|
|
|
92
|
-
|
|
93
|
-
|
|
135
|
+
vec4 pos = positions;
|
|
136
|
+
|
|
137
|
+
#ifdef HAS_SKIN
|
|
138
|
+
mat4 skinMat = getSkinMatrix(WEIGHTS_0, JOINTS_0);
|
|
139
|
+
pos = skinMat * pos;
|
|
140
|
+
_NORMAL = skinMat * _NORMAL;
|
|
141
|
+
_TANGENT = vec4((skinMat * vec4(_TANGENT.xyz, 0.)).xyz, _TANGENT.w);
|
|
142
|
+
#endif
|
|
143
|
+
|
|
144
|
+
pbr_setPositionNormalTangentUV(pos, _NORMAL, _TANGENT, _TEXCOORD_0);
|
|
145
|
+
gl_Position = pbrProjection.modelViewProjectionMatrix * pos;
|
|
94
146
|
}
|
|
95
147
|
`;
|
|
96
148
|
const fs = /* glsl */ `\
|
|
@@ -126,7 +178,7 @@ export function createGLTFModel(device, options) {
|
|
|
126
178
|
geometry,
|
|
127
179
|
topology: geometry.topology,
|
|
128
180
|
vertexCount,
|
|
129
|
-
modules: [pbrMaterial],
|
|
181
|
+
modules: [pbrMaterial, skin],
|
|
130
182
|
...modelOptions,
|
|
131
183
|
defines: { ...parsedPPBRMaterial.defines, ...modelOptions.defines },
|
|
132
184
|
parameters: { ...parameters, ...parsedPPBRMaterial.parameters, ...modelOptions.parameters }
|
|
@@ -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,EAAwC,GAAG,EAAC,MAAM,eAAe,CAAC;AACzE,OAAO,EAAC,WAAW,
|
|
1
|
+
{"version":3,"file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,EAAE;QACF,EAAE;QACF,QAAQ;QACR,QAAQ,EAAE,QAAQ,CAAC,QAAQ;QAC3B,WAAW;QACX,OAAO,EAAE,CAAC,WAAW,EAAE,IAAI,CAAC;QAC5B,GAAG,YAAY;QAEf,OAAO,EAAE,EAAC,GAAG,kBAAkB,CAAC,OAAO,EAAE,GAAG,YAAY,CAAC,OAAO,EAAC;QACjE,UAAU,EAAE,EAAC,GAAG,UAAU,EAAE,GAAG,kBAAkB,CAAC,UAAU,EAAE,GAAG,YAAY,CAAC,UAAU,EAAC;KAC1F,CAAC;IAEF,MAAM,KAAK,GAAG,IAAI,KAAK,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;IAE5C,MAAM,EAAC,MAAM,EAAE,GAAG,gBAAgB,EAAC,GAAG;QACpC,GAAG,kBAAkB,CAAC,QAAQ;QAC9B,GAAG,YAAY,CAAC,QAAQ;QACxB,GAAG,kBAAkB,CAAC,QAAQ;QAC9B,GAAG,YAAY,CAAC,QAAQ;KACzB,CAAC;IAEF,KAAK,CAAC,YAAY,CAAC,QAAQ,CAAC,EAAC,WAAW,EAAE,gBAAgB,EAAE,aAAa,EAAE,EAAC,MAAM,EAAC,EAAC,CAAC,CAAC;IACtF,OAAO,IAAI,SAAS,CAAC,EAAC,gBAAgB,EAAE,KAAK,EAAC,CAAC,CAAC;AAClD,CAAC"}
|
|
@@ -4,9 +4,23 @@ import { GLTFPostprocessed } from '@loaders.gl/gltf';
|
|
|
4
4
|
import { Light } from '@luma.gl/shadertools';
|
|
5
5
|
import { type ParseGLTFOptions } from "../parsers/parse-gltf.js";
|
|
6
6
|
import { GLTFAnimator } from "./gltf-animator.js";
|
|
7
|
-
|
|
7
|
+
/** Scenegraph bundle returned from a parsed glTF asset. */
|
|
8
|
+
export type GLTFScenegraphs = {
|
|
9
|
+
/** Scene roots produced from the glTF scenes array. */
|
|
8
10
|
scenes: GroupNode[];
|
|
11
|
+
/** Animation controller for glTF animations. */
|
|
9
12
|
animator: GLTFAnimator;
|
|
13
|
+
/** Parsed punctual lights from the asset. */
|
|
10
14
|
lights: Light[];
|
|
15
|
+
/** Map from glTF mesh ids to generated mesh group nodes. */
|
|
16
|
+
gltfMeshIdToNodeMap: Map<string, GroupNode>;
|
|
17
|
+
/** Map from glTF node indices to generated scenegraph nodes. */
|
|
18
|
+
gltfNodeIndexToNodeMap: Map<number, GroupNode>;
|
|
19
|
+
/** Map from glTF node ids to generated scenegraph nodes. */
|
|
20
|
+
gltfNodeIdToNodeMap: Map<string, GroupNode>;
|
|
21
|
+
/** Original post-processed glTF document. */
|
|
22
|
+
gltf: GLTFPostprocessed;
|
|
11
23
|
};
|
|
24
|
+
/** Converts a post-processed glTF asset into luma.gl scenegraph nodes and animation helpers. */
|
|
25
|
+
export declare function createScenegraphsFromGLTF(device: Device, gltf: GLTFPostprocessed, options?: ParseGLTFOptions): GLTFScenegraphs;
|
|
12
26
|
//# 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;AAC1C,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;
|
|
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;AAC1C,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;AAG7C,2DAA2D;AAC3D,MAAM,MAAM,eAAe,GAAG;IAC5B,uDAAuD;IACvD,MAAM,EAAE,SAAS,EAAE,CAAC;IACpB,gDAAgD;IAChD,QAAQ,EAAE,YAAY,CAAC;IACvB,6CAA6C;IAC7C,MAAM,EAAE,KAAK,EAAE,CAAC;IAEhB,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,CAoBjB"}
|
|
@@ -5,14 +5,20 @@ import { parseGLTF } from "../parsers/parse-gltf.js";
|
|
|
5
5
|
import { parseGLTFLights } from "../parsers/parse-gltf-lights.js";
|
|
6
6
|
import { GLTFAnimator } from "./gltf-animator.js";
|
|
7
7
|
import { parseGLTFAnimations } from "../parsers/parse-gltf-animations.js";
|
|
8
|
-
|
|
8
|
+
/** Converts a post-processed glTF asset into luma.gl scenegraph nodes and animation helpers. */
|
|
9
9
|
export function createScenegraphsFromGLTF(device, gltf, options) {
|
|
10
|
-
|
|
11
|
-
const scenes = parseGLTF(device, gltf, options);
|
|
12
|
-
// Note: There is a nasty dependency on injected nodes in the glTF
|
|
10
|
+
const { scenes, gltfMeshIdToNodeMap, gltfNodeIdToNodeMap, gltfNodeIndexToNodeMap } = parseGLTF(device, gltf, options);
|
|
13
11
|
const animations = parseGLTFAnimations(gltf);
|
|
14
|
-
const animator = new GLTFAnimator({ animations });
|
|
12
|
+
const animator = new GLTFAnimator({ animations, gltfNodeIdToNodeMap });
|
|
15
13
|
const lights = parseGLTFLights(gltf);
|
|
16
|
-
return {
|
|
14
|
+
return {
|
|
15
|
+
scenes,
|
|
16
|
+
animator,
|
|
17
|
+
lights,
|
|
18
|
+
gltfMeshIdToNodeMap,
|
|
19
|
+
gltfNodeIdToNodeMap,
|
|
20
|
+
gltfNodeIndexToNodeMap,
|
|
21
|
+
gltf
|
|
22
|
+
};
|
|
17
23
|
}
|
|
18
24
|
//# 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;AAMpC,OAAO,EAAC,SAAS,EAAwB,iCAA8B;AACvE,OAAO,EAAC,eAAe,EAAC,wCAAqC;AAC7D,OAAO,EAAC,YAAY,EAAC,2BAAwB;AAC7C,OAAO,EAAC,mBAAmB,EAAC,4CAAyC;
|
|
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;AAsBrE,gGAAgG;AAChG,MAAM,UAAU,yBAAyB,CACvC,MAAc,EACd,IAAuB,EACvB,OAA0B;IAE1B,MAAM,EAAC,MAAM,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,sBAAsB,EAAC,GAAG,SAAS,CAC1F,MAAM,EACN,IAAI,EACJ,OAAO,CACR,CAAC;IAEF,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;IAErC,OAAO;QACL,MAAM;QACN,QAAQ;QACR,MAAM;QACN,mBAAmB;QACnB,mBAAmB;QACnB,sBAAsB;QACtB,IAAI;KACL,CAAC;AACJ,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,uBA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ifier: 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
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gltf-animator.js","sourceRoot":"","sources":["../../src/gltf/gltf-animator.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;
|
|
1
|
+
{"version":3,"file":"gltf-animator.js","sourceRoot":"","sources":["../../src/gltf/gltf-animator.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAEpC,OAAO,EAAC,GAAG,EAAC,MAAM,eAAe,CAAC;AAGlC,OAAO,EAAC,WAAW,EAAC,oCAAiC;AAgBrD,qEAAqE;AACrE,MAAM,kBAAkB;IACtB,yCAAyC;IACzC,SAAS,CAAgB;IACzB,sCAAsC;IACtC,mBAAmB,CAAyB;IAC5C,sCAAsC;IACtC,SAAS,GAAW,CAAC,CAAC;IACtB,6CAA6C;IAC7C,OAAO,GAAY,IAAI,CAAC;IACxB,iCAAiC;IACjC,KAAK,GAAW,CAAC,CAAC;IAElB,6CAA6C;IAC7C,YAAY,KAA8B;QACxC,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC,SAAS,CAAC;QACjC,IAAI,CAAC,mBAAmB,GAAG,KAAK,CAAC,mBAAmB,CAAC;QACrD,IAAI,CAAC,SAAS,CAAC,IAAI,KAAK,SAAS,CAAC;QAClC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IAC7B,CAAC;IAED,8EAA8E;IAC9E,OAAO,CAAC,MAAc;QACpB,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;YAClB,OAAO;QACT,CAAC;QAED,MAAM,OAAO,GAAG,MAAM,GAAG,IAAI,CAAC;QAC9B,MAAM,IAAI,GAAG,CAAC,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC;QAErD,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,EAAC,OAAO,EAAE,YAAY,EAAE,IAAI,EAAC,EAAE,EAAE;YAChE,MAAM,UAAU,GA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