@babylonjs/core 7.28.0 → 7.30.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 (120) hide show
  1. package/Culling/ray.core.d.ts +13 -0
  2. package/Culling/ray.core.js +14 -6
  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/webgpuShaderProcessorsWGSL.js +4 -1
  7. package/Engines/WebGPU/webgpuShaderProcessorsWGSL.js.map +1 -1
  8. package/Engines/abstractEngine.js +2 -2
  9. package/Engines/abstractEngine.js.map +1 -1
  10. package/Engines/engine.d.ts +2 -1
  11. package/Engines/index.d.ts +1 -0
  12. package/Engines/index.js +1 -0
  13. package/Engines/index.js.map +1 -1
  14. package/Engines/nullEngine.d.ts +1 -0
  15. package/Engines/nullEngine.js +1 -0
  16. package/Engines/nullEngine.js.map +1 -1
  17. package/Engines/webgpuEngine.d.ts +4 -0
  18. package/Engines/webgpuEngine.js +2 -4
  19. package/Engines/webgpuEngine.js.map +1 -1
  20. package/Lights/Shadows/shadowGenerator.js +1 -1
  21. package/Lights/Shadows/shadowGenerator.js.map +1 -1
  22. package/Loading/Plugins/babylonFileLoader.js +34 -18
  23. package/Loading/Plugins/babylonFileLoader.js.map +1 -1
  24. package/Materials/Textures/rawTexture3D.d.ts +12 -0
  25. package/Materials/Textures/rawTexture3D.js +18 -0
  26. package/Materials/Textures/rawTexture3D.js.map +1 -1
  27. package/Materials/Textures/renderTargetTexture.js +1 -2
  28. package/Materials/Textures/renderTargetTexture.js.map +1 -1
  29. package/Materials/effect.d.ts +11 -0
  30. package/Materials/effect.js +20 -0
  31. package/Materials/effect.js.map +1 -1
  32. package/Materials/materialPluginBase.d.ts +46 -46
  33. package/Materials/materialPluginBase.js +46 -60
  34. package/Materials/materialPluginBase.js.map +1 -1
  35. package/Meshes/Builders/greasedLineBuilder.d.ts +0 -16
  36. package/Meshes/Builders/greasedLineBuilder.js.map +1 -1
  37. package/Meshes/GreasedLine/greasedLineBaseMesh.d.ts +17 -1
  38. package/Meshes/GreasedLine/greasedLineBaseMesh.js +3 -2
  39. package/Meshes/GreasedLine/greasedLineBaseMesh.js.map +1 -1
  40. package/Meshes/Node/Blocks/Set/latticeBlock.d.ts +91 -0
  41. package/Meshes/Node/Blocks/Set/latticeBlock.js +194 -0
  42. package/Meshes/Node/Blocks/Set/latticeBlock.js.map +1 -0
  43. package/Meshes/Node/Blocks/Set/setPositionsBlock.js +11 -4
  44. package/Meshes/Node/Blocks/Set/setPositionsBlock.js.map +1 -1
  45. package/Meshes/Node/Blocks/geometryClampBlock.d.ts +8 -0
  46. package/Meshes/Node/Blocks/geometryClampBlock.js +22 -6
  47. package/Meshes/Node/Blocks/geometryClampBlock.js.map +1 -1
  48. package/Meshes/Node/Blocks/geometryInputBlock.js +2 -0
  49. package/Meshes/Node/Blocks/geometryInputBlock.js.map +1 -1
  50. package/Meshes/Node/Blocks/geometryInterceptorBlock.d.ts +5 -0
  51. package/Meshes/Node/Blocks/geometryInterceptorBlock.js +5 -1
  52. package/Meshes/Node/Blocks/geometryInterceptorBlock.js.map +1 -1
  53. package/Meshes/Node/Enums/nodeGeometryContextualSources.d.ts +5 -1
  54. package/Meshes/Node/Enums/nodeGeometryContextualSources.js +4 -0
  55. package/Meshes/Node/Enums/nodeGeometryContextualSources.js.map +1 -1
  56. package/Meshes/Node/index.d.ts +1 -0
  57. package/Meshes/Node/index.js +1 -0
  58. package/Meshes/Node/index.js.map +1 -1
  59. package/Meshes/Node/nodeGeometryBuildState.js +12 -0
  60. package/Meshes/Node/nodeGeometryBuildState.js.map +1 -1
  61. package/Meshes/abstractMesh.d.ts +2 -0
  62. package/Meshes/abstractMesh.hotSpot.d.ts +30 -0
  63. package/Meshes/abstractMesh.hotSpot.js +84 -0
  64. package/Meshes/abstractMesh.hotSpot.js.map +1 -0
  65. package/Meshes/abstractMesh.js +2 -0
  66. package/Meshes/abstractMesh.js.map +1 -1
  67. package/Meshes/index.d.ts +3 -0
  68. package/Meshes/index.js +3 -0
  69. package/Meshes/index.js.map +1 -1
  70. package/Meshes/lattice.d.ts +110 -0
  71. package/Meshes/lattice.js +224 -0
  72. package/Meshes/lattice.js.map +1 -0
  73. package/Meshes/lattice.material.d.ts +82 -0
  74. package/Meshes/lattice.material.js +259 -0
  75. package/Meshes/lattice.material.js.map +1 -0
  76. package/Meshes/mesh.js +1 -1
  77. package/Meshes/mesh.js.map +1 -1
  78. package/Misc/greasedLineTools.d.ts +1 -2
  79. package/Misc/greasedLineTools.js.map +1 -1
  80. package/Misc/index.d.ts +1 -0
  81. package/Misc/index.js +1 -0
  82. package/Misc/index.js.map +1 -1
  83. package/Misc/screenshotTools.js +0 -3
  84. package/Misc/screenshotTools.js.map +1 -1
  85. package/Misc/snapshotRenderingHelper.d.ts +63 -0
  86. package/Misc/snapshotRenderingHelper.js +182 -0
  87. package/Misc/snapshotRenderingHelper.js.map +1 -0
  88. package/Morph/morphTargetManager.js +0 -1
  89. package/Morph/morphTargetManager.js.map +1 -1
  90. package/Shaders/spriteMap.fragment.d.ts +4 -0
  91. package/Shaders/spriteMap.fragment.js +16 -3
  92. package/Shaders/spriteMap.fragment.js.map +1 -1
  93. package/Shaders/spriteMap.vertex.d.ts +3 -0
  94. package/Shaders/spriteMap.vertex.js +14 -2
  95. package/Shaders/spriteMap.vertex.js.map +1 -1
  96. package/ShadersWGSL/bilateralBlurQuality.fragment.js +1 -1
  97. package/ShadersWGSL/bilateralBlurQuality.fragment.js.map +1 -1
  98. package/ShadersWGSL/default.fragment.js +1 -1
  99. package/ShadersWGSL/default.fragment.js.map +1 -1
  100. package/ShadersWGSL/geometry.fragment.js +2 -2
  101. package/ShadersWGSL/geometry.fragment.js.map +1 -1
  102. package/ShadersWGSL/geometry.vertex.js +2 -2
  103. package/ShadersWGSL/geometry.vertex.js.map +1 -1
  104. package/ShadersWGSL/pbr.fragment.js +1 -1
  105. package/ShadersWGSL/pbr.fragment.js.map +1 -1
  106. package/ShadersWGSL/rsmFullGlobalIllumination.fragment.js +1 -1
  107. package/ShadersWGSL/rsmFullGlobalIllumination.fragment.js.map +1 -1
  108. package/Sprites/spriteManager.d.ts +10 -1
  109. package/Sprites/spriteManager.js +3 -2
  110. package/Sprites/spriteManager.js.map +1 -1
  111. package/Sprites/spriteMap.d.ts +7 -0
  112. package/Sprites/spriteMap.js +29 -1
  113. package/Sprites/spriteMap.js.map +1 -1
  114. package/Sprites/spritePackedManager.d.ts +6 -1
  115. package/Sprites/spritePackedManager.js +6 -2
  116. package/Sprites/spritePackedManager.js.map +1 -1
  117. package/Sprites/spriteRenderer.d.ts +16 -3
  118. package/Sprites/spriteRenderer.js +5 -3
  119. package/Sprites/spriteRenderer.js.map +1 -1
  120. package/package.json +1 -1
@@ -0,0 +1,259 @@
1
+ import { RawTexture3D } from "../Materials/Textures/rawTexture3D.js";
2
+ import { MaterialPluginBase } from "../Materials/materialPluginBase.js";
3
+
4
+ /**
5
+ * Material plugin to add hardware accelerated lattice support
6
+ * #HBZD72#5 - webgl2
7
+ * #HBZD72#6 - webgpu
8
+ */
9
+ export class LatticePluginMaterial extends MaterialPluginBase {
10
+ /**
11
+ * Create a new LatticePluginMaterial
12
+ * @param lattice defines the lattice this plugin is associated with
13
+ * @param material defines the material this plugin is associated with
14
+ */
15
+ constructor(lattice, material) {
16
+ super(material, "Lattice", 200);
17
+ this._lattice = lattice;
18
+ this.refreshData();
19
+ // let's enable it by default
20
+ this._enable(true);
21
+ }
22
+ /**
23
+ * Get the class name of the plugin
24
+ * @returns the string "LatticePluginMaterial"
25
+ */
26
+ getClassName() {
27
+ return "LatticePluginMaterial";
28
+ }
29
+ /**
30
+ * Defines if the plugin supports the specified shader language
31
+ * @param shaderLanguage defines the shader language to check
32
+ * @returns true if supported, false otherwise
33
+ */
34
+ isCompatible(shaderLanguage) {
35
+ switch (shaderLanguage) {
36
+ case 0 /* ShaderLanguage.GLSL */:
37
+ case 1 /* ShaderLanguage.WGSL */:
38
+ return true;
39
+ default:
40
+ return false;
41
+ }
42
+ }
43
+ /**
44
+ * Must be called when the lattice data was updated
45
+ */
46
+ refreshData() {
47
+ const length = this._lattice.resolutionX * this._lattice.resolutionY * this._lattice.resolutionZ * 4;
48
+ if (!this._latticeData || this._latticeData.length !== length) {
49
+ this._latticeData = new Float32Array(length);
50
+ }
51
+ for (let i = 0; i < this._lattice.resolutionX; i++) {
52
+ for (let j = 0; j < this._lattice.resolutionY; j++) {
53
+ for (let k = 0; k < this._lattice.resolutionZ; k++) {
54
+ const control = this._lattice.data[i][j][k];
55
+ const index = i + this._lattice.resolutionX * (j + this._lattice.resolutionY * k);
56
+ control.toArray(this._latticeData, index * 4);
57
+ }
58
+ }
59
+ }
60
+ if (!this._latticeDataTexture ||
61
+ this._latticeDataTexture.width !== this._lattice.resolutionX ||
62
+ this._latticeDataTexture.height !== this._lattice.resolutionY ||
63
+ this._latticeDataTexture.depth !== this._lattice.resolutionZ) {
64
+ if (this._latticeDataTexture) {
65
+ this._latticeDataTexture.dispose();
66
+ }
67
+ this._latticeDataTexture = new RawTexture3D(this._latticeData, this._lattice.resolutionX, this._lattice.resolutionY, this._lattice.resolutionZ, 5, this._material.getScene(), false, false, 1, 1);
68
+ }
69
+ else {
70
+ this._latticeDataTexture.update(this._latticeData);
71
+ }
72
+ }
73
+ /**
74
+ * Gets the description of the uniforms to add to the ubo (if engine supports ubos) or to inject directly in the vertex/fragment shaders (if engine does not support ubos)
75
+ * @param shaderLanguage The shader language to use.
76
+ * @returns the description of the uniforms
77
+ */
78
+ getUniforms(shaderLanguage) {
79
+ if (shaderLanguage === 1 /* ShaderLanguage.WGSL */) {
80
+ // For webgpu we only define the UBO with the correct type and size.
81
+ return {
82
+ ubo: [
83
+ { name: "lattice_cellSize", size: 3, type: "vec3" },
84
+ { name: "lattice_min", size: 3, type: "vec3" },
85
+ { name: "lattice_max", size: 3, type: "vec3" },
86
+ { name: "lattice_resolution", size: 3, type: "vec3" },
87
+ { name: "lattice_position", size: 3, type: "vec3" },
88
+ ],
89
+ };
90
+ }
91
+ return {
92
+ // first, define the UBO with the correct type and size.
93
+ ubo: [
94
+ { name: "lattice_cellSize", size: 3, type: "vec3" },
95
+ { name: "lattice_min", size: 3, type: "vec3" },
96
+ { name: "lattice_max", size: 3, type: "vec3" },
97
+ { name: "lattice_resolution", size: 3, type: "vec3" },
98
+ { name: "lattice_position", size: 3, type: "vec3" },
99
+ ],
100
+ // now, on the vertex shader, add the uniform itself in case uniform buffers are not supported by the engine
101
+ vertex: `
102
+ uniform vec3 lattice_cellSize;
103
+ uniform vec3 lattice_min;
104
+ uniform vec3 lattice_max;
105
+ uniform vec3 lattice_resolution;
106
+ uniform vec3 lattice_position;
107
+ `,
108
+ };
109
+ }
110
+ /**
111
+ * Binds the material data.
112
+ * @param uniformBuffer defines the Uniform buffer to fill in.
113
+ */
114
+ bindForSubMesh(uniformBuffer) {
115
+ this._lattice.updateInternals();
116
+ uniformBuffer.updateVector3("lattice_cellSize", this._lattice.cellSize);
117
+ uniformBuffer.updateVector3("lattice_min", this._lattice.min);
118
+ uniformBuffer.updateVector3("lattice_max", this._lattice.max);
119
+ uniformBuffer.updateFloat3("lattice_resolution", this._lattice.resolutionX, this._lattice.resolutionY, this._lattice.resolutionZ);
120
+ uniformBuffer.updateVector3("lattice_position", this._lattice.position);
121
+ uniformBuffer.setTexture("latticeData", this._latticeDataTexture);
122
+ }
123
+ /**
124
+ * Gets the samplers used by the plugin.
125
+ * @param samplers list that the sampler names should be added to.
126
+ */
127
+ getSamplers(samplers) {
128
+ samplers.push("latticeData");
129
+ }
130
+ _prepareCode(shaderLanguage = 0 /* ShaderLanguage.GLSL */) {
131
+ if (this._code) {
132
+ return this._code;
133
+ }
134
+ let code = `
135
+ if (positionUpdated.x >= lattice_min.x && positionUpdated.x <= lattice_max.x &&
136
+ positionUpdated.y >= lattice_min.y && positionUpdated.y <= lattice_max.y &&
137
+ positionUpdated.z >= lattice_min.z && positionUpdated.z <= lattice_max.z) {
138
+
139
+ // Map vertex position to lattice local coordinates
140
+ vec3d localPos = vec3c((positionUpdated.x - lattice_min.x) / lattice_cellSize.x, (positionUpdated.y - lattice_min.y) / lattice_cellSize.y, (positionUpdated.z - lattice_min.z) / lattice_cellSize.z);
141
+
142
+ // Get integer lattice indices
143
+ intd i0 = intc(floor(localPos.x));
144
+ intd j0 = intc(floor(localPos.y));
145
+ intd k0 = intc(floor(localPos.z));
146
+
147
+ intd resX = intc(lattice_resolution.x) - 1;
148
+ intd resY = intc(lattice_resolution.y) - 1;
149
+ intd resZ = intc(lattice_resolution.z) - 1;
150
+
151
+ intd i1 = min(i0 + 1, resX);
152
+ intd j1 = min(j0 + 1, resY);
153
+ intd k1 = min(k0 + 1, resZ);
154
+
155
+ // Compute interpolation weights
156
+ floatd tx = localPos.x - floatc(i0);
157
+ floatd ty = localPos.y - floatc(j0);
158
+ floatd tz = localPos.z - floatc(k0);
159
+
160
+ // Ensure indices are within bounds
161
+ intd ii0 = clamp(i0, 0, resX);
162
+ intd jj0 = clamp(j0, 0, resY);
163
+ intd kk0 = clamp(k0, 0, resZ);
164
+ intd ii1 = clamp(i1, 0, resX);
165
+ intd jj1 = clamp(j1, 0, resY);
166
+ intd kk1 = clamp(k1, 0, resZ);
167
+
168
+ // Get lattice control points
169
+ vec3d p000 = texelFetch(latticeData, ivec3c(ii0, jj0, kk0), 0).rgb;
170
+ vec3d p100 = texelFetch(latticeData, ivec3c(ii1, jj0, kk0), 0).rgb;
171
+ vec3d p010 = texelFetch(latticeData, ivec3c(ii0, jj1, kk0), 0).rgb;
172
+ vec3d p110 = texelFetch(latticeData, ivec3c(ii1, jj1, kk0), 0).rgb;
173
+ vec3d p001 = texelFetch(latticeData, ivec3c(ii0, jj0, kk1), 0).rgb;
174
+ vec3d p101 = texelFetch(latticeData, ivec3c(ii1, jj0, kk1), 0).rgb;
175
+ vec3d p011 = texelFetch(latticeData, ivec3c(ii0, jj1, kk1), 0).rgb;
176
+ vec3d p111 = texelFetch(latticeData, ivec3c(ii1, jj1, kk1), 0).rgb;
177
+
178
+ // Trilinear interpolation
179
+ vec3d p00 = mix(p000, p100, tx);
180
+ vec3d p01 = mix(p001, p101, tx);
181
+ vec3d p10 = mix(p010, p110, tx);
182
+ vec3d p11 = mix(p011, p111, tx);
183
+
184
+ vec3d p0 = mix(p00, p10, ty);
185
+ vec3d p1 = mix(p01, p11, ty);
186
+
187
+ vec3d deformedPos = mix(p0, p1, tz);
188
+ positionUpdated = deformedPos + lattice_position;
189
+ };
190
+ `;
191
+ if (shaderLanguage === 1 /* ShaderLanguage.WGSL */) {
192
+ code =
193
+ `
194
+ let lattice_min = uniforms.lattice_min;
195
+ let lattice_max = uniforms.lattice_max;
196
+ let lattice_resolution = uniforms.lattice_resolution;
197
+ let lattice_position = uniforms.lattice_position;
198
+ let lattice_cellSize = uniforms.lattice_cellSize;
199
+ ` + code;
200
+ code = code.replace(/ivec3c/g, "vec3i");
201
+ code = code.replace(/vec3d/g, "var");
202
+ code = code.replace(/vec3c/g, "vec3f");
203
+ code = code.replace(/intd/g, "var");
204
+ code = code.replace(/intc/g, "i32");
205
+ code = code.replace(/floatd/g, "var");
206
+ code = code.replace(/floatc/g, "f32");
207
+ code = code.replace(/texelFetch/g, "textureLoad");
208
+ }
209
+ else {
210
+ code = code.replace(/ivec3c/g, "ivec3");
211
+ code = code.replace(/vec3d/g, "vec3");
212
+ code = code.replace(/vec3c/g, "vec3");
213
+ code = code.replace(/intd/g, "int");
214
+ code = code.replace(/intc/g, "int");
215
+ code = code.replace(/floatd/g, "float");
216
+ code = code.replace(/floatc/g, "float");
217
+ }
218
+ this._code = code;
219
+ return this._code;
220
+ }
221
+ /**
222
+ * Returns a list of custom shader code fragments to customize the shader.
223
+ * @param shaderType "vertex" or "fragment"
224
+ * @param shaderLanguage The shader language to use.
225
+ * @returns null if no code to be added, or a list of pointName =\> code.
226
+ */
227
+ getCustomCode(shaderType, shaderLanguage = 0 /* ShaderLanguage.GLSL */) {
228
+ if (shaderType === "vertex") {
229
+ // we're adding this specific code at the end of the main() function
230
+ if (shaderLanguage === 1 /* ShaderLanguage.WGSL */) {
231
+ return {
232
+ CUSTOM_VERTEX_DEFINITIONS: `
233
+ var latticeData: texture_3d<f32>;
234
+ `,
235
+ CUSTOM_VERTEX_UPDATE_POSITION: this._prepareCode(shaderLanguage),
236
+ };
237
+ }
238
+ return {
239
+ CUSTOM_VERTEX_DEFINITIONS: `
240
+ precision highp sampler3D;
241
+ uniform sampler3D latticeData;
242
+ `,
243
+ CUSTOM_VERTEX_UPDATE_POSITION: this._prepareCode(shaderLanguage),
244
+ };
245
+ }
246
+ // for other shader types we're not doing anything, return null
247
+ return null;
248
+ }
249
+ /**
250
+ * Disposes the resources of the material.
251
+ */
252
+ dispose() {
253
+ if (this._latticeDataTexture) {
254
+ this._latticeDataTexture.dispose();
255
+ this._latticeDataTexture = null;
256
+ }
257
+ }
258
+ }
259
+ //# sourceMappingURL=lattice.material.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lattice.material.js","sourceRoot":"","sources":["../../../../dev/core/src/Meshes/lattice.material.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,8CAA6C;AAEpE,OAAO,EAAE,kBAAkB,EAAE,2CAA0C;AAGvE,OAAO,EAAE,SAAS,EAAE,gCAA+B;AAInD;;;;GAIG;AACH,MAAM,OAAO,qBAAsB,SAAQ,kBAAkB;IAMzD;;;;OAIG;IACH,YAAY,OAAgB,EAAE,QAAkB;QAC5C,KAAK,CAAC,QAAQ,EAAE,SAAS,EAAE,GAAG,CAAC,CAAC;QAEhC,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;QAExB,IAAI,CAAC,WAAW,EAAE,CAAC;QAEnB,6BAA6B;QAC7B,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IACvB,CAAC;IAED;;;OAGG;IACa,YAAY;QACxB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C,OAAO,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;YACtC,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;YACtC,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;YACpC,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;YACpC,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;YACxC,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;SAC3C;QACD,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QAElB,OAAO,IAAI,CAAC,KAAK,CAAC;IACtB,CAAC;IAED;;;;;OAKG;IACa,aAAa,CAAC,UAAkB,EAAE,cAAc,8BAAsB;QAClF,IAAI,UAAU,KAAK,QAAQ,EAAE;YACzB,oEAAoE;YACpE,IAAI,cAAc,gCAAwB,EAAE;gBACxC,OAAO;oBACH,yBAAyB,EAAE;;qBAE1B;oBACD,6BAA6B,EAAE,IAAI,CAAC,YAAY,CAAC,cAAc,CAAC;iBACnE,CAAC;aACL;YAED,OAAO;gBACH,yBAAyB,EAAE;;;iBAG1B;gBACD,6BAA6B,EAAE,IAAI,CAAC,YAAY,CAAC,cAAc,CAAC;aACnE,CAAC;SACL;QACD,+DAA+D;QAC/D,OAAO,IAAI,CAAC;IAChB,CAAC;IAED;;OAEG;IACa,OAAO;QACnB,IAAI,IAAI,CAAC,mBAAmB,EAAE;YAC1B,IAAI,CAAC,mBAAmB,CAAC,OAAO,EAAE,CAAC;YACnC,IAAI,CAAC,mBAAmB,GAAG,IAAI,CAAC;SACnC;IACL,CAAC;CACJ","sourcesContent":["import { RawTexture3D } from \"core/Materials/Textures/rawTexture3D\";\r\nimport type { Material } from \"core/Materials/material\";\r\nimport { MaterialPluginBase } from \"core/Materials/materialPluginBase\";\r\nimport type { Lattice } from \"./lattice\";\r\nimport type { Nullable } from \"core/types\";\r\nimport { Constants } from \"core/Engines/constants\";\r\nimport { ShaderLanguage } from \"core/Materials/shaderLanguage\";\r\nimport type { UniformBuffer } from \"core/Materials/uniformBuffer\";\r\n\r\n/**\r\n * Material plugin to add hardware accelerated lattice support\r\n * #HBZD72#5 - webgl2\r\n * #HBZD72#6 - webgpu\r\n */\r\nexport class LatticePluginMaterial extends MaterialPluginBase {\r\n private _lattice: Lattice;\r\n private _latticeDataTexture: Nullable<RawTexture3D>;\r\n private _latticeData: Float32Array;\r\n private _code: string;\r\n\r\n /**\r\n * Create a new LatticePluginMaterial\r\n * @param lattice defines the lattice this plugin is associated with\r\n * @param material defines the material this plugin is associated with\r\n */\r\n constructor(lattice: Lattice, material: Material) {\r\n super(material, \"Lattice\", 200);\r\n\r\n this._lattice = lattice;\r\n\r\n this.refreshData();\r\n\r\n // let's enable it by default\r\n this._enable(true);\r\n }\r\n\r\n /**\r\n * Get the class name of the plugin\r\n * @returns the string \"LatticePluginMaterial\"\r\n */\r\n public override getClassName() {\r\n return \"LatticePluginMaterial\";\r\n }\r\n\r\n /**\r\n * Defines if the plugin supports the specified shader language\r\n * @param shaderLanguage defines the shader language to check\r\n * @returns true if supported, false otherwise\r\n */\r\n public override isCompatible(shaderLanguage: ShaderLanguage) {\r\n switch (shaderLanguage) {\r\n case ShaderLanguage.GLSL:\r\n case ShaderLanguage.WGSL:\r\n return true;\r\n default:\r\n return false;\r\n }\r\n }\r\n\r\n /**\r\n * Must be called when the lattice data was updated\r\n */\r\n public refreshData() {\r\n const length = this._lattice.resolutionX * this._lattice.resolutionY * this._lattice.resolutionZ * 4;\r\n if (!this._latticeData || this._latticeData.length !== length) {\r\n this._latticeData = new Float32Array(length);\r\n }\r\n\r\n for (let i = 0; i < this._lattice.resolutionX; i++) {\r\n for (let j = 0; j < this._lattice.resolutionY; j++) {\r\n for (let k = 0; k < this._lattice.resolutionZ; k++) {\r\n const control = this._lattice.data[i][j][k];\r\n const index = i + this._lattice.resolutionX * (j + this._lattice.resolutionY * k);\r\n control.toArray(this._latticeData, index * 4);\r\n }\r\n }\r\n }\r\n\r\n if (\r\n !this._latticeDataTexture ||\r\n this._latticeDataTexture.width !== this._lattice.resolutionX ||\r\n this._latticeDataTexture.height !== this._lattice.resolutionY ||\r\n this._latticeDataTexture.depth !== this._lattice.resolutionZ\r\n ) {\r\n if (this._latticeDataTexture) {\r\n this._latticeDataTexture.dispose();\r\n }\r\n\r\n this._latticeDataTexture = new RawTexture3D(\r\n this._latticeData,\r\n this._lattice.resolutionX,\r\n this._lattice.resolutionY,\r\n this._lattice.resolutionZ,\r\n Constants.TEXTUREFORMAT_RGBA,\r\n this._material.getScene(),\r\n false,\r\n false,\r\n Constants.TEXTURE_NEAREST_SAMPLINGMODE,\r\n Constants.TEXTURETYPE_FLOAT\r\n );\r\n } else {\r\n this._latticeDataTexture.update(this._latticeData);\r\n }\r\n }\r\n\r\n /**\r\n * Gets the description of the uniforms to add to the ubo (if engine supports ubos) or to inject directly in the vertex/fragment shaders (if engine does not support ubos)\r\n * @param shaderLanguage The shader language to use.\r\n * @returns the description of the uniforms\r\n */\r\n public override getUniforms(shaderLanguage: ShaderLanguage) {\r\n if (shaderLanguage === ShaderLanguage.WGSL) {\r\n // For webgpu we only define the UBO with the correct type and size.\r\n return {\r\n ubo: [\r\n { name: \"lattice_cellSize\", size: 3, type: \"vec3\" },\r\n { name: \"lattice_min\", size: 3, type: \"vec3\" },\r\n { name: \"lattice_max\", size: 3, type: \"vec3\" },\r\n { name: \"lattice_resolution\", size: 3, type: \"vec3\" },\r\n { name: \"lattice_position\", size: 3, type: \"vec3\" },\r\n ],\r\n };\r\n }\r\n return {\r\n // first, define the UBO with the correct type and size.\r\n ubo: [\r\n { name: \"lattice_cellSize\", size: 3, type: \"vec3\" },\r\n { name: \"lattice_min\", size: 3, type: \"vec3\" },\r\n { name: \"lattice_max\", size: 3, type: \"vec3\" },\r\n { name: \"lattice_resolution\", size: 3, type: \"vec3\" },\r\n { name: \"lattice_position\", size: 3, type: \"vec3\" },\r\n ],\r\n // now, on the vertex shader, add the uniform itself in case uniform buffers are not supported by the engine\r\n vertex: `\r\n uniform vec3 lattice_cellSize;\r\n uniform vec3 lattice_min;\r\n uniform vec3 lattice_max;\r\n uniform vec3 lattice_resolution;\r\n uniform vec3 lattice_position;\r\n `,\r\n };\r\n }\r\n\r\n /**\r\n * Binds the material data.\r\n * @param uniformBuffer defines the Uniform buffer to fill in.\r\n */\r\n public override bindForSubMesh(uniformBuffer: UniformBuffer) {\r\n this._lattice.updateInternals();\r\n\r\n uniformBuffer.updateVector3(\"lattice_cellSize\", this._lattice.cellSize);\r\n uniformBuffer.updateVector3(\"lattice_min\", this._lattice.min);\r\n uniformBuffer.updateVector3(\"lattice_max\", this._lattice.max);\r\n uniformBuffer.updateFloat3(\"lattice_resolution\", this._lattice.resolutionX, this._lattice.resolutionY, this._lattice.resolutionZ);\r\n uniformBuffer.updateVector3(\"lattice_position\", this._lattice.position);\r\n\r\n uniformBuffer.setTexture(\"latticeData\", this._latticeDataTexture);\r\n }\r\n\r\n /**\r\n * Gets the samplers used by the plugin.\r\n * @param samplers list that the sampler names should be added to.\r\n */\r\n public override getSamplers(samplers: string[]): void {\r\n samplers.push(\"latticeData\");\r\n }\r\n\r\n private _prepareCode(shaderLanguage = ShaderLanguage.GLSL) {\r\n if (this._code) {\r\n return this._code;\r\n }\r\n\r\n let code = `\r\n if (positionUpdated.x >= lattice_min.x && positionUpdated.x <= lattice_max.x && \r\n positionUpdated.y >= lattice_min.y && positionUpdated.y <= lattice_max.y && \r\n positionUpdated.z >= lattice_min.z && positionUpdated.z <= lattice_max.z) {\r\n\r\n // Map vertex position to lattice local coordinates\r\n vec3d localPos = vec3c((positionUpdated.x - lattice_min.x) / lattice_cellSize.x, (positionUpdated.y - lattice_min.y) / lattice_cellSize.y, (positionUpdated.z - lattice_min.z) / lattice_cellSize.z);\r\n\r\n // Get integer lattice indices\r\n intd i0 = intc(floor(localPos.x));\r\n intd j0 = intc(floor(localPos.y));\r\n intd k0 = intc(floor(localPos.z));\r\n\r\n intd resX = intc(lattice_resolution.x) - 1;\r\n intd resY = intc(lattice_resolution.y) - 1;\r\n intd resZ = intc(lattice_resolution.z) - 1;\r\n\r\n intd i1 = min(i0 + 1, resX);\r\n intd j1 = min(j0 + 1, resY);\r\n intd k1 = min(k0 + 1, resZ);\r\n\r\n // Compute interpolation weights\r\n floatd tx = localPos.x - floatc(i0);\r\n floatd ty = localPos.y - floatc(j0);\r\n floatd tz = localPos.z - floatc(k0);\r\n\r\n // Ensure indices are within bounds\r\n intd ii0 = clamp(i0, 0, resX);\r\n intd jj0 = clamp(j0, 0, resY);\r\n intd kk0 = clamp(k0, 0, resZ);\r\n intd ii1 = clamp(i1, 0, resX);\r\n intd jj1 = clamp(j1, 0, resY);\r\n intd kk1 = clamp(k1, 0, resZ);\r\n\r\n // Get lattice control points\r\n vec3d p000 = texelFetch(latticeData, ivec3c(ii0, jj0, kk0), 0).rgb;\r\n vec3d p100 = texelFetch(latticeData, ivec3c(ii1, jj0, kk0), 0).rgb;\r\n vec3d p010 = texelFetch(latticeData, ivec3c(ii0, jj1, kk0), 0).rgb;\r\n vec3d p110 = texelFetch(latticeData, ivec3c(ii1, jj1, kk0), 0).rgb;\r\n vec3d p001 = texelFetch(latticeData, ivec3c(ii0, jj0, kk1), 0).rgb;\r\n vec3d p101 = texelFetch(latticeData, ivec3c(ii1, jj0, kk1), 0).rgb;\r\n vec3d p011 = texelFetch(latticeData, ivec3c(ii0, jj1, kk1), 0).rgb;\r\n vec3d p111 = texelFetch(latticeData, ivec3c(ii1, jj1, kk1), 0).rgb;\r\n\r\n // Trilinear interpolation\r\n vec3d p00 = mix(p000, p100, tx);\r\n vec3d p01 = mix(p001, p101, tx);\r\n vec3d p10 = mix(p010, p110, tx);\r\n vec3d p11 = mix(p011, p111, tx);\r\n\r\n vec3d p0 = mix(p00, p10, ty);\r\n vec3d p1 = mix(p01, p11, ty);\r\n\r\n vec3d deformedPos = mix(p0, p1, tz);\r\n positionUpdated = deformedPos + lattice_position;\r\n };\r\n `;\r\n\r\n if (shaderLanguage === ShaderLanguage.WGSL) {\r\n code =\r\n `\r\n let lattice_min = uniforms.lattice_min;\r\n let lattice_max = uniforms.lattice_max;\r\n let lattice_resolution = uniforms.lattice_resolution;\r\n let lattice_position = uniforms.lattice_position;\r\n let lattice_cellSize = uniforms.lattice_cellSize;\r\n ` + code;\r\n\r\n code = code.replace(/ivec3c/g, \"vec3i\");\r\n code = code.replace(/vec3d/g, \"var\");\r\n code = code.replace(/vec3c/g, \"vec3f\");\r\n code = code.replace(/intd/g, \"var\");\r\n code = code.replace(/intc/g, \"i32\");\r\n code = code.replace(/floatd/g, \"var\");\r\n code = code.replace(/floatc/g, \"f32\");\r\n code = code.replace(/texelFetch/g, \"textureLoad\");\r\n } else {\r\n code = code.replace(/ivec3c/g, \"ivec3\");\r\n code = code.replace(/vec3d/g, \"vec3\");\r\n code = code.replace(/vec3c/g, \"vec3\");\r\n code = code.replace(/intd/g, \"int\");\r\n code = code.replace(/intc/g, \"int\");\r\n code = code.replace(/floatd/g, \"float\");\r\n code = code.replace(/floatc/g, \"float\");\r\n }\r\n this._code = code;\r\n\r\n return this._code;\r\n }\r\n\r\n /**\r\n * Returns a list of custom shader code fragments to customize the shader.\r\n * @param shaderType \"vertex\" or \"fragment\"\r\n * @param shaderLanguage The shader language to use.\r\n * @returns null if no code to be added, or a list of pointName =\\> code.\r\n */\r\n public override getCustomCode(shaderType: string, shaderLanguage = ShaderLanguage.GLSL) {\r\n if (shaderType === \"vertex\") {\r\n // we're adding this specific code at the end of the main() function\r\n if (shaderLanguage === ShaderLanguage.WGSL) {\r\n return {\r\n CUSTOM_VERTEX_DEFINITIONS: `\r\n var latticeData: texture_3d<f32>;\r\n `,\r\n CUSTOM_VERTEX_UPDATE_POSITION: this._prepareCode(shaderLanguage),\r\n };\r\n }\r\n\r\n return {\r\n CUSTOM_VERTEX_DEFINITIONS: `\r\n precision highp sampler3D;\r\n uniform sampler3D latticeData;\r\n `,\r\n CUSTOM_VERTEX_UPDATE_POSITION: this._prepareCode(shaderLanguage),\r\n };\r\n }\r\n // for other shader types we're not doing anything, return null\r\n return null;\r\n }\r\n\r\n /**\r\n * Disposes the resources of the material.\r\n */\r\n public override dispose(): void {\r\n if (this._latticeDataTexture) {\r\n this._latticeDataTexture.dispose();\r\n this._latticeDataTexture = null;\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) {