@babylonjs/core 7.27.3 → 7.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.
Files changed (86) hide show
  1. package/Culling/ray.core.d.ts +13 -0
  2. package/Culling/ray.core.js +16 -11
  3. package/Culling/ray.core.js.map +1 -1
  4. package/Engines/WebGPU/Extensions/engine.debugging.js +24 -0
  5. package/Engines/WebGPU/Extensions/engine.debugging.js.map +1 -1
  6. package/Engines/WebGPU/webgpuBufferManager.js +3 -2
  7. package/Engines/WebGPU/webgpuBufferManager.js.map +1 -1
  8. package/Engines/WebGPU/webgpuPipelineContext.js +1 -0
  9. package/Engines/WebGPU/webgpuPipelineContext.js.map +1 -1
  10. package/Engines/abstractEngine.js +2 -2
  11. package/Engines/abstractEngine.js.map +1 -1
  12. package/Engines/index.d.ts +2 -0
  13. package/Engines/index.js +2 -0
  14. package/Engines/index.js.map +1 -1
  15. package/Engines/webgpuEngine.js +1 -1
  16. package/Engines/webgpuEngine.js.map +1 -1
  17. package/Inputs/scene.inputManager.js +2 -1
  18. package/Inputs/scene.inputManager.js.map +1 -1
  19. package/Lights/Shadows/shadowGenerator.js +1 -1
  20. package/Lights/Shadows/shadowGenerator.js.map +1 -1
  21. package/Loading/Plugins/babylonFileLoader.js +34 -18
  22. package/Loading/Plugins/babylonFileLoader.js.map +1 -1
  23. package/Materials/Textures/renderTargetTexture.js +1 -2
  24. package/Materials/Textures/renderTargetTexture.js.map +1 -1
  25. package/Meshes/Builders/greasedLineBuilder.d.ts +0 -16
  26. package/Meshes/Builders/greasedLineBuilder.js.map +1 -1
  27. package/Meshes/GreasedLine/greasedLineBaseMesh.d.ts +17 -1
  28. package/Meshes/GreasedLine/greasedLineBaseMesh.js +3 -2
  29. package/Meshes/GreasedLine/greasedLineBaseMesh.js.map +1 -1
  30. package/Meshes/Node/Blocks/Set/setPositionsBlock.js +11 -4
  31. package/Meshes/Node/Blocks/Set/setPositionsBlock.js.map +1 -1
  32. package/Meshes/Node/Blocks/geometryInterceptorBlock.d.ts +36 -0
  33. package/Meshes/Node/Blocks/geometryInterceptorBlock.js +60 -0
  34. package/Meshes/Node/Blocks/geometryInterceptorBlock.js.map +1 -0
  35. package/Meshes/Node/index.d.ts +1 -0
  36. package/Meshes/Node/index.js +1 -0
  37. package/Meshes/Node/index.js.map +1 -1
  38. package/Meshes/WebGPU/webgpuDataBuffer.d.ts +3 -1
  39. package/Meshes/WebGPU/webgpuDataBuffer.js +6 -1
  40. package/Meshes/WebGPU/webgpuDataBuffer.js.map +1 -1
  41. package/Meshes/abstractMesh.d.ts +2 -0
  42. package/Meshes/abstractMesh.hotSpot.d.ts +30 -0
  43. package/Meshes/abstractMesh.hotSpot.js +84 -0
  44. package/Meshes/abstractMesh.hotSpot.js.map +1 -0
  45. package/Meshes/abstractMesh.js +2 -0
  46. package/Meshes/abstractMesh.js.map +1 -1
  47. package/Meshes/index.d.ts +2 -0
  48. package/Meshes/index.js +2 -0
  49. package/Meshes/index.js.map +1 -1
  50. package/Meshes/lattice.d.ts +93 -0
  51. package/Meshes/lattice.js +196 -0
  52. package/Meshes/lattice.js.map +1 -0
  53. package/Meshes/mesh.js +1 -1
  54. package/Meshes/mesh.js.map +1 -1
  55. package/Misc/greasedLineTools.d.ts +1 -2
  56. package/Misc/greasedLineTools.js.map +1 -1
  57. package/Misc/index.d.ts +1 -0
  58. package/Misc/index.js +1 -0
  59. package/Misc/index.js.map +1 -1
  60. package/Misc/snapshotRenderingHelper.d.ts +63 -0
  61. package/Misc/snapshotRenderingHelper.js +182 -0
  62. package/Misc/snapshotRenderingHelper.js.map +1 -0
  63. package/Morph/morphTargetManager.js +0 -1
  64. package/Morph/morphTargetManager.js.map +1 -1
  65. package/Shaders/spriteMap.fragment.d.ts +4 -0
  66. package/Shaders/spriteMap.fragment.js +16 -3
  67. package/Shaders/spriteMap.fragment.js.map +1 -1
  68. package/Shaders/spriteMap.vertex.d.ts +3 -0
  69. package/Shaders/spriteMap.vertex.js +14 -2
  70. package/Shaders/spriteMap.vertex.js.map +1 -1
  71. package/ShadersWGSL/bilateralBlurQuality.fragment.js +1 -1
  72. package/ShadersWGSL/bilateralBlurQuality.fragment.js.map +1 -1
  73. package/ShadersWGSL/geometry.fragment.js +2 -2
  74. package/ShadersWGSL/geometry.fragment.js.map +1 -1
  75. package/ShadersWGSL/geometry.vertex.js +2 -2
  76. package/ShadersWGSL/geometry.vertex.js.map +1 -1
  77. package/ShadersWGSL/rsmFullGlobalIllumination.fragment.js +1 -1
  78. package/ShadersWGSL/rsmFullGlobalIllumination.fragment.js.map +1 -1
  79. package/Sprites/spriteMap.d.ts +7 -0
  80. package/Sprites/spriteMap.js +29 -1
  81. package/Sprites/spriteMap.js.map +1 -1
  82. package/import.helper.d.ts +5 -0
  83. package/import.helper.js +6 -0
  84. package/import.helper.js.map +1 -0
  85. package/package.json +1 -1
  86. package/scene.js.map +1 -1
package/Meshes/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from "./abstractMesh";
2
2
  import "./abstractMesh.decalMap";
3
+ export * from "./abstractMesh.hotSpot";
3
4
  export * from "./Compression/index";
4
5
  export * from "./csg";
5
6
  export * from "./meshUVSpaceRenderer";
@@ -19,6 +20,7 @@ export * from "./polygonMesh";
19
20
  export * from "./geodesicMesh";
20
21
  export * from "./subMesh";
21
22
  export * from "./subMesh.project";
23
+ export * from "./lattice";
22
24
  export * from "./meshLODLevel";
23
25
  export * from "./transformNode";
24
26
  export * from "./Builders/index";
package/Meshes/index.js CHANGED
@@ -2,6 +2,7 @@
2
2
  /* eslint-disable import/no-internal-modules */
3
3
  export * from "./abstractMesh.js";
4
4
  import "./abstractMesh.decalMap.js";
5
+ export * from "./abstractMesh.hotSpot.js";
5
6
  export * from "./Compression/index.js";
6
7
  export * from "./csg.js";
7
8
  export * from "./meshUVSpaceRenderer.js";
@@ -21,6 +22,7 @@ export * from "./polygonMesh.js";
21
22
  export * from "./geodesicMesh.js";
22
23
  export * from "./subMesh.js";
23
24
  export * from "./subMesh.project.js";
25
+ export * from "./lattice.js";
24
26
  export * from "./meshLODLevel.js";
25
27
  export * from "./transformNode.js";
26
28
  export * from "./Builders/index.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../dev/core/src/Meshes/index.ts"],"names":[],"mappings":"AAAA,kCAAkC;AAClC,+CAA+C;AAC/C,cAAc,gBAAgB,CAAC;AAC/B,OAAO,yBAAyB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,OAAO,CAAC;AACtB,cAAc,uBAAuB,CAAC;AACtC,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC;AAC5B,cAAc,QAAQ,CAAC;AACvB,cAAc,mBAAmB,CAAC;AAClC,cAAc,eAAe,CAAC;AAC9B,cAAc,sBAAsB,CAAC;AACrC,cAAc,oCAAoC,CAAC;AACnD,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,WAAW,CAAC;AAC1B,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,yBAAyB,CAAC;AACxC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,qCAAqC,CAAC;AACpD,cAAc,mCAAmC,CAAC;AAClD,OAAO,oBAAoB,CAAC;AAC5B,gDAAgD;AAChD,cAAc,oBAAoB,CAAC;AACnC,cAAc,cAAc,CAAC;AAC7B,cAAc,2CAA2C,CAAC;AAE1D,WAAW;AACX,cAAc,2BAA2B,CAAC;AAC1C,cAAc,yBAAyB,CAAC;AACxC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,6BAA6B,CAAC;AAE5C,sBAAsB;AACtB,cAAc,uCAAuC,CAAC;AACtD,cAAc,yCAAyC,CAAC;AACxD,cAAc,6CAA6C,CAAC;AAC5D,cAAc,+CAA+C,CAAC;AAC9D,cAAc,kDAAkD,CAAC;AACjE,cAAc,gDAAgD,CAAC;AAC/D,cAAc,2CAA2C,CAAC;AAC1D,cAAc,6CAA6C,CAAC;AAC5D,cAAc,iDAAiD,CAAC;AAChE,cAAc,mDAAmD,CAAC;AAClE,cAAc,sDAAsD,CAAC;AACrE,cAAc,oDAAoD,CAAC","sourcesContent":["/* eslint-disable import/export */\r\n/* eslint-disable import/no-internal-modules */\r\nexport * from \"./abstractMesh\";\r\nimport \"./abstractMesh.decalMap\";\r\nexport * from \"./Compression/index\";\r\nexport * from \"./csg\";\r\nexport * from \"./meshUVSpaceRenderer\";\r\nexport * from \"./geometry\";\r\nexport * from \"./groundMesh\";\r\nexport * from \"./goldbergMesh\";\r\nexport * from \"./trailMesh\";\r\nexport * from \"./instancedMesh\";\r\nexport * from \"./linesMesh\";\r\nexport * from \"./mesh\";\r\nexport * from \"./mesh.vertexData\";\r\nexport * from \"./meshBuilder\";\r\nexport * from \"./meshSimplification\";\r\nexport * from \"./meshSimplificationSceneComponent\";\r\nexport * from \"./meshUtils\";\r\nexport * from \"./polygonMesh\";\r\nexport * from \"./geodesicMesh\";\r\nexport * from \"./subMesh\";\r\nexport * from \"./subMesh.project\";\r\nexport * from \"./meshLODLevel\";\r\nexport * from \"./transformNode\";\r\nexport * from \"./Builders/index\";\r\nexport * from \"./WebGL/webGLDataBuffer\";\r\nexport * from \"./WebGPU/webgpuDataBuffer\";\r\nexport * from \"./GreasedLine/greasedLineMesh\";\r\nexport * from \"./GreasedLine/greasedLineRibbonMesh\";\r\nexport * from \"./GreasedLine/greasedLineBaseMesh\";\r\nimport \"./thinInstanceMesh\";\r\n// eslint-disable-next-line no-duplicate-imports\r\nexport * from \"./thinInstanceMesh\";\r\nexport * from \"./Node/index\";\r\nexport * from \"./GaussianSplatting/gaussianSplattingMesh\";\r\n\r\n// LineMesh\r\nexport * from \"../Shaders/color.fragment\";\r\nexport * from \"../Shaders/color.vertex\";\r\nexport * from \"../ShadersWGSL/color.fragment\";\r\nexport * from \"../ShadersWGSL/color.vertex\";\r\n\r\n// MeshUVSPaceRenderer\r\nexport * from \"../Shaders/meshUVSpaceRenderer.vertex\";\r\nexport * from \"../Shaders/meshUVSpaceRenderer.fragment\";\r\nexport * from \"../Shaders/meshUVSpaceRendererMasker.vertex\";\r\nexport * from \"../Shaders/meshUVSpaceRendererMasker.fragment\";\r\nexport * from \"../Shaders/meshUVSpaceRendererFinaliser.fragment\";\r\nexport * from \"../Shaders/meshUVSpaceRendererFinaliser.vertex\";\r\nexport * from \"../ShadersWGSL/meshUVSpaceRenderer.vertex\";\r\nexport * from \"../ShadersWGSL/meshUVSpaceRenderer.fragment\";\r\nexport * from \"../ShadersWGSL/meshUVSpaceRendererMasker.vertex\";\r\nexport * from \"../ShadersWGSL/meshUVSpaceRendererMasker.fragment\";\r\nexport * from \"../ShadersWGSL/meshUVSpaceRendererFinaliser.fragment\";\r\nexport * from \"../ShadersWGSL/meshUVSpaceRendererFinaliser.vertex\";\r\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../dev/core/src/Meshes/index.ts"],"names":[],"mappings":"AAAA,kCAAkC;AAClC,+CAA+C;AAC/C,cAAc,gBAAgB,CAAC;AAC/B,OAAO,yBAAyB,CAAC;AACjC,cAAc,wBAAwB,CAAC;AACvC,cAAc,qBAAqB,CAAC;AACpC,cAAc,OAAO,CAAC;AACtB,cAAc,uBAAuB,CAAC;AACtC,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC;AAC5B,cAAc,QAAQ,CAAC;AACvB,cAAc,mBAAmB,CAAC;AAClC,cAAc,eAAe,CAAC;AAC9B,cAAc,sBAAsB,CAAC;AACrC,cAAc,oCAAoC,CAAC;AACnD,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,WAAW,CAAC;AAC1B,cAAc,mBAAmB,CAAC;AAClC,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,yBAAyB,CAAC;AACxC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,qCAAqC,CAAC;AACpD,cAAc,mCAAmC,CAAC;AAClD,OAAO,oBAAoB,CAAC;AAC5B,gDAAgD;AAChD,cAAc,oBAAoB,CAAC;AACnC,cAAc,cAAc,CAAC;AAC7B,cAAc,2CAA2C,CAAC;AAE1D,WAAW;AACX,cAAc,2BAA2B,CAAC;AAC1C,cAAc,yBAAyB,CAAC;AACxC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,6BAA6B,CAAC;AAE5C,sBAAsB;AACtB,cAAc,uCAAuC,CAAC;AACtD,cAAc,yCAAyC,CAAC;AACxD,cAAc,6CAA6C,CAAC;AAC5D,cAAc,+CAA+C,CAAC;AAC9D,cAAc,kDAAkD,CAAC;AACjE,cAAc,gDAAgD,CAAC;AAC/D,cAAc,2CAA2C,CAAC;AAC1D,cAAc,6CAA6C,CAAC;AAC5D,cAAc,iDAAiD,CAAC;AAChE,cAAc,mDAAmD,CAAC;AAClE,cAAc,sDAAsD,CAAC;AACrE,cAAc,oDAAoD,CAAC","sourcesContent":["/* eslint-disable import/export */\r\n/* eslint-disable import/no-internal-modules */\r\nexport * from \"./abstractMesh\";\r\nimport \"./abstractMesh.decalMap\";\r\nexport * from \"./abstractMesh.hotSpot\";\r\nexport * from \"./Compression/index\";\r\nexport * from \"./csg\";\r\nexport * from \"./meshUVSpaceRenderer\";\r\nexport * from \"./geometry\";\r\nexport * from \"./groundMesh\";\r\nexport * from \"./goldbergMesh\";\r\nexport * from \"./trailMesh\";\r\nexport * from \"./instancedMesh\";\r\nexport * from \"./linesMesh\";\r\nexport * from \"./mesh\";\r\nexport * from \"./mesh.vertexData\";\r\nexport * from \"./meshBuilder\";\r\nexport * from \"./meshSimplification\";\r\nexport * from \"./meshSimplificationSceneComponent\";\r\nexport * from \"./meshUtils\";\r\nexport * from \"./polygonMesh\";\r\nexport * from \"./geodesicMesh\";\r\nexport * from \"./subMesh\";\r\nexport * from \"./subMesh.project\";\r\nexport * from \"./lattice\";\r\nexport * from \"./meshLODLevel\";\r\nexport * from \"./transformNode\";\r\nexport * from \"./Builders/index\";\r\nexport * from \"./WebGL/webGLDataBuffer\";\r\nexport * from \"./WebGPU/webgpuDataBuffer\";\r\nexport * from \"./GreasedLine/greasedLineMesh\";\r\nexport * from \"./GreasedLine/greasedLineRibbonMesh\";\r\nexport * from \"./GreasedLine/greasedLineBaseMesh\";\r\nimport \"./thinInstanceMesh\";\r\n// eslint-disable-next-line no-duplicate-imports\r\nexport * from \"./thinInstanceMesh\";\r\nexport * from \"./Node/index\";\r\nexport * from \"./GaussianSplatting/gaussianSplattingMesh\";\r\n\r\n// LineMesh\r\nexport * from \"../Shaders/color.fragment\";\r\nexport * from \"../Shaders/color.vertex\";\r\nexport * from \"../ShadersWGSL/color.fragment\";\r\nexport * from \"../ShadersWGSL/color.vertex\";\r\n\r\n// MeshUVSPaceRenderer\r\nexport * from \"../Shaders/meshUVSpaceRenderer.vertex\";\r\nexport * from \"../Shaders/meshUVSpaceRenderer.fragment\";\r\nexport * from \"../Shaders/meshUVSpaceRendererMasker.vertex\";\r\nexport * from \"../Shaders/meshUVSpaceRendererMasker.fragment\";\r\nexport * from \"../Shaders/meshUVSpaceRendererFinaliser.fragment\";\r\nexport * from \"../Shaders/meshUVSpaceRendererFinaliser.vertex\";\r\nexport * from \"../ShadersWGSL/meshUVSpaceRenderer.vertex\";\r\nexport * from \"../ShadersWGSL/meshUVSpaceRenderer.fragment\";\r\nexport * from \"../ShadersWGSL/meshUVSpaceRendererMasker.vertex\";\r\nexport * from \"../ShadersWGSL/meshUVSpaceRendererMasker.fragment\";\r\nexport * from \"../ShadersWGSL/meshUVSpaceRendererFinaliser.fragment\";\r\nexport * from \"../ShadersWGSL/meshUVSpaceRendererFinaliser.vertex\";\r\n"]}
@@ -0,0 +1,93 @@
1
+ import { Vector3 } from "../Maths/math.vector.js";
2
+ import type { Mesh } from "./mesh";
3
+ import type { FloatArray } from "../types.js";
4
+ /**
5
+ * Interface used to define options for creating a lattice
6
+ */
7
+ export interface ILatticeOptions {
8
+ /** resolution on x axis */
9
+ resolutionX: number;
10
+ /** resolution on y axis */
11
+ resolutionY: number;
12
+ /** resolution on z axis */
13
+ resolutionZ: number;
14
+ /** the lattice position in object space */
15
+ position: Vector3;
16
+ /** size of the lattice along each axis in object space */
17
+ size: Vector3;
18
+ /** Optional mesh to adapt the size to */
19
+ autoAdaptToMesh?: Mesh;
20
+ }
21
+ /**
22
+ * Class used to represent a lattice
23
+ * #MDVD75#18 - Moving lattice bounds
24
+ * #MDVD75#23 - Twist
25
+ */
26
+ export declare class Lattice {
27
+ private _resolutionX;
28
+ private _resolutionY;
29
+ private _resolutionZ;
30
+ private _position;
31
+ private _size;
32
+ private _data;
33
+ private _min;
34
+ private _max;
35
+ private _localPos;
36
+ private _tmpVector;
37
+ private _lerpVector0;
38
+ private _lerpVector1;
39
+ private _lerpVector2;
40
+ private _lerpVector3;
41
+ private _lerpVector4;
42
+ private _lerpVector5;
43
+ /**
44
+ * @returns the string "Lattice"
45
+ */
46
+ getClassName(): string;
47
+ /**
48
+ * Gets the resolution on x axis
49
+ */
50
+ get resolutionX(): number;
51
+ /**
52
+ * Gets the resolution on y axis
53
+ */
54
+ get resolutionY(): number;
55
+ /**
56
+ * Gets the resolution on z axis
57
+ */
58
+ get resolutionZ(): number;
59
+ /**
60
+ * Gets the size of the lattice along each axis in object space
61
+ * Updating the size requires you to call update afterwards
62
+ */
63
+ get size(): Vector3;
64
+ /**
65
+ * Gets the lattice position in object space
66
+ */
67
+ get position(): Vector3;
68
+ /**
69
+ * Gets the data of the lattice
70
+ */
71
+ get data(): Vector3[][][];
72
+ /**
73
+ * Creates a new Lattice
74
+ * @param options options for creating
75
+ */
76
+ constructor(options: Partial<ILatticeOptions>);
77
+ private _allocateData;
78
+ /**
79
+ * Update of the lattice data
80
+ */
81
+ update(): void;
82
+ /**
83
+ * Apply the lattice to a mesh
84
+ * @param mesh mesh to deform
85
+ */
86
+ deformMesh(mesh: Mesh): void;
87
+ /**
88
+ * Apply the lattice to a set of points
89
+ * @param positions vertex data to deform
90
+ * @param target optional target array to store the result (operation will be done in place in not defined)
91
+ */
92
+ deform(positions: FloatArray, target?: FloatArray): void;
93
+ }
@@ -0,0 +1,196 @@
1
+ import { Vector3 } from "../Maths/math.vector.js";
2
+ import { VertexBuffer } from "./buffer.js";
3
+ import { Clamp } from "../Maths/math.scalar.functions.js";
4
+ /**
5
+ * Class used to represent a lattice
6
+ * #MDVD75#18 - Moving lattice bounds
7
+ * #MDVD75#23 - Twist
8
+ */
9
+ export class Lattice {
10
+ /**
11
+ * @returns the string "Lattice"
12
+ */
13
+ getClassName() {
14
+ return "Lattice";
15
+ }
16
+ /**
17
+ * Gets the resolution on x axis
18
+ */
19
+ get resolutionX() {
20
+ return this._resolutionX;
21
+ }
22
+ /**
23
+ * Gets the resolution on y axis
24
+ */
25
+ get resolutionY() {
26
+ return this._resolutionY;
27
+ }
28
+ /**
29
+ * Gets the resolution on z axis
30
+ */
31
+ get resolutionZ() {
32
+ return this._resolutionZ;
33
+ }
34
+ /**
35
+ * Gets the size of the lattice along each axis in object space
36
+ * Updating the size requires you to call update afterwards
37
+ */
38
+ get size() {
39
+ return this._size;
40
+ }
41
+ /**
42
+ * Gets the lattice position in object space
43
+ */
44
+ get position() {
45
+ return this._position;
46
+ }
47
+ /**
48
+ * Gets the data of the lattice
49
+ */
50
+ get data() {
51
+ return this._data;
52
+ }
53
+ /**
54
+ * Creates a new Lattice
55
+ * @param options options for creating
56
+ */
57
+ constructor(options) {
58
+ // Cache
59
+ this._min = new Vector3(-0.5, -0.5, -0.5);
60
+ this._max = new Vector3(0.5, 0.5, 0.5);
61
+ this._localPos = new Vector3();
62
+ this._tmpVector = new Vector3();
63
+ this._lerpVector0 = new Vector3();
64
+ this._lerpVector1 = new Vector3();
65
+ this._lerpVector2 = new Vector3();
66
+ this._lerpVector3 = new Vector3();
67
+ this._lerpVector4 = new Vector3();
68
+ this._lerpVector5 = new Vector3();
69
+ const localOptions = {
70
+ resolutionX: 3,
71
+ resolutionY: 3,
72
+ resolutionZ: 3,
73
+ position: Vector3.Zero(),
74
+ size: Vector3.One(),
75
+ ...options,
76
+ };
77
+ this._resolutionX = localOptions.resolutionX;
78
+ this._resolutionY = localOptions.resolutionY;
79
+ this._resolutionZ = localOptions.resolutionZ;
80
+ this._position = localOptions.position;
81
+ this._size = localOptions.autoAdaptToMesh ? localOptions.autoAdaptToMesh.getBoundingInfo().boundingBox.extendSize.scale(2) : localOptions.size;
82
+ // Allocate data
83
+ this._allocateData();
84
+ this.update();
85
+ }
86
+ _allocateData() {
87
+ this._data = new Array(this.resolutionX);
88
+ for (let i = 0; i < this.resolutionX; i++) {
89
+ this._data[i] = new Array(this.resolutionY);
90
+ for (let j = 0; j < this.resolutionY; j++) {
91
+ this._data[i][j] = new Array(this.resolutionZ);
92
+ for (let k = 0; k < this.resolutionZ; k++) {
93
+ this._data[i][j][k] = Vector3.Zero();
94
+ }
95
+ }
96
+ }
97
+ }
98
+ /**
99
+ * Update of the lattice data
100
+ */
101
+ update() {
102
+ for (let i = 0; i < this.resolutionX; i++) {
103
+ for (let j = 0; j < this.resolutionY; j++) {
104
+ for (let k = 0; k < this.resolutionZ; k++) {
105
+ const x = -this.size.x / 2 + this.size.x * (i / (this.resolutionX - 1));
106
+ const y = -this.size.y / 2 + this.size.y * (j / (this.resolutionY - 1));
107
+ const z = -this.size.z / 2 + this.size.z * (k / (this.resolutionZ - 1));
108
+ this._data[i][j][k].set(x, y, z);
109
+ }
110
+ }
111
+ }
112
+ }
113
+ /**
114
+ * Apply the lattice to a mesh
115
+ * @param mesh mesh to deform
116
+ */
117
+ deformMesh(mesh) {
118
+ const positions = mesh.getVerticesData(VertexBuffer.PositionKind);
119
+ if (!positions) {
120
+ return;
121
+ }
122
+ // Apply the lattice
123
+ this.deform(positions);
124
+ // Update back the mesh
125
+ mesh.setVerticesData(VertexBuffer.PositionKind, positions, true);
126
+ }
127
+ /**
128
+ * Apply the lattice to a set of points
129
+ * @param positions vertex data to deform
130
+ * @param target optional target array to store the result (operation will be done in place in not defined)
131
+ */
132
+ deform(positions, target) {
133
+ const nx = this._resolutionX;
134
+ const ny = this._resolutionY;
135
+ const nz = this._resolutionZ;
136
+ // Calculate the size of each cell in the lattice
137
+ const cellSize = new Vector3(this.size.x / (nx - 1), this.size.y / (ny - 1), this.size.z / (nz - 1));
138
+ // Calculate the lattice bounds
139
+ this._min.set(this.position.x - this.size.x / 2, this.position.y - this.size.y / 2, this.position.z - this.size.z / 2);
140
+ this._min.addToRef(this._size, this._max);
141
+ const min = this._min;
142
+ const max = this._max;
143
+ // Loop over each vertex
144
+ for (let i = 0; i < positions.length; i += 3) {
145
+ const vertex = this._tmpVector.fromArray(positions, i);
146
+ // Check we are inside
147
+ if (vertex.x < min.x || vertex.x > max.x || vertex.y < min.y || vertex.y > max.y || vertex.z < min.z || vertex.z > max.z) {
148
+ if (target) {
149
+ vertex.toArray(target, i);
150
+ }
151
+ continue;
152
+ }
153
+ // Map vertex position to lattice local coordinates
154
+ const localPos = this._localPos.set((vertex.x - min.x) / cellSize.x, (vertex.y - min.y) / cellSize.y, (vertex.z - min.z) / cellSize.z);
155
+ // Get integer lattice indices
156
+ const i0 = Math.floor(localPos.x);
157
+ const j0 = Math.floor(localPos.y);
158
+ const k0 = Math.floor(localPos.z);
159
+ const i1 = Math.min(i0 + 1, nx - 1);
160
+ const j1 = Math.min(j0 + 1, ny - 1);
161
+ const k1 = Math.min(k0 + 1, nz - 1);
162
+ // Compute interpolation weights
163
+ const tx = localPos.x - i0;
164
+ const ty = localPos.y - j0;
165
+ const tz = localPos.z - k0;
166
+ // Ensure indices are within bounds
167
+ const ii0 = Clamp(i0, 0, nx - 1);
168
+ const jj0 = Clamp(j0, 0, ny - 1);
169
+ const kk0 = Clamp(k0, 0, nz - 1);
170
+ const ii1 = Clamp(i1, 0, nx - 1);
171
+ const jj1 = Clamp(j1, 0, ny - 1);
172
+ const kk1 = Clamp(k1, 0, nz - 1);
173
+ // Get lattice control points
174
+ const p000 = this._data[ii0][jj0][kk0];
175
+ const p100 = this._data[ii1][jj0][kk0];
176
+ const p010 = this._data[ii0][jj1][kk0];
177
+ const p110 = this._data[ii1][jj1][kk0];
178
+ const p001 = this._data[ii0][jj0][kk1];
179
+ const p101 = this._data[ii1][jj0][kk1];
180
+ const p011 = this._data[ii0][jj1][kk1];
181
+ const p111 = this._data[ii1][jj1][kk1];
182
+ // Trilinear interpolation
183
+ const p00 = Vector3.LerpToRef(p000, p100, tx, this._lerpVector0);
184
+ const p01 = Vector3.LerpToRef(p001, p101, tx, this._lerpVector1);
185
+ const p10 = Vector3.LerpToRef(p010, p110, tx, this._lerpVector2);
186
+ const p11 = Vector3.LerpToRef(p011, p111, tx, this._lerpVector3);
187
+ const p0 = Vector3.LerpToRef(p00, p10, ty, this._lerpVector4);
188
+ const p1 = Vector3.LerpToRef(p01, p11, ty, this._lerpVector5);
189
+ const deformedPos = Vector3.LerpToRef(p0, p1, tz, this._lerpVector0);
190
+ deformedPos.addInPlace(this.position);
191
+ // Apply deformation to the vertex
192
+ deformedPos.toArray(target || positions, i);
193
+ }
194
+ }
195
+ }
196
+ //# sourceMappingURL=lattice.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lattice.js","sourceRoot":"","sources":["../../../../dev/core/src/Meshes/lattice.ts"],"names":[],"mappings":"AAAA,O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O,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;YAEjE,MAAM,EAAE,GAAG,OAAO,CAAC,SAAS,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;YAC9D,MAAM,EAAE,GAAG,OAAO,CAAC,SAAS,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;YAE9D,MAAM,WAAW,GAAG,OAAO,CAAC,SAAS,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;YACrE,WAAW,CAAC,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YAEtC,kCAAkC;YAClC,WAAW,CAAC,OAAO,CAAC,MAAM,IAAI,SAAS,EAAE,CAAC,CAAC,CAAC;SAC/C;IACL,CAAC;CACJ","sourcesContent":["import { Vector3 } from \"core/Maths/math.vector\";\r\nimport type { Mesh } from \"./mesh\";\r\nimport type { FloatArray } from \"core/types\";\r\nimport { VertexBuffer } from \"./buffer\";\r\nimport { Clamp } from \"core/Maths/math.scalar.functions\";\r\n\r\n/**\r\n * Interface used to define options for creating a lattice\r\n */\r\nexport interface ILatticeOptions {\r\n /** resolution on x axis */\r\n resolutionX: number;\r\n /** resolution on y axis */\r\n resolutionY: number;\r\n /** resolution on z axis */\r\n resolutionZ: number;\r\n /** the lattice position in object space */\r\n position: Vector3;\r\n /** size of the lattice along each axis in object space */\r\n size: Vector3;\r\n /** Optional mesh to adapt the size to */\r\n autoAdaptToMesh?: Mesh;\r\n}\r\n\r\n/**\r\n * Class used to represent a lattice\r\n * #MDVD75#18 - Moving lattice bounds\r\n * #MDVD75#23 - Twist\r\n */\r\nexport class Lattice {\r\n private _resolutionX: number;\r\n private _resolutionY: number;\r\n private _resolutionZ: number;\r\n private _position: Vector3;\r\n private _size: Vector3;\r\n\r\n private _data: Vector3[][][];\r\n\r\n // Cache\r\n private _min = new Vector3(-0.5, -0.5, -0.5);\r\n private _max = new Vector3(0.5, 0.5, 0.5);\r\n private _localPos = new Vector3();\r\n private _tmpVector = new Vector3();\r\n private _lerpVector0 = new Vector3();\r\n private _lerpVector1 = new Vector3();\r\n private _lerpVector2 = new Vector3();\r\n private _lerpVector3 = new Vector3();\r\n private _lerpVector4 = new Vector3();\r\n private _lerpVector5 = new Vector3();\r\n\r\n /**\r\n * @returns the string \"Lattice\"\r\n */\r\n public getClassName(): string {\r\n return \"Lattice\";\r\n }\r\n\r\n /**\r\n * Gets the resolution on x axis\r\n */\r\n public get resolutionX(): number {\r\n return this._resolutionX;\r\n }\r\n\r\n /**\r\n * Gets the resolution on y axis\r\n */\r\n public get resolutionY(): number {\r\n return this._resolutionY;\r\n }\r\n\r\n /**\r\n * Gets the resolution on z axis\r\n */\r\n public get resolutionZ(): number {\r\n return this._resolutionZ;\r\n }\r\n\r\n /**\r\n * Gets the size of the lattice along each axis in object space\r\n * Updating the size requires you to call update afterwards\r\n */\r\n public get size(): Vector3 {\r\n return this._size;\r\n }\r\n\r\n /**\r\n * Gets the lattice position in object space\r\n */\r\n public get position(): Vector3 {\r\n return this._position;\r\n }\r\n\r\n /**\r\n * Gets the data of the lattice\r\n */\r\n public get data(): Vector3[][][] {\r\n return this._data;\r\n }\r\n\r\n /**\r\n * Creates a new Lattice\r\n * @param options options for creating\r\n */\r\n public constructor(options: Partial<ILatticeOptions>) {\r\n const localOptions: ILatticeOptions = {\r\n resolutionX: 3,\r\n resolutionY: 3,\r\n resolutionZ: 3,\r\n position: Vector3.Zero(),\r\n size: Vector3.One(),\r\n ...options,\r\n };\r\n\r\n this._resolutionX = localOptions.resolutionX;\r\n this._resolutionY = localOptions.resolutionY;\r\n this._resolutionZ = localOptions.resolutionZ;\r\n this._position = localOptions.position;\r\n this._size = localOptions.autoAdaptToMesh ? localOptions.autoAdaptToMesh.getBoundingInfo().boundingBox.extendSize.scale(2) : localOptions.size;\r\n\r\n // Allocate data\r\n this._allocateData();\r\n this.update();\r\n }\r\n\r\n private _allocateData() {\r\n this._data = new Array<Array<Array<Vector3>>>(this.resolutionX);\r\n for (let i = 0; i < this.resolutionX; i++) {\r\n this._data[i] = new Array<Array<Vector3>>(this.resolutionY);\r\n for (let j = 0; j < this.resolutionY; j++) {\r\n this._data[i][j] = new Array<Vector3>(this.resolutionZ);\r\n for (let k = 0; k < this.resolutionZ; k++) {\r\n this._data[i][j][k] = Vector3.Zero();\r\n }\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Update of the lattice data\r\n */\r\n public update() {\r\n for (let i = 0; i < this.resolutionX; i++) {\r\n for (let j = 0; j < this.resolutionY; j++) {\r\n for (let k = 0; k < this.resolutionZ; k++) {\r\n const x = -this.size.x / 2 + this.size.x * (i / (this.resolutionX - 1));\r\n const y = -this.size.y / 2 + this.size.y * (j / (this.resolutionY - 1));\r\n const z = -this.size.z / 2 + this.size.z * (k / (this.resolutionZ - 1));\r\n\r\n this._data[i][j][k].set(x, y, z);\r\n }\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Apply the lattice to a mesh\r\n * @param mesh mesh to deform\r\n */\r\n public deformMesh(mesh: Mesh) {\r\n const positions = mesh.getVerticesData(VertexBuffer.PositionKind);\r\n\r\n if (!positions) {\r\n return;\r\n }\r\n\r\n // Apply the lattice\r\n this.deform(positions);\r\n\r\n // Update back the mesh\r\n mesh.setVerticesData(VertexBuffer.PositionKind, positions, true);\r\n }\r\n\r\n /**\r\n * Apply the lattice to a set of points\r\n * @param positions vertex data to deform\r\n * @param target optional target array to store the result (operation will be done in place in not defined)\r\n */\r\n public deform(positions: FloatArray, target?: FloatArray) {\r\n const nx = this._resolutionX;\r\n const ny = this._resolutionY;\r\n const nz = this._resolutionZ;\r\n\r\n // Calculate the size of each cell in the lattice\r\n const cellSize = new Vector3(this.size.x / (nx - 1), this.size.y / (ny - 1), this.size.z / (nz - 1));\r\n\r\n // Calculate the lattice bounds\r\n this._min.set(this.position.x - this.size.x / 2, this.position.y - this.size.y / 2, this.position.z - this.size.z / 2);\r\n this._min.addToRef(this._size, this._max);\r\n\r\n const min = this._min;\r\n const max = this._max;\r\n\r\n // Loop over each vertex\r\n for (let i = 0; i < positions.length; i += 3) {\r\n const vertex = this._tmpVector.fromArray(positions, i);\r\n\r\n // Check we are inside\r\n if (vertex.x < min.x || vertex.x > max.x || vertex.y < min.y || vertex.y > max.y || vertex.z < min.z || vertex.z > max.z) {\r\n if (target) {\r\n vertex.toArray(target, i);\r\n }\r\n continue;\r\n }\r\n\r\n // Map vertex position to lattice local coordinates\r\n const localPos = this._localPos.set((vertex.x - min.x) / cellSize.x, (vertex.y - min.y) / cellSize.y, (vertex.z - min.z) / cellSize.z);\r\n\r\n // Get integer lattice indices\r\n const i0 = Math.floor(localPos.x);\r\n const j0 = Math.floor(localPos.y);\r\n const k0 = Math.floor(localPos.z);\r\n\r\n const i1 = Math.min(i0 + 1, nx - 1);\r\n const j1 = Math.min(j0 + 1, ny - 1);\r\n const k1 = Math.min(k0 + 1, nz - 1);\r\n\r\n // Compute interpolation weights\r\n const tx = localPos.x - i0;\r\n const ty = localPos.y - j0;\r\n const tz = localPos.z - k0;\r\n\r\n // Ensure indices are within bounds\r\n const ii0 = Clamp(i0, 0, nx - 1);\r\n const jj0 = Clamp(j0, 0, ny - 1);\r\n const kk0 = Clamp(k0, 0, nz - 1);\r\n const ii1 = Clamp(i1, 0, nx - 1);\r\n const jj1 = Clamp(j1, 0, ny - 1);\r\n const kk1 = Clamp(k1, 0, nz - 1);\r\n\r\n // Get lattice control points\r\n const p000 = this._data[ii0][jj0][kk0];\r\n const p100 = this._data[ii1][jj0][kk0];\r\n const p010 = this._data[ii0][jj1][kk0];\r\n const p110 = this._data[ii1][jj1][kk0];\r\n const p001 = this._data[ii0][jj0][kk1];\r\n const p101 = this._data[ii1][jj0][kk1];\r\n const p011 = this._data[ii0][jj1][kk1];\r\n const p111 = this._data[ii1][jj1][kk1];\r\n\r\n // Trilinear interpolation\r\n const p00 = Vector3.LerpToRef(p000, p100, tx, this._lerpVector0);\r\n const p01 = Vector3.LerpToRef(p001, p101, tx, this._lerpVector1);\r\n const p10 = Vector3.LerpToRef(p010, p110, tx, this._lerpVector2);\r\n const p11 = Vector3.LerpToRef(p011, p111, tx, this._lerpVector3);\r\n\r\n const p0 = Vector3.LerpToRef(p00, p10, ty, this._lerpVector4);\r\n const p1 = Vector3.LerpToRef(p01, p11, ty, this._lerpVector5);\r\n\r\n const deformedPos = Vector3.LerpToRef(p0, p1, tz, this._lerpVector0);\r\n deformedPos.addInPlace(this.position);\r\n\r\n // Apply deformation to the vertex\r\n deformedPos.toArray(target || positions, i);\r\n }\r\n }\r\n}\r\n"]}
package/Meshes/mesh.js CHANGED
@@ -3484,7 +3484,7 @@ export class Mesh extends AbstractMesh {
3484
3484
  }
3485
3485
  // Morph targets
3486
3486
  if (parsedMesh.morphTargetManagerId > -1) {
3487
- mesh.morphTargetManager = scene.getMorphTargetManagerById(parsedMesh.morphTargetManagerId);
3487
+ mesh._waitingMorphTargetManagerId = parsedMesh.morphTargetManagerId;
3488
3488
  }
3489
3489
  // Skeleton
3490
3490
  if (parsedMesh.skeletonId !== undefined && parsedMesh.skeletonId !== null) {