@woosh/meep-engine 2.48.20 → 2.48.21
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/package.json +1 -1
- package/src/engine/graphics/micron/MICRON_GEOMETRY_FIELD.js +0 -1
- package/src/engine/graphics/micron/MICRON_URI_FIELD.js +0 -1
- package/src/engine/graphics/micron/build/MICRON_PATCH_SIZE_MAX.js +0 -5
- package/src/engine/graphics/micron/build/PatchRepresentation.js +0 -424
- package/src/engine/graphics/micron/build/buildMicronGeometryFromBufferGeometry.js +0 -311
- package/src/engine/graphics/micron/build/build_geometry_info.js +0 -21
- package/src/engine/graphics/micron/build/clustering/assignInitialPatchNeighbours.js +0 -63
- package/src/engine/graphics/micron/build/clustering/assign_patch_neighbours_from_topology.js +0 -46
- package/src/engine/graphics/micron/build/clustering/build_clustering_2.js +0 -37
- package/src/engine/graphics/micron/build/clustering/build_leaf_patches.js +0 -326
- package/src/engine/graphics/micron/build/clustering/build_leaf_patches_metis.js +0 -76
- package/src/engine/graphics/micron/build/clustering/computeBorderLengthChange.js +0 -59
- package/src/engine/graphics/micron/build/clustering/computeFaceCurvatureScore.js +0 -57
- package/src/engine/graphics/micron/build/clustering/computeOpenFaceFreedom.js +0 -35
- package/src/engine/graphics/micron/build/clustering/compute_face_connection_weight.js +0 -35
- package/src/engine/graphics/micron/build/clustering/populateOpenFaceNeighboursForPatch.js +0 -56
- package/src/engine/graphics/micron/build/clustering/validate_leaf_patch_connectivity.js +0 -44
- package/src/engine/graphics/micron/build/compute_micron_buffer_array_constructor.js +0 -24
- package/src/engine/graphics/micron/build/compute_vertex_remap_cost.js +0 -29
- package/src/engine/graphics/micron/build/debug/build_clustering_info.js +0 -58
- package/src/engine/graphics/micron/build/debug/build_graph_info.js +0 -59
- package/src/engine/graphics/micron/build/fill_patch_geometry_data.js +0 -270
- package/src/engine/graphics/micron/build/hierarchy/buildAbstractPatchHierarchy.js +0 -196
- package/src/engine/graphics/micron/build/hierarchy/build_intermediate_patch_topology.js +0 -162
- package/src/engine/graphics/micron/build/hierarchy/build_merge_graph.js +0 -89
- package/src/engine/graphics/micron/build/hierarchy/computePatchMergeScore.js +0 -146
- package/src/engine/graphics/micron/build/hierarchy/compute_patches_shared_vertex_count.js +0 -32
- package/src/engine/graphics/micron/build/hierarchy/compute_patches_shared_vertices.js +0 -34
- package/src/engine/graphics/micron/build/hierarchy/merge_patches.js +0 -581
- package/src/engine/graphics/micron/build/hierarchy/metis_cluster_clusters.js +0 -53
- package/src/engine/graphics/micron/build/hierarchy/optimize_graph_partitioning_balance.js +0 -515
- package/src/engine/graphics/micron/build/hierarchy/patch_combine.js +0 -180
- package/src/engine/graphics/micron/build/hierarchy/patch_fill_holes_by_uncollapse.js +0 -60
- package/src/engine/graphics/micron/build/hierarchy/patch_stitch_parent_border.js +0 -320
- package/src/engine/graphics/micron/build/hierarchy/qvdr_build_simplified_clusters.js +0 -547
- package/src/engine/graphics/micron/build/hierarchy/qvdr_build_tree.js +0 -140
- package/src/engine/graphics/micron/buildPatchwork.js +0 -68
- package/src/engine/graphics/micron/convert_three_object_to_micron.js +0 -179
- package/src/engine/graphics/micron/debug/VirtualGeometryStats.js +0 -42
- package/src/engine/graphics/micron/format/MICRON_GEOMETRY_PROPERTY_NAME.js +0 -1
- package/src/engine/graphics/micron/format/MicronGeometry.d.ts +0 -21
- package/src/engine/graphics/micron/format/MicronGeometry.js +0 -334
- package/src/engine/graphics/micron/format/MicronGeometryPatch.d.ts +0 -3
- package/src/engine/graphics/micron/format/MicronGeometryPatch.js +0 -205
- package/src/engine/graphics/micron/format/MicronGeometryPatchOccurance.js +0 -50
- package/src/engine/graphics/micron/format/ThreeMicronMesh.d.ts +0 -10
- package/src/engine/graphics/micron/format/ThreeMicronMesh.js +0 -45
- package/src/engine/graphics/micron/format/VirtualGeometry.js +0 -158
- package/src/engine/graphics/micron/format/micron_build_proxy_geometry.js +0 -205
- package/src/engine/graphics/micron/format/serialization/MicronGeometryBinarySerializationAdapter.js +0 -123
- package/src/engine/graphics/micron/format/serialization/MicronGeometryBinarySerializationAdapter.spec.js +0 -63
- package/src/engine/graphics/micron/format/serialization/collection/geometry_collection_serialization.js +0 -83
- package/src/engine/graphics/micron/format/serialization/collection/geometry_collection_serialization.spec.js +0 -51
- package/src/engine/graphics/micron/format/serialization/deserialize_attribute_spec.js +0 -25
- package/src/engine/graphics/micron/format/serialization/deserialize_patch.js +0 -106
- package/src/engine/graphics/micron/format/serialization/serialize_attribute_spec.js +0 -18
- package/src/engine/graphics/micron/format/serialization/serialize_patch.js +0 -84
- package/src/engine/graphics/micron/format/validate_patch_bounds.js +0 -69
- package/src/engine/graphics/micron/plugin/GLTFAssetTransformer.js +0 -265
- package/src/engine/graphics/micron/plugin/GLTF_MICRON_ID_FIELD.js +0 -5
- package/src/engine/graphics/micron/plugin/MicronRenderPlugin.d.ts +0 -8
- package/src/engine/graphics/micron/plugin/MicronRenderPlugin.js +0 -150
- package/src/engine/graphics/micron/plugin/serialization/BufferGeometrySerializationAdapter.js +0 -176
- package/src/engine/graphics/micron/plugin/shaded_geometry/MicronShadedGeometryRenderAdapter.js +0 -216
- package/src/engine/graphics/micron/prototypeMicronProxyBuild.js +0 -227
- package/src/engine/graphics/micron/prototypeVirtualGeometry.js +0 -911
- package/src/engine/graphics/micron/render/PatchCacheKey.js +0 -79
- package/src/engine/graphics/micron/render/VIRTUAL_MESH_FLAG.d.ts +0 -1
- package/src/engine/graphics/micron/render/VIRTUAL_MESH_FLAG.js +0 -1
- package/src/engine/graphics/micron/render/VirtualGeometryBuilder.js +0 -207
- package/src/engine/graphics/micron/render/approximateTriangleArea.js +0 -25
- package/src/engine/graphics/micron/render/culling/PatchCullingSystem.js +0 -129
- package/src/engine/graphics/micron/render/instanced/PatchDataTextures.js +0 -329
- package/src/engine/graphics/micron/render/instanced/ThreeInstancedAdapter.js +0 -175
- package/src/engine/graphics/micron/render/instanced/shader/constants.js +0 -3
- package/src/engine/graphics/micron/render/instanced/shader/gen_micron_vertex_attribute_texture_name.js +0 -8
- package/src/engine/graphics/micron/render/instanced/shader/shader_rewrite_standard.js +0 -250
- package/src/engine/graphics/micron/render/makeThreeMeshFromVirtualGeometry.js +0 -37
- package/src/engine/graphics/micron/render/refinement/ActivePatchFlags.js +0 -8
- package/src/engine/graphics/micron/render/refinement/ActivePatchList.js +0 -241
- package/src/engine/graphics/micron/render/refinement/ActivePatchRecord.js +0 -154
- package/src/engine/graphics/micron/render/refinement/RefinementSpec.js +0 -84
- package/src/engine/graphics/micron/render/refinement/get_geometry_patch_cut.js +0 -133
- package/src/engine/graphics/micron/render/refinement/is_patch_facing_back.js +0 -43
- package/src/engine/graphics/micron/render/refinement/is_patch_visible.js +0 -37
- package/src/engine/graphics/micron/render/v1/MaterialContext.js +0 -150
- package/src/engine/graphics/micron/render/v1/MaterialVertexSpec.js +0 -115
- package/src/engine/graphics/micron/render/v1/MicronRenderContext.js +0 -145
- package/src/engine/graphics/micron/render/v1/ThreeVirtualGeometryAdapter.js +0 -255
- package/src/engine/graphics/micron/render/v1/VGThreeRenderer.js +0 -142
- package/src/engine/graphics/micron/render/v1/getTransformedPositionsCached.js +0 -54
- package/src/engine/graphics/micron/simplifyGeometry.js +0 -26
- package/src/engine/graphics/micron/util/patchToBufferGeometry.js +0 -19
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import { mortonEncode_magicbits } from "../../../../core/geom/3d/morton/mortonEncode_magicbits.js";
|
|
2
|
-
import { isArrayEqualStrict } from "../../../../core/collection/array/isArrayEqualStrict.js";
|
|
3
|
-
import { SimpleObjectPoolFactory } from "../../../../core/model/object/SimpleObjectPoolFactory.js";
|
|
4
|
-
import { computeHashFloat } from "../../../../core/primitives/numbers/computeHashFloat.js";
|
|
5
|
-
|
|
6
|
-
export class PatchCacheKey {
|
|
7
|
-
constructor() {
|
|
8
|
-
/**
|
|
9
|
-
*
|
|
10
|
-
* @type {number}
|
|
11
|
-
*/
|
|
12
|
-
this.patch_id = 0;
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
*
|
|
16
|
-
* @type {number}
|
|
17
|
-
*/
|
|
18
|
-
this.geometry_id = 0;
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
*
|
|
22
|
-
* @type {Float32Array}
|
|
23
|
-
*/
|
|
24
|
-
this.transform = new Float32Array(16);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
hash() {
|
|
28
|
-
const transform = this.transform;
|
|
29
|
-
|
|
30
|
-
// only use position for hashing as that's the primary changing attribute in practice
|
|
31
|
-
const x = transform[12];
|
|
32
|
-
const y = transform[13];
|
|
33
|
-
const z = transform[14];
|
|
34
|
-
|
|
35
|
-
const position_hash = mortonEncode_magicbits(
|
|
36
|
-
computeHashFloat(x * 3.1234),
|
|
37
|
-
computeHashFloat(y * 289.0),
|
|
38
|
-
computeHashFloat(z * 34)
|
|
39
|
-
);
|
|
40
|
-
|
|
41
|
-
return position_hash + this.patch_id ^ this.geometry_id;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
*
|
|
46
|
-
* @param {PatchCacheKey} other
|
|
47
|
-
*/
|
|
48
|
-
equals(other) {
|
|
49
|
-
return this.patch_id === other.patch_id
|
|
50
|
-
&& this.geometry_id === other.geometry_id
|
|
51
|
-
&& isArrayEqualStrict(this.transform, other.transform)
|
|
52
|
-
;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
*
|
|
57
|
-
* @param {PatchCacheKey} other
|
|
58
|
-
*/
|
|
59
|
-
copy(other) {
|
|
60
|
-
this.patch_id = other.patch_id;
|
|
61
|
-
this.geometry_id = other.geometry_id;
|
|
62
|
-
this.transform.set(other.transform);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
*
|
|
67
|
-
* @param {MicronGeometryPatchOccurrence} o
|
|
68
|
-
*/
|
|
69
|
-
fromPatchOccurrence(o) {
|
|
70
|
-
this.patch_id = o.patch.id;
|
|
71
|
-
this.geometry_id = o.geometry_id;
|
|
72
|
-
this.transform.set(o.transform);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
PatchCacheKey.pool = new SimpleObjectPoolFactory({
|
|
77
|
-
type: PatchCacheKey,
|
|
78
|
-
size: 1024
|
|
79
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const VIRTUAL_MESH_FLAG: string
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const VIRTUAL_MESH_FLAG = '@meep/is-virtual';
|
|
@@ -1,207 +0,0 @@
|
|
|
1
|
-
import { array_copy } from "../../../../core/collection/array/copyArray.js";
|
|
2
|
-
import Vector2 from "../../../../core/geom/Vector2.js";
|
|
3
|
-
import { RefinementSpec } from "./refinement/RefinementSpec.js";
|
|
4
|
-
import { mat4 } from "gl-matrix";
|
|
5
|
-
import { get_geometry_patch_cut } from "./refinement/get_geometry_patch_cut.js";
|
|
6
|
-
import { traverseThreeObject } from "../../ecs/highlight/renderer/traverseThreeObject.js";
|
|
7
|
-
|
|
8
|
-
export class VirtualGeometryBuilder {
|
|
9
|
-
constructor() {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const common_buffer = new ArrayBuffer(192);
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Camera's world inverse matrix
|
|
17
|
-
* @type {Float32Array|number[]|mat4}
|
|
18
|
-
*/
|
|
19
|
-
this.matrix_world_inverse = new Float32Array(common_buffer, 0, 16);
|
|
20
|
-
/**
|
|
21
|
-
* Camera's projection matrix
|
|
22
|
-
* @type {Float32Array|number[]|mat4}
|
|
23
|
-
*/
|
|
24
|
-
this.matrix_projection = new Float32Array(common_buffer, 64, 16);
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
*
|
|
28
|
-
* @type {Float32Array|number[]|mat4}
|
|
29
|
-
*/
|
|
30
|
-
this.view_projection_matrix = new Float32Array(common_buffer, 128, 16);
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* @private
|
|
34
|
-
* @type {VirtualGeometry|null}
|
|
35
|
-
*/
|
|
36
|
-
this.output = null;
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
*
|
|
40
|
-
* @type {THREE.Object3D[]}
|
|
41
|
-
*/
|
|
42
|
-
this.input_scene = [];
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
*
|
|
46
|
-
* @type {number}
|
|
47
|
-
*/
|
|
48
|
-
this.input_scene_length = 0;
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Screen resolution
|
|
52
|
-
* @type {Vector2}
|
|
53
|
-
*/
|
|
54
|
-
this.resolution = new Vector2();
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* How much error to accept when deciding to subdivide a cluster
|
|
58
|
-
* Measured in pixels
|
|
59
|
-
* Higher value will result in better performance but more visible artifacts
|
|
60
|
-
* @type {number}
|
|
61
|
-
*/
|
|
62
|
-
this.error_bias = 2;
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
*
|
|
66
|
-
* @type {RefinementSpec}
|
|
67
|
-
*/
|
|
68
|
-
this.refinement_spec = new RefinementSpec();
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
dropCache() {
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
*
|
|
76
|
-
* @param {VirtualGeometry} output
|
|
77
|
-
*/
|
|
78
|
-
setOutput(output) {
|
|
79
|
-
this.output = output;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
*
|
|
84
|
-
* @param {THREE.PerspectiveCamera} camera
|
|
85
|
-
*/
|
|
86
|
-
setMatricesFromCamera(camera) {
|
|
87
|
-
camera.updateProjectionMatrix();
|
|
88
|
-
camera.updateMatrix();
|
|
89
|
-
camera.updateMatrixWorld(true);
|
|
90
|
-
|
|
91
|
-
this.matrix_world_inverse.set(camera.matrixWorldInverse.elements);
|
|
92
|
-
this.matrix_projection.set(camera.projectionMatrix.elements);
|
|
93
|
-
|
|
94
|
-
mat4.multiply(this.view_projection_matrix, this.matrix_projection, this.matrix_world_inverse);
|
|
95
|
-
|
|
96
|
-
//
|
|
97
|
-
this.refinement_spec.focal_length = camera.fov / 180;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* @private
|
|
102
|
-
* @param {THREE.Object3D|ThreeMicronMesh} object
|
|
103
|
-
*/
|
|
104
|
-
buildForObject(object) {
|
|
105
|
-
if (!object.visible) {
|
|
106
|
-
return;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
if (object.isMicronMesh) {
|
|
110
|
-
/**
|
|
111
|
-
*
|
|
112
|
-
* @type {MicronGeometry|undefined}
|
|
113
|
-
*/
|
|
114
|
-
const micron_geometry = object.geometry;
|
|
115
|
-
|
|
116
|
-
if (micron_geometry !== undefined) {
|
|
117
|
-
|
|
118
|
-
this.buildForMesh(
|
|
119
|
-
object.instance_id,
|
|
120
|
-
micron_geometry,
|
|
121
|
-
object.matrixWorld.elements
|
|
122
|
-
);
|
|
123
|
-
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
*
|
|
130
|
-
* @param {number} instance_id
|
|
131
|
-
* @param {MicronGeometry} geometry
|
|
132
|
-
* @param {number[]} transform world transform matrix of the instance
|
|
133
|
-
*/
|
|
134
|
-
buildForMesh(
|
|
135
|
-
instance_id,
|
|
136
|
-
geometry,
|
|
137
|
-
transform
|
|
138
|
-
) {
|
|
139
|
-
const refinement_spec = this.refinement_spec;
|
|
140
|
-
|
|
141
|
-
refinement_spec.build(transform, this.view_projection_matrix);
|
|
142
|
-
|
|
143
|
-
const output = this.output;
|
|
144
|
-
|
|
145
|
-
output.stats_instance_count++;
|
|
146
|
-
output.stats_source_triangle_count += geometry.source_triangle_count;
|
|
147
|
-
output.stats_source_vertex_count += geometry.source_vertex_count;
|
|
148
|
-
|
|
149
|
-
output.loolup_geometries[geometry.id] = geometry;
|
|
150
|
-
output.lookup_instance_transforms[instance_id] = transform;
|
|
151
|
-
|
|
152
|
-
// build up occurrences
|
|
153
|
-
get_geometry_patch_cut(
|
|
154
|
-
output,
|
|
155
|
-
refinement_spec,
|
|
156
|
-
geometry,
|
|
157
|
-
instance_id,
|
|
158
|
-
transform
|
|
159
|
-
);
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
clearScene() {
|
|
163
|
-
this.input_scene_length = 0;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
/**
|
|
167
|
-
*
|
|
168
|
-
* @param {THREE.Object3D[]} objects
|
|
169
|
-
*/
|
|
170
|
-
appendToScene(objects) {
|
|
171
|
-
const object_count = objects.length;
|
|
172
|
-
array_copy(objects, 0, this.input_scene, this.input_scene_length, object_count);
|
|
173
|
-
|
|
174
|
-
this.input_scene_length += object_count;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
initialize_build() {
|
|
178
|
-
|
|
179
|
-
// update refinement spec
|
|
180
|
-
this.refinement_spec.error_threshold = this.error_bias;
|
|
181
|
-
|
|
182
|
-
const resolution = this.resolution;
|
|
183
|
-
|
|
184
|
-
this.refinement_spec.setResolution(resolution.x, resolution.y);
|
|
185
|
-
|
|
186
|
-
// clear output
|
|
187
|
-
this.output.clear();
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
build() {
|
|
191
|
-
this.initialize_build();
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
const n = this.input_scene_length;
|
|
195
|
-
const input_objects = this.input_scene;
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
for (let i = 0; i < n; i++) {
|
|
199
|
-
const object3D = input_objects[i];
|
|
200
|
-
|
|
201
|
-
traverseThreeObject(object3D, this.buildForObject, this);
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
// console.log(`Enforces splits: ${this.__info_enforced_node_splits}`);
|
|
206
|
-
}
|
|
207
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Approximate the proportion of patch area that a single triangle takes,
|
|
3
|
-
* this is done for error calculation to decide whether a patch needs to be split or not
|
|
4
|
-
* @param {MicronGeometryPatch} patch
|
|
5
|
-
* @returns {number}
|
|
6
|
-
*/
|
|
7
|
-
export function approximateTriangleArea(patch) {
|
|
8
|
-
const average_area = 1 / patch.polygon_count;
|
|
9
|
-
|
|
10
|
-
// TODO instead of using average area, compute and recall smallest triangle's area as proportion of the patch instead
|
|
11
|
-
|
|
12
|
-
// TODO come up with a good way to approximate the proportion of the projected screen area that bounds of the patch take up to that of the projected area of the patch geometry itself
|
|
13
|
-
|
|
14
|
-
/*
|
|
15
|
-
TODO approximate visible area as a transformed disk with the area equal to total area of the patch, modified by the normal cone
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
disk_area = patch.total_area;
|
|
19
|
-
|
|
20
|
-
disk_projected_area = estimate_maximum_projected_disk_area(projection_matrix, patch.normal_cone.direction, patch.normal_cone.angle)
|
|
21
|
-
|
|
22
|
-
*/
|
|
23
|
-
|
|
24
|
-
return average_area;
|
|
25
|
-
}
|
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
import { Matrix4 } from "three";
|
|
2
|
-
import { BitSet } from "../../../../../core/binary/BitSet.js";
|
|
3
|
-
import { GLSLSimulationShader } from "../../../particles/node-based/simulation/GLSLSimulationShader.js";
|
|
4
|
-
import { EmitterAttributeData } from "../../../particles/node-based/simulation/EmitterAttributeData.js";
|
|
5
|
-
import { ParticleSpecification } from "../../../particles/node-based/particle/ParticleSpecification.js";
|
|
6
|
-
import { GLDataBuffer } from "../../../particles/node-based/simulation/GLDataBuffer.js";
|
|
7
|
-
import {
|
|
8
|
-
ParticleAttributeSpecification
|
|
9
|
-
} from "../../../particles/node-based/particle/ParticleAttributeSpecification.js";
|
|
10
|
-
import { ParticleDataTypes } from "../../../particles/node-based/nodes/ParticleDataTypes.js";
|
|
11
|
-
import { NodeGraph } from "../../../../../core/model/node-graph/NodeGraph.js";
|
|
12
|
-
import { ReadVector3Attribute } from "../../../particles/node-based/nodes/attribute/ReadVector3Attribute.js";
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const depth_cull_patch_spec = build_spec();
|
|
16
|
-
|
|
17
|
-
function build_spec() {
|
|
18
|
-
const graph = new NodeGraph();
|
|
19
|
-
|
|
20
|
-
const attr_read_v3 = new ReadVector3Attribute();
|
|
21
|
-
|
|
22
|
-
const n_read_v_min = graph.createNode(attr_read_v3);
|
|
23
|
-
|
|
24
|
-
const r = ParticleSpecification.from(
|
|
25
|
-
[
|
|
26
|
-
ParticleAttributeSpecification.from('v_min', ParticleDataTypes.Vector3),
|
|
27
|
-
ParticleAttributeSpecification.from('v_max', ParticleDataTypes.Vector3)
|
|
28
|
-
],
|
|
29
|
-
[
|
|
30
|
-
ParticleAttributeSpecification.from('projection_matrix', ParticleDataTypes.Matrix4),
|
|
31
|
-
ParticleAttributeSpecification.from('depth_buffer', ParticleDataTypes.Texture2D)
|
|
32
|
-
], graph
|
|
33
|
-
);
|
|
34
|
-
|
|
35
|
-
r.initialize();
|
|
36
|
-
|
|
37
|
-
return r;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
*
|
|
42
|
-
* @returns {GLSLSimulationShader}
|
|
43
|
-
*/
|
|
44
|
-
function buildExecutor() {
|
|
45
|
-
return GLSLSimulationShader.from(
|
|
46
|
-
depth_cull_patch_spec.model,
|
|
47
|
-
depth_cull_patch_spec.attributes,
|
|
48
|
-
depth_cull_patch_spec.uniforms
|
|
49
|
-
);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
const MAX_PATCH_COUNT = 60000;
|
|
53
|
-
|
|
54
|
-
export class PatchCullingSystem {
|
|
55
|
-
constructor() {
|
|
56
|
-
/**
|
|
57
|
-
*
|
|
58
|
-
* @type {MicronGeometryPatchOccurrence[]}
|
|
59
|
-
*/
|
|
60
|
-
this.input = [];
|
|
61
|
-
this.input_size = 0;
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
*
|
|
65
|
-
* @type {Matrix4}
|
|
66
|
-
*/
|
|
67
|
-
this.matrix_projection = new Matrix4()
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
*
|
|
71
|
-
* @type {WebGL2RenderingContext|null}
|
|
72
|
-
*/
|
|
73
|
-
this.gl_context = null;
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
*
|
|
77
|
-
* @type {BitSet}
|
|
78
|
-
*/
|
|
79
|
-
this.visibility_flags = new BitSet();
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
*
|
|
83
|
-
* @type {GLSLSimulationShader}
|
|
84
|
-
* @private
|
|
85
|
-
*/
|
|
86
|
-
this.__exeuctor = buildExecutor();
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
this.__buffer = GLDataBuffer.float32(MAX_PATCH_COUNT);
|
|
90
|
-
|
|
91
|
-
this.__depth_cull_attribute_source = EmitterAttributeData.from(depth_cull_patch_spec, this.__buffer, MAX_PATCH_COUNT);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
initialize() {
|
|
95
|
-
const gl = this.gl_context;
|
|
96
|
-
|
|
97
|
-
this.__buffer.initialize(gl);
|
|
98
|
-
this.__exeuctor.compile(gl);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
finalize() {
|
|
102
|
-
this.__exeuctor.dispose();
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
*
|
|
107
|
-
* @param {MicronGeometryPatchOccurrence[]} data
|
|
108
|
-
* @param {number} length
|
|
109
|
-
*/
|
|
110
|
-
setInput(data, length) {
|
|
111
|
-
this.input = data;
|
|
112
|
-
this.input_size = length;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
runDepthOcclusionCulling(depth_buffer) {
|
|
116
|
-
// 1 - put all input patches into the vertex buffer
|
|
117
|
-
|
|
118
|
-
// 2 - execute transform shader
|
|
119
|
-
|
|
120
|
-
this.__exeuctor.execute([this.matrix_projection.elements], this.__depth_cull_attribute_source);
|
|
121
|
-
// 3 - transform results are marked as visible or not
|
|
122
|
-
for (let i = 0; i < this.input_size; i++) {
|
|
123
|
-
const visibility = this.__depth_cull_attribute_source.readAttributeFloat(0, i);
|
|
124
|
-
|
|
125
|
-
this.visibility_flags.set(i, visibility !== 0);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
}
|
|
129
|
-
}
|