@babylonjs/loaders 6.21.0 → 6.21.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
1
  import { DracoCompression } from "@babylonjs/core/Meshes/Compression/dracoCompression.js";
2
2
  import type { Nullable } from "@babylonjs/core/types.js";
3
- import { Geometry } from "@babylonjs/core/Meshes/geometry.js";
3
+ import type { Geometry } from "@babylonjs/core/Meshes/geometry.js";
4
4
  import type { Mesh } from "@babylonjs/core/Meshes/mesh.js";
5
5
  import type { IMeshPrimitive } from "../glTFLoaderInterfaces";
6
6
  import type { IGLTFLoaderExtension } from "../glTFLoaderExtension";
@@ -1,6 +1,5 @@
1
1
  import { DracoCompression } from "@babylonjs/core/Meshes/Compression/dracoCompression.js";
2
2
  import { VertexBuffer } from "@babylonjs/core/Buffers/buffer.js";
3
- import { Geometry } from "@babylonjs/core/Meshes/geometry.js";
4
3
  import { GLTFLoader, ArrayItem } from "../glTFLoader.js";
5
4
  const NAME = "KHR_draco_mesh_compression";
6
5
  /**
@@ -39,36 +38,16 @@ export class KHR_draco_mesh_compression {
39
38
  }
40
39
  }
41
40
  const attributes = {};
42
- const dividers = {};
43
41
  const loadAttribute = (name, kind) => {
44
42
  const uniqueId = extension.attributes[name];
45
- if (uniqueId === undefined || primitive.attributes[name] === undefined) {
43
+ if (uniqueId == undefined) {
46
44
  return;
47
45
  }
48
- attributes[kind] = uniqueId;
49
- const accessor = ArrayItem.Get(`${context}/attributes/${name}`, this._loader.gltf.accessors, primitive.attributes[name]);
50
- if (accessor.normalized && accessor.componentType !== 5126 /* AccessorComponentType.FLOAT */) {
51
- let divider = 1;
52
- switch (accessor.componentType) {
53
- case 5120 /* AccessorComponentType.BYTE */:
54
- divider = 127.0;
55
- break;
56
- case 5121 /* AccessorComponentType.UNSIGNED_BYTE */:
57
- divider = 255.0;
58
- break;
59
- case 5122 /* AccessorComponentType.SHORT */:
60
- divider = 32767.0;
61
- break;
62
- case 5123 /* AccessorComponentType.UNSIGNED_SHORT */:
63
- divider = 65535.0;
64
- break;
65
- }
66
- dividers[kind] = divider;
67
- }
68
46
  babylonMesh._delayInfo = babylonMesh._delayInfo || [];
69
47
  if (babylonMesh._delayInfo.indexOf(kind) === -1) {
70
48
  babylonMesh._delayInfo.push(kind);
71
49
  }
50
+ attributes[kind] = uniqueId;
72
51
  };
73
52
  loadAttribute("POSITION", VertexBuffer.PositionKind);
74
53
  loadAttribute("NORMAL", VertexBuffer.NormalKind);
@@ -86,14 +65,7 @@ export class KHR_draco_mesh_compression {
86
65
  if (!bufferView._dracoBabylonGeometry) {
87
66
  bufferView._dracoBabylonGeometry = this._loader.loadBufferViewAsync(`/bufferViews/${bufferView.index}`, bufferView).then((data) => {
88
67
  const dracoCompression = this.dracoCompression || DracoCompression.Default;
89
- return dracoCompression
90
- .decodeMeshAsync(data, attributes, dividers)
91
- .then((babylonVertexData) => {
92
- const babylonGeometry = new Geometry(babylonMesh.name, this._loader.babylonScene);
93
- babylonVertexData.applyToGeometry(babylonGeometry);
94
- return babylonGeometry;
95
- })
96
- .catch((error) => {
68
+ return dracoCompression.decodeMeshToGeometryAsync(babylonMesh.name, this._loader.babylonScene, data, attributes).catch((error) => {
97
69
  throw new Error(`${context}: ${error.message}`);
98
70
  });
99
71
  });
@@ -1 +1 @@
1
- {"version":3,"file":"KHR_draco_mesh_compression.js","sourceRoot":"","sources":["../../../../../../dev/loaders/src/glTF/2.0/Extensions/KHR_draco_mesh_compression.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,+DAAiD;AAE5E,OAAO,EAAE,YAAY,EAAE,0CAA4B;AACnD,OAAO,EAAE,QAAQ,EAAE,2CAA6B;AAOhD,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAEtD,MAAM,IAAI,GAAG,4BAA4B,CAAC;AAM1C;;GAEG;AACH,gEAAgE;AAChE,MAAM,OAAO,0BAA0B;IAkBnC;;OAEG;IACH,YAAY,MAAkB;QApB9B;;WAEG;QACa,SAAI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AAC,CAAC;oBACpD,CAAC,CAAC,CAAC;gBACX,CAAC,CAAC,CAAC;aACN;YAED,OAAO,UAAU,CAAC,qBAAqB,CAAC;QAC5C,CAAC,CAAC,CAAC;IACP,CAAC;CACJ;AAED,UAAU,CAAC,iBAAiB,CAAC,IAAI,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,0BAA0B,CAAC,MAAM,CAAC,CAAC,CAAC","sourcesContent":["import { DracoCompression } from \"core/Meshes/Compression/dracoCompression\";\r\nimport type { Nullable } from \"core/types\";\r\nimport { VertexBuffer } from \"core/Buffers/buffer\";\r\nimport { Geometry } from \"core/Meshes/geometry\";\r\nimport type { Mesh } from \"core/Meshes/mesh\";\r\n\r\nimport { MeshPrimitiveMode, AccessorComponentType } from \"babylonjs-gltf2interface\";\r\nimport type { IKHRDracoMeshCompression } from \"babylonjs-gltf2interface\";\r\nimport type { IMeshPrimitive, IBufferView } from \"../glTFLoaderInterfaces\";\r\nimport type { IGLTFLoaderExtension } from \"../glTFLoaderExtension\";\r\nimport { GLTFLoader, ArrayItem } from \"../glTFLoader\";\r\n\r\nconst NAME = \"KHR_draco_mesh_compression\";\r\n\r\ninterface IBufferViewDraco extends IBufferView {\r\n _dracoBabylonGeometry?: Promise<Geometry>;\r\n}\r\n\r\n/**\r\n * [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_draco_mesh_compression/README.md)\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class KHR_draco_mesh_compression implements IGLTFLoaderExtension {\r\n /**\r\n * The name of this extension.\r\n */\r\n public readonly name = NAME;\r\n\r\n /**\r\n * The draco compression used to decode vertex data or DracoCompression.Default if not defined\r\n */\r\n public dracoCompression?: DracoCompression;\r\n\r\n /**\r\n * Defines whether this extension is enabled.\r\n */\r\n public enabled: boolean;\r\n\r\n private _loader: GLTFLoader;\r\n\r\n /**\r\n * @internal\r\n */\r\n constructor(loader: GLTFLoader) {\r\n this._loader = loader;\r\n this.enabled = DracoCompression.DecoderAvailable && this._loader.isExtensionUsed(NAME);\r\n }\r\n\r\n /** @internal */\r\n public dispose(): void {\r\n delete this.dracoCompression;\r\n (this._loader as any) = null;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _loadVertexDataAsync(context: string, primitive: IMeshPrimitive, babylonMesh: Mesh): Nullable<Promise<Geometry>> {\r\n return GLTFLoader.LoadExtensionAsync<IKHRDracoMeshCompression, Geometry>(context, primitive, this.name, (extensionContext, extension) => {\r\n if (primitive.mode != undefined) {\r\n if (primitive.mode !== MeshPrimitiveMode.TRIANGLE_STRIP && primitive.mode !== MeshPrimitiveMode.TRIANGLES) {\r\n throw new Error(`${context}: Unsupported mode ${primitive.mode}`);\r\n }\r\n\r\n // TODO: handle triangle strips\r\n if (primitive.mode === MeshPrimitiveMode.TRIANGLE_STRIP) {\r\n throw new Error(`${context}: Mode ${primitive.mode} is not currently supported`);\r\n }\r\n }\r\n\r\n const attributes: {\r\n [kind: string]: number;\r\n } = {};\r\n const dividers: {\r\n [kind: string]: number;\r\n } = {};\r\n const loadAttribute = (name: string, kind: string) => {\r\n const uniqueId = extension.attributes[name];\r\n if (uniqueId === undefined || primitive.attributes[name] === undefined) {\r\n return;\r\n }\r\n\r\n attributes[kind] = uniqueId;\r\n const accessor = ArrayItem.Get(`${context}/attributes/${name}`, this._loader.gltf.accessors, primitive.attributes[name]);\r\n if (accessor.normalized && accessor.componentType !== AccessorComponentType.FLOAT) {\r\n let divider = 1;\r\n switch (accessor.componentType) {\r\n case AccessorComponentType.BYTE:\r\n divider = 127.0;\r\n break;\r\n case AccessorComponentType.UNSIGNED_BYTE:\r\n divider = 255.0;\r\n break;\r\n case AccessorComponentType.SHORT:\r\n divider = 32767.0;\r\n break;\r\n case AccessorComponentType.UNSIGNED_SHORT:\r\n divider = 65535.0;\r\n break;\r\n }\r\n dividers[kind] = divider;\r\n }\r\n\r\n babylonMesh._delayInfo = babylonMesh._delayInfo || [];\r\n if (babylonMesh._delayInfo.indexOf(kind) === -1) {\r\n babylonMesh._delayInfo.push(kind);\r\n }\r\n };\r\n\r\n loadAttribute(\"POSITION\", VertexBuffer.PositionKind);\r\n loadAttribute(\"NORMAL\", VertexBuffer.NormalKind);\r\n loadAttribute(\"TANGENT\", VertexBuffer.TangentKind);\r\n loadAttribute(\"TEXCOORD_0\", VertexBuffer.UVKind);\r\n loadAttribute(\"TEXCOORD_1\", VertexBuffer.UV2Kind);\r\n loadAttribute(\"TEXCOORD_2\", VertexBuffer.UV3Kind);\r\n loadAttribute(\"TEXCOORD_3\", VertexBuffer.UV4Kind);\r\n loadAttribute(\"TEXCOORD_4\", VertexBuffer.UV5Kind);\r\n loadAttribute(\"TEXCOORD_5\", VertexBuffer.UV6Kind);\r\n loadAttribute(\"JOINTS_0\", VertexBuffer.MatricesIndicesKind);\r\n loadAttribute(\"WEIGHTS_0\", VertexBuffer.MatricesWeightsKind);\r\n loadAttribute(\"COLOR_0\", VertexBuffer.ColorKind);\r\n\r\n const bufferView = ArrayItem.Get(extensionContext, this._loader.gltf.bufferViews, extension.bufferView) as IBufferViewDraco;\r\n if (!bufferView._dracoBabylonGeometry) {\r\n bufferView._dracoBabylonGeometry = this._loader.loadBufferViewAsync(`/bufferViews/${bufferView.index}`, bufferView).then((data) => {\r\n const dracoCompression = this.dracoCompression || DracoCompression.Default;\r\n return dracoCompression\r\n .decodeMeshAsync(data, attributes, dividers)\r\n .then((babylonVertexData) => {\r\n const babylonGeometry = new Geometry(babylonMesh.name, this._loader.babylonScene);\r\n babylonVertexData.applyToGeometry(babylonGeometry);\r\n return babylonGeometry;\r\n })\r\n .catch((error) => {\r\n throw new Error(`${context}: ${error.message}`);\r\n });\r\n });\r\n }\r\n\r\n return bufferView._dracoBabylonGeometry;\r\n });\r\n }\r\n}\r\n\r\nGLTFLoader.RegisterExtension(NAME, (loader) => new KHR_draco_mesh_compression(loader));\r\n"]}
1
+ {"version":3,"file":"KHR_draco_mesh_compression.js","sourceRoot":"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AAY,CAAC,SAAS,CAAC,CAAC;YAEjD,MAAM,UAAU,GAAG,SAAS,CAAC,GAAG,CAAC,gBAAgB,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,WAAW,EAAE,SAAS,CAAC,UAAU,CAAqB,CAAC;YAC5H,IAAI,CAAC,UAAU,CAAC,qBAAqB,EAAE;gBACnC,UAAU,CAAC,qBAAqB,GAAG,IAAI,CAAC,OAAO,CAAC,mBAAmB,CAAC,gBAAgB,UAAU,CAAC,KAAK,EAAE,EAAE,UAAU,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE;oBAC9H,MAAM,gBAAgB,GAAG,IAAI,CAAC,gBAAgB,IAAI,gBAAgB,CAAC,OAAO,CAAC;oBAC3E,OAAO,gBAAgB,CAAC,yBAAyB,CAAC,WAAW,CAAC,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,YAAY,EAAE,IAAI,EAAE,UAAU,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;wBAC7H,MAAM,IAAI,KAAK,CAAC,GAAG,OAAO,KAAK,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;oBACpD,CAAC,CAAC,CAAC;gBACP,CAAC,CAAC,CAAC;aACN;YAED,OAAO,UAAU,CAAC,qBAAqB,CAAC;QAC5C,CAAC,CAAC,CAAC;IACP,CAAC;CACJ;AAED,UAAU,CAAC,iBAAiB,CAAC,IAAI,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,0BAA0B,CAAC,MAAM,CAAC,CAAC,CAAC","sourcesContent":["import { DracoCompression } from \"core/Meshes/Compression/dracoCompression\";\r\nimport type { Nullable } from \"core/types\";\r\nimport { VertexBuffer } from \"core/Buffers/buffer\";\r\nimport type { Geometry } from \"core/Meshes/geometry\";\r\nimport type { Mesh } from \"core/Meshes/mesh\";\r\n\r\nimport { MeshPrimitiveMode } from \"babylonjs-gltf2interface\";\r\nimport type { IKHRDracoMeshCompression } from \"babylonjs-gltf2interface\";\r\nimport type { IMeshPrimitive, IBufferView } from \"../glTFLoaderInterfaces\";\r\nimport type { IGLTFLoaderExtension } from \"../glTFLoaderExtension\";\r\nimport { GLTFLoader, ArrayItem } from \"../glTFLoader\";\r\n\r\nconst NAME = \"KHR_draco_mesh_compression\";\r\n\r\ninterface IBufferViewDraco extends IBufferView {\r\n _dracoBabylonGeometry?: Promise<Geometry>;\r\n}\r\n\r\n/**\r\n * [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_draco_mesh_compression/README.md)\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class KHR_draco_mesh_compression implements IGLTFLoaderExtension {\r\n /**\r\n * The name of this extension.\r\n */\r\n public readonly name = NAME;\r\n\r\n /**\r\n * The draco compression used to decode vertex data or DracoCompression.Default if not defined\r\n */\r\n public dracoCompression?: DracoCompression;\r\n\r\n /**\r\n * Defines whether this extension is enabled.\r\n */\r\n public enabled: boolean;\r\n\r\n private _loader: GLTFLoader;\r\n\r\n /**\r\n * @internal\r\n */\r\n constructor(loader: GLTFLoader) {\r\n this._loader = loader;\r\n this.enabled = DracoCompression.DecoderAvailable && this._loader.isExtensionUsed(NAME);\r\n }\r\n\r\n /** @internal */\r\n public dispose(): void {\r\n delete this.dracoCompression;\r\n (this._loader as any) = null;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _loadVertexDataAsync(context: string, primitive: IMeshPrimitive, babylonMesh: Mesh): Nullable<Promise<Geometry>> {\r\n return GLTFLoader.LoadExtensionAsync<IKHRDracoMeshCompression, Geometry>(context, primitive, this.name, (extensionContext, extension) => {\r\n if (primitive.mode != undefined) {\r\n if (primitive.mode !== MeshPrimitiveMode.TRIANGLE_STRIP && primitive.mode !== MeshPrimitiveMode.TRIANGLES) {\r\n throw new Error(`${context}: Unsupported mode ${primitive.mode}`);\r\n }\r\n\r\n // TODO: handle triangle strips\r\n if (primitive.mode === MeshPrimitiveMode.TRIANGLE_STRIP) {\r\n throw new Error(`${context}: Mode ${primitive.mode} is not currently supported`);\r\n }\r\n }\r\n\r\n const attributes: { [kind: string]: number } = {};\r\n const loadAttribute = (name: string, kind: string) => {\r\n const uniqueId = extension.attributes[name];\r\n if (uniqueId == undefined) {\r\n return;\r\n }\r\n\r\n babylonMesh._delayInfo = babylonMesh._delayInfo || [];\r\n if (babylonMesh._delayInfo.indexOf(kind) === -1) {\r\n babylonMesh._delayInfo.push(kind);\r\n }\r\n\r\n attributes[kind] = uniqueId;\r\n };\r\n\r\n loadAttribute(\"POSITION\", VertexBuffer.PositionKind);\r\n loadAttribute(\"NORMAL\", VertexBuffer.NormalKind);\r\n loadAttribute(\"TANGENT\", VertexBuffer.TangentKind);\r\n loadAttribute(\"TEXCOORD_0\", VertexBuffer.UVKind);\r\n loadAttribute(\"TEXCOORD_1\", VertexBuffer.UV2Kind);\r\n loadAttribute(\"TEXCOORD_2\", VertexBuffer.UV3Kind);\r\n loadAttribute(\"TEXCOORD_3\", VertexBuffer.UV4Kind);\r\n loadAttribute(\"TEXCOORD_4\", VertexBuffer.UV5Kind);\r\n loadAttribute(\"TEXCOORD_5\", VertexBuffer.UV6Kind);\r\n loadAttribute(\"JOINTS_0\", VertexBuffer.MatricesIndicesKind);\r\n loadAttribute(\"WEIGHTS_0\", VertexBuffer.MatricesWeightsKind);\r\n loadAttribute(\"COLOR_0\", VertexBuffer.ColorKind);\r\n\r\n const bufferView = ArrayItem.Get(extensionContext, this._loader.gltf.bufferViews, extension.bufferView) as IBufferViewDraco;\r\n if (!bufferView._dracoBabylonGeometry) {\r\n bufferView._dracoBabylonGeometry = this._loader.loadBufferViewAsync(`/bufferViews/${bufferView.index}`, bufferView).then((data) => {\r\n const dracoCompression = this.dracoCompression || DracoCompression.Default;\r\n return dracoCompression.decodeMeshToGeometryAsync(babylonMesh.name, this._loader.babylonScene, data, attributes).catch((error) => {\r\n throw new Error(`${context}: ${error.message}`);\r\n });\r\n });\r\n }\r\n\r\n return bufferView._dracoBabylonGeometry;\r\n });\r\n }\r\n}\r\n\r\nGLTFLoader.RegisterExtension(NAME, (loader) => new KHR_draco_mesh_compression(loader));\r\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@babylonjs/loaders",
3
- "version": "6.21.0",
3
+ "version": "6.21.1",
4
4
  "main": "index.js",
5
5
  "module": "index.js",
6
6
  "types": "index.d.ts",
@@ -18,10 +18,10 @@
18
18
  "postcompile": "build-tools -c add-js-to-es6"
19
19
  },
20
20
  "devDependencies": {
21
- "@babylonjs/core": "^6.21.0",
21
+ "@babylonjs/core": "^6.21.1",
22
22
  "@dev/build-tools": "^1.0.0",
23
23
  "@lts/loaders": "^1.0.0",
24
- "babylonjs-gltf2interface": "^6.21.0"
24
+ "babylonjs-gltf2interface": "^6.21.1"
25
25
  },
26
26
  "peerDependencies": {
27
27
  "@babylonjs/core": "^6.0.0",