@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,255 +0,0 @@
|
|
|
1
|
-
import { BufferAttribute, BufferGeometry, DynamicDrawUsage } from "three";
|
|
2
|
-
import Signal from "../../../../../core/events/signal/Signal.js";
|
|
3
|
-
import {
|
|
4
|
-
DataType2TypedArrayConstructorMapping
|
|
5
|
-
} from "../../../../../core/binary/type/DataType2TypedArrayConstructorMapping.js";
|
|
6
|
-
import { getTransformedPositionsCached } from "./getTransformedPositionsCached.js";
|
|
7
|
-
import { Color } from "../../../../../core/color/Color.js";
|
|
8
|
-
import { seededRandom } from "../../../../../core/math/random/seededRandom.js";
|
|
9
|
-
import { randomFloatBetween } from "../../../../../core/math/random/randomFloatBetween.js";
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const scratch_random = seededRandom(0);
|
|
13
|
-
const scratch_color = new Color();
|
|
14
|
-
|
|
15
|
-
export class ThreeVirtualGeometryAdapter {
|
|
16
|
-
constructor() {
|
|
17
|
-
this.buffer_geometry = new BufferGeometry();
|
|
18
|
-
|
|
19
|
-
this.__vertex_capacity = -1;
|
|
20
|
-
this.__face_capacity = -1;
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
*
|
|
24
|
-
* @type {VertexDataSpec}
|
|
25
|
-
* @private
|
|
26
|
-
*/
|
|
27
|
-
this.__vertex_spec = null;
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
*
|
|
31
|
-
* @type {Signal}
|
|
32
|
-
*/
|
|
33
|
-
this.onRebuild = new Signal();
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
*
|
|
37
|
-
* @type {boolean}
|
|
38
|
-
* @private
|
|
39
|
-
*/
|
|
40
|
-
this.__enable_debug_attribute_patch_vertex_color = true;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
*
|
|
45
|
-
* @param {number} vertex_count
|
|
46
|
-
* @param {number} face_count
|
|
47
|
-
*/
|
|
48
|
-
resizeGeometry(vertex_count, face_count) {
|
|
49
|
-
if (this.__face_capacity < face_count || this.__vertex_capacity < vertex_count) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
this.rebuildBufferGeometry(vertex_count, face_count);
|
|
53
|
-
}
|
|
54
|
-
this.buffer_geometry.setDrawRange(0, face_count * 3);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
*
|
|
59
|
-
* @param {number} vertex_count
|
|
60
|
-
* @param {number} face_count
|
|
61
|
-
*/
|
|
62
|
-
rebuildBufferGeometry(vertex_count, face_count) {
|
|
63
|
-
|
|
64
|
-
this.buffer_geometry.dispose();
|
|
65
|
-
|
|
66
|
-
const geometry = new BufferGeometry();
|
|
67
|
-
|
|
68
|
-
const index_buffer = new BufferAttribute(new Uint32Array(face_count * 3), 1, false);
|
|
69
|
-
index_buffer.setUsage(DynamicDrawUsage);
|
|
70
|
-
geometry.setIndex(index_buffer);
|
|
71
|
-
|
|
72
|
-
const vertexSpec = this.__vertex_spec;
|
|
73
|
-
const vertexAttributeSpecs = vertexSpec.attributes;
|
|
74
|
-
|
|
75
|
-
for (let i = 0; i < vertexAttributeSpecs.length; i++) {
|
|
76
|
-
const attribute_spec = vertexAttributeSpecs[i];
|
|
77
|
-
|
|
78
|
-
const array = new DataType2TypedArrayConstructorMapping[attribute_spec.type](vertex_count * attribute_spec.itemSize);
|
|
79
|
-
|
|
80
|
-
const attribute = new BufferAttribute(array, attribute_spec.itemSize, attribute_spec.normalized);
|
|
81
|
-
attribute.setUsage(DynamicDrawUsage);
|
|
82
|
-
|
|
83
|
-
geometry.setAttribute(attribute_spec.name, attribute);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
if (this.__enable_debug_attribute_patch_vertex_color) {
|
|
87
|
-
//
|
|
88
|
-
const colors_array = new Uint8Array(vertex_count * 3);
|
|
89
|
-
geometry.setAttribute('color', new BufferAttribute(colors_array, 3, true));
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
this.__face_capacity = face_count;
|
|
93
|
-
this.__vertex_capacity = vertex_count;
|
|
94
|
-
|
|
95
|
-
this.buffer_geometry = geometry;
|
|
96
|
-
|
|
97
|
-
this.onRebuild.send0();
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
*
|
|
103
|
-
* @param {VirtualGeometry} vg
|
|
104
|
-
*/
|
|
105
|
-
build(vg) {
|
|
106
|
-
const face_count = vg.computeFaceCount();
|
|
107
|
-
const vertex_count = vg.computeVertexCount();
|
|
108
|
-
|
|
109
|
-
this.resizeGeometry(vertex_count, face_count);
|
|
110
|
-
|
|
111
|
-
const geometry = this.buffer_geometry;
|
|
112
|
-
|
|
113
|
-
const attribute_index = geometry.getIndex();
|
|
114
|
-
attribute_index.needsUpdate = true;
|
|
115
|
-
attribute_index.updateRange.offset = 0;
|
|
116
|
-
attribute_index.updateRange.count = face_count * 3;
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
const vertex_attribute_specs = this.__vertex_spec.attributes;
|
|
120
|
-
const vertex_attribute_spec_count = vertex_attribute_specs.length;
|
|
121
|
-
|
|
122
|
-
// map attributes by index for faster access
|
|
123
|
-
const geometry_attributes = [];
|
|
124
|
-
for (let i = 0; i < vertex_attribute_specs.length; i++) {
|
|
125
|
-
const attributeSpec = vertex_attribute_specs[i];
|
|
126
|
-
const geometry_attribute = geometry.getAttribute(attributeSpec.name);
|
|
127
|
-
geometry_attribute.needsUpdate = true;
|
|
128
|
-
geometry_attribute.updateRange.offset = 0;
|
|
129
|
-
geometry_attribute.updateRange.count = vertex_count * geometry_attribute.itemSize;
|
|
130
|
-
|
|
131
|
-
geometry_attributes.push(geometry_attribute);
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
// populate
|
|
135
|
-
let face_cursor = 0;
|
|
136
|
-
let vertex_cursor = 0;
|
|
137
|
-
|
|
138
|
-
/*
|
|
139
|
-
WebGL offers gl_VertexID attribute: https://webgl2fundamentals.org/webgl/lessons/webgl-drawing-without-data.html
|
|
140
|
-
can use gl_VertexID to figure out which patch a triangle/vertex belongs to
|
|
141
|
-
inside transform shader, apply matrix transform to the patch geometry
|
|
142
|
-
can use textures to store some extra data if we don't want to touch geometry unnecessarily
|
|
143
|
-
*/
|
|
144
|
-
// TODO do a transform feedback pass, store patch info in a texture
|
|
145
|
-
|
|
146
|
-
const patches = vg.patches;
|
|
147
|
-
const patch_count = vg.patch_count;
|
|
148
|
-
|
|
149
|
-
const destination_index_attribute_array = attribute_index.array;
|
|
150
|
-
|
|
151
|
-
// fill indices
|
|
152
|
-
for (let patch_index = 0; patch_index < patch_count; patch_index++) {
|
|
153
|
-
const occurrence = patches[patch_index];
|
|
154
|
-
|
|
155
|
-
const patch = occurrence.patch;
|
|
156
|
-
const patch_face_count = patch.polygon_count;
|
|
157
|
-
const patch_vertex_count = patch.vertex_count;
|
|
158
|
-
const face_indices = patch.face_indices;
|
|
159
|
-
|
|
160
|
-
const patch_index_size = patch_face_count * 3;
|
|
161
|
-
const face_cursor_3 = face_cursor * 3;
|
|
162
|
-
|
|
163
|
-
for (let i = 0; i < patch_index_size; i++) {
|
|
164
|
-
const source_vertex_index = face_indices[i];
|
|
165
|
-
const remapped_vertex_index = source_vertex_index + vertex_cursor;
|
|
166
|
-
|
|
167
|
-
destination_index_attribute_array[face_cursor_3 + i] = remapped_vertex_index;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
face_cursor += patch_face_count;
|
|
171
|
-
vertex_cursor += patch_vertex_count;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
for (let i = 0; i < vertex_attribute_spec_count; i++) {
|
|
175
|
-
const attributeSpec = vertex_attribute_specs[i];
|
|
176
|
-
|
|
177
|
-
const itemSize = attributeSpec.itemSize;
|
|
178
|
-
|
|
179
|
-
const geometryAttribute = geometry_attributes[i];
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
const destination_attribute_array = geometryAttribute.array;
|
|
183
|
-
vertex_cursor = 0;
|
|
184
|
-
|
|
185
|
-
for (let patch_index = 0; patch_index < patch_count; patch_index++) {
|
|
186
|
-
const occurrence = patches[patch_index];
|
|
187
|
-
|
|
188
|
-
const patch = occurrence.patch;
|
|
189
|
-
|
|
190
|
-
const patch_vertex_count = patch.vertex_count;
|
|
191
|
-
|
|
192
|
-
const vertex_array_start_offset = vertex_cursor * itemSize;
|
|
193
|
-
|
|
194
|
-
// fill vertex data
|
|
195
|
-
const source_attribute_array = patch.vertex_attribute_arrays[i];
|
|
196
|
-
|
|
197
|
-
let transformed_attribute_array;
|
|
198
|
-
if (attributeSpec.name === 'position') {
|
|
199
|
-
transformed_attribute_array = getTransformedPositionsCached(occurrence, i);
|
|
200
|
-
} else {
|
|
201
|
-
transformed_attribute_array = source_attribute_array;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
destination_attribute_array.set(transformed_attribute_array, vertex_array_start_offset);
|
|
205
|
-
|
|
206
|
-
// update cursors
|
|
207
|
-
vertex_cursor += patch_vertex_count;
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
if (this.__enable_debug_attribute_patch_vertex_color) {
|
|
215
|
-
vertex_cursor = 0;
|
|
216
|
-
const color_attribute = geometry.getAttribute('color');
|
|
217
|
-
const colors_array = color_attribute.array;
|
|
218
|
-
|
|
219
|
-
for (let patch_index = 0; patch_index < patch_count; patch_index++) {
|
|
220
|
-
const occurrence = patches[patch_index];
|
|
221
|
-
|
|
222
|
-
const patch = occurrence.patch;
|
|
223
|
-
|
|
224
|
-
const patch_vertex_count = patch.vertex_count;
|
|
225
|
-
|
|
226
|
-
const vertex_array_start_offset = vertex_cursor * 3;
|
|
227
|
-
|
|
228
|
-
// compute color
|
|
229
|
-
|
|
230
|
-
scratch_random.setCurrentSeed(occurrence.hash());
|
|
231
|
-
|
|
232
|
-
scratch_color.setHSL(scratch_random(), randomFloatBetween(scratch_random, 0.5, 0.9), 0.5);
|
|
233
|
-
|
|
234
|
-
const r = Math.round(scratch_color.r * 255);
|
|
235
|
-
const g = Math.round(scratch_color.g * 255);
|
|
236
|
-
const b = Math.round(scratch_color.b * 255);
|
|
237
|
-
|
|
238
|
-
for (let i = 0; i < patch_vertex_count; i++) {
|
|
239
|
-
const i3 = i * 3 + vertex_array_start_offset;
|
|
240
|
-
colors_array[i3] = r;
|
|
241
|
-
colors_array[i3 + 1] = g;
|
|
242
|
-
colors_array[i3 + 2] = b;
|
|
243
|
-
}
|
|
244
|
-
// update cursors
|
|
245
|
-
vertex_cursor += patch_vertex_count;
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
color_attribute.needsUpdate = true;
|
|
249
|
-
color_attribute.updateRange.offset = 0;
|
|
250
|
-
color_attribute.updateRange.count = vertex_count * 3;
|
|
251
|
-
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
}
|
|
255
|
-
}
|
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
import Vector2 from "../../../../../core/geom/Vector2.js";
|
|
2
|
-
import { MaterialContext } from "./MaterialContext.js";
|
|
3
|
-
import { array_copy } from "../../../../../core/collection/array/copyArray.js";
|
|
4
|
-
import { MicronRenderContext } from "./MicronRenderContext.js";
|
|
5
|
-
import { MaterialVertexSpec, MaterialVertexSpecFlags } from "./MaterialVertexSpec.js";
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
*
|
|
9
|
-
* @type {MaterialVertexSpec}
|
|
10
|
-
*/
|
|
11
|
-
const scratch_mvc = new MaterialVertexSpec();
|
|
12
|
-
|
|
13
|
-
export class VGThreeRenderer {
|
|
14
|
-
constructor() {
|
|
15
|
-
/**
|
|
16
|
-
*
|
|
17
|
-
* @type {Object3D[]}
|
|
18
|
-
* @private
|
|
19
|
-
*/
|
|
20
|
-
this.__inputs = [];
|
|
21
|
-
|
|
22
|
-
this.ctx = new MicronRenderContext();
|
|
23
|
-
|
|
24
|
-
this.on = {
|
|
25
|
-
/**
|
|
26
|
-
* @type {Signal<MaterialContext>}
|
|
27
|
-
*/
|
|
28
|
-
contextAdded: this.ctx.on.contextAdded
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
get geometry() {
|
|
33
|
-
return this.ctx.geometry;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Enable/disable wireframe rendering
|
|
38
|
-
* @param {boolean} x
|
|
39
|
-
*/
|
|
40
|
-
set wireframe(x) {
|
|
41
|
-
this.ctx.wireframe = x;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
*
|
|
46
|
-
* @param {THREE.Scene} scene
|
|
47
|
-
*/
|
|
48
|
-
attach(scene) {
|
|
49
|
-
this.__inputs.push(scene);
|
|
50
|
-
this.ctx.builder.appendToScene([scene]);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
attachMany(objects, object_count = objects.length) {
|
|
54
|
-
array_copy(objects, 0, this.__inputs, this.__inputs.length, objects.length);
|
|
55
|
-
this.ctx.builder.appendToScene(objects);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
clear() {
|
|
59
|
-
this.__inputs = [];
|
|
60
|
-
this.ctx.builder.clearScene();
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
__prepare_contexts() {
|
|
64
|
-
// clear contexts
|
|
65
|
-
const render_context = this.ctx;
|
|
66
|
-
const contexts = render_context.__contexts_array;
|
|
67
|
-
const context_count = contexts.length;
|
|
68
|
-
|
|
69
|
-
for (let i = 0; i < context_count; i++) {
|
|
70
|
-
const ctx = contexts[i];
|
|
71
|
-
|
|
72
|
-
ctx.instances.clear();
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
const processObject = (o) => {
|
|
76
|
-
if (o.isMicronMesh) {
|
|
77
|
-
/**
|
|
78
|
-
*
|
|
79
|
-
* @type {ThreeMicronMesh}
|
|
80
|
-
*/
|
|
81
|
-
const m = o;
|
|
82
|
-
|
|
83
|
-
scratch_mvc.material = m.material;
|
|
84
|
-
scratch_mvc.spec = m.geometry.vertex_spec;
|
|
85
|
-
scratch_mvc.writeFlag(MaterialVertexSpecFlags.CastShadow, m.castShadow);
|
|
86
|
-
scratch_mvc.writeFlag(MaterialVertexSpecFlags.ReceiveShadow, m.receiveShadow);
|
|
87
|
-
|
|
88
|
-
const ctx = render_context.obtain_material(scratch_mvc);
|
|
89
|
-
|
|
90
|
-
ctx.instances.add(o.instance_id);
|
|
91
|
-
}
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
const inputs = this.__inputs;
|
|
95
|
-
const input_count = inputs.length;
|
|
96
|
-
|
|
97
|
-
for (let i = 0; i < input_count; i++) {
|
|
98
|
-
const input_object = inputs[i];
|
|
99
|
-
|
|
100
|
-
input_object.traverse(processObject);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
render() {
|
|
106
|
-
this.ctx.render();
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
*
|
|
112
|
-
* @param {THREE.WebGLRenderer} renderer
|
|
113
|
-
* @param {THREE.PerspectiveCamera|THREE.OrthographicCamera|THREE.Camera} camera
|
|
114
|
-
*/
|
|
115
|
-
update(renderer, camera) {
|
|
116
|
-
this.__prepare_contexts();
|
|
117
|
-
|
|
118
|
-
const resolution = new Vector2();
|
|
119
|
-
let pixelRatio = 1;
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
*
|
|
123
|
-
* @type {THREE.RenderTarget}
|
|
124
|
-
*/
|
|
125
|
-
const render_target = renderer.getRenderTarget();
|
|
126
|
-
|
|
127
|
-
if (render_target !== null) {
|
|
128
|
-
resolution.set(render_target.width, render_target.height);
|
|
129
|
-
} else {
|
|
130
|
-
renderer.getSize(resolution);
|
|
131
|
-
pixelRatio = renderer.getPixelRatio();
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
const vg_builder = this.ctx.builder;
|
|
135
|
-
|
|
136
|
-
vg_builder.resolution.set(resolution.x * pixelRatio, resolution.y * pixelRatio);
|
|
137
|
-
vg_builder.setMatricesFromCamera(camera);
|
|
138
|
-
vg_builder.setOutput(this.ctx.geometry);
|
|
139
|
-
|
|
140
|
-
vg_builder.build();
|
|
141
|
-
}
|
|
142
|
-
}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { PatchCacheKey } from "../PatchCacheKey.js";
|
|
2
|
-
import { apply_mat4_transform_to_v3_array } from "../../../../../core/geom/3d/apply_mat4_transform_to_v3_array.js";
|
|
3
|
-
import { Cache } from "../../../../../core/cache/Cache.js";
|
|
4
|
-
import { invokeObjectHash } from "../../../../../core/model/object/invokeObjectHash.js";
|
|
5
|
-
import { invokeObjectEquals } from "../../../../../core/model/object/invokeObjectEquals.js";
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
*
|
|
9
|
-
* @type {Cache<PatchCacheKey, Float32Array>}
|
|
10
|
-
*/
|
|
11
|
-
export const transformed_position_cache = new Cache({
|
|
12
|
-
keyHashFunction: invokeObjectHash,
|
|
13
|
-
keyEqualityFunction: invokeObjectEquals,
|
|
14
|
-
valueWeigher(array) {
|
|
15
|
-
return array.length * 4
|
|
16
|
-
},
|
|
17
|
-
maxWeight: 100 * 1024 * 1024 //100Mb
|
|
18
|
-
});
|
|
19
|
-
transformed_position_cache.onEvicted.add(PatchCacheKey.pool.release, PatchCacheKey.pool);
|
|
20
|
-
const scratch_cache_key = new PatchCacheKey();
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
*
|
|
24
|
-
* @param {MicronGeometryPatchOccurrence} occurrence
|
|
25
|
-
* @param {number} attribute_index
|
|
26
|
-
* @returns {Float32Array}
|
|
27
|
-
*/
|
|
28
|
-
export function getTransformedPositionsCached(occurrence, attribute_index) {
|
|
29
|
-
// we assume that cache misses will be less frequent, so we use an additional fixed key for faster cache queries
|
|
30
|
-
scratch_cache_key.fromPatchOccurrence(occurrence);
|
|
31
|
-
|
|
32
|
-
const existing = transformed_position_cache.get(scratch_cache_key);
|
|
33
|
-
|
|
34
|
-
if (existing !== null) {
|
|
35
|
-
// cache hit
|
|
36
|
-
return existing;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
// create key to be stored in cache
|
|
40
|
-
const key = PatchCacheKey.pool.get();
|
|
41
|
-
key.copy(scratch_cache_key);
|
|
42
|
-
|
|
43
|
-
const patch = occurrence.patch;
|
|
44
|
-
const source_array = patch.vertex_attribute_arrays[attribute_index];
|
|
45
|
-
|
|
46
|
-
const destination = new Float32Array(source_array.length);
|
|
47
|
-
|
|
48
|
-
apply_mat4_transform_to_v3_array(source_array, 0, destination, 0, patch.vertex_count, occurrence.transform.elements);
|
|
49
|
-
|
|
50
|
-
// store in cache
|
|
51
|
-
transformed_position_cache.put(key, destination);
|
|
52
|
-
|
|
53
|
-
return destination;
|
|
54
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { TopoMesh } from "../../../core/geom/3d/topology/struct/TopoMesh.js";
|
|
2
|
-
import { simplifyTopoMesh } from "../../../core/geom/3d/topology/simplify/simplifyTopoMesh.js";
|
|
3
|
-
import {
|
|
4
|
-
topo_mesh_to_three_buffer_geometry
|
|
5
|
-
} from "../../../core/geom/3d/topology/topo_mesh_to_three_buffer_geometry.js";
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
*
|
|
9
|
-
* @param {BufferGeometry} input
|
|
10
|
-
* @param {number} target
|
|
11
|
-
* @return {BufferGeometry}
|
|
12
|
-
*/
|
|
13
|
-
function simplifyGeometry(input, target) {
|
|
14
|
-
const position_attribute = input.getAttribute("position");
|
|
15
|
-
const index_attribute = input.index;
|
|
16
|
-
|
|
17
|
-
const topo = new TopoMesh();
|
|
18
|
-
|
|
19
|
-
topo.build(position_attribute.array, index_attribute.array);
|
|
20
|
-
|
|
21
|
-
// expandConnectivityByLocality(topo);
|
|
22
|
-
|
|
23
|
-
simplifyTopoMesh(topo, target);
|
|
24
|
-
|
|
25
|
-
return topo_mesh_to_three_buffer_geometry(topo);
|
|
26
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { BufferAttribute, BufferGeometry, InterleavedBuffer, InterleavedBufferAttribute } from "three";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
*
|
|
5
|
-
* @param {MicronGeometryPatch} patch
|
|
6
|
-
* @returns {BufferGeometry}
|
|
7
|
-
*/
|
|
8
|
-
export function patchToBufferGeometry(patch) {
|
|
9
|
-
const geometry = new BufferGeometry();
|
|
10
|
-
|
|
11
|
-
geometry.setIndex(new BufferAttribute(patch.face_indices, 1, false))
|
|
12
|
-
|
|
13
|
-
const interleavedBuffer = new InterleavedBuffer(new Float32Array(patch.vertex_attribute_data), 3);
|
|
14
|
-
const position_attribute = new InterleavedBufferAttribute(interleavedBuffer, 3, 0, false);
|
|
15
|
-
geometry.setAttribute("position", position_attribute);
|
|
16
|
-
geometry.computeVertexNormals();
|
|
17
|
-
|
|
18
|
-
return geometry;
|
|
19
|
-
}
|