@babylonjs/serializers 5.45.2 → 5.47.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.
- package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.js +8 -8
- package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_lights_punctual.js +5 -5
- package/glTF/2.0/Extensions/KHR_lights_punctual.js.map +1 -1
- package/glTF/2.0/glTFAnimation.js +43 -43
- package/glTF/2.0/glTFAnimation.js.map +1 -1
- package/glTF/2.0/glTFData.js +2 -2
- package/glTF/2.0/glTFData.js.map +1 -1
- package/glTF/2.0/glTFExporter.js +78 -78
- package/glTF/2.0/glTFExporter.js.map +1 -1
- package/glTF/2.0/glTFMaterialExporter.js +36 -36
- package/glTF/2.0/glTFMaterialExporter.js.map +1 -1
- package/glTF/2.0/glTFUtilities.js +7 -7
- package/package.json +3 -3
@@ -62,16 +62,16 @@ export class EXT_mesh_gpu_instancing {
|
|
62
62
|
};
|
63
63
|
// do we need to write TRANSLATION ?
|
64
64
|
if (hasAnyInstanceWorldTranslation) {
|
65
|
-
extension.attributes["TRANSLATION"] = this._buildAccessor(translationBuffer, "VEC3" /* VEC3 */, babylonNode.thinInstanceCount, binaryWriter, 5126 /* FLOAT */);
|
65
|
+
extension.attributes["TRANSLATION"] = this._buildAccessor(translationBuffer, "VEC3" /* AccessorType.VEC3 */, babylonNode.thinInstanceCount, binaryWriter, 5126 /* AccessorComponentType.FLOAT */);
|
66
66
|
}
|
67
67
|
// do we need to write ROTATION ?
|
68
68
|
if (hasAnyInstanceWorldRotation) {
|
69
|
-
const componentType = 5126 /* FLOAT */; // we decided to stay on FLOAT for now see https://github.com/BabylonJS/Babylon.js/pull/12495
|
70
|
-
extension.attributes["ROTATION"] = this._buildAccessor(rotationBuffer, "VEC4" /* VEC4 */, babylonNode.thinInstanceCount, binaryWriter, componentType);
|
69
|
+
const componentType = 5126 /* AccessorComponentType.FLOAT */; // we decided to stay on FLOAT for now see https://github.com/BabylonJS/Babylon.js/pull/12495
|
70
|
+
extension.attributes["ROTATION"] = this._buildAccessor(rotationBuffer, "VEC4" /* AccessorType.VEC4 */, babylonNode.thinInstanceCount, binaryWriter, componentType);
|
71
71
|
}
|
72
72
|
// do we need to write SCALE ?
|
73
73
|
if (hasAnyInstanceWorldScale) {
|
74
|
-
extension.attributes["SCALE"] = this._buildAccessor(scaleBuffer, "VEC3" /* VEC3 */, babylonNode.thinInstanceCount, binaryWriter, 5126 /* FLOAT */);
|
74
|
+
extension.attributes["SCALE"] = this._buildAccessor(scaleBuffer, "VEC3" /* AccessorType.VEC3 */, babylonNode.thinInstanceCount, binaryWriter, 5126 /* AccessorComponentType.FLOAT */);
|
75
75
|
}
|
76
76
|
/* eslint-enable @typescript-eslint/naming-convention*/
|
77
77
|
node.extensions = node.extensions || {};
|
@@ -85,19 +85,19 @@ export class EXT_mesh_gpu_instancing {
|
|
85
85
|
// write the buffer
|
86
86
|
const bufferOffset = binaryWriter.getByteOffset();
|
87
87
|
switch (componentType) {
|
88
|
-
case 5126 /* FLOAT */: {
|
88
|
+
case 5126 /* AccessorComponentType.FLOAT */: {
|
89
89
|
for (let i = 0; i != buffer.length; i++) {
|
90
90
|
binaryWriter.setFloat32(buffer[i]);
|
91
91
|
}
|
92
92
|
break;
|
93
93
|
}
|
94
|
-
case 5120 /* BYTE */: {
|
94
|
+
case 5120 /* AccessorComponentType.BYTE */: {
|
95
95
|
for (let i = 0; i != buffer.length; i++) {
|
96
96
|
binaryWriter.setByte(buffer[i] * 127);
|
97
97
|
}
|
98
98
|
break;
|
99
99
|
}
|
100
|
-
case 5122 /* SHORT */: {
|
100
|
+
case 5122 /* AccessorComponentType.SHORT */: {
|
101
101
|
for (let i = 0; i != buffer.length; i++) {
|
102
102
|
binaryWriter.setInt16(buffer[i] * 32767);
|
103
103
|
}
|
@@ -115,7 +115,7 @@ export class EXT_mesh_gpu_instancing {
|
|
115
115
|
componentType: componentType,
|
116
116
|
count: count,
|
117
117
|
type: type,
|
118
|
-
normalized: componentType == 5120 /* BYTE */ || componentType == 5122 /* SHORT */,
|
118
|
+
normalized: componentType == 5120 /* AccessorComponentType.BYTE */ || componentType == 5122 /* AccessorComponentType.SHORT */,
|
119
119
|
};
|
120
120
|
this._exporter._accessors.push(accessor);
|
121
121
|
return accessorIndex;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"EXT_mesh_gpu_instancing.js","sourceRoot":"","sources":["../../../../../../lts/serializers/generated/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAG5C,OAAO,EAAE,IAAI,EAAE,uCAAyB;AACxC,oDAAsC;AACtC,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,OAAO,EAAE,6CAA+B;AACzE,OAAO,EAAE,YAAY,EAAE,0CAA4B;AAEnD,MAAM,IAAI,GAAG,yBAAyB,CAAC;AAEvC;;GAEG;AACH,gEAAgE;AAChE,MAAM,OAAO,uBAAuB;IAchC,YAAY,QAAmB;QAb/B,6BAA6B;QACb,SAAI,GAAG,IAAI,CAAC;QAE5B,gDAAgD;QACzC,YAAO,GAAG,IAAI,CAAC;QAEtB,iDAAiD;QAC1C,aAAQ,GAAG,KAAK,CAAC;QAIhB,aAAQ,GAAG,KAAK,CAAC;QAGrB,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;IAC9B,CAAC;IAEM,OAAO,KAAI,CAAC;IAEnB,gBAAgB;IAChB,IAAW,OAAO;QACd,OAAO,IAAI,CAAC,QAAQ,CAAC;IACzB,CAAC;IAEM,mBAAmB,CACtB,OAAe,EACf,IAAqB,EACrB,WAAiB,EACjB,OAAmC,EACnC,YAA4B;QAE5B,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;YAC3B,IAAI,IAAI,IAAI,WAAW,YAAY,IAAI,EAAE;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AAG,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,MAAM,CAAC;QAC3D,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAErC,6BAA6B;QAC7B,MAAM,aAAa,GAAG,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,MAAM,CAAC;QACvD,MAAM,QAAQ,GAAc;YACxB,UAAU,EAAE,eAAe;YAC3B,aAAa,EAAE,aAAa;YAC5B,KAAK,EAAE,KAAK;YACZ,IAAI,EAAE,IAAI;YACV,UAAU,EAAE,aAAa,mBAA8B,IAAI,aAAa,oBAA+B;SAC1G,CAAC;QACF,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACzC,OAAO,aAAa,CAAC;IACzB,CAAC;CACJ;AAED,6DAA6D;AAC7D,SAAS,CAAC,iBAAiB,CAAC,IAAI,EAAE,CAAC,QAAQ,EAAE,EAAE,CAAC,IAAI,uBAAuB,CAAC,QAAQ,CAAC,CAAC,CAAC","sourcesContent":["import type { IBufferView, IAccessor, INode, IEXTMeshGpuInstancing } from \"babylonjs-gltf2interface\";\r\nimport { AccessorType, AccessorComponentType } from \"babylonjs-gltf2interface\";\r\nimport type { IGLTFExporterExtensionV2 } from \"../glTFExporterExtension\";\r\nimport type { _BinaryWriter } from \"../glTFExporter\";\r\nimport { _Exporter } from \"../glTFExporter\";\r\nimport type { Nullable } from \"core/types\";\r\nimport type { Node } from \"core/node\";\r\nimport { Mesh } from \"core/Meshes/mesh\";\r\nimport \"core/Meshes/thinInstanceMesh\";\r\nimport { TmpVectors, Quaternion, Vector3 } from \"core/Maths/math.vector\";\r\nimport { VertexBuffer } from \"core/Buffers/buffer\";\r\n\r\nconst NAME = \"EXT_mesh_gpu_instancing\";\r\n\r\n/**\r\n * [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Vendor/EXT_mesh_gpu_instancing/README.md)\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class EXT_mesh_gpu_instancing 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 private _exporter: _Exporter;\r\n\r\n private _wasUsed = false;\r\n\r\n constructor(exporter: _Exporter) {\r\n this._exporter = exporter;\r\n }\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 postExportNodeAsync?(\r\n context: string,\r\n node: Nullable<INode>,\r\n babylonNode: Node,\r\n nodeMap?: { [key: number]: number },\r\n binaryWriter?: _BinaryWriter\r\n ): Promise<Nullable<INode>> {\r\n return new Promise((resolve) => {\r\n if (node && babylonNode instanceof Mesh) {\r\n if (babylonNode.hasThinInstances && binaryWriter) {\r\n this._wasUsed = true;\r\n\r\n const noTranslation = Vector3.Zero();\r\n const noRotation = Quaternion.Identity();\r\n const noScale = Vector3.One();\r\n\r\n // retreive all the instance world matrix\r\n const matrix = babylonNode.thinInstanceGetWorldMatrices();\r\n\r\n const iwt = TmpVectors.Vector3[2];\r\n const iwr = TmpVectors.Quaternion[1];\r\n const iws = TmpVectors.Vector3[3];\r\n\r\n let hasAnyInstanceWorldTranslation = false;\r\n let hasAnyInstanceWorldRotation = false;\r\n let hasAnyInstanceWorldScale = false;\r\n\r\n // prepare temp buffers\r\n const translationBuffer = new Float32Array(babylonNode.thinInstanceCount * 3);\r\n const rotationBuffer = new Float32Array(babylonNode.thinInstanceCount * 4);\r\n const scaleBuffer = new Float32Array(babylonNode.thinInstanceCount * 3);\r\n\r\n let i = 0;\r\n for (const m of matrix) {\r\n m.decompose(iws, iwr, iwt);\r\n\r\n // fill the temp buffer\r\n translationBuffer.set(iwt.asArray(), i * 3);\r\n rotationBuffer.set(iwr.normalize().asArray(), i * 4); // ensure the quaternion is normalized\r\n scaleBuffer.set(iws.asArray(), i * 3);\r\n\r\n // this is where we decide if there is any transformation\r\n hasAnyInstanceWorldTranslation = hasAnyInstanceWorldTranslation || !iwt.equalsWithEpsilon(noTranslation);\r\n hasAnyInstanceWorldRotation = hasAnyInstanceWorldRotation || !iwr.equalsWithEpsilon(noRotation);\r\n hasAnyInstanceWorldScale = hasAnyInstanceWorldScale || !iws.equalsWithEpsilon(noScale);\r\n\r\n i++;\r\n }\r\n\r\n const extension: IEXTMeshGpuInstancing = {\r\n attributes: {},\r\n };\r\n\r\n // do we need to write TRANSLATION ?\r\n if (hasAnyInstanceWorldTranslation) {\r\n extension.attributes[\"TRANSLATION\"] = this._buildAccessor(\r\n translationBuffer,\r\n AccessorType.VEC3,\r\n babylonNode.thinInstanceCount,\r\n binaryWriter,\r\n AccessorComponentType.FLOAT\r\n );\r\n }\r\n // do we need to write ROTATION ?\r\n if (hasAnyInstanceWorldRotation) {\r\n const componentType = AccessorComponentType.FLOAT; // we decided to stay on FLOAT for now see https://github.com/BabylonJS/Babylon.js/pull/12495\r\n extension.attributes[\"ROTATION\"] = this._buildAccessor(rotationBuffer, AccessorType.VEC4, babylonNode.thinInstanceCount, binaryWriter, componentType);\r\n }\r\n // do we need to write SCALE ?\r\n if (hasAnyInstanceWorldScale) {\r\n extension.attributes[\"SCALE\"] = this._buildAccessor(\r\n scaleBuffer,\r\n AccessorType.VEC3,\r\n babylonNode.thinInstanceCount,\r\n binaryWriter,\r\n AccessorComponentType.FLOAT\r\n );\r\n }\r\n\r\n /* eslint-enable @typescript-eslint/naming-convention*/\r\n node.extensions = node.extensions || {};\r\n node.extensions[NAME] = extension;\r\n }\r\n }\r\n resolve(node);\r\n });\r\n }\r\n\r\n private _buildAccessor(buffer: Float32Array, type: AccessorType, count: number, binaryWriter: _BinaryWriter, componentType: AccessorComponentType): number {\r\n // write the buffer\r\n const bufferOffset = binaryWriter.getByteOffset();\r\n switch (componentType) {\r\n case AccessorComponentType.FLOAT: {\r\n for (let i = 0; i != buffer.length; i++) {\r\n binaryWriter.setFloat32(buffer[i]);\r\n }\r\n break;\r\n }\r\n case AccessorComponentType.BYTE: {\r\n for (let i = 0; i != buffer.length; i++) {\r\n binaryWriter.setByte(buffer[i] * 127);\r\n }\r\n break;\r\n }\r\n case AccessorComponentType.SHORT: {\r\n for (let i = 0; i != buffer.length; i++) {\r\n binaryWriter.setInt16(buffer[i] * 32767);\r\n }\r\n\r\n break;\r\n }\r\n }\r\n // build the buffer view\r\n const bv: IBufferView = { buffer: 0, byteOffset: bufferOffset, byteLength: buffer.length * VertexBuffer.GetTypeByteLength(componentType) };\r\n const bufferViewIndex = this._exporter._bufferViews.length;\r\n this._exporter._bufferViews.push(bv);\r\n\r\n // finally build the accessor\r\n const accessorIndex = this._exporter._accessors.length;\r\n const accessor: IAccessor = {\r\n bufferView: bufferViewIndex,\r\n componentType: componentType,\r\n count: count,\r\n type: type,\r\n normalized: componentType == AccessorComponentType.BYTE || componentType == AccessorComponentType.SHORT,\r\n };\r\n this._exporter._accessors.push(accessor);\r\n return accessorIndex;\r\n }\r\n}\r\n\r\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n_Exporter.RegisterExtension(NAME, (exporter) => new EXT_mesh_gpu_instancing(exporter));\r\n"]}
|
1
|
+
{"version":3,"file":"EXT_mesh_gpu_instancing.js","sourceRoot":"","sources":["../../../../../../lts/serializers/generated/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAG5C,OAAO,EAAE,IAAI,EAAE,uCAAyB;AACxC,oDAAsC;AACtC,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,OAAO,EAAE,6CAA+B;AACzE,OAAO,EAAE,YAAY,EAAE,0CAA4B;AAEnD,MAAM,IAAI,GAAG,yBAAyB,CAAC;AAEvC;;GAEG;AACH,gEAAgE;AAChE,MAAM,OAAO,uBAAuB;IAchC,YAAY,QAAmB;QAb/B,6BAA6B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port { AccessorType, AccessorComponentType } from \"babylonjs-gltf2interface\";\r\nimport type { IGLTFExporterExtensionV2 } from \"../glTFExporterExtension\";\r\nimport type { _BinaryWriter } from \"../glTFExporter\";\r\nimport { _Exporter } from \"../glTFExporter\";\r\nimport type { Nullable } from \"core/types\";\r\nimport type { Node } from \"core/node\";\r\nimport { Mesh } from \"core/Meshes/mesh\";\r\nimport \"core/Meshes/thinInstanceMesh\";\r\nimport { TmpVectors, Quaternion, Vector3 } from \"core/Maths/math.vector\";\r\nimport { VertexBuffer } from \"core/Buffers/buffer\";\r\n\r\nconst NAME = \"EXT_mesh_gpu_instancing\";\r\n\r\n/**\r\n * [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Vendor/EXT_mesh_gpu_instancing/README.md)\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class EXT_mesh_gpu_instancing 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 private _exporter: _Exporter;\r\n\r\n private _wasUsed = false;\r\n\r\n constructor(exporter: _Exporter) {\r\n this._exporter = exporter;\r\n }\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 postExportNodeAsync?(\r\n context: string,\r\n node: Nullable<INode>,\r\n babylonNode: Node,\r\n nodeMap?: { [key: number]: number },\r\n binaryWriter?: _BinaryWriter\r\n ): Promise<Nullable<INode>> {\r\n return new Promise((resolve) => {\r\n if (node && babylonNode instanceof Mesh) {\r\n if (babylonNode.hasThinInstances && binaryWriter) {\r\n this._wasUsed = true;\r\n\r\n const noTranslation = Vector3.Zero();\r\n const noRotation = Quaternion.Identity();\r\n const noScale = Vector3.One();\r\n\r\n // retreive all the instance world matrix\r\n const matrix = babylonNode.thinInstanceGetWorldMatrices();\r\n\r\n const iwt = TmpVectors.Vector3[2];\r\n const iwr = TmpVectors.Quaternion[1];\r\n const iws = TmpVectors.Vector3[3];\r\n\r\n let hasAnyInstanceWorldTranslation = false;\r\n let hasAnyInstanceWorldRotation = false;\r\n let hasAnyInstanceWorldScale = false;\r\n\r\n // prepare temp buffers\r\n const translationBuffer = new Float32Array(babylonNode.thinInstanceCount * 3);\r\n const rotationBuffer = new Float32Array(babylonNode.thinInstanceCount * 4);\r\n const scaleBuffer = new Float32Array(babylonNode.thinInstanceCount * 3);\r\n\r\n let i = 0;\r\n for (const m of matrix) {\r\n m.decompose(iws, iwr, iwt);\r\n\r\n // fill the temp buffer\r\n translationBuffer.set(iwt.asArray(), i * 3);\r\n rotationBuffer.set(iwr.normalize().asArray(), i * 4); // ensure the quaternion is normalized\r\n scaleBuffer.set(iws.asArray(), i * 3);\r\n\r\n // this is where we decide if there is any transformation\r\n hasAnyInstanceWorldTranslation = hasAnyInstanceWorldTranslation || !iwt.equalsWithEpsilon(noTranslation);\r\n hasAnyInstanceWorldRotation = hasAnyInstanceWorldRotation || !iwr.equalsWithEpsilon(noRotation);\r\n hasAnyInstanceWorldScale = hasAnyInstanceWorldScale || !iws.equalsWithEpsilon(noScale);\r\n\r\n i++;\r\n }\r\n\r\n const extension: IEXTMeshGpuInstancing = {\r\n attributes: {},\r\n };\r\n\r\n // do we need to write TRANSLATION ?\r\n if (hasAnyInstanceWorldTranslation) {\r\n extension.attributes[\"TRANSLATION\"] = this._buildAccessor(\r\n translationBuffer,\r\n AccessorType.VEC3,\r\n babylonNode.thinInstanceCount,\r\n binaryWriter,\r\n AccessorComponentType.FLOAT\r\n );\r\n }\r\n // do we need to write ROTATION ?\r\n if (hasAnyInstanceWorldRotation) {\r\n const componentType = AccessorComponentType.FLOAT; // we decided to stay on FLOAT for now see https://github.com/BabylonJS/Babylon.js/pull/12495\r\n extension.attributes[\"ROTATION\"] = this._buildAccessor(rotationBuffer, AccessorType.VEC4, babylonNode.thinInstanceCount, binaryWriter, componentType);\r\n }\r\n // do we need to write SCALE ?\r\n if (hasAnyInstanceWorldScale) {\r\n extension.attributes[\"SCALE\"] = this._buildAccessor(\r\n scaleBuffer,\r\n AccessorType.VEC3,\r\n babylonNode.thinInstanceCount,\r\n binaryWriter,\r\n AccessorComponentType.FLOAT\r\n );\r\n }\r\n\r\n /* eslint-enable @typescript-eslint/naming-convention*/\r\n node.extensions = node.extensions || {};\r\n node.extensions[NAME] = extension;\r\n }\r\n }\r\n resolve(node);\r\n });\r\n }\r\n\r\n private _buildAccessor(buffer: Float32Array, type: AccessorType, count: number, binaryWriter: _BinaryWriter, componentType: AccessorComponentType): number {\r\n // write the buffer\r\n const bufferOffset = binaryWriter.getByteOffset();\r\n switch (componentType) {\r\n case AccessorComponentType.FLOAT: {\r\n for (let i = 0; i != buffer.length; i++) {\r\n binaryWriter.setFloat32(buffer[i]);\r\n }\r\n break;\r\n }\r\n case AccessorComponentType.BYTE: {\r\n for (let i = 0; i != buffer.length; i++) {\r\n binaryWriter.setByte(buffer[i] * 127);\r\n }\r\n break;\r\n }\r\n case AccessorComponentType.SHORT: {\r\n for (let i = 0; i != buffer.length; i++) {\r\n binaryWriter.setInt16(buffer[i] * 32767);\r\n }\r\n\r\n break;\r\n }\r\n }\r\n // build the buffer view\r\n const bv: IBufferView = { buffer: 0, byteOffset: bufferOffset, byteLength: buffer.length * VertexBuffer.GetTypeByteLength(componentType) };\r\n const bufferViewIndex = this._exporter._bufferViews.length;\r\n this._exporter._bufferViews.push(bv);\r\n\r\n // finally build the accessor\r\n const accessorIndex = this._exporter._accessors.length;\r\n const accessor: IAccessor = {\r\n bufferView: bufferViewIndex,\r\n componentType: componentType,\r\n count: count,\r\n type: type,\r\n normalized: componentType == AccessorComponentType.BYTE || componentType == AccessorComponentType.SHORT,\r\n };\r\n this._exporter._accessors.push(accessor);\r\n return accessorIndex;\r\n }\r\n}\r\n\r\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n_Exporter.RegisterExtension(NAME, (exporter) => new EXT_mesh_gpu_instancing(exporter));\r\n"]}
|
@@ -50,11 +50,11 @@ export class KHR_lights_punctual {
|
|
50
50
|
const babylonLight = babylonNode;
|
51
51
|
let light;
|
52
52
|
const lightType = babylonLight.getTypeID() == Light.LIGHTTYPEID_POINTLIGHT
|
53
|
-
? "point" /* POINT */
|
53
|
+
? "point" /* KHRLightsPunctual_LightType.POINT */
|
54
54
|
: babylonLight.getTypeID() == Light.LIGHTTYPEID_DIRECTIONALLIGHT
|
55
|
-
? "directional" /* DIRECTIONAL */
|
55
|
+
? "directional" /* KHRLightsPunctual_LightType.DIRECTIONAL */
|
56
56
|
: babylonLight.getTypeID() == Light.LIGHTTYPEID_SPOTLIGHT
|
57
|
-
? "spot" /* SPOT */
|
57
|
+
? "spot" /* KHRLightsPunctual_LightType.SPOT */
|
58
58
|
: null;
|
59
59
|
if (lightType == null) {
|
60
60
|
Logger.Warn(`${context}: Light ${babylonLight.name} is not supported in ${NAME}`);
|
@@ -68,7 +68,7 @@ export class KHR_lights_punctual {
|
|
68
68
|
}
|
69
69
|
node.translation = lightPosition.asArray();
|
70
70
|
}
|
71
|
-
if (lightType !== "point" /* POINT */) {
|
71
|
+
if (lightType !== "point" /* KHRLightsPunctual_LightType.POINT */) {
|
72
72
|
const localAxis = babylonLight.direction;
|
73
73
|
const yaw = -Math.atan2(localAxis.z * (this._exporter._babylonScene.useRightHandedSystem ? -1 : 1), localAxis.x) + Math.PI / 2;
|
74
74
|
const len = Math.sqrt(localAxis.x * localAxis.x + localAxis.z * localAxis.z);
|
@@ -96,7 +96,7 @@ export class KHR_lights_punctual {
|
|
96
96
|
if (babylonLight.range !== Number.MAX_VALUE) {
|
97
97
|
light.range = babylonLight.range;
|
98
98
|
}
|
99
|
-
if (lightType === "spot" /* SPOT */) {
|
99
|
+
if (lightType === "spot" /* KHRLightsPunctual_LightType.SPOT */) {
|
100
100
|
const babylonSpotLight = babylonLight;
|
101
101
|
if (babylonSpotLight.angle !== Math.PI / 2.0) {
|
102
102
|
if (light.spot == null) {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"KHR_lights_punctual.js","sourceRoot":"","sources":["../../../../../../lts/serializers/generated/glTF/2.0/Extensions/KHR_lights_punctual.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,EAAE,6CAA+B;AACjF,OAAO,EAAE,MAAM,EAAE,4CAA8B;AAC/C,OAAO,EAAE,KAAK,EAAE,wCAA0B;AAC1C,OAAO,EAAE,gBAAgB,EAAE,mDAAqC;AAEhE,OAAO,EAAE,WAAW,EAAE,8CAAgC;AAItD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,MAAM,EAAE,uCAAyB;AAC1C,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,MAAM,IAAI,GAAG,qBAAqB,CAAC;AAEnC;;GAEG;AACH,gEAAgE;AAChE,MAAM,OAAO,mBAAmB;IAe5B;;OAEG;IACH,YAAY,QAAmB;QAjB/B,kCAAkC;QAClB,SAAI,GAAG,IAAI,CAAC;QAE5B,iDAAiD;QAC1C,YAAO,GAAG,IAAI,CAAC;QAEtB,iDAAiD;QAC1C,aAAQ,GAAG,KAAK,CAAC;QAWpB,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;IAC9B,CAAC;IAED,gBAAgB;IACT,OAAO;QACT,IAAI,CAAC,OAAe,GAAG,IAAI,CAAC;IACjC,CAAC;IAED,gBAAgB;IAChB,IAAW,OAAO;QACd,OAAO,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC;IAC1B,CAAC;IAED,gBAAgB;IACT,WAAW;QACd,IAAI,CAAC,SAAU,CAAC,KAAK,CAAC,UAAW,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC;IAC3D,CAAC;IACD;;;;;;;OAOG;IACI,mBAAmB,CAAC,OAAe,EAAE,IAAqB,EAAE,WAAi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J;AAED,SAAS,CAAC,iBAAiB,CAAC,IAAI,EAAE,CAAC,QAAQ,EAAE,EAAE,CAAC,IAAI,mBAAmB,CAAC,QAAQ,CAAC,CAAC,CAAC","sourcesContent":["import type { SpotLight } from \"core/Lights/spotLight\";\r\nimport type { Nullable } from \"core/types\";\r\nimport { Vector3, Quaternion, TmpVectors, Matrix } from \"core/Maths/math.vector\";\r\nimport { Color3 } from \"core/Maths/math.color\";\r\nimport { Light } from \"core/Lights/light\";\r\nimport { DirectionalLight } from \"core/Lights/directionalLight\";\r\nimport type { Node } from \"core/node\";\r\nimport { ShadowLight } from \"core/Lights/shadowLight\";\r\nimport type { INode, IKHRLightsPunctual_LightReference, IKHRLightsPunctual_Light, IKHRLightsPunctual } from \"babylonjs-gltf2interface\";\r\nimport { KHRLightsPunctual_LightType } from \"babylonjs-gltf2interface\";\r\nimport type { IGLTFExporterExtensionV2 } from \"../glTFExporterExtension\";\r\nimport { _Exporter } from \"../glTFExporter\";\r\nimport { Logger } from \"core/Misc/logger\";\r\nimport { _GLTFUtilities } from \"../glTFUtilities\";\r\n\r\nconst NAME = \"KHR_lights_punctual\";\r\n\r\n/**\r\n * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_lights_punctual/README.md)\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class KHR_lights_punctual implements IGLTFExporterExtensionV2 {\r\n /** The 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 _exporter: _Exporter;\r\n\r\n private _lights: IKHRLightsPunctual;\r\n\r\n /**\r\n * @internal\r\n */\r\n constructor(exporter: _Exporter) {\r\n this._exporter = exporter;\r\n }\r\n\r\n /** @internal */\r\n public dispose() {\r\n (this._lights as any) = null;\r\n }\r\n\r\n /** @internal */\r\n public get wasUsed() {\r\n return !!this._lights;\r\n }\r\n\r\n /** @internal */\r\n public onExporting(): void {\r\n this._exporter!._glTF.extensions![NAME] = this._lights;\r\n }\r\n /**\r\n * Define this method to modify the default behavior when exporting a node\r\n * @param context The context when exporting the node\r\n * @param node glTF node\r\n * @param babylonNode BabylonJS node\r\n * @param nodeMap Node mapping of unique id to glTF node index\r\n * @returns nullable INode promise\r\n */\r\n public postExportNodeAsync(context: string, node: Nullable<INode>, babylonNode: Node, nodeMap?: { [key: number]: number }): Promise<Nullable<INode>> {\r\n return new Promise((resolve) => {\r\n if (node && babylonNode instanceof ShadowLight) {\r\n const babylonLight: ShadowLight = babylonNode;\r\n let light: IKHRLightsPunctual_Light;\r\n\r\n const lightType =\r\n babylonLight.getTypeID() == Light.LIGHTTYPEID_POINTLIGHT\r\n ? KHRLightsPunctual_LightType.POINT\r\n : babylonLight.getTypeID() == Light.LIGHTTYPEID_DIRECTIONALLIGHT\r\n ? KHRLightsPunctual_LightType.DIRECTIONAL\r\n : babylonLight.getTypeID() == Light.LIGHTTYPEID_SPOTLIGHT\r\n ? KHRLightsPunctual_LightType.SPOT\r\n : null;\r\n if (lightType == null) {\r\n Logger.Warn(`${context}: Light ${babylonLight.name} is not supported in ${NAME}`);\r\n } else {\r\n const lightPosition = babylonLight.position.clone();\r\n const convertToRightHandedSystem = this._exporter._convertToRightHandedSystemMap[babylonNode.uniqueId];\r\n if (!lightPosition.equals(Vector3.Zero())) {\r\n if (convertToRightHandedSystem) {\r\n _GLTFUtilities._GetRightHandedPositionVector3FromRef(lightPosition);\r\n }\r\n node.translation = lightPosition.asArray();\r\n }\r\n if (lightType !== KHRLightsPunctual_LightType.POINT) {\r\n const localAxis = babylonLight.direction;\r\n const yaw = -Math.atan2(localAxis.z * (this._exporter._babylonScene.useRightHandedSystem ? -1 : 1), localAxis.x) + Math.PI / 2;\r\n const len = Math.sqrt(localAxis.x * localAxis.x + localAxis.z * localAxis.z);\r\n const pitch = -Math.atan2(localAxis.y, len);\r\n const lightRotationQuaternion = Quaternion.RotationYawPitchRoll(yaw, pitch, 0);\r\n if (convertToRightHandedSystem) {\r\n _GLTFUtilities._GetRightHandedQuaternionFromRef(lightRotationQuaternion);\r\n }\r\n if (!lightRotationQuaternion.equals(Quaternion.Identity())) {\r\n node.rotation = lightRotationQuaternion.asArray();\r\n }\r\n }\r\n\r\n if (babylonLight.falloffType !== Light.FALLOFF_GLTF) {\r\n Logger.Warn(`${context}: Light falloff for ${babylonLight.name} does not match the ${NAME} specification!`);\r\n }\r\n light = {\r\n type: lightType,\r\n };\r\n if (!babylonLight.diffuse.equals(Color3.White())) {\r\n light.color = babylonLight.diffuse.asArray();\r\n }\r\n if (babylonLight.intensity !== 1.0) {\r\n light.intensity = babylonLight.intensity;\r\n }\r\n if (babylonLight.range !== Number.MAX_VALUE) {\r\n light.range = babylonLight.range;\r\n }\r\n\r\n if (lightType === KHRLightsPunctual_LightType.SPOT) {\r\n const babylonSpotLight = babylonLight as SpotLight;\r\n if (babylonSpotLight.angle !== Math.PI / 2.0) {\r\n if (light.spot == null) {\r\n light.spot = {};\r\n }\r\n light.spot.outerConeAngle = babylonSpotLight.angle / 2.0;\r\n }\r\n if (babylonSpotLight.innerAngle !== 0) {\r\n if (light.spot == null) {\r\n light.spot = {};\r\n }\r\n light.spot.innerConeAngle = babylonSpotLight.innerAngle / 2.0;\r\n }\r\n }\r\n\r\n if (this._lights == null) {\r\n this._lights = {\r\n lights: [],\r\n };\r\n }\r\n\r\n this._lights.lights.push(light);\r\n\r\n const lightReference: IKHRLightsPunctual_LightReference = {\r\n light: this._lights.lights.length - 1,\r\n };\r\n\r\n // Avoid duplicating the Light's parent node if possible.\r\n const parentBabylonNode = babylonNode.parent;\r\n if (parentBabylonNode && parentBabylonNode.getChildren().length == 1) {\r\n const parentNode = this._exporter._nodes[nodeMap![parentBabylonNode.uniqueId]];\r\n if (parentNode) {\r\n const parentNodeLocalMatrix = TmpVectors.Matrix[0];\r\n const parentInvertNodeLocalMatrix = TmpVectors.Matrix[1];\r\n const parentNodeLocalTranslation = parentNode.translation\r\n ? new Vector3(parentNode.translation[0], parentNode.translation[1], parentNode.translation[2])\r\n : Vector3.Zero();\r\n const parentNodeLocalRotation = parentNode.rotation\r\n ? new Quaternion(parentNode.rotation[0], parentNode.rotation[1], parentNode.rotation[2], parentNode.rotation[3])\r\n : Quaternion.Identity();\r\n const parentNodeLocalScale = parentNode.scale ? new Vector3(parentNode.scale[0], parentNode.scale[1], parentNode.scale[2]) : Vector3.One();\r\n\r\n Matrix.ComposeToRef(parentNodeLocalScale, parentNodeLocalRotation, parentNodeLocalTranslation, parentNodeLocalMatrix);\r\n parentNodeLocalMatrix.invertToRef(parentInvertNodeLocalMatrix);\r\n\r\n // Convert light local matrix to local matrix relative to grandparent, facing -Z\r\n const lightLocalMatrix = TmpVectors.Matrix[2];\r\n const nodeLocalTranslation = node.translation ? new Vector3(node.translation[0], node.translation[1], node.translation[2]) : Vector3.Zero();\r\n\r\n // Undo directional light positional offset\r\n if (babylonLight instanceof DirectionalLight) {\r\n nodeLocalTranslation.subtractInPlace(\r\n this._exporter._babylonScene.useRightHandedSystem\r\n ? babylonLight.direction\r\n : _GLTFUtilities._GetRightHandedPositionVector3(babylonLight.direction)\r\n );\r\n }\r\n const nodeLocalRotation = this._exporter._babylonScene.useRightHandedSystem ? Quaternion.Identity() : new Quaternion(0, 1, 0, 0);\r\n if (node.rotation) {\r\n nodeLocalRotation.multiplyInPlace(new Quaternion(node.rotation[0], node.rotation[1], node.rotation[2], node.rotation[3]));\r\n }\r\n const nodeLocalScale = node.scale ? new Vector3(node.scale[0], node.scale[1], node.scale[2]) : Vector3.One();\r\n\r\n Matrix.ComposeToRef(nodeLocalScale, nodeLocalRotation, nodeLocalTranslation, lightLocalMatrix);\r\n lightLocalMatrix.multiplyToRef(parentInvertNodeLocalMatrix, lightLocalMatrix);\r\n const parentNewScale = TmpVectors.Vector3[0];\r\n const parentNewRotationQuaternion = TmpVectors.Quaternion[0];\r\n const parentNewTranslation = TmpVectors.Vector3[1];\r\n\r\n lightLocalMatrix.decompose(parentNewScale, parentNewRotationQuaternion, parentNewTranslation);\r\n parentNode.scale = parentNewScale.asArray();\r\n parentNode.rotation = parentNewRotationQuaternion.asArray();\r\n parentNode.translation = parentNewTranslation.asArray();\r\n\r\n if (parentNode.extensions == null) {\r\n parentNode.extensions = {};\r\n }\r\n parentNode.extensions[NAME] = lightReference;\r\n\r\n // Do not export the original node\r\n resolve(null);\r\n return;\r\n }\r\n }\r\n\r\n if (node.extensions == null) {\r\n node.extensions = {};\r\n }\r\n\r\n node.extensions[NAME] = lightReference;\r\n }\r\n }\r\n resolve(node);\r\n });\r\n }\r\n}\r\n\r\n_Exporter.RegisterExtension(NAME, (exporter) => new KHR_lights_punctual(exporter));\r\n"]}
|
1
|
+
{"version":3,"file":"KHR_lights_punctual.js","sourceRoot":"","sources":["../../../../../../lts/serializers/generated/glTF/2.0/Extensions/KHR_lights_punctual.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,EAAE,6CAA+B;AACjF,OAAO,EAAE,MAAM,EAAE,4CAA8B;AAC/C,OAAO,EAAE,KAAK,EAAE,wCAA0B;AAC1C,OAAO,EAAE,gBAAgB,EAAE,mDAAqC;AAEhE,OAAO,EAAE,WAAW,EAAE,8CAAgC;AAItD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,MAAM,EAAE,uCAAyB;AAC1C,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,MAAM,IAAI,GAAG,qBAAqB,CAAC;AAEnC;;GAEG;AACH,gEAAgE;AAChE,MAAM,OAAO,mBAAmB;IAe5B;;OAEG;IACH,YAAY,QAAmB;QAjB/B,kCAAkC;QAClB,SAAI,GAAG,IAAI,CAAC;QAE5B,iDAAiD;QAC1C,YAAO,GAAG,IAAI,CAAC;QAEtB,iDAAiD;QAC1C,aAAQ,GAAG,KA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AC/B,UAAU,CAAC,UAAU,GAAG,EAAE,CAAC;6BAC9B;4BACD,UAAU,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,cAAc,CAAC;4BAE7C,kCAAkC;4BAClC,OAAO,CAAC,IAAI,CAAC,CAAC;4BACd,OAAO;yBACV;qBACJ;oBAED,IAAI,IAAI,CAAC,UAAU,IAAI,IAAI,EAAE;wBACzB,IAAI,CAAC,UAAU,GAAG,EAAE,CAAC;qBACxB;oBAED,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,cAAc,CAAC;iBAC1C;aACJ;YACD,OAAO,CAAC,IAAI,CAAC,CAAC;QAClB,CAAC,CAAC,CAAC;IACP,CAAC;CACJ;AAED,SAAS,CAAC,iBAAiB,CAAC,IAAI,EAAE,CAAC,QAAQ,EAAE,EAAE,CAAC,IAAI,mBAAmB,CAAC,QAAQ,CAAC,CAAC,CAAC","sourcesContent":["import type { SpotLight } from \"core/Lights/spotLight\";\r\nimport type { Nullable } from \"core/types\";\r\nimport { Vector3, Quaternion, TmpVectors, Matrix } from \"core/Maths/math.vector\";\r\nimport { Color3 } from \"core/Maths/math.color\";\r\nimport { Light } from \"core/Lights/light\";\r\nimport { DirectionalLight } from \"core/Lights/directionalLight\";\r\nimport type { Node } from \"core/node\";\r\nimport { ShadowLight } from \"core/Lights/shadowLight\";\r\nimport type { INode, IKHRLightsPunctual_LightReference, IKHRLightsPunctual_Light, IKHRLightsPunctual } from \"babylonjs-gltf2interface\";\r\nimport { KHRLightsPunctual_LightType } from \"babylonjs-gltf2interface\";\r\nimport type { IGLTFExporterExtensionV2 } from \"../glTFExporterExtension\";\r\nimport { _Exporter } from \"../glTFExporter\";\r\nimport { Logger } from \"core/Misc/logger\";\r\nimport { _GLTFUtilities } from \"../glTFUtilities\";\r\n\r\nconst NAME = \"KHR_lights_punctual\";\r\n\r\n/**\r\n * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_lights_punctual/README.md)\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class KHR_lights_punctual implements IGLTFExporterExtensionV2 {\r\n /** The 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 _exporter: _Exporter;\r\n\r\n private _lights: IKHRLightsPunctual;\r\n\r\n /**\r\n * @internal\r\n */\r\n constructor(exporter: _Exporter) {\r\n this._exporter = exporter;\r\n }\r\n\r\n /** @internal */\r\n public dispose() {\r\n (this._lights as any) = null;\r\n }\r\n\r\n /** @internal */\r\n public get wasUsed() {\r\n return !!this._lights;\r\n }\r\n\r\n /** @internal */\r\n public onExporting(): void {\r\n this._exporter!._glTF.extensions![NAME] = this._lights;\r\n }\r\n /**\r\n * Define this method to modify the default behavior when exporting a node\r\n * @param context The context when exporting the node\r\n * @param node glTF node\r\n * @param babylonNode BabylonJS node\r\n * @param nodeMap Node mapping of unique id to glTF node index\r\n * @returns nullable INode promise\r\n */\r\n public postExportNodeAsync(context: string, node: Nullable<INode>, babylonNode: Node, nodeMap?: { [key: number]: number }): Promise<Nullable<INode>> {\r\n return new Promise((resolve) => {\r\n if (node && babylonNode instanceof ShadowLight) {\r\n const babylonLight: ShadowLight = babylonNode;\r\n let light: IKHRLightsPunctual_Light;\r\n\r\n const lightType =\r\n babylonLight.getTypeID() == Light.LIGHTTYPEID_POINTLIGHT\r\n ? KHRLightsPunctual_LightType.POINT\r\n : babylonLight.getTypeID() == Light.LIGHTTYPEID_DIRECTIONALLIGHT\r\n ? KHRLightsPunctual_LightType.DIRECTIONAL\r\n : babylonLight.getTypeID() == Light.LIGHTTYPEID_SPOTLIGHT\r\n ? KHRLightsPunctual_LightType.SPOT\r\n : null;\r\n if (lightType == null) {\r\n Logger.Warn(`${context}: Light ${babylonLight.name} is not supported in ${NAME}`);\r\n } else {\r\n const lightPosition = babylonLight.position.clone();\r\n const convertToRightHandedSystem = this._exporter._convertToRightHandedSystemMap[babylonNode.uniqueId];\r\n if (!lightPosition.equals(Vector3.Zero())) {\r\n if (convertToRightHandedSystem) {\r\n _GLTFUtilities._GetRightHandedPositionVector3FromRef(lightPosition);\r\n }\r\n node.translation = lightPosition.asArray();\r\n }\r\n if (lightType !== KHRLightsPunctual_LightType.POINT) {\r\n const localAxis = babylonLight.direction;\r\n const yaw = -Math.atan2(localAxis.z * (this._exporter._babylonScene.useRightHandedSystem ? -1 : 1), localAxis.x) + Math.PI / 2;\r\n const len = Math.sqrt(localAxis.x * localAxis.x + localAxis.z * localAxis.z);\r\n const pitch = -Math.atan2(localAxis.y, len);\r\n const lightRotationQuaternion = Quaternion.RotationYawPitchRoll(yaw, pitch, 0);\r\n if (convertToRightHandedSystem) {\r\n _GLTFUtilities._GetRightHandedQuaternionFromRef(lightRotationQuaternion);\r\n }\r\n if (!lightRotationQuaternion.equals(Quaternion.Identity())) {\r\n node.rotation = lightRotationQuaternion.asArray();\r\n }\r\n }\r\n\r\n if (babylonLight.falloffType !== Light.FALLOFF_GLTF) {\r\n Logger.Warn(`${context}: Light falloff for ${babylonLight.name} does not match the ${NAME} specification!`);\r\n }\r\n light = {\r\n type: lightType,\r\n };\r\n if (!babylonLight.diffuse.equals(Color3.White())) {\r\n light.color = babylonLight.diffuse.asArray();\r\n }\r\n if (babylonLight.intensity !== 1.0) {\r\n light.intensity = babylonLight.intensity;\r\n }\r\n if (babylonLight.range !== Number.MAX_VALUE) {\r\n light.range = babylonLight.range;\r\n }\r\n\r\n if (lightType === KHRLightsPunctual_LightType.SPOT) {\r\n const babylonSpotLight = babylonLight as SpotLight;\r\n if (babylonSpotLight.angle !== Math.PI / 2.0) {\r\n if (light.spot == null) {\r\n light.spot = {};\r\n }\r\n light.spot.outerConeAngle = babylonSpotLight.angle / 2.0;\r\n }\r\n if (babylonSpotLight.innerAngle !== 0) {\r\n if (light.spot == null) {\r\n light.spot = {};\r\n }\r\n light.spot.innerConeAngle = babylonSpotLight.innerAngle / 2.0;\r\n }\r\n }\r\n\r\n if (this._lights == null) {\r\n this._lights = {\r\n lights: [],\r\n };\r\n }\r\n\r\n this._lights.lights.push(light);\r\n\r\n const lightReference: IKHRLightsPunctual_LightReference = {\r\n light: this._lights.lights.length - 1,\r\n };\r\n\r\n // Avoid duplicating the Light's parent node if possible.\r\n const parentBabylonNode = babylonNode.parent;\r\n if (parentBabylonNode && parentBabylonNode.getChildren().length == 1) {\r\n const parentNode = this._exporter._nodes[nodeMap![parentBabylonNode.uniqueId]];\r\n if (parentNode) {\r\n const parentNodeLocalMatrix = TmpVectors.Matrix[0];\r\n const parentInvertNodeLocalMatrix = TmpVectors.Matrix[1];\r\n const parentNodeLocalTranslation = parentNode.translation\r\n ? new Vector3(parentNode.translation[0], parentNode.translation[1], parentNode.translation[2])\r\n : Vector3.Zero();\r\n const parentNodeLocalRotation = parentNode.rotation\r\n ? new Quaternion(parentNode.rotation[0], parentNode.rotation[1], parentNode.rotation[2], parentNode.rotation[3])\r\n : Quaternion.Identity();\r\n const parentNodeLocalScale = parentNode.scale ? new Vector3(parentNode.scale[0], parentNode.scale[1], parentNode.scale[2]) : Vector3.One();\r\n\r\n Matrix.ComposeToRef(parentNodeLocalScale, parentNodeLocalRotation, parentNodeLocalTranslation, parentNodeLocalMatrix);\r\n parentNodeLocalMatrix.invertToRef(parentInvertNodeLocalMatrix);\r\n\r\n // Convert light local matrix to local matrix relative to grandparent, facing -Z\r\n const lightLocalMatrix = TmpVectors.Matrix[2];\r\n const nodeLocalTranslation = node.translation ? new Vector3(node.translation[0], node.translation[1], node.translation[2]) : Vector3.Zero();\r\n\r\n // Undo directional light positional offset\r\n if (babylonLight instanceof DirectionalLight) {\r\n nodeLocalTranslation.subtractInPlace(\r\n this._exporter._babylonScene.useRightHandedSystem\r\n ? babylonLight.direction\r\n : _GLTFUtilities._GetRightHandedPositionVector3(babylonLight.direction)\r\n );\r\n }\r\n const nodeLocalRotation = this._exporter._babylonScene.useRightHandedSystem ? Quaternion.Identity() : new Quaternion(0, 1, 0, 0);\r\n if (node.rotation) {\r\n nodeLocalRotation.multiplyInPlace(new Quaternion(node.rotation[0], node.rotation[1], node.rotation[2], node.rotation[3]));\r\n }\r\n const nodeLocalScale = node.scale ? new Vector3(node.scale[0], node.scale[1], node.scale[2]) : Vector3.One();\r\n\r\n Matrix.ComposeToRef(nodeLocalScale, nodeLocalRotation, nodeLocalTranslation, lightLocalMatrix);\r\n lightLocalMatrix.multiplyToRef(parentInvertNodeLocalMatrix, lightLocalMatrix);\r\n const parentNewScale = TmpVectors.Vector3[0];\r\n const parentNewRotationQuaternion = TmpVectors.Quaternion[0];\r\n const parentNewTranslation = TmpVectors.Vector3[1];\r\n\r\n lightLocalMatrix.decompose(parentNewScale, parentNewRotationQuaternion, parentNewTranslation);\r\n parentNode.scale = parentNewScale.asArray();\r\n parentNode.rotation = parentNewRotationQuaternion.asArray();\r\n parentNode.translation = parentNewTranslation.asArray();\r\n\r\n if (parentNode.extensions == null) {\r\n parentNode.extensions = {};\r\n }\r\n parentNode.extensions[NAME] = lightReference;\r\n\r\n // Do not export the original node\r\n resolve(null);\r\n return;\r\n }\r\n }\r\n\r\n if (node.extensions == null) {\r\n node.extensions = {};\r\n }\r\n\r\n node.extensions[NAME] = lightReference;\r\n }\r\n }\r\n resolve(node);\r\n });\r\n }\r\n}\r\n\r\n_Exporter.RegisterExtension(NAME, (exporter) => new KHR_lights_punctual(exporter));\r\n"]}
|
@@ -62,10 +62,10 @@ export class _GLTFAnimation {
|
|
62
62
|
_GLTFAnimation._CreateBakedAnimation(babylonTransformNode, animation, animationChannelTargetPath, minMaxKeyFrames.min, minMaxKeyFrames.max, animation.framePerSecond, animationSampleRate, inputs, outputs, minMaxKeyFrames, convertToRightHandedSystem, useQuaternion);
|
63
63
|
}
|
64
64
|
else {
|
65
|
-
if (interpolation === "LINEAR" /* LINEAR */ || interpolation === "STEP" /* STEP */) {
|
65
|
+
if (interpolation === "LINEAR" /* AnimationSamplerInterpolation.LINEAR */ || interpolation === "STEP" /* AnimationSamplerInterpolation.STEP */) {
|
66
66
|
_GLTFAnimation._CreateLinearOrStepAnimation(babylonTransformNode, animation, animationChannelTargetPath, frameDelta, inputs, outputs, convertToRightHandedSystem, useQuaternion);
|
67
67
|
}
|
68
|
-
else if (interpolation === "CUBICSPLINE" /* CUBICSPLINE */) {
|
68
|
+
else if (interpolation === "CUBICSPLINE" /* AnimationSamplerInterpolation.CUBICSPLINE */) {
|
69
69
|
_GLTFAnimation._CreateCubicSplineAnimation(babylonTransformNode, animation, animationChannelTargetPath, frameDelta, inputs, outputs, convertToRightHandedSystem, useQuaternion);
|
70
70
|
}
|
71
71
|
else {
|
@@ -87,32 +87,32 @@ export class _GLTFAnimation {
|
|
87
87
|
}
|
88
88
|
static _DeduceAnimationInfo(animation) {
|
89
89
|
let animationChannelTargetPath = null;
|
90
|
-
let dataAccessorType = "VEC3" /* VEC3 */;
|
90
|
+
let dataAccessorType = "VEC3" /* AccessorType.VEC3 */;
|
91
91
|
let useQuaternion = false;
|
92
92
|
const property = animation.targetProperty.split(".");
|
93
93
|
switch (property[0]) {
|
94
94
|
case "scaling": {
|
95
|
-
animationChannelTargetPath = "scale" /* SCALE */;
|
95
|
+
animationChannelTargetPath = "scale" /* AnimationChannelTargetPath.SCALE */;
|
96
96
|
break;
|
97
97
|
}
|
98
98
|
case "position": {
|
99
|
-
animationChannelTargetPath = "translation" /* TRANSLATION */;
|
99
|
+
animationChannelTargetPath = "translation" /* AnimationChannelTargetPath.TRANSLATION */;
|
100
100
|
break;
|
101
101
|
}
|
102
102
|
case "rotation": {
|
103
|
-
dataAccessorType = "VEC4" /* VEC4 */;
|
104
|
-
animationChannelTargetPath = "rotation" /* ROTATION */;
|
103
|
+
dataAccessorType = "VEC4" /* AccessorType.VEC4 */;
|
104
|
+
animationChannelTargetPath = "rotation" /* AnimationChannelTargetPath.ROTATION */;
|
105
105
|
break;
|
106
106
|
}
|
107
107
|
case "rotationQuaternion": {
|
108
|
-
dataAccessorType = "VEC4" /* VEC4 */;
|
108
|
+
dataAccessorType = "VEC4" /* AccessorType.VEC4 */;
|
109
109
|
useQuaternion = true;
|
110
|
-
animationChannelTargetPath = "rotation" /* ROTATION */;
|
110
|
+
animationChannelTargetPath = "rotation" /* AnimationChannelTargetPath.ROTATION */;
|
111
111
|
break;
|
112
112
|
}
|
113
113
|
case "influence": {
|
114
|
-
dataAccessorType = "SCALAR" /* SCALAR */;
|
115
|
-
animationChannelTargetPath = "weights" /* WEIGHTS */;
|
114
|
+
dataAccessorType = "SCALAR" /* AccessorType.SCALAR */;
|
115
|
+
animationChannelTargetPath = "weights" /* AnimationChannelTargetPath.WEIGHTS */;
|
116
116
|
break;
|
117
117
|
}
|
118
118
|
default: {
|
@@ -378,7 +378,7 @@ export class _GLTFAnimation {
|
|
378
378
|
animationData.inputs.forEach(function (input) {
|
379
379
|
binaryWriter.setFloat32(input);
|
380
380
|
});
|
381
|
-
accessor = _GLTFUtilities._CreateAccessor(bufferViews.length - 1, `${name} keyframes`, "SCALAR" /* SCALAR */, 5126 /* FLOAT */, animationData.inputs.length, null, [animationData.inputsMin], [animationData.inputsMax]);
|
381
|
+
accessor = _GLTFUtilities._CreateAccessor(bufferViews.length - 1, `${name} keyframes`, "SCALAR" /* AccessorType.SCALAR */, 5126 /* AccessorComponentType.FLOAT */, animationData.inputs.length, null, [animationData.inputsMin], [animationData.inputsMax]);
|
382
382
|
accessors.push(accessor);
|
383
383
|
keyframeAccessorIndex = accessors.length - 1;
|
384
384
|
// create bufferview and accessor for keyed values.
|
@@ -392,7 +392,7 @@ export class _GLTFAnimation {
|
|
392
392
|
binaryWriter.setFloat32(entry);
|
393
393
|
});
|
394
394
|
});
|
395
|
-
accessor = _GLTFUtilities._CreateAccessor(bufferViews.length - 1, `${name} data`, dataAccessorType, 5126 /* FLOAT */, outputLength, null, null, null);
|
395
|
+
accessor = _GLTFUtilities._CreateAccessor(bufferViews.length - 1, `${name} data`, dataAccessorType, 5126 /* AccessorComponentType.FLOAT */, outputLength, null, null, null);
|
396
396
|
accessors.push(accessor);
|
397
397
|
dataAccessorIndex = accessors.length - 1;
|
398
398
|
// create sampler
|
@@ -500,15 +500,15 @@ export class _GLTFAnimation {
|
|
500
500
|
const value = useQuaternion ? Quaternion.FromArray(basePositionRotationOrScale).normalize() : Vector3.FromArray(basePositionRotationOrScale);
|
501
501
|
switch (componentName) {
|
502
502
|
case "x": {
|
503
|
-
value[componentName] = convertToRightHandedSystem && useQuaternion && animationChannelTargetPath !== "scale" /* SCALE */ ? -factor : factor;
|
503
|
+
value[componentName] = convertToRightHandedSystem && useQuaternion && animationChannelTargetPath !== "scale" /* AnimationChannelTargetPath.SCALE */ ? -factor : factor;
|
504
504
|
break;
|
505
505
|
}
|
506
506
|
case "y": {
|
507
|
-
value[componentName] = convertToRightHandedSystem && useQuaternion && animationChannelTargetPath !== "scale" /* SCALE */ ? -factor : factor;
|
507
|
+
value[componentName] = convertToRightHandedSystem && useQuaternion && animationChannelTargetPath !== "scale" /* AnimationChannelTargetPath.SCALE */ ? -factor : factor;
|
508
508
|
break;
|
509
509
|
}
|
510
510
|
case "z": {
|
511
|
-
value[componentName] = convertToRightHandedSystem && !useQuaternion && animationChannelTargetPath !== "scale" /* SCALE */ ? -factor : factor;
|
511
|
+
value[componentName] = convertToRightHandedSystem && !useQuaternion && animationChannelTargetPath !== "scale" /* AnimationChannelTargetPath.SCALE */ ? -factor : factor;
|
512
512
|
break;
|
513
513
|
}
|
514
514
|
case "w": {
|
@@ -524,14 +524,14 @@ export class _GLTFAnimation {
|
|
524
524
|
static _SetInterpolatedValue(babylonTransformNode, value, time, animation, animationChannelTargetPath, quaternionCache, inputs, outputs, convertToRightHandedSystem, useQuaternion) {
|
525
525
|
let cacheValue;
|
526
526
|
inputs.push(time);
|
527
|
-
if (animationChannelTargetPath === "weights" /* WEIGHTS */) {
|
527
|
+
if (animationChannelTargetPath === "weights" /* AnimationChannelTargetPath.WEIGHTS */) {
|
528
528
|
outputs.push([value]);
|
529
529
|
return;
|
530
530
|
}
|
531
531
|
if (animation.dataType === Animation.ANIMATIONTYPE_FLOAT) {
|
532
532
|
value = this._ConvertFactorToVector3OrQuaternion(value, babylonTransformNode, animation, animationChannelTargetPath, convertToRightHandedSystem, useQuaternion);
|
533
533
|
}
|
534
|
-
if (animationChannelTargetPath === "rotation" /* ROTATION */) {
|
534
|
+
if (animationChannelTargetPath === "rotation" /* AnimationChannelTargetPath.ROTATION */) {
|
535
535
|
if (useQuaternion) {
|
536
536
|
quaternionCache = value;
|
537
537
|
}
|
@@ -550,7 +550,7 @@ export class _GLTFAnimation {
|
|
550
550
|
else {
|
551
551
|
// scaling and position animation
|
552
552
|
cacheValue = value;
|
553
|
-
if (convertToRightHandedSystem && animationChannelTargetPath !== "scale" /* SCALE */) {
|
553
|
+
if (convertToRightHandedSystem && animationChannelTargetPath !== "scale" /* AnimationChannelTargetPath.SCALE */) {
|
554
554
|
_GLTFUtilities._GetRightHandedPositionVector3FromRef(cacheValue);
|
555
555
|
if (!babylonTransformNode.parent) {
|
556
556
|
cacheValue.x *= -1;
|
@@ -591,14 +591,14 @@ export class _GLTFAnimation {
|
|
591
591
|
static _CreateCubicSplineAnimation(babylonTransformNode, animation, animationChannelTargetPath, frameDelta, inputs, outputs, convertToRightHandedSystem, useQuaternion) {
|
592
592
|
animation.getKeys().forEach(function (keyFrame) {
|
593
593
|
inputs.push(keyFrame.frame / animation.framePerSecond); // keyframes in seconds.
|
594
|
-
_GLTFAnimation._AddSplineTangent(babylonTransformNode, _TangentType.INTANGENT, outputs, animationChannelTargetPath, "CUBICSPLINE" /* CUBICSPLINE */, keyFrame, frameDelta, useQuaternion, convertToRightHandedSystem);
|
594
|
+
_GLTFAnimation._AddSplineTangent(babylonTransformNode, _TangentType.INTANGENT, outputs, animationChannelTargetPath, "CUBICSPLINE" /* AnimationSamplerInterpolation.CUBICSPLINE */, keyFrame, frameDelta, useQuaternion, convertToRightHandedSystem);
|
595
595
|
_GLTFAnimation._AddKeyframeValue(keyFrame, animation, outputs, animationChannelTargetPath, babylonTransformNode, convertToRightHandedSystem, useQuaternion);
|
596
|
-
_GLTFAnimation._AddSplineTangent(babylonTransformNode, _TangentType.OUTTANGENT, outputs, animationChannelTargetPath, "CUBICSPLINE" /* CUBICSPLINE */, keyFrame, frameDelta, useQuaternion, convertToRightHandedSystem);
|
596
|
+
_GLTFAnimation._AddSplineTangent(babylonTransformNode, _TangentType.OUTTANGENT, outputs, animationChannelTargetPath, "CUBICSPLINE" /* AnimationSamplerInterpolation.CUBICSPLINE */, keyFrame, frameDelta, useQuaternion, convertToRightHandedSystem);
|
597
597
|
});
|
598
598
|
}
|
599
599
|
static _GetBasePositionRotationOrScale(babylonTransformNode, animationChannelTargetPath, convertToRightHandedSystem, useQuaternion) {
|
600
600
|
let basePositionRotationOrScale;
|
601
|
-
if (animationChannelTargetPath === "rotation" /* ROTATION */) {
|
601
|
+
if (animationChannelTargetPath === "rotation" /* AnimationChannelTargetPath.ROTATION */) {
|
602
602
|
if (useQuaternion) {
|
603
603
|
const q = babylonTransformNode.rotationQuaternion;
|
604
604
|
basePositionRotationOrScale = (q !== null && q !== void 0 ? q : Quaternion.Identity()).asArray();
|
@@ -615,7 +615,7 @@ export class _GLTFAnimation {
|
|
615
615
|
_GLTFUtilities._GetRightHandedNormalArray3FromRef(basePositionRotationOrScale);
|
616
616
|
}
|
617
617
|
}
|
618
|
-
else if (animationChannelTargetPath === "translation" /* TRANSLATION */) {
|
618
|
+
else if (animationChannelTargetPath === "translation" /* AnimationChannelTargetPath.TRANSLATION */) {
|
619
619
|
const p = babylonTransformNode.position;
|
620
620
|
basePositionRotationOrScale = (p !== null && p !== void 0 ? p : Vector3.Zero()).asArray();
|
621
621
|
if (convertToRightHandedSystem) {
|
@@ -645,7 +645,7 @@ export class _GLTFAnimation {
|
|
645
645
|
const animationType = animation.dataType;
|
646
646
|
if (animationType === Animation.ANIMATIONTYPE_VECTOR3) {
|
647
647
|
value = keyFrame.value.asArray();
|
648
|
-
if (animationChannelTargetPath === "rotation" /* ROTATION */) {
|
648
|
+
if (animationChannelTargetPath === "rotation" /* AnimationChannelTargetPath.ROTATION */) {
|
649
649
|
const array = Vector3.FromArray(value);
|
650
650
|
let rotationQuaternion = Quaternion.RotationYawPitchRoll(array.y, array.x, array.z);
|
651
651
|
if (convertToRightHandedSystem) {
|
@@ -656,7 +656,7 @@ export class _GLTFAnimation {
|
|
656
656
|
}
|
657
657
|
value = rotationQuaternion.asArray();
|
658
658
|
}
|
659
|
-
else if (animationChannelTargetPath === "translation" /* TRANSLATION */) {
|
659
|
+
else if (animationChannelTargetPath === "translation" /* AnimationChannelTargetPath.TRANSLATION */) {
|
660
660
|
if (convertToRightHandedSystem) {
|
661
661
|
_GLTFUtilities._GetRightHandedNormalArray3FromRef(value);
|
662
662
|
if (!babylonTransformNode.parent) {
|
@@ -668,14 +668,14 @@ export class _GLTFAnimation {
|
|
668
668
|
outputs.push(value); // scale vector.
|
669
669
|
}
|
670
670
|
else if (animationType === Animation.ANIMATIONTYPE_FLOAT) {
|
671
|
-
if (animationChannelTargetPath === "weights" /* WEIGHTS */) {
|
671
|
+
if (animationChannelTargetPath === "weights" /* AnimationChannelTargetPath.WEIGHTS */) {
|
672
672
|
outputs.push([keyFrame.value]);
|
673
673
|
}
|
674
674
|
else {
|
675
675
|
// handles single component x, y, z or w component animation by using a base property and animating over a component.
|
676
676
|
newPositionRotationOrScale = this._ConvertFactorToVector3OrQuaternion(keyFrame.value, babylonTransformNode, animation, animationChannelTargetPath, convertToRightHandedSystem, useQuaternion);
|
677
677
|
if (newPositionRotationOrScale) {
|
678
|
-
if (animationChannelTargetPath === "rotation" /* ROTATION */) {
|
678
|
+
if (animationChannelTargetPath === "rotation" /* AnimationChannelTargetPath.ROTATION */) {
|
679
679
|
let posRotScale = useQuaternion
|
680
680
|
? newPositionRotationOrScale
|
681
681
|
: Quaternion.RotationYawPitchRoll(newPositionRotationOrScale.y, newPositionRotationOrScale.x, newPositionRotationOrScale.z).normalize();
|
@@ -687,7 +687,7 @@ export class _GLTFAnimation {
|
|
687
687
|
}
|
688
688
|
outputs.push(posRotScale.asArray());
|
689
689
|
}
|
690
|
-
else if (animationChannelTargetPath === "translation" /* TRANSLATION */) {
|
690
|
+
else if (animationChannelTargetPath === "translation" /* AnimationChannelTargetPath.TRANSLATION */) {
|
691
691
|
if (convertToRightHandedSystem) {
|
692
692
|
_GLTFUtilities._GetRightHandedNormalVector3FromRef(newPositionRotationOrScale);
|
693
693
|
if (!babylonTransformNode.parent) {
|
@@ -724,44 +724,44 @@ export class _GLTFAnimation {
|
|
724
724
|
let interpolationType;
|
725
725
|
let shouldBakeAnimation = false;
|
726
726
|
let key;
|
727
|
-
if (animationChannelTargetPath === "rotation" /* ROTATION */ && !useQuaternion) {
|
728
|
-
return { interpolationType: "LINEAR" /* LINEAR */, shouldBakeAnimation: true };
|
727
|
+
if (animationChannelTargetPath === "rotation" /* AnimationChannelTargetPath.ROTATION */ && !useQuaternion) {
|
728
|
+
return { interpolationType: "LINEAR" /* AnimationSamplerInterpolation.LINEAR */, shouldBakeAnimation: true };
|
729
729
|
}
|
730
730
|
for (let i = 0, length = keyFrames.length; i < length; ++i) {
|
731
731
|
key = keyFrames[i];
|
732
732
|
if (key.inTangent || key.outTangent) {
|
733
733
|
if (interpolationType) {
|
734
|
-
if (interpolationType !== "CUBICSPLINE" /* CUBICSPLINE */) {
|
735
|
-
interpolationType = "LINEAR" /* LINEAR */;
|
734
|
+
if (interpolationType !== "CUBICSPLINE" /* AnimationSamplerInterpolation.CUBICSPLINE */) {
|
735
|
+
interpolationType = "LINEAR" /* AnimationSamplerInterpolation.LINEAR */;
|
736
736
|
shouldBakeAnimation = true;
|
737
737
|
break;
|
738
738
|
}
|
739
739
|
}
|
740
740
|
else {
|
741
|
-
interpolationType = "CUBICSPLINE" /* CUBICSPLINE */;
|
741
|
+
interpolationType = "CUBICSPLINE" /* AnimationSamplerInterpolation.CUBICSPLINE */;
|
742
742
|
}
|
743
743
|
}
|
744
744
|
else {
|
745
745
|
if (interpolationType) {
|
746
|
-
if (interpolationType === "CUBICSPLINE" /* CUBICSPLINE */ ||
|
747
|
-
(key.interpolation && key.interpolation === AnimationKeyInterpolation.STEP && interpolationType !== "STEP" /* STEP */)) {
|
748
|
-
interpolationType = "LINEAR" /* LINEAR */;
|
746
|
+
if (interpolationType === "CUBICSPLINE" /* AnimationSamplerInterpolation.CUBICSPLINE */ ||
|
747
|
+
(key.interpolation && key.interpolation === AnimationKeyInterpolation.STEP && interpolationType !== "STEP" /* AnimationSamplerInterpolation.STEP */)) {
|
748
|
+
interpolationType = "LINEAR" /* AnimationSamplerInterpolation.LINEAR */;
|
749
749
|
shouldBakeAnimation = true;
|
750
750
|
break;
|
751
751
|
}
|
752
752
|
}
|
753
753
|
else {
|
754
754
|
if (key.interpolation && key.interpolation === AnimationKeyInterpolation.STEP) {
|
755
|
-
interpolationType = "STEP" /* STEP */;
|
755
|
+
interpolationType = "STEP" /* AnimationSamplerInterpolation.STEP */;
|
756
756
|
}
|
757
757
|
else {
|
758
|
-
interpolationType = "LINEAR" /* LINEAR */;
|
758
|
+
interpolationType = "LINEAR" /* AnimationSamplerInterpolation.LINEAR */;
|
759
759
|
}
|
760
760
|
}
|
761
761
|
}
|
762
762
|
}
|
763
763
|
if (!interpolationType) {
|
764
|
-
interpolationType = "LINEAR" /* LINEAR */;
|
764
|
+
interpolationType = "LINEAR" /* AnimationSamplerInterpolation.LINEAR */;
|
765
765
|
}
|
766
766
|
return { interpolationType: interpolationType, shouldBakeAnimation: shouldBakeAnimation };
|
767
767
|
}
|
@@ -781,8 +781,8 @@ export class _GLTFAnimation {
|
|
781
781
|
static _AddSplineTangent(babylonTransformNode, tangentType, outputs, animationChannelTargetPath, interpolation, keyFrame, frameDelta, useQuaternion, convertToRightHandedSystem) {
|
782
782
|
let tangent;
|
783
783
|
const tangentValue = tangentType === _TangentType.INTANGENT ? keyFrame.inTangent : keyFrame.outTangent;
|
784
|
-
if (interpolation === "CUBICSPLINE" /* CUBICSPLINE */) {
|
785
|
-
if (animationChannelTargetPath === "rotation" /* ROTATION */) {
|
784
|
+
if (interpolation === "CUBICSPLINE" /* AnimationSamplerInterpolation.CUBICSPLINE */) {
|
785
|
+
if (animationChannelTargetPath === "rotation" /* AnimationChannelTargetPath.ROTATION */) {
|
786
786
|
if (tangentValue) {
|
787
787
|
if (useQuaternion) {
|
788
788
|
tangent = tangentValue.asArray();
|
@@ -802,7 +802,7 @@ export class _GLTFAnimation {
|
|
802
802
|
tangent = [0, 0, 0, 0];
|
803
803
|
}
|
804
804
|
}
|
805
|
-
else if (animationChannelTargetPath === "weights" /* WEIGHTS */) {
|
805
|
+
else if (animationChannelTargetPath === "weights" /* AnimationChannelTargetPath.WEIGHTS */) {
|
806
806
|
if (tangentValue) {
|
807
807
|
tangent = [tangentValue];
|
808
808
|
}
|
@@ -814,7 +814,7 @@ export class _GLTFAnimation {
|
|
814
814
|
if (tangentValue) {
|
815
815
|
tangent = tangentValue.asArray();
|
816
816
|
if (convertToRightHandedSystem) {
|
817
|
-
if (animationChannelTargetPath === "translation" /* TRANSLATION */) {
|
817
|
+
if (animationChannelTargetPath === "translation" /* AnimationChannelTargetPath.TRANSLATION */) {
|
818
818
|
_GLTFUtilities._GetRightHandedPositionArray3FromRef(tangent);
|
819
819
|
if (!babylonTransformNode.parent) {
|
820
820
|
tangent[0] *= -1; // x
|