@babylonjs/loaders 5.23.0 → 5.24.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -35,7 +35,7 @@ export declare class MTLFileLoader {
35
35
  * @param rootUrl The root url to load from
36
36
  * @param value The value stored in the mtl
37
37
  * @param scene
38
- * @return The Texture
38
+ * @returns The Texture
39
39
  */
40
40
  private static _GetTexture;
41
41
  }
@@ -197,7 +197,7 @@ export class MTLFileLoader {
197
197
  * @param rootUrl The root url to load from
198
198
  * @param value The value stored in the mtl
199
199
  * @param scene
200
- * @return The Texture
200
+ * @returns The Texture
201
201
  */
202
202
  static _GetTexture(rootUrl, value, scene) {
203
203
  if (!value) {
@@ -1 +1 @@
1
- {"version":3,"file":"mtlFileLoader.js","sourceRoot":"","sources":["../../../../../lts/loaders/generated/OBJ/mtlFileLoader.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,4CAA8B;AAC/C,OAAO,EAAE,OAAO,EAAE,sDAAwC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,sDAAwC;AAInE;;GAEG;AACH,MAAM,OAAO,aAAa;IAA1B;QAMI;;WAEG;QACI,cAAS,GAAuB,EAAE,CAAC;IA+M9C,CAAC;IA7MG;;;;;;;;;;OAUG;IACI,QAAQ,CAAC,KAAY,EAAE,IAA0B,EAAE,OAAe,EAAE,cAAwC;QAC/G,IAAI,IAAI,YAAY,WAAW,EAAE;YAC7B,OAAO;SACV;QAED,+BAA+B;QAC/B,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAC/B,kCAAkC;QAClC,MAAM,iBAAiB,GAAG,KAAK,CAAC;QAChC,uBAAuB;QACvB,IAAI,KAAe,CAAC;QACpB,cAAc;QACd,IAAI,QAAQ,GAA+B,IAAI,CAAC;QAEhD,mBAAmB;QACnB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;YACnC,MAAM,IAAI,GAAG,KAAK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;YACV,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;SACjC;IACL,CAAC;IAED;;;;;;;;;;OAUG;IACK,MAAM,CAAC,WAAW,CAAC,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;iBAAM;gBACH,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;;AAtND;;GAEG;AACW,8BAAgB,GAAG,IAAI,CAAC","sourcesContent":["import type { Nullable } from \"core/types\";\r\nimport { Color3 } from \"core/Maths/math.color\";\r\nimport { Texture } from \"core/Materials/Textures/texture\";\r\nimport { StandardMaterial } from \"core/Materials/standardMaterial\";\r\n\r\nimport type { Scene } from \"core/scene\";\r\nimport type { AssetContainer } from \"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 const lines = data.split(\"\\n\");\r\n // whitespace char ie: [ \\t\\r\\n\\f]\r\n const delimiter_pattern = /\\s+/;\r\n //Array with RGB colors\r\n let color: number[];\r\n //New material\r\n let material: Nullable<StandardMaterial> = null;\r\n\r\n //Look at each line\r\n for (let i = 0; i < lines.length; i++) {\r\n const 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 const pos = line.indexOf(\" \");\r\n let 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 const 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 //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 texture 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 * @param scene\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 let url = rootUrl;\r\n // Load from input file.\r\n if (rootUrl === \"file:\") {\r\n let 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 } 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"]}
1
+ {"version":3,"file":"mtlFileLoader.js","sourceRoot":"","sources":["../../../../../lts/loaders/generated/OBJ/mtlFileLoader.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,4CAA8B;AAC/C,OAAO,EAAE,OAAO,EAAE,sDAAwC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,sDAAwC;AAInE;;GAEG;AACH,MAAM,OAAO,aAAa;IAA1B;QAMI;;WAEG;QACI,cAAS,GAAuB,EAAE,CAAC;IA+M9C,CAAC;IA7MG;;;;;;;;;;OAUG;IACI,QAAQ,CAAC,KAAY,EAAE,IAA0B,EAAE,OAAe,EAAE,cAAwC;QAC/G,IAAI,IAAI,YAAY,WAAW,EAAE;YAC7B,OAAO;SACV;QAED,+BAA+B;QAC/B,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAC/B,kCAAkC;QAClC,MAAM,iBAAiB,GAAG,KAAK,CAAC;QAChC,uBAAuB;QACvB,IAAI,KAAe,CAAC;QACpB,cAAc;QACd,IAAI,QAAQ,GAA+B,IAAI,CAAC;QAEhD,mBAAmB;QACnB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;YACnC,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,C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AC,QAAQ,CAAC,CAAC;SACjC;IACL,CAAC;IAED;;;;;;;;;;OAUG;IACK,MAAM,CAAC,WAAW,CAAC,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;iBAAM;gBACH,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;;AAtND;;GAEG;AACW,8BAAgB,GAAG,IAAI,CAAC","sourcesContent":["import type { Nullable } from \"core/types\";\r\nimport { Color3 } from \"core/Maths/math.color\";\r\nimport { Texture } from \"core/Materials/Textures/texture\";\r\nimport { StandardMaterial } from \"core/Materials/standardMaterial\";\r\n\r\nimport type { Scene } from \"core/scene\";\r\nimport type { AssetContainer } from \"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 const lines = data.split(\"\\n\");\r\n // whitespace char ie: [ \\t\\r\\n\\f]\r\n const delimiter_pattern = /\\s+/;\r\n //Array with RGB colors\r\n let color: number[];\r\n //New material\r\n let material: Nullable<StandardMaterial> = null;\r\n\r\n //Look at each line\r\n for (let i = 0; i < lines.length; i++) {\r\n const 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 const pos = line.indexOf(\" \");\r\n let 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 const 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 //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 texture 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 * @param scene\r\n * @returns 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 let url = rootUrl;\r\n // Load from input file.\r\n if (rootUrl === \"file:\") {\r\n let 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 } 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"]}
@@ -70,7 +70,7 @@ export declare class KHR_animation_pointer implements IGLTFLoaderExtension {
70
70
  * - "/materials/2/extensions/KHR_materials_emissive_strength/emissiveStrength"
71
71
  * @param context
72
72
  * @param pointer
73
- * @return
73
+ * @returns
74
74
  */
75
75
  private _parseAnimationPointer;
76
76
  }
@@ -212,7 +212,7 @@ export class KHR_animation_pointer {
212
212
  * - "/materials/2/extensions/KHR_materials_emissive_strength/emissiveStrength"
213
213
  * @param context
214
214
  * @param pointer
215
- * @return
215
+ * @returns
216
216
  */
217
217
  _parseAnimationPointer(context, pointer) {
218
218
  const sep = "/";
@@ -1 +1 @@
1
- {"version":3,"file":"KHR_animation_pointer.js","sourceRoot":"","sources":["../../../../../../../lts/loaders/generated/glTF/2.0/Extensions/KHR_animation_pointer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAEtD,OAAO,EAAE,cAAc,EAAE,qDAAuC;AAKhE,OAAO,EAAE,yBAAyB,EAAE,mDAAqC;AACzE,OAAO,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAEtE,OAAO,EAAE,2BAA2B,EAAE,MAAM,kBAAkB,CAAC;AAE/D,MAAM,IAAI,GAAG,UAAU,CAAC,wBAAwB,CAAC;AASjD;;GAEG;AACH,gEAAgE;AAChE,MAAM,OAAO,qBAAqB;IAa9B;;;OAGG;IACH,YAAY,MAAkB;QAhB9B;;WA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r\nimport { ArrayItem, GLTFLoader } from \"../glTFLoader\";\r\nimport type { Nullable } from \"core/types\";\r\nimport { AnimationGroup } from \"core/Animations/animationGroup\";\r\nimport type { IAnimatable } from \"core/Animations/animatable.interface\";\r\nimport type { IAnimation, IAnimationChannel, _IAnimationSamplerData, IAnimationSampler } from \"../glTFLoaderInterfaces\";\r\n\r\nimport { AnimationChannelTargetPath, AnimationSamplerInterpolation } from \"babylonjs-gltf2interface\";\r\nimport { AnimationKeyInterpolation } from \"core/Animations/animationKey\";\r\nimport { CoreAnimationPointerMap } from \"./KHR_animation_pointer.map\";\r\nimport type { GetGltfNodeTargetFn, IAnimationPointerPropertyInfos } from \"./KHR_animation_pointer.map\";\r\nimport { getDataAccessorElementCount } from \"../glTFUtilities\";\r\n\r\nconst NAME = GLTFLoader._KHRAnimationPointerName;\r\n\r\ninterface IAnimationChannelTarget {\r\n stride?: number;\r\n target: any;\r\n properties: Array<IAnimationPointerPropertyInfos>;\r\n params: any;\r\n}\r\n\r\n/**\r\n * [Specification PR](https://github.com/KhronosGroup/glTF/pull/2147)\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class KHR_animation_pointer implements IGLTFLoaderExtension {\r\n /**\r\n * used to gently ignore invalid pointer. If false, invalid pointer will throw exception.\r\n */\r\n public ignoreInvalidPointer: boolean = true;\r\n\r\n /**\r\n * The name of this extension.\r\n */\r\n public readonly name = NAME;\r\n\r\n private _loader: GLTFLoader;\r\n\r\n /**\r\n * @param loader\r\n * @hidden\r\n */\r\n constructor(loader: GLTFLoader) {\r\n this._loader = loader;\r\n }\r\n\r\n /**\r\n * Defines whether this extension is enabled.\r\n */\r\n public get enabled(): boolean {\r\n return this._loader.isExtensionUsed(NAME);\r\n }\r\n\r\n /** @hidden */\r\n public dispose() {\r\n (this._loader as any) = null;\r\n }\r\n\r\n /**\r\n * according to specification,\r\n * It is not allowed to animate a glTFid property, as it does change the structure of the glTF in general\r\n * It is not allowed to animate a name property in general.\r\n * @param property\r\n * @hidden\r\n */\r\n public accept(property: string): boolean {\r\n return property != \"name\";\r\n }\r\n\r\n public loadAnimationAsync(context: string, animation: IAnimation): Nullable<Promise<AnimationGroup>> {\r\n // ensure an animation group is present.\r\n if (!animation._babylonAnimationGroup) {\r\n this._loader.babylonScene._blockEntityCollection = !!this._loader._assetContainer;\r\n const group = new AnimationGroup(animation.name || `animation${animation.index}`, this._loader.babylonScene);\r\n group._parentContainer = this._loader._assetContainer;\r\n this._loader.babylonScene._blockEntityCollection = false;\r\n animation._babylonAnimationGroup = group;\r\n }\r\n const babylonAnimationGroup = animation._babylonAnimationGroup;\r\n\r\n const promises = new Array<Promise<any>>();\r\n ArrayItem.Assign(animation.channels);\r\n ArrayItem.Assign(animation.samplers);\r\n\r\n for (const channel of animation.channels) {\r\n promises.push(this._loadAnimationChannelAsync(`${context}/channels/${channel.index}`, context, animation, channel));\r\n }\r\n\r\n return Promise.all(promises).then(() => {\r\n babylonAnimationGroup.normalize(0);\r\n return babylonAnimationGroup;\r\n });\r\n }\r\n\r\n /**\r\n * @hidden Loads a glTF animation channel.\r\n * @param context The context when loading the asset\r\n * @param animationContext The context of the animation when loading the asset\r\n * @param animation The glTF animation property\r\n * @param channel The glTF animation channel property\r\n * @param animationTargetOverride The babylon animation channel target override property. My be null.\r\n * @returns A void promise when the channel load is complete\r\n */\r\n public _loadAnimationChannelAsync(\r\n context: string,\r\n animationContext: string,\r\n animation: IAnimation,\r\n channel: IAnimationChannel,\r\n animationTargetOverride: Nullable<IAnimatable> = null\r\n ): Promise<void> {\r\n if (channel.target.path != AnimationChannelTargetPath.POINTER) {\r\n throw new Error(`${context}/target/path: Invalid value (${channel.target.path})`);\r\n }\r\n\r\n if (channel.target.node != undefined) {\r\n // According to KHR_animation_pointer specification\r\n // If this extension is used, the animation.channel.target.node must not be set.\r\n // Because the node is defined, the channel is ignored and not animated due to the specification.\r\n return Promise.resolve();\r\n }\r\n\r\n const pointer = channel.target.extensions?.KHR_animation_pointer?.pointer;\r\n if (!pointer) {\r\n throw new Error(`${context}/target/extensions/${this.name}: Pointer is missing`);\r\n }\r\n\r\n const sampler = ArrayItem.Get(`${context}/sampler`, animation.samplers, channel.sampler);\r\n\r\n return this._loadAnimationSamplerAsync(`${context}/samplers/${channel.sampler}`, sampler).then((data) => {\r\n // this is where we process the pointer.\r\n const animationTarget = this._parseAnimationPointer(`${context}/extensions/${this.name}/pointer`, pointer);\r\n\r\n if (!animationTarget) {\r\n return;\r\n }\r\n // build the keys\r\n // build the animations into the group\r\n const babylonAnimationGroup = animation._babylonAnimationGroup;\r\n if (!babylonAnimationGroup) {\r\n return;\r\n }\r\n\r\n const outputAccessor = ArrayItem.Get(`${context}/output`, this._loader.gltf.accessors, sampler.output);\r\n // stride is the size of each element stored into the output buffer.\r\n const stride = animationTarget.stride ?? getDataAccessorElementCount(outputAccessor.type);\r\n const fps = this._loader.parent.targetFps;\r\n\r\n // we extract the corresponding values from the read value.\r\n // the reason for that is one GLTF value may be dispatched to several Babylon properties\r\n // one of example is baseColorFactor which is a Color4 under GLTF and dispatched to\r\n // - albedoColor as Color3(Color4.r,Color4.g,Color4.b)\r\n // - alpha as Color4.a\r\n for (const propertyInfo of animationTarget.properties) {\r\n // Ignore animations that have no animation valid targets.\r\n if (!propertyInfo.isValid(animationTarget.target)) {\r\n return;\r\n }\r\n\r\n // build the keys.\r\n const keys = new Array(data.input.length);\r\n let outputOffset = 0;\r\n\r\n switch (data.interpolation) {\r\n case AnimationSamplerInterpolation.STEP: {\r\n for (let frameIndex = 0; frameIndex < data.input.length; frameIndex++) {\r\n keys[frameIndex] = {\r\n frame: data.input[frameIndex] * fps,\r\n value: propertyInfo.get(animationTarget.target, data.output, outputOffset),\r\n interpolation: AnimationKeyInterpolation.STEP,\r\n };\r\n outputOffset += stride;\r\n }\r\n break;\r\n }\r\n case AnimationSamplerInterpolation.CUBICSPLINE: {\r\n const invfps = 1 / fps;\r\n for (let frameIndex = 0; frameIndex < data.input.length; frameIndex++) {\r\n const k: any = {\r\n frame: data.input[frameIndex] * fps,\r\n };\r\n\r\n (k.inTangent = propertyInfo.get(animationTarget.target, data.output, outputOffset, invfps)), (outputOffset += stride);\r\n (k.value = propertyInfo.get(animationTarget.target, data.output, outputOffset)), (outputOffset += stride);\r\n (k.outTangent = propertyInfo.get(animationTarget.target, data.output, outputOffset, invfps)), (outputOffset += stride);\r\n\r\n keys[frameIndex] = k;\r\n }\r\n break;\r\n }\r\n case AnimationSamplerInterpolation.LINEAR:\r\n default: {\r\n for (let frameIndex = 0; frameIndex < data.input.length; frameIndex++) {\r\n keys[frameIndex] = {\r\n frame: data.input[frameIndex] * fps,\r\n value: propertyInfo.get(animationTarget.target, data.output, outputOffset),\r\n };\r\n outputOffset += stride;\r\n }\r\n break;\r\n }\r\n }\r\n\r\n // each properties has its own build animation process.\r\n // these logics are located into KHR_animation_pointer.map.ts\r\n propertyInfo.buildAnimations(animationTarget.target, fps, keys, babylonAnimationGroup, animationTargetOverride, animationTarget.params);\r\n }\r\n });\r\n }\r\n\r\n private _loadAnimationSamplerAsync(context: string, sampler: IAnimationSampler): Promise<_IAnimationSamplerData> {\r\n if (sampler._data) {\r\n return sampler._data;\r\n }\r\n\r\n const interpolation = sampler.interpolation || AnimationSamplerInterpolation.LINEAR;\r\n switch (interpolation) {\r\n case AnimationSamplerInterpolation.STEP:\r\n case AnimationSamplerInterpolation.LINEAR:\r\n case AnimationSamplerInterpolation.CUBICSPLINE: {\r\n break;\r\n }\r\n default: {\r\n throw new Error(`${context}/interpolation: Invalid value (${sampler.interpolation})`);\r\n }\r\n }\r\n\r\n const inputAccessor = ArrayItem.Get(`${context}/input`, this._loader.gltf.accessors, sampler.input);\r\n const outputAccessor = ArrayItem.Get(`${context}/output`, this._loader.gltf.accessors, sampler.output);\r\n sampler._data = Promise.all([\r\n this._loader._loadFloatAccessorAsync(`/accessors/${inputAccessor.index}`, inputAccessor),\r\n this._loader._loadFloatAccessorAsync(`/accessors/${outputAccessor.index}`, outputAccessor),\r\n ]).then(([inputData, outputData]) => {\r\n return {\r\n input: inputData,\r\n interpolation: interpolation,\r\n output: outputData,\r\n };\r\n });\r\n\r\n return sampler._data;\r\n }\r\n\r\n /**\r\n * parsing animation pointer is the core of animation channel.\r\n * Animation pointer is a Json pointer, which mean it locate an item into the json hierarchy.\r\n * Consequentely the pointer has the following BNF\r\n \r\n * <animationPointer> := <sep><assetContainer><sep><assetIndex><sep><propertyPath>\r\n * <assetContainer> := \"nodes\" | \"materials\" | \"meshes\" | \"cameras\" | \"extensions\" \r\n * <assetIndex> := <digit> | <name>\r\n * <propertyPath> := <extensionPath> | <standardPath>\r\n * <extensionPath> := \"extensions\"<sep><name><sep><standardPath>\r\n * <standardPath> := <name> | <name><sep><standardPath> \r\n * <sep>:= \"/\"\r\n * <name> := W+\r\n * <digit> := D+\r\n * \r\n * examples of pointer are\r\n * - \"/nodes/0/rotation\"\r\n * - \"/materials/2/emissiveFactor\"\r\n * - \"/materials/2/pbrMetallicRoughness/baseColorFactor\"\r\n * - \"/materials/2/extensions/KHR_materials_emissive_strength/emissiveStrength\"\r\n * @param context \r\n * @param pointer \r\n * @return \r\n */\r\n private _parseAnimationPointer(context: string, pointer: string): Nullable<IAnimationChannelTarget> {\r\n const sep = \"/\";\r\n if (pointer.charAt(0) == sep) {\r\n pointer = pointer.substring(1);\r\n }\r\n const parts = pointer.split(sep);\r\n // we have a least 3 part\r\n if (parts.length >= 3) {\r\n let node = CoreAnimationPointerMap; // the map of possible path\r\n const indices = [];\r\n let getTarget: Nullable<GetGltfNodeTargetFn> = null;\r\n for (let i = 0; i < parts.length; i++) {\r\n const part = parts[i];\r\n node = node[part];\r\n\r\n if (!node) {\r\n // nothing to do so far\r\n break;\r\n }\r\n\r\n if (node.getTarget) {\r\n getTarget = node.getTarget;\r\n }\r\n\r\n if (node.hasIndex) {\r\n indices.push(parts[++i]);\r\n // move to the next part\r\n continue;\r\n }\r\n\r\n if (node.isIndex) {\r\n indices.push(part);\r\n // move to the next part\r\n continue;\r\n }\r\n\r\n if (node.properties && getTarget) {\r\n const t = getTarget(this._loader.gltf, indices[0]);\r\n if (t != null) {\r\n return {\r\n target: t,\r\n stride: node.getStride ? node.getStride(t) : undefined,\r\n properties: node.properties,\r\n params: indices,\r\n };\r\n }\r\n }\r\n }\r\n }\r\n if (this.ignoreInvalidPointer) {\r\n return null;\r\n }\r\n throw new Error(`${context} invalid pointer. ${pointer}`);\r\n }\r\n}\r\n\r\nGLTFLoader.RegisterExtension(NAME, (loader) => new KHR_animation_pointer(loader));\r\n"]}
1
+ {"version":3,"file":"KHR_animation_pointer.js","sourceRoot":"","sources":["../../../../../../../lts/loaders/generated/glTF/2.0/Extensions/KHR_animation_pointer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAEtD,OAAO,EAAE,cAAc,EAAE,qDAAuC;AAKhE,OAAO,EAAE,yBAAyB,EAAE,mDAAqC;AACzE,OAAO,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAEtE,OAAO,EAAE,2BAA2B,EAAE,MAAM,kBAAkB,CAAC;AAE/D,MAAM,IAAI,GAAG,UAAU,CAAC,wBAAwB,CAAC;AASjD;;GAEG;AACH,gEAAgE;AAChE,MAAM,OAAO,qBAAqB;IAa9B;;;OAGG;IACH,YAAY,MAAkB;QAhB9B;;WAEG;QACI,yBAAoB,GAAY,IAAI,CAAC;QAE5C;;WAEG;QACa,SAAI,GAAG,IAAI,CAAC;QASxB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;IAC1B,CAAC;IAED;;OAEG;IACH,IAAW,OAAO;QACd,OAAO,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;IAC9C,CAAC;IAED,cAAc;IACP,OAAO;QACT,IAAI,CAAC,OAAe,GAAG,IAAI,CAAC;IACjC,CAAC;IAED;;;;;;OAMG;IACI,MAAM,CAAC,QAAgB;QAC1B,OAAO,QAAQ,I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OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;oBACnB,wBAAwB;oBACxB,SAAS;iBACZ;gBAED,IAAI,IAAI,CAAC,UAAU,IAAI,SAAS,EAAE;oBAC9B,MAAM,CAAC,GAAG,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;oBACnD,IAAI,CAAC,IAAI,IAAI,EAAE;wBACX,OAAO;4BACH,MAAM,EAAE,CAAC;4BACT,MAAM,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS;4BACtD,UAAU,EAAE,IAAI,CAAC,UAAU;4BAC3B,MAAM,EAAE,OAAO;yBAClB,CAAC;qBACL;iBACJ;aACJ;SACJ;QACD,IAAI,IAAI,CAAC,oBAAoB,EAAE;YAC3B,OAAO,IAAI,CAAC;SACf;QACD,MAAM,IAAI,KAAK,CAAC,GAAG,OAAO,qBAAqB,OAAO,EAAE,CAAC,CAAC;IAC9D,CAAC;CACJ;AAED,UAAU,CAAC,iBAAiB,CAAC,IAAI,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,qBAAqB,CAAC,MAAM,CAAC,CAAC,CAAC","sourcesContent":["import type { IGLTFLoaderExtension } from \"../glTFLoaderExtension\";\r\nimport { ArrayItem, GLTFLoader } from \"../glTFLoader\";\r\nimport type { Nullable } from \"core/types\";\r\nimport { AnimationGroup } from \"core/Animations/animationGroup\";\r\nimport type { IAnimatable } from \"core/Animations/animatable.interface\";\r\nimport type { IAnimation, IAnimationChannel, _IAnimationSamplerData, IAnimationSampler } from \"../glTFLoaderInterfaces\";\r\n\r\nimport { AnimationChannelTargetPath, AnimationSamplerInterpolation } from \"babylonjs-gltf2interface\";\r\nimport { AnimationKeyInterpolation } from \"core/Animations/animationKey\";\r\nimport { CoreAnimationPointerMap } from \"./KHR_animation_pointer.map\";\r\nimport type { GetGltfNodeTargetFn, IAnimationPointerPropertyInfos } from \"./KHR_animation_pointer.map\";\r\nimport { getDataAccessorElementCount } from \"../glTFUtilities\";\r\n\r\nconst NAME = GLTFLoader._KHRAnimationPointerName;\r\n\r\ninterface IAnimationChannelTarget {\r\n stride?: number;\r\n target: any;\r\n properties: Array<IAnimationPointerPropertyInfos>;\r\n params: any;\r\n}\r\n\r\n/**\r\n * [Specification PR](https://github.com/KhronosGroup/glTF/pull/2147)\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class KHR_animation_pointer implements IGLTFLoaderExtension {\r\n /**\r\n * used to gently ignore invalid pointer. If false, invalid pointer will throw exception.\r\n */\r\n public ignoreInvalidPointer: boolean = true;\r\n\r\n /**\r\n * The name of this extension.\r\n */\r\n public readonly name = NAME;\r\n\r\n private _loader: GLTFLoader;\r\n\r\n /**\r\n * @param loader\r\n * @hidden\r\n */\r\n constructor(loader: GLTFLoader) {\r\n this._loader = loader;\r\n }\r\n\r\n /**\r\n * Defines whether this extension is enabled.\r\n */\r\n public get enabled(): boolean {\r\n return this._loader.isExtensionUsed(NAME);\r\n }\r\n\r\n /** @hidden */\r\n public dispose() {\r\n (this._loader as any) = null;\r\n }\r\n\r\n /**\r\n * according to specification,\r\n * It is not allowed to animate a glTFid property, as it does change the structure of the glTF in general\r\n * It is not allowed to animate a name property in general.\r\n * @param property\r\n * @hidden\r\n */\r\n public accept(property: string): boolean {\r\n return property != \"name\";\r\n }\r\n\r\n public loadAnimationAsync(context: string, animation: IAnimation): Nullable<Promise<AnimationGroup>> {\r\n // ensure an animation group is present.\r\n if (!animation._babylonAnimationGroup) {\r\n this._loader.babylonScene._blockEntityCollection = !!this._loader._assetContainer;\r\n const group = new AnimationGroup(animation.name || `animation${animation.index}`, this._loader.babylonScene);\r\n group._parentContainer = this._loader._assetContainer;\r\n this._loader.babylonScene._blockEntityCollection = false;\r\n animation._babylonAnimationGroup = group;\r\n }\r\n const babylonAnimationGroup = animation._babylonAnimationGroup;\r\n\r\n const promises = new Array<Promise<any>>();\r\n ArrayItem.Assign(animation.channels);\r\n ArrayItem.Assign(animation.samplers);\r\n\r\n for (const channel of animation.channels) {\r\n promises.push(this._loadAnimationChannelAsync(`${context}/channels/${channel.index}`, context, animation, channel));\r\n }\r\n\r\n return Promise.all(promises).then(() => {\r\n babylonAnimationGroup.normalize(0);\r\n return babylonAnimationGroup;\r\n });\r\n }\r\n\r\n /**\r\n * @hidden Loads a glTF animation channel.\r\n * @param context The context when loading the asset\r\n * @param animationContext The context of the animation when loading the asset\r\n * @param animation The glTF animation property\r\n * @param channel The glTF animation channel property\r\n * @param animationTargetOverride The babylon animation channel target override property. My be null.\r\n * @returns A void promise when the channel load is complete\r\n */\r\n public _loadAnimationChannelAsync(\r\n context: string,\r\n animationContext: string,\r\n animation: IAnimation,\r\n channel: IAnimationChannel,\r\n animationTargetOverride: Nullable<IAnimatable> = null\r\n ): Promise<void> {\r\n if (channel.target.path != AnimationChannelTargetPath.POINTER) {\r\n throw new Error(`${context}/target/path: Invalid value (${channel.target.path})`);\r\n }\r\n\r\n if (channel.target.node != undefined) {\r\n // According to KHR_animation_pointer specification\r\n // If this extension is used, the animation.channel.target.node must not be set.\r\n // Because the node is defined, the channel is ignored and not animated due to the specification.\r\n return Promise.resolve();\r\n }\r\n\r\n const pointer = channel.target.extensions?.KHR_animation_pointer?.pointer;\r\n if (!pointer) {\r\n throw new Error(`${context}/target/extensions/${this.name}: Pointer is missing`);\r\n }\r\n\r\n const sampler = ArrayItem.Get(`${context}/sampler`, animation.samplers, channel.sampler);\r\n\r\n return this._loadAnimationSamplerAsync(`${context}/samplers/${channel.sampler}`, sampler).then((data) => {\r\n // this is where we process the pointer.\r\n const animationTarget = this._parseAnimationPointer(`${context}/extensions/${this.name}/pointer`, pointer);\r\n\r\n if (!animationTarget) {\r\n return;\r\n }\r\n // build the keys\r\n // build the animations into the group\r\n const babylonAnimationGroup = animation._babylonAnimationGroup;\r\n if (!babylonAnimationGroup) {\r\n return;\r\n }\r\n\r\n const outputAccessor = ArrayItem.Get(`${context}/output`, this._loader.gltf.accessors, sampler.output);\r\n // stride is the size of each element stored into the output buffer.\r\n const stride = animationTarget.stride ?? getDataAccessorElementCount(outputAccessor.type);\r\n const fps = this._loader.parent.targetFps;\r\n\r\n // we extract the corresponding values from the read value.\r\n // the reason for that is one GLTF value may be dispatched to several Babylon properties\r\n // one of example is baseColorFactor which is a Color4 under GLTF and dispatched to\r\n // - albedoColor as Color3(Color4.r,Color4.g,Color4.b)\r\n // - alpha as Color4.a\r\n for (const propertyInfo of animationTarget.properties) {\r\n // Ignore animations that have no animation valid targets.\r\n if (!propertyInfo.isValid(animationTarget.target)) {\r\n return;\r\n }\r\n\r\n // build the keys.\r\n const keys = new Array(data.input.length);\r\n let outputOffset = 0;\r\n\r\n switch (data.interpolation) {\r\n case AnimationSamplerInterpolation.STEP: {\r\n for (let frameIndex = 0; frameIndex < data.input.length; frameIndex++) {\r\n keys[frameIndex] = {\r\n frame: data.input[frameIndex] * fps,\r\n value: propertyInfo.get(animationTarget.target, data.output, outputOffset),\r\n interpolation: AnimationKeyInterpolation.STEP,\r\n };\r\n outputOffset += stride;\r\n }\r\n break;\r\n }\r\n case AnimationSamplerInterpolation.CUBICSPLINE: {\r\n const invfps = 1 / fps;\r\n for (let frameIndex = 0; frameIndex < data.input.length; frameIndex++) {\r\n const k: any = {\r\n frame: data.input[frameIndex] * fps,\r\n };\r\n\r\n (k.inTangent = propertyInfo.get(animationTarget.target, data.output, outputOffset, invfps)), (outputOffset += stride);\r\n (k.value = propertyInfo.get(animationTarget.target, data.output, outputOffset)), (outputOffset += stride);\r\n (k.outTangent = propertyInfo.get(animationTarget.target, data.output, outputOffset, invfps)), (outputOffset += stride);\r\n\r\n keys[frameIndex] = k;\r\n }\r\n break;\r\n }\r\n case AnimationSamplerInterpolation.LINEAR:\r\n default: {\r\n for (let frameIndex = 0; frameIndex < data.input.length; frameIndex++) {\r\n keys[frameIndex] = {\r\n frame: data.input[frameIndex] * fps,\r\n value: propertyInfo.get(animationTarget.target, data.output, outputOffset),\r\n };\r\n outputOffset += stride;\r\n }\r\n break;\r\n }\r\n }\r\n\r\n // each properties has its own build animation process.\r\n // these logics are located into KHR_animation_pointer.map.ts\r\n propertyInfo.buildAnimations(animationTarget.target, fps, keys, babylonAnimationGroup, animationTargetOverride, animationTarget.params);\r\n }\r\n });\r\n }\r\n\r\n private _loadAnimationSamplerAsync(context: string, sampler: IAnimationSampler): Promise<_IAnimationSamplerData> {\r\n if (sampler._data) {\r\n return sampler._data;\r\n }\r\n\r\n const interpolation = sampler.interpolation || AnimationSamplerInterpolation.LINEAR;\r\n switch (interpolation) {\r\n case AnimationSamplerInterpolation.STEP:\r\n case AnimationSamplerInterpolation.LINEAR:\r\n case AnimationSamplerInterpolation.CUBICSPLINE: {\r\n break;\r\n }\r\n default: {\r\n throw new Error(`${context}/interpolation: Invalid value (${sampler.interpolation})`);\r\n }\r\n }\r\n\r\n const inputAccessor = ArrayItem.Get(`${context}/input`, this._loader.gltf.accessors, sampler.input);\r\n const outputAccessor = ArrayItem.Get(`${context}/output`, this._loader.gltf.accessors, sampler.output);\r\n sampler._data = Promise.all([\r\n this._loader._loadFloatAccessorAsync(`/accessors/${inputAccessor.index}`, inputAccessor),\r\n this._loader._loadFloatAccessorAsync(`/accessors/${outputAccessor.index}`, outputAccessor),\r\n ]).then(([inputData, outputData]) => {\r\n return {\r\n input: inputData,\r\n interpolation: interpolation,\r\n output: outputData,\r\n };\r\n });\r\n\r\n return sampler._data;\r\n }\r\n\r\n /**\r\n * parsing animation pointer is the core of animation channel.\r\n * Animation pointer is a Json pointer, which mean it locate an item into the json hierarchy.\r\n * Consequentely the pointer has the following BNF\r\n \r\n * <animationPointer> := <sep><assetContainer><sep><assetIndex><sep><propertyPath>\r\n * <assetContainer> := \"nodes\" | \"materials\" | \"meshes\" | \"cameras\" | \"extensions\" \r\n * <assetIndex> := <digit> | <name>\r\n * <propertyPath> := <extensionPath> | <standardPath>\r\n * <extensionPath> := \"extensions\"<sep><name><sep><standardPath>\r\n * <standardPath> := <name> | <name><sep><standardPath> \r\n * <sep>:= \"/\"\r\n * <name> := W+\r\n * <digit> := D+\r\n * \r\n * examples of pointer are\r\n * - \"/nodes/0/rotation\"\r\n * - \"/materials/2/emissiveFactor\"\r\n * - \"/materials/2/pbrMetallicRoughness/baseColorFactor\"\r\n * - \"/materials/2/extensions/KHR_materials_emissive_strength/emissiveStrength\"\r\n * @param context \r\n * @param pointer \r\n * @returns \r\n */\r\n private _parseAnimationPointer(context: string, pointer: string): Nullable<IAnimationChannelTarget> {\r\n const sep = \"/\";\r\n if (pointer.charAt(0) == sep) {\r\n pointer = pointer.substring(1);\r\n }\r\n const parts = pointer.split(sep);\r\n // we have a least 3 part\r\n if (parts.length >= 3) {\r\n let node = CoreAnimationPointerMap; // the map of possible path\r\n const indices = [];\r\n let getTarget: Nullable<GetGltfNodeTargetFn> = null;\r\n for (let i = 0; i < parts.length; i++) {\r\n const part = parts[i];\r\n node = node[part];\r\n\r\n if (!node) {\r\n // nothing to do so far\r\n break;\r\n }\r\n\r\n if (node.getTarget) {\r\n getTarget = node.getTarget;\r\n }\r\n\r\n if (node.hasIndex) {\r\n indices.push(parts[++i]);\r\n // move to the next part\r\n continue;\r\n }\r\n\r\n if (node.isIndex) {\r\n indices.push(part);\r\n // move to the next part\r\n continue;\r\n }\r\n\r\n if (node.properties && getTarget) {\r\n const t = getTarget(this._loader.gltf, indices[0]);\r\n if (t != null) {\r\n return {\r\n target: t,\r\n stride: node.getStride ? node.getStride(t) : undefined,\r\n properties: node.properties,\r\n params: indices,\r\n };\r\n }\r\n }\r\n }\r\n }\r\n if (this.ignoreInvalidPointer) {\r\n return null;\r\n }\r\n throw new Error(`${context} invalid pointer. ${pointer}`);\r\n }\r\n}\r\n\r\nGLTFLoader.RegisterExtension(NAME, (loader) => new KHR_animation_pointer(loader));\r\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@babylonjs/loaders",
3
- "version": "5.23.0",
3
+ "version": "5.24.0",
4
4
  "main": "index.js",
5
5
  "module": "index.js",
6
6
  "types": "index.d.ts",
@@ -19,10 +19,10 @@
19
19
  "prepublishOnly": "build-tools -c prepare-es6-build"
20
20
  },
21
21
  "devDependencies": {
22
- "@babylonjs/core": "^5.23.0",
22
+ "@babylonjs/core": "^5.24.0",
23
23
  "@dev/build-tools": "^1.0.0",
24
24
  "@lts/loaders": "^1.0.0",
25
- "babylonjs-gltf2interface": "^5.23.0",
25
+ "babylonjs-gltf2interface": "^5.24.0",
26
26
  "rimraf": "^3.0.2",
27
27
  "typescript": "^4.4.4"
28
28
  },