|
@@ -2448,23 +2448,24 @@ var BABYLON;
|
|
|
BABYLON.Tools.Error("Extension with the same name '" + extension.name + "' already exists");
|
|
|
return;
|
|
|
}
|
|
|
- this.Extensions[extension.name] = extension;
|
|
|
- };
|
|
|
- GLTFLoader.LoadMaterial = function (index) {
|
|
|
- return BABYLON.GLTFFileLoader.GLTFLoaderV2._loadMaterial(index);
|
|
|
- };
|
|
|
- GLTFLoader.LoadCoreMaterial = function (index) {
|
|
|
- return BABYLON.GLTFFileLoader.GLTFLoaderV2._loadCoreMaterial(index);
|
|
|
- };
|
|
|
- GLTFLoader.LoadCommonMaterialProperties = function (material) {
|
|
|
- return BABYLON.GLTFFileLoader.GLTFLoaderV2._loadCommonMaterialProperties(material);
|
|
|
- };
|
|
|
- GLTFLoader.LoadAlphaProperties = function (material) {
|
|
|
- return BABYLON.GLTFFileLoader.GLTFLoaderV2._loadAlphaProperties(material);
|
|
|
- };
|
|
|
- GLTFLoader.LoadTexture = function (textureInfo) {
|
|
|
- return BABYLON.GLTFFileLoader.GLTFLoaderV2._loadTexture(textureInfo);
|
|
|
+ GLTFLoader.Extensions[extension.name] = extension;
|
|
|
+ // Keep the order of registration so that extensions registered first are called first.
|
|
|
+ GLTF2.GLTFLoaderExtension._Extensions.push(extension);
|
|
|
};
|
|
|
+ Object.defineProperty(GLTFLoader.prototype, "gltf", {
|
|
|
+ get: function () {
|
|
|
+ return this._gltf;
|
|
|
+ },
|
|
|
+ enumerable: true,
|
|
|
+ configurable: true
|
|
|
+ });
|
|
|
+ Object.defineProperty(GLTFLoader.prototype, "babylonScene", {
|
|
|
+ get: function () {
|
|
|
+ return this._babylonScene;
|
|
|
+ },
|
|
|
+ enumerable: true,
|
|
|
+ configurable: true
|
|
|
+ });
|
|
|
GLTFLoader.prototype.importMeshAsync = function (meshesNames, scene, data, rootUrl, onSuccess, onError) {
|
|
|
var _this = this;
|
|
|
this._loadAsync(meshesNames, scene, data, rootUrl, function () {
|
|
@@ -2493,28 +2494,34 @@ var BABYLON;
|
|
|
this._loadAsync(null, scene, data, rootUrl, onSuccess, onError);
|
|
|
};
|
|
|
GLTFLoader.prototype._loadAsync = function (nodeNames, scene, data, rootUrl, onSuccess, onError) {
|
|
|
- var _this = this;
|
|
|
scene.useRightHandedSystem = true;
|
|
|
this._clear();
|
|
|
this._loadData(data);
|
|
|
this._babylonScene = scene;
|
|
|
this._rootUrl = rootUrl;
|
|
|
- this._onLoaded = function () {
|
|
|
- _this._showMeshes();
|
|
|
- _this._startAnimations();
|
|
|
- if (_this._errors.length === 0) {
|
|
|
- onSuccess();
|
|
|
- }
|
|
|
- else {
|
|
|
- _this._errors.forEach(function (error) { return BABYLON.Tools.Error(error); });
|
|
|
- onError();
|
|
|
- }
|
|
|
- _this._clear();
|
|
|
- };
|
|
|
- this._addPendingData(this);
|
|
|
+ this._onSuccess = onSuccess;
|
|
|
+ this._onError = onError;
|
|
|
+ this.addPendingData(this);
|
|
|
this._loadScene(nodeNames);
|
|
|
this._loadAnimations();
|
|
|
- this._removePendingData(this);
|
|
|
+ this.removePendingData(this);
|
|
|
+ };
|
|
|
+ GLTFLoader.prototype._onRenderReady = function () {
|
|
|
+ this._showMeshes();
|
|
|
+ this._startAnimations();
|
|
|
+ if (this._errors.length === 0) {
|
|
|
+ this._onSuccess();
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ this._errors.forEach(function (error) { return BABYLON.Tools.Error(error); });
|
|
|
+ this._errors = [];
|
|
|
+ this._onError();
|
|
|
+ }
|
|
|
+ };
|
|
|
+ GLTFLoader.prototype._onLoaderComplete = function () {
|
|
|
+ this._errors.forEach(function (error) { return BABYLON.Tools.Error(error); });
|
|
|
+ this._errors = [];
|
|
|
+ this._clear();
|
|
|
};
|
|
|
GLTFLoader.prototype._loadData = function (data) {
|
|
|
this._gltf = data.json;
|
|
@@ -2557,13 +2564,6 @@ var BABYLON;
|
|
|
}
|
|
|
};
|
|
|
GLTFLoader.prototype._clear = function () {
|
|
|
- this._gltf = undefined;
|
|
|
- this._pendingCount = 0;
|
|
|
- this._onLoaded = undefined;
|
|
|
- this._errors = [];
|
|
|
- this._babylonScene = undefined;
|
|
|
- this._rootUrl = undefined;
|
|
|
- this._defaultMaterial = undefined;
|
|
|
// Revoke object urls created during load
|
|
|
if (this._gltf && this._gltf.textures) {
|
|
|
for (var i = 0; i < this._gltf.textures.length; i++) {
|
|
@@ -2573,14 +2573,42 @@ var BABYLON;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ this._gltf = undefined;
|
|
|
+ this._errors = [];
|
|
|
+ this._babylonScene = undefined;
|
|
|
+ this._rootUrl = undefined;
|
|
|
+ this._defaultMaterial = undefined;
|
|
|
+ this._onSuccess = undefined;
|
|
|
+ this._onError = undefined;
|
|
|
+ this._renderReady = false;
|
|
|
+ this._renderPendingCount = 0;
|
|
|
+ this._loaderPendingCount = 0;
|
|
|
};
|
|
|
GLTFLoader.prototype._loadScene = function (nodeNames) {
|
|
|
var _this = this;
|
|
|
- nodeNames = (nodeNames === "") ? null : nodeNames;
|
|
|
- nodeNames = (nodeNames instanceof Array) ? nodeNames : [nodeNames];
|
|
|
var scene = this._gltf.scenes[this._gltf.scene || 0];
|
|
|
- this._traverseScene(nodeNames, scene, function (node) { return _this._loadSkin(node); });
|
|
|
- this._traverseScene(nodeNames, scene, function (node, parentNode) { return _this._loadMesh(node, parentNode); });
|
|
|
+ var nodeIndices = scene.nodes;
|
|
|
+ this._traverseNodes(nodeIndices, function (node, index, parentNode) {
|
|
|
+ node.index = index;
|
|
|
+ node.parent = parentNode;
|
|
|
+ return true;
|
|
|
+ });
|
|
|
+ if (nodeNames) {
|
|
|
+ if (!(nodeNames instanceof Array)) {
|
|
|
+ nodeNames = [nodeNames];
|
|
|
+ }
|
|
|
+ var filteredNodeIndices = new Array();
|
|
|
+ this._traverseNodes(nodeIndices, function (node) {
|
|
|
+ if (nodeNames.indexOf(node.name) === -1) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ filteredNodeIndices.push(node.index);
|
|
|
+ return false;
|
|
|
+ });
|
|
|
+ nodeIndices = filteredNodeIndices;
|
|
|
+ }
|
|
|
+ this._traverseNodes(nodeIndices, function (node) { return _this._loadSkin(node); });
|
|
|
+ this._traverseNodes(nodeIndices, function (node) { return _this._loadMesh(node); });
|
|
|
};
|
|
|
GLTFLoader.prototype._loadSkin = function (node) {
|
|
|
var _this = this;
|
|
@@ -2602,7 +2630,7 @@ var BABYLON;
|
|
|
}
|
|
|
var accessor = this._gltf.accessors[skin.inverseBindMatrices];
|
|
|
this._loadAccessorAsync(accessor, function (data) {
|
|
|
- _this._traverseNode(null, skin.skeleton, function (node, parent) { return _this._updateBone(node, parent, skin, data); });
|
|
|
+ _this._traverseNode(skin.skeleton, function (node, index, parent) { return _this._updateBone(node, parent, skin, data); });
|
|
|
});
|
|
|
}
|
|
|
return true;
|
|
@@ -2631,7 +2659,7 @@ var BABYLON;
|
|
|
node.babylonAnimationTargets.push(babylonBone);
|
|
|
return babylonBone;
|
|
|
};
|
|
|
- GLTFLoader.prototype._loadMesh = function (node, parentNode) {
|
|
|
+ GLTFLoader.prototype._loadMesh = function (node) {
|
|
|
var babylonMesh = new BABYLON.Mesh(node.name || "mesh" + node.index, this._babylonScene);
|
|
|
babylonMesh.isVisible = false;
|
|
|
this._loadTransform(node, babylonMesh);
|
|
@@ -2639,7 +2667,7 @@ var BABYLON;
|
|
|
var mesh = this._gltf.meshes[node.mesh];
|
|
|
this._loadMeshData(node, mesh, babylonMesh);
|
|
|
}
|
|
|
- babylonMesh.parent = parentNode ? parentNode.babylonMesh : null;
|
|
|
+ babylonMesh.parent = node.parent ? node.parent.babylonMesh : null;
|
|
|
node.babylonMesh = babylonMesh;
|
|
|
node.babylonAnimationTargets = node.babylonAnimationTargets || [];
|
|
|
node.babylonAnimationTargets.push(node.babylonMesh);
|
|
@@ -2655,17 +2683,16 @@ var BABYLON;
|
|
|
GLTFLoader.prototype._loadMeshData = function (node, mesh, babylonMesh) {
|
|
|
var _this = this;
|
|
|
babylonMesh.name = mesh.name || babylonMesh.name;
|
|
|
- babylonMesh.subMeshes = [];
|
|
|
- var multiMaterial = new BABYLON.MultiMaterial(babylonMesh.name, this._babylonScene);
|
|
|
- babylonMesh.material = multiMaterial;
|
|
|
+ var babylonMultiMaterial = new BABYLON.MultiMaterial(babylonMesh.name, this._babylonScene);
|
|
|
+ babylonMesh.material = babylonMultiMaterial;
|
|
|
var geometry = new BABYLON.Geometry(babylonMesh.name, this._babylonScene, null, false, babylonMesh);
|
|
|
var vertexData = new BABYLON.VertexData();
|
|
|
vertexData.positions = [];
|
|
|
vertexData.indices = [];
|
|
|
var subMeshInfos = [];
|
|
|
- var primitivesLoaded = 0;
|
|
|
- var numPrimitives = mesh.primitives.length;
|
|
|
- var _loop_1 = function () {
|
|
|
+ var loadedPrimitives = 0;
|
|
|
+ var totalPrimitives = mesh.primitives.length;
|
|
|
+ var _loop_1 = function (i) {
|
|
|
var primitive = mesh.primitives[i];
|
|
|
if (primitive.mode && primitive.mode !== GLTF2.EMeshPrimitiveMode.TRIANGLES) {
|
|
|
// TODO: handle other primitive modes
|
|
@@ -2675,28 +2702,40 @@ var BABYLON;
|
|
|
this_1._loadVertexDataAsync(primitive, function (subVertexData) {
|
|
|
_this._loadMorphTargetsData(mesh, primitive, subVertexData, babylonMesh);
|
|
|
subMeshInfos.push({
|
|
|
- materialIndex: multiMaterial.subMaterials.length,
|
|
|
+ materialIndex: i,
|
|
|
verticesStart: vertexData.positions.length,
|
|
|
verticesCount: subVertexData.positions.length,
|
|
|
indicesStart: vertexData.indices.length,
|
|
|
indicesCount: subVertexData.indices.length
|
|
|
});
|
|
|
- var subMaterial = primitive.material === undefined ? _this._getDefaultMaterial() : GLTF2.GLTFLoaderExtension.LoadMaterial(primitive.material);
|
|
|
- multiMaterial.subMaterials.push(subMaterial);
|
|
|
vertexData.merge(subVertexData);
|
|
|
- if (++primitivesLoaded === numPrimitives) {
|
|
|
+ if (primitive.material === undefined) {
|
|
|
+ babylonMultiMaterial.subMaterials[i] = _this._getDefaultMaterial();
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ _this.loadMaterial(primitive.material, function (babylonSubMaterial) {
|
|
|
+ if (_this._renderReady) {
|
|
|
+ babylonSubMaterial.forceCompilation(babylonMesh, function (babylonSubMaterial) {
|
|
|
+ babylonMultiMaterial.subMaterials[i] = babylonSubMaterial;
|
|
|
+ });
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ babylonMultiMaterial.subMaterials[i] = babylonSubMaterial;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if (++loadedPrimitives === totalPrimitives) {
|
|
|
geometry.setAllVerticesData(vertexData, false);
|
|
|
- // Sub meshes must be created after setting vertex data because of mesh._createGlobalSubMesh.
|
|
|
- for (var i = 0; i < subMeshInfos.length; i++) {
|
|
|
- var info = subMeshInfos[i];
|
|
|
- new BABYLON.SubMesh(info.materialIndex, info.verticesStart, info.verticesCount, info.indicesStart, info.indicesCount, babylonMesh);
|
|
|
- }
|
|
|
+ // TODO: optimize this so that sub meshes can be created without being overwritten after setting vertex data.
|
|
|
+ // Sub meshes must be cleared and created after setting vertex data because of mesh._createGlobalSubMesh.
|
|
|
+ babylonMesh.subMeshes = [];
|
|
|
+ subMeshInfos.forEach(function (info) { return new BABYLON.SubMesh(info.materialIndex, info.verticesStart, info.verticesCount, info.indicesStart, info.indicesCount, babylonMesh); });
|
|
|
}
|
|
|
});
|
|
|
};
|
|
|
var this_1 = this;
|
|
|
- for (var i = 0; i < numPrimitives; i++) {
|
|
|
- _loop_1();
|
|
|
+ for (var i = 0; i < totalPrimitives; i++) {
|
|
|
+ _loop_1(i);
|
|
|
}
|
|
|
};
|
|
|
GLTFLoader.prototype._loadVertexDataAsync = function (primitive, onSuccess) {
|
|
@@ -2708,7 +2747,7 @@ var BABYLON;
|
|
|
}
|
|
|
var vertexData = new BABYLON.VertexData();
|
|
|
var loadedAttributes = 0;
|
|
|
- var numAttributes = Object.keys(attributes).length;
|
|
|
+ var totalAttributes = Object.keys(attributes).length;
|
|
|
var _loop_2 = function (semantic) {
|
|
|
accessor = this_2._gltf.accessors[attributes[semantic]];
|
|
|
this_2._loadAccessorAsync(accessor, function (data) {
|
|
@@ -2741,7 +2780,7 @@ var BABYLON;
|
|
|
BABYLON.Tools.Warn("Ignoring unrecognized semantic '" + semantic + "'");
|
|
|
break;
|
|
|
}
|
|
|
- if (++loadedAttributes === numAttributes) {
|
|
|
+ if (++loadedAttributes === totalAttributes) {
|
|
|
var indicesAccessor = _this._gltf.accessors[primitive.indices];
|
|
|
if (indicesAccessor) {
|
|
|
_this._loadAccessorAsync(indicesAccessor, function (data) {
|
|
@@ -2848,34 +2887,21 @@ var BABYLON;
|
|
|
babylonMesh.rotationQuaternion = rotation;
|
|
|
babylonMesh.scaling = scaling;
|
|
|
};
|
|
|
- GLTFLoader.prototype._traverseScene = function (nodeNames, scene, action) {
|
|
|
- var nodes = scene.nodes;
|
|
|
- if (nodes) {
|
|
|
- for (var i = 0; i < nodes.length; i++) {
|
|
|
- this._traverseNode(nodeNames, nodes[i], action);
|
|
|
- }
|
|
|
+ GLTFLoader.prototype._traverseNodes = function (indices, action, parentNode) {
|
|
|
+ if (parentNode === void 0) { parentNode = null; }
|
|
|
+ for (var i = 0; i < indices.length; i++) {
|
|
|
+ this._traverseNode(indices[i], action, parentNode);
|
|
|
}
|
|
|
};
|
|
|
- GLTFLoader.prototype._traverseNode = function (nodeNames, index, action, parentNode) {
|
|
|
+ GLTFLoader.prototype._traverseNode = function (index, action, parentNode) {
|
|
|
if (parentNode === void 0) { parentNode = null; }
|
|
|
var node = this._gltf.nodes[index];
|
|
|
- if (nodeNames) {
|
|
|
- if (nodeNames.indexOf(node.name)) {
|
|
|
- // load all children
|
|
|
- nodeNames = null;
|
|
|
- }
|
|
|
- else {
|
|
|
- // skip this node tree
|
|
|
- return;
|
|
|
- }
|
|
|
- }
|
|
|
- node.index = index;
|
|
|
- if (!action(node, parentNode)) {
|
|
|
+ if (!action(node, index, parentNode)) {
|
|
|
return;
|
|
|
}
|
|
|
if (node.children) {
|
|
|
for (var i = 0; i < node.children.length; i++) {
|
|
|
- this._traverseNode(nodeNames, node.children[i], action, node);
|
|
|
+ this._traverseNode(node.children[i], action, node);
|
|
|
}
|
|
|
}
|
|
|
};
|
|
@@ -3004,11 +3030,11 @@ var BABYLON;
|
|
|
GLTFLoader.prototype._loadBufferAsync = function (index, onSuccess) {
|
|
|
var _this = this;
|
|
|
var buffer = this._gltf.buffers[index];
|
|
|
- this._addPendingData(buffer);
|
|
|
+ this.addPendingData(buffer);
|
|
|
if (buffer.loadedData) {
|
|
|
setTimeout(function () {
|
|
|
onSuccess(buffer.loadedData);
|
|
|
- _this._removePendingData(buffer);
|
|
|
+ _this.removePendingData(buffer);
|
|
|
});
|
|
|
}
|
|
|
else if (GLTF2.GLTFUtils.IsBase64(buffer.uri)) {
|
|
@@ -3016,20 +3042,20 @@ var BABYLON;
|
|
|
buffer.loadedData = new Uint8Array(data);
|
|
|
setTimeout(function () {
|
|
|
onSuccess(buffer.loadedData);
|
|
|
- _this._removePendingData(buffer);
|
|
|
+ _this.removePendingData(buffer);
|
|
|
});
|
|
|
}
|
|
|
else if (buffer.loadedObservable) {
|
|
|
buffer.loadedObservable.add(function (buffer) {
|
|
|
onSuccess(buffer.loadedData);
|
|
|
- _this._removePendingData(buffer);
|
|
|
+ _this.removePendingData(buffer);
|
|
|
});
|
|
|
}
|
|
|
else {
|
|
|
buffer.loadedObservable = new BABYLON.Observable();
|
|
|
buffer.loadedObservable.add(function (buffer) {
|
|
|
onSuccess(buffer.loadedData);
|
|
|
- _this._removePendingData(buffer);
|
|
|
+ _this.removePendingData(buffer);
|
|
|
});
|
|
|
BABYLON.Tools.LoadFile(this._rootUrl + buffer.uri, function (data) {
|
|
|
buffer.loadedData = new Uint8Array(data);
|
|
@@ -3037,7 +3063,7 @@ var BABYLON;
|
|
|
buffer.loadedObservable = null;
|
|
|
}, null, null, true, function (request) {
|
|
|
_this._errors.push("Failed to load file '" + buffer.uri + "': " + request.statusText + "(" + request.status + ")");
|
|
|
- _this._removePendingData(buffer);
|
|
|
+ _this.removePendingData(buffer);
|
|
|
});
|
|
|
}
|
|
|
};
|
|
@@ -3084,12 +3110,27 @@ var BABYLON;
|
|
|
var byteLength = accessor.count * GLTF2.GLTFUtils.GetByteStrideFromType(accessor);
|
|
|
this._loadBufferViewAsync(bufferView, byteOffset, byteLength, accessor.componentType, onSuccess);
|
|
|
};
|
|
|
- GLTFLoader.prototype._addPendingData = function (data) {
|
|
|
- this._pendingCount++;
|
|
|
+ GLTFLoader.prototype.addPendingData = function (data) {
|
|
|
+ if (!this._renderReady) {
|
|
|
+ this._renderPendingCount++;
|
|
|
+ }
|
|
|
+ this.addLoaderPendingData(data);
|
|
|
+ };
|
|
|
+ GLTFLoader.prototype.removePendingData = function (data) {
|
|
|
+ if (!this._renderReady) {
|
|
|
+ if (--this._renderPendingCount === 0) {
|
|
|
+ this._renderReady = true;
|
|
|
+ this._onRenderReady();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ this.removeLoaderPendingData(data);
|
|
|
+ };
|
|
|
+ GLTFLoader.prototype.addLoaderPendingData = function (data) {
|
|
|
+ this._loaderPendingCount++;
|
|
|
};
|
|
|
- GLTFLoader.prototype._removePendingData = function (data) {
|
|
|
- if (--this._pendingCount === 0) {
|
|
|
- this._onLoaded();
|
|
|
+ GLTFLoader.prototype.removeLoaderPendingData = function (data) {
|
|
|
+ if (--this._loaderPendingCount === 0) {
|
|
|
+ this._onLoaderComplete();
|
|
|
}
|
|
|
};
|
|
|
GLTFLoader.prototype._getDefaultMaterial = function () {
|
|
@@ -3106,46 +3147,49 @@ var BABYLON;
|
|
|
}
|
|
|
return this._defaultMaterial;
|
|
|
};
|
|
|
- GLTFLoader.prototype._loadMaterial = function (index) {
|
|
|
- var materials = this._gltf.materials;
|
|
|
- var material = materials ? materials[index] : null;
|
|
|
- if (!material) {
|
|
|
- BABYLON.Tools.Warn("Material index (" + index + ") does not exist");
|
|
|
- return null;
|
|
|
- }
|
|
|
- material.babylonMaterial = new BABYLON.PBRMaterial(material.name || "mat" + index, this._babylonScene);
|
|
|
- material.babylonMaterial.sideOrientation = BABYLON.Material.CounterClockWiseSideOrientation;
|
|
|
- material.babylonMaterial.useScalarInLinearSpace = true;
|
|
|
- return material;
|
|
|
- };
|
|
|
- GLTFLoader.prototype._loadCoreMaterial = function (index) {
|
|
|
- var material = this._loadMaterial(index);
|
|
|
- if (!material) {
|
|
|
- return null;
|
|
|
- }
|
|
|
- this._loadCommonMaterialProperties(material);
|
|
|
+ GLTFLoader.prototype._loadMaterialMetallicRoughnessProperties = function (material) {
|
|
|
// Ensure metallic workflow
|
|
|
material.babylonMaterial.metallic = 1;
|
|
|
material.babylonMaterial.roughness = 1;
|
|
|
var properties = material.pbrMetallicRoughness;
|
|
|
- if (properties) {
|
|
|
- material.babylonMaterial.albedoColor = properties.baseColorFactor ? BABYLON.Color3.FromArray(properties.baseColorFactor) : new BABYLON.Color3(1, 1, 1);
|
|
|
- material.babylonMaterial.metallic = properties.metallicFactor === undefined ? 1 : properties.metallicFactor;
|
|
|
- material.babylonMaterial.roughness = properties.roughnessFactor === undefined ? 1 : properties.roughnessFactor;
|
|
|
- if (properties.baseColorTexture) {
|
|
|
- material.babylonMaterial.albedoTexture = this._loadTexture(properties.baseColorTexture);
|
|
|
- this._loadAlphaProperties(material);
|
|
|
- }
|
|
|
- if (properties.metallicRoughnessTexture) {
|
|
|
- material.babylonMaterial.metallicTexture = this._loadTexture(properties.metallicRoughnessTexture);
|
|
|
- material.babylonMaterial.useMetallnessFromMetallicTextureBlue = true;
|
|
|
- material.babylonMaterial.useRoughnessFromMetallicTextureGreen = true;
|
|
|
- material.babylonMaterial.useRoughnessFromMetallicTextureAlpha = false;
|
|
|
- }
|
|
|
+ if (!properties) {
|
|
|
+ return;
|
|
|
}
|
|
|
- return material.babylonMaterial;
|
|
|
+ material.babylonMaterial.albedoColor = properties.baseColorFactor ? BABYLON.Color3.FromArray(properties.baseColorFactor) : new BABYLON.Color3(1, 1, 1);
|
|
|
+ material.babylonMaterial.metallic = properties.metallicFactor === undefined ? 1 : properties.metallicFactor;
|
|
|
+ material.babylonMaterial.roughness = properties.roughnessFactor === undefined ? 1 : properties.roughnessFactor;
|
|
|
+ if (properties.baseColorTexture) {
|
|
|
+ material.babylonMaterial.albedoTexture = this.loadTexture(properties.baseColorTexture);
|
|
|
+ this.loadMaterialAlphaProperties(material);
|
|
|
+ }
|
|
|
+ if (properties.metallicRoughnessTexture) {
|
|
|
+ material.babylonMaterial.metallicTexture = this.loadTexture(properties.metallicRoughnessTexture);
|
|
|
+ material.babylonMaterial.useMetallnessFromMetallicTextureBlue = true;
|
|
|
+ material.babylonMaterial.useRoughnessFromMetallicTextureGreen = true;
|
|
|
+ material.babylonMaterial.useRoughnessFromMetallicTextureAlpha = false;
|
|
|
+ }
|
|
|
+ };
|
|
|
+ GLTFLoader.prototype.loadMaterial = function (index, assign) {
|
|
|
+ var material = this._gltf.materials[index];
|
|
|
+ material.index = index;
|
|
|
+ if (material.babylonMaterial) {
|
|
|
+ assign(material.babylonMaterial);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (GLTF2.GLTFLoaderExtension.LoadMaterial(this, material, assign)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ this.createPbrMaterial(material);
|
|
|
+ this.loadMaterialBaseProperties(material);
|
|
|
+ this._loadMaterialMetallicRoughnessProperties(material);
|
|
|
+ assign(material.babylonMaterial);
|
|
|
+ };
|
|
|
+ GLTFLoader.prototype.createPbrMaterial = function (material) {
|
|
|
+ material.babylonMaterial = new BABYLON.PBRMaterial(material.name || "mat" + material.index, this._babylonScene);
|
|
|
+ material.babylonMaterial.sideOrientation = BABYLON.Material.CounterClockWiseSideOrientation;
|
|
|
+ material.babylonMaterial.useScalarInLinearSpace = true;
|
|
|
};
|
|
|
- GLTFLoader.prototype._loadCommonMaterialProperties = function (material) {
|
|
|
+ GLTFLoader.prototype.loadMaterialBaseProperties = function (material) {
|
|
|
material.babylonMaterial.useEmissiveAsIllumination = (material.emissiveFactor || material.emissiveTexture) ? true : false;
|
|
|
material.babylonMaterial.emissiveColor = material.emissiveFactor ? BABYLON.Color3.FromArray(material.emissiveFactor) : new BABYLON.Color3(0, 0, 0);
|
|
|
if (material.doubleSided) {
|
|
@@ -3153,23 +3197,23 @@ var BABYLON;
|
|
|
material.babylonMaterial.twoSidedLighting = true;
|
|
|
}
|
|
|
if (material.normalTexture) {
|
|
|
- material.babylonMaterial.bumpTexture = this._loadTexture(material.normalTexture);
|
|
|
+ material.babylonMaterial.bumpTexture = this.loadTexture(material.normalTexture);
|
|
|
if (material.normalTexture.scale !== undefined) {
|
|
|
material.babylonMaterial.bumpTexture.level = material.normalTexture.scale;
|
|
|
}
|
|
|
}
|
|
|
if (material.occlusionTexture) {
|
|
|
- material.babylonMaterial.ambientTexture = this._loadTexture(material.occlusionTexture);
|
|
|
+ material.babylonMaterial.ambientTexture = this.loadTexture(material.occlusionTexture);
|
|
|
material.babylonMaterial.useAmbientInGrayScale = true;
|
|
|
if (material.occlusionTexture.strength !== undefined) {
|
|
|
material.babylonMaterial.ambientTextureStrength = material.occlusionTexture.strength;
|
|
|
}
|
|
|
}
|
|
|
if (material.emissiveTexture) {
|
|
|
- material.babylonMaterial.emissiveTexture = this._loadTexture(material.emissiveTexture);
|
|
|
+ material.babylonMaterial.emissiveTexture = this.loadTexture(material.emissiveTexture);
|
|
|
}
|
|
|
};
|
|
|
- GLTFLoader.prototype._loadAlphaProperties = function (material) {
|
|
|
+ GLTFLoader.prototype.loadMaterialAlphaProperties = function (material) {
|
|
|
var alphaMode = material.alphaMode || "OPAQUE";
|
|
|
switch (alphaMode) {
|
|
|
case "OPAQUE":
|
|
@@ -3178,18 +3222,17 @@ var BABYLON;
|
|
|
case "MASK":
|
|
|
material.babylonMaterial.albedoTexture.hasAlpha = true;
|
|
|
material.babylonMaterial.useAlphaFromAlbedoTexture = false;
|
|
|
- material.babylonMaterial.alphaMode = BABYLON.Engine.ALPHA_DISABLE;
|
|
|
break;
|
|
|
case "BLEND":
|
|
|
material.babylonMaterial.albedoTexture.hasAlpha = true;
|
|
|
material.babylonMaterial.useAlphaFromAlbedoTexture = true;
|
|
|
- material.babylonMaterial.alphaMode = BABYLON.Engine.ALPHA_COMBINE;
|
|
|
break;
|
|
|
default:
|
|
|
- BABYLON.Tools.Error("Invalid alpha mode '" + material.alphaMode + "'");
|
|
|
+ BABYLON.Tools.Warn("Invalid alpha mode '" + material.alphaMode + "'");
|
|
|
+ break;
|
|
|
}
|
|
|
};
|
|
|
- GLTFLoader.prototype._loadTexture = function (textureInfo) {
|
|
|
+ GLTFLoader.prototype.loadTexture = function (textureInfo) {
|
|
|
var _this = this;
|
|
|
var texture = this._gltf.textures[textureInfo.index];
|
|
|
var texCoord = textureInfo.texCoord || 0;
|
|
@@ -3232,12 +3275,12 @@ var BABYLON;
|
|
|
var sampler = (texture.sampler === undefined ? {} : this._gltf.samplers[texture.sampler]);
|
|
|
var noMipMaps = (sampler.minFilter === GLTF2.ETextureMinFilter.NEAREST || sampler.minFilter === GLTF2.ETextureMinFilter.LINEAR);
|
|
|
var samplingMode = GLTF2.GLTFUtils.GetTextureFilterMode(sampler.minFilter);
|
|
|
- this._addPendingData(texture);
|
|
|
+ this.addPendingData(texture);
|
|
|
var babylonTexture = new BABYLON.Texture(url, this._babylonScene, noMipMaps, false, samplingMode, function () {
|
|
|
- _this._removePendingData(texture);
|
|
|
+ _this.removePendingData(texture);
|
|
|
}, function () {
|
|
|
_this._errors.push("Failed to load texture '" + source.uri + "'");
|
|
|
- _this._removePendingData(texture);
|
|
|
+ _this.removePendingData(texture);
|
|
|
});
|
|
|
babylonTexture.coordinatesIndex = texCoord;
|
|
|
babylonTexture.wrapU = GLTF2.GLTFUtils.GetWrapMode(sampler.wrapS);
|
|
@@ -3358,42 +3401,39 @@ var BABYLON;
|
|
|
var GLTF2;
|
|
|
(function (GLTF2) {
|
|
|
var GLTFLoaderExtension = (function () {
|
|
|
- function GLTFLoaderExtension(name) {
|
|
|
+ function GLTFLoaderExtension() {
|
|
|
this.enabled = true;
|
|
|
- this._name = name;
|
|
|
}
|
|
|
- Object.defineProperty(GLTFLoaderExtension.prototype, "name", {
|
|
|
- get: function () {
|
|
|
- return this._name;
|
|
|
- },
|
|
|
- enumerable: true,
|
|
|
- configurable: true
|
|
|
- });
|
|
|
- GLTFLoaderExtension.prototype.loadMaterial = function (index) { return null; };
|
|
|
- // ---------
|
|
|
- // Utilities
|
|
|
- // ---------
|
|
|
- GLTFLoaderExtension.LoadMaterial = function (index) {
|
|
|
- for (var extensionName in GLTF2.GLTFLoader.Extensions) {
|
|
|
- var extension = GLTF2.GLTFLoader.Extensions[extensionName];
|
|
|
- if (extension.enabled) {
|
|
|
- var babylonMaterial = extension.loadMaterial(index);
|
|
|
- if (babylonMaterial) {
|
|
|
- return babylonMaterial;
|
|
|
- }
|
|
|
+ GLTFLoaderExtension.prototype.loadMaterial = function (loader, material, assign) { return false; };
|
|
|
+ GLTFLoaderExtension.LoadMaterial = function (loader, material, assign) {
|
|
|
+ return this._ApplyExtensions(function (extension) { return extension.loadMaterial(loader, material, assign); });
|
|
|
+ };
|
|
|
+ GLTFLoaderExtension._ApplyExtensions = function (action) {
|
|
|
+ var extensions = GLTFLoaderExtension._Extensions;
|
|
|
+ if (!extensions) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ for (var i = 0; i < extensions.length; i++) {
|
|
|
+ var extension = extensions[i];
|
|
|
+ if (extension.enabled && action(extension)) {
|
|
|
+ return true;
|
|
|
}
|
|
|
}
|
|
|
- return GLTF2.GLTFLoader.LoadCoreMaterial(index);
|
|
|
+ return false;
|
|
|
};
|
|
|
return GLTFLoaderExtension;
|
|
|
}());
|
|
|
+ //
|
|
|
+ // Utilities
|
|
|
+ //
|
|
|
+ GLTFLoaderExtension._Extensions = [];
|
|
|
GLTF2.GLTFLoaderExtension = GLTFLoaderExtension;
|
|
|
})(GLTF2 = BABYLON.GLTF2 || (BABYLON.GLTF2 = {}));
|
|
|
})(BABYLON || (BABYLON = {}));
|
|
|
|
|
|
//# sourceMappingURL=babylon.glTFLoaderExtension.js.map
|
|
|
|
|
|
-/// <reference path="../../../../dist/preview release/babylon.d.ts"/>
|
|
|
+/// <reference path="../../../../../dist/preview release/babylon.d.ts"/>
|
|
|
var __extends = (this && this.__extends) || (function () {
|
|
|
var extendStatics = Object.setPrototypeOf ||
|
|
|
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
@@ -3408,43 +3448,122 @@ var BABYLON;
|
|
|
(function (BABYLON) {
|
|
|
var GLTF2;
|
|
|
(function (GLTF2) {
|
|
|
- var GLTFMaterialsPbrSpecularGlossinessExtension = (function (_super) {
|
|
|
- __extends(GLTFMaterialsPbrSpecularGlossinessExtension, _super);
|
|
|
- function GLTFMaterialsPbrSpecularGlossinessExtension() {
|
|
|
- return _super.call(this, "KHR_materials_pbrSpecularGlossiness") || this;
|
|
|
- }
|
|
|
- GLTFMaterialsPbrSpecularGlossinessExtension.prototype.loadMaterial = function (index) {
|
|
|
- var material = GLTF2.GLTFLoader.LoadMaterial(index);
|
|
|
- if (!material || !material.extensions)
|
|
|
- return null;
|
|
|
- var properties = material.extensions[this.name];
|
|
|
- if (!properties)
|
|
|
- return null;
|
|
|
- GLTF2.GLTFLoader.LoadCommonMaterialProperties(material);
|
|
|
- //
|
|
|
- // Load Factors
|
|
|
- //
|
|
|
- material.babylonMaterial.albedoColor = properties.diffuseFactor ? BABYLON.Color3.FromArray(properties.diffuseFactor) : new BABYLON.Color3(1, 1, 1);
|
|
|
- material.babylonMaterial.reflectivityColor = properties.specularFactor ? BABYLON.Color3.FromArray(properties.specularFactor) : new BABYLON.Color3(1, 1, 1);
|
|
|
- material.babylonMaterial.microSurface = properties.glossinessFactor === undefined ? 1 : properties.glossinessFactor;
|
|
|
- //
|
|
|
- // Load Textures
|
|
|
- //
|
|
|
- if (properties.diffuseTexture) {
|
|
|
- material.babylonMaterial.albedoTexture = GLTF2.GLTFLoader.LoadTexture(properties.diffuseTexture);
|
|
|
- GLTF2.GLTFLoader.LoadAlphaProperties(material);
|
|
|
- }
|
|
|
- if (properties.specularGlossinessTexture) {
|
|
|
- material.babylonMaterial.reflectivityTexture = GLTF2.GLTFLoader.LoadTexture(properties.specularGlossinessTexture);
|
|
|
- material.babylonMaterial.useMicroSurfaceFromReflectivityMapAlpha = true;
|
|
|
- }
|
|
|
- return material.babylonMaterial;
|
|
|
- };
|
|
|
- return GLTFMaterialsPbrSpecularGlossinessExtension;
|
|
|
- }(GLTF2.GLTFLoaderExtension));
|
|
|
- GLTF2.GLTFMaterialsPbrSpecularGlossinessExtension = GLTFMaterialsPbrSpecularGlossinessExtension;
|
|
|
- GLTF2.GLTFLoader.RegisterExtension(new GLTFMaterialsPbrSpecularGlossinessExtension());
|
|
|
+ var Extensions;
|
|
|
+ (function (Extensions) {
|
|
|
+ var MSFTLOD = (function (_super) {
|
|
|
+ __extends(MSFTLOD, _super);
|
|
|
+ function MSFTLOD() {
|
|
|
+ return _super !== null && _super.apply(this, arguments) || this;
|
|
|
+ }
|
|
|
+ Object.defineProperty(MSFTLOD.prototype, "name", {
|
|
|
+ get: function () {
|
|
|
+ return "MSFT_lod";
|
|
|
+ },
|
|
|
+ enumerable: true,
|
|
|
+ configurable: true
|
|
|
+ });
|
|
|
+ MSFTLOD.prototype.loadMaterial = function (loader, material, assign) {
|
|
|
+ if (!material.extensions) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ var properties = material.extensions[this.name];
|
|
|
+ if (!properties) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ // Clear out the extension so that it won't get loaded again.
|
|
|
+ material.extensions[this.name] = undefined;
|
|
|
+ // Tell the loader not to clear its state until the highest LOD is loaded.
|
|
|
+ loader.addLoaderPendingData(material);
|
|
|
+ // Start with the lowest quality LOD.
|
|
|
+ var materialLODs = [material.index].concat(properties.ids);
|
|
|
+ this.loadMaterialLOD(loader, material, materialLODs, materialLODs.length - 1, assign);
|
|
|
+ return true;
|
|
|
+ };
|
|
|
+ MSFTLOD.prototype.loadMaterialLOD = function (loader, material, materialLODs, lod, assign) {
|
|
|
+ var _this = this;
|
|
|
+ loader.loadMaterial(materialLODs[lod], function (babylonMaterial) {
|
|
|
+ babylonMaterial.name += ".LOD" + lod;
|
|
|
+ assign(babylonMaterial);
|
|
|
+ // Loading is complete if this is the highest quality LOD.
|
|
|
+ if (lod === 0) {
|
|
|
+ loader.removeLoaderPendingData(material);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // Load the next LOD when all of the textures are loaded.
|
|
|
+ BABYLON.BaseTexture.WhenAllReady(babylonMaterial.getActiveTextures(), function () {
|
|
|
+ _this.loadMaterialLOD(loader, material, materialLODs, lod - 1, assign);
|
|
|
+ });
|
|
|
+ });
|
|
|
+ };
|
|
|
+ return MSFTLOD;
|
|
|
+ }(GLTF2.GLTFLoaderExtension));
|
|
|
+ Extensions.MSFTLOD = MSFTLOD;
|
|
|
+ GLTF2.GLTFLoader.RegisterExtension(new MSFTLOD());
|
|
|
+ })(Extensions = GLTF2.Extensions || (GLTF2.Extensions = {}));
|
|
|
+ })(GLTF2 = BABYLON.GLTF2 || (BABYLON.GLTF2 = {}));
|
|
|
+})(BABYLON || (BABYLON = {}));
|
|
|
+
|
|
|
+//# sourceMappingURL=MSFT_lod.js.map
|
|
|
+
|
|
|
+/// <reference path="../../../../../dist/preview release/babylon.d.ts"/>
|
|
|
+var __extends = (this && this.__extends) || (function () {
|
|
|
+ var extendStatics = Object.setPrototypeOf ||
|
|
|
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
|
+ function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
|
|
+ return function (d, b) {
|
|
|
+ extendStatics(d, b);
|
|
|
+ function __() { this.constructor = d; }
|
|
|
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
|
+ };
|
|
|
+})();
|
|
|
+var BABYLON;
|
|
|
+(function (BABYLON) {
|
|
|
+ var GLTF2;
|
|
|
+ (function (GLTF2) {
|
|
|
+ var Extensions;
|
|
|
+ (function (Extensions) {
|
|
|
+ var KHRMaterialsPbrSpecularGlossiness = (function (_super) {
|
|
|
+ __extends(KHRMaterialsPbrSpecularGlossiness, _super);
|
|
|
+ function KHRMaterialsPbrSpecularGlossiness() {
|
|
|
+ return _super !== null && _super.apply(this, arguments) || this;
|
|
|
+ }
|
|
|
+ Object.defineProperty(KHRMaterialsPbrSpecularGlossiness.prototype, "name", {
|
|
|
+ get: function () {
|
|
|
+ return "KHR_materials_pbrSpecularGlossiness";
|
|
|
+ },
|
|
|
+ enumerable: true,
|
|
|
+ configurable: true
|
|
|
+ });
|
|
|
+ KHRMaterialsPbrSpecularGlossiness.prototype.loadMaterial = function (loader, material, assign) {
|
|
|
+ if (!material.extensions) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ var properties = material.extensions[this.name];
|
|
|
+ if (!properties) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ loader.createPbrMaterial(material);
|
|
|
+ loader.loadMaterialBaseProperties(material);
|
|
|
+ material.babylonMaterial.albedoColor = properties.diffuseFactor ? BABYLON.Color3.FromArray(properties.diffuseFactor) : new BABYLON.Color3(1, 1, 1);
|
|
|
+ material.babylonMaterial.reflectivityColor = properties.specularFactor ? BABYLON.Color3.FromArray(properties.specularFactor) : new BABYLON.Color3(1, 1, 1);
|
|
|
+ material.babylonMaterial.microSurface = properties.glossinessFactor === undefined ? 1 : properties.glossinessFactor;
|
|
|
+ if (properties.diffuseTexture) {
|
|
|
+ material.babylonMaterial.albedoTexture = loader.loadTexture(properties.diffuseTexture);
|
|
|
+ loader.loadMaterialAlphaProperties(material);
|
|
|
+ }
|
|
|
+ if (properties.specularGlossinessTexture) {
|
|
|
+ material.babylonMaterial.reflectivityTexture = loader.loadTexture(properties.specularGlossinessTexture);
|
|
|
+ material.babylonMaterial.useMicroSurfaceFromReflectivityMapAlpha = true;
|
|
|
+ }
|
|
|
+ assign(material.babylonMaterial);
|
|
|
+ return true;
|
|
|
+ };
|
|
|
+ return KHRMaterialsPbrSpecularGlossiness;
|
|
|
+ }(GLTF2.GLTFLoaderExtension));
|
|
|
+ Extensions.KHRMaterialsPbrSpecularGlossiness = KHRMaterialsPbrSpecularGlossiness;
|
|
|
+ GLTF2.GLTFLoader.RegisterExtension(new KHRMaterialsPbrSpecularGlossiness());
|
|
|
+ })(Extensions = GLTF2.Extensions || (GLTF2.Extensions = {}));
|
|
|
})(GLTF2 = BABYLON.GLTF2 || (BABYLON.GLTF2 = {}));
|
|
|
})(BABYLON || (BABYLON = {}));
|
|
|
|
|
|
-//# sourceMappingURL=babylon.glTFMaterialsPbrSpecularGlossinessExtension.js.map
|
|
|
+//# sourceMappingURL=KHR_materials_pbrSpecularGlossiness.js.map
|