@woosh/meep-engine 2.108.2 → 2.108.4

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 (122) hide show
  1. package/build/bundle-worker-terrain.js +1 -1
  2. package/build/meep.cjs +490 -193
  3. package/build/meep.min.js +1 -1
  4. package/build/meep.module.js +490 -193
  5. package/package.json +1 -1
  6. package/src/core/bvh2/binary/2/BinaryUint32BVH.d.ts +6 -0
  7. package/src/core/bvh2/binary/2/BinaryUint32BVH.d.ts.map +1 -1
  8. package/src/core/bvh2/binary/2/BinaryUint32BVH.js +15 -3
  9. package/src/core/bvh2/bvh3/build_triangle_morton_codes.js +3 -3
  10. package/src/core/bvh2/bvh3/ebvh_build_for_geometry_morton.d.ts.map +1 -1
  11. package/src/core/bvh2/bvh3/ebvh_build_for_geometry_morton.js +25 -14
  12. package/src/core/collection/array/arrayQuickSort.d.ts +0 -9
  13. package/src/core/collection/array/arrayQuickSort.d.ts.map +1 -1
  14. package/src/core/collection/array/arrayQuickSort.js +0 -73
  15. package/src/core/collection/array/array_quick_sort_by_comparator.d.ts +10 -0
  16. package/src/core/collection/array/array_quick_sort_by_comparator.d.ts.map +1 -0
  17. package/src/core/collection/array/array_quick_sort_by_comparator.js +75 -0
  18. package/src/core/collection/array/array_quick_sort_by_lookup.d.ts +8 -0
  19. package/src/core/collection/array/array_quick_sort_by_lookup.d.ts.map +1 -0
  20. package/src/core/collection/array/array_quick_sort_by_lookup.js +78 -0
  21. package/src/core/geom/2d/triangle2d_get_barycentric.d.ts +15 -0
  22. package/src/core/geom/2d/triangle2d_get_barycentric.d.ts.map +1 -0
  23. package/src/core/geom/2d/triangle2d_get_barycentric.js +48 -0
  24. package/src/core/geom/3d/aabb/aabb3_from_v3_array.d.ts.map +1 -1
  25. package/src/core/geom/3d/aabb/aabb3_from_v3_array.js +2 -7
  26. package/src/core/geom/3d/aabb3_compute_from_triangle.d.ts +11 -0
  27. package/src/core/geom/3d/aabb3_compute_from_triangle.d.ts.map +1 -0
  28. package/src/core/geom/3d/aabb3_compute_from_triangle.js +43 -0
  29. package/src/core/geom/3d/sphere/harmonics/sh3_dering_optimize_positive.js +5 -5
  30. package/src/core/geom/3d/sphere/harmonics/sh_compute_K.d.ts +9 -0
  31. package/src/core/geom/3d/sphere/harmonics/sh_compute_K.d.ts.map +1 -0
  32. package/src/core/geom/3d/sphere/harmonics/sh_compute_K.js +17 -0
  33. package/src/core/geom/3d/tetrahedra/TetrahedralMesh.d.ts +6 -3
  34. package/src/core/geom/3d/tetrahedra/TetrahedralMesh.d.ts.map +1 -1
  35. package/src/core/geom/3d/tetrahedra/TetrahedralMesh.js +56 -18
  36. package/src/core/geom/3d/tetrahedra/delaunay/tetrahedral_mesh_walk_towards_containing_tetrahedron.d.ts +1 -1
  37. package/src/core/geom/3d/tetrahedra/delaunay/tetrahedral_mesh_walk_towards_containing_tetrahedron.d.ts.map +1 -1
  38. package/src/core/geom/3d/tetrahedra/delaunay/tetrahedral_mesh_walk_towards_containing_tetrahedron.js +11 -4
  39. package/src/core/geom/3d/tetrahedra/{GetDepthForTetrahedronProbe.glsl → triangle/GetDepthForTetrahedronProbe.glsl} +17 -10
  40. package/src/core/geom/3d/tetrahedra/triangle/prototype.d.ts +2 -0
  41. package/src/core/geom/3d/tetrahedra/triangle/prototype.d.ts.map +1 -0
  42. package/src/core/geom/3d/tetrahedra/triangle/prototype.js +128 -0
  43. package/src/core/geom/3d/tetrahedra/triangle/trace_triangular_depth_map.d.ts +13 -0
  44. package/src/core/geom/3d/tetrahedra/triangle/trace_triangular_depth_map.d.ts.map +1 -0
  45. package/src/core/geom/3d/tetrahedra/triangle/trace_triangular_depth_map.js +120 -0
  46. package/src/core/geom/3d/tetrahedra/triangle/triangle_encode_rasterized_depth.d.ts +3 -0
  47. package/src/core/geom/3d/tetrahedra/triangle/triangle_encode_rasterized_depth.d.ts.map +1 -0
  48. package/src/core/geom/3d/tetrahedra/triangle/triangle_encode_rasterized_depth.js +106 -0
  49. package/src/core/math/factorial.d.ts +7 -0
  50. package/src/core/math/factorial.d.ts.map +1 -0
  51. package/src/core/math/factorial.js +15 -0
  52. package/src/core/math/factorial.spec.d.ts +2 -0
  53. package/src/core/math/factorial.spec.d.ts.map +1 -0
  54. package/src/core/math/factorial.spec.js +9 -0
  55. package/src/core/model/DebouncedObservedBoolean.d.ts +1 -1
  56. package/src/core/model/DebouncedObservedBoolean.d.ts.map +1 -1
  57. package/src/core/model/node-graph/node/NodeDescription.d.ts +6 -4
  58. package/src/engine/asset/loaders/material/computeTextureEquality.d.ts.map +1 -1
  59. package/src/engine/asset/loaders/material/computeTextureEquality.js +8 -1
  60. package/src/engine/graphics/ecs/mesh-v2/render/adapters/AbstractRenderAdapter.d.ts.map +1 -1
  61. package/src/engine/graphics/ecs/mesh-v2/render/adapters/AbstractRenderAdapter.js +3 -1
  62. package/src/engine/graphics/filter/sampler2d_flipY_in_place.d.ts +8 -0
  63. package/src/engine/graphics/filter/sampler2d_flipY_in_place.d.ts.map +1 -0
  64. package/src/engine/graphics/filter/{FlipArrayInPlace.js → sampler2d_flipY_in_place.js} +1 -1
  65. package/src/engine/graphics/geometry/bvh/buffered/bvh32_set_leaf_from_triangle.d.ts.map +1 -1
  66. package/src/engine/graphics/geometry/bvh/buffered/bvh32_set_leaf_from_triangle.js +5 -27
  67. package/src/engine/graphics/render/Lines.d.ts.map +1 -1
  68. package/src/engine/graphics/render/Lines.js +10 -2
  69. package/src/engine/graphics/sh3/gi/material/MaterialTransformer.d.ts +24 -0
  70. package/src/engine/graphics/sh3/gi/material/MaterialTransformer.d.ts.map +1 -0
  71. package/src/engine/graphics/sh3/gi/material/MaterialTransformer.js +293 -0
  72. package/src/engine/graphics/sh3/gi/material/build_fragment_shader.d.ts +6 -0
  73. package/src/engine/graphics/sh3/gi/material/build_fragment_shader.d.ts.map +1 -0
  74. package/src/engine/graphics/sh3/gi/material/build_fragment_shader.js +71 -0
  75. package/src/engine/graphics/sh3/gi/material/build_vertex_shader.d.ts +6 -0
  76. package/src/engine/graphics/sh3/gi/material/build_vertex_shader.d.ts.map +1 -0
  77. package/src/engine/graphics/sh3/gi/material/build_vertex_shader.js +256 -0
  78. package/src/engine/graphics/sh3/gi/tetrahedral_mesh_to_texture.js +4 -4
  79. package/src/engine/graphics/sh3/lpv/LightProbeVolume.d.ts +3 -1
  80. package/src/engine/graphics/sh3/lpv/LightProbeVolume.d.ts.map +1 -1
  81. package/src/engine/graphics/sh3/lpv/LightProbeVolume.js +12 -1
  82. package/src/engine/graphics/sh3/lpv/build_probes_for_scene.d.ts +2 -1
  83. package/src/engine/graphics/sh3/lpv/build_probes_for_scene.d.ts.map +1 -1
  84. package/src/engine/graphics/sh3/lpv/build_probes_for_scene.js +6 -6
  85. package/src/engine/graphics/sh3/lpv/probe_volume_to_textures.d.ts +8 -0
  86. package/src/engine/graphics/sh3/lpv/probe_volume_to_textures.d.ts.map +1 -1
  87. package/src/engine/graphics/sh3/lpv/probe_volume_to_textures.js +3 -2
  88. package/src/engine/graphics/sh3/path_tracer/PathTracedScene.d.ts.map +1 -1
  89. package/src/engine/graphics/sh3/path_tracer/PathTracedScene.js +9 -4
  90. package/src/engine/graphics/sh3/path_tracer/PathTracer.d.ts +3 -3
  91. package/src/engine/graphics/sh3/path_tracer/PathTracer.d.ts.map +1 -1
  92. package/src/engine/graphics/sh3/path_tracer/PathTracer.js +2 -2
  93. package/src/engine/graphics/sh3/path_tracer/compute_triangle_group_aabb3.d.ts +2 -2
  94. package/src/engine/graphics/sh3/path_tracer/compute_triangle_group_aabb3.d.ts.map +1 -1
  95. package/src/engine/graphics/sh3/path_tracer/compute_triangle_group_aabb3.js +18 -8
  96. package/src/engine/graphics/sh3/prototypeSH3Probe.js +51 -22
  97. package/src/engine/graphics/texture/AttributeDataTexture.d.ts.map +1 -1
  98. package/src/engine/graphics/texture/AttributeDataTexture.js +8 -2
  99. package/src/engine/graphics/texture/computeThreeTextureFormat.js +2 -1
  100. package/src/engine/graphics/texture/computeThreeTextureFormatFromDataType.d.ts +7 -0
  101. package/src/engine/graphics/texture/computeThreeTextureFormatFromDataType.d.ts.map +1 -0
  102. package/src/engine/graphics/texture/computeThreeTextureFormatFromDataType.js +13 -0
  103. package/src/engine/graphics/texture/formatToChannelCount.d.ts.map +1 -1
  104. package/src/engine/graphics/texture/formatToChannelCount.js +8 -1
  105. package/src/engine/graphics/texture/numericTypeFromBinaryDataType.d.ts +9 -0
  106. package/src/engine/graphics/texture/numericTypeFromBinaryDataType.d.ts.map +1 -0
  107. package/src/engine/graphics/texture/numericTypeFromBinaryDataType.js +31 -0
  108. package/src/engine/graphics/texture/sampler/Sampler2D.js +2 -2
  109. package/src/engine/graphics/texture/sampler/convertTexture2Sampler2D.d.ts.map +1 -1
  110. package/src/engine/graphics/texture/sampler/convertTexture2Sampler2D.js +47 -19
  111. package/src/engine/graphics/texture/sampler/debug/prototypeSamplerFiltering.js +5 -33
  112. package/src/engine/graphics/texture/sampler/sampler2d_copy_rectangle.d.ts +11 -0
  113. package/src/engine/graphics/texture/sampler/sampler2d_copy_rectangle.d.ts.map +1 -0
  114. package/src/engine/graphics/texture/sampler/sampler2d_copy_rectangle.js +41 -0
  115. package/src/engine/graphics/texture/virtual/VirtualTextureUsage.d.ts +0 -4
  116. package/src/engine/graphics/texture/virtual/VirtualTextureUsage.d.ts.map +1 -1
  117. package/src/engine/graphics/texture/virtual/VirtualTextureUsage.js +19 -30
  118. package/src/engine/graphics/filter/FlipArrayInPlace.d.ts +0 -8
  119. package/src/engine/graphics/filter/FlipArrayInPlace.d.ts.map +0 -1
  120. package/src/engine/graphics/sh3/path_tracer/texture/SoftwareTextureCache.d.ts +0 -3
  121. package/src/engine/graphics/sh3/path_tracer/texture/SoftwareTextureCache.d.ts.map +0 -1
  122. package/src/engine/graphics/sh3/path_tracer/texture/SoftwareTextureCache.js +0 -3
@@ -1,3 +1,4 @@
1
+ import { GUI } from "dat.gui";
1
2
  import {
2
3
  ClampToEdgeWrapping,
3
4
  DataTexture,
@@ -45,10 +46,10 @@ import { ShadedGeometryFlags } from "../ecs/mesh-v2/ShadedGeometryFlags.js";
45
46
  import { ShadedGeometrySystem } from "../ecs/mesh-v2/ShadedGeometrySystem.js";
46
47
  import { three_object_to_entity_composition } from "../ecs/mesh-v2/three_object_to_entity_composition.js";
47
48
  import { GizmoRenderingPlugin } from "../render/gizmo/GizmoRenderingPlugin.js";
49
+ import { MaterialTransformer } from "./gi/material/MaterialTransformer.js";
48
50
  import { build_probes_for_scene } from "./lpv/build_probes_for_scene.js";
49
51
  import { LightProbeVolume } from "./lpv/LightProbeVolume.js";
50
52
  import { LightProbeVolumeSerializationAdapter } from "./lpv/LightProbeVolumeSerializationAdapter.js";
51
- import { probe_volume_to_textures } from "./lpv/probe_volume_to_textures.js";
52
53
 
53
54
  /**
54
55
  *
@@ -197,17 +198,22 @@ function make_test_texture(t = 1) {
197
198
  *
198
199
  * @param {Engine} engine
199
200
  * @param {string} path
201
+ * @param {LightProbeVolume} volume
200
202
  * @return {Promise<LightProbeVolume>}
201
203
  */
202
- async function getVolume({ engine, path }) {
204
+ async function getVolume({
205
+ engine,
206
+ path,
207
+ volume = new LightProbeVolume()
208
+ }) {
209
+
210
+ volume.clear();
203
211
 
204
212
  const key = `lpv:${path}`;
205
213
 
206
214
  const adapter = new LightProbeVolumeSerializationAdapter();
207
215
 
208
216
  if (await engine.storage.promiseContains(key)) {
209
- const volume = new LightProbeVolume();
210
-
211
217
  const data = await engine.storage.promiseLoadBinary(key);
212
218
 
213
219
  console.log(`LPV data size ${number_pretty_print(data.byteLength)} bytes`);
@@ -224,11 +230,12 @@ async function getVolume({ engine, path }) {
224
230
 
225
231
  const ecd = engine.entityManager.dataset;
226
232
 
227
- const volume = await build_probes_for_scene({
233
+ await build_probes_for_scene({
234
+ volume,
228
235
  engine,
229
236
  ecd,
230
237
  bounds: mesh_bounds,
231
- density: 10000
238
+ density: 3000
232
239
  });
233
240
 
234
241
  const buffer = new BinaryBuffer();
@@ -242,7 +249,13 @@ async function getVolume({ engine, path }) {
242
249
  return volume;
243
250
  }
244
251
 
245
- function createFloor({ level, ecd }) {
252
+ /**
253
+ *
254
+ * @param {number} level
255
+ * @param {EntityComponentDataset} ecd
256
+ * @param {GraphicsEngine} graphics
257
+ */
258
+ function createFloor({ level, ecd, graphics }) {
246
259
 
247
260
  const texture_frequency = 10;
248
261
  const size = 1000;
@@ -259,6 +272,15 @@ function createFloor({ level, ecd }) {
259
272
  });
260
273
 
261
274
 
275
+ const material = graphics.getMaterialManager().obtain(new MeshStandardMaterial({
276
+ map: map
277
+ })).getValue();
278
+
279
+ const geometry = new PlaneBufferGeometry(1, 1, 100, 100);
280
+
281
+ geometry.computeVertexNormals();
282
+ geometry.computeTangents();
283
+
262
284
  new Entity()
263
285
  .add(Transform.fromJSON({
264
286
  position: {
@@ -269,9 +291,7 @@ function createFloor({ level, ecd }) {
269
291
  rotation: Quaternion.fromEulerAngles(-Math.PI * 0.5, 0, 0),
270
292
  scale: size
271
293
  }))
272
- .add(ShadedGeometry.from(new PlaneBufferGeometry(1, 1), new MeshStandardMaterial({
273
- map: map
274
- })))
294
+ .add(ShadedGeometry.from(geometry, material))
275
295
  .build(ecd);
276
296
 
277
297
  }
@@ -282,6 +302,12 @@ function createFloor({ level, ecd }) {
282
302
  * @return {Promise<void>}
283
303
  */
284
304
  async function main(engine) {
305
+ const volume = new LightProbeVolume();
306
+
307
+ const transformer = new MaterialTransformer({ volume });
308
+
309
+ engine.graphics.getMaterialManager().addCompileStep(transformer);
310
+
285
311
  await EngineHarness.buildBasics({
286
312
  engine,
287
313
  enableWater: false,
@@ -303,10 +329,11 @@ async function main(engine) {
303
329
  await EngineHarness.buildLights({
304
330
  engine,
305
331
  shadowmapResolution: 4096,
306
- ambientIntensity: 0.01,
332
+ ambientIntensity: 0.0,
307
333
  sun: sun_color,
308
- sunIntensity: 1,
309
- sunDirection: new Vector3(0.5, -1, 0.3)
334
+ sunIntensity: 1.7,
335
+ // sunDirection: new Vector3(0.5, -1, 0.3)
336
+ sunDirection: new Vector3(1.2, -1,0.2 )
310
337
  })
311
338
 
312
339
  engine.graphics.getRenderer().setClearColor('#1e3441', 1);
@@ -318,7 +345,6 @@ async function main(engine) {
318
345
 
319
346
  // const path = 'data/models/LowPolyTownshipSet/Small_house/Small_house.gltf';
320
347
  // const path = 'data/models/sibenik/2/model.gltf';
321
- const path = 'data/models/sibenik/3-window-less/model.gltf';
322
348
  // const path = 'data/models/vokselia_spawn/model.gltf';
323
349
  // const path = 'data/models/LowPolyTownshipSet/Town_Hall/model.gltf';
324
350
  // const path = 'data/models/pica_pica/pica_pica.gltf';
@@ -330,8 +356,10 @@ async function main(engine) {
330
356
  // const path = 'data/models/samples/cyberpunk_bike/scene.gltf';
331
357
  // const path = 'data/models/samples/sd_macross_city_standoff_diorama/scene.gltf';
332
358
  // const path = 'data/models/Slaughter Mech/Slaugter Mech.gltf';
333
- // const path = 'data/models/sponza-pbr/gltf/sponza.glb';
359
+ const path = 'data/models/sponza-pbr/gltf/sponza.glb';
334
360
  // const path = 'data/models/samples/gi_box_01/model.glb';
361
+ // const path = 'data/models/samples/gi_box_01/model-thick-1.glb';
362
+ // const path = 'data/models/sibenik/3-window-less/model.gltf';
335
363
 
336
364
  const mesh_asset = await engine.assetManager.promise(path, 'model/gltf+json');
337
365
  const gltf = mesh_asset.gltf;
@@ -350,7 +378,8 @@ async function main(engine) {
350
378
 
351
379
  createFloor({
352
380
  level: mesh_asset.boundingBox.y0,
353
- ecd
381
+ ecd,
382
+ graphics: engine.graphics
354
383
  });
355
384
 
356
385
  const composition = three_object_to_entity_composition(gltf.scene);
@@ -419,21 +448,21 @@ async function main(engine) {
419
448
 
420
449
  console.time('getVolume');
421
450
  // console.profile('getVolume');
422
- const volume = await getVolume({ engine, path });
451
+ await getVolume({ engine, path, volume });
423
452
  // console.profileEnd('getVolume');
424
453
  console.timeEnd('getVolume');
425
454
 
426
455
  console.log('LPV:', volume);
427
456
 
457
+ transformer.update();
458
+
428
459
 
429
460
  volume.visualize_probes({ ecd, size: model_footprint * 0.002 });
430
- // volume.visualize_mesh({ ecd , opacity: 0.2});
461
+ // volume.visualize_mesh({ ecd, opacity: 0.5 });
431
462
 
432
- console.time('prepareTextures');
433
- const textures = probe_volume_to_textures(volume);
434
- console.timeEnd('prepareTextures');
463
+ new GUI()
464
+ .add(transformer, 'intensity').min(0).max(10);
435
465
 
436
- console.log(textures);
437
466
 
438
467
  // mesh_entity.addEventListener(SGMeshEvents.AssetLoaded, build);
439
468
  //
@@ -1 +1 @@
1
- {"version":3,"file":"AttributeDataTexture.d.ts","sourceRoot":"","sources":["../../../../../src/engine/graphics/texture/AttributeDataTexture.js"],"names":[],"mappings":"AAYA;IAwRI;;;;;;OAMG;IACH,+CAHW,MAAM,cACN,MAAM,GAHL,oBAAoB,CAO/B;IAhSD;;;;;OAKG;IACH,+CAHW,MAAM,cACN,MAAM,EA2ChB;IA/BG;;;;OAIG;IACH,eAAkB;IAElB,mBAAoB;IAEpB;;;;OAIG;IACH,uBAAkC;IAElC;;;;OAIG;IACH,kBAAqB;IAErB;;;;OAIG;IACH,qBAA8B;IAKlC;;;OAGG;IACH,0BAEC;IAED,cASC;IAED,0BAGC;IAED,2BAEC;IAED;;;OAGG;IACH,mBAFW,MAAM,QAwChB;IAED,cA4BC;IAED;;;;;;OAMG;IACH,yBALW,MAAM,WACN,MAAM,EAAE,UACR,MAAM,EAAE,GACN,OAAO,CAoCnB;IAED;;;;;OAKG;IACH,8BAJW,MAAM,WACN,MAAM,EAAE,UACR,MAAM,EAAE,QAmClB;IAED;;;OAGG;IACH,sBAFW,MAAM,QAgBhB;IAED;;;OAGG;IACH,sCAEC;IAED;;;OAGG;IACH,2BAEC;IAED;;;OAGG;IACH,oBAFY,MAAM,CAIjB;CAYJ;4BA9S0C,OAAO"}
1
+ {"version":3,"file":"AttributeDataTexture.d.ts","sourceRoot":"","sources":["../../../../../src/engine/graphics/texture/AttributeDataTexture.js"],"names":[],"mappings":"AAaA;IA6RI;;;;;;OAMG;IACH,+CAHW,MAAM,cACN,MAAM,GAHL,oBAAoB,CAO/B;IArSD;;;;;OAKG;IACH,+CAHW,MAAM,cACN,MAAM,EA2ChB;IA/BG;;;;OAIG;IACH,eAAkB;IAElB,mBAAoB;IAEpB;;;;OAIG;IACH,uBAAkC;IAElC;;;;OAIG;IACH,kBAAqB;IAErB;;;;OAIG;IACH,qBAA8B;IAKlC;;;OAGG;IACH,0BAEC;IAED,cASC;IAED,0BAGC;IAED,2BAEC;IAED;;;OAGG;IACH,mBAFW,MAAM,QAwChB;IAED,cAiCC;IAED;;;;;;OAMG;IACH,yBALW,MAAM,WACN,MAAM,EAAE,UACR,MAAM,EAAE,GACN,OAAO,CAoCnB;IAED;;;;;OAKG;IACH,8BAJW,MAAM,WACN,MAAM,EAAE,UACR,MAAM,EAAE,QAmClB;IAED;;;OAGG;IACH,sBAFW,MAAM,QAgBhB;IAED;;;OAGG;IACH,sCAEC;IAED;;;OAGG;IACH,2BAEC;IAED;;;OAGG;IACH,oBAFY,MAAM,CAIjB;CAYJ;4BApT0C,OAAO"}
@@ -5,7 +5,8 @@ import {
5
5
  } from "../../../core/binary/type/DataType2TypedArrayConstructorMapping.js";
6
6
  import { DataTypeByteSizes } from "../../../core/binary/type/DataTypeByteSizes.js";
7
7
  import { typed_array_copy } from "../../../core/collection/array/typed/typed_array_copy.js";
8
- import { channelCountToThreeTextureFormat } from "./channelCountToThreeTextureFormat.js";
8
+
9
+ import { computeThreeTextureFormatFromDataType } from "./computeThreeTextureFormatFromDataType.js";
9
10
  import { computeThreeTextureInternalFormatFromDataType } from "./computeThreeTextureInternalFormatFromDataType.js";
10
11
  import { computeThreeTextureTypeFromDataType } from "./computeThreeTextureTypeFromDataType.js";
11
12
  import { normalized_internal_format } from "./normalized_internal_format.js";
@@ -140,7 +141,7 @@ export class AttributeDataTexture {
140
141
  const width = this.computeSlotWidth() * this.__column_count;
141
142
  const height = Math.ceil(this.__capacity / this.__column_count);
142
143
 
143
- const format = channelCountToThreeTextureFormat(spec.itemSize);
144
+ const format = computeThreeTextureFormatFromDataType(spec.type, spec.itemSize);
144
145
  const type = computeThreeTextureTypeFromDataType(spec.type);
145
146
 
146
147
  const array = new TypedArray(width * height * spec.itemSize);
@@ -151,12 +152,17 @@ export class AttributeDataTexture {
151
152
  texture.generateMipmaps = false;
152
153
  texture.minFilter = texture.magFilter = NearestFilter;
153
154
 
155
+ texture.format = format;
156
+ texture.type = type;
157
+
154
158
  if (spec.normalized) {
155
159
  texture.internalFormat = normalized_internal_format(spec.type, spec.itemSize);
156
160
  } else {
157
161
  texture.internalFormat = computeThreeTextureInternalFormatFromDataType(spec.type, spec.itemSize);
158
162
  }
159
163
 
164
+ texture.needsUpdate = true;
165
+
160
166
  this.__texture = texture;
161
167
 
162
168
 
@@ -1,6 +1,6 @@
1
1
  import { NumericType } from "../../../core/math/NumericType.js";
2
- import { channelCountToThreIntegerTextureType } from "./channelCountToThreIntegerTextureType.js";
3
2
  import { channelCountToThreeTextureFormat } from "./channelCountToThreeTextureFormat.js";
3
+ import { channelCountToThreIntegerTextureType } from "./channelCountToThreIntegerTextureType.js";
4
4
 
5
5
  /**
6
6
  *
@@ -16,3 +16,4 @@ export function computeThreeTextureFormat(type, channel_count) {
16
16
  throw new Error(`Unsupported numeric type '${type}'`);
17
17
  }
18
18
  }
19
+
@@ -0,0 +1,7 @@
1
+ /**
2
+ *
3
+ * @param {BinaryDataType} dt
4
+ * @param {number} channel_count
5
+ */
6
+ export function computeThreeTextureFormatFromDataType(dt: BinaryDataType, channel_count: number): number | import("three").PixelFormat;
7
+ //# sourceMappingURL=computeThreeTextureFormatFromDataType.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"computeThreeTextureFormatFromDataType.d.ts","sourceRoot":"","sources":["../../../../../src/engine/graphics/texture/computeThreeTextureFormatFromDataType.js"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,yFAFW,MAAM,wCAMhB"}
@@ -0,0 +1,13 @@
1
+ import { computeThreeTextureFormat } from "./computeThreeTextureFormat.js";
2
+ import { numericTypeFromBinaryDataType } from "./numericTypeFromBinaryDataType.js";
3
+
4
+ /**
5
+ *
6
+ * @param {BinaryDataType} dt
7
+ * @param {number} channel_count
8
+ */
9
+ export function computeThreeTextureFormatFromDataType(dt, channel_count) {
10
+ const numeric_type = numericTypeFromBinaryDataType(dt);
11
+
12
+ return computeThreeTextureFormat(numeric_type, channel_count);
13
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"formatToChannelCount.d.ts","sourceRoot":"","sources":["../../../../../src/engine/graphics/texture/formatToChannelCount.js"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,6CAHW,MAAM,GACJ,MAAM,CAgBlB"}
1
+ {"version":3,"file":"formatToChannelCount.d.ts","sourceRoot":"","sources":["../../../../../src/engine/graphics/texture/formatToChannelCount.js"],"names":[],"mappings":"AASA;;;;GAIG;AACH,6CAHW,MAAM,GACJ,MAAM,CAgBlB"}
@@ -1,4 +1,11 @@
1
- import { RedFormat, RedIntegerFormat, RGBAFormat, RGBFormat, RGFormat } from "three";
1
+ import { RedFormat, RedIntegerFormat, RGBAFormat, RGFormat } from "three";
2
+
3
+
4
+ /**
5
+ * WebGL constant, declared explicitly to avoid issues with later THREE.js versions where it is absent
6
+ * @type {number}
7
+ */
8
+ const RGBFormat = 1022;
2
9
 
3
10
  /**
4
11
  *
@@ -0,0 +1,9 @@
1
+ /**
2
+ *
3
+ * @param {BinaryDataType} dt
4
+ * @returns {NumericType}
5
+ */
6
+ export function numericTypeFromBinaryDataType(dt: BinaryDataType): NumericType;
7
+ import { BinaryDataType } from "../../../core/binary/type/BinaryDataType.js";
8
+ import { NumericType } from "../../../core/math/NumericType.js";
9
+ //# sourceMappingURL=numericTypeFromBinaryDataType.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"numericTypeFromBinaryDataType.d.ts","sourceRoot":"","sources":["../../../../../src/engine/graphics/texture/numericTypeFromBinaryDataType.js"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,kDAHW,cAAc,GACZ,WAAW,CAwBvB;+BA9B8B,6CAA6C;4BAChD,mCAAmC"}
@@ -0,0 +1,31 @@
1
+ import { BinaryDataType } from "../../../core/binary/type/BinaryDataType.js";
2
+ import { NumericType } from "../../../core/math/NumericType.js";
3
+
4
+ /**
5
+ *
6
+ * @param {BinaryDataType} dt
7
+ * @returns {NumericType}
8
+ */
9
+ export function numericTypeFromBinaryDataType(dt) {
10
+
11
+ switch (dt) {
12
+ case BinaryDataType.Uint8:
13
+ case BinaryDataType.Uint16:
14
+ case BinaryDataType.Uint32:
15
+ return NumericType.Uint
16
+
17
+ case BinaryDataType.Int8:
18
+ case BinaryDataType.Int16:
19
+ case BinaryDataType.Int32:
20
+ return NumericType.Int;
21
+
22
+ case BinaryDataType.Float16:
23
+ case BinaryDataType.Float32:
24
+ case BinaryDataType.Float64:
25
+ return NumericType.Float;
26
+
27
+ default:
28
+ throw new Error(`Unsupported data type '${dt}'`);
29
+ }
30
+
31
+ }
@@ -396,8 +396,8 @@ export class Sampler2D {
396
396
  const clamped_x = clamp(x, 0, x_max);
397
397
  const clamped_y = clamp(y, 0, y_max);
398
398
 
399
- const x0 = clamped_x | 0;
400
- const y0 = clamped_y | 0;
399
+ const x0 = clamped_x >>> 0;
400
+ const y0 = clamped_y >>> 0;
401
401
 
402
402
  //
403
403
  const row0 = y0 * rowSize;
@@ -1 +1 @@
1
- {"version":3,"file":"convertTexture2Sampler2D.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/texture/sampler/convertTexture2Sampler2D.js"],"names":[],"mappings":"AAUA;;;;;;;GAOG;AACH,mEALW,MAAM,WACN,MAAM,UACN,OAAO,GACN,SAAS,CAyEpB;0BArFyB,gBAAgB"}
1
+ {"version":3,"file":"convertTexture2Sampler2D.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/texture/sampler/convertTexture2Sampler2D.js"],"names":[],"mappings":"AAaA;;;;;;;GAOG;AACH,mEALW,MAAM,WACN,MAAM,UACN,OAAO,GACN,SAAS,CAkGpB;0BA/GyB,gBAAgB"}
@@ -1,8 +1,11 @@
1
- import { flipArrayInPlace } from "../../filter/FlipArrayInPlace.js";
2
1
  import ImageFilter from "../../filter/ImageFilter.js";
2
+ import { sampler2d_flipY_in_place } from "../../filter/sampler2d_flipY_in_place.js";
3
3
  import CopyShader from "../../postprocess/threejs/shaders/CopyShader.js";
4
4
  import { WebGLRendererPool } from "../../render/RendererPool.js";
5
+ import { formatToChannelCount } from "../formatToChannelCount.js";
6
+ import { sampler2d_scale } from "./resize/sampler2d_scale.js";
5
7
  import { Sampler2D } from "./Sampler2D.js";
8
+ import { sampler2d_ensure_uint8_RGBA } from "./sampler2d_ensure_uint8_RGBA.js";
6
9
 
7
10
 
8
11
  const DEFAULT_TEXTURE_WIDTH = 512;
@@ -25,6 +28,8 @@ export function convertTexture2Sampler2D(
25
28
  let _height = height;
26
29
  let _width = width;
27
30
 
31
+ const channel_count = formatToChannelCount(texture.format);
32
+
28
33
  // TODO take channel count into account
29
34
 
30
35
  if (_width === undefined || _height === undefined) {
@@ -59,32 +64,55 @@ export function convertTexture2Sampler2D(
59
64
 
60
65
  }
61
66
 
62
- // TODO add special case for DataTexture
63
67
 
64
- const built = WebGLRendererPool.global.use(renderer => {
68
+ let data;
65
69
 
66
- const ctx = renderer.getContext();
70
+ if (texture.isDataTexture === true) {
67
71
 
68
- //support for compressed textures
69
- ctx.getExtension("WEBGL_compressed_texture_s3tc");
72
+ // special case
73
+
74
+ const source = new Sampler2D(texture.image.data, channel_count, texture.image.width, texture.image.height);
75
+
76
+ let converted = sampler2d_ensure_uint8_RGBA(source);
77
+
78
+ if (converted.width !== _width || converted.height !== _height) {
79
+ const target = Sampler2D.uint8(4, _width, _height);
80
+
81
+ sampler2d_scale(converted, target);
82
+
83
+ converted = target;
84
+ }
85
+
86
+ data = converted.data;
87
+
88
+ } else {
89
+ const built = WebGLRendererPool.global.use(renderer => {
90
+
91
+ const ctx = renderer.getContext();
92
+
93
+ //support for compressed textures
94
+ ctx.getExtension("WEBGL_compressed_texture_s3tc");
95
+
96
+ return ImageFilter(renderer, _width, _height, {
97
+ vertexShader: CopyShader.vertexShader,
98
+ fragmentShader: CopyShader.fragmentShader,
99
+ uniforms: {
100
+ tDiffuse: {
101
+ value: texture,
102
+ type: 't'
103
+ },
104
+ opacity: { value: 1.0 }
105
+ }
106
+ });
70
107
 
71
- return ImageFilter(renderer, _width, _height, {
72
- vertexShader: CopyShader.vertexShader,
73
- fragmentShader: CopyShader.fragmentShader,
74
- uniforms: {
75
- tDiffuse: {
76
- value: texture,
77
- type: 't'
78
- },
79
- opacity: { value: 1.0 }
80
- }
81
108
  });
82
109
 
83
- });
110
+ data = built.array;
111
+ }
84
112
 
85
113
  if (flipY) {
86
- flipArrayInPlace(built.array, _width, _height);
114
+ sampler2d_flipY_in_place(data, _width, _height);
87
115
  }
88
116
 
89
- return new Sampler2D(built.array, 4, _width, _height);
117
+ return new Sampler2D(data, 4, _width, _height);
90
118
  }
@@ -16,6 +16,7 @@ import { sampler2d_scale_down_lanczos } from "../resize/sampler2d_scale_down_lan
16
16
  import { sampler2d_scale_down_mipmap } from "../resize/sampler2d_scale_down_mipmap.js";
17
17
  import { sampler2d_scale_generic } from "../resize/sampler2d_scale_generic.js";
18
18
  import { Sampler2D } from "../Sampler2D.js";
19
+ import { sampler2d_copy_rectangle } from "../sampler2d_copy_rectangle.js";
19
20
  import { debug_draw_sampler } from "./debug_draw_sampler.js";
20
21
  import { debug_draw_sampler_grid } from "./debug_draw_sampler_grid.js";
21
22
 
@@ -35,40 +36,11 @@ function setup_zoom_preview({ engine, sampler }) {
35
36
 
36
37
  const preview_container = debug_draw_sampler(engine, preview, 0, sampler.height);
37
38
  preview_container.transformOrigin.set(0, 0);
38
- // preview_container.scale.setScalar(20);
39
-
40
- /**
41
- *
42
- * @param {Sampler2D} source
43
- * @param {Sampler2D} target
44
- * @param {number} u0
45
- * @param {number} v0
46
- * @param {number} u1
47
- * @param {number} v1
48
- */
49
- function update_preview(
50
- source, target,
51
- u0, v0, u1, v1
52
- ) {
53
-
54
- const sample = [];
55
-
56
- for (let y = 0; y < target.height; y++) {
57
- for (let x = 0; x < target.width; x++) {
58
-
59
- const local_u = x / target.width;
60
- const local_v = y / target.height;
61
39
 
62
- source.sampleBilinearUV(local_u * (u1 - u0) + u0, local_v * (v1 - v0) + v0, sample);
63
-
64
- target.write(x, y, sample);
65
-
66
- }
67
- }
40
+ // preview_container.scale.setScalar(20);
68
41
 
69
- }
70
42
 
71
- function setPreviewPosition(x,y){
43
+ function setPreviewPosition(x, y) {
72
44
  const window_size = 0.1;
73
45
 
74
46
 
@@ -81,7 +53,7 @@ function setup_zoom_preview({ engine, sampler }) {
81
53
  const center_v = clamp(v, w_2, 1 - w_2);
82
54
 
83
55
 
84
- update_preview(
56
+ sampler2d_copy_rectangle(
85
57
  sampler, preview,
86
58
  center_u - w_2, center_v - w_2,
87
59
  center_u + w_2, center_v + w_2
@@ -89,7 +61,7 @@ function setup_zoom_preview({ engine, sampler }) {
89
61
 
90
62
  preview_container.$redraw();
91
63
 
92
- console.log(x,y);
64
+ console.log(x, y);
93
65
  }
94
66
 
95
67
  // setPreviewPosition(366,420);
@@ -0,0 +1,11 @@
1
+ /**
2
+ *
3
+ * @param {Sampler2D} source
4
+ * @param {Sampler2D} target
5
+ * @param {number} u0
6
+ * @param {number} v0
7
+ * @param {number} u1
8
+ * @param {number} v1
9
+ */
10
+ export function sampler2d_copy_rectangle(source: Sampler2D, target: Sampler2D, u0: number, v0: number, u1: number, v1: number): void;
11
+ //# sourceMappingURL=sampler2d_copy_rectangle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sampler2d_copy_rectangle.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/texture/sampler/sampler2d_copy_rectangle.js"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,mFALW,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,QAiChB"}
@@ -0,0 +1,41 @@
1
+ /**
2
+ *
3
+ * @param {Sampler2D} source
4
+ * @param {Sampler2D} target
5
+ * @param {number} u0
6
+ * @param {number} v0
7
+ * @param {number} u1
8
+ * @param {number} v1
9
+ */
10
+ export function sampler2d_copy_rectangle(
11
+ source, target,
12
+ u0, v0, u1, v1
13
+ ) {
14
+
15
+ const sample = [];
16
+
17
+ const target_height = target.height;
18
+ const target_width = target.width;
19
+
20
+ const v_span = v1 - v0;
21
+ const u_span = u1 - u0;
22
+
23
+ const v_multiplier = v_span / target_height;
24
+ const u_multiplier = u_span / target_width;
25
+
26
+ for (let y = 0; y < target_height; y++) {
27
+
28
+ const source_v = y * v_multiplier + v0;
29
+
30
+ for (let x = 0; x < target_width; x++) {
31
+
32
+ const source_u = x * u_multiplier + u0;
33
+
34
+ source.sampleBilinearUV(source_u, source_v, sample);
35
+
36
+ target.write(x, y, sample);
37
+
38
+ }
39
+ }
40
+
41
+ }
@@ -25,10 +25,6 @@ export class VirtualTextureUsage {
25
25
  * @param {number} bias added to the ancestor tiles to make them more likely to be loaded
26
26
  */
27
27
  promoteAncestors(bias?: number): void;
28
- /**
29
- * Sort occupancy list in descending order
30
- */
31
- sortOccupancy(): void;
32
28
  sortOccupancyByLOD(): void;
33
29
  /**
34
30
  *
@@ -1 +1 @@
1
- {"version":3,"file":"VirtualTextureUsage.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/texture/virtual/VirtualTextureUsage.js"],"names":[],"mappings":"AAOA;IAcI,0BAEC;IAKD,+BAIC;IAED,4BAEC;IAGD,6BAEC;IAED,8BAEC;IAkBD;;;;OAIG;IACH,mCAHW,MAAM,GACJ,MAAM,CAMlB;IAED;;;;;;OAMG;IACH,gBALW,MAAM,KACN,MAAM,KACN,MAAM,GACJ,MAAM,CAMlB;IAED,cAGC;IAED;;;;OAIG;IACH,wBAFW,MAAM,QAsChB;IAWD;;OAEG;IACH,sBAiBC;IAED,2BAqBC;IAGD;;;OAGG;IACH,kBAFW,UAAU,QAsCpB;;CACJ"}
1
+ {"version":3,"file":"VirtualTextureUsage.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/texture/virtual/VirtualTextureUsage.js"],"names":[],"mappings":"AAMA;IAcI,0BAEC;IAKD,+BAIC;IAED,4BAEC;IAGD,6BAEC;IAED,8BAEC;IAkBD;;;;OAIG;IACH,mCAHW,MAAM,GACJ,MAAM,CAMlB;IAED;;;;;;OAMG;IACH,gBALW,MAAM,KACN,MAAM,KACN,MAAM,GACJ,MAAM,CAMlB;IAED,cAGC;IAED;;;;OAIG;IACH,wBAFW,MAAM,QAsChB;IAWD,2BAiCC;IAGD;;;OAGG;IACH,kBAFW,UAAU,QAsCpB;;CACJ"}
@@ -1,6 +1,5 @@
1
- import { array_quick_sort_by_comparator, arrayQuickSort } from "../../../../core/collection/array/arrayQuickSort.js";
1
+ import { array_quick_sort_by_comparator } from "../../../../core/collection/array/array_quick_sort_by_comparator.js";
2
2
  import { compose_tile_address } from "./tile/compose_tile_address.js";
3
- import { decompose_finger_print } from "./tile/decompose_finger_print.js";
4
3
  import { finger_print_to_tile_address } from "./tile/finger_print_to_tile_address.js";
5
4
  import { tile_address_to_finger_print } from "./tile/tile_address_to_finger_print.js";
6
5
 
@@ -142,36 +141,21 @@ export class VirtualTextureUsage {
142
141
  this.#occupancy_cursor++;
143
142
  }
144
143
 
145
- /**
146
- * Sort occupancy list in descending order
147
- */
148
- sortOccupancy() {
149
- // array_quick_sort_by_comparator(this.#occupancy, (a, b) => {
150
- //
151
- // return a-b;
152
- //
153
- //
154
- // }, null, 0, this.#occupancy_cursor - 1);
155
-
156
- //
157
- // arrayQuickSort(this.#occupancy, v => -v, null, 0, this.#occupancy_cursor - 1);
158
- arrayQuickSort(
159
- this.#occupancy,
160
- (index) => {
161
- return -this.#counts_intrinsic[index]
162
- }, null,
163
- 0, this.#occupancy_cursor - 1
164
- );
165
- }
166
-
167
144
  sortOccupancyByLOD() {
168
- array_quick_sort_by_comparator(this.#occupancy, (a, b) => {
145
+ /**
146
+ *
147
+ * @param {number} a
148
+ * @param {number} b
149
+ * @return {number}
150
+ */
151
+ const compare = (a, b) => {
169
152
 
170
153
  const fingerprint_a = tile_address_to_finger_print(a);
171
154
  const fingerprint_b = tile_address_to_finger_print(b);
172
155
 
173
- const { mip: mip_a } = decompose_finger_print(fingerprint_a);
174
- const { mip: mip_b } = decompose_finger_print(fingerprint_b);
156
+ // read MIP levels
157
+ const mip_a = (fingerprint_a >> 24) & 0xFF;
158
+ const mip_b = (fingerprint_b >> 24) & 0xFF;
175
159
 
176
160
  const mip_delta = mip_a - mip_b;
177
161
 
@@ -179,11 +163,16 @@ export class VirtualTextureUsage {
179
163
  return mip_delta;
180
164
  }
181
165
 
182
- const count_a = this.#counts_intrinsic[a];
183
- const count_b = this.#counts_intrinsic[b];
166
+ const intrinsic = this.#counts_intrinsic;
167
+
168
+ const count_a = intrinsic[a];
169
+ const count_b = intrinsic[b];
170
+
184
171
  return count_b - count_a;
185
172
 
186
- }, null, 0, this.#occupancy_cursor - 1);
173
+ };
174
+
175
+ array_quick_sort_by_comparator(this.#occupancy, compare, null, 0, this.#occupancy_cursor - 1);
187
176
 
188
177
  }
189
178