@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,329 +0,0 @@
|
|
|
1
|
-
import { assert } from "../../../../../core/assert.js";
|
|
2
|
-
import { BitSet } from "../../../../../core/binary/BitSet.js";
|
|
3
|
-
import { AttributeDataTexture } from "../../../texture/AttributeDataTexture.js";
|
|
4
|
-
import { max3 } from "../../../../../core/math/max3.js";
|
|
5
|
-
import { gen_micron_vertex_attribute_texture_name } from "./shader/gen_micron_vertex_attribute_texture_name.js";
|
|
6
|
-
import { min2 } from "../../../../../core/math/min2.js";
|
|
7
|
-
import { MICRON_PATCH_SIZE_MAX } from "../../build/MICRON_PATCH_SIZE_MAX.js";
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
*
|
|
11
|
-
* @type {number}
|
|
12
|
-
*/
|
|
13
|
-
const ALLOCATION_GROW_STEP = 16;
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
*
|
|
17
|
-
* @type {number}
|
|
18
|
-
*/
|
|
19
|
-
const ALLOCATION_GROW_FACTOR = 1.2;
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
*
|
|
23
|
-
* @type {number}
|
|
24
|
-
*/
|
|
25
|
-
const MAX_TEXTURE_SIZE = 16384;
|
|
26
|
-
|
|
27
|
-
const VERTICES_PER_TRIANGLE = 3;
|
|
28
|
-
const ATTRIBUTE_TEXTURE_SLOT_WIDTH =MICRON_PATCH_SIZE_MAX * VERTICES_PER_TRIANGLE;
|
|
29
|
-
|
|
30
|
-
export class PatchDataTextures {
|
|
31
|
-
/**
|
|
32
|
-
*
|
|
33
|
-
* @param {VertexDataSpec} spec
|
|
34
|
-
* @param {number} [column_count]
|
|
35
|
-
*/
|
|
36
|
-
constructor(spec, column_count = 2) {
|
|
37
|
-
assert.defined(spec, 'spec');
|
|
38
|
-
assert.isNonNegativeInteger(column_count, 'column_count');
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
*
|
|
42
|
-
* @type {VertexDataSpec}
|
|
43
|
-
* @private
|
|
44
|
-
*/
|
|
45
|
-
this.__spec = spec;
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
*
|
|
49
|
-
* @type {AttributeDataTexture[]}
|
|
50
|
-
* @private
|
|
51
|
-
*/
|
|
52
|
-
this.__attributes = [];
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
*
|
|
56
|
-
* @type {Map<MicronGeometryPatch, number>}
|
|
57
|
-
* @private
|
|
58
|
-
*/
|
|
59
|
-
this.__residence = new Map();
|
|
60
|
-
|
|
61
|
-
this.__occupied_slots = new BitSet();
|
|
62
|
-
|
|
63
|
-
this.__capacity = 0;
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
*
|
|
67
|
-
* @type {number}
|
|
68
|
-
* @private
|
|
69
|
-
*/
|
|
70
|
-
this.__column_count = column_count;
|
|
71
|
-
|
|
72
|
-
// initialize attributes
|
|
73
|
-
const attributes = this.__attributes;
|
|
74
|
-
const attribute_count = spec.attributes.length;
|
|
75
|
-
|
|
76
|
-
for (let i = 0; i < attribute_count; i++) {
|
|
77
|
-
attributes[i] = new AttributeDataTexture(spec.attributes[i], this.__column_count, ATTRIBUTE_TEXTURE_SLOT_WIDTH);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
*
|
|
84
|
-
* @returns {VertexDataSpec}
|
|
85
|
-
*/
|
|
86
|
-
get spec() {
|
|
87
|
-
return this.__spec;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
*
|
|
92
|
-
* @returns {number}
|
|
93
|
-
*/
|
|
94
|
-
get column_count() {
|
|
95
|
-
return this.__column_count;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* Clear all data
|
|
100
|
-
*/
|
|
101
|
-
clear() {
|
|
102
|
-
this.__residence.clear();
|
|
103
|
-
this.__occupied_slots.reset();
|
|
104
|
-
|
|
105
|
-
const attributes = this.__attributes;
|
|
106
|
-
const attribute_count = attributes.length;
|
|
107
|
-
for (let i = 0; i < attribute_count; i++) {
|
|
108
|
-
const attribute = attributes[i];
|
|
109
|
-
|
|
110
|
-
attribute.clear();
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
estimateByteSize() {
|
|
115
|
-
let result = 0;
|
|
116
|
-
|
|
117
|
-
const attributes = this.__attributes;
|
|
118
|
-
const attribute_count = attributes.length;
|
|
119
|
-
for (let i = 0; i < attribute_count; i++) {
|
|
120
|
-
const attribute = attributes[i];
|
|
121
|
-
|
|
122
|
-
result += attribute.estimateByteSize();
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
return result;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
*
|
|
130
|
-
* @param {number} n
|
|
131
|
-
*/
|
|
132
|
-
set capacity(n) {
|
|
133
|
-
// console.log(`#PatchDataTextures.capacity = ${n}`); // DEBUG
|
|
134
|
-
|
|
135
|
-
const attributes = this.__attributes;
|
|
136
|
-
const attribute_count = attributes.length;
|
|
137
|
-
for (let i = 0; i < attribute_count; i++) {
|
|
138
|
-
const attribute = attributes[i];
|
|
139
|
-
|
|
140
|
-
attribute.resize(n);
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
this.__capacity = n;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
*
|
|
148
|
-
* @param {number} index
|
|
149
|
-
*/
|
|
150
|
-
zero_fill_slot(index) {
|
|
151
|
-
const attributes = this.__attributes;
|
|
152
|
-
const attribute_count = attributes.length;
|
|
153
|
-
for (let i = 0; i < attribute_count; i++) {
|
|
154
|
-
const attribute = attributes[i];
|
|
155
|
-
|
|
156
|
-
attribute.zero_fill_slot(index);
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
/**
|
|
161
|
-
*
|
|
162
|
-
* @param {MicronGeometryPatch} patch
|
|
163
|
-
* @return {boolean}
|
|
164
|
-
*/
|
|
165
|
-
release(patch) {
|
|
166
|
-
const address = this.__residence.get(patch);
|
|
167
|
-
|
|
168
|
-
if (address !== undefined) {
|
|
169
|
-
this.__residence.delete(patch);
|
|
170
|
-
this.__occupied_slots.clear(address);
|
|
171
|
-
|
|
172
|
-
// zero-fill slot
|
|
173
|
-
this.zero_fill_slot(address);
|
|
174
|
-
|
|
175
|
-
return true;
|
|
176
|
-
} else {
|
|
177
|
-
return false;
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
/**
|
|
182
|
-
*
|
|
183
|
-
* @param {number} address
|
|
184
|
-
* @param {MicronGeometryPatch} patch
|
|
185
|
-
*/
|
|
186
|
-
bind(address, patch) {
|
|
187
|
-
// console.log(`#PatchDataTextures.bind(${address}, ${patch.id})`); // DEBUG
|
|
188
|
-
|
|
189
|
-
this.__residence.set(patch, address);
|
|
190
|
-
this.__occupied_slots.set(address, true);
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
/**
|
|
194
|
-
*
|
|
195
|
-
* @param {number} address
|
|
196
|
-
* @param {MicronGeometryPatch} patch
|
|
197
|
-
*/
|
|
198
|
-
write_data(address, patch) {
|
|
199
|
-
// console.log(`#PatchDataTextures.write_data(${address}, ${patch.id})`); // DEBUG
|
|
200
|
-
|
|
201
|
-
const indices = patch.face_indices;
|
|
202
|
-
|
|
203
|
-
const attribute_arrays = patch.vertex_attribute_arrays;
|
|
204
|
-
|
|
205
|
-
const attribute_textures = this.__attributes;
|
|
206
|
-
const attribute_count = attribute_arrays.length;
|
|
207
|
-
|
|
208
|
-
for (let i = 0; i < attribute_count; i++) {
|
|
209
|
-
const attribute_source = attribute_arrays[i];
|
|
210
|
-
|
|
211
|
-
const attribute_texture = attribute_textures[i];
|
|
212
|
-
|
|
213
|
-
attribute_texture.write_slot_from_indexed(address, indices, attribute_source);
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
/**
|
|
218
|
-
*
|
|
219
|
-
* @param {number} address
|
|
220
|
-
* @param {MicronGeometryPatch} patch
|
|
221
|
-
* @returns {boolean}
|
|
222
|
-
*/
|
|
223
|
-
is_slot_data_equal(address, patch) {
|
|
224
|
-
const indices = patch.face_indices;
|
|
225
|
-
|
|
226
|
-
const attribute_arrays = patch.vertex_attribute_arrays;
|
|
227
|
-
|
|
228
|
-
const attribute_textures = this.__attributes;
|
|
229
|
-
const attribute_count = attribute_arrays.length;
|
|
230
|
-
|
|
231
|
-
for (let i = 0; i < attribute_count; i++) {
|
|
232
|
-
const attribute_source = attribute_arrays[i];
|
|
233
|
-
|
|
234
|
-
const attribute_texture = attribute_textures[i];
|
|
235
|
-
|
|
236
|
-
const equal = attribute_texture.is_slot_data_equal(address, indices, attribute_source);
|
|
237
|
-
|
|
238
|
-
if (!equal) {
|
|
239
|
-
return false;
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
return true;
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
/**
|
|
247
|
-
*
|
|
248
|
-
* @param {number} capacity
|
|
249
|
-
*/
|
|
250
|
-
ensureCapacity(capacity) {
|
|
251
|
-
const existing_capacity = this.__capacity;
|
|
252
|
-
|
|
253
|
-
if (capacity > existing_capacity) {
|
|
254
|
-
let next_capacity = max3(
|
|
255
|
-
existing_capacity + ALLOCATION_GROW_STEP,
|
|
256
|
-
Math.ceil(existing_capacity * ALLOCATION_GROW_FACTOR),
|
|
257
|
-
capacity + 1
|
|
258
|
-
);
|
|
259
|
-
|
|
260
|
-
// Clamp to maximum texture size
|
|
261
|
-
next_capacity = min2(next_capacity, MAX_TEXTURE_SIZE * this.__column_count);
|
|
262
|
-
|
|
263
|
-
if (next_capacity < capacity) {
|
|
264
|
-
throw new Error(`Maximum texture size exceeded`);
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
this.capacity = next_capacity;
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
validate_contents() {
|
|
272
|
-
for (const [patch, address] of this.__residence) {
|
|
273
|
-
if (!this.is_slot_data_equal(address, patch)) {
|
|
274
|
-
return false;
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
return true;
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
/**
|
|
283
|
-
*
|
|
284
|
-
* @param {MicronGeometryPatch} patch
|
|
285
|
-
* @returns {number}
|
|
286
|
-
*/
|
|
287
|
-
ensure(patch) {
|
|
288
|
-
|
|
289
|
-
const existing_address = this.__residence.get(patch);
|
|
290
|
-
|
|
291
|
-
if (existing_address !== undefined) {
|
|
292
|
-
return existing_address;
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
// write
|
|
296
|
-
const address = this.__occupied_slots.nextClearBit(0);
|
|
297
|
-
|
|
298
|
-
this.ensureCapacity(address + 1);
|
|
299
|
-
|
|
300
|
-
this.bind(address, patch);
|
|
301
|
-
this.write_data(address, patch);
|
|
302
|
-
|
|
303
|
-
return address;
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
genUniforms() {
|
|
307
|
-
const result = {};
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
const attributes = this.__attributes;
|
|
311
|
-
const attribute_count = attributes.length;
|
|
312
|
-
|
|
313
|
-
for (let i = 0; i < attribute_count; i++) {
|
|
314
|
-
const attribute = attributes[i];
|
|
315
|
-
|
|
316
|
-
const spec = attribute.spec;
|
|
317
|
-
|
|
318
|
-
const uniform_name = gen_micron_vertex_attribute_texture_name(spec.name);
|
|
319
|
-
|
|
320
|
-
result[uniform_name] = {
|
|
321
|
-
type: 't',
|
|
322
|
-
value: attribute.texture
|
|
323
|
-
};
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
return result;
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
}
|
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
import { PatchDataTextures } from "./PatchDataTextures.js";
|
|
2
|
-
import {
|
|
3
|
-
BufferAttribute,
|
|
4
|
-
InstancedBufferAttribute,
|
|
5
|
-
InstancedBufferGeometry,
|
|
6
|
-
StaticReadUsage,
|
|
7
|
-
StreamDrawUsage
|
|
8
|
-
} from "three";
|
|
9
|
-
import { MICRON_PATCH_SIZE_MAX } from "../../build/MICRON_PATCH_SIZE_MAX.js";
|
|
10
|
-
import Signal from "../../../../../core/events/signal/Signal.js";
|
|
11
|
-
import { ATTRIBUTE_NAME_ADDRESS, ATTRIBUTE_NAME_TRANSFORM } from "./shader/constants.js";
|
|
12
|
-
import { shader_rewrite_standard } from "./shader/shader_rewrite_standard.js";
|
|
13
|
-
|
|
14
|
-
export class ThreeInstancedAdapter {
|
|
15
|
-
/**
|
|
16
|
-
*
|
|
17
|
-
* @param {VertexDataSpec} spec
|
|
18
|
-
*/
|
|
19
|
-
constructor(spec) {
|
|
20
|
-
/**
|
|
21
|
-
*
|
|
22
|
-
* @type {InstancedBufferGeometry|null}
|
|
23
|
-
* @private
|
|
24
|
-
*/
|
|
25
|
-
this.__buffer_geometry = null;
|
|
26
|
-
|
|
27
|
-
// build non-indexed geometry for a patch
|
|
28
|
-
|
|
29
|
-
this.__capacity = -1;
|
|
30
|
-
|
|
31
|
-
this.__spec = spec;
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* 10 columns come from 4096 texture resolution, that seems to be maximum widely supported resolution.
|
|
36
|
-
* Here's the math: 4096/ (3*128) = 10.6666
|
|
37
|
-
* @type {PatchDataTextures}
|
|
38
|
-
* @private
|
|
39
|
-
*/
|
|
40
|
-
this.__patch_data = new PatchDataTextures(spec, 10);
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
this.__uniforms = Object.assign({}, this.__patch_data.genUniforms());
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
*
|
|
47
|
-
* @type {Signal}
|
|
48
|
-
*/
|
|
49
|
-
this.onRebuild = new Signal();
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
*
|
|
54
|
-
* @param {{vertexShader,fragmentShader,uniforms:Object<IUniform>}} shader
|
|
55
|
-
*/
|
|
56
|
-
rewriteMaterial(shader) {
|
|
57
|
-
shader_rewrite_standard(shader, this.__uniforms, this.__spec, this.__patch_data.column_count);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
__build_geometry() {
|
|
61
|
-
if (this.__buffer_geometry !== null) {
|
|
62
|
-
this.__buffer_geometry.dispose();
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
this.__buffer_geometry = new InstancedBufferGeometry();
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
// build non-indexed geometry for a patch
|
|
69
|
-
const geo = this.__buffer_geometry;
|
|
70
|
-
|
|
71
|
-
const position_buffer = new BufferAttribute(new Uint8Array(MICRON_PATCH_SIZE_MAX * 3 * 3), 3, false);
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
position_buffer.setUsage(StaticReadUsage);
|
|
75
|
-
|
|
76
|
-
geo.setAttribute('position', position_buffer);
|
|
77
|
-
// geo.setAttribute('normal', new BufferAttribute(new Uint8Array(MICRON_PATCH_SIZE_MAX * 3 * 3), 3, false));
|
|
78
|
-
|
|
79
|
-
// instance attributes
|
|
80
|
-
const capacity = this.__capacity;
|
|
81
|
-
|
|
82
|
-
const transform_buffer = new InstancedBufferAttribute(new Float32Array(capacity * 16), 16, false);
|
|
83
|
-
// const transform_buffer = new InstancedInterleavedBuffer(this.__attribute__transform, 16);
|
|
84
|
-
transform_buffer.setUsage(StreamDrawUsage);
|
|
85
|
-
|
|
86
|
-
geo.setAttribute(ATTRIBUTE_NAME_TRANSFORM, transform_buffer);
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
const ia_patch_ref = new InstancedBufferAttribute(new Uint16Array(capacity), 1, false);
|
|
90
|
-
ia_patch_ref.setUsage(StreamDrawUsage);
|
|
91
|
-
|
|
92
|
-
geo.setAttribute(ATTRIBUTE_NAME_ADDRESS, ia_patch_ref);
|
|
93
|
-
|
|
94
|
-
// signal
|
|
95
|
-
this.onRebuild.send0();
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
*
|
|
100
|
-
* @param {number} target
|
|
101
|
-
* @private
|
|
102
|
-
*/
|
|
103
|
-
__resize_capacity(target) {
|
|
104
|
-
this.__capacity = target;
|
|
105
|
-
this.__build_geometry();
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
*
|
|
110
|
-
* @param {number} v
|
|
111
|
-
* @private
|
|
112
|
-
*/
|
|
113
|
-
__prepare_capacity(v) {
|
|
114
|
-
if (this.__capacity < v) {
|
|
115
|
-
this.__resize_capacity(v);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
const geometry = this.__buffer_geometry;
|
|
119
|
-
|
|
120
|
-
if (geometry.instanceCount !== v) {
|
|
121
|
-
geometry.instanceCount = v;
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
*
|
|
128
|
-
* @param {Uint32Array} patches
|
|
129
|
-
* @param {number} patch_count
|
|
130
|
-
* @param {VirtualGeometry} virtual_geometry
|
|
131
|
-
*/
|
|
132
|
-
build(patches, patch_count, virtual_geometry) {
|
|
133
|
-
this.__prepare_capacity(patch_count);
|
|
134
|
-
|
|
135
|
-
const geo = this.__buffer_geometry;
|
|
136
|
-
|
|
137
|
-
const patch_transform_attribute = geo.attributes[ATTRIBUTE_NAME_TRANSFORM];
|
|
138
|
-
/**
|
|
139
|
-
*
|
|
140
|
-
* @type {Float32Array}
|
|
141
|
-
*/
|
|
142
|
-
const patch_transform_array = patch_transform_attribute.array;
|
|
143
|
-
|
|
144
|
-
patch_transform_attribute.needsUpdate = true;
|
|
145
|
-
|
|
146
|
-
const patch_address_attribute = geo.attributes[ATTRIBUTE_NAME_ADDRESS];
|
|
147
|
-
const patch_address_array = patch_address_attribute.array;
|
|
148
|
-
|
|
149
|
-
patch_address_attribute.needsUpdate = true;
|
|
150
|
-
|
|
151
|
-
const patch_data = this.__patch_data;
|
|
152
|
-
const transforms = virtual_geometry.lookup_instance_transforms;
|
|
153
|
-
const geometries = virtual_geometry.loolup_geometries;
|
|
154
|
-
|
|
155
|
-
for (let i = 0; i < patch_count; i++) {
|
|
156
|
-
const i3 = i * 3;
|
|
157
|
-
|
|
158
|
-
const instance_id = patches[i3];
|
|
159
|
-
const geometry_id = patches[i3 + 1];
|
|
160
|
-
const patch_id = patches[i3 + 2];
|
|
161
|
-
|
|
162
|
-
const transform = transforms[instance_id];
|
|
163
|
-
const micron_geometry = geometries[geometry_id];
|
|
164
|
-
const patch = micron_geometry.patches[patch_id];
|
|
165
|
-
|
|
166
|
-
const i16 = i * 16;
|
|
167
|
-
|
|
168
|
-
patch_transform_array.set(transform, i16);
|
|
169
|
-
|
|
170
|
-
const patch_slot_id = patch_data.ensure(patch);
|
|
171
|
-
|
|
172
|
-
patch_address_array[i] = patch_slot_id;
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
}
|