|
@@ -281,10 +281,12 @@ module BABYLON.GLTF2 {
|
|
|
vertexData.positions = [];
|
|
|
vertexData.indices = [];
|
|
|
|
|
|
+ var subMeshInfos: { materialIndex: number, verticesStart: number, verticesCount: number, indicesStart: number, indicesCount: number }[] = [];
|
|
|
+
|
|
|
var primitivesLoaded = 0;
|
|
|
var numPrimitives = mesh.primitives.length;
|
|
|
for (var i = 0; i < numPrimitives; i++) {
|
|
|
- var primitive = mesh.primitives[i];
|
|
|
+ let primitive = mesh.primitives[i];
|
|
|
if (primitive.mode && primitive.mode !== EMeshPrimitiveMode.TRIANGLES) {
|
|
|
// TODO: handle other primitive modes
|
|
|
throw new Error("Not implemented");
|
|
@@ -295,13 +297,26 @@ module BABYLON.GLTF2 {
|
|
|
this._loadVertexDataAsync(primitive, subVertexData => {
|
|
|
this._loadMorphTargetsData(mesh, primitive, subVertexData, babylonMesh);
|
|
|
|
|
|
- var subMesh = new SubMesh(multiMaterial.subMaterials.length, vertexData.positions.length, subVertexData.positions.length, vertexData.indices.length, subVertexData.indices.length, babylonMesh);
|
|
|
+ subMeshInfos.push({
|
|
|
+ materialIndex: multiMaterial.subMaterials.length,
|
|
|
+ verticesStart: vertexData.positions.length,
|
|
|
+ verticesCount: subVertexData.positions.length,
|
|
|
+ indicesStart: vertexData.indices.length,
|
|
|
+ indicesCount: subVertexData.indices.length
|
|
|
+ });
|
|
|
+
|
|
|
var subMaterial = primitive.material === undefined ? this._getDefaultMaterial() : GLTFLoaderExtension.LoadMaterial(primitive.material);
|
|
|
multiMaterial.subMaterials.push(subMaterial);
|
|
|
vertexData.merge(subVertexData);
|
|
|
|
|
|
if (++primitivesLoaded === numPrimitives) {
|
|
|
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 SubMesh(info.materialIndex, info.verticesStart, info.verticesCount, info.indicesStart, info.indicesCount, babylonMesh);
|
|
|
+ }
|
|
|
}
|
|
|
});
|
|
|
}
|
|
@@ -777,24 +792,22 @@ module BABYLON.GLTF2 {
|
|
|
material.babylonMaterial.roughness = 1;
|
|
|
|
|
|
var properties = material.pbrMetallicRoughness;
|
|
|
- if (!properties) {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- material.babylonMaterial.albedoColor = properties.baseColorFactor ? Color3.FromArray(properties.baseColorFactor) : new 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) {
|
|
|
+ material.babylonMaterial.albedoColor = properties.baseColorFactor ? Color3.FromArray(properties.baseColorFactor) : new 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.metallicRoughnessTexture) {
|
|
|
+ material.babylonMaterial.metallicTexture = this._loadTexture(properties.metallicRoughnessTexture);
|
|
|
+ material.babylonMaterial.useMetallnessFromMetallicTextureBlue = true;
|
|
|
+ material.babylonMaterial.useRoughnessFromMetallicTextureGreen = true;
|
|
|
+ material.babylonMaterial.useRoughnessFromMetallicTextureAlpha = false;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
return material.babylonMaterial;
|