@babylonjs/serializers 7.12.0 → 7.13.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,6 +2,7 @@ import type { IBufferView, AccessorComponentType, IAccessor } from "babylonjs-gl
2
2
  import { AccessorType } from "babylonjs-gltf2interface";
3
3
  import type { FloatArray, Nullable } from "@babylonjs/core/types.js";
4
4
  import type { Vector4 } from "@babylonjs/core/Maths/math.vector.js";
5
+ import { Vector3 } from "@babylonjs/core/Maths/math.vector.js";
5
6
  /**
6
7
  * @internal
7
8
  */
@@ -40,6 +41,6 @@ export declare class _GLTFUtilities {
40
41
  min: number[];
41
42
  max: number[];
42
43
  };
43
- static _NormalizeTangentFromRef(tangent: Vector4): void;
44
+ static _NormalizeTangentFromRef(tangent: Vector4 | Vector3): void;
44
45
  static _GetDataAccessorElementCount(accessorType: AccessorType): 1 | 3 | 2 | 4 | 9 | 16;
45
46
  }
@@ -1 +1 @@
1
- {"version":3,"file":"glTFUtilities.js","sourceRoot":"","sources":["../../../../../dev/serializers/src/glTF/2.0/glTFUtilities.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,OAAO,EAAE,6CAA+B;AAEjD;;GAEG;AACH,MAAM,OAAO,cAAc;IACvB;;;;;;;;OAQG;IACI,MAAM,CAAC,iBAAiB,CAAC,WAAmB,EAAE,UAAkB,EAAE,UAAkB,EAAE,UAAmB,EAAE,IAAa;QAC3H,MAAM,UAAU,GAAgB,EAAE,MAAM,EAAE,WAAW,EAAE,UAAU,EAAE,UAAU,EAAE,CAAC;QAChF,IAAI,UAAU,EAAE;YACZ,UAAU,CAAC,UAAU,GAAG,UAAU,CAAC;SACtC;QACD,IAAI,IAAI,EAAE;YACN,UAAU,CAAC,IAAI,GAAG,IAAI,CAAC;SAC1B;QACD,IAAI,UAAU,EAAE;YACZ,UAAU,CAAC,UAAU,GAAG,UAAU,CAAC;SACtC;QAED,OAAO,UAAU,CAAC;IACtB,CAAC;IAED;;;;;;;;;;;OAWG;IACI,MAAM,CAAC,eAAe,CACzB,eAAuB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port { AccessorType } from \"babylonjs-gltf2interface\";\r\n\r\nimport type { FloatArray, Nullable } from \"core/types\";\r\nimport type { Vector4 } from \"core/Maths/math.vector\";\r\nimport { Vector3 } from \"core/Maths/math.vector\";\r\n\r\n/**\r\n * @internal\r\n */\r\nexport class _GLTFUtilities {\r\n /**\r\n * Creates a buffer view based on the supplied arguments\r\n * @param bufferIndex index value of the specified buffer\r\n * @param byteOffset byte offset value\r\n * @param byteLength byte length of the bufferView\r\n * @param byteStride byte distance between conequential elements\r\n * @param name name of the buffer view\r\n * @returns bufferView for glTF\r\n */\r\n public static _CreateBufferView(bufferIndex: number, byteOffset: number, byteLength: number, byteStride?: number, name?: string): IBufferView {\r\n const bufferview: IBufferView = { buffer: bufferIndex, byteLength: byteLength };\r\n if (byteOffset) {\r\n bufferview.byteOffset = byteOffset;\r\n }\r\n if (name) {\r\n bufferview.name = name;\r\n }\r\n if (byteStride) {\r\n bufferview.byteStride = byteStride;\r\n }\r\n\r\n return bufferview;\r\n }\r\n\r\n /**\r\n * Creates an accessor based on the supplied arguments\r\n * @param bufferviewIndex The index of the bufferview referenced by this accessor\r\n * @param name The name of the accessor\r\n * @param type The type of the accessor\r\n * @param componentType The datatype of components in the attribute\r\n * @param count The number of attributes referenced by this accessor\r\n * @param byteOffset The offset relative to the start of the bufferView in bytes\r\n * @param min Minimum value of each component in this attribute\r\n * @param max Maximum value of each component in this attribute\r\n * @returns accessor for glTF\r\n */\r\n public static _CreateAccessor(\r\n bufferviewIndex: number,\r\n name: string,\r\n type: AccessorType,\r\n componentType: AccessorComponentType,\r\n count: number,\r\n byteOffset: Nullable<number>,\r\n min: Nullable<number[]>,\r\n max: Nullable<number[]>\r\n ): IAccessor {\r\n const accessor: IAccessor = { name: name, bufferView: bufferviewIndex, componentType: componentType, count: count, type: type };\r\n\r\n if (min != null) {\r\n accessor.min = min;\r\n }\r\n if (max != null) {\r\n accessor.max = max;\r\n }\r\n if (byteOffset != null) {\r\n accessor.byteOffset = byteOffset;\r\n }\r\n\r\n return accessor;\r\n }\r\n\r\n /**\r\n * Calculates the minimum and maximum values of an array of position floats\r\n * @param positions Positions array of a mesh\r\n * @param vertexStart Starting vertex offset to calculate min and max values\r\n * @param vertexCount Number of vertices to check for min and max values\r\n * @returns min number array and max number array\r\n */\r\n public static _CalculateMinMaxPositions(positions: FloatArray, vertexStart: number, vertexCount: number): { min: number[]; max: number[] } {\r\n const min = [Infinity, Infinity, Infinity];\r\n const max = [-Infinity, -Infinity, -Infinity];\r\n const positionStrideSize = 3;\r\n let indexOffset: number;\r\n let position: Vector3;\r\n let vector: number[];\r\n\r\n if (vertexCount) {\r\n for (let i = vertexStart, length = vertexStart + vertexCount; i < length; ++i) {\r\n indexOffset = positionStrideSize * i;\r\n\r\n position = Vector3.FromArray(positions, indexOffset);\r\n vector = position.asArray();\r\n\r\n for (let j = 0; j < positionStrideSize; ++j) {\r\n const num = vector[j];\r\n if (num < min[j]) {\r\n min[j] = num;\r\n }\r\n if (num > max[j]) {\r\n max[j] = num;\r\n }\r\n ++indexOffset;\r\n }\r\n }\r\n }\r\n return { min, max };\r\n }\r\n\r\n public static _NormalizeTangentFromRef(tangent: Vector4) {\r\n const length = Math.sqrt(tangent.x * tangent.x + tangent.y * tangent.y + tangent.z * tangent.z);\r\n if (length > 0) {\r\n tangent.x /= length;\r\n tangent.y /= length;\r\n tangent.z /= length;\r\n }\r\n }\r\n\r\n public static _GetDataAccessorElementCount(accessorType: AccessorType) {\r\n switch (accessorType) {\r\n case AccessorType.MAT2:\r\n return 4;\r\n case AccessorType.MAT3:\r\n return 9;\r\n case AccessorType.MAT4:\r\n return 16;\r\n case AccessorType.SCALAR:\r\n return 1;\r\n case AccessorType.VEC2:\r\n return 2;\r\n case AccessorType.VEC3:\r\n return 3;\r\n case AccessorType.VEC4:\r\n return 4;\r\n }\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"glTFUtilities.js","sourceRoot":"","sources":["../../../../../dev/serializers/src/glTF/2.0/glTFUtilities.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C,GAAG,OAAO,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;QAChG,IAAI,MAAM,GAAG,CAAC,EAAE;YACZ,OAAO,CAAC,CAAC,IAAI,MAAM,CAAC;YACpB,OAAO,CAAC,CAAC,IAAI,MAAM,CAAC;YACpB,OAAO,CAAC,CAAC,IAAI,MAAM,CAAC;SACvB;IACL,CAAC;IAEM,MAAM,CAAC,4BAA4B,CAAC,YAA0B;QACjE,QAAQ,YAAY,EAAE;YAClB;gBACI,OAAO,CAAC,CAAC;YACb;gBACI,OAAO,CAAC,CAAC;YACb;gBACI,OAAO,EAAE,CAAC;YACd;gBACI,OAAO,CAAC,CAAC;YACb;gBACI,OAAO,CAAC,CAAC;YACb;gBACI,OAAO,CAAC,CAAC;YACb;gBACI,OAAO,CAAC,CAAC;SAChB;IACL,CAAC;CACJ","sourcesContent":["import type { IBufferView, AccessorComponentType, IAccessor } from \"babylonjs-gltf2interface\";\r\nimport { AccessorType } from \"babylonjs-gltf2interface\";\r\n\r\nimport type { FloatArray, Nullable } from \"core/types\";\r\nimport type { Vector4 } from \"core/Maths/math.vector\";\r\nimport { Vector3 } from \"core/Maths/math.vector\";\r\n\r\n/**\r\n * @internal\r\n */\r\nexport class _GLTFUtilities {\r\n /**\r\n * Creates a buffer view based on the supplied arguments\r\n * @param bufferIndex index value of the specified buffer\r\n * @param byteOffset byte offset value\r\n * @param byteLength byte length of the bufferView\r\n * @param byteStride byte distance between conequential elements\r\n * @param name name of the buffer view\r\n * @returns bufferView for glTF\r\n */\r\n public static _CreateBufferView(bufferIndex: number, byteOffset: number, byteLength: number, byteStride?: number, name?: string): IBufferView {\r\n const bufferview: IBufferView = { buffer: bufferIndex, byteLength: byteLength };\r\n if (byteOffset) {\r\n bufferview.byteOffset = byteOffset;\r\n }\r\n if (name) {\r\n bufferview.name = name;\r\n }\r\n if (byteStride) {\r\n bufferview.byteStride = byteStride;\r\n }\r\n\r\n return bufferview;\r\n }\r\n\r\n /**\r\n * Creates an accessor based on the supplied arguments\r\n * @param bufferviewIndex The index of the bufferview referenced by this accessor\r\n * @param name The name of the accessor\r\n * @param type The type of the accessor\r\n * @param componentType The datatype of components in the attribute\r\n * @param count The number of attributes referenced by this accessor\r\n * @param byteOffset The offset relative to the start of the bufferView in bytes\r\n * @param min Minimum value of each component in this attribute\r\n * @param max Maximum value of each component in this attribute\r\n * @returns accessor for glTF\r\n */\r\n public static _CreateAccessor(\r\n bufferviewIndex: number,\r\n name: string,\r\n type: AccessorType,\r\n componentType: AccessorComponentType,\r\n count: number,\r\n byteOffset: Nullable<number>,\r\n min: Nullable<number[]>,\r\n max: Nullable<number[]>\r\n ): IAccessor {\r\n const accessor: IAccessor = { name: name, bufferView: bufferviewIndex, componentType: componentType, count: count, type: type };\r\n\r\n if (min != null) {\r\n accessor.min = min;\r\n }\r\n if (max != null) {\r\n accessor.max = max;\r\n }\r\n if (byteOffset != null) {\r\n accessor.byteOffset = byteOffset;\r\n }\r\n\r\n return accessor;\r\n }\r\n\r\n /**\r\n * Calculates the minimum and maximum values of an array of position floats\r\n * @param positions Positions array of a mesh\r\n * @param vertexStart Starting vertex offset to calculate min and max values\r\n * @param vertexCount Number of vertices to check for min and max values\r\n * @returns min number array and max number array\r\n */\r\n public static _CalculateMinMaxPositions(positions: FloatArray, vertexStart: number, vertexCount: number): { min: number[]; max: number[] } {\r\n const min = [Infinity, Infinity, Infinity];\r\n const max = [-Infinity, -Infinity, -Infinity];\r\n const positionStrideSize = 3;\r\n let indexOffset: number;\r\n let position: Vector3;\r\n let vector: number[];\r\n\r\n if (vertexCount) {\r\n for (let i = vertexStart, length = vertexStart + vertexCount; i < length; ++i) {\r\n indexOffset = positionStrideSize * i;\r\n\r\n position = Vector3.FromArray(positions, indexOffset);\r\n vector = position.asArray();\r\n\r\n for (let j = 0; j < positionStrideSize; ++j) {\r\n const num = vector[j];\r\n if (num < min[j]) {\r\n min[j] = num;\r\n }\r\n if (num > max[j]) {\r\n max[j] = num;\r\n }\r\n ++indexOffset;\r\n }\r\n }\r\n }\r\n return { min, max };\r\n }\r\n\r\n public static _NormalizeTangentFromRef(tangent: Vector4 | Vector3) {\r\n const length = Math.sqrt(tangent.x * tangent.x + tangent.y * tangent.y + tangent.z * tangent.z);\r\n if (length > 0) {\r\n tangent.x /= length;\r\n tangent.y /= length;\r\n tangent.z /= length;\r\n }\r\n }\r\n\r\n public static _GetDataAccessorElementCount(accessorType: AccessorType) {\r\n switch (accessorType) {\r\n case AccessorType.MAT2:\r\n return 4;\r\n case AccessorType.MAT3:\r\n return 9;\r\n case AccessorType.MAT4:\r\n return 16;\r\n case AccessorType.SCALAR:\r\n return 1;\r\n case AccessorType.VEC2:\r\n return 2;\r\n case AccessorType.VEC3:\r\n return 3;\r\n case AccessorType.VEC4:\r\n return 4;\r\n }\r\n }\r\n}\r\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@babylonjs/serializers",
3
- "version": "7.12.0",
3
+ "version": "7.13.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": "^7.12.0",
21
+ "@babylonjs/core": "^7.13.1",
22
22
  "@dev/build-tools": "^1.0.0",
23
23
  "@lts/serializers": "^1.0.0",
24
- "babylonjs-gltf2interface": "^7.12.0"
24
+ "babylonjs-gltf2interface": "^7.13.1"
25
25
  },
26
26
  "peerDependencies": {
27
27
  "@babylonjs/core": "^7.0.0",