|
@@ -992,6 +992,12 @@ var BABYLON;
|
|
".glb": { isBinary: true }
|
|
".glb": { isBinary: true }
|
|
};
|
|
};
|
|
}
|
|
}
|
|
|
|
+ GLTFFileLoader.prototype.dispose = function () {
|
|
|
|
+ if (this._loader) {
|
|
|
|
+ this._loader.dispose();
|
|
|
|
+ this._loader = null;
|
|
|
|
+ }
|
|
|
|
+ };
|
|
GLTFFileLoader.prototype.importMeshAsync = function (meshesNames, scene, data, rootUrl, onSuccess, onProgress, onError) {
|
|
GLTFFileLoader.prototype.importMeshAsync = function (meshesNames, scene, data, rootUrl, onSuccess, onProgress, onError) {
|
|
var loaderData = GLTFFileLoader._parse(data, onError);
|
|
var loaderData = GLTFFileLoader._parse(data, onError);
|
|
if (!loaderData) {
|
|
if (!loaderData) {
|
|
@@ -1000,11 +1006,11 @@ var BABYLON;
|
|
if (this.onParsed) {
|
|
if (this.onParsed) {
|
|
this.onParsed(loaderData);
|
|
this.onParsed(loaderData);
|
|
}
|
|
}
|
|
- var loader = this._getLoader(loaderData, onError);
|
|
|
|
- if (!loader) {
|
|
|
|
|
|
+ this._loader = this._getLoader(loaderData, onError);
|
|
|
|
+ if (!this._loader) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
- loader.importMeshAsync(meshesNames, scene, loaderData, rootUrl, onSuccess, onProgress, onError);
|
|
|
|
|
|
+ this._loader.importMeshAsync(meshesNames, scene, loaderData, rootUrl, onSuccess, onProgress, onError);
|
|
};
|
|
};
|
|
GLTFFileLoader.prototype.loadAsync = function (scene, data, rootUrl, onSuccess, onProgress, onError) {
|
|
GLTFFileLoader.prototype.loadAsync = function (scene, data, rootUrl, onSuccess, onProgress, onError) {
|
|
var loaderData = GLTFFileLoader._parse(data, onError);
|
|
var loaderData = GLTFFileLoader._parse(data, onError);
|
|
@@ -1014,11 +1020,11 @@ var BABYLON;
|
|
if (this.onParsed) {
|
|
if (this.onParsed) {
|
|
this.onParsed(loaderData);
|
|
this.onParsed(loaderData);
|
|
}
|
|
}
|
|
- var loader = this._getLoader(loaderData, onError);
|
|
|
|
- if (!loader) {
|
|
|
|
|
|
+ this._loader = this._getLoader(loaderData, onError);
|
|
|
|
+ if (!this._loader) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
- return loader.loadAsync(scene, loaderData, rootUrl, onSuccess, onProgress, onError);
|
|
|
|
|
|
+ return this._loader.loadAsync(scene, loaderData, rootUrl, onSuccess, onProgress, onError);
|
|
};
|
|
};
|
|
GLTFFileLoader.prototype.canDirectLoad = function (data) {
|
|
GLTFFileLoader.prototype.canDirectLoad = function (data) {
|
|
return ((data.indexOf("scene") !== -1) && (data.indexOf("node") !== -1));
|
|
return ((data.indexOf("scene") !== -1) && (data.indexOf("node") !== -1));
|
|
@@ -1134,18 +1140,18 @@ var BABYLON;
|
|
// Look for BIN chunk
|
|
// Look for BIN chunk
|
|
var bin = null;
|
|
var bin = null;
|
|
while (binaryReader.getPosition() < binaryReader.getLength()) {
|
|
while (binaryReader.getPosition() < binaryReader.getLength()) {
|
|
- chunkLength = binaryReader.readUint32();
|
|
|
|
- chunkFormat = binaryReader.readUint32();
|
|
|
|
- switch (chunkFormat) {
|
|
|
|
|
|
+ var chunkLength_1 = binaryReader.readUint32();
|
|
|
|
+ var chunkFormat_1 = binaryReader.readUint32();
|
|
|
|
+ switch (chunkFormat_1) {
|
|
case ChunkFormat.JSON:
|
|
case ChunkFormat.JSON:
|
|
onError("Unexpected JSON chunk");
|
|
onError("Unexpected JSON chunk");
|
|
return null;
|
|
return null;
|
|
case ChunkFormat.BIN:
|
|
case ChunkFormat.BIN:
|
|
- bin = binaryReader.readUint8Array(chunkLength);
|
|
|
|
|
|
+ bin = binaryReader.readUint8Array(chunkLength_1);
|
|
break;
|
|
break;
|
|
default:
|
|
default:
|
|
// ignore unrecognized chunkFormat
|
|
// ignore unrecognized chunkFormat
|
|
- binaryReader.skipBytes(chunkLength);
|
|
|
|
|
|
+ binaryReader.skipBytes(chunkLength_1);
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -1178,7 +1184,7 @@ var BABYLON;
|
|
GLTFFileLoader._decodeBufferToText = function (buffer) {
|
|
GLTFFileLoader._decodeBufferToText = function (buffer) {
|
|
var result = "";
|
|
var result = "";
|
|
var length = buffer.byteLength;
|
|
var length = buffer.byteLength;
|
|
- for (var i = 0; i < length; ++i) {
|
|
|
|
|
|
+ for (var i = 0; i < length; i++) {
|
|
result += String.fromCharCode(buffer[i]);
|
|
result += String.fromCharCode(buffer[i]);
|
|
}
|
|
}
|
|
return result;
|
|
return result;
|
|
@@ -2568,6 +2574,9 @@ var BABYLON;
|
|
}
|
|
}
|
|
GLTFLoader.Extensions[extension.name] = extension;
|
|
GLTFLoader.Extensions[extension.name] = extension;
|
|
};
|
|
};
|
|
|
|
+ GLTFLoader.prototype.dispose = function () {
|
|
|
|
+ // do nothing
|
|
|
|
+ };
|
|
GLTFLoader.prototype.importMeshAsync = function (meshesNames, scene, data, rootUrl, onSuccess, onProgress, onError) {
|
|
GLTFLoader.prototype.importMeshAsync = function (meshesNames, scene, data, rootUrl, onSuccess, onProgress, onError) {
|
|
var _this = this;
|
|
var _this = this;
|
|
scene.useRightHandedSystem = true;
|
|
scene.useRightHandedSystem = true;
|
|
@@ -3385,8 +3394,9 @@ var BABYLON;
|
|
}());
|
|
}());
|
|
var GLTFLoader = /** @class */ (function () {
|
|
var GLTFLoader = /** @class */ (function () {
|
|
function GLTFLoader(parent) {
|
|
function GLTFLoader(parent) {
|
|
- this._renderReady = false;
|
|
|
|
this._disposed = false;
|
|
this._disposed = false;
|
|
|
|
+ this._renderReady = false;
|
|
|
|
+ this._requests = new Array();
|
|
this._renderReadyObservable = new BABYLON.Observable();
|
|
this._renderReadyObservable = new BABYLON.Observable();
|
|
// Count of pending work that needs to complete before the asset is rendered.
|
|
// Count of pending work that needs to complete before the asset is rendered.
|
|
this._renderPendingCount = 0;
|
|
this._renderPendingCount = 0;
|
|
@@ -3409,24 +3419,37 @@ var BABYLON;
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
this._disposed = true;
|
|
this._disposed = true;
|
|
|
|
+ // Abort requests that are not complete
|
|
|
|
+ for (var _i = 0, _a = this._requests; _i < _a.length; _i++) {
|
|
|
|
+ var request = _a[_i];
|
|
|
|
+ if (request.readyState !== (XMLHttpRequest.DONE || 4)) {
|
|
|
|
+ request.abort();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
// Revoke object urls created during load
|
|
// Revoke object urls created during load
|
|
if (this._gltf.textures) {
|
|
if (this._gltf.textures) {
|
|
- this._gltf.textures.forEach(function (texture) {
|
|
|
|
|
|
+ for (var _b = 0, _c = this._gltf.textures; _b < _c.length; _b++) {
|
|
|
|
+ var texture = _c[_b];
|
|
if (texture.url) {
|
|
if (texture.url) {
|
|
URL.revokeObjectURL(texture.url);
|
|
URL.revokeObjectURL(texture.url);
|
|
}
|
|
}
|
|
- });
|
|
|
|
|
|
+ }
|
|
}
|
|
}
|
|
this._gltf = undefined;
|
|
this._gltf = undefined;
|
|
this._babylonScene = undefined;
|
|
this._babylonScene = undefined;
|
|
|
|
+ this._parent = undefined;
|
|
this._rootUrl = undefined;
|
|
this._rootUrl = undefined;
|
|
this._defaultMaterial = undefined;
|
|
this._defaultMaterial = undefined;
|
|
|
|
+ this._rootNode = undefined;
|
|
this._successCallback = undefined;
|
|
this._successCallback = undefined;
|
|
|
|
+ this._progressCallback = undefined;
|
|
this._errorCallback = undefined;
|
|
this._errorCallback = undefined;
|
|
this._renderReady = false;
|
|
this._renderReady = false;
|
|
- this._renderReadyObservable.clear();
|
|
|
|
|
|
+ this._requests = undefined;
|
|
|
|
+ this._renderReadyObservable = undefined;
|
|
this._renderPendingCount = 0;
|
|
this._renderPendingCount = 0;
|
|
this._loaderPendingCount = 0;
|
|
this._loaderPendingCount = 0;
|
|
|
|
+ this._loaderTrackers = undefined;
|
|
};
|
|
};
|
|
GLTFLoader.prototype.importMeshAsync = function (meshesNames, scene, data, rootUrl, onSuccess, onProgress, onError) {
|
|
GLTFLoader.prototype.importMeshAsync = function (meshesNames, scene, data, rootUrl, onSuccess, onProgress, onError) {
|
|
var _this = this;
|
|
var _this = this;
|
|
@@ -3494,9 +3517,6 @@ var BABYLON;
|
|
this._startAnimations();
|
|
this._startAnimations();
|
|
this._successCallback();
|
|
this._successCallback();
|
|
this._renderReadyObservable.notifyObservers(this);
|
|
this._renderReadyObservable.notifyObservers(this);
|
|
- if (this._parent.onReady) {
|
|
|
|
- this._parent.onReady();
|
|
|
|
- }
|
|
|
|
};
|
|
};
|
|
GLTFLoader.prototype._onComplete = function () {
|
|
GLTFLoader.prototype._onComplete = function () {
|
|
if (this._parent.onComplete) {
|
|
if (this._parent.onComplete) {
|
|
@@ -3524,11 +3544,12 @@ var BABYLON;
|
|
var meshes = [this._rootNode.babylonMesh];
|
|
var meshes = [this._rootNode.babylonMesh];
|
|
var nodes = this._gltf.nodes;
|
|
var nodes = this._gltf.nodes;
|
|
if (nodes) {
|
|
if (nodes) {
|
|
- nodes.forEach(function (node) {
|
|
|
|
|
|
+ for (var _i = 0, nodes_1 = nodes; _i < nodes_1.length; _i++) {
|
|
|
|
+ var node = nodes_1[_i];
|
|
if (node.babylonMesh) {
|
|
if (node.babylonMesh) {
|
|
meshes.push(node.babylonMesh);
|
|
meshes.push(node.babylonMesh);
|
|
}
|
|
}
|
|
- });
|
|
|
|
|
|
+ }
|
|
}
|
|
}
|
|
return meshes;
|
|
return meshes;
|
|
};
|
|
};
|
|
@@ -3536,11 +3557,12 @@ var BABYLON;
|
|
var skeletons = new Array();
|
|
var skeletons = new Array();
|
|
var skins = this._gltf.skins;
|
|
var skins = this._gltf.skins;
|
|
if (skins) {
|
|
if (skins) {
|
|
- skins.forEach(function (skin) {
|
|
|
|
|
|
+ for (var _i = 0, skins_1 = skins; _i < skins_1.length; _i++) {
|
|
|
|
+ var skin = skins_1[_i];
|
|
if (skin.babylonSkeleton instanceof BABYLON.Skeleton) {
|
|
if (skin.babylonSkeleton instanceof BABYLON.Skeleton) {
|
|
skeletons.push(skin.babylonSkeleton);
|
|
skeletons.push(skin.babylonSkeleton);
|
|
}
|
|
}
|
|
- });
|
|
|
|
|
|
+ }
|
|
}
|
|
}
|
|
return skeletons;
|
|
return skeletons;
|
|
};
|
|
};
|
|
@@ -3548,15 +3570,18 @@ var BABYLON;
|
|
var targets = new Array();
|
|
var targets = new Array();
|
|
var animations = this._gltf.animations;
|
|
var animations = this._gltf.animations;
|
|
if (animations) {
|
|
if (animations) {
|
|
- animations.forEach(function (animation) {
|
|
|
|
|
|
+ for (var _i = 0, animations_1 = animations; _i < animations_1.length; _i++) {
|
|
|
|
+ var animation = animations_1[_i];
|
|
targets.push.apply(targets, animation.targets);
|
|
targets.push.apply(targets, animation.targets);
|
|
- });
|
|
|
|
|
|
+ }
|
|
}
|
|
}
|
|
return targets;
|
|
return targets;
|
|
};
|
|
};
|
|
GLTFLoader.prototype._startAnimations = function () {
|
|
GLTFLoader.prototype._startAnimations = function () {
|
|
- var _this = this;
|
|
|
|
- this._getAnimationTargets().forEach(function (target) { return _this._babylonScene.beginAnimation(target, 0, Number.MAX_VALUE, true); });
|
|
|
|
|
|
+ for (var _i = 0, _a = this._getAnimationTargets(); _i < _a.length; _i++) {
|
|
|
|
+ var target = _a[_i];
|
|
|
|
+ this._babylonScene.beginAnimation(target, 0, Number.MAX_VALUE, true);
|
|
|
|
+ }
|
|
};
|
|
};
|
|
GLTFLoader.prototype._loadDefaultScene = function (nodeNames) {
|
|
GLTFLoader.prototype._loadDefaultScene = function (nodeNames) {
|
|
var scene = GLTF2.GLTFUtils.GetArrayItem(this._gltf.scenes, this._gltf.scene || 0);
|
|
var scene = GLTF2.GLTFUtils.GetArrayItem(this._gltf.scenes, this._gltf.scene || 0);
|
|
@@ -3593,22 +3618,23 @@ var BABYLON;
|
|
if (!(nodeNames instanceof Array)) {
|
|
if (!(nodeNames instanceof Array)) {
|
|
nodeNames = [nodeNames];
|
|
nodeNames = [nodeNames];
|
|
}
|
|
}
|
|
- var filteredNodeIndices = new Array();
|
|
|
|
|
|
+ var filteredNodeIndices_1 = new Array();
|
|
this._traverseNodes(context, nodeIndices, function (node) {
|
|
this._traverseNodes(context, nodeIndices, function (node) {
|
|
if (nodeNames.indexOf(node.name) !== -1) {
|
|
if (nodeNames.indexOf(node.name) !== -1) {
|
|
- filteredNodeIndices.push(node.index);
|
|
|
|
|
|
+ filteredNodeIndices_1.push(node.index);
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
return true;
|
|
}, this._rootNode);
|
|
}, this._rootNode);
|
|
- nodeIndices = filteredNodeIndices;
|
|
|
|
|
|
+ nodeIndices = filteredNodeIndices_1;
|
|
}
|
|
}
|
|
- for (var i = 0; i < nodeIndices.length; i++) {
|
|
|
|
- var node = GLTF2.GLTFUtils.GetArrayItem(this._gltf.nodes, nodeIndices[i]);
|
|
|
|
|
|
+ for (var _i = 0, nodeIndices_1 = nodeIndices; _i < nodeIndices_1.length; _i++) {
|
|
|
|
+ var index = nodeIndices_1[_i];
|
|
|
|
+ var node = GLTF2.GLTFUtils.GetArrayItem(this._gltf.nodes, index);
|
|
if (!node) {
|
|
if (!node) {
|
|
- throw new Error(context + ": Failed to find node " + nodeIndices[i]);
|
|
|
|
|
|
+ throw new Error(context + ": Failed to find node " + index);
|
|
}
|
|
}
|
|
- this._loadNode("#/nodes/" + nodeIndices[i], node);
|
|
|
|
|
|
+ this._loadNode("#/nodes/" + index, node);
|
|
}
|
|
}
|
|
// Disable the root mesh until the asset is ready to render.
|
|
// Disable the root mesh until the asset is ready to render.
|
|
this._rootNode.babylonMesh.setEnabled(false);
|
|
this._rootNode.babylonMesh.setEnabled(false);
|
|
@@ -3640,25 +3666,26 @@ var BABYLON;
|
|
// TODO: handle cameras
|
|
// TODO: handle cameras
|
|
}
|
|
}
|
|
if (node.children) {
|
|
if (node.children) {
|
|
- for (var i = 0; i < node.children.length; i++) {
|
|
|
|
- var childNode = GLTF2.GLTFUtils.GetArrayItem(this._gltf.nodes, node.children[i]);
|
|
|
|
|
|
+ for (var _i = 0, _a = node.children; _i < _a.length; _i++) {
|
|
|
|
+ var index = _a[_i];
|
|
|
|
+ var childNode = GLTF2.GLTFUtils.GetArrayItem(this._gltf.nodes, index);
|
|
if (!childNode) {
|
|
if (!childNode) {
|
|
- throw new Error(context + ": Failed to find child node " + node.children[i]);
|
|
|
|
|
|
+ throw new Error(context + ": Failed to find child node " + index);
|
|
}
|
|
}
|
|
- this._loadNode("#/nodes/" + node.children[i], childNode);
|
|
|
|
|
|
+ this._loadNode("#/nodes/" + index, childNode);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
};
|
|
};
|
|
GLTFLoader.prototype._loadMesh = function (context, node, mesh) {
|
|
GLTFLoader.prototype._loadMesh = function (context, node, mesh) {
|
|
var _this = this;
|
|
var _this = this;
|
|
node.babylonMesh.name = node.babylonMesh.name || mesh.name;
|
|
node.babylonMesh.name = node.babylonMesh.name || mesh.name;
|
|
- if (!mesh.primitives || mesh.primitives.length === 0) {
|
|
|
|
|
|
+ var primitives = mesh.primitives;
|
|
|
|
+ if (!primitives || primitives.length === 0) {
|
|
throw new Error(context + ": Primitives are missing");
|
|
throw new Error(context + ": Primitives are missing");
|
|
}
|
|
}
|
|
this._createMorphTargets(context, node, mesh);
|
|
this._createMorphTargets(context, node, mesh);
|
|
this._loadAllVertexDataAsync(context, mesh, function () {
|
|
this._loadAllVertexDataAsync(context, mesh, function () {
|
|
_this._loadMorphTargets(context, node, mesh);
|
|
_this._loadMorphTargets(context, node, mesh);
|
|
- var primitives = mesh.primitives;
|
|
|
|
var vertexData = new BABYLON.VertexData();
|
|
var vertexData = new BABYLON.VertexData();
|
|
for (var _i = 0, primitives_1 = primitives; _i < primitives_1.length; _i++) {
|
|
for (var _i = 0, primitives_1 = primitives; _i < primitives_1.length; _i++) {
|
|
var primitive = primitives_1[_i];
|
|
var primitive = primitives_1[_i];
|
|
@@ -3671,62 +3698,68 @@ var BABYLON;
|
|
var verticesStart = 0;
|
|
var verticesStart = 0;
|
|
var indicesStart = 0;
|
|
var indicesStart = 0;
|
|
for (var index = 0; index < primitives.length; index++) {
|
|
for (var index = 0; index < primitives.length; index++) {
|
|
- var vertexData = primitives[index].vertexData;
|
|
|
|
- var verticesCount = vertexData.positions.length;
|
|
|
|
- var indicesCount = vertexData.indices.length;
|
|
|
|
|
|
+ var vertexData_1 = primitives[index].vertexData;
|
|
|
|
+ var verticesCount = vertexData_1.positions.length;
|
|
|
|
+ var indicesCount = vertexData_1.indices.length;
|
|
BABYLON.SubMesh.AddToMesh(index, verticesStart, verticesCount, indicesStart, indicesCount, node.babylonMesh);
|
|
BABYLON.SubMesh.AddToMesh(index, verticesStart, verticesCount, indicesStart, indicesCount, node.babylonMesh);
|
|
verticesStart += verticesCount;
|
|
verticesStart += verticesCount;
|
|
indicesStart += indicesCount;
|
|
indicesStart += indicesCount;
|
|
}
|
|
}
|
|
;
|
|
;
|
|
- var multiMaterial = new BABYLON.MultiMaterial(node.babylonMesh.name, _this._babylonScene);
|
|
|
|
- node.babylonMesh.material = multiMaterial;
|
|
|
|
- var subMaterials = multiMaterial.subMaterials;
|
|
|
|
- for (var index = 0; index < primitives.length; index++) {
|
|
|
|
- var primitive = primitives[index];
|
|
|
|
- if (primitive.material == null) {
|
|
|
|
- subMaterials[index] = _this._getDefaultMaterial();
|
|
|
|
|
|
+ });
|
|
|
|
+ var multiMaterial = new BABYLON.MultiMaterial(node.babylonMesh.name, this._babylonScene);
|
|
|
|
+ node.babylonMesh.material = multiMaterial;
|
|
|
|
+ var subMaterials = multiMaterial.subMaterials;
|
|
|
|
+ var _loop_1 = function (index) {
|
|
|
|
+ var primitive = primitives[index];
|
|
|
|
+ if (primitive.material == null) {
|
|
|
|
+ subMaterials[index] = this_1._getDefaultMaterial();
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ var material_1 = GLTF2.GLTFUtils.GetArrayItem(this_1._gltf.materials, primitive.material);
|
|
|
|
+ if (!material_1) {
|
|
|
|
+ throw new Error(context + ": Failed to find material " + primitive.material);
|
|
}
|
|
}
|
|
- else {
|
|
|
|
- var material = GLTF2.GLTFUtils.GetArrayItem(_this._gltf.materials, primitive.material);
|
|
|
|
- if (!material) {
|
|
|
|
- throw new Error(context + ": Failed to find material " + primitive.material);
|
|
|
|
|
|
+ this_1._loadMaterial("#/materials/" + material_1.index, material_1, function (babylonMaterial, isNew) {
|
|
|
|
+ if (isNew && _this._parent.onMaterialLoaded) {
|
|
|
|
+ _this._parent.onMaterialLoaded(babylonMaterial);
|
|
}
|
|
}
|
|
- _this._loadMaterial("#/materials/" + material.index, material, function (babylonMaterial, isNew) {
|
|
|
|
- if (isNew && _this._parent.onMaterialLoaded) {
|
|
|
|
- _this._parent.onMaterialLoaded(babylonMaterial);
|
|
|
|
- }
|
|
|
|
- if (_this._parent.onBeforeMaterialReadyAsync) {
|
|
|
|
- _this._addLoaderPendingData(material);
|
|
|
|
- _this._parent.onBeforeMaterialReadyAsync(babylonMaterial, node.babylonMesh, subMaterials[index] != null, function () {
|
|
|
|
|
|
+ if (_this._parent.onBeforeMaterialReadyAsync) {
|
|
|
|
+ _this._addLoaderPendingData(material_1);
|
|
|
|
+ _this._parent.onBeforeMaterialReadyAsync(babylonMaterial, node.babylonMesh, subMaterials[index] != null, function () {
|
|
|
|
+ _this._tryCatchOnError(function () {
|
|
subMaterials[index] = babylonMaterial;
|
|
subMaterials[index] = babylonMaterial;
|
|
- _this._removeLoaderPendingData(material);
|
|
|
|
|
|
+ _this._removeLoaderPendingData(material_1);
|
|
});
|
|
});
|
|
- }
|
|
|
|
- else {
|
|
|
|
- subMaterials[index] = babylonMaterial;
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ subMaterials[index] = babylonMaterial;
|
|
|
|
+ }
|
|
|
|
+ });
|
|
}
|
|
}
|
|
- ;
|
|
|
|
- });
|
|
|
|
|
|
+ };
|
|
|
|
+ var this_1 = this;
|
|
|
|
+ for (var index = 0; index < primitives.length; index++) {
|
|
|
|
+ _loop_1(index);
|
|
|
|
+ }
|
|
|
|
+ ;
|
|
};
|
|
};
|
|
GLTFLoader.prototype._loadAllVertexDataAsync = function (context, mesh, onSuccess) {
|
|
GLTFLoader.prototype._loadAllVertexDataAsync = function (context, mesh, onSuccess) {
|
|
var primitives = mesh.primitives;
|
|
var primitives = mesh.primitives;
|
|
var numRemainingPrimitives = primitives.length;
|
|
var numRemainingPrimitives = primitives.length;
|
|
- var _loop_1 = function () {
|
|
|
|
|
|
+ var _loop_2 = function (index) {
|
|
var primitive = primitives[index];
|
|
var primitive = primitives[index];
|
|
- this_1._loadVertexDataAsync(context + "/primitive/" + index, mesh, primitive, function (vertexData) {
|
|
|
|
|
|
+ this_2._loadVertexDataAsync(context + "/primitive/" + index, mesh, primitive, function (vertexData) {
|
|
primitive.vertexData = vertexData;
|
|
primitive.vertexData = vertexData;
|
|
if (--numRemainingPrimitives === 0) {
|
|
if (--numRemainingPrimitives === 0) {
|
|
onSuccess();
|
|
onSuccess();
|
|
}
|
|
}
|
|
});
|
|
});
|
|
};
|
|
};
|
|
- var this_1 = this;
|
|
|
|
|
|
+ var this_2 = this;
|
|
for (var index = 0; index < primitives.length; index++) {
|
|
for (var index = 0; index < primitives.length; index++) {
|
|
- _loop_1();
|
|
|
|
|
|
+ _loop_2(index);
|
|
}
|
|
}
|
|
};
|
|
};
|
|
GLTFLoader.prototype._loadVertexDataAsync = function (context, mesh, primitive, onSuccess) {
|
|
GLTFLoader.prototype._loadVertexDataAsync = function (context, mesh, primitive, onSuccess) {
|
|
@@ -3741,12 +3774,12 @@ var BABYLON;
|
|
}
|
|
}
|
|
var vertexData = new BABYLON.VertexData();
|
|
var vertexData = new BABYLON.VertexData();
|
|
var numRemainingAttributes = Object.keys(attributes).length;
|
|
var numRemainingAttributes = Object.keys(attributes).length;
|
|
- var _loop_2 = function (attribute) {
|
|
|
|
- accessor = GLTF2.GLTFUtils.GetArrayItem(this_2._gltf.accessors, attributes[attribute]);
|
|
|
|
|
|
+ var _loop_3 = function (attribute) {
|
|
|
|
+ var accessor = GLTF2.GLTFUtils.GetArrayItem(this_3._gltf.accessors, attributes[attribute]);
|
|
if (!accessor) {
|
|
if (!accessor) {
|
|
throw new Error(context + ": Failed to find attribute '" + attribute + "' accessor " + attributes[attribute]);
|
|
throw new Error(context + ": Failed to find attribute '" + attribute + "' accessor " + attributes[attribute]);
|
|
}
|
|
}
|
|
- this_2._loadAccessorAsync("#/accessors/" + accessor.index, accessor, function (data) {
|
|
|
|
|
|
+ this_3._loadAccessorAsync("#/accessors/" + accessor.index, accessor, function (data) {
|
|
switch (attribute) {
|
|
switch (attribute) {
|
|
case "NORMAL":
|
|
case "NORMAL":
|
|
vertexData.normals = data;
|
|
vertexData.normals = data;
|
|
@@ -3779,7 +3812,9 @@ var BABYLON;
|
|
if (--numRemainingAttributes === 0) {
|
|
if (--numRemainingAttributes === 0) {
|
|
if (primitive.indices == null) {
|
|
if (primitive.indices == null) {
|
|
vertexData.indices = new Uint32Array(vertexData.positions.length / 3);
|
|
vertexData.indices = new Uint32Array(vertexData.positions.length / 3);
|
|
- vertexData.indices.forEach(function (v, i) { return vertexData.indices[i] = i; });
|
|
|
|
|
|
+ for (var i = 0; i < vertexData.indices.length; i++) {
|
|
|
|
+ vertexData.indices[i] = i;
|
|
|
|
+ }
|
|
onSuccess(vertexData);
|
|
onSuccess(vertexData);
|
|
}
|
|
}
|
|
else {
|
|
else {
|
|
@@ -3795,9 +3830,9 @@ var BABYLON;
|
|
}
|
|
}
|
|
});
|
|
});
|
|
};
|
|
};
|
|
- var this_2 = this, accessor;
|
|
|
|
|
|
+ var this_3 = this;
|
|
for (var attribute in attributes) {
|
|
for (var attribute in attributes) {
|
|
- _loop_2(attribute);
|
|
|
|
|
|
+ _loop_3(attribute);
|
|
}
|
|
}
|
|
};
|
|
};
|
|
GLTFLoader.prototype._createMorphTargets = function (context, node, mesh) {
|
|
GLTFLoader.prototype._createMorphTargets = function (context, node, mesh) {
|
|
@@ -3830,7 +3865,7 @@ var BABYLON;
|
|
var vertexData = new BABYLON.VertexData();
|
|
var vertexData = new BABYLON.VertexData();
|
|
for (var _i = 0, _a = mesh.primitives; _i < _a.length; _i++) {
|
|
for (var _i = 0, _a = mesh.primitives; _i < _a.length; _i++) {
|
|
var primitive = _a[_i];
|
|
var primitive = _a[_i];
|
|
- vertexData.merge(primitive.targetsVertexData[index]);
|
|
|
|
|
|
+ vertexData.merge(primitive.targetsVertexData[index], { tangentLength: 3 });
|
|
}
|
|
}
|
|
var target = morphTargetManager.getTarget(index);
|
|
var target = morphTargetManager.getTarget(index);
|
|
target.setNormals(vertexData.normals);
|
|
target.setNormals(vertexData.normals);
|
|
@@ -3841,33 +3876,36 @@ var BABYLON;
|
|
};
|
|
};
|
|
GLTFLoader.prototype._loadAllMorphTargetVertexDataAsync = function (context, node, mesh, onSuccess) {
|
|
GLTFLoader.prototype._loadAllMorphTargetVertexDataAsync = function (context, node, mesh, onSuccess) {
|
|
var numRemainingTargets = mesh.primitives.length * node.babylonMesh.morphTargetManager.numTargets;
|
|
var numRemainingTargets = mesh.primitives.length * node.babylonMesh.morphTargetManager.numTargets;
|
|
- for (var _i = 0, _a = mesh.primitives; _i < _a.length; _i++) {
|
|
|
|
- var primitive = _a[_i];
|
|
|
|
|
|
+ var _loop_4 = function (primitive) {
|
|
var targets = primitive.targets;
|
|
var targets = primitive.targets;
|
|
primitive.targetsVertexData = new Array(targets.length);
|
|
primitive.targetsVertexData = new Array(targets.length);
|
|
- var _loop_3 = function (index) {
|
|
|
|
- this_3._loadMorphTargetVertexDataAsync(context + "/targets/" + index, primitive.vertexData, targets[index], function (vertexData) {
|
|
|
|
|
|
+ var _loop_5 = function (index) {
|
|
|
|
+ this_4._loadMorphTargetVertexDataAsync(context + "/targets/" + index, primitive.vertexData, targets[index], function (vertexData) {
|
|
primitive.targetsVertexData[index] = vertexData;
|
|
primitive.targetsVertexData[index] = vertexData;
|
|
if (--numRemainingTargets === 0) {
|
|
if (--numRemainingTargets === 0) {
|
|
onSuccess();
|
|
onSuccess();
|
|
}
|
|
}
|
|
});
|
|
});
|
|
};
|
|
};
|
|
- var this_3 = this;
|
|
|
|
for (var index = 0; index < targets.length; index++) {
|
|
for (var index = 0; index < targets.length; index++) {
|
|
- _loop_3(index);
|
|
|
|
|
|
+ _loop_5(index);
|
|
}
|
|
}
|
|
|
|
+ };
|
|
|
|
+ var this_4 = this;
|
|
|
|
+ for (var _i = 0, _a = mesh.primitives; _i < _a.length; _i++) {
|
|
|
|
+ var primitive = _a[_i];
|
|
|
|
+ _loop_4(primitive);
|
|
}
|
|
}
|
|
};
|
|
};
|
|
GLTFLoader.prototype._loadMorphTargetVertexDataAsync = function (context, vertexData, attributes, onSuccess) {
|
|
GLTFLoader.prototype._loadMorphTargetVertexDataAsync = function (context, vertexData, attributes, onSuccess) {
|
|
var targetVertexData = new BABYLON.VertexData();
|
|
var targetVertexData = new BABYLON.VertexData();
|
|
var numRemainingAttributes = Object.keys(attributes).length;
|
|
var numRemainingAttributes = Object.keys(attributes).length;
|
|
- var _loop_4 = function (attribute) {
|
|
|
|
- accessor = GLTF2.GLTFUtils.GetArrayItem(this_4._gltf.accessors, attributes[attribute]);
|
|
|
|
|
|
+ var _loop_6 = function (attribute) {
|
|
|
|
+ var accessor = GLTF2.GLTFUtils.GetArrayItem(this_5._gltf.accessors, attributes[attribute]);
|
|
if (!accessor) {
|
|
if (!accessor) {
|
|
throw new Error(context + ": Failed to find attribute '" + attribute + "' accessor " + attributes[attribute]);
|
|
throw new Error(context + ": Failed to find attribute '" + attribute + "' accessor " + attributes[attribute]);
|
|
}
|
|
}
|
|
- this_4._loadAccessorAsync("#/accessors/" + accessor.index, accessor, function (data) {
|
|
|
|
|
|
+ this_5._loadAccessorAsync("#/accessors/" + accessor.index, accessor, function (data) {
|
|
// glTF stores morph target information as deltas while babylon.js expects the final data.
|
|
// glTF stores morph target information as deltas while babylon.js expects the final data.
|
|
// As a result we have to add the original data to the delta to calculate the final data.
|
|
// As a result we have to add the original data to the delta to calculate the final data.
|
|
var values = data;
|
|
var values = data;
|
|
@@ -3905,9 +3943,9 @@ var BABYLON;
|
|
}
|
|
}
|
|
});
|
|
});
|
|
};
|
|
};
|
|
- var this_4 = this, accessor;
|
|
|
|
|
|
+ var this_5 = this;
|
|
for (var attribute in attributes) {
|
|
for (var attribute in attributes) {
|
|
- _loop_4(attribute);
|
|
|
|
|
|
+ _loop_6(attribute);
|
|
}
|
|
}
|
|
};
|
|
};
|
|
GLTFLoader.prototype._loadTransform = function (node) {
|
|
GLTFLoader.prototype._loadTransform = function (node) {
|
|
@@ -3915,8 +3953,8 @@ var BABYLON;
|
|
var rotation = BABYLON.Quaternion.Identity();
|
|
var rotation = BABYLON.Quaternion.Identity();
|
|
var scaling = BABYLON.Vector3.One();
|
|
var scaling = BABYLON.Vector3.One();
|
|
if (node.matrix) {
|
|
if (node.matrix) {
|
|
- var mat = BABYLON.Matrix.FromArray(node.matrix);
|
|
|
|
- mat.decompose(scaling, rotation, position);
|
|
|
|
|
|
+ var matrix = BABYLON.Matrix.FromArray(node.matrix);
|
|
|
|
+ matrix.decompose(scaling, rotation, position);
|
|
}
|
|
}
|
|
else {
|
|
else {
|
|
if (node.translation)
|
|
if (node.translation)
|
|
@@ -3958,10 +3996,11 @@ var BABYLON;
|
|
};
|
|
};
|
|
GLTFLoader.prototype._loadBones = function (context, skin, inverseBindMatrixData) {
|
|
GLTFLoader.prototype._loadBones = function (context, skin, inverseBindMatrixData) {
|
|
var babylonBones = {};
|
|
var babylonBones = {};
|
|
- for (var i = 0; i < skin.joints.length; i++) {
|
|
|
|
- var node = GLTF2.GLTFUtils.GetArrayItem(this._gltf.nodes, skin.joints[i]);
|
|
|
|
|
|
+ for (var _i = 0, _a = skin.joints; _i < _a.length; _i++) {
|
|
|
|
+ var index = _a[_i];
|
|
|
|
+ var node = GLTF2.GLTFUtils.GetArrayItem(this._gltf.nodes, index);
|
|
if (!node) {
|
|
if (!node) {
|
|
- throw new Error(context + ": Failed to find joint " + skin.joints[i]);
|
|
|
|
|
|
+ throw new Error(context + ": Failed to find joint " + index);
|
|
}
|
|
}
|
|
this._loadBone(node, skin, inverseBindMatrixData, babylonBones);
|
|
this._loadBone(node, skin, inverseBindMatrixData, babylonBones);
|
|
}
|
|
}
|
|
@@ -3993,10 +4032,11 @@ var BABYLON;
|
|
};
|
|
};
|
|
GLTFLoader.prototype._traverseNodes = function (context, indices, action, parentNode) {
|
|
GLTFLoader.prototype._traverseNodes = function (context, indices, action, parentNode) {
|
|
if (parentNode === void 0) { parentNode = null; }
|
|
if (parentNode === void 0) { parentNode = null; }
|
|
- for (var i = 0; i < indices.length; i++) {
|
|
|
|
- var node = GLTF2.GLTFUtils.GetArrayItem(this._gltf.nodes, indices[i]);
|
|
|
|
|
|
+ for (var _i = 0, indices_1 = indices; _i < indices_1.length; _i++) {
|
|
|
|
+ var index = indices_1[_i];
|
|
|
|
+ var node = GLTF2.GLTFUtils.GetArrayItem(this._gltf.nodes, index);
|
|
if (!node) {
|
|
if (!node) {
|
|
- throw new Error(context + ": Failed to find node " + indices[i]);
|
|
|
|
|
|
+ throw new Error(context + ": Failed to find node " + index);
|
|
}
|
|
}
|
|
this._traverseNode(context, node, action, parentNode);
|
|
this._traverseNode(context, node, action, parentNode);
|
|
}
|
|
}
|
|
@@ -4129,7 +4169,7 @@ var BABYLON;
|
|
animation.targets = animation.targets || [];
|
|
animation.targets = animation.targets || [];
|
|
if (targetPath === "influence") {
|
|
if (targetPath === "influence") {
|
|
var morphTargetManager = targetNode.babylonMesh.morphTargetManager;
|
|
var morphTargetManager = targetNode.babylonMesh.morphTargetManager;
|
|
- for (var targetIndex = 0; targetIndex < morphTargetManager.numTargets; targetIndex++) {
|
|
|
|
|
|
+ var _loop_7 = function (targetIndex) {
|
|
var morphTarget = morphTargetManager.getTarget(targetIndex);
|
|
var morphTarget = morphTargetManager.getTarget(targetIndex);
|
|
var animationName = (animation.name || "anim" + animation.index) + "_" + targetIndex;
|
|
var animationName = (animation.name || "anim" + animation.index) + "_" + targetIndex;
|
|
var babylonAnimation = new BABYLON.Animation(animationName, targetPath, 1, animationType);
|
|
var babylonAnimation = new BABYLON.Animation(animationName, targetPath, 1, animationType);
|
|
@@ -4141,14 +4181,17 @@ var BABYLON;
|
|
}); }));
|
|
}); }));
|
|
morphTarget.animations.push(babylonAnimation);
|
|
morphTarget.animations.push(babylonAnimation);
|
|
animation.targets.push(morphTarget);
|
|
animation.targets.push(morphTarget);
|
|
|
|
+ };
|
|
|
|
+ for (var targetIndex = 0; targetIndex < morphTargetManager.numTargets; targetIndex++) {
|
|
|
|
+ _loop_7(targetIndex);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else {
|
|
else {
|
|
var animationName = animation.name || "anim" + animation.index;
|
|
var animationName = animation.name || "anim" + animation.index;
|
|
var babylonAnimation = new BABYLON.Animation(animationName, targetPath, 1, animationType);
|
|
var babylonAnimation = new BABYLON.Animation(animationName, targetPath, 1, animationType);
|
|
babylonAnimation.setKeys(keys);
|
|
babylonAnimation.setKeys(keys);
|
|
- for (var i = 0; i < targetNode.babylonAnimationTargets.length; i++) {
|
|
|
|
- var target = targetNode.babylonAnimationTargets[i];
|
|
|
|
|
|
+ for (var _i = 0, _a = targetNode.babylonAnimationTargets; _i < _a.length; _i++) {
|
|
|
|
+ var target = _a[_i];
|
|
target.animations.push(babylonAnimation.clone());
|
|
target.animations.push(babylonAnimation.clone());
|
|
animation.targets.push(target);
|
|
animation.targets.push(target);
|
|
}
|
|
}
|
|
@@ -4195,28 +4238,15 @@ var BABYLON;
|
|
this._removePendingData(buffer);
|
|
this._removePendingData(buffer);
|
|
}
|
|
}
|
|
else {
|
|
else {
|
|
- if (!GLTF2.GLTFUtils.ValidateUri(buffer.uri)) {
|
|
|
|
- throw new Error(context + ": Uri '" + buffer.uri + "' is invalid");
|
|
|
|
- }
|
|
|
|
buffer.loadedObservable = new BABYLON.Observable();
|
|
buffer.loadedObservable = new BABYLON.Observable();
|
|
buffer.loadedObservable.add(function (buffer) {
|
|
buffer.loadedObservable.add(function (buffer) {
|
|
onSuccess(buffer.loadedData);
|
|
onSuccess(buffer.loadedData);
|
|
_this._removePendingData(buffer);
|
|
_this._removePendingData(buffer);
|
|
});
|
|
});
|
|
- BABYLON.Tools.LoadFile(this._rootUrl + buffer.uri, function (data) {
|
|
|
|
- _this._tryCatchOnError(function () {
|
|
|
|
- buffer.loadedData = new Uint8Array(data);
|
|
|
|
- buffer.loadedObservable.notifyObservers(buffer);
|
|
|
|
- buffer.loadedObservable = null;
|
|
|
|
- });
|
|
|
|
- }, function (event) {
|
|
|
|
- _this._tryCatchOnError(function () {
|
|
|
|
- _this._onProgress(event);
|
|
|
|
- });
|
|
|
|
- }, this._babylonScene.database, true, function (request) {
|
|
|
|
- _this._tryCatchOnError(function () {
|
|
|
|
- throw new Error(context + ": Failed to load '" + buffer.uri + "'" + (request ? ": " + request.status + " " + request.statusText : ""));
|
|
|
|
- });
|
|
|
|
|
|
+ this._loadUri(context, buffer.uri, function (data) {
|
|
|
|
+ buffer.loadedData = data;
|
|
|
|
+ buffer.loadedObservable.notifyObservers(buffer);
|
|
|
|
+ buffer.loadedObservable = null;
|
|
});
|
|
});
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -4231,8 +4261,9 @@ var BABYLON;
|
|
if (_this._disposed) {
|
|
if (_this._disposed) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
+ var data;
|
|
try {
|
|
try {
|
|
- var data = new Uint8Array(bufferData.buffer, bufferData.byteOffset + (bufferView.byteOffset || 0), bufferView.byteLength);
|
|
|
|
|
|
+ data = new Uint8Array(bufferData.buffer, bufferData.byteOffset + (bufferView.byteOffset || 0), bufferView.byteLength);
|
|
}
|
|
}
|
|
catch (e) {
|
|
catch (e) {
|
|
throw new Error(context + ": " + e.message);
|
|
throw new Error(context + ": " + e.message);
|
|
@@ -4258,27 +4289,32 @@ var BABYLON;
|
|
throw new Error(context + ": Invalid type (" + accessor.type + ")");
|
|
throw new Error(context + ": Invalid type (" + accessor.type + ")");
|
|
}
|
|
}
|
|
var data;
|
|
var data;
|
|
- switch (accessor.componentType) {
|
|
|
|
- case GLTF2.EComponentType.BYTE:
|
|
|
|
- data = _this._buildArrayBuffer(Float32Array, context, bufferViewData, accessor.byteOffset, accessor.count, numComponents, bufferView.byteStride);
|
|
|
|
- break;
|
|
|
|
- case GLTF2.EComponentType.UNSIGNED_BYTE:
|
|
|
|
- data = _this._buildArrayBuffer(Uint8Array, context, bufferViewData, accessor.byteOffset, accessor.count, numComponents, bufferView.byteStride);
|
|
|
|
- break;
|
|
|
|
- case GLTF2.EComponentType.SHORT:
|
|
|
|
- data = _this._buildArrayBuffer(Int16Array, context, bufferViewData, accessor.byteOffset, accessor.count, numComponents, bufferView.byteStride);
|
|
|
|
- break;
|
|
|
|
- case GLTF2.EComponentType.UNSIGNED_SHORT:
|
|
|
|
- data = _this._buildArrayBuffer(Uint16Array, context, bufferViewData, accessor.byteOffset, accessor.count, numComponents, bufferView.byteStride);
|
|
|
|
- break;
|
|
|
|
- case GLTF2.EComponentType.UNSIGNED_INT:
|
|
|
|
- data = _this._buildArrayBuffer(Uint32Array, context, bufferViewData, accessor.byteOffset, accessor.count, numComponents, bufferView.byteStride);
|
|
|
|
- break;
|
|
|
|
- case GLTF2.EComponentType.FLOAT:
|
|
|
|
- data = _this._buildArrayBuffer(Float32Array, context, bufferViewData, accessor.byteOffset, accessor.count, numComponents, bufferView.byteStride);
|
|
|
|
- break;
|
|
|
|
- default:
|
|
|
|
- throw new Error(context + ": Invalid component type (" + accessor.componentType + ")");
|
|
|
|
|
|
+ try {
|
|
|
|
+ switch (accessor.componentType) {
|
|
|
|
+ case GLTF2.EComponentType.BYTE:
|
|
|
|
+ data = _this._buildArrayBuffer(Float32Array, bufferViewData, accessor.byteOffset, accessor.count, numComponents, bufferView.byteStride);
|
|
|
|
+ break;
|
|
|
|
+ case GLTF2.EComponentType.UNSIGNED_BYTE:
|
|
|
|
+ data = _this._buildArrayBuffer(Uint8Array, bufferViewData, accessor.byteOffset, accessor.count, numComponents, bufferView.byteStride);
|
|
|
|
+ break;
|
|
|
|
+ case GLTF2.EComponentType.SHORT:
|
|
|
|
+ data = _this._buildArrayBuffer(Int16Array, bufferViewData, accessor.byteOffset, accessor.count, numComponents, bufferView.byteStride);
|
|
|
|
+ break;
|
|
|
|
+ case GLTF2.EComponentType.UNSIGNED_SHORT:
|
|
|
|
+ data = _this._buildArrayBuffer(Uint16Array, bufferViewData, accessor.byteOffset, accessor.count, numComponents, bufferView.byteStride);
|
|
|
|
+ break;
|
|
|
|
+ case GLTF2.EComponentType.UNSIGNED_INT:
|
|
|
|
+ data = _this._buildArrayBuffer(Uint32Array, bufferViewData, accessor.byteOffset, accessor.count, numComponents, bufferView.byteStride);
|
|
|
|
+ break;
|
|
|
|
+ case GLTF2.EComponentType.FLOAT:
|
|
|
|
+ data = _this._buildArrayBuffer(Float32Array, bufferViewData, accessor.byteOffset, accessor.count, numComponents, bufferView.byteStride);
|
|
|
|
+ break;
|
|
|
|
+ default:
|
|
|
|
+ throw new Error(context + ": Invalid component type (" + accessor.componentType + ")");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ catch (e) {
|
|
|
|
+ throw new Error(context + ": " + e);
|
|
}
|
|
}
|
|
onSuccess(data);
|
|
onSuccess(data);
|
|
});
|
|
});
|
|
@@ -4295,30 +4331,25 @@ var BABYLON;
|
|
}
|
|
}
|
|
return 0;
|
|
return 0;
|
|
};
|
|
};
|
|
- GLTFLoader.prototype._buildArrayBuffer = function (typedArray, context, data, byteOffset, count, numComponents, byteStride) {
|
|
|
|
- try {
|
|
|
|
- var byteOffset = data.byteOffset + (byteOffset || 0);
|
|
|
|
- var targetLength = count * numComponents;
|
|
|
|
- if (byteStride == null || byteStride === numComponents * typedArray.BYTES_PER_ELEMENT) {
|
|
|
|
- return new typedArray(data.buffer, byteOffset, targetLength);
|
|
|
|
- }
|
|
|
|
- var elementStride = byteStride / typedArray.BYTES_PER_ELEMENT;
|
|
|
|
- var sourceBuffer = new typedArray(data.buffer, byteOffset, elementStride * count);
|
|
|
|
- var targetBuffer = new typedArray(targetLength);
|
|
|
|
- var sourceIndex = 0;
|
|
|
|
- var targetIndex = 0;
|
|
|
|
- while (targetIndex < targetLength) {
|
|
|
|
- for (var componentIndex = 0; componentIndex < numComponents; componentIndex++) {
|
|
|
|
- targetBuffer[targetIndex] = sourceBuffer[sourceIndex + componentIndex];
|
|
|
|
- targetIndex++;
|
|
|
|
- }
|
|
|
|
- sourceIndex += elementStride;
|
|
|
|
- }
|
|
|
|
- return targetBuffer;
|
|
|
|
|
|
+ GLTFLoader.prototype._buildArrayBuffer = function (typedArray, data, byteOffset, count, numComponents, byteStride) {
|
|
|
|
+ byteOffset = data.byteOffset + (byteOffset || 0);
|
|
|
|
+ var targetLength = count * numComponents;
|
|
|
|
+ if (byteStride == null || byteStride === numComponents * typedArray.BYTES_PER_ELEMENT) {
|
|
|
|
+ return new typedArray(data.buffer, byteOffset, targetLength);
|
|
}
|
|
}
|
|
- catch (e) {
|
|
|
|
- throw new Error(context + ": " + e);
|
|
|
|
|
|
+ var elementStride = byteStride / typedArray.BYTES_PER_ELEMENT;
|
|
|
|
+ var sourceBuffer = new typedArray(data.buffer, byteOffset, elementStride * count);
|
|
|
|
+ var targetBuffer = new typedArray(targetLength);
|
|
|
|
+ var sourceIndex = 0;
|
|
|
|
+ var targetIndex = 0;
|
|
|
|
+ while (targetIndex < targetLength) {
|
|
|
|
+ for (var componentIndex = 0; componentIndex < numComponents; componentIndex++) {
|
|
|
|
+ targetBuffer[targetIndex] = sourceBuffer[sourceIndex + componentIndex];
|
|
|
|
+ targetIndex++;
|
|
|
|
+ }
|
|
|
|
+ sourceIndex += elementStride;
|
|
}
|
|
}
|
|
|
|
+ return targetBuffer;
|
|
};
|
|
};
|
|
GLTFLoader.prototype._addPendingData = function (data) {
|
|
GLTFLoader.prototype._addPendingData = function (data) {
|
|
if (!this._renderReady) {
|
|
if (!this._renderReady) {
|
|
@@ -4337,10 +4368,16 @@ var BABYLON;
|
|
};
|
|
};
|
|
GLTFLoader.prototype._addLoaderPendingData = function (data) {
|
|
GLTFLoader.prototype._addLoaderPendingData = function (data) {
|
|
this._loaderPendingCount++;
|
|
this._loaderPendingCount++;
|
|
- this._loaderTrackers.forEach(function (tracker) { return tracker._addPendingData(data); });
|
|
|
|
|
|
+ for (var _i = 0, _a = this._loaderTrackers; _i < _a.length; _i++) {
|
|
|
|
+ var tracker = _a[_i];
|
|
|
|
+ tracker._addPendingData(data);
|
|
|
|
+ }
|
|
};
|
|
};
|
|
GLTFLoader.prototype._removeLoaderPendingData = function (data) {
|
|
GLTFLoader.prototype._removeLoaderPendingData = function (data) {
|
|
- this._loaderTrackers.forEach(function (tracker) { return tracker._removePendingData(data); });
|
|
|
|
|
|
+ for (var _i = 0, _a = this._loaderTrackers; _i < _a.length; _i++) {
|
|
|
|
+ var tracker = _a[_i];
|
|
|
|
+ tracker._removePendingData(data);
|
|
|
|
+ }
|
|
if (--this._loaderPendingCount === 0) {
|
|
if (--this._loaderPendingCount === 0) {
|
|
this._onComplete();
|
|
this._onComplete();
|
|
}
|
|
}
|
|
@@ -4522,12 +4559,12 @@ var BABYLON;
|
|
texture.dataReadyObservable.add(function (texture) {
|
|
texture.dataReadyObservable.add(function (texture) {
|
|
babylonTexture.updateURL(texture.url);
|
|
babylonTexture.updateURL(texture.url);
|
|
});
|
|
});
|
|
- var image = GLTF2.GLTFUtils.GetArrayItem(this._gltf.images, texture.source);
|
|
|
|
- if (!image) {
|
|
|
|
|
|
+ var image_1 = GLTF2.GLTFUtils.GetArrayItem(this._gltf.images, texture.source);
|
|
|
|
+ if (!image_1) {
|
|
throw new Error(context + ": Failed to find source " + texture.source);
|
|
throw new Error(context + ": Failed to find source " + texture.source);
|
|
}
|
|
}
|
|
- this._loadImage("#/images/" + image.index, image, function (data) {
|
|
|
|
- texture.url = URL.createObjectURL(new Blob([data], { type: image.mimeType }));
|
|
|
|
|
|
+ this._loadImage("#/images/" + image_1.index, image_1, function (data) {
|
|
|
|
+ texture.url = URL.createObjectURL(new Blob([data], { type: image_1.mimeType }));
|
|
texture.dataReadyObservable.notifyObservers(texture);
|
|
texture.dataReadyObservable.notifyObservers(texture);
|
|
});
|
|
});
|
|
}
|
|
}
|
|
@@ -4541,28 +4578,12 @@ var BABYLON;
|
|
return babylonTexture;
|
|
return babylonTexture;
|
|
};
|
|
};
|
|
GLTFLoader.prototype._loadImage = function (context, image, onSuccess) {
|
|
GLTFLoader.prototype._loadImage = function (context, image, onSuccess) {
|
|
- var _this = this;
|
|
|
|
if (image.uri) {
|
|
if (image.uri) {
|
|
- if (!GLTF2.GLTFUtils.ValidateUri(image.uri)) {
|
|
|
|
- throw new Error(context + ": Uri '" + image.uri + "' is invalid");
|
|
|
|
- }
|
|
|
|
if (GLTF2.GLTFUtils.IsBase64(image.uri)) {
|
|
if (GLTF2.GLTFUtils.IsBase64(image.uri)) {
|
|
onSuccess(new Uint8Array(GLTF2.GLTFUtils.DecodeBase64(image.uri)));
|
|
onSuccess(new Uint8Array(GLTF2.GLTFUtils.DecodeBase64(image.uri)));
|
|
}
|
|
}
|
|
else {
|
|
else {
|
|
- BABYLON.Tools.LoadFile(this._rootUrl + image.uri, function (data) {
|
|
|
|
- _this._tryCatchOnError(function () {
|
|
|
|
- onSuccess(data);
|
|
|
|
- });
|
|
|
|
- }, function (event) {
|
|
|
|
- _this._tryCatchOnError(function () {
|
|
|
|
- _this._onProgress(event);
|
|
|
|
- });
|
|
|
|
- }, this._babylonScene.database, true, function (request) {
|
|
|
|
- _this._tryCatchOnError(function () {
|
|
|
|
- throw new Error(context + ": Failed to load '" + image.uri + "'" + (request ? ": " + request.status + " " + request.statusText : ""));
|
|
|
|
- });
|
|
|
|
- });
|
|
|
|
|
|
+ this._loadUri(context, image.uri, onSuccess);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else {
|
|
else {
|
|
@@ -4573,6 +4594,28 @@ var BABYLON;
|
|
this._loadBufferViewAsync("#/bufferViews/" + bufferView.index, bufferView, onSuccess);
|
|
this._loadBufferViewAsync("#/bufferViews/" + bufferView.index, bufferView, onSuccess);
|
|
}
|
|
}
|
|
};
|
|
};
|
|
|
|
+ GLTFLoader.prototype._loadUri = function (context, uri, onSuccess) {
|
|
|
|
+ var _this = this;
|
|
|
|
+ if (!GLTF2.GLTFUtils.ValidateUri(uri)) {
|
|
|
|
+ throw new Error(context + ": Uri '" + uri + "' is invalid");
|
|
|
|
+ }
|
|
|
|
+ var request = BABYLON.Tools.LoadFile(this._rootUrl + uri, function (data) {
|
|
|
|
+ _this._tryCatchOnError(function () {
|
|
|
|
+ onSuccess(new Uint8Array(data));
|
|
|
|
+ });
|
|
|
|
+ }, function (event) {
|
|
|
|
+ _this._tryCatchOnError(function () {
|
|
|
|
+ _this._onProgress(event);
|
|
|
|
+ });
|
|
|
|
+ }, this._babylonScene.database, true, function (request) {
|
|
|
|
+ _this._tryCatchOnError(function () {
|
|
|
|
+ throw new Error(context + ": Failed to load '" + uri + "'" + (request ? ": " + request.status + " " + request.statusText : ""));
|
|
|
|
+ });
|
|
|
|
+ });
|
|
|
|
+ if (request) {
|
|
|
|
+ this._requests.push(request);
|
|
|
|
+ }
|
|
|
|
+ };
|
|
GLTFLoader.prototype._tryCatchOnError = function (handler) {
|
|
GLTFLoader.prototype._tryCatchOnError = function (handler) {
|
|
try {
|
|
try {
|
|
handler();
|
|
handler();
|
|
@@ -4735,8 +4778,8 @@ var BABYLON;
|
|
if (!extensions) {
|
|
if (!extensions) {
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
- for (var i = 0; i < extensions.length; i++) {
|
|
|
|
- var extension = extensions[i];
|
|
|
|
|
|
+ for (var _i = 0, extensions_1 = extensions; _i < extensions_1.length; _i++) {
|
|
|
|
+ var extension = extensions_1[_i];
|
|
if (extension.enabled && action(extension)) {
|
|
if (extension.enabled && action(extension)) {
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
@@ -4814,7 +4857,9 @@ var BABYLON;
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
setTimeout(function () {
|
|
setTimeout(function () {
|
|
- _this._loadNodeLOD(loader, context, nodes, index - 1, onComplete);
|
|
|
|
|
|
+ loader._tryCatchOnError(function () {
|
|
|
|
+ _this._loadNodeLOD(loader, context, nodes, index - 1, onComplete);
|
|
|
|
+ });
|
|
}, MSFTLOD.MinimalLODDelay);
|
|
}, MSFTLOD.MinimalLODDelay);
|
|
});
|
|
});
|
|
};
|
|
};
|
|
@@ -4843,7 +4888,9 @@ var BABYLON;
|
|
loader._executeWhenRenderReady(function () {
|
|
loader._executeWhenRenderReady(function () {
|
|
BABYLON.BaseTexture.WhenAllReady(babylonMaterial.getActiveTextures(), function () {
|
|
BABYLON.BaseTexture.WhenAllReady(babylonMaterial.getActiveTextures(), function () {
|
|
setTimeout(function () {
|
|
setTimeout(function () {
|
|
- _this._loadMaterialLOD(loader, context, materials, index - 1, assign, onComplete);
|
|
|
|
|
|
+ loader._tryCatchOnError(function () {
|
|
|
|
+ _this._loadMaterialLOD(loader, context, materials, index - 1, assign, onComplete);
|
|
|
|
+ });
|
|
}, MSFTLOD.MinimalLODDelay);
|
|
}, MSFTLOD.MinimalLODDelay);
|
|
});
|
|
});
|
|
});
|
|
});
|