@ohuoy/easymap 1.0.19 → 1.0.21
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/bundle.js +318 -290
- package/dist/example - /345/211/257/346/234/254/bundle.js" +318 -290
- package/dist/example - /345/211/257/346/234/254/index.html" +11 -11
- package/index.js +4 -0
- package/lib/threebox-plugin/CHANGELOG.md +665 -0
- package/lib/threebox-plugin/LICENSE.txt +97 -0
- package/lib/threebox-plugin/README.md +199 -0
- package/lib/threebox-plugin/exports.js +2 -0
- package/lib/threebox-plugin/main.js +8 -0
- package/lib/threebox-plugin/package.json +44 -0
- package/lib/threebox-plugin/server.stop.js +13 -0
- package/lib/threebox-plugin/src/Threebox.js +1216 -0
- package/lib/threebox-plugin/src/animation/AnimationManager.js +483 -0
- package/lib/threebox-plugin/src/camera/CameraSync.js +302 -0
- package/lib/threebox-plugin/src/objects/CSS2DRenderer.js +245 -0
- package/lib/threebox-plugin/src/objects/LabelRenderer.js +71 -0
- package/lib/threebox-plugin/src/objects/Object3D.js +34 -0
- package/lib/threebox-plugin/src/objects/effects/BuildingShadows.js +115 -0
- package/lib/threebox-plugin/src/objects/extrusion.js +61 -0
- package/lib/threebox-plugin/src/objects/fflate.min.js +15 -0
- package/lib/threebox-plugin/src/objects/label.js +29 -0
- package/lib/threebox-plugin/src/objects/line.js +1386 -0
- package/lib/threebox-plugin/src/objects/loadObj.js +142 -0
- package/lib/threebox-plugin/src/objects/loaders/ColladaLoader.js +3751 -0
- package/lib/threebox-plugin/src/objects/loaders/FBXLoader.js +3864 -0
- package/lib/threebox-plugin/src/objects/loaders/GLTFLoader.js +3857 -0
- package/lib/threebox-plugin/src/objects/loaders/MTLLoader.js +498 -0
- package/lib/threebox-plugin/src/objects/loaders/OBJLoader.js +818 -0
- package/lib/threebox-plugin/src/objects/objects.js +1113 -0
- package/lib/threebox-plugin/src/objects/sphere.js +28 -0
- package/lib/threebox-plugin/src/objects/tooltip.js +27 -0
- package/lib/threebox-plugin/src/objects/tube.js +35 -0
- package/lib/threebox-plugin/src/three.js +6 -0
- package/lib/threebox-plugin/src/three.module.js +54571 -0
- package/lib/threebox-plugin/src/utils/ValueGenerator.js +11 -0
- package/lib/threebox-plugin/src/utils/constants.js +21 -0
- package/lib/threebox-plugin/src/utils/material.js +52 -0
- package/lib/threebox-plugin/src/utils/suncalc.js +322 -0
- package/lib/threebox-plugin/src/utils/utils.js +424 -0
- package/lib/threebox-plugin/src/utils/validate.js +115 -0
- package/package.json +18 -18
- package/src/components/EasyMapMarker.js +8 -0
- package/src/components/control/DrawBar.js +5 -0
- package/src/components/control/TilesBar.js +116 -27
- package/src/components/control/Toobars.js +20 -1
- package/src/components/layer/AlarmLayer.js +4 -1
- package/src/components/layer/AnimationBarbsLayer.js +1 -1
- package/src/components/layer/AnimationLayer copy.js +1 -1
- package/src/components/layer/AnimationLayer.js +11 -3
- package/src/components/layer/CustomIconLayer.js +1 -1
- package/src/components/layer/ExtrusionLayer.js +1 -1
- package/src/components/layer/ExtrusionLayerold.js +2 -1
- package/src/components/layer/MarkerAreaLayer.js +1 -1
- package/src/components/layer/PathLineLayer.js +1 -1
- package/src/components/layer/ThreeScanLayer.js +51 -14
- package/src/components/layer/ThreeWallLayer.js +1 -1
- package/webpack.config.js +2 -1
|
@@ -0,0 +1,3864 @@
|
|
|
1
|
+
|
|
2
|
+
import * as THREE from '../../three.module.js'
|
|
3
|
+
import fflate from '../fflate.min.js'
|
|
4
|
+
//const fflate = require('../fflate.min.js');
|
|
5
|
+
|
|
6
|
+
/**co
|
|
7
|
+
* @author Kyle-Larson https://github.com/Kyle-Larson
|
|
8
|
+
* @author Takahiro https://github.com/takahirox
|
|
9
|
+
* @author Lewy Blue https://github.com/looeee
|
|
10
|
+
*
|
|
11
|
+
* Loader loads FBX file and generates Group representing FBX scene.
|
|
12
|
+
* Requires FBX file to be >= 7.0 and in ASCII or >= 6400 in Binary format
|
|
13
|
+
* Versions lower than this may load but will probably have errors
|
|
14
|
+
*
|
|
15
|
+
* Needs Support:
|
|
16
|
+
* Morph normals / blend shape normals
|
|
17
|
+
*
|
|
18
|
+
* FBX format references:
|
|
19
|
+
* https://wiki.blender.org/index.php/User:Mont29/Foundation/FBX_File_Structure
|
|
20
|
+
* http://help.autodesk.com/view/FBX/2017/ENU/?guid=__cpp_ref_index_html (C++ SDK reference)
|
|
21
|
+
*
|
|
22
|
+
* Binary format specification:
|
|
23
|
+
* https://code.blender.org/2013/08/fbx-binary-file-format-specification/
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Loader loads FBX file and generates Group representing FBX scene.
|
|
29
|
+
* Requires FBX file to be >= 7.0 and in ASCII or >= 6400 in Binary format
|
|
30
|
+
* Versions lower than this may load but will probably have errors
|
|
31
|
+
*
|
|
32
|
+
* Needs Support:
|
|
33
|
+
* Morph normals / blend shape normals
|
|
34
|
+
*
|
|
35
|
+
* FBX format references:
|
|
36
|
+
* https://wiki.blender.org/index.php/User:Mont29/Foundation/FBX_File_Structure
|
|
37
|
+
* http://help.autodesk.com/view/FBX/2017/ENU/?guid=__cpp_ref_index_html (C++ SDK reference)
|
|
38
|
+
*
|
|
39
|
+
* Binary format specification:
|
|
40
|
+
* https://code.blender.org/2013/08/fbx-binary-file-format-specification/
|
|
41
|
+
*/
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
// (function () {
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* THREE.Loader loads FBX file and generates THREE.Group representing FBX scene.
|
|
48
|
+
* Requires FBX file to be >= 7.0 and in ASCII or >= 6400 in Binary format
|
|
49
|
+
* Versions lower than this may load but will probably have errors
|
|
50
|
+
*
|
|
51
|
+
* Needs Support:
|
|
52
|
+
* Morph normals / blend shape normals
|
|
53
|
+
*
|
|
54
|
+
* FBX format references:
|
|
55
|
+
* https://wiki.blender.org/index.php/User:Mont29/Foundation/FBX_File_Structure
|
|
56
|
+
* http://help.autodesk.com/view/FBX/2017/ENU/?guid=__cpp_ref_index_html (C++ SDK reference)
|
|
57
|
+
*
|
|
58
|
+
* Binary format specification:
|
|
59
|
+
* https://code.blender.org/2013/08/fbx-binary-file-format-specification/
|
|
60
|
+
*/
|
|
61
|
+
|
|
62
|
+
let fbxTree;
|
|
63
|
+
let connections;
|
|
64
|
+
let sceneGraph;
|
|
65
|
+
|
|
66
|
+
class FBXLoader extends THREE.Loader {
|
|
67
|
+
|
|
68
|
+
constructor(manager) {
|
|
69
|
+
|
|
70
|
+
super(manager);
|
|
71
|
+
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
load(url, onLoad, onProgress, onError) {
|
|
75
|
+
|
|
76
|
+
const scope = this;
|
|
77
|
+
const path = scope.path === '' ? THREE.LoaderUtils.extractUrlBase(url) : scope.path;
|
|
78
|
+
const loader = new THREE.FileLoader(this.manager);
|
|
79
|
+
loader.setPath(scope.path);
|
|
80
|
+
loader.setResponseType('arraybuffer');
|
|
81
|
+
loader.setRequestHeader(scope.requestHeader);
|
|
82
|
+
loader.setWithCredentials(scope.withCredentials);
|
|
83
|
+
loader.load(url, function (buffer) {
|
|
84
|
+
|
|
85
|
+
try {
|
|
86
|
+
|
|
87
|
+
onLoad(scope.parse(buffer, path));
|
|
88
|
+
|
|
89
|
+
} catch (e) {
|
|
90
|
+
|
|
91
|
+
if (onError) {
|
|
92
|
+
|
|
93
|
+
onError(e);
|
|
94
|
+
|
|
95
|
+
} else {
|
|
96
|
+
|
|
97
|
+
console.error(e);
|
|
98
|
+
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
scope.manager.itemError(url);
|
|
102
|
+
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
}, onProgress, onError);
|
|
106
|
+
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
parse(FBXBuffer, path) {
|
|
110
|
+
|
|
111
|
+
if (isFbxFormatBinary(FBXBuffer)) {
|
|
112
|
+
|
|
113
|
+
fbxTree = new BinaryParser().parse(FBXBuffer);
|
|
114
|
+
|
|
115
|
+
} else {
|
|
116
|
+
|
|
117
|
+
const FBXText = convertArrayBufferToString(FBXBuffer);
|
|
118
|
+
|
|
119
|
+
if (!isFbxFormatASCII(FBXText)) {
|
|
120
|
+
|
|
121
|
+
throw new Error('THREE.FBXLoader: Unknown format.');
|
|
122
|
+
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if (getFbxVersion(FBXText) < 7000) {
|
|
126
|
+
|
|
127
|
+
throw new Error('THREE.FBXLoader: FBX version not supported, FileVersion: ' + getFbxVersion(FBXText));
|
|
128
|
+
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
fbxTree = new TextParser().parse(FBXText);
|
|
132
|
+
|
|
133
|
+
} // console.log( fbxTree );
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
const textureLoader = new THREE.TextureLoader(this.manager).setPath(this.resourcePath || path).setCrossOrigin(this.crossOrigin);
|
|
137
|
+
return new FBXTreeParser(textureLoader, this.manager).parse(fbxTree);
|
|
138
|
+
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
} // Parse the FBXTree object returned by the BinaryParser or TextParser and return a THREE.Group
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
class FBXTreeParser {
|
|
145
|
+
|
|
146
|
+
constructor(textureLoader, manager) {
|
|
147
|
+
|
|
148
|
+
this.textureLoader = textureLoader;
|
|
149
|
+
this.manager = manager;
|
|
150
|
+
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
parse() {
|
|
154
|
+
|
|
155
|
+
connections = this.parseConnections();
|
|
156
|
+
const images = this.parseImages();
|
|
157
|
+
const textures = this.parseTextures(images);
|
|
158
|
+
const materials = this.parseMaterials(textures);
|
|
159
|
+
const deformers = this.parseDeformers();
|
|
160
|
+
const geometryMap = new GeometryParser().parse(deformers);
|
|
161
|
+
this.parseScene(deformers, geometryMap, materials);
|
|
162
|
+
return sceneGraph;
|
|
163
|
+
|
|
164
|
+
} // Parses FBXTree.Connections which holds parent-child connections between objects (e.g. material -> texture, model->geometry )
|
|
165
|
+
// and details the connection type
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
parseConnections() {
|
|
169
|
+
|
|
170
|
+
const connectionMap = new Map();
|
|
171
|
+
|
|
172
|
+
if ('Connections' in fbxTree) {
|
|
173
|
+
|
|
174
|
+
const rawConnections = fbxTree.Connections.connections;
|
|
175
|
+
rawConnections.forEach(function (rawConnection) {
|
|
176
|
+
|
|
177
|
+
const fromID = rawConnection[0];
|
|
178
|
+
const toID = rawConnection[1];
|
|
179
|
+
const relationship = rawConnection[2];
|
|
180
|
+
|
|
181
|
+
if (!connectionMap.has(fromID)) {
|
|
182
|
+
|
|
183
|
+
connectionMap.set(fromID, {
|
|
184
|
+
parents: [],
|
|
185
|
+
children: []
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
const parentRelationship = {
|
|
191
|
+
ID: toID,
|
|
192
|
+
relationship: relationship
|
|
193
|
+
};
|
|
194
|
+
connectionMap.get(fromID).parents.push(parentRelationship);
|
|
195
|
+
|
|
196
|
+
if (!connectionMap.has(toID)) {
|
|
197
|
+
|
|
198
|
+
connectionMap.set(toID, {
|
|
199
|
+
parents: [],
|
|
200
|
+
children: []
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
const childRelationship = {
|
|
206
|
+
ID: fromID,
|
|
207
|
+
relationship: relationship
|
|
208
|
+
};
|
|
209
|
+
connectionMap.get(toID).children.push(childRelationship);
|
|
210
|
+
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
return connectionMap;
|
|
216
|
+
|
|
217
|
+
} // Parse FBXTree.Objects.Video for embedded image data
|
|
218
|
+
// These images are connected to textures in FBXTree.Objects.Textures
|
|
219
|
+
// via FBXTree.Connections.
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
parseImages() {
|
|
223
|
+
|
|
224
|
+
const images = {};
|
|
225
|
+
const blobs = {};
|
|
226
|
+
|
|
227
|
+
if ('Video' in fbxTree.Objects) {
|
|
228
|
+
|
|
229
|
+
const videoNodes = fbxTree.Objects.Video;
|
|
230
|
+
|
|
231
|
+
for (const nodeID in videoNodes) {
|
|
232
|
+
|
|
233
|
+
const videoNode = videoNodes[nodeID];
|
|
234
|
+
const id = parseInt(nodeID);
|
|
235
|
+
images[id] = videoNode.RelativeFilename || videoNode.Filename; // raw image data is in videoNode.Content
|
|
236
|
+
|
|
237
|
+
if ('Content' in videoNode) {
|
|
238
|
+
|
|
239
|
+
const arrayBufferContent = videoNode.Content instanceof ArrayBuffer && videoNode.Content.byteLength > 0;
|
|
240
|
+
const base64Content = typeof videoNode.Content === 'string' && videoNode.Content !== '';
|
|
241
|
+
|
|
242
|
+
if (arrayBufferContent || base64Content) {
|
|
243
|
+
|
|
244
|
+
const image = this.parseImage(videoNodes[nodeID]);
|
|
245
|
+
blobs[videoNode.RelativeFilename || videoNode.Filename] = image;
|
|
246
|
+
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
for (const id in images) {
|
|
256
|
+
|
|
257
|
+
const filename = images[id];
|
|
258
|
+
if (blobs[filename] !== undefined) images[id] = blobs[filename]; else images[id] = images[id].split('\\').pop();
|
|
259
|
+
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
return images;
|
|
263
|
+
|
|
264
|
+
} // Parse embedded image data in FBXTree.Video.Content
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
parseImage(videoNode) {
|
|
268
|
+
|
|
269
|
+
const content = videoNode.Content;
|
|
270
|
+
const fileName = videoNode.RelativeFilename || videoNode.Filename;
|
|
271
|
+
const extension = fileName.slice(fileName.lastIndexOf('.') + 1).toLowerCase();
|
|
272
|
+
let type;
|
|
273
|
+
|
|
274
|
+
switch (extension) {
|
|
275
|
+
|
|
276
|
+
case 'bmp':
|
|
277
|
+
type = 'image/bmp';
|
|
278
|
+
break;
|
|
279
|
+
|
|
280
|
+
case 'jpg':
|
|
281
|
+
case 'jpeg':
|
|
282
|
+
type = 'image/jpeg';
|
|
283
|
+
break;
|
|
284
|
+
|
|
285
|
+
case 'png':
|
|
286
|
+
type = 'image/png';
|
|
287
|
+
break;
|
|
288
|
+
|
|
289
|
+
case 'tif':
|
|
290
|
+
type = 'image/tiff';
|
|
291
|
+
break;
|
|
292
|
+
|
|
293
|
+
case 'tga':
|
|
294
|
+
if (this.manager.getHandler('.tga') === null) {
|
|
295
|
+
|
|
296
|
+
console.warn('FBXLoader: TGA loader not found, skipping ', fileName);
|
|
297
|
+
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
type = 'image/tga';
|
|
301
|
+
break;
|
|
302
|
+
|
|
303
|
+
default:
|
|
304
|
+
console.warn('FBXLoader: Image type "' + extension + '" is not supported.');
|
|
305
|
+
return;
|
|
306
|
+
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
if (typeof content === 'string') {
|
|
310
|
+
|
|
311
|
+
// ASCII format
|
|
312
|
+
return 'data:' + type + ';base64,' + content;
|
|
313
|
+
|
|
314
|
+
} else {
|
|
315
|
+
|
|
316
|
+
// Binary Format
|
|
317
|
+
const array = new Uint8Array(content);
|
|
318
|
+
return window.URL.createObjectURL(new Blob([array], {
|
|
319
|
+
type: type
|
|
320
|
+
}));
|
|
321
|
+
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
} // Parse nodes in FBXTree.Objects.Texture
|
|
325
|
+
// These contain details such as UV scaling, cropping, rotation etc and are connected
|
|
326
|
+
// to images in FBXTree.Objects.Video
|
|
327
|
+
|
|
328
|
+
|
|
329
|
+
parseTextures(images) {
|
|
330
|
+
|
|
331
|
+
const textureMap = new Map();
|
|
332
|
+
|
|
333
|
+
if ('Texture' in fbxTree.Objects) {
|
|
334
|
+
|
|
335
|
+
const textureNodes = fbxTree.Objects.Texture;
|
|
336
|
+
|
|
337
|
+
for (const nodeID in textureNodes) {
|
|
338
|
+
|
|
339
|
+
const texture = this.parseTexture(textureNodes[nodeID], images);
|
|
340
|
+
textureMap.set(parseInt(nodeID), texture);
|
|
341
|
+
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
return textureMap;
|
|
347
|
+
|
|
348
|
+
} // Parse individual node in FBXTree.Objects.Texture
|
|
349
|
+
|
|
350
|
+
|
|
351
|
+
parseTexture(textureNode, images) {
|
|
352
|
+
|
|
353
|
+
const texture = this.loadTexture(textureNode, images);
|
|
354
|
+
texture.ID = textureNode.id;
|
|
355
|
+
texture.name = textureNode.attrName;
|
|
356
|
+
const wrapModeU = textureNode.WrapModeU;
|
|
357
|
+
const wrapModeV = textureNode.WrapModeV;
|
|
358
|
+
const valueU = wrapModeU !== undefined ? wrapModeU.value : 0;
|
|
359
|
+
const valueV = wrapModeV !== undefined ? wrapModeV.value : 0; // http://download.autodesk.com/us/fbx/SDKdocs/FBX_SDK_Help/files/fbxsdkref/class_k_fbx_texture.html#889640e63e2e681259ea81061b85143a
|
|
360
|
+
// 0: repeat(default), 1: clamp
|
|
361
|
+
|
|
362
|
+
texture.wrapS = valueU === 0 ? THREE.RepeatWrapping : THREE.ClampToEdgeWrapping;
|
|
363
|
+
texture.wrapT = valueV === 0 ? THREE.RepeatWrapping : THREE.ClampToEdgeWrapping;
|
|
364
|
+
|
|
365
|
+
if ('Scaling' in textureNode) {
|
|
366
|
+
|
|
367
|
+
const values = textureNode.Scaling.value;
|
|
368
|
+
texture.repeat.x = values[0];
|
|
369
|
+
texture.repeat.y = values[1];
|
|
370
|
+
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
return texture;
|
|
374
|
+
|
|
375
|
+
} // load a texture specified as a blob or data URI, or via an external URL using THREE.TextureLoader
|
|
376
|
+
|
|
377
|
+
|
|
378
|
+
loadTexture(textureNode, images) {
|
|
379
|
+
|
|
380
|
+
let fileName;
|
|
381
|
+
const currentPath = this.textureLoader.path;
|
|
382
|
+
const children = connections.get(textureNode.id).children;
|
|
383
|
+
|
|
384
|
+
if (children !== undefined && children.length > 0 && images[children[0].ID] !== undefined) {
|
|
385
|
+
|
|
386
|
+
fileName = images[children[0].ID];
|
|
387
|
+
|
|
388
|
+
if (fileName.indexOf('blob:') === 0 || fileName.indexOf('data:') === 0) {
|
|
389
|
+
|
|
390
|
+
this.textureLoader.setPath(undefined);
|
|
391
|
+
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
let texture;
|
|
397
|
+
const extension = textureNode.FileName.slice(- 3).toLowerCase();
|
|
398
|
+
|
|
399
|
+
if (extension === 'tga') {
|
|
400
|
+
|
|
401
|
+
const loader = this.manager.getHandler('.tga');
|
|
402
|
+
|
|
403
|
+
if (loader === null) {
|
|
404
|
+
|
|
405
|
+
console.warn('FBXLoader: TGA loader not found, creating placeholder texture for', textureNode.RelativeFilename);
|
|
406
|
+
texture = new THREE.Texture();
|
|
407
|
+
|
|
408
|
+
} else {
|
|
409
|
+
|
|
410
|
+
loader.setPath(this.textureLoader.path);
|
|
411
|
+
texture = loader.load(fileName);
|
|
412
|
+
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
} else if (extension === 'psd') {
|
|
416
|
+
|
|
417
|
+
console.warn('FBXLoader: PSD textures are not supported, creating placeholder texture for', textureNode.RelativeFilename);
|
|
418
|
+
texture = new THREE.Texture();
|
|
419
|
+
|
|
420
|
+
} else {
|
|
421
|
+
|
|
422
|
+
texture = this.textureLoader.load(fileName);
|
|
423
|
+
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
this.textureLoader.setPath(currentPath);
|
|
427
|
+
return texture;
|
|
428
|
+
|
|
429
|
+
} // Parse nodes in FBXTree.Objects.Material
|
|
430
|
+
|
|
431
|
+
|
|
432
|
+
parseMaterials(textureMap) {
|
|
433
|
+
|
|
434
|
+
const materialMap = new Map();
|
|
435
|
+
|
|
436
|
+
if ('Material' in fbxTree.Objects) {
|
|
437
|
+
|
|
438
|
+
const materialNodes = fbxTree.Objects.Material;
|
|
439
|
+
|
|
440
|
+
for (const nodeID in materialNodes) {
|
|
441
|
+
|
|
442
|
+
const material = this.parseMaterial(materialNodes[nodeID], textureMap);
|
|
443
|
+
if (material !== null) materialMap.set(parseInt(nodeID), material);
|
|
444
|
+
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
return materialMap;
|
|
450
|
+
|
|
451
|
+
} // Parse single node in FBXTree.Objects.Material
|
|
452
|
+
// Materials are connected to texture maps in FBXTree.Objects.Textures
|
|
453
|
+
// FBX format currently only supports Lambert and Phong shading models
|
|
454
|
+
|
|
455
|
+
|
|
456
|
+
parseMaterial(materialNode, textureMap) {
|
|
457
|
+
|
|
458
|
+
const ID = materialNode.id;
|
|
459
|
+
const name = materialNode.attrName;
|
|
460
|
+
let type = materialNode.ShadingModel; // Case where FBX wraps shading model in property object.
|
|
461
|
+
|
|
462
|
+
if (typeof type === 'object') {
|
|
463
|
+
|
|
464
|
+
type = type.value;
|
|
465
|
+
|
|
466
|
+
} // Ignore unused materials which don't have any connections.
|
|
467
|
+
|
|
468
|
+
|
|
469
|
+
if (!connections.has(ID)) return null;
|
|
470
|
+
const parameters = this.parseParameters(materialNode, textureMap, ID);
|
|
471
|
+
let material;
|
|
472
|
+
|
|
473
|
+
switch (type.toLowerCase()) {
|
|
474
|
+
|
|
475
|
+
case 'phong':
|
|
476
|
+
material = new THREE.MeshPhongMaterial();
|
|
477
|
+
break;
|
|
478
|
+
|
|
479
|
+
case 'lambert':
|
|
480
|
+
material = new THREE.MeshLambertMaterial();
|
|
481
|
+
break;
|
|
482
|
+
|
|
483
|
+
default:
|
|
484
|
+
console.warn('THREE.FBXLoader: unknown material type "%s". Defaulting to THREE.MeshPhongMaterial.', type);
|
|
485
|
+
material = new THREE.MeshPhongMaterial();
|
|
486
|
+
break;
|
|
487
|
+
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
material.setValues(parameters);
|
|
491
|
+
material.name = name;
|
|
492
|
+
return material;
|
|
493
|
+
|
|
494
|
+
} // Parse FBX material and return parameters suitable for a three.js material
|
|
495
|
+
// Also parse the texture map and return any textures associated with the material
|
|
496
|
+
|
|
497
|
+
|
|
498
|
+
parseParameters(materialNode, textureMap, ID) {
|
|
499
|
+
|
|
500
|
+
const parameters = {};
|
|
501
|
+
|
|
502
|
+
if (materialNode.BumpFactor) {
|
|
503
|
+
|
|
504
|
+
parameters.bumpScale = materialNode.BumpFactor.value;
|
|
505
|
+
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
if (materialNode.Diffuse) {
|
|
509
|
+
|
|
510
|
+
parameters.color = new THREE.Color().fromArray(materialNode.Diffuse.value);
|
|
511
|
+
|
|
512
|
+
} else if (materialNode.DiffuseColor && (materialNode.DiffuseColor.type === 'Color' || materialNode.DiffuseColor.type === 'ColorRGB')) {
|
|
513
|
+
|
|
514
|
+
// The blender exporter exports diffuse here instead of in materialNode.Diffuse
|
|
515
|
+
parameters.color = new THREE.Color().fromArray(materialNode.DiffuseColor.value);
|
|
516
|
+
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
if (materialNode.DisplacementFactor) {
|
|
520
|
+
|
|
521
|
+
parameters.displacementScale = materialNode.DisplacementFactor.value;
|
|
522
|
+
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
if (materialNode.Emissive) {
|
|
526
|
+
|
|
527
|
+
parameters.emissive = new THREE.Color().fromArray(materialNode.Emissive.value);
|
|
528
|
+
|
|
529
|
+
} else if (materialNode.EmissiveColor && (materialNode.EmissiveColor.type === 'Color' || materialNode.EmissiveColor.type === 'ColorRGB')) {
|
|
530
|
+
|
|
531
|
+
// The blender exporter exports emissive color here instead of in materialNode.Emissive
|
|
532
|
+
parameters.emissive = new THREE.Color().fromArray(materialNode.EmissiveColor.value);
|
|
533
|
+
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
if (materialNode.EmissiveFactor) {
|
|
537
|
+
|
|
538
|
+
parameters.emissiveIntensity = parseFloat(materialNode.EmissiveFactor.value);
|
|
539
|
+
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
if (materialNode.Opacity) {
|
|
543
|
+
|
|
544
|
+
parameters.opacity = parseFloat(materialNode.Opacity.value);
|
|
545
|
+
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
if (parameters.opacity < 1.0) {
|
|
549
|
+
|
|
550
|
+
parameters.transparent = true;
|
|
551
|
+
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
if (materialNode.ReflectionFactor) {
|
|
555
|
+
|
|
556
|
+
parameters.reflectivity = materialNode.ReflectionFactor.value;
|
|
557
|
+
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
if (materialNode.Shininess) {
|
|
561
|
+
|
|
562
|
+
parameters.shininess = materialNode.Shininess.value;
|
|
563
|
+
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
if (materialNode.Specular) {
|
|
567
|
+
|
|
568
|
+
parameters.specular = new THREE.Color().fromArray(materialNode.Specular.value);
|
|
569
|
+
|
|
570
|
+
} else if (materialNode.SpecularColor && materialNode.SpecularColor.type === 'Color') {
|
|
571
|
+
|
|
572
|
+
// The blender exporter exports specular color here instead of in materialNode.Specular
|
|
573
|
+
parameters.specular = new THREE.Color().fromArray(materialNode.SpecularColor.value);
|
|
574
|
+
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
const scope = this;
|
|
578
|
+
connections.get(ID).children.forEach(function (child) {
|
|
579
|
+
|
|
580
|
+
const type = child.relationship;
|
|
581
|
+
|
|
582
|
+
switch (type) {
|
|
583
|
+
|
|
584
|
+
case 'Bump':
|
|
585
|
+
parameters.bumpMap = scope.getTexture(textureMap, child.ID);
|
|
586
|
+
break;
|
|
587
|
+
|
|
588
|
+
case 'Maya|TEX_ao_map':
|
|
589
|
+
parameters.aoMap = scope.getTexture(textureMap, child.ID);
|
|
590
|
+
break;
|
|
591
|
+
|
|
592
|
+
case 'DiffuseColor':
|
|
593
|
+
case 'Maya|TEX_color_map':
|
|
594
|
+
parameters.map = scope.getTexture(textureMap, child.ID);
|
|
595
|
+
|
|
596
|
+
if (parameters.map !== undefined) {
|
|
597
|
+
|
|
598
|
+
parameters.map.encoding = THREE.sRGBEncoding;
|
|
599
|
+
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
break;
|
|
603
|
+
|
|
604
|
+
case 'DisplacementColor':
|
|
605
|
+
parameters.displacementMap = scope.getTexture(textureMap, child.ID);
|
|
606
|
+
break;
|
|
607
|
+
|
|
608
|
+
case 'EmissiveColor':
|
|
609
|
+
parameters.emissiveMap = scope.getTexture(textureMap, child.ID);
|
|
610
|
+
|
|
611
|
+
if (parameters.emissiveMap !== undefined) {
|
|
612
|
+
|
|
613
|
+
parameters.emissiveMap.encoding = THREE.sRGBEncoding;
|
|
614
|
+
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
break;
|
|
618
|
+
|
|
619
|
+
case 'NormalMap':
|
|
620
|
+
case 'Maya|TEX_normal_map':
|
|
621
|
+
parameters.normalMap = scope.getTexture(textureMap, child.ID);
|
|
622
|
+
break;
|
|
623
|
+
|
|
624
|
+
case 'ReflectionColor':
|
|
625
|
+
parameters.envMap = scope.getTexture(textureMap, child.ID);
|
|
626
|
+
|
|
627
|
+
if (parameters.envMap !== undefined) {
|
|
628
|
+
|
|
629
|
+
parameters.envMap.mapping = THREE.EquirectangularReflectionMapping;
|
|
630
|
+
parameters.envMap.encoding = THREE.sRGBEncoding;
|
|
631
|
+
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
break;
|
|
635
|
+
|
|
636
|
+
case 'SpecularColor':
|
|
637
|
+
parameters.specularMap = scope.getTexture(textureMap, child.ID);
|
|
638
|
+
|
|
639
|
+
if (parameters.specularMap !== undefined) {
|
|
640
|
+
|
|
641
|
+
parameters.specularMap.encoding = THREE.sRGBEncoding;
|
|
642
|
+
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
break;
|
|
646
|
+
|
|
647
|
+
case 'TransparentColor':
|
|
648
|
+
case 'TransparencyFactor':
|
|
649
|
+
parameters.alphaMap = scope.getTexture(textureMap, child.ID);
|
|
650
|
+
parameters.transparent = true;
|
|
651
|
+
break;
|
|
652
|
+
|
|
653
|
+
case 'AmbientColor':
|
|
654
|
+
case 'ShininessExponent': // AKA glossiness map
|
|
655
|
+
|
|
656
|
+
case 'SpecularFactor': // AKA specularLevel
|
|
657
|
+
|
|
658
|
+
case 'VectorDisplacementColor': // NOTE: Seems to be a copy of DisplacementColor
|
|
659
|
+
|
|
660
|
+
default:
|
|
661
|
+
console.warn('THREE.FBXLoader: %s map is not supported in three.js, skipping texture.', type);
|
|
662
|
+
break;
|
|
663
|
+
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
});
|
|
667
|
+
return parameters;
|
|
668
|
+
|
|
669
|
+
} // get a texture from the textureMap for use by a material.
|
|
670
|
+
|
|
671
|
+
|
|
672
|
+
getTexture(textureMap, id) {
|
|
673
|
+
|
|
674
|
+
// if the texture is a layered texture, just use the first layer and issue a warning
|
|
675
|
+
if ('LayeredTexture' in fbxTree.Objects && id in fbxTree.Objects.LayeredTexture) {
|
|
676
|
+
|
|
677
|
+
console.warn('THREE.FBXLoader: layered textures are not supported in three.js. Discarding all but first layer.');
|
|
678
|
+
id = connections.get(id).children[0].ID;
|
|
679
|
+
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
return textureMap.get(id);
|
|
683
|
+
|
|
684
|
+
} // Parse nodes in FBXTree.Objects.Deformer
|
|
685
|
+
// Deformer node can contain skinning or Vertex Cache animation data, however only skinning is supported here
|
|
686
|
+
// Generates map of THREE.Skeleton-like objects for use later when generating and binding skeletons.
|
|
687
|
+
|
|
688
|
+
|
|
689
|
+
parseDeformers() {
|
|
690
|
+
|
|
691
|
+
const skeletons = {};
|
|
692
|
+
const morphTargets = {};
|
|
693
|
+
|
|
694
|
+
if ('Deformer' in fbxTree.Objects) {
|
|
695
|
+
|
|
696
|
+
const DeformerNodes = fbxTree.Objects.Deformer;
|
|
697
|
+
|
|
698
|
+
for (const nodeID in DeformerNodes) {
|
|
699
|
+
|
|
700
|
+
const deformerNode = DeformerNodes[nodeID];
|
|
701
|
+
const relationships = connections.get(parseInt(nodeID));
|
|
702
|
+
|
|
703
|
+
if (deformerNode.attrType === 'Skin') {
|
|
704
|
+
|
|
705
|
+
const skeleton = this.parseSkeleton(relationships, DeformerNodes);
|
|
706
|
+
skeleton.ID = nodeID;
|
|
707
|
+
if (relationships.parents.length > 1) console.warn('THREE.FBXLoader: skeleton attached to more than one geometry is not supported.');
|
|
708
|
+
skeleton.geometryID = relationships.parents[0].ID;
|
|
709
|
+
skeletons[nodeID] = skeleton;
|
|
710
|
+
|
|
711
|
+
} else if (deformerNode.attrType === 'BlendShape') {
|
|
712
|
+
|
|
713
|
+
const morphTarget = {
|
|
714
|
+
id: nodeID
|
|
715
|
+
};
|
|
716
|
+
morphTarget.rawTargets = this.parseMorphTargets(relationships, DeformerNodes);
|
|
717
|
+
morphTarget.id = nodeID;
|
|
718
|
+
if (relationships.parents.length > 1) console.warn('THREE.FBXLoader: morph target attached to more than one geometry is not supported.');
|
|
719
|
+
morphTargets[nodeID] = morphTarget;
|
|
720
|
+
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
return {
|
|
728
|
+
skeletons: skeletons,
|
|
729
|
+
morphTargets: morphTargets
|
|
730
|
+
};
|
|
731
|
+
|
|
732
|
+
} // Parse single nodes in FBXTree.Objects.Deformer
|
|
733
|
+
// The top level skeleton node has type 'Skin' and sub nodes have type 'Cluster'
|
|
734
|
+
// Each skin node represents a skeleton and each cluster node represents a bone
|
|
735
|
+
|
|
736
|
+
|
|
737
|
+
parseSkeleton(relationships, deformerNodes) {
|
|
738
|
+
|
|
739
|
+
const rawBones = [];
|
|
740
|
+
relationships.children.forEach(function (child) {
|
|
741
|
+
|
|
742
|
+
const boneNode = deformerNodes[child.ID];
|
|
743
|
+
if (boneNode.attrType !== 'Cluster') return;
|
|
744
|
+
const rawBone = {
|
|
745
|
+
ID: child.ID,
|
|
746
|
+
indices: [],
|
|
747
|
+
weights: [],
|
|
748
|
+
transformLink: new THREE.Matrix4().fromArray(boneNode.TransformLink.a) // transform: new THREE.Matrix4().fromArray( boneNode.Transform.a ),
|
|
749
|
+
// linkMode: boneNode.Mode,
|
|
750
|
+
|
|
751
|
+
};
|
|
752
|
+
|
|
753
|
+
if ('Indexes' in boneNode) {
|
|
754
|
+
|
|
755
|
+
rawBone.indices = boneNode.Indexes.a;
|
|
756
|
+
rawBone.weights = boneNode.Weights.a;
|
|
757
|
+
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
rawBones.push(rawBone);
|
|
761
|
+
|
|
762
|
+
});
|
|
763
|
+
return {
|
|
764
|
+
rawBones: rawBones,
|
|
765
|
+
bones: []
|
|
766
|
+
};
|
|
767
|
+
|
|
768
|
+
} // The top level morph deformer node has type "BlendShape" and sub nodes have type "BlendShapeChannel"
|
|
769
|
+
|
|
770
|
+
|
|
771
|
+
parseMorphTargets(relationships, deformerNodes) {
|
|
772
|
+
|
|
773
|
+
const rawMorphTargets = [];
|
|
774
|
+
|
|
775
|
+
for (let i = 0; i < relationships.children.length; i++) {
|
|
776
|
+
|
|
777
|
+
const child = relationships.children[i];
|
|
778
|
+
const morphTargetNode = deformerNodes[child.ID];
|
|
779
|
+
const rawMorphTarget = {
|
|
780
|
+
name: morphTargetNode.attrName,
|
|
781
|
+
initialWeight: morphTargetNode.DeformPercent,
|
|
782
|
+
id: morphTargetNode.id,
|
|
783
|
+
fullWeights: morphTargetNode.FullWeights.a
|
|
784
|
+
};
|
|
785
|
+
if (morphTargetNode.attrType !== 'BlendShapeChannel') return;
|
|
786
|
+
rawMorphTarget.geoID = connections.get(parseInt(child.ID)).children.filter(function (child) {
|
|
787
|
+
|
|
788
|
+
return child.relationship === undefined;
|
|
789
|
+
|
|
790
|
+
})[0].ID;
|
|
791
|
+
rawMorphTargets.push(rawMorphTarget);
|
|
792
|
+
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
return rawMorphTargets;
|
|
796
|
+
|
|
797
|
+
} // create the main THREE.Group() to be returned by the loader
|
|
798
|
+
|
|
799
|
+
|
|
800
|
+
parseScene(deformers, geometryMap, materialMap) {
|
|
801
|
+
|
|
802
|
+
sceneGraph = new THREE.Group();
|
|
803
|
+
const modelMap = this.parseModels(deformers.skeletons, geometryMap, materialMap);
|
|
804
|
+
const modelNodes = fbxTree.Objects.Model;
|
|
805
|
+
const scope = this;
|
|
806
|
+
modelMap.forEach(function (model) {
|
|
807
|
+
|
|
808
|
+
const modelNode = modelNodes[model.ID];
|
|
809
|
+
scope.setLookAtProperties(model, modelNode);
|
|
810
|
+
const parentConnections = connections.get(model.ID).parents;
|
|
811
|
+
parentConnections.forEach(function (connection) {
|
|
812
|
+
|
|
813
|
+
const parent = modelMap.get(connection.ID);
|
|
814
|
+
if (parent !== undefined) parent.add(model);
|
|
815
|
+
|
|
816
|
+
});
|
|
817
|
+
|
|
818
|
+
if (model.parent === null) {
|
|
819
|
+
|
|
820
|
+
sceneGraph.add(model);
|
|
821
|
+
|
|
822
|
+
}
|
|
823
|
+
|
|
824
|
+
});
|
|
825
|
+
this.bindSkeleton(deformers.skeletons, geometryMap, modelMap);
|
|
826
|
+
this.createAmbientLight();
|
|
827
|
+
sceneGraph.traverse(function (node) {
|
|
828
|
+
|
|
829
|
+
if (node.userData.transformData) {
|
|
830
|
+
|
|
831
|
+
if (node.parent) {
|
|
832
|
+
|
|
833
|
+
node.userData.transformData.parentMatrix = node.parent.matrix;
|
|
834
|
+
node.userData.transformData.parentMatrixWorld = node.parent.matrixWorld;
|
|
835
|
+
|
|
836
|
+
}
|
|
837
|
+
|
|
838
|
+
const transform = generateTransform(node.userData.transformData);
|
|
839
|
+
node.applyMatrix4(transform);
|
|
840
|
+
node.updateWorldMatrix();
|
|
841
|
+
|
|
842
|
+
}
|
|
843
|
+
|
|
844
|
+
});
|
|
845
|
+
const animations = new AnimationParser().parse(); // if all the models where already combined in a single group, just return that
|
|
846
|
+
|
|
847
|
+
if (sceneGraph.children.length === 1 && sceneGraph.children[0].isGroup) {
|
|
848
|
+
|
|
849
|
+
sceneGraph.children[0].animations = animations;
|
|
850
|
+
sceneGraph = sceneGraph.children[0];
|
|
851
|
+
|
|
852
|
+
}
|
|
853
|
+
|
|
854
|
+
sceneGraph.animations = animations;
|
|
855
|
+
|
|
856
|
+
} // parse nodes in FBXTree.Objects.Model
|
|
857
|
+
|
|
858
|
+
|
|
859
|
+
parseModels(skeletons, geometryMap, materialMap) {
|
|
860
|
+
|
|
861
|
+
const modelMap = new Map();
|
|
862
|
+
const modelNodes = fbxTree.Objects.Model;
|
|
863
|
+
|
|
864
|
+
for (const nodeID in modelNodes) {
|
|
865
|
+
|
|
866
|
+
const id = parseInt(nodeID);
|
|
867
|
+
const node = modelNodes[nodeID];
|
|
868
|
+
const relationships = connections.get(id);
|
|
869
|
+
let model = this.buildSkeleton(relationships, skeletons, id, node.attrName);
|
|
870
|
+
|
|
871
|
+
if (!model) {
|
|
872
|
+
|
|
873
|
+
switch (node.attrType) {
|
|
874
|
+
|
|
875
|
+
case 'Camera':
|
|
876
|
+
model = this.createCamera(relationships);
|
|
877
|
+
break;
|
|
878
|
+
|
|
879
|
+
case 'Light':
|
|
880
|
+
model = this.createLight(relationships);
|
|
881
|
+
break;
|
|
882
|
+
|
|
883
|
+
case 'Mesh':
|
|
884
|
+
model = this.createMesh(relationships, geometryMap, materialMap);
|
|
885
|
+
break;
|
|
886
|
+
|
|
887
|
+
case 'NurbsCurve':
|
|
888
|
+
model = this.createCurve(relationships, geometryMap);
|
|
889
|
+
break;
|
|
890
|
+
|
|
891
|
+
case 'LimbNode':
|
|
892
|
+
case 'Root':
|
|
893
|
+
model = new THREE.Bone();
|
|
894
|
+
break;
|
|
895
|
+
|
|
896
|
+
case 'Null':
|
|
897
|
+
default:
|
|
898
|
+
model = new THREE.Group();
|
|
899
|
+
break;
|
|
900
|
+
|
|
901
|
+
}
|
|
902
|
+
|
|
903
|
+
model.name = node.attrName ? THREE.PropertyBinding.sanitizeNodeName(node.attrName) : '';
|
|
904
|
+
model.ID = id;
|
|
905
|
+
|
|
906
|
+
}
|
|
907
|
+
|
|
908
|
+
this.getTransformData(model, node);
|
|
909
|
+
modelMap.set(id, model);
|
|
910
|
+
|
|
911
|
+
}
|
|
912
|
+
|
|
913
|
+
return modelMap;
|
|
914
|
+
|
|
915
|
+
}
|
|
916
|
+
|
|
917
|
+
buildSkeleton(relationships, skeletons, id, name) {
|
|
918
|
+
|
|
919
|
+
let bone = null;
|
|
920
|
+
relationships.parents.forEach(function (parent) {
|
|
921
|
+
|
|
922
|
+
for (const ID in skeletons) {
|
|
923
|
+
|
|
924
|
+
const skeleton = skeletons[ID];
|
|
925
|
+
skeleton.rawBones.forEach(function (rawBone, i) {
|
|
926
|
+
|
|
927
|
+
if (rawBone.ID === parent.ID) {
|
|
928
|
+
|
|
929
|
+
const subBone = bone;
|
|
930
|
+
bone = new THREE.Bone();
|
|
931
|
+
bone.matrixWorld.copy(rawBone.transformLink); // set name and id here - otherwise in cases where "subBone" is created it will not have a name / id
|
|
932
|
+
|
|
933
|
+
bone.name = name ? THREE.PropertyBinding.sanitizeNodeName(name) : '';
|
|
934
|
+
bone.ID = id;
|
|
935
|
+
skeleton.bones[i] = bone; // In cases where a bone is shared between multiple meshes
|
|
936
|
+
// duplicate the bone here and and it as a child of the first bone
|
|
937
|
+
|
|
938
|
+
if (subBone !== null) {
|
|
939
|
+
|
|
940
|
+
bone.add(subBone);
|
|
941
|
+
|
|
942
|
+
}
|
|
943
|
+
|
|
944
|
+
}
|
|
945
|
+
|
|
946
|
+
});
|
|
947
|
+
|
|
948
|
+
}
|
|
949
|
+
|
|
950
|
+
});
|
|
951
|
+
return bone;
|
|
952
|
+
|
|
953
|
+
} // create a THREE.PerspectiveCamera or THREE.OrthographicCamera
|
|
954
|
+
|
|
955
|
+
|
|
956
|
+
createCamera(relationships) {
|
|
957
|
+
|
|
958
|
+
let model;
|
|
959
|
+
let cameraAttribute;
|
|
960
|
+
relationships.children.forEach(function (child) {
|
|
961
|
+
|
|
962
|
+
const attr = fbxTree.Objects.NodeAttribute[child.ID];
|
|
963
|
+
|
|
964
|
+
if (attr !== undefined) {
|
|
965
|
+
|
|
966
|
+
cameraAttribute = attr;
|
|
967
|
+
|
|
968
|
+
}
|
|
969
|
+
|
|
970
|
+
});
|
|
971
|
+
|
|
972
|
+
if (cameraAttribute === undefined) {
|
|
973
|
+
|
|
974
|
+
model = new THREE.Object3D();
|
|
975
|
+
|
|
976
|
+
} else {
|
|
977
|
+
|
|
978
|
+
let type = 0;
|
|
979
|
+
|
|
980
|
+
if (cameraAttribute.CameraProjectionType !== undefined && cameraAttribute.CameraProjectionType.value === 1) {
|
|
981
|
+
|
|
982
|
+
type = 1;
|
|
983
|
+
|
|
984
|
+
}
|
|
985
|
+
|
|
986
|
+
let nearClippingPlane = 1;
|
|
987
|
+
|
|
988
|
+
if (cameraAttribute.NearPlane !== undefined) {
|
|
989
|
+
|
|
990
|
+
nearClippingPlane = cameraAttribute.NearPlane.value / 1000;
|
|
991
|
+
|
|
992
|
+
}
|
|
993
|
+
|
|
994
|
+
let farClippingPlane = 1000;
|
|
995
|
+
|
|
996
|
+
if (cameraAttribute.FarPlane !== undefined) {
|
|
997
|
+
|
|
998
|
+
farClippingPlane = cameraAttribute.FarPlane.value / 1000;
|
|
999
|
+
|
|
1000
|
+
}
|
|
1001
|
+
|
|
1002
|
+
let width = window.innerWidth;
|
|
1003
|
+
let height = window.innerHeight;
|
|
1004
|
+
|
|
1005
|
+
if (cameraAttribute.AspectWidth !== undefined && cameraAttribute.AspectHeight !== undefined) {
|
|
1006
|
+
|
|
1007
|
+
width = cameraAttribute.AspectWidth.value;
|
|
1008
|
+
height = cameraAttribute.AspectHeight.value;
|
|
1009
|
+
|
|
1010
|
+
}
|
|
1011
|
+
|
|
1012
|
+
const aspect = width / height;
|
|
1013
|
+
let fov = 45;
|
|
1014
|
+
|
|
1015
|
+
if (cameraAttribute.FieldOfView !== undefined) {
|
|
1016
|
+
|
|
1017
|
+
fov = cameraAttribute.FieldOfView.value;
|
|
1018
|
+
|
|
1019
|
+
}
|
|
1020
|
+
|
|
1021
|
+
const focalLength = cameraAttribute.FocalLength ? cameraAttribute.FocalLength.value : null;
|
|
1022
|
+
|
|
1023
|
+
switch (type) {
|
|
1024
|
+
|
|
1025
|
+
case 0:
|
|
1026
|
+
// Perspective
|
|
1027
|
+
model = new THREE.PerspectiveCamera(fov, aspect, nearClippingPlane, farClippingPlane);
|
|
1028
|
+
if (focalLength !== null) model.setFocalLength(focalLength);
|
|
1029
|
+
break;
|
|
1030
|
+
|
|
1031
|
+
case 1:
|
|
1032
|
+
// Orthographic
|
|
1033
|
+
model = new THREE.OrthographicCamera(- width / 2, width / 2, height / 2, - height / 2, nearClippingPlane, farClippingPlane);
|
|
1034
|
+
break;
|
|
1035
|
+
|
|
1036
|
+
default:
|
|
1037
|
+
console.warn('THREE.FBXLoader: Unknown camera type ' + type + '.');
|
|
1038
|
+
model = new THREE.Object3D();
|
|
1039
|
+
break;
|
|
1040
|
+
|
|
1041
|
+
}
|
|
1042
|
+
|
|
1043
|
+
}
|
|
1044
|
+
|
|
1045
|
+
return model;
|
|
1046
|
+
|
|
1047
|
+
} // Create a THREE.DirectionalLight, THREE.PointLight or THREE.SpotLight
|
|
1048
|
+
|
|
1049
|
+
|
|
1050
|
+
createLight(relationships) {
|
|
1051
|
+
|
|
1052
|
+
let model;
|
|
1053
|
+
let lightAttribute;
|
|
1054
|
+
relationships.children.forEach(function (child) {
|
|
1055
|
+
|
|
1056
|
+
const attr = fbxTree.Objects.NodeAttribute[child.ID];
|
|
1057
|
+
|
|
1058
|
+
if (attr !== undefined) {
|
|
1059
|
+
|
|
1060
|
+
lightAttribute = attr;
|
|
1061
|
+
|
|
1062
|
+
}
|
|
1063
|
+
|
|
1064
|
+
});
|
|
1065
|
+
|
|
1066
|
+
if (lightAttribute === undefined) {
|
|
1067
|
+
|
|
1068
|
+
model = new THREE.Object3D();
|
|
1069
|
+
|
|
1070
|
+
} else {
|
|
1071
|
+
|
|
1072
|
+
let type; // LightType can be undefined for Point lights
|
|
1073
|
+
|
|
1074
|
+
if (lightAttribute.LightType === undefined) {
|
|
1075
|
+
|
|
1076
|
+
type = 0;
|
|
1077
|
+
|
|
1078
|
+
} else {
|
|
1079
|
+
|
|
1080
|
+
type = lightAttribute.LightType.value;
|
|
1081
|
+
|
|
1082
|
+
}
|
|
1083
|
+
|
|
1084
|
+
let color = 0xffffff;
|
|
1085
|
+
|
|
1086
|
+
if (lightAttribute.Color !== undefined) {
|
|
1087
|
+
|
|
1088
|
+
color = new THREE.Color().fromArray(lightAttribute.Color.value);
|
|
1089
|
+
|
|
1090
|
+
}
|
|
1091
|
+
|
|
1092
|
+
let intensity = lightAttribute.Intensity === undefined ? 1 : lightAttribute.Intensity.value / 100; // light disabled
|
|
1093
|
+
|
|
1094
|
+
if (lightAttribute.CastLightOnObject !== undefined && lightAttribute.CastLightOnObject.value === 0) {
|
|
1095
|
+
|
|
1096
|
+
intensity = 0;
|
|
1097
|
+
|
|
1098
|
+
}
|
|
1099
|
+
|
|
1100
|
+
let distance = 0;
|
|
1101
|
+
|
|
1102
|
+
if (lightAttribute.FarAttenuationEnd !== undefined) {
|
|
1103
|
+
|
|
1104
|
+
if (lightAttribute.EnableFarAttenuation !== undefined && lightAttribute.EnableFarAttenuation.value === 0) {
|
|
1105
|
+
|
|
1106
|
+
distance = 0;
|
|
1107
|
+
|
|
1108
|
+
} else {
|
|
1109
|
+
|
|
1110
|
+
distance = lightAttribute.FarAttenuationEnd.value;
|
|
1111
|
+
|
|
1112
|
+
}
|
|
1113
|
+
|
|
1114
|
+
} // TODO: could this be calculated linearly from FarAttenuationStart to FarAttenuationEnd?
|
|
1115
|
+
|
|
1116
|
+
|
|
1117
|
+
const decay = 1;
|
|
1118
|
+
|
|
1119
|
+
switch (type) {
|
|
1120
|
+
|
|
1121
|
+
case 0:
|
|
1122
|
+
// Point
|
|
1123
|
+
model = new THREE.PointLight(color, intensity, distance, decay);
|
|
1124
|
+
break;
|
|
1125
|
+
|
|
1126
|
+
case 1:
|
|
1127
|
+
// Directional
|
|
1128
|
+
model = new THREE.DirectionalLight(color, intensity);
|
|
1129
|
+
break;
|
|
1130
|
+
|
|
1131
|
+
case 2:
|
|
1132
|
+
// Spot
|
|
1133
|
+
let angle = Math.PI / 3;
|
|
1134
|
+
|
|
1135
|
+
if (lightAttribute.InnerAngle !== undefined) {
|
|
1136
|
+
|
|
1137
|
+
angle = THREE.MathUtils.degToRad(lightAttribute.InnerAngle.value);
|
|
1138
|
+
|
|
1139
|
+
}
|
|
1140
|
+
|
|
1141
|
+
let penumbra = 0;
|
|
1142
|
+
|
|
1143
|
+
if (lightAttribute.OuterAngle !== undefined) {
|
|
1144
|
+
|
|
1145
|
+
// TODO: this is not correct - FBX calculates outer and inner angle in degrees
|
|
1146
|
+
// with OuterAngle > InnerAngle && OuterAngle <= Math.PI
|
|
1147
|
+
// while three.js uses a penumbra between (0, 1) to attenuate the inner angle
|
|
1148
|
+
penumbra = THREE.MathUtils.degToRad(lightAttribute.OuterAngle.value);
|
|
1149
|
+
penumbra = Math.max(penumbra, 1);
|
|
1150
|
+
|
|
1151
|
+
}
|
|
1152
|
+
|
|
1153
|
+
model = new THREE.SpotLight(color, intensity, distance, angle, penumbra, decay);
|
|
1154
|
+
break;
|
|
1155
|
+
|
|
1156
|
+
default:
|
|
1157
|
+
console.warn('THREE.FBXLoader: Unknown light type ' + lightAttribute.LightType.value + ', defaulting to a THREE.PointLight.');
|
|
1158
|
+
model = new THREE.PointLight(color, intensity);
|
|
1159
|
+
break;
|
|
1160
|
+
|
|
1161
|
+
}
|
|
1162
|
+
|
|
1163
|
+
if (lightAttribute.CastShadows !== undefined && lightAttribute.CastShadows.value === 1) {
|
|
1164
|
+
|
|
1165
|
+
model.castShadow = true;
|
|
1166
|
+
|
|
1167
|
+
}
|
|
1168
|
+
|
|
1169
|
+
}
|
|
1170
|
+
|
|
1171
|
+
return model;
|
|
1172
|
+
|
|
1173
|
+
}
|
|
1174
|
+
|
|
1175
|
+
createMesh(relationships, geometryMap, materialMap) {
|
|
1176
|
+
|
|
1177
|
+
let model;
|
|
1178
|
+
let geometry = null;
|
|
1179
|
+
let material = null;
|
|
1180
|
+
const materials = []; // get geometry and materials(s) from connections
|
|
1181
|
+
|
|
1182
|
+
relationships.children.forEach(function (child) {
|
|
1183
|
+
|
|
1184
|
+
if (geometryMap.has(child.ID)) {
|
|
1185
|
+
|
|
1186
|
+
geometry = geometryMap.get(child.ID);
|
|
1187
|
+
|
|
1188
|
+
}
|
|
1189
|
+
|
|
1190
|
+
if (materialMap.has(child.ID)) {
|
|
1191
|
+
|
|
1192
|
+
materials.push(materialMap.get(child.ID));
|
|
1193
|
+
|
|
1194
|
+
}
|
|
1195
|
+
|
|
1196
|
+
});
|
|
1197
|
+
|
|
1198
|
+
if (materials.length > 1) {
|
|
1199
|
+
|
|
1200
|
+
material = materials;
|
|
1201
|
+
|
|
1202
|
+
} else if (materials.length > 0) {
|
|
1203
|
+
|
|
1204
|
+
material = materials[0];
|
|
1205
|
+
|
|
1206
|
+
} else {
|
|
1207
|
+
|
|
1208
|
+
material = new THREE.MeshPhongMaterial({
|
|
1209
|
+
color: 0xcccccc
|
|
1210
|
+
});
|
|
1211
|
+
materials.push(material);
|
|
1212
|
+
|
|
1213
|
+
}
|
|
1214
|
+
|
|
1215
|
+
if ('color' in geometry.attributes) {
|
|
1216
|
+
|
|
1217
|
+
materials.forEach(function (material) {
|
|
1218
|
+
|
|
1219
|
+
material.vertexColors = true;
|
|
1220
|
+
|
|
1221
|
+
});
|
|
1222
|
+
|
|
1223
|
+
}
|
|
1224
|
+
|
|
1225
|
+
if (geometry.FBX_Deformer) {
|
|
1226
|
+
|
|
1227
|
+
model = new THREE.SkinnedMesh(geometry, material);
|
|
1228
|
+
model.normalizeSkinWeights();
|
|
1229
|
+
|
|
1230
|
+
} else {
|
|
1231
|
+
|
|
1232
|
+
model = new THREE.Mesh(geometry, material);
|
|
1233
|
+
|
|
1234
|
+
}
|
|
1235
|
+
|
|
1236
|
+
return model;
|
|
1237
|
+
|
|
1238
|
+
}
|
|
1239
|
+
|
|
1240
|
+
createCurve(relationships, geometryMap) {
|
|
1241
|
+
|
|
1242
|
+
const geometry = relationships.children.reduce(function (geo, child) {
|
|
1243
|
+
|
|
1244
|
+
if (geometryMap.has(child.ID)) geo = geometryMap.get(child.ID);
|
|
1245
|
+
return geo;
|
|
1246
|
+
|
|
1247
|
+
}, null); // FBX does not list materials for Nurbs lines, so we'll just put our own in here.
|
|
1248
|
+
|
|
1249
|
+
const material = new THREE.LineBasicMaterial({
|
|
1250
|
+
color: 0x3300ff,
|
|
1251
|
+
linewidth: 1
|
|
1252
|
+
});
|
|
1253
|
+
return new THREE.Line(geometry, material);
|
|
1254
|
+
|
|
1255
|
+
} // parse the model node for transform data
|
|
1256
|
+
|
|
1257
|
+
|
|
1258
|
+
getTransformData(model, modelNode) {
|
|
1259
|
+
|
|
1260
|
+
const transformData = {};
|
|
1261
|
+
if ('InheritType' in modelNode) transformData.inheritType = parseInt(modelNode.InheritType.value);
|
|
1262
|
+
if ('RotationOrder' in modelNode) transformData.eulerOrder = getEulerOrder(modelNode.RotationOrder.value); else transformData.eulerOrder = 'ZYX';
|
|
1263
|
+
if ('Lcl_Translation' in modelNode) transformData.translation = modelNode.Lcl_Translation.value;
|
|
1264
|
+
if ('PreRotation' in modelNode) transformData.preRotation = modelNode.PreRotation.value;
|
|
1265
|
+
if ('Lcl_Rotation' in modelNode) transformData.rotation = modelNode.Lcl_Rotation.value;
|
|
1266
|
+
if ('PostRotation' in modelNode) transformData.postRotation = modelNode.PostRotation.value;
|
|
1267
|
+
if ('Lcl_Scaling' in modelNode) transformData.scale = modelNode.Lcl_Scaling.value;
|
|
1268
|
+
if ('ScalingOffset' in modelNode) transformData.scalingOffset = modelNode.ScalingOffset.value;
|
|
1269
|
+
if ('ScalingPivot' in modelNode) transformData.scalingPivot = modelNode.ScalingPivot.value;
|
|
1270
|
+
if ('RotationOffset' in modelNode) transformData.rotationOffset = modelNode.RotationOffset.value;
|
|
1271
|
+
if ('RotationPivot' in modelNode) transformData.rotationPivot = modelNode.RotationPivot.value;
|
|
1272
|
+
model.userData.transformData = transformData;
|
|
1273
|
+
|
|
1274
|
+
}
|
|
1275
|
+
|
|
1276
|
+
setLookAtProperties(model, modelNode) {
|
|
1277
|
+
|
|
1278
|
+
if ('LookAtProperty' in modelNode) {
|
|
1279
|
+
|
|
1280
|
+
const children = connections.get(model.ID).children;
|
|
1281
|
+
children.forEach(function (child) {
|
|
1282
|
+
|
|
1283
|
+
if (child.relationship === 'LookAtProperty') {
|
|
1284
|
+
|
|
1285
|
+
const lookAtTarget = fbxTree.Objects.Model[child.ID];
|
|
1286
|
+
|
|
1287
|
+
if ('Lcl_Translation' in lookAtTarget) {
|
|
1288
|
+
|
|
1289
|
+
const pos = lookAtTarget.Lcl_Translation.value; // THREE.DirectionalLight, THREE.SpotLight
|
|
1290
|
+
|
|
1291
|
+
if (model.target !== undefined) {
|
|
1292
|
+
|
|
1293
|
+
model.target.position.fromArray(pos);
|
|
1294
|
+
sceneGraph.add(model.target);
|
|
1295
|
+
|
|
1296
|
+
} else {
|
|
1297
|
+
|
|
1298
|
+
// Cameras and other Object3Ds
|
|
1299
|
+
model.lookAt(new THREE.Vector3().fromArray(pos));
|
|
1300
|
+
|
|
1301
|
+
}
|
|
1302
|
+
|
|
1303
|
+
}
|
|
1304
|
+
|
|
1305
|
+
}
|
|
1306
|
+
|
|
1307
|
+
});
|
|
1308
|
+
|
|
1309
|
+
}
|
|
1310
|
+
|
|
1311
|
+
}
|
|
1312
|
+
|
|
1313
|
+
bindSkeleton(skeletons, geometryMap, modelMap) {
|
|
1314
|
+
|
|
1315
|
+
const bindMatrices = this.parsePoseNodes();
|
|
1316
|
+
|
|
1317
|
+
for (const ID in skeletons) {
|
|
1318
|
+
|
|
1319
|
+
const skeleton = skeletons[ID];
|
|
1320
|
+
const parents = connections.get(parseInt(skeleton.ID)).parents;
|
|
1321
|
+
parents.forEach(function (parent) {
|
|
1322
|
+
|
|
1323
|
+
if (geometryMap.has(parent.ID)) {
|
|
1324
|
+
|
|
1325
|
+
const geoID = parent.ID;
|
|
1326
|
+
const geoRelationships = connections.get(geoID);
|
|
1327
|
+
geoRelationships.parents.forEach(function (geoConnParent) {
|
|
1328
|
+
|
|
1329
|
+
if (modelMap.has(geoConnParent.ID)) {
|
|
1330
|
+
|
|
1331
|
+
const model = modelMap.get(geoConnParent.ID);
|
|
1332
|
+
model.bind(new THREE.Skeleton(skeleton.bones), bindMatrices[geoConnParent.ID]);
|
|
1333
|
+
|
|
1334
|
+
}
|
|
1335
|
+
|
|
1336
|
+
});
|
|
1337
|
+
|
|
1338
|
+
}
|
|
1339
|
+
|
|
1340
|
+
});
|
|
1341
|
+
|
|
1342
|
+
}
|
|
1343
|
+
|
|
1344
|
+
}
|
|
1345
|
+
|
|
1346
|
+
parsePoseNodes() {
|
|
1347
|
+
|
|
1348
|
+
const bindMatrices = {};
|
|
1349
|
+
|
|
1350
|
+
if ('Pose' in fbxTree.Objects) {
|
|
1351
|
+
|
|
1352
|
+
const BindPoseNode = fbxTree.Objects.Pose;
|
|
1353
|
+
|
|
1354
|
+
for (const nodeID in BindPoseNode) {
|
|
1355
|
+
|
|
1356
|
+
if (BindPoseNode[nodeID].attrType === 'BindPose') {
|
|
1357
|
+
|
|
1358
|
+
const poseNodes = BindPoseNode[nodeID].PoseNode;
|
|
1359
|
+
|
|
1360
|
+
if (Array.isArray(poseNodes)) {
|
|
1361
|
+
|
|
1362
|
+
poseNodes.forEach(function (poseNode) {
|
|
1363
|
+
|
|
1364
|
+
bindMatrices[poseNode.Node] = new THREE.Matrix4().fromArray(poseNode.Matrix.a);
|
|
1365
|
+
|
|
1366
|
+
});
|
|
1367
|
+
|
|
1368
|
+
} else {
|
|
1369
|
+
|
|
1370
|
+
bindMatrices[poseNodes.Node] = new THREE.Matrix4().fromArray(poseNodes.Matrix.a);
|
|
1371
|
+
|
|
1372
|
+
}
|
|
1373
|
+
|
|
1374
|
+
}
|
|
1375
|
+
|
|
1376
|
+
}
|
|
1377
|
+
|
|
1378
|
+
}
|
|
1379
|
+
|
|
1380
|
+
return bindMatrices;
|
|
1381
|
+
|
|
1382
|
+
} // Parse ambient color in FBXTree.GlobalSettings - if it's not set to black (default), create an ambient light
|
|
1383
|
+
|
|
1384
|
+
|
|
1385
|
+
createAmbientLight() {
|
|
1386
|
+
|
|
1387
|
+
if ('GlobalSettings' in fbxTree && 'AmbientColor' in fbxTree.GlobalSettings) {
|
|
1388
|
+
|
|
1389
|
+
const ambientColor = fbxTree.GlobalSettings.AmbientColor.value;
|
|
1390
|
+
const r = ambientColor[0];
|
|
1391
|
+
const g = ambientColor[1];
|
|
1392
|
+
const b = ambientColor[2];
|
|
1393
|
+
|
|
1394
|
+
if (r !== 0 || g !== 0 || b !== 0) {
|
|
1395
|
+
|
|
1396
|
+
const color = new THREE.Color(r, g, b);
|
|
1397
|
+
sceneGraph.add(new THREE.AmbientLight(color, 1));
|
|
1398
|
+
|
|
1399
|
+
}
|
|
1400
|
+
|
|
1401
|
+
}
|
|
1402
|
+
|
|
1403
|
+
}
|
|
1404
|
+
|
|
1405
|
+
} // parse Geometry data from FBXTree and return map of BufferGeometries
|
|
1406
|
+
|
|
1407
|
+
|
|
1408
|
+
class GeometryParser {
|
|
1409
|
+
|
|
1410
|
+
// Parse nodes in FBXTree.Objects.Geometry
|
|
1411
|
+
parse(deformers) {
|
|
1412
|
+
|
|
1413
|
+
const geometryMap = new Map();
|
|
1414
|
+
|
|
1415
|
+
if ('Geometry' in fbxTree.Objects) {
|
|
1416
|
+
|
|
1417
|
+
const geoNodes = fbxTree.Objects.Geometry;
|
|
1418
|
+
|
|
1419
|
+
for (const nodeID in geoNodes) {
|
|
1420
|
+
|
|
1421
|
+
const relationships = connections.get(parseInt(nodeID));
|
|
1422
|
+
const geo = this.parseGeometry(relationships, geoNodes[nodeID], deformers);
|
|
1423
|
+
geometryMap.set(parseInt(nodeID), geo);
|
|
1424
|
+
|
|
1425
|
+
}
|
|
1426
|
+
|
|
1427
|
+
}
|
|
1428
|
+
|
|
1429
|
+
return geometryMap;
|
|
1430
|
+
|
|
1431
|
+
} // Parse single node in FBXTree.Objects.Geometry
|
|
1432
|
+
|
|
1433
|
+
|
|
1434
|
+
parseGeometry(relationships, geoNode, deformers) {
|
|
1435
|
+
|
|
1436
|
+
switch (geoNode.attrType) {
|
|
1437
|
+
|
|
1438
|
+
case 'Mesh':
|
|
1439
|
+
return this.parseMeshGeometry(relationships, geoNode, deformers);
|
|
1440
|
+
break;
|
|
1441
|
+
|
|
1442
|
+
case 'NurbsCurve':
|
|
1443
|
+
return this.parseNurbsGeometry(geoNode);
|
|
1444
|
+
break;
|
|
1445
|
+
|
|
1446
|
+
}
|
|
1447
|
+
|
|
1448
|
+
} // Parse single node mesh geometry in FBXTree.Objects.Geometry
|
|
1449
|
+
|
|
1450
|
+
|
|
1451
|
+
parseMeshGeometry(relationships, geoNode, deformers) {
|
|
1452
|
+
|
|
1453
|
+
const skeletons = deformers.skeletons;
|
|
1454
|
+
const morphTargets = [];
|
|
1455
|
+
const modelNodes = relationships.parents.map(function (parent) {
|
|
1456
|
+
|
|
1457
|
+
return fbxTree.Objects.Model[parent.ID];
|
|
1458
|
+
|
|
1459
|
+
}); // don't create geometry if it is not associated with any models
|
|
1460
|
+
|
|
1461
|
+
if (modelNodes.length === 0) return;
|
|
1462
|
+
const skeleton = relationships.children.reduce(function (skeleton, child) {
|
|
1463
|
+
|
|
1464
|
+
if (skeletons[child.ID] !== undefined) skeleton = skeletons[child.ID];
|
|
1465
|
+
return skeleton;
|
|
1466
|
+
|
|
1467
|
+
}, null);
|
|
1468
|
+
relationships.children.forEach(function (child) {
|
|
1469
|
+
|
|
1470
|
+
if (deformers.morphTargets[child.ID] !== undefined) {
|
|
1471
|
+
|
|
1472
|
+
morphTargets.push(deformers.morphTargets[child.ID]);
|
|
1473
|
+
|
|
1474
|
+
}
|
|
1475
|
+
|
|
1476
|
+
}); // Assume one model and get the preRotation from that
|
|
1477
|
+
// if there is more than one model associated with the geometry this may cause problems
|
|
1478
|
+
|
|
1479
|
+
const modelNode = modelNodes[0];
|
|
1480
|
+
const transformData = {};
|
|
1481
|
+
if ('RotationOrder' in modelNode) transformData.eulerOrder = getEulerOrder(modelNode.RotationOrder.value);
|
|
1482
|
+
if ('InheritType' in modelNode) transformData.inheritType = parseInt(modelNode.InheritType.value);
|
|
1483
|
+
if ('GeometricTranslation' in modelNode) transformData.translation = modelNode.GeometricTranslation.value;
|
|
1484
|
+
if ('GeometricRotation' in modelNode) transformData.rotation = modelNode.GeometricRotation.value;
|
|
1485
|
+
if ('GeometricScaling' in modelNode) transformData.scale = modelNode.GeometricScaling.value;
|
|
1486
|
+
const transform = generateTransform(transformData);
|
|
1487
|
+
return this.genGeometry(geoNode, skeleton, morphTargets, transform);
|
|
1488
|
+
|
|
1489
|
+
} // Generate a THREE.BufferGeometry from a node in FBXTree.Objects.Geometry
|
|
1490
|
+
|
|
1491
|
+
|
|
1492
|
+
genGeometry(geoNode, skeleton, morphTargets, preTransform) {
|
|
1493
|
+
|
|
1494
|
+
const geo = new THREE.BufferGeometry();
|
|
1495
|
+
if (geoNode.attrName) geo.name = geoNode.attrName;
|
|
1496
|
+
const geoInfo = this.parseGeoNode(geoNode, skeleton);
|
|
1497
|
+
const buffers = this.genBuffers(geoInfo);
|
|
1498
|
+
const positionAttribute = new THREE.Float32BufferAttribute(buffers.vertex, 3);
|
|
1499
|
+
positionAttribute.applyMatrix4(preTransform);
|
|
1500
|
+
geo.setAttribute('position', positionAttribute);
|
|
1501
|
+
|
|
1502
|
+
if (buffers.colors.length > 0) {
|
|
1503
|
+
|
|
1504
|
+
geo.setAttribute('color', new THREE.Float32BufferAttribute(buffers.colors, 3));
|
|
1505
|
+
|
|
1506
|
+
}
|
|
1507
|
+
|
|
1508
|
+
if (skeleton) {
|
|
1509
|
+
|
|
1510
|
+
geo.setAttribute('skinIndex', new THREE.Uint16BufferAttribute(buffers.weightsIndices, 4));
|
|
1511
|
+
geo.setAttribute('skinWeight', new THREE.Float32BufferAttribute(buffers.vertexWeights, 4)); // used later to bind the skeleton to the model
|
|
1512
|
+
|
|
1513
|
+
geo.FBX_Deformer = skeleton;
|
|
1514
|
+
|
|
1515
|
+
}
|
|
1516
|
+
|
|
1517
|
+
if (buffers.normal.length > 0) {
|
|
1518
|
+
|
|
1519
|
+
const normalMatrix = new THREE.Matrix3().getNormalMatrix(preTransform);
|
|
1520
|
+
const normalAttribute = new THREE.Float32BufferAttribute(buffers.normal, 3);
|
|
1521
|
+
normalAttribute.applyNormalMatrix(normalMatrix);
|
|
1522
|
+
geo.setAttribute('normal', normalAttribute);
|
|
1523
|
+
|
|
1524
|
+
}
|
|
1525
|
+
|
|
1526
|
+
buffers.uvs.forEach(function (uvBuffer, i) {
|
|
1527
|
+
|
|
1528
|
+
// subsequent uv buffers are called 'uv1', 'uv2', ...
|
|
1529
|
+
let name = 'uv' + (i + 1).toString(); // the first uv buffer is just called 'uv'
|
|
1530
|
+
|
|
1531
|
+
if (i === 0) {
|
|
1532
|
+
|
|
1533
|
+
name = 'uv';
|
|
1534
|
+
|
|
1535
|
+
}
|
|
1536
|
+
|
|
1537
|
+
geo.setAttribute(name, new THREE.Float32BufferAttribute(buffers.uvs[i], 2));
|
|
1538
|
+
|
|
1539
|
+
});
|
|
1540
|
+
|
|
1541
|
+
if (geoInfo.material && geoInfo.material.mappingType !== 'AllSame') {
|
|
1542
|
+
|
|
1543
|
+
// Convert the material indices of each vertex into rendering groups on the geometry.
|
|
1544
|
+
let prevMaterialIndex = buffers.materialIndex[0];
|
|
1545
|
+
let startIndex = 0;
|
|
1546
|
+
buffers.materialIndex.forEach(function (currentIndex, i) {
|
|
1547
|
+
|
|
1548
|
+
if (currentIndex !== prevMaterialIndex) {
|
|
1549
|
+
|
|
1550
|
+
geo.addGroup(startIndex, i - startIndex, prevMaterialIndex);
|
|
1551
|
+
prevMaterialIndex = currentIndex;
|
|
1552
|
+
startIndex = i;
|
|
1553
|
+
|
|
1554
|
+
}
|
|
1555
|
+
|
|
1556
|
+
}); // the loop above doesn't add the last group, do that here.
|
|
1557
|
+
|
|
1558
|
+
if (geo.groups.length > 0) {
|
|
1559
|
+
|
|
1560
|
+
const lastGroup = geo.groups[geo.groups.length - 1];
|
|
1561
|
+
const lastIndex = lastGroup.start + lastGroup.count;
|
|
1562
|
+
|
|
1563
|
+
if (lastIndex !== buffers.materialIndex.length) {
|
|
1564
|
+
|
|
1565
|
+
geo.addGroup(lastIndex, buffers.materialIndex.length - lastIndex, prevMaterialIndex);
|
|
1566
|
+
|
|
1567
|
+
}
|
|
1568
|
+
|
|
1569
|
+
} // case where there are multiple materials but the whole geometry is only
|
|
1570
|
+
// using one of them
|
|
1571
|
+
|
|
1572
|
+
|
|
1573
|
+
if (geo.groups.length === 0) {
|
|
1574
|
+
|
|
1575
|
+
geo.addGroup(0, buffers.materialIndex.length, buffers.materialIndex[0]);
|
|
1576
|
+
|
|
1577
|
+
}
|
|
1578
|
+
|
|
1579
|
+
}
|
|
1580
|
+
|
|
1581
|
+
this.addMorphTargets(geo, geoNode, morphTargets, preTransform);
|
|
1582
|
+
return geo;
|
|
1583
|
+
|
|
1584
|
+
}
|
|
1585
|
+
|
|
1586
|
+
parseGeoNode(geoNode, skeleton) {
|
|
1587
|
+
|
|
1588
|
+
const geoInfo = {};
|
|
1589
|
+
geoInfo.vertexPositions = geoNode.Vertices !== undefined ? geoNode.Vertices.a : [];
|
|
1590
|
+
geoInfo.vertexIndices = geoNode.PolygonVertexIndex !== undefined ? geoNode.PolygonVertexIndex.a : [];
|
|
1591
|
+
|
|
1592
|
+
if (geoNode.LayerElementColor) {
|
|
1593
|
+
|
|
1594
|
+
geoInfo.color = this.parseVertexColors(geoNode.LayerElementColor[0]);
|
|
1595
|
+
|
|
1596
|
+
}
|
|
1597
|
+
|
|
1598
|
+
if (geoNode.LayerElementMaterial) {
|
|
1599
|
+
|
|
1600
|
+
geoInfo.material = this.parseMaterialIndices(geoNode.LayerElementMaterial[0]);
|
|
1601
|
+
|
|
1602
|
+
}
|
|
1603
|
+
|
|
1604
|
+
if (geoNode.LayerElementNormal) {
|
|
1605
|
+
|
|
1606
|
+
geoInfo.normal = this.parseNormals(geoNode.LayerElementNormal[0]);
|
|
1607
|
+
|
|
1608
|
+
}
|
|
1609
|
+
|
|
1610
|
+
if (geoNode.LayerElementUV) {
|
|
1611
|
+
|
|
1612
|
+
geoInfo.uv = [];
|
|
1613
|
+
let i = 0;
|
|
1614
|
+
|
|
1615
|
+
while (geoNode.LayerElementUV[i]) {
|
|
1616
|
+
|
|
1617
|
+
if (geoNode.LayerElementUV[i].UV) {
|
|
1618
|
+
|
|
1619
|
+
geoInfo.uv.push(this.parseUVs(geoNode.LayerElementUV[i]));
|
|
1620
|
+
|
|
1621
|
+
}
|
|
1622
|
+
|
|
1623
|
+
i++;
|
|
1624
|
+
|
|
1625
|
+
}
|
|
1626
|
+
|
|
1627
|
+
}
|
|
1628
|
+
|
|
1629
|
+
geoInfo.weightTable = {};
|
|
1630
|
+
|
|
1631
|
+
if (skeleton !== null) {
|
|
1632
|
+
|
|
1633
|
+
geoInfo.skeleton = skeleton;
|
|
1634
|
+
skeleton.rawBones.forEach(function (rawBone, i) {
|
|
1635
|
+
|
|
1636
|
+
// loop over the bone's vertex indices and weights
|
|
1637
|
+
rawBone.indices.forEach(function (index, j) {
|
|
1638
|
+
|
|
1639
|
+
if (geoInfo.weightTable[index] === undefined) geoInfo.weightTable[index] = [];
|
|
1640
|
+
geoInfo.weightTable[index].push({
|
|
1641
|
+
id: i,
|
|
1642
|
+
weight: rawBone.weights[j]
|
|
1643
|
+
});
|
|
1644
|
+
|
|
1645
|
+
});
|
|
1646
|
+
|
|
1647
|
+
});
|
|
1648
|
+
|
|
1649
|
+
}
|
|
1650
|
+
|
|
1651
|
+
return geoInfo;
|
|
1652
|
+
|
|
1653
|
+
}
|
|
1654
|
+
|
|
1655
|
+
genBuffers(geoInfo) {
|
|
1656
|
+
|
|
1657
|
+
const buffers = {
|
|
1658
|
+
vertex: [],
|
|
1659
|
+
normal: [],
|
|
1660
|
+
colors: [],
|
|
1661
|
+
uvs: [],
|
|
1662
|
+
materialIndex: [],
|
|
1663
|
+
vertexWeights: [],
|
|
1664
|
+
weightsIndices: []
|
|
1665
|
+
};
|
|
1666
|
+
let polygonIndex = 0;
|
|
1667
|
+
let faceLength = 0;
|
|
1668
|
+
let displayedWeightsWarning = false; // these will hold data for a single face
|
|
1669
|
+
|
|
1670
|
+
let facePositionIndexes = [];
|
|
1671
|
+
let faceNormals = [];
|
|
1672
|
+
let faceColors = [];
|
|
1673
|
+
let faceUVs = [];
|
|
1674
|
+
let faceWeights = [];
|
|
1675
|
+
let faceWeightIndices = [];
|
|
1676
|
+
const scope = this;
|
|
1677
|
+
geoInfo.vertexIndices.forEach(function (vertexIndex, polygonVertexIndex) {
|
|
1678
|
+
|
|
1679
|
+
let materialIndex;
|
|
1680
|
+
let endOfFace = false; // Face index and vertex index arrays are combined in a single array
|
|
1681
|
+
// A cube with quad faces looks like this:
|
|
1682
|
+
// PolygonVertexIndex: *24 {
|
|
1683
|
+
// a: 0, 1, 3, -3, 2, 3, 5, -5, 4, 5, 7, -7, 6, 7, 1, -1, 1, 7, 5, -4, 6, 0, 2, -5
|
|
1684
|
+
// }
|
|
1685
|
+
// Negative numbers mark the end of a face - first face here is 0, 1, 3, -3
|
|
1686
|
+
// to find index of last vertex bit shift the index: ^ - 1
|
|
1687
|
+
|
|
1688
|
+
if (vertexIndex < 0) {
|
|
1689
|
+
|
|
1690
|
+
vertexIndex = vertexIndex ^ - 1; // equivalent to ( x * -1 ) - 1
|
|
1691
|
+
|
|
1692
|
+
endOfFace = true;
|
|
1693
|
+
|
|
1694
|
+
}
|
|
1695
|
+
|
|
1696
|
+
let weightIndices = [];
|
|
1697
|
+
let weights = [];
|
|
1698
|
+
facePositionIndexes.push(vertexIndex * 3, vertexIndex * 3 + 1, vertexIndex * 3 + 2);
|
|
1699
|
+
|
|
1700
|
+
if (geoInfo.color) {
|
|
1701
|
+
|
|
1702
|
+
const data = getData(polygonVertexIndex, polygonIndex, vertexIndex, geoInfo.color);
|
|
1703
|
+
faceColors.push(data[0], data[1], data[2]);
|
|
1704
|
+
|
|
1705
|
+
}
|
|
1706
|
+
|
|
1707
|
+
if (geoInfo.skeleton) {
|
|
1708
|
+
|
|
1709
|
+
if (geoInfo.weightTable[vertexIndex] !== undefined) {
|
|
1710
|
+
|
|
1711
|
+
geoInfo.weightTable[vertexIndex].forEach(function (wt) {
|
|
1712
|
+
|
|
1713
|
+
weights.push(wt.weight);
|
|
1714
|
+
weightIndices.push(wt.id);
|
|
1715
|
+
|
|
1716
|
+
});
|
|
1717
|
+
|
|
1718
|
+
}
|
|
1719
|
+
|
|
1720
|
+
if (weights.length > 4) {
|
|
1721
|
+
|
|
1722
|
+
if (!displayedWeightsWarning) {
|
|
1723
|
+
|
|
1724
|
+
console.warn('THREE.FBXLoader: Vertex has more than 4 skinning weights assigned to vertex. Deleting additional weights.');
|
|
1725
|
+
displayedWeightsWarning = true;
|
|
1726
|
+
|
|
1727
|
+
}
|
|
1728
|
+
|
|
1729
|
+
const wIndex = [0, 0, 0, 0];
|
|
1730
|
+
const Weight = [0, 0, 0, 0];
|
|
1731
|
+
weights.forEach(function (weight, weightIndex) {
|
|
1732
|
+
|
|
1733
|
+
let currentWeight = weight;
|
|
1734
|
+
let currentIndex = weightIndices[weightIndex];
|
|
1735
|
+
Weight.forEach(function (comparedWeight, comparedWeightIndex, comparedWeightArray) {
|
|
1736
|
+
|
|
1737
|
+
if (currentWeight > comparedWeight) {
|
|
1738
|
+
|
|
1739
|
+
comparedWeightArray[comparedWeightIndex] = currentWeight;
|
|
1740
|
+
currentWeight = comparedWeight;
|
|
1741
|
+
const tmp = wIndex[comparedWeightIndex];
|
|
1742
|
+
wIndex[comparedWeightIndex] = currentIndex;
|
|
1743
|
+
currentIndex = tmp;
|
|
1744
|
+
|
|
1745
|
+
}
|
|
1746
|
+
|
|
1747
|
+
});
|
|
1748
|
+
|
|
1749
|
+
});
|
|
1750
|
+
weightIndices = wIndex;
|
|
1751
|
+
weights = Weight;
|
|
1752
|
+
|
|
1753
|
+
} // if the weight array is shorter than 4 pad with 0s
|
|
1754
|
+
|
|
1755
|
+
|
|
1756
|
+
while (weights.length < 4) {
|
|
1757
|
+
|
|
1758
|
+
weights.push(0);
|
|
1759
|
+
weightIndices.push(0);
|
|
1760
|
+
|
|
1761
|
+
}
|
|
1762
|
+
|
|
1763
|
+
for (let i = 0; i < 4; ++i) {
|
|
1764
|
+
|
|
1765
|
+
faceWeights.push(weights[i]);
|
|
1766
|
+
faceWeightIndices.push(weightIndices[i]);
|
|
1767
|
+
|
|
1768
|
+
}
|
|
1769
|
+
|
|
1770
|
+
}
|
|
1771
|
+
|
|
1772
|
+
if (geoInfo.normal) {
|
|
1773
|
+
|
|
1774
|
+
const data = getData(polygonVertexIndex, polygonIndex, vertexIndex, geoInfo.normal);
|
|
1775
|
+
faceNormals.push(data[0], data[1], data[2]);
|
|
1776
|
+
|
|
1777
|
+
}
|
|
1778
|
+
|
|
1779
|
+
if (geoInfo.material && geoInfo.material.mappingType !== 'AllSame') {
|
|
1780
|
+
|
|
1781
|
+
materialIndex = getData(polygonVertexIndex, polygonIndex, vertexIndex, geoInfo.material)[0];
|
|
1782
|
+
|
|
1783
|
+
}
|
|
1784
|
+
|
|
1785
|
+
if (geoInfo.uv) {
|
|
1786
|
+
|
|
1787
|
+
geoInfo.uv.forEach(function (uv, i) {
|
|
1788
|
+
|
|
1789
|
+
const data = getData(polygonVertexIndex, polygonIndex, vertexIndex, uv);
|
|
1790
|
+
|
|
1791
|
+
if (faceUVs[i] === undefined) {
|
|
1792
|
+
|
|
1793
|
+
faceUVs[i] = [];
|
|
1794
|
+
|
|
1795
|
+
}
|
|
1796
|
+
|
|
1797
|
+
faceUVs[i].push(data[0]);
|
|
1798
|
+
faceUVs[i].push(data[1]);
|
|
1799
|
+
|
|
1800
|
+
});
|
|
1801
|
+
|
|
1802
|
+
}
|
|
1803
|
+
|
|
1804
|
+
faceLength++;
|
|
1805
|
+
|
|
1806
|
+
if (endOfFace) {
|
|
1807
|
+
|
|
1808
|
+
scope.genFace(buffers, geoInfo, facePositionIndexes, materialIndex, faceNormals, faceColors, faceUVs, faceWeights, faceWeightIndices, faceLength);
|
|
1809
|
+
polygonIndex++;
|
|
1810
|
+
faceLength = 0; // reset arrays for the next face
|
|
1811
|
+
|
|
1812
|
+
facePositionIndexes = [];
|
|
1813
|
+
faceNormals = [];
|
|
1814
|
+
faceColors = [];
|
|
1815
|
+
faceUVs = [];
|
|
1816
|
+
faceWeights = [];
|
|
1817
|
+
faceWeightIndices = [];
|
|
1818
|
+
|
|
1819
|
+
}
|
|
1820
|
+
|
|
1821
|
+
});
|
|
1822
|
+
return buffers;
|
|
1823
|
+
|
|
1824
|
+
} // Generate data for a single face in a geometry. If the face is a quad then split it into 2 tris
|
|
1825
|
+
|
|
1826
|
+
|
|
1827
|
+
genFace(buffers, geoInfo, facePositionIndexes, materialIndex, faceNormals, faceColors, faceUVs, faceWeights, faceWeightIndices, faceLength) {
|
|
1828
|
+
|
|
1829
|
+
for (let i = 2; i < faceLength; i++) {
|
|
1830
|
+
|
|
1831
|
+
buffers.vertex.push(geoInfo.vertexPositions[facePositionIndexes[0]]);
|
|
1832
|
+
buffers.vertex.push(geoInfo.vertexPositions[facePositionIndexes[1]]);
|
|
1833
|
+
buffers.vertex.push(geoInfo.vertexPositions[facePositionIndexes[2]]);
|
|
1834
|
+
buffers.vertex.push(geoInfo.vertexPositions[facePositionIndexes[(i - 1) * 3]]);
|
|
1835
|
+
buffers.vertex.push(geoInfo.vertexPositions[facePositionIndexes[(i - 1) * 3 + 1]]);
|
|
1836
|
+
buffers.vertex.push(geoInfo.vertexPositions[facePositionIndexes[(i - 1) * 3 + 2]]);
|
|
1837
|
+
buffers.vertex.push(geoInfo.vertexPositions[facePositionIndexes[i * 3]]);
|
|
1838
|
+
buffers.vertex.push(geoInfo.vertexPositions[facePositionIndexes[i * 3 + 1]]);
|
|
1839
|
+
buffers.vertex.push(geoInfo.vertexPositions[facePositionIndexes[i * 3 + 2]]);
|
|
1840
|
+
|
|
1841
|
+
if (geoInfo.skeleton) {
|
|
1842
|
+
|
|
1843
|
+
buffers.vertexWeights.push(faceWeights[0]);
|
|
1844
|
+
buffers.vertexWeights.push(faceWeights[1]);
|
|
1845
|
+
buffers.vertexWeights.push(faceWeights[2]);
|
|
1846
|
+
buffers.vertexWeights.push(faceWeights[3]);
|
|
1847
|
+
buffers.vertexWeights.push(faceWeights[(i - 1) * 4]);
|
|
1848
|
+
buffers.vertexWeights.push(faceWeights[(i - 1) * 4 + 1]);
|
|
1849
|
+
buffers.vertexWeights.push(faceWeights[(i - 1) * 4 + 2]);
|
|
1850
|
+
buffers.vertexWeights.push(faceWeights[(i - 1) * 4 + 3]);
|
|
1851
|
+
buffers.vertexWeights.push(faceWeights[i * 4]);
|
|
1852
|
+
buffers.vertexWeights.push(faceWeights[i * 4 + 1]);
|
|
1853
|
+
buffers.vertexWeights.push(faceWeights[i * 4 + 2]);
|
|
1854
|
+
buffers.vertexWeights.push(faceWeights[i * 4 + 3]);
|
|
1855
|
+
buffers.weightsIndices.push(faceWeightIndices[0]);
|
|
1856
|
+
buffers.weightsIndices.push(faceWeightIndices[1]);
|
|
1857
|
+
buffers.weightsIndices.push(faceWeightIndices[2]);
|
|
1858
|
+
buffers.weightsIndices.push(faceWeightIndices[3]);
|
|
1859
|
+
buffers.weightsIndices.push(faceWeightIndices[(i - 1) * 4]);
|
|
1860
|
+
buffers.weightsIndices.push(faceWeightIndices[(i - 1) * 4 + 1]);
|
|
1861
|
+
buffers.weightsIndices.push(faceWeightIndices[(i - 1) * 4 + 2]);
|
|
1862
|
+
buffers.weightsIndices.push(faceWeightIndices[(i - 1) * 4 + 3]);
|
|
1863
|
+
buffers.weightsIndices.push(faceWeightIndices[i * 4]);
|
|
1864
|
+
buffers.weightsIndices.push(faceWeightIndices[i * 4 + 1]);
|
|
1865
|
+
buffers.weightsIndices.push(faceWeightIndices[i * 4 + 2]);
|
|
1866
|
+
buffers.weightsIndices.push(faceWeightIndices[i * 4 + 3]);
|
|
1867
|
+
|
|
1868
|
+
}
|
|
1869
|
+
|
|
1870
|
+
if (geoInfo.color) {
|
|
1871
|
+
|
|
1872
|
+
buffers.colors.push(faceColors[0]);
|
|
1873
|
+
buffers.colors.push(faceColors[1]);
|
|
1874
|
+
buffers.colors.push(faceColors[2]);
|
|
1875
|
+
buffers.colors.push(faceColors[(i - 1) * 3]);
|
|
1876
|
+
buffers.colors.push(faceColors[(i - 1) * 3 + 1]);
|
|
1877
|
+
buffers.colors.push(faceColors[(i - 1) * 3 + 2]);
|
|
1878
|
+
buffers.colors.push(faceColors[i * 3]);
|
|
1879
|
+
buffers.colors.push(faceColors[i * 3 + 1]);
|
|
1880
|
+
buffers.colors.push(faceColors[i * 3 + 2]);
|
|
1881
|
+
|
|
1882
|
+
}
|
|
1883
|
+
|
|
1884
|
+
if (geoInfo.material && geoInfo.material.mappingType !== 'AllSame') {
|
|
1885
|
+
|
|
1886
|
+
buffers.materialIndex.push(materialIndex);
|
|
1887
|
+
buffers.materialIndex.push(materialIndex);
|
|
1888
|
+
buffers.materialIndex.push(materialIndex);
|
|
1889
|
+
|
|
1890
|
+
}
|
|
1891
|
+
|
|
1892
|
+
if (geoInfo.normal) {
|
|
1893
|
+
|
|
1894
|
+
buffers.normal.push(faceNormals[0]);
|
|
1895
|
+
buffers.normal.push(faceNormals[1]);
|
|
1896
|
+
buffers.normal.push(faceNormals[2]);
|
|
1897
|
+
buffers.normal.push(faceNormals[(i - 1) * 3]);
|
|
1898
|
+
buffers.normal.push(faceNormals[(i - 1) * 3 + 1]);
|
|
1899
|
+
buffers.normal.push(faceNormals[(i - 1) * 3 + 2]);
|
|
1900
|
+
buffers.normal.push(faceNormals[i * 3]);
|
|
1901
|
+
buffers.normal.push(faceNormals[i * 3 + 1]);
|
|
1902
|
+
buffers.normal.push(faceNormals[i * 3 + 2]);
|
|
1903
|
+
|
|
1904
|
+
}
|
|
1905
|
+
|
|
1906
|
+
if (geoInfo.uv) {
|
|
1907
|
+
|
|
1908
|
+
geoInfo.uv.forEach(function (uv, j) {
|
|
1909
|
+
|
|
1910
|
+
if (buffers.uvs[j] === undefined) buffers.uvs[j] = [];
|
|
1911
|
+
buffers.uvs[j].push(faceUVs[j][0]);
|
|
1912
|
+
buffers.uvs[j].push(faceUVs[j][1]);
|
|
1913
|
+
buffers.uvs[j].push(faceUVs[j][(i - 1) * 2]);
|
|
1914
|
+
buffers.uvs[j].push(faceUVs[j][(i - 1) * 2 + 1]);
|
|
1915
|
+
buffers.uvs[j].push(faceUVs[j][i * 2]);
|
|
1916
|
+
buffers.uvs[j].push(faceUVs[j][i * 2 + 1]);
|
|
1917
|
+
|
|
1918
|
+
});
|
|
1919
|
+
|
|
1920
|
+
}
|
|
1921
|
+
|
|
1922
|
+
}
|
|
1923
|
+
|
|
1924
|
+
}
|
|
1925
|
+
|
|
1926
|
+
addMorphTargets(parentGeo, parentGeoNode, morphTargets, preTransform) {
|
|
1927
|
+
|
|
1928
|
+
if (morphTargets.length === 0) return;
|
|
1929
|
+
parentGeo.morphTargetsRelative = true;
|
|
1930
|
+
parentGeo.morphAttributes.position = []; // parentGeo.morphAttributes.normal = []; // not implemented
|
|
1931
|
+
|
|
1932
|
+
const scope = this;
|
|
1933
|
+
morphTargets.forEach(function (morphTarget) {
|
|
1934
|
+
|
|
1935
|
+
morphTarget.rawTargets.forEach(function (rawTarget) {
|
|
1936
|
+
|
|
1937
|
+
const morphGeoNode = fbxTree.Objects.Geometry[rawTarget.geoID];
|
|
1938
|
+
|
|
1939
|
+
if (morphGeoNode !== undefined) {
|
|
1940
|
+
|
|
1941
|
+
scope.genMorphGeometry(parentGeo, parentGeoNode, morphGeoNode, preTransform, rawTarget.name);
|
|
1942
|
+
|
|
1943
|
+
}
|
|
1944
|
+
|
|
1945
|
+
});
|
|
1946
|
+
|
|
1947
|
+
});
|
|
1948
|
+
|
|
1949
|
+
} // a morph geometry node is similar to a standard node, and the node is also contained
|
|
1950
|
+
// in FBXTree.Objects.Geometry, however it can only have attributes for position, normal
|
|
1951
|
+
// and a special attribute Index defining which vertices of the original geometry are affected
|
|
1952
|
+
// Normal and position attributes only have data for the vertices that are affected by the morph
|
|
1953
|
+
|
|
1954
|
+
|
|
1955
|
+
genMorphGeometry(parentGeo, parentGeoNode, morphGeoNode, preTransform, name) {
|
|
1956
|
+
|
|
1957
|
+
const vertexIndices = parentGeoNode.PolygonVertexIndex !== undefined ? parentGeoNode.PolygonVertexIndex.a : [];
|
|
1958
|
+
const morphPositionsSparse = morphGeoNode.Vertices !== undefined ? morphGeoNode.Vertices.a : [];
|
|
1959
|
+
const indices = morphGeoNode.Indexes !== undefined ? morphGeoNode.Indexes.a : [];
|
|
1960
|
+
const length = parentGeo.attributes.position.count * 3;
|
|
1961
|
+
const morphPositions = new Float32Array(length);
|
|
1962
|
+
|
|
1963
|
+
for (let i = 0; i < indices.length; i++) {
|
|
1964
|
+
|
|
1965
|
+
const morphIndex = indices[i] * 3;
|
|
1966
|
+
morphPositions[morphIndex] = morphPositionsSparse[i * 3];
|
|
1967
|
+
morphPositions[morphIndex + 1] = morphPositionsSparse[i * 3 + 1];
|
|
1968
|
+
morphPositions[morphIndex + 2] = morphPositionsSparse[i * 3 + 2];
|
|
1969
|
+
|
|
1970
|
+
} // TODO: add morph normal support
|
|
1971
|
+
|
|
1972
|
+
|
|
1973
|
+
const morphGeoInfo = {
|
|
1974
|
+
vertexIndices: vertexIndices,
|
|
1975
|
+
vertexPositions: morphPositions
|
|
1976
|
+
};
|
|
1977
|
+
const morphBuffers = this.genBuffers(morphGeoInfo);
|
|
1978
|
+
const positionAttribute = new THREE.Float32BufferAttribute(morphBuffers.vertex, 3);
|
|
1979
|
+
positionAttribute.name = name || morphGeoNode.attrName;
|
|
1980
|
+
positionAttribute.applyMatrix4(preTransform);
|
|
1981
|
+
parentGeo.morphAttributes.position.push(positionAttribute);
|
|
1982
|
+
|
|
1983
|
+
} // Parse normal from FBXTree.Objects.Geometry.LayerElementNormal if it exists
|
|
1984
|
+
|
|
1985
|
+
|
|
1986
|
+
parseNormals(NormalNode) {
|
|
1987
|
+
|
|
1988
|
+
const mappingType = NormalNode.MappingInformationType;
|
|
1989
|
+
const referenceType = NormalNode.ReferenceInformationType;
|
|
1990
|
+
const buffer = NormalNode.Normals.a;
|
|
1991
|
+
let indexBuffer = [];
|
|
1992
|
+
|
|
1993
|
+
if (referenceType === 'IndexToDirect') {
|
|
1994
|
+
|
|
1995
|
+
if ('NormalIndex' in NormalNode) {
|
|
1996
|
+
|
|
1997
|
+
indexBuffer = NormalNode.NormalIndex.a;
|
|
1998
|
+
|
|
1999
|
+
} else if ('NormalsIndex' in NormalNode) {
|
|
2000
|
+
|
|
2001
|
+
indexBuffer = NormalNode.NormalsIndex.a;
|
|
2002
|
+
|
|
2003
|
+
}
|
|
2004
|
+
|
|
2005
|
+
}
|
|
2006
|
+
|
|
2007
|
+
return {
|
|
2008
|
+
dataSize: 3,
|
|
2009
|
+
buffer: buffer,
|
|
2010
|
+
indices: indexBuffer,
|
|
2011
|
+
mappingType: mappingType,
|
|
2012
|
+
referenceType: referenceType
|
|
2013
|
+
};
|
|
2014
|
+
|
|
2015
|
+
} // Parse UVs from FBXTree.Objects.Geometry.LayerElementUV if it exists
|
|
2016
|
+
|
|
2017
|
+
|
|
2018
|
+
parseUVs(UVNode) {
|
|
2019
|
+
|
|
2020
|
+
const mappingType = UVNode.MappingInformationType;
|
|
2021
|
+
const referenceType = UVNode.ReferenceInformationType;
|
|
2022
|
+
const buffer = UVNode.UV.a;
|
|
2023
|
+
let indexBuffer = [];
|
|
2024
|
+
|
|
2025
|
+
if (referenceType === 'IndexToDirect') {
|
|
2026
|
+
|
|
2027
|
+
indexBuffer = UVNode.UVIndex.a;
|
|
2028
|
+
|
|
2029
|
+
}
|
|
2030
|
+
|
|
2031
|
+
return {
|
|
2032
|
+
dataSize: 2,
|
|
2033
|
+
buffer: buffer,
|
|
2034
|
+
indices: indexBuffer,
|
|
2035
|
+
mappingType: mappingType,
|
|
2036
|
+
referenceType: referenceType
|
|
2037
|
+
};
|
|
2038
|
+
|
|
2039
|
+
} // Parse Vertex Colors from FBXTree.Objects.Geometry.LayerElementColor if it exists
|
|
2040
|
+
|
|
2041
|
+
|
|
2042
|
+
parseVertexColors(ColorNode) {
|
|
2043
|
+
|
|
2044
|
+
const mappingType = ColorNode.MappingInformationType;
|
|
2045
|
+
const referenceType = ColorNode.ReferenceInformationType;
|
|
2046
|
+
const buffer = ColorNode.Colors.a;
|
|
2047
|
+
let indexBuffer = [];
|
|
2048
|
+
|
|
2049
|
+
if (referenceType === 'IndexToDirect') {
|
|
2050
|
+
|
|
2051
|
+
indexBuffer = ColorNode.ColorIndex.a;
|
|
2052
|
+
|
|
2053
|
+
}
|
|
2054
|
+
|
|
2055
|
+
return {
|
|
2056
|
+
dataSize: 4,
|
|
2057
|
+
buffer: buffer,
|
|
2058
|
+
indices: indexBuffer,
|
|
2059
|
+
mappingType: mappingType,
|
|
2060
|
+
referenceType: referenceType
|
|
2061
|
+
};
|
|
2062
|
+
|
|
2063
|
+
} // Parse mapping and material data in FBXTree.Objects.Geometry.LayerElementMaterial if it exists
|
|
2064
|
+
|
|
2065
|
+
|
|
2066
|
+
parseMaterialIndices(MaterialNode) {
|
|
2067
|
+
|
|
2068
|
+
const mappingType = MaterialNode.MappingInformationType;
|
|
2069
|
+
const referenceType = MaterialNode.ReferenceInformationType;
|
|
2070
|
+
|
|
2071
|
+
if (mappingType === 'NoMappingInformation') {
|
|
2072
|
+
|
|
2073
|
+
return {
|
|
2074
|
+
dataSize: 1,
|
|
2075
|
+
buffer: [0],
|
|
2076
|
+
indices: [0],
|
|
2077
|
+
mappingType: 'AllSame',
|
|
2078
|
+
referenceType: referenceType
|
|
2079
|
+
};
|
|
2080
|
+
|
|
2081
|
+
}
|
|
2082
|
+
|
|
2083
|
+
const materialIndexBuffer = MaterialNode.Materials.a; // Since materials are stored as indices, there's a bit of a mismatch between FBX and what
|
|
2084
|
+
// we expect.So we create an intermediate buffer that points to the index in the buffer,
|
|
2085
|
+
// for conforming with the other functions we've written for other data.
|
|
2086
|
+
|
|
2087
|
+
const materialIndices = [];
|
|
2088
|
+
|
|
2089
|
+
for (let i = 0; i < materialIndexBuffer.length; ++i) {
|
|
2090
|
+
|
|
2091
|
+
materialIndices.push(i);
|
|
2092
|
+
|
|
2093
|
+
}
|
|
2094
|
+
|
|
2095
|
+
return {
|
|
2096
|
+
dataSize: 1,
|
|
2097
|
+
buffer: materialIndexBuffer,
|
|
2098
|
+
indices: materialIndices,
|
|
2099
|
+
mappingType: mappingType,
|
|
2100
|
+
referenceType: referenceType
|
|
2101
|
+
};
|
|
2102
|
+
|
|
2103
|
+
} // Generate a NurbGeometry from a node in FBXTree.Objects.Geometry
|
|
2104
|
+
|
|
2105
|
+
|
|
2106
|
+
parseNurbsGeometry(geoNode) {
|
|
2107
|
+
|
|
2108
|
+
if (THREE.NURBSCurve === undefined) {
|
|
2109
|
+
|
|
2110
|
+
console.error('THREE.FBXLoader: The loader relies on THREE.NURBSCurve for any nurbs present in the model. Nurbs will show up as empty geometry.');
|
|
2111
|
+
return new THREE.BufferGeometry();
|
|
2112
|
+
|
|
2113
|
+
}
|
|
2114
|
+
|
|
2115
|
+
const order = parseInt(geoNode.Order);
|
|
2116
|
+
|
|
2117
|
+
if (isNaN(order)) {
|
|
2118
|
+
|
|
2119
|
+
console.error('THREE.FBXLoader: Invalid Order %s given for geometry ID: %s', geoNode.Order, geoNode.id);
|
|
2120
|
+
return new THREE.BufferGeometry();
|
|
2121
|
+
|
|
2122
|
+
}
|
|
2123
|
+
|
|
2124
|
+
const degree = order - 1;
|
|
2125
|
+
const knots = geoNode.KnotVector.a;
|
|
2126
|
+
const controlPoints = [];
|
|
2127
|
+
const pointsValues = geoNode.Points.a;
|
|
2128
|
+
|
|
2129
|
+
for (let i = 0, l = pointsValues.length; i < l; i += 4) {
|
|
2130
|
+
|
|
2131
|
+
controlPoints.push(new THREE.Vector4().fromArray(pointsValues, i));
|
|
2132
|
+
|
|
2133
|
+
}
|
|
2134
|
+
|
|
2135
|
+
let startKnot, endKnot;
|
|
2136
|
+
|
|
2137
|
+
if (geoNode.Form === 'Closed') {
|
|
2138
|
+
|
|
2139
|
+
controlPoints.push(controlPoints[0]);
|
|
2140
|
+
|
|
2141
|
+
} else if (geoNode.Form === 'Periodic') {
|
|
2142
|
+
|
|
2143
|
+
startKnot = degree;
|
|
2144
|
+
endKnot = knots.length - 1 - startKnot;
|
|
2145
|
+
|
|
2146
|
+
for (let i = 0; i < degree; ++i) {
|
|
2147
|
+
|
|
2148
|
+
controlPoints.push(controlPoints[i]);
|
|
2149
|
+
|
|
2150
|
+
}
|
|
2151
|
+
|
|
2152
|
+
}
|
|
2153
|
+
|
|
2154
|
+
const curve = new THREE.NURBSCurve(degree, knots, controlPoints, startKnot, endKnot);
|
|
2155
|
+
const points = curve.getPoints(controlPoints.length * 12);
|
|
2156
|
+
return new THREE.BufferGeometry().setFromPoints(points);
|
|
2157
|
+
|
|
2158
|
+
}
|
|
2159
|
+
|
|
2160
|
+
} // parse animation data from FBXTree
|
|
2161
|
+
|
|
2162
|
+
|
|
2163
|
+
class AnimationParser {
|
|
2164
|
+
|
|
2165
|
+
// take raw animation clips and turn them into three.js animation clips
|
|
2166
|
+
parse() {
|
|
2167
|
+
|
|
2168
|
+
const animationClips = [];
|
|
2169
|
+
const rawClips = this.parseClips();
|
|
2170
|
+
|
|
2171
|
+
if (rawClips !== undefined) {
|
|
2172
|
+
|
|
2173
|
+
for (const key in rawClips) {
|
|
2174
|
+
|
|
2175
|
+
const rawClip = rawClips[key];
|
|
2176
|
+
const clip = this.addClip(rawClip);
|
|
2177
|
+
animationClips.push(clip);
|
|
2178
|
+
|
|
2179
|
+
}
|
|
2180
|
+
|
|
2181
|
+
}
|
|
2182
|
+
|
|
2183
|
+
return animationClips;
|
|
2184
|
+
|
|
2185
|
+
}
|
|
2186
|
+
|
|
2187
|
+
parseClips() {
|
|
2188
|
+
|
|
2189
|
+
// since the actual transformation data is stored in FBXTree.Objects.AnimationCurve,
|
|
2190
|
+
// if this is undefined we can safely assume there are no animations
|
|
2191
|
+
if (fbxTree.Objects.AnimationCurve === undefined) return undefined;
|
|
2192
|
+
const curveNodesMap = this.parseAnimationCurveNodes();
|
|
2193
|
+
this.parseAnimationCurves(curveNodesMap);
|
|
2194
|
+
const layersMap = this.parseAnimationLayers(curveNodesMap);
|
|
2195
|
+
const rawClips = this.parseAnimStacks(layersMap);
|
|
2196
|
+
return rawClips;
|
|
2197
|
+
|
|
2198
|
+
} // parse nodes in FBXTree.Objects.AnimationCurveNode
|
|
2199
|
+
// each AnimationCurveNode holds data for an animation transform for a model (e.g. left arm rotation )
|
|
2200
|
+
// and is referenced by an AnimationLayer
|
|
2201
|
+
|
|
2202
|
+
|
|
2203
|
+
parseAnimationCurveNodes() {
|
|
2204
|
+
|
|
2205
|
+
const rawCurveNodes = fbxTree.Objects.AnimationCurveNode;
|
|
2206
|
+
const curveNodesMap = new Map();
|
|
2207
|
+
|
|
2208
|
+
for (const nodeID in rawCurveNodes) {
|
|
2209
|
+
|
|
2210
|
+
const rawCurveNode = rawCurveNodes[nodeID];
|
|
2211
|
+
|
|
2212
|
+
if (rawCurveNode.attrName.match(/S|R|T|DeformPercent/) !== null) {
|
|
2213
|
+
|
|
2214
|
+
const curveNode = {
|
|
2215
|
+
id: rawCurveNode.id,
|
|
2216
|
+
attr: rawCurveNode.attrName,
|
|
2217
|
+
curves: {}
|
|
2218
|
+
};
|
|
2219
|
+
curveNodesMap.set(curveNode.id, curveNode);
|
|
2220
|
+
|
|
2221
|
+
}
|
|
2222
|
+
|
|
2223
|
+
}
|
|
2224
|
+
|
|
2225
|
+
return curveNodesMap;
|
|
2226
|
+
|
|
2227
|
+
} // parse nodes in FBXTree.Objects.AnimationCurve and connect them up to
|
|
2228
|
+
// previously parsed AnimationCurveNodes. Each AnimationCurve holds data for a single animated
|
|
2229
|
+
// axis ( e.g. times and values of x rotation)
|
|
2230
|
+
|
|
2231
|
+
|
|
2232
|
+
parseAnimationCurves(curveNodesMap) {
|
|
2233
|
+
|
|
2234
|
+
const rawCurves = fbxTree.Objects.AnimationCurve; // TODO: Many values are identical up to roundoff error, but won't be optimised
|
|
2235
|
+
// e.g. position times: [0, 0.4, 0. 8]
|
|
2236
|
+
// position values: [7.23538335023477e-7, 93.67518615722656, -0.9982695579528809, 7.23538335023477e-7, 93.67518615722656, -0.9982695579528809, 7.235384487103147e-7, 93.67520904541016, -0.9982695579528809]
|
|
2237
|
+
// clearly, this should be optimised to
|
|
2238
|
+
// times: [0], positions [7.23538335023477e-7, 93.67518615722656, -0.9982695579528809]
|
|
2239
|
+
// this shows up in nearly every FBX file, and generally time array is length > 100
|
|
2240
|
+
|
|
2241
|
+
for (const nodeID in rawCurves) {
|
|
2242
|
+
|
|
2243
|
+
const animationCurve = {
|
|
2244
|
+
id: rawCurves[nodeID].id,
|
|
2245
|
+
times: rawCurves[nodeID].KeyTime.a.map(convertFBXTimeToSeconds),
|
|
2246
|
+
values: rawCurves[nodeID].KeyValueFloat.a
|
|
2247
|
+
};
|
|
2248
|
+
const relationships = connections.get(animationCurve.id);
|
|
2249
|
+
|
|
2250
|
+
if (relationships !== undefined) {
|
|
2251
|
+
|
|
2252
|
+
const animationCurveID = relationships.parents[0].ID;
|
|
2253
|
+
const animationCurveRelationship = relationships.parents[0].relationship;
|
|
2254
|
+
|
|
2255
|
+
if (animationCurveRelationship.match(/X/)) {
|
|
2256
|
+
|
|
2257
|
+
curveNodesMap.get(animationCurveID).curves['x'] = animationCurve;
|
|
2258
|
+
|
|
2259
|
+
} else if (animationCurveRelationship.match(/Y/)) {
|
|
2260
|
+
|
|
2261
|
+
curveNodesMap.get(animationCurveID).curves['y'] = animationCurve;
|
|
2262
|
+
|
|
2263
|
+
} else if (animationCurveRelationship.match(/Z/)) {
|
|
2264
|
+
|
|
2265
|
+
curveNodesMap.get(animationCurveID).curves['z'] = animationCurve;
|
|
2266
|
+
|
|
2267
|
+
} else if (animationCurveRelationship.match(/d|DeformPercent/) && curveNodesMap.has(animationCurveID)) {
|
|
2268
|
+
|
|
2269
|
+
curveNodesMap.get(animationCurveID).curves['morph'] = animationCurve;
|
|
2270
|
+
|
|
2271
|
+
}
|
|
2272
|
+
|
|
2273
|
+
}
|
|
2274
|
+
|
|
2275
|
+
}
|
|
2276
|
+
|
|
2277
|
+
} // parse nodes in FBXTree.Objects.AnimationLayer. Each layers holds references
|
|
2278
|
+
// to various AnimationCurveNodes and is referenced by an AnimationStack node
|
|
2279
|
+
// note: theoretically a stack can have multiple layers, however in practice there always seems to be one per stack
|
|
2280
|
+
|
|
2281
|
+
|
|
2282
|
+
parseAnimationLayers(curveNodesMap) {
|
|
2283
|
+
|
|
2284
|
+
const rawLayers = fbxTree.Objects.AnimationLayer;
|
|
2285
|
+
const layersMap = new Map();
|
|
2286
|
+
|
|
2287
|
+
for (const nodeID in rawLayers) {
|
|
2288
|
+
|
|
2289
|
+
const layerCurveNodes = [];
|
|
2290
|
+
const connection = connections.get(parseInt(nodeID));
|
|
2291
|
+
|
|
2292
|
+
if (connection !== undefined) {
|
|
2293
|
+
|
|
2294
|
+
// all the animationCurveNodes used in the layer
|
|
2295
|
+
const children = connection.children;
|
|
2296
|
+
children.forEach(function (child, i) {
|
|
2297
|
+
|
|
2298
|
+
if (curveNodesMap.has(child.ID)) {
|
|
2299
|
+
|
|
2300
|
+
const curveNode = curveNodesMap.get(child.ID); // check that the curves are defined for at least one axis, otherwise ignore the curveNode
|
|
2301
|
+
|
|
2302
|
+
if (curveNode.curves.x !== undefined || curveNode.curves.y !== undefined || curveNode.curves.z !== undefined) {
|
|
2303
|
+
|
|
2304
|
+
if (layerCurveNodes[i] === undefined) {
|
|
2305
|
+
|
|
2306
|
+
const modelID = connections.get(child.ID).parents.filter(function (parent) {
|
|
2307
|
+
|
|
2308
|
+
return parent.relationship !== undefined;
|
|
2309
|
+
|
|
2310
|
+
})[0].ID;
|
|
2311
|
+
|
|
2312
|
+
if (modelID !== undefined) {
|
|
2313
|
+
|
|
2314
|
+
const rawModel = fbxTree.Objects.Model[modelID.toString()];
|
|
2315
|
+
|
|
2316
|
+
if (rawModel === undefined) {
|
|
2317
|
+
|
|
2318
|
+
console.warn('THREE.FBXLoader: Encountered a unused curve.', child);
|
|
2319
|
+
return;
|
|
2320
|
+
|
|
2321
|
+
}
|
|
2322
|
+
|
|
2323
|
+
const node = {
|
|
2324
|
+
modelName: rawModel.attrName ? THREE.PropertyBinding.sanitizeNodeName(rawModel.attrName) : '',
|
|
2325
|
+
ID: rawModel.id,
|
|
2326
|
+
initialPosition: [0, 0, 0],
|
|
2327
|
+
initialRotation: [0, 0, 0],
|
|
2328
|
+
initialScale: [1, 1, 1]
|
|
2329
|
+
};
|
|
2330
|
+
sceneGraph.traverse(function (child) {
|
|
2331
|
+
|
|
2332
|
+
if (child.ID === rawModel.id) {
|
|
2333
|
+
|
|
2334
|
+
node.transform = child.matrix;
|
|
2335
|
+
if (child.userData.transformData) node.eulerOrder = child.userData.transformData.eulerOrder;
|
|
2336
|
+
|
|
2337
|
+
}
|
|
2338
|
+
|
|
2339
|
+
});
|
|
2340
|
+
if (!node.transform) node.transform = new THREE.Matrix4(); // if the animated model is pre rotated, we'll have to apply the pre rotations to every
|
|
2341
|
+
// animation value as well
|
|
2342
|
+
|
|
2343
|
+
if ('PreRotation' in rawModel) node.preRotation = rawModel.PreRotation.value;
|
|
2344
|
+
if ('PostRotation' in rawModel) node.postRotation = rawModel.PostRotation.value;
|
|
2345
|
+
layerCurveNodes[i] = node;
|
|
2346
|
+
|
|
2347
|
+
}
|
|
2348
|
+
|
|
2349
|
+
}
|
|
2350
|
+
|
|
2351
|
+
if (layerCurveNodes[i]) layerCurveNodes[i][curveNode.attr] = curveNode;
|
|
2352
|
+
|
|
2353
|
+
} else if (curveNode.curves.morph !== undefined) {
|
|
2354
|
+
|
|
2355
|
+
if (layerCurveNodes[i] === undefined) {
|
|
2356
|
+
|
|
2357
|
+
const deformerID = connections.get(child.ID).parents.filter(function (parent) {
|
|
2358
|
+
|
|
2359
|
+
return parent.relationship !== undefined;
|
|
2360
|
+
|
|
2361
|
+
})[0].ID;
|
|
2362
|
+
const morpherID = connections.get(deformerID).parents[0].ID;
|
|
2363
|
+
const geoID = connections.get(morpherID).parents[0].ID; // assuming geometry is not used in more than one model
|
|
2364
|
+
|
|
2365
|
+
const modelID = connections.get(geoID).parents[0].ID;
|
|
2366
|
+
const rawModel = fbxTree.Objects.Model[modelID];
|
|
2367
|
+
const node = {
|
|
2368
|
+
modelName: rawModel.attrName ? THREE.PropertyBinding.sanitizeNodeName(rawModel.attrName) : '',
|
|
2369
|
+
morphName: fbxTree.Objects.Deformer[deformerID].attrName
|
|
2370
|
+
};
|
|
2371
|
+
layerCurveNodes[i] = node;
|
|
2372
|
+
|
|
2373
|
+
}
|
|
2374
|
+
|
|
2375
|
+
layerCurveNodes[i][curveNode.attr] = curveNode;
|
|
2376
|
+
|
|
2377
|
+
}
|
|
2378
|
+
|
|
2379
|
+
}
|
|
2380
|
+
|
|
2381
|
+
});
|
|
2382
|
+
layersMap.set(parseInt(nodeID), layerCurveNodes);
|
|
2383
|
+
|
|
2384
|
+
}
|
|
2385
|
+
|
|
2386
|
+
}
|
|
2387
|
+
|
|
2388
|
+
return layersMap;
|
|
2389
|
+
|
|
2390
|
+
} // parse nodes in FBXTree.Objects.AnimationStack. These are the top level node in the animation
|
|
2391
|
+
// hierarchy. Each Stack node will be used to create a THREE.AnimationClip
|
|
2392
|
+
|
|
2393
|
+
|
|
2394
|
+
parseAnimStacks(layersMap) {
|
|
2395
|
+
|
|
2396
|
+
const rawStacks = fbxTree.Objects.AnimationStack; // connect the stacks (clips) up to the layers
|
|
2397
|
+
|
|
2398
|
+
const rawClips = {};
|
|
2399
|
+
|
|
2400
|
+
for (const nodeID in rawStacks) {
|
|
2401
|
+
|
|
2402
|
+
const children = connections.get(parseInt(nodeID)).children;
|
|
2403
|
+
|
|
2404
|
+
if (children.length > 1) {
|
|
2405
|
+
|
|
2406
|
+
// it seems like stacks will always be associated with a single layer. But just in case there are files
|
|
2407
|
+
// where there are multiple layers per stack, we'll display a warning
|
|
2408
|
+
console.warn('THREE.FBXLoader: Encountered an animation stack with multiple layers, this is currently not supported. Ignoring subsequent layers.');
|
|
2409
|
+
|
|
2410
|
+
}
|
|
2411
|
+
|
|
2412
|
+
const layer = layersMap.get(children[0].ID);
|
|
2413
|
+
rawClips[nodeID] = {
|
|
2414
|
+
name: rawStacks[nodeID].attrName,
|
|
2415
|
+
layer: layer
|
|
2416
|
+
};
|
|
2417
|
+
|
|
2418
|
+
}
|
|
2419
|
+
|
|
2420
|
+
return rawClips;
|
|
2421
|
+
|
|
2422
|
+
}
|
|
2423
|
+
|
|
2424
|
+
addClip(rawClip) {
|
|
2425
|
+
|
|
2426
|
+
let tracks = [];
|
|
2427
|
+
const scope = this;
|
|
2428
|
+
rawClip.layer.forEach(function (rawTracks) {
|
|
2429
|
+
|
|
2430
|
+
tracks = tracks.concat(scope.generateTracks(rawTracks));
|
|
2431
|
+
|
|
2432
|
+
});
|
|
2433
|
+
return new THREE.AnimationClip(rawClip.name, - 1, tracks);
|
|
2434
|
+
|
|
2435
|
+
}
|
|
2436
|
+
|
|
2437
|
+
generateTracks(rawTracks) {
|
|
2438
|
+
|
|
2439
|
+
const tracks = [];
|
|
2440
|
+
let initialPosition = new THREE.Vector3();
|
|
2441
|
+
let initialRotation = new THREE.Quaternion();
|
|
2442
|
+
let initialScale = new THREE.Vector3();
|
|
2443
|
+
if (rawTracks.transform) rawTracks.transform.decompose(initialPosition, initialRotation, initialScale);
|
|
2444
|
+
initialPosition = initialPosition.toArray();
|
|
2445
|
+
initialRotation = new THREE.Euler().setFromQuaternion(initialRotation, rawTracks.eulerOrder).toArray();
|
|
2446
|
+
initialScale = initialScale.toArray();
|
|
2447
|
+
|
|
2448
|
+
if (rawTracks.T !== undefined && Object.keys(rawTracks.T.curves).length > 0) {
|
|
2449
|
+
|
|
2450
|
+
const positionTrack = this.generateVectorTrack(rawTracks.modelName, rawTracks.T.curves, initialPosition, 'position');
|
|
2451
|
+
if (positionTrack !== undefined) tracks.push(positionTrack);
|
|
2452
|
+
|
|
2453
|
+
}
|
|
2454
|
+
|
|
2455
|
+
if (rawTracks.R !== undefined && Object.keys(rawTracks.R.curves).length > 0) {
|
|
2456
|
+
|
|
2457
|
+
const rotationTrack = this.generateRotationTrack(rawTracks.modelName, rawTracks.R.curves, initialRotation, rawTracks.preRotation, rawTracks.postRotation, rawTracks.eulerOrder);
|
|
2458
|
+
if (rotationTrack !== undefined) tracks.push(rotationTrack);
|
|
2459
|
+
|
|
2460
|
+
}
|
|
2461
|
+
|
|
2462
|
+
if (rawTracks.S !== undefined && Object.keys(rawTracks.S.curves).length > 0) {
|
|
2463
|
+
|
|
2464
|
+
const scaleTrack = this.generateVectorTrack(rawTracks.modelName, rawTracks.S.curves, initialScale, 'scale');
|
|
2465
|
+
if (scaleTrack !== undefined) tracks.push(scaleTrack);
|
|
2466
|
+
|
|
2467
|
+
}
|
|
2468
|
+
|
|
2469
|
+
if (rawTracks.DeformPercent !== undefined) {
|
|
2470
|
+
|
|
2471
|
+
const morphTrack = this.generateMorphTrack(rawTracks);
|
|
2472
|
+
if (morphTrack !== undefined) tracks.push(morphTrack);
|
|
2473
|
+
|
|
2474
|
+
}
|
|
2475
|
+
|
|
2476
|
+
return tracks;
|
|
2477
|
+
|
|
2478
|
+
}
|
|
2479
|
+
|
|
2480
|
+
generateVectorTrack(modelName, curves, initialValue, type) {
|
|
2481
|
+
|
|
2482
|
+
const times = this.getTimesForAllAxes(curves);
|
|
2483
|
+
const values = this.getKeyframeTrackValues(times, curves, initialValue);
|
|
2484
|
+
return new THREE.VectorKeyframeTrack(modelName + '.' + type, times, values);
|
|
2485
|
+
|
|
2486
|
+
}
|
|
2487
|
+
|
|
2488
|
+
generateRotationTrack(modelName, curves, initialValue, preRotation, postRotation, eulerOrder) {
|
|
2489
|
+
|
|
2490
|
+
if (curves.x !== undefined) {
|
|
2491
|
+
|
|
2492
|
+
this.interpolateRotations(curves.x);
|
|
2493
|
+
curves.x.values = curves.x.values.map(THREE.MathUtils.degToRad);
|
|
2494
|
+
|
|
2495
|
+
}
|
|
2496
|
+
|
|
2497
|
+
if (curves.y !== undefined) {
|
|
2498
|
+
|
|
2499
|
+
this.interpolateRotations(curves.y);
|
|
2500
|
+
curves.y.values = curves.y.values.map(THREE.MathUtils.degToRad);
|
|
2501
|
+
|
|
2502
|
+
}
|
|
2503
|
+
|
|
2504
|
+
if (curves.z !== undefined) {
|
|
2505
|
+
|
|
2506
|
+
this.interpolateRotations(curves.z);
|
|
2507
|
+
curves.z.values = curves.z.values.map(THREE.MathUtils.degToRad);
|
|
2508
|
+
|
|
2509
|
+
}
|
|
2510
|
+
|
|
2511
|
+
const times = this.getTimesForAllAxes(curves);
|
|
2512
|
+
const values = this.getKeyframeTrackValues(times, curves, initialValue);
|
|
2513
|
+
|
|
2514
|
+
if (preRotation !== undefined) {
|
|
2515
|
+
|
|
2516
|
+
preRotation = preRotation.map(THREE.MathUtils.degToRad);
|
|
2517
|
+
preRotation.push(eulerOrder);
|
|
2518
|
+
preRotation = new THREE.Euler().fromArray(preRotation);
|
|
2519
|
+
preRotation = new THREE.Quaternion().setFromEuler(preRotation);
|
|
2520
|
+
|
|
2521
|
+
}
|
|
2522
|
+
|
|
2523
|
+
if (postRotation !== undefined) {
|
|
2524
|
+
|
|
2525
|
+
postRotation = postRotation.map(THREE.MathUtils.degToRad);
|
|
2526
|
+
postRotation.push(eulerOrder);
|
|
2527
|
+
postRotation = new THREE.Euler().fromArray(postRotation);
|
|
2528
|
+
postRotation = new THREE.Quaternion().setFromEuler(postRotation).invert();
|
|
2529
|
+
|
|
2530
|
+
}
|
|
2531
|
+
|
|
2532
|
+
const quaternion = new THREE.Quaternion();
|
|
2533
|
+
const euler = new THREE.Euler();
|
|
2534
|
+
const quaternionValues = [];
|
|
2535
|
+
|
|
2536
|
+
for (let i = 0; i < values.length; i += 3) {
|
|
2537
|
+
|
|
2538
|
+
euler.set(values[i], values[i + 1], values[i + 2], eulerOrder);
|
|
2539
|
+
quaternion.setFromEuler(euler);
|
|
2540
|
+
if (preRotation !== undefined) quaternion.premultiply(preRotation);
|
|
2541
|
+
if (postRotation !== undefined) quaternion.multiply(postRotation);
|
|
2542
|
+
quaternion.toArray(quaternionValues, i / 3 * 4);
|
|
2543
|
+
|
|
2544
|
+
}
|
|
2545
|
+
|
|
2546
|
+
return new THREE.QuaternionKeyframeTrack(modelName + '.quaternion', times, quaternionValues);
|
|
2547
|
+
|
|
2548
|
+
}
|
|
2549
|
+
|
|
2550
|
+
generateMorphTrack(rawTracks) {
|
|
2551
|
+
|
|
2552
|
+
const curves = rawTracks.DeformPercent.curves.morph;
|
|
2553
|
+
const values = curves.values.map(function (val) {
|
|
2554
|
+
|
|
2555
|
+
return val / 100;
|
|
2556
|
+
|
|
2557
|
+
});
|
|
2558
|
+
const morphNum = sceneGraph.getObjectByName(rawTracks.modelName).morphTargetDictionary[rawTracks.morphName];
|
|
2559
|
+
return new THREE.NumberKeyframeTrack(rawTracks.modelName + '.morphTargetInfluences[' + morphNum + ']', curves.times, values);
|
|
2560
|
+
|
|
2561
|
+
} // For all animated objects, times are defined separately for each axis
|
|
2562
|
+
// Here we'll combine the times into one sorted array without duplicates
|
|
2563
|
+
|
|
2564
|
+
|
|
2565
|
+
getTimesForAllAxes(curves) {
|
|
2566
|
+
|
|
2567
|
+
let times = []; // first join together the times for each axis, if defined
|
|
2568
|
+
|
|
2569
|
+
if (curves.x !== undefined) times = times.concat(curves.x.times);
|
|
2570
|
+
if (curves.y !== undefined) times = times.concat(curves.y.times);
|
|
2571
|
+
if (curves.z !== undefined) times = times.concat(curves.z.times); // then sort them
|
|
2572
|
+
|
|
2573
|
+
times = times.sort(function (a, b) {
|
|
2574
|
+
|
|
2575
|
+
return a - b;
|
|
2576
|
+
|
|
2577
|
+
}); // and remove duplicates
|
|
2578
|
+
|
|
2579
|
+
if (times.length > 1) {
|
|
2580
|
+
|
|
2581
|
+
let targetIndex = 1;
|
|
2582
|
+
let lastValue = times[0];
|
|
2583
|
+
|
|
2584
|
+
for (let i = 1; i < times.length; i++) {
|
|
2585
|
+
|
|
2586
|
+
const currentValue = times[i];
|
|
2587
|
+
|
|
2588
|
+
if (currentValue !== lastValue) {
|
|
2589
|
+
|
|
2590
|
+
times[targetIndex] = currentValue;
|
|
2591
|
+
lastValue = currentValue;
|
|
2592
|
+
targetIndex++;
|
|
2593
|
+
|
|
2594
|
+
}
|
|
2595
|
+
|
|
2596
|
+
}
|
|
2597
|
+
|
|
2598
|
+
times = times.slice(0, targetIndex);
|
|
2599
|
+
|
|
2600
|
+
}
|
|
2601
|
+
|
|
2602
|
+
return times;
|
|
2603
|
+
|
|
2604
|
+
}
|
|
2605
|
+
|
|
2606
|
+
getKeyframeTrackValues(times, curves, initialValue) {
|
|
2607
|
+
|
|
2608
|
+
const prevValue = initialValue;
|
|
2609
|
+
const values = [];
|
|
2610
|
+
let xIndex = - 1;
|
|
2611
|
+
let yIndex = - 1;
|
|
2612
|
+
let zIndex = - 1;
|
|
2613
|
+
times.forEach(function (time) {
|
|
2614
|
+
|
|
2615
|
+
if (curves.x) xIndex = curves.x.times.indexOf(time);
|
|
2616
|
+
if (curves.y) yIndex = curves.y.times.indexOf(time);
|
|
2617
|
+
if (curves.z) zIndex = curves.z.times.indexOf(time); // if there is an x value defined for this frame, use that
|
|
2618
|
+
|
|
2619
|
+
if (xIndex !== - 1) {
|
|
2620
|
+
|
|
2621
|
+
const xValue = curves.x.values[xIndex];
|
|
2622
|
+
values.push(xValue);
|
|
2623
|
+
prevValue[0] = xValue;
|
|
2624
|
+
|
|
2625
|
+
} else {
|
|
2626
|
+
|
|
2627
|
+
// otherwise use the x value from the previous frame
|
|
2628
|
+
values.push(prevValue[0]);
|
|
2629
|
+
|
|
2630
|
+
}
|
|
2631
|
+
|
|
2632
|
+
if (yIndex !== - 1) {
|
|
2633
|
+
|
|
2634
|
+
const yValue = curves.y.values[yIndex];
|
|
2635
|
+
values.push(yValue);
|
|
2636
|
+
prevValue[1] = yValue;
|
|
2637
|
+
|
|
2638
|
+
} else {
|
|
2639
|
+
|
|
2640
|
+
values.push(prevValue[1]);
|
|
2641
|
+
|
|
2642
|
+
}
|
|
2643
|
+
|
|
2644
|
+
if (zIndex !== - 1) {
|
|
2645
|
+
|
|
2646
|
+
const zValue = curves.z.values[zIndex];
|
|
2647
|
+
values.push(zValue);
|
|
2648
|
+
prevValue[2] = zValue;
|
|
2649
|
+
|
|
2650
|
+
} else {
|
|
2651
|
+
|
|
2652
|
+
values.push(prevValue[2]);
|
|
2653
|
+
|
|
2654
|
+
}
|
|
2655
|
+
|
|
2656
|
+
});
|
|
2657
|
+
return values;
|
|
2658
|
+
|
|
2659
|
+
} // Rotations are defined as THREE.Euler angles which can have values of any size
|
|
2660
|
+
// These will be converted to quaternions which don't support values greater than
|
|
2661
|
+
// PI, so we'll interpolate large rotations
|
|
2662
|
+
|
|
2663
|
+
|
|
2664
|
+
interpolateRotations(curve) {
|
|
2665
|
+
|
|
2666
|
+
for (let i = 1; i < curve.values.length; i++) {
|
|
2667
|
+
|
|
2668
|
+
const initialValue = curve.values[i - 1];
|
|
2669
|
+
const valuesSpan = curve.values[i] - initialValue;
|
|
2670
|
+
const absoluteSpan = Math.abs(valuesSpan);
|
|
2671
|
+
|
|
2672
|
+
if (absoluteSpan >= 180) {
|
|
2673
|
+
|
|
2674
|
+
const numSubIntervals = absoluteSpan / 180;
|
|
2675
|
+
const step = valuesSpan / numSubIntervals;
|
|
2676
|
+
let nextValue = initialValue + step;
|
|
2677
|
+
const initialTime = curve.times[i - 1];
|
|
2678
|
+
const timeSpan = curve.times[i] - initialTime;
|
|
2679
|
+
const interval = timeSpan / numSubIntervals;
|
|
2680
|
+
let nextTime = initialTime + interval;
|
|
2681
|
+
const interpolatedTimes = [];
|
|
2682
|
+
const interpolatedValues = [];
|
|
2683
|
+
|
|
2684
|
+
while (nextTime < curve.times[i]) {
|
|
2685
|
+
|
|
2686
|
+
interpolatedTimes.push(nextTime);
|
|
2687
|
+
nextTime += interval;
|
|
2688
|
+
interpolatedValues.push(nextValue);
|
|
2689
|
+
nextValue += step;
|
|
2690
|
+
|
|
2691
|
+
}
|
|
2692
|
+
|
|
2693
|
+
curve.times = inject(curve.times, i, interpolatedTimes);
|
|
2694
|
+
curve.values = inject(curve.values, i, interpolatedValues);
|
|
2695
|
+
|
|
2696
|
+
}
|
|
2697
|
+
|
|
2698
|
+
}
|
|
2699
|
+
|
|
2700
|
+
}
|
|
2701
|
+
|
|
2702
|
+
} // parse an FBX file in ASCII format
|
|
2703
|
+
|
|
2704
|
+
|
|
2705
|
+
class TextParser {
|
|
2706
|
+
|
|
2707
|
+
getPrevNode() {
|
|
2708
|
+
|
|
2709
|
+
return this.nodeStack[this.currentIndent - 2];
|
|
2710
|
+
|
|
2711
|
+
}
|
|
2712
|
+
|
|
2713
|
+
getCurrentNode() {
|
|
2714
|
+
|
|
2715
|
+
return this.nodeStack[this.currentIndent - 1];
|
|
2716
|
+
|
|
2717
|
+
}
|
|
2718
|
+
|
|
2719
|
+
getCurrentProp() {
|
|
2720
|
+
|
|
2721
|
+
return this.currentProp;
|
|
2722
|
+
|
|
2723
|
+
}
|
|
2724
|
+
|
|
2725
|
+
pushStack(node) {
|
|
2726
|
+
|
|
2727
|
+
this.nodeStack.push(node);
|
|
2728
|
+
this.currentIndent += 1;
|
|
2729
|
+
|
|
2730
|
+
}
|
|
2731
|
+
|
|
2732
|
+
popStack() {
|
|
2733
|
+
|
|
2734
|
+
this.nodeStack.pop();
|
|
2735
|
+
this.currentIndent -= 1;
|
|
2736
|
+
|
|
2737
|
+
}
|
|
2738
|
+
|
|
2739
|
+
setCurrentProp(val, name) {
|
|
2740
|
+
|
|
2741
|
+
this.currentProp = val;
|
|
2742
|
+
this.currentPropName = name;
|
|
2743
|
+
|
|
2744
|
+
}
|
|
2745
|
+
|
|
2746
|
+
parse(text) {
|
|
2747
|
+
|
|
2748
|
+
this.currentIndent = 0;
|
|
2749
|
+
this.allNodes = new FBXTree();
|
|
2750
|
+
this.nodeStack = [];
|
|
2751
|
+
this.currentProp = [];
|
|
2752
|
+
this.currentPropName = '';
|
|
2753
|
+
const scope = this;
|
|
2754
|
+
const split = text.split(/[\r\n]+/);
|
|
2755
|
+
split.forEach(function (line, i) {
|
|
2756
|
+
|
|
2757
|
+
const matchComment = line.match(/^[\s\t]*;/);
|
|
2758
|
+
const matchEmpty = line.match(/^[\s\t]*$/);
|
|
2759
|
+
if (matchComment || matchEmpty) return;
|
|
2760
|
+
const matchBeginning = line.match('^\\t{' + scope.currentIndent + '}(\\w+):(.*){', '');
|
|
2761
|
+
const matchProperty = line.match('^\\t{' + scope.currentIndent + '}(\\w+):[\\s\\t\\r\\n](.*)');
|
|
2762
|
+
const matchEnd = line.match('^\\t{' + (scope.currentIndent - 1) + '}}');
|
|
2763
|
+
|
|
2764
|
+
if (matchBeginning) {
|
|
2765
|
+
|
|
2766
|
+
scope.parseNodeBegin(line, matchBeginning);
|
|
2767
|
+
|
|
2768
|
+
} else if (matchProperty) {
|
|
2769
|
+
|
|
2770
|
+
scope.parseNodeProperty(line, matchProperty, split[++i]);
|
|
2771
|
+
|
|
2772
|
+
} else if (matchEnd) {
|
|
2773
|
+
|
|
2774
|
+
scope.popStack();
|
|
2775
|
+
|
|
2776
|
+
} else if (line.match(/^[^\s\t}]/)) {
|
|
2777
|
+
|
|
2778
|
+
// large arrays are split over multiple lines terminated with a ',' character
|
|
2779
|
+
// if this is encountered the line needs to be joined to the previous line
|
|
2780
|
+
scope.parseNodePropertyContinued(line);
|
|
2781
|
+
|
|
2782
|
+
}
|
|
2783
|
+
|
|
2784
|
+
});
|
|
2785
|
+
return this.allNodes;
|
|
2786
|
+
|
|
2787
|
+
}
|
|
2788
|
+
|
|
2789
|
+
parseNodeBegin(line, property) {
|
|
2790
|
+
|
|
2791
|
+
const nodeName = property[1].trim().replace(/^"/, '').replace(/"$/, '');
|
|
2792
|
+
const nodeAttrs = property[2].split(',').map(function (attr) {
|
|
2793
|
+
|
|
2794
|
+
return attr.trim().replace(/^"/, '').replace(/"$/, '');
|
|
2795
|
+
|
|
2796
|
+
});
|
|
2797
|
+
const node = {
|
|
2798
|
+
name: nodeName
|
|
2799
|
+
};
|
|
2800
|
+
const attrs = this.parseNodeAttr(nodeAttrs);
|
|
2801
|
+
const currentNode = this.getCurrentNode(); // a top node
|
|
2802
|
+
|
|
2803
|
+
if (this.currentIndent === 0) {
|
|
2804
|
+
|
|
2805
|
+
this.allNodes.add(nodeName, node);
|
|
2806
|
+
|
|
2807
|
+
} else {
|
|
2808
|
+
|
|
2809
|
+
// a subnode
|
|
2810
|
+
// if the subnode already exists, append it
|
|
2811
|
+
if (nodeName in currentNode) {
|
|
2812
|
+
|
|
2813
|
+
// special case Pose needs PoseNodes as an array
|
|
2814
|
+
if (nodeName === 'PoseNode') {
|
|
2815
|
+
|
|
2816
|
+
currentNode.PoseNode.push(node);
|
|
2817
|
+
|
|
2818
|
+
} else if (currentNode[nodeName].id !== undefined) {
|
|
2819
|
+
|
|
2820
|
+
currentNode[nodeName] = {};
|
|
2821
|
+
currentNode[nodeName][currentNode[nodeName].id] = currentNode[nodeName];
|
|
2822
|
+
|
|
2823
|
+
}
|
|
2824
|
+
|
|
2825
|
+
if (attrs.id !== '') currentNode[nodeName][attrs.id] = node;
|
|
2826
|
+
|
|
2827
|
+
} else if (typeof attrs.id === 'number') {
|
|
2828
|
+
|
|
2829
|
+
currentNode[nodeName] = {};
|
|
2830
|
+
currentNode[nodeName][attrs.id] = node;
|
|
2831
|
+
|
|
2832
|
+
} else if (nodeName !== 'Properties70') {
|
|
2833
|
+
|
|
2834
|
+
if (nodeName === 'PoseNode') currentNode[nodeName] = [node]; else currentNode[nodeName] = node;
|
|
2835
|
+
|
|
2836
|
+
}
|
|
2837
|
+
|
|
2838
|
+
}
|
|
2839
|
+
|
|
2840
|
+
if (typeof attrs.id === 'number') node.id = attrs.id;
|
|
2841
|
+
if (attrs.name !== '') node.attrName = attrs.name;
|
|
2842
|
+
if (attrs.type !== '') node.attrType = attrs.type;
|
|
2843
|
+
this.pushStack(node);
|
|
2844
|
+
|
|
2845
|
+
}
|
|
2846
|
+
|
|
2847
|
+
parseNodeAttr(attrs) {
|
|
2848
|
+
|
|
2849
|
+
let id = attrs[0];
|
|
2850
|
+
|
|
2851
|
+
if (attrs[0] !== '') {
|
|
2852
|
+
|
|
2853
|
+
id = parseInt(attrs[0]);
|
|
2854
|
+
|
|
2855
|
+
if (isNaN(id)) {
|
|
2856
|
+
|
|
2857
|
+
id = attrs[0];
|
|
2858
|
+
|
|
2859
|
+
}
|
|
2860
|
+
|
|
2861
|
+
}
|
|
2862
|
+
|
|
2863
|
+
let name = '',
|
|
2864
|
+
type = '';
|
|
2865
|
+
|
|
2866
|
+
if (attrs.length > 1) {
|
|
2867
|
+
|
|
2868
|
+
name = attrs[1].replace(/^(\w+)::/, '');
|
|
2869
|
+
type = attrs[2];
|
|
2870
|
+
|
|
2871
|
+
}
|
|
2872
|
+
|
|
2873
|
+
return {
|
|
2874
|
+
id: id,
|
|
2875
|
+
name: name,
|
|
2876
|
+
type: type
|
|
2877
|
+
};
|
|
2878
|
+
|
|
2879
|
+
}
|
|
2880
|
+
|
|
2881
|
+
parseNodeProperty(line, property, contentLine) {
|
|
2882
|
+
|
|
2883
|
+
let propName = property[1].replace(/^"/, '').replace(/"$/, '').trim();
|
|
2884
|
+
let propValue = property[2].replace(/^"/, '').replace(/"$/, '').trim(); // for special case: base64 image data follows "Content: ," line
|
|
2885
|
+
// Content: ,
|
|
2886
|
+
// "/9j/4RDaRXhpZgAATU0A..."
|
|
2887
|
+
|
|
2888
|
+
if (propName === 'Content' && propValue === ',') {
|
|
2889
|
+
|
|
2890
|
+
propValue = contentLine.replace(/"/g, '').replace(/,$/, '').trim();
|
|
2891
|
+
|
|
2892
|
+
}
|
|
2893
|
+
|
|
2894
|
+
const currentNode = this.getCurrentNode();
|
|
2895
|
+
const parentName = currentNode.name;
|
|
2896
|
+
|
|
2897
|
+
if (parentName === 'Properties70') {
|
|
2898
|
+
|
|
2899
|
+
this.parseNodeSpecialProperty(line, propName, propValue);
|
|
2900
|
+
return;
|
|
2901
|
+
|
|
2902
|
+
} // Connections
|
|
2903
|
+
|
|
2904
|
+
|
|
2905
|
+
if (propName === 'C') {
|
|
2906
|
+
|
|
2907
|
+
const connProps = propValue.split(',').slice(1);
|
|
2908
|
+
const from = parseInt(connProps[0]);
|
|
2909
|
+
const to = parseInt(connProps[1]);
|
|
2910
|
+
let rest = propValue.split(',').slice(3);
|
|
2911
|
+
rest = rest.map(function (elem) {
|
|
2912
|
+
|
|
2913
|
+
return elem.trim().replace(/^"/, '');
|
|
2914
|
+
|
|
2915
|
+
});
|
|
2916
|
+
propName = 'connections';
|
|
2917
|
+
propValue = [from, to];
|
|
2918
|
+
append(propValue, rest);
|
|
2919
|
+
|
|
2920
|
+
if (currentNode[propName] === undefined) {
|
|
2921
|
+
|
|
2922
|
+
currentNode[propName] = [];
|
|
2923
|
+
|
|
2924
|
+
}
|
|
2925
|
+
|
|
2926
|
+
} // Node
|
|
2927
|
+
|
|
2928
|
+
|
|
2929
|
+
if (propName === 'Node') currentNode.id = propValue; // connections
|
|
2930
|
+
|
|
2931
|
+
if (propName in currentNode && Array.isArray(currentNode[propName])) {
|
|
2932
|
+
|
|
2933
|
+
currentNode[propName].push(propValue);
|
|
2934
|
+
|
|
2935
|
+
} else {
|
|
2936
|
+
|
|
2937
|
+
if (propName !== 'a') currentNode[propName] = propValue; else currentNode.a = propValue;
|
|
2938
|
+
|
|
2939
|
+
}
|
|
2940
|
+
|
|
2941
|
+
this.setCurrentProp(currentNode, propName); // convert string to array, unless it ends in ',' in which case more will be added to it
|
|
2942
|
+
|
|
2943
|
+
if (propName === 'a' && propValue.slice(- 1) !== ',') {
|
|
2944
|
+
|
|
2945
|
+
currentNode.a = parseNumberArray(propValue);
|
|
2946
|
+
|
|
2947
|
+
}
|
|
2948
|
+
|
|
2949
|
+
}
|
|
2950
|
+
|
|
2951
|
+
parseNodePropertyContinued(line) {
|
|
2952
|
+
|
|
2953
|
+
const currentNode = this.getCurrentNode();
|
|
2954
|
+
currentNode.a += line; // if the line doesn't end in ',' we have reached the end of the property value
|
|
2955
|
+
// so convert the string to an array
|
|
2956
|
+
|
|
2957
|
+
if (line.slice(- 1) !== ',') {
|
|
2958
|
+
|
|
2959
|
+
currentNode.a = parseNumberArray(currentNode.a);
|
|
2960
|
+
|
|
2961
|
+
}
|
|
2962
|
+
|
|
2963
|
+
} // parse "Property70"
|
|
2964
|
+
|
|
2965
|
+
|
|
2966
|
+
parseNodeSpecialProperty(line, propName, propValue) {
|
|
2967
|
+
|
|
2968
|
+
// split this
|
|
2969
|
+
// P: "Lcl Scaling", "Lcl Scaling", "", "A",1,1,1
|
|
2970
|
+
// into array like below
|
|
2971
|
+
// ["Lcl Scaling", "Lcl Scaling", "", "A", "1,1,1" ]
|
|
2972
|
+
const props = propValue.split('",').map(function (prop) {
|
|
2973
|
+
|
|
2974
|
+
return prop.trim().replace(/^\"/, '').replace(/\s/, '_');
|
|
2975
|
+
|
|
2976
|
+
});
|
|
2977
|
+
const innerPropName = props[0];
|
|
2978
|
+
const innerPropType1 = props[1];
|
|
2979
|
+
const innerPropType2 = props[2];
|
|
2980
|
+
const innerPropFlag = props[3];
|
|
2981
|
+
let innerPropValue = props[4]; // cast values where needed, otherwise leave as strings
|
|
2982
|
+
|
|
2983
|
+
switch (innerPropType1) {
|
|
2984
|
+
|
|
2985
|
+
case 'int':
|
|
2986
|
+
case 'enum':
|
|
2987
|
+
case 'bool':
|
|
2988
|
+
case 'ULongLong':
|
|
2989
|
+
case 'double':
|
|
2990
|
+
case 'Number':
|
|
2991
|
+
case 'FieldOfView':
|
|
2992
|
+
innerPropValue = parseFloat(innerPropValue);
|
|
2993
|
+
break;
|
|
2994
|
+
|
|
2995
|
+
case 'Color':
|
|
2996
|
+
case 'ColorRGB':
|
|
2997
|
+
case 'Vector3D':
|
|
2998
|
+
case 'Lcl_Translation':
|
|
2999
|
+
case 'Lcl_Rotation':
|
|
3000
|
+
case 'Lcl_Scaling':
|
|
3001
|
+
innerPropValue = parseNumberArray(innerPropValue);
|
|
3002
|
+
break;
|
|
3003
|
+
|
|
3004
|
+
} // CAUTION: these props must append to parent's parent
|
|
3005
|
+
|
|
3006
|
+
|
|
3007
|
+
this.getPrevNode()[innerPropName] = {
|
|
3008
|
+
'type': innerPropType1,
|
|
3009
|
+
'type2': innerPropType2,
|
|
3010
|
+
'flag': innerPropFlag,
|
|
3011
|
+
'value': innerPropValue
|
|
3012
|
+
};
|
|
3013
|
+
this.setCurrentProp(this.getPrevNode(), innerPropName);
|
|
3014
|
+
|
|
3015
|
+
}
|
|
3016
|
+
|
|
3017
|
+
} // Parse an FBX file in Binary format
|
|
3018
|
+
|
|
3019
|
+
|
|
3020
|
+
class BinaryParser {
|
|
3021
|
+
|
|
3022
|
+
parse(buffer) {
|
|
3023
|
+
|
|
3024
|
+
const reader = new BinaryReader(buffer);
|
|
3025
|
+
reader.skip(23); // skip magic 23 bytes
|
|
3026
|
+
|
|
3027
|
+
const version = reader.getUint32();
|
|
3028
|
+
|
|
3029
|
+
if (version < 6400) {
|
|
3030
|
+
|
|
3031
|
+
throw new Error('THREE.FBXLoader: FBX version not supported, FileVersion: ' + version);
|
|
3032
|
+
|
|
3033
|
+
}
|
|
3034
|
+
|
|
3035
|
+
const allNodes = new FBXTree();
|
|
3036
|
+
|
|
3037
|
+
while (!this.endOfContent(reader)) {
|
|
3038
|
+
|
|
3039
|
+
const node = this.parseNode(reader, version);
|
|
3040
|
+
if (node !== null) allNodes.add(node.name, node);
|
|
3041
|
+
|
|
3042
|
+
}
|
|
3043
|
+
|
|
3044
|
+
return allNodes;
|
|
3045
|
+
|
|
3046
|
+
} // Check if reader has reached the end of content.
|
|
3047
|
+
|
|
3048
|
+
|
|
3049
|
+
endOfContent(reader) {
|
|
3050
|
+
|
|
3051
|
+
// footer size: 160bytes + 16-byte alignment padding
|
|
3052
|
+
// - 16bytes: magic
|
|
3053
|
+
// - padding til 16-byte alignment (at least 1byte?)
|
|
3054
|
+
// (seems like some exporters embed fixed 15 or 16bytes?)
|
|
3055
|
+
// - 4bytes: magic
|
|
3056
|
+
// - 4bytes: version
|
|
3057
|
+
// - 120bytes: zero
|
|
3058
|
+
// - 16bytes: magic
|
|
3059
|
+
if (reader.size() % 16 === 0) {
|
|
3060
|
+
|
|
3061
|
+
return (reader.getOffset() + 160 + 16 & ~0xf) >= reader.size();
|
|
3062
|
+
|
|
3063
|
+
} else {
|
|
3064
|
+
|
|
3065
|
+
return reader.getOffset() + 160 + 16 >= reader.size();
|
|
3066
|
+
|
|
3067
|
+
}
|
|
3068
|
+
|
|
3069
|
+
} // recursively parse nodes until the end of the file is reached
|
|
3070
|
+
|
|
3071
|
+
|
|
3072
|
+
parseNode(reader, version) {
|
|
3073
|
+
|
|
3074
|
+
const node = {}; // The first three data sizes depends on version.
|
|
3075
|
+
|
|
3076
|
+
const endOffset = version >= 7500 ? reader.getUint64() : reader.getUint32();
|
|
3077
|
+
const numProperties = version >= 7500 ? reader.getUint64() : reader.getUint32();
|
|
3078
|
+
version >= 7500 ? reader.getUint64() : reader.getUint32(); // the returned propertyListLen is not used
|
|
3079
|
+
|
|
3080
|
+
const nameLen = reader.getUint8();
|
|
3081
|
+
const name = reader.getString(nameLen); // Regards this node as NULL-record if endOffset is zero
|
|
3082
|
+
|
|
3083
|
+
if (endOffset === 0) return null;
|
|
3084
|
+
const propertyList = [];
|
|
3085
|
+
|
|
3086
|
+
for (let i = 0; i < numProperties; i++) {
|
|
3087
|
+
|
|
3088
|
+
propertyList.push(this.parseProperty(reader));
|
|
3089
|
+
|
|
3090
|
+
} // Regards the first three elements in propertyList as id, attrName, and attrType
|
|
3091
|
+
|
|
3092
|
+
|
|
3093
|
+
const id = propertyList.length > 0 ? propertyList[0] : '';
|
|
3094
|
+
const attrName = propertyList.length > 1 ? propertyList[1] : '';
|
|
3095
|
+
const attrType = propertyList.length > 2 ? propertyList[2] : ''; // check if this node represents just a single property
|
|
3096
|
+
// like (name, 0) set or (name2, [0, 1, 2]) set of {name: 0, name2: [0, 1, 2]}
|
|
3097
|
+
|
|
3098
|
+
node.singleProperty = numProperties === 1 && reader.getOffset() === endOffset ? true : false;
|
|
3099
|
+
|
|
3100
|
+
while (endOffset > reader.getOffset()) {
|
|
3101
|
+
|
|
3102
|
+
const subNode = this.parseNode(reader, version);
|
|
3103
|
+
if (subNode !== null) this.parseSubNode(name, node, subNode);
|
|
3104
|
+
|
|
3105
|
+
}
|
|
3106
|
+
|
|
3107
|
+
node.propertyList = propertyList; // raw property list used by parent
|
|
3108
|
+
|
|
3109
|
+
if (typeof id === 'number') node.id = id;
|
|
3110
|
+
if (attrName !== '') node.attrName = attrName;
|
|
3111
|
+
if (attrType !== '') node.attrType = attrType;
|
|
3112
|
+
if (name !== '') node.name = name;
|
|
3113
|
+
return node;
|
|
3114
|
+
|
|
3115
|
+
}
|
|
3116
|
+
|
|
3117
|
+
parseSubNode(name, node, subNode) {
|
|
3118
|
+
|
|
3119
|
+
// special case: child node is single property
|
|
3120
|
+
if (subNode.singleProperty === true) {
|
|
3121
|
+
|
|
3122
|
+
const value = subNode.propertyList[0];
|
|
3123
|
+
|
|
3124
|
+
if (Array.isArray(value)) {
|
|
3125
|
+
|
|
3126
|
+
node[subNode.name] = subNode;
|
|
3127
|
+
subNode.a = value;
|
|
3128
|
+
|
|
3129
|
+
} else {
|
|
3130
|
+
|
|
3131
|
+
node[subNode.name] = value;
|
|
3132
|
+
|
|
3133
|
+
}
|
|
3134
|
+
|
|
3135
|
+
} else if (name === 'Connections' && subNode.name === 'C') {
|
|
3136
|
+
|
|
3137
|
+
const array = [];
|
|
3138
|
+
subNode.propertyList.forEach(function (property, i) {
|
|
3139
|
+
|
|
3140
|
+
// first Connection is FBX type (OO, OP, etc.). We'll discard these
|
|
3141
|
+
if (i !== 0) array.push(property);
|
|
3142
|
+
|
|
3143
|
+
});
|
|
3144
|
+
|
|
3145
|
+
if (node.connections === undefined) {
|
|
3146
|
+
|
|
3147
|
+
node.connections = [];
|
|
3148
|
+
|
|
3149
|
+
}
|
|
3150
|
+
|
|
3151
|
+
node.connections.push(array);
|
|
3152
|
+
|
|
3153
|
+
} else if (subNode.name === 'Properties70') {
|
|
3154
|
+
|
|
3155
|
+
const keys = Object.keys(subNode);
|
|
3156
|
+
keys.forEach(function (key) {
|
|
3157
|
+
|
|
3158
|
+
node[key] = subNode[key];
|
|
3159
|
+
|
|
3160
|
+
});
|
|
3161
|
+
|
|
3162
|
+
} else if (name === 'Properties70' && subNode.name === 'P') {
|
|
3163
|
+
|
|
3164
|
+
let innerPropName = subNode.propertyList[0];
|
|
3165
|
+
let innerPropType1 = subNode.propertyList[1];
|
|
3166
|
+
const innerPropType2 = subNode.propertyList[2];
|
|
3167
|
+
const innerPropFlag = subNode.propertyList[3];
|
|
3168
|
+
let innerPropValue;
|
|
3169
|
+
if (innerPropName.indexOf('Lcl ') === 0) innerPropName = innerPropName.replace('Lcl ', 'Lcl_');
|
|
3170
|
+
if (innerPropType1.indexOf('Lcl ') === 0) innerPropType1 = innerPropType1.replace('Lcl ', 'Lcl_');
|
|
3171
|
+
|
|
3172
|
+
if (innerPropType1 === 'Color' || innerPropType1 === 'ColorRGB' || innerPropType1 === 'Vector' || innerPropType1 === 'Vector3D' || innerPropType1.indexOf('Lcl_') === 0) {
|
|
3173
|
+
|
|
3174
|
+
innerPropValue = [subNode.propertyList[4], subNode.propertyList[5], subNode.propertyList[6]];
|
|
3175
|
+
|
|
3176
|
+
} else {
|
|
3177
|
+
|
|
3178
|
+
innerPropValue = subNode.propertyList[4];
|
|
3179
|
+
|
|
3180
|
+
} // this will be copied to parent, see above
|
|
3181
|
+
|
|
3182
|
+
|
|
3183
|
+
node[innerPropName] = {
|
|
3184
|
+
'type': innerPropType1,
|
|
3185
|
+
'type2': innerPropType2,
|
|
3186
|
+
'flag': innerPropFlag,
|
|
3187
|
+
'value': innerPropValue
|
|
3188
|
+
};
|
|
3189
|
+
|
|
3190
|
+
} else if (node[subNode.name] === undefined) {
|
|
3191
|
+
|
|
3192
|
+
if (typeof subNode.id === 'number') {
|
|
3193
|
+
|
|
3194
|
+
node[subNode.name] = {};
|
|
3195
|
+
node[subNode.name][subNode.id] = subNode;
|
|
3196
|
+
|
|
3197
|
+
} else {
|
|
3198
|
+
|
|
3199
|
+
node[subNode.name] = subNode;
|
|
3200
|
+
|
|
3201
|
+
}
|
|
3202
|
+
|
|
3203
|
+
} else {
|
|
3204
|
+
|
|
3205
|
+
if (subNode.name === 'PoseNode') {
|
|
3206
|
+
|
|
3207
|
+
if (!Array.isArray(node[subNode.name])) {
|
|
3208
|
+
|
|
3209
|
+
node[subNode.name] = [node[subNode.name]];
|
|
3210
|
+
|
|
3211
|
+
}
|
|
3212
|
+
|
|
3213
|
+
node[subNode.name].push(subNode);
|
|
3214
|
+
|
|
3215
|
+
} else if (node[subNode.name][subNode.id] === undefined) {
|
|
3216
|
+
|
|
3217
|
+
node[subNode.name][subNode.id] = subNode;
|
|
3218
|
+
|
|
3219
|
+
}
|
|
3220
|
+
|
|
3221
|
+
}
|
|
3222
|
+
|
|
3223
|
+
}
|
|
3224
|
+
|
|
3225
|
+
parseProperty(reader) {
|
|
3226
|
+
|
|
3227
|
+
const type = reader.getString(1);
|
|
3228
|
+
let length;
|
|
3229
|
+
|
|
3230
|
+
switch (type) {
|
|
3231
|
+
|
|
3232
|
+
case 'C':
|
|
3233
|
+
return reader.getBoolean();
|
|
3234
|
+
|
|
3235
|
+
case 'D':
|
|
3236
|
+
return reader.getFloat64();
|
|
3237
|
+
|
|
3238
|
+
case 'F':
|
|
3239
|
+
return reader.getFloat32();
|
|
3240
|
+
|
|
3241
|
+
case 'I':
|
|
3242
|
+
return reader.getInt32();
|
|
3243
|
+
|
|
3244
|
+
case 'L':
|
|
3245
|
+
return reader.getInt64();
|
|
3246
|
+
|
|
3247
|
+
case 'R':
|
|
3248
|
+
length = reader.getUint32();
|
|
3249
|
+
return reader.getArrayBuffer(length);
|
|
3250
|
+
|
|
3251
|
+
case 'S':
|
|
3252
|
+
length = reader.getUint32();
|
|
3253
|
+
return reader.getString(length);
|
|
3254
|
+
|
|
3255
|
+
case 'Y':
|
|
3256
|
+
return reader.getInt16();
|
|
3257
|
+
|
|
3258
|
+
case 'b':
|
|
3259
|
+
case 'c':
|
|
3260
|
+
case 'd':
|
|
3261
|
+
case 'f':
|
|
3262
|
+
case 'i':
|
|
3263
|
+
case 'l':
|
|
3264
|
+
const arrayLength = reader.getUint32();
|
|
3265
|
+
const encoding = reader.getUint32(); // 0: non-compressed, 1: compressed
|
|
3266
|
+
|
|
3267
|
+
const compressedLength = reader.getUint32();
|
|
3268
|
+
|
|
3269
|
+
if (encoding === 0) {
|
|
3270
|
+
|
|
3271
|
+
switch (type) {
|
|
3272
|
+
|
|
3273
|
+
case 'b':
|
|
3274
|
+
case 'c':
|
|
3275
|
+
return reader.getBooleanArray(arrayLength);
|
|
3276
|
+
|
|
3277
|
+
case 'd':
|
|
3278
|
+
return reader.getFloat64Array(arrayLength);
|
|
3279
|
+
|
|
3280
|
+
case 'f':
|
|
3281
|
+
return reader.getFloat32Array(arrayLength);
|
|
3282
|
+
|
|
3283
|
+
case 'i':
|
|
3284
|
+
return reader.getInt32Array(arrayLength);
|
|
3285
|
+
|
|
3286
|
+
case 'l':
|
|
3287
|
+
return reader.getInt64Array(arrayLength);
|
|
3288
|
+
|
|
3289
|
+
}
|
|
3290
|
+
|
|
3291
|
+
}
|
|
3292
|
+
|
|
3293
|
+
if (typeof fflate === 'undefined') {
|
|
3294
|
+
|
|
3295
|
+
console.error('THREE.FBXLoader: External library fflate.min.js required.');
|
|
3296
|
+
|
|
3297
|
+
}
|
|
3298
|
+
|
|
3299
|
+
const data = fflate.unzlibSync(new Uint8Array(reader.getArrayBuffer(compressedLength))); // eslint-disable-line no-undef
|
|
3300
|
+
|
|
3301
|
+
const reader2 = new BinaryReader(data.buffer);
|
|
3302
|
+
|
|
3303
|
+
switch (type) {
|
|
3304
|
+
|
|
3305
|
+
case 'b':
|
|
3306
|
+
case 'c':
|
|
3307
|
+
return reader2.getBooleanArray(arrayLength);
|
|
3308
|
+
|
|
3309
|
+
case 'd':
|
|
3310
|
+
return reader2.getFloat64Array(arrayLength);
|
|
3311
|
+
|
|
3312
|
+
case 'f':
|
|
3313
|
+
return reader2.getFloat32Array(arrayLength);
|
|
3314
|
+
|
|
3315
|
+
case 'i':
|
|
3316
|
+
return reader2.getInt32Array(arrayLength);
|
|
3317
|
+
|
|
3318
|
+
case 'l':
|
|
3319
|
+
return reader2.getInt64Array(arrayLength);
|
|
3320
|
+
|
|
3321
|
+
}
|
|
3322
|
+
|
|
3323
|
+
default:
|
|
3324
|
+
throw new Error('THREE.FBXLoader: Unknown property type ' + type);
|
|
3325
|
+
|
|
3326
|
+
}
|
|
3327
|
+
|
|
3328
|
+
}
|
|
3329
|
+
|
|
3330
|
+
}
|
|
3331
|
+
|
|
3332
|
+
class BinaryReader {
|
|
3333
|
+
|
|
3334
|
+
constructor(buffer, littleEndian) {
|
|
3335
|
+
|
|
3336
|
+
this.dv = new DataView(buffer);
|
|
3337
|
+
this.offset = 0;
|
|
3338
|
+
this.littleEndian = littleEndian !== undefined ? littleEndian : true;
|
|
3339
|
+
|
|
3340
|
+
}
|
|
3341
|
+
|
|
3342
|
+
getOffset() {
|
|
3343
|
+
|
|
3344
|
+
return this.offset;
|
|
3345
|
+
|
|
3346
|
+
}
|
|
3347
|
+
|
|
3348
|
+
size() {
|
|
3349
|
+
|
|
3350
|
+
return this.dv.buffer.byteLength;
|
|
3351
|
+
|
|
3352
|
+
}
|
|
3353
|
+
|
|
3354
|
+
skip(length) {
|
|
3355
|
+
|
|
3356
|
+
this.offset += length;
|
|
3357
|
+
|
|
3358
|
+
} // seems like true/false representation depends on exporter.
|
|
3359
|
+
// true: 1 or 'Y'(=0x59), false: 0 or 'T'(=0x54)
|
|
3360
|
+
// then sees LSB.
|
|
3361
|
+
|
|
3362
|
+
|
|
3363
|
+
getBoolean() {
|
|
3364
|
+
|
|
3365
|
+
return (this.getUint8() & 1) === 1;
|
|
3366
|
+
|
|
3367
|
+
}
|
|
3368
|
+
|
|
3369
|
+
getBooleanArray(size) {
|
|
3370
|
+
|
|
3371
|
+
const a = [];
|
|
3372
|
+
|
|
3373
|
+
for (let i = 0; i < size; i++) {
|
|
3374
|
+
|
|
3375
|
+
a.push(this.getBoolean());
|
|
3376
|
+
|
|
3377
|
+
}
|
|
3378
|
+
|
|
3379
|
+
return a;
|
|
3380
|
+
|
|
3381
|
+
}
|
|
3382
|
+
|
|
3383
|
+
getUint8() {
|
|
3384
|
+
|
|
3385
|
+
const value = this.dv.getUint8(this.offset);
|
|
3386
|
+
this.offset += 1;
|
|
3387
|
+
return value;
|
|
3388
|
+
|
|
3389
|
+
}
|
|
3390
|
+
|
|
3391
|
+
getInt16() {
|
|
3392
|
+
|
|
3393
|
+
const value = this.dv.getInt16(this.offset, this.littleEndian);
|
|
3394
|
+
this.offset += 2;
|
|
3395
|
+
return value;
|
|
3396
|
+
|
|
3397
|
+
}
|
|
3398
|
+
|
|
3399
|
+
getInt32() {
|
|
3400
|
+
|
|
3401
|
+
const value = this.dv.getInt32(this.offset, this.littleEndian);
|
|
3402
|
+
this.offset += 4;
|
|
3403
|
+
return value;
|
|
3404
|
+
|
|
3405
|
+
}
|
|
3406
|
+
|
|
3407
|
+
getInt32Array(size) {
|
|
3408
|
+
|
|
3409
|
+
const a = [];
|
|
3410
|
+
|
|
3411
|
+
for (let i = 0; i < size; i++) {
|
|
3412
|
+
|
|
3413
|
+
a.push(this.getInt32());
|
|
3414
|
+
|
|
3415
|
+
}
|
|
3416
|
+
|
|
3417
|
+
return a;
|
|
3418
|
+
|
|
3419
|
+
}
|
|
3420
|
+
|
|
3421
|
+
getUint32() {
|
|
3422
|
+
|
|
3423
|
+
const value = this.dv.getUint32(this.offset, this.littleEndian);
|
|
3424
|
+
this.offset += 4;
|
|
3425
|
+
return value;
|
|
3426
|
+
|
|
3427
|
+
} // JavaScript doesn't support 64-bit integer so calculate this here
|
|
3428
|
+
// 1 << 32 will return 1 so using multiply operation instead here.
|
|
3429
|
+
// There's a possibility that this method returns wrong value if the value
|
|
3430
|
+
// is out of the range between Number.MAX_SAFE_INTEGER and Number.MIN_SAFE_INTEGER.
|
|
3431
|
+
// TODO: safely handle 64-bit integer
|
|
3432
|
+
|
|
3433
|
+
|
|
3434
|
+
getInt64() {
|
|
3435
|
+
|
|
3436
|
+
let low, high;
|
|
3437
|
+
|
|
3438
|
+
if (this.littleEndian) {
|
|
3439
|
+
|
|
3440
|
+
low = this.getUint32();
|
|
3441
|
+
high = this.getUint32();
|
|
3442
|
+
|
|
3443
|
+
} else {
|
|
3444
|
+
|
|
3445
|
+
high = this.getUint32();
|
|
3446
|
+
low = this.getUint32();
|
|
3447
|
+
|
|
3448
|
+
} // calculate negative value
|
|
3449
|
+
|
|
3450
|
+
|
|
3451
|
+
if (high & 0x80000000) {
|
|
3452
|
+
|
|
3453
|
+
high = ~high & 0xFFFFFFFF;
|
|
3454
|
+
low = ~low & 0xFFFFFFFF;
|
|
3455
|
+
if (low === 0xFFFFFFFF) high = high + 1 & 0xFFFFFFFF;
|
|
3456
|
+
low = low + 1 & 0xFFFFFFFF;
|
|
3457
|
+
return - (high * 0x100000000 + low);
|
|
3458
|
+
|
|
3459
|
+
}
|
|
3460
|
+
|
|
3461
|
+
return high * 0x100000000 + low;
|
|
3462
|
+
|
|
3463
|
+
}
|
|
3464
|
+
|
|
3465
|
+
getInt64Array(size) {
|
|
3466
|
+
|
|
3467
|
+
const a = [];
|
|
3468
|
+
|
|
3469
|
+
for (let i = 0; i < size; i++) {
|
|
3470
|
+
|
|
3471
|
+
a.push(this.getInt64());
|
|
3472
|
+
|
|
3473
|
+
}
|
|
3474
|
+
|
|
3475
|
+
return a;
|
|
3476
|
+
|
|
3477
|
+
} // Note: see getInt64() comment
|
|
3478
|
+
|
|
3479
|
+
|
|
3480
|
+
getUint64() {
|
|
3481
|
+
|
|
3482
|
+
let low, high;
|
|
3483
|
+
|
|
3484
|
+
if (this.littleEndian) {
|
|
3485
|
+
|
|
3486
|
+
low = this.getUint32();
|
|
3487
|
+
high = this.getUint32();
|
|
3488
|
+
|
|
3489
|
+
} else {
|
|
3490
|
+
|
|
3491
|
+
high = this.getUint32();
|
|
3492
|
+
low = this.getUint32();
|
|
3493
|
+
|
|
3494
|
+
}
|
|
3495
|
+
|
|
3496
|
+
return high * 0x100000000 + low;
|
|
3497
|
+
|
|
3498
|
+
}
|
|
3499
|
+
|
|
3500
|
+
getFloat32() {
|
|
3501
|
+
|
|
3502
|
+
const value = this.dv.getFloat32(this.offset, this.littleEndian);
|
|
3503
|
+
this.offset += 4;
|
|
3504
|
+
return value;
|
|
3505
|
+
|
|
3506
|
+
}
|
|
3507
|
+
|
|
3508
|
+
getFloat32Array(size) {
|
|
3509
|
+
|
|
3510
|
+
const a = [];
|
|
3511
|
+
|
|
3512
|
+
for (let i = 0; i < size; i++) {
|
|
3513
|
+
|
|
3514
|
+
a.push(this.getFloat32());
|
|
3515
|
+
|
|
3516
|
+
}
|
|
3517
|
+
|
|
3518
|
+
return a;
|
|
3519
|
+
|
|
3520
|
+
}
|
|
3521
|
+
|
|
3522
|
+
getFloat64() {
|
|
3523
|
+
|
|
3524
|
+
const value = this.dv.getFloat64(this.offset, this.littleEndian);
|
|
3525
|
+
this.offset += 8;
|
|
3526
|
+
return value;
|
|
3527
|
+
|
|
3528
|
+
}
|
|
3529
|
+
|
|
3530
|
+
getFloat64Array(size) {
|
|
3531
|
+
|
|
3532
|
+
const a = [];
|
|
3533
|
+
|
|
3534
|
+
for (let i = 0; i < size; i++) {
|
|
3535
|
+
|
|
3536
|
+
a.push(this.getFloat64());
|
|
3537
|
+
|
|
3538
|
+
}
|
|
3539
|
+
|
|
3540
|
+
return a;
|
|
3541
|
+
|
|
3542
|
+
}
|
|
3543
|
+
|
|
3544
|
+
getArrayBuffer(size) {
|
|
3545
|
+
|
|
3546
|
+
const value = this.dv.buffer.slice(this.offset, this.offset + size);
|
|
3547
|
+
this.offset += size;
|
|
3548
|
+
return value;
|
|
3549
|
+
|
|
3550
|
+
}
|
|
3551
|
+
|
|
3552
|
+
getString(size) {
|
|
3553
|
+
|
|
3554
|
+
// note: safari 9 doesn't support Uint8Array.indexOf; create intermediate array instead
|
|
3555
|
+
let a = [];
|
|
3556
|
+
|
|
3557
|
+
for (let i = 0; i < size; i++) {
|
|
3558
|
+
|
|
3559
|
+
a[i] = this.getUint8();
|
|
3560
|
+
|
|
3561
|
+
}
|
|
3562
|
+
|
|
3563
|
+
const nullByte = a.indexOf(0);
|
|
3564
|
+
if (nullByte >= 0) a = a.slice(0, nullByte);
|
|
3565
|
+
return THREE.LoaderUtils.decodeText(new Uint8Array(a));
|
|
3566
|
+
|
|
3567
|
+
}
|
|
3568
|
+
|
|
3569
|
+
} // FBXTree holds a representation of the FBX data, returned by the TextParser ( FBX ASCII format)
|
|
3570
|
+
// and BinaryParser( FBX Binary format)
|
|
3571
|
+
|
|
3572
|
+
|
|
3573
|
+
class FBXTree {
|
|
3574
|
+
|
|
3575
|
+
add(key, val) {
|
|
3576
|
+
|
|
3577
|
+
this[key] = val;
|
|
3578
|
+
|
|
3579
|
+
}
|
|
3580
|
+
|
|
3581
|
+
} // ************** UTILITY FUNCTIONS **************
|
|
3582
|
+
|
|
3583
|
+
|
|
3584
|
+
function isFbxFormatBinary(buffer) {
|
|
3585
|
+
|
|
3586
|
+
const CORRECT = 'Kaydara\u0020FBX\u0020Binary\u0020\u0020\0';
|
|
3587
|
+
return buffer.byteLength >= CORRECT.length && CORRECT === convertArrayBufferToString(buffer, 0, CORRECT.length);
|
|
3588
|
+
|
|
3589
|
+
}
|
|
3590
|
+
|
|
3591
|
+
function isFbxFormatASCII(text) {
|
|
3592
|
+
|
|
3593
|
+
const CORRECT = ['K', 'a', 'y', 'd', 'a', 'r', 'a', '\\', 'F', 'B', 'X', '\\', 'B', 'i', 'n', 'a', 'r', 'y', '\\', '\\'];
|
|
3594
|
+
let cursor = 0;
|
|
3595
|
+
|
|
3596
|
+
function read(offset) {
|
|
3597
|
+
|
|
3598
|
+
const result = text[offset - 1];
|
|
3599
|
+
text = text.slice(cursor + offset);
|
|
3600
|
+
cursor++;
|
|
3601
|
+
return result;
|
|
3602
|
+
|
|
3603
|
+
}
|
|
3604
|
+
|
|
3605
|
+
for (let i = 0; i < CORRECT.length; ++i) {
|
|
3606
|
+
|
|
3607
|
+
const num = read(1);
|
|
3608
|
+
|
|
3609
|
+
if (num === CORRECT[i]) {
|
|
3610
|
+
|
|
3611
|
+
return false;
|
|
3612
|
+
|
|
3613
|
+
}
|
|
3614
|
+
|
|
3615
|
+
}
|
|
3616
|
+
|
|
3617
|
+
return true;
|
|
3618
|
+
|
|
3619
|
+
}
|
|
3620
|
+
|
|
3621
|
+
function getFbxVersion(text) {
|
|
3622
|
+
|
|
3623
|
+
const versionRegExp = /FBXVersion: (\d+)/;
|
|
3624
|
+
const match = text.match(versionRegExp);
|
|
3625
|
+
|
|
3626
|
+
if (match) {
|
|
3627
|
+
|
|
3628
|
+
const version = parseInt(match[1]);
|
|
3629
|
+
return version;
|
|
3630
|
+
|
|
3631
|
+
}
|
|
3632
|
+
|
|
3633
|
+
throw new Error('THREE.FBXLoader: Cannot find the version number for the file given.');
|
|
3634
|
+
|
|
3635
|
+
} // Converts FBX ticks into real time seconds.
|
|
3636
|
+
|
|
3637
|
+
|
|
3638
|
+
function convertFBXTimeToSeconds(time) {
|
|
3639
|
+
|
|
3640
|
+
return time / 46186158000;
|
|
3641
|
+
|
|
3642
|
+
}
|
|
3643
|
+
|
|
3644
|
+
const dataArray = []; // extracts the data from the correct position in the FBX array based on indexing type
|
|
3645
|
+
|
|
3646
|
+
function getData(polygonVertexIndex, polygonIndex, vertexIndex, infoObject) {
|
|
3647
|
+
|
|
3648
|
+
let index;
|
|
3649
|
+
|
|
3650
|
+
switch (infoObject.mappingType) {
|
|
3651
|
+
|
|
3652
|
+
case 'ByPolygonVertex':
|
|
3653
|
+
index = polygonVertexIndex;
|
|
3654
|
+
break;
|
|
3655
|
+
|
|
3656
|
+
case 'ByPolygon':
|
|
3657
|
+
index = polygonIndex;
|
|
3658
|
+
break;
|
|
3659
|
+
|
|
3660
|
+
case 'ByVertice':
|
|
3661
|
+
index = vertexIndex;
|
|
3662
|
+
break;
|
|
3663
|
+
|
|
3664
|
+
case 'AllSame':
|
|
3665
|
+
index = infoObject.indices[0];
|
|
3666
|
+
break;
|
|
3667
|
+
|
|
3668
|
+
default:
|
|
3669
|
+
console.warn('THREE.FBXLoader: unknown attribute mapping type ' + infoObject.mappingType);
|
|
3670
|
+
|
|
3671
|
+
}
|
|
3672
|
+
|
|
3673
|
+
if (infoObject.referenceType === 'IndexToDirect') index = infoObject.indices[index];
|
|
3674
|
+
const from = index * infoObject.dataSize;
|
|
3675
|
+
const to = from + infoObject.dataSize;
|
|
3676
|
+
return slice(dataArray, infoObject.buffer, from, to);
|
|
3677
|
+
|
|
3678
|
+
}
|
|
3679
|
+
|
|
3680
|
+
const tempEuler = new THREE.Euler();
|
|
3681
|
+
const tempVec = new THREE.Vector3(); // generate transformation from FBX transform data
|
|
3682
|
+
// ref: https://help.autodesk.com/view/FBX/2017/ENU/?guid=__files_GUID_10CDD63C_79C1_4F2D_BB28_AD2BE65A02ED_htm
|
|
3683
|
+
// ref: http://docs.autodesk.com/FBX/2014/ENU/FBX-SDK-Documentation/index.html?url=cpp_ref/_transformations_2main_8cxx-example.html,topicNumber=cpp_ref__transformations_2main_8cxx_example_htmlfc10a1e1-b18d-4e72-9dc0-70d0f1959f5e
|
|
3684
|
+
|
|
3685
|
+
function generateTransform(transformData) {
|
|
3686
|
+
|
|
3687
|
+
const lTranslationM = new THREE.Matrix4();
|
|
3688
|
+
const lPreRotationM = new THREE.Matrix4();
|
|
3689
|
+
const lRotationM = new THREE.Matrix4();
|
|
3690
|
+
const lPostRotationM = new THREE.Matrix4();
|
|
3691
|
+
const lScalingM = new THREE.Matrix4();
|
|
3692
|
+
const lScalingPivotM = new THREE.Matrix4();
|
|
3693
|
+
const lScalingOffsetM = new THREE.Matrix4();
|
|
3694
|
+
const lRotationOffsetM = new THREE.Matrix4();
|
|
3695
|
+
const lRotationPivotM = new THREE.Matrix4();
|
|
3696
|
+
const lParentGX = new THREE.Matrix4();
|
|
3697
|
+
const lParentLX = new THREE.Matrix4();
|
|
3698
|
+
const lGlobalT = new THREE.Matrix4();
|
|
3699
|
+
const inheritType = transformData.inheritType ? transformData.inheritType : 0;
|
|
3700
|
+
if (transformData.translation) lTranslationM.setPosition(tempVec.fromArray(transformData.translation));
|
|
3701
|
+
|
|
3702
|
+
if (transformData.preRotation) {
|
|
3703
|
+
|
|
3704
|
+
const array = transformData.preRotation.map(THREE.MathUtils.degToRad);
|
|
3705
|
+
array.push(transformData.eulerOrder);
|
|
3706
|
+
lPreRotationM.makeRotationFromEuler(tempEuler.fromArray(array));
|
|
3707
|
+
|
|
3708
|
+
}
|
|
3709
|
+
|
|
3710
|
+
if (transformData.rotation) {
|
|
3711
|
+
|
|
3712
|
+
const array = transformData.rotation.map(THREE.MathUtils.degToRad);
|
|
3713
|
+
array.push(transformData.eulerOrder);
|
|
3714
|
+
lRotationM.makeRotationFromEuler(tempEuler.fromArray(array));
|
|
3715
|
+
|
|
3716
|
+
}
|
|
3717
|
+
|
|
3718
|
+
if (transformData.postRotation) {
|
|
3719
|
+
|
|
3720
|
+
const array = transformData.postRotation.map(THREE.MathUtils.degToRad);
|
|
3721
|
+
array.push(transformData.eulerOrder);
|
|
3722
|
+
lPostRotationM.makeRotationFromEuler(tempEuler.fromArray(array));
|
|
3723
|
+
lPostRotationM.invert();
|
|
3724
|
+
|
|
3725
|
+
}
|
|
3726
|
+
|
|
3727
|
+
if (transformData.scale) lScalingM.scale(tempVec.fromArray(transformData.scale)); // Pivots and offsets
|
|
3728
|
+
|
|
3729
|
+
if (transformData.scalingOffset) lScalingOffsetM.setPosition(tempVec.fromArray(transformData.scalingOffset));
|
|
3730
|
+
if (transformData.scalingPivot) lScalingPivotM.setPosition(tempVec.fromArray(transformData.scalingPivot));
|
|
3731
|
+
if (transformData.rotationOffset) lRotationOffsetM.setPosition(tempVec.fromArray(transformData.rotationOffset));
|
|
3732
|
+
if (transformData.rotationPivot) lRotationPivotM.setPosition(tempVec.fromArray(transformData.rotationPivot)); // parent transform
|
|
3733
|
+
|
|
3734
|
+
if (transformData.parentMatrixWorld) {
|
|
3735
|
+
|
|
3736
|
+
lParentLX.copy(transformData.parentMatrix);
|
|
3737
|
+
lParentGX.copy(transformData.parentMatrixWorld);
|
|
3738
|
+
|
|
3739
|
+
}
|
|
3740
|
+
|
|
3741
|
+
const lLRM = lPreRotationM.clone().multiply(lRotationM).multiply(lPostRotationM); // Global Rotation
|
|
3742
|
+
|
|
3743
|
+
const lParentGRM = new THREE.Matrix4();
|
|
3744
|
+
lParentGRM.extractRotation(lParentGX); // Global Shear*Scaling
|
|
3745
|
+
|
|
3746
|
+
const lParentTM = new THREE.Matrix4();
|
|
3747
|
+
lParentTM.copyPosition(lParentGX);
|
|
3748
|
+
const lParentGRSM = lParentTM.clone().invert().multiply(lParentGX);
|
|
3749
|
+
const lParentGSM = lParentGRM.clone().invert().multiply(lParentGRSM);
|
|
3750
|
+
const lLSM = lScalingM;
|
|
3751
|
+
const lGlobalRS = new THREE.Matrix4();
|
|
3752
|
+
|
|
3753
|
+
if (inheritType === 0) {
|
|
3754
|
+
|
|
3755
|
+
lGlobalRS.copy(lParentGRM).multiply(lLRM).multiply(lParentGSM).multiply(lLSM);
|
|
3756
|
+
|
|
3757
|
+
} else if (inheritType === 1) {
|
|
3758
|
+
|
|
3759
|
+
lGlobalRS.copy(lParentGRM).multiply(lParentGSM).multiply(lLRM).multiply(lLSM);
|
|
3760
|
+
|
|
3761
|
+
} else {
|
|
3762
|
+
|
|
3763
|
+
const lParentLSM = new THREE.Matrix4().scale(new THREE.Vector3().setFromMatrixScale(lParentLX));
|
|
3764
|
+
const lParentLSM_inv = lParentLSM.clone().invert();
|
|
3765
|
+
const lParentGSM_noLocal = lParentGSM.clone().multiply(lParentLSM_inv);
|
|
3766
|
+
lGlobalRS.copy(lParentGRM).multiply(lLRM).multiply(lParentGSM_noLocal).multiply(lLSM);
|
|
3767
|
+
|
|
3768
|
+
}
|
|
3769
|
+
|
|
3770
|
+
const lRotationPivotM_inv = lRotationPivotM.clone().invert();
|
|
3771
|
+
const lScalingPivotM_inv = lScalingPivotM.clone().invert(); // Calculate the local transform matrix
|
|
3772
|
+
|
|
3773
|
+
let lTransform = lTranslationM.clone().multiply(lRotationOffsetM).multiply(lRotationPivotM).multiply(lPreRotationM).multiply(lRotationM).multiply(lPostRotationM).multiply(lRotationPivotM_inv).multiply(lScalingOffsetM).multiply(lScalingPivotM).multiply(lScalingM).multiply(lScalingPivotM_inv);
|
|
3774
|
+
const lLocalTWithAllPivotAndOffsetInfo = new THREE.Matrix4().copyPosition(lTransform);
|
|
3775
|
+
const lGlobalTranslation = lParentGX.clone().multiply(lLocalTWithAllPivotAndOffsetInfo);
|
|
3776
|
+
lGlobalT.copyPosition(lGlobalTranslation);
|
|
3777
|
+
lTransform = lGlobalT.clone().multiply(lGlobalRS); // from global to local
|
|
3778
|
+
|
|
3779
|
+
lTransform.premultiply(lParentGX.invert());
|
|
3780
|
+
return lTransform;
|
|
3781
|
+
|
|
3782
|
+
} // Returns the three.js intrinsic THREE.Euler order corresponding to FBX extrinsic THREE.Euler order
|
|
3783
|
+
// ref: http://help.autodesk.com/view/FBX/2017/ENU/?guid=__cpp_ref_class_fbx_euler_html
|
|
3784
|
+
|
|
3785
|
+
|
|
3786
|
+
function getEulerOrder(order) {
|
|
3787
|
+
|
|
3788
|
+
order = order || 0;
|
|
3789
|
+
const enums = ['ZYX', // -> XYZ extrinsic
|
|
3790
|
+
'YZX', // -> XZY extrinsic
|
|
3791
|
+
'XZY', // -> YZX extrinsic
|
|
3792
|
+
'ZXY', // -> YXZ extrinsic
|
|
3793
|
+
'YXZ', // -> ZXY extrinsic
|
|
3794
|
+
'XYZ' // -> ZYX extrinsic
|
|
3795
|
+
//'SphericXYZ', // not possible to support
|
|
3796
|
+
];
|
|
3797
|
+
|
|
3798
|
+
if (order === 6) {
|
|
3799
|
+
|
|
3800
|
+
console.warn('THREE.FBXLoader: unsupported THREE.Euler Order: Spherical XYZ. Animations and rotations may be incorrect.');
|
|
3801
|
+
return enums[0];
|
|
3802
|
+
|
|
3803
|
+
}
|
|
3804
|
+
|
|
3805
|
+
return enums[order];
|
|
3806
|
+
|
|
3807
|
+
} // Parses comma separated list of numbers and returns them an array.
|
|
3808
|
+
// Used internally by the TextParser
|
|
3809
|
+
|
|
3810
|
+
|
|
3811
|
+
function parseNumberArray(value) {
|
|
3812
|
+
|
|
3813
|
+
const array = value.split(',').map(function (val) {
|
|
3814
|
+
|
|
3815
|
+
return parseFloat(val);
|
|
3816
|
+
|
|
3817
|
+
});
|
|
3818
|
+
return array;
|
|
3819
|
+
|
|
3820
|
+
}
|
|
3821
|
+
|
|
3822
|
+
function convertArrayBufferToString(buffer, from, to) {
|
|
3823
|
+
|
|
3824
|
+
if (from === undefined) from = 0;
|
|
3825
|
+
if (to === undefined) to = buffer.byteLength;
|
|
3826
|
+
return THREE.LoaderUtils.decodeText(new Uint8Array(buffer, from, to));
|
|
3827
|
+
|
|
3828
|
+
}
|
|
3829
|
+
|
|
3830
|
+
function append(a, b) {
|
|
3831
|
+
|
|
3832
|
+
for (let i = 0, j = a.length, l = b.length; i < l; i++, j++) {
|
|
3833
|
+
|
|
3834
|
+
a[j] = b[i];
|
|
3835
|
+
|
|
3836
|
+
}
|
|
3837
|
+
|
|
3838
|
+
}
|
|
3839
|
+
|
|
3840
|
+
function slice(a, b, from, to) {
|
|
3841
|
+
|
|
3842
|
+
for (let i = from, j = 0; i < to; i++, j++) {
|
|
3843
|
+
|
|
3844
|
+
a[j] = b[i];
|
|
3845
|
+
|
|
3846
|
+
}
|
|
3847
|
+
|
|
3848
|
+
return a;
|
|
3849
|
+
|
|
3850
|
+
} // inject array a2 into array a1 at index
|
|
3851
|
+
|
|
3852
|
+
|
|
3853
|
+
function inject(a1, index, a2) {
|
|
3854
|
+
|
|
3855
|
+
return a1.slice(0, index).concat(a2).concat(a1.slice(index));
|
|
3856
|
+
|
|
3857
|
+
}
|
|
3858
|
+
|
|
3859
|
+
let OBJTHREE = Object.assign({},THREE)
|
|
3860
|
+
OBJTHREE.FBXLoader = FBXLoader;
|
|
3861
|
+
|
|
3862
|
+
// })();
|
|
3863
|
+
|
|
3864
|
+
export default OBJTHREE.FBXLoader;
|