@babylonjs/serializers 7.49.0 → 7.50.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,15 +3,16 @@ import { GLTFExporter } from "../glTFExporter.js";
3
3
  const NAME = "KHR_texture_transform";
4
4
  /**
5
5
  * Computes the adjusted offset for a rotation centered about the origin.
6
- * This does not work when scaling is involved; investigation is needed.
7
6
  * @internal
8
7
  */
9
8
  function AdjustOffsetForRotationCenter(babylonTexture) {
10
- const { uOffset, vOffset, uRotationCenter, vRotationCenter, wAng } = babylonTexture;
11
- const cosAngle = Math.cos(-wAng);
12
- const sinAngle = Math.sin(-wAng);
13
- const deltaU = uRotationCenter * (1 - cosAngle) - vRotationCenter * sinAngle;
14
- const deltaV = vRotationCenter * (1 - cosAngle) + uRotationCenter * sinAngle;
9
+ const { uOffset, vOffset, uRotationCenter, vRotationCenter, uScale, vScale, wAng } = babylonTexture;
10
+ const cosAngle = Math.cos(wAng);
11
+ const sinAngle = Math.sin(wAng);
12
+ const scaledURotationCenter = uRotationCenter * uScale;
13
+ const scaledVRotationCenter = vRotationCenter * vScale;
14
+ const deltaU = scaledURotationCenter * (1 - cosAngle) + scaledVRotationCenter * sinAngle;
15
+ const deltaV = scaledVRotationCenter * (1 - cosAngle) - scaledURotationCenter * sinAngle;
15
16
  return [uOffset + deltaU, vOffset + deltaV];
16
17
  }
17
18
  /**
@@ -63,11 +64,12 @@ export class KHR_texture_transform {
63
64
  }
64
65
  if (babylonTexture.wAng !== 0) {
65
66
  if (babylonTexture.uRotationCenter !== 0 || babylonTexture.vRotationCenter !== 0) {
66
- if (babylonTexture.uScale !== 1 || babylonTexture.vScale !== 1) {
67
- Tools.Warn(`${context}: Texture ${babylonTexture.name} with scaling and a rotation not centered at the origin cannot be exported with ${NAME}`);
67
+ // See https://github.com/mrdoob/three.js/issues/15831 for more details.
68
+ if (babylonTexture.homogeneousRotationInUVTransform && babylonTexture.uScale !== babylonTexture.vScale) {
69
+ Tools.Warn(`${context}: Texture ${babylonTexture.name} with homogenousRotationInUVTransform, non-uniform scaling, and non-zero rotation cannot be exported with ${NAME}.`);
68
70
  return;
69
71
  }
70
- Tools.Warn(`${context}: Texture ${babylonTexture.name} with rotation not centered at the origin will be exported with an adjusted texture offset for ${NAME}.`);
72
+ Tools.Warn(`${context}: Texture ${babylonTexture.name} with non-origin rotation center will be exported using an adjusted offset with ${NAME}.`);
71
73
  textureTransform.offset = AdjustOffsetForRotationCenter(babylonTexture);
72
74
  }
73
75
  textureTransform.rotation = -babylonTexture.wAng;
@@ -1 +1 @@
1
- {"version":3,"file":"KHR_texture_transform.js","sourceRoot":"","sources":["../../../../../../dev/serializers/src/glTF/2.0/Extensions/KHR_texture_transform.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,sCAAwB;AAGxC,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,MAAM,IAAI,GAAG,uBAAuB,CAAC;AAErC;;;;GAIG;AACH,SAAS,6BAA6B,CAAC,cAAuB;IAC1D,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,IAAI,EAAE,GAAG,cAAc,CAAC;IACpF,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC;IACjC,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC;IACjC,MAAM,MAAM,GAAG,eAAe,GAAG,CAAC,CAAC,GAAG,QAAQ,CAAC,GAAG,eAAe,GAAG,QAAQ,CAAC;IAC7E,MAAM,MAAM,GAAG,eAAe,GAAG,CAAC,CAAC,GAAG,QAAQ,CAAC,GAAG,eAAe,GAAG,QAAQ,CAAC;IAC7E,OAAO,CAAC,OAAO,GAAG,MAAM,EAAE,OAAO,GAAG,MAAM,CAAC,CAAC;AAChD,CAAC;AAED;;GAEG;AACH,gEAAgE;AAChE,MAAM,OAAO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D,WAAW,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,gBAAgB,CAAC;IACpD,CAAC;CACJ;AAED,YAAY,CAAC,iBAAiB,CAAC,IAAI,EAAE,GAAG,EAAE,CAAC,IAAI,qBAAqB,EAAE,CAAC,CAAC","sourcesContent":["import type { ITextureInfo, IKHRTextureTransform } from \"babylonjs-gltf2interface\";\r\nimport { Tools } from \"core/Misc/tools\";\r\nimport type { Texture } from \"core/Materials/Textures/texture\";\r\nimport type { IGLTFExporterExtensionV2 } from \"../glTFExporterExtension\";\r\nimport { GLTFExporter } from \"../glTFExporter\";\r\n\r\nconst NAME = \"KHR_texture_transform\";\r\n\r\n/**\r\n * Computes the adjusted offset for a rotation centered about the origin.\r\n * This does not work when scaling is involved; investigation is needed.\r\n * @internal\r\n */\r\nfunction AdjustOffsetForRotationCenter(babylonTexture: Texture): [number, number] {\r\n const { uOffset, vOffset, uRotationCenter, vRotationCenter, wAng } = babylonTexture;\r\n const cosAngle = Math.cos(-wAng);\r\n const sinAngle = Math.sin(-wAng);\r\n const deltaU = uRotationCenter * (1 - cosAngle) - vRotationCenter * sinAngle;\r\n const deltaV = vRotationCenter * (1 - cosAngle) + uRotationCenter * sinAngle;\r\n return [uOffset + deltaU, vOffset + deltaV];\r\n}\r\n\r\n/**\r\n * @internal\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class KHR_texture_transform implements IGLTFExporterExtensionV2 {\r\n /** Name of this extension */\r\n public readonly name = NAME;\r\n\r\n /** Defines whether this extension is enabled */\r\n public enabled = true;\r\n\r\n /** Defines whether this extension is required */\r\n public required = false;\r\n\r\n /** Reference to the glTF exporter */\r\n private _wasUsed = false;\r\n\r\n constructor() {}\r\n\r\n public dispose() {}\r\n\r\n /** @internal */\r\n public get wasUsed() {\r\n return this._wasUsed;\r\n }\r\n\r\n public postExportTexture?(context: string, textureInfo: ITextureInfo, babylonTexture: Texture): void {\r\n const scene = babylonTexture.getScene();\r\n if (!scene) {\r\n Tools.Warn(`${context}: \"scene\" is not defined for Babylon texture ${babylonTexture.name}!`);\r\n }\r\n\r\n /*\r\n * The KHR_texture_transform schema only supports w rotation around the origin.\r\n * See https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_texture_transform#gltf-schema-updates.\r\n */\r\n if (babylonTexture.uAng !== 0 || babylonTexture.vAng !== 0) {\r\n Tools.Warn(`${context}: Texture ${babylonTexture.name} with rotation in the u or v axis is not supported in glTF.`);\r\n // Usually, we'd always early return here if the texture uses an unsupported combination of transform properties,\r\n // but we're making an exception here to maintain backwards compatibility.\r\n if (babylonTexture.uRotationCenter !== 0 || babylonTexture.vRotationCenter !== 0) {\r\n return;\r\n }\r\n }\r\n\r\n const textureTransform: IKHRTextureTransform = {};\r\n let transformIsRequired = false;\r\n\r\n if (babylonTexture.uOffset !== 0 || babylonTexture.vOffset !== 0) {\r\n textureTransform.offset = [babylonTexture.uOffset, babylonTexture.vOffset];\r\n transformIsRequired = true;\r\n }\r\n\r\n if (babylonTexture.uScale !== 1 || babylonTexture.vScale !== 1) {\r\n textureTransform.scale = [babylonTexture.uScale, babylonTexture.vScale];\r\n transformIsRequired = true;\r\n }\r\n\r\n if (babylonTexture.wAng !== 0) {\r\n if (babylonTexture.uRotationCenter !== 0 || babylonTexture.vRotationCenter !== 0) {\r\n if (babylonTexture.uScale !== 1 || babylonTexture.vScale !== 1) {\r\n Tools.Warn(`${context}: Texture ${babylonTexture.name} with scaling and a rotation not centered at the origin cannot be exported with ${NAME}`);\r\n return;\r\n }\r\n Tools.Warn(`${context}: Texture ${babylonTexture.name} with rotation not centered at the origin will be exported with an adjusted texture offset for ${NAME}.`);\r\n textureTransform.offset = AdjustOffsetForRotationCenter(babylonTexture);\r\n }\r\n textureTransform.rotation = -babylonTexture.wAng;\r\n transformIsRequired = true;\r\n }\r\n\r\n if (babylonTexture.coordinatesIndex !== 0) {\r\n textureTransform.texCoord = babylonTexture.coordinatesIndex;\r\n transformIsRequired = true;\r\n }\r\n\r\n if (!transformIsRequired) {\r\n return;\r\n }\r\n\r\n this._wasUsed = true;\r\n if (!textureInfo.extensions) {\r\n textureInfo.extensions = {};\r\n }\r\n textureInfo.extensions[NAME] = textureTransform;\r\n }\r\n}\r\n\r\nGLTFExporter.RegisterExtension(NAME, () => new KHR_texture_transform());\r\n"]}
1
+ {"version":3,"file":"KHR_texture_transform.js","sourceRoot":"","sources":["../../../../../../dev/serializers/src/glTF/2.0/Extensions/KHR_texture_transform.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,sCAAwB;AAGxC,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,MAAM,IAAI,GAAG,uBAAuB,CAAC;AAErC;;;GAGG;AACH,SAAS,6BAA6B,CAAC,cAAuB;IAC1D,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,cAAc,CAAC;IACpG,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAChC,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAChC,MAAM,qBAAqB,GAAG,eAAe,GAAG,MAAM,CAAC;IACvD,MAAM,qBAAqB,GAAG,eAAe,GAAG,MAAM,CAAC;IACvD,MAAM,MAAM,GAAG,qBAAqB,GAAG,CAAC,CAAC,GAAG,QAAQ,CAAC,GAAG,qBAAqB,GAAG,QAAQ,CAAC;IACzF,MAAM,MAAM,GAAG,qBAAqB,GAAG,CAAC,CAAC,GAAG,QAAQ,CAAC,GAAG,qBAAqB,GAAG,QAAQ,CAAC;IACzF,OAAO,CAAC,OAAO,GAAG,MAAM,EAAE,OAAO,GAAG,MAAM,CAAC,CAAC;AAChD,CAAC;AAED;;GAEG;AACH,gEAAgE;AAChE,MAAM,OAAO,qBAAqB;IAa9B;QAZA,6BAA6B;QACb,SAAI,GAAG,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AAC,GAAG,gBAAgB,CAAC;IACpD,CAAC;CACJ;AAED,YAAY,CAAC,iBAAiB,CAAC,IAAI,EAAE,GAAG,EAAE,CAAC,IAAI,qBAAqB,EAAE,CAAC,CAAC","sourcesContent":["import type { ITextureInfo, IKHRTextureTransform } from \"babylonjs-gltf2interface\";\r\nimport { Tools } from \"core/Misc/tools\";\r\nimport type { Texture } from \"core/Materials/Textures/texture\";\r\nimport type { IGLTFExporterExtensionV2 } from \"../glTFExporterExtension\";\r\nimport { GLTFExporter } from \"../glTFExporter\";\r\n\r\nconst NAME = \"KHR_texture_transform\";\r\n\r\n/**\r\n * Computes the adjusted offset for a rotation centered about the origin.\r\n * @internal\r\n */\r\nfunction AdjustOffsetForRotationCenter(babylonTexture: Texture): [number, number] {\r\n const { uOffset, vOffset, uRotationCenter, vRotationCenter, uScale, vScale, wAng } = babylonTexture;\r\n const cosAngle = Math.cos(wAng);\r\n const sinAngle = Math.sin(wAng);\r\n const scaledURotationCenter = uRotationCenter * uScale;\r\n const scaledVRotationCenter = vRotationCenter * vScale;\r\n const deltaU = scaledURotationCenter * (1 - cosAngle) + scaledVRotationCenter * sinAngle;\r\n const deltaV = scaledVRotationCenter * (1 - cosAngle) - scaledURotationCenter * sinAngle;\r\n return [uOffset + deltaU, vOffset + deltaV];\r\n}\r\n\r\n/**\r\n * @internal\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class KHR_texture_transform implements IGLTFExporterExtensionV2 {\r\n /** Name of this extension */\r\n public readonly name = NAME;\r\n\r\n /** Defines whether this extension is enabled */\r\n public enabled = true;\r\n\r\n /** Defines whether this extension is required */\r\n public required = false;\r\n\r\n /** Reference to the glTF exporter */\r\n private _wasUsed = false;\r\n\r\n constructor() {}\r\n\r\n public dispose() {}\r\n\r\n /** @internal */\r\n public get wasUsed() {\r\n return this._wasUsed;\r\n }\r\n\r\n public postExportTexture?(context: string, textureInfo: ITextureInfo, babylonTexture: Texture): void {\r\n const scene = babylonTexture.getScene();\r\n if (!scene) {\r\n Tools.Warn(`${context}: \"scene\" is not defined for Babylon texture ${babylonTexture.name}!`);\r\n }\r\n\r\n /*\r\n * The KHR_texture_transform schema only supports w rotation around the origin.\r\n * See https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_texture_transform#gltf-schema-updates.\r\n */\r\n if (babylonTexture.uAng !== 0 || babylonTexture.vAng !== 0) {\r\n Tools.Warn(`${context}: Texture ${babylonTexture.name} with rotation in the u or v axis is not supported in glTF.`);\r\n // Usually, we'd always early return here if the texture uses an unsupported combination of transform properties,\r\n // but we're making an exception here to maintain backwards compatibility.\r\n if (babylonTexture.uRotationCenter !== 0 || babylonTexture.vRotationCenter !== 0) {\r\n return;\r\n }\r\n }\r\n\r\n const textureTransform: IKHRTextureTransform = {};\r\n let transformIsRequired = false;\r\n\r\n if (babylonTexture.uOffset !== 0 || babylonTexture.vOffset !== 0) {\r\n textureTransform.offset = [babylonTexture.uOffset, babylonTexture.vOffset];\r\n transformIsRequired = true;\r\n }\r\n\r\n if (babylonTexture.uScale !== 1 || babylonTexture.vScale !== 1) {\r\n textureTransform.scale = [babylonTexture.uScale, babylonTexture.vScale];\r\n transformIsRequired = true;\r\n }\r\n\r\n if (babylonTexture.wAng !== 0) {\r\n if (babylonTexture.uRotationCenter !== 0 || babylonTexture.vRotationCenter !== 0) {\r\n // See https://github.com/mrdoob/three.js/issues/15831 for more details.\r\n if (babylonTexture.homogeneousRotationInUVTransform && babylonTexture.uScale !== babylonTexture.vScale) {\r\n Tools.Warn(\r\n `${context}: Texture ${babylonTexture.name} with homogenousRotationInUVTransform, non-uniform scaling, and non-zero rotation cannot be exported with ${NAME}.`\r\n );\r\n return;\r\n }\r\n Tools.Warn(`${context}: Texture ${babylonTexture.name} with non-origin rotation center will be exported using an adjusted offset with ${NAME}.`);\r\n textureTransform.offset = AdjustOffsetForRotationCenter(babylonTexture);\r\n }\r\n textureTransform.rotation = -babylonTexture.wAng;\r\n transformIsRequired = true;\r\n }\r\n\r\n if (babylonTexture.coordinatesIndex !== 0) {\r\n textureTransform.texCoord = babylonTexture.coordinatesIndex;\r\n transformIsRequired = true;\r\n }\r\n\r\n if (!transformIsRequired) {\r\n return;\r\n }\r\n\r\n this._wasUsed = true;\r\n if (!textureInfo.extensions) {\r\n textureInfo.extensions = {};\r\n }\r\n textureInfo.extensions[NAME] = textureTransform;\r\n }\r\n}\r\n\r\nGLTFExporter.RegisterExtension(NAME, () => new KHR_texture_transform());\r\n"]}
@@ -1,6 +1,6 @@
1
1
  import { NormalizeTangent } from "./glTFUtilities.js";
2
2
  import { VertexBuffer } from "@babylonjs/core/Buffers/buffer.js";
3
- import { Vector3 } from "@babylonjs/core/Maths/math.vector.js";
3
+ import { Vector3, Vector4 } from "@babylonjs/core/Maths/math.vector.js";
4
4
  import { Tools } from "@babylonjs/core/Misc/tools.js";
5
5
  export function BuildMorphTargetBuffers(morphTarget, mesh, bufferManager, bufferViews, accessors, convertToRightHanded) {
6
6
  const result = {
@@ -98,6 +98,47 @@ export function BuildMorphTargetBuffers(morphTarget, mesh, bufferManager, buffer
98
98
  Tools.Warn(`Morph target tangents for mesh ${mesh.name} were not exported. Mesh does not have tangents vertex data`);
99
99
  }
100
100
  }
101
+ if (morphTarget.hasColors) {
102
+ const morphColors = morphTarget.getColors();
103
+ const originalColors = mesh.getVerticesData(VertexBuffer.ColorKind, undefined, undefined, true);
104
+ const buffer = mesh.getVertexBuffer(VertexBuffer.ColorKind, true);
105
+ if (originalColors && buffer) {
106
+ const componentSize = buffer.getSize();
107
+ vertexCount = originalColors.length / componentSize;
108
+ const colorData = new Float32Array(vertexCount * componentSize);
109
+ vertexStart = 0;
110
+ for (let i = vertexStart; i < vertexCount; ++i) {
111
+ if (componentSize === 3) {
112
+ const originalColor = Vector3.FromArray(originalColors, i * componentSize);
113
+ const morphColor = Vector3.FromArray(morphColors, i * componentSize);
114
+ morphColor.subtractToRef(originalColor, difference);
115
+ colorData[i * 3] = difference.x;
116
+ colorData[i * 3 + 1] = difference.y;
117
+ colorData[i * 3 + 2] = difference.z;
118
+ }
119
+ else if (componentSize === 4) {
120
+ const difference4 = new Vector4();
121
+ const originalColor = Vector4.FromArray(originalColors, i * componentSize);
122
+ const morphColor = Vector4.FromArray(morphColors, i * componentSize);
123
+ morphColor.subtractToRef(originalColor, difference4);
124
+ colorData[i * 4] = difference4.x;
125
+ colorData[i * 4 + 1] = difference4.y;
126
+ colorData[i * 4 + 2] = difference4.z;
127
+ colorData[i * 4 + 3] = difference4.w;
128
+ }
129
+ else {
130
+ Tools.Warn(`Unsupported number of components for color attribute: ${componentSize}`);
131
+ }
132
+ }
133
+ const bufferView = bufferManager.createBufferView(colorData, floatSize * componentSize);
134
+ const accessor = bufferManager.createAccessor(bufferView, componentSize === 3 ? "VEC3" /* AccessorType.VEC3 */ : "VEC4" /* AccessorType.VEC4 */, 5126 /* AccessorComponentType.FLOAT */, vertexCount, 0);
135
+ accessors.push(accessor);
136
+ result.attributes["COLOR_0"] = accessors.length - 1;
137
+ }
138
+ else {
139
+ Tools.Warn(`Morph target colors for mesh ${mesh.name} were not exported. Mesh does not have colors vertex data`);
140
+ }
141
+ }
101
142
  return result;
102
143
  }
103
144
  //# sourceMappingURL=glTFMorphTargetsUtilities.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"glTFMorphTargetsUtilities.js","sourceRoot":"","sources":["../../../../../dev/serializers/src/glTF/2.0/glTFMorphTargetsUtilities.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAEnD,OAAO,EAAE,YAAY,EAAE,0CAA4B;AACnD,OAAO,EAAE,OAAO,EAAE,6CAA+B;AACjD,OAAO,EAAE,KAAK,EAAE,sCAAwB;AAYxC,MAAM,UAAU,uBAAuB,CACnC,WAAwB,EACxB,IAAU,EACV,aAA4B,EAC5B,WAA0B,EAC1B,SAAsB,EACtB,oBAA6B;IAE7B,MAAM,MAAM,GAAqB;QAC7B,UAAU,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,CAAC;gBACnE,gBAAgB,CAAC,eAAe,CAAC,CAAC;gBAElC,gFAAgF;gBAChF,MAAM,YAAY,GAAG,OAAO,CAAC,SAAS,CAAC,aAAa,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;gBAC7D,gBAAgB,CAAC,YAAY,CAAC,CAAC;gBAE/B,YAAY,CAAC,aAAa,CAAC,eAAe,EAAE,UAAU,CAAC,CAAC;gBACxD,WAAW,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,GAAG,KAAK,CAAC;gBAC1C,WAAW,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC;gBACtC,WAAW,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC;YAC1C,CAAC;YACD,MAAM,UAAU,GAAG,aAAa,CAAC,gBAAgB,CAAC,WAAW,EAAE,SAAS,GAAG,CAAC,CAAC,CAAC;YAC9E,MAAM,QAAQ,GAAG,aAAa,CAAC,cAAc,CAAC,UAAU,0EAAkD,WAAW,EAAE,CAAC,CAAC,CAAC;YAC1H,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YACzB,MAAM,CAAC,UAAU,CAAC,SAAS,CAAC,GAAG,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC;QACxD,CAAC;aAAM,CAAC;YACJ,KAAK,CAAC,IAAI,CAAC,kCAAkC,IAAI,CAAC,IAAI,6DAA6D,CAAC,CAAC;QACzH,CAAC;IACL,CAAC;IAED,OAAO,MAAM,CAAC;AAClB,CAAC","sourcesContent":["import type { IBufferView, IAccessor } from \"babylonjs-gltf2interface\";\r\nimport { AccessorComponentType, AccessorType } from \"babylonjs-gltf2interface\";\r\nimport type { MorphTarget } from \"core/Morph/morphTarget\";\r\nimport type { BufferManager } from \"./bufferManager\";\r\n\r\nimport { NormalizeTangent } from \"./glTFUtilities\";\r\nimport type { Mesh } from \"core/Meshes/mesh\";\r\nimport { VertexBuffer } from \"core/Buffers/buffer\";\r\nimport { Vector3 } from \"core/Maths/math.vector\";\r\nimport { Tools } from \"core/Misc/tools\";\r\n\r\n/**\r\n * Interface to store morph target information.\r\n * @internal\r\n */\r\nexport interface IMorphTargetData {\r\n attributes: Record<string, number>;\r\n influence: number;\r\n name: string;\r\n}\r\n\r\nexport function BuildMorphTargetBuffers(\r\n morphTarget: MorphTarget,\r\n mesh: Mesh,\r\n bufferManager: BufferManager,\r\n bufferViews: IBufferView[],\r\n accessors: IAccessor[],\r\n convertToRightHanded: boolean\r\n): IMorphTargetData {\r\n const result: IMorphTargetData = {\r\n attributes: {},\r\n influence: morphTarget.influence,\r\n name: morphTarget.name,\r\n };\r\n\r\n const flipX = convertToRightHanded ? -1 : 1;\r\n const floatSize = 4;\r\n const difference = Vector3.Zero();\r\n let vertexStart = 0;\r\n let vertexCount = 0;\r\n\r\n if (morphTarget.hasPositions) {\r\n const morphPositions = morphTarget.getPositions()!;\r\n const originalPositions = mesh.getVerticesData(VertexBuffer.PositionKind, undefined, undefined, true);\r\n\r\n if (originalPositions) {\r\n const positionData = new Float32Array(originalPositions.length);\r\n const min = [Infinity, Infinity, Infinity];\r\n const max = [-Infinity, -Infinity, -Infinity];\r\n vertexCount = originalPositions.length / 3;\r\n vertexStart = 0;\r\n for (let i = vertexStart; i < vertexCount; ++i) {\r\n const originalPosition = Vector3.FromArray(originalPositions, i * 3);\r\n const morphPosition = Vector3.FromArray(morphPositions, i * 3);\r\n morphPosition.subtractToRef(originalPosition, difference);\r\n difference.x *= flipX;\r\n\r\n min[0] = Math.min(min[0], difference.x);\r\n max[0] = Math.max(max[0], difference.x);\r\n\r\n min[1] = Math.min(min[1], difference.y);\r\n max[1] = Math.max(max[1], difference.y);\r\n\r\n min[2] = Math.min(min[2], difference.z);\r\n max[2] = Math.max(max[2], difference.z);\r\n\r\n positionData[i * 3] = difference.x;\r\n positionData[i * 3 + 1] = difference.y;\r\n positionData[i * 3 + 2] = difference.z;\r\n }\r\n\r\n const bufferView = bufferManager.createBufferView(positionData, floatSize * 3);\r\n const accessor = bufferManager.createAccessor(bufferView, AccessorType.VEC3, AccessorComponentType.FLOAT, morphPositions.length / 3, 0, { min, max });\r\n accessors.push(accessor);\r\n result.attributes[\"POSITION\"] = accessors.length - 1;\r\n } else {\r\n Tools.Warn(`Morph target positions for mesh ${mesh.name} were not exported. Mesh does not have position vertex data`);\r\n }\r\n }\r\n\r\n if (morphTarget.hasNormals) {\r\n const morphNormals = morphTarget.getNormals()!;\r\n const originalNormals = mesh.getVerticesData(VertexBuffer.NormalKind, undefined, undefined, true);\r\n\r\n if (originalNormals) {\r\n const normalData = new Float32Array(originalNormals.length);\r\n vertexCount = originalNormals.length / 3;\r\n vertexStart = 0;\r\n for (let i = vertexStart; i < vertexCount; ++i) {\r\n const originalNormal = Vector3.FromArray(originalNormals, i * 3).normalize();\r\n const morphNormal = Vector3.FromArray(morphNormals, i * 3).normalize();\r\n morphNormal.subtractToRef(originalNormal, difference);\r\n\r\n normalData[i * 3] = difference.x * flipX;\r\n normalData[i * 3 + 1] = difference.y;\r\n normalData[i * 3 + 2] = difference.z;\r\n }\r\n\r\n const bufferView = bufferManager.createBufferView(normalData, floatSize * 3);\r\n const accessor = bufferManager.createAccessor(bufferView, AccessorType.VEC3, AccessorComponentType.FLOAT, morphNormals.length / 3, 0);\r\n accessors.push(accessor);\r\n result.attributes[\"NORMAL\"] = accessors.length - 1;\r\n } else {\r\n Tools.Warn(`Morph target normals for mesh ${mesh.name} were not exported. Mesh does not have normals vertex data`);\r\n }\r\n }\r\n\r\n if (morphTarget.hasTangents) {\r\n const morphTangents = morphTarget.getTangents()!;\r\n const originalTangents = mesh.getVerticesData(VertexBuffer.TangentKind, undefined, undefined, true);\r\n\r\n if (originalTangents) {\r\n vertexCount = originalTangents.length / 4;\r\n const tangentData = new Float32Array(vertexCount * 3);\r\n vertexStart = 0;\r\n for (let i = vertexStart; i < vertexCount; ++i) {\r\n // Only read the x, y, z components and ignore w\r\n const originalTangent = Vector3.FromArray(originalTangents, i * 4);\r\n NormalizeTangent(originalTangent);\r\n\r\n // Morph target tangents omit the w component so it won't be present in the data\r\n const morphTangent = Vector3.FromArray(morphTangents, i * 3);\r\n NormalizeTangent(morphTangent);\r\n\r\n morphTangent.subtractToRef(originalTangent, difference);\r\n tangentData[i * 3] = difference.x * flipX;\r\n tangentData[i * 3 + 1] = difference.y;\r\n tangentData[i * 3 + 2] = difference.z;\r\n }\r\n const bufferView = bufferManager.createBufferView(tangentData, floatSize * 3);\r\n const accessor = bufferManager.createAccessor(bufferView, AccessorType.VEC3, AccessorComponentType.FLOAT, vertexCount, 0);\r\n accessors.push(accessor);\r\n result.attributes[\"TANGENT\"] = accessors.length - 1;\r\n } else {\r\n Tools.Warn(`Morph target tangents for mesh ${mesh.name} were not exported. Mesh does not have tangents vertex data`);\r\n }\r\n }\r\n\r\n return result;\r\n}\r\n"]}
1
+ {"version":3,"file":"glTFMorphTargetsUtilities.js","sourceRoot":"","sources":["../../../../../dev/serializers/src/glTF/2.0/glTFMorphTargetsUtilities.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAEnD,OAAO,EAAE,YAAY,EAAE,0CAA4B;AACnD,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,6CAA+B;AAC1D,OAAO,EAAE,KAAK,EAAE,sCAAwB;AAYxC,MAAM,UAAU,uBAAuB,CACnC,WAAwB,EACxB,IAAU,EACV,aAA4B,EAC5B,WAA0B,EAC1B,SAAsB,EACtB,oBAA6B;IAE7B,MAAM,MAAM,GAAqB;QAC7B,UAAU,EAAE,EAAE;QACd,SAAS,EAAE,WAAW,CAAC,SAAS;QAChC,IAAI,EAAE,WAAW,CAAC,IAAI;KACzB,CAAC;IAEF,MAAM,KAAK,GAAG,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAC5C,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,CAAC;oBACrC,SAAS,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC;oBACrC,SAAS,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC;gBACzC,CAAC;qBAAM,CAAC;oBACJ,KAAK,CAAC,IAAI,CAAC,yDAAyD,aAAa,EAAE,CAAC,CAAC;gBACzF,CAAC;YACL,CAAC;YACD,MAAM,UAAU,GAAG,aAAa,CAAC,gBAAgB,CAAC,SAAS,EAAE,SAAS,GAAG,aAAa,CAAC,CAAC;YACxF,MAAM,QAAQ,GAAG,aAAa,CAAC,cAAc,CAAC,UAAU,EAAE,aAAa,KAAK,CAAC,CAAC,CAAC,gCAAmB,CAAC,+BAAkB,0CAA+B,WAAW,EAAE,CAAC,CAAC,CAAC;YACpK,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YACzB,MAAM,CAAC,UAAU,CAAC,SAAS,CAAC,GAAG,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC;QACxD,CAAC;aAAM,CAAC;YACJ,KAAK,CAAC,IAAI,CAAC,gCAAgC,IAAI,CAAC,IAAI,2DAA2D,CAAC,CAAC;QACrH,CAAC;IACL,CAAC;IAED,OAAO,MAAM,CAAC;AAClB,CAAC","sourcesContent":["import type { IBufferView, IAccessor } from \"babylonjs-gltf2interface\";\r\nimport { AccessorComponentType, AccessorType } from \"babylonjs-gltf2interface\";\r\nimport type { MorphTarget } from \"core/Morph/morphTarget\";\r\nimport type { BufferManager } from \"./bufferManager\";\r\n\r\nimport { NormalizeTangent } from \"./glTFUtilities\";\r\nimport type { Mesh } from \"core/Meshes/mesh\";\r\nimport { VertexBuffer } from \"core/Buffers/buffer\";\r\nimport { Vector3, Vector4 } from \"core/Maths/math.vector\";\r\nimport { Tools } from \"core/Misc/tools\";\r\n\r\n/**\r\n * Interface to store morph target information.\r\n * @internal\r\n */\r\nexport interface IMorphTargetData {\r\n attributes: Record<string, number>;\r\n influence: number;\r\n name: string;\r\n}\r\n\r\nexport function BuildMorphTargetBuffers(\r\n morphTarget: MorphTarget,\r\n mesh: Mesh,\r\n bufferManager: BufferManager,\r\n bufferViews: IBufferView[],\r\n accessors: IAccessor[],\r\n convertToRightHanded: boolean\r\n): IMorphTargetData {\r\n const result: IMorphTargetData = {\r\n attributes: {},\r\n influence: morphTarget.influence,\r\n name: morphTarget.name,\r\n };\r\n\r\n const flipX = convertToRightHanded ? -1 : 1;\r\n const floatSize = 4;\r\n const difference = Vector3.Zero();\r\n let vertexStart = 0;\r\n let vertexCount = 0;\r\n\r\n if (morphTarget.hasPositions) {\r\n const morphPositions = morphTarget.getPositions()!;\r\n const originalPositions = mesh.getVerticesData(VertexBuffer.PositionKind, undefined, undefined, true);\r\n\r\n if (originalPositions) {\r\n const positionData = new Float32Array(originalPositions.length);\r\n const min = [Infinity, Infinity, Infinity];\r\n const max = [-Infinity, -Infinity, -Infinity];\r\n vertexCount = originalPositions.length / 3;\r\n vertexStart = 0;\r\n for (let i = vertexStart; i < vertexCount; ++i) {\r\n const originalPosition = Vector3.FromArray(originalPositions, i * 3);\r\n const morphPosition = Vector3.FromArray(morphPositions, i * 3);\r\n morphPosition.subtractToRef(originalPosition, difference);\r\n difference.x *= flipX;\r\n\r\n min[0] = Math.min(min[0], difference.x);\r\n max[0] = Math.max(max[0], difference.x);\r\n\r\n min[1] = Math.min(min[1], difference.y);\r\n max[1] = Math.max(max[1], difference.y);\r\n\r\n min[2] = Math.min(min[2], difference.z);\r\n max[2] = Math.max(max[2], difference.z);\r\n\r\n positionData[i * 3] = difference.x;\r\n positionData[i * 3 + 1] = difference.y;\r\n positionData[i * 3 + 2] = difference.z;\r\n }\r\n\r\n const bufferView = bufferManager.createBufferView(positionData, floatSize * 3);\r\n const accessor = bufferManager.createAccessor(bufferView, AccessorType.VEC3, AccessorComponentType.FLOAT, morphPositions.length / 3, 0, { min, max });\r\n accessors.push(accessor);\r\n result.attributes[\"POSITION\"] = accessors.length - 1;\r\n } else {\r\n Tools.Warn(`Morph target positions for mesh ${mesh.name} were not exported. Mesh does not have position vertex data`);\r\n }\r\n }\r\n\r\n if (morphTarget.hasNormals) {\r\n const morphNormals = morphTarget.getNormals()!;\r\n const originalNormals = mesh.getVerticesData(VertexBuffer.NormalKind, undefined, undefined, true);\r\n\r\n if (originalNormals) {\r\n const normalData = new Float32Array(originalNormals.length);\r\n vertexCount = originalNormals.length / 3;\r\n vertexStart = 0;\r\n for (let i = vertexStart; i < vertexCount; ++i) {\r\n const originalNormal = Vector3.FromArray(originalNormals, i * 3).normalize();\r\n const morphNormal = Vector3.FromArray(morphNormals, i * 3).normalize();\r\n morphNormal.subtractToRef(originalNormal, difference);\r\n\r\n normalData[i * 3] = difference.x * flipX;\r\n normalData[i * 3 + 1] = difference.y;\r\n normalData[i * 3 + 2] = difference.z;\r\n }\r\n\r\n const bufferView = bufferManager.createBufferView(normalData, floatSize * 3);\r\n const accessor = bufferManager.createAccessor(bufferView, AccessorType.VEC3, AccessorComponentType.FLOAT, morphNormals.length / 3, 0);\r\n accessors.push(accessor);\r\n result.attributes[\"NORMAL\"] = accessors.length - 1;\r\n } else {\r\n Tools.Warn(`Morph target normals for mesh ${mesh.name} were not exported. Mesh does not have normals vertex data`);\r\n }\r\n }\r\n\r\n if (morphTarget.hasTangents) {\r\n const morphTangents = morphTarget.getTangents()!;\r\n const originalTangents = mesh.getVerticesData(VertexBuffer.TangentKind, undefined, undefined, true);\r\n\r\n if (originalTangents) {\r\n vertexCount = originalTangents.length / 4;\r\n const tangentData = new Float32Array(vertexCount * 3);\r\n vertexStart = 0;\r\n for (let i = vertexStart; i < vertexCount; ++i) {\r\n // Only read the x, y, z components and ignore w\r\n const originalTangent = Vector3.FromArray(originalTangents, i * 4);\r\n NormalizeTangent(originalTangent);\r\n\r\n // Morph target tangents omit the w component so it won't be present in the data\r\n const morphTangent = Vector3.FromArray(morphTangents, i * 3);\r\n NormalizeTangent(morphTangent);\r\n\r\n morphTangent.subtractToRef(originalTangent, difference);\r\n tangentData[i * 3] = difference.x * flipX;\r\n tangentData[i * 3 + 1] = difference.y;\r\n tangentData[i * 3 + 2] = difference.z;\r\n }\r\n const bufferView = bufferManager.createBufferView(tangentData, floatSize * 3);\r\n const accessor = bufferManager.createAccessor(bufferView, AccessorType.VEC3, AccessorComponentType.FLOAT, vertexCount, 0);\r\n accessors.push(accessor);\r\n result.attributes[\"TANGENT\"] = accessors.length - 1;\r\n } else {\r\n Tools.Warn(`Morph target tangents for mesh ${mesh.name} were not exported. Mesh does not have tangents vertex data`);\r\n }\r\n }\r\n\r\n if (morphTarget.hasColors) {\r\n const morphColors = morphTarget.getColors()!;\r\n const originalColors = mesh.getVerticesData(VertexBuffer.ColorKind, undefined, undefined, true);\r\n\r\n const buffer = mesh.getVertexBuffer(VertexBuffer.ColorKind, true);\r\n\r\n if (originalColors && buffer) {\r\n const componentSize = buffer.getSize();\r\n\r\n vertexCount = originalColors.length / componentSize;\r\n const colorData = new Float32Array(vertexCount * componentSize);\r\n vertexStart = 0;\r\n for (let i = vertexStart; i < vertexCount; ++i) {\r\n if (componentSize === 3) {\r\n const originalColor = Vector3.FromArray(originalColors, i * componentSize);\r\n const morphColor = Vector3.FromArray(morphColors, i * componentSize);\r\n\r\n morphColor.subtractToRef(originalColor, difference);\r\n colorData[i * 3] = difference.x;\r\n colorData[i * 3 + 1] = difference.y;\r\n colorData[i * 3 + 2] = difference.z;\r\n } else if (componentSize === 4) {\r\n const difference4 = new Vector4();\r\n const originalColor = Vector4.FromArray(originalColors, i * componentSize);\r\n const morphColor = Vector4.FromArray(morphColors, i * componentSize);\r\n\r\n morphColor.subtractToRef(originalColor, difference4);\r\n colorData[i * 4] = difference4.x;\r\n colorData[i * 4 + 1] = difference4.y;\r\n colorData[i * 4 + 2] = difference4.z;\r\n colorData[i * 4 + 3] = difference4.w;\r\n } else {\r\n Tools.Warn(`Unsupported number of components for color attribute: ${componentSize}`);\r\n }\r\n }\r\n const bufferView = bufferManager.createBufferView(colorData, floatSize * componentSize);\r\n const accessor = bufferManager.createAccessor(bufferView, componentSize === 3 ? AccessorType.VEC3 : AccessorType.VEC4, AccessorComponentType.FLOAT, vertexCount, 0);\r\n accessors.push(accessor);\r\n result.attributes[\"COLOR_0\"] = accessors.length - 1;\r\n } else {\r\n Tools.Warn(`Morph target colors for mesh ${mesh.name} were not exported. Mesh does not have colors vertex data`);\r\n }\r\n }\r\n\r\n return result;\r\n}\r\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@babylonjs/serializers",
3
- "version": "7.49.0",
3
+ "version": "7.50.0",
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.49.0",
21
+ "@babylonjs/core": "^7.50.0",
22
22
  "@dev/build-tools": "^1.0.0",
23
23
  "@lts/serializers": "^1.0.0",
24
- "babylonjs-gltf2interface": "^7.49.0"
24
+ "babylonjs-gltf2interface": "^7.50.0"
25
25
  },
26
26
  "peerDependencies": {
27
27
  "@babylonjs/core": "^7.0.0",