@woosh/meep-engine 2.42.8 → 2.43.1

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 (137) hide show
  1. package/core/binary/BitSet.js +4 -4
  2. package/core/binary/ctz32.js +40 -0
  3. package/core/collection/ObservedMap.js +61 -57
  4. package/core/collection/heap/FastBinaryHeap.js +7 -1
  5. package/core/collection/heap/Uint32Heap.js +19 -0
  6. package/core/collection/map/AsyncLoadingCache.js +3 -1
  7. package/core/geom/2d/compute_polygon_area_2d.js +32 -0
  8. package/core/geom/2d/compute_polygon_area_2d.spec.js +10 -0
  9. package/core/geom/2d/compute_triangle_area_2d.js +15 -0
  10. package/core/geom/2d/compute_triangle_area_2d.spec.js +9 -0
  11. package/core/geom/2d/convex-hull/convex_hull_jarvis_2d.js +64 -0
  12. package/core/geom/2d/convex-hull/convex_hull_jarvis_2d.spec.js +33 -0
  13. package/core/geom/2d/convex-hull/convex_hull_monotone_2d.js +82 -0
  14. package/core/geom/2d/convex-hull/fixed_convex_hull_humus.js +135 -0
  15. package/core/geom/2d/convex-hull/fixed_convex_hull_relaxation.js +282 -0
  16. package/core/geom/2d/convex-hull/orientation3.js +444 -0
  17. package/core/geom/2d/convex-hull/orientation3_array.js +22 -0
  18. package/core/geom/2d/convex-hull/orientation3_v2.js +12 -0
  19. package/core/geom/2d/intersect_ray_2d.js +56 -0
  20. package/core/geom/2d/quad-tree/QuadTreeNode.js +0 -81
  21. package/core/geom/2d/quad-tree/qt_match_data_by_circle.js +70 -0
  22. package/core/geom/3d/matrix/m4_multiply_alphatensor.js +131 -0
  23. package/core/geom/3d/plane/orient3d_fast.js +2 -6
  24. package/core/geom/3d/tetrahedra/README.md +7 -0
  25. package/core/geom/3d/tetrahedra/compute_bounding_simplex_3d.js +3 -1
  26. package/core/geom/3d/tetrahedra/delaunay/Cavity.js +48 -0
  27. package/core/geom/3d/tetrahedra/{compute_delaunay_tetrahedral_mesh.js → delaunay/compute_delaunay_tetrahedral_mesh.js} +15 -7
  28. package/core/geom/3d/tetrahedra/{compute_delaunay_tetrahedral_mesh.spec.js → delaunay/compute_delaunay_tetrahedral_mesh.spec.js} +0 -0
  29. package/core/geom/3d/tetrahedra/delaunay/tetrahedral_mesh_compute_cavity.js +73 -0
  30. package/core/geom/3d/tetrahedra/delaunay/tetrahedral_mesh_walk_toward_cavity.js +48 -0
  31. package/core/geom/3d/tetrahedra/hxt/a.js +524 -0
  32. package/core/geom/3d/tetrahedra/hxt/hxt.js +140 -0
  33. package/core/geom/3d/tetrahedra/hxt/hxt.wasm +0 -0
  34. package/core/geom/3d/tetrahedra/point_in_tetrahedron_circumsphere.js +35 -20
  35. package/core/geom/3d/tetrahedra/prototypeTetrahedraBuilder.js +98 -0
  36. package/core/geom/3d/tetrahedra/tetrahedra_collection.js +60 -131
  37. package/core/geom/packing/{MaxRectangles.js → max-rect/MaxRectangles.js} +28 -124
  38. package/core/geom/packing/max-rect/removeRedundantBoxes.js +69 -0
  39. package/core/geom/packing/max-rect/removeRedundantBoxesArray.js +40 -0
  40. package/core/geom/v3_distance_above_plane.js +1 -1
  41. package/core/graph/layout/BoxLayouter.js +2 -88
  42. package/core/graph/layout/CircleLayout.js +2 -1
  43. package/core/graph/layout/box/forceIntoBox.js +45 -0
  44. package/core/graph/layout/box/pullBoxTowardsPoint.js +20 -0
  45. package/core/graph/layout/box/resolveAABB2Overlap.js +22 -0
  46. package/core/math/bessel_3.js +11 -0
  47. package/core/math/bessel_i0.js +26 -0
  48. package/core/process/executor/ConcurrentExecutor.spec.js +2 -1
  49. package/core/process/task/util/actionTask.js +19 -0
  50. package/core/process/task/util/countTask.js +62 -0
  51. package/core/process/task/util/delayTask.js +45 -0
  52. package/core/process/task/util/emptyTask.js +19 -0
  53. package/core/process/task/util/failingTask.js +17 -0
  54. package/core/process/task/util/futureTask.js +48 -0
  55. package/core/process/task/util/promiseTask.js +42 -0
  56. package/core/process/task/util/randomCountTask.js +64 -0
  57. package/core/process/task/util/wrapTaskIgnoreFailure.js +47 -0
  58. package/engine/Engine.js +8 -8
  59. package/engine/EngineBootstrapper.js +1 -1
  60. package/engine/asset/AssetManager.d.ts +2 -0
  61. package/engine/asset/AssetManager.js +197 -53
  62. package/engine/asset/AssetRequest.js +32 -0
  63. package/engine/asset/loaders/ArrayBufferLoader.js +62 -50
  64. package/engine/asset/loaders/image/png/PNG.js +15 -1
  65. package/engine/asset/loaders/image/png/PNGReader.js +3 -2
  66. package/engine/ecs/foliage/ecs/InstancedMeshUtils.js +2 -1
  67. package/engine/ecs/storage/BinaryBufferDeSerializer.js +1 -1
  68. package/engine/ecs/storage/JSONDeSerializer.js +2 -1
  69. package/engine/ecs/terrain/ecs/splat/SplatMapOptimizer.js +2 -1
  70. package/engine/ecs/terrain/ecs/splat/SplatMapping.js +1 -1
  71. package/engine/graphics/camera/makeScreenScissorFrustum.js +1 -1
  72. package/engine/graphics/camera/testClippingPlaneComputation.js +4 -45
  73. package/engine/graphics/ecs/camera/FrustumProjector.js +6 -0
  74. package/engine/graphics/ecs/decal/v2/FPDecalSystem.js +5 -0
  75. package/engine/graphics/ecs/decal/v2/prototypeDecalSystem.js +23 -4
  76. package/engine/graphics/ecs/highlight/plugin/OutlineRenderPlugin.js +1 -1
  77. package/engine/graphics/ecs/mesh-v2/ShadedGeometry.js +11 -0
  78. package/engine/graphics/geometry/FULL_SCREEN_TRIANGLE_GEOMETRY.js +1 -2
  79. package/engine/graphics/impostors/octahedral/ImpostorBaker.js +5 -2
  80. package/engine/graphics/impostors/octahedral/ImpostorDescription.js +18 -0
  81. package/engine/graphics/impostors/octahedral/bake/prepare_bake_material.js +15 -0
  82. package/engine/graphics/impostors/octahedral/prototypeBaker.js +66 -79
  83. package/engine/graphics/impostors/octahedral/shader/ImpostorShaderWireframeV0.js +134 -0
  84. package/engine/graphics/impostors/octahedral/util/build_cutout_from_atlas_by_alpha.js +128 -0
  85. package/engine/graphics/impostors/octahedral/util/build_geometry_from_cutout_shape.js +32 -0
  86. package/engine/graphics/impostors/octahedral/util/load_mesh_for_bake.js +31 -0
  87. package/engine/graphics/impostors/octahedral/util/makeImpostorAtlasPreview.js +107 -0
  88. package/engine/graphics/material/manager/ManagedMaterial.js +4 -0
  89. package/engine/graphics/material/manager/MaterialManager.js +1 -0
  90. package/engine/graphics/material/optimization/MaterialOptimizationContext.js +7 -3
  91. package/engine/graphics/particles/particular/engine/renderers/billboard/ParticleBillboardMaterial.js +2 -2
  92. package/engine/graphics/render/forward_plus/prototype/prototypeLightManager.js +2 -2
  93. package/engine/graphics/render/visibility/hiz/buildCanvasViewFromTexture.js +83 -27
  94. package/engine/graphics/shadows/ShadowMapRenderer.js +11 -4
  95. package/engine/graphics/texture/atlas/AbstractTextureAtlas.js +2 -1
  96. package/engine/graphics/texture/atlas/CachingTextureAtlas.js +208 -38
  97. package/engine/graphics/texture/atlas/TextureAtlas.js +31 -24
  98. package/engine/graphics/texture/atlas/gpu/WebGLTextureAtlas.js +1 -1
  99. package/engine/graphics/texture/sampler/filter/box.js +16 -0
  100. package/engine/graphics/texture/sampler/filter/cubic2.js +32 -0
  101. package/engine/graphics/texture/sampler/filter/gaussian.js +16 -0
  102. package/engine/graphics/texture/sampler/filter/kaiser_1.js +19 -0
  103. package/engine/graphics/texture/sampler/filter/kaiser_bessel_window.js +19 -0
  104. package/engine/graphics/texture/sampler/filter/mitchell.js +55 -0
  105. package/engine/graphics/texture/sampler/filter/sampler2d_scale_down_generic.js +109 -0
  106. package/engine/graphics/texture/sampler/filter/triangle.js +19 -0
  107. package/engine/graphics/texture/sampler/prototypeSamplerFiltering.js +187 -86
  108. package/engine/graphics/texture/sampler/sampler2_d_scale_down_lanczos.js +77 -25
  109. package/engine/graphics/texture/sampler/search/make_edge_condition_channel_threshold.js +34 -0
  110. package/engine/graphics/texture/sampler/search/sampler2d_find_pixels.js +24 -0
  111. package/engine/graphics/texture/sprite/prototypeSpriteCutoutGeometry.js +212 -0
  112. package/engine/knowledge/database/StaticKnowledgeDataTable.js +1 -1
  113. package/engine/navigation/grid/AStar.js +1 -1
  114. package/engine/scene/Scene.js +1 -1
  115. package/engine/scene/SerializedScene.js +1 -1
  116. package/engine/scene/transitionToScene.js +3 -1
  117. package/generation/example/main.js +1 -1
  118. package/generation/grid/generation/GridTaskApplyActionToCells.js +1 -1
  119. package/generation/grid/generation/GridTaskDensityMarkerDistribution.js +1 -1
  120. package/generation/grid/generation/GridTaskExecuteRuleTimes.js +1 -1
  121. package/generation/grid/generation/NoopGridTaskGenerator.js +1 -1
  122. package/generation/grid/generation/discrete/GridTaskCellularAutomata.js +2 -1
  123. package/generation/grid/generation/discrete/GridTaskConnectRooms.js +1 -1
  124. package/generation/grid/generation/discrete/layer/GridTaskBuildSourceDistanceMap.js +3 -2
  125. package/generation/grid/generation/discrete/layer/GridTaskDistanceToMarkers.js +1 -1
  126. package/generation/grid/generation/grid/GridTaskAddNodesFixed.js +1 -1
  127. package/generation/grid/generation/road/GridTaskGenerateRoads.js +3 -2
  128. package/generation/grid/generation/util/buildDistanceMapToObjective.js +1 -1
  129. package/generation/markers/GridActionRuleSet.js +2 -1
  130. package/generation/placement/GridCellActionTransformNearbyMarkers.js +2 -4
  131. package/generation/theme/ThemeEngine.js +4 -1
  132. package/package.json +1 -1
  133. package/view/asset/AssetLoaderStatusView.js +5 -5
  134. package/view/minimap/gl/MinimapTerrainGL.js +1 -2
  135. package/view/renderModel.js +1 -1
  136. package/view/tooltip/TooltipView.js +5 -5
  137. package/core/process/task/TaskUtils.js +0 -352
@@ -0,0 +1,128 @@
1
+ //
2
+
3
+ import { renderSamplerFromTexture } from "../../../render/visibility/hiz/buildCanvasViewFromTexture.js";
4
+ import { convex_hull_jarvis_2d } from "../../../../../core/geom/2d/convex-hull/convex_hull_jarvis_2d.js";
5
+ import { fixed_convex_hull_relaxation } from "../../../../../core/geom/2d/convex-hull/fixed_convex_hull_relaxation.js";
6
+ import { array_copy } from "../../../../../core/collection/array/copyArray.js";
7
+ import { Sampler2D } from "../../../texture/sampler/Sampler2D.js";
8
+ import { max2 } from "../../../../../core/math/max2.js";
9
+ import { sampler2d_find_pixels } from "../../../texture/sampler/search/sampler2d_find_pixels.js";
10
+ import {
11
+ make_edge_condition_channel_threshold
12
+ } from "../../../texture/sampler/search/make_edge_condition_channel_threshold.js";
13
+ import { compute_polygon_area_2d } from "../../../../../core/geom/2d/compute_polygon_area_2d.js";
14
+
15
+ /**
16
+ * TODO For this specific use-case with octahedral impostors we can get away tracing a circular shape in general.
17
+ * A circle is a lot easier to quantize (as long as we make sure we place edges outside of the circle)
18
+ * @param {ImpostorDescription} impostor
19
+ * @param {THREE.WebGLRenderer} renderer
20
+ * @returns {number}
21
+ */
22
+ export function build_cutout_from_atlas_by_alpha(impostor, renderer) {
23
+ // get impostor data first
24
+
25
+ const ctrl = renderSamplerFromTexture({
26
+ renderer: renderer,
27
+ // swizzle: ['a', 'a', 'a', 1],
28
+ swizzle: ['a', 'a', 'a', 1],
29
+ texture: impostor.rt.texture[0]
30
+ });
31
+
32
+ ctrl.render();
33
+
34
+ const source_canvas_data = ctrl.destination.data;
35
+
36
+ // build set of border pixels
37
+ const frame_size = impostor.resolution / impostor.frame_count;
38
+ const frame_size_i = Math.ceil(frame_size);
39
+
40
+ const accummulator = Sampler2D.uint8(1, frame_size_i, frame_size_i);
41
+
42
+ for (let i = 0; i < impostor.frame_count; i++) {
43
+
44
+ const frame_offset_y = Math.floor(frame_size * i);
45
+
46
+ for (let j = 0; j < impostor.frame_count; j++) {
47
+
48
+ const frame_offset_x = Math.floor(frame_size * j);
49
+
50
+ for (let y = 0; y < frame_size_i; y++) {
51
+ const global_y = frame_offset_y + y;
52
+
53
+ for (let x = 0; x < frame_size_i; x++) {
54
+
55
+ const global_x = x + frame_offset_x;
56
+
57
+ const global_index = global_y * impostor.resolution + global_x;
58
+
59
+ const v = source_canvas_data[global_index * 4];
60
+
61
+
62
+ if (v > 0) {
63
+
64
+ const local_index = y * frame_size_i + x;
65
+
66
+ accummulator.data[local_index] = max2(v, accummulator.data[local_index]);
67
+ }
68
+ }
69
+ }
70
+ }
71
+ }
72
+
73
+
74
+ const edge_pixels = sampler2d_find_pixels(accummulator, make_edge_condition_channel_threshold(0, 5));
75
+
76
+ // filtered pixels
77
+ const filtered_edge_pixels = [];
78
+
79
+ const half_pixel = 0.5;
80
+
81
+ for (let i = 0; i < edge_pixels.length; i += 2) {
82
+ const x = edge_pixels[i];
83
+ const y = edge_pixels[i + 1];
84
+
85
+ filtered_edge_pixels.push(x - half_pixel, y - half_pixel);
86
+ filtered_edge_pixels.push(x + half_pixel, y - half_pixel);
87
+ filtered_edge_pixels.push(x + half_pixel, y + half_pixel);
88
+ filtered_edge_pixels.push(x - half_pixel, y + half_pixel);
89
+ }
90
+
91
+ const hull_point_indices = convex_hull_jarvis_2d(filtered_edge_pixels, filtered_edge_pixels.length / 2);
92
+
93
+ const hull_points = [];
94
+
95
+ for (let i = 0; i < hull_point_indices.length; i++) {
96
+ const hpi = hull_point_indices[i];
97
+
98
+ array_copy(filtered_edge_pixels, hpi * 2, hull_points, i * 2, 2);
99
+ }
100
+
101
+ const cutout_vertex_count = 8;
102
+
103
+ const cutout_points = new Float32Array(cutout_vertex_count * 2);
104
+
105
+ fixed_convex_hull_relaxation(cutout_points, 0, cutout_vertex_count, hull_points, hull_point_indices.length);
106
+
107
+ // normalize points
108
+ for (let i = 0; i < cutout_vertex_count; i++) {
109
+ cutout_points[i * 2] /= frame_size;
110
+ cutout_points[i * 2 + 1] /= frame_size;
111
+ }
112
+
113
+ const area = compute_polygon_area_2d(cutout_points, cutout_vertex_count);
114
+
115
+ console.log(`Cutout area: ${area}`);
116
+
117
+ if (area >= 0.99 && cutout_vertex_count >= 4) {
118
+ // default back to aligned quad, produced result is a degradation
119
+ return new Float32Array([
120
+ 0, 0,
121
+ 1, 0,
122
+ 1, 1,
123
+ 0, 1
124
+ ]);
125
+ }
126
+
127
+ return cutout_points;
128
+ }
@@ -0,0 +1,32 @@
1
+ import { Matrix4, Shape, ShapeBufferGeometry } from "three";
2
+
3
+ /**
4
+ *
5
+ * @param {number[]} cutout
6
+ * @return {THREE.BufferGeometry}
7
+ */
8
+ export function build_geometry_from_cutout_shape(cutout) {
9
+
10
+ const shape = new Shape();
11
+
12
+ shape.moveTo(cutout[0], cutout[1]);
13
+
14
+ for (let i = 2; i < cutout.length; i += 2) {
15
+ shape.lineTo(cutout[i], cutout[i + 1]);
16
+ }
17
+
18
+ shape.closePath();
19
+
20
+ const geometry = new ShapeBufferGeometry(shape);
21
+
22
+ // move shape by 0.5 to center on origin
23
+ const attribute = geometry.getAttribute('position');
24
+
25
+ const mat = new Matrix4();
26
+ mat.makeTranslation(-0.5, -0.5, 0);
27
+
28
+ attribute.applyMatrix4(mat);
29
+ //
30
+
31
+ return geometry;
32
+ }
@@ -0,0 +1,31 @@
1
+ import { GameAssetType } from "../../../../asset/GameAssetType.js";
2
+ import { three_object_to_entity_composition } from "../../../ecs/mesh-v2/three_object_to_entity_composition.js";
3
+ import { ShadedGeometry } from "../../../ecs/mesh-v2/ShadedGeometry.js";
4
+ import { Transform } from "../../../../ecs/transform/Transform.js";
5
+
6
+ /**
7
+ *
8
+ * @param {Engine} engine
9
+ * @param {string} url
10
+ * @return {Promise<{mesh:ShadedGeometry,transform:mat4}[]>}
11
+ */
12
+ export async function load_mesh_for_bake(engine, url) {
13
+
14
+ const gltf_asset = await engine.assetManager.promise(url, GameAssetType.ModelGLTF_JSON);
15
+
16
+ const node_hierarchy = three_object_to_entity_composition(gltf_asset.create());
17
+
18
+ const objects = [];
19
+
20
+ node_hierarchy.traverse(n => {
21
+ const sg = n.entity.getComponent(ShadedGeometry);
22
+ if (sg !== null) {
23
+ objects.push({
24
+ mesh: sg,
25
+ transform: n.entity.getComponent(Transform).matrix
26
+ })
27
+ }
28
+ });
29
+
30
+ return objects;
31
+ }
@@ -0,0 +1,107 @@
1
+ import { buildCanvasViewFromTexture } from "../../../render/visibility/hiz/buildCanvasViewFromTexture.js";
2
+ import EmptyView from "../../../../../view/elements/EmptyView.js";
3
+ import { CanvasView } from "../../../../../view/elements/CanvasView.js";
4
+
5
+ /**
6
+ * @param {ImpostorDescription} impostor
7
+ * @returns {View}
8
+ */
9
+ function makeGrid(impostor) {
10
+ const vGrid = new CanvasView();
11
+
12
+ vGrid.size.set(impostor.resolution, impostor.resolution);
13
+
14
+ const ctx = vGrid.context2d;
15
+
16
+ ctx.strokeStyle = "rgba(64,255,0,0.5)";
17
+ ctx.lineWidth = 1;
18
+
19
+ ctx.beginPath();
20
+
21
+ const frame_size = impostor.resolution / impostor.frame_count;
22
+
23
+ for (let i = 0; i < impostor.frame_count; i++) {
24
+
25
+ ctx.moveTo(0, i * frame_size);
26
+ ctx.lineTo(impostor.resolution, i * frame_size);
27
+ }
28
+
29
+ for (let i = 0; i < impostor.frame_count; i++) {
30
+ ctx.moveTo(i * frame_size, 0);
31
+ ctx.lineTo(i * frame_size, impostor.resolution);
32
+ }
33
+
34
+ ctx.stroke();
35
+
36
+ vGrid.css({
37
+
38
+ position: 'absolute',
39
+ top: '0',
40
+ left: '0'
41
+ });
42
+ return vGrid;
43
+ }
44
+
45
+ /**
46
+ *
47
+ * @param {ImpostorDescription} impostor
48
+ * @param {THREE.WebGLRenderer} renderer
49
+ * @param {'albedo'|'normal'|'depth'|'alpha'} [mode]
50
+ * @param {boolean} [show_grid]
51
+ * @return {View}
52
+ */
53
+ export function makeImpostorAtlasPreview({
54
+ impostor,
55
+ renderer,
56
+ mode = 'albedo',
57
+ show_grid = true
58
+ }) {
59
+
60
+ const options = {};
61
+
62
+
63
+ switch (mode) {
64
+ case "normal":
65
+ options.swizzle = ['r', 'g', 'b', 1];
66
+ options.texture = impostor.rt.texture[1]
67
+ break
68
+ case "alpha":
69
+ options.swizzle = ['a', 'a', 'a', 1];
70
+ options.texture = impostor.rt.texture[0]
71
+ break;
72
+ case "depth":
73
+ options.swizzle = ['a', 'a', 'a', 1];
74
+ options.texture = impostor.rt.texture[1]
75
+ break;
76
+ default:
77
+ console.warn(`Unsupported mode '${mode}', defaulting to albedo`);
78
+ //fall-through
79
+ case 'albedo':
80
+ options.swizzle = ['r', 'g', 'b', 1];
81
+ options.texture = impostor.rt.texture[0]
82
+ break;
83
+ }
84
+
85
+ const ctrl = buildCanvasViewFromTexture(Object.assign({ renderer }, options));
86
+
87
+ ctrl.view.css({
88
+ opacity: 1,
89
+ position: 'absolute',
90
+ top: '0',
91
+ left: '0'
92
+ });
93
+ ctrl.render();
94
+
95
+ const vContainer = new EmptyView();
96
+
97
+ vContainer.addChild(ctrl.view);
98
+
99
+ if (show_grid) {
100
+
101
+ const vGrid = makeGrid(impostor);
102
+
103
+ vContainer.addChild(vGrid);
104
+ }
105
+
106
+ return vContainer;
107
+ }
@@ -40,6 +40,10 @@ export class ManagedMaterial {
40
40
  return this.__source;
41
41
  }
42
42
 
43
+ setSource(v) {
44
+ this.__source = v;
45
+ }
46
+
43
47
  /**
44
48
  *
45
49
  * @returns {Material}
@@ -155,6 +155,7 @@ export class MaterialManager {
155
155
  const mat = this.__compile(source);
156
156
 
157
157
  material = new ManagedMaterial(mat);
158
+ material.setSource(source);
158
159
  }
159
160
 
160
161
  material.onLastReleased.addOne(this.__handle_last_reference_removed, this);
@@ -2,7 +2,7 @@ import { traverseThreeObject } from "../../ecs/highlight/renderer/traverseThreeO
2
2
  import { TextureAttachmentsByMaterialType } from "../../../asset/loaders/material/TextureAttachmensByMaterialType.js";
3
3
  import { HashMap } from "../../../../core/collection/HashMap.js";
4
4
  import AABB2 from "../../../../core/geom/AABB2.js";
5
- import { MaxRectanglesPacker } from "../../../../core/geom/packing/MaxRectangles.js";
5
+ import { MaxRectanglesPacker } from "../../../../core/geom/packing/max-rect/MaxRectangles.js";
6
6
  import { Sampler2D } from "../../texture/sampler/Sampler2D.js";
7
7
  import { array_push_if_unique } from "../../../../core/collection/array/array_push_if_unique.js";
8
8
  import { computeMaterialHash } from "../../../asset/loaders/material/computeMaterialHash.js";
@@ -21,10 +21,14 @@ import { convertTexture2Sampler2D } from "../../texture/sampler/convertTexture2S
21
21
  import { BUFFER_GEOMETRY_UVS } from "./BUFFER_GEOMETRY_UVS.js";
22
22
  import { is_compliant_mesh } from "./is_compliant_mesh.js";
23
23
  import { MaterialDescriptor } from "./MaterialDescriptor.js";
24
- import { computeThreeTextureTypeFromDataType } from "../../render/forward_plus/data/computeThreeTextureTypeFromDataType.js";
24
+ import {
25
+ computeThreeTextureTypeFromDataType
26
+ } from "../../render/forward_plus/data/computeThreeTextureTypeFromDataType.js";
25
27
  import { typedArrayToDataType } from "../../../../core/collection/array/typedArrayToDataType.js";
26
28
  import { DataType } from "../../../../core/collection/table/DataType.js";
27
- import { compute_typed_array_constructor_from_data_type } from "../../../../core/collection/table/DataType2TypedArrayConstructorMapping.js";
29
+ import {
30
+ compute_typed_array_constructor_from_data_type
31
+ } from "../../../../core/collection/table/DataType2TypedArrayConstructorMapping.js";
28
32
  import { copy_Sampler2D_channel_data } from "../../texture/sampler/copy_Sampler2D_channel_data.js";
29
33
  import { channelCountToThreeTextureFormat } from "../../texture/channelCountToThreeTextureFormat.js";
30
34
  import { prepare_atlas_texture } from "./prepare_atlas_texture.js";
@@ -7,9 +7,9 @@ import {
7
7
  OneMinusSrcAlphaFactor,
8
8
  ShaderMaterial,
9
9
  UniformsLib,
10
- UniformsUtils
10
+ UniformsUtils,
11
+ Vector2 as ThreeVector2
11
12
  } from "three";
12
- import { Vector2 as ThreeVector2 } from "three/src/math/Vector2.js";
13
13
 
14
14
  const CHUNK_LAMBERT_LIGHTING = `
15
15
  vec3 diffuse = vec3( 1.0 );
@@ -1561,10 +1561,10 @@ function draw_camera_view_planes() {
1561
1561
  // prepare_scene_2();
1562
1562
  // prepare_scene_decal_0();
1563
1563
  // prepare_scene_decal_1();
1564
- prepare_scene_decal_2();
1564
+ // prepare_scene_decal_2();
1565
1565
  // prepare_scene_9();
1566
1566
  // prepare_scene_2();
1567
- // prepare_scene_0();
1567
+ prepare_scene_0();
1568
1568
  animate();
1569
1569
 
1570
1570
  // draw_camera_view_planes();
@@ -14,6 +14,7 @@ import { FULL_SCREEN_TRIANGLE_GEOMETRY } from "../../../geometry/FULL_SCREEN_TRI
14
14
  import { formatToChannelCount } from "../../../texture/formatToChannelCount.js";
15
15
  import { glsl_gen_swizzled_read } from "../../../shaders/glsl_gen_swizzled_read.js";
16
16
  import { assert } from "../../../../../core/assert.js";
17
+ import { Sampler2D } from "../../../texture/sampler/Sampler2D.js";
17
18
 
18
19
 
19
20
  /**
@@ -92,6 +93,7 @@ function makeShader({ texture, alpha_override, swizzle }) {
92
93
  });
93
94
  }
94
95
 
96
+
95
97
  /**
96
98
  *
97
99
  * @param {number} height
@@ -100,29 +102,21 @@ function makeShader({ texture, alpha_override, swizzle }) {
100
102
  * @param {THREE.WebGLRenderer} renderer
101
103
  * @param {boolean} [flipY]
102
104
  * @param {(string|number)[]} [swizzle]
103
- * @return {{view: View, render: function}}
105
+ * @param {Sampler2D} [destination]
106
+ * @return {{destination: Sampler2D, render: function}}
104
107
  */
105
- export function buildCanvasViewFromTexture({
106
- texture = CheckersTexture.create(),
107
- width = texture.image.width,
108
- height = texture.image.height,
109
- renderer,
110
- flipY = true,
111
- swizzle = ['r', 'g', 'b', 'a']
112
- }) {
113
-
108
+ export function renderSamplerFromTexture({
109
+
110
+ texture = CheckersTexture.create(),
111
+ width = texture.image.width,
112
+ height = texture.image.height,
113
+ renderer,
114
+ flipY = true,
115
+ swizzle = ['r', 'g', 'b', 'a'],
116
+ destination = Sampler2D.uint8clamped(4, width, height)
117
+ }) {
114
118
  assert.isArray(swizzle, 'swizzle');
115
119
 
116
- const canvasView = new CanvasView();
117
- canvasView.css({
118
- position: 'absolute',
119
- left: 0,
120
- top: 0
121
- });
122
- canvasView.size.set(width, height);
123
-
124
- const ctx = canvasView.context2d;
125
-
126
120
  let copyShader = null;
127
121
 
128
122
  const camera = new OrthographicCamera(-1, 1, 1, -1, 0, 1);
@@ -147,8 +141,6 @@ export function buildCanvasViewFromTexture({
147
141
  };
148
142
  const renderTarget = new WebGLRenderTarget(width, height, renderTargetOptions);
149
143
 
150
- const imageData = ctx.createImageData(width, height);
151
-
152
144
  let __texture_cached = texture;
153
145
 
154
146
  /**
@@ -172,7 +164,10 @@ export function buildCanvasViewFromTexture({
172
164
 
173
165
  const render = () => {
174
166
 
175
- getShader().uniforms.tDiffuse.value = texture;
167
+ const shader = getShader();
168
+
169
+ shader.uniforms.tDiffuse.value = texture;
170
+ shader.uniformsNeedUpdate = true;
176
171
 
177
172
  const _rt = renderer.getRenderTarget();
178
173
 
@@ -180,16 +175,15 @@ export function buildCanvasViewFromTexture({
180
175
 
181
176
  renderer.render(scene, camera);
182
177
 
183
- gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, imageData.data);
184
-
178
+ destination.resize(width, height);
185
179
 
186
- ctx.putImageData(imageData, 0, 0)
180
+ gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, destination.data);
187
181
 
188
182
  renderer.setRenderTarget(_rt);
189
183
  };
190
184
 
191
185
  return {
192
- view: canvasView,
186
+ destination,
193
187
  render,
194
188
  set texture(v) {
195
189
 
@@ -199,3 +193,65 @@ export function buildCanvasViewFromTexture({
199
193
  }
200
194
  }
201
195
  }
196
+
197
+ /**
198
+ *
199
+ * @param {number} height
200
+ * @param {number} width
201
+ * @param {THREE.Texture} texture
202
+ * @param {THREE.WebGLRenderer} renderer
203
+ * @param {boolean} [flipY]
204
+ * @param {(string|number)[]} [swizzle]
205
+ * @return {{view: View, render: function}}
206
+ */
207
+ export function buildCanvasViewFromTexture({
208
+ texture,
209
+ width = texture.image.width,
210
+ height = texture.image.height,
211
+ renderer,
212
+ flipY = true,
213
+ swizzle
214
+ }) {
215
+
216
+ const canvasView = new CanvasView();
217
+ canvasView.css({
218
+ position: 'absolute',
219
+ left: 0,
220
+ top: 0
221
+ });
222
+ canvasView.size.set(width, height);
223
+
224
+ const ctx = canvasView.context2d;
225
+
226
+ const imageData = ctx.createImageData(width, height);
227
+
228
+ // wrap imageData in Sampler2D
229
+ const sampler = new Sampler2D(imageData.data, 4, width, height);
230
+
231
+
232
+ const ctrl = renderSamplerFromTexture({
233
+ texture,
234
+ width,
235
+ height,
236
+ flipY,
237
+ renderer,
238
+ swizzle,
239
+ destination: sampler
240
+ });
241
+
242
+
243
+ function render() {
244
+ ctrl.render();
245
+
246
+ ctx.putImageData(imageData, 0, 0);
247
+ }
248
+
249
+
250
+ return {
251
+ view: canvasView,
252
+ render,
253
+ set texture(v) {
254
+ ctrl.texture = v;
255
+ }
256
+ }
257
+ }
@@ -1,8 +1,15 @@
1
- import { Color, Scene, Vector2, VSMShadowMap } from "three";
2
- import { LinearFilter, NearestFilter, RGBAFormat } from "three/src/constants.js";
3
- import { WebGLRenderTarget } from "three/src/renderers/WebGLRenderTarget.js";
1
+ import {
2
+ Color,
3
+ LinearFilter,
4
+ NearestFilter,
5
+ RGBAFormat,
6
+ Scene,
7
+ ShaderMaterial,
8
+ Vector2,
9
+ VSMShadowMap,
10
+ WebGLRenderTarget
11
+ } from "three";
4
12
  import Signal from "../../../core/events/signal/Signal.js";
5
- import { ShaderMaterial } from "three/src/materials/ShaderMaterial.js";
6
13
  import { fragment as vsm_frag, vertex as vsm_vert } from "./vsm.glsl.js";
7
14
  import { renderScreenSpace } from "../render/utils/renderScreenSpace.js";
8
15
 
@@ -2,9 +2,10 @@ export class AbstractTextureAtlas {
2
2
  /**
3
3
  *
4
4
  * @param {Sampler2D} sampler
5
+ * @param {number} padding
5
6
  * @returns {AtlasPatch}
6
7
  */
7
- add(sampler) {
8
+ add(sampler, padding) {
8
9
  throw new Error('Not Implemented');
9
10
  }
10
11