@galacean/engine-loader 1.0.0-beta.9 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/main.js +534 -411
- package/dist/main.js.map +1 -1
- package/dist/miniprogram.js +534 -411
- package/dist/module.js +536 -413
- package/dist/module.js.map +1 -1
- package/package.json +5 -5
- package/types/GLTFContentRestorer.d.ts +18 -8
- package/types/ProjectLoader.d.ts +1 -0
- package/types/gltf/GLTFResource.d.ts +2 -6
- package/types/gltf/GLTFUtil.d.ts +3 -3
- package/types/gltf/GLTFUtils.d.ts +3 -2
- package/types/gltf/extensions/GLTFExtensionSchema.d.ts +1 -1
- package/types/gltf/parser/GLTFAnimationParser.d.ts +2 -2
- package/types/gltf/parser/GLTFMeshParser.d.ts +5 -5
- package/types/gltf/parser/GLTFParser.d.ts +1 -1
- package/types/gltf/parser/GLTFParserContext.d.ts +7 -2
- package/types/gltf/parser/GLTFSceneParser.d.ts +2 -2
- package/types/gltf/parser/GLTFSchemaParser.d.ts +7 -0
- package/types/gltf/parser/GLTFSkinParser.d.ts +2 -1
- package/types/gltf/parser/GLTFTextureParser.d.ts +3 -2
- package/types/ktx2/BinomialLLCTranscoder/BinomialLLCTranscoder.d.ts +13 -0
- package/types/ktx2/BinomialLLCTranscoder/TranscodeWorkerCode.d.ts +33 -0
- package/types/ktx2/KTX2Container.d.ts +72 -0
- package/types/ktx2/KTX2Loader.d.ts +53 -0
- package/types/ktx2/KTX2TargetFormat.d.ts +21 -0
- package/types/ktx2/KhronosTranscoder/KhronosTranscoder.d.ts +17 -0
- package/types/ktx2/KhronosTranscoder/TranscoderWorkerCode.d.ts +34 -0
- package/types/ktx2/TranscodeResult.d.ts +10 -0
- package/types/ktx2/WorkerPool.d.ts +32 -0
- package/types/ktx2/constants.d.ts +7 -0
- package/types/ktx2/transcoder/AbstractTranscoder.d.ts +55 -0
- package/types/ktx2/transcoder/BinomialLLCTranscoder.d.ts +8 -0
- package/types/ktx2/transcoder/BinomialLLCWorkerCode.d.ts +2 -0
- package/types/ktx2/transcoder/KhronosTranscoder.d.ts +13 -0
- package/types/ktx2/transcoder/KhronosWorkerCode.d.ts +1 -0
- package/types/ktx2/zstddec.d.ts +62 -0
- package/types/resource-deserialize/index.d.ts +3 -3
- package/types/resource-deserialize/resources/mesh/MeshDecoder.d.ts +1 -1
- package/types/resource-deserialize/resources/parser/PrefabParser.d.ts +5 -0
- package/types/resource-deserialize/resources/parser/ReflectionParser.d.ts +14 -0
- package/types/resource-deserialize/resources/prefab/PrefabDesign.d.ts +4 -4
- package/types/resource-deserialize/resources/scene/SceneParser.d.ts +1 -1
- package/types/resource-deserialize/resources/scene/SceneParserContext.d.ts +1 -1
- package/types/resource-deserialize/resources/schema/BasicSchema.d.ts +61 -0
- package/types/resource-deserialize/resources/schema/MaterialSchema.d.ts +91 -0
- package/types/resource-deserialize/resources/schema/ProjectSchema.d.ts +9 -0
- package/types/resource-deserialize/resources/schema/SceneSchema.d.ts +41 -0
- package/types/resource-deserialize/resources/schema/index.d.ts +3 -0
package/dist/module.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { resourceLoader, AssetType, AssetPromise, AnimatorController, AnimatorControllerLayer, AnimatorStateMachine, Loader, AnimatorStateTransition, TextureCube, TextureFilterMode, TextureCubeFace, AmbientLight, DiffuseMode, Font, request, ContentRestorer, IndexFormat, VertexElementFormat, Utils, AnimationClip,
|
|
1
|
+
import { resourceLoader, AssetType, AssetPromise, AnimatorController, AnimatorControllerLayer, AnimatorStateMachine, Loader, AnimatorStateTransition, TextureCube, TextureFilterMode, TextureCubeFace, AmbientLight, DiffuseMode, Font, request, ContentRestorer, IndexFormat, VertexElementFormat, Utils, AnimationClip, AnimationFloatArrayCurve, Keyframe, InterpolationType, AnimationQuaternionCurve, AnimationVector3Curve, SkinnedMeshRenderer, Transform, Entity, PBRMaterial, Logger, PBRSpecularMaterial, TextureCoordinate, RenderFace, VertexElement, Buffer, BufferBindFlag, BufferUsage, BlendShape, ModelMesh, Camera, Animator, BlinnPhongMaterial, MeshRenderer, Skin, TextureWrapMode as TextureWrapMode$1, Texture2D, ReferResource, TextureFormat, Material, Shader, DirectLight, ParticleRenderer, PointLight, SpotLight, Script, SpriteMask, SpriteRenderer, TextRenderer, AnimationEvent, AnimationColorCurve, AnimationVector4Curve, AnimationVector2Curve, AnimationArrayCurve, AnimationFloatCurve, Scene, SpriteAtlas, Sprite, BackgroundMode, UnlitMaterial } from '@galacean/engine-core';
|
|
2
2
|
import { SphericalHarmonics3, Vector2, Vector3, Vector4, Color, Quaternion, Matrix, Rect } from '@galacean/engine-math';
|
|
3
3
|
import { GLCompressedTextureInternalFormat } from '@galacean/engine-rhi-webgl';
|
|
4
4
|
import { DRACODecoder } from '@galacean/engine-draco';
|
|
@@ -117,7 +117,8 @@ var AnimatorControllerLoader = /*#__PURE__*/ function(Loader1) {
|
|
|
117
117
|
state.wrapMode = wrapMode;
|
|
118
118
|
state.clipStartTime = clipStartNormalizedTime;
|
|
119
119
|
state.clipEndTime = clipEndNormalizedTime;
|
|
120
|
-
|
|
120
|
+
var scriptsObject = JSON.parse(scripts);
|
|
121
|
+
scriptsObject == null ? void 0 : scriptsObject.forEach(function(script) {
|
|
121
122
|
state.addStateMachineScript(Loader.getClass(script));
|
|
122
123
|
});
|
|
123
124
|
if (clipData) {
|
|
@@ -217,7 +218,8 @@ var EnvLoader = /*#__PURE__*/ function(Loader) {
|
|
|
217
218
|
var shArray = new Float32Array(arraybuffer, 0, 27);
|
|
218
219
|
var shByteLength = 27 * 4;
|
|
219
220
|
var size = (_ref = new Uint16Array(arraybuffer, shByteLength, 1)) == null ? void 0 : _ref[0];
|
|
220
|
-
var
|
|
221
|
+
var engine = resourceManager.engine;
|
|
222
|
+
var texture = new TextureCube(engine, size);
|
|
221
223
|
texture.filterMode = TextureFilterMode.Trilinear;
|
|
222
224
|
var mipmapCount = texture.mipmapCount;
|
|
223
225
|
var offset = shByteLength + 2;
|
|
@@ -230,7 +232,7 @@ var EnvLoader = /*#__PURE__*/ function(Loader) {
|
|
|
230
232
|
texture.setPixelBuffer(TextureCubeFace.PositiveX + face, data, mipLevel);
|
|
231
233
|
}
|
|
232
234
|
}
|
|
233
|
-
var ambientLight = new AmbientLight();
|
|
235
|
+
var ambientLight = new AmbientLight(engine);
|
|
234
236
|
var sh = new SphericalHarmonics3();
|
|
235
237
|
ambientLight.diffuseMode = DiffuseMode.SphericalHarmonics;
|
|
236
238
|
sh.copyFromArray(shArray);
|
|
@@ -437,15 +439,18 @@ function _create_for_of_iterator_helper_loose(o, allowArrayLike) {
|
|
|
437
439
|
for(var _iterator2 = _create_for_of_iterator_helper_loose(meshInfo.blendShapes), _step2; !(_step2 = _iterator2()).done;){
|
|
438
440
|
var restoreInfo = _step2.value;
|
|
439
441
|
var frame = restoreInfo.blendShape.frames[0];
|
|
440
|
-
var
|
|
441
|
-
|
|
442
|
+
var position = restoreInfo.position;
|
|
443
|
+
var positionData = _this._getBufferData(buffers, position.buffer);
|
|
444
|
+
frame.deltaPositions = GLTFUtils.bufferToVector3Array(positionData, position.stride, position.byteOffset, position.count);
|
|
442
445
|
if (restoreInfo.normal) {
|
|
443
|
-
var
|
|
444
|
-
|
|
446
|
+
var normal = restoreInfo.normal;
|
|
447
|
+
var normalData = _this._getBufferData(buffers, normal.buffer);
|
|
448
|
+
frame.deltaNormals = GLTFUtils.bufferToVector3Array(normalData, normal.stride, normal.byteOffset, normal.count);
|
|
445
449
|
}
|
|
446
450
|
if (restoreInfo.tangent) {
|
|
447
|
-
var
|
|
448
|
-
|
|
451
|
+
var tangent = restoreInfo.tangent;
|
|
452
|
+
var tangentData = _this._getBufferData(buffers, tangent.buffer);
|
|
453
|
+
frame.deltaTangents = GLTFUtils.bufferToVector3Array(tangentData, tangent.stride, tangent.byteOffset, tangent.count);
|
|
449
454
|
}
|
|
450
455
|
}
|
|
451
456
|
mesh.uploadData(true);
|
|
@@ -529,6 +534,14 @@ function _create_for_of_iterator_helper_loose(o, allowArrayLike) {
|
|
|
529
534
|
this.normal = normal;
|
|
530
535
|
this.tangent = tangent;
|
|
531
536
|
};
|
|
537
|
+
/**
|
|
538
|
+
* @internal
|
|
539
|
+
*/ var BlendShapeDataRestoreInfo = function BlendShapeDataRestoreInfo(buffer, stride, byteOffset, count) {
|
|
540
|
+
this.buffer = buffer;
|
|
541
|
+
this.stride = stride;
|
|
542
|
+
this.byteOffset = byteOffset;
|
|
543
|
+
this.count = count;
|
|
544
|
+
};
|
|
532
545
|
|
|
533
546
|
/**
|
|
534
547
|
* Module for glTF 2.0 Interface
|
|
@@ -700,6 +713,11 @@ var TextureWrapMode;
|
|
|
700
713
|
promiseMap["" + url] = this._initPromiseInfo(this.masterPromiseInfo);
|
|
701
714
|
}
|
|
702
715
|
var _proto = GLTFParserContext.prototype;
|
|
716
|
+
/**
|
|
717
|
+
* Get all the buffer data.
|
|
718
|
+
*/ _proto.getBuffers = function getBuffers() {
|
|
719
|
+
return Promise.resolve(this._buffers);
|
|
720
|
+
};
|
|
703
721
|
_proto._initPromiseInfo = function _initPromiseInfo(promiseInfo) {
|
|
704
722
|
var promise = new AssetPromise(function(resolve, reject, setProgress, onCancel) {
|
|
705
723
|
promiseInfo.resolve = resolve;
|
|
@@ -821,44 +839,58 @@ var TextureWrapMode;
|
|
|
821
839
|
}
|
|
822
840
|
};
|
|
823
841
|
GLTFUtils.getAccessorBuffer = function getAccessorBuffer(context, bufferViews, accessor) {
|
|
824
|
-
var buffers = context.buffers;
|
|
825
842
|
var componentType = accessor.componentType;
|
|
826
843
|
var bufferView = bufferViews[accessor.bufferView];
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
var
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
var
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
844
|
+
return context.getBuffers().then(function(buffers) {
|
|
845
|
+
var bufferIndex = bufferView.buffer;
|
|
846
|
+
var buffer = buffers[bufferIndex];
|
|
847
|
+
var _bufferView_byteOffset;
|
|
848
|
+
var bufferByteOffset = (_bufferView_byteOffset = bufferView.byteOffset) != null ? _bufferView_byteOffset : 0;
|
|
849
|
+
var _accessor_byteOffset;
|
|
850
|
+
var byteOffset = (_accessor_byteOffset = accessor.byteOffset) != null ? _accessor_byteOffset : 0;
|
|
851
|
+
var TypedArray = GLTFUtils.getComponentType(componentType);
|
|
852
|
+
var dataElementSize = GLTFUtils.getAccessorTypeSize(accessor.type);
|
|
853
|
+
var dataElementBytes = TypedArray.BYTES_PER_ELEMENT;
|
|
854
|
+
var elementStride = dataElementSize * dataElementBytes;
|
|
855
|
+
var accessorCount = accessor.count;
|
|
856
|
+
var bufferStride = bufferView.byteStride;
|
|
857
|
+
var bufferInfo;
|
|
858
|
+
// According to the glTF official documentation only byteStride not undefined is allowed
|
|
859
|
+
if (bufferStride !== undefined && bufferStride !== elementStride) {
|
|
860
|
+
var bufferSlice = Math.floor(byteOffset / bufferStride);
|
|
861
|
+
var bufferCacheKey = accessor.bufferView + ":" + componentType + ":" + bufferSlice + ":" + accessorCount;
|
|
862
|
+
var accessorBufferCache = context.accessorBufferCache;
|
|
863
|
+
bufferInfo = accessorBufferCache[bufferCacheKey];
|
|
864
|
+
if (!bufferInfo) {
|
|
865
|
+
var offset = bufferByteOffset + bufferSlice * bufferStride;
|
|
866
|
+
var count = accessorCount * (bufferStride / dataElementBytes);
|
|
867
|
+
var data = new TypedArray(buffer, offset, count);
|
|
868
|
+
accessorBufferCache[bufferCacheKey] = bufferInfo = new BufferInfo(data, true, bufferStride);
|
|
869
|
+
bufferInfo.restoreInfo = new BufferDataRestoreInfo(new RestoreDataAccessor(bufferIndex, TypedArray, offset, count));
|
|
870
|
+
}
|
|
871
|
+
} else {
|
|
872
|
+
var offset1 = bufferByteOffset + byteOffset;
|
|
873
|
+
var count1 = accessorCount * dataElementSize;
|
|
874
|
+
var data1 = new TypedArray(buffer, offset1, count1);
|
|
875
|
+
bufferInfo = new BufferInfo(data1, false, elementStride);
|
|
876
|
+
bufferInfo.restoreInfo = new BufferDataRestoreInfo(new RestoreDataAccessor(bufferIndex, TypedArray, offset1, count1));
|
|
850
877
|
}
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
878
|
+
if (accessor.sparse) {
|
|
879
|
+
GLTFUtils.processingSparseData(bufferViews, accessor, buffers, bufferInfo);
|
|
880
|
+
}
|
|
881
|
+
return bufferInfo;
|
|
882
|
+
});
|
|
883
|
+
};
|
|
884
|
+
GLTFUtils.bufferToVector3Array = function bufferToVector3Array(data, byteStride, accessorByteOffset, count) {
|
|
885
|
+
var bytesPerElement = data.BYTES_PER_ELEMENT;
|
|
886
|
+
var offset = accessorByteOffset % byteStride / bytesPerElement;
|
|
887
|
+
var stride = byteStride / bytesPerElement;
|
|
888
|
+
var vector3s = new Array(count);
|
|
889
|
+
for(var i = 0; i < count; i++){
|
|
890
|
+
var index = offset + i * stride;
|
|
891
|
+
vector3s[i] = new Vector3(data[index], data[index + 1], data[index + 2]);
|
|
860
892
|
}
|
|
861
|
-
return
|
|
893
|
+
return vector3s;
|
|
862
894
|
};
|
|
863
895
|
/**
|
|
864
896
|
* @deprecated
|
|
@@ -1324,7 +1356,7 @@ var GLTFAnimationParser = /*#__PURE__*/ function(GLTFParser1) {
|
|
|
1324
1356
|
}
|
|
1325
1357
|
var _proto = GLTFAnimationParser.prototype;
|
|
1326
1358
|
_proto.parse = function parse(context) {
|
|
1327
|
-
var glTF = context.glTF
|
|
1359
|
+
var glTF = context.glTF, glTFResource = context.glTFResource;
|
|
1328
1360
|
glTFResource.entities;
|
|
1329
1361
|
var animations = glTF.animations; glTF.accessors; glTF.bufferViews;
|
|
1330
1362
|
if (!animations) {
|
|
@@ -1334,106 +1366,120 @@ var GLTFAnimationParser = /*#__PURE__*/ function(GLTFParser1) {
|
|
|
1334
1366
|
var animationClipCount = animations.length;
|
|
1335
1367
|
var animationClipPromises = [];
|
|
1336
1368
|
new Array(animationClipCount);
|
|
1369
|
+
var parseStandardPropertyPromises = new Array();
|
|
1337
1370
|
for(var i = 0; i < animationClipCount; i++){
|
|
1338
1371
|
var animationInfo = animations[i];
|
|
1339
1372
|
var _animationInfo_name = animationInfo.name, name = _animationInfo_name === void 0 ? "AnimationClip" + i : _animationInfo_name;
|
|
1340
1373
|
var animationClip = GLTFParser.executeExtensionsCreateAndParse(animationInfo.extensions, context, animationInfo);
|
|
1341
1374
|
if (!animationClip) {
|
|
1342
1375
|
animationClip = new AnimationClip(name);
|
|
1343
|
-
GLTFAnimationParser._parseStandardProperty(context, animationClip, animationInfo);
|
|
1376
|
+
parseStandardPropertyPromises.push(GLTFAnimationParser._parseStandardProperty(context, animationClip, animationInfo));
|
|
1344
1377
|
}
|
|
1345
1378
|
animationClipPromises.push(animationClip);
|
|
1346
1379
|
}
|
|
1347
|
-
return AssetPromise.all(
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
var
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1380
|
+
return AssetPromise.all(parseStandardPropertyPromises).then(function() {
|
|
1381
|
+
return AssetPromise.all(animationClipPromises).then(function(animationClips) {
|
|
1382
|
+
glTFResource.animations = animationClips;
|
|
1383
|
+
for(var i = 0; i < glTF.animations.length; i++){
|
|
1384
|
+
var animationInfo = glTF.animations[i];
|
|
1385
|
+
GLTFParser.executeExtensionsAdditiveAndParse(animationInfo.extensions, context, animationClips[i], animationInfo);
|
|
1386
|
+
}
|
|
1387
|
+
animationClipsPromiseInfo.resolve(animationClips);
|
|
1388
|
+
return animationClipsPromiseInfo.promise;
|
|
1389
|
+
});
|
|
1355
1390
|
});
|
|
1356
1391
|
};
|
|
1357
1392
|
/**
|
|
1358
1393
|
* @internal
|
|
1359
1394
|
*/ GLTFAnimationParser._parseStandardProperty = function _parseStandardProperty(context, animationClip, animationInfo) {
|
|
1395
|
+
var _loop = function(j, m) {
|
|
1396
|
+
var gltfSampler = samplers[j];
|
|
1397
|
+
var inputAccessor = accessors[gltfSampler.input];
|
|
1398
|
+
var outputAccessor = accessors[gltfSampler.output];
|
|
1399
|
+
var promise = Promise.all([
|
|
1400
|
+
GLTFUtils.getAccessorBuffer(context, bufferViews, inputAccessor),
|
|
1401
|
+
GLTFUtils.getAccessorBuffer(context, bufferViews, outputAccessor)
|
|
1402
|
+
]).then(function(bufferInfos) {
|
|
1403
|
+
var input = bufferInfos[0].data;
|
|
1404
|
+
var output = bufferInfos[1].data;
|
|
1405
|
+
if (outputAccessor.normalized) {
|
|
1406
|
+
var scale = GLTFUtils.getNormalizedComponentScale(outputAccessor.componentType);
|
|
1407
|
+
var scaled = new Float32Array(output.length);
|
|
1408
|
+
for(var k = 0, v = output.length; k < v; k++){
|
|
1409
|
+
scaled[k] = output[k] * scale;
|
|
1410
|
+
}
|
|
1411
|
+
output = scaled;
|
|
1412
|
+
}
|
|
1413
|
+
var outputStride = output.length / input.length;
|
|
1414
|
+
var _gltfSampler_interpolation;
|
|
1415
|
+
var interpolation = (_gltfSampler_interpolation = gltfSampler.interpolation) != null ? _gltfSampler_interpolation : AnimationSamplerInterpolation.Linear;
|
|
1416
|
+
var samplerInterpolation;
|
|
1417
|
+
switch(interpolation){
|
|
1418
|
+
case AnimationSamplerInterpolation.CubicSpine:
|
|
1419
|
+
samplerInterpolation = InterpolationType.CubicSpine;
|
|
1420
|
+
break;
|
|
1421
|
+
case AnimationSamplerInterpolation.Step:
|
|
1422
|
+
samplerInterpolation = InterpolationType.Step;
|
|
1423
|
+
break;
|
|
1424
|
+
case AnimationSamplerInterpolation.Linear:
|
|
1425
|
+
samplerInterpolation = InterpolationType.Linear;
|
|
1426
|
+
break;
|
|
1427
|
+
}
|
|
1428
|
+
input[input.length - 1];
|
|
1429
|
+
sampleDataCollection.push({
|
|
1430
|
+
type: outputAccessor.type,
|
|
1431
|
+
interpolation: samplerInterpolation,
|
|
1432
|
+
input: input,
|
|
1433
|
+
output: output,
|
|
1434
|
+
outputSize: outputStride
|
|
1435
|
+
});
|
|
1436
|
+
});
|
|
1437
|
+
promises.push(promise);
|
|
1438
|
+
};
|
|
1439
|
+
var _this = this;
|
|
1360
1440
|
var glTF = context.glTF, glTFResource = context.glTFResource;
|
|
1361
1441
|
var entities = glTFResource.entities;
|
|
1362
1442
|
var accessors = glTF.accessors, bufferViews = glTF.bufferViews;
|
|
1363
1443
|
var channels = animationInfo.channels, samplers = animationInfo.samplers;
|
|
1364
1444
|
var sampleDataCollection = new Array();
|
|
1445
|
+
var promises = new Array();
|
|
1365
1446
|
// parse samplers
|
|
1366
|
-
for(var j = 0, m = samplers.length; j < m; j++)
|
|
1367
|
-
|
|
1368
|
-
var
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
var
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1447
|
+
for(var j = 0, m = samplers.length; j < m; j++)_loop(j);
|
|
1448
|
+
return Promise.all(promises).then(function() {
|
|
1449
|
+
for(var j = 0, m = channels.length; j < m; j++){
|
|
1450
|
+
var gltfChannel = channels[j];
|
|
1451
|
+
var target = gltfChannel.target;
|
|
1452
|
+
var channelTargetEntity = entities[target.node];
|
|
1453
|
+
var relativePath = "";
|
|
1454
|
+
var entity = channelTargetEntity;
|
|
1455
|
+
while(entity.parent){
|
|
1456
|
+
relativePath = relativePath === "" ? "" + entity.name : entity.name + "/" + relativePath;
|
|
1457
|
+
entity = entity.parent;
|
|
1377
1458
|
}
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
output: output,
|
|
1401
|
-
outputSize: outputStride
|
|
1402
|
-
});
|
|
1403
|
-
}
|
|
1404
|
-
for(var j1 = 0, m1 = channels.length; j1 < m1; j1++){
|
|
1405
|
-
var gltfChannel = channels[j1];
|
|
1406
|
-
var target = gltfChannel.target;
|
|
1407
|
-
var channelTargetEntity = entities[target.node];
|
|
1408
|
-
var relativePath = "";
|
|
1409
|
-
var entity = channelTargetEntity;
|
|
1410
|
-
while(entity.parent){
|
|
1411
|
-
relativePath = relativePath === "" ? "" + entity.name : entity.name + "/" + relativePath;
|
|
1412
|
-
entity = entity.parent;
|
|
1413
|
-
}
|
|
1414
|
-
var ComponentType = void 0;
|
|
1415
|
-
var propertyName = void 0;
|
|
1416
|
-
switch(target.path){
|
|
1417
|
-
case AnimationChannelTargetPath.TRANSLATION:
|
|
1418
|
-
ComponentType = Transform;
|
|
1419
|
-
propertyName = "position";
|
|
1420
|
-
break;
|
|
1421
|
-
case AnimationChannelTargetPath.ROTATION:
|
|
1422
|
-
ComponentType = Transform;
|
|
1423
|
-
propertyName = "rotationQuaternion";
|
|
1424
|
-
break;
|
|
1425
|
-
case AnimationChannelTargetPath.SCALE:
|
|
1426
|
-
ComponentType = Transform;
|
|
1427
|
-
propertyName = "scale";
|
|
1428
|
-
break;
|
|
1429
|
-
case AnimationChannelTargetPath.WEIGHTS:
|
|
1430
|
-
ComponentType = SkinnedMeshRenderer;
|
|
1431
|
-
propertyName = "blendShapeWeights";
|
|
1432
|
-
break;
|
|
1459
|
+
var ComponentType = void 0;
|
|
1460
|
+
var propertyName = void 0;
|
|
1461
|
+
switch(target.path){
|
|
1462
|
+
case AnimationChannelTargetPath.TRANSLATION:
|
|
1463
|
+
ComponentType = Transform;
|
|
1464
|
+
propertyName = "position";
|
|
1465
|
+
break;
|
|
1466
|
+
case AnimationChannelTargetPath.ROTATION:
|
|
1467
|
+
ComponentType = Transform;
|
|
1468
|
+
propertyName = "rotationQuaternion";
|
|
1469
|
+
break;
|
|
1470
|
+
case AnimationChannelTargetPath.SCALE:
|
|
1471
|
+
ComponentType = Transform;
|
|
1472
|
+
propertyName = "scale";
|
|
1473
|
+
break;
|
|
1474
|
+
case AnimationChannelTargetPath.WEIGHTS:
|
|
1475
|
+
ComponentType = SkinnedMeshRenderer;
|
|
1476
|
+
propertyName = "blendShapeWeights";
|
|
1477
|
+
break;
|
|
1478
|
+
}
|
|
1479
|
+
var curve = _this._addCurve(target.path, gltfChannel, sampleDataCollection);
|
|
1480
|
+
animationClip.addCurveBinding(relativePath, ComponentType, propertyName, curve);
|
|
1433
1481
|
}
|
|
1434
|
-
|
|
1435
|
-
animationClip.addCurveBinding(relativePath, ComponentType, propertyName, curve);
|
|
1436
|
-
}
|
|
1482
|
+
});
|
|
1437
1483
|
};
|
|
1438
1484
|
GLTFAnimationParser._addCurve = function _addCurve(animationChannelTargetPath, gltfChannel, sampleDataCollection) {
|
|
1439
1485
|
var sampleData = sampleDataCollection[gltfChannel.sampler];
|
|
@@ -1528,20 +1574,18 @@ var GLTFBufferParser = /*#__PURE__*/ function(GLTFParser) {
|
|
|
1528
1574
|
}).then(function(param) {
|
|
1529
1575
|
var glTF = param.glTF, buffers = param.buffers;
|
|
1530
1576
|
context.glTF = glTF;
|
|
1531
|
-
context.
|
|
1577
|
+
context._buffers = buffers;
|
|
1532
1578
|
});
|
|
1533
1579
|
} else {
|
|
1534
1580
|
return request(url, {
|
|
1535
1581
|
type: "json"
|
|
1536
1582
|
}).then(function(glTF) {
|
|
1537
1583
|
context.glTF = glTF;
|
|
1538
|
-
|
|
1584
|
+
context._buffers = Promise.all(glTF.buffers.map(function(buffer) {
|
|
1539
1585
|
var absoluteUrl = Utils.resolveAbsoluteUrl(url, buffer.uri);
|
|
1540
1586
|
restoreBufferRequests.push(new BufferRequestInfo(absoluteUrl, requestConfig));
|
|
1541
1587
|
return request(absoluteUrl, requestConfig);
|
|
1542
|
-
}))
|
|
1543
|
-
context.buffers = buffers;
|
|
1544
|
-
});
|
|
1588
|
+
}));
|
|
1545
1589
|
});
|
|
1546
1590
|
}
|
|
1547
1591
|
};
|
|
@@ -1620,6 +1664,10 @@ var GLTFEntityParser = /*#__PURE__*/ function(GLTFParser) {
|
|
|
1620
1664
|
}
|
|
1621
1665
|
sceneRoots[i] = rootEntity;
|
|
1622
1666
|
}
|
|
1667
|
+
// @ts-ignore
|
|
1668
|
+
sceneRoots[i]._hookResource = glTFResource;
|
|
1669
|
+
// @ts-ignore
|
|
1670
|
+
glTFResource._addReferCount(1);
|
|
1623
1671
|
}
|
|
1624
1672
|
glTFResource.sceneRoots = sceneRoots;
|
|
1625
1673
|
glTFResource.defaultSceneRoot = sceneRoots[sceneID];
|
|
@@ -1786,7 +1834,9 @@ var GLTFMeshParser = /*#__PURE__*/ function(GLTFParser1) {
|
|
|
1786
1834
|
}
|
|
1787
1835
|
}, function() {
|
|
1788
1836
|
var indexAccessor = glTF.accessors[gltfPrimitive.indices];
|
|
1789
|
-
return
|
|
1837
|
+
return context.getBuffers().then(function(buffers) {
|
|
1838
|
+
return GLTFUtils.getAccessorData(glTF, indexAccessor, buffers);
|
|
1839
|
+
});
|
|
1790
1840
|
}, context.keepMeshData).then(resolve);
|
|
1791
1841
|
}
|
|
1792
1842
|
});
|
|
@@ -1796,7 +1846,7 @@ var GLTFMeshParser = /*#__PURE__*/ function(GLTFParser1) {
|
|
|
1796
1846
|
for(var j = 0; j < gltfMesh.primitives.length; j++)_loop(j);
|
|
1797
1847
|
meshPromises[i] = Promise.all(primitivePromises);
|
|
1798
1848
|
};
|
|
1799
|
-
var glTF = context.glTF,
|
|
1849
|
+
var glTF = context.glTF, glTFResource = context.glTFResource;
|
|
1800
1850
|
var engine = glTFResource.engine;
|
|
1801
1851
|
if (!glTF.meshes) return;
|
|
1802
1852
|
var meshesPromiseInfo = context.meshesPromiseInfo;
|
|
@@ -1811,8 +1861,109 @@ var GLTFMeshParser = /*#__PURE__*/ function(GLTFParser1) {
|
|
|
1811
1861
|
/**
|
|
1812
1862
|
* @internal
|
|
1813
1863
|
*/ GLTFMeshParser._parseMeshFromGLTFPrimitive = function _parseMeshFromGLTFPrimitive(context, mesh, meshRestoreInfo, gltfMesh, gltfPrimitive, gltf, getVertexBufferData, getBlendShapeData, getIndexBufferData, keepMeshData) {
|
|
1864
|
+
var _loop = function(attribute) {
|
|
1865
|
+
var accessor = accessors[attributes[attribute]];
|
|
1866
|
+
var promise = GLTFUtils.getAccessorBuffer(context, gltf.bufferViews, accessor).then(function(accessorBuffer) {
|
|
1867
|
+
var dataElementSize = GLTFUtils.getAccessorTypeSize(accessor.type);
|
|
1868
|
+
var accessorCount = accessor.count;
|
|
1869
|
+
var vertices = accessorBuffer.data;
|
|
1870
|
+
var vertexElement;
|
|
1871
|
+
var meshId = mesh.instanceId;
|
|
1872
|
+
var vertexBindingInfos = accessorBuffer.vertexBindingInfos;
|
|
1873
|
+
var elementNormalized = accessor.normalized;
|
|
1874
|
+
var elementFormat = GLTFUtils.getElementFormat(accessor.componentType, dataElementSize, elementNormalized);
|
|
1875
|
+
var scaleFactor;
|
|
1876
|
+
elementNormalized && (scaleFactor = GLTFUtils.getNormalizedComponentScale(accessor.componentType));
|
|
1877
|
+
var elementOffset;
|
|
1878
|
+
if (accessorBuffer.interleaved) {
|
|
1879
|
+
var byteOffset = accessor.byteOffset || 0;
|
|
1880
|
+
var stride = accessorBuffer.stride;
|
|
1881
|
+
elementOffset = byteOffset % stride;
|
|
1882
|
+
if (vertexBindingInfos[meshId] === undefined) {
|
|
1883
|
+
vertexElement = new VertexElement(attribute, elementOffset, elementFormat, bufferBindIndex);
|
|
1884
|
+
var vertexBuffer = accessorBuffer.vertexBuffer;
|
|
1885
|
+
if (!vertexBuffer) {
|
|
1886
|
+
vertexBuffer = new Buffer(engine, BufferBindFlag.VertexBuffer, vertices.byteLength, BufferUsage.Static);
|
|
1887
|
+
vertexBuffer.setData(vertices);
|
|
1888
|
+
accessorBuffer.vertexBuffer = vertexBuffer;
|
|
1889
|
+
meshRestoreInfo.vertexBuffers.push(new BufferRestoreInfo(vertexBuffer, accessorBuffer.restoreInfo));
|
|
1890
|
+
}
|
|
1891
|
+
mesh.setVertexBufferBinding(vertexBuffer, stride, bufferBindIndex);
|
|
1892
|
+
vertexBindingInfos[meshId] = bufferBindIndex++;
|
|
1893
|
+
} else {
|
|
1894
|
+
vertexElement = new VertexElement(attribute, elementOffset, elementFormat, vertexBindingInfos[meshId]);
|
|
1895
|
+
}
|
|
1896
|
+
} else {
|
|
1897
|
+
elementOffset = 0;
|
|
1898
|
+
vertexElement = new VertexElement(attribute, elementOffset, elementFormat, bufferBindIndex);
|
|
1899
|
+
var vertexBuffer1 = new Buffer(engine, BufferBindFlag.VertexBuffer, vertices.byteLength, BufferUsage.Static);
|
|
1900
|
+
vertexBuffer1.setData(vertices);
|
|
1901
|
+
meshRestoreInfo.vertexBuffers.push(new BufferRestoreInfo(vertexBuffer1, accessorBuffer.restoreInfo));
|
|
1902
|
+
mesh.setVertexBufferBinding(vertexBuffer1, accessorBuffer.stride, bufferBindIndex);
|
|
1903
|
+
vertexBindingInfos[meshId] = bufferBindIndex++;
|
|
1904
|
+
}
|
|
1905
|
+
vertexElements.push(vertexElement);
|
|
1906
|
+
if (attribute === "POSITION") {
|
|
1907
|
+
vertexCount = accessorCount;
|
|
1908
|
+
var _mesh_bounds = mesh.bounds, min = _mesh_bounds.min, max = _mesh_bounds.max;
|
|
1909
|
+
if (accessor.min && accessor.max) {
|
|
1910
|
+
min.copyFromArray(accessor.min);
|
|
1911
|
+
max.copyFromArray(accessor.max);
|
|
1912
|
+
if (keepMeshData) {
|
|
1913
|
+
var baseOffset = elementOffset / vertices.BYTES_PER_ELEMENT;
|
|
1914
|
+
var stride1 = vertices.length / accessorCount;
|
|
1915
|
+
for(var j = 0; j < accessorCount; j++){
|
|
1916
|
+
var offset = baseOffset + j * stride1;
|
|
1917
|
+
var position = new Vector3(vertices[offset], vertices[offset + 1], vertices[offset + 2]);
|
|
1918
|
+
elementNormalized && position.scale(scaleFactor);
|
|
1919
|
+
positions[j] = position;
|
|
1920
|
+
}
|
|
1921
|
+
}
|
|
1922
|
+
} else {
|
|
1923
|
+
var position1 = GLTFMeshParser._tempVector3;
|
|
1924
|
+
min.set(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
|
|
1925
|
+
max.set(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE);
|
|
1926
|
+
var baseOffset1 = elementOffset / vertices.BYTES_PER_ELEMENT;
|
|
1927
|
+
var stride2 = vertices.length / accessorCount;
|
|
1928
|
+
for(var j1 = 0; j1 < accessorCount; j1++){
|
|
1929
|
+
var offset1 = baseOffset1 + j1 * stride2;
|
|
1930
|
+
position1.copyFromArray(vertices, offset1);
|
|
1931
|
+
Vector3.min(min, position1, min);
|
|
1932
|
+
Vector3.max(max, position1, max);
|
|
1933
|
+
if (keepMeshData) {
|
|
1934
|
+
var clonePosition = position1.clone();
|
|
1935
|
+
elementNormalized && clonePosition.scale(scaleFactor);
|
|
1936
|
+
positions[j1] = clonePosition;
|
|
1937
|
+
}
|
|
1938
|
+
}
|
|
1939
|
+
}
|
|
1940
|
+
if (elementNormalized) {
|
|
1941
|
+
min.scale(scaleFactor);
|
|
1942
|
+
max.scale(scaleFactor);
|
|
1943
|
+
}
|
|
1944
|
+
} else if (attribute === "JOINTS_0" && keepMeshData) {
|
|
1945
|
+
var baseOffset2 = elementOffset / vertices.BYTES_PER_ELEMENT;
|
|
1946
|
+
var stride3 = vertices.length / accessorCount;
|
|
1947
|
+
for(var j2 = 0; j2 < accessorCount; j2++){
|
|
1948
|
+
var offset2 = baseOffset2 + j2 * stride3;
|
|
1949
|
+
var boneIndex = new Vector4(vertices[offset2], vertices[offset2 + 1], vertices[offset2 + 2], vertices[offset2 + 3]);
|
|
1950
|
+
elementNormalized && boneIndex.scale(scaleFactor);
|
|
1951
|
+
boneIndices[j2] = boneIndex;
|
|
1952
|
+
}
|
|
1953
|
+
} else if (attribute === "WEIGHTS_0" && keepMeshData) {
|
|
1954
|
+
var baseOffset3 = elementOffset / vertices.BYTES_PER_ELEMENT;
|
|
1955
|
+
var stride4 = vertices.length / accessorCount;
|
|
1956
|
+
for(var j3 = 0; j3 < accessorCount; j3++){
|
|
1957
|
+
var offset3 = baseOffset3 + j3 * stride4;
|
|
1958
|
+
var boneWeight = new Vector4(vertices[offset3], vertices[offset3 + 1], vertices[offset3 + 2], vertices[offset3 + 3]);
|
|
1959
|
+
elementNormalized && boneWeight.scale(scaleFactor);
|
|
1960
|
+
boneWeights[j3] = boneWeight;
|
|
1961
|
+
}
|
|
1962
|
+
}
|
|
1963
|
+
});
|
|
1964
|
+
promises.push(promise);
|
|
1965
|
+
};
|
|
1814
1966
|
var accessors = gltf.accessors;
|
|
1815
|
-
context.buffers;
|
|
1816
1967
|
var attributes = gltfPrimitive.attributes, targets = gltfPrimitive.targets, indices = gltfPrimitive.indices, mode = gltfPrimitive.mode;
|
|
1817
1968
|
var engine = mesh.engine;
|
|
1818
1969
|
var vertexElements = new Array();
|
|
@@ -1826,145 +1977,85 @@ var GLTFMeshParser = /*#__PURE__*/ function(GLTFParser1) {
|
|
|
1826
1977
|
boneIndices = new Array(vertexCount);
|
|
1827
1978
|
boneWeights = new Array(vertexCount);
|
|
1828
1979
|
}
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
var elementOffset = void 0;
|
|
1843
|
-
if (accessorBuffer.interleaved) {
|
|
1844
|
-
var byteOffset = accessor.byteOffset || 0;
|
|
1845
|
-
var stride = accessorBuffer.stride;
|
|
1846
|
-
elementOffset = byteOffset % stride;
|
|
1847
|
-
if (vertexBindingInfos[meshId] === undefined) {
|
|
1848
|
-
vertexElement = new VertexElement(attribute, elementOffset, elementFormat, bufferBindIndex);
|
|
1849
|
-
var vertexBuffer = accessorBuffer.vertexBuffer;
|
|
1850
|
-
if (!vertexBuffer) {
|
|
1851
|
-
vertexBuffer = new Buffer(engine, BufferBindFlag.VertexBuffer, vertices.byteLength, BufferUsage.Static);
|
|
1852
|
-
vertexBuffer.setData(vertices);
|
|
1853
|
-
accessorBuffer.vertexBuffer = vertexBuffer;
|
|
1854
|
-
meshRestoreInfo.vertexBuffers.push(new BufferRestoreInfo(vertexBuffer, accessorBuffer.restoreInfo));
|
|
1855
|
-
}
|
|
1856
|
-
mesh.setVertexBufferBinding(vertexBuffer, stride, bufferBindIndex);
|
|
1857
|
-
vertexBindingInfos[meshId] = bufferBindIndex++;
|
|
1858
|
-
} else {
|
|
1859
|
-
vertexElement = new VertexElement(attribute, elementOffset, elementFormat, vertexBindingInfos[meshId]);
|
|
1860
|
-
}
|
|
1980
|
+
var promises = new Array();
|
|
1981
|
+
for(var attribute in attributes)_loop(attribute);
|
|
1982
|
+
return Promise.all(promises).then(function() {
|
|
1983
|
+
mesh.setVertexElements(vertexElements);
|
|
1984
|
+
// Indices
|
|
1985
|
+
if (indices !== undefined) {
|
|
1986
|
+
var indexAccessor = gltf.accessors[indices];
|
|
1987
|
+
var promise = GLTFUtils.getAccessorBuffer(context, gltf.bufferViews, indexAccessor).then(function(accessorBuffer) {
|
|
1988
|
+
mesh.setIndices(accessorBuffer.data);
|
|
1989
|
+
mesh.addSubMesh(0, indexAccessor.count, mode);
|
|
1990
|
+
meshRestoreInfo.indexBuffer = accessorBuffer.restoreInfo;
|
|
1991
|
+
});
|
|
1992
|
+
promises.push(promise);
|
|
1861
1993
|
} else {
|
|
1862
|
-
|
|
1863
|
-
vertexElement = new VertexElement(attribute, elementOffset, elementFormat, bufferBindIndex);
|
|
1864
|
-
var vertexBuffer1 = new Buffer(engine, BufferBindFlag.VertexBuffer, vertices.byteLength, BufferUsage.Static);
|
|
1865
|
-
vertexBuffer1.setData(vertices);
|
|
1866
|
-
meshRestoreInfo.vertexBuffers.push(new BufferRestoreInfo(vertexBuffer1, accessorBuffer.restoreInfo));
|
|
1867
|
-
mesh.setVertexBufferBinding(vertexBuffer1, accessorBuffer.stride, bufferBindIndex);
|
|
1868
|
-
vertexBindingInfos[meshId] = bufferBindIndex++;
|
|
1994
|
+
mesh.addSubMesh(0, vertexCount, mode);
|
|
1869
1995
|
}
|
|
1870
|
-
|
|
1871
|
-
if (
|
|
1872
|
-
|
|
1873
|
-
var _mesh_bounds = mesh.bounds, min = _mesh_bounds.min, max = _mesh_bounds.max;
|
|
1874
|
-
if (accessor.min && accessor.max) {
|
|
1875
|
-
min.copyFromArray(accessor.min);
|
|
1876
|
-
max.copyFromArray(accessor.max);
|
|
1877
|
-
if (keepMeshData) {
|
|
1878
|
-
var baseOffset = elementOffset / vertices.BYTES_PER_ELEMENT;
|
|
1879
|
-
var stride1 = vertices.length / accessorCount;
|
|
1880
|
-
for(var j = 0; j < accessorCount; j++){
|
|
1881
|
-
var offset = baseOffset + j * stride1;
|
|
1882
|
-
var position = new Vector3(vertices[offset], vertices[offset + 1], vertices[offset + 2]);
|
|
1883
|
-
elementNormalized && position.scale(scaleFactor);
|
|
1884
|
-
positions[j] = position;
|
|
1885
|
-
}
|
|
1886
|
-
}
|
|
1887
|
-
} else {
|
|
1888
|
-
var position1 = GLTFMeshParser._tempVector3;
|
|
1889
|
-
min.set(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
|
|
1890
|
-
max.set(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE);
|
|
1891
|
-
var baseOffset1 = elementOffset / vertices.BYTES_PER_ELEMENT;
|
|
1892
|
-
var stride2 = vertices.length / accessorCount;
|
|
1893
|
-
for(var j1 = 0; j1 < accessorCount; j1++){
|
|
1894
|
-
var offset1 = baseOffset1 + j1 * stride2;
|
|
1895
|
-
position1.copyFromArray(vertices, offset1);
|
|
1896
|
-
Vector3.min(min, position1, min);
|
|
1897
|
-
Vector3.max(max, position1, max);
|
|
1898
|
-
if (keepMeshData) {
|
|
1899
|
-
var clonePosition = position1.clone();
|
|
1900
|
-
elementNormalized && clonePosition.scale(scaleFactor);
|
|
1901
|
-
positions[j1] = clonePosition;
|
|
1902
|
-
}
|
|
1903
|
-
}
|
|
1904
|
-
}
|
|
1905
|
-
if (elementNormalized) {
|
|
1906
|
-
min.scale(scaleFactor);
|
|
1907
|
-
max.scale(scaleFactor);
|
|
1908
|
-
}
|
|
1909
|
-
} else if (attribute === "JOINTS_0" && keepMeshData) {
|
|
1910
|
-
var baseOffset2 = elementOffset / vertices.BYTES_PER_ELEMENT;
|
|
1911
|
-
var stride3 = vertices.length / accessorCount;
|
|
1912
|
-
for(var j2 = 0; j2 < accessorCount; j2++){
|
|
1913
|
-
var offset2 = baseOffset2 + j2 * stride3;
|
|
1914
|
-
var boneIndex = new Vector4(vertices[offset2], vertices[offset2 + 1], vertices[offset2 + 2], vertices[offset2 + 3]);
|
|
1915
|
-
elementNormalized && boneIndex.scale(scaleFactor);
|
|
1916
|
-
boneIndices[j2] = boneIndex;
|
|
1917
|
-
}
|
|
1918
|
-
} else if (attribute === "WEIGHTS_0" && keepMeshData) {
|
|
1919
|
-
var baseOffset3 = elementOffset / vertices.BYTES_PER_ELEMENT;
|
|
1920
|
-
var stride4 = vertices.length / accessorCount;
|
|
1921
|
-
for(var j3 = 0; j3 < accessorCount; j3++){
|
|
1922
|
-
var offset3 = baseOffset3 + j3 * stride4;
|
|
1923
|
-
var boneWeight = new Vector4(vertices[offset3], vertices[offset3 + 1], vertices[offset3 + 2], vertices[offset3 + 3]);
|
|
1924
|
-
elementNormalized && boneWeight.scale(scaleFactor);
|
|
1925
|
-
boneWeights[j3] = boneWeight;
|
|
1926
|
-
}
|
|
1996
|
+
// BlendShapes
|
|
1997
|
+
if (targets) {
|
|
1998
|
+
promises.push(GLTFMeshParser._createBlendShape(mesh, meshRestoreInfo, gltfMesh, accessors, targets, getBlendShapeData));
|
|
1927
1999
|
}
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
}
|
|
1940
|
-
// BlendShapes
|
|
1941
|
-
targets && GLTFMeshParser._createBlendShape(mesh, meshRestoreInfo, gltfMesh, targets, getBlendShapeData);
|
|
1942
|
-
mesh.uploadData(!keepMeshData);
|
|
1943
|
-
//@ts-ignore
|
|
1944
|
-
mesh._positions = positions;
|
|
1945
|
-
//@ts-ignore
|
|
1946
|
-
mesh._boneIndices = boneIndices;
|
|
1947
|
-
//@ts-ignore
|
|
1948
|
-
mesh._boneWeights = boneWeights;
|
|
1949
|
-
return Promise.resolve(mesh);
|
|
2000
|
+
return Promise.all(promises).then(function() {
|
|
2001
|
+
mesh.uploadData(!keepMeshData);
|
|
2002
|
+
//@ts-ignore
|
|
2003
|
+
mesh._positions = positions;
|
|
2004
|
+
//@ts-ignore
|
|
2005
|
+
mesh._boneIndices = boneIndices;
|
|
2006
|
+
//@ts-ignore
|
|
2007
|
+
mesh._boneWeights = boneWeights;
|
|
2008
|
+
return Promise.resolve(mesh);
|
|
2009
|
+
});
|
|
2010
|
+
});
|
|
1950
2011
|
};
|
|
1951
2012
|
/**
|
|
1952
2013
|
* @internal
|
|
1953
|
-
*/ GLTFMeshParser._createBlendShape = function _createBlendShape(mesh, meshRestoreInfo, glTFMesh, glTFTargets, getBlendShapeData) {
|
|
1954
|
-
var
|
|
1955
|
-
for(var i = 0, n = glTFTargets.length; i < n; i++){
|
|
2014
|
+
*/ GLTFMeshParser._createBlendShape = function _createBlendShape(mesh, meshRestoreInfo, glTFMesh, accessors, glTFTargets, getBlendShapeData) {
|
|
2015
|
+
var _loop = function(i, n) {
|
|
1956
2016
|
var name = blendShapeNames ? blendShapeNames[i] : "blendShape" + i;
|
|
1957
|
-
var
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
2017
|
+
var promise = Promise.all([
|
|
2018
|
+
getBlendShapeData("POSITION", i),
|
|
2019
|
+
getBlendShapeData("NORMAL", i),
|
|
2020
|
+
getBlendShapeData("TANGENT", i)
|
|
2021
|
+
]).then(function(infos) {
|
|
2022
|
+
var posBufferInfo = infos[0];
|
|
2023
|
+
var norBufferInfo = infos[1];
|
|
2024
|
+
var tanBufferInfo = infos[2];
|
|
2025
|
+
var target = glTFTargets[i];
|
|
2026
|
+
var posAccessor;
|
|
2027
|
+
var norAccessor;
|
|
2028
|
+
var tanAccessor;
|
|
2029
|
+
var positions = null;
|
|
2030
|
+
if (posBufferInfo) {
|
|
2031
|
+
posAccessor = accessors[target["POSITION"]];
|
|
2032
|
+
var _posAccessor_byteOffset;
|
|
2033
|
+
positions = GLTFUtils.bufferToVector3Array(posBufferInfo.data, posBufferInfo.stride, (_posAccessor_byteOffset = posAccessor.byteOffset) != null ? _posAccessor_byteOffset : 0, posAccessor.count);
|
|
2034
|
+
}
|
|
2035
|
+
var normals = null;
|
|
2036
|
+
if (norBufferInfo) {
|
|
2037
|
+
norAccessor = accessors[target["NORMAL"]];
|
|
2038
|
+
var _norAccessor_byteOffset;
|
|
2039
|
+
normals = GLTFUtils.bufferToVector3Array(norBufferInfo.data, norBufferInfo.stride, (_norAccessor_byteOffset = norAccessor.byteOffset) != null ? _norAccessor_byteOffset : 0, norAccessor.count);
|
|
2040
|
+
}
|
|
2041
|
+
var tangents = null;
|
|
2042
|
+
if (tanBufferInfo) {
|
|
2043
|
+
tanAccessor = accessors[target["NORMAL"]];
|
|
2044
|
+
var _tanAccessor_byteOffset;
|
|
2045
|
+
tangents = GLTFUtils.bufferToVector3Array(tanBufferInfo.data, tanBufferInfo.stride, (_tanAccessor_byteOffset = tanAccessor.byteOffset) != null ? _tanAccessor_byteOffset : 0, tanAccessor.count);
|
|
2046
|
+
}
|
|
2047
|
+
var blendShape = new BlendShape(name);
|
|
2048
|
+
blendShape.addFrame(1.0, positions, normals, tangents);
|
|
2049
|
+
mesh.addBlendShape(blendShape);
|
|
2050
|
+
var _posAccessor_byteOffset1, _norAccessor_byteOffset1, _tanAccessor_byteOffset1;
|
|
2051
|
+
meshRestoreInfo.blendShapes.push(new BlendShapeRestoreInfo(blendShape, new BlendShapeDataRestoreInfo(posBufferInfo.restoreInfo, posBufferInfo.stride, (_posAccessor_byteOffset1 = posAccessor.byteOffset) != null ? _posAccessor_byteOffset1 : 0, posAccessor.count), norBufferInfo ? new BlendShapeDataRestoreInfo(norBufferInfo.restoreInfo, norBufferInfo.stride, (_norAccessor_byteOffset1 = norAccessor.byteOffset) != null ? _norAccessor_byteOffset1 : 0, norAccessor.count) : null, tanBufferInfo ? new BlendShapeDataRestoreInfo(tanBufferInfo.restoreInfo, tanBufferInfo.stride, (_tanAccessor_byteOffset1 = tanAccessor.byteOffset) != null ? _tanAccessor_byteOffset1 : 0, tanAccessor.count) : null));
|
|
2052
|
+
});
|
|
2053
|
+
promises.push(promise);
|
|
2054
|
+
};
|
|
2055
|
+
var blendShapeNames = glTFMesh.extras ? glTFMesh.extras.targetNames : null;
|
|
2056
|
+
var promises = new Array();
|
|
2057
|
+
for(var i = 0, n = glTFTargets.length; i < n; i++)_loop(i);
|
|
2058
|
+
return Promise.all(promises);
|
|
1968
2059
|
};
|
|
1969
2060
|
return GLTFMeshParser;
|
|
1970
2061
|
}(GLTFParser);
|
|
@@ -2116,51 +2207,58 @@ var GLTFSkinParser = /*#__PURE__*/ function(GLTFParser) {
|
|
|
2116
2207
|
}
|
|
2117
2208
|
var _proto = GLTFSkinParser.prototype;
|
|
2118
2209
|
_proto.parse = function parse(context) {
|
|
2119
|
-
var
|
|
2120
|
-
var entities = glTFResource.entities;
|
|
2121
|
-
var gltfSkins = glTF.skins;
|
|
2122
|
-
if (!gltfSkins) return;
|
|
2123
|
-
var count = gltfSkins.length;
|
|
2124
|
-
var skins = new Array(count);
|
|
2125
|
-
for(var i = 0; i < count; i++){
|
|
2210
|
+
var _loop = function(i) {
|
|
2126
2211
|
var _gltfSkins_i = gltfSkins[i], inverseBindMatrices = _gltfSkins_i.inverseBindMatrices, skeleton = _gltfSkins_i.skeleton, joints = _gltfSkins_i.joints, _gltfSkins_i_name = _gltfSkins_i.name, name = _gltfSkins_i_name === void 0 ? "SKIN_" + i : _gltfSkins_i_name;
|
|
2127
2212
|
var jointCount = joints.length;
|
|
2128
2213
|
var skin = new Skin(name);
|
|
2129
2214
|
skin.inverseBindMatrices.length = jointCount;
|
|
2130
2215
|
// parse IBM
|
|
2131
2216
|
var accessor = glTF.accessors[inverseBindMatrices];
|
|
2132
|
-
var
|
|
2133
|
-
|
|
2134
|
-
var
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2217
|
+
var promise = GLTFUtils.getAccessorBuffer(context, glTF.bufferViews, accessor).then(function(bufferInfo) {
|
|
2218
|
+
var buffer = bufferInfo.data;
|
|
2219
|
+
for(var i = 0; i < jointCount; i++){
|
|
2220
|
+
var inverseBindMatrix = new Matrix();
|
|
2221
|
+
inverseBindMatrix.copyFromArray(buffer, i * 16);
|
|
2222
|
+
skin.inverseBindMatrices[i] = inverseBindMatrix;
|
|
2223
|
+
// get joints
|
|
2224
|
+
for(var i1 = 0; i1 < jointCount; i1++){
|
|
2225
|
+
var jointIndex = joints[i1];
|
|
2226
|
+
var jointName = entities[jointIndex].name;
|
|
2227
|
+
skin.joints[i1] = jointName;
|
|
2228
|
+
// @todo Temporary solution, but it can alleviate the current BUG, and the skinning data mechanism of SkinnedMeshRenderer will be completely refactored in the future
|
|
2229
|
+
for(var j = entities.length - 1; j >= 0; j--){
|
|
2230
|
+
if (jointIndex !== j && entities[j].name === jointName) {
|
|
2231
|
+
entities[j].name = jointName + "_" + j;
|
|
2232
|
+
}
|
|
2233
|
+
}
|
|
2234
|
+
}
|
|
2235
|
+
// get skeleton
|
|
2236
|
+
if (skeleton !== undefined) {
|
|
2237
|
+
skin.skeleton = entities[skeleton].name;
|
|
2238
|
+
} else {
|
|
2239
|
+
var rootBone = _this._findSkeletonRootBone(joints, entities);
|
|
2240
|
+
if (rootBone) {
|
|
2241
|
+
skin.skeleton = rootBone.name;
|
|
2242
|
+
} else {
|
|
2243
|
+
throw "Failed to find skeleton root bone.";
|
|
2244
|
+
}
|
|
2147
2245
|
}
|
|
2148
2246
|
}
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2247
|
+
return skin;
|
|
2248
|
+
});
|
|
2249
|
+
promises.push(promise);
|
|
2250
|
+
};
|
|
2251
|
+
var _this = this;
|
|
2252
|
+
var glTFResource = context.glTFResource, glTF = context.glTF;
|
|
2253
|
+
var entities = glTFResource.entities;
|
|
2254
|
+
var gltfSkins = glTF.skins;
|
|
2255
|
+
if (!gltfSkins) return;
|
|
2256
|
+
var count = gltfSkins.length;
|
|
2257
|
+
var promises = new Array();
|
|
2258
|
+
for(var i = 0; i < count; i++)_loop(i);
|
|
2259
|
+
return AssetPromise.all(promises).then(function(skins) {
|
|
2260
|
+
glTFResource.skins = skins;
|
|
2261
|
+
});
|
|
2164
2262
|
};
|
|
2165
2263
|
_proto._findSkeletonRootBone = function _findSkeletonRootBone(joints, entities) {
|
|
2166
2264
|
var paths = {};
|
|
@@ -2201,13 +2299,14 @@ var GLTFTextureParser = /*#__PURE__*/ function(GLTFParser) {
|
|
|
2201
2299
|
var _proto = GLTFTextureParser.prototype;
|
|
2202
2300
|
_proto.parse = function parse(context) {
|
|
2203
2301
|
var _this = this;
|
|
2204
|
-
var glTFResource = context.glTFResource, glTF = context.glTF
|
|
2302
|
+
var glTFResource = context.glTFResource, glTF = context.glTF;
|
|
2205
2303
|
var engine = glTFResource.engine, url = glTFResource.url;
|
|
2206
2304
|
if (glTF.textures) {
|
|
2207
2305
|
var texturesPromiseInfo = context.texturesPromiseInfo;
|
|
2208
2306
|
AssetPromise.all(glTF.textures.map(function(param, index) {
|
|
2209
2307
|
var sampler = param.sampler, _param_source = param.source, source = _param_source === void 0 ? 0 : _param_source, textureName = param.name;
|
|
2210
2308
|
var _glTF_images_source = glTF.images[source], uri = _glTF_images_source.uri, bufferViewIndex = _glTF_images_source.bufferView, mimeType = _glTF_images_source.mimeType, imageName = _glTF_images_source.name;
|
|
2309
|
+
var samplerInfo = sampler !== undefined && _this._getSamplerInfo(glTF.samplers[sampler]);
|
|
2211
2310
|
if (uri) {
|
|
2212
2311
|
// TODO: support ktx extension https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_texture_basisu/README.md
|
|
2213
2312
|
var index1 = uri.lastIndexOf(".");
|
|
@@ -2215,31 +2314,36 @@ var GLTFTextureParser = /*#__PURE__*/ function(GLTFParser) {
|
|
|
2215
2314
|
var type = ext.startsWith("ktx") ? AssetType.KTX : AssetType.Texture2D;
|
|
2216
2315
|
return engine.resourceManager.load({
|
|
2217
2316
|
url: Utils.resolveAbsoluteUrl(url, uri),
|
|
2218
|
-
type: type
|
|
2317
|
+
type: type,
|
|
2318
|
+
params: {
|
|
2319
|
+
mipmap: samplerInfo == null ? void 0 : samplerInfo.mipmap
|
|
2320
|
+
}
|
|
2219
2321
|
}).then(function(texture) {
|
|
2220
2322
|
if (!texture.name) {
|
|
2221
2323
|
texture.name = textureName || imageName || "texture_" + index1;
|
|
2222
2324
|
}
|
|
2223
2325
|
if (sampler !== undefined) {
|
|
2224
|
-
_this._parseSampler(texture,
|
|
2326
|
+
_this._parseSampler(texture, samplerInfo);
|
|
2225
2327
|
}
|
|
2226
2328
|
return texture;
|
|
2227
2329
|
});
|
|
2228
2330
|
} else {
|
|
2229
2331
|
var bufferView = glTF.bufferViews[bufferViewIndex];
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2332
|
+
return context.getBuffers().then(function(buffers) {
|
|
2333
|
+
var buffer = buffers[bufferView.buffer];
|
|
2334
|
+
var imageBuffer = new Uint8Array(buffer, bufferView.byteOffset, bufferView.byteLength);
|
|
2335
|
+
return GLTFUtils.loadImageBuffer(imageBuffer, mimeType).then(function(image) {
|
|
2336
|
+
var texture = new Texture2D(engine, image.width, image.height, undefined, samplerInfo == null ? void 0 : samplerInfo.mipmap);
|
|
2337
|
+
texture.setImageSource(image);
|
|
2338
|
+
texture.generateMipmaps();
|
|
2339
|
+
texture.name = textureName || imageName || "texture_" + index;
|
|
2340
|
+
if (sampler !== undefined) {
|
|
2341
|
+
_this._parseSampler(texture, samplerInfo);
|
|
2342
|
+
}
|
|
2343
|
+
var bufferTextureRestoreInfo = new BufferTextureRestoreInfo(texture, bufferView, mimeType);
|
|
2344
|
+
context.contentRestorer.bufferTextures.push(bufferTextureRestoreInfo);
|
|
2345
|
+
return texture;
|
|
2346
|
+
});
|
|
2243
2347
|
});
|
|
2244
2348
|
}
|
|
2245
2349
|
})).then(function(textures) {
|
|
@@ -2249,22 +2353,39 @@ var GLTFTextureParser = /*#__PURE__*/ function(GLTFParser) {
|
|
|
2249
2353
|
return texturesPromiseInfo.promise;
|
|
2250
2354
|
}
|
|
2251
2355
|
};
|
|
2252
|
-
_proto.
|
|
2253
|
-
var
|
|
2254
|
-
|
|
2356
|
+
_proto._getSamplerInfo = function _getSamplerInfo(sampler) {
|
|
2357
|
+
var minFilter = sampler.minFilter, magFilter = sampler.magFilter, wrapS = sampler.wrapS, wrapT = sampler.wrapT;
|
|
2358
|
+
var info = {};
|
|
2359
|
+
if (minFilter || magFilter) {
|
|
2360
|
+
info.mipmap = minFilter >= TextureMinFilter.NEAREST_MIPMAP_NEAREST;
|
|
2255
2361
|
if (magFilter === TextureMagFilter.NEAREST) {
|
|
2256
|
-
|
|
2257
|
-
} else if (minFilter <= TextureMinFilter.LINEAR_MIPMAP_NEAREST) {
|
|
2258
|
-
texture.filterMode = TextureFilterMode.Bilinear;
|
|
2362
|
+
info.filterMode = TextureFilterMode.Point;
|
|
2259
2363
|
} else {
|
|
2260
|
-
|
|
2364
|
+
if (minFilter <= TextureMinFilter.LINEAR_MIPMAP_NEAREST) {
|
|
2365
|
+
info.filterMode = TextureFilterMode.Bilinear;
|
|
2366
|
+
} else {
|
|
2367
|
+
info.filterMode = TextureFilterMode.Trilinear;
|
|
2368
|
+
}
|
|
2261
2369
|
}
|
|
2262
2370
|
}
|
|
2263
2371
|
if (wrapS) {
|
|
2264
|
-
|
|
2372
|
+
info.wrapModeU = GLTFTextureParser._wrapMap[wrapS];
|
|
2265
2373
|
}
|
|
2266
2374
|
if (wrapT) {
|
|
2267
|
-
|
|
2375
|
+
info.wrapModeV = GLTFTextureParser._wrapMap[wrapT];
|
|
2376
|
+
}
|
|
2377
|
+
return info;
|
|
2378
|
+
};
|
|
2379
|
+
_proto._parseSampler = function _parseSampler(texture, samplerInfo) {
|
|
2380
|
+
var filterMode = samplerInfo.filterMode, wrapModeU = samplerInfo.wrapModeU, wrapModeV = samplerInfo.wrapModeV;
|
|
2381
|
+
if (filterMode !== undefined) {
|
|
2382
|
+
texture.filterMode = filterMode;
|
|
2383
|
+
}
|
|
2384
|
+
if (wrapModeU !== undefined) {
|
|
2385
|
+
texture.wrapModeU = wrapModeU;
|
|
2386
|
+
}
|
|
2387
|
+
if (wrapModeV !== undefined) {
|
|
2388
|
+
texture.wrapModeV = wrapModeV;
|
|
2268
2389
|
}
|
|
2269
2390
|
};
|
|
2270
2391
|
return GLTFTextureParser;
|
|
@@ -2362,33 +2483,16 @@ var GLTFValidator = /*#__PURE__*/ function(GLTFParser1) {
|
|
|
2362
2483
|
|
|
2363
2484
|
/**
|
|
2364
2485
|
* Product after glTF parser, usually, `defaultSceneRoot` is only needed to use.
|
|
2365
|
-
*/ var GLTFResource = /*#__PURE__*/ function(
|
|
2366
|
-
_inherits(GLTFResource,
|
|
2486
|
+
*/ var GLTFResource = /*#__PURE__*/ function(ReferResource) {
|
|
2487
|
+
_inherits(GLTFResource, ReferResource);
|
|
2367
2488
|
function GLTFResource(engine, url) {
|
|
2368
2489
|
var _this;
|
|
2369
|
-
_this =
|
|
2490
|
+
_this = ReferResource.call(this, engine) || this;
|
|
2370
2491
|
_this.url = url;
|
|
2371
2492
|
return _this;
|
|
2372
2493
|
}
|
|
2373
|
-
var _proto = GLTFResource.prototype;
|
|
2374
|
-
/**
|
|
2375
|
-
* @internal
|
|
2376
|
-
*/ _proto._onDestroy = function _onDestroy() {
|
|
2377
|
-
EngineObject.prototype._onDestroy.call(this);
|
|
2378
|
-
this.defaultSceneRoot.destroy();
|
|
2379
|
-
this.textures = null;
|
|
2380
|
-
this.materials = null;
|
|
2381
|
-
this.meshes = null;
|
|
2382
|
-
this.skins = null;
|
|
2383
|
-
this.animations = null;
|
|
2384
|
-
this.entities = null;
|
|
2385
|
-
this.cameras = null;
|
|
2386
|
-
this.lights = null;
|
|
2387
|
-
this.sceneRoots = null;
|
|
2388
|
-
this.extensionsData = null;
|
|
2389
|
-
};
|
|
2390
2494
|
return GLTFResource;
|
|
2391
|
-
}(
|
|
2495
|
+
}(ReferResource);
|
|
2392
2496
|
|
|
2393
2497
|
var GLTFLoader = /*#__PURE__*/ function(Loader) {
|
|
2394
2498
|
_inherits(GLTFLoader, Loader);
|
|
@@ -2418,8 +2522,14 @@ var GLTFLoader = /*#__PURE__*/ function(Loader) {
|
|
|
2418
2522
|
resourceManager.addContentRestorer(restorer);
|
|
2419
2523
|
masterPromiseInfo.resolve(glTFResource);
|
|
2420
2524
|
}).catch(function(e) {
|
|
2421
|
-
|
|
2422
|
-
|
|
2525
|
+
var msg = "Error loading glTF model from " + url + " : " + e;
|
|
2526
|
+
Logger.error(msg);
|
|
2527
|
+
masterPromiseInfo.reject(msg);
|
|
2528
|
+
context.defaultSceneRootPromiseInfo.reject(e);
|
|
2529
|
+
context.texturesPromiseInfo.reject(e);
|
|
2530
|
+
context.materialsPromiseInfo.reject(e);
|
|
2531
|
+
context.meshesPromiseInfo.reject(e);
|
|
2532
|
+
context.animationClipsPromiseInfo.reject(e);
|
|
2423
2533
|
});
|
|
2424
2534
|
return context.promiseMap;
|
|
2425
2535
|
};
|
|
@@ -3021,6 +3131,15 @@ KTXLoader = __decorate([
|
|
|
3021
3131
|
])
|
|
3022
3132
|
], KTXLoader);
|
|
3023
3133
|
|
|
3134
|
+
function parseProperty(object, key, value) {
|
|
3135
|
+
if (typeof value === "object") {
|
|
3136
|
+
for(var subKey in value){
|
|
3137
|
+
parseProperty(object[key], subKey, value[subKey]);
|
|
3138
|
+
}
|
|
3139
|
+
} else {
|
|
3140
|
+
object[key] = value;
|
|
3141
|
+
}
|
|
3142
|
+
}
|
|
3024
3143
|
var MaterialLoader = /*#__PURE__*/ function(Loader) {
|
|
3025
3144
|
_inherits(MaterialLoader, Loader);
|
|
3026
3145
|
function MaterialLoader() {
|
|
@@ -3032,7 +3151,7 @@ var MaterialLoader = /*#__PURE__*/ function(Loader) {
|
|
|
3032
3151
|
return new AssetPromise(function(resolve, reject) {
|
|
3033
3152
|
_this.request(item.url, _extends({}, item, {
|
|
3034
3153
|
type: "json"
|
|
3035
|
-
})).then(function(
|
|
3154
|
+
})).then(function(materialSchema) {
|
|
3036
3155
|
var _loop = function(key) {
|
|
3037
3156
|
var _shaderData_key = shaderData[key], type = _shaderData_key.type, value = _shaderData_key.value;
|
|
3038
3157
|
switch(type){
|
|
@@ -3060,27 +3179,8 @@ var MaterialLoader = /*#__PURE__*/ function(Loader) {
|
|
|
3060
3179
|
}
|
|
3061
3180
|
};
|
|
3062
3181
|
var engine = resourceManager.engine;
|
|
3063
|
-
var name =
|
|
3064
|
-
var material;
|
|
3065
|
-
switch(shader){
|
|
3066
|
-
case "pbr":
|
|
3067
|
-
material = new PBRMaterial(engine);
|
|
3068
|
-
break;
|
|
3069
|
-
case "pbr-specular":
|
|
3070
|
-
material = new PBRSpecularMaterial(engine);
|
|
3071
|
-
break;
|
|
3072
|
-
case "unlit":
|
|
3073
|
-
material = new UnlitMaterial(engine);
|
|
3074
|
-
break;
|
|
3075
|
-
case "blinn-phong":
|
|
3076
|
-
material = new BlinnPhongMaterial(engine);
|
|
3077
|
-
break;
|
|
3078
|
-
case "bake-pbr":
|
|
3079
|
-
// @todo refactor custom shader later
|
|
3080
|
-
// @ts-ignore
|
|
3081
|
-
material = new PBRBaseMaterial(engine, Shader.find("bake-pbr"));
|
|
3082
|
-
break;
|
|
3083
|
-
}
|
|
3182
|
+
var name = materialSchema.name, shader = materialSchema.shader, shaderData = materialSchema.shaderData, macros = materialSchema.macros, renderState = materialSchema.renderState;
|
|
3183
|
+
var material = new Material(engine, Shader.find(shader));
|
|
3084
3184
|
material.name = name;
|
|
3085
3185
|
var texturePromises = new Array();
|
|
3086
3186
|
var materialShaderData = material.shaderData;
|
|
@@ -3093,9 +3193,7 @@ var MaterialLoader = /*#__PURE__*/ function(Loader) {
|
|
|
3093
3193
|
materialShaderData.enableMacro(name1, value);
|
|
3094
3194
|
}
|
|
3095
3195
|
}
|
|
3096
|
-
|
|
3097
|
-
material[key1] = renderState[key1];
|
|
3098
|
-
}
|
|
3196
|
+
parseProperty(material, "renderState", renderState);
|
|
3099
3197
|
return Promise.all(texturePromises).then(function() {
|
|
3100
3198
|
resolve(material);
|
|
3101
3199
|
});
|
|
@@ -3850,6 +3948,12 @@ AnimationClipDecoder = __decorate([
|
|
|
3850
3948
|
decoder("AnimationClip")
|
|
3851
3949
|
], AnimationClipDecoder);
|
|
3852
3950
|
|
|
3951
|
+
var SpecularMode;
|
|
3952
|
+
(function(SpecularMode) {
|
|
3953
|
+
SpecularMode["Sky"] = "Sky";
|
|
3954
|
+
SpecularMode["Custom"] = "Custom";
|
|
3955
|
+
})(SpecularMode || (SpecularMode = {}));
|
|
3956
|
+
|
|
3853
3957
|
var SceneParserContext = /*#__PURE__*/ function() {
|
|
3854
3958
|
function SceneParserContext(originalData, scene) {
|
|
3855
3959
|
this.originalData = originalData;
|
|
@@ -3977,7 +4081,7 @@ var MeshLoader$1 = /*#__PURE__*/ function(Loader) {
|
|
|
3977
4081
|
decode(data, resourceManager.engine).then(function(mesh) {
|
|
3978
4082
|
resolve(mesh);
|
|
3979
4083
|
});
|
|
3980
|
-
});
|
|
4084
|
+
}).catch(reject);
|
|
3981
4085
|
});
|
|
3982
4086
|
};
|
|
3983
4087
|
return MeshLoader;
|
|
@@ -3996,14 +4100,14 @@ var EditorTextureLoader = /*#__PURE__*/ function(Loader) {
|
|
|
3996
4100
|
var _proto = EditorTextureLoader.prototype;
|
|
3997
4101
|
_proto.load = function load(item, resourceManager) {
|
|
3998
4102
|
var _this = this;
|
|
3999
|
-
return new AssetPromise(function(resolve) {
|
|
4103
|
+
return new AssetPromise(function(resolve, reject) {
|
|
4000
4104
|
_this.request(item.url, {
|
|
4001
4105
|
type: "arraybuffer"
|
|
4002
4106
|
}).then(function(data) {
|
|
4003
4107
|
decode(data, resourceManager.engine).then(function(texture) {
|
|
4004
4108
|
resolve(texture);
|
|
4005
4109
|
});
|
|
4006
|
-
});
|
|
4110
|
+
}).catch(reject);
|
|
4007
4111
|
});
|
|
4008
4112
|
};
|
|
4009
4113
|
return EditorTextureLoader;
|
|
@@ -4380,7 +4484,7 @@ var AnimationClipLoader = /*#__PURE__*/ function(Loader) {
|
|
|
4380
4484
|
_this.request(item.url, _extends({}, item, {
|
|
4381
4485
|
type: "arraybuffer"
|
|
4382
4486
|
})).then(function(data) {
|
|
4383
|
-
return decode(data, resourceManager.engine);
|
|
4487
|
+
return decode(data, resourceManager.engine).then(resolve);
|
|
4384
4488
|
}).catch(reject);
|
|
4385
4489
|
});
|
|
4386
4490
|
};
|
|
@@ -4408,16 +4512,32 @@ var SceneLoader = /*#__PURE__*/ function(Loader) {
|
|
|
4408
4512
|
// @ts-ignore
|
|
4409
4513
|
engine.resourceManager.initVirtualResources(data.files);
|
|
4410
4514
|
return SceneParser.parse(engine, data).then(function(scene) {
|
|
4515
|
+
var promises = [];
|
|
4411
4516
|
// parse ambient light
|
|
4412
4517
|
var ambient = data.scene.ambient;
|
|
4413
|
-
var
|
|
4414
|
-
if (ambient.
|
|
4415
|
-
|
|
4416
|
-
|
|
4417
|
-
|
|
4518
|
+
var useCustomAmbient = ambient.specularMode === "Custom";
|
|
4519
|
+
if (useCustomAmbient && ambient.customAmbientLight) {
|
|
4520
|
+
// @ts-ignore
|
|
4521
|
+
// prettier-ignore
|
|
4522
|
+
var customAmbientPromise = resourceManager.getResourceByRef(ambient.customAmbientLight).then(function(ambientLight) {
|
|
4523
|
+
scene.ambientLight = ambientLight;
|
|
4524
|
+
scene.ambientLight.diffuseIntensity = ambient.diffuseIntensity;
|
|
4525
|
+
scene.ambientLight.specularIntensity = ambient.specularIntensity;
|
|
4526
|
+
scene.ambientLight.diffuseMode = ambient.diffuseMode;
|
|
4527
|
+
scene.ambientLight.diffuseSolidColor.copyFrom(ambient.diffuseSolidColor);
|
|
4528
|
+
});
|
|
4529
|
+
promises.push(customAmbientPromise);
|
|
4530
|
+
} else if (!useCustomAmbient && ambient.ambientLight) {
|
|
4531
|
+
// @ts-ignore
|
|
4532
|
+
// prettier-ignore
|
|
4533
|
+
var ambientLightPromise = resourceManager.getResourceByRef(ambient.ambientLight).then(function(ambientLight) {
|
|
4534
|
+
scene.ambientLight = ambientLight;
|
|
4418
4535
|
scene.ambientLight.diffuseIntensity = ambient.diffuseIntensity;
|
|
4419
4536
|
scene.ambientLight.specularIntensity = ambient.specularIntensity;
|
|
4537
|
+
scene.ambientLight.diffuseMode = ambient.diffuseMode;
|
|
4538
|
+
scene.ambientLight.diffuseSolidColor.copyFrom(ambient.diffuseSolidColor);
|
|
4420
4539
|
});
|
|
4540
|
+
promises.push(ambientLightPromise);
|
|
4421
4541
|
} else {
|
|
4422
4542
|
scene.ambientLight.diffuseIntensity = ambient.diffuseIntensity;
|
|
4423
4543
|
scene.ambientLight.specularIntensity = ambient.specularIntensity;
|
|
@@ -4425,30 +4545,34 @@ var SceneLoader = /*#__PURE__*/ function(Loader) {
|
|
|
4425
4545
|
}
|
|
4426
4546
|
var background = data.scene.background;
|
|
4427
4547
|
scene.background.mode = background.mode;
|
|
4428
|
-
var backgroundPromise = Promise.resolve();
|
|
4429
4548
|
switch(scene.background.mode){
|
|
4430
4549
|
case BackgroundMode.SolidColor:
|
|
4431
4550
|
scene.background.solidColor.copyFrom(background.color);
|
|
4432
4551
|
break;
|
|
4433
4552
|
case BackgroundMode.Sky:
|
|
4434
|
-
if (background.
|
|
4553
|
+
if (background.skyMesh && background.skyMaterial) {
|
|
4554
|
+
// @ts-ignore
|
|
4555
|
+
var skyMeshPromise = resourceManager.getResourceByRef(background.skyMesh).then(function(mesh) {
|
|
4556
|
+
scene.background.sky.mesh = mesh;
|
|
4557
|
+
});
|
|
4435
4558
|
// @ts-ignore
|
|
4436
|
-
|
|
4437
|
-
|
|
4438
|
-
|
|
4439
|
-
skyMaterial.texture = light.specularTexture;
|
|
4440
|
-
skyMaterial.textureDecodeRGBM = true;
|
|
4441
|
-
sky.material = skyMaterial;
|
|
4442
|
-
sky.mesh = PrimitiveMesh.createCuboid(engine, 1, 1, 1);
|
|
4559
|
+
// prettier-ignore
|
|
4560
|
+
var skyMaterialPromise = resourceManager.getResourceByRef(background.skyMaterial).then(function(material) {
|
|
4561
|
+
scene.background.sky.material = material;
|
|
4443
4562
|
});
|
|
4563
|
+
promises.push(skyMeshPromise, skyMaterialPromise);
|
|
4564
|
+
} else {
|
|
4565
|
+
Logger.warn("Sky background mode requires skyMesh and skyMaterial");
|
|
4444
4566
|
}
|
|
4445
4567
|
break;
|
|
4446
4568
|
case BackgroundMode.Texture:
|
|
4447
4569
|
if (background.texture) {
|
|
4448
4570
|
// @ts-ignore
|
|
4449
|
-
|
|
4571
|
+
// prettier-ignore
|
|
4572
|
+
var backgroundPromise = resourceManager.getResourceByRef(background.texture).then(function(texture) {
|
|
4450
4573
|
scene.background.texture = texture;
|
|
4451
4574
|
});
|
|
4575
|
+
promises.push(backgroundPromise);
|
|
4452
4576
|
}
|
|
4453
4577
|
break;
|
|
4454
4578
|
}
|
|
@@ -4460,10 +4584,7 @@ var SceneLoader = /*#__PURE__*/ function(Loader) {
|
|
|
4460
4584
|
if (shadow.shadowDistance != undefined) scene.shadowDistance = shadow.shadowDistance;
|
|
4461
4585
|
if (shadow.shadowCascades != undefined) scene.shadowCascades = shadow.shadowCascades;
|
|
4462
4586
|
}
|
|
4463
|
-
return Promise.all(
|
|
4464
|
-
ambientLightPromise,
|
|
4465
|
-
backgroundPromise
|
|
4466
|
-
]).then(function() {
|
|
4587
|
+
return Promise.all(promises).then(function() {
|
|
4467
4588
|
resolve(scene);
|
|
4468
4589
|
});
|
|
4469
4590
|
});
|
|
@@ -4506,7 +4627,7 @@ var KHR_draco_mesh_compression = (_KHR_draco_mesh_compression = /*#__PURE__*/ fu
|
|
|
4506
4627
|
};
|
|
4507
4628
|
_proto.createAndParse = function createAndParse(context, schema, glTFPrimitive, glTFMesh) {
|
|
4508
4629
|
var _this = this;
|
|
4509
|
-
var glTF = context.glTF,
|
|
4630
|
+
var glTF = context.glTF, engine = context.glTFResource.engine;
|
|
4510
4631
|
var bufferViews = glTF.bufferViews, accessors = glTF.accessors;
|
|
4511
4632
|
var bufferViewIndex = schema.bufferView, gltfAttributeMap = schema.attributes;
|
|
4512
4633
|
var attributeMap = {};
|
|
@@ -4528,21 +4649,23 @@ var KHR_draco_mesh_compression = (_KHR_draco_mesh_compression = /*#__PURE__*/ fu
|
|
|
4528
4649
|
useUniqueIDs: true,
|
|
4529
4650
|
indexType: indexType
|
|
4530
4651
|
};
|
|
4531
|
-
|
|
4532
|
-
|
|
4533
|
-
|
|
4534
|
-
|
|
4535
|
-
|
|
4536
|
-
|
|
4537
|
-
|
|
4652
|
+
return context.getBuffers().then(function(buffers) {
|
|
4653
|
+
var buffer = GLTFUtils.getBufferViewData(bufferViews[bufferViewIndex], buffers);
|
|
4654
|
+
return KHR_draco_mesh_compression._decoder.decode(buffer, taskConfig).then(function(decodedGeometry) {
|
|
4655
|
+
var mesh = new ModelMesh(engine, glTFMesh.name);
|
|
4656
|
+
return _this._parseMeshFromGLTFPrimitiveDraco(mesh, glTFMesh, glTFPrimitive, glTF, function(attributeSemantic) {
|
|
4657
|
+
for(var j = 0; j < decodedGeometry.attributes.length; j++){
|
|
4658
|
+
if (decodedGeometry.attributes[j].name === attributeSemantic) {
|
|
4659
|
+
return decodedGeometry.attributes[j].array;
|
|
4660
|
+
}
|
|
4538
4661
|
}
|
|
4539
|
-
|
|
4540
|
-
|
|
4541
|
-
|
|
4542
|
-
|
|
4543
|
-
|
|
4544
|
-
|
|
4545
|
-
}
|
|
4662
|
+
return null;
|
|
4663
|
+
}, function(attributeSemantic, shapeIndex) {
|
|
4664
|
+
throw "BlendShape animation is not supported when using draco.";
|
|
4665
|
+
}, function() {
|
|
4666
|
+
return decodedGeometry.index.array;
|
|
4667
|
+
}, context.keepMeshData);
|
|
4668
|
+
});
|
|
4546
4669
|
});
|
|
4547
4670
|
};
|
|
4548
4671
|
_proto._parseMeshFromGLTFPrimitiveDraco = function _parseMeshFromGLTFPrimitiveDraco(mesh, gltfMesh, gltfPrimitive, gltf, getVertexBufferData, getBlendShapeData, getIndexBufferData, keepMeshData) {
|
|
@@ -4641,7 +4764,7 @@ var KHR_draco_mesh_compression = (_KHR_draco_mesh_compression = /*#__PURE__*/ fu
|
|
|
4641
4764
|
mesh.addSubMesh(0, vertexCount, mode);
|
|
4642
4765
|
}
|
|
4643
4766
|
// BlendShapes
|
|
4644
|
-
targets && GLTFMeshParser._createBlendShape(mesh, null, gltfMesh, targets, getBlendShapeData);
|
|
4767
|
+
targets && GLTFMeshParser._createBlendShape(mesh, null, gltfMesh, accessors, targets, getBlendShapeData);
|
|
4645
4768
|
mesh.uploadData(!keepMeshData);
|
|
4646
4769
|
return Promise.resolve(mesh);
|
|
4647
4770
|
};
|
|
@@ -4875,5 +4998,5 @@ GALACEAN_animation_event = __decorate([
|
|
|
4875
4998
|
registerGLTFExtension("GALACEAN_animation_event", GLTFExtensionMode.AdditiveParse)
|
|
4876
4999
|
], GALACEAN_animation_event);
|
|
4877
5000
|
|
|
4878
|
-
export { AnimationClipDecoder, ComponentMap, EditorTextureLoader, GLTFAnimationParser, GLTFBufferParser, GLTFEntityParser, GLTFExtensionMode, GLTFExtensionParser, GLTFMaterialParser, GLTFMeshParser, GLTFParser, GLTFParserContext, GLTFPipeline, GLTFResource, GLTFSceneParser, GLTFSkinParser, GLTFTextureParser, GLTFUtils, GLTFValidator, InterpolableValueType, MeshDecoder, MeshLoader$1 as MeshLoader, PrefabParser, ReflectionParser, SceneParser, Texture2DDecoder, decode, parseSingleKTX, registerGLTFExtension };
|
|
5001
|
+
export { AnimationClipDecoder, ComponentMap, EditorTextureLoader, GLTFAnimationParser, GLTFBufferParser, GLTFEntityParser, GLTFExtensionMode, GLTFExtensionParser, GLTFMaterialParser, GLTFMeshParser, GLTFParser, GLTFParserContext, GLTFPipeline, GLTFResource, GLTFSceneParser, GLTFSkinParser, GLTFTextureParser, GLTFUtils, GLTFValidator, InterpolableValueType, MeshDecoder, MeshLoader$1 as MeshLoader, PrefabParser, ReflectionParser, SceneParser, SpecularMode, Texture2DDecoder, decode, parseSingleKTX, registerGLTFExtension };
|
|
4879
5002
|
//# sourceMappingURL=module.js.map
|