@woosh/meep-engine 2.33.4 → 2.33.9
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.
- package/core/binary/BinaryBuffer.js +26 -2
- package/core/bvh2/LeafNode.js +6 -1
- package/core/bvh2/aabb3/AABB3.js +21 -1
- package/core/collection/RingBuffer.js +40 -10
- package/core/collection/array/copyArray.js +2 -2
- package/core/collection/array/typed/typed_array_copy.js +2 -2
- package/core/collection/set/compute_set_difference.js +32 -0
- package/core/collection/set/compute_set_intersection.js +22 -0
- package/core/collection/set/set_remove.js +15 -0
- package/core/collection/table/DataType2TypedArrayConstructorMapping.js +2 -0
- package/core/collection/table/DataTypeByteSizes.js +21 -0
- package/core/collection/table/RowFirstTable.js +1 -88
- package/core/collection/table/RowFirstTable.spec.js +3 -1
- package/core/collection/table/RowFirstTableSpec.js +9 -19
- package/core/collection/table/computeDataTypeByIndex.js +21 -0
- package/core/collection/table/deserializeRowFirstTable.js +48 -0
- package/core/collection/table/serializeRowFirstTable.js +27 -0
- package/core/color/Color.js +1 -0
- package/core/color/ColorUtils.js +12 -3
- package/core/geom/3d/aabb/aabb3_compute_projected_area.js +6 -4
- package/core/geom/3d/aabb/aabb3_estimate_projected_area2.js +59 -0
- package/core/geom/3d/aabb/aabb3_from_min_max.js +15 -0
- package/core/geom/3d/aabb/aabb3_matrix4_project.js +33 -0
- package/core/geom/3d/aabb/aabb3_matrix4_project.spec.js +41 -0
- package/core/geom/3d/aabb/aabb3_matrix4_project_by_corners.js +96 -0
- package/{engine/graphics/micron/render/v1 → core/geom/3d}/apply_mat4_transform_to_v3_array.js +0 -0
- package/{engine/graphics/micron/build/bounds → core/geom/3d}/compute_bounding_cone_of_2_cones.js +3 -3
- package/{engine/graphics/micron/build/bounds → core/geom/3d}/compute_bounding_cone_of_2_cones.spec.js +1 -1
- package/{engine/graphics/micron/build/bounds → core/geom/3d}/compute_bounding_sphere_of_2_spheres.js +3 -3
- package/{engine/graphics/micron/util → core/geom/3d}/encode_unit3_hemioct.js +0 -0
- package/core/geom/3d/frustum/array_normalize_plane.js +25 -0
- package/core/geom/3d/frustum/array_setFromProjectionMatrix.js +60 -0
- package/{engine/graphics/micron/util → core/geom/3d}/unit_hemioct.spec.js +1 -1
- package/{engine/graphics/micron/build → core}/graph/MultiNode.js +0 -0
- package/{engine/graphics/micron/build → core}/graph/SquareMatrix.js +2 -2
- package/{engine/graphics/micron/build → core}/graph/SquareMatrix.spec.js +1 -1
- package/{engine/graphics/micron/build → core}/graph/WeightedEdge.js +1 -1
- package/{engine/graphics/micron/build → core}/graph/build_face_graph_from_mesh.js +2 -2
- package/{engine/graphics/micron/build/clustering → core/graph}/cluster_mesh_metis.js +2 -6
- package/{engine/graphics/micron/build → core}/graph/coarsen_graph.js +1 -1
- package/{engine/graphics/micron/build → core}/graph/coarsen_graph.spec.js +1 -1
- package/{engine/graphics/micron/build → core}/graph/eigen/eigen.js +0 -0
- package/{engine/graphics/micron/build → core}/graph/eigen/eigen.spec.js +1 -1
- package/{engine/graphics/micron/build/hierarchy → core/graph/eigen}/eigen_values_find_spectral_gap.js +0 -0
- package/{engine/graphics/micron/build → core}/graph/graph_adjacency_matrix.js +0 -0
- package/{engine/graphics/micron/build → core}/graph/graph_compute_disconnected_clusters.js +0 -0
- package/{engine/graphics/micron/build → core}/graph/graph_degree_matrix.js +0 -0
- package/{engine/graphics/micron/build → core}/graph/graph_k_means_cluster.js +5 -5
- package/{engine/graphics/micron/build → core}/graph/graph_laplacian_matrix.js +1 -1
- package/{engine/graphics/micron/build → core}/graph/metis/metis.js +2 -2
- package/{engine/graphics/micron/build → core}/graph/metis/metis_options.js +0 -0
- package/{engine/graphics/micron/build → core}/graph/mn_graph_collapse_weighted_edge.js +0 -0
- package/core/process/undo/ActionProcessor.d.ts +2 -0
- package/core/process/undo/ActionProcessor.js +59 -1
- package/core/process/undo/ActionProcessor.spec.js +59 -0
- package/core/process/undo/Mark.js +2 -1
- package/engine/Engine.d.ts +2 -0
- package/engine/EngineHarness.js +4 -4
- package/engine/asset/loaders/material/bitmap2sampler_gl.js +19 -0
- package/engine/asset/loaders/material/computeImageBitmapEquality.js +7 -19
- package/engine/ecs/foliage/InstancedFoliage.js +3 -5
- package/engine/ecs/fow/serialization/FogOfWarSerializationAdapter.js +2 -1
- package/engine/ecs/transform/Transform.js +2 -1
- package/engine/graphics/GraphicsEngine.js +9 -116
- package/engine/graphics/ecs/mesh/updateNodeByTransformAndBBB.js +22 -37
- package/engine/graphics/ecs/mesh-v2/ShadedGeometry.js +155 -0
- package/engine/graphics/ecs/mesh-v2/ShadedGeometrySystem.js +68 -0
- package/engine/graphics/ecs/mesh-v2/prototypeShadedGeometry.js +31 -0
- package/engine/graphics/filter/FlipArrayInPlace.js +25 -0
- package/engine/graphics/filter/FlipArrayViaCanvas.js +13 -0
- package/engine/graphics/filter/ImageFilter.js +20 -51
- package/engine/graphics/{micron → geometry}/aabb3_to_buffer_geometry.js +0 -0
- package/engine/graphics/{micron/build → geometry/buffered}/compute_buffer_geometry_byte_size.js +0 -0
- package/engine/graphics/geometry/instancing/InstancedMeshGroup.js +25 -16
- package/engine/graphics/material/SplatMaterial.js +4 -97
- package/engine/graphics/micron/build/buildMicronGeometryFromBufferGeometry.js +2 -6
- package/engine/graphics/micron/build/clustering/build_clustering_2.js +2 -2
- package/engine/graphics/micron/build/clustering/build_leaf_patches_metis.js +1 -1
- package/engine/graphics/micron/build/fill_patch_geometry_data.js +2 -0
- package/engine/graphics/micron/build/hierarchy/buildAbstractPatchHierarchy.js +3 -3
- package/engine/graphics/micron/build/hierarchy/build_intermediate_patch_topology.js +0 -72
- package/engine/graphics/micron/build/hierarchy/build_merge_graph.js +2 -2
- package/engine/graphics/micron/build/hierarchy/computePatchMergeScore.js +3 -3
- package/engine/graphics/micron/build/hierarchy/merge_patches.js +6 -3
- package/engine/graphics/micron/build/hierarchy/metis_cluster_clusters.js +1 -1
- package/engine/graphics/micron/build/hierarchy/optimize_graph_partitioning_balance.js +1 -1
- package/engine/graphics/micron/build/hierarchy/patch_combine.js +2 -2
- package/engine/graphics/micron/build/hierarchy/qvdr_build_simplified_clusters.js +2 -1
- package/engine/graphics/micron/format/MicronGeometry.js +12 -0
- package/engine/graphics/micron/format/MicronGeometryBufferAttributeSpec.js +2 -2
- package/engine/graphics/micron/format/MicronGeometryPatch.js +17 -9
- package/engine/graphics/micron/format/MicronVertexDataSpec.js +25 -3
- package/engine/graphics/micron/format/serialization/MicronGeometryBinarySerializationAdapter.js +101 -0
- package/engine/graphics/micron/format/serialization/deserialize_attribute_spec.js +25 -0
- package/engine/graphics/micron/format/serialization/deserialize_patch.js +104 -0
- package/engine/graphics/micron/format/serialization/serialize_attribute_spec.js +18 -0
- package/engine/graphics/micron/format/serialization/serialize_patch.js +84 -0
- package/engine/graphics/micron/prototypeVirtualGeometry.js +1 -1
- package/engine/graphics/micron/render/VirtualGeometryBuilder.js +27 -23
- package/engine/graphics/micron/render/culling/{PathCullingSystem.js → PatchCullingSystem.js} +1 -1
- package/engine/graphics/micron/render/instanced/AttributeDataTexture.js +3 -5
- package/engine/graphics/micron/render/refinement/ActivePatchList.js +38 -49
- package/engine/graphics/micron/render/refinement/ActivePatchRecord.js +4 -2
- package/engine/graphics/micron/render/refinement/RefinementSpec.js +98 -0
- package/engine/graphics/micron/render/v1/MaterialVertexSpec.js +21 -0
- package/engine/graphics/micron/render/v1/VGThreeRenderer.js +12 -9
- package/engine/graphics/micron/render/v1/getTransformedPositionsCached.js +1 -1
- package/engine/graphics/render/buffer/buffers/ColorAndDepthFrameBuffer.js +5 -3
- package/engine/graphics/render/buffer/buffers/prototypeNormalFrameBuffer.js +8 -10
- package/engine/graphics/render/forward_plus/LightManager.js +5 -7
- package/engine/graphics/render/forward_plus/data/NumericType.js +9 -0
- package/engine/graphics/render/forward_plus/{TextureBackedMemoryRegion.js → data/TextureBackedMemoryRegion.js} +11 -190
- package/engine/graphics/render/forward_plus/data/channelCountToThreIntegerTextureType.js +16 -0
- package/engine/graphics/render/forward_plus/data/computeDataType.js +36 -0
- package/engine/graphics/render/forward_plus/data/computeThreeTextureFormat.js +18 -0
- package/engine/graphics/render/forward_plus/data/computeThreeTextureInternalFormatFromDataType.js +63 -0
- package/engine/graphics/render/forward_plus/data/computeThreeTextureTypeFromDataType.js +41 -0
- package/engine/graphics/render/forward_plus/plugin/ptototypeFPPlugin.js +1 -1
- package/engine/graphics/render/forward_plus/prototypeLightManager.js +1 -1
- package/engine/graphics/render/visibility/hiz/buffer/HierarchicalZBuffer.js +198 -0
- package/engine/graphics/render/visibility/hiz/buffer/ReductionShader.js +51 -0
- package/engine/graphics/render/visibility/hiz/buildCanvasViewFromTexture.js +179 -0
- package/engine/graphics/render/visibility/hiz/prototypeHiZ.js +440 -0
- package/engine/graphics/render/visibility/hiz/query/BatchOcclusionQuery.js +174 -0
- package/engine/graphics/render/visibility/hiz/query/QueryShader.js +173 -0
- package/engine/graphics/shadows/ShadowMapRenderer.js +12 -2
- package/engine/graphics/texture/cubemap/buildCubeURLs.js +13 -0
- package/engine/graphics/texture/cubemap/load_environment_map.d.ts +8 -0
- package/engine/graphics/texture/cubemap/load_environment_map.js +163 -0
- package/engine/graphics/texture/sampler/Sampler2D.js +18 -62
- package/engine/graphics/texture/sampler/TextureBinaryBufferSerializer.js +1 -1
- package/engine/graphics/texture/sampler/convertTexture2Sampler2D.js +3 -2
- package/engine/graphics/texture/sampler/debug/paintSamplerOnHTML.js +3 -2
- package/engine/graphics/texture/sampler/differenceSampler.js +31 -0
- package/engine/graphics/texture/sampler/typedArrayConstructorByInstance.js +25 -0
- package/engine/graphics/texture/sampler/util/drawSamplerHTML.js +3 -2
- package/engine/graphics/texture/virtual/v2/ShaderUsage.js +6 -5
- package/engine/graphics/texture/virtual/v2/prototype.js +16 -6
- package/engine/network/convertPathToURL.js +6 -0
- package/engine/plugin/EnginePluginManager.d.ts +9 -0
- package/engine/reference/v2/Reference.d.ts +7 -0
- package/package.json +1 -1
- package/view/minimap/gl/MinimapMarkersGL.js +2 -2
- package/engine/graphics/micron/build/clustering/cluster_mesh_vertices.js +0 -3
- package/engine/graphics/micron/render/RefinementSpec.js +0 -181
|
@@ -4,21 +4,6 @@ import { aabb3_project_to_2d } from "../../../../../core/geom/3d/aabb/aabb3_comp
|
|
|
4
4
|
import { BitSet } from "../../../../../core/binary/BitSet.js";
|
|
5
5
|
import { aabb3_intersects_frustum } from "../../../../../core/bvh2/aabb3/aabb3_intersects_frustum.js";
|
|
6
6
|
|
|
7
|
-
/**
|
|
8
|
-
*
|
|
9
|
-
* @param {number[]|Float32Array} bounding_box_corners
|
|
10
|
-
* @param {RefinementSpec} spec
|
|
11
|
-
* @returns {number}
|
|
12
|
-
*/
|
|
13
|
-
function compute_projected_area(bounding_box_corners, spec) {
|
|
14
|
-
// Cull by screen area
|
|
15
|
-
const normalized_screen_area = aabb3_project_to_2d(bounding_box_corners, spec.projection_matrix);
|
|
16
|
-
|
|
17
|
-
const patch_screen_area = normalized_screen_area * spec.viewport_area;
|
|
18
|
-
|
|
19
|
-
return patch_screen_area;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
7
|
export class ActivePatchList {
|
|
23
8
|
constructor() {
|
|
24
9
|
/**
|
|
@@ -38,6 +23,19 @@ export class ActivePatchList {
|
|
|
38
23
|
* @type {BitSet}
|
|
39
24
|
*/
|
|
40
25
|
this.unfolded = new BitSet();
|
|
26
|
+
|
|
27
|
+
// prevent re-allocation related thrashing
|
|
28
|
+
this.unfolded.preventShrink();
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
clear() {
|
|
32
|
+
const unfolded = this.unfolded;
|
|
33
|
+
|
|
34
|
+
unfolded.reset();
|
|
35
|
+
|
|
36
|
+
ActivePatchRecord.pool_release_all(this.records);
|
|
37
|
+
|
|
38
|
+
this.records = null;
|
|
41
39
|
}
|
|
42
40
|
|
|
43
41
|
/**
|
|
@@ -45,14 +43,15 @@ export class ActivePatchList {
|
|
|
45
43
|
* @param {MicronGeometry} geometry
|
|
46
44
|
*/
|
|
47
45
|
initializeFromGeometry(geometry) {
|
|
48
|
-
|
|
46
|
+
this.clear();
|
|
47
|
+
|
|
48
|
+
const record = ActivePatchRecord.pool_get();
|
|
49
49
|
|
|
50
|
+
record.patch = geometry.root;
|
|
50
51
|
record.link_next = null;
|
|
51
52
|
record.link_previous = null;
|
|
52
53
|
|
|
53
54
|
const unfolded = this.unfolded;
|
|
54
|
-
|
|
55
|
-
unfolded.reset();
|
|
56
55
|
unfolded.set(record.patch.id, true);
|
|
57
56
|
|
|
58
57
|
this.records = record;
|
|
@@ -61,6 +60,7 @@ export class ActivePatchList {
|
|
|
61
60
|
/**
|
|
62
61
|
*
|
|
63
62
|
* @param {ActivePatchRecord} record
|
|
63
|
+
* @returns {ActivePatchRecord}
|
|
64
64
|
*/
|
|
65
65
|
node_split(record) {
|
|
66
66
|
|
|
@@ -73,19 +73,24 @@ export class ActivePatchList {
|
|
|
73
73
|
|
|
74
74
|
const child_id = child.id;
|
|
75
75
|
|
|
76
|
-
if (unfolded.
|
|
76
|
+
if (unfolded.getAndSet(child_id)) {
|
|
77
77
|
// already unfolded, skip
|
|
78
78
|
continue;
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
-
const child_record = ActivePatchRecord.
|
|
81
|
+
const child_record = ActivePatchRecord.pool_get();
|
|
82
|
+
child_record.patch = child;
|
|
82
83
|
|
|
83
84
|
this.record_insert_after(record, child_record);
|
|
84
|
-
|
|
85
|
-
unfolded.set(child_id, true);
|
|
86
85
|
}
|
|
87
86
|
|
|
88
87
|
this.record_remove(record);
|
|
88
|
+
|
|
89
|
+
const next = record.link_next;
|
|
90
|
+
|
|
91
|
+
ActivePatchRecord.pool_release(record);
|
|
92
|
+
|
|
93
|
+
return next;
|
|
89
94
|
}
|
|
90
95
|
|
|
91
96
|
/**
|
|
@@ -180,8 +185,12 @@ export class ActivePatchList {
|
|
|
180
185
|
refine(spec) {
|
|
181
186
|
|
|
182
187
|
const frustum_planes = spec.frustum_f32;
|
|
188
|
+
const projection_matrix = spec.projection_matrix;
|
|
189
|
+
const error_threshold = spec.error_threshold_normalized;
|
|
190
|
+
|
|
191
|
+
let record = this.records
|
|
183
192
|
|
|
184
|
-
for (
|
|
193
|
+
for (; record !== null;) {
|
|
185
194
|
|
|
186
195
|
const node = record.patch;
|
|
187
196
|
|
|
@@ -192,32 +201,17 @@ export class ActivePatchList {
|
|
|
192
201
|
check if node is in view frustum
|
|
193
202
|
NOTE: following suggestion in "FastMesh: Efficient View-dependent Meshing" by Renato Pajarola et al, we can do a more coarse frustum test approximating frustum as a cone initially
|
|
194
203
|
*/
|
|
195
|
-
const
|
|
196
|
-
const in_view_frustum = aabb3_intersects_frustum(bounding_box, frustum_planes);
|
|
204
|
+
const in_view_frustum = aabb3_intersects_frustum(node.bounding_box, frustum_planes);
|
|
197
205
|
|
|
198
206
|
if (!in_view_frustum) {
|
|
199
207
|
// outside of view frustum, cull
|
|
200
208
|
if (prev_is_visible) {
|
|
201
209
|
record.clearFlag(ActivePatchFlags.Visible);
|
|
202
210
|
}
|
|
211
|
+
record = record.link_next;
|
|
203
212
|
continue;
|
|
204
213
|
}
|
|
205
214
|
|
|
206
|
-
// compute projected bounds of the patch
|
|
207
|
-
// const patch_screen_area = compute_projected_area(bounding_box, spec);
|
|
208
|
-
|
|
209
|
-
// const patch_is_too_small_to_be_seen = patch_screen_area < spec.error_threshold;
|
|
210
|
-
//
|
|
211
|
-
// if (patch_is_too_small_to_be_seen) {
|
|
212
|
-
// // the whole patch is too small, cull
|
|
213
|
-
// if (prev_is_visible) {
|
|
214
|
-
// record.clearFlag(ActivePatchFlags.Visible);
|
|
215
|
-
// }
|
|
216
|
-
//
|
|
217
|
-
// // try to merge with sibling
|
|
218
|
-
// continue;
|
|
219
|
-
// }
|
|
220
|
-
|
|
221
215
|
if (!prev_is_visible) {
|
|
222
216
|
record.setFlag(ActivePatchFlags.Visible);
|
|
223
217
|
}
|
|
@@ -235,22 +229,17 @@ export class ActivePatchList {
|
|
|
235
229
|
// not the lowest level of LOD, see if subdivision might be necessary
|
|
236
230
|
|
|
237
231
|
// compute average triangle area
|
|
238
|
-
const group_screen_area = aabb3_project_to_2d(node.group_bounding_box_corners,
|
|
232
|
+
const group_screen_area = aabb3_project_to_2d(node.group_bounding_box_corners, projection_matrix);
|
|
239
233
|
const screen_space_error = node.group_error * group_screen_area;
|
|
240
234
|
|
|
241
|
-
|
|
242
|
-
if (screen_space_error > spec.error_threshold_normalized) {
|
|
235
|
+
if (screen_space_error > error_threshold) {
|
|
243
236
|
// error too large, needs to be split
|
|
244
|
-
this.node_split(record);
|
|
237
|
+
record = this.node_split(record);
|
|
245
238
|
continue;
|
|
246
239
|
}
|
|
247
240
|
}
|
|
248
241
|
|
|
249
|
-
|
|
250
|
-
// check if record and its sibling can be merged
|
|
251
|
-
// if (approximate_triangle_area < spec.error_threshold) {
|
|
252
|
-
// this.node_try_merge(record, spec);
|
|
253
|
-
// }
|
|
242
|
+
record = record.link_next;
|
|
254
243
|
}
|
|
255
244
|
}
|
|
256
245
|
}
|
|
@@ -60,8 +60,6 @@ export class ActivePatchRecord {
|
|
|
60
60
|
patch_pool_size--;
|
|
61
61
|
|
|
62
62
|
// reset record
|
|
63
|
-
r.link_next = null;
|
|
64
|
-
|
|
65
63
|
r.flags = 0;
|
|
66
64
|
|
|
67
65
|
return r;
|
|
@@ -91,6 +89,10 @@ export class ActivePatchRecord {
|
|
|
91
89
|
* @param {ActivePatchRecord} r
|
|
92
90
|
*/
|
|
93
91
|
static pool_release_all(r) {
|
|
92
|
+
if (r === null) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
|
|
94
96
|
let p = r;
|
|
95
97
|
|
|
96
98
|
for (; patch_pool_size < patch_limit;) {
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import Vector2 from "../../../../../core/geom/Vector2.js";
|
|
2
|
+
import { mat4 } from "gl-matrix";
|
|
3
|
+
import { array_setFromProjectionMatrix } from "../../../../../core/geom/3d/frustum/array_setFromProjectionMatrix.js";
|
|
4
|
+
|
|
5
|
+
export class RefinementSpec {
|
|
6
|
+
constructor() {
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Viewport resolution
|
|
10
|
+
* @type {Vector2}
|
|
11
|
+
*/
|
|
12
|
+
this.resolution = new Vector2();
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Number of pixels in the viewport
|
|
16
|
+
* @type {number}
|
|
17
|
+
*/
|
|
18
|
+
this.viewport_area = 0;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* How much error to accept when deciding to subdivide a cluster
|
|
22
|
+
* Measured in pixels
|
|
23
|
+
* Higher value will result in better performance but more visible artifacts
|
|
24
|
+
* @type {number}
|
|
25
|
+
*/
|
|
26
|
+
this.error_threshold = 1;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Error threshold as a fraction of the screen area instead of pixels, derived internally from pixel value
|
|
30
|
+
* @type {number}
|
|
31
|
+
*/
|
|
32
|
+
this.error_threshold_normalized = 1;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Continuous memory region for faster access
|
|
36
|
+
* @type {ArrayBuffer}
|
|
37
|
+
*/
|
|
38
|
+
const array_buffer = new ArrayBuffer(160);
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Object-space camera frustum
|
|
42
|
+
* Frustum planes in compact form
|
|
43
|
+
* @type {Float32Array}
|
|
44
|
+
*/
|
|
45
|
+
this.frustum_f32 = new Float32Array(array_buffer, 0, 24);
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Contains transformation from camera space to object space
|
|
50
|
+
* @type {Float32Array|number[]|mat4}
|
|
51
|
+
*/
|
|
52
|
+
this.projection_matrix = new Float32Array(array_buffer, 24 * 4, 16);
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Model world transform
|
|
56
|
+
* @type {Float32Array|number[]|mat4}
|
|
57
|
+
*/
|
|
58
|
+
// this.transform = new Float32Array(16);
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Object-space camera position
|
|
62
|
+
* @type {Float32Array}
|
|
63
|
+
*/
|
|
64
|
+
this.view_position = new Float32Array(3);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
get frustum() {
|
|
68
|
+
throw new Error('deprecated, use .frustum_f32 instead');
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
setResolution(x, y) {
|
|
72
|
+
this.resolution.set(x, y);
|
|
73
|
+
|
|
74
|
+
this.viewport_area = x * y;
|
|
75
|
+
|
|
76
|
+
this.error_threshold_normalized = this.error_threshold / this.viewport_area;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
*
|
|
81
|
+
* @param {number[]|mat4|Float32Array|ArrayLike<number>} transform world-space object transform
|
|
82
|
+
* @param {number[]|mat4|Float32Array|ArrayLike<number>} matrix_world_inverse camera's world inverse matrix
|
|
83
|
+
* @param {number[]|mat4|Float32Array|ArrayLike<number>} matrix_projection camera's projection matrix
|
|
84
|
+
*/
|
|
85
|
+
build(transform, matrix_world_inverse, matrix_projection) {
|
|
86
|
+
// const _transform = this.transform;
|
|
87
|
+
// _transform.set(transform);
|
|
88
|
+
|
|
89
|
+
// build projection matrix
|
|
90
|
+
const projection_matrix = this.projection_matrix;
|
|
91
|
+
|
|
92
|
+
mat4.multiply(projection_matrix, matrix_world_inverse, transform);
|
|
93
|
+
mat4.multiply(projection_matrix, matrix_projection, projection_matrix);
|
|
94
|
+
|
|
95
|
+
// compute view frustum in model-space
|
|
96
|
+
array_setFromProjectionMatrix(this.frustum_f32, projection_matrix);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
@@ -12,6 +12,27 @@ export class MaterialVertexSpec {
|
|
|
12
12
|
this.material = null;
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
+
/**
|
|
16
|
+
*
|
|
17
|
+
* @param {MaterialVertexSpec} other
|
|
18
|
+
*/
|
|
19
|
+
copy(other) {
|
|
20
|
+
this.spec = other.spec;
|
|
21
|
+
this.material = other.material;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
*
|
|
26
|
+
* @return {MaterialVertexSpec}
|
|
27
|
+
*/
|
|
28
|
+
clone() {
|
|
29
|
+
const r = new MaterialVertexSpec();
|
|
30
|
+
|
|
31
|
+
r.copy(this);
|
|
32
|
+
|
|
33
|
+
return r;
|
|
34
|
+
}
|
|
35
|
+
|
|
15
36
|
/**
|
|
16
37
|
* @param {MicronVertexDataSpec} spec
|
|
17
38
|
* @param {Material} material
|
|
@@ -7,6 +7,12 @@ import { HashMap } from "../../../../../core/collection/HashMap.js";
|
|
|
7
7
|
import Signal from "../../../../../core/events/signal/Signal.js";
|
|
8
8
|
import { array_copy } from "../../../../../core/collection/array/copyArray.js";
|
|
9
9
|
|
|
10
|
+
/**
|
|
11
|
+
*
|
|
12
|
+
* @type {MaterialVertexSpec}
|
|
13
|
+
*/
|
|
14
|
+
const scratch_mvc = new MaterialVertexSpec();
|
|
15
|
+
|
|
10
16
|
export class VGThreeRenderer {
|
|
11
17
|
constructor() {
|
|
12
18
|
this.geometry = new VirtualGeometry();
|
|
@@ -32,13 +38,6 @@ export class VGThreeRenderer {
|
|
|
32
38
|
*/
|
|
33
39
|
this.__contexts_array = [];
|
|
34
40
|
|
|
35
|
-
/**
|
|
36
|
-
*
|
|
37
|
-
* @type {Scene|null}
|
|
38
|
-
* @private
|
|
39
|
-
*/
|
|
40
|
-
this.__scene = null;
|
|
41
|
-
|
|
42
41
|
/**
|
|
43
42
|
*
|
|
44
43
|
* @type {Object3D[]}
|
|
@@ -75,14 +74,18 @@ export class VGThreeRenderer {
|
|
|
75
74
|
* @private
|
|
76
75
|
*/
|
|
77
76
|
__obtain_material(spec, m) {
|
|
78
|
-
|
|
77
|
+
scratch_mvc.material = m;
|
|
78
|
+
scratch_mvc.spec = spec;
|
|
79
79
|
|
|
80
|
-
const existing = this.material_contexts.get(
|
|
80
|
+
const existing = this.material_contexts.get(scratch_mvc);
|
|
81
81
|
|
|
82
82
|
if (existing !== undefined) {
|
|
83
83
|
return existing;
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
+
// create a separate instance to be stored alongside the context
|
|
87
|
+
const key = scratch_mvc.clone();
|
|
88
|
+
|
|
86
89
|
const ctx = new MaterialContext(spec, m);
|
|
87
90
|
|
|
88
91
|
ctx.init(this.__gl_context);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PatchCacheKey } from "../PatchCacheKey.js";
|
|
2
|
-
import { apply_mat4_transform_to_v3_array } from "
|
|
2
|
+
import { apply_mat4_transform_to_v3_array } from "../../../../../core/geom/3d/apply_mat4_transform_to_v3_array.js";
|
|
3
3
|
import { Cache } from "../../../../../core/cache/Cache.js";
|
|
4
4
|
import { invokeObjectHash } from "../../../../../core/model/object/invokeObjectHash.js";
|
|
5
5
|
import { invokeObjectEquals } from "../../../../../core/model/object/invokeObjectEquals.js";
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { FrameBuffer } from "../FrameBuffer.js";
|
|
2
2
|
import {
|
|
3
|
+
DepthFormat,
|
|
3
4
|
DepthTexture,
|
|
4
5
|
FloatType,
|
|
5
6
|
NearestFilter,
|
|
6
|
-
|
|
7
|
+
RGBFormat,
|
|
7
8
|
sRGBEncoding,
|
|
8
9
|
Vector2,
|
|
9
10
|
WebGLMultisampleRenderTarget
|
|
@@ -39,9 +40,9 @@ export class ColorAndDepthFrameBuffer extends FrameBuffer {
|
|
|
39
40
|
|
|
40
41
|
renderer.getSize(size);
|
|
41
42
|
|
|
42
|
-
const target = new WebGLMultisampleRenderTarget(size.x, size.y);
|
|
43
|
+
const target = new WebGLMultisampleRenderTarget(size.x, size.y,{ignoreDepth: false});
|
|
43
44
|
|
|
44
|
-
target.texture.format =
|
|
45
|
+
target.texture.format = RGBFormat; // note, three.js required RGBA render texture, even though RGB would do here
|
|
45
46
|
target.texture.minFilter = NearestFilter;
|
|
46
47
|
target.texture.magFilter = NearestFilter;
|
|
47
48
|
target.texture.generateMipmaps = false;
|
|
@@ -51,6 +52,7 @@ export class ColorAndDepthFrameBuffer extends FrameBuffer {
|
|
|
51
52
|
target.depthBuffer = true;
|
|
52
53
|
|
|
53
54
|
target.depthTexture = new DepthTexture();
|
|
55
|
+
target.depthTexture.format = DepthFormat;
|
|
54
56
|
target.depthTexture.type = FloatType;
|
|
55
57
|
target.depthTexture.generateMipmaps = false;
|
|
56
58
|
target.depthTexture.internalFormat = 'DEPTH_COMPONENT32F';
|
|
@@ -50,8 +50,6 @@ import { enableEditor } from "../../../../../editor/enableEditor.js";
|
|
|
50
50
|
import EntityBuilder from "../../../../ecs/EntityBuilder.js";
|
|
51
51
|
import { Transform } from "../../../../ecs/transform/Transform.js";
|
|
52
52
|
import Mesh from "../../../ecs/mesh/Mesh.js";
|
|
53
|
-
import ViewportPosition from "../../../../ecs/gui/position/ViewportPosition.js";
|
|
54
|
-
import GUIElement from "../../../../ecs/gui/GUIElement.js";
|
|
55
53
|
import { CopyShader } from "three/examples/jsm/shaders/CopyShader.js";
|
|
56
54
|
import {
|
|
57
55
|
DoubleSide,
|
|
@@ -64,11 +62,11 @@ import {
|
|
|
64
62
|
UniformsUtils,
|
|
65
63
|
WebGLRenderTarget
|
|
66
64
|
} from "three";
|
|
67
|
-
import { buildCubeURLs } from "../../../GraphicsEngine.js";
|
|
68
65
|
import { AmbientOcclusionPostProcessEffect } from "../simple-fx/ao/AmbientOcclusionPostProcessEffect.js";
|
|
69
66
|
import { PathDisplaySystem } from "../../../ecs/path/PathDisplaySystem.js";
|
|
70
67
|
import { MicronRenderPlugin } from "../../../micron/plugin/MicronRenderPlugin.js";
|
|
71
68
|
import { StandardFrameBuffers } from "../../../StandardFrameBuffers.js";
|
|
69
|
+
import { buildCubeURLs } from "../../../texture/cubemap/buildCubeURLs.js";
|
|
72
70
|
|
|
73
71
|
const engineHarness = new EngineHarness();
|
|
74
72
|
|
|
@@ -386,13 +384,13 @@ function main(engine) {
|
|
|
386
384
|
// .build(ecd);
|
|
387
385
|
|
|
388
386
|
// const canvasView = makeCameraClippingDebug(engine);
|
|
389
|
-
|
|
390
|
-
new EntityBuilder()
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
387
|
+
//
|
|
388
|
+
// new EntityBuilder()
|
|
389
|
+
// .add(ViewportPosition.fromJSON({
|
|
390
|
+
// offset: new Vector2(10, 10)
|
|
391
|
+
// }))
|
|
392
|
+
// .add(GUIElement.fromView(canvasView))
|
|
393
|
+
// .build(ecd);
|
|
396
394
|
|
|
397
395
|
|
|
398
396
|
}
|
|
@@ -11,15 +11,13 @@ import { compute_light_data_hash_0 } from "./cluster/compute_light_data_hash_0.j
|
|
|
11
11
|
import { read_plane_pair } from "./cluster/read_plane_pair.js";
|
|
12
12
|
import { read_frustum_planes_to_array } from "./cluster/read_frustum_planes_to_array.js";
|
|
13
13
|
import { compute_cluster_planes_from_points } from "./cluster/compute_cluster_planes_from_points.js";
|
|
14
|
-
import {
|
|
15
|
-
computeDataType,
|
|
16
|
-
computeThreeTextureInternalFormatFromDataType,
|
|
17
|
-
computeThreeTextureTypeFromDataType,
|
|
18
|
-
NumericType,
|
|
19
|
-
TextureBackedMemoryRegion
|
|
20
|
-
} from "./TextureBackedMemoryRegion.js";
|
|
14
|
+
import { TextureBackedMemoryRegion } from "./data/TextureBackedMemoryRegion.js";
|
|
21
15
|
import { assert } from "../../../../core/assert.js";
|
|
22
16
|
import { DataType2TypedArrayConstructorMapping } from "../../../../core/collection/table/DataType2TypedArrayConstructorMapping.js";
|
|
17
|
+
import { NumericType } from "./data/NumericType.js";
|
|
18
|
+
import { computeDataType } from "./data/computeDataType.js";
|
|
19
|
+
import { computeThreeTextureTypeFromDataType } from "./data/computeThreeTextureTypeFromDataType.js";
|
|
20
|
+
import { computeThreeTextureInternalFormatFromDataType } from "./data/computeThreeTextureInternalFormatFromDataType.js";
|
|
23
21
|
|
|
24
22
|
const LOOKUP_CACHE_SIZE = 16384; // must be power of two
|
|
25
23
|
/**
|
|
@@ -1,36 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
RGIntegerFormat,
|
|
13
|
-
ShortType,
|
|
14
|
-
UnsignedByteType,
|
|
15
|
-
UnsignedIntType,
|
|
16
|
-
UnsignedShortType
|
|
17
|
-
} from "three";
|
|
18
|
-
import { DataType } from "../../../../core/collection/table/DataType.js";
|
|
19
|
-
import { assert } from "../../../../core/assert.js";
|
|
20
|
-
import { DataType2TypedArrayConstructorMapping } from "../../../../core/collection/table/DataType2TypedArrayConstructorMapping.js";
|
|
21
|
-
import { max2 } from "../../../../core/math/max2.js";
|
|
22
|
-
import { channelCountToThreeTextureFormat } from "../../texture/channelCountToThreeTextureFormat.js";
|
|
23
|
-
import { DataTypeByteSizes } from "../../../../core/collection/table/RowFirstTableSpec.js";
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
*
|
|
27
|
-
* @enum {number}
|
|
28
|
-
*/
|
|
29
|
-
export const NumericType = {
|
|
30
|
-
Uint: 0,
|
|
31
|
-
Int: 1,
|
|
32
|
-
Float: 2
|
|
33
|
-
};
|
|
1
|
+
import { DataTexture, NearestFilter, RedFormat, UnsignedByteType } from "three";
|
|
2
|
+
import { DataType } from "../../../../../core/collection/table/DataType.js";
|
|
3
|
+
import { assert } from "../../../../../core/assert.js";
|
|
4
|
+
import { DataType2TypedArrayConstructorMapping } from "../../../../../core/collection/table/DataType2TypedArrayConstructorMapping.js";
|
|
5
|
+
import { max2 } from "../../../../../core/math/max2.js";
|
|
6
|
+
import { NumericType } from "./NumericType.js";
|
|
7
|
+
import { computeDataType } from "./computeDataType.js";
|
|
8
|
+
import { computeThreeTextureTypeFromDataType } from "./computeThreeTextureTypeFromDataType.js";
|
|
9
|
+
import { computeThreeTextureInternalFormatFromDataType } from "./computeThreeTextureInternalFormatFromDataType.js";
|
|
10
|
+
import { computeThreeTextureFormat } from "./computeThreeTextureFormat.js";
|
|
11
|
+
import { DataTypeByteSizes } from "../../../../../core/collection/table/DataTypeByteSizes.js";
|
|
34
12
|
|
|
35
13
|
/**
|
|
36
14
|
* How wide a data texture is
|
|
@@ -42,163 +20,6 @@ const SHRINK_FACTOR = 0.5;
|
|
|
42
20
|
const GROW_FACTOR = 1.05;
|
|
43
21
|
|
|
44
22
|
|
|
45
|
-
/**
|
|
46
|
-
*
|
|
47
|
-
* @param {NumericType} type
|
|
48
|
-
* @param {number} precision
|
|
49
|
-
* @returns {DataType}
|
|
50
|
-
*/
|
|
51
|
-
export function computeDataType(type, precision) {
|
|
52
|
-
if (type === NumericType.Uint) {
|
|
53
|
-
if (precision <= 8) {
|
|
54
|
-
return DataType.Uint8;
|
|
55
|
-
} else if (precision <= 16) {
|
|
56
|
-
return DataType.Uint16;
|
|
57
|
-
} else if (precision <= 32) {
|
|
58
|
-
return DataType.Uint32;
|
|
59
|
-
}
|
|
60
|
-
} else if (type === NumericType.Int) {
|
|
61
|
-
if (precision <= 8) {
|
|
62
|
-
return DataType.Int8;
|
|
63
|
-
} else if (precision <= 16) {
|
|
64
|
-
return DataType.Int16;
|
|
65
|
-
} else if (precision <= 32) {
|
|
66
|
-
return DataType.Int32;
|
|
67
|
-
}
|
|
68
|
-
} else if (type === NumericType.Float) {
|
|
69
|
-
if (precision <= 32) {
|
|
70
|
-
return DataType.Float32;
|
|
71
|
-
} else if (precision <= 64) {
|
|
72
|
-
return DataType.Float64;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
throw new Error(`Unsupported numeric type(=${type}) and precision(=${precision}) combination`);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
*
|
|
81
|
-
* @param {DataType} dt
|
|
82
|
-
* @returns {number}
|
|
83
|
-
*/
|
|
84
|
-
export function computeThreeTextureTypeFromDataType(dt) {
|
|
85
|
-
switch (dt) {
|
|
86
|
-
case DataType.Uint8:
|
|
87
|
-
return UnsignedByteType;
|
|
88
|
-
case DataType.Uint16:
|
|
89
|
-
return UnsignedShortType;
|
|
90
|
-
case DataType.Uint32:
|
|
91
|
-
return UnsignedIntType;
|
|
92
|
-
case DataType.Int8:
|
|
93
|
-
return ByteType;
|
|
94
|
-
case DataType.Int16:
|
|
95
|
-
return ShortType;
|
|
96
|
-
case DataType.Int32:
|
|
97
|
-
return IntType;
|
|
98
|
-
case DataType.Float16:
|
|
99
|
-
return HalfFloatType;
|
|
100
|
-
case DataType.Float32:
|
|
101
|
-
return FloatType;
|
|
102
|
-
case DataType.Float64:
|
|
103
|
-
return FloatType;
|
|
104
|
-
default:
|
|
105
|
-
throw new Error(`Unsupported data type '${dt}'`);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
*
|
|
112
|
-
* @param {DataType} dt
|
|
113
|
-
* @param {number} channel_count
|
|
114
|
-
* @returns {string|THREE.PixelFormatGPU}
|
|
115
|
-
*/
|
|
116
|
-
export function computeThreeTextureInternalFormatFromDataType(dt, channel_count) {
|
|
117
|
-
let suffix = '';
|
|
118
|
-
switch (dt) {
|
|
119
|
-
case DataType.Uint8:
|
|
120
|
-
suffix = '8UI';
|
|
121
|
-
break;
|
|
122
|
-
case DataType.Uint16:
|
|
123
|
-
suffix = '16UI';
|
|
124
|
-
break;
|
|
125
|
-
case DataType.Uint32:
|
|
126
|
-
suffix = '32UI';
|
|
127
|
-
break;
|
|
128
|
-
case DataType.Int8:
|
|
129
|
-
suffix = '8I';
|
|
130
|
-
break;
|
|
131
|
-
case DataType.Int16:
|
|
132
|
-
suffix = '16I';
|
|
133
|
-
break;
|
|
134
|
-
case DataType.Int32:
|
|
135
|
-
suffix = '32I';
|
|
136
|
-
break;
|
|
137
|
-
case DataType.Float16:
|
|
138
|
-
suffix = '16F';
|
|
139
|
-
break;
|
|
140
|
-
case DataType.Float32:
|
|
141
|
-
suffix = '32F';
|
|
142
|
-
break;
|
|
143
|
-
case DataType.Float64:
|
|
144
|
-
suffix = '64F';
|
|
145
|
-
break;
|
|
146
|
-
default:
|
|
147
|
-
throw new Error(`Unsupported data type '${dt}'`);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
let prefix = '';
|
|
151
|
-
|
|
152
|
-
switch (channel_count) {
|
|
153
|
-
case 1:
|
|
154
|
-
prefix = 'R';
|
|
155
|
-
break;
|
|
156
|
-
case 2:
|
|
157
|
-
prefix = 'RG';
|
|
158
|
-
break;
|
|
159
|
-
case 3:
|
|
160
|
-
prefix = 'RGB';
|
|
161
|
-
break;
|
|
162
|
-
case 4:
|
|
163
|
-
prefix = 'RGBA';
|
|
164
|
-
break;
|
|
165
|
-
default:
|
|
166
|
-
throw new Error(`Unsupported channel count '${channel_count}'`);
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
return prefix + suffix;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
function channelCountToThreIntegerTextureType(channel_count) {
|
|
173
|
-
switch (channel_count) {
|
|
174
|
-
case 1:
|
|
175
|
-
return RedIntegerFormat;
|
|
176
|
-
case 2:
|
|
177
|
-
return RGIntegerFormat;
|
|
178
|
-
case 3:
|
|
179
|
-
return RGBIntegerFormat;
|
|
180
|
-
case 4:
|
|
181
|
-
return RGBAIntegerFormat;
|
|
182
|
-
default:
|
|
183
|
-
throw new Error(`Unsupported channel count '${channel_count}'`);
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
/**
|
|
188
|
-
*
|
|
189
|
-
* @param {NumericType} type
|
|
190
|
-
* @param {number} channel_count
|
|
191
|
-
*/
|
|
192
|
-
function computeThreeTextureFormat(type, channel_count) {
|
|
193
|
-
if (type === NumericType.Uint || type === NumericType.Int) {
|
|
194
|
-
return channelCountToThreIntegerTextureType(channel_count);
|
|
195
|
-
} else if (type === NumericType.Float) {
|
|
196
|
-
return channelCountToThreeTextureFormat(channel_count);
|
|
197
|
-
} else {
|
|
198
|
-
throw new Error(`Unsupported numeric type '${type}'`);
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
|
|
202
23
|
export class TextureBackedMemoryRegion {
|
|
203
24
|
|
|
204
25
|
constructor() {
|