@woosh/meep-engine 2.138.13 → 2.138.16

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 (63) hide show
  1. package/build/bundle-worker-image-decoder.js +1 -1
  2. package/package.json +1 -1
  3. package/samples/terrain/from_image_2.js +2 -10
  4. package/src/engine/asset/loaders/image/ImageDecoderWorker.js +1 -1
  5. package/src/engine/asset/loaders/image/ImageRGBADataLoader.d.ts.map +1 -1
  6. package/src/engine/asset/loaders/image/ImageRGBADataLoader.js +6 -1
  7. package/src/engine/asset/loaders/image/png/PNGReader.d.ts +1 -99
  8. package/src/engine/asset/loaders/image/png/PNGReader.d.ts.map +1 -1
  9. package/src/engine/asset/loaders/image/png/PNGReader.js +31 -420
  10. package/src/engine/asset/loaders/image/png/chunk/png_chunk_decode_iTXt.d.ts +12 -0
  11. package/src/engine/asset/loaders/image/png/chunk/png_chunk_decode_iTXt.d.ts.map +1 -0
  12. package/src/engine/asset/loaders/image/png/chunk/png_chunk_decode_iTXt.js +53 -0
  13. package/src/engine/asset/loaders/image/png/chunk/png_chunk_decode_zTXt.d.ts +10 -0
  14. package/src/engine/asset/loaders/image/png/chunk/png_chunk_decode_zTXt.d.ts.map +1 -0
  15. package/src/engine/asset/loaders/image/png/chunk/png_chunk_decode_zTXt.js +42 -0
  16. package/src/engine/asset/loaders/image/png/filter/png_filter_unFilterAverage.d.ts +18 -0
  17. package/src/engine/asset/loaders/image/png/filter/png_filter_unFilterAverage.d.ts.map +1 -0
  18. package/src/engine/asset/loaders/image/png/filter/png_filter_unFilterAverage.js +59 -0
  19. package/src/engine/asset/loaders/image/png/filter/png_filter_unFilterNone.d.ts +17 -0
  20. package/src/engine/asset/loaders/image/png/filter/png_filter_unFilterNone.d.ts.map +1 -0
  21. package/src/engine/asset/loaders/image/png/filter/png_filter_unFilterNone.js +55 -0
  22. package/src/engine/asset/loaders/image/png/filter/png_filter_unFilterPaeth.d.ts +17 -0
  23. package/src/engine/asset/loaders/image/png/filter/png_filter_unFilterPaeth.d.ts.map +1 -0
  24. package/src/engine/asset/loaders/image/png/filter/png_filter_unFilterPaeth.js +74 -0
  25. package/src/engine/asset/loaders/image/png/filter/png_filter_unFilterSub.d.ts +15 -0
  26. package/src/engine/asset/loaders/image/png/filter/png_filter_unFilterSub.d.ts.map +1 -0
  27. package/src/engine/asset/loaders/image/png/filter/png_filter_unFilterSub.js +34 -0
  28. package/src/engine/asset/loaders/image/png/filter/png_filter_unFilterUp.d.ts +16 -0
  29. package/src/engine/asset/loaders/image/png/filter/png_filter_unFilterUp.d.ts.map +1 -0
  30. package/src/engine/asset/loaders/image/png/filter/png_filter_unFilterUp.js +46 -0
  31. package/src/engine/asset/loaders/image/png/inflate.d.ts +7 -0
  32. package/src/engine/asset/loaders/image/png/inflate.d.ts.map +1 -0
  33. package/src/engine/asset/loaders/image/png/inflate.js +20 -0
  34. package/src/engine/ecs/terrain/ecs/Terrain.js +1 -1
  35. package/src/engine/ecs/terrain/ecs/splat/SplatMapping.d.ts.map +1 -1
  36. package/src/engine/ecs/terrain/ecs/splat/SplatMapping.js +32 -9
  37. package/src/engine/graphics/impostors/octahedral/prototypeBaker.js +202 -8
  38. package/src/engine/graphics/impostors/octahedral/shader/ImpostorShaderDepthV0.d.ts +10 -0
  39. package/src/engine/graphics/impostors/octahedral/shader/ImpostorShaderDepthV0.d.ts.map +1 -0
  40. package/src/engine/graphics/impostors/octahedral/shader/ImpostorShaderDepthV0.js +418 -0
  41. package/src/engine/graphics/impostors/octahedral/shader/ImpostorShaderLitV0.d.ts +14 -0
  42. package/src/engine/graphics/impostors/octahedral/shader/ImpostorShaderLitV0.d.ts.map +1 -0
  43. package/src/engine/graphics/impostors/octahedral/shader/ImpostorShaderLitV0.js +757 -0
  44. package/src/engine/graphics/impostors/octahedral/shader/ImpostorShaderNormalsV0.d.ts +13 -0
  45. package/src/engine/graphics/impostors/octahedral/shader/ImpostorShaderNormalsV0.d.ts.map +1 -0
  46. package/src/engine/graphics/impostors/octahedral/shader/ImpostorShaderNormalsV0.js +380 -0
  47. package/src/engine/graphics/impostors/octahedral/shader/ImpostorShaderPerPixelV0.d.ts +6 -0
  48. package/src/engine/graphics/impostors/octahedral/shader/ImpostorShaderPerPixelV0.d.ts.map +1 -0
  49. package/src/engine/graphics/impostors/octahedral/shader/ImpostorShaderPerPixelV0.js +406 -0
  50. package/src/engine/graphics/impostors/octahedral/shader/ImpostorShaderV0.d.ts.map +1 -1
  51. package/src/engine/graphics/impostors/octahedral/shader/ImpostorShaderV0.js +8 -1
  52. package/src/engine/graphics/impostors/octahedral/shader/ImpostorShaderViewportDepthV0.d.ts +14 -0
  53. package/src/engine/graphics/impostors/octahedral/shader/ImpostorShaderViewportDepthV0.d.ts.map +1 -0
  54. package/src/engine/graphics/impostors/octahedral/shader/ImpostorShaderViewportDepthV0.js +356 -0
  55. package/src/engine/graphics/impostors/octahedral/shader/ImpostorShaderWireframeV0.d.ts.map +1 -1
  56. package/src/engine/graphics/impostors/octahedral/shader/ImpostorShaderWireframeV0.js +4 -1
  57. package/src/engine/graphics/shaders/TerrainShader.js +2 -2
  58. package/src/engine/intelligence/mcts/MonteCarlo.d.ts +35 -4
  59. package/src/engine/intelligence/mcts/MonteCarlo.d.ts.map +1 -1
  60. package/src/engine/intelligence/mcts/MonteCarlo.js +101 -31
  61. package/src/engine/intelligence/mcts/StateNode.d.ts +47 -24
  62. package/src/engine/intelligence/mcts/StateNode.d.ts.map +1 -1
  63. package/src/engine/intelligence/mcts/StateNode.js +364 -316
@@ -22,7 +22,12 @@ import { ShadedGeometryFlags } from "../../ecs/mesh-v2/ShadedGeometryFlags.js";
22
22
  import { ShadedGeometrySystem } from "../../ecs/mesh-v2/ShadedGeometrySystem.js";
23
23
  import { ImpostorBaker } from "./ImpostorBaker.js";
24
24
  import { ImpostorCaptureType } from "./ImpostorCaptureType.js";
25
+ import { ImpostorShaderDepthV0 } from "./shader/ImpostorShaderDepthV0.js";
26
+ import { ImpostorShaderLitV0 } from "./shader/ImpostorShaderLitV0.js";
27
+ import { ImpostorShaderNormalsV0 } from "./shader/ImpostorShaderNormalsV0.js";
28
+ import { ImpostorShaderPerPixelV0 } from "./shader/ImpostorShaderPerPixelV0.js";
25
29
  import { ImpostorShaderV0 } from "./shader/ImpostorShaderV0.js";
30
+ import { ImpostorShaderViewportDepthV0 } from "./shader/ImpostorShaderViewportDepthV0.js";
26
31
  import { ImpostorShaderWireframeV0 } from "./shader/ImpostorShaderWireframeV0.js";
27
32
  import { build_geometry_from_cutout_shape } from "./util/build_geometry_from_cutout_shape.js";
28
33
  import { load_mesh_for_bake } from "./util/load_mesh_for_bake.js";
@@ -42,6 +47,13 @@ async function main(engine) {
42
47
  enableLights: true,
43
48
  enableShadows: true,
44
49
  cameraAutoClip: true,
50
+ // Default terrain is 20x20 (size 10 * gridScale 2). The impostor
51
+ // lineup below stretches x=10..25, so widen the plane to fit
52
+ // everything plus a small margin on each side.
53
+ terrainSize: new Vector2(18, 12),
54
+ // Recentre the camera focus on the lineup's midpoint so the
55
+ // wider terrain is framed correctly rather than slid off-screen.
56
+ focus: new Vector3(17, 0, 10),
45
57
  });
46
58
 
47
59
 
@@ -73,7 +85,7 @@ async function main(engine) {
73
85
  const id = baker.bake({
74
86
  objects,
75
87
  frames: 32,
76
- resolution: 1024,
88
+ resolution: 1024*8,
77
89
  type: ImpostorCaptureType.FullSphere
78
90
  });
79
91
  // console.profileEnd('bake');
@@ -95,7 +107,12 @@ async function main(engine) {
95
107
  .add(GUIElement.fromView(ctrl))
96
108
  // .build(ecd);
97
109
 
98
- // build out preview scene with impostor and the original
110
+ // build out preview scene: lay out the five variants side-by-side
111
+ // (V0 / per-pixel V0 / lit / world-normal viz / true mesh) so they
112
+ // share the same scene lighting and the differences are easy to
113
+ // compare. The normals viz sits next to lit because it shows exactly
114
+ // what the lit shader is feeding to the lighting equations — handy
115
+ // for diagnosing wrong-looking shading.
99
116
  const t0 = Transform.fromJSON({
100
117
  position: { x: 10, y: 0.5, z: 10 },
101
118
  scale: 3,
@@ -104,15 +121,45 @@ async function main(engine) {
104
121
 
105
122
  t0.scale.setScalar(3 / (id.sphere_radius * 2));
106
123
 
124
+ // Slot 0: original V0 + its wireframe overlay.
107
125
  const entity_impostor = make_impostor_entity(id, t0);
108
126
  entity_impostor.build(ecd);
109
127
 
110
128
  const entity_impostor_wireframe = make_impostor_wireframe(id, t0);
111
129
  entity_impostor_wireframe.build(ecd);
112
130
 
113
- const t1 = new Transform();
114
- t1.copy(t0);
115
- t1.position._add(3, 0, 0);
131
+ // Slot 1: per-pixel projection variant (visually identical to V0).
132
+ const t_per_pixel = new Transform();
133
+ t_per_pixel.copy(t0);
134
+ t_per_pixel.position._add(3, 0, 0);
135
+ make_impostor_per_pixel_entity(id, t_per_pixel).build(ecd);
136
+
137
+ // Slot 2: lit variant — only one that responds to scene lights and
138
+ // receives shadows from neighbours.
139
+ const t_lit = new Transform();
140
+ t_lit.copy(t0);
141
+ t_lit.position._add(6, 0, 0);
142
+ make_impostor_lit_entity(id, t_lit).build(ecd);
143
+
144
+ // Slot 3: world-space normal viz (debug pair for the lit variant).
145
+ const t_normals = new Transform();
146
+ t_normals.copy(t0);
147
+ t_normals.position._add(9, 0, 0);
148
+ make_impostor_normals_entity(id, t_normals).build(ecd);
149
+
150
+ // Slot 4: viewport-depth viz — shows the parallax surface's
151
+ // gl_FragCoord.z-equivalent as grayscale. Same construction the
152
+ // caster's gl_FragDepth uses; useful for spotting where the lit
153
+ // shader's shadow coord diverges from what the shadow map holds.
154
+ const t_depth = new Transform();
155
+ t_depth.copy(t0);
156
+ t_depth.position._add(12, 0, 0);
157
+ make_impostor_viewport_depth_entity(id, t_depth).build(ecd);
158
+
159
+ // Slot 5: original mesh as ground-truth reference.
160
+ const t_truth = new Transform();
161
+ t_truth.copy(t0);
162
+ t_truth.position._add(15, 0, 0);
116
163
 
117
164
  const sg_mesh = SGMesh.fromURL(path);
118
165
 
@@ -122,7 +169,7 @@ async function main(engine) {
122
169
  const entity_true_mesh = new Entity();
123
170
  entity_true_mesh
124
171
  .add(sg_mesh)
125
- .add(t1)
172
+ .add(t_truth)
126
173
  .build(ecd);
127
174
 
128
175
 
@@ -153,7 +200,7 @@ function make_spin(entity, speed = 1, axis = Vector3.up) {
153
200
 
154
201
  /**
155
202
  *
156
- * @param {{tBase,tGeometry,uFrames,uOffset,uRadius,uIsFullSphere}} uniforms
203
+ * @param {{tBase,tGeometry,uFrames,uOffset,uRadius,uIsFullSphere,tMaterial?}} uniforms
157
204
  * @param {ImpostorDescription} id
158
205
  */
159
206
  function write_impostor_definition_to_material_uniforms(uniforms, id) {
@@ -164,6 +211,12 @@ function write_impostor_definition_to_material_uniforms(uniforms, id) {
164
211
  uniforms.uOffset.value.set(id.offset[0], id.offset[1], id.offset[2]);
165
212
  uniforms.uRadius.value = id.sphere_radius;
166
213
  uniforms.uIsFullSphere.value = id.capture_type === ImpostorCaptureType.FullSphere;
214
+
215
+ // ORM texture is only consumed by the lit shader; older variants
216
+ // declare the uniform but never read it, so the assignment is harmless.
217
+ if (uniforms.tMaterial !== undefined) {
218
+ uniforms.tMaterial.value = id.rt.texture[2];
219
+ }
167
220
  }
168
221
 
169
222
  function make_impostor_wireframe(id, t = new Transform()) {
@@ -188,6 +241,19 @@ function make_impostor_wireframe(id, t = new Transform()) {
188
241
  ;
189
242
  }
190
243
 
244
+ /**
245
+ * Build a `depth_material` instance for shadow casting that mirrors the
246
+ * card geometry of whichever colour material we're using. Pulling this
247
+ * out keeps the per-variant factories below short.
248
+ *
249
+ * @param {ImpostorDescription} id
250
+ */
251
+ function make_impostor_depth_material(id) {
252
+ const depth_mat = new ImpostorShaderDepthV0();
253
+ write_impostor_definition_to_material_uniforms(depth_mat.uniforms, id);
254
+ return depth_mat;
255
+ }
256
+
191
257
  /**
192
258
  *
193
259
  * @param {ImpostorDescription} id
@@ -206,7 +272,104 @@ function make_impostor_entity(id, t = new Transform()) {
206
272
 
207
273
  const sg = ShadedGeometry.from(build_geometry_from_cutout_shape(id.cutout), mat);
208
274
 
209
- sg.depth_material = mat;
275
+ // V0 is unlit so it has no shadow to receive; it can still CAST a
276
+ // shadow using ImpostorShaderDepthV0, which traces the same parallax
277
+ // surface so the silhouette matches.
278
+ sg.depth_material = make_impostor_depth_material(id);
279
+ sg.clearFlag(ShadedGeometryFlags.ReceiveShadow);
280
+
281
+ return new Entity()
282
+ .add(transform)
283
+ .add(sg)
284
+ ;
285
+
286
+ }
287
+
288
+ /**
289
+ * Same as {@link make_impostor_entity} but with the per-pixel projection
290
+ * variant. Visually identical at the same camera distance — the difference
291
+ * is purely where the projection math runs on the GPU.
292
+ *
293
+ * @param {ImpostorDescription} id
294
+ * @param {Transform} t
295
+ * @returns {Entity}
296
+ */
297
+ function make_impostor_per_pixel_entity(id, t = new Transform()) {
298
+
299
+ const mat = new ImpostorShaderPerPixelV0();
300
+
301
+ write_impostor_definition_to_material_uniforms(mat.uniforms, id);
302
+
303
+ const transform = new Transform();
304
+ transform.copy(t);
305
+
306
+ const sg = ShadedGeometry.from(build_geometry_from_cutout_shape(id.cutout), mat);
307
+
308
+ sg.depth_material = make_impostor_depth_material(id);
309
+ sg.clearFlag(ShadedGeometryFlags.ReceiveShadow);
310
+
311
+ return new Entity()
312
+ .add(transform)
313
+ .add(sg)
314
+ ;
315
+ }
316
+
317
+ /**
318
+ * Debug viz: shows the world-space surface normal at each impostor pixel
319
+ * as RGB. Same parallax + atlas-decode math as the lit shader, so any
320
+ * weirdness here is also producing the lit shader's lighting.
321
+ *
322
+ * @param {ImpostorDescription} id
323
+ * @param {Transform} t
324
+ * @returns {Entity}
325
+ */
326
+ function make_impostor_normals_entity(id, t = new Transform()) {
327
+
328
+ const mat = new ImpostorShaderNormalsV0();
329
+
330
+ write_impostor_definition_to_material_uniforms(mat.uniforms, id);
331
+
332
+ const transform = new Transform();
333
+ transform.copy(t);
334
+
335
+ const sg = ShadedGeometry.from(build_geometry_from_cutout_shape(id.cutout), mat);
336
+
337
+ // Viz pass: don't participate in shadow casting/receiving — otherwise
338
+ // it'd influence its lit neighbour's shadow and confuse the comparison.
339
+ sg.depth_material = make_impostor_depth_material(id);
340
+ sg.clearFlag(ShadedGeometryFlags.CastShadow);
341
+ sg.clearFlag(ShadedGeometryFlags.ReceiveShadow);
342
+
343
+ return new Entity()
344
+ .add(transform)
345
+ .add(sg)
346
+ ;
347
+ }
348
+
349
+ /**
350
+ * Debug viz: shows the parallax-corrected surface's VIEWPORT depth as
351
+ * grayscale (closer = brighter). Same surface-position math as the lit
352
+ * shader's shadow coord and the depth material's gl_FragDepth write, so
353
+ * if shadows look wrong this slot is the most direct check.
354
+ *
355
+ * @param {ImpostorDescription} id
356
+ * @param {Transform} t
357
+ * @returns {Entity}
358
+ */
359
+ function make_impostor_viewport_depth_entity(id, t = new Transform()) {
360
+
361
+ const mat = new ImpostorShaderViewportDepthV0();
362
+
363
+ write_impostor_definition_to_material_uniforms(mat.uniforms, id);
364
+
365
+ const transform = new Transform();
366
+ transform.copy(t);
367
+
368
+ const sg = ShadedGeometry.from(build_geometry_from_cutout_shape(id.cutout), mat);
369
+
370
+ // Same as normals viz — opt out of shadow casting/receiving so it
371
+ // doesn't influence what its neighbours see.
372
+ sg.depth_material = make_impostor_depth_material(id);
210
373
  sg.clearFlag(ShadedGeometryFlags.CastShadow);
211
374
  sg.clearFlag(ShadedGeometryFlags.ReceiveShadow);
212
375
 
@@ -214,7 +377,38 @@ function make_impostor_entity(id, t = new Transform()) {
214
377
  .add(transform)
215
378
  .add(sg)
216
379
  ;
380
+ }
381
+
382
+ /**
383
+ * Lit impostor — applies three.js's STANDARD lighting model and receives
384
+ * shadow maps in addition to casting them.
385
+ *
386
+ * @param {ImpostorDescription} id
387
+ * @param {Transform} t
388
+ * @returns {Entity}
389
+ */
390
+ function make_impostor_lit_entity(id, t = new Transform()) {
391
+
392
+ const mat = new ImpostorShaderLitV0();
217
393
 
394
+ write_impostor_definition_to_material_uniforms(mat.uniforms, id);
395
+
396
+ const transform = new Transform();
397
+ transform.copy(t);
398
+
399
+ const sg = ShadedGeometry.from(build_geometry_from_cutout_shape(id.cutout), mat);
400
+
401
+ sg.depth_material = make_impostor_depth_material(id);
402
+ // CastShadow + ReceiveShadow on by default. Self-cast works because
403
+ // both sides (caster via gl_FragDepth, receiver via per-fragment
404
+ // customShadowCoord computed from the same atlas-derived parallax
405
+ // surface) agree on where the impostor's surface actually is in
406
+ // world space.
407
+
408
+ return new Entity()
409
+ .add(transform)
410
+ .add(sg)
411
+ ;
218
412
  }
219
413
 
220
414
  new EngineHarness().initialize({
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Depth-pass companion to ImpostorShaderV0. Use this as
3
+ * ShadedGeometry.depth_material so the impostor casts a shadow whose
4
+ * silhouette matches the visible card.
5
+ */
6
+ export class ImpostorShaderDepthV0 extends RawShaderMaterial {
7
+ constructor();
8
+ }
9
+ import { RawShaderMaterial } from "three";
10
+ //# sourceMappingURL=ImpostorShaderDepthV0.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ImpostorShaderDepthV0.d.ts","sourceRoot":"","sources":["../../../../../../../src/engine/graphics/impostors/octahedral/shader/ImpostorShaderDepthV0.js"],"names":[],"mappings":"AAsXA;;;;GAIG;AACH;IACI,cAoCC;CACJ;kCA5ZM,OAAO"}