@galacean/engine 1.0.0-beta.16 → 1.0.0-beta.17
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/browser.js +411 -339
- package/dist/browser.min.js +1 -1
- package/dist/main.js +1 -1
- package/dist/miniprogram.js +1 -1
- package/dist/module.js +1 -1
- package/package.json +5 -5
package/dist/browser.js
CHANGED
|
@@ -9628,6 +9628,7 @@
|
|
|
9628
9628
|
cloneEntity._hookResource = hookResource;
|
|
9629
9629
|
hookResource._addReferCount(1);
|
|
9630
9630
|
}
|
|
9631
|
+
cloneEntity.layer = this.layer;
|
|
9631
9632
|
cloneEntity._isActive = this._isActive;
|
|
9632
9633
|
cloneEntity.transform.localMatrix = this.transform.localMatrix;
|
|
9633
9634
|
var children = this._children;
|
|
@@ -33731,7 +33732,8 @@
|
|
|
33731
33732
|
state.wrapMode = wrapMode;
|
|
33732
33733
|
state.clipStartTime = clipStartNormalizedTime;
|
|
33733
33734
|
state.clipEndTime = clipEndNormalizedTime;
|
|
33734
|
-
|
|
33735
|
+
var scriptsObject = JSON.parse(scripts);
|
|
33736
|
+
scriptsObject == null ? void 0 : scriptsObject.forEach(function(script) {
|
|
33735
33737
|
state.addStateMachineScript(Loader.getClass(script));
|
|
33736
33738
|
});
|
|
33737
33739
|
if (clipData) {
|
|
@@ -34297,6 +34299,11 @@
|
|
|
34297
34299
|
promiseMap["" + url] = this._initPromiseInfo(this.masterPromiseInfo);
|
|
34298
34300
|
};
|
|
34299
34301
|
var _proto = GLTFParserContext.prototype;
|
|
34302
|
+
/**
|
|
34303
|
+
* Get all the buffer data.
|
|
34304
|
+
*/ _proto.getBuffers = function getBuffers() {
|
|
34305
|
+
return Promise.resolve(this._buffers);
|
|
34306
|
+
};
|
|
34300
34307
|
_proto._initPromiseInfo = function _initPromiseInfo(promiseInfo) {
|
|
34301
34308
|
var promise = new AssetPromise(function(resolve, reject, setProgress, onCancel) {
|
|
34302
34309
|
promiseInfo.resolve = resolve;
|
|
@@ -34416,44 +34423,45 @@
|
|
|
34416
34423
|
}
|
|
34417
34424
|
};
|
|
34418
34425
|
GLTFUtils.getAccessorBuffer = function getAccessorBuffer(context, bufferViews, accessor) {
|
|
34419
|
-
var buffers = context.buffers;
|
|
34420
34426
|
var componentType = accessor.componentType;
|
|
34421
34427
|
var bufferView = bufferViews[accessor.bufferView];
|
|
34422
|
-
|
|
34423
|
-
|
|
34424
|
-
|
|
34425
|
-
|
|
34426
|
-
|
|
34427
|
-
|
|
34428
|
-
|
|
34429
|
-
|
|
34430
|
-
|
|
34431
|
-
|
|
34432
|
-
|
|
34433
|
-
|
|
34434
|
-
|
|
34435
|
-
|
|
34436
|
-
|
|
34437
|
-
|
|
34438
|
-
|
|
34439
|
-
|
|
34440
|
-
|
|
34441
|
-
|
|
34442
|
-
|
|
34443
|
-
|
|
34444
|
-
|
|
34428
|
+
return context.getBuffers().then(function(buffers) {
|
|
34429
|
+
var bufferIndex = bufferView.buffer;
|
|
34430
|
+
var buffer = buffers[bufferIndex];
|
|
34431
|
+
var bufferByteOffset = bufferView.byteOffset || 0;
|
|
34432
|
+
var byteOffset = accessor.byteOffset || 0;
|
|
34433
|
+
var TypedArray = GLTFUtils.getComponentType(componentType);
|
|
34434
|
+
var dataElementSize = GLTFUtils.getAccessorTypeSize(accessor.type);
|
|
34435
|
+
var dataElementBytes = TypedArray.BYTES_PER_ELEMENT;
|
|
34436
|
+
var elementStride = dataElementSize * dataElementBytes;
|
|
34437
|
+
var accessorCount = accessor.count;
|
|
34438
|
+
var bufferStride = bufferView.byteStride;
|
|
34439
|
+
var bufferInfo;
|
|
34440
|
+
// According to the glTF official documentation only byteStride not undefined is allowed
|
|
34441
|
+
if (bufferStride !== undefined && bufferStride !== elementStride) {
|
|
34442
|
+
var bufferSlice = Math.floor(byteOffset / bufferStride);
|
|
34443
|
+
var bufferCacheKey = accessor.bufferView + ":" + componentType + ":" + bufferSlice + ":" + accessorCount;
|
|
34444
|
+
var accessorBufferCache = context.accessorBufferCache;
|
|
34445
|
+
bufferInfo = accessorBufferCache[bufferCacheKey];
|
|
34446
|
+
if (!bufferInfo) {
|
|
34447
|
+
var offset = bufferByteOffset + bufferSlice * bufferStride;
|
|
34448
|
+
var count = accessorCount * (bufferStride / dataElementBytes);
|
|
34449
|
+
var data = new TypedArray(buffer, offset, count);
|
|
34450
|
+
accessorBufferCache[bufferCacheKey] = bufferInfo = new BufferInfo(data, true, bufferStride);
|
|
34451
|
+
bufferInfo.restoreInfo = new BufferDataRestoreInfo(new RestoreDataAccessor(bufferIndex, TypedArray, offset, count));
|
|
34452
|
+
}
|
|
34453
|
+
} else {
|
|
34454
|
+
var offset1 = bufferByteOffset + byteOffset;
|
|
34455
|
+
var count1 = accessorCount * dataElementSize;
|
|
34456
|
+
var data1 = new TypedArray(buffer, offset1, count1);
|
|
34457
|
+
bufferInfo = new BufferInfo(data1, false, elementStride);
|
|
34458
|
+
bufferInfo.restoreInfo = new BufferDataRestoreInfo(new RestoreDataAccessor(bufferIndex, TypedArray, offset1, count1));
|
|
34445
34459
|
}
|
|
34446
|
-
|
|
34447
|
-
|
|
34448
|
-
|
|
34449
|
-
|
|
34450
|
-
|
|
34451
|
-
bufferInfo.restoreInfo = new BufferDataRestoreInfo(new RestoreDataAccessor(bufferIndex, TypedArray, offset1, count1));
|
|
34452
|
-
}
|
|
34453
|
-
if (accessor.sparse) {
|
|
34454
|
-
GLTFUtils.processingSparseData(bufferViews, accessor, buffers, bufferInfo);
|
|
34455
|
-
}
|
|
34456
|
-
return bufferInfo;
|
|
34460
|
+
if (accessor.sparse) {
|
|
34461
|
+
GLTFUtils.processingSparseData(bufferViews, accessor, buffers, bufferInfo);
|
|
34462
|
+
}
|
|
34463
|
+
return bufferInfo;
|
|
34464
|
+
});
|
|
34457
34465
|
};
|
|
34458
34466
|
/**
|
|
34459
34467
|
* @deprecated
|
|
@@ -34912,9 +34920,7 @@
|
|
|
34912
34920
|
_inherits(GLTFAnimationParser, GLTFParser1);
|
|
34913
34921
|
var _proto = GLTFAnimationParser.prototype;
|
|
34914
34922
|
_proto.parse = function parse(context) {
|
|
34915
|
-
var glTF = context.glTF;
|
|
34916
|
-
context.buffers;
|
|
34917
|
-
var glTFResource = context.glTFResource;
|
|
34923
|
+
var glTF = context.glTF, glTFResource = context.glTFResource;
|
|
34918
34924
|
glTFResource.entities;
|
|
34919
34925
|
var animations = glTF.animations;
|
|
34920
34926
|
glTF.accessors;
|
|
@@ -34926,106 +34932,120 @@
|
|
|
34926
34932
|
var animationClipCount = animations.length;
|
|
34927
34933
|
var animationClipPromises = [];
|
|
34928
34934
|
new Array(animationClipCount);
|
|
34935
|
+
var parseStandardPropertyPromises = new Array();
|
|
34929
34936
|
for(var i = 0; i < animationClipCount; i++){
|
|
34930
34937
|
var animationInfo = animations[i];
|
|
34931
34938
|
var _animationInfo_name = animationInfo.name, name = _animationInfo_name === void 0 ? "AnimationClip" + i : _animationInfo_name;
|
|
34932
34939
|
var animationClip = GLTFParser.executeExtensionsCreateAndParse(animationInfo.extensions, context, animationInfo);
|
|
34933
34940
|
if (!animationClip) {
|
|
34934
34941
|
animationClip = new AnimationClip(name);
|
|
34935
|
-
GLTFAnimationParser._parseStandardProperty(context, animationClip, animationInfo);
|
|
34942
|
+
parseStandardPropertyPromises.push(GLTFAnimationParser._parseStandardProperty(context, animationClip, animationInfo));
|
|
34936
34943
|
}
|
|
34937
34944
|
animationClipPromises.push(animationClip);
|
|
34938
34945
|
}
|
|
34939
|
-
return AssetPromise.all(
|
|
34940
|
-
|
|
34941
|
-
|
|
34942
|
-
var
|
|
34943
|
-
|
|
34944
|
-
|
|
34945
|
-
|
|
34946
|
-
|
|
34946
|
+
return AssetPromise.all(parseStandardPropertyPromises).then(function() {
|
|
34947
|
+
return AssetPromise.all(animationClipPromises).then(function(animationClips) {
|
|
34948
|
+
glTFResource.animations = animationClips;
|
|
34949
|
+
for(var i = 0; i < glTF.animations.length; i++){
|
|
34950
|
+
var animationInfo = glTF.animations[i];
|
|
34951
|
+
GLTFParser.executeExtensionsAdditiveAndParse(animationInfo.extensions, context, animationClips[i], animationInfo);
|
|
34952
|
+
}
|
|
34953
|
+
animationClipsPromiseInfo.resolve(animationClips);
|
|
34954
|
+
return animationClipsPromiseInfo.promise;
|
|
34955
|
+
});
|
|
34947
34956
|
});
|
|
34948
34957
|
};
|
|
34949
34958
|
/**
|
|
34950
34959
|
* @internal
|
|
34951
34960
|
*/ GLTFAnimationParser._parseStandardProperty = function _parseStandardProperty(context, animationClip, animationInfo) {
|
|
34961
|
+
var _loop = function _loop(j, m) {
|
|
34962
|
+
var gltfSampler = samplers[j];
|
|
34963
|
+
var inputAccessor = accessors[gltfSampler.input];
|
|
34964
|
+
var outputAccessor = accessors[gltfSampler.output];
|
|
34965
|
+
var promise = Promise.all([
|
|
34966
|
+
GLTFUtils.getAccessorBuffer(context, bufferViews, inputAccessor),
|
|
34967
|
+
GLTFUtils.getAccessorBuffer(context, bufferViews, outputAccessor)
|
|
34968
|
+
]).then(function(bufferInfos) {
|
|
34969
|
+
var input = bufferInfos[0].data;
|
|
34970
|
+
var output = bufferInfos[1].data;
|
|
34971
|
+
if (outputAccessor.normalized) {
|
|
34972
|
+
var scale = GLTFUtils.getNormalizedComponentScale(outputAccessor.componentType);
|
|
34973
|
+
var scaled = new Float32Array(output.length);
|
|
34974
|
+
for(var k = 0, v = output.length; k < v; k++){
|
|
34975
|
+
scaled[k] = output[k] * scale;
|
|
34976
|
+
}
|
|
34977
|
+
output = scaled;
|
|
34978
|
+
}
|
|
34979
|
+
var outputStride = output.length / input.length;
|
|
34980
|
+
var _gltfSampler_interpolation;
|
|
34981
|
+
var interpolation = (_gltfSampler_interpolation = gltfSampler.interpolation) != null ? _gltfSampler_interpolation : AnimationSamplerInterpolation.Linear;
|
|
34982
|
+
var samplerInterpolation;
|
|
34983
|
+
switch(interpolation){
|
|
34984
|
+
case AnimationSamplerInterpolation.CubicSpine:
|
|
34985
|
+
samplerInterpolation = exports.InterpolationType.CubicSpine;
|
|
34986
|
+
break;
|
|
34987
|
+
case AnimationSamplerInterpolation.Step:
|
|
34988
|
+
samplerInterpolation = exports.InterpolationType.Step;
|
|
34989
|
+
break;
|
|
34990
|
+
case AnimationSamplerInterpolation.Linear:
|
|
34991
|
+
samplerInterpolation = exports.InterpolationType.Linear;
|
|
34992
|
+
break;
|
|
34993
|
+
}
|
|
34994
|
+
input[input.length - 1];
|
|
34995
|
+
sampleDataCollection.push({
|
|
34996
|
+
type: outputAccessor.type,
|
|
34997
|
+
interpolation: samplerInterpolation,
|
|
34998
|
+
input: input,
|
|
34999
|
+
output: output,
|
|
35000
|
+
outputSize: outputStride
|
|
35001
|
+
});
|
|
35002
|
+
});
|
|
35003
|
+
promises.push(promise);
|
|
35004
|
+
};
|
|
35005
|
+
var _this = this;
|
|
34952
35006
|
var glTF = context.glTF, glTFResource = context.glTFResource;
|
|
34953
35007
|
var entities = glTFResource.entities;
|
|
34954
35008
|
var accessors = glTF.accessors, bufferViews = glTF.bufferViews;
|
|
34955
35009
|
var channels = animationInfo.channels, samplers = animationInfo.samplers;
|
|
34956
35010
|
var sampleDataCollection = new Array();
|
|
35011
|
+
var promises = new Array();
|
|
34957
35012
|
// parse samplers
|
|
34958
|
-
for(var j = 0, m = samplers.length; j < m; j++)
|
|
34959
|
-
|
|
34960
|
-
var
|
|
34961
|
-
|
|
34962
|
-
|
|
34963
|
-
|
|
34964
|
-
|
|
34965
|
-
var
|
|
34966
|
-
|
|
34967
|
-
|
|
34968
|
-
|
|
34969
|
-
}
|
|
34970
|
-
|
|
34971
|
-
|
|
34972
|
-
|
|
34973
|
-
|
|
34974
|
-
|
|
34975
|
-
|
|
34976
|
-
|
|
34977
|
-
|
|
34978
|
-
|
|
34979
|
-
|
|
34980
|
-
|
|
34981
|
-
|
|
34982
|
-
|
|
34983
|
-
|
|
34984
|
-
|
|
34985
|
-
|
|
34986
|
-
|
|
34987
|
-
|
|
34988
|
-
|
|
34989
|
-
|
|
34990
|
-
|
|
34991
|
-
|
|
34992
|
-
output: output,
|
|
34993
|
-
outputSize: outputStride
|
|
34994
|
-
});
|
|
34995
|
-
}
|
|
34996
|
-
for(var j1 = 0, m1 = channels.length; j1 < m1; j1++){
|
|
34997
|
-
var gltfChannel = channels[j1];
|
|
34998
|
-
var target = gltfChannel.target;
|
|
34999
|
-
var channelTargetEntity = entities[target.node];
|
|
35000
|
-
var relativePath = "";
|
|
35001
|
-
var entity = channelTargetEntity;
|
|
35002
|
-
while(entity.parent){
|
|
35003
|
-
relativePath = relativePath === "" ? "" + entity.name : entity.name + "/" + relativePath;
|
|
35004
|
-
entity = entity.parent;
|
|
35005
|
-
}
|
|
35006
|
-
var ComponentType = void 0;
|
|
35007
|
-
var propertyName = void 0;
|
|
35008
|
-
switch(target.path){
|
|
35009
|
-
case AnimationChannelTargetPath.TRANSLATION:
|
|
35010
|
-
ComponentType = Transform;
|
|
35011
|
-
propertyName = "position";
|
|
35012
|
-
break;
|
|
35013
|
-
case AnimationChannelTargetPath.ROTATION:
|
|
35014
|
-
ComponentType = Transform;
|
|
35015
|
-
propertyName = "rotationQuaternion";
|
|
35016
|
-
break;
|
|
35017
|
-
case AnimationChannelTargetPath.SCALE:
|
|
35018
|
-
ComponentType = Transform;
|
|
35019
|
-
propertyName = "scale";
|
|
35020
|
-
break;
|
|
35021
|
-
case AnimationChannelTargetPath.WEIGHTS:
|
|
35022
|
-
ComponentType = SkinnedMeshRenderer;
|
|
35023
|
-
propertyName = "blendShapeWeights";
|
|
35024
|
-
break;
|
|
35013
|
+
for(var j = 0, m = samplers.length; j < m; j++)_loop(j);
|
|
35014
|
+
return Promise.all(promises).then(function() {
|
|
35015
|
+
for(var j = 0, m = channels.length; j < m; j++){
|
|
35016
|
+
var gltfChannel = channels[j];
|
|
35017
|
+
var target = gltfChannel.target;
|
|
35018
|
+
var channelTargetEntity = entities[target.node];
|
|
35019
|
+
var relativePath = "";
|
|
35020
|
+
var entity = channelTargetEntity;
|
|
35021
|
+
while(entity.parent){
|
|
35022
|
+
relativePath = relativePath === "" ? "" + entity.name : entity.name + "/" + relativePath;
|
|
35023
|
+
entity = entity.parent;
|
|
35024
|
+
}
|
|
35025
|
+
var ComponentType = void 0;
|
|
35026
|
+
var propertyName = void 0;
|
|
35027
|
+
switch(target.path){
|
|
35028
|
+
case AnimationChannelTargetPath.TRANSLATION:
|
|
35029
|
+
ComponentType = Transform;
|
|
35030
|
+
propertyName = "position";
|
|
35031
|
+
break;
|
|
35032
|
+
case AnimationChannelTargetPath.ROTATION:
|
|
35033
|
+
ComponentType = Transform;
|
|
35034
|
+
propertyName = "rotationQuaternion";
|
|
35035
|
+
break;
|
|
35036
|
+
case AnimationChannelTargetPath.SCALE:
|
|
35037
|
+
ComponentType = Transform;
|
|
35038
|
+
propertyName = "scale";
|
|
35039
|
+
break;
|
|
35040
|
+
case AnimationChannelTargetPath.WEIGHTS:
|
|
35041
|
+
ComponentType = SkinnedMeshRenderer;
|
|
35042
|
+
propertyName = "blendShapeWeights";
|
|
35043
|
+
break;
|
|
35044
|
+
}
|
|
35045
|
+
var curve = _this._addCurve(target.path, gltfChannel, sampleDataCollection);
|
|
35046
|
+
animationClip.addCurveBinding(relativePath, ComponentType, propertyName, curve);
|
|
35025
35047
|
}
|
|
35026
|
-
|
|
35027
|
-
animationClip.addCurveBinding(relativePath, ComponentType, propertyName, curve);
|
|
35028
|
-
}
|
|
35048
|
+
});
|
|
35029
35049
|
};
|
|
35030
35050
|
GLTFAnimationParser._addCurve = function _addCurve(animationChannelTargetPath, gltfChannel, sampleDataCollection) {
|
|
35031
35051
|
var sampleData = sampleDataCollection[gltfChannel.sampler];
|
|
@@ -35119,20 +35139,18 @@
|
|
|
35119
35139
|
}).then(function(param) {
|
|
35120
35140
|
var glTF = param.glTF, buffers = param.buffers;
|
|
35121
35141
|
context.glTF = glTF;
|
|
35122
|
-
context.
|
|
35142
|
+
context._buffers = buffers;
|
|
35123
35143
|
});
|
|
35124
35144
|
} else {
|
|
35125
35145
|
return request(url, {
|
|
35126
35146
|
type: "json"
|
|
35127
35147
|
}).then(function(glTF) {
|
|
35128
35148
|
context.glTF = glTF;
|
|
35129
|
-
|
|
35149
|
+
context._buffers = Promise.all(glTF.buffers.map(function(buffer) {
|
|
35130
35150
|
var absoluteUrl = Utils.resolveAbsoluteUrl(url, buffer.uri);
|
|
35131
35151
|
restoreBufferRequests.push(new BufferRequestInfo(absoluteUrl, requestConfig));
|
|
35132
35152
|
return request(absoluteUrl, requestConfig);
|
|
35133
|
-
}))
|
|
35134
|
-
context.buffers = buffers;
|
|
35135
|
-
});
|
|
35153
|
+
}));
|
|
35136
35154
|
});
|
|
35137
35155
|
}
|
|
35138
35156
|
};
|
|
@@ -35377,7 +35395,9 @@
|
|
|
35377
35395
|
}
|
|
35378
35396
|
}, function() {
|
|
35379
35397
|
var indexAccessor = glTF.accessors[gltfPrimitive.indices];
|
|
35380
|
-
return
|
|
35398
|
+
return context.getBuffers().then(function(buffers) {
|
|
35399
|
+
return GLTFUtils.getAccessorData(glTF, indexAccessor, buffers);
|
|
35400
|
+
});
|
|
35381
35401
|
}, context.keepMeshData).then(resolve);
|
|
35382
35402
|
}
|
|
35383
35403
|
});
|
|
@@ -35387,7 +35407,7 @@
|
|
|
35387
35407
|
for(var j = 0; j < gltfMesh.primitives.length; j++)_loop(j);
|
|
35388
35408
|
meshPromises[i] = Promise.all(primitivePromises);
|
|
35389
35409
|
};
|
|
35390
|
-
var glTF = context.glTF,
|
|
35410
|
+
var glTF = context.glTF, glTFResource = context.glTFResource;
|
|
35391
35411
|
var engine = glTFResource.engine;
|
|
35392
35412
|
if (!glTF.meshes) return;
|
|
35393
35413
|
var meshesPromiseInfo = context.meshesPromiseInfo;
|
|
@@ -35402,8 +35422,109 @@
|
|
|
35402
35422
|
/**
|
|
35403
35423
|
* @internal
|
|
35404
35424
|
*/ GLTFMeshParser._parseMeshFromGLTFPrimitive = function _parseMeshFromGLTFPrimitive(context, mesh, meshRestoreInfo, gltfMesh, gltfPrimitive, gltf, getVertexBufferData, getBlendShapeData, getIndexBufferData, keepMeshData) {
|
|
35425
|
+
var _loop = function _loop(attribute) {
|
|
35426
|
+
var accessor = accessors[attributes[attribute]];
|
|
35427
|
+
var promise = GLTFUtils.getAccessorBuffer(context, gltf.bufferViews, accessor).then(function(accessorBuffer) {
|
|
35428
|
+
var dataElementSize = GLTFUtils.getAccessorTypeSize(accessor.type);
|
|
35429
|
+
var accessorCount = accessor.count;
|
|
35430
|
+
var vertices = accessorBuffer.data;
|
|
35431
|
+
var vertexElement;
|
|
35432
|
+
var meshId = mesh.instanceId;
|
|
35433
|
+
var vertexBindingInfos = accessorBuffer.vertexBindingInfos;
|
|
35434
|
+
var elementNormalized = accessor.normalized;
|
|
35435
|
+
var elementFormat = GLTFUtils.getElementFormat(accessor.componentType, dataElementSize, elementNormalized);
|
|
35436
|
+
var scaleFactor;
|
|
35437
|
+
elementNormalized && (scaleFactor = GLTFUtils.getNormalizedComponentScale(accessor.componentType));
|
|
35438
|
+
var elementOffset;
|
|
35439
|
+
if (accessorBuffer.interleaved) {
|
|
35440
|
+
var byteOffset = accessor.byteOffset || 0;
|
|
35441
|
+
var stride = accessorBuffer.stride;
|
|
35442
|
+
elementOffset = byteOffset % stride;
|
|
35443
|
+
if (vertexBindingInfos[meshId] === undefined) {
|
|
35444
|
+
vertexElement = new VertexElement(attribute, elementOffset, elementFormat, bufferBindIndex);
|
|
35445
|
+
var vertexBuffer = accessorBuffer.vertexBuffer;
|
|
35446
|
+
if (!vertexBuffer) {
|
|
35447
|
+
vertexBuffer = new Buffer(engine, exports.BufferBindFlag.VertexBuffer, vertices.byteLength, exports.BufferUsage.Static);
|
|
35448
|
+
vertexBuffer.setData(vertices);
|
|
35449
|
+
accessorBuffer.vertexBuffer = vertexBuffer;
|
|
35450
|
+
meshRestoreInfo.vertexBuffers.push(new BufferRestoreInfo(vertexBuffer, accessorBuffer.restoreInfo));
|
|
35451
|
+
}
|
|
35452
|
+
mesh.setVertexBufferBinding(vertexBuffer, stride, bufferBindIndex);
|
|
35453
|
+
vertexBindingInfos[meshId] = bufferBindIndex++;
|
|
35454
|
+
} else {
|
|
35455
|
+
vertexElement = new VertexElement(attribute, elementOffset, elementFormat, vertexBindingInfos[meshId]);
|
|
35456
|
+
}
|
|
35457
|
+
} else {
|
|
35458
|
+
elementOffset = 0;
|
|
35459
|
+
vertexElement = new VertexElement(attribute, elementOffset, elementFormat, bufferBindIndex);
|
|
35460
|
+
var vertexBuffer1 = new Buffer(engine, exports.BufferBindFlag.VertexBuffer, vertices.byteLength, exports.BufferUsage.Static);
|
|
35461
|
+
vertexBuffer1.setData(vertices);
|
|
35462
|
+
meshRestoreInfo.vertexBuffers.push(new BufferRestoreInfo(vertexBuffer1, accessorBuffer.restoreInfo));
|
|
35463
|
+
mesh.setVertexBufferBinding(vertexBuffer1, accessorBuffer.stride, bufferBindIndex);
|
|
35464
|
+
vertexBindingInfos[meshId] = bufferBindIndex++;
|
|
35465
|
+
}
|
|
35466
|
+
vertexElements.push(vertexElement);
|
|
35467
|
+
if (attribute === "POSITION") {
|
|
35468
|
+
vertexCount = accessorCount;
|
|
35469
|
+
var _mesh_bounds = mesh.bounds, min = _mesh_bounds.min, max = _mesh_bounds.max;
|
|
35470
|
+
if (accessor.min && accessor.max) {
|
|
35471
|
+
min.copyFromArray(accessor.min);
|
|
35472
|
+
max.copyFromArray(accessor.max);
|
|
35473
|
+
if (keepMeshData) {
|
|
35474
|
+
var baseOffset = elementOffset / vertices.BYTES_PER_ELEMENT;
|
|
35475
|
+
var stride1 = vertices.length / accessorCount;
|
|
35476
|
+
for(var j = 0; j < accessorCount; j++){
|
|
35477
|
+
var offset = baseOffset + j * stride1;
|
|
35478
|
+
var position = new Vector3(vertices[offset], vertices[offset + 1], vertices[offset + 2]);
|
|
35479
|
+
elementNormalized && position.scale(scaleFactor);
|
|
35480
|
+
positions[j] = position;
|
|
35481
|
+
}
|
|
35482
|
+
}
|
|
35483
|
+
} else {
|
|
35484
|
+
var position1 = GLTFMeshParser._tempVector3;
|
|
35485
|
+
min.set(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
|
|
35486
|
+
max.set(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE);
|
|
35487
|
+
var baseOffset1 = elementOffset / vertices.BYTES_PER_ELEMENT;
|
|
35488
|
+
var stride2 = vertices.length / accessorCount;
|
|
35489
|
+
for(var j1 = 0; j1 < accessorCount; j1++){
|
|
35490
|
+
var offset1 = baseOffset1 + j1 * stride2;
|
|
35491
|
+
position1.copyFromArray(vertices, offset1);
|
|
35492
|
+
Vector3.min(min, position1, min);
|
|
35493
|
+
Vector3.max(max, position1, max);
|
|
35494
|
+
if (keepMeshData) {
|
|
35495
|
+
var clonePosition = position1.clone();
|
|
35496
|
+
elementNormalized && clonePosition.scale(scaleFactor);
|
|
35497
|
+
positions[j1] = clonePosition;
|
|
35498
|
+
}
|
|
35499
|
+
}
|
|
35500
|
+
}
|
|
35501
|
+
if (elementNormalized) {
|
|
35502
|
+
min.scale(scaleFactor);
|
|
35503
|
+
max.scale(scaleFactor);
|
|
35504
|
+
}
|
|
35505
|
+
} else if (attribute === "JOINTS_0" && keepMeshData) {
|
|
35506
|
+
var baseOffset2 = elementOffset / vertices.BYTES_PER_ELEMENT;
|
|
35507
|
+
var stride3 = vertices.length / accessorCount;
|
|
35508
|
+
for(var j2 = 0; j2 < accessorCount; j2++){
|
|
35509
|
+
var offset2 = baseOffset2 + j2 * stride3;
|
|
35510
|
+
var boneIndex = new Vector4(vertices[offset2], vertices[offset2 + 1], vertices[offset2 + 2], vertices[offset2 + 3]);
|
|
35511
|
+
elementNormalized && boneIndex.scale(scaleFactor);
|
|
35512
|
+
boneIndices[j2] = boneIndex;
|
|
35513
|
+
}
|
|
35514
|
+
} else if (attribute === "WEIGHTS_0" && keepMeshData) {
|
|
35515
|
+
var baseOffset3 = elementOffset / vertices.BYTES_PER_ELEMENT;
|
|
35516
|
+
var stride4 = vertices.length / accessorCount;
|
|
35517
|
+
for(var j3 = 0; j3 < accessorCount; j3++){
|
|
35518
|
+
var offset3 = baseOffset3 + j3 * stride4;
|
|
35519
|
+
var boneWeight = new Vector4(vertices[offset3], vertices[offset3 + 1], vertices[offset3 + 2], vertices[offset3 + 3]);
|
|
35520
|
+
elementNormalized && boneWeight.scale(scaleFactor);
|
|
35521
|
+
boneWeights[j3] = boneWeight;
|
|
35522
|
+
}
|
|
35523
|
+
}
|
|
35524
|
+
});
|
|
35525
|
+
promises.push(promise);
|
|
35526
|
+
};
|
|
35405
35527
|
var accessors = gltf.accessors;
|
|
35406
|
-
context.buffers;
|
|
35407
35528
|
var attributes = gltfPrimitive.attributes, targets = gltfPrimitive.targets, indices = gltfPrimitive.indices, mode = gltfPrimitive.mode;
|
|
35408
35529
|
var engine = mesh.engine;
|
|
35409
35530
|
var vertexElements = new Array();
|
|
@@ -35417,145 +35538,65 @@
|
|
|
35417
35538
|
boneIndices = new Array(vertexCount);
|
|
35418
35539
|
boneWeights = new Array(vertexCount);
|
|
35419
35540
|
}
|
|
35420
|
-
|
|
35421
|
-
|
|
35422
|
-
|
|
35423
|
-
|
|
35424
|
-
|
|
35425
|
-
|
|
35426
|
-
|
|
35427
|
-
|
|
35428
|
-
|
|
35429
|
-
|
|
35430
|
-
|
|
35431
|
-
|
|
35432
|
-
|
|
35433
|
-
var elementOffset = void 0;
|
|
35434
|
-
if (accessorBuffer.interleaved) {
|
|
35435
|
-
var byteOffset = accessor.byteOffset || 0;
|
|
35436
|
-
var stride = accessorBuffer.stride;
|
|
35437
|
-
elementOffset = byteOffset % stride;
|
|
35438
|
-
if (vertexBindingInfos[meshId] === undefined) {
|
|
35439
|
-
vertexElement = new VertexElement(attribute, elementOffset, elementFormat, bufferBindIndex);
|
|
35440
|
-
var vertexBuffer = accessorBuffer.vertexBuffer;
|
|
35441
|
-
if (!vertexBuffer) {
|
|
35442
|
-
vertexBuffer = new Buffer(engine, exports.BufferBindFlag.VertexBuffer, vertices.byteLength, exports.BufferUsage.Static);
|
|
35443
|
-
vertexBuffer.setData(vertices);
|
|
35444
|
-
accessorBuffer.vertexBuffer = vertexBuffer;
|
|
35445
|
-
meshRestoreInfo.vertexBuffers.push(new BufferRestoreInfo(vertexBuffer, accessorBuffer.restoreInfo));
|
|
35446
|
-
}
|
|
35447
|
-
mesh.setVertexBufferBinding(vertexBuffer, stride, bufferBindIndex);
|
|
35448
|
-
vertexBindingInfos[meshId] = bufferBindIndex++;
|
|
35449
|
-
} else {
|
|
35450
|
-
vertexElement = new VertexElement(attribute, elementOffset, elementFormat, vertexBindingInfos[meshId]);
|
|
35451
|
-
}
|
|
35541
|
+
var promises = new Array();
|
|
35542
|
+
for(var attribute in attributes)_loop(attribute);
|
|
35543
|
+
return Promise.all(promises).then(function() {
|
|
35544
|
+
mesh.setVertexElements(vertexElements);
|
|
35545
|
+
// Indices
|
|
35546
|
+
if (indices !== undefined) {
|
|
35547
|
+
var indexAccessor = gltf.accessors[indices];
|
|
35548
|
+
var promise = GLTFUtils.getAccessorBuffer(context, gltf.bufferViews, indexAccessor).then(function(accessorBuffer) {
|
|
35549
|
+
mesh.setIndices(accessorBuffer.data);
|
|
35550
|
+
mesh.addSubMesh(0, indexAccessor.count, mode);
|
|
35551
|
+
meshRestoreInfo.indexBuffer = accessorBuffer.restoreInfo;
|
|
35552
|
+
});
|
|
35553
|
+
promises.push(promise);
|
|
35452
35554
|
} else {
|
|
35453
|
-
|
|
35454
|
-
|
|
35455
|
-
|
|
35456
|
-
|
|
35457
|
-
|
|
35458
|
-
|
|
35459
|
-
|
|
35460
|
-
|
|
35461
|
-
|
|
35462
|
-
|
|
35463
|
-
|
|
35464
|
-
|
|
35465
|
-
|
|
35466
|
-
|
|
35467
|
-
|
|
35468
|
-
|
|
35469
|
-
|
|
35470
|
-
var stride1 = vertices.length / accessorCount;
|
|
35471
|
-
for(var j = 0; j < accessorCount; j++){
|
|
35472
|
-
var offset = baseOffset + j * stride1;
|
|
35473
|
-
var position = new Vector3(vertices[offset], vertices[offset + 1], vertices[offset + 2]);
|
|
35474
|
-
elementNormalized && position.scale(scaleFactor);
|
|
35475
|
-
positions[j] = position;
|
|
35476
|
-
}
|
|
35477
|
-
}
|
|
35478
|
-
} else {
|
|
35479
|
-
var position1 = GLTFMeshParser._tempVector3;
|
|
35480
|
-
min.set(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
|
|
35481
|
-
max.set(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE);
|
|
35482
|
-
var baseOffset1 = elementOffset / vertices.BYTES_PER_ELEMENT;
|
|
35483
|
-
var stride2 = vertices.length / accessorCount;
|
|
35484
|
-
for(var j1 = 0; j1 < accessorCount; j1++){
|
|
35485
|
-
var offset1 = baseOffset1 + j1 * stride2;
|
|
35486
|
-
position1.copyFromArray(vertices, offset1);
|
|
35487
|
-
Vector3.min(min, position1, min);
|
|
35488
|
-
Vector3.max(max, position1, max);
|
|
35489
|
-
if (keepMeshData) {
|
|
35490
|
-
var clonePosition = position1.clone();
|
|
35491
|
-
elementNormalized && clonePosition.scale(scaleFactor);
|
|
35492
|
-
positions[j1] = clonePosition;
|
|
35493
|
-
}
|
|
35494
|
-
}
|
|
35495
|
-
}
|
|
35496
|
-
if (elementNormalized) {
|
|
35497
|
-
min.scale(scaleFactor);
|
|
35498
|
-
max.scale(scaleFactor);
|
|
35499
|
-
}
|
|
35500
|
-
} else if (attribute === "JOINTS_0" && keepMeshData) {
|
|
35501
|
-
var baseOffset2 = elementOffset / vertices.BYTES_PER_ELEMENT;
|
|
35502
|
-
var stride3 = vertices.length / accessorCount;
|
|
35503
|
-
for(var j2 = 0; j2 < accessorCount; j2++){
|
|
35504
|
-
var offset2 = baseOffset2 + j2 * stride3;
|
|
35505
|
-
var boneIndex = new Vector4(vertices[offset2], vertices[offset2 + 1], vertices[offset2 + 2], vertices[offset2 + 3]);
|
|
35506
|
-
elementNormalized && boneIndex.scale(scaleFactor);
|
|
35507
|
-
boneIndices[j2] = boneIndex;
|
|
35508
|
-
}
|
|
35509
|
-
} else if (attribute === "WEIGHTS_0" && keepMeshData) {
|
|
35510
|
-
var baseOffset3 = elementOffset / vertices.BYTES_PER_ELEMENT;
|
|
35511
|
-
var stride4 = vertices.length / accessorCount;
|
|
35512
|
-
for(var j3 = 0; j3 < accessorCount; j3++){
|
|
35513
|
-
var offset3 = baseOffset3 + j3 * stride4;
|
|
35514
|
-
var boneWeight = new Vector4(vertices[offset3], vertices[offset3 + 1], vertices[offset3 + 2], vertices[offset3 + 3]);
|
|
35515
|
-
elementNormalized && boneWeight.scale(scaleFactor);
|
|
35516
|
-
boneWeights[j3] = boneWeight;
|
|
35517
|
-
}
|
|
35518
|
-
}
|
|
35519
|
-
}
|
|
35520
|
-
mesh.setVertexElements(vertexElements);
|
|
35521
|
-
// Indices
|
|
35522
|
-
if (indices !== undefined) {
|
|
35523
|
-
var indexAccessor = gltf.accessors[indices];
|
|
35524
|
-
var accessorBuffer1 = GLTFUtils.getAccessorBuffer(context, gltf.bufferViews, indexAccessor);
|
|
35525
|
-
mesh.setIndices(accessorBuffer1.data);
|
|
35526
|
-
mesh.addSubMesh(0, indexAccessor.count, mode);
|
|
35527
|
-
meshRestoreInfo.indexBuffer = accessorBuffer1.restoreInfo;
|
|
35528
|
-
} else {
|
|
35529
|
-
mesh.addSubMesh(0, vertexCount, mode);
|
|
35530
|
-
}
|
|
35531
|
-
// BlendShapes
|
|
35532
|
-
targets && GLTFMeshParser._createBlendShape(mesh, meshRestoreInfo, gltfMesh, targets, getBlendShapeData);
|
|
35533
|
-
mesh.uploadData(!keepMeshData);
|
|
35534
|
-
//@ts-ignore
|
|
35535
|
-
mesh._positions = positions;
|
|
35536
|
-
//@ts-ignore
|
|
35537
|
-
mesh._boneIndices = boneIndices;
|
|
35538
|
-
//@ts-ignore
|
|
35539
|
-
mesh._boneWeights = boneWeights;
|
|
35540
|
-
return Promise.resolve(mesh);
|
|
35555
|
+
mesh.addSubMesh(0, vertexCount, mode);
|
|
35556
|
+
}
|
|
35557
|
+
// BlendShapes
|
|
35558
|
+
if (targets) {
|
|
35559
|
+
promises.push(GLTFMeshParser._createBlendShape(mesh, meshRestoreInfo, gltfMesh, targets, getBlendShapeData));
|
|
35560
|
+
}
|
|
35561
|
+
return Promise.all(promises).then(function() {
|
|
35562
|
+
mesh.uploadData(!keepMeshData);
|
|
35563
|
+
//@ts-ignore
|
|
35564
|
+
mesh._positions = positions;
|
|
35565
|
+
//@ts-ignore
|
|
35566
|
+
mesh._boneIndices = boneIndices;
|
|
35567
|
+
//@ts-ignore
|
|
35568
|
+
mesh._boneWeights = boneWeights;
|
|
35569
|
+
return Promise.resolve(mesh);
|
|
35570
|
+
});
|
|
35571
|
+
});
|
|
35541
35572
|
};
|
|
35542
35573
|
/**
|
|
35543
35574
|
* @internal
|
|
35544
35575
|
*/ GLTFMeshParser._createBlendShape = function _createBlendShape(mesh, meshRestoreInfo, glTFMesh, glTFTargets, getBlendShapeData) {
|
|
35545
|
-
var
|
|
35546
|
-
for(var i = 0, n = glTFTargets.length; i < n; i++){
|
|
35576
|
+
var _loop = function _loop(i, n) {
|
|
35547
35577
|
var name = blendShapeNames ? blendShapeNames[i] : "blendShape" + i;
|
|
35548
|
-
var
|
|
35549
|
-
|
|
35550
|
-
|
|
35551
|
-
|
|
35552
|
-
|
|
35553
|
-
|
|
35554
|
-
|
|
35555
|
-
|
|
35556
|
-
|
|
35557
|
-
|
|
35558
|
-
|
|
35578
|
+
var promise = Promise.all([
|
|
35579
|
+
getBlendShapeData("POSITION", i),
|
|
35580
|
+
getBlendShapeData("NORMAL", i),
|
|
35581
|
+
getBlendShapeData("TANGENT", i)
|
|
35582
|
+
]).then(function(infos) {
|
|
35583
|
+
var deltaPosBufferInfo = infos[0];
|
|
35584
|
+
var deltaNorBufferInfo = infos[1];
|
|
35585
|
+
var deltaTanBufferInfo = infos[2];
|
|
35586
|
+
var deltaPositions = deltaPosBufferInfo.data ? GLTFUtils.floatBufferToVector3Array(deltaPosBufferInfo.data) : null;
|
|
35587
|
+
var deltaNormals = (deltaNorBufferInfo == null ? void 0 : deltaNorBufferInfo.data) ? GLTFUtils.floatBufferToVector3Array(deltaNorBufferInfo == null ? void 0 : deltaNorBufferInfo.data) : null;
|
|
35588
|
+
var deltaTangents = (deltaTanBufferInfo == null ? void 0 : deltaTanBufferInfo.data) ? GLTFUtils.floatBufferToVector3Array(deltaTanBufferInfo == null ? void 0 : deltaTanBufferInfo.data) : null;
|
|
35589
|
+
var blendShape = new BlendShape(name);
|
|
35590
|
+
blendShape.addFrame(1.0, deltaPositions, deltaNormals, deltaTangents);
|
|
35591
|
+
mesh.addBlendShape(blendShape);
|
|
35592
|
+
meshRestoreInfo.blendShapes.push(new BlendShapeRestoreInfo(blendShape, deltaPosBufferInfo.restoreInfo, deltaNorBufferInfo == null ? void 0 : deltaNorBufferInfo.restoreInfo, deltaTanBufferInfo == null ? void 0 : deltaTanBufferInfo.restoreInfo));
|
|
35593
|
+
});
|
|
35594
|
+
promises.push(promise);
|
|
35595
|
+
};
|
|
35596
|
+
var blendShapeNames = glTFMesh.extras ? glTFMesh.extras.targetNames : null;
|
|
35597
|
+
var promises = new Array();
|
|
35598
|
+
for(var i = 0, n = glTFTargets.length; i < n; i++)_loop(i);
|
|
35599
|
+
return Promise.all(promises);
|
|
35559
35600
|
};
|
|
35560
35601
|
return GLTFMeshParser;
|
|
35561
35602
|
}(GLTFParser);
|
|
@@ -35705,52 +35746,58 @@
|
|
|
35705
35746
|
_inherits(GLTFSkinParser, GLTFParser);
|
|
35706
35747
|
var _proto = GLTFSkinParser.prototype;
|
|
35707
35748
|
_proto.parse = function parse(context) {
|
|
35708
|
-
var
|
|
35709
|
-
context.buffers;
|
|
35710
|
-
var entities = glTFResource.entities;
|
|
35711
|
-
var gltfSkins = glTF.skins;
|
|
35712
|
-
if (!gltfSkins) return;
|
|
35713
|
-
var count = gltfSkins.length;
|
|
35714
|
-
var skins = new Array(count);
|
|
35715
|
-
for(var i = 0; i < count; i++){
|
|
35749
|
+
var _loop = function _loop(i) {
|
|
35716
35750
|
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;
|
|
35717
35751
|
var jointCount = joints.length;
|
|
35718
35752
|
var skin = new Skin(name);
|
|
35719
35753
|
skin.inverseBindMatrices.length = jointCount;
|
|
35720
35754
|
// parse IBM
|
|
35721
35755
|
var accessor = glTF.accessors[inverseBindMatrices];
|
|
35722
|
-
var
|
|
35723
|
-
|
|
35724
|
-
var
|
|
35725
|
-
|
|
35726
|
-
|
|
35727
|
-
|
|
35728
|
-
|
|
35729
|
-
|
|
35730
|
-
|
|
35731
|
-
|
|
35732
|
-
|
|
35733
|
-
|
|
35734
|
-
|
|
35735
|
-
|
|
35736
|
-
|
|
35756
|
+
var promise = GLTFUtils.getAccessorBuffer(context, glTF.bufferViews, accessor).then(function(bufferInfo) {
|
|
35757
|
+
var buffer = bufferInfo.data;
|
|
35758
|
+
for(var _$i = 0; _$i < jointCount; _$i++){
|
|
35759
|
+
var inverseBindMatrix = new Matrix();
|
|
35760
|
+
inverseBindMatrix.copyFromArray(buffer, _$i * 16);
|
|
35761
|
+
skin.inverseBindMatrices[_$i] = inverseBindMatrix;
|
|
35762
|
+
// get joints
|
|
35763
|
+
for(var i1 = 0; i1 < jointCount; i1++){
|
|
35764
|
+
var jointIndex = joints[i1];
|
|
35765
|
+
var jointName = entities[jointIndex].name;
|
|
35766
|
+
skin.joints[i1] = jointName;
|
|
35767
|
+
// @todo Temporary solution, but it can alleviate the current BUG, and the skinning data mechanism of SkinnedMeshRenderer will be completely refactored in the future
|
|
35768
|
+
for(var j = entities.length - 1; j >= 0; j--){
|
|
35769
|
+
if (jointIndex !== j && entities[j].name === jointName) {
|
|
35770
|
+
entities[j].name = jointName + "_" + j;
|
|
35771
|
+
}
|
|
35772
|
+
}
|
|
35773
|
+
}
|
|
35774
|
+
// get skeleton
|
|
35775
|
+
if (skeleton !== undefined) {
|
|
35776
|
+
skin.skeleton = entities[skeleton].name;
|
|
35777
|
+
} else {
|
|
35778
|
+
var rootBone = _this._findSkeletonRootBone(joints, entities);
|
|
35779
|
+
if (rootBone) {
|
|
35780
|
+
skin.skeleton = rootBone.name;
|
|
35781
|
+
} else {
|
|
35782
|
+
throw "Failed to find skeleton root bone.";
|
|
35783
|
+
}
|
|
35737
35784
|
}
|
|
35738
35785
|
}
|
|
35739
|
-
|
|
35740
|
-
|
|
35741
|
-
|
|
35742
|
-
|
|
35743
|
-
|
|
35744
|
-
|
|
35745
|
-
|
|
35746
|
-
|
|
35747
|
-
|
|
35748
|
-
|
|
35749
|
-
|
|
35750
|
-
|
|
35751
|
-
|
|
35752
|
-
|
|
35753
|
-
|
|
35786
|
+
return skin;
|
|
35787
|
+
});
|
|
35788
|
+
promises.push(promise);
|
|
35789
|
+
};
|
|
35790
|
+
var _this = this;
|
|
35791
|
+
var glTFResource = context.glTFResource, glTF = context.glTF;
|
|
35792
|
+
var entities = glTFResource.entities;
|
|
35793
|
+
var gltfSkins = glTF.skins;
|
|
35794
|
+
if (!gltfSkins) return;
|
|
35795
|
+
var count = gltfSkins.length;
|
|
35796
|
+
var promises = new Array();
|
|
35797
|
+
for(var i = 0; i < count; i++)_loop(i);
|
|
35798
|
+
return AssetPromise.all(promises).then(function(skins) {
|
|
35799
|
+
glTFResource.skins = skins;
|
|
35800
|
+
});
|
|
35754
35801
|
};
|
|
35755
35802
|
_proto._findSkeletonRootBone = function _findSkeletonRootBone(joints, entities) {
|
|
35756
35803
|
var paths = {};
|
|
@@ -35790,13 +35837,14 @@
|
|
|
35790
35837
|
var _proto = GLTFTextureParser.prototype;
|
|
35791
35838
|
_proto.parse = function parse(context) {
|
|
35792
35839
|
var _this = this;
|
|
35793
|
-
var glTFResource = context.glTFResource, glTF = context.glTF
|
|
35840
|
+
var glTFResource = context.glTFResource, glTF = context.glTF;
|
|
35794
35841
|
var engine = glTFResource.engine, url = glTFResource.url;
|
|
35795
35842
|
if (glTF.textures) {
|
|
35796
35843
|
var texturesPromiseInfo = context.texturesPromiseInfo;
|
|
35797
35844
|
AssetPromise.all(glTF.textures.map(function(param, index) {
|
|
35798
35845
|
var sampler = param.sampler, _param_source = param.source, source = _param_source === void 0 ? 0 : _param_source, textureName = param.name;
|
|
35799
35846
|
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;
|
|
35847
|
+
var samplerInfo = sampler !== undefined && _this._getSamplerInfo(glTF.samplers[sampler]);
|
|
35800
35848
|
if (uri) {
|
|
35801
35849
|
// TODO: support ktx extension https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_texture_basisu/README.md
|
|
35802
35850
|
var index1 = uri.lastIndexOf(".");
|
|
@@ -35804,31 +35852,36 @@
|
|
|
35804
35852
|
var type = ext.startsWith("ktx") ? exports.AssetType.KTX : exports.AssetType.Texture2D;
|
|
35805
35853
|
return engine.resourceManager.load({
|
|
35806
35854
|
url: Utils.resolveAbsoluteUrl(url, uri),
|
|
35807
|
-
type: type
|
|
35855
|
+
type: type,
|
|
35856
|
+
params: {
|
|
35857
|
+
mipmap: samplerInfo == null ? void 0 : samplerInfo.mipmap
|
|
35858
|
+
}
|
|
35808
35859
|
}).then(function(texture) {
|
|
35809
35860
|
if (!texture.name) {
|
|
35810
35861
|
texture.name = textureName || imageName || "texture_" + index1;
|
|
35811
35862
|
}
|
|
35812
35863
|
if (sampler !== undefined) {
|
|
35813
|
-
_this._parseSampler(texture,
|
|
35864
|
+
_this._parseSampler(texture, samplerInfo);
|
|
35814
35865
|
}
|
|
35815
35866
|
return texture;
|
|
35816
35867
|
});
|
|
35817
35868
|
} else {
|
|
35818
35869
|
var bufferView = glTF.bufferViews[bufferViewIndex];
|
|
35819
|
-
|
|
35820
|
-
|
|
35821
|
-
|
|
35822
|
-
|
|
35823
|
-
|
|
35824
|
-
|
|
35825
|
-
|
|
35826
|
-
|
|
35827
|
-
|
|
35828
|
-
|
|
35829
|
-
|
|
35830
|
-
|
|
35831
|
-
|
|
35870
|
+
return context.getBuffers().then(function(buffers) {
|
|
35871
|
+
var buffer = buffers[bufferView.buffer];
|
|
35872
|
+
var imageBuffer = new Uint8Array(buffer, bufferView.byteOffset, bufferView.byteLength);
|
|
35873
|
+
return GLTFUtils.loadImageBuffer(imageBuffer, mimeType).then(function(image) {
|
|
35874
|
+
var texture = new Texture2D(engine, image.width, image.height, undefined, samplerInfo == null ? void 0 : samplerInfo.mipmap);
|
|
35875
|
+
texture.setImageSource(image);
|
|
35876
|
+
texture.generateMipmaps();
|
|
35877
|
+
texture.name = textureName || imageName || "texture_" + index;
|
|
35878
|
+
if (sampler !== undefined) {
|
|
35879
|
+
_this._parseSampler(texture, samplerInfo);
|
|
35880
|
+
}
|
|
35881
|
+
var bufferTextureRestoreInfo = new BufferTextureRestoreInfo(texture, bufferView, mimeType);
|
|
35882
|
+
context.contentRestorer.bufferTextures.push(bufferTextureRestoreInfo);
|
|
35883
|
+
return texture;
|
|
35884
|
+
});
|
|
35832
35885
|
});
|
|
35833
35886
|
}
|
|
35834
35887
|
})).then(function(textures) {
|
|
@@ -35838,22 +35891,39 @@
|
|
|
35838
35891
|
return texturesPromiseInfo.promise;
|
|
35839
35892
|
}
|
|
35840
35893
|
};
|
|
35841
|
-
_proto.
|
|
35842
|
-
var
|
|
35843
|
-
|
|
35894
|
+
_proto._getSamplerInfo = function _getSamplerInfo(sampler) {
|
|
35895
|
+
var minFilter = sampler.minFilter, magFilter = sampler.magFilter, wrapS = sampler.wrapS, wrapT = sampler.wrapT;
|
|
35896
|
+
var info = {};
|
|
35897
|
+
if (minFilter || magFilter) {
|
|
35898
|
+
info.mipmap = minFilter >= TextureMinFilter.NEAREST_MIPMAP_NEAREST;
|
|
35844
35899
|
if (magFilter === TextureMagFilter.NEAREST) {
|
|
35845
|
-
|
|
35846
|
-
} else if (minFilter <= TextureMinFilter.LINEAR_MIPMAP_NEAREST) {
|
|
35847
|
-
texture.filterMode = exports.TextureFilterMode.Bilinear;
|
|
35900
|
+
info.filterMode = exports.TextureFilterMode.Point;
|
|
35848
35901
|
} else {
|
|
35849
|
-
|
|
35902
|
+
if (minFilter <= TextureMinFilter.LINEAR_MIPMAP_NEAREST) {
|
|
35903
|
+
info.filterMode = exports.TextureFilterMode.Bilinear;
|
|
35904
|
+
} else {
|
|
35905
|
+
info.filterMode = exports.TextureFilterMode.Trilinear;
|
|
35906
|
+
}
|
|
35850
35907
|
}
|
|
35851
35908
|
}
|
|
35852
35909
|
if (wrapS) {
|
|
35853
|
-
|
|
35910
|
+
info.wrapModeU = GLTFTextureParser._wrapMap[wrapS];
|
|
35854
35911
|
}
|
|
35855
35912
|
if (wrapT) {
|
|
35856
|
-
|
|
35913
|
+
info.wrapModeV = GLTFTextureParser._wrapMap[wrapT];
|
|
35914
|
+
}
|
|
35915
|
+
return info;
|
|
35916
|
+
};
|
|
35917
|
+
_proto._parseSampler = function _parseSampler(texture, samplerInfo) {
|
|
35918
|
+
var filterMode = samplerInfo.filterMode, wrapModeU = samplerInfo.wrapModeU, wrapModeV = samplerInfo.wrapModeV;
|
|
35919
|
+
if (filterMode) {
|
|
35920
|
+
texture.filterMode = filterMode;
|
|
35921
|
+
}
|
|
35922
|
+
if (wrapModeU) {
|
|
35923
|
+
texture.wrapModeU = wrapModeU;
|
|
35924
|
+
}
|
|
35925
|
+
if (wrapModeV) {
|
|
35926
|
+
texture.wrapModeV = wrapModeV;
|
|
35857
35927
|
}
|
|
35858
35928
|
};
|
|
35859
35929
|
return GLTFTextureParser;
|
|
@@ -37907,7 +37977,7 @@
|
|
|
37907
37977
|
_this.request(item.url, _extends({}, item, {
|
|
37908
37978
|
type: "arraybuffer"
|
|
37909
37979
|
})).then(function(data) {
|
|
37910
|
-
return decode(data, resourceManager.engine);
|
|
37980
|
+
return decode(data, resourceManager.engine).then(resolve);
|
|
37911
37981
|
}).catch(reject);
|
|
37912
37982
|
});
|
|
37913
37983
|
};
|
|
@@ -38044,7 +38114,7 @@
|
|
|
38044
38114
|
};
|
|
38045
38115
|
_proto.createAndParse = function createAndParse(context, schema, glTFPrimitive, glTFMesh) {
|
|
38046
38116
|
var _this = this;
|
|
38047
|
-
var glTF = context.glTF,
|
|
38117
|
+
var glTF = context.glTF, engine = context.glTFResource.engine;
|
|
38048
38118
|
var bufferViews = glTF.bufferViews, accessors = glTF.accessors;
|
|
38049
38119
|
var bufferViewIndex = schema.bufferView, gltfAttributeMap = schema.attributes;
|
|
38050
38120
|
var attributeMap = {};
|
|
@@ -38066,21 +38136,23 @@
|
|
|
38066
38136
|
useUniqueIDs: true,
|
|
38067
38137
|
indexType: indexType
|
|
38068
38138
|
};
|
|
38069
|
-
|
|
38070
|
-
|
|
38071
|
-
|
|
38072
|
-
|
|
38073
|
-
|
|
38074
|
-
|
|
38075
|
-
|
|
38139
|
+
return context.getBuffers().then(function(buffers) {
|
|
38140
|
+
var buffer = GLTFUtils.getBufferViewData(bufferViews[bufferViewIndex], buffers);
|
|
38141
|
+
return KHR_draco_mesh_compression._decoder.decode(buffer, taskConfig).then(function(decodedGeometry) {
|
|
38142
|
+
var mesh = new ModelMesh(engine, glTFMesh.name);
|
|
38143
|
+
return _this._parseMeshFromGLTFPrimitiveDraco(mesh, glTFMesh, glTFPrimitive, glTF, function(attributeSemantic) {
|
|
38144
|
+
for(var j = 0; j < decodedGeometry.attributes.length; j++){
|
|
38145
|
+
if (decodedGeometry.attributes[j].name === attributeSemantic) {
|
|
38146
|
+
return decodedGeometry.attributes[j].array;
|
|
38147
|
+
}
|
|
38076
38148
|
}
|
|
38077
|
-
|
|
38078
|
-
|
|
38079
|
-
|
|
38080
|
-
|
|
38081
|
-
|
|
38082
|
-
|
|
38083
|
-
}
|
|
38149
|
+
return null;
|
|
38150
|
+
}, function(attributeSemantic, shapeIndex) {
|
|
38151
|
+
throw "BlendShape animation is not supported when using draco.";
|
|
38152
|
+
}, function() {
|
|
38153
|
+
return decodedGeometry.index.array;
|
|
38154
|
+
}, context.keepMeshData);
|
|
38155
|
+
});
|
|
38084
38156
|
});
|
|
38085
38157
|
};
|
|
38086
38158
|
_proto._parseMeshFromGLTFPrimitiveDraco = function _parseMeshFromGLTFPrimitiveDraco(mesh, gltfMesh, gltfPrimitive, gltf, getVertexBufferData, getBlendShapeData, getIndexBufferData, keepMeshData) {
|
|
@@ -38405,7 +38477,7 @@
|
|
|
38405
38477
|
], GALACEAN_animation_event);
|
|
38406
38478
|
|
|
38407
38479
|
//@ts-ignore
|
|
38408
|
-
var version = "1.0.0-beta.
|
|
38480
|
+
var version = "1.0.0-beta.17";
|
|
38409
38481
|
console.log("Galacean engine version: " + version);
|
|
38410
38482
|
for(var key in CoreObjects){
|
|
38411
38483
|
Loader.registerClass(key, CoreObjects[key]);
|