@woosh/meep-engine 2.34.47 → 2.34.48
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/BitSet.js +4 -2
- package/core/geom/3d/aabb/aabb3_estimate_projected_area2.js +1 -1
- package/engine/ecs/foliage/ecs/Foliage2System.js +15 -3
- package/engine/graphics/micron/format/MicronGeometry.js +1 -3
- package/engine/graphics/micron/prototypeVirtualGeometry.js +5 -3
- package/engine/graphics/micron/render/VirtualGeometryBuilder.js +10 -42
- package/engine/graphics/micron/render/refinement/get_geometry_patch_cut.js +123 -0
- package/package.json +1 -1
package/core/binary/BitSet.js
CHANGED
|
@@ -533,12 +533,14 @@ BitSet.prototype.shift = function (distance, start_index, end_index) {
|
|
|
533
533
|
* Sets all of the bits in this BitSet to false.
|
|
534
534
|
*/
|
|
535
535
|
BitSet.prototype.reset = function () {
|
|
536
|
-
|
|
536
|
+
const current_length = this.__length;
|
|
537
|
+
|
|
538
|
+
if (current_length <= 0) {
|
|
537
539
|
// no action required
|
|
538
540
|
return;
|
|
539
541
|
}
|
|
540
542
|
|
|
541
|
-
this.__data_uint32.fill(0, 0, Math.ceil(
|
|
543
|
+
this.__data_uint32.fill(0, 0, Math.ceil(current_length / 32));
|
|
542
544
|
this.__length = 0;
|
|
543
545
|
};
|
|
544
546
|
|
|
@@ -111,10 +111,22 @@ export class Foliage2System extends System {
|
|
|
111
111
|
|
|
112
112
|
this.renderLayer = graphics.layers.create('instanced-mesh-system');
|
|
113
113
|
|
|
114
|
-
|
|
114
|
+
/**
|
|
115
|
+
*
|
|
116
|
+
* @type {CameraViewManager}
|
|
117
|
+
*/
|
|
118
|
+
const views = graphics.views;
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
*
|
|
122
|
+
* @type {List<CameraView>}
|
|
123
|
+
*/
|
|
124
|
+
const view_list = views.elements;
|
|
125
|
+
|
|
126
|
+
view_list.forEach(this.__handle_view_added, this);
|
|
115
127
|
|
|
116
|
-
|
|
117
|
-
|
|
128
|
+
view_list.on.added.add(this.__handle_view_added, this);
|
|
129
|
+
view_list.on.removed.add(this.__handle_view_removed, this);
|
|
118
130
|
|
|
119
131
|
this.renderLayer.buildVisibleSet = (destination, destination_offset, view) => {
|
|
120
132
|
const data = this.data;
|
|
@@ -261,8 +261,8 @@ function init() {
|
|
|
261
261
|
|
|
262
262
|
// shadow_camera.onBeforeRender = do_vgrt_update;
|
|
263
263
|
|
|
264
|
-
scene.add(new CameraHelper(shadow_camera));
|
|
265
|
-
scene.add(new DirectionalLightHelper(directionalLight));
|
|
264
|
+
// scene.add(new CameraHelper(shadow_camera));
|
|
265
|
+
// scene.add(new DirectionalLightHelper(directionalLight));
|
|
266
266
|
|
|
267
267
|
shadow_camera.updateProjectionMatrix();
|
|
268
268
|
|
|
@@ -459,7 +459,7 @@ function init() {
|
|
|
459
459
|
|
|
460
460
|
// sample_gltf_sponza();
|
|
461
461
|
// gltf_sample('data/models/RTS_Buildings_Humans/18/Building_R_18_out/Building_R_18.gltf');
|
|
462
|
-
sample_lucy();
|
|
462
|
+
// sample_lucy();
|
|
463
463
|
// sample_dragon();
|
|
464
464
|
// sample_gltf_hapro_2();
|
|
465
465
|
// sample_gltf_hapro_1();
|
|
@@ -479,6 +479,8 @@ function init() {
|
|
|
479
479
|
// gltf_sample('moicon/03_Jan_22_Demo/8-assets/model.gltf');
|
|
480
480
|
// gltf_sample('moicon/03_Jan_22_Demo/worker_test/model.gltf');
|
|
481
481
|
// gltf_sample('moicon/A4/A4/model.gltf');
|
|
482
|
+
gltf_sample('moicon/ztest_object_many_pieces/model.gltf');
|
|
483
|
+
// gltf_grid('moicon/ztest_object_many_pieces/model.gltf', 3, 3);
|
|
482
484
|
|
|
483
485
|
document.addEventListener("mousemove", onDocumentMouseMove);
|
|
484
486
|
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { array_copy } from "../../../../core/collection/array/copyArray.js";
|
|
2
2
|
import Vector2 from "../../../../core/geom/Vector2.js";
|
|
3
|
-
import { MicronGeometryPatchOccurrence } from "../format/MicronGeometryPatchOccurance.js";
|
|
4
3
|
import { RefinementSpec } from "./refinement/RefinementSpec.js";
|
|
5
4
|
import { ActivePatchList } from "./refinement/ActivePatchList.js";
|
|
6
|
-
import { ActivePatchFlags } from "./refinement/ActivePatchFlags.js";
|
|
7
5
|
import { mat4 } from "gl-matrix";
|
|
6
|
+
import { get_geometry_patch_cut } from "./refinement/get_geometry_patch_cut.js";
|
|
8
7
|
|
|
9
8
|
/**
|
|
10
9
|
* @readonly
|
|
@@ -158,8 +157,6 @@ export class VirtualGeometryBuilder {
|
|
|
158
157
|
transform,
|
|
159
158
|
apl
|
|
160
159
|
) {
|
|
161
|
-
apl.initializeFromGeometry(geometry);
|
|
162
|
-
|
|
163
160
|
refinement_spec.build(transform, this.view_projection_matrix);
|
|
164
161
|
|
|
165
162
|
const output = this.output;
|
|
@@ -168,48 +165,19 @@ export class VirtualGeometryBuilder {
|
|
|
168
165
|
output.stats_source_triangle_count += geometry.source_triangle_count;
|
|
169
166
|
output.stats_source_vertex_count += geometry.source_vertex_count;
|
|
170
167
|
|
|
171
|
-
// apl.build_from_lod(geometry, 0);
|
|
172
|
-
apl.refine(refinement_spec);
|
|
173
|
-
|
|
174
168
|
// build up occurances
|
|
175
169
|
const output_patches = output.patches;
|
|
176
|
-
let output_patch_cursor = output.patch_count;
|
|
177
|
-
let patch_instance;
|
|
178
|
-
|
|
179
|
-
const geometry_id = geometry.id;
|
|
180
|
-
|
|
181
|
-
for (
|
|
182
|
-
let record = apl.records;
|
|
183
|
-
record !== null;
|
|
184
|
-
record = record.link_next
|
|
185
|
-
) {
|
|
186
|
-
|
|
187
|
-
if (!record.getFlag(ActivePatchFlags.Visible)) {
|
|
188
|
-
// patch is not visible, skip
|
|
189
|
-
continue;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
const patch = record.patch;
|
|
193
|
-
patch_instance = output_patches[output_patch_cursor];
|
|
194
|
-
|
|
195
|
-
if (patch_instance === undefined) {
|
|
196
|
-
// no instance available for reuse - create a new one
|
|
197
|
-
patch_instance = new MicronGeometryPatchOccurrence();
|
|
198
|
-
output_patches[output_patch_cursor] = patch_instance;
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
patch_instance.instance_id = instance_id;
|
|
202
|
-
patch_instance.geometry_id = geometry_id;
|
|
203
|
-
patch_instance.patch = patch;
|
|
204
|
-
patch_instance.transform = transform;
|
|
205
|
-
|
|
206
|
-
output_patch_cursor++;
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
output.patch_count = output_patch_cursor;
|
|
210
170
|
|
|
171
|
+
const added_patch_count = get_geometry_patch_cut(
|
|
172
|
+
output_patches,
|
|
173
|
+
output.patch_count,
|
|
174
|
+
refinement_spec,
|
|
175
|
+
geometry,
|
|
176
|
+
instance_id,
|
|
177
|
+
transform
|
|
178
|
+
);
|
|
211
179
|
|
|
212
|
-
|
|
180
|
+
output.patch_count += added_patch_count;
|
|
213
181
|
}
|
|
214
182
|
|
|
215
183
|
clearScene() {
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { BitSet } from "../../../../../core/binary/BitSet.js";
|
|
2
|
+
import { aabb3_intersects_frustum_array } from "../../../../../core/bvh2/aabb3/aabb3_intersects_frustum_array.js";
|
|
3
|
+
import { MicronGeometryPatchOccurrence } from "../../format/MicronGeometryPatchOccurance.js";
|
|
4
|
+
import { aabb3_estimate_projected_area2 } from "../../../../../core/geom/3d/aabb/aabb3_estimate_projected_area2.js";
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
*
|
|
9
|
+
* @type {BitSet}
|
|
10
|
+
*/
|
|
11
|
+
const scratch_traversal_bitset = new BitSet();
|
|
12
|
+
scratch_traversal_bitset.preventShrink();
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @readonly
|
|
16
|
+
* @type {MicronGeometryPatch[]}
|
|
17
|
+
*/
|
|
18
|
+
const scratch_traversal_stack = [];
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
*
|
|
22
|
+
* @param {MicronGeometryPatchOccurrence[]} destination
|
|
23
|
+
* @param {number} destination_offset
|
|
24
|
+
* @param {RefinementSpec} spec
|
|
25
|
+
* @param {MicronGeometry} geometry
|
|
26
|
+
* @param instance_id
|
|
27
|
+
* @param transform
|
|
28
|
+
* @returns {number}
|
|
29
|
+
*/
|
|
30
|
+
export function get_geometry_patch_cut(
|
|
31
|
+
destination,
|
|
32
|
+
destination_offset,
|
|
33
|
+
spec,
|
|
34
|
+
geometry,
|
|
35
|
+
instance_id,
|
|
36
|
+
transform
|
|
37
|
+
) {
|
|
38
|
+
|
|
39
|
+
const frustum_planes = spec.frustum_f32;
|
|
40
|
+
const projection_matrix = spec.projection_matrix;
|
|
41
|
+
const error_threshold = spec.error_threshold_normalized;
|
|
42
|
+
|
|
43
|
+
let output_patch_cursor = destination_offset;
|
|
44
|
+
|
|
45
|
+
let i;
|
|
46
|
+
let stack_cursor = 1;
|
|
47
|
+
let patch_instance;
|
|
48
|
+
|
|
49
|
+
// initialize stack
|
|
50
|
+
const stack = scratch_traversal_stack;
|
|
51
|
+
const root = geometry.root;
|
|
52
|
+
stack[0] = root;
|
|
53
|
+
|
|
54
|
+
const included_set = scratch_traversal_bitset;
|
|
55
|
+
included_set.reset();
|
|
56
|
+
|
|
57
|
+
included_set.set(root.id, true);
|
|
58
|
+
|
|
59
|
+
while (stack_cursor > 0) {
|
|
60
|
+
stack_cursor--;
|
|
61
|
+
|
|
62
|
+
const patch = stack[stack_cursor];
|
|
63
|
+
|
|
64
|
+
/*
|
|
65
|
+
check if node is in view frustum
|
|
66
|
+
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
|
|
67
|
+
*/
|
|
68
|
+
const in_view_frustum = aabb3_intersects_frustum_array(patch.bounding_box, frustum_planes);
|
|
69
|
+
|
|
70
|
+
if (!in_view_frustum) {
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// check if record needs to be split
|
|
75
|
+
if (patch.lod > 0) {
|
|
76
|
+
|
|
77
|
+
// not the lowest level of LOD, see if subdivision might be necessary
|
|
78
|
+
|
|
79
|
+
// compute average triangle area
|
|
80
|
+
// const group_screen_area = aabb3_project_to_2d(patch.group_bounding_box_corners, projection_matrix);
|
|
81
|
+
const group_screen_area = aabb3_estimate_projected_area2(patch.group_bounding_box, projection_matrix);
|
|
82
|
+
const screen_space_error = patch.group_error * group_screen_area;
|
|
83
|
+
|
|
84
|
+
if (screen_space_error > error_threshold) {
|
|
85
|
+
// error too large, needs to be split
|
|
86
|
+
|
|
87
|
+
const children = patch.children;
|
|
88
|
+
const child_count = children.length;
|
|
89
|
+
|
|
90
|
+
for (i = 0; i < child_count; i++) {
|
|
91
|
+
const child = children[i];
|
|
92
|
+
|
|
93
|
+
if (included_set.getAndSet(child.id)) {
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
stack[stack_cursor++] = child;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
patch_instance = destination[output_patch_cursor];
|
|
106
|
+
|
|
107
|
+
if (patch_instance === undefined) {
|
|
108
|
+
// no instance available for reuse - create a new one
|
|
109
|
+
patch_instance = new MicronGeometryPatchOccurrence();
|
|
110
|
+
destination[output_patch_cursor] = patch_instance;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
patch_instance.instance_id = instance_id;
|
|
114
|
+
patch_instance.geometry_id = geometry.id;
|
|
115
|
+
patch_instance.patch = patch;
|
|
116
|
+
patch_instance.transform = transform;
|
|
117
|
+
|
|
118
|
+
output_patch_cursor++;
|
|
119
|
+
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return output_patch_cursor - destination_offset;
|
|
123
|
+
}
|
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"productName": "Meep",
|
|
6
6
|
"description": "production-ready JavaScript game engine based on Entity Component System Architecture",
|
|
7
7
|
"author": "Alexander Goldring",
|
|
8
|
-
"version": "2.34.
|
|
8
|
+
"version": "2.34.48",
|
|
9
9
|
"dependencies": {
|
|
10
10
|
"gl-matrix": "3.4.3",
|
|
11
11
|
"fast-levenshtein": "2.0.6",
|