@babylonjs/loaders 9.27.1 → 9.29.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/BVH/bvhLoader.js +1 -3
- package/BVH/bvhLoader.js.map +1 -1
- package/OBJ/mtlFileLoader.d.ts +8 -1
- package/OBJ/mtlFileLoader.js +55 -13
- package/OBJ/mtlFileLoader.js.map +1 -1
- package/OBJ/objFileLoader.pure.d.ts +5 -0
- package/OBJ/objFileLoader.pure.js +87 -65
- package/OBJ/objFileLoader.pure.js.map +1 -1
- package/OBJ/objLoadingOptions.d.ts +6 -0
- package/OBJ/objLoadingOptions.js.map +1 -1
- package/OBJ/solidParser.js +17 -6
- package/OBJ/solidParser.js.map +1 -1
- package/SPLAT/splatFileLoader.pure.js +86 -82
- package/SPLAT/splatFileLoader.pure.js.map +1 -1
- package/STL/stlFileLoader.pure.d.ts +1 -0
- package/STL/stlFileLoader.pure.js +18 -16
- package/STL/stlFileLoader.pure.js.map +1 -1
- package/glTF/1.0/glTFLoader.pure.js +30 -37
- package/glTF/1.0/glTFLoader.pure.js.map +1 -1
- package/glTF/2.0/Extensions/EXT_lights_area.pure.js +16 -23
- package/glTF/2.0/Extensions/EXT_lights_area.pure.js.map +1 -1
- package/glTF/2.0/Extensions/EXT_lights_ies.pure.js +1 -3
- package/glTF/2.0/Extensions/EXT_lights_ies.pure.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_gaussian_splatting.pure.js +1 -3
- package/glTF/2.0/Extensions/KHR_gaussian_splatting.pure.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_interactivity/interactivityGraphExporter.d.ts +7 -0
- package/glTF/2.0/Extensions/KHR_interactivity/interactivityGraphExporter.js +17 -3
- package/glTF/2.0/Extensions/KHR_interactivity/interactivityGraphExporter.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_interactivity/interactivityNodeReference.d.ts +13 -0
- package/glTF/2.0/Extensions/KHR_interactivity/interactivityNodeReference.js +16 -0
- package/glTF/2.0/Extensions/KHR_interactivity/interactivityNodeReference.js.map +1 -0
- package/glTF/2.0/Extensions/KHR_lights_punctual.pure.js +18 -25
- package/glTF/2.0/Extensions/KHR_lights_punctual.pure.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_node_hoverability.pure.js +3 -10
- package/glTF/2.0/Extensions/KHR_node_hoverability.pure.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_node_selectability.pure.js +2 -5
- package/glTF/2.0/Extensions/KHR_node_selectability.pure.js.map +1 -1
- package/glTF/2.0/glTFLoader.pure.js +15 -37
- package/glTF/2.0/glTFLoader.pure.js.map +1 -1
- package/package.json +3 -3
|
@@ -44,34 +44,27 @@ export class EXT_lights_area {
|
|
|
44
44
|
return GLTFLoader.LoadExtensionAsync(context, node, this.name, async (extensionContext, extension) => {
|
|
45
45
|
this._loader._allMaterialsDirtyRequired = true;
|
|
46
46
|
return await this._loader.loadNodeAsync(context, node, (babylonMesh) => {
|
|
47
|
-
let babylonLight;
|
|
48
47
|
const light = ArrayItem.Get(extensionContext, this._lights, extension.light);
|
|
49
48
|
const name = light.name || babylonMesh.name;
|
|
50
|
-
this._loader.babylonScene._blockEntityCollection = !!this._loader._assetContainer;
|
|
51
49
|
const size = light.size !== undefined ? light.size : 1.0;
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
50
|
+
const babylonLight = this._loader.babylonScene._executeWithBlockedEntityCollection(!!this._loader._assetContainer, () => {
|
|
51
|
+
switch (light.type) {
|
|
52
|
+
case "rect" /* EXTLightsArea_LightType.RECT */: {
|
|
53
|
+
const width = light.rect?.aspect !== undefined ? light.rect.aspect * size : size;
|
|
54
|
+
const height = size;
|
|
55
|
+
return new RectAreaLight(name, Vector3.Zero(), width, height, this._loader.babylonScene);
|
|
56
|
+
}
|
|
57
|
+
case "disk" /* EXTLightsArea_LightType.DISK */: {
|
|
58
|
+
// For disk lights, we'll use a rectangle light with the same area to approximate the disk light
|
|
59
|
+
// In the future, this could be extended to support actual disk area lights
|
|
60
|
+
const newSize = Math.sqrt(size * size * 0.25 * Math.PI); // Area of the disk
|
|
61
|
+
return new RectAreaLight(name, Vector3.Zero(), newSize, newSize, this._loader.babylonScene);
|
|
62
|
+
}
|
|
63
|
+
default:
|
|
64
|
+
throw new Error(`${extensionContext}: Invalid area light type (${light.type})`);
|
|
59
65
|
}
|
|
60
|
-
|
|
61
|
-
// For disk lights, we'll use a rectangle light with the same area to approximate the disk light
|
|
62
|
-
// In the future, this could be extended to support actual disk area lights
|
|
63
|
-
const newSize = Math.sqrt(size * size * 0.25 * Math.PI); // Area of the disk
|
|
64
|
-
const babylonRectAreaLight = new RectAreaLight(name, Vector3.Zero(), newSize, newSize, this._loader.babylonScene);
|
|
65
|
-
babylonLight = babylonRectAreaLight;
|
|
66
|
-
break;
|
|
67
|
-
}
|
|
68
|
-
default: {
|
|
69
|
-
this._loader.babylonScene._blockEntityCollection = false;
|
|
70
|
-
throw new Error(`${extensionContext}: Invalid area light type (${light.type})`);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
66
|
+
});
|
|
73
67
|
babylonLight._parentContainer = this._loader._assetContainer;
|
|
74
|
-
this._loader.babylonScene._blockEntityCollection = false;
|
|
75
68
|
light._babylonLight = babylonLight;
|
|
76
69
|
babylonLight.falloffType = Light.FALLOFF_GLTF;
|
|
77
70
|
babylonLight.diffuse = light.color ? Color3.FromArray(light.color) : Color3.White();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EXT_lights_area.pure.js","sourceRoot":"","sources":["../../../../../../dev/loaders/src/glTF/2.0/Extensions/EXT_lights_area.pure.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AACpD,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CA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C,YAAY,CAAC,OAAO,CAAC,EAAE,EAAE,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC;gBACpF,eAAe,CAAC,MAAM,GAAG,WAAW,CAAC;gBACrC,YAAY,CAAC,MAAM,GAAG,eAAe,CAAC;gBAEtC,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;gBAE/C,UAAU,CAAC,kBAAkB,CAAC,YAAY,EAAE,gBAAgB,CAAC,CAAC;gBAE9D,MAAM,CAAC,WAAW,CAAC,CAAC;YACxB,CAAC,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;IACP,CAAC;CACJ;AAED,IAAI,WAAW,GAAG,KAAK,CAAC;AACxB;;;GAGG;AACH,gEAAgE;AAChE,MAAM,UAAU,uBAAuB;IACnC,IAAI,WAAW,EAAE,CAAC;QACd,OAAO;IACX,CAAC;IACD,WAAW,GAAG,IAAI,CAAC;IAEnB,uBAAuB,CAAC,IAAI,CAAC,CAAC;IAE9B,qBAAqB,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,eAAe,CAAC,MAAM,CAAC,CAAC,CAAC;AAC/E,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\r\nimport { type Nullable } from \"core/types\";\r\nimport { Vector3, Quaternion } from \"core/Maths/math.vector.pure\";\r\nimport { Color3 } from \"core/Maths/math.color.pure\";\r\nimport { Light } from \"core/Lights/light\";\r\nimport { RectAreaLight } from \"core/Lights/rectAreaLight.pure\";\r\nimport { type TransformNode, TransformNode as BabylonTransformNode } from \"core/Meshes/transformNode.pure\";\r\n\r\nimport { type IEXTLightsArea_LightReference, EXTLightsArea_LightType } from \"babylonjs-gltf2interface\";\r\nimport { type INode, type IEXTLightsArea_Light } from \"../glTFLoaderInterfaces\";\r\nimport { type IGLTFLoaderExtension } from \"../glTFLoaderExtension\";\r\nimport { GLTFLoader, ArrayItem } from \"../glTFLoader.pure\";\r\nimport { registerGLTFExtension, unregisterGLTFExtension } from \"../glTFLoaderExtensionRegistry\";\r\n\r\nconst NAME = \"EXT_lights_area\";\r\n\r\n/**\r\n * [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Vendor/EXT_lights_area/README.md)\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class EXT_lights_area implements IGLTFLoaderExtension {\r\n /**\r\n * The name of this extension.\r\n */\r\n public readonly name = NAME;\r\n\r\n /**\r\n * Defines whether this extension is enabled.\r\n */\r\n public enabled: boolean;\r\n\r\n /** hidden */\r\n private _loader: GLTFLoader;\r\n private _lights?: IEXTLightsArea_Light[];\r\n\r\n /**\r\n * @internal\r\n */\r\n constructor(loader: GLTFLoader) {\r\n this._loader = loader;\r\n this.enabled = this._loader.isExtensionUsed(NAME);\r\n }\r\n\r\n /** @internal */\r\n public dispose() {\r\n (this._loader as any) = null;\r\n delete this._lights;\r\n }\r\n\r\n /** @internal */\r\n public onLoading(): void {\r\n const extensions = this._loader.gltf.extensions;\r\n if (extensions && extensions[this.name]) {\r\n const extension = extensions[this.name];\r\n this._lights = extension.lights;\r\n ArrayItem.Assign(this._lights);\r\n }\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n // eslint-disable-next-line no-restricted-syntax\r\n public loadNodeAsync(context: string, node: INode, assign: (babylonTransformNode: TransformNode) => void): Nullable<Promise<TransformNode>> {\r\n return GLTFLoader.LoadExtensionAsync<IEXTLightsArea_LightReference, TransformNode>(context, node, this.name, async (extensionContext, extension) => {\r\n this._loader._allMaterialsDirtyRequired = true;\r\n\r\n return await this._loader.loadNodeAsync(context, node, (babylonMesh) => {\r\n let babylonLight: Light;\r\n\r\n const light = ArrayItem.Get(extensionContext, this._lights, extension.light);\r\n const name = light.name || babylonMesh.name;\r\n\r\n this._loader.babylonScene._blockEntityCollection = !!this._loader._assetContainer;\r\n const size = light.size !== undefined ? light.size : 1.0;\r\n\r\n switch (light.type) {\r\n case EXTLightsArea_LightType.RECT: {\r\n const width = light.rect?.aspect !== undefined ? light.rect.aspect * size : size;\r\n const height = size;\r\n const babylonRectAreaLight = new RectAreaLight(name, Vector3.Zero(), width, height, this._loader.babylonScene);\r\n babylonLight = babylonRectAreaLight;\r\n break;\r\n }\r\n case EXTLightsArea_LightType.DISK: {\r\n // For disk lights, we'll use a rectangle light with the same area to approximate the disk light\r\n // In the future, this could be extended to support actual disk area lights\r\n const newSize = Math.sqrt(size * size * 0.25 * Math.PI); // Area of the disk\r\n const babylonRectAreaLight = new RectAreaLight(name, Vector3.Zero(), newSize, newSize, this._loader.babylonScene);\r\n babylonLight = babylonRectAreaLight;\r\n break;\r\n }\r\n default: {\r\n this._loader.babylonScene._blockEntityCollection = false;\r\n throw new Error(`${extensionContext}: Invalid area light type (${light.type})`);\r\n }\r\n }\r\n\r\n babylonLight._parentContainer = this._loader._assetContainer;\r\n this._loader.babylonScene._blockEntityCollection = false;\r\n light._babylonLight = babylonLight;\r\n\r\n babylonLight.falloffType = Light.FALLOFF_GLTF;\r\n babylonLight.diffuse = light.color ? Color3.FromArray(light.color) : Color3.White();\r\n babylonLight.intensity = light.intensity == undefined ? 1 : light.intensity;\r\n\r\n // glTF EXT_lights_area specifies lights face down -Z, but Babylon.js area lights face down +Z\r\n // Create a parent transform node with 180-degree rotation around Y axis to flip the direction\r\n const lightParentNode = new BabylonTransformNode(`${name}_orientation`, this._loader.babylonScene);\r\n lightParentNode.rotationQuaternion = Quaternion.RotationAxis(Vector3.Up(), Math.PI);\r\n lightParentNode.parent = babylonMesh;\r\n babylonLight.parent = lightParentNode;\r\n\r\n this._loader._babylonLights.push(babylonLight);\r\n\r\n GLTFLoader.AddPointerMetadata(babylonLight, extensionContext);\r\n\r\n assign(babylonMesh);\r\n });\r\n });\r\n }\r\n}\r\n\r\nlet _Registered = false;\r\n/**\r\n * Registers the EXT_lights_area glTF loader extension.\r\n * Safe to call multiple times; only the first call has an effect.\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport function RegisterEXT_lights_area(): void {\r\n if (_Registered) {\r\n return;\r\n }\r\n _Registered = true;\r\n\r\n unregisterGLTFExtension(NAME);\r\n\r\n registerGLTFExtension(NAME, true, (loader) => new EXT_lights_area(loader));\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"EXT_lights_area.pure.js","sourceRoot":"","sources":["../../../../../../dev/loaders/src/glTF/2.0/Extensions/EXT_lights_area.pure.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AACpD,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AAC/D,OAAO,EAAsB,aAAa,IAAI,oBAAoB,EAAE,MAAM,gCAAgC,CAAC;AAK3G,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAAE,qBAAqB,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AAEhG,MAAM,IAAI,GAAG,iBAAiB,CAAC;AAE/B;;GAEG;AACH,gEAAgE;AAChE,MAAM,OAAO,eAAe;IAexB;;OAEG;IACH,YAAY,MAAkB;QAjB9B;;WAEG;QACa,SAAI,GAAG,IAAI,CAAC;QAexB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;IACtD,CAAC;IAED,gBAAgB;IACT,OAAO;QACT,IAAI,CAAC,OAAe,GAAG,IAAI,CAAC;QAC7B,OAAO,IAAI,CAAC,OAAO,CAAC;IACxB,CAAC;IAED,gBAAgB;IACT,SAAS;QACZ,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC;QAChD,IAAI,UA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A8F;gBAC9F,8FAA8F;gBAC9F,MAAM,eAAe,GAAG,IAAI,oBAAoB,CAAC,GAAG,IAAI,cAAc,EAAE,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;gBACnG,eAAe,CAAC,kBAAkB,GAAG,UAAU,CAAC,YAAY,CAAC,OAAO,CAAC,EAAE,EAAE,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC;gBACpF,eAAe,CAAC,MAAM,GAAG,WAAW,CAAC;gBACrC,YAAY,CAAC,MAAM,GAAG,eAAe,CAAC;gBAEtC,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;gBAE/C,UAAU,CAAC,kBAAkB,CAAC,YAAY,EAAE,gBAAgB,CAAC,CAAC;gBAE9D,MAAM,CAAC,WAAW,CAAC,CAAC;YACxB,CAAC,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;IACP,CAAC;CACJ;AAED,IAAI,WAAW,GAAG,KAAK,CAAC;AACxB;;;GAGG;AACH,gEAAgE;AAChE,MAAM,UAAU,uBAAuB;IACnC,IAAI,WAAW,EAAE,CAAC;QACd,OAAO;IACX,CAAC;IACD,WAAW,GAAG,IAAI,CAAC;IAEnB,uBAAuB,CAAC,IAAI,CAAC,CAAC;IAE9B,qBAAqB,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,eAAe,CAAC,MAAM,CAAC,CAAC,CAAC;AAC/E,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\r\nimport { type Nullable } from \"core/types\";\r\nimport { Vector3, Quaternion } from \"core/Maths/math.vector.pure\";\r\nimport { Color3 } from \"core/Maths/math.color.pure\";\r\nimport { Light } from \"core/Lights/light\";\r\nimport { RectAreaLight } from \"core/Lights/rectAreaLight.pure\";\r\nimport { type TransformNode, TransformNode as BabylonTransformNode } from \"core/Meshes/transformNode.pure\";\r\n\r\nimport { type IEXTLightsArea_LightReference, EXTLightsArea_LightType } from \"babylonjs-gltf2interface\";\r\nimport { type INode, type IEXTLightsArea_Light } from \"../glTFLoaderInterfaces\";\r\nimport { type IGLTFLoaderExtension } from \"../glTFLoaderExtension\";\r\nimport { GLTFLoader, ArrayItem } from \"../glTFLoader.pure\";\r\nimport { registerGLTFExtension, unregisterGLTFExtension } from \"../glTFLoaderExtensionRegistry\";\r\n\r\nconst NAME = \"EXT_lights_area\";\r\n\r\n/**\r\n * [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Vendor/EXT_lights_area/README.md)\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class EXT_lights_area implements IGLTFLoaderExtension {\r\n /**\r\n * The name of this extension.\r\n */\r\n public readonly name = NAME;\r\n\r\n /**\r\n * Defines whether this extension is enabled.\r\n */\r\n public enabled: boolean;\r\n\r\n /** hidden */\r\n private _loader: GLTFLoader;\r\n private _lights?: IEXTLightsArea_Light[];\r\n\r\n /**\r\n * @internal\r\n */\r\n constructor(loader: GLTFLoader) {\r\n this._loader = loader;\r\n this.enabled = this._loader.isExtensionUsed(NAME);\r\n }\r\n\r\n /** @internal */\r\n public dispose() {\r\n (this._loader as any) = null;\r\n delete this._lights;\r\n }\r\n\r\n /** @internal */\r\n public onLoading(): void {\r\n const extensions = this._loader.gltf.extensions;\r\n if (extensions && extensions[this.name]) {\r\n const extension = extensions[this.name];\r\n this._lights = extension.lights;\r\n ArrayItem.Assign(this._lights);\r\n }\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n // eslint-disable-next-line no-restricted-syntax\r\n public loadNodeAsync(context: string, node: INode, assign: (babylonTransformNode: TransformNode) => void): Nullable<Promise<TransformNode>> {\r\n return GLTFLoader.LoadExtensionAsync<IEXTLightsArea_LightReference, TransformNode>(context, node, this.name, async (extensionContext, extension) => {\r\n this._loader._allMaterialsDirtyRequired = true;\r\n\r\n return await this._loader.loadNodeAsync(context, node, (babylonMesh) => {\r\n const light = ArrayItem.Get(extensionContext, this._lights, extension.light);\r\n const name = light.name || babylonMesh.name;\r\n const size = light.size !== undefined ? light.size : 1.0;\r\n const babylonLight = this._loader.babylonScene._executeWithBlockedEntityCollection(!!this._loader._assetContainer, () => {\r\n switch (light.type) {\r\n case EXTLightsArea_LightType.RECT: {\r\n const width = light.rect?.aspect !== undefined ? light.rect.aspect * size : size;\r\n const height = size;\r\n return new RectAreaLight(name, Vector3.Zero(), width, height, this._loader.babylonScene);\r\n }\r\n case EXTLightsArea_LightType.DISK: {\r\n // For disk lights, we'll use a rectangle light with the same area to approximate the disk light\r\n // In the future, this could be extended to support actual disk area lights\r\n const newSize = Math.sqrt(size * size * 0.25 * Math.PI); // Area of the disk\r\n return new RectAreaLight(name, Vector3.Zero(), newSize, newSize, this._loader.babylonScene);\r\n }\r\n default:\r\n throw new Error(`${extensionContext}: Invalid area light type (${light.type})`);\r\n }\r\n });\r\n\r\n babylonLight._parentContainer = this._loader._assetContainer;\r\n light._babylonLight = babylonLight;\r\n\r\n babylonLight.falloffType = Light.FALLOFF_GLTF;\r\n babylonLight.diffuse = light.color ? Color3.FromArray(light.color) : Color3.White();\r\n babylonLight.intensity = light.intensity == undefined ? 1 : light.intensity;\r\n\r\n // glTF EXT_lights_area specifies lights face down -Z, but Babylon.js area lights face down +Z\r\n // Create a parent transform node with 180-degree rotation around Y axis to flip the direction\r\n const lightParentNode = new BabylonTransformNode(`${name}_orientation`, this._loader.babylonScene);\r\n lightParentNode.rotationQuaternion = Quaternion.RotationAxis(Vector3.Up(), Math.PI);\r\n lightParentNode.parent = babylonMesh;\r\n babylonLight.parent = lightParentNode;\r\n\r\n this._loader._babylonLights.push(babylonLight);\r\n\r\n GLTFLoader.AddPointerMetadata(babylonLight, extensionContext);\r\n\r\n assign(babylonMesh);\r\n });\r\n });\r\n }\r\n}\r\n\r\nlet _Registered = false;\r\n/**\r\n * Registers the EXT_lights_area glTF loader extension.\r\n * Safe to call multiple times; only the first call has an effect.\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport function RegisterEXT_lights_area(): void {\r\n if (_Registered) {\r\n return;\r\n }\r\n _Registered = true;\r\n\r\n unregisterGLTFExtension(NAME);\r\n\r\n registerGLTFExtension(NAME, true, (loader) => new EXT_lights_area(loader));\r\n}\r\n"]}
|
|
@@ -49,12 +49,10 @@ export class EXT_lights_ies {
|
|
|
49
49
|
const transformNode = await this._loader.loadNodeAsync(context, node, (babylonMesh) => {
|
|
50
50
|
light = ArrayItem.Get(extensionContext, this._lights, extension.light);
|
|
51
51
|
const name = light.name || babylonMesh.name;
|
|
52
|
-
this._loader.babylonScene.
|
|
53
|
-
babylonSpotLight = new SpotLight(name, Vector3.Zero(), Vector3.Backward(), 0, 1, this._loader.babylonScene);
|
|
52
|
+
babylonSpotLight = this._loader.babylonScene._executeWithBlockedEntityCollection(!!this._loader._assetContainer, () => new SpotLight(name, Vector3.Zero(), Vector3.Backward(), 0, 1, this._loader.babylonScene));
|
|
54
53
|
babylonSpotLight.angle = Math.PI / 2;
|
|
55
54
|
babylonSpotLight.innerAngle = 0;
|
|
56
55
|
babylonSpotLight._parentContainer = this._loader._assetContainer;
|
|
57
|
-
this._loader.babylonScene._blockEntityCollection = false;
|
|
58
56
|
light._babylonLight = babylonSpotLight;
|
|
59
57
|
babylonSpotLight.falloffType = Light.FALLOFF_GLTF;
|
|
60
58
|
babylonSpotLight.diffuse = extension.color ? Color3.FromArray(extension.color) : Color3.White();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EXT_lights_ies.pure.js","sourceRoot":"","sources":["../../../../../../dev/loaders/src/glTF/2.0/Extensions/EXT_lights_ies.pure.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,6BAA6B,CAAC;AACtD,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AACvD,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,C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,CAAC;YAC9E,CAAC;iBAAM,CAAC;gBACJ,MAAM,UAAU,GAAG,SAAS,CAAC,GAAG,CAAC,GAAG,OAAO,aAAa,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,WAAW,EAAE,KAAM,CAAC,UAAU,CAAC,CAAC;gBAC5G,UAAU,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,mBAAmB,CAAC,gBAAgB,UAAU,CAAC,KAAK,EAAE,EAAE,UAAU,CAAC,CAAC;YACxG,CAAC;YACD,gBAAiB,CAAC,iBAAiB,GAAG,IAAI,OAAO,CAC7C,gBAAiB,CAAC,IAAI,GAAG,aAAa,EACtC,IAAI,CAAC,OAAO,CAAC,YAAY,EACzB,IAAI,EACJ,KAAK,EACL,SAAS,EACT,IAAI,EACJ,IAAI,EACJ,UAAU,EACV,IAAI,EACJ,SAAS,EACT,SAAS,EACT,SAAS,EACT,SAAS,EACT,MAAM,CACT,CAAC;YAEF,OAAO,aAAa,CAAC;QACzB,CAAC,CAAC,CAAC;IACP,CAAC;CACJ;AAED,IAAI,WAAW,GAAG,KAAK,CAAC;AACxB;;;GAGG;AACH,gEAAgE;AAChE,MAAM,UAAU,sBAAsB;IAClC,IAAI,WAAW,EAAE,CAAC;QACd,OAAO;IACX,CAAC;IACD,WAAW,GAAG,IAAI,CAAC;IAEnB,uBAAuB,CAAC,IAAI,CAAC,CAAC;IAE9B,qBAAqB,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC;AAC9E,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\r\nimport { type Nullable } from \"core/types\";\r\nimport { Vector3 } from \"core/Maths/math.vector.pure\";\r\nimport { Color3 } from \"core/Maths/math.color.pure\";\r\nimport { SpotLight } from \"core/Lights/spotLight.pure\";\r\nimport { Light } from \"core/Lights/light\";\r\nimport { type TransformNode } from \"core/Meshes/transformNode.pure\";\r\n\r\nimport { type IEXTLightsIES_LightReference } from \"babylonjs-gltf2interface\";\r\nimport { type IEXTLightsIES_Light, type INode } from \"../glTFLoaderInterfaces\";\r\nimport { type IGLTFLoaderExtension } from \"../glTFLoaderExtension\";\r\nimport { GLTFLoader, ArrayItem } from \"../glTFLoader.pure\";\r\nimport { registerGLTFExtension, unregisterGLTFExtension } from \"../glTFLoaderExtensionRegistry\";\r\nimport { Texture } from \"core/Materials/Textures/texture.pure\";\r\n\r\nconst NAME = \"EXT_lights_ies\";\r\n\r\n/**\r\n * [Specification](https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Vendor/EXT_lights_ies)\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class EXT_lights_ies implements IGLTFLoaderExtension {\r\n /**\r\n * The name of this extension.\r\n */\r\n public readonly name = NAME;\r\n\r\n /**\r\n * Defines whether this extension is enabled.\r\n */\r\n public enabled: boolean;\r\n\r\n /** hidden */\r\n private _loader: GLTFLoader;\r\n private _lights?: IEXTLightsIES_Light[];\r\n\r\n /**\r\n * @internal\r\n */\r\n constructor(loader: GLTFLoader) {\r\n this._loader = loader;\r\n this.enabled = this._loader.isExtensionUsed(NAME);\r\n }\r\n\r\n /** @internal */\r\n public dispose() {\r\n (this._loader as any) = null;\r\n delete this._lights;\r\n }\r\n\r\n /** @internal */\r\n public onLoading(): void {\r\n const extensions = this._loader.gltf.extensions;\r\n if (extensions && extensions[this.name]) {\r\n const extension = extensions[this.name];\r\n this._lights = extension.lights;\r\n ArrayItem.Assign(this._lights);\r\n }\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n // eslint-disable-next-line no-restricted-syntax\r\n // eslint-disable-next-line no-restricted-syntax\r\n public loadNodeAsync(context: string, node: INode, assign: (babylonTransformNode: TransformNode) => void): Nullable<Promise<TransformNode>> {\r\n return GLTFLoader.LoadExtensionAsync<IEXTLightsIES_LightReference, TransformNode>(context, node, this.name, async (extensionContext, extension) => {\r\n this._loader._allMaterialsDirtyRequired = true;\r\n\r\n let babylonSpotLight: SpotLight;\r\n let light: IEXTLightsIES_Light;\r\n\r\n const transformNode = await this._loader.loadNodeAsync(context, node, (babylonMesh) => {\r\n light = ArrayItem.Get(extensionContext, this._lights, extension.light);\r\n const name = light.name || babylonMesh.name;\r\n\r\n babylonSpotLight = this._loader.babylonScene._executeWithBlockedEntityCollection(\r\n !!this._loader._assetContainer,\r\n () => new SpotLight(name, Vector3.Zero(), Vector3.Backward(), 0, 1, this._loader.babylonScene)\r\n );\r\n babylonSpotLight.angle = Math.PI / 2;\r\n babylonSpotLight.innerAngle = 0;\r\n\r\n babylonSpotLight._parentContainer = this._loader._assetContainer;\r\n light._babylonLight = babylonSpotLight;\r\n\r\n babylonSpotLight.falloffType = Light.FALLOFF_GLTF;\r\n babylonSpotLight.diffuse = extension.color ? Color3.FromArray(extension.color) : Color3.White();\r\n babylonSpotLight.intensity = extension.multiplier || 1;\r\n babylonSpotLight.range = Number.MAX_VALUE;\r\n babylonSpotLight.parent = babylonMesh;\r\n\r\n this._loader._babylonLights.push(babylonSpotLight);\r\n\r\n GLTFLoader.AddPointerMetadata(babylonSpotLight, extensionContext);\r\n\r\n assign(babylonMesh);\r\n });\r\n\r\n // Load the profile\r\n let bufferData: ArrayBufferView;\r\n if (light!.uri) {\r\n bufferData = await this._loader.loadUriAsync(context, light!, light!.uri);\r\n } else {\r\n const bufferView = ArrayItem.Get(`${context}/bufferView`, this._loader.gltf.bufferViews, light!.bufferView);\r\n bufferData = await this._loader.loadBufferViewAsync(`/bufferViews/${bufferView.index}`, bufferView);\r\n }\r\n babylonSpotLight!.iesProfileTexture = new Texture(\r\n babylonSpotLight!.name + \"_iesProfile\",\r\n this._loader.babylonScene,\r\n true,\r\n false,\r\n undefined,\r\n null,\r\n null,\r\n bufferData,\r\n true,\r\n undefined,\r\n undefined,\r\n undefined,\r\n undefined,\r\n \".ies\"\r\n );\r\n\r\n return transformNode;\r\n });\r\n }\r\n}\r\n\r\nlet _Registered = false;\r\n/**\r\n * Registers the EXT_lights_ies glTF loader extension.\r\n * Safe to call multiple times; only the first call has an effect.\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport function RegisterEXT_lights_ies(): void {\r\n if (_Registered) {\r\n return;\r\n }\r\n _Registered = true;\r\n\r\n unregisterGLTFExtension(NAME);\r\n\r\n registerGLTFExtension(NAME, true, (loader) => new EXT_lights_ies(loader));\r\n}\r\n"]}
|
|
@@ -74,10 +74,8 @@ export class KHR_gaussian_splatting {
|
|
|
74
74
|
// attribute data). The base loader wires the node's transform node from this assign call
|
|
75
75
|
// synchronously, so it must happen before the first await. The splat data is uploaded afterwards.
|
|
76
76
|
const scene = loader.babylonScene;
|
|
77
|
-
|
|
78
|
-
const gaussianSplattingMesh = new GaussianSplattingMesh(name, null, scene);
|
|
77
|
+
const gaussianSplattingMesh = scene._executeWithBlockedEntityCollection(!!loader._assetContainer, () => new GaussianSplattingMesh(name, null, scene));
|
|
79
78
|
gaussianSplattingMesh._parentContainer = loader._assetContainer;
|
|
80
|
-
scene._blockEntityCollection = false;
|
|
81
79
|
GLTFLoader.AddPointerMetadata(gaussianSplattingMesh, context);
|
|
82
80
|
loader.parent.onMeshLoadedObservable.notifyObservers(gaussianSplattingMesh);
|
|
83
81
|
assign(gaussianSplattingMesh);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"KHR_gaussian_splatting.pure.js","sourceRoot":"","sources":["../../../../../../dev/loaders/src/glTF/2.0/Extensions/KHR_gaussian_splatting.pure.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,qBAAqB,EAAE,MAAM,0DAA0D,CAAC;AACjG,OAAO,EAAE,iBAAiB,EAAE,MAAM,8DAA8D,CAAC;AAKjG,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAAE,qBAAqB,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AAEhG,MAAM,IAAI,GAAG,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D,KAAK,IAAI,OAAO,GAAG,CAAC,EAAE,OAAO,GAAG,CAAC,EAAE,OAAO,EAAE,EAAE,CAAC;4BAC3C,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,GAAG,OAAO,CAAC;4BACrC,MAAM,YAAY,GAAG,SAAS,IAAI,CAAC,CAAC,CAAC,6BAA6B;4BAClE,MAAM,kBAAkB,GAAG,SAAS,GAAG,EAAE,CAAC,CAAC,iBAAiB;4BAC5D,SAAS,CAAC,YAAY,CAAC,CAAC,cAAc,GAAG,kBAAkB,CAAC,GAAG,QAAQ,CAAC,QAAQ,CAAC,CAAC,GAAG,OAAO,CAAC,GAAG,GAAG,GAAG,GAAG,CAAC,CAAC;wBAC/G,CAAC;oBACL,CAAC;gBACL,CAAC;YACL,CAAC;YAED,MAAM,qBAAqB,CAAC,eAAe,CAAC,MAAM,EAAE,SAAS,IAAI,SAAS,EAAE,SAAS,EAAE,QAAQ,IAAI,SAAS,CAAC,CAAC;YAE9G,OAAO,qBAAqB,CAAC;QACjC,CAAC,CAAC,CAAC;IACP,CAAC;CACJ;AAED,IAAI,WAAW,GAAG,KAAK,CAAC;AACxB;;;GAGG;AACH,gEAAgE;AAChE,MAAM,UAAU,8BAA8B;IAC1C,IAAI,WAAW,EAAE,CAAC;QACd,OAAO;IACX,CAAC;IACD,WAAW,GAAG,IAAI,CAAC;IAEnB,uBAAuB,CAAC,IAAI,CAAC,CAAC;IAE9B,qBAAqB,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,sBAAsB,CAAC,MAAM,CAAC,CAAC,CAAC;AACtF,CAAC","sourcesContent":["import { type Nullable } from \"core/types\";\r\nimport { type AbstractMesh } from \"core/Meshes/abstractMesh.pure\";\r\nimport { GaussianSplattingMesh } from \"core/Meshes/GaussianSplatting/gaussianSplattingMesh.pure\";\r\nimport { AllocateShBuffers } from \"core/Meshes/GaussianSplatting/gaussianSplattingMeshBase.pure\";\r\n\r\nimport { MeshPrimitiveMode, type IKHRGaussianSplatting } from \"babylonjs-gltf2interface\";\r\nimport { type IMeshPrimitive, type INode, type IMesh, type IAccessor } from \"../glTFLoaderInterfaces\";\r\nimport { type IGLTFLoaderExtension } from \"../glTFLoaderExtension\";\r\nimport { GLTFLoader, ArrayItem } from \"../glTFLoader.pure\";\r\nimport { registerGLTFExtension, unregisterGLTFExtension } from \"../glTFLoaderExtensionRegistry\";\r\n\r\nconst NAME = \"KHR_gaussian_splatting\";\r\n\r\n// Zeroth-order spherical harmonics coefficient used to reconstruct a base color from the SH DC term.\r\nconst ShC0 = 0.28209479177387814;\r\n\r\n// Attribute semantics defined by the KHR_gaussian_splatting ellipse kernel.\r\nconst RotationAttribute = \"KHR_gaussian_splatting:ROTATION\";\r\nconst ScaleAttribute = \"KHR_gaussian_splatting:SCALE\";\r\nconst OpacityAttribute = \"KHR_gaussian_splatting:OPACITY\";\r\nconst ShDegree0Attribute = \"KHR_gaussian_splatting:SH_DEGREE_0_COEF_0\";\r\n\r\n// Number of spherical harmonics coefficients (VEC3) for each degree beyond the DC term.\r\nconst ShCoefficientCountPerDegree = [0, 3, 5, 7];\r\n\r\nfunction Clamp255(value: number): number {\r\n return value <= 0 ? 0 : value >= 255 ? 255 : (value + 0.5) | 0;\r\n}\r\n\r\n/**\r\n * [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_gaussian_splatting/README.md)\r\n * Loads a mesh primitive tagged with KHR_gaussian_splatting as a {@link GaussianSplattingMesh}.\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class KHR_gaussian_splatting implements IGLTFLoaderExtension {\r\n /**\r\n * The name of this extension.\r\n */\r\n public readonly name = NAME;\r\n\r\n /**\r\n * Defines whether this extension is enabled.\r\n */\r\n public enabled: boolean;\r\n\r\n private _loader: GLTFLoader;\r\n\r\n /**\r\n * @internal\r\n */\r\n constructor(loader: GLTFLoader) {\r\n this._loader = loader;\r\n this.enabled = this._loader.isExtensionUsed(NAME);\r\n }\r\n\r\n /** @internal */\r\n public dispose(): void {\r\n (this._loader as any) = null;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n // eslint-disable-next-line no-restricted-syntax\r\n public _loadMeshPrimitiveAsync(\r\n context: string,\r\n name: string,\r\n node: INode,\r\n mesh: IMesh,\r\n primitive: IMeshPrimitive,\r\n assign: (babylonMesh: AbstractMesh) => void\r\n ): Nullable<Promise<AbstractMesh>> {\r\n return GLTFLoader.LoadExtensionAsync<IKHRGaussianSplatting, AbstractMesh>(context, primitive, this.name, async (extensionContext) => {\r\n if (primitive.mode != undefined && primitive.mode !== MeshPrimitiveMode.POINTS) {\r\n throw new Error(`${extensionContext}: Gaussian splatting primitives must use POINTS mode`);\r\n }\r\n\r\n const loader = this._loader;\r\n\r\n const loadAttribute = (attributeName: string): Nullable<Promise<Float32Array>> => {\r\n const accessorIndex = primitive.attributes[attributeName];\r\n if (accessorIndex == undefined) {\r\n return null;\r\n }\r\n const accessor = ArrayItem.Get(`${context}/attributes/${attributeName}`, loader.gltf.accessors, accessorIndex) as IAccessor;\r\n return loader._loadFloatAccessorAsync(`/accessors/${accessor.index}`, accessor);\r\n };\r\n\r\n const positionsPromise = loadAttribute(\"POSITION\");\r\n if (!positionsPromise) {\r\n throw new Error(`${extensionContext}: Gaussian splatting primitive is missing the POSITION attribute`);\r\n }\r\n\r\n // Determine which spherical harmonics degrees are present (all lower degrees must exist per spec).\r\n let shDegree = 0;\r\n const shAttributeNames: string[] = [];\r\n for (let degree = 1; degree <= 3; degree++) {\r\n if (primitive.attributes[`KHR_gaussian_splatting:SH_DEGREE_${degree}_COEF_0`] == undefined) {\r\n break;\r\n }\r\n shDegree = degree;\r\n for (let coef = 0; coef < ShCoefficientCountPerDegree[degree]; coef++) {\r\n shAttributeNames.push(`KHR_gaussian_splatting:SH_DEGREE_${degree}_COEF_${coef}`);\r\n }\r\n }\r\n\r\n // Create the Gaussian Splatting mesh and assign it to the node synchronously (before awaiting the\r\n // attribute data). The base loader wires the node's transform node from this assign call\r\n // synchronously, so it must happen before the first await. The splat data is uploaded afterwards.\r\n const scene = loader.babylonScene;\r\n scene._blockEntityCollection = !!loader._assetContainer;\r\n const gaussianSplattingMesh = new GaussianSplattingMesh(name, null, scene);\r\n gaussianSplattingMesh._parentContainer = loader._assetContainer;\r\n scene._blockEntityCollection = false;\r\n\r\n GLTFLoader.AddPointerMetadata(gaussianSplattingMesh, context);\r\n loader.parent.onMeshLoadedObservable.notifyObservers(gaussianSplattingMesh);\r\n assign(gaussianSplattingMesh);\r\n\r\n const engineCaps = scene.getEngine().getCaps();\r\n\r\n const [positions, rotations, scales, opacities, shDegree0, colors, ...shHigherDegrees] = await Promise.all([\r\n positionsPromise,\r\n loadAttribute(RotationAttribute),\r\n loadAttribute(ScaleAttribute),\r\n loadAttribute(OpacityAttribute),\r\n loadAttribute(ShDegree0Attribute),\r\n loadAttribute(\"COLOR_0\"),\r\n ...shAttributeNames.map((attributeName): Nullable<Promise<Float32Array>> => loadAttribute(attributeName)),\r\n ]);\r\n\r\n const splatCount = positions.length / 3;\r\n const colorStride = colors ? colors.length / splatCount : 0;\r\n\r\n const rowOutputLength = 3 * 4 + 3 * 4 + 4 + 4; // 32 bytes: position(12) scale(12) color RGBA(4) quaternion wxyz(4)\r\n const buffer = new ArrayBuffer(rowOutputLength * splatCount);\r\n const floatView = new Float32Array(buffer);\r\n const byteView = new Uint8Array(buffer);\r\n\r\n // Build spherical harmonics texture buffers for degrees above 0.\r\n let shBuffers: Nullable<Uint8Array[]> = null;\r\n if (shDegree > 0) {\r\n const shVectorCount = (shDegree + 1) * (shDegree + 1) - 1;\r\n const shComponentCount = shVectorCount * 3;\r\n const textureCount = Math.ceil(shComponentCount / 16);\r\n const width = engineCaps.maxTextureSize;\r\n const height = Math.ceil(splatCount / width);\r\n shBuffers = AllocateShBuffers(textureCount, height * width * 4 * 4);\r\n }\r\n\r\n for (let i = 0; i < splatCount; i++) {\r\n const floatBase = i * 8;\r\n const byteBase = i * 32;\r\n const p = i * 3;\r\n\r\n // Position (float32 x3, bytes 0-11)\r\n floatView[floatBase + 0] = positions[p + 0];\r\n floatView[floatBase + 1] = positions[p + 1];\r\n floatView[floatBase + 2] = positions[p + 2];\r\n\r\n // Scale (float32 x3, bytes 12-23) — glTF stores linear scale directly.\r\n floatView[floatBase + 3] = scales ? scales[p + 0] : 1;\r\n floatView[floatBase + 4] = scales ? scales[p + 1] : 1;\r\n floatView[floatBase + 5] = scales ? scales[p + 2] : 1;\r\n\r\n // Color RGB (uint8 x3, bytes 24-26) — reconstructed from the SH DC term, or COLOR_0 as a fallback.\r\n if (shDegree0) {\r\n byteView[byteBase + 24] = Clamp255((0.5 + ShC0 * shDegree0[p + 0]) * 255);\r\n byteView[byteBase + 25] = Clamp255((0.5 + ShC0 * shDegree0[p + 1]) * 255);\r\n byteView[byteBase + 26] = Clamp255((0.5 + ShC0 * shDegree0[p + 2]) * 255);\r\n } else if (colors) {\r\n const c = i * colorStride;\r\n byteView[byteBase + 24] = Clamp255(colors[c + 0] * 255);\r\n byteView[byteBase + 25] = Clamp255(colors[c + 1] * 255);\r\n byteView[byteBase + 26] = Clamp255(colors[c + 2] * 255);\r\n } else {\r\n byteView[byteBase + 24] = 255;\r\n byteView[byteBase + 25] = 255;\r\n byteView[byteBase + 26] = 255;\r\n }\r\n\r\n // Alpha (uint8, byte 27) — opacity is a normalized linear value per spec.\r\n if (opacities) {\r\n byteView[byteBase + 27] = Clamp255(opacities[i] * 255);\r\n } else if (colors && colorStride >= 4) {\r\n byteView[byteBase + 27] = Clamp255(colors[i * colorStride + 3] * 255);\r\n } else {\r\n byteView[byteBase + 27] = 255;\r\n }\r\n\r\n // Quaternion (uint8 x4, bytes 28-31) stored as wxyz encoded as q * 127.5 + 127.5. glTF stores xyzw.\r\n const r = i * 4;\r\n const qx = rotations ? rotations[r + 0] : 0;\r\n const qy = rotations ? rotations[r + 1] : 0;\r\n const qz = rotations ? rotations[r + 2] : 0;\r\n const qw = rotations ? rotations[r + 3] : 1;\r\n byteView[byteBase + 28] = Clamp255(qw * 127.5 + 127.5);\r\n byteView[byteBase + 29] = Clamp255(qx * 127.5 + 127.5);\r\n byteView[byteBase + 30] = Clamp255(qy * 127.5 + 127.5);\r\n byteView[byteBase + 31] = Clamp255(qz * 127.5 + 127.5);\r\n\r\n // Spherical harmonics (coefficient-major, channel-minor) encoded as coeff * 128 + 128.\r\n if (shBuffers) {\r\n const offsetPerSplat = i * 16;\r\n for (let coef = 0; coef < shHigherDegrees.length; coef++) {\r\n const coefData = shHigherDegrees[coef];\r\n if (!coefData) {\r\n continue;\r\n }\r\n for (let channel = 0; channel < 3; channel++) {\r\n const flatIndex = coef * 3 + channel;\r\n const textureIndex = flatIndex >> 4; // Math.floor(flatIndex / 16)\r\n const byteIndexInTexture = flatIndex & 15; // flatIndex % 16\r\n shBuffers[textureIndex][offsetPerSplat + byteIndexInTexture] = Clamp255(coefData[p + channel] * 128 + 128);\r\n }\r\n }\r\n }\r\n }\r\n\r\n await gaussianSplattingMesh.updateDataAsync(buffer, shBuffers ?? undefined, undefined, shDegree || undefined);\r\n\r\n return gaussianSplattingMesh;\r\n });\r\n }\r\n}\r\n\r\nlet _Registered = false;\r\n/**\r\n * Registers the KHR_gaussian_splatting glTF loader extension.\r\n * Safe to call multiple times; only the first call has an effect.\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport function RegisterKHR_gaussian_splatting(): void {\r\n if (_Registered) {\r\n return;\r\n }\r\n _Registered = true;\r\n\r\n unregisterGLTFExtension(NAME);\r\n\r\n registerGLTFExtension(NAME, true, (loader) => new KHR_gaussian_splatting(loader));\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"KHR_gaussian_splatting.pure.js","sourceRoot":"","sources":["../../../../../../dev/loaders/src/glTF/2.0/Extensions/KHR_gaussian_splatting.pure.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,qBAAqB,EAAE,MAAM,0DAA0D,CAAC;AACjG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type AbstractMesh } from \"core/Meshes/abstractMesh.pure\";\r\nimport { GaussianSplattingMesh } from \"core/Meshes/GaussianSplatting/gaussianSplattingMesh.pure\";\r\nimport { AllocateShBuffers } from \"core/Meshes/GaussianSplatting/gaussianSplattingMeshBase.pure\";\r\n\r\nimport { MeshPrimitiveMode, type IKHRGaussianSplatting } from \"babylonjs-gltf2interface\";\r\nimport { type IMeshPrimitive, type INode, type IMesh, type IAccessor } from \"../glTFLoaderInterfaces\";\r\nimport { type IGLTFLoaderExtension } from \"../glTFLoaderExtension\";\r\nimport { GLTFLoader, ArrayItem } from \"../glTFLoader.pure\";\r\nimport { registerGLTFExtension, unregisterGLTFExtension } from \"../glTFLoaderExtensionRegistry\";\r\n\r\nconst NAME = \"KHR_gaussian_splatting\";\r\n\r\n// Zeroth-order spherical harmonics coefficient used to reconstruct a base color from the SH DC term.\r\nconst ShC0 = 0.28209479177387814;\r\n\r\n// Attribute semantics defined by the KHR_gaussian_splatting ellipse kernel.\r\nconst RotationAttribute = \"KHR_gaussian_splatting:ROTATION\";\r\nconst ScaleAttribute = \"KHR_gaussian_splatting:SCALE\";\r\nconst OpacityAttribute = \"KHR_gaussian_splatting:OPACITY\";\r\nconst ShDegree0Attribute = \"KHR_gaussian_splatting:SH_DEGREE_0_COEF_0\";\r\n\r\n// Number of spherical harmonics coefficients (VEC3) for each degree beyond the DC term.\r\nconst ShCoefficientCountPerDegree = [0, 3, 5, 7];\r\n\r\nfunction Clamp255(value: number): number {\r\n return value <= 0 ? 0 : value >= 255 ? 255 : (value + 0.5) | 0;\r\n}\r\n\r\n/**\r\n * [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_gaussian_splatting/README.md)\r\n * Loads a mesh primitive tagged with KHR_gaussian_splatting as a {@link GaussianSplattingMesh}.\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class KHR_gaussian_splatting implements IGLTFLoaderExtension {\r\n /**\r\n * The name of this extension.\r\n */\r\n public readonly name = NAME;\r\n\r\n /**\r\n * Defines whether this extension is enabled.\r\n */\r\n public enabled: boolean;\r\n\r\n private _loader: GLTFLoader;\r\n\r\n /**\r\n * @internal\r\n */\r\n constructor(loader: GLTFLoader) {\r\n this._loader = loader;\r\n this.enabled = this._loader.isExtensionUsed(NAME);\r\n }\r\n\r\n /** @internal */\r\n public dispose(): void {\r\n (this._loader as any) = null;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n // eslint-disable-next-line no-restricted-syntax\r\n public _loadMeshPrimitiveAsync(\r\n context: string,\r\n name: string,\r\n node: INode,\r\n mesh: IMesh,\r\n primitive: IMeshPrimitive,\r\n assign: (babylonMesh: AbstractMesh) => void\r\n ): Nullable<Promise<AbstractMesh>> {\r\n return GLTFLoader.LoadExtensionAsync<IKHRGaussianSplatting, AbstractMesh>(context, primitive, this.name, async (extensionContext) => {\r\n if (primitive.mode != undefined && primitive.mode !== MeshPrimitiveMode.POINTS) {\r\n throw new Error(`${extensionContext}: Gaussian splatting primitives must use POINTS mode`);\r\n }\r\n\r\n const loader = this._loader;\r\n\r\n const loadAttribute = (attributeName: string): Nullable<Promise<Float32Array>> => {\r\n const accessorIndex = primitive.attributes[attributeName];\r\n if (accessorIndex == undefined) {\r\n return null;\r\n }\r\n const accessor = ArrayItem.Get(`${context}/attributes/${attributeName}`, loader.gltf.accessors, accessorIndex) as IAccessor;\r\n return loader._loadFloatAccessorAsync(`/accessors/${accessor.index}`, accessor);\r\n };\r\n\r\n const positionsPromise = loadAttribute(\"POSITION\");\r\n if (!positionsPromise) {\r\n throw new Error(`${extensionContext}: Gaussian splatting primitive is missing the POSITION attribute`);\r\n }\r\n\r\n // Determine which spherical harmonics degrees are present (all lower degrees must exist per spec).\r\n let shDegree = 0;\r\n const shAttributeNames: string[] = [];\r\n for (let degree = 1; degree <= 3; degree++) {\r\n if (primitive.attributes[`KHR_gaussian_splatting:SH_DEGREE_${degree}_COEF_0`] == undefined) {\r\n break;\r\n }\r\n shDegree = degree;\r\n for (let coef = 0; coef < ShCoefficientCountPerDegree[degree]; coef++) {\r\n shAttributeNames.push(`KHR_gaussian_splatting:SH_DEGREE_${degree}_COEF_${coef}`);\r\n }\r\n }\r\n\r\n // Create the Gaussian Splatting mesh and assign it to the node synchronously (before awaiting the\r\n // attribute data). The base loader wires the node's transform node from this assign call\r\n // synchronously, so it must happen before the first await. The splat data is uploaded afterwards.\r\n const scene = loader.babylonScene;\r\n const gaussianSplattingMesh = scene._executeWithBlockedEntityCollection(!!loader._assetContainer, () => new GaussianSplattingMesh(name, null, scene));\r\n gaussianSplattingMesh._parentContainer = loader._assetContainer;\r\n\r\n GLTFLoader.AddPointerMetadata(gaussianSplattingMesh, context);\r\n loader.parent.onMeshLoadedObservable.notifyObservers(gaussianSplattingMesh);\r\n assign(gaussianSplattingMesh);\r\n\r\n const engineCaps = scene.getEngine().getCaps();\r\n\r\n const [positions, rotations, scales, opacities, shDegree0, colors, ...shHigherDegrees] = await Promise.all([\r\n positionsPromise,\r\n loadAttribute(RotationAttribute),\r\n loadAttribute(ScaleAttribute),\r\n loadAttribute(OpacityAttribute),\r\n loadAttribute(ShDegree0Attribute),\r\n loadAttribute(\"COLOR_0\"),\r\n ...shAttributeNames.map((attributeName): Nullable<Promise<Float32Array>> => loadAttribute(attributeName)),\r\n ]);\r\n\r\n const splatCount = positions.length / 3;\r\n const colorStride = colors ? colors.length / splatCount : 0;\r\n\r\n const rowOutputLength = 3 * 4 + 3 * 4 + 4 + 4; // 32 bytes: position(12) scale(12) color RGBA(4) quaternion wxyz(4)\r\n const buffer = new ArrayBuffer(rowOutputLength * splatCount);\r\n const floatView = new Float32Array(buffer);\r\n const byteView = new Uint8Array(buffer);\r\n\r\n // Build spherical harmonics texture buffers for degrees above 0.\r\n let shBuffers: Nullable<Uint8Array[]> = null;\r\n if (shDegree > 0) {\r\n const shVectorCount = (shDegree + 1) * (shDegree + 1) - 1;\r\n const shComponentCount = shVectorCount * 3;\r\n const textureCount = Math.ceil(shComponentCount / 16);\r\n const width = engineCaps.maxTextureSize;\r\n const height = Math.ceil(splatCount / width);\r\n shBuffers = AllocateShBuffers(textureCount, height * width * 4 * 4);\r\n }\r\n\r\n for (let i = 0; i < splatCount; i++) {\r\n const floatBase = i * 8;\r\n const byteBase = i * 32;\r\n const p = i * 3;\r\n\r\n // Position (float32 x3, bytes 0-11)\r\n floatView[floatBase + 0] = positions[p + 0];\r\n floatView[floatBase + 1] = positions[p + 1];\r\n floatView[floatBase + 2] = positions[p + 2];\r\n\r\n // Scale (float32 x3, bytes 12-23) — glTF stores linear scale directly.\r\n floatView[floatBase + 3] = scales ? scales[p + 0] : 1;\r\n floatView[floatBase + 4] = scales ? scales[p + 1] : 1;\r\n floatView[floatBase + 5] = scales ? scales[p + 2] : 1;\r\n\r\n // Color RGB (uint8 x3, bytes 24-26) — reconstructed from the SH DC term, or COLOR_0 as a fallback.\r\n if (shDegree0) {\r\n byteView[byteBase + 24] = Clamp255((0.5 + ShC0 * shDegree0[p + 0]) * 255);\r\n byteView[byteBase + 25] = Clamp255((0.5 + ShC0 * shDegree0[p + 1]) * 255);\r\n byteView[byteBase + 26] = Clamp255((0.5 + ShC0 * shDegree0[p + 2]) * 255);\r\n } else if (colors) {\r\n const c = i * colorStride;\r\n byteView[byteBase + 24] = Clamp255(colors[c + 0] * 255);\r\n byteView[byteBase + 25] = Clamp255(colors[c + 1] * 255);\r\n byteView[byteBase + 26] = Clamp255(colors[c + 2] * 255);\r\n } else {\r\n byteView[byteBase + 24] = 255;\r\n byteView[byteBase + 25] = 255;\r\n byteView[byteBase + 26] = 255;\r\n }\r\n\r\n // Alpha (uint8, byte 27) — opacity is a normalized linear value per spec.\r\n if (opacities) {\r\n byteView[byteBase + 27] = Clamp255(opacities[i] * 255);\r\n } else if (colors && colorStride >= 4) {\r\n byteView[byteBase + 27] = Clamp255(colors[i * colorStride + 3] * 255);\r\n } else {\r\n byteView[byteBase + 27] = 255;\r\n }\r\n\r\n // Quaternion (uint8 x4, bytes 28-31) stored as wxyz encoded as q * 127.5 + 127.5. glTF stores xyzw.\r\n const r = i * 4;\r\n const qx = rotations ? rotations[r + 0] : 0;\r\n const qy = rotations ? rotations[r + 1] : 0;\r\n const qz = rotations ? rotations[r + 2] : 0;\r\n const qw = rotations ? rotations[r + 3] : 1;\r\n byteView[byteBase + 28] = Clamp255(qw * 127.5 + 127.5);\r\n byteView[byteBase + 29] = Clamp255(qx * 127.5 + 127.5);\r\n byteView[byteBase + 30] = Clamp255(qy * 127.5 + 127.5);\r\n byteView[byteBase + 31] = Clamp255(qz * 127.5 + 127.5);\r\n\r\n // Spherical harmonics (coefficient-major, channel-minor) encoded as coeff * 128 + 128.\r\n if (shBuffers) {\r\n const offsetPerSplat = i * 16;\r\n for (let coef = 0; coef < shHigherDegrees.length; coef++) {\r\n const coefData = shHigherDegrees[coef];\r\n if (!coefData) {\r\n continue;\r\n }\r\n for (let channel = 0; channel < 3; channel++) {\r\n const flatIndex = coef * 3 + channel;\r\n const textureIndex = flatIndex >> 4; // Math.floor(flatIndex / 16)\r\n const byteIndexInTexture = flatIndex & 15; // flatIndex % 16\r\n shBuffers[textureIndex][offsetPerSplat + byteIndexInTexture] = Clamp255(coefData[p + channel] * 128 + 128);\r\n }\r\n }\r\n }\r\n }\r\n\r\n await gaussianSplattingMesh.updateDataAsync(buffer, shBuffers ?? undefined, undefined, shDegree || undefined);\r\n\r\n return gaussianSplattingMesh;\r\n });\r\n }\r\n}\r\n\r\nlet _Registered = false;\r\n/**\r\n * Registers the KHR_gaussian_splatting glTF loader extension.\r\n * Safe to call multiple times; only the first call has an effect.\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport function RegisterKHR_gaussian_splatting(): void {\r\n if (_Registered) {\r\n return;\r\n }\r\n _Registered = true;\r\n\r\n unregisterGLTFExtension(NAME);\r\n\r\n registerGLTFExtension(NAME, true, (loader) => new KHR_gaussian_splatting(loader));\r\n}\r\n"]}
|
|
@@ -195,7 +195,14 @@ export declare class KHRInteractivityExportPlan implements IKHRInteractivityExpo
|
|
|
195
195
|
* @returns canonical KHR_interactivity payload
|
|
196
196
|
*/
|
|
197
197
|
build(context: IKHRInteractivitySerializerContext): IKHRInteractivity;
|
|
198
|
+
/**
|
|
199
|
+
* Builds a graph for patching the original glTF document using its existing entity indices.
|
|
200
|
+
* Companion node extensions are already present in that document and are retained by the patcher.
|
|
201
|
+
* @returns canonical KHR_interactivity payload with source glTF indices
|
|
202
|
+
*/
|
|
203
|
+
buildWithSourceIndices(): IKHRInteractivity;
|
|
198
204
|
private _getSourceGraph;
|
|
205
|
+
private _createSourceIndexContext;
|
|
199
206
|
private _validateBuildWithSourceIndices;
|
|
200
207
|
private _analyzeGraphs;
|
|
201
208
|
private _classifyStandaloneBlock;
|
|
@@ -489,6 +489,17 @@ export class KHRInteractivityExportPlan {
|
|
|
489
489
|
}
|
|
490
490
|
return source;
|
|
491
491
|
}
|
|
492
|
+
/**
|
|
493
|
+
* Builds a graph for patching the original glTF document using its existing entity indices.
|
|
494
|
+
* Companion node extensions are already present in that document and are retained by the patcher.
|
|
495
|
+
* @returns canonical KHR_interactivity payload with source glTF indices
|
|
496
|
+
*/
|
|
497
|
+
buildWithSourceIndices() {
|
|
498
|
+
if (!this._options.sourceGLTF) {
|
|
499
|
+
throw new Error("Source glTF data is required to retain entity indices.");
|
|
500
|
+
}
|
|
501
|
+
return this.build(this._createSourceIndexContext());
|
|
502
|
+
}
|
|
492
503
|
_getSourceGraph(graph, graphIndex) {
|
|
493
504
|
const documentGraph = this._options.document?.graphs[graphIndex]?.source;
|
|
494
505
|
if (documentGraph) {
|
|
@@ -497,11 +508,10 @@ export class KHRInteractivityExportPlan {
|
|
|
497
508
|
const provenance = graph.metadata?.khrInteractivity;
|
|
498
509
|
return provenance?.source ? CloneKHRInteractivityGraph(provenance.source) : undefined;
|
|
499
510
|
}
|
|
500
|
-
|
|
501
|
-
const diagnostics = [];
|
|
511
|
+
_createSourceIndexContext() {
|
|
502
512
|
const sourceGLTF = this._options.sourceGLTF;
|
|
503
513
|
const indexOrUndefined = (index) => (index !== undefined && index >= 0 ? index : undefined);
|
|
504
|
-
|
|
514
|
+
return {
|
|
505
515
|
getNodeCount: () => sourceGLTF?.nodes?.length ?? 0,
|
|
506
516
|
getNodeIndex: (node) => indexOrUndefined(sourceGLTF?.nodes?.findIndex((candidate) => candidate._babylonTransformNode === node)),
|
|
507
517
|
getAnimationIndex: (animation) => indexOrUndefined(sourceGLTF?.animations?.findIndex((candidate) => candidate._babylonAnimationGroup === animation)),
|
|
@@ -510,6 +520,10 @@ export class KHRInteractivityExportPlan {
|
|
|
510
520
|
getRootIndex: (collection, entity) => this._getSourceRootIndex(collection, entity),
|
|
511
521
|
setNodeExtension: () => { },
|
|
512
522
|
};
|
|
523
|
+
}
|
|
524
|
+
_validateBuildWithSourceIndices() {
|
|
525
|
+
const diagnostics = [];
|
|
526
|
+
const context = this._createSourceIndexContext();
|
|
513
527
|
this._isPreflight = true;
|
|
514
528
|
try {
|
|
515
529
|
for (const analysis of this._graphAnalyses) {
|