|
@@ -3144,9 +3144,10 @@ var BABYLON;
|
|
|
var _this = this;
|
|
|
var promises = new Array();
|
|
|
this._createMorphTargets(context, node, mesh, primitive, babylonMesh);
|
|
|
- promises.push(this._loadVertexDataAsync(context, primitive, babylonMesh).then(function (babylonVertexData) {
|
|
|
- new BABYLON.Geometry(babylonMesh.name, _this._babylonScene, babylonVertexData, false, babylonMesh);
|
|
|
- return _this._loadMorphTargetsAsync(context, primitive, babylonMesh, babylonVertexData);
|
|
|
+ promises.push(this._loadVertexDataAsync(context, primitive, babylonMesh).then(function (babylonGeometry) {
|
|
|
+ return _this._loadMorphTargetsAsync(context, primitive, babylonMesh, babylonGeometry).then(function () {
|
|
|
+ babylonGeometry.applyToMesh(babylonMesh);
|
|
|
+ });
|
|
|
}));
|
|
|
var babylonDrawMode = GLTFLoader._GetDrawMode(context, primitive.mode);
|
|
|
if (primitive.material == undefined) {
|
|
@@ -3171,24 +3172,17 @@ var BABYLON;
|
|
|
throw new Error(context + ": Attributes are missing");
|
|
|
}
|
|
|
var promises = new Array();
|
|
|
- var babylonVertexData = new BABYLON.VertexData();
|
|
|
+ var babylonGeometry = new BABYLON.Geometry(babylonMesh.name, this._babylonScene);
|
|
|
if (primitive.indices == undefined) {
|
|
|
- var positionAccessorIndex = attributes["POSITION"];
|
|
|
- if (positionAccessorIndex != undefined) {
|
|
|
- var accessor = GLTFLoader._GetProperty(context + "/attributes/POSITION", this._gltf.accessors, positionAccessorIndex);
|
|
|
- babylonVertexData.indices = new Uint32Array(accessor.count);
|
|
|
- for (var i = 0; i < babylonVertexData.indices.length; i++) {
|
|
|
- babylonVertexData.indices[i] = i;
|
|
|
- }
|
|
|
- }
|
|
|
+ babylonMesh.isUnIndexed = true;
|
|
|
}
|
|
|
else {
|
|
|
- var indicesAccessor = GLTFLoader._GetProperty(context + "/indices", this._gltf.accessors, primitive.indices);
|
|
|
- promises.push(this._loadAccessorAsync("#/accessors/" + indicesAccessor._index, indicesAccessor).then(function (data) {
|
|
|
- babylonVertexData.indices = data;
|
|
|
+ var accessor = GLTFLoader._GetProperty(context + "/indices", this._gltf.accessors, primitive.indices);
|
|
|
+ promises.push(this._loadAccessorAsync("#/accessors/" + accessor._index, accessor).then(function (data) {
|
|
|
+ babylonGeometry.setIndices(data);
|
|
|
}));
|
|
|
}
|
|
|
- var loadAttribute = function (attribute, kind) {
|
|
|
+ var loadAttribute = function (attribute, kind, callback) {
|
|
|
if (attributes[attribute] == undefined) {
|
|
|
return;
|
|
|
}
|
|
@@ -3196,18 +3190,13 @@ var BABYLON;
|
|
|
if (babylonMesh._delayInfo.indexOf(kind) === -1) {
|
|
|
babylonMesh._delayInfo.push(kind);
|
|
|
}
|
|
|
- if (attribute === "COLOR_0") {
|
|
|
- // Assume vertex color has alpha on the mesh. The alphaMode of the material controls whether the material should use alpha or not.
|
|
|
- babylonMesh.hasVertexAlpha = true;
|
|
|
- }
|
|
|
var accessor = GLTFLoader._GetProperty(context + "/attributes/" + attribute, _this._gltf.accessors, attributes[attribute]);
|
|
|
- promises.push(_this._loadAccessorAsync("#/accessors/" + accessor._index, accessor).then(function (data) {
|
|
|
- var attributeData = GLTFLoader._ConvertToFloat32Array(context, accessor, data);
|
|
|
- if (attribute === "COLOR_0" && accessor.type === "VEC3") {
|
|
|
- attributeData = GLTFLoader._ConvertVec3ToVec4(context, attributeData);
|
|
|
- }
|
|
|
- babylonVertexData.set(attributeData, kind);
|
|
|
+ promises.push(_this._loadVertexAccessorAsync("#/accessors/" + accessor._index, accessor, kind).then(function (babylonVertexBuffer) {
|
|
|
+ babylonGeometry.setVerticesBuffer(babylonVertexBuffer, accessor.count);
|
|
|
}));
|
|
|
+ if (callback) {
|
|
|
+ callback(accessor);
|
|
|
+ }
|
|
|
};
|
|
|
loadAttribute("POSITION", BABYLON.VertexBuffer.PositionKind);
|
|
|
loadAttribute("NORMAL", BABYLON.VertexBuffer.NormalKind);
|
|
@@ -3216,9 +3205,13 @@ var BABYLON;
|
|
|
loadAttribute("TEXCOORD_1", BABYLON.VertexBuffer.UV2Kind);
|
|
|
loadAttribute("JOINTS_0", BABYLON.VertexBuffer.MatricesIndicesKind);
|
|
|
loadAttribute("WEIGHTS_0", BABYLON.VertexBuffer.MatricesWeightsKind);
|
|
|
- loadAttribute("COLOR_0", BABYLON.VertexBuffer.ColorKind);
|
|
|
+ loadAttribute("COLOR_0", BABYLON.VertexBuffer.ColorKind, function (accessor) {
|
|
|
+ if (accessor.type === "VEC4" /* VEC4 */) {
|
|
|
+ babylonMesh.hasVertexAlpha = true;
|
|
|
+ }
|
|
|
+ });
|
|
|
return Promise.all(promises).then(function () {
|
|
|
- return babylonVertexData;
|
|
|
+ return babylonGeometry;
|
|
|
});
|
|
|
};
|
|
|
GLTFLoader.prototype._createMorphTargets = function (context, node, mesh, primitive, babylonMesh) {
|
|
@@ -3238,7 +3231,7 @@ var BABYLON;
|
|
|
// TODO: tell the target whether it has positions, normals, tangents
|
|
|
}
|
|
|
};
|
|
|
- GLTFLoader.prototype._loadMorphTargetsAsync = function (context, primitive, babylonMesh, babylonVertexData) {
|
|
|
+ GLTFLoader.prototype._loadMorphTargetsAsync = function (context, primitive, babylonMesh, babylonGeometry) {
|
|
|
if (!primitive.targets) {
|
|
|
return Promise.resolve();
|
|
|
}
|
|
@@ -3246,93 +3239,55 @@ var BABYLON;
|
|
|
var morphTargetManager = babylonMesh.morphTargetManager;
|
|
|
for (var index = 0; index < morphTargetManager.numTargets; index++) {
|
|
|
var babylonMorphTarget = morphTargetManager.getTarget(index);
|
|
|
- promises.push(this._loadMorphTargetVertexDataAsync(context + "/targets/" + index, babylonVertexData, primitive.targets[index], babylonMorphTarget));
|
|
|
+ promises.push(this._loadMorphTargetVertexDataAsync(context + "/targets/" + index, babylonGeometry, primitive.targets[index], babylonMorphTarget));
|
|
|
}
|
|
|
return Promise.all(promises).then(function () { });
|
|
|
};
|
|
|
- GLTFLoader.prototype._loadMorphTargetVertexDataAsync = function (context, babylonVertexData, attributes, babylonMorphTarget) {
|
|
|
+ GLTFLoader.prototype._loadMorphTargetVertexDataAsync = function (context, babylonGeometry, attributes, babylonMorphTarget) {
|
|
|
var _this = this;
|
|
|
var promises = new Array();
|
|
|
- var loadAttribute = function (attribute, setData) {
|
|
|
+ var loadAttribute = function (attribute, kind, setData) {
|
|
|
if (attributes[attribute] == undefined) {
|
|
|
return;
|
|
|
}
|
|
|
+ var babylonVertexBuffer = babylonGeometry.getVertexBuffer(kind);
|
|
|
+ if (!babylonVertexBuffer) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
var accessor = GLTFLoader._GetProperty(context + "/" + attribute, _this._gltf.accessors, attributes[attribute]);
|
|
|
promises.push(_this._loadAccessorAsync("#/accessors/" + accessor._index, accessor).then(function (data) {
|
|
|
- setData(data);
|
|
|
+ if (!(data instanceof Float32Array)) {
|
|
|
+ throw new Error(context + ": Morph target accessor must have float data");
|
|
|
+ }
|
|
|
+ setData(babylonVertexBuffer, data);
|
|
|
}));
|
|
|
};
|
|
|
- loadAttribute("POSITION", function (data) {
|
|
|
- if (babylonVertexData.positions) {
|
|
|
- for (var i = 0; i < data.length; i++) {
|
|
|
- data[i] += babylonVertexData.positions[i];
|
|
|
- }
|
|
|
- babylonMorphTarget.setPositions(data);
|
|
|
- }
|
|
|
+ loadAttribute("POSITION", BABYLON.VertexBuffer.PositionKind, function (babylonVertexBuffer, data) {
|
|
|
+ babylonVertexBuffer.forEach(data.length, function (value, index) {
|
|
|
+ data[index] += value;
|
|
|
+ });
|
|
|
+ babylonMorphTarget.setPositions(data);
|
|
|
});
|
|
|
- loadAttribute("NORMAL", function (data) {
|
|
|
- if (babylonVertexData.normals) {
|
|
|
- for (var i = 0; i < data.length; i++) {
|
|
|
- data[i] += babylonVertexData.normals[i];
|
|
|
- }
|
|
|
- babylonMorphTarget.setNormals(data);
|
|
|
- }
|
|
|
+ loadAttribute("NORMAL", BABYLON.VertexBuffer.NormalKind, function (babylonVertexBuffer, data) {
|
|
|
+ babylonVertexBuffer.forEach(data.length, function (value, index) {
|
|
|
+ data[index] += value;
|
|
|
+ });
|
|
|
+ babylonMorphTarget.setNormals(data);
|
|
|
});
|
|
|
- loadAttribute("TANGENT", function (data) {
|
|
|
- if (babylonVertexData.tangents) {
|
|
|
+ loadAttribute("TANGENT", BABYLON.VertexBuffer.TangentKind, function (babylonVertexBuffer, data) {
|
|
|
+ var dataIndex = 0;
|
|
|
+ babylonVertexBuffer.forEach(data.length, function (value, index) {
|
|
|
// Tangent data for morph targets is stored as xyz delta.
|
|
|
// The vertexData.tangent is stored as xyzw.
|
|
|
// So we need to skip every fourth vertexData.tangent.
|
|
|
- for (var i = 0, j = 0; i < data.length; i++) {
|
|
|
- data[i] += babylonVertexData.tangents[j++];
|
|
|
- if ((i + 1) % 3 == 0) {
|
|
|
- j++;
|
|
|
- }
|
|
|
+ if (((index + 1) % 4) !== 0) {
|
|
|
+ data[dataIndex++] += value;
|
|
|
}
|
|
|
- babylonMorphTarget.setTangents(data);
|
|
|
- }
|
|
|
+ });
|
|
|
+ babylonMorphTarget.setTangents(data);
|
|
|
});
|
|
|
return Promise.all(promises).then(function () { });
|
|
|
};
|
|
|
- GLTFLoader._ConvertToFloat32Array = function (context, accessor, data) {
|
|
|
- if (accessor.componentType == 5126 /* FLOAT */) {
|
|
|
- return data;
|
|
|
- }
|
|
|
- var factor = 1;
|
|
|
- if (accessor.normalized) {
|
|
|
- switch (accessor.componentType) {
|
|
|
- case 5121 /* UNSIGNED_BYTE */: {
|
|
|
- factor = 1 / 255;
|
|
|
- break;
|
|
|
- }
|
|
|
- case 5123 /* UNSIGNED_SHORT */: {
|
|
|
- factor = 1 / 65535;
|
|
|
- break;
|
|
|
- }
|
|
|
- default: {
|
|
|
- throw new Error(context + ": Invalid component type (" + accessor.componentType + ")");
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- var result = new Float32Array(accessor.count * GLTFLoader._GetNumComponents(context, accessor.type));
|
|
|
- for (var i = 0; i < result.length; i++) {
|
|
|
- result[i] = data[i] * factor;
|
|
|
- }
|
|
|
- return result;
|
|
|
- };
|
|
|
- GLTFLoader._ConvertVec3ToVec4 = function (context, data) {
|
|
|
- var result = new Float32Array(data.length / 3 * 4);
|
|
|
- var offset = 0;
|
|
|
- for (var i = 0; i < result.length; i++) {
|
|
|
- if ((i + 1) % 4 === 0) {
|
|
|
- result[i] = 1;
|
|
|
- }
|
|
|
- else {
|
|
|
- result[i] = data[offset++];
|
|
|
- }
|
|
|
- }
|
|
|
- return result;
|
|
|
- };
|
|
|
GLTFLoader._LoadTransform = function (node, babylonNode) {
|
|
|
var position = BABYLON.Vector3.Zero();
|
|
|
var rotation = BABYLON.Quaternion.Identity();
|
|
@@ -3649,9 +3604,9 @@ var BABYLON;
|
|
|
return bufferView._data;
|
|
|
}
|
|
|
var buffer = GLTFLoader._GetProperty(context + "/buffer", this._gltf.buffers, bufferView.buffer);
|
|
|
- bufferView._data = this._loadBufferAsync("#/buffers/" + buffer._index, buffer).then(function (bufferData) {
|
|
|
+ bufferView._data = this._loadBufferAsync("#/buffers/" + buffer._index, buffer).then(function (data) {
|
|
|
try {
|
|
|
- return new Uint8Array(bufferData.buffer, bufferData.byteOffset + (bufferView.byteOffset || 0), bufferView.byteLength);
|
|
|
+ return new Uint8Array(data.buffer, data.byteOffset + (bufferView.byteOffset || 0), bufferView.byteLength);
|
|
|
}
|
|
|
catch (e) {
|
|
|
throw new Error(context + ": " + e.message);
|
|
@@ -3660,7 +3615,6 @@ var BABYLON;
|
|
|
return bufferView._data;
|
|
|
};
|
|
|
GLTFLoader.prototype._loadAccessorAsync = function (context, accessor) {
|
|
|
- var _this = this;
|
|
|
if (accessor.sparse) {
|
|
|
throw new Error(context + ": Sparse accessors are not currently supported");
|
|
|
}
|
|
@@ -3668,63 +3622,65 @@ var BABYLON;
|
|
|
return accessor._data;
|
|
|
}
|
|
|
var bufferView = GLTFLoader._GetProperty(context + "/bufferView", this._gltf.bufferViews, accessor.bufferView);
|
|
|
- accessor._data = this._loadBufferViewAsync("#/bufferViews/" + bufferView._index, bufferView).then(function (bufferViewData) {
|
|
|
- var numComponents = GLTFLoader._GetNumComponents(context, accessor.type);
|
|
|
- var byteOffset = accessor.byteOffset || 0;
|
|
|
- var byteStride = bufferView.byteStride;
|
|
|
- if (byteStride === 0) {
|
|
|
- BABYLON.Tools.Warn(context + ": Byte stride of 0 is not valid");
|
|
|
- }
|
|
|
+ accessor._data = this._loadBufferViewAsync("#/bufferViews/" + bufferView._index, bufferView).then(function (data) {
|
|
|
+ var buffer = data.buffer;
|
|
|
+ var byteOffset = data.byteOffset + (accessor.byteOffset || 0);
|
|
|
+ var length = GLTFLoader._GetNumComponents(context, accessor.type) * accessor.count;
|
|
|
try {
|
|
|
switch (accessor.componentType) {
|
|
|
case 5120 /* BYTE */: {
|
|
|
- return _this._buildArrayBuffer(Float32Array, bufferViewData, byteOffset, accessor.count, numComponents, byteStride);
|
|
|
+ return new Int8Array(buffer, byteOffset, length);
|
|
|
}
|
|
|
case 5121 /* UNSIGNED_BYTE */: {
|
|
|
- return _this._buildArrayBuffer(Uint8Array, bufferViewData, byteOffset, accessor.count, numComponents, byteStride);
|
|
|
+ return new Uint8Array(buffer, byteOffset, length);
|
|
|
}
|
|
|
case 5122 /* SHORT */: {
|
|
|
- return _this._buildArrayBuffer(Int16Array, bufferViewData, byteOffset, accessor.count, numComponents, byteStride);
|
|
|
+ return new Int16Array(buffer, byteOffset, length);
|
|
|
}
|
|
|
case 5123 /* UNSIGNED_SHORT */: {
|
|
|
- return _this._buildArrayBuffer(Uint16Array, bufferViewData, byteOffset, accessor.count, numComponents, byteStride);
|
|
|
+ return new Uint16Array(buffer, byteOffset, length);
|
|
|
}
|
|
|
case 5125 /* UNSIGNED_INT */: {
|
|
|
- return _this._buildArrayBuffer(Uint32Array, bufferViewData, byteOffset, accessor.count, numComponents, byteStride);
|
|
|
+ return new Uint32Array(buffer, byteOffset, length);
|
|
|
}
|
|
|
case 5126 /* FLOAT */: {
|
|
|
- return _this._buildArrayBuffer(Float32Array, bufferViewData, byteOffset, accessor.count, numComponents, byteStride);
|
|
|
+ return new Float32Array(buffer, byteOffset, length);
|
|
|
}
|
|
|
default: {
|
|
|
- throw new Error(context + ": Invalid component type (" + accessor.componentType + ")");
|
|
|
+ throw new Error(context + ": Invalid accessor component type " + accessor.componentType);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
catch (e) {
|
|
|
- throw new Error(context + ": " + e.messsage);
|
|
|
+ throw new Error(context + ": " + e);
|
|
|
}
|
|
|
});
|
|
|
return accessor._data;
|
|
|
};
|
|
|
- GLTFLoader.prototype._buildArrayBuffer = function (typedArray, data, byteOffset, count, numComponents, byteStride) {
|
|
|
- byteOffset += data.byteOffset;
|
|
|
- var targetLength = count * numComponents;
|
|
|
- if (!byteStride || byteStride === numComponents * typedArray.BYTES_PER_ELEMENT) {
|
|
|
- return new typedArray(data.buffer, byteOffset, targetLength);
|
|
|
+ GLTFLoader.prototype._loadVertexBufferViewAsync = function (context, bufferView, kind) {
|
|
|
+ var _this = this;
|
|
|
+ if (bufferView._babylonBuffer) {
|
|
|
+ return bufferView._babylonBuffer;
|
|
|
}
|
|
|
- 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;
|
|
|
+ bufferView._babylonBuffer = this._loadBufferViewAsync(context, bufferView).then(function (data) {
|
|
|
+ return new BABYLON.Buffer(_this._babylonScene.getEngine(), data, false);
|
|
|
+ });
|
|
|
+ return bufferView._babylonBuffer;
|
|
|
+ };
|
|
|
+ GLTFLoader.prototype._loadVertexAccessorAsync = function (context, accessor, kind) {
|
|
|
+ var _this = this;
|
|
|
+ if (accessor.sparse) {
|
|
|
+ throw new Error(context + ": Sparse accessors are not currently supported");
|
|
|
}
|
|
|
- return targetBuffer;
|
|
|
+ if (accessor._babylonVertexBuffer) {
|
|
|
+ return accessor._babylonVertexBuffer;
|
|
|
+ }
|
|
|
+ var bufferView = GLTFLoader._GetProperty(context + "/bufferView", this._gltf.bufferViews, accessor.bufferView);
|
|
|
+ accessor._babylonVertexBuffer = this._loadVertexBufferViewAsync("#/bufferViews/" + bufferView._index, bufferView, kind).then(function (buffer) {
|
|
|
+ var size = GLTFLoader._GetNumComponents(context, accessor.type);
|
|
|
+ return new BABYLON.VertexBuffer(_this._babylonScene.getEngine(), buffer, kind, false, false, bufferView.byteStride, false, accessor.byteOffset, size, accessor.componentType, accessor.normalized, true);
|
|
|
+ });
|
|
|
+ return accessor._babylonVertexBuffer;
|
|
|
};
|
|
|
GLTFLoader.prototype._getDefaultMaterial = function (drawMode) {
|
|
|
var babylonMaterial = this._defaultBabylonMaterials[drawMode];
|
|
@@ -4261,9 +4217,9 @@ var BABYLON;
|
|
|
}
|
|
|
MSFT_lod.prototype._loadNodeAsync = function (context, node) {
|
|
|
var _this = this;
|
|
|
- return this._loadExtensionAsync(context, node, function (context, extension) {
|
|
|
+ return this._loadExtensionAsync(context, node, function (extensionContext, extension) {
|
|
|
var firstPromise;
|
|
|
- var nodeLODs = _this._getLODs(context, node, _this._loader._gltf.nodes, extension.ids);
|
|
|
+ var nodeLODs = _this._getLODs(extensionContext, node, _this._loader._gltf.nodes, extension.ids);
|
|
|
var _loop_1 = function (indexLOD) {
|
|
|
var nodeLOD = nodeLODs[indexLOD];
|
|
|
if (indexLOD !== 0) {
|
|
@@ -4308,9 +4264,9 @@ var BABYLON;
|
|
|
if (this._loadingNodeLOD) {
|
|
|
return null;
|
|
|
}
|
|
|
- return this._loadExtensionAsync(context, material, function (context, extension) {
|
|
|
+ return this._loadExtensionAsync(context, material, function (extensionContext, extension) {
|
|
|
var firstPromise;
|
|
|
- var materialLODs = _this._getLODs(context, material, _this._loader._gltf.materials, extension.ids);
|
|
|
+ var materialLODs = _this._getLODs(extensionContext, material, _this._loader._gltf.materials, extension.ids);
|
|
|
var _loop_2 = function (indexLOD) {
|
|
|
var materialLOD = materialLODs[indexLOD];
|
|
|
if (indexLOD !== 0) {
|
|
@@ -4472,7 +4428,11 @@ var BABYLON;
|
|
|
if (!_this._dracoCompression) {
|
|
|
_this._dracoCompression = new BABYLON.DracoCompression();
|
|
|
}
|
|
|
- return _this._dracoCompression.decodeMeshAsync(data, attributes);
|
|
|
+ return _this._dracoCompression.decodeMeshAsync(data, attributes).then(function (babylonVertexData) {
|
|
|
+ var babylonGeometry = new BABYLON.Geometry(babylonMesh.name, _this._loader._babylonScene);
|
|
|
+ babylonVertexData.applyToGeometry(babylonGeometry);
|
|
|
+ return babylonGeometry;
|
|
|
+ });
|
|
|
}
|
|
|
catch (e) {
|
|
|
throw new Error(context + ": " + e.message);
|
|
@@ -4519,7 +4479,7 @@ var BABYLON;
|
|
|
}
|
|
|
KHR_materials_pbrSpecularGlossiness.prototype._loadMaterialAsync = function (context, material, babylonMesh, babylonDrawMode, assign) {
|
|
|
var _this = this;
|
|
|
- return this._loadExtensionAsync(context, material, function (context, extension) {
|
|
|
+ return this._loadExtensionAsync(context, material, function (extensionContext, extension) {
|
|
|
material._babylonData = material._babylonData || {};
|
|
|
var babylonData = material._babylonData[babylonDrawMode];
|
|
|
if (!babylonData) {
|
|
@@ -4527,7 +4487,7 @@ var BABYLON;
|
|
|
var name_1 = material.name || "materialSG_" + material._index;
|
|
|
var babylonMaterial = _this._loader._createMaterial(BABYLON.PBRMaterial, name_1, babylonDrawMode);
|
|
|
promises.push(_this._loader._loadMaterialBasePropertiesAsync(context, material, babylonMaterial));
|
|
|
- promises.push(_this._loadSpecularGlossinessPropertiesAsync(context, material, extension, babylonMaterial));
|
|
|
+ promises.push(_this._loadSpecularGlossinessPropertiesAsync(extensionContext, material, extension, babylonMaterial));
|
|
|
_this._loader.onMaterialLoadedObservable.notifyObservers(babylonMaterial);
|
|
|
babylonData = {
|
|
|
material: babylonMaterial,
|
|
@@ -4595,6 +4555,93 @@ var BABYLON;
|
|
|
(function (GLTF2) {
|
|
|
var Extensions;
|
|
|
(function (Extensions) {
|
|
|
+ // https://github.com/donmccurdy/glTF/tree/feat-khr-materials-cmnConstant/extensions/2.0/Khronos/KHR_materials_unlit
|
|
|
+ var NAME = "KHR_materials_unlit";
|
|
|
+ var KHR_materials_unlit = /** @class */ (function (_super) {
|
|
|
+ __extends(KHR_materials_unlit, _super);
|
|
|
+ function KHR_materials_unlit() {
|
|
|
+ var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
|
+ _this.name = NAME;
|
|
|
+ return _this;
|
|
|
+ }
|
|
|
+ KHR_materials_unlit.prototype._loadMaterialAsync = function (context, material, babylonMesh, babylonDrawMode, assign) {
|
|
|
+ var _this = this;
|
|
|
+ return this._loadExtensionAsync(context, material, function () {
|
|
|
+ material._babylonData = material._babylonData || {};
|
|
|
+ var babylonData = material._babylonData[babylonDrawMode];
|
|
|
+ if (!babylonData) {
|
|
|
+ var name_1 = material.name || "materialUnlit_" + material._index;
|
|
|
+ var babylonMaterial = _this._loader._createMaterial(BABYLON.PBRMaterial, name_1, babylonDrawMode);
|
|
|
+ babylonMaterial.unlit = true;
|
|
|
+ var promise = _this._loadUnlitPropertiesAsync(context, material, babylonMaterial);
|
|
|
+ _this._loader.onMaterialLoadedObservable.notifyObservers(babylonMaterial);
|
|
|
+ babylonData = {
|
|
|
+ material: babylonMaterial,
|
|
|
+ meshes: [],
|
|
|
+ loaded: promise
|
|
|
+ };
|
|
|
+ material._babylonData[babylonDrawMode] = babylonData;
|
|
|
+ }
|
|
|
+ babylonData.meshes.push(babylonMesh);
|
|
|
+ assign(babylonData.material);
|
|
|
+ return babylonData.loaded;
|
|
|
+ });
|
|
|
+ };
|
|
|
+ KHR_materials_unlit.prototype._loadUnlitPropertiesAsync = function (context, material, babylonMaterial) {
|
|
|
+ var promises = new Array();
|
|
|
+ // Ensure metallic workflow
|
|
|
+ babylonMaterial.metallic = 1;
|
|
|
+ babylonMaterial.roughness = 1;
|
|
|
+ var properties = material.pbrMetallicRoughness;
|
|
|
+ if (properties) {
|
|
|
+ if (properties.baseColorFactor) {
|
|
|
+ babylonMaterial.albedoColor = BABYLON.Color3.FromArray(properties.baseColorFactor);
|
|
|
+ babylonMaterial.alpha = properties.baseColorFactor[3];
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ babylonMaterial.albedoColor = BABYLON.Color3.White();
|
|
|
+ }
|
|
|
+ if (properties.baseColorTexture) {
|
|
|
+ promises.push(this._loader._loadTextureAsync(context + "/baseColorTexture", properties.baseColorTexture, function (texture) {
|
|
|
+ babylonMaterial.albedoTexture = texture;
|
|
|
+ }));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (material.doubleSided) {
|
|
|
+ babylonMaterial.backFaceCulling = false;
|
|
|
+ babylonMaterial.twoSidedLighting = true;
|
|
|
+ }
|
|
|
+ this._loader._loadMaterialAlphaProperties(context, material, babylonMaterial);
|
|
|
+ return Promise.all(promises).then(function () { });
|
|
|
+ };
|
|
|
+ return KHR_materials_unlit;
|
|
|
+ }(GLTF2.GLTFLoaderExtension));
|
|
|
+ Extensions.KHR_materials_unlit = KHR_materials_unlit;
|
|
|
+ GLTF2.GLTFLoader._Register(NAME, function (loader) { return new KHR_materials_unlit(loader); });
|
|
|
+ })(Extensions = GLTF2.Extensions || (GLTF2.Extensions = {}));
|
|
|
+ })(GLTF2 = BABYLON.GLTF2 || (BABYLON.GLTF2 = {}));
|
|
|
+})(BABYLON || (BABYLON = {}));
|
|
|
+
|
|
|
+//# sourceMappingURL=KHR_materials_unlit.js.map
|
|
|
+
|
|
|
+"use strict";
|
|
|
+/// <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) {
|
|
|
// https://github.com/MiiBond/glTF/tree/khr_lights_v1/extensions/Khronos/KHR_lights
|
|
|
var NAME = "KHR_lights";
|
|
|
var LightType;
|
|
@@ -4613,11 +4660,11 @@ var BABYLON;
|
|
|
}
|
|
|
KHR_lights.prototype._loadSceneAsync = function (context, scene) {
|
|
|
var _this = this;
|
|
|
- return this._loadExtensionAsync(context, scene, function (context, extension) {
|
|
|
- var promise = _this._loader._loadSceneAsync(context, scene);
|
|
|
- var light = GLTF2.GLTFLoader._GetProperty(context, _this._lights, extension.light);
|
|
|
+ return this._loadExtensionAsync(context, scene, function (extensionContext, extension) {
|
|
|
+ var promise = _this._loader._loadSceneAsync(extensionContext, scene);
|
|
|
+ var light = GLTF2.GLTFLoader._GetProperty(extensionContext, _this._lights, extension.light);
|
|
|
if (light.type !== LightType.AMBIENT) {
|
|
|
- throw new Error(context + ": Only ambient lights are allowed on a scene");
|
|
|
+ throw new Error(extensionContext + ": Only ambient lights are allowed on a scene");
|
|
|
}
|
|
|
_this._loader._babylonScene.ambientColor = light.color ? BABYLON.Color3.FromArray(light.color) : BABYLON.Color3.Black();
|
|
|
return promise;
|
|
@@ -4625,14 +4672,14 @@ var BABYLON;
|
|
|
};
|
|
|
KHR_lights.prototype._loadNodeAsync = function (context, node) {
|
|
|
var _this = this;
|
|
|
- return this._loadExtensionAsync(context, node, function (context, extension) {
|
|
|
- var promise = _this._loader._loadNodeAsync(context, node);
|
|
|
+ return this._loadExtensionAsync(context, node, function (extensionContext, extension) {
|
|
|
+ var promise = _this._loader._loadNodeAsync(extensionContext, node);
|
|
|
var babylonLight;
|
|
|
- var light = GLTF2.GLTFLoader._GetProperty(context, _this._lights, extension.light);
|
|
|
+ var light = GLTF2.GLTFLoader._GetProperty(extensionContext, _this._lights, extension.light);
|
|
|
var name = node._babylonMesh.name;
|
|
|
switch (light.type) {
|
|
|
case LightType.AMBIENT: {
|
|
|
- throw new Error(context + ": Ambient lights are not allowed on a node");
|
|
|
+ throw new Error(extensionContext + ": Ambient lights are not allowed on a node");
|
|
|
}
|
|
|
case LightType.DIRECTIONAL: {
|
|
|
babylonLight = new BABYLON.DirectionalLight(name, BABYLON.Vector3.Forward(), _this._loader._babylonScene);
|
|
@@ -4651,7 +4698,7 @@ var BABYLON;
|
|
|
break;
|
|
|
}
|
|
|
default: {
|
|
|
- throw new Error(context + ": Invalid light type (" + light.type + ")");
|
|
|
+ throw new Error(extensionContext + ": Invalid light type (" + light.type + ")");
|
|
|
}
|
|
|
}
|
|
|
babylonLight.diffuse = light.color ? BABYLON.Color3.FromArray(light.color) : BABYLON.Color3.White();
|