@woosh/meep-engine 2.34.47 → 2.35.0
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 +10 -3
- package/core/bvh2/BinaryNode.js +19 -35
- package/core/bvh2/aabb3/aabb3_intersects_frustum_array.js +5 -5
- package/core/bvh2/aabb3_combined_surface_area.js +21 -0
- package/core/bvh2/traversal/queryBinaryNode_FrustumIntersections.js +24 -12
- package/core/cache/Cache.d.ts +2 -0
- package/core/cache/Cache.js +27 -23
- package/core/geom/3d/aabb/aabb3_estimate_projected_area2.js +1 -1
- package/core/geom/3d/frustum/frustum_from_projection_matrix_array.js +29 -24
- package/core/math/max2.js +2 -6
- package/core/math/min2.js +2 -6
- package/engine/asset/loaders/geometry/geometry/computeGeometryEquality.js +3 -2
- package/engine/asset/loaders/geometry/geometry/computeGeometryHash.js +9 -1
- package/engine/ecs/EntityComponentDataset.js +7 -2
- package/engine/ecs/foliage/ViewState.js +13 -3
- package/engine/ecs/foliage/ecs/Foliage2System.js +15 -3
- package/engine/ecs/parent/EntityNode.js +23 -11
- package/engine/ecs/transform/Transform.js +15 -13
- package/engine/graphics/ecs/mesh-v2/ShadedGeometry.js +63 -26
- package/engine/graphics/ecs/mesh-v2/ShadedGeometrySystem.js +63 -3
- package/engine/graphics/ecs/mesh-v2/render/AbstractRenderAdapter.js +67 -0
- package/engine/graphics/ecs/mesh-v2/render/GenericRendererAdapter.js +48 -0
- package/engine/graphics/ecs/mesh-v2/render/InstancedRendererAdapter.js +110 -0
- package/engine/graphics/ecs/mesh-v2/render/ShadedGeometryRendererContext.js +98 -0
- package/engine/graphics/ecs/mesh-v2/sample/load_gltf.js +5 -0
- package/engine/graphics/ecs/mesh-v2/sample/prototypeShadedGeometry.js +23 -5
- package/engine/graphics/ecs/mesh-v2/three_object_to_entity_composition.js +8 -3
- package/engine/graphics/geometry/instancing/InstancedMeshGroup.js +23 -85
- package/engine/graphics/geometry/instancing/rewriteMaterial.js +9 -45
- package/engine/graphics/material/optimization/BUFFER_GEOMETRY_UVS.js +10 -0
- package/engine/graphics/material/optimization/MaterialDescriptor.js +46 -0
- package/engine/graphics/material/optimization/MaterialOptimizationContext.js +470 -201
- package/engine/graphics/material/optimization/UvContext.js +18 -0
- package/engine/graphics/material/optimization/is_compliant_mesh.js +71 -0
- package/engine/graphics/material/optimization/prepare_atlas_texture.js +23 -0
- package/engine/graphics/material/optimization/prototypeMaterialOptimizer.js +127 -0
- package/engine/graphics/micron/convert_three_object_to_micron.js +0 -2
- package/engine/graphics/micron/format/MicronGeometry.js +1 -3
- package/engine/graphics/micron/format/MicronGeometryPatch.js +34 -24
- package/engine/graphics/micron/format/VirtualGeometry.js +47 -11
- package/engine/graphics/micron/format/serialization/MicronGeometryBinarySerializationAdapter.js +22 -0
- package/engine/graphics/micron/prototypeVirtualGeometry.js +10 -5
- package/engine/graphics/micron/render/VirtualGeometryBuilder.js +14 -55
- package/engine/graphics/micron/render/instanced/AttributeDataTexture.js +1 -45
- package/engine/graphics/micron/render/instanced/ThreeInstancedAdapter.js +18 -7
- package/engine/graphics/micron/render/refinement/RefinementSpec.js +0 -12
- package/engine/graphics/micron/render/refinement/get_geometry_patch_cut.js +118 -0
- package/engine/graphics/micron/render/v1/MaterialContext.js +3 -2
- package/engine/graphics/micron/render/v1/VGThreeRenderer.js +19 -4
- package/engine/graphics/render/utils/ThreeBypassRenderer.js +3 -2
- package/engine/graphics/texture/normalized_internal_format.js +48 -0
- package/engine/graphics/texture/sampler/Sampler2D.js +6 -0
- package/engine/graphics/texture/sampler/sampler2d_copy_channel_data.js +25 -0
- package/engine/graphics/texture/sampler/scaleSampler2D.js +3 -0
- package/engine/graphics/texture/sampler/util/drawSamplerHTML.js +14 -1
- package/package.json +1 -1
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import Vector2 from "../../../../core/geom/Vector2.js";
|
|
2
|
+
import AABB2 from "../../../../core/geom/AABB2.js";
|
|
3
|
+
|
|
4
|
+
export class UvContext {
|
|
5
|
+
constructor() {
|
|
6
|
+
/**
|
|
7
|
+
* Resolution of texture
|
|
8
|
+
* @type {Vector2}
|
|
9
|
+
*/
|
|
10
|
+
this.resolution = new Vector2(1, 1);
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
*
|
|
14
|
+
* @type {AABB2}
|
|
15
|
+
*/
|
|
16
|
+
this.atlas_patch = new AABB2();
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { TextureAttachmentsByMaterialType } from "../../../asset/loaders/material/TextureAttachmensByMaterialType.js";
|
|
2
|
+
import { max2 } from "../../../../core/math/max2.js";
|
|
3
|
+
import { BUFFER_GEOMETRY_UVS } from "./BUFFER_GEOMETRY_UVS.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Is this mesh qualified to be optimized?
|
|
7
|
+
* @param {THREE.Mesh} mesh
|
|
8
|
+
* @returns {boolean}
|
|
9
|
+
*/
|
|
10
|
+
export function is_compliant_mesh(mesh) {
|
|
11
|
+
const material = mesh.material;
|
|
12
|
+
|
|
13
|
+
const attachments = TextureAttachmentsByMaterialType[material.type];
|
|
14
|
+
|
|
15
|
+
const uv_scales = [1, 1, 1, 1];
|
|
16
|
+
|
|
17
|
+
const texture_attachment_count = attachments.length;
|
|
18
|
+
|
|
19
|
+
for (let i = 0; i < texture_attachment_count; i++) {
|
|
20
|
+
const attachment = attachments[i];
|
|
21
|
+
|
|
22
|
+
const texture = attachment.read(material);
|
|
23
|
+
if (texture === undefined || texture === null) {
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const uv_index = attachment.uv_index;
|
|
28
|
+
|
|
29
|
+
uv_scales[uv_index * 2] = max2(uv_scales[uv_index * 2], texture.repeat.x)
|
|
30
|
+
uv_scales[uv_index * 2 + 1] = max2(uv_scales[uv_index * 2 + 1], texture.repeat.y)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const geometry = mesh.geometry;
|
|
34
|
+
|
|
35
|
+
for (let i = 0; i < BUFFER_GEOMETRY_UVS.length; i++) {
|
|
36
|
+
const uv_metadata = BUFFER_GEOMETRY_UVS[i];
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
*
|
|
40
|
+
* @type {THREE.BufferAttribute }
|
|
41
|
+
*/
|
|
42
|
+
const attribute = geometry.attributes[uv_metadata.name];
|
|
43
|
+
|
|
44
|
+
if (attribute === undefined) {
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const attribute_data = attribute.array;
|
|
49
|
+
const n = attribute_data.length;
|
|
50
|
+
|
|
51
|
+
const uv_index = uv_metadata.index;
|
|
52
|
+
const uv_index_2 = uv_index * 2;
|
|
53
|
+
|
|
54
|
+
for (let j = 0; j < n; j += 2) {
|
|
55
|
+
const x = attribute_data[j];
|
|
56
|
+
const y = attribute_data[j + 1];
|
|
57
|
+
|
|
58
|
+
const scaled_u = x * uv_scales[uv_index_2];
|
|
59
|
+
const scaled_v = y * uv_scales[uv_index_2 + 1];
|
|
60
|
+
|
|
61
|
+
if (scaled_u > 1 || scaled_u < 0 || scaled_v > 1 || scaled_v < 0) {
|
|
62
|
+
// repeating/negative UV value
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return true;
|
|
71
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { LinearEncoding, LinearFilter, LinearMipmapLinearFilter, sRGBEncoding } from "three";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* @param {Texture} texture
|
|
6
|
+
* @param {string} attachment_name
|
|
7
|
+
*/
|
|
8
|
+
export function prepare_atlas_texture(texture, attachment_name) {
|
|
9
|
+
|
|
10
|
+
switch (attachment_name) {
|
|
11
|
+
case 'diffuse':
|
|
12
|
+
texture.encoding = sRGBEncoding;
|
|
13
|
+
break;
|
|
14
|
+
default:
|
|
15
|
+
texture.encoding = LinearEncoding;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
texture.anisotropy = 4;
|
|
19
|
+
texture.minFilter = LinearMipmapLinearFilter;
|
|
20
|
+
texture.magFilter = LinearFilter;
|
|
21
|
+
|
|
22
|
+
texture.generateMipmaps = true;
|
|
23
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { EngineHarness } from "../../../EngineHarness.js";
|
|
2
|
+
import { EngineConfiguration } from "../../../EngineConfiguration.js";
|
|
3
|
+
import { ShadedGeometrySystem } from "../../ecs/mesh-v2/ShadedGeometrySystem.js";
|
|
4
|
+
import { AttachmentSystem } from "../../../ecs/attachment/AttachmentSystem.js";
|
|
5
|
+
import { TransformAttachmentSystem } from "../../../ecs/transform-attachment/TransformAttachmentSystem.js";
|
|
6
|
+
import { GameAssetType } from "../../../asset/GameAssetType.js";
|
|
7
|
+
import { GLTFAssetLoader } from "../../../asset/loaders/GLTFAssetLoader.js";
|
|
8
|
+
import { three_object_to_entity_composition } from "../../ecs/mesh-v2/three_object_to_entity_composition.js";
|
|
9
|
+
import { MaterialOptimizationContext } from "./MaterialOptimizationContext.js";
|
|
10
|
+
import { bvh_traverse_pre_order_using_stack } from "../../../../core/bvh2/traversal/bvh_traverse_pre_order_using_stack.js";
|
|
11
|
+
|
|
12
|
+
const eh = new EngineHarness();
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
*
|
|
17
|
+
* @param {Engine} engine
|
|
18
|
+
*/
|
|
19
|
+
function optimize(engine) {
|
|
20
|
+
MaterialOptimizationContext.MAX_TEXTURE_SIZE = engine.graphics.renderer.capabilities.maxTextureSize;
|
|
21
|
+
|
|
22
|
+
const optimizer = new MaterialOptimizationContext();
|
|
23
|
+
|
|
24
|
+
engine.graphics.layers.layers.forEach(l => {
|
|
25
|
+
bvh_traverse_pre_order_using_stack(l.bvh, node => {
|
|
26
|
+
if (node.isLeafNode) {
|
|
27
|
+
const object = l.extractRenderable(node.object);
|
|
28
|
+
|
|
29
|
+
if (object) {
|
|
30
|
+
optimizer.addObject(object);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
optimizer.update();
|
|
37
|
+
|
|
38
|
+
console.log(optimizer);
|
|
39
|
+
|
|
40
|
+
// drawSamplerHTML(document.body, optimizer.atlases.get('roughness'), 20, 20, 1, 0, 512);
|
|
41
|
+
// drawSamplerHTML(document.body, optimizer.atlases.get('metalness'), 532, 20, 1, 0, 512);
|
|
42
|
+
// drawSamplerHTML(document.body, optimizer.atlases.get('ao'), 20, 532, 1, 0, 512);
|
|
43
|
+
// drawSamplerHTML(document.body, optimizer.atlases.get('normal'), 532, 20, 1, 0, 512);
|
|
44
|
+
// drawSamplerHTML(document.body, optimizer.atlases.get('diffuse'), 20, 20, 1, 0, 1024);
|
|
45
|
+
// drawSamplerHTML(document.body, optimizer.atlases.get('normal'), 552, 20, 1, 0, 512);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
*
|
|
50
|
+
* @param {EngineHarness} harness
|
|
51
|
+
* @return {Promise<void>}
|
|
52
|
+
*/
|
|
53
|
+
async function init(harness) {
|
|
54
|
+
const engine = harness.engine;
|
|
55
|
+
|
|
56
|
+
const config = new EngineConfiguration();
|
|
57
|
+
|
|
58
|
+
config.addSystem(new ShadedGeometrySystem(engine));
|
|
59
|
+
config.addSystem(new AttachmentSystem());
|
|
60
|
+
config.addSystem(new TransformAttachmentSystem());
|
|
61
|
+
|
|
62
|
+
const gltf_loader = new GLTFAssetLoader();
|
|
63
|
+
|
|
64
|
+
config.addLoader(GameAssetType.ModelGLTF_JSON, gltf_loader);
|
|
65
|
+
|
|
66
|
+
await config.apply(engine);
|
|
67
|
+
|
|
68
|
+
eh.initialize().then(main);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
*
|
|
73
|
+
* @param {string} path
|
|
74
|
+
* @param {Engine} engine
|
|
75
|
+
*/
|
|
76
|
+
async function load_gltf(path, engine) {
|
|
77
|
+
const em = engine.entityManager;
|
|
78
|
+
|
|
79
|
+
const ecd = em.dataset;
|
|
80
|
+
|
|
81
|
+
const asset = await engine.assetManager.promise(path, GameAssetType.ModelGLTF_JSON);
|
|
82
|
+
|
|
83
|
+
const three_object = asset.create();
|
|
84
|
+
|
|
85
|
+
console.time('composition conversion');
|
|
86
|
+
const composition = three_object_to_entity_composition(three_object);
|
|
87
|
+
console.timeEnd('composition conversion');
|
|
88
|
+
|
|
89
|
+
console.time('composition build');
|
|
90
|
+
// console.profile('composition build');
|
|
91
|
+
composition.build(ecd);
|
|
92
|
+
// console.profileEnd('composition build');
|
|
93
|
+
console.timeEnd('composition build');
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
async function timeout(t = 1) {
|
|
97
|
+
await new Promise((resolve, reject) => setTimeout(resolve, t));
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
*
|
|
102
|
+
* @param {Engine} engine
|
|
103
|
+
*/
|
|
104
|
+
async function main(engine) {
|
|
105
|
+
|
|
106
|
+
EngineHarness.buildBasics({
|
|
107
|
+
engine,
|
|
108
|
+
enableWater: false,
|
|
109
|
+
enableTerrain: true
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
// a small delay to let background tasks finish, so we can get better performance reading later on
|
|
113
|
+
timeout(2000);
|
|
114
|
+
|
|
115
|
+
await load_gltf('moicon/06_04_hapro/08-clickable-assets-new/model.gltf', engine);
|
|
116
|
+
// await load_gltf('moicon/06_04_hapro/05-ground-floor/model.gltf', engine);
|
|
117
|
+
|
|
118
|
+
optimize(engine);
|
|
119
|
+
|
|
120
|
+
// load_gltf('moicon/06_04_hapro/07-1st-basement/model.gltf', engine);
|
|
121
|
+
// load_gltf('moicon/06_04_hapro/06-lower-ground/model.gltf', engine);
|
|
122
|
+
// load_gltf('moicon/06_04_hapro/05-ground-floor/model.gltf', engine);
|
|
123
|
+
// load_gltf('moicon/06_04_hapro/04-1st-floor/model.gltf', engine);
|
|
124
|
+
// load_gltf('moicon/06_04_hapro/03-2nd-floor/model.gltf', engine);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
init(eh);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { squirrel3 } from "../../../../core/math/hash/squirrel3.js";
|
|
2
1
|
import { ConicRay } from "../../../../core/geom/ConicRay.js";
|
|
3
2
|
import { vec4 } from "gl-matrix";
|
|
3
|
+
import { assert } from "../../../../core/assert.js";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Patches are organized into a tree hierarchy
|
|
@@ -13,36 +13,37 @@ export class MicronGeometryPatch {
|
|
|
13
13
|
*/
|
|
14
14
|
this.id = 0;
|
|
15
15
|
|
|
16
|
-
/**
|
|
17
|
-
* Continuous memory region for various pieces of data to get better memory access patterns
|
|
18
|
-
* All pieces of data end up in a continuous piece of memory, resulting in better cache coherence
|
|
19
|
-
* @type {ArrayBuffer}
|
|
20
|
-
*/
|
|
21
|
-
const array_buffer = new ArrayBuffer((6 + 6 + 24) * 4);
|
|
22
|
-
|
|
23
16
|
/**
|
|
24
17
|
* Bounds are used to determine screen error and whether a patch should be subdivided or not for rendering
|
|
25
18
|
* @type {number[]}
|
|
26
19
|
*/
|
|
27
|
-
this.bounding_box =
|
|
20
|
+
this.bounding_box = null;
|
|
28
21
|
|
|
29
22
|
/**
|
|
30
23
|
*
|
|
31
24
|
* @type {vec4|number[]}
|
|
32
25
|
*/
|
|
33
|
-
this.bounding_sphere = vec4.create()
|
|
26
|
+
this.bounding_sphere = vec4.create();
|
|
34
27
|
|
|
35
28
|
/**
|
|
36
29
|
*
|
|
37
30
|
* @type {number[]|Float32Array}
|
|
38
31
|
*/
|
|
39
|
-
this.group_bounding_box =
|
|
32
|
+
this.group_bounding_box = null;
|
|
40
33
|
|
|
41
34
|
/**
|
|
42
35
|
*
|
|
43
36
|
* @type {number[]|Float32Array}
|
|
44
37
|
*/
|
|
45
|
-
this.group_bounding_box_corners =
|
|
38
|
+
this.group_bounding_box_corners = null;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Continuous memory region for various pieces of data to get better memory access patterns
|
|
42
|
+
* All pieces of data end up in a continuous piece of memory, resulting in better cache coherence
|
|
43
|
+
* @type {ArrayBuffer}
|
|
44
|
+
*/
|
|
45
|
+
const array_buffer = new ArrayBuffer(144);
|
|
46
|
+
this.allocate_metadata(array_buffer, 0);
|
|
46
47
|
|
|
47
48
|
/**
|
|
48
49
|
*
|
|
@@ -114,21 +115,25 @@ export class MicronGeometryPatch {
|
|
|
114
115
|
}
|
|
115
116
|
|
|
116
117
|
/**
|
|
117
|
-
*
|
|
118
|
+
*
|
|
119
|
+
* @param {ArrayBuffer} buffer
|
|
120
|
+
* @param {number} offset
|
|
121
|
+
* @returns {number}
|
|
118
122
|
*/
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
}
|
|
123
|
+
allocate_metadata(buffer, offset) {
|
|
124
|
+
assert.greaterThanOrEqual(buffer.byteLength, offset + 144, 'buffer underflow');
|
|
122
125
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
126
|
+
this.bounding_box = new Float32Array(buffer, offset, 6);
|
|
127
|
+
|
|
128
|
+
this.group_bounding_box = new Float32Array(buffer, offset + 24, 6);
|
|
129
|
+
|
|
130
|
+
this.group_bounding_box_corners = new Float32Array(buffer, offset + 48, 24);
|
|
131
|
+
|
|
132
|
+
return 144;
|
|
128
133
|
}
|
|
129
134
|
|
|
130
135
|
hash() {
|
|
131
|
-
return
|
|
136
|
+
return this.id;
|
|
132
137
|
}
|
|
133
138
|
|
|
134
139
|
computeByteSize() {
|
|
@@ -136,8 +141,13 @@ export class MicronGeometryPatch {
|
|
|
136
141
|
|
|
137
142
|
result += this.face_indices.buffer.byteLength;
|
|
138
143
|
|
|
139
|
-
|
|
140
|
-
|
|
144
|
+
const attribute_arrays = this.vertex_attribute_arrays;
|
|
145
|
+
const attribute_count = attribute_arrays.length;
|
|
146
|
+
|
|
147
|
+
for (let i = 0; i < attribute_count; i++) {
|
|
148
|
+
const attribute_array = attribute_arrays[i];
|
|
149
|
+
|
|
150
|
+
result += attribute_array.buffer.byteLength;
|
|
141
151
|
}
|
|
142
152
|
|
|
143
153
|
return result;
|
|
@@ -1,12 +1,31 @@
|
|
|
1
|
+
import { MicronGeometryPatchOccurrence } from "./MicronGeometryPatchOccurance.js";
|
|
2
|
+
|
|
1
3
|
export class VirtualGeometry {
|
|
2
4
|
constructor() {
|
|
5
|
+
/**
|
|
6
|
+
* pack patch instance as [INSTANCE_ID, GEOMETRY_ID, PATCH_ID]
|
|
7
|
+
* @type {number[]}
|
|
8
|
+
*/
|
|
9
|
+
this.patches = new Uint32Array(300000);
|
|
10
|
+
|
|
3
11
|
/**
|
|
4
12
|
*
|
|
5
|
-
* @type {
|
|
13
|
+
* @type {number}
|
|
6
14
|
*/
|
|
7
|
-
this.patches = [];
|
|
8
15
|
this.patch_count = 0;
|
|
9
16
|
|
|
17
|
+
/**
|
|
18
|
+
* Lookup table of matrix transforms
|
|
19
|
+
* @type {number[][]}
|
|
20
|
+
*/
|
|
21
|
+
this.lookup_instance_transforms = [];
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Lookup table of geometries
|
|
25
|
+
* @type {MicronGeometry[]}
|
|
26
|
+
*/
|
|
27
|
+
this.loolup_geometries = [];
|
|
28
|
+
|
|
10
29
|
/**
|
|
11
30
|
*
|
|
12
31
|
* @type {number}
|
|
@@ -30,11 +49,20 @@ export class VirtualGeometry {
|
|
|
30
49
|
*/
|
|
31
50
|
computeFaceCount() {
|
|
32
51
|
let r = 0;
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
52
|
+
const patch_count = this.patch_count;
|
|
53
|
+
const patches = this.patches;
|
|
54
|
+
|
|
55
|
+
for (let i = 0; i < patch_count; i++) {
|
|
56
|
+
const i3 = i * 3;
|
|
57
|
+
|
|
58
|
+
const geometry_id = patches[i3 + 1];
|
|
59
|
+
const patch_id = patches[i3 + 2];
|
|
60
|
+
|
|
61
|
+
const geometry = this.loolup_geometries[geometry_id];
|
|
36
62
|
|
|
37
|
-
|
|
63
|
+
const patch = geometry.patches[patch_id];
|
|
64
|
+
|
|
65
|
+
r += patch.polygon_count;
|
|
38
66
|
}
|
|
39
67
|
|
|
40
68
|
return r;
|
|
@@ -46,11 +74,19 @@ export class VirtualGeometry {
|
|
|
46
74
|
*/
|
|
47
75
|
computeVertexCount() {
|
|
48
76
|
let r = 0;
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
77
|
+
const patch_count = this.patch_count;
|
|
78
|
+
const patches = this.patches;
|
|
79
|
+
for (let i = 0; i < patch_count; i++) {
|
|
80
|
+
const i3 = i * 3;
|
|
81
|
+
|
|
82
|
+
const geometry_id = patches[i3 + 1];
|
|
83
|
+
const patch_id = patches[i3 + 2];
|
|
84
|
+
|
|
85
|
+
const geometry = this.loolup_geometries[geometry_id];
|
|
86
|
+
|
|
87
|
+
const patch = geometry.patches[patch_id];
|
|
52
88
|
|
|
53
|
-
r +=
|
|
89
|
+
r += patch.vertex_count;
|
|
54
90
|
}
|
|
55
91
|
|
|
56
92
|
return r;
|
|
@@ -61,7 +97,7 @@ export class VirtualGeometry {
|
|
|
61
97
|
* @param {MicronGeometryPatchOccurrence} patch
|
|
62
98
|
*/
|
|
63
99
|
add(patch) {
|
|
64
|
-
|
|
100
|
+
throw new Error('Deprecated');
|
|
65
101
|
}
|
|
66
102
|
|
|
67
103
|
clear() {
|
package/engine/graphics/micron/format/serialization/MicronGeometryBinarySerializationAdapter.js
CHANGED
|
@@ -77,25 +77,47 @@ export class MicronGeometryBinarySerializationAdapter extends BinaryClassSeriali
|
|
|
77
77
|
|
|
78
78
|
const patch_count = buffer.readUintVar();
|
|
79
79
|
|
|
80
|
+
/**
|
|
81
|
+
*
|
|
82
|
+
* @type {MicronGeometryPatch[]}
|
|
83
|
+
*/
|
|
80
84
|
const patches = [];
|
|
81
85
|
|
|
86
|
+
// for the sake of speed, we will allocate all metadata in the same piece of memory to make traversal of patch hierarchy faster
|
|
87
|
+
const md_buffer = new ArrayBuffer(patch_count * 144);
|
|
88
|
+
let md_buffer_offset = 0;
|
|
89
|
+
|
|
82
90
|
// build initial patches
|
|
83
91
|
for (let i = 0; i < patch_count; i++) {
|
|
84
92
|
const patch = new MicronGeometryPatch();
|
|
85
93
|
|
|
86
94
|
patch.id = i;
|
|
87
95
|
|
|
96
|
+
md_buffer_offset += patch.allocate_metadata(md_buffer, md_buffer_offset);
|
|
97
|
+
|
|
88
98
|
patches[i] = patch;
|
|
89
99
|
}
|
|
90
100
|
|
|
101
|
+
let source_triangle_count = 0;
|
|
102
|
+
// NOTE: we can't easily find out source vertex count as vertices are duplicated across patches
|
|
103
|
+
|
|
104
|
+
|
|
91
105
|
//read patches
|
|
92
106
|
for (let i = 0; i < patch_count; i++) {
|
|
93
107
|
const patch = patches[i];
|
|
94
108
|
|
|
95
109
|
deserialize_patch(buffer, patch, vertex_spec, patches);
|
|
110
|
+
|
|
111
|
+
// collect source metadata
|
|
112
|
+
if (patch.lod === 0) {
|
|
113
|
+
source_triangle_count += patch.polygon_count;
|
|
114
|
+
}
|
|
96
115
|
}
|
|
97
116
|
|
|
98
117
|
value.patches = patches;
|
|
99
118
|
value.root = patches[root_patch_index];
|
|
119
|
+
|
|
120
|
+
// write source metadata
|
|
121
|
+
value.source_triangle_count = source_triangle_count;
|
|
100
122
|
}
|
|
101
123
|
}
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AmbientLight,
|
|
3
3
|
BoxBufferGeometry,
|
|
4
|
-
CameraHelper,
|
|
5
4
|
CubeTextureLoader,
|
|
6
5
|
DirectionalLight,
|
|
7
|
-
DirectionalLightHelper,
|
|
8
6
|
FrontSide,
|
|
9
7
|
Matrix4,
|
|
10
8
|
Mesh,
|
|
@@ -64,6 +62,10 @@ metrics.create({
|
|
|
64
62
|
name: 'adapter_update', buffer_size: METRIC_BUFFER_SIZE
|
|
65
63
|
});
|
|
66
64
|
|
|
65
|
+
metrics.create({
|
|
66
|
+
name: 'debug_v0', buffer_size: METRIC_BUFFER_SIZE
|
|
67
|
+
});
|
|
68
|
+
|
|
67
69
|
let container, stats;
|
|
68
70
|
|
|
69
71
|
let camera, scene, renderer;
|
|
@@ -261,8 +263,8 @@ function init() {
|
|
|
261
263
|
|
|
262
264
|
// shadow_camera.onBeforeRender = do_vgrt_update;
|
|
263
265
|
|
|
264
|
-
scene.add(new CameraHelper(shadow_camera));
|
|
265
|
-
scene.add(new DirectionalLightHelper(directionalLight));
|
|
266
|
+
// scene.add(new CameraHelper(shadow_camera));
|
|
267
|
+
// scene.add(new DirectionalLightHelper(directionalLight));
|
|
266
268
|
|
|
267
269
|
shadow_camera.updateProjectionMatrix();
|
|
268
270
|
|
|
@@ -459,7 +461,7 @@ function init() {
|
|
|
459
461
|
|
|
460
462
|
// sample_gltf_sponza();
|
|
461
463
|
// gltf_sample('data/models/RTS_Buildings_Humans/18/Building_R_18_out/Building_R_18.gltf');
|
|
462
|
-
sample_lucy();
|
|
464
|
+
// sample_lucy();
|
|
463
465
|
// sample_dragon();
|
|
464
466
|
// sample_gltf_hapro_2();
|
|
465
467
|
// sample_gltf_hapro_1();
|
|
@@ -479,6 +481,9 @@ function init() {
|
|
|
479
481
|
// gltf_sample('moicon/03_Jan_22_Demo/8-assets/model.gltf');
|
|
480
482
|
// gltf_sample('moicon/03_Jan_22_Demo/worker_test/model.gltf');
|
|
481
483
|
// gltf_sample('moicon/A4/A4/model.gltf');
|
|
484
|
+
gltf_sample('moicon/06_04_hapro/08-clickable-assets-new/model.gltf');
|
|
485
|
+
// gltf_sample('moicon/ztest_object_many_pieces/model.gltf');
|
|
486
|
+
// gltf_grid('moicon/ztest_object_many_pieces/model.gltf', 3, 3);
|
|
482
487
|
|
|
483
488
|
document.addEventListener("mousemove", onDocumentMouseMove);
|
|
484
489
|
|
|
@@ -1,10 +1,10 @@
|
|
|
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";
|
|
7
|
+
import { traverseThreeObject } from "../../ecs/highlight/renderer/traverseThreeObject.js";
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* @readonly
|
|
@@ -107,7 +107,7 @@ export class VirtualGeometryBuilder {
|
|
|
107
107
|
}
|
|
108
108
|
|
|
109
109
|
/**
|
|
110
|
-
*
|
|
110
|
+
* @private
|
|
111
111
|
* @param {THREE.Object3D|ThreeMicronMesh} object
|
|
112
112
|
*/
|
|
113
113
|
buildForObject(object) {
|
|
@@ -134,15 +134,6 @@ export class VirtualGeometryBuilder {
|
|
|
134
134
|
);
|
|
135
135
|
}
|
|
136
136
|
}
|
|
137
|
-
|
|
138
|
-
const children = object.children;
|
|
139
|
-
const children_count = children.length;
|
|
140
|
-
|
|
141
|
-
for (let i = 0; i < children_count; i++) {
|
|
142
|
-
const child = children[i];
|
|
143
|
-
|
|
144
|
-
this.buildForObject(child);
|
|
145
|
-
}
|
|
146
137
|
}
|
|
147
138
|
|
|
148
139
|
/**
|
|
@@ -158,8 +149,6 @@ export class VirtualGeometryBuilder {
|
|
|
158
149
|
transform,
|
|
159
150
|
apl
|
|
160
151
|
) {
|
|
161
|
-
apl.initializeFromGeometry(geometry);
|
|
162
|
-
|
|
163
152
|
refinement_spec.build(transform, this.view_projection_matrix);
|
|
164
153
|
|
|
165
154
|
const output = this.output;
|
|
@@ -168,48 +157,17 @@ export class VirtualGeometryBuilder {
|
|
|
168
157
|
output.stats_source_triangle_count += geometry.source_triangle_count;
|
|
169
158
|
output.stats_source_vertex_count += geometry.source_vertex_count;
|
|
170
159
|
|
|
171
|
-
|
|
172
|
-
|
|
160
|
+
output.loolup_geometries[geometry.id] = geometry;
|
|
161
|
+
output.lookup_instance_transforms[instance_id] = transform;
|
|
173
162
|
|
|
174
163
|
// build up occurances
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
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
|
-
|
|
211
|
-
|
|
212
|
-
// TODO sort patches based on camera distance to better utilize z-culling in hardware
|
|
164
|
+
get_geometry_patch_cut(
|
|
165
|
+
output,
|
|
166
|
+
refinement_spec,
|
|
167
|
+
geometry,
|
|
168
|
+
instance_id,
|
|
169
|
+
transform
|
|
170
|
+
);
|
|
213
171
|
}
|
|
214
172
|
|
|
215
173
|
clearScene() {
|
|
@@ -243,10 +201,11 @@ export class VirtualGeometryBuilder {
|
|
|
243
201
|
const n = this.input_scene_length;
|
|
244
202
|
const input_objects = this.input_scene;
|
|
245
203
|
|
|
204
|
+
|
|
246
205
|
for (let i = 0; i < n; i++) {
|
|
247
206
|
const object3D = input_objects[i];
|
|
248
207
|
|
|
249
|
-
this.buildForObject
|
|
208
|
+
traverseThreeObject(object3D, this.buildForObject, this);
|
|
250
209
|
}
|
|
251
210
|
|
|
252
211
|
|