@babylonjs/loaders 5.0.0-beta.7 → 5.0.0-rc.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -28,7 +28,7 @@ var MTLFileLoader = /** @class */ (function () {
28
28
  }
29
29
  //Split the lines from the file
30
30
  var lines = data.split('\n');
31
- //Space char
31
+ // whitespace char ie: [ \t\r\n\f]
32
32
  var delimiter_pattern = /\s+/;
33
33
  //Array with RGB colors
34
34
  var color;
@@ -126,7 +126,17 @@ var MTLFileLoader = /** @class */ (function () {
126
126
  }
127
127
  else if (key === "map_bump" && material) {
128
128
  //The bump texture
129
- material.bumpTexture = MTLFileLoader._getTexture(rootUrl, value, scene);
129
+ var values = value.split(delimiter_pattern);
130
+ var bumpMultiplierIndex = values.indexOf('-bm');
131
+ var bumpMultiplier = null;
132
+ if (bumpMultiplierIndex >= 0) {
133
+ bumpMultiplier = values[bumpMultiplierIndex + 1];
134
+ values.splice(bumpMultiplierIndex, 2); // remove
135
+ }
136
+ material.bumpTexture = MTLFileLoader._getTexture(rootUrl, values.join(' '), scene);
137
+ if (material.bumpTexture && bumpMultiplier !== null) {
138
+ material.bumpTexture.level = parseFloat(bumpMultiplier);
139
+ }
130
140
  }
131
141
  else if (key === "map_d" && material) {
132
142
  // The dissolve of the material
@@ -1 +1 @@
1
- {"version":3,"file":"mtlFileLoader.js","sourceRoot":"","sources":["../../../sourceES6/loaders/src/OBJ/mtlFileLoader.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,kCAAkC,CAAC;AAC1D,OAAO,EAAE,OAAO,EAAE,MAAM,4CAA4C,CAAC;AACrE,OAAO,EAAE,gBAAgB,EAAE,MAAM,4CAA4C,CAAC;AAI9E;;GAEG;AACH;IAAA;QAMI;;WAEG;QACI,cAAS,GAAuB,EAAE,CAAC;IAoM9C,CAAC;IAlMG;;;;;;;;;;OAUG;IACI,gCAAQ,GAAf,UAAgB,KAAY,EAAE,IAA0B,EAAE,OAAe,EAAE,cAAwC;QAC/G,IAAI,IAAI,YAA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B,OAAe,EAAE,KAAa,EAAE,KAAY;QACnE,IAAI,CAAC,KAAK,EAAE;YACR,OAAO,IAAI,CAAC;SACf;QAED,IAAI,GAAG,GAAG,OAAO,CAAC;QAClB,wBAAwB;QACxB,IAAI,OAAO,KAAK,OAAO,EAAE;YACrB,IAAI,aAAa,GAAG,KAAK,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;YAC5C,IAAI,aAAa,KAAK,CAAC,CAAC,EAAE;gBACtB,aAAa,GAAG,KAAK,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;aAC1C;YAED,IAAI,aAAa,GAAG,CAAC,CAAC,EAAE;gBACpB,GAAG,IAAI,KAAK,CAAC,MAAM,CAAC,aAAa,GAAG,CAAC,CAAC,CAAC;aAC1C;iBACI;gBACD,GAAG,IAAI,KAAK,CAAC;aAChB;SACJ;QACD,uBAAuB;aAClB;YACD,GAAG,IAAI,KAAK,CAAC;SAChB;QAED,OAAO,IAAI,OAAO,CAAC,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,aAAa,CAAC,gBAAgB,CAAC,CAAC;IAC1E,CAAC;IA3MD;;OAEG;IACW,8BAAgB,GAAG,IAAI,CAAC;IAyM1C,oBAAC;CAAA,AA7MD,IA6MC;SA7MY,aAAa","sourcesContent":["import { Nullable } from \"@babylonjs/core/types\";\r\nimport { Color3 } from '@babylonjs/core/Maths/math.color';\r\nimport { Texture } from \"@babylonjs/core/Materials/Textures/texture\";\r\nimport { StandardMaterial } from \"@babylonjs/core/Materials/standardMaterial\";\r\n\r\nimport { Scene } from \"@babylonjs/core/scene\";\r\nimport { AssetContainer } from \"@babylonjs/core/assetContainer\";\r\n/**\r\n * Class reading and parsing the MTL file bundled with the obj file.\r\n */\r\nexport class MTLFileLoader {\r\n /**\r\n * Invert Y-Axis of referenced textures on load\r\n */\r\n public static INVERT_TEXTURE_Y = true;\r\n\r\n /**\r\n * All material loaded from the mtl will be set here\r\n */\r\n public materials: StandardMaterial[] = [];\r\n\r\n /**\r\n * This function will read the mtl file and create each material described inside\r\n * This function could be improve by adding :\r\n * -some component missing (Ni, Tf...)\r\n * -including the specific options available\r\n *\r\n * @param scene defines the scene the material will be created in\r\n * @param data defines the mtl data to parse\r\n * @param rootUrl defines the rooturl to use in order to load relative dependencies\r\n * @param assetContainer defines the asset container to store the material in (can be null)\r\n */\r\n public parseMTL(scene: Scene, data: string | ArrayBuffer, rootUrl: string, assetContainer: Nullable<AssetContainer>): void {\r\n if (data instanceof ArrayBuffer) {\r\n return;\r\n }\r\n\r\n //Split the lines from the file\r\n var lines = data.split('\\n');\r\n //Space char\r\n var delimiter_pattern = /\\s+/;\r\n //Array with RGB colors\r\n var color: number[];\r\n //New material\r\n var material: Nullable<StandardMaterial> = null;\r\n\r\n //Look at each line\r\n for (var i = 0; i < lines.length; i++) {\r\n var line = lines[i].trim();\r\n\r\n // Blank line or comment\r\n if (line.length === 0 || line.charAt(0) === '#') {\r\n continue;\r\n }\r\n\r\n //Get the first parameter (keyword)\r\n var pos = line.indexOf(' ');\r\n var key = (pos >= 0) ? line.substring(0, pos) : line;\r\n key = key.toLowerCase();\r\n\r\n //Get the data following the key\r\n var value: string = (pos >= 0) ? line.substring(pos + 1).trim() : \"\";\r\n\r\n //This mtl keyword will create the new material\r\n if (key === \"newmtl\") {\r\n //Check if it is the first material.\r\n // Materials specifications are described after this keyword.\r\n if (material) {\r\n //Add the previous material in the material array.\r\n this.materials.push(material);\r\n }\r\n //Create a new material.\r\n // value is the name of the material read in the mtl file\r\n\r\n scene._blockEntityCollection = !!assetContainer;\r\n material = new StandardMaterial(value, scene);\r\n material._parentContainer = assetContainer;\r\n scene._blockEntityCollection = false;\r\n } else if (key === \"kd\" && material) {\r\n // Diffuse color (color under white light) using RGB values\r\n\r\n //value = \"r g b\"\r\n color = <number[]>value.split(delimiter_pattern, 3).map(parseFloat);\r\n //color = [r,g,b]\r\n //Set tghe color into the material\r\n material.diffuseColor = Color3.FromArray(color);\r\n } else if (key === \"ka\" && material) {\r\n // Ambient color (color under shadow) using RGB values\r\n\r\n //value = \"r g b\"\r\n color = <number[]>value.split(delimiter_pattern, 3).map(parseFloat);\r\n //color = [r,g,b]\r\n //Set tghe color into the material\r\n material.ambientColor = Color3.FromArray(color);\r\n } else if (key === \"ks\" && material) {\r\n // Specular color (color when light is reflected from shiny surface) using RGB values\r\n\r\n //value = \"r g b\"\r\n color = <number[]>value.split(delimiter_pattern, 3).map(parseFloat);\r\n //color = [r,g,b]\r\n //Set the color into the material\r\n material.specularColor = Color3.FromArray(color);\r\n } else if (key === \"ke\" && material) {\r\n // Emissive color using RGB values\r\n color = value.split(delimiter_pattern, 3).map(parseFloat);\r\n material.emissiveColor = Color3.FromArray(color);\r\n } else if (key === \"ns\" && material) {\r\n\r\n //value = \"Integer\"\r\n material.specularPower = parseFloat(value);\r\n } else if (key === \"d\" && material) {\r\n //d is dissolve for current material. It mean alpha for BABYLON\r\n material.alpha = parseFloat(value);\r\n\r\n //Texture\r\n //This part can be improved by adding the possible options of texture\r\n } else if (key === \"map_ka\" && material) {\r\n // ambient texture map with a loaded image\r\n //We must first get the folder of the image\r\n material.ambientTexture = MTLFileLoader._getTexture(rootUrl, value, scene);\r\n } else if (key === \"map_kd\" && material) {\r\n // Diffuse texture map with a loaded image\r\n material.diffuseTexture = MTLFileLoader._getTexture(rootUrl, value, scene);\r\n } else if (key === \"map_ks\" && material) {\r\n // Specular texture map with a loaded image\r\n //We must first get the folder of the image\r\n material.specularTexture = MTLFileLoader._getTexture(rootUrl, value, scene);\r\n } else if (key === \"map_ns\") {\r\n //Specular\r\n //Specular highlight component\r\n //We must first get the folder of the image\r\n //\r\n //Not supported by BABYLON\r\n //\r\n // continue;\r\n } else if (key === \"map_bump\" && material) {\r\n //The bump texture\r\n material.bumpTexture = MTLFileLoader._getTexture(rootUrl, value, scene);\r\n } else if (key === \"map_d\" && material) {\r\n // The dissolve of the material\r\n material.opacityTexture = MTLFileLoader._getTexture(rootUrl, value, scene);\r\n\r\n //Options for illumination\r\n } else if (key === \"illum\") {\r\n //Illumination\r\n if (value === \"0\") {\r\n //That mean Kd == Kd\r\n } else if (value === \"1\") {\r\n //Color on and Ambient on\r\n } else if (value === \"2\") {\r\n //Highlight on\r\n } else if (value === \"3\") {\r\n //Reflection on and Ray trace on\r\n } else if (value === \"4\") {\r\n //Transparency: Glass on, Reflection: Ray trace on\r\n } else if (value === \"5\") {\r\n //Reflection: Fresnel on and Ray trace on\r\n } else if (value === \"6\") {\r\n //Transparency: Refraction on, Reflection: Fresnel off and Ray trace on\r\n } else if (value === \"7\") {\r\n //Transparency: Refraction on, Reflection: Fresnel on and Ray trace on\r\n } else if (value === \"8\") {\r\n //Reflection on and Ray trace off\r\n } else if (value === \"9\") {\r\n //Transparency: Glass on, Reflection: Ray trace off\r\n } else if (value === \"10\") {\r\n //Casts shadows onto invisible surfaces\r\n }\r\n } else {\r\n // console.log(\"Unhandled expression at line : \" + i +'\\n' + \"with value : \" + line);\r\n }\r\n }\r\n //At the end of the file, add the last material\r\n if (material) {\r\n this.materials.push(material);\r\n }\r\n }\r\n\r\n /**\r\n * Gets the texture for the material.\r\n *\r\n * If the material is imported from input file,\r\n * We sanitize the url to ensure it takes the textre from aside the material.\r\n *\r\n * @param rootUrl The root url to load from\r\n * @param value The value stored in the mtl\r\n * @return The Texture\r\n */\r\n private static _getTexture(rootUrl: string, value: string, scene: Scene): Nullable<Texture> {\r\n if (!value) {\r\n return null;\r\n }\r\n\r\n var url = rootUrl;\r\n // Load from input file.\r\n if (rootUrl === \"file:\") {\r\n var lastDelimiter = value.lastIndexOf(\"\\\\\");\r\n if (lastDelimiter === -1) {\r\n lastDelimiter = value.lastIndexOf(\"/\");\r\n }\r\n\r\n if (lastDelimiter > -1) {\r\n url += value.substr(lastDelimiter + 1);\r\n }\r\n else {\r\n url += value;\r\n }\r\n }\r\n // Not from input file.\r\n else {\r\n url += value;\r\n }\r\n\r\n return new Texture(url, scene, false, MTLFileLoader.INVERT_TEXTURE_Y);\r\n }\r\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,IAAI,CAAC,CAAC;YAC5C,IAAI,aAAa,KAAK,CAAC,CAAC,EAAE;gBACtB,aAAa,GAAG,KAAK,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;aAC1C;YAED,IAAI,aAAa,GAAG,CAAC,CAAC,EAAE;gBACpB,GAAG,IAAI,KAAK,CAAC,MAAM,CAAC,aAAa,GAAG,CAAC,CAAC,CAAC;aAC1C;iBACI;gBACD,GAAG,IAAI,KAAK,CAAC;aAChB;SACJ;QACD,uBAAuB;aAClB;YACD,GAAG,IAAI,KAAK,CAAC;SAChB;QAED,OAAO,IAAI,OAAO,CAAC,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,aAAa,CAAC,gBAAgB,CAAC,CAAC;IAC1E,CAAC;IAvND;;OAEG;IACW,8BAAgB,GAAG,IAAI,CAAC;IAqN1C,oBAAC;CAAA,AAzND,IAyNC;SAzNY,aAAa","sourcesContent":["import { Nullable } from \"@babylonjs/core/types\";\r\nimport { Color3 } from '@babylonjs/core/Maths/math.color';\r\nimport { Texture } from \"@babylonjs/core/Materials/Textures/texture\";\r\nimport { StandardMaterial } from \"@babylonjs/core/Materials/standardMaterial\";\r\n\r\nimport { Scene } from \"@babylonjs/core/scene\";\r\nimport { AssetContainer } from \"@babylonjs/core/assetContainer\";\r\n/**\r\n * Class reading and parsing the MTL file bundled with the obj file.\r\n */\r\nexport class MTLFileLoader {\r\n /**\r\n * Invert Y-Axis of referenced textures on load\r\n */\r\n public static INVERT_TEXTURE_Y = true;\r\n\r\n /**\r\n * All material loaded from the mtl will be set here\r\n */\r\n public materials: StandardMaterial[] = [];\r\n\r\n /**\r\n * This function will read the mtl file and create each material described inside\r\n * This function could be improve by adding :\r\n * -some component missing (Ni, Tf...)\r\n * -including the specific options available\r\n *\r\n * @param scene defines the scene the material will be created in\r\n * @param data defines the mtl data to parse\r\n * @param rootUrl defines the rooturl to use in order to load relative dependencies\r\n * @param assetContainer defines the asset container to store the material in (can be null)\r\n */\r\n public parseMTL(scene: Scene, data: string | ArrayBuffer, rootUrl: string, assetContainer: Nullable<AssetContainer>): void {\r\n if (data instanceof ArrayBuffer) {\r\n return;\r\n }\r\n\r\n //Split the lines from the file\r\n var lines = data.split('\\n');\r\n // whitespace char ie: [ \\t\\r\\n\\f]\r\n var delimiter_pattern = /\\s+/;\r\n //Array with RGB colors\r\n var color: number[];\r\n //New material\r\n var material: Nullable<StandardMaterial> = null;\r\n\r\n //Look at each line\r\n for (var i = 0; i < lines.length; i++) {\r\n var line = lines[i].trim();\r\n\r\n // Blank line or comment\r\n if (line.length === 0 || line.charAt(0) === '#') {\r\n continue;\r\n }\r\n\r\n //Get the first parameter (keyword)\r\n var pos = line.indexOf(' ');\r\n var key = (pos >= 0) ? line.substring(0, pos) : line;\r\n key = key.toLowerCase();\r\n\r\n //Get the data following the key\r\n var value: string = (pos >= 0) ? line.substring(pos + 1).trim() : \"\";\r\n\r\n //This mtl keyword will create the new material\r\n if (key === \"newmtl\") {\r\n //Check if it is the first material.\r\n // Materials specifications are described after this keyword.\r\n if (material) {\r\n //Add the previous material in the material array.\r\n this.materials.push(material);\r\n }\r\n //Create a new material.\r\n // value is the name of the material read in the mtl file\r\n\r\n scene._blockEntityCollection = !!assetContainer;\r\n material = new StandardMaterial(value, scene);\r\n material._parentContainer = assetContainer;\r\n scene._blockEntityCollection = false;\r\n } else if (key === \"kd\" && material) {\r\n // Diffuse color (color under white light) using RGB values\r\n\r\n //value = \"r g b\"\r\n color = <number[]>value.split(delimiter_pattern, 3).map(parseFloat);\r\n //color = [r,g,b]\r\n //Set tghe color into the material\r\n material.diffuseColor = Color3.FromArray(color);\r\n } else if (key === \"ka\" && material) {\r\n // Ambient color (color under shadow) using RGB values\r\n\r\n //value = \"r g b\"\r\n color = <number[]>value.split(delimiter_pattern, 3).map(parseFloat);\r\n //color = [r,g,b]\r\n //Set tghe color into the material\r\n material.ambientColor = Color3.FromArray(color);\r\n } else if (key === \"ks\" && material) {\r\n // Specular color (color when light is reflected from shiny surface) using RGB values\r\n\r\n //value = \"r g b\"\r\n color = <number[]>value.split(delimiter_pattern, 3).map(parseFloat);\r\n //color = [r,g,b]\r\n //Set the color into the material\r\n material.specularColor = Color3.FromArray(color);\r\n } else if (key === \"ke\" && material) {\r\n // Emissive color using RGB values\r\n color = value.split(delimiter_pattern, 3).map(parseFloat);\r\n material.emissiveColor = Color3.FromArray(color);\r\n } else if (key === \"ns\" && material) {\r\n\r\n //value = \"Integer\"\r\n material.specularPower = parseFloat(value);\r\n } else if (key === \"d\" && material) {\r\n //d is dissolve for current material. It mean alpha for BABYLON\r\n material.alpha = parseFloat(value);\r\n\r\n //Texture\r\n //This part can be improved by adding the possible options of texture\r\n } else if (key === \"map_ka\" && material) {\r\n // ambient texture map with a loaded image\r\n //We must first get the folder of the image\r\n material.ambientTexture = MTLFileLoader._getTexture(rootUrl, value, scene);\r\n } else if (key === \"map_kd\" && material) {\r\n // Diffuse texture map with a loaded image\r\n material.diffuseTexture = MTLFileLoader._getTexture(rootUrl, value, scene);\r\n } else if (key === \"map_ks\" && material) {\r\n // Specular texture map with a loaded image\r\n //We must first get the folder of the image\r\n material.specularTexture = MTLFileLoader._getTexture(rootUrl, value, scene);\r\n } else if (key === \"map_ns\") {\r\n //Specular\r\n //Specular highlight component\r\n //We must first get the folder of the image\r\n //\r\n //Not supported by BABYLON\r\n //\r\n // continue;\r\n } else if (key === \"map_bump\" && material) {\r\n //The bump texture\r\n const values = value.split(delimiter_pattern);\r\n const bumpMultiplierIndex = values.indexOf('-bm');\r\n let bumpMultiplier: Nullable<string> = null;\r\n\r\n if (bumpMultiplierIndex >= 0) {\r\n bumpMultiplier = values[bumpMultiplierIndex + 1];\r\n values.splice(bumpMultiplierIndex, 2); // remove\r\n }\r\n\r\n material.bumpTexture = MTLFileLoader._getTexture(rootUrl, values.join(' '), scene);\r\n if (material.bumpTexture && bumpMultiplier !== null) {\r\n material.bumpTexture.level = parseFloat(bumpMultiplier);\r\n }\r\n } else if (key === \"map_d\" && material) {\r\n // The dissolve of the material\r\n material.opacityTexture = MTLFileLoader._getTexture(rootUrl, value, scene);\r\n\r\n //Options for illumination\r\n } else if (key === \"illum\") {\r\n //Illumination\r\n if (value === \"0\") {\r\n //That mean Kd == Kd\r\n } else if (value === \"1\") {\r\n //Color on and Ambient on\r\n } else if (value === \"2\") {\r\n //Highlight on\r\n } else if (value === \"3\") {\r\n //Reflection on and Ray trace on\r\n } else if (value === \"4\") {\r\n //Transparency: Glass on, Reflection: Ray trace on\r\n } else if (value === \"5\") {\r\n //Reflection: Fresnel on and Ray trace on\r\n } else if (value === \"6\") {\r\n //Transparency: Refraction on, Reflection: Fresnel off and Ray trace on\r\n } else if (value === \"7\") {\r\n //Transparency: Refraction on, Reflection: Fresnel on and Ray trace on\r\n } else if (value === \"8\") {\r\n //Reflection on and Ray trace off\r\n } else if (value === \"9\") {\r\n //Transparency: Glass on, Reflection: Ray trace off\r\n } else if (value === \"10\") {\r\n //Casts shadows onto invisible surfaces\r\n }\r\n } else {\r\n // console.log(\"Unhandled expression at line : \" + i +'\\n' + \"with value : \" + line);\r\n }\r\n }\r\n //At the end of the file, add the last material\r\n if (material) {\r\n this.materials.push(material);\r\n }\r\n }\r\n\r\n /**\r\n * Gets the texture for the material.\r\n *\r\n * If the material is imported from input file,\r\n * We sanitize the url to ensure it takes the textre from aside the material.\r\n *\r\n * @param rootUrl The root url to load from\r\n * @param value The value stored in the mtl\r\n * @return The Texture\r\n */\r\n private static _getTexture(rootUrl: string, value: string, scene: Scene): Nullable<Texture> {\r\n if (!value) {\r\n return null;\r\n }\r\n\r\n var url = rootUrl;\r\n // Load from input file.\r\n if (rootUrl === \"file:\") {\r\n var lastDelimiter = value.lastIndexOf(\"\\\\\");\r\n if (lastDelimiter === -1) {\r\n lastDelimiter = value.lastIndexOf(\"/\");\r\n }\r\n\r\n if (lastDelimiter > -1) {\r\n url += value.substr(lastDelimiter + 1);\r\n }\r\n else {\r\n url += value;\r\n }\r\n }\r\n // Not from input file.\r\n else {\r\n url += value;\r\n }\r\n\r\n return new Texture(url, scene, false, MTLFileLoader.INVERT_TEXTURE_Y);\r\n }\r\n}\r\n"]}
@@ -3,6 +3,7 @@ import { Nullable } from "@babylonjs/core/types";
3
3
  import { GLTFLoader } from "../glTFLoader";
4
4
  import { IGLTFLoaderExtension } from "../glTFLoaderExtension";
5
5
  import { INode } from "../glTFLoaderInterfaces";
6
+ import "@babylonjs/core/Meshes/thinInstanceMesh";
6
7
  /**
7
8
  * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1691)
8
9
  * [Playground Sample](https://playground.babylonjs.com/#QFIGLW#9)
@@ -1,6 +1,7 @@
1
1
  import { Vector3, Quaternion, Matrix } from '@babylonjs/core/Maths/math.vector.js';
2
2
  import { GLTFLoader, ArrayItem } from "../glTFLoader.js";
3
3
  import { TmpVectors } from '@babylonjs/core/Maths/math.vector.js';
4
+ import "@babylonjs/core/Meshes/thinInstanceMesh.js";
4
5
  var NAME = "EXT_mesh_gpu_instancing";
5
6
  /**
6
7
  * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1691)
@@ -1 +1 @@
1
- {"version":3,"file":"EXT_mesh_gpu_instancing.js","sourceRoot":"","sources":["../../../../../sourceES6/loaders/src/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,mCAAmC,CAAC;AAIhF,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAGtD,OAAO,EAAE,UAAU,EAAE,MAAM,mCAAmC,CAAC;AAG/D,IAAM,IAAI,GAAG,yBAAyB,CAAC;AAEvC;;;;GAIG;AACH;IAaI,cAAc;IACd,iCAAY,MAAkB;QAb9B;;WAEG;QACa,SAAI,GAAG,IAAI,CAAC;QAWxB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,C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AAU,CAAC,cAAc,CAAC,cAAc,EAAE,CAAC,GAAG,CAAC,EAAE,UAAU,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;wBAC7F,WAAW,IAAI,OAAO,CAAC,cAAc,CAAC,WAAW,EAAE,CAAC,GAAG,CAAC,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;wBAEjF,MAAM,CAAC,YAAY,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;wBAElH,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,QAAQ,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC;qBACtD;oBAED,KAA0B,UAA6B,EAA7B,KAAA,IAAI,CAAC,uBAAwB,EAA7B,cAA6B,EAA7B,IAA6B,EAAE;wBAApD,IAAM,WAAW,SAAA;wBACjB,WAAoB,CAAC,qBAAqB,CAAC,QAAQ,EAAE,QAAQ,EAAE,EAAE,EAAE,IAAI,CAAC,CAAC;qBAC7E;oBAED,OAAO,oBAAoB,CAAC;gBAChC,CAAC,CAAC,CAAC;YACP,CAAC,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;IACP,CAAC;IACL,8BAAC;AAAD,CAAC,AAvFD,IAuFC;;AAED,UAAU,CAAC,iBAAiB,CAAC,IAAI,EAAE,UAAC,MAAM,IAAK,OAAA,IAAI,uBAAuB,CAAC,MAAM,CAAC,EAAnC,CAAmC,CAAC,CAAC","sourcesContent":["import { Vector3, Quaternion, Matrix } from '@babylonjs/core/Maths/math.vector';\nimport { Mesh } from '@babylonjs/core/Meshes/mesh';\nimport { TransformNode } from \"@babylonjs/core/Meshes/transformNode\";\nimport { Nullable } from \"@babylonjs/core/types\";\nimport { GLTFLoader, ArrayItem } from \"../glTFLoader\";\nimport { IGLTFLoaderExtension } from \"../glTFLoaderExtension\";\nimport { INode } from \"../glTFLoaderInterfaces\";\nimport { TmpVectors } from '@babylonjs/core/Maths/math.vector';\nimport { IEXTMeshGpuInstancing } from \"babylonjs-gltf2interface\";\n\nconst NAME = \"EXT_mesh_gpu_instancing\";\n\n/**\n * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1691)\n * [Playground Sample](https://playground.babylonjs.com/#QFIGLW#9)\n * !!! Experimental Extension Subject to Changes !!!\n */\nexport class EXT_mesh_gpu_instancing implements IGLTFLoaderExtension {\n /**\n * The name of this extension.\n */\n public readonly name = NAME;\n\n /**\n * Defines whether this extension is enabled.\n */\n public enabled: boolean;\n\n private _loader: GLTFLoader;\n\n /** @hidden */\n constructor(loader: GLTFLoader) {\n this._loader = loader;\n this.enabled = this._loader.isExtensionUsed(NAME);\n }\n\n /** @hidden */\n public dispose() {\n (this._loader as any) = null;\n }\n\n /** @hidden */\n public loadNodeAsync(context: string, node: INode, assign: (babylonTransformNode: TransformNode) => void): Nullable<Promise<TransformNode>> {\n return GLTFLoader.LoadExtensionAsync<IEXTMeshGpuInstancing, TransformNode>(context, node, this.name, (extensionContext, extension) => {\n this._loader._disableInstancedMesh++;\n\n const promise = this._loader.loadNodeAsync(`/nodes/${node.index}`, node, assign);\n\n this._loader._disableInstancedMesh--;\n\n if (!node._primitiveBabylonMeshes) {\n return promise;\n }\n\n const promises = new Array<Promise<Nullable<Float32Array>>>();\n let instanceCount = 0;\n\n const loadAttribute = (attribute: string) => {\n if (extension.attributes[attribute] == undefined) {\n promises.push(Promise.resolve(null));\n return;\n }\n\n const accessor = ArrayItem.Get(`${extensionContext}/attributes/${attribute}`, this._loader.gltf.accessors, extension.attributes[attribute]);\n promises.push(this._loader._loadFloatAccessorAsync(`/accessors/${accessor.bufferView}`, accessor));\n\n if (instanceCount === 0) {\n instanceCount = accessor.count;\n } else if (instanceCount !== accessor.count) {\n throw new Error(`${extensionContext}/attributes: Instance buffer accessors do not have the same count.`);\n }\n };\n\n loadAttribute(\"TRANSLATION\");\n loadAttribute(\"ROTATION\");\n loadAttribute(\"SCALE\");\n\n return promise.then((babylonTransformNode) => {\n return Promise.all(promises).then(([translationBuffer, rotationBuffer, scaleBuffer]) => {\n const matrices = new Float32Array(instanceCount * 16);\n\n TmpVectors.Vector3[0].copyFromFloats(0, 0, 0); // translation\n TmpVectors.Quaternion[0].copyFromFloats(0, 0, 0, 1); // rotation\n TmpVectors.Vector3[1].copyFromFloats(1, 1, 1); // scale\n\n for (let i = 0; i < instanceCount; ++i) {\n translationBuffer && Vector3.FromArrayToRef(translationBuffer, i * 3, TmpVectors.Vector3[0]);\n rotationBuffer && Quaternion.FromArrayToRef(rotationBuffer, i * 4, TmpVectors.Quaternion[0]);\n scaleBuffer && Vector3.FromArrayToRef(scaleBuffer, i * 3, TmpVectors.Vector3[1]);\n\n Matrix.ComposeToRef(TmpVectors.Vector3[1], TmpVectors.Quaternion[0], TmpVectors.Vector3[0], TmpVectors.Matrix[0]);\n\n TmpVectors.Matrix[0].copyToArray(matrices, i * 16);\n }\n\n for (const babylonMesh of node._primitiveBabylonMeshes!) {\n (babylonMesh as Mesh).thinInstanceSetBuffer(\"matrix\", matrices, 16, true);\n }\n\n return babylonTransformNode;\n });\n });\n });\n }\n}\n\nGLTFLoader.RegisterExtension(NAME, (loader) => new EXT_mesh_gpu_instancing(loader));\n"]}
1
+ {"version":3,"file":"EXT_mesh_gpu_instancing.js","sourceRoot":"","sources":["../../../../../sourceES6/loaders/src/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,mCAAmC,CAAC;AAIhF,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAGtD,OAAO,EAAE,UAAU,EAAE,MAAM,mCAAmC,CAAC;AAG/D,OAAO,yCAAyC,CAAC;AAEjD,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CAAC,EAAnC,CAAmC,CAAC,CAAC","sourcesContent":["import { Vector3, Quaternion, Matrix } from '@babylonjs/core/Maths/math.vector';\nimport { Mesh } from '@babylonjs/core/Meshes/mesh';\nimport { TransformNode } from \"@babylonjs/core/Meshes/transformNode\";\nimport { Nullable } from \"@babylonjs/core/types\";\nimport { GLTFLoader, ArrayItem } from \"../glTFLoader\";\nimport { IGLTFLoaderExtension } from \"../glTFLoaderExtension\";\nimport { INode } from \"../glTFLoaderInterfaces\";\nimport { TmpVectors } from '@babylonjs/core/Maths/math.vector';\nimport { IEXTMeshGpuInstancing } from \"babylonjs-gltf2interface\";\n\nimport \"@babylonjs/core/Meshes/thinInstanceMesh\";\n\nconst NAME = \"EXT_mesh_gpu_instancing\";\n\n/**\n * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1691)\n * [Playground Sample](https://playground.babylonjs.com/#QFIGLW#9)\n * !!! Experimental Extension Subject to Changes !!!\n */\nexport class EXT_mesh_gpu_instancing implements IGLTFLoaderExtension {\n /**\n * The name of this extension.\n */\n public readonly name = NAME;\n\n /**\n * Defines whether this extension is enabled.\n */\n public enabled: boolean;\n\n private _loader: GLTFLoader;\n\n /** @hidden */\n constructor(loader: GLTFLoader) {\n this._loader = loader;\n this.enabled = this._loader.isExtensionUsed(NAME);\n }\n\n /** @hidden */\n public dispose() {\n (this._loader as any) = null;\n }\n\n /** @hidden */\n public loadNodeAsync(context: string, node: INode, assign: (babylonTransformNode: TransformNode) => void): Nullable<Promise<TransformNode>> {\n return GLTFLoader.LoadExtensionAsync<IEXTMeshGpuInstancing, TransformNode>(context, node, this.name, (extensionContext, extension) => {\n this._loader._disableInstancedMesh++;\n\n const promise = this._loader.loadNodeAsync(`/nodes/${node.index}`, node, assign);\n\n this._loader._disableInstancedMesh--;\n\n if (!node._primitiveBabylonMeshes) {\n return promise;\n }\n\n const promises = new Array<Promise<Nullable<Float32Array>>>();\n let instanceCount = 0;\n\n const loadAttribute = (attribute: string) => {\n if (extension.attributes[attribute] == undefined) {\n promises.push(Promise.resolve(null));\n return;\n }\n\n const accessor = ArrayItem.Get(`${extensionContext}/attributes/${attribute}`, this._loader.gltf.accessors, extension.attributes[attribute]);\n promises.push(this._loader._loadFloatAccessorAsync(`/accessors/${accessor.bufferView}`, accessor));\n\n if (instanceCount === 0) {\n instanceCount = accessor.count;\n } else if (instanceCount !== accessor.count) {\n throw new Error(`${extensionContext}/attributes: Instance buffer accessors do not have the same count.`);\n }\n };\n\n loadAttribute(\"TRANSLATION\");\n loadAttribute(\"ROTATION\");\n loadAttribute(\"SCALE\");\n\n return promise.then((babylonTransformNode) => {\n return Promise.all(promises).then(([translationBuffer, rotationBuffer, scaleBuffer]) => {\n const matrices = new Float32Array(instanceCount * 16);\n\n TmpVectors.Vector3[0].copyFromFloats(0, 0, 0); // translation\n TmpVectors.Quaternion[0].copyFromFloats(0, 0, 0, 1); // rotation\n TmpVectors.Vector3[1].copyFromFloats(1, 1, 1); // scale\n\n for (let i = 0; i < instanceCount; ++i) {\n translationBuffer && Vector3.FromArrayToRef(translationBuffer, i * 3, TmpVectors.Vector3[0]);\n rotationBuffer && Quaternion.FromArrayToRef(rotationBuffer, i * 4, TmpVectors.Quaternion[0]);\n scaleBuffer && Vector3.FromArrayToRef(scaleBuffer, i * 3, TmpVectors.Vector3[1]);\n\n Matrix.ComposeToRef(TmpVectors.Vector3[1], TmpVectors.Quaternion[0], TmpVectors.Vector3[0], TmpVectors.Matrix[0]);\n\n TmpVectors.Matrix[0].copyToArray(matrices, i * 16);\n }\n\n for (const babylonMesh of node._primitiveBabylonMeshes!) {\n (babylonMesh as Mesh).thinInstanceSetBuffer(\"matrix\", matrices, 16, true);\n }\n\n return babylonTransformNode;\n });\n });\n });\n }\n}\n\nGLTFLoader.RegisterExtension(NAME, (loader) => new EXT_mesh_gpu_instancing(loader));\n"]}
@@ -46,9 +46,9 @@ export declare class GLTFLoader implements IGLTFLoader {
46
46
  _babylonLights: Light[];
47
47
  /** @hidden */
48
48
  _disableInstancedMesh: number;
49
+ private readonly _parent;
50
+ private readonly _extensions;
49
51
  private _disposed;
50
- private _parent;
51
- private _extensions;
52
52
  private _rootUrl;
53
53
  private _fileName;
54
54
  private _uniqueRootUrl;
@@ -57,6 +57,7 @@ export declare class GLTFLoader implements IGLTFLoader {
57
57
  private _babylonScene;
58
58
  private _rootBabylonMesh;
59
59
  private _defaultBabylonMaterialData;
60
+ private _postSceneLoadActions;
60
61
  private static _RegisteredExtensions;
61
62
  /**
62
63
  * The default glTF sampler.
@@ -149,6 +150,7 @@ export declare class GLTFLoader implements IGLTFLoader {
149
150
  private static _LoadTransform;
150
151
  private _loadSkinAsync;
151
152
  private _loadBones;
153
+ private _findSkeletonRootNode;
152
154
  private _loadBone;
153
155
  private _loadSkinInverseBindMatricesDataAsync;
154
156
  private _updateBoneMatrices;
@@ -71,10 +71,15 @@ var GLTFLoader = /** @class */ (function () {
71
71
  this._babylonLights = [];
72
72
  /** @hidden */
73
73
  this._disableInstancedMesh = 0;
74
- this._disposed = false;
75
74
  this._extensions = new Array();
75
+ this._disposed = false;
76
+ this._rootUrl = null;
77
+ this._fileName = null;
78
+ this._uniqueRootUrl = null;
79
+ this._bin = null;
76
80
  this._rootBabylonMesh = null;
77
81
  this._defaultBabylonMaterialData = {};
82
+ this._postSceneLoadActions = new Array();
78
83
  this._parent = parent;
79
84
  }
80
85
  /**
@@ -107,6 +112,9 @@ var GLTFLoader = /** @class */ (function () {
107
112
  * The object that represents the glTF JSON.
108
113
  */
109
114
  get: function () {
115
+ if (!this._gltf) {
116
+ throw new Error("glTF JSON is not available");
117
+ }
110
118
  return this._gltf;
111
119
  },
112
120
  enumerable: false,
@@ -137,6 +145,9 @@ var GLTFLoader = /** @class */ (function () {
137
145
  * The Babylon scene when loading the asset.
138
146
  */
139
147
  get: function () {
148
+ if (!this._babylonScene) {
149
+ throw new Error("Scene is not available");
150
+ }
140
151
  return this._babylonScene;
141
152
  },
142
153
  enumerable: false,
@@ -159,14 +170,14 @@ var GLTFLoader = /** @class */ (function () {
159
170
  }
160
171
  this._disposed = true;
161
172
  this._completePromises.length = 0;
162
- for (var name_1 in this._extensions) {
163
- var extension = this._extensions[name_1];
164
- extension.dispose && extension.dispose();
165
- delete this._extensions[name_1];
166
- }
167
- this._gltf = null;
168
- this._babylonScene = null;
173
+ this._extensions.forEach(function (extension) { return extension.dispose && extension.dispose(); });
174
+ this._extensions.length = 0;
175
+ this._gltf = null; // TODO
176
+ this._bin = null;
177
+ this._babylonScene = null; // TODO
169
178
  this._rootBabylonMesh = null;
179
+ this._defaultBabylonMaterialData = {};
180
+ this._postSceneLoadActions.length = 0;
170
181
  this._parent.dispose();
171
182
  };
172
183
  /** @hidden */
@@ -349,10 +360,10 @@ var GLTFLoader = /** @class */ (function () {
349
360
  }
350
361
  };
351
362
  GLTFLoader.prototype._loadExtensions = function () {
352
- for (var name_2 in GLTFLoader._RegisteredExtensions) {
353
- var extension = GLTFLoader._RegisteredExtensions[name_2].factory(this);
354
- if (extension.name !== name_2) {
355
- Logger.Warn("The name of the glTF loader extension instance does not match the registered name: ".concat(extension.name, " !== ").concat(name_2));
363
+ for (var name_1 in GLTFLoader._RegisteredExtensions) {
364
+ var extension = GLTFLoader._RegisteredExtensions[name_1].factory(this);
365
+ if (extension.name !== name_1) {
366
+ Logger.Warn("The name of the glTF loader extension instance does not match the registered name: ".concat(extension.name, " !== ").concat(name_1));
356
367
  }
357
368
  this._extensions.push(extension);
358
369
  this._parent.onExtensionLoadedObservable.notifyObservers(extension);
@@ -362,16 +373,16 @@ var GLTFLoader = /** @class */ (function () {
362
373
  };
363
374
  GLTFLoader.prototype._checkExtensions = function () {
364
375
  if (this._gltf.extensionsRequired) {
365
- var _loop_1 = function (name_3) {
366
- var available = this_1._extensions.some(function (extension) { return extension.name === name_3 && extension.enabled; });
376
+ var _loop_1 = function (name_2) {
377
+ var available = this_1._extensions.some(function (extension) { return extension.name === name_2 && extension.enabled; });
367
378
  if (!available) {
368
- throw new Error("Require extension ".concat(name_3, " is not available"));
379
+ throw new Error("Require extension ".concat(name_2, " is not available"));
369
380
  }
370
381
  };
371
382
  var this_1 = this;
372
383
  for (var _i = 0, _a = this._gltf.extensionsRequired; _i < _a.length; _i++) {
373
- var name_3 = _a[_i];
374
- _loop_1(name_3);
384
+ var name_2 = _a[_i];
385
+ _loop_1(name_2);
375
386
  }
376
387
  }
377
388
  };
@@ -428,18 +439,9 @@ var GLTFLoader = /** @class */ (function () {
428
439
  }));
429
440
  }
430
441
  }
431
- // Link all Babylon bones for each glTF node with the corresponding Babylon transform node.
432
- // A glTF joint is a pointer to a glTF node in the glTF node hierarchy similar to Unity3D.
433
- if (this._gltf.nodes) {
434
- for (var _b = 0, _c = this._gltf.nodes; _b < _c.length; _b++) {
435
- var node = _c[_b];
436
- if (node._babylonTransformNode && node._babylonBones) {
437
- for (var _d = 0, _e = node._babylonBones; _d < _e.length; _d++) {
438
- var babylonBone = _e[_d];
439
- babylonBone.linkTransformNode(node._babylonTransformNode);
440
- }
441
- }
442
- }
442
+ for (var _b = 0, _c = this._postSceneLoadActions; _b < _c.length; _b++) {
443
+ var action = _c[_b];
444
+ action();
443
445
  }
444
446
  promises.push(this._loadAnimationsAsync());
445
447
  this.logClose();
@@ -591,7 +593,7 @@ var GLTFLoader = /** @class */ (function () {
591
593
  }
592
594
  assign(babylonTransformNode);
593
595
  };
594
- if (node.mesh == undefined) {
596
+ if (node.mesh == undefined || node.skin != undefined) {
595
597
  var nodeName = node.name || "node".concat(node.index);
596
598
  this._babylonScene._blockEntityCollection = !!this._assetContainer;
597
599
  node._babylonTransformNode = new TransformNode(nodeName, this._babylonScene);
@@ -599,9 +601,37 @@ var GLTFLoader = /** @class */ (function () {
599
601
  this._babylonScene._blockEntityCollection = false;
600
602
  loadNode(node._babylonTransformNode);
601
603
  }
602
- else {
603
- var mesh = ArrayItem.Get("".concat(context, "/mesh"), this._gltf.meshes, node.mesh);
604
- promises.push(this._loadMeshAsync("/meshes/".concat(mesh.index), node, mesh, loadNode));
604
+ if (node.mesh != undefined) {
605
+ if (node.skin == undefined) {
606
+ var mesh = ArrayItem.Get("".concat(context, "/mesh"), this._gltf.meshes, node.mesh);
607
+ promises.push(this._loadMeshAsync("/meshes/".concat(mesh.index), node, mesh, loadNode));
608
+ }
609
+ else {
610
+ // See https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#skins (second implementation note)
611
+ // This code path will place the skinned mesh as a sibling of the skeleton root node without loading the
612
+ // transform, which effectively ignores the transform of the skinned mesh, as per spec.
613
+ var mesh = ArrayItem.Get("".concat(context, "/mesh"), this._gltf.meshes, node.mesh);
614
+ promises.push(this._loadMeshAsync("/meshes/".concat(mesh.index), node, mesh, function (babylonTransformNode) {
615
+ GLTFLoader.AddPointerMetadata(babylonTransformNode, context);
616
+ var skin = ArrayItem.Get("".concat(context, "/skin"), _this._gltf.skins, node.skin);
617
+ promises.push(_this._loadSkinAsync("/skins/".concat(skin.index), node, skin, function (babylonSkeleton) {
618
+ _this._forEachPrimitive(node, function (babylonMesh) {
619
+ babylonMesh.skeleton = babylonSkeleton;
620
+ });
621
+ // Wait until the scene is loaded to ensure the skeleton root node has been loaded.
622
+ _this._postSceneLoadActions.push(function () {
623
+ if (skin.skeleton != undefined) {
624
+ // Place the skinned mesh node as a sibling of the skeleton root node.
625
+ var skeletonRootNode = ArrayItem.Get("/skins/".concat(skin.index, "/skeleton"), _this._gltf.nodes, skin.skeleton);
626
+ babylonTransformNode.parent = skeletonRootNode.parent._babylonTransformNode;
627
+ }
628
+ else {
629
+ babylonTransformNode.parent = _this._rootBabylonMesh;
630
+ }
631
+ });
632
+ }));
633
+ }));
634
+ }
605
635
  }
606
636
  this.logClose();
607
637
  return Promise.all(promises).then(function () {
@@ -649,10 +679,6 @@ var GLTFLoader = /** @class */ (function () {
649
679
  }));
650
680
  }
651
681
  }
652
- if (node.skin != undefined) {
653
- var skin = ArrayItem.Get("".concat(context, "/skin"), this._gltf.skins, node.skin);
654
- promises.push(this._loadSkinAsync("/skins/".concat(skin.index), node, skin));
655
- }
656
682
  assign(node._babylonTransformNode);
657
683
  this.logClose();
658
684
  return Promise.all(promises).then(function () {
@@ -843,8 +869,8 @@ var GLTFLoader = /** @class */ (function () {
843
869
  babylonMesh.morphTargetManager.areUpdatesFrozen = true;
844
870
  for (var index = 0; index < primitive.targets.length; index++) {
845
871
  var weight = node.weights ? node.weights[index] : mesh.weights ? mesh.weights[index] : 0;
846
- var name_4 = targetNames ? targetNames[index] : "morphTarget".concat(index);
847
- babylonMesh.morphTargetManager.addTarget(new MorphTarget(name_4, weight, babylonMesh.getScene()));
872
+ var name_3 = targetNames ? targetNames[index] : "morphTarget".concat(index);
873
+ babylonMesh.morphTargetManager.addTarget(new MorphTarget(name_3, weight, babylonMesh.getScene()));
848
874
  // TODO: tell the target whether it has positions, normals, tangents
849
875
  }
850
876
  };
@@ -936,19 +962,14 @@ var GLTFLoader = /** @class */ (function () {
936
962
  babylonNode.rotationQuaternion = rotation;
937
963
  babylonNode.scaling = scaling;
938
964
  };
939
- GLTFLoader.prototype._loadSkinAsync = function (context, node, skin) {
965
+ GLTFLoader.prototype._loadSkinAsync = function (context, node, skin, assign) {
940
966
  var _this = this;
941
967
  var extensionPromise = this._extensionsLoadSkinAsync(context, node, skin);
942
968
  if (extensionPromise) {
943
969
  return extensionPromise;
944
970
  }
945
- var assignSkeleton = function (skeleton) {
946
- _this._forEachPrimitive(node, function (babylonMesh) {
947
- babylonMesh.skeleton = skeleton;
948
- });
949
- };
950
971
  if (skin._data) {
951
- assignSkeleton(skin._data.babylonSkeleton);
972
+ assign(skin._data.babylonSkeleton);
952
973
  return skin._data.promise;
953
974
  }
954
975
  var skeletonId = "skeleton".concat(skin.index);
@@ -956,10 +977,7 @@ var GLTFLoader = /** @class */ (function () {
956
977
  var babylonSkeleton = new Skeleton(skin.name || skeletonId, skeletonId, this._babylonScene);
957
978
  babylonSkeleton._parentContainer = this._assetContainer;
958
979
  this._babylonScene._blockEntityCollection = false;
959
- // See https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#skins (second implementation note)
960
- babylonSkeleton.overrideMesh = this._rootBabylonMesh;
961
980
  this._loadBones(context, skin, babylonSkeleton);
962
- assignSkeleton(babylonSkeleton);
963
981
  var promise = this._loadSkinInverseBindMatricesDataAsync(context, skin).then(function (inverseBindMatricesData) {
964
982
  _this._updateBoneMatrices(babylonSkeleton, inverseBindMatricesData);
965
983
  });
@@ -967,9 +985,36 @@ var GLTFLoader = /** @class */ (function () {
967
985
  babylonSkeleton: babylonSkeleton,
968
986
  promise: promise
969
987
  };
988
+ assign(babylonSkeleton);
970
989
  return promise;
971
990
  };
972
991
  GLTFLoader.prototype._loadBones = function (context, skin, babylonSkeleton) {
992
+ if (skin.skeleton == undefined || this._parent.alwaysComputeSkeletonRootNode) {
993
+ var rootNode = this._findSkeletonRootNode("".concat(context, "/joints"), skin.joints);
994
+ if (rootNode) {
995
+ if (skin.skeleton === undefined) {
996
+ skin.skeleton = rootNode.index;
997
+ }
998
+ else {
999
+ var isParent = function (a, b) {
1000
+ for (; b.parent; b = b.parent) {
1001
+ if (b.parent === a) {
1002
+ return true;
1003
+ }
1004
+ }
1005
+ return false;
1006
+ };
1007
+ var skeletonNode = ArrayItem.Get("".concat(context, "/skeleton"), this._gltf.nodes, skin.skeleton);
1008
+ if (skeletonNode !== rootNode && !isParent(skeletonNode, rootNode)) {
1009
+ Logger.Warn("".concat(context, "/skeleton: Overriding with nearest common ancestor as skeleton node is not a common root"));
1010
+ skin.skeleton = rootNode.index;
1011
+ }
1012
+ }
1013
+ }
1014
+ else {
1015
+ Logger.Warn("".concat(context, ": Failed to find common root"));
1016
+ }
1017
+ }
973
1018
  var babylonBones = {};
974
1019
  for (var _i = 0, _a = skin.joints; _i < _a.length; _i++) {
975
1020
  var index = _a[_i];
@@ -977,20 +1022,57 @@ var GLTFLoader = /** @class */ (function () {
977
1022
  this._loadBone(node, skin, babylonSkeleton, babylonBones);
978
1023
  }
979
1024
  };
1025
+ GLTFLoader.prototype._findSkeletonRootNode = function (context, joints) {
1026
+ var paths = {};
1027
+ for (var _i = 0, joints_1 = joints; _i < joints_1.length; _i++) {
1028
+ var index = joints_1[_i];
1029
+ var path = new Array();
1030
+ var node = ArrayItem.Get("".concat(context, "/").concat(index), this._gltf.nodes, index);
1031
+ while (node.index !== -1) {
1032
+ path.unshift(node);
1033
+ node = node.parent;
1034
+ }
1035
+ paths[index] = path;
1036
+ }
1037
+ var rootNode = null;
1038
+ for (var i = 0;; ++i) {
1039
+ var path = paths[joints[0]];
1040
+ if (i >= path.length) {
1041
+ return rootNode;
1042
+ }
1043
+ var node = path[i];
1044
+ for (var j = 1; j < joints.length; ++j) {
1045
+ path = paths[joints[j]];
1046
+ if (i >= path.length || node !== path[i]) {
1047
+ return rootNode;
1048
+ }
1049
+ }
1050
+ rootNode = node;
1051
+ }
1052
+ };
980
1053
  GLTFLoader.prototype._loadBone = function (node, skin, babylonSkeleton, babylonBones) {
981
1054
  var babylonBone = babylonBones[node.index];
982
1055
  if (babylonBone) {
983
1056
  return babylonBone;
984
1057
  }
985
- var babylonParentBone = null;
986
- if (node.parent && node.parent._babylonTransformNode !== this._rootBabylonMesh) {
987
- babylonParentBone = this._loadBone(node.parent, skin, babylonSkeleton, babylonBones);
1058
+ var parentBabylonBone = null;
1059
+ if (node.index !== skin.skeleton) {
1060
+ if (node.parent && node.parent.index !== -1) {
1061
+ parentBabylonBone = this._loadBone(node.parent, skin, babylonSkeleton, babylonBones);
1062
+ }
1063
+ else if (skin.skeleton !== undefined) {
1064
+ Logger.Warn("/skins/".concat(skin.index, "/skeleton: Skeleton node is not a common root"));
1065
+ }
988
1066
  }
989
1067
  var boneIndex = skin.joints.indexOf(node.index);
990
- babylonBone = new Bone(node.name || "joint".concat(node.index), babylonSkeleton, babylonParentBone, this._getNodeMatrix(node), null, null, boneIndex);
1068
+ babylonBone = new Bone(node.name || "joint".concat(node.index), babylonSkeleton, parentBabylonBone, this._getNodeMatrix(node), null, null, boneIndex);
991
1069
  babylonBones[node.index] = babylonBone;
992
- node._babylonBones = node._babylonBones || [];
993
- node._babylonBones.push(babylonBone);
1070
+ // Wait until the scene is loaded to ensure the transform nodes are loaded.
1071
+ this._postSceneLoadActions.push(function () {
1072
+ // Link the Babylon bone with the corresponding Babylon transform node.
1073
+ // A glTF joint is a pointer to a glTF node in the glTF node hierarchy similar to Unity3D.
1074
+ babylonBone.linkTransformNode(node._babylonTransformNode);
1075
+ });
994
1076
  return babylonBone;
995
1077
  };
996
1078
  GLTFLoader.prototype._loadSkinInverseBindMatricesDataAsync = function (context, skin) {
@@ -1179,34 +1261,34 @@ var GLTFLoader = /** @class */ (function () {
1179
1261
  var getNextOutputValue;
1180
1262
  switch (targetPath) {
1181
1263
  case "position": {
1182
- getNextOutputValue = function () {
1183
- var value = Vector3.FromArray(data.output, outputBufferOffset);
1264
+ getNextOutputValue = function (scale) {
1265
+ var value = Vector3.FromArray(data.output, outputBufferOffset).scaleInPlace(scale);
1184
1266
  outputBufferOffset += 3;
1185
1267
  return value;
1186
1268
  };
1187
1269
  break;
1188
1270
  }
1189
1271
  case "rotationQuaternion": {
1190
- getNextOutputValue = function () {
1191
- var value = Quaternion.FromArray(data.output, outputBufferOffset);
1272
+ getNextOutputValue = function (scale) {
1273
+ var value = Quaternion.FromArray(data.output, outputBufferOffset).scaleInPlace(scale);
1192
1274
  outputBufferOffset += 4;
1193
1275
  return value;
1194
1276
  };
1195
1277
  break;
1196
1278
  }
1197
1279
  case "scaling": {
1198
- getNextOutputValue = function () {
1199
- var value = Vector3.FromArray(data.output, outputBufferOffset);
1280
+ getNextOutputValue = function (scale) {
1281
+ var value = Vector3.FromArray(data.output, outputBufferOffset).scaleInPlace(scale);
1200
1282
  outputBufferOffset += 3;
1201
1283
  return value;
1202
1284
  };
1203
1285
  break;
1204
1286
  }
1205
1287
  case "influence": {
1206
- getNextOutputValue = function () {
1288
+ getNextOutputValue = function (scale) {
1207
1289
  var value = new Array(targetNode._numMorphTargets);
1208
1290
  for (var i = 0; i < targetNode._numMorphTargets; i++) {
1209
- value[i] = data.output[outputBufferOffset++];
1291
+ value[i] = data.output[outputBufferOffset++] * scale;
1210
1292
  }
1211
1293
  return value;
1212
1294
  };
@@ -1217,25 +1299,26 @@ var GLTFLoader = /** @class */ (function () {
1217
1299
  switch (data.interpolation) {
1218
1300
  case "STEP" /* STEP */: {
1219
1301
  getNextKey = function (frameIndex) { return ({
1220
- frame: data.input[frameIndex],
1221
- value: getNextOutputValue(),
1302
+ frame: data.input[frameIndex] * _this.parent.targetFps,
1303
+ value: getNextOutputValue(1),
1222
1304
  interpolation: AnimationKeyInterpolation.STEP
1223
1305
  }); };
1224
1306
  break;
1225
1307
  }
1226
1308
  case "LINEAR" /* LINEAR */: {
1227
1309
  getNextKey = function (frameIndex) { return ({
1228
- frame: data.input[frameIndex],
1229
- value: getNextOutputValue()
1310
+ frame: data.input[frameIndex] * _this.parent.targetFps,
1311
+ value: getNextOutputValue(1)
1230
1312
  }); };
1231
1313
  break;
1232
1314
  }
1233
1315
  case "CUBICSPLINE" /* CUBICSPLINE */: {
1316
+ var invTargetFps_1 = 1 / _this.parent.targetFps;
1234
1317
  getNextKey = function (frameIndex) { return ({
1235
- frame: data.input[frameIndex],
1236
- inTangent: getNextOutputValue(),
1237
- value: getNextOutputValue(),
1238
- outTangent: getNextOutputValue()
1318
+ frame: data.input[frameIndex] * _this.parent.targetFps,
1319
+ inTangent: getNextOutputValue(invTargetFps_1),
1320
+ value: getNextOutputValue(1),
1321
+ outTangent: getNextOutputValue(invTargetFps_1)
1239
1322
  }); };
1240
1323
  break;
1241
1324
  }
@@ -1247,7 +1330,7 @@ var GLTFLoader = /** @class */ (function () {
1247
1330
  if (targetPath === "influence") {
1248
1331
  var _loop_2 = function (targetIndex) {
1249
1332
  var animationName = "".concat(babylonAnimationGroup.name, "_channel").concat(babylonAnimationGroup.targetedAnimations.length);
1250
- var babylonAnimation = new Animation(animationName, targetPath, 1, animationType);
1333
+ var babylonAnimation = new Animation(animationName, targetPath, _this.parent.targetFps, animationType);
1251
1334
  babylonAnimation.setKeys(keys.map(function (key) { return ({
1252
1335
  frame: key.frame,
1253
1336
  inTangent: key.inTangent ? key.inTangent[targetIndex] : undefined,
@@ -1268,7 +1351,7 @@ var GLTFLoader = /** @class */ (function () {
1268
1351
  }
1269
1352
  else {
1270
1353
  var animationName = "".concat(babylonAnimationGroup.name, "_channel").concat(babylonAnimationGroup.targetedAnimations.length);
1271
- var babylonAnimation = new Animation(animationName, targetPath, 1, animationType);
1354
+ var babylonAnimation = new Animation(animationName, targetPath, _this.parent.targetFps, animationType);
1272
1355
  babylonAnimation.setKeys(keys);
1273
1356
  if (animationTargetOverride != null && animationTargetOverride.animations != null) {
1274
1357
  animationTargetOverride.animations.push(babylonAnimation);