@babylonjs/serializers 8.11.0 → 8.13.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.
@@ -83,17 +83,14 @@ export class KHR_lights_punctual {
|
|
83
83
|
}
|
84
84
|
node.translation = translation.asArray();
|
85
85
|
}
|
86
|
-
//
|
87
|
-
// glTF lights
|
88
|
-
// compute a quaternion that aligns the Babylon light's direction with glTF's constant one.
|
86
|
+
// Represent the Babylon light's direction as a quaternion
|
87
|
+
// relative to glTF lights' forward direction, (0, 0, -1).
|
89
88
|
if (lightType !== "point" /* KHRLightsPunctual_LightType.POINT */) {
|
90
89
|
const direction = babylonNode.direction.normalizeToRef(TmpVectors.Vector3[0]);
|
91
90
|
if (convertToRightHanded) {
|
92
91
|
ConvertToRightHandedPosition(direction);
|
93
92
|
}
|
94
|
-
const
|
95
|
-
const axis = Vector3.Cross(LIGHTDIRECTION, direction);
|
96
|
-
const lightRotationQuaternion = Quaternion.RotationAxisToRef(axis, angle, TmpVectors.Quaternion[0]);
|
93
|
+
const lightRotationQuaternion = Quaternion.FromUnitVectorsToRef(LIGHTDIRECTION, direction, TmpVectors.Quaternion[0]);
|
97
94
|
if (!Quaternion.IsIdentity(lightRotationQuaternion)) {
|
98
95
|
node.rotation = lightRotationQuaternion.asArray();
|
99
96
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"KHR_lights_punctual.js","sourceRoot":"","sources":["../../../../../../dev/serializers/src/glTF/2.0/Extensions/KHR_lights_punctual.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,6CAA+B;AACzE,OAAO,EAAE,KAAK,EAAE,wCAA0B;AAE1C,OAAO,EAAE,WAAW,EAAE,8CAAgC;AAItD,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,MAAM,EAAE,uCAAyB;AAC1C,OAAO,EAAE,4BAA4B,EAAE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,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 } from \"core/Maths/math.vector\";\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 { GLTFExporter } from \"../glTFExporter\";\r\nimport { Logger } from \"core/Misc/logger\";\r\nimport { ConvertToRightHandedPosition, OmitDefaultValues, CollapseChildIntoParent, IsChildCollapsible } from \"../glTFUtilities\";\r\n\r\nconst NAME = \"KHR_lights_punctual\";\r\nconst DEFAULTS: Omit<IKHRLightsPunctual_Light, \"type\"> = {\r\n name: \"\",\r\n color: [1, 1, 1],\r\n intensity: 1,\r\n range: Number.MAX_VALUE,\r\n};\r\nconst SPOTDEFAULTS: NonNullable<IKHRLightsPunctual_Light[\"spot\"]> = {\r\n innerConeAngle: 0,\r\n outerConeAngle: Math.PI / 4.0,\r\n};\r\nconst LIGHTDIRECTION = Vector3.Backward();\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: GLTFExporter;\r\n\r\n private _lights: IKHRLightsPunctual;\r\n\r\n /**\r\n * @internal\r\n */\r\n constructor(exporter: GLTFExporter) {\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 babylon node to glTF node index\r\n * @param convertToRightHanded Flag to convert the values to right-handed\r\n * @returns nullable INode promise\r\n */\r\n public async postExportNodeAsync(context: string, node: INode, babylonNode: Node, nodeMap: Map<Node, number>, convertToRightHanded: boolean): Promise<Nullable<INode>> {\r\n return await new Promise((resolve) => {\r\n if (!(babylonNode instanceof Light)) {\r\n resolve(node);\r\n return;\r\n }\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 || !(babylonNode instanceof ShadowLight)) {\r\n Logger.Warn(`${context}: Light ${babylonNode.name} is not supported in ${NAME}`);\r\n resolve(node);\r\n return;\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\r\n // Set the node's translation and rotation here, since lights are not handled in exportNodeAsync\r\n if (!babylonNode.position.equalsToFloats(0, 0, 0)) {\r\n const translation = TmpVectors.Vector3[0].copyFrom(babylonNode.position);\r\n if (convertToRightHanded) {\r\n ConvertToRightHandedPosition(translation);\r\n }\r\n node.translation = translation.asArray();\r\n }\r\n\r\n // Babylon lights have \"constant\" rotation and variable direction, while\r\n // glTF lights have variable rotation and constant direction. Therefore,\r\n // compute a quaternion that aligns the Babylon light's direction with glTF's constant one.\r\n if (lightType !== KHRLightsPunctual_LightType.POINT) {\r\n const direction = babylonNode.direction.normalizeToRef(TmpVectors.Vector3[0]);\r\n if (convertToRightHanded) {\r\n ConvertToRightHandedPosition(direction);\r\n }\r\n const angle = Math.acos(Vector3.Dot(LIGHTDIRECTION, direction));\r\n const axis = Vector3.Cross(LIGHTDIRECTION, direction);\r\n const lightRotationQuaternion = Quaternion.RotationAxisToRef(axis, angle, TmpVectors.Quaternion[0]);\r\n if (!Quaternion.IsIdentity(lightRotationQuaternion)) {\r\n node.rotation = lightRotationQuaternion.asArray();\r\n }\r\n }\r\n\r\n const light: IKHRLightsPunctual_Light = {\r\n type: lightType,\r\n name: babylonNode.name,\r\n color: babylonNode.diffuse.asArray(),\r\n intensity: babylonNode.intensity,\r\n range: babylonNode.range,\r\n };\r\n OmitDefaultValues(light, DEFAULTS);\r\n\r\n // Separately handle the required 'spot' field for spot lights\r\n if (lightType === KHRLightsPunctual_LightType.SPOT) {\r\n const babylonSpotLight = babylonNode as SpotLight;\r\n light.spot = {\r\n innerConeAngle: babylonSpotLight.innerAngle / 2.0,\r\n outerConeAngle: babylonSpotLight.angle / 2.0,\r\n };\r\n OmitDefaultValues(light.spot, SPOTDEFAULTS);\r\n }\r\n\r\n this._lights ||= {\r\n lights: [],\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 // Assign the light to its parent node, if possible, to condense the glTF\r\n // Why and when: the glTF loader generates a new parent TransformNode for each light node, which we should undo on export\r\n const parentBabylonNode = babylonNode.parent;\r\n\r\n if (parentBabylonNode && IsChildCollapsible(babylonNode, parentBabylonNode)) {\r\n const parentNodeIndex = nodeMap.get(parentBabylonNode);\r\n if (parentNodeIndex) {\r\n // Combine the light's transformation with the parent's\r\n const parentNode = this._exporter._nodes[parentNodeIndex];\r\n CollapseChildIntoParent(node, parentNode);\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 resolve(node);\r\n });\r\n }\r\n}\r\n\r\nGLTFExporter.RegisterExtension(NAME, (exporter) => new KHR_lights_punctual(exporter));\r\n"]}
|
1
|
+
{"version":3,"file":"KHR_lights_punctual.js","sourceRoot":"","sources":["../../../../../../dev/serializers/src/glTF/2.0/Extensions/KHR_lights_punctual.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,6CAA+B;AACzE,OAAO,EAAE,KAAK,EAAE,wCAA0B;AAE1C,OAAO,EAAE,WAAW,EAAE,8CAAgC;AAItD,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,MAAM,EAAE,uCAAyB;AAC1C,OAAO,EAAE,4BAA4B,EAAE,iBAAiB,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAEhI,MAAM,IAAI,GAAG,qBAAqB,CAAC;AACnC,MAAM,QAAQ,GAA2C;IACrD,IAAI,EAAE,EAAE;IACR,KAAK,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;IAChB,SAAS,EAAE,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC,SAAS;CAC1B,CAAC;AACF,MAAM,YAAY,GAAkD;IAChE,cAAc,EAAE,CAAC;IACjB,cAAc,EAAE,IAAI,CAAC,EAAE,GAAG,GAAG;CAChC,CAAC;AACF,MAAM,cAAc,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC;AAE1C;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,SAAS,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC;oBAC1D,uBAAuB,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;oBAC1C,UAAU,CAAC,UAAU,KAArB,UAAU,CAAC,UAAU,GAAK,EAAE,EAAC;oBAC7B,UAAU,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,cAAc,CAAC;oBAE7C,kCAAkC;oBAClC,OAAO,CAAC,IAAI,CAAC,CAAC;oBACd,OAAO;gBACX,CAAC;YACL,CAAC;YAED,IAAI,CAAC,UAAU,KAAf,IAAI,CAAC,UAAU,GAAK,EAAE,EAAC;YACvB,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,cAAc,CAAC;YACvC,OAAO,CAAC,IAAI,CAAC,CAAC;QAClB,CAAC,CAAC,CAAC;IACP,CAAC;CACJ;AAED,YAAY,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 } from \"core/Maths/math.vector\";\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 { GLTFExporter } from \"../glTFExporter\";\r\nimport { Logger } from \"core/Misc/logger\";\r\nimport { ConvertToRightHandedPosition, OmitDefaultValues, CollapseChildIntoParent, IsChildCollapsible } from \"../glTFUtilities\";\r\n\r\nconst NAME = \"KHR_lights_punctual\";\r\nconst DEFAULTS: Omit<IKHRLightsPunctual_Light, \"type\"> = {\r\n name: \"\",\r\n color: [1, 1, 1],\r\n intensity: 1,\r\n range: Number.MAX_VALUE,\r\n};\r\nconst SPOTDEFAULTS: NonNullable<IKHRLightsPunctual_Light[\"spot\"]> = {\r\n innerConeAngle: 0,\r\n outerConeAngle: Math.PI / 4.0,\r\n};\r\nconst LIGHTDIRECTION = Vector3.Backward();\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: GLTFExporter;\r\n\r\n private _lights: IKHRLightsPunctual;\r\n\r\n /**\r\n * @internal\r\n */\r\n constructor(exporter: GLTFExporter) {\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 babylon node to glTF node index\r\n * @param convertToRightHanded Flag to convert the values to right-handed\r\n * @returns nullable INode promise\r\n */\r\n public async postExportNodeAsync(context: string, node: INode, babylonNode: Node, nodeMap: Map<Node, number>, convertToRightHanded: boolean): Promise<Nullable<INode>> {\r\n return await new Promise((resolve) => {\r\n if (!(babylonNode instanceof Light)) {\r\n resolve(node);\r\n return;\r\n }\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 || !(babylonNode instanceof ShadowLight)) {\r\n Logger.Warn(`${context}: Light ${babylonNode.name} is not supported in ${NAME}`);\r\n resolve(node);\r\n return;\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\r\n // Set the node's translation and rotation here, since lights are not handled in exportNodeAsync\r\n if (!babylonNode.position.equalsToFloats(0, 0, 0)) {\r\n const translation = TmpVectors.Vector3[0].copyFrom(babylonNode.position);\r\n if (convertToRightHanded) {\r\n ConvertToRightHandedPosition(translation);\r\n }\r\n node.translation = translation.asArray();\r\n }\r\n\r\n // Represent the Babylon light's direction as a quaternion\r\n // relative to glTF lights' forward direction, (0, 0, -1).\r\n if (lightType !== KHRLightsPunctual_LightType.POINT) {\r\n const direction = babylonNode.direction.normalizeToRef(TmpVectors.Vector3[0]);\r\n if (convertToRightHanded) {\r\n ConvertToRightHandedPosition(direction);\r\n }\r\n\r\n const lightRotationQuaternion = Quaternion.FromUnitVectorsToRef(LIGHTDIRECTION, direction, TmpVectors.Quaternion[0]);\r\n if (!Quaternion.IsIdentity(lightRotationQuaternion)) {\r\n node.rotation = lightRotationQuaternion.asArray();\r\n }\r\n }\r\n\r\n const light: IKHRLightsPunctual_Light = {\r\n type: lightType,\r\n name: babylonNode.name,\r\n color: babylonNode.diffuse.asArray(),\r\n intensity: babylonNode.intensity,\r\n range: babylonNode.range,\r\n };\r\n OmitDefaultValues(light, DEFAULTS);\r\n\r\n // Separately handle the required 'spot' field for spot lights\r\n if (lightType === KHRLightsPunctual_LightType.SPOT) {\r\n const babylonSpotLight = babylonNode as SpotLight;\r\n light.spot = {\r\n innerConeAngle: babylonSpotLight.innerAngle / 2.0,\r\n outerConeAngle: babylonSpotLight.angle / 2.0,\r\n };\r\n OmitDefaultValues(light.spot, SPOTDEFAULTS);\r\n }\r\n\r\n this._lights ||= {\r\n lights: [],\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 // Assign the light to its parent node, if possible, to condense the glTF\r\n // Why and when: the glTF loader generates a new parent TransformNode for each light node, which we should undo on export\r\n const parentBabylonNode = babylonNode.parent;\r\n\r\n if (parentBabylonNode && IsChildCollapsible(babylonNode, parentBabylonNode)) {\r\n const parentNodeIndex = nodeMap.get(parentBabylonNode);\r\n if (parentNodeIndex) {\r\n // Combine the light's transformation with the parent's\r\n const parentNode = this._exporter._nodes[parentNodeIndex];\r\n CollapseChildIntoParent(node, parentNode);\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 resolve(node);\r\n });\r\n }\r\n}\r\n\r\nGLTFExporter.RegisterExtension(NAME, (exporter) => new KHR_lights_punctual(exporter));\r\n"]}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@babylonjs/serializers",
|
3
|
-
"version": "8.
|
3
|
+
"version": "8.13.0",
|
4
4
|
"main": "index.js",
|
5
5
|
"module": "index.js",
|
6
6
|
"types": "index.d.ts",
|
@@ -18,10 +18,10 @@
|
|
18
18
|
"postcompile": "build-tools -c add-js-to-es6"
|
19
19
|
},
|
20
20
|
"devDependencies": {
|
21
|
-
"@babylonjs/core": "^8.
|
21
|
+
"@babylonjs/core": "^8.13.0",
|
22
22
|
"@dev/build-tools": "^1.0.0",
|
23
23
|
"@lts/serializers": "^1.0.0",
|
24
|
-
"babylonjs-gltf2interface": "^8.
|
24
|
+
"babylonjs-gltf2interface": "^8.13.0"
|
25
25
|
},
|
26
26
|
"peerDependencies": {
|
27
27
|
"@babylonjs/core": "^8.0.0",
|