@luma.gl/gltf 9.0.0-alpha.54 → 9.0.0-beta.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 +3643 -15000
- package/dist/dist.min.js +393 -0
- package/dist/gltf/create-gltf-model.d.ts +1 -1
- package/dist/gltf/create-gltf-model.d.ts.map +1 -1
- package/dist/gltf/create-gltf-model.js +34 -51
- package/dist/gltf/create-gltf-objects.d.ts +2 -2
- package/dist/gltf/create-gltf-objects.d.ts.map +1 -1
- package/dist/gltf/create-gltf-objects.js +4 -8
- package/dist/gltf/gltf-animator.d.ts.map +1 -1
- package/dist/gltf/gltf-animator.js +167 -202
- package/dist/gltf/gltf-instantiator.d.ts +3 -4
- package/dist/gltf/gltf-instantiator.d.ts.map +1 -1
- package/dist/gltf/gltf-instantiator.js +170 -161
- package/dist/index.cjs +62 -63
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +6 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/pbr/parse-pbr-material.d.ts +1 -1
- package/dist/pbr/parse-pbr-material.d.ts.map +1 -1
- package/dist/pbr/parse-pbr-material.js +320 -135
- package/dist/pbr/pbr-environment.d.ts.map +1 -1
- package/dist/pbr/pbr-environment.js +56 -59
- package/dist.min.js +4 -1215
- package/package.json +14 -15
- package/src/gltf/create-gltf-model.ts +4 -4
- package/src/gltf/gltf-animator.ts +3 -3
- package/src/gltf/gltf-instantiator.ts +45 -30
- package/src/index.ts +0 -1
- package/src/pbr/parse-pbr-material.ts +15 -12
- package/src/pbr/pbr-environment.ts +18 -11
- package/dist/gltf/create-gltf-model.js.map +0 -1
- package/dist/gltf/create-gltf-objects.js.map +0 -1
- package/dist/gltf/gltf-animator.js.map +0 -1
- package/dist/gltf/gltf-instantiator.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/pbr/parse-pbr-material.js.map +0 -1
- package/dist/pbr/pbr-environment.js.map +0 -1
|
@@ -1,224 +1,189 @@
|
|
|
1
1
|
import { assert, log } from '@luma.gl/core';
|
|
2
2
|
import { Matrix4, Quaternion } from '@math.gl/core';
|
|
3
|
+
// TODO: import from loaders.gl?
|
|
3
4
|
export const ATTRIBUTE_TYPE_TO_COMPONENTS = {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
SCALAR: 1,
|
|
6
|
+
VEC2: 2,
|
|
7
|
+
VEC3: 3,
|
|
8
|
+
VEC4: 4,
|
|
9
|
+
MAT2: 4,
|
|
10
|
+
MAT3: 9,
|
|
11
|
+
MAT4: 16
|
|
11
12
|
};
|
|
12
13
|
export const ATTRIBUTE_COMPONENT_TYPE_TO_ARRAY = {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
5120: Int8Array,
|
|
15
|
+
5121: Uint8Array,
|
|
16
|
+
5122: Int16Array,
|
|
17
|
+
5123: Uint16Array,
|
|
18
|
+
5125: Uint32Array,
|
|
19
|
+
5126: Float32Array
|
|
19
20
|
};
|
|
20
21
|
class GLTFAnimation {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
} = _ref;
|
|
41
|
-
interpolate(time, sampler, target, path);
|
|
42
|
-
applyTranslationRotationScale(target, target._node);
|
|
43
|
-
});
|
|
44
|
-
}
|
|
22
|
+
name;
|
|
23
|
+
startTime = 0;
|
|
24
|
+
playing = true;
|
|
25
|
+
speed = 1;
|
|
26
|
+
channels = [];
|
|
27
|
+
constructor(props) {
|
|
28
|
+
Object.assign(this, props);
|
|
29
|
+
}
|
|
30
|
+
animate(timeMs) {
|
|
31
|
+
if (!this.playing) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const absTime = timeMs / 1000;
|
|
35
|
+
const time = (absTime - this.startTime) * this.speed;
|
|
36
|
+
this.channels.forEach(({ sampler, target, path }) => {
|
|
37
|
+
interpolate(time, sampler, target, path);
|
|
38
|
+
applyTranslationRotationScale(target, target._node);
|
|
39
|
+
});
|
|
40
|
+
}
|
|
45
41
|
}
|
|
46
42
|
export class GLTFAnimator {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
return new GLTFAnimation({
|
|
75
|
-
name,
|
|
76
|
-
channels
|
|
77
|
-
});
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
animate(time) {
|
|
81
|
-
this.setTime(time);
|
|
82
|
-
}
|
|
83
|
-
setTime(time) {
|
|
84
|
-
this.animations.forEach(animation => animation.animate(time));
|
|
85
|
-
}
|
|
86
|
-
getAnimations() {
|
|
87
|
-
return this.animations;
|
|
88
|
-
}
|
|
43
|
+
animations;
|
|
44
|
+
constructor(gltf) {
|
|
45
|
+
this.animations = gltf.animations.map((animation, index) => {
|
|
46
|
+
const name = animation.name || `Animation-${index}`;
|
|
47
|
+
const samplers = animation.samplers.map(({ input, interpolation = 'LINEAR', output }) => ({
|
|
48
|
+
input: accessorToJsArray(gltf.accessors[input]),
|
|
49
|
+
interpolation,
|
|
50
|
+
output: accessorToJsArray(gltf.accessors[output])
|
|
51
|
+
}));
|
|
52
|
+
const channels = animation.channels.map(({ sampler, target }) => ({
|
|
53
|
+
sampler: samplers[sampler],
|
|
54
|
+
target: gltf.nodes[target.node],
|
|
55
|
+
path: target.path
|
|
56
|
+
}));
|
|
57
|
+
return new GLTFAnimation({ name, channels });
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
/** @deprecated Use .setTime(). Will be removed (deck.gl is using this) */
|
|
61
|
+
animate(time) {
|
|
62
|
+
this.setTime(time);
|
|
63
|
+
}
|
|
64
|
+
setTime(time) {
|
|
65
|
+
this.animations.forEach(animation => animation.animate(time));
|
|
66
|
+
}
|
|
67
|
+
getAnimations() {
|
|
68
|
+
return this.animations;
|
|
69
|
+
}
|
|
89
70
|
}
|
|
71
|
+
//
|
|
90
72
|
function accessorToJsArray(accessor) {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
return accessor._animation;
|
|
73
|
+
if (!accessor._animation) {
|
|
74
|
+
const ArrayType = ATTRIBUTE_COMPONENT_TYPE_TO_ARRAY[accessor.componentType];
|
|
75
|
+
const components = ATTRIBUTE_TYPE_TO_COMPONENTS[accessor.type];
|
|
76
|
+
const length = components * accessor.count;
|
|
77
|
+
const { buffer, byteOffset } = accessor.bufferView.data;
|
|
78
|
+
const array = new ArrayType(buffer, byteOffset + (accessor.byteOffset || 0), length);
|
|
79
|
+
if (components === 1) {
|
|
80
|
+
accessor._animation = Array.from(array);
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
// Slice array
|
|
84
|
+
const slicedArray = [];
|
|
85
|
+
for (let i = 0; i < array.length; i += components) {
|
|
86
|
+
slicedArray.push(Array.from(array.slice(i, i + components)));
|
|
87
|
+
}
|
|
88
|
+
accessor._animation = slicedArray;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return accessor._animation;
|
|
111
92
|
}
|
|
93
|
+
// TODO: share with GLTFInstantiator
|
|
112
94
|
const helperMatrix = new Matrix4();
|
|
113
95
|
function applyTranslationRotationScale(gltfNode, node) {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
96
|
+
node.matrix.identity();
|
|
97
|
+
if (gltfNode.translation) {
|
|
98
|
+
node.matrix.translate(gltfNode.translation);
|
|
99
|
+
}
|
|
100
|
+
if (gltfNode.rotation) {
|
|
101
|
+
const rotationMatrix = helperMatrix.fromQuaternion(gltfNode.rotation);
|
|
102
|
+
node.matrix.multiplyRight(rotationMatrix);
|
|
103
|
+
}
|
|
104
|
+
if (gltfNode.scale) {
|
|
105
|
+
node.matrix.scale(gltfNode.scale);
|
|
106
|
+
}
|
|
125
107
|
}
|
|
126
108
|
const quaternion = new Quaternion();
|
|
127
109
|
function linearInterpolate(target, path, start, stop, ratio) {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
}
|
|
141
|
-
}
|
|
110
|
+
if (path === 'rotation') {
|
|
111
|
+
// SLERP when path is rotation
|
|
112
|
+
quaternion.slerp({ start, target: stop, ratio });
|
|
113
|
+
for (let i = 0; i < quaternion.length; i++) {
|
|
114
|
+
target[path][i] = quaternion[i];
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
// regular interpolation
|
|
119
|
+
for (let i = 0; i < start.length; i++) {
|
|
120
|
+
target[path][i] = ratio * stop[i] + (1 - ratio) * start[i];
|
|
121
|
+
}
|
|
122
|
+
}
|
|
142
123
|
}
|
|
143
|
-
function cubicsplineInterpolate(target, path,
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
const m1 = inTangent1[i] * tDiff;
|
|
155
|
-
target[path][i] = (2 * Math.pow(t, 3) - 3 * Math.pow(t, 2) + 1) * p0[i] + (Math.pow(t, 3) - 2 * Math.pow(t, 2) + t) * m0 + (-2 * Math.pow(t, 3) + 3 * Math.pow(t, 2)) * p1[i] + (Math.pow(t, 3) - Math.pow(t, 2)) * m1;
|
|
156
|
-
}
|
|
124
|
+
function cubicsplineInterpolate(target, path, { p0, outTangent0, inTangent1, p1, tDiff, ratio: t }) {
|
|
125
|
+
// TODO: Quaternion might need normalization
|
|
126
|
+
for (let i = 0; i < target[path].length; i++) {
|
|
127
|
+
const m0 = outTangent0[i] * tDiff;
|
|
128
|
+
const m1 = inTangent1[i] * tDiff;
|
|
129
|
+
target[path][i] =
|
|
130
|
+
(2 * Math.pow(t, 3) - 3 * Math.pow(t, 2) + 1) * p0[i] +
|
|
131
|
+
(Math.pow(t, 3) - 2 * Math.pow(t, 2) + t) * m0 +
|
|
132
|
+
(-2 * Math.pow(t, 3) + 3 * Math.pow(t, 2)) * p1[i] +
|
|
133
|
+
(Math.pow(t, 3) - Math.pow(t, 2)) * m1;
|
|
134
|
+
}
|
|
157
135
|
}
|
|
158
136
|
function stepInterpolate(target, path, value) {
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
137
|
+
for (let i = 0; i < value.length; i++) {
|
|
138
|
+
target[path][i] = value[i];
|
|
139
|
+
}
|
|
162
140
|
}
|
|
163
|
-
function interpolate(time,
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
outTangent0,
|
|
212
|
-
inTangent1,
|
|
213
|
-
p1,
|
|
214
|
-
tDiff,
|
|
215
|
-
ratio
|
|
216
|
-
});
|
|
217
|
-
}
|
|
218
|
-
break;
|
|
219
|
-
default:
|
|
220
|
-
log.warn(`Interpolation ${interpolation} not supported`)();
|
|
221
|
-
break;
|
|
222
|
-
}
|
|
141
|
+
function interpolate(time, { input, interpolation, output }, target, path) {
|
|
142
|
+
const maxTime = input[input.length - 1];
|
|
143
|
+
const animationTime = time % maxTime;
|
|
144
|
+
const nextIndex = input.findIndex(t => t >= animationTime);
|
|
145
|
+
const previousIndex = Math.max(0, nextIndex - 1);
|
|
146
|
+
if (!Array.isArray(target[path])) {
|
|
147
|
+
switch (path) {
|
|
148
|
+
case 'translation':
|
|
149
|
+
target[path] = [0, 0, 0];
|
|
150
|
+
break;
|
|
151
|
+
case 'rotation':
|
|
152
|
+
target[path] = [0, 0, 0, 1];
|
|
153
|
+
break;
|
|
154
|
+
case 'scale':
|
|
155
|
+
target[path] = [1, 1, 1];
|
|
156
|
+
break;
|
|
157
|
+
default:
|
|
158
|
+
log.warn(`Bad animation path ${path}`)();
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
assert(target[path].length === output[previousIndex].length);
|
|
162
|
+
const previousTime = input[previousIndex];
|
|
163
|
+
const nextTime = input[nextIndex];
|
|
164
|
+
switch (interpolation) {
|
|
165
|
+
case 'STEP':
|
|
166
|
+
stepInterpolate(target, path, output[previousIndex]);
|
|
167
|
+
break;
|
|
168
|
+
case 'LINEAR':
|
|
169
|
+
if (nextTime > previousTime) {
|
|
170
|
+
const ratio = (animationTime - previousTime) / (nextTime - previousTime);
|
|
171
|
+
linearInterpolate(target, path, output[previousIndex], output[nextIndex], ratio);
|
|
172
|
+
}
|
|
173
|
+
break;
|
|
174
|
+
case 'CUBICSPLINE':
|
|
175
|
+
if (nextTime > previousTime) {
|
|
176
|
+
const ratio = (animationTime - previousTime) / (nextTime - previousTime);
|
|
177
|
+
const tDiff = nextTime - previousTime;
|
|
178
|
+
const p0 = output[3 * previousIndex + 1];
|
|
179
|
+
const outTangent0 = output[3 * previousIndex + 2];
|
|
180
|
+
const inTangent1 = output[3 * nextIndex + 0];
|
|
181
|
+
const p1 = output[3 * nextIndex + 1];
|
|
182
|
+
cubicsplineInterpolate(target, path, { p0, outTangent0, inTangent1, p1, tDiff, ratio });
|
|
183
|
+
}
|
|
184
|
+
break;
|
|
185
|
+
default:
|
|
186
|
+
log.warn(`Interpolation ${interpolation} not supported`)();
|
|
187
|
+
break;
|
|
188
|
+
}
|
|
223
189
|
}
|
|
224
|
-
//# sourceMappingURL=gltf-animator.js.map
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { Device, Buffer, PrimitiveTopology } from '@luma.gl/core';
|
|
2
2
|
import { Geometry, GroupNode, ModelNode, ModelProps } from '@luma.gl/engine';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import type { PBREnvironment } from '../pbr/pbr-environment';
|
|
3
|
+
import { GLTFAnimator } from "./gltf-animator.js";
|
|
4
|
+
import type { PBREnvironment } from "../pbr/pbr-environment.js";
|
|
6
5
|
export type GLTFInstantiatorOptions = {
|
|
7
6
|
modelOptions?: Partial<ModelProps>;
|
|
8
7
|
pbrDebug?: boolean;
|
|
@@ -15,7 +14,7 @@ export type GLTFInstantiatorOptions = {
|
|
|
15
14
|
* Walks the parsed and resolved glTF structure and builds a luma.gl scenegraph
|
|
16
15
|
*/
|
|
17
16
|
export declare class GLTFInstantiator {
|
|
18
|
-
device:
|
|
17
|
+
device: Device;
|
|
19
18
|
options: GLTFInstantiatorOptions;
|
|
20
19
|
gltf: any;
|
|
21
20
|
constructor(device: Device, options?: GLTFInstantiatorOptions);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gltf-instantiator.d.ts","sourceRoot":"","sources":["../../src/gltf/gltf-instantiator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAE,MAAM,EAAE,iBAAiB,EAAC,MAAM,eAAe,CAAC;AAChE,OAAO,EAAC,QAAQ,
|
|
1
|
+
{"version":3,"file":"gltf-instantiator.d.ts","sourceRoot":"","sources":["../../src/gltf/gltf-instantiator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAE,MAAM,EAAE,iBAAiB,EAAC,MAAM,eAAe,CAAC;AAChE,OAAO,EAAC,QAAQ,EAAqB,SAAS,EAAE,SAAS,EAAE,UAAU,EAAC,MAAM,iBAAiB,CAAC;AAG9F,OAAO,EAAC,YAAY,EAAC,2BAAwB;AAE7C,OAAO,KAAK,EAAC,cAAc,EAAC,kCAA+B;AAE3D,MAAM,MAAM,uBAAuB,GAAG;IACpC,YAAY,CAAC,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC;IACnC,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,6BAA6B,CAAC,EAAE,cAAc,CAAC;IAC/C,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,CAAC;AAUF;;;GAGG;AACH,qBAAa,gBAAgB;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,uBAAuB,CAAC;IACjC,IAAI,EAAE,GAAG,CAAC;gBAEE,MAAM,EAAE,MAAM,EAAE,OAAO,GAAE,uBAA4B;IAKjE,WAAW,CAAC,IAAI,EAAE,GAAG,GAAG,SAAS,EAAE;IAMnC,cAAc,IAAI,YAAY;IAQ9B,WAAW,CAAC,SAAS,EAAE,GAAG,GAAG,SAAS;IAUtC,UAAU,CAAC,QAAQ,KAAA;IAuCnB,UAAU,CAAC,QAAQ,KAAA,GAAG,SAAS;IAiB/B,eAAe,CAAC,aAAa,EAAE,GAAG,EAAE,CAAC,EAAE,MAAM,EAAE,QAAQ,KAAA,GAAG,SAAS;IA0BnE,cAAc,CAAC,UAAU,EAAE,GAAG;IAI9B,cAAc,CAAC,EAAE,EAAE,MAAM,EAAE,aAAa,EAAE,GAAG,EAAE,QAAQ,EAAE,iBAAiB,GAAG,QAAQ;IAgBrF,YAAY,CAAC,SAAS,KAAA,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM;IAuB9C,aAAa,CAAC,WAAW,KAAA;IAMzB,QAAQ,IAAI,OAAO;CAOpB;AAKD,aAAK,MAAM;IACT,MAAM,IAAM;IACZ,KAAK,IAAM;IACX,SAAS,IAAM;IACf,UAAU,IAAM;IAChB,SAAS,IAAM;IACf,cAAc,IAAM;IACpB,YAAY,IAAM;CACnB;AAED,wBAAgB,2BAA2B,CACzC,QAAQ,EACJ,MAAM,CAAC,MAAM,GACb,MAAM,CAAC,KAAK,GACZ,MAAM,CAAC,UAAU,GACjB,MAAM,CAAC,SAAS,GAChB,MAAM,CAAC,SAAS,GAChB,MAAM,CAAC,cAAc,GACrB,MAAM,CAAC,YAAY,GACtB,iBAAiB,CAmBnB"}
|