@babylonjs/serializers 6.6.1 → 6.8.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.d.ts +2 -2
- package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_lights_punctual.d.ts +1 -1
- package/glTF/2.0/Extensions/KHR_lights_punctual.js +48 -72
- package/glTF/2.0/Extensions/KHR_lights_punctual.js.map +1 -1
- package/glTF/2.0/glTFAnimation.d.ts +4 -16
- package/glTF/2.0/glTFAnimation.js +38 -132
- package/glTF/2.0/glTFAnimation.js.map +1 -1
- package/glTF/2.0/glTFExporter.d.ts +6 -50
- package/glTF/2.0/glTFExporter.js +135 -212
- package/glTF/2.0/glTFExporter.js.map +1 -1
- package/glTF/2.0/glTFExporterExtension.d.ts +2 -2
- package/glTF/2.0/glTFExporterExtension.js.map +1 -1
- package/glTF/2.0/glTFSerializer.d.ts +9 -4
- package/glTF/2.0/glTFSerializer.js.map +1 -1
- package/glTF/2.0/glTFUtilities.d.ts +2 -56
- package/glTF/2.0/glTFUtilities.js +1 -81
- package/glTF/2.0/glTFUtilities.js.map +1 -1
- package/package.json +3 -3
@@ -21,8 +21,8 @@ export declare class EXT_mesh_gpu_instancing implements IGLTFExporterExtensionV2
|
|
21
21
|
dispose(): void;
|
22
22
|
/** @internal */
|
23
23
|
get wasUsed(): boolean;
|
24
|
-
postExportNodeAsync
|
24
|
+
postExportNodeAsync(context: string, node: Nullable<INode>, babylonNode: Node, nodeMap: {
|
25
25
|
[key: number]: number;
|
26
|
-
}, binaryWriter
|
26
|
+
}, binaryWriter: _BinaryWriter): Promise<Nullable<INode>>;
|
27
27
|
private _buildAccessor;
|
28
28
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"EXT_mesh_gpu_instancing.js","sourceRoot":"","sources":["../../../../../../lts/serializers/generated/glTF/2.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AAE,aAAa,yCAA8B,IAAI,aAAa,0CAA+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;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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AM,EAAE,CAAC,EAAE,UAAU,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,CAAC,MAAM,GAAG,YAAY,CAAC,iBAAiB,CAAC,aAAa,CAAC,EAAE,CAAC;QAC3I,MAAM,eAAe,GAAG,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,yCAA8B,IAAI,aAAa,0CAA+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"]}
|
@@ -34,7 +34,7 @@ export declare class KHR_lights_punctual implements IGLTFExporterExtensionV2 {
|
|
34
34
|
* @param nodeMap Node mapping of unique id to glTF node index
|
35
35
|
* @returns nullable INode promise
|
36
36
|
*/
|
37
|
-
postExportNodeAsync(context: string, node: Nullable<INode>, babylonNode: Node, nodeMap
|
37
|
+
postExportNodeAsync(context: string, node: Nullable<INode>, babylonNode: Node, nodeMap: {
|
38
38
|
[key: number]: number;
|
39
39
|
}): Promise<Nullable<INode>>;
|
40
40
|
}
|
@@ -1,11 +1,9 @@
|
|
1
1
|
import { Vector3, Quaternion, TmpVectors, Matrix } from "@babylonjs/core/Maths/math.vector.js";
|
2
2
|
import { Color3 } from "@babylonjs/core/Maths/math.color.js";
|
3
3
|
import { Light } from "@babylonjs/core/Lights/light.js";
|
4
|
-
import { DirectionalLight } from "@babylonjs/core/Lights/directionalLight.js";
|
5
4
|
import { ShadowLight } from "@babylonjs/core/Lights/shadowLight.js";
|
6
5
|
import { _Exporter } from "../glTFExporter.js";
|
7
6
|
import { Logger } from "@babylonjs/core/Misc/logger.js";
|
8
|
-
import { _GLTFUtilities } from "../glTFUtilities.js";
|
9
7
|
const NAME = "KHR_lights_punctual";
|
10
8
|
/**
|
11
9
|
* [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_lights_punctual/README.md)
|
@@ -47,57 +45,48 @@ export class KHR_lights_punctual {
|
|
47
45
|
postExportNodeAsync(context, node, babylonNode, nodeMap) {
|
48
46
|
return new Promise((resolve) => {
|
49
47
|
if (node && babylonNode instanceof ShadowLight) {
|
50
|
-
const babylonLight = babylonNode;
|
51
48
|
let light;
|
52
|
-
const lightType =
|
49
|
+
const lightType = babylonNode.getTypeID() == Light.LIGHTTYPEID_POINTLIGHT
|
53
50
|
? "point" /* KHRLightsPunctual_LightType.POINT */
|
54
|
-
:
|
51
|
+
: babylonNode.getTypeID() == Light.LIGHTTYPEID_DIRECTIONALLIGHT
|
55
52
|
? "directional" /* KHRLightsPunctual_LightType.DIRECTIONAL */
|
56
|
-
:
|
53
|
+
: babylonNode.getTypeID() == Light.LIGHTTYPEID_SPOTLIGHT
|
57
54
|
? "spot" /* KHRLightsPunctual_LightType.SPOT */
|
58
55
|
: null;
|
59
56
|
if (lightType == null) {
|
60
|
-
Logger.Warn(`${context}: Light ${
|
57
|
+
Logger.Warn(`${context}: Light ${babylonNode.name} is not supported in ${NAME}`);
|
61
58
|
}
|
62
59
|
else {
|
63
|
-
|
64
|
-
|
65
|
-
if (!lightPosition.equals(Vector3.Zero())) {
|
66
|
-
if (convertToRightHandedSystem) {
|
67
|
-
_GLTFUtilities._GetRightHandedPositionVector3FromRef(lightPosition);
|
68
|
-
}
|
69
|
-
node.translation = lightPosition.asArray();
|
60
|
+
if (!babylonNode.position.equalsToFloats(0, 0, 0)) {
|
61
|
+
node.translation = babylonNode.position.asArray();
|
70
62
|
}
|
71
63
|
if (lightType !== "point" /* KHRLightsPunctual_LightType.POINT */) {
|
72
|
-
const localAxis =
|
73
|
-
const yaw = -Math.atan2(localAxis.z
|
64
|
+
const localAxis = babylonNode.direction;
|
65
|
+
const yaw = -Math.atan2(localAxis.z, localAxis.x) + Math.PI / 2;
|
74
66
|
const len = Math.sqrt(localAxis.x * localAxis.x + localAxis.z * localAxis.z);
|
75
67
|
const pitch = -Math.atan2(localAxis.y, len);
|
76
|
-
const lightRotationQuaternion = Quaternion.RotationYawPitchRoll(yaw, pitch, 0);
|
77
|
-
if (
|
78
|
-
_GLTFUtilities._GetRightHandedQuaternionFromRef(lightRotationQuaternion);
|
79
|
-
}
|
80
|
-
if (!lightRotationQuaternion.equals(Quaternion.Identity())) {
|
68
|
+
const lightRotationQuaternion = Quaternion.RotationYawPitchRoll(yaw + Math.PI, pitch, 0);
|
69
|
+
if (!Quaternion.IsIdentity(lightRotationQuaternion)) {
|
81
70
|
node.rotation = lightRotationQuaternion.asArray();
|
82
71
|
}
|
83
72
|
}
|
84
|
-
if (
|
85
|
-
Logger.Warn(`${context}: Light falloff for ${
|
73
|
+
if (babylonNode.falloffType !== Light.FALLOFF_GLTF) {
|
74
|
+
Logger.Warn(`${context}: Light falloff for ${babylonNode.name} does not match the ${NAME} specification!`);
|
86
75
|
}
|
87
76
|
light = {
|
88
77
|
type: lightType,
|
89
78
|
};
|
90
|
-
if (!
|
91
|
-
light.color =
|
79
|
+
if (!babylonNode.diffuse.equals(Color3.White())) {
|
80
|
+
light.color = babylonNode.diffuse.asArray();
|
92
81
|
}
|
93
|
-
if (
|
94
|
-
light.intensity =
|
82
|
+
if (babylonNode.intensity !== 1.0) {
|
83
|
+
light.intensity = babylonNode.intensity;
|
95
84
|
}
|
96
|
-
if (
|
97
|
-
light.range =
|
85
|
+
if (babylonNode.range !== Number.MAX_VALUE) {
|
86
|
+
light.range = babylonNode.range;
|
98
87
|
}
|
99
88
|
if (lightType === "spot" /* KHRLightsPunctual_LightType.SPOT */) {
|
100
|
-
const babylonSpotLight =
|
89
|
+
const babylonSpotLight = babylonNode;
|
101
90
|
if (babylonSpotLight.angle !== Math.PI / 2.0) {
|
102
91
|
if (light.spot == null) {
|
103
92
|
light.spot = {};
|
@@ -111,11 +100,9 @@ export class KHR_lights_punctual {
|
|
111
100
|
light.spot.innerConeAngle = babylonSpotLight.innerAngle / 2.0;
|
112
101
|
}
|
113
102
|
}
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
};
|
118
|
-
}
|
103
|
+
this._lights || (this._lights = {
|
104
|
+
lights: [],
|
105
|
+
});
|
119
106
|
this._lights.lights.push(light);
|
120
107
|
const lightReference = {
|
121
108
|
light: this._lights.lights.length - 1,
|
@@ -125,52 +112,41 @@ export class KHR_lights_punctual {
|
|
125
112
|
if (parentBabylonNode && parentBabylonNode.getChildren().length == 1) {
|
126
113
|
const parentNode = this._exporter._nodes[nodeMap[parentBabylonNode.uniqueId]];
|
127
114
|
if (parentNode) {
|
128
|
-
const
|
129
|
-
const
|
130
|
-
const
|
131
|
-
|
132
|
-
|
133
|
-
const
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
// Undo directional light positional offset
|
143
|
-
if (babylonLight instanceof DirectionalLight) {
|
144
|
-
nodeLocalTranslation.subtractInPlace(this._exporter._babylonScene.useRightHandedSystem
|
145
|
-
? babylonLight.direction
|
146
|
-
: _GLTFUtilities._GetRightHandedPositionVector3(babylonLight.direction));
|
115
|
+
const parentTranslation = Vector3.FromArrayToRef(parentNode.translation || [0, 0, 0], 0, TmpVectors.Vector3[0]);
|
116
|
+
const parentRotation = Quaternion.FromArrayToRef(parentNode.rotation || [0, 0, 0, 1], 0, TmpVectors.Quaternion[0]);
|
117
|
+
const parentScale = Vector3.FromArrayToRef(parentNode.scale || [1, 1, 1], 0, TmpVectors.Vector3[1]);
|
118
|
+
const parentMatrix = Matrix.ComposeToRef(parentScale, parentRotation, parentTranslation, TmpVectors.Matrix[0]);
|
119
|
+
const translation = Vector3.FromArrayToRef(node.translation || [0, 0, 0], 0, TmpVectors.Vector3[2]);
|
120
|
+
const rotation = Quaternion.FromArrayToRef(node.rotation || [0, 0, 0, 1], 0, TmpVectors.Quaternion[1]);
|
121
|
+
const matrix = Matrix.ComposeToRef(Vector3.OneReadOnly, rotation, translation, TmpVectors.Matrix[1]);
|
122
|
+
parentMatrix.multiplyToRef(matrix, matrix);
|
123
|
+
matrix.decompose(parentScale, parentRotation, parentTranslation);
|
124
|
+
if (parentTranslation.equalsToFloats(0, 0, 0)) {
|
125
|
+
delete parentNode.translation;
|
126
|
+
}
|
127
|
+
else {
|
128
|
+
parentNode.translation = parentTranslation.asArray();
|
147
129
|
}
|
148
|
-
|
149
|
-
|
150
|
-
nodeLocalRotation.multiplyInPlace(new Quaternion(node.rotation[0], node.rotation[1], node.rotation[2], node.rotation[3]));
|
130
|
+
if (Quaternion.IsIdentity(parentRotation)) {
|
131
|
+
delete parentNode.rotation;
|
151
132
|
}
|
152
|
-
|
153
|
-
|
154
|
-
lightLocalMatrix.multiplyToRef(parentInvertNodeLocalMatrix, lightLocalMatrix);
|
155
|
-
const parentNewScale = TmpVectors.Vector3[0];
|
156
|
-
const parentNewRotationQuaternion = TmpVectors.Quaternion[0];
|
157
|
-
const parentNewTranslation = TmpVectors.Vector3[1];
|
158
|
-
lightLocalMatrix.decompose(parentNewScale, parentNewRotationQuaternion, parentNewTranslation);
|
159
|
-
parentNode.scale = parentNewScale.asArray();
|
160
|
-
parentNode.rotation = parentNewRotationQuaternion.asArray();
|
161
|
-
parentNode.translation = parentNewTranslation.asArray();
|
162
|
-
if (parentNode.extensions == null) {
|
163
|
-
parentNode.extensions = {};
|
133
|
+
else {
|
134
|
+
parentNode.rotation = parentRotation.asArray();
|
164
135
|
}
|
136
|
+
if (parentScale.equalsToFloats(1, 1, 1)) {
|
137
|
+
delete parentNode.scale;
|
138
|
+
}
|
139
|
+
else {
|
140
|
+
parentNode.scale = parentScale.asArray();
|
141
|
+
}
|
142
|
+
parentNode.extensions || (parentNode.extensions = {});
|
165
143
|
parentNode.extensions[NAME] = lightReference;
|
166
144
|
// Do not export the original node
|
167
145
|
resolve(null);
|
168
146
|
return;
|
169
147
|
}
|
170
148
|
}
|
171
|
-
|
172
|
-
node.extensions = {};
|
173
|
-
}
|
149
|
+
node.extensions || (node.extensions = {});
|
174
150
|
node.extensions[NAME] = lightReference;
|
175
151
|
}
|
176
152
|
}
|
@@ -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,IAA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AW,GAAG,oBAAoB,CAAC,OAAO,EAAE,CAAC;4BAExD,IAAI,UAAU,CAAC,UAAU,IAAI,IAAI,EAAE;gCAC/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"]}
|
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,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U,GAAK,EAAE,EAAC;4BAC7B,UAAU,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,cAAc,CAAC;4BAE7C,kCAAkC;4BAClC,OAAO,CAAC,IAAI,CAAC,CAAC;4BACd,OAAO;yBACV;qBACJ;oBAED,IAAI,CAAC,UAAU,KAAf,IAAI,CAAC,UAAU,GAAK,EAAE,EAAC;oBACvB,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 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 let light: IKHRLightsPunctual_Light;\r\n\r\n const lightType =\r\n babylonNode.getTypeID() == Light.LIGHTTYPEID_POINTLIGHT\r\n ? KHRLightsPunctual_LightType.POINT\r\n : babylonNode.getTypeID() == Light.LIGHTTYPEID_DIRECTIONALLIGHT\r\n ? KHRLightsPunctual_LightType.DIRECTIONAL\r\n : babylonNode.getTypeID() == Light.LIGHTTYPEID_SPOTLIGHT\r\n ? KHRLightsPunctual_LightType.SPOT\r\n : null;\r\n if (lightType == null) {\r\n Logger.Warn(`${context}: Light ${babylonNode.name} is not supported in ${NAME}`);\r\n } else {\r\n if (!babylonNode.position.equalsToFloats(0, 0, 0)) {\r\n node.translation = babylonNode.position.asArray();\r\n }\r\n if (lightType !== KHRLightsPunctual_LightType.POINT) {\r\n const localAxis = babylonNode.direction;\r\n const yaw = -Math.atan2(localAxis.z, 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 + Math.PI, pitch, 0);\r\n if (!Quaternion.IsIdentity(lightRotationQuaternion)) {\r\n node.rotation = lightRotationQuaternion.asArray();\r\n }\r\n }\r\n\r\n if (babylonNode.falloffType !== Light.FALLOFF_GLTF) {\r\n Logger.Warn(`${context}: Light falloff for ${babylonNode.name} does not match the ${NAME} specification!`);\r\n }\r\n light = {\r\n type: lightType,\r\n };\r\n if (!babylonNode.diffuse.equals(Color3.White())) {\r\n light.color = babylonNode.diffuse.asArray();\r\n }\r\n if (babylonNode.intensity !== 1.0) {\r\n light.intensity = babylonNode.intensity;\r\n }\r\n if (babylonNode.range !== Number.MAX_VALUE) {\r\n light.range = babylonNode.range;\r\n }\r\n\r\n if (lightType === KHRLightsPunctual_LightType.SPOT) {\r\n const babylonSpotLight = babylonNode 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 this._lights ||= {\r\n lights: [],\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 parentTranslation = Vector3.FromArrayToRef(parentNode.translation || [0, 0, 0], 0, TmpVectors.Vector3[0]);\r\n const parentRotation = Quaternion.FromArrayToRef(parentNode.rotation || [0, 0, 0, 1], 0, TmpVectors.Quaternion[0]);\r\n const parentScale = Vector3.FromArrayToRef(parentNode.scale || [1, 1, 1], 0, TmpVectors.Vector3[1]);\r\n const parentMatrix = Matrix.ComposeToRef(parentScale, parentRotation, parentTranslation, TmpVectors.Matrix[0]);\r\n\r\n const translation = Vector3.FromArrayToRef(node.translation || [0, 0, 0], 0, TmpVectors.Vector3[2]);\r\n const rotation = Quaternion.FromArrayToRef(node.rotation || [0, 0, 0, 1], 0, TmpVectors.Quaternion[1]);\r\n const matrix = Matrix.ComposeToRef(Vector3.OneReadOnly, rotation, translation, TmpVectors.Matrix[1]);\r\n\r\n parentMatrix.multiplyToRef(matrix, matrix);\r\n matrix.decompose(parentScale, parentRotation, parentTranslation);\r\n\r\n if (parentTranslation.equalsToFloats(0, 0, 0)) {\r\n delete parentNode.translation;\r\n } else {\r\n parentNode.translation = parentTranslation.asArray();\r\n }\r\n\r\n if (Quaternion.IsIdentity(parentRotation)) {\r\n delete parentNode.rotation;\r\n } else {\r\n parentNode.rotation = parentRotation.asArray();\r\n }\r\n\r\n if (parentScale.equalsToFloats(1, 1, 1)) {\r\n delete parentNode.scale;\r\n } else {\r\n parentNode.scale = parentScale.asArray();\r\n }\r\n\r\n parentNode.extensions ||= {};\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 node.extensions ||= {};\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"]}
|
@@ -66,11 +66,10 @@ export declare class _GLTFAnimation {
|
|
66
66
|
* @param babylonTransformNode - BabylonJS mesh.
|
67
67
|
* @param animation - animation.
|
68
68
|
* @param animationChannelTargetPath - The target animation channel.
|
69
|
-
* @param convertToRightHandedSystem - Specifies if the values should be converted to right-handed.
|
70
69
|
* @param useQuaternion - Specifies if quaternions are used.
|
71
70
|
* @returns nullable IAnimationData
|
72
71
|
*/
|
73
|
-
static _CreateNodeAnimation(babylonTransformNode: Node, animation: Animation, animationChannelTargetPath: AnimationChannelTargetPath,
|
72
|
+
static _CreateNodeAnimation(babylonTransformNode: Node, animation: Animation, animationChannelTargetPath: AnimationChannelTargetPath, useQuaternion: boolean, animationSampleRate: number): Nullable<_IAnimationData>;
|
74
73
|
private static _DeduceAnimationInfo;
|
75
74
|
/**
|
76
75
|
* @ignore
|
@@ -83,12 +82,11 @@ export declare class _GLTFAnimation {
|
|
83
82
|
* @param binaryWriter
|
84
83
|
* @param bufferViews
|
85
84
|
* @param accessors
|
86
|
-
* @param convertToRightHandedSystem
|
87
85
|
* @param animationSampleRate
|
88
86
|
*/
|
89
87
|
static _CreateNodeAnimationFromNodeAnimations(babylonNode: Node, runtimeGLTFAnimation: IAnimation, idleGLTFAnimations: IAnimation[], nodeMap: {
|
90
88
|
[key: number]: number;
|
91
|
-
}, nodes: INode[], binaryWriter: _BinaryWriter, bufferViews: IBufferView[], accessors: IAccessor[],
|
89
|
+
}, nodes: INode[], binaryWriter: _BinaryWriter, bufferViews: IBufferView[], accessors: IAccessor[], animationSampleRate: number, shouldExportAnimation?: (animation: Animation) => boolean): void;
|
92
90
|
/**
|
93
91
|
* @ignore
|
94
92
|
* Create individual morph animations from the mesh's morph target animation tracks
|
@@ -100,12 +98,11 @@ export declare class _GLTFAnimation {
|
|
100
98
|
* @param binaryWriter
|
101
99
|
* @param bufferViews
|
102
100
|
* @param accessors
|
103
|
-
* @param convertToRightHandedSystem
|
104
101
|
* @param animationSampleRate
|
105
102
|
*/
|
106
103
|
static _CreateMorphTargetAnimationFromMorphTargetAnimations(babylonNode: Node, runtimeGLTFAnimation: IAnimation, idleGLTFAnimations: IAnimation[], nodeMap: {
|
107
104
|
[key: number]: number;
|
108
|
-
}, nodes: INode[], binaryWriter: _BinaryWriter, bufferViews: IBufferView[], accessors: IAccessor[],
|
105
|
+
}, nodes: INode[], binaryWriter: _BinaryWriter, bufferViews: IBufferView[], accessors: IAccessor[], animationSampleRate: number, shouldExportAnimation?: (animation: Animation) => boolean): void;
|
109
106
|
/**
|
110
107
|
* @ignore
|
111
108
|
* Create node and morph animations from the animation groups
|
@@ -116,14 +113,11 @@ export declare class _GLTFAnimation {
|
|
116
113
|
* @param binaryWriter
|
117
114
|
* @param bufferViews
|
118
115
|
* @param accessors
|
119
|
-
* @param convertToRightHandedSystemMap
|
120
116
|
* @param animationSampleRate
|
121
117
|
*/
|
122
118
|
static _CreateNodeAndMorphAnimationFromAnimationGroups(babylonScene: Scene, glTFAnimations: IAnimation[], nodeMap: {
|
123
119
|
[key: number]: number;
|
124
|
-
},
|
125
|
-
[nodeId: number]: boolean;
|
126
|
-
}, animationSampleRate: number, shouldExportAnimation?: (animation: Animation) => boolean): void;
|
120
|
+
}, binaryWriter: _BinaryWriter, bufferViews: IBufferView[], accessors: IAccessor[], animationSampleRate: number, shouldExportAnimation?: (animation: Animation) => boolean): void;
|
127
121
|
private static _AddAnimation;
|
128
122
|
/**
|
129
123
|
* Create a baked animation
|
@@ -139,7 +133,6 @@ export declare class _GLTFAnimation {
|
|
139
133
|
* @param minMaxFrames
|
140
134
|
* @param minMaxFrames.min
|
141
135
|
* @param minMaxFrames.max
|
142
|
-
* @param convertToRightHandedSystem converts the values to right-handed
|
143
136
|
* @param useQuaternion specifies if quaternions should be used
|
144
137
|
*/
|
145
138
|
private static _CreateBakedAnimation;
|
@@ -150,10 +143,8 @@ export declare class _GLTFAnimation {
|
|
150
143
|
* @param babylonTransformNode BabylonJS mesh
|
151
144
|
* @param animation BabylonJS animation
|
152
145
|
* @param animationChannelTargetPath The target animation channel
|
153
|
-
* @param frameDelta The difference between the last and first frame of the animation
|
154
146
|
* @param inputs Array to store the key frame times
|
155
147
|
* @param outputs Array to store the key frame data
|
156
|
-
* @param convertToRightHandedSystem Specifies if the position data should be converted to right handed
|
157
148
|
* @param useQuaternion Specifies if quaternions are used in the animation
|
158
149
|
*/
|
159
150
|
private static _CreateLinearOrStepAnimation;
|
@@ -165,7 +156,6 @@ export declare class _GLTFAnimation {
|
|
165
156
|
* @param frameDelta The difference between the last and first frame of the animation
|
166
157
|
* @param inputs Array to store the key frame times
|
167
158
|
* @param outputs Array to store the key frame data
|
168
|
-
* @param convertToRightHandedSystem Specifies if the position data should be converted to right handed
|
169
159
|
* @param useQuaternion Specifies if quaternions are used in the animation
|
170
160
|
*/
|
171
161
|
private static _CreateCubicSplineAnimation;
|
@@ -177,7 +167,6 @@ export declare class _GLTFAnimation {
|
|
177
167
|
* @param outputs
|
178
168
|
* @param animationChannelTargetPath
|
179
169
|
* @param babylonTransformNode
|
180
|
-
* @param convertToRightHandedSystem
|
181
170
|
* @param useQuaternion
|
182
171
|
*/
|
183
172
|
private static _AddKeyframeValue;
|
@@ -199,7 +188,6 @@ export declare class _GLTFAnimation {
|
|
199
188
|
* @param keyFrame The key frame with the animation data
|
200
189
|
* @param frameDelta Time difference between two frames used to scale the tangent by the frame delta
|
201
190
|
* @param useQuaternion Specifies if quaternions are used
|
202
|
-
* @param convertToRightHandedSystem Specifies if the values should be converted to right-handed
|
203
191
|
*/
|
204
192
|
private static _AddSplineTangent;
|
205
193
|
/**
|