@onerjs/core 8.50.6 → 8.50.8

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.
Files changed (79) hide show
  1. package/AudioV2/abstractAudio/abstractSound.d.ts +1 -0
  2. package/AudioV2/abstractAudio/abstractSound.js +9 -0
  3. package/AudioV2/abstractAudio/abstractSound.js.map +1 -1
  4. package/AudioV2/abstractAudio/audioEngineV2.d.ts +6 -0
  5. package/AudioV2/abstractAudio/audioEngineV2.js +8 -0
  6. package/AudioV2/abstractAudio/audioEngineV2.js.map +1 -1
  7. package/AudioV2/webAudio/webAudioEngine.d.ts +2 -0
  8. package/AudioV2/webAudio/webAudioEngine.js +29 -2
  9. package/AudioV2/webAudio/webAudioEngine.js.map +1 -1
  10. package/Engines/Native/nativeHelpers.js +26 -0
  11. package/Engines/Native/nativeHelpers.js.map +1 -1
  12. package/Engines/WebGPU/webgpuTextureHelper.js +26 -0
  13. package/Engines/WebGPU/webgpuTextureHelper.js.map +1 -1
  14. package/Engines/abstractEngine.js +2 -2
  15. package/Engines/abstractEngine.js.map +1 -1
  16. package/Engines/constants.d.ts +52 -0
  17. package/Engines/constants.js +52 -0
  18. package/Engines/constants.js.map +1 -1
  19. package/Engines/engine.d.ts +15 -2
  20. package/Engines/thinEngine.js +52 -0
  21. package/Engines/thinEngine.js.map +1 -1
  22. package/FrameGraph/frameGraphTextureManager.js +26 -0
  23. package/FrameGraph/frameGraphTextureManager.js.map +1 -1
  24. package/Loading/Plugins/babylonFileLoader.js +14 -0
  25. package/Loading/Plugins/babylonFileLoader.js.map +1 -1
  26. package/Materials/PBR/openpbrMaterial.d.ts +11 -0
  27. package/Materials/PBR/openpbrMaterial.js +56 -9
  28. package/Materials/PBR/openpbrMaterial.js.map +1 -1
  29. package/Materials/Textures/Loaders/ktxTextureLoader.js +26 -0
  30. package/Materials/Textures/Loaders/ktxTextureLoader.js.map +1 -1
  31. package/Materials/material.d.ts +16 -1
  32. package/Materials/material.js +16 -1
  33. package/Materials/material.js.map +1 -1
  34. package/Meshes/Builders/polygonBuilder.d.ts +1 -0
  35. package/Meshes/Builders/polygonBuilder.js +27 -20
  36. package/Meshes/Builders/polygonBuilder.js.map +1 -1
  37. package/Meshes/GaussianSplatting/gaussianSplattingMesh.d.ts +1 -1
  38. package/Meshes/GaussianSplatting/gaussianSplattingMesh.js +16 -18
  39. package/Meshes/GaussianSplatting/gaussianSplattingMesh.js.map +1 -1
  40. package/Meshes/GaussianSplatting/gaussianSplattingMeshBase.d.ts +24 -0
  41. package/Meshes/GaussianSplatting/gaussianSplattingMeshBase.js +93 -18
  42. package/Meshes/GaussianSplatting/gaussianSplattingMeshBase.js.map +1 -1
  43. package/Meshes/mesh.js +3 -0
  44. package/Meshes/mesh.js.map +1 -1
  45. package/Meshes/transformNode.d.ts +6 -0
  46. package/Meshes/transformNode.js +6 -0
  47. package/Meshes/transformNode.js.map +1 -1
  48. package/Misc/snapshotRenderingHelper.d.ts +7 -1
  49. package/Misc/snapshotRenderingHelper.js +7 -1
  50. package/Misc/snapshotRenderingHelper.js.map +1 -1
  51. package/Misc/stringTools.js +2 -2
  52. package/Misc/stringTools.js.map +1 -1
  53. package/Misc/textureTools.js +26 -0
  54. package/Misc/textureTools.js.map +1 -1
  55. package/Misc/tools.js +1 -1
  56. package/Misc/tools.js.map +1 -1
  57. package/Shaders/ShadersInclude/hdrFilteringFunctions.js +1 -1
  58. package/Shaders/ShadersInclude/hdrFilteringFunctions.js.map +1 -1
  59. package/Shaders/ShadersInclude/openpbrBackgroundTransmission.js +1 -1
  60. package/Shaders/ShadersInclude/openpbrBackgroundTransmission.js.map +1 -1
  61. package/Shaders/ShadersInclude/openpbrDirectLighting.js +18 -10
  62. package/Shaders/ShadersInclude/openpbrDirectLighting.js.map +1 -1
  63. package/Shaders/ShadersInclude/openpbrEnvironmentLighting.js +34 -12
  64. package/Shaders/ShadersInclude/openpbrEnvironmentLighting.js.map +1 -1
  65. package/Shaders/openpbr.fragment.js +14 -15
  66. package/Shaders/openpbr.fragment.js.map +1 -1
  67. package/ShadersWGSL/ShadersInclude/hdrFilteringFunctions.js +1 -1
  68. package/ShadersWGSL/ShadersInclude/hdrFilteringFunctions.js.map +1 -1
  69. package/ShadersWGSL/ShadersInclude/openpbrBackgroundTransmission.js +1 -1
  70. package/ShadersWGSL/ShadersInclude/openpbrBackgroundTransmission.js.map +1 -1
  71. package/ShadersWGSL/ShadersInclude/openpbrDirectLighting.js +19 -11
  72. package/ShadersWGSL/ShadersInclude/openpbrDirectLighting.js.map +1 -1
  73. package/ShadersWGSL/ShadersInclude/openpbrDirectLightingInit.js +3 -3
  74. package/ShadersWGSL/ShadersInclude/openpbrDirectLightingInit.js.map +1 -1
  75. package/ShadersWGSL/ShadersInclude/openpbrEnvironmentLighting.js +34 -12
  76. package/ShadersWGSL/ShadersInclude/openpbrEnvironmentLighting.js.map +1 -1
  77. package/ShadersWGSL/openpbr.fragment.js +14 -15
  78. package/ShadersWGSL/openpbr.fragment.js.map +1 -1
  79. package/package.json +1 -1
@@ -139,29 +139,36 @@ export function CreatePolygon(name, options, scene = null, earcutInjection = ear
139
139
  const holes = options.holes || [];
140
140
  const depth = options.depth || 0;
141
141
  const smoothingThreshold = options.smoothingThreshold || 2;
142
- const contours = [];
143
- let hole;
144
- for (let i = 0; i < shape.length; i++) {
145
- contours[i] = new Vector2(shape[i].x, shape[i].z);
142
+ if (options.instance) {
143
+ const vertexData = CreatePolygonVertexData(options.instance, options.sideOrientation, options.faceUV, options.faceColors, options.frontUVs, options.backUVs, options.wrap);
144
+ vertexData.applyToMesh(options.instance, options.updatable);
145
+ return options.instance;
146
146
  }
147
- const epsilon = 0.00000001;
148
- if (contours[0].equalsWithEpsilon(contours[contours.length - 1], epsilon)) {
149
- contours.pop();
150
- }
151
- const polygonTriangulation = new PolygonMeshBuilder(name, contours, scene || EngineStore.LastCreatedScene, earcutInjection);
152
- for (let hNb = 0; hNb < holes.length; hNb++) {
153
- hole = [];
154
- for (let hPoint = 0; hPoint < holes[hNb].length; hPoint++) {
155
- hole.push(new Vector2(holes[hNb][hPoint].x, holes[hNb][hPoint].z));
147
+ else {
148
+ const contours = [];
149
+ let hole;
150
+ for (let i = 0; i < shape.length; i++) {
151
+ contours[i] = new Vector2(shape[i].x, shape[i].z);
152
+ }
153
+ const epsilon = 0.00000001;
154
+ if (contours[0].equalsWithEpsilon(contours[contours.length - 1], epsilon)) {
155
+ contours.pop();
156
+ }
157
+ const polygonTriangulation = new PolygonMeshBuilder(name, contours, scene || EngineStore.LastCreatedScene, earcutInjection);
158
+ for (let hNb = 0; hNb < holes.length; hNb++) {
159
+ hole = [];
160
+ for (let hPoint = 0; hPoint < holes[hNb].length; hPoint++) {
161
+ hole.push(new Vector2(holes[hNb][hPoint].x, holes[hNb][hPoint].z));
162
+ }
163
+ polygonTriangulation.addHole(hole);
156
164
  }
157
- polygonTriangulation.addHole(hole);
165
+ //updatability is set during applyToMesh; setting to true in triangulation build produces errors
166
+ const polygon = polygonTriangulation.build(false, depth, smoothingThreshold);
167
+ polygon._originalBuilderSideOrientation = options.sideOrientation;
168
+ const vertexData = CreatePolygonVertexData(polygon, options.sideOrientation, options.faceUV, options.faceColors, options.frontUVs, options.backUVs, options.wrap);
169
+ vertexData.applyToMesh(polygon, options.updatable);
170
+ return polygon;
158
171
  }
159
- //updatability is set during applyToMesh; setting to true in triangulation build produces errors
160
- const polygon = polygonTriangulation.build(false, depth, smoothingThreshold);
161
- polygon._originalBuilderSideOrientation = options.sideOrientation;
162
- const vertexData = CreatePolygonVertexData(polygon, options.sideOrientation, options.faceUV, options.faceColors, options.frontUVs, options.backUVs, options.wrap);
163
- vertexData.applyToMesh(polygon, options.updatable);
164
- return polygon;
165
172
  }
166
173
  /**
167
174
  * Creates an extruded polygon mesh, with depth in the Y direction.
@@ -1 +1 @@
1
- {"version":3,"file":"polygonBuilder.js","sourceRoot":"","sources":["../../../../../dev/core/src/Meshes/Builders/polygonBuilder.ts"],"names":[],"mappings":"A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,MAAM,cAAc,GAAG;IAC1B,cAAc;IACd,aAAa;CAChB,CAAC;AAEF,UAAU,CAAC,aAAa,GAAG,uBAAuB,CAAC;AACnD,IAAI,CAAC,aAAa,GAAG,CAAC,IAAY,EAAE,KAAgB,EAAE,KAAY,EAAE,KAAmB,EAAE,SAAmB,EAAE,eAAwB,EAAE,eAAe,GAAG,MAAM,EAAQ,EAAE;IACtK,MAAM,OAAO,GAAG;QACZ,KAAK,EAAE,KAAK;QACZ,KAAK,EAAE,KAAK;QACZ,SAAS,EAAE,SAAS;QACpB,eAAe,EAAE,eAAe;KACnC,CAAC;IACF,OAAO,aAAa,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,eAAe,CAAC,CAAC;AAChE,CAAC,CAAC;AAEF,IAAI,CAAC,cAAc,GAAG,CAClB,IAAY,EACZ,KAAgB,EAChB,KAAa,EACb,KAAY,EACZ,KAAmB,EACnB,SAAmB,EACnB,eAAwB,EACxB,eAAe,GAAG,MAAM,EACpB,EAAE;IACN,MAAM,OAAO,GAAG;QACZ,KAAK,EAAE,KAAK;QACZ,KAAK,EAAE,KAAK;QACZ,KAAK,EAAE,KAAK;QACZ,SAAS,EAAE,SAAS;QACpB,eAAe,EAAE,eAAe;KACnC,CAAC;IACF,OAAO,cAAc,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,eAAe,CAAC,CAAC;AACjE,CAAC,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\r\nimport { type Scene } from \"../../scene\";\r\nimport { type Vector3, Vector2, Vector4 } from \"../../Maths/math.vector\";\r\nimport { Color4 } from \"../../Maths/math.color\";\r\nimport { Mesh } from \"../mesh\";\r\nimport { VertexData } from \"../mesh.vertexData\";\r\nimport { PolygonMeshBuilder } from \"../polygonMesh\";\r\nimport { type FloatArray, type IndicesArray, type Nullable } from \"../../types\";\r\nimport { VertexBuffer } from \"../../Buffers/buffer\";\r\nimport { EngineStore } from \"../../Engines/engineStore\";\r\nimport { useOpenGLOrientationForUV } from \"../../Compat/compatibilityOptions\";\r\n\r\ndeclare let earcut: any;\r\n\r\n/**\r\n * Creates the VertexData for an irregular Polygon in the XoZ plane using a mesh built by polygonTriangulation.build()\r\n * All parameters are provided by CreatePolygon as needed\r\n * @param polygon a mesh built from polygonTriangulation.build()\r\n * @param sideOrientation takes the values Mesh.FRONTSIDE (default), Mesh.BACKSIDE or Mesh.DOUBLESIDE\r\n * @param fUV an array of Vector4 elements used to set different images to the top, rings and bottom respectively\r\n * @param fColors an array of Color3 elements used to set different colors to the top, rings and bottom respectively\r\n * @param frontUVs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the front side, optional, default vector4 (0, 0, 1, 1)\r\n * @param backUVs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the back side, optional, default vector4 (0, 0, 1, 1)\r\n * @param wrp a boolean, default false, when true and fUVs used texture is wrapped around all sides, when false texture is applied side\r\n * @returns the VertexData of the Polygon\r\n */\r\nexport function CreatePolygonVertexData(polygon: Mesh, sideOrientation: number, fUV?: Vector4[], fColors?: Color4[], frontUVs?: Vector4, backUVs?: Vector4, wrp?: boolean) {\r\n const faceUV: Vector4[] = fUV || new Array<Vector4>(3);\r\n const faceColors = fColors;\r\n const colors = [];\r\n const wrap: boolean = wrp || false;\r\n\r\n // default face colors and UV if undefined\r\n for (let f = 0; f < 3; f++) {\r\n if (faceUV[f] === undefined) {\r\n faceUV[f] = new Vector4(0, 0, 1, 1);\r\n }\r\n if (faceColors && faceColors[f] === undefined) {\r\n faceColors[f] = new Color4(1, 1, 1, 1);\r\n }\r\n }\r\n\r\n const positions = <FloatArray>polygon.getVerticesData(VertexBuffer.PositionKind);\r\n const normals = <FloatArray>polygon.getVerticesData(VertexBuffer.NormalKind);\r\n const uvs = <FloatArray>polygon.getVerticesData(VertexBuffer.UVKind);\r\n const indices = <IndicesArray>polygon.getIndices();\r\n const startIndex = positions.length / 9;\r\n let disp: number;\r\n let distX: number;\r\n let distZ: number;\r\n let dist: number;\r\n let totalLen = 0;\r\n const cumulate = [0];\r\n if (wrap) {\r\n for (let idx = startIndex; idx < positions.length / 3; idx += 4) {\r\n distX = positions[3 * (idx + 2)] - positions[3 * idx];\r\n distZ = positions[3 * (idx + 2) + 2] - positions[3 * idx + 2];\r\n dist = Math.sqrt(distX * distX + distZ * distZ);\r\n totalLen += dist;\r\n cumulate.push(totalLen);\r\n }\r\n }\r\n // set face colours and textures\r\n let idx: number;\r\n let face: number = 0;\r\n for (let index = 0; index < normals.length; index += 3) {\r\n //Edge Face no. 1\r\n if (Math.abs(normals[index + 1]) < 0.001) {\r\n face = 1;\r\n }\r\n //Top Face no. 0\r\n if (Math.abs(normals[index + 1] - 1) < 0.001) {\r\n face = 0;\r\n }\r\n //Bottom Face no. 2\r\n if (Math.abs(normals[index + 1] + 1) < 0.001) {\r\n face = 2;\r\n }\r\n idx = index / 3;\r\n if (face === 1) {\r\n disp = idx - startIndex;\r\n if (disp % 4 < 1.5) {\r\n if (wrap) {\r\n uvs[2 * idx] = faceUV[face].x + ((faceUV[face].z - faceUV[face].x) * cumulate[Math.floor(disp / 4)]) / totalLen;\r\n } else {\r\n uvs[2 * idx] = faceUV[face].x;\r\n }\r\n } else {\r\n if (wrap) {\r\n uvs[2 * idx] = faceUV[face].x + ((faceUV[face].z - faceUV[face].x) * cumulate[Math.floor(disp / 4) + 1]) / totalLen;\r\n } else {\r\n uvs[2 * idx] = faceUV[face].z;\r\n }\r\n }\r\n if (disp % 2 === 0) {\r\n uvs[2 * idx + 1] = useOpenGLOrientationForUV ? 1.0 - faceUV[face].w : faceUV[face].w;\r\n } else {\r\n uvs[2 * idx + 1] = useOpenGLOrientationForUV ? 1.0 - faceUV[face].y : faceUV[face].y;\r\n }\r\n } else {\r\n uvs[2 * idx] = (1 - uvs[2 * idx]) * faceUV[face].x + uvs[2 * idx] * faceUV[face].z;\r\n uvs[2 * idx + 1] = (1 - uvs[2 * idx + 1]) * faceUV[face].y + uvs[2 * idx + 1] * faceUV[face].w;\r\n\r\n if (useOpenGLOrientationForUV) {\r\n uvs[2 * idx + 1] = 1.0 - uvs[2 * idx + 1];\r\n }\r\n }\r\n if (faceColors) {\r\n colors.push(faceColors[face].r, faceColors[face].g, faceColors[face].b, faceColors[face].a);\r\n }\r\n }\r\n\r\n // sides\r\n VertexData._ComputeSides(sideOrientation, positions, indices, normals, uvs, frontUVs, backUVs);\r\n\r\n // Result\r\n const vertexData = new VertexData();\r\n vertexData.indices = indices;\r\n vertexData.positions = positions;\r\n vertexData.normals = normals;\r\n vertexData.uvs = uvs;\r\n\r\n if (faceColors) {\r\n const totalColors = sideOrientation === VertexData.DOUBLESIDE ? colors.concat(colors) : colors;\r\n vertexData.colors = totalColors;\r\n }\r\n\r\n return vertexData;\r\n}\r\n\r\n/**\r\n * Creates a polygon mesh\r\n * The polygon's shape will depend on the input parameters and is constructed parallel to a ground mesh\r\n * * The parameter `shape` is a required array of successive Vector3 representing the corners of the polygon in th XoZ plane, that is y = 0 for all vectors\r\n * * You can set the mesh side orientation with the values : Mesh.FRONTSIDE (default), Mesh.BACKSIDE or Mesh.DOUBLESIDE\r\n * * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created\r\n * * If you create a double-sided mesh, you can choose what parts of the texture image to crop and stick respectively on the front and the back sides with the parameters `frontUVs` and `backUVs` (Vector4)\r\n * * Remember you can only change the shape positions, not their number when updating a polygon\r\n * @param name defines the name of the mesh\r\n * @param options defines the options used to create the mesh\r\n * @param scene defines the hosting scene\r\n * @param earcutInjection can be used to inject your own earcut reference\r\n * @returns the polygon mesh\r\n */\r\nexport function CreatePolygon(\r\n name: string,\r\n options: {\r\n shape: Vector3[];\r\n holes?: Vector3[][];\r\n depth?: number;\r\n smoothingThreshold?: number;\r\n faceUV?: Vector4[];\r\n faceColors?: Color4[];\r\n updatable?: boolean;\r\n sideOrientation?: number;\r\n frontUVs?: Vector4;\r\n backUVs?: Vector4;\r\n wrap?: boolean;\r\n },\r\n scene: Nullable<Scene> = null,\r\n earcutInjection = earcut\r\n): Mesh {\r\n options.sideOrientation = Mesh._GetDefaultSideOrientation(options.sideOrientation);\r\n const shape = options.shape;\r\n const holes = options.holes || [];\r\n const depth = options.depth || 0;\r\n const smoothingThreshold = options.smoothingThreshold || 2;\r\n const contours: Array<Vector2> = [];\r\n let hole: Array<Vector2>;\r\n\r\n for (let i = 0; i < shape.length; i++) {\r\n contours[i] = new Vector2(shape[i].x, shape[i].z);\r\n }\r\n const epsilon = 0.00000001;\r\n if (contours[0].equalsWithEpsilon(contours[contours.length - 1], epsilon)) {\r\n contours.pop();\r\n }\r\n\r\n const polygonTriangulation = new PolygonMeshBuilder(name, contours, scene || EngineStore.LastCreatedScene!, earcutInjection);\r\n for (let hNb = 0; hNb < holes.length; hNb++) {\r\n hole = [];\r\n for (let hPoint = 0; hPoint < holes[hNb].length; hPoint++) {\r\n hole.push(new Vector2(holes[hNb][hPoint].x, holes[hNb][hPoint].z));\r\n }\r\n polygonTriangulation.addHole(hole);\r\n }\r\n //updatability is set during applyToMesh; setting to true in triangulation build produces errors\r\n const polygon = polygonTriangulation.build(false, depth, smoothingThreshold);\r\n polygon._originalBuilderSideOrientation = options.sideOrientation;\r\n const vertexData = CreatePolygonVertexData(polygon, options.sideOrientation, options.faceUV, options.faceColors, options.frontUVs, options.backUVs, options.wrap);\r\n vertexData.applyToMesh(polygon, options.updatable);\r\n\r\n return polygon;\r\n}\r\n\r\n/**\r\n * Creates an extruded polygon mesh, with depth in the Y direction.\r\n * * You can set different colors and different images to the top, bottom and extruded side by using the parameters `faceColors` (an array of 3 Color3 elements) and `faceUV` (an array of 3 Vector4 elements)\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/materials/using/texturePerBoxFace\r\n * @param name defines the name of the mesh\r\n * @param options defines the options used to create the mesh\r\n * @param scene defines the hosting scene\r\n * @param earcutInjection can be used to inject your own earcut reference\r\n * @returns the polygon mesh\r\n */\r\nexport function ExtrudePolygon(\r\n name: string,\r\n options: {\r\n shape: Vector3[];\r\n holes?: Vector3[][];\r\n depth?: number;\r\n faceUV?: Vector4[];\r\n faceColors?: Color4[];\r\n updatable?: boolean;\r\n sideOrientation?: number;\r\n frontUVs?: Vector4;\r\n backUVs?: Vector4;\r\n wrap?: boolean;\r\n },\r\n scene: Nullable<Scene> = null,\r\n earcutInjection = earcut\r\n): Mesh {\r\n return CreatePolygon(name, options, scene, earcutInjection);\r\n}\r\n/**\r\n * Class containing static functions to help procedurally build meshes\r\n * @deprecated use the functions directly from the module\r\n */\r\nexport const PolygonBuilder = {\r\n ExtrudePolygon,\r\n CreatePolygon,\r\n};\r\n\r\nVertexData.CreatePolygon = CreatePolygonVertexData;\r\nMesh.CreatePolygon = (name: string, shape: Vector3[], scene: Scene, holes?: Vector3[][], updatable?: boolean, sideOrientation?: number, earcutInjection = earcut): Mesh => {\r\n const options = {\r\n shape: shape,\r\n holes: holes,\r\n updatable: updatable,\r\n sideOrientation: sideOrientation,\r\n };\r\n return CreatePolygon(name, options, scene, earcutInjection);\r\n};\r\n\r\nMesh.ExtrudePolygon = (\r\n name: string,\r\n shape: Vector3[],\r\n depth: number,\r\n scene: Scene,\r\n holes?: Vector3[][],\r\n updatable?: boolean,\r\n sideOrientation?: number,\r\n earcutInjection = earcut\r\n): Mesh => {\r\n const options = {\r\n shape: shape,\r\n holes: holes,\r\n depth: depth,\r\n updatable: updatable,\r\n sideOrientation: sideOrientation,\r\n };\r\n return ExtrudePolygon(name, options, scene, earcutInjection);\r\n};\r\n"]}
1
+ {"version":3,"file":"polygonBuilder.js","sourceRoot":"","sources":["../../../../../dev/core/src/Meshes/Builders/polygonBuilder.ts"],"names":[],"mappings":"AAEA,OAAO,EAAgB,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AACzE,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAChD,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAC/B,OAAO,EAAE,UAAU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AAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,cAAc,CAC1B,IAAY,EACZ,OAWC,EACD,QAAyB,IAAI,EAC7B,eAAe,GAAG,MAAM;IAExB,OAAO,aAAa,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,eAAe,CAAC,CAAC;AAChE,CAAC;AACD;;;GAGG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG;IAC1B,cAAc;IACd,aAAa;CAChB,CAAC;AAEF,UAAU,CAAC,aAAa,GAAG,uBAAuB,CAAC;AACnD,IAAI,CAAC,aAAa,GAAG,CAAC,IAAY,EAAE,KAAgB,EAAE,KAAY,EAAE,KAAmB,EAAE,SAAmB,EAAE,eAAwB,EAAE,eAAe,GAAG,MAAM,EAAQ,EAAE;IACtK,MAAM,OAAO,GAAG;QACZ,KAAK,EAAE,KAAK;QACZ,KAAK,EAAE,KAAK;QACZ,SAAS,EAAE,SAAS;QACpB,eAAe,EAAE,eAAe;KACnC,CAAC;IACF,OAAO,aAAa,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,eAAe,CAAC,CAAC;AAChE,CAAC,CAAC;AAEF,IAAI,CAAC,cAAc,GAAG,CAClB,IAAY,EACZ,KAAgB,EAChB,KAAa,EACb,KAAY,EACZ,KAAmB,EACnB,SAAmB,EACnB,eAAwB,EACxB,eAAe,GAAG,MAAM,EACpB,EAAE;IACN,MAAM,OAAO,GAAG;QACZ,KAAK,EAAE,KAAK;QACZ,KAAK,EAAE,KAAK;QACZ,KAAK,EAAE,KAAK;QACZ,SAAS,EAAE,SAAS;QACpB,eAAe,EAAE,eAAe;KACnC,CAAC;IACF,OAAO,cAAc,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,eAAe,CAAC,CAAC;AACjE,CAAC,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\r\nimport { type Scene } from \"../../scene\";\r\nimport { type Vector3, Vector2, Vector4 } from \"../../Maths/math.vector\";\r\nimport { Color4 } from \"../../Maths/math.color\";\r\nimport { Mesh } from \"../mesh\";\r\nimport { VertexData } from \"../mesh.vertexData\";\r\nimport { PolygonMeshBuilder } from \"../polygonMesh\";\r\nimport { type FloatArray, type IndicesArray, type Nullable } from \"../../types\";\r\nimport { VertexBuffer } from \"../../Buffers/buffer\";\r\nimport { EngineStore } from \"../../Engines/engineStore\";\r\nimport { useOpenGLOrientationForUV } from \"../../Compat/compatibilityOptions\";\r\n\r\ndeclare let earcut: any;\r\n\r\n/**\r\n * Creates the VertexData for an irregular Polygon in the XoZ plane using a mesh built by polygonTriangulation.build()\r\n * All parameters are provided by CreatePolygon as needed\r\n * @param polygon a mesh built from polygonTriangulation.build()\r\n * @param sideOrientation takes the values Mesh.FRONTSIDE (default), Mesh.BACKSIDE or Mesh.DOUBLESIDE\r\n * @param fUV an array of Vector4 elements used to set different images to the top, rings and bottom respectively\r\n * @param fColors an array of Color3 elements used to set different colors to the top, rings and bottom respectively\r\n * @param frontUVs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the front side, optional, default vector4 (0, 0, 1, 1)\r\n * @param backUVs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the back side, optional, default vector4 (0, 0, 1, 1)\r\n * @param wrp a boolean, default false, when true and fUVs used texture is wrapped around all sides, when false texture is applied side\r\n * @returns the VertexData of the Polygon\r\n */\r\nexport function CreatePolygonVertexData(polygon: Mesh, sideOrientation: number, fUV?: Vector4[], fColors?: Color4[], frontUVs?: Vector4, backUVs?: Vector4, wrp?: boolean) {\r\n const faceUV: Vector4[] = fUV || new Array<Vector4>(3);\r\n const faceColors = fColors;\r\n const colors = [];\r\n const wrap: boolean = wrp || false;\r\n\r\n // default face colors and UV if undefined\r\n for (let f = 0; f < 3; f++) {\r\n if (faceUV[f] === undefined) {\r\n faceUV[f] = new Vector4(0, 0, 1, 1);\r\n }\r\n if (faceColors && faceColors[f] === undefined) {\r\n faceColors[f] = new Color4(1, 1, 1, 1);\r\n }\r\n }\r\n\r\n const positions = <FloatArray>polygon.getVerticesData(VertexBuffer.PositionKind);\r\n const normals = <FloatArray>polygon.getVerticesData(VertexBuffer.NormalKind);\r\n const uvs = <FloatArray>polygon.getVerticesData(VertexBuffer.UVKind);\r\n const indices = <IndicesArray>polygon.getIndices();\r\n const startIndex = positions.length / 9;\r\n let disp: number;\r\n let distX: number;\r\n let distZ: number;\r\n let dist: number;\r\n let totalLen = 0;\r\n const cumulate = [0];\r\n if (wrap) {\r\n for (let idx = startIndex; idx < positions.length / 3; idx += 4) {\r\n distX = positions[3 * (idx + 2)] - positions[3 * idx];\r\n distZ = positions[3 * (idx + 2) + 2] - positions[3 * idx + 2];\r\n dist = Math.sqrt(distX * distX + distZ * distZ);\r\n totalLen += dist;\r\n cumulate.push(totalLen);\r\n }\r\n }\r\n // set face colours and textures\r\n let idx: number;\r\n let face: number = 0;\r\n for (let index = 0; index < normals.length; index += 3) {\r\n //Edge Face no. 1\r\n if (Math.abs(normals[index + 1]) < 0.001) {\r\n face = 1;\r\n }\r\n //Top Face no. 0\r\n if (Math.abs(normals[index + 1] - 1) < 0.001) {\r\n face = 0;\r\n }\r\n //Bottom Face no. 2\r\n if (Math.abs(normals[index + 1] + 1) < 0.001) {\r\n face = 2;\r\n }\r\n idx = index / 3;\r\n if (face === 1) {\r\n disp = idx - startIndex;\r\n if (disp % 4 < 1.5) {\r\n if (wrap) {\r\n uvs[2 * idx] = faceUV[face].x + ((faceUV[face].z - faceUV[face].x) * cumulate[Math.floor(disp / 4)]) / totalLen;\r\n } else {\r\n uvs[2 * idx] = faceUV[face].x;\r\n }\r\n } else {\r\n if (wrap) {\r\n uvs[2 * idx] = faceUV[face].x + ((faceUV[face].z - faceUV[face].x) * cumulate[Math.floor(disp / 4) + 1]) / totalLen;\r\n } else {\r\n uvs[2 * idx] = faceUV[face].z;\r\n }\r\n }\r\n if (disp % 2 === 0) {\r\n uvs[2 * idx + 1] = useOpenGLOrientationForUV ? 1.0 - faceUV[face].w : faceUV[face].w;\r\n } else {\r\n uvs[2 * idx + 1] = useOpenGLOrientationForUV ? 1.0 - faceUV[face].y : faceUV[face].y;\r\n }\r\n } else {\r\n uvs[2 * idx] = (1 - uvs[2 * idx]) * faceUV[face].x + uvs[2 * idx] * faceUV[face].z;\r\n uvs[2 * idx + 1] = (1 - uvs[2 * idx + 1]) * faceUV[face].y + uvs[2 * idx + 1] * faceUV[face].w;\r\n\r\n if (useOpenGLOrientationForUV) {\r\n uvs[2 * idx + 1] = 1.0 - uvs[2 * idx + 1];\r\n }\r\n }\r\n if (faceColors) {\r\n colors.push(faceColors[face].r, faceColors[face].g, faceColors[face].b, faceColors[face].a);\r\n }\r\n }\r\n\r\n // sides\r\n VertexData._ComputeSides(sideOrientation, positions, indices, normals, uvs, frontUVs, backUVs);\r\n\r\n // Result\r\n const vertexData = new VertexData();\r\n vertexData.indices = indices;\r\n vertexData.positions = positions;\r\n vertexData.normals = normals;\r\n vertexData.uvs = uvs;\r\n\r\n if (faceColors) {\r\n const totalColors = sideOrientation === VertexData.DOUBLESIDE ? colors.concat(colors) : colors;\r\n vertexData.colors = totalColors;\r\n }\r\n\r\n return vertexData;\r\n}\r\n\r\n/**\r\n * Creates a polygon mesh\r\n * The polygon's shape will depend on the input parameters and is constructed parallel to a ground mesh\r\n * * The parameter `shape` is a required array of successive Vector3 representing the corners of the polygon in th XoZ plane, that is y = 0 for all vectors\r\n * * You can set the mesh side orientation with the values : Mesh.FRONTSIDE (default), Mesh.BACKSIDE or Mesh.DOUBLESIDE\r\n * * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created\r\n * * If you create a double-sided mesh, you can choose what parts of the texture image to crop and stick respectively on the front and the back sides with the parameters `frontUVs` and `backUVs` (Vector4)\r\n * * Remember you can only change the shape positions, not their number when updating a polygon\r\n * @param name defines the name of the mesh\r\n * @param options defines the options used to create the mesh\r\n * @param scene defines the hosting scene\r\n * @param earcutInjection can be used to inject your own earcut reference\r\n * @returns the polygon mesh\r\n */\r\nexport function CreatePolygon(\r\n name: string,\r\n options: {\r\n shape: Vector3[];\r\n holes?: Vector3[][];\r\n depth?: number;\r\n smoothingThreshold?: number;\r\n faceUV?: Vector4[];\r\n faceColors?: Color4[];\r\n updatable?: boolean;\r\n sideOrientation?: number;\r\n frontUVs?: Vector4;\r\n backUVs?: Vector4;\r\n wrap?: boolean;\r\n instance?: Mesh;\r\n },\r\n scene: Nullable<Scene> = null,\r\n earcutInjection = earcut\r\n): Mesh {\r\n options.sideOrientation = Mesh._GetDefaultSideOrientation(options.sideOrientation);\r\n const shape = options.shape;\r\n const holes = options.holes || [];\r\n const depth = options.depth || 0;\r\n const smoothingThreshold = options.smoothingThreshold || 2;\r\n if (options.instance) {\r\n const vertexData = CreatePolygonVertexData(options.instance, options.sideOrientation, options.faceUV, options.faceColors, options.frontUVs, options.backUVs, options.wrap);\r\n vertexData.applyToMesh(options.instance, options.updatable);\r\n return options.instance;\r\n } else {\r\n const contours: Array<Vector2> = [];\r\n let hole: Array<Vector2>;\r\n\r\n for (let i = 0; i < shape.length; i++) {\r\n contours[i] = new Vector2(shape[i].x, shape[i].z);\r\n }\r\n const epsilon = 0.00000001;\r\n if (contours[0].equalsWithEpsilon(contours[contours.length - 1], epsilon)) {\r\n contours.pop();\r\n }\r\n\r\n const polygonTriangulation = new PolygonMeshBuilder(name, contours, scene || EngineStore.LastCreatedScene!, earcutInjection);\r\n for (let hNb = 0; hNb < holes.length; hNb++) {\r\n hole = [];\r\n for (let hPoint = 0; hPoint < holes[hNb].length; hPoint++) {\r\n hole.push(new Vector2(holes[hNb][hPoint].x, holes[hNb][hPoint].z));\r\n }\r\n polygonTriangulation.addHole(hole);\r\n }\r\n //updatability is set during applyToMesh; setting to true in triangulation build produces errors\r\n const polygon = polygonTriangulation.build(false, depth, smoothingThreshold);\r\n polygon._originalBuilderSideOrientation = options.sideOrientation;\r\n const vertexData = CreatePolygonVertexData(polygon, options.sideOrientation, options.faceUV, options.faceColors, options.frontUVs, options.backUVs, options.wrap);\r\n vertexData.applyToMesh(polygon, options.updatable);\r\n return polygon;\r\n }\r\n}\r\n\r\n/**\r\n * Creates an extruded polygon mesh, with depth in the Y direction.\r\n * * You can set different colors and different images to the top, bottom and extruded side by using the parameters `faceColors` (an array of 3 Color3 elements) and `faceUV` (an array of 3 Vector4 elements)\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/materials/using/texturePerBoxFace\r\n * @param name defines the name of the mesh\r\n * @param options defines the options used to create the mesh\r\n * @param scene defines the hosting scene\r\n * @param earcutInjection can be used to inject your own earcut reference\r\n * @returns the polygon mesh\r\n */\r\nexport function ExtrudePolygon(\r\n name: string,\r\n options: {\r\n shape: Vector3[];\r\n holes?: Vector3[][];\r\n depth?: number;\r\n faceUV?: Vector4[];\r\n faceColors?: Color4[];\r\n updatable?: boolean;\r\n sideOrientation?: number;\r\n frontUVs?: Vector4;\r\n backUVs?: Vector4;\r\n wrap?: boolean;\r\n },\r\n scene: Nullable<Scene> = null,\r\n earcutInjection = earcut\r\n): Mesh {\r\n return CreatePolygon(name, options, scene, earcutInjection);\r\n}\r\n/**\r\n * Class containing static functions to help procedurally build meshes\r\n * @deprecated use the functions directly from the module\r\n */\r\nexport const PolygonBuilder = {\r\n ExtrudePolygon,\r\n CreatePolygon,\r\n};\r\n\r\nVertexData.CreatePolygon = CreatePolygonVertexData;\r\nMesh.CreatePolygon = (name: string, shape: Vector3[], scene: Scene, holes?: Vector3[][], updatable?: boolean, sideOrientation?: number, earcutInjection = earcut): Mesh => {\r\n const options = {\r\n shape: shape,\r\n holes: holes,\r\n updatable: updatable,\r\n sideOrientation: sideOrientation,\r\n };\r\n return CreatePolygon(name, options, scene, earcutInjection);\r\n};\r\n\r\nMesh.ExtrudePolygon = (\r\n name: string,\r\n shape: Vector3[],\r\n depth: number,\r\n scene: Scene,\r\n holes?: Vector3[][],\r\n updatable?: boolean,\r\n sideOrientation?: number,\r\n earcutInjection = earcut\r\n): Mesh => {\r\n const options = {\r\n shape: shape,\r\n holes: holes,\r\n depth: depth,\r\n updatable: updatable,\r\n sideOrientation: sideOrientation,\r\n };\r\n return ExtrudePolygon(name, options, scene, earcutInjection);\r\n};\r\n"]}
@@ -10,7 +10,7 @@ import { type BaseTexture } from "../../Materials/Textures/baseTexture.js";
10
10
  interface IGaussianSplattingPartSource {
11
11
  name: string;
12
12
  _vertexCount: number;
13
- _splatsData: Nullable<ArrayBuffer>;
13
+ _splatsData: Nullable<ArrayBuffer | ArrayBufferView>;
14
14
  _shData: Nullable<Uint8Array[]>;
15
15
  _shDegree: number;
16
16
  isCompound: boolean;
@@ -379,11 +379,12 @@ export class GaussianSplattingMesh extends GaussianSplattingMeshBase {
379
379
  const splatByteLength = proxy._vertexCount * _GaussianSplattingBytesPerSplat;
380
380
  const shByteOffset = proxy._shDataOffset * _GaussianSplattingBytesPerShTexel;
381
381
  const shByteLength = proxy._vertexCount * _GaussianSplattingBytesPerShTexel;
382
+ const splatBytes = GaussianSplattingMeshBase._GetSplatDataBytes(this._splatsData);
382
383
  return {
383
384
  name: proxy.name,
384
385
  _vertexCount: proxy._vertexCount,
385
- _splatsData: this._splatsData.slice(splatByteOffset, splatByteOffset + splatByteLength),
386
- _shData: this._shData?.map((texture) => texture.slice(shByteOffset, shByteOffset + shByteLength)) ?? null,
386
+ _splatsData: splatBytes.subarray(splatByteOffset, splatByteOffset + splatByteLength),
387
+ _shData: this._shData?.map((texture) => texture.subarray(shByteOffset, shByteOffset + shByteLength)) ?? null,
387
388
  _shDegree: this._shData?.length ?? 0,
388
389
  isCompound: false,
389
390
  getWorldMatrix: () => proxy.getWorldMatrix(),
@@ -397,13 +398,10 @@ export class GaussianSplattingMesh extends GaussianSplattingMeshBase {
397
398
  this._shData = null;
398
399
  return;
399
400
  }
400
- const getSourceBuffer = (data) => {
401
- return data instanceof ArrayBuffer ? data : data.buffer;
402
- };
403
401
  const mergedSplatsData = new Uint8Array(totalCount * _GaussianSplattingBytesPerSplat);
404
402
  let splatByteOffset = 0;
405
403
  if (this._splatsData && existingVertexCount > 0) {
406
- mergedSplatsData.set(new Uint8Array(getSourceBuffer(this._splatsData), 0, existingVertexCount * _GaussianSplattingBytesPerSplat), splatByteOffset);
404
+ mergedSplatsData.set(GaussianSplattingMeshBase._GetSplatDataBytes(this._splatsData).subarray(0, existingVertexCount * _GaussianSplattingBytesPerSplat), splatByteOffset);
407
405
  splatByteOffset += existingVertexCount * _GaussianSplattingBytesPerSplat;
408
406
  }
409
407
  for (const other of others) {
@@ -411,7 +409,7 @@ export class GaussianSplattingMesh extends GaussianSplattingMeshBase {
411
409
  continue;
412
410
  }
413
411
  const splatByteLength = other._vertexCount * _GaussianSplattingBytesPerSplat;
414
- mergedSplatsData.set(new Uint8Array(getSourceBuffer(other._splatsData), 0, splatByteLength), splatByteOffset);
412
+ mergedSplatsData.set(GaussianSplattingMeshBase._GetSplatDataBytes(other._splatsData).subarray(0, splatByteLength), splatByteOffset);
415
413
  splatByteOffset += splatByteLength;
416
414
  }
417
415
  this._splatsData = mergedSplatsData.buffer;
@@ -479,7 +477,7 @@ export class GaussianSplattingMesh extends GaussianSplattingMeshBase {
479
477
  const covB = new Uint16Array(covBSItemSize * textureLength);
480
478
  const colorArray = new Uint8Array(textureLength * 4);
481
479
  // Determine merged SH degree
482
- const hasSH = this._shData !== null && others.every((o) => o._shData !== null);
480
+ const hasSH = (splatCountA === 0 || this._shData !== null) && others.every((o) => o._shData !== null);
483
481
  const shDegreeNew = hasSH ? Math.max(this._shDegree, ...others.map((o) => o._shDegree)) : 0;
484
482
  let sh = undefined;
485
483
  if (hasSH && shDegreeNew > 0) {
@@ -555,8 +553,8 @@ export class GaussianSplattingMesh extends GaussianSplattingMeshBase {
555
553
  const proxyVertexCount = this._partProxies.reduce((sum, proxy) => sum + (proxy ? proxy._vertexCount : 0), 0);
556
554
  const part0Count = splatCountA - proxyVertexCount;
557
555
  if (part0Count > 0) {
558
- const uBufA = new Uint8Array(this._splatsData);
559
- const fBufA = new Float32Array(this._splatsData);
556
+ const uBufA = GaussianSplattingMeshBase._GetSplatDataBytes(this._splatsData);
557
+ const fBufA = GaussianSplattingMeshBase._GetSplatDataFloats(this._splatsData);
560
558
  for (let i = 0; i < part0Count; i++) {
561
559
  this._makeSplat(i, fBufA, uBufA, covA, covB, colorArray, minimum, maximum, false);
562
560
  }
@@ -593,8 +591,8 @@ export class GaussianSplattingMesh extends GaussianSplattingMeshBase {
593
591
  // In the preferred scenario B (empty composer) splatCountA is 0 and this
594
592
  // entire branch is skipped by the outer `if (splatCountA > 0)` guard.
595
593
  if (this._splatsData) {
596
- const uBufA = new Uint8Array(this._splatsData);
597
- const fBufA = new Float32Array(this._splatsData);
594
+ const uBufA = GaussianSplattingMeshBase._GetSplatDataBytes(this._splatsData);
595
+ const fBufA = GaussianSplattingMeshBase._GetSplatDataFloats(this._splatsData);
598
596
  for (let i = 0; i < splatCountA; i++) {
599
597
  this._makeSplat(i, fBufA, uBufA, covA, covB, colorArray, minimum, maximum, false);
600
598
  }
@@ -622,8 +620,8 @@ export class GaussianSplattingMesh extends GaussianSplattingMeshBase {
622
620
  // addPart call (scenario A legacy path). Re-process the partial boundary
623
621
  // row so it is not clobbered by stale zeros during the sub-texture upload.
624
622
  if (this._splatsData) {
625
- const uBufA = new Uint8Array(this._splatsData);
626
- const fBufA = new Float32Array(this._splatsData);
623
+ const uBufA = GaussianSplattingMeshBase._GetSplatDataBytes(this._splatsData);
624
+ const fBufA = GaussianSplattingMeshBase._GetSplatDataFloats(this._splatsData);
627
625
  for (let i = firstNewTexel; i < splatCountA; i++) {
628
626
  this._makeSplat(i, fBufA, uBufA, covA, covB, colorArray, minimum, maximum, false, i);
629
627
  }
@@ -643,8 +641,8 @@ export class GaussianSplattingMesh extends GaussianSplattingMeshBase {
643
641
  const partStarts = new Array(this._partProxies.length).fill(0);
644
642
  // Legacy scenario A: part 0 is the mesh's own loaded data.
645
643
  if (!this._partProxies[0] && this._splatsData && part0Count > 0) {
646
- srcUBufs[0] = new Uint8Array(this._splatsData);
647
- srcFBufs[0] = new Float32Array(this._splatsData);
644
+ srcUBufs[0] = GaussianSplattingMeshBase._GetSplatDataBytes(this._splatsData);
645
+ srcFBufs[0] = GaussianSplattingMeshBase._GetSplatDataFloats(this._splatsData);
648
646
  partStarts[0] = 0;
649
647
  }
650
648
  // All proxied parts — start from pi=0 to cover preferred scenario B.
@@ -658,8 +656,8 @@ export class GaussianSplattingMesh extends GaussianSplattingMeshBase {
658
656
  if (!source || !source._splatsData) {
659
657
  throw new Error(`Cannot rebuild compound part "${proxy.name}": the retained compound source data is not available.`);
660
658
  }
661
- srcUBufs[pi] = new Uint8Array(source._splatsData);
662
- srcFBufs[pi] = new Float32Array(source._splatsData);
659
+ srcUBufs[pi] = GaussianSplattingMeshBase._GetSplatDataBytes(source._splatsData);
660
+ srcFBufs[pi] = GaussianSplattingMeshBase._GetSplatDataFloats(source._splatsData);
663
661
  partStarts[pi] = cumOffset;
664
662
  cumOffset += source._vertexCount;
665
663
  }