@woosh/meep-engine 2.48.19 → 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.
Files changed (117) hide show
  1. package/package.json +1 -1
  2. package/src/core/binary/type/BinaryDataType.d.ts +15 -0
  3. package/src/{engine/graphics/render/forward_plus/data/computeDataType.js → core/binary/type/computeBinaryDataTypeByPrecision.js} +3 -3
  4. package/src/core/geom/2d/quad-tree/qt_query_data_nearest_to_point.js +62 -0
  5. package/src/core/graph/layout/computeDisconnectedSubGraphs.js +1 -0
  6. package/src/core/process/task/TaskGroup.js +1 -1
  7. package/src/core/process/task/util/task_tree_compute_leaf_tasks.js +21 -0
  8. package/src/engine/graphics/geometry/AttributeSpec.d.ts +2 -2
  9. package/src/engine/graphics/material/optimization/MaterialOptimizationContext.js +1 -3
  10. package/src/engine/graphics/render/forward_plus/LightManager.js +9 -7
  11. package/src/engine/graphics/{micron/render/instanced → texture}/AttributeDataTexture.js +28 -19
  12. package/src/engine/graphics/{render/forward_plus/data → texture}/TextureBackedMemoryRegion.js +8 -8
  13. package/src/engine/graphics/{render/forward_plus/data → texture}/computeThreeTextureFormat.js +2 -2
  14. package/src/engine/graphics/{render/forward_plus/data → texture}/computeThreeTextureInternalFormatFromDataType.js +1 -1
  15. package/src/engine/graphics/{render/forward_plus/data → texture}/computeThreeTextureTypeFromDataType.js +1 -1
  16. package/src/engine/graphics/texture/sampler/Sampler2D2Canvas.js +1 -1
  17. package/src/engine/graphics/texture/sampler/sampler2DToFloat32Texture.js +1 -3
  18. package/src/generation/GridTaskGroup.js +4 -4
  19. package/src/generation/filtering/numeric/util/populateSampler2DFromCellFilter.js +10 -2
  20. package/src/generation/filtering/numeric/util/sampler_from_filter.js +26 -0
  21. package/src/generation/filtering/numeric/util/visualise_filters_as_grid.js +81 -0
  22. package/src/generation/grid/generation/GridTaskSequence.js +3 -1
  23. package/src/engine/graphics/micron/MICRON_GEOMETRY_FIELD.js +0 -1
  24. package/src/engine/graphics/micron/MICRON_URI_FIELD.js +0 -1
  25. package/src/engine/graphics/micron/build/MICRON_PATCH_SIZE_MAX.js +0 -5
  26. package/src/engine/graphics/micron/build/PatchRepresentation.js +0 -424
  27. package/src/engine/graphics/micron/build/buildMicronGeometryFromBufferGeometry.js +0 -311
  28. package/src/engine/graphics/micron/build/build_geometry_info.js +0 -21
  29. package/src/engine/graphics/micron/build/clustering/assignInitialPatchNeighbours.js +0 -63
  30. package/src/engine/graphics/micron/build/clustering/assign_patch_neighbours_from_topology.js +0 -46
  31. package/src/engine/graphics/micron/build/clustering/build_clustering_2.js +0 -37
  32. package/src/engine/graphics/micron/build/clustering/build_leaf_patches.js +0 -326
  33. package/src/engine/graphics/micron/build/clustering/build_leaf_patches_metis.js +0 -76
  34. package/src/engine/graphics/micron/build/clustering/computeBorderLengthChange.js +0 -59
  35. package/src/engine/graphics/micron/build/clustering/computeFaceCurvatureScore.js +0 -57
  36. package/src/engine/graphics/micron/build/clustering/computeOpenFaceFreedom.js +0 -35
  37. package/src/engine/graphics/micron/build/clustering/compute_face_connection_weight.js +0 -35
  38. package/src/engine/graphics/micron/build/clustering/populateOpenFaceNeighboursForPatch.js +0 -56
  39. package/src/engine/graphics/micron/build/clustering/validate_leaf_patch_connectivity.js +0 -44
  40. package/src/engine/graphics/micron/build/compute_micron_buffer_array_constructor.js +0 -24
  41. package/src/engine/graphics/micron/build/compute_vertex_remap_cost.js +0 -29
  42. package/src/engine/graphics/micron/build/debug/build_clustering_info.js +0 -58
  43. package/src/engine/graphics/micron/build/debug/build_graph_info.js +0 -59
  44. package/src/engine/graphics/micron/build/fill_patch_geometry_data.js +0 -270
  45. package/src/engine/graphics/micron/build/hierarchy/buildAbstractPatchHierarchy.js +0 -196
  46. package/src/engine/graphics/micron/build/hierarchy/build_intermediate_patch_topology.js +0 -162
  47. package/src/engine/graphics/micron/build/hierarchy/build_merge_graph.js +0 -89
  48. package/src/engine/graphics/micron/build/hierarchy/computePatchMergeScore.js +0 -146
  49. package/src/engine/graphics/micron/build/hierarchy/compute_patches_shared_vertex_count.js +0 -32
  50. package/src/engine/graphics/micron/build/hierarchy/compute_patches_shared_vertices.js +0 -34
  51. package/src/engine/graphics/micron/build/hierarchy/merge_patches.js +0 -581
  52. package/src/engine/graphics/micron/build/hierarchy/metis_cluster_clusters.js +0 -53
  53. package/src/engine/graphics/micron/build/hierarchy/optimize_graph_partitioning_balance.js +0 -515
  54. package/src/engine/graphics/micron/build/hierarchy/patch_combine.js +0 -180
  55. package/src/engine/graphics/micron/build/hierarchy/patch_fill_holes_by_uncollapse.js +0 -60
  56. package/src/engine/graphics/micron/build/hierarchy/patch_stitch_parent_border.js +0 -320
  57. package/src/engine/graphics/micron/build/hierarchy/qvdr_build_simplified_clusters.js +0 -547
  58. package/src/engine/graphics/micron/build/hierarchy/qvdr_build_tree.js +0 -140
  59. package/src/engine/graphics/micron/buildPatchwork.js +0 -68
  60. package/src/engine/graphics/micron/convert_three_object_to_micron.js +0 -179
  61. package/src/engine/graphics/micron/debug/VirtualGeometryStats.js +0 -42
  62. package/src/engine/graphics/micron/format/MICRON_GEOMETRY_PROPERTY_NAME.js +0 -1
  63. package/src/engine/graphics/micron/format/MicronGeometry.d.ts +0 -21
  64. package/src/engine/graphics/micron/format/MicronGeometry.js +0 -334
  65. package/src/engine/graphics/micron/format/MicronGeometryPatch.d.ts +0 -3
  66. package/src/engine/graphics/micron/format/MicronGeometryPatch.js +0 -205
  67. package/src/engine/graphics/micron/format/MicronGeometryPatchOccurance.js +0 -50
  68. package/src/engine/graphics/micron/format/ThreeMicronMesh.d.ts +0 -10
  69. package/src/engine/graphics/micron/format/ThreeMicronMesh.js +0 -45
  70. package/src/engine/graphics/micron/format/VirtualGeometry.js +0 -158
  71. package/src/engine/graphics/micron/format/micron_build_proxy_geometry.js +0 -205
  72. package/src/engine/graphics/micron/format/serialization/MicronGeometryBinarySerializationAdapter.js +0 -123
  73. package/src/engine/graphics/micron/format/serialization/MicronGeometryBinarySerializationAdapter.spec.js +0 -63
  74. package/src/engine/graphics/micron/format/serialization/collection/geometry_collection_serialization.js +0 -83
  75. package/src/engine/graphics/micron/format/serialization/collection/geometry_collection_serialization.spec.js +0 -51
  76. package/src/engine/graphics/micron/format/serialization/deserialize_attribute_spec.js +0 -25
  77. package/src/engine/graphics/micron/format/serialization/deserialize_patch.js +0 -106
  78. package/src/engine/graphics/micron/format/serialization/serialize_attribute_spec.js +0 -18
  79. package/src/engine/graphics/micron/format/serialization/serialize_patch.js +0 -84
  80. package/src/engine/graphics/micron/format/validate_patch_bounds.js +0 -69
  81. package/src/engine/graphics/micron/plugin/GLTFAssetTransformer.js +0 -265
  82. package/src/engine/graphics/micron/plugin/GLTF_MICRON_ID_FIELD.js +0 -5
  83. package/src/engine/graphics/micron/plugin/MicronRenderPlugin.d.ts +0 -8
  84. package/src/engine/graphics/micron/plugin/MicronRenderPlugin.js +0 -150
  85. package/src/engine/graphics/micron/plugin/serialization/BufferGeometrySerializationAdapter.js +0 -176
  86. package/src/engine/graphics/micron/plugin/shaded_geometry/MicronShadedGeometryRenderAdapter.js +0 -216
  87. package/src/engine/graphics/micron/prototypeMicronProxyBuild.js +0 -227
  88. package/src/engine/graphics/micron/prototypeVirtualGeometry.js +0 -911
  89. package/src/engine/graphics/micron/render/PatchCacheKey.js +0 -79
  90. package/src/engine/graphics/micron/render/VIRTUAL_MESH_FLAG.d.ts +0 -1
  91. package/src/engine/graphics/micron/render/VIRTUAL_MESH_FLAG.js +0 -1
  92. package/src/engine/graphics/micron/render/VirtualGeometryBuilder.js +0 -207
  93. package/src/engine/graphics/micron/render/approximateTriangleArea.js +0 -25
  94. package/src/engine/graphics/micron/render/culling/PatchCullingSystem.js +0 -129
  95. package/src/engine/graphics/micron/render/instanced/PatchDataTextures.js +0 -325
  96. package/src/engine/graphics/micron/render/instanced/ThreeInstancedAdapter.js +0 -175
  97. package/src/engine/graphics/micron/render/instanced/shader/constants.js +0 -3
  98. package/src/engine/graphics/micron/render/instanced/shader/gen_micron_vertex_attribute_texture_name.js +0 -8
  99. package/src/engine/graphics/micron/render/instanced/shader/shader_rewrite_standard.js +0 -250
  100. package/src/engine/graphics/micron/render/makeThreeMeshFromVirtualGeometry.js +0 -37
  101. package/src/engine/graphics/micron/render/refinement/ActivePatchFlags.js +0 -8
  102. package/src/engine/graphics/micron/render/refinement/ActivePatchList.js +0 -241
  103. package/src/engine/graphics/micron/render/refinement/ActivePatchRecord.js +0 -154
  104. package/src/engine/graphics/micron/render/refinement/RefinementSpec.js +0 -84
  105. package/src/engine/graphics/micron/render/refinement/get_geometry_patch_cut.js +0 -133
  106. package/src/engine/graphics/micron/render/refinement/is_patch_facing_back.js +0 -43
  107. package/src/engine/graphics/micron/render/refinement/is_patch_visible.js +0 -37
  108. package/src/engine/graphics/micron/render/v1/MaterialContext.js +0 -150
  109. package/src/engine/graphics/micron/render/v1/MaterialVertexSpec.js +0 -115
  110. package/src/engine/graphics/micron/render/v1/MicronRenderContext.js +0 -145
  111. package/src/engine/graphics/micron/render/v1/ThreeVirtualGeometryAdapter.js +0 -255
  112. package/src/engine/graphics/micron/render/v1/VGThreeRenderer.js +0 -142
  113. package/src/engine/graphics/micron/render/v1/getTransformedPositionsCached.js +0 -54
  114. package/src/engine/graphics/micron/simplifyGeometry.js +0 -26
  115. package/src/engine/graphics/micron/util/patchToBufferGeometry.js +0 -19
  116. /package/src/{engine/graphics/render/forward_plus/data → core/math}/NumericType.js +0 -0
  117. /package/src/engine/graphics/{render/forward_plus/data → texture}/channelCountToThreIntegerTextureType.js +0 -0
@@ -1,911 +0,0 @@
1
- import {
2
- AmbientLight,
3
- BoxBufferGeometry,
4
- CubeTextureLoader,
5
- DirectionalLight,
6
- FrontSide,
7
- Matrix4,
8
- Mesh,
9
- MeshBasicMaterial,
10
- MeshStandardMaterial,
11
- OctahedronBufferGeometry,
12
- PerspectiveCamera,
13
- PlaneBufferGeometry,
14
- PointLight,
15
- RepeatWrapping,
16
- Scene,
17
- SphereBufferGeometry,
18
- SphereGeometry,
19
- sRGBEncoding,
20
- TextureLoader,
21
- Vector2,
22
- Vector3,
23
- VSMShadowMap,
24
- WebGLRenderer
25
- } from "three";
26
- import { OrbitControls } from "three/examples/jsm/controls/OrbitControls.js";
27
- import Stats from "three/examples/jsm/libs/stats.module.js";
28
- import { PLYLoader } from "three/examples/jsm/loaders/PLYLoader.js";
29
- import { VirtualGeometryBuilder } from "./render/VirtualGeometryBuilder.js";
30
- import { VirtualGeometryStats } from "./debug/VirtualGeometryStats.js";
31
- import { MetricCollection } from "../../development/performance/MetricCollection.js";
32
- import { MetricStatistics } from "../../development/performance/MetricStatistics.js";
33
- import { prettyPrint } from "../../../core/NumberFormat.js";
34
- import { VGThreeRenderer } from "./render/v1/VGThreeRenderer.js";
35
- import { GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader.js";
36
- import { convert_three_object_to_micron } from "./convert_three_object_to_micron.js";
37
- import { DRACOLoader } from "three/examples/jsm/loaders/DRACOLoader.js";
38
- import { TextureAttachmentsByMaterialType } from "../../asset/loaders/material/TextureAttachmensByMaterialType.js";
39
- import { distributePointsOnMesh } from "../particles/particular/engine/utils/distrubuteParticlesOnMesh.js";
40
- import { BinaryNode } from "../../../core/bvh2/BinaryNode.js";
41
- import {
42
- queryBinaryNode_SphereIntersections_Data
43
- } from "../../../core/bvh2/traversal/queryBinaryNode_SphereIntersections.js";
44
- import { ensureGeometryBoundingSphere } from "../geometry/buffered/ensureGeometryBoundingSphere.js";
45
- import { StaticMaterialCache } from "../../asset/loaders/material/StaticMaterialCache.js";
46
- import convertSampler2D2Canvas from "../texture/sampler/Sampler2D2Canvas.js";
47
- import { CanvasView } from "../../../view/elements/CanvasView.js";
48
- import { Sampler2D } from "../texture/sampler/Sampler2D.js";
49
- import { sampler2d_scale_down_linear } from "../texture/sampler/sampler2d_scale_down_linear.js";
50
- import { ShadowMapRenderer } from "../shadows/ShadowMapRenderer.js";
51
- import { mat4 } from "gl-matrix";
52
- import { seededRandom } from "../../../core/math/random/seededRandom.js";
53
- import { Color } from "../../../core/color/Color.js";
54
-
55
- document.body.style.margin = 0;
56
-
57
- const background = new TextureLoader().load('data/textures/utility/checkers_white_grey_256x256.png');
58
- background.repeat.set(50, 30);
59
- background.wrapS = RepeatWrapping;
60
- background.wrapT = RepeatWrapping;
61
-
62
- const metrics = new MetricCollection();
63
- const METRIC_BUFFER_SIZE = 1000;
64
- metrics.create({
65
- name: 'vg_build', buffer_size: METRIC_BUFFER_SIZE
66
- });
67
- metrics.create({
68
- name: 'adapter_update', buffer_size: METRIC_BUFFER_SIZE
69
- });
70
-
71
- metrics.create({
72
- name: 'debug_v0', buffer_size: METRIC_BUFFER_SIZE
73
- });
74
-
75
- let container, stats;
76
-
77
- let camera, scene, renderer;
78
- let directionalLight;
79
- let pointLight;
80
-
81
- let mouseX = 0, mouseY = 0;
82
-
83
- let windowHalfX = window.innerWidth / 2;
84
- let windowHalfY = window.innerHeight / 2;
85
-
86
- const vg_builder = new VirtualGeometryBuilder();
87
-
88
- window.vg_builder = vg_builder;
89
-
90
- const vgtr = new VGThreeRenderer();
91
- window.vgtr = vgtr;
92
-
93
- const shadowmapRenderer = new ShadowMapRenderer();
94
-
95
- function build_stats() {
96
-
97
- const stats = new VirtualGeometryStats(vgtr.geometry);
98
- stats.css({
99
- position: 'fixed',
100
- right: '10px',
101
- top: '10px',
102
- background: 'rgba(255,255,255,0.75)',
103
- padding: '4px',
104
- whiteSpace: 'pre',
105
- userSelect: 'all',
106
- borderRadius: '8px',
107
- boxShadow: '0 0 4px rgba(0,0,0,0.5)'
108
- });
109
-
110
- document.body.appendChild(stats.el);
111
- stats.link();
112
- }
113
-
114
-
115
- function debug_shadow_map() {
116
- const map = directionalLight.shadow.map;
117
-
118
- const sampler = Sampler2D.uint8(4, map.width, map.height);
119
- renderer.readRenderTargetPixels(map, 0, 0, map.width, map.height, sampler.data);
120
-
121
- const cv = new CanvasView();
122
- cv.css({
123
- position: 'fixed',
124
- right: '10px',
125
- top: '10px',
126
- zIndex: 5
127
- });
128
-
129
-
130
- for (let i = 0; i < sampler.width * sampler.height; i++) {
131
- sampler.data[i * 4 + 3] = 255;
132
- }
133
-
134
- const resampled = Sampler2D.uint8(4, 512, 512);
135
-
136
- sampler2d_scale_down_linear(sampler, resampled);
137
-
138
- convertSampler2D2Canvas(resampled, 1, 0, cv.el);
139
-
140
- document.body.appendChild(cv.el);
141
- cv.link();
142
-
143
- }
144
-
145
- window.debug_shadow_map = debug_shadow_map;
146
-
147
- init();
148
-
149
-
150
- const orbitControls = new OrbitControls(camera, container);
151
-
152
-
153
- animate();
154
-
155
- async function micron_add_object(object, random_color = false) {
156
- object.traverse(t => {
157
- t.castShadow = true;
158
- t.receiveShadow = true;
159
-
160
- t.matrixAutoUpdate = false;
161
-
162
- const material = t.material;
163
-
164
- if (t.isMesh && material !== null) {
165
-
166
- const attachments = TextureAttachmentsByMaterialType[material.type];
167
-
168
- if (attachments !== undefined) {
169
-
170
- const n = attachments.length;
171
-
172
- for (let i = 0; i < n; i++) {
173
- const a = attachments[i];
174
- const texture = a.read(material);
175
-
176
- if (texture !== undefined && texture !== null) {
177
- texture.anisotropy = 8;
178
- }
179
- }
180
-
181
- }
182
-
183
- }
184
- });
185
-
186
- if (random_color) {
187
- const random = seededRandom(7);
188
-
189
- const color = new Color();
190
-
191
- object.traverse(t => {
192
- if (t.isMesh && t.material !== null) {
193
-
194
-
195
- color.setHSV(random(), 1, 1);
196
-
197
- t.material = new MeshStandardMaterial({
198
- color: color.toUint()
199
- });
200
-
201
- }
202
- });
203
- }
204
-
205
-
206
- object.traverse(t => {
207
- if (t.isMesh && t.material !== null) {
208
-
209
- t.material = StaticMaterialCache.Global.acquire(t.material);
210
-
211
- }
212
- });
213
-
214
- object.updateMatrix();
215
-
216
- // console.profile('m');
217
- const r = await convert_three_object_to_micron(object);
218
- // console.profileEnd('m');
219
-
220
- r.traverse(o => {
221
- if (o.isMicronMesh) {
222
- // o.material = cubeMaterial1;
223
- }
224
- })
225
-
226
- scene.add(r);
227
-
228
- vgtr.attach(r);
229
-
230
- return r;
231
- }
232
-
233
- function init() {
234
-
235
- container = document.createElement("div");
236
- document.body.appendChild(container);
237
-
238
- camera = new PerspectiveCamera(45, window.innerWidth / window.innerHeight, 1, 1000000);
239
- camera.position.z = -4000;
240
-
241
- //
242
-
243
-
244
- scene = new Scene();
245
-
246
- window.scene = scene;
247
-
248
- // LIGHTS
249
-
250
- const ambient = new AmbientLight(0xffffff, 0.1);
251
- scene.add(ambient);
252
-
253
- pointLight = new PointLight(0x6666ff, 0.5);
254
- pointLight.position.y = 1000;
255
- scene.add(pointLight);
256
-
257
- // light representation
258
-
259
- const sphere = new SphereGeometry(100, 16, 8);
260
-
261
- const mesh = new Mesh(sphere, new MeshBasicMaterial({ color: 0xffffff }));
262
- mesh.scale.set(0.5, 0.5, 0.5);
263
- pointLight.add(mesh);
264
-
265
- // add directional light
266
- directionalLight = new DirectionalLight(0xFFAAAA, 0.8);
267
- directionalLight.position.set(-500, 1000, 300);
268
- directionalLight.castShadow = true;
269
- const shadow_camera = directionalLight.shadow.camera;
270
- // small bias to prevent shadow acne
271
- directionalLight.shadow.bias = -0.0001;
272
- // directionalLight.shadow.mapSize.set(4096, 4096);
273
- directionalLight.shadow.mapSize.set(1024, 1024);
274
- directionalLight.shadow.autoUpdate = false;
275
-
276
- window.light = directionalLight;
277
- // directionalLight.shadow.autoUpdate = true;
278
-
279
- shadow_camera.near = 0.1;
280
- shadow_camera.far = 2000;
281
-
282
- const shadow_camera_size = 15;
283
-
284
- shadow_camera.left = -shadow_camera_size / 2;
285
- shadow_camera.right = shadow_camera_size / 2;
286
-
287
- shadow_camera.bottom = -shadow_camera_size / 2;
288
- shadow_camera.top = shadow_camera_size / 2;
289
-
290
- // shadow_camera.onBeforeRender = do_vgrt_update;
291
-
292
- // scene.add(new CameraHelper(shadow_camera));
293
- // scene.add(new DirectionalLightHelper(directionalLight));
294
-
295
- shadow_camera.updateProjectionMatrix();
296
-
297
-
298
- scene.add(directionalLight);
299
-
300
- // material samples
301
-
302
- const cubeMaterial1 = new MeshStandardMaterial({
303
- wireframe: false,
304
- side: FrontSide,
305
- color: 0xffffff
306
- // color: 0x000000
307
- });
308
-
309
- //
310
-
311
- renderer = new WebGLRenderer({
312
- antialias: true,
313
- preserveDrawingBuffer: true,
314
- stencil: false
315
- });
316
-
317
- renderer.shadowMap.enabled = true;
318
- renderer.shadowMap.type = VSMShadowMap;
319
- // renderer.shadowMap.type = BasicShadowMap;
320
- renderer.sortObjects = false;
321
-
322
- renderer.setPixelRatio(window.devicePixelRatio);
323
- renderer.setSize(window.innerWidth, window.innerHeight);
324
- container.appendChild(renderer.domElement);
325
-
326
- stats = new Stats();
327
- container.appendChild(stats.dom);
328
-
329
- vgtr.__gl_context = renderer.getContext();
330
- // vgtr.scene = scene
331
- vgtr.on.contextAdded.add(ctx => {
332
- scene.add(ctx.mesh);
333
- })
334
-
335
- build_stats();
336
-
337
- function sample_square() {
338
- const geometry = new PlaneBufferGeometry(1, 1, 100, 100);
339
-
340
- const m = new Matrix4();
341
-
342
- m.makeRotationX(Math.PI);
343
-
344
- geometry.applyMatrix4(m);
345
-
346
- createScene(geometry, cubeMaterial1, 1000);
347
- }
348
-
349
- function sample_sphere() {
350
- const geometry = new SphereBufferGeometry(0.5, 200, 200);
351
-
352
-
353
- createScene(geometry, cubeMaterial1, 1000);
354
- }
355
-
356
- function sample_box() {
357
- const geometry = new BoxBufferGeometry(1, 1, 1, 100, 100, 100);
358
-
359
-
360
- createScene(geometry, cubeMaterial1, 1000);
361
- }
362
-
363
- function sample_tetrahedron() {
364
- const geometry = new OctahedronBufferGeometry(0.5, 5);
365
-
366
-
367
- createScene(geometry, cubeMaterial1, 1000);
368
- }
369
-
370
- function sample_lucy() {
371
- const loader = new PLYLoader();
372
- loader.load("data/models/stanford/Lucy100k.ply", function (geometry) {
373
-
374
- createScene(geometry, cubeMaterial1, 1.5);
375
-
376
- });
377
- }
378
-
379
- function sample_isiflow_floor() {
380
- const loader = new PLYLoader();
381
- loader.load("moicon/isiflow_Oct_15_21/0/floor_01.ply", function (geometry) {
382
-
383
- createScene(geometry, cubeMaterial1, 1.5);
384
-
385
- });
386
- }
387
-
388
- function sample_lucy_28m() {
389
- const loader = new PLYLoader();
390
- loader.load("data/models/stanford/lucy.ply", function (geometry) {
391
-
392
- createScene(geometry, cubeMaterial1, 1.5);
393
-
394
- });
395
- }
396
-
397
- function sample_bunny() {
398
- const loader = new PLYLoader();
399
- loader.load("data/models/stanford/bun_zipper_res2.ply", function (geometry) {
400
-
401
- createScene(geometry, cubeMaterial1, 7000);
402
-
403
- });
404
- }
405
-
406
- function sample_dragon() {
407
- const loader = new PLYLoader();
408
- loader.load("data/models/stanford/dragon_recon/dragon_vrip.ply", function (geometry) {
409
-
410
- createScene(geometry, cubeMaterial1, 7000);
411
-
412
- });
413
- }
414
-
415
- function sample_sponza() {
416
- const loader = new PLYLoader();
417
- loader.load("data/models/sponza-pbr/ply/sponza.ply", function (geometry) {
418
-
419
- createScene(geometry, cubeMaterial1, 10);
420
-
421
- });
422
- }
423
-
424
- const loader = new GLTFLoader();
425
- const dracoLoader = new DRACOLoader();
426
-
427
- let pathname = window.location.pathname;
428
- if (pathname.length > 0 && pathname.endsWith('/')) {
429
- pathname = pathname.slice(0, -1);
430
- }
431
- dracoLoader.setDecoderPath(`${pathname}/libs/draco/`);
432
- dracoLoader.setWorkerLimit(2);
433
- loader.setDRACOLoader(dracoLoader);
434
-
435
- function gltf_sample(path) {
436
-
437
-
438
- return new Promise((resolve, reject) => {
439
- loader.load(path, async (gltf) => {
440
- const object = gltf.scene;
441
- object.traverse(t => {
442
- t.castShadow = true;
443
- t.receiveShadow = true;
444
- })
445
-
446
- const r = await micron_add_object(object, false);
447
- // scene.add(object);
448
-
449
-
450
- // update shadowmap
451
- // directionalLight.shadow.needsUpdate = true;
452
-
453
- resolve(r);
454
- });
455
- });
456
- }
457
-
458
- async function gltf_grid(path, x_count = 5, y_count = 5) {
459
- const grid_size = 20;
460
- for (let i = 0; i < y_count; i++) {
461
- for (let j = 0; j < x_count; j++) {
462
- const o = await gltf_sample(path);
463
-
464
- o.position.set(
465
- (i - y_count / 2) * grid_size,
466
- 0,
467
- (j - x_count / 2) * grid_size
468
- );
469
-
470
- o.traverse(x => {
471
- x.updateMatrix();
472
- x.updateWorldMatrix(false, true);
473
- });
474
- }
475
- }
476
- }
477
-
478
- function sample_gltf_sponza() {
479
- gltf_sample('data/models/sponza-pbr/gltf/sponza.glb');
480
- }
481
-
482
- function sample_gltf_hapro_1() {
483
- gltf_sample('data/models/moicon/05-ground-floor/model.gltf');
484
- }
485
-
486
- function sample_gltf_hapro_2() {
487
- gltf_sample('data/models/moicon/08-clickable-assets/model.gltf');
488
- }
489
-
490
- function sample_gltf_rts_factory() {
491
- gltf_sample('data/models/RTS_Buildings_Humans/18/Building_R_18_out/Building_R_18.gltf');
492
- }
493
-
494
- function sample_gltf_broken_isiflow() {
495
- gltf_sample('data/models/moicon/isiflow_Oct_15_21/2/model.gltf');
496
- }
497
-
498
- // sample_gltf_sponza();
499
- // gltf_sample('data/models/RTS_Buildings_Humans/18/Building_R_18_out/Building_R_18.gltf');
500
- // sample_dragon();
501
- // sample_gltf_hapro_2();
502
- // sample_gltf_hapro_1();
503
- // sample_gltf_broken_isiflow();
504
- // gltf_grid('data/models/RTS_Buildings_Humans/18/Building_R_18_out/Building_R_18.gltf');
505
- // gltf_sample('moicon/08-clickable-assets/model.gltf');
506
- // gltf_sample('moicon/05-ground-floor/model.gltf');
507
- // gltf_sample('moicon/29_Dec_2021_Nammo/1/model.gltf');
508
- // gltf_sample('moicon/29_Dec_2021_Nammo/1-onematerial/model.gltf');
509
- // gltf_sample('moicon/29_Dec_2021_Nammo/2/model.gltf');
510
- // gltf_sample('moicon/03_Jan_22_Demo/1-ground_floor/model.gltf');
511
- // gltf_sample('moicon/03_Jan_22_Demo/2-1st_floor/model.gltf');
512
- // gltf_sample('moicon/03_Jan_22_Demo/3-area_ground_floor/model.gltf');
513
- // gltf_sample('moicon/03_Jan_22_Demo/4-area_1st_floor/model.gltf');
514
- // gltf_sample('moicon/03_Jan_22_Demo/8-assets/model.gltf');
515
- // gltf_sample('moicon/03_Jan_22_Demo/worker_test/model.gltf');
516
- // gltf_sample('moicon/A4/A4/model.gltf');
517
- // gltf_sample('moicon/06_04_hapro/08-clickable-assets-new/model.gltf');
518
- // gltf_grid('moicon/ztest_object_many_pieces/model.gltf', 3, 3);
519
- // gltf_sample('moicon/ztest_object_many_pieces/model.gltf');
520
- // gltf_sample('moicon/62cf22227f7b8f0012ca5988/model.gltf');
521
- // gltf_sample('moicon/gnutti_not_optimized/model.gltf');
522
- // gltf_grid('data/models/moicon/Kople/EVCharger1.gltf');
523
- // gltf_sample('data/models/moicon/Kople/EVCharger1.gltf');
524
- // gltf_sample('data/models/moicon/isiflow_Oct_15_21/0/model.gltf');
525
- sample_lucy();
526
- // sample_square();
527
- // sample_isiflow_floor();
528
-
529
- document.addEventListener("mousemove", onDocumentMouseMove);
530
-
531
- //
532
-
533
- window.addEventListener("resize", onWindowResize);
534
-
535
- // envmap
536
- const genCubeUrls = function (prefix, postfix) {
537
-
538
- return [
539
- prefix + "posx" + postfix, prefix + "negx" + postfix,
540
- prefix + "posy" + postfix, prefix + "negy" + postfix,
541
- prefix + "posz" + postfix, prefix + "negz" + postfix
542
- ];
543
-
544
- };
545
-
546
- const urls = genCubeUrls("data/textures/cubemaps/hip_miramar/32/", ".png");
547
-
548
- new CubeTextureLoader().load(urls, function (cubeTexture) {
549
-
550
- cubeTexture.encoding = sRGBEncoding;
551
-
552
- // scene.background = new Color(0.1, 0.1, 0.1);
553
- // scene.background = new ThreeColor(1, 0.3, 0.3);
554
- // scene.background = new Color(0.3, 1, 0.3);
555
-
556
- scene.background = background;
557
- scene.environment = cubeTexture;
558
-
559
-
560
- // const lightProbe = new LightProbe();
561
- //
562
- // lightProbe.copy(LightProbeGenerator.fromCubeTexture(cubeTexture));
563
- // lightProbe.intensity = 1.2;
564
-
565
- // scene.add(lightProbe);
566
- });
567
-
568
- onWindowResize();
569
- }
570
-
571
- function onWindowResize() {
572
-
573
- const w = window.innerWidth;
574
- const h = window.innerHeight;
575
-
576
- windowHalfX = w / 2;
577
- windowHalfY = h / 2;
578
-
579
- camera.aspect = w / h;
580
- camera.updateProjectionMatrix();
581
-
582
- renderer.setSize(w, h);
583
-
584
- background.repeat.set(w / 20, h / 20);
585
- }
586
-
587
-
588
- /**
589
- *
590
- * @param {THREE.BufferGeometry} geometry
591
- * @param {THREE.Material} m1
592
- * @param {number} scale
593
- */
594
- function createScene(geometry, m1, scale) {
595
-
596
- geometry.computeVertexNormals();
597
-
598
-
599
- const grid_size = 100;
600
- const grid_spacing = 2000;
601
-
602
- for (let i = 0; i < grid_size; i++) {
603
- for (let j = 0; j < grid_size; j++) {
604
-
605
- const mesh = new Mesh(geometry, m1);
606
-
607
- mesh.scale.setScalar(scale);
608
-
609
- mesh.position.x = grid_spacing * (i - grid_size / 2);
610
- mesh.position.z = grid_spacing * (j - grid_size / 2);
611
-
612
- mesh.frustumCulled = false;
613
-
614
- micron_add_object(mesh);
615
- // scene.add(mesh);
616
- }
617
- }
618
-
619
- }
620
-
621
- function createMeshOfMeshes(geometry, material, size = 1000) {
622
- ensureGeometryBoundingSphere(geometry);
623
- const scale = size / geometry.boundingSphere.radius;
624
-
625
- const shape = new Mesh(geometry, material);
626
- shape.scale.setScalar(scale);
627
-
628
- meshOfMeshes({
629
- shape: shape,
630
- count: 50000,
631
- particle: geometry,
632
- particle_scale: scale / 30,
633
- material: material
634
- });
635
- }
636
-
637
- /**
638
- *
639
- * @param {Mesh} shape
640
- * @param {number} count
641
- * @param {THREE.BufferGeometry} particle
642
- * @param {THREE.Material} material
643
- * @param {number} [particle_scale]
644
- * @param {number} [crowding]
645
- */
646
- function meshOfMeshes({ shape, count, particle, material, particle_scale = 1, crowding = 1 }) {
647
-
648
- ensureGeometryBoundingSphere(particle);
649
-
650
- const shape_geometry = shape.geometry;
651
-
652
- const normal_attribute = shape_geometry.getAttribute('normal');
653
- const normal_array = normal_attribute.array;
654
-
655
- const bvh = new BinaryNode();
656
- bvh.setNegativelyInfiniteBounds();
657
-
658
- const scratch_array = [];
659
-
660
- const particle_bounds_radius = particle.boundingSphere.radius * particle_scale;
661
-
662
- function place(
663
- x, y, z,
664
- i,
665
- triangle_index, t, r,
666
- a, b, c
667
- ) {
668
-
669
- if (queryBinaryNode_SphereIntersections_Data(scratch_array, 0, bvh, x, y, z, particle_bounds_radius) > 0) {
670
- return;
671
- }
672
-
673
- let mesh = new Mesh(particle, material);
674
-
675
- //read triangle points
676
- const a3 = a * 3;
677
-
678
- const ax = normal_array[a3];
679
- const ay = normal_array[a3 + 1];
680
- const az = normal_array[a3 + 2];
681
-
682
- const b3 = b * 3;
683
-
684
- const bx = normal_array[b3];
685
- const by = normal_array[b3 + 1];
686
- const bz = normal_array[b3 + 2];
687
-
688
- const c3 = c * 3;
689
-
690
- const cx = normal_array[c3];
691
- const cy = normal_array[c3 + 1];
692
- const cz = normal_array[c3 + 2];
693
-
694
- // method from here: https://math.stackexchange.com/questions/538458/triangle-point-picking-in-3d
695
- const cax = cx - ax;
696
- const cay = cy - ay;
697
- const caz = cz - az;
698
-
699
- const bax = bx - ax;
700
- const bay = by - ay;
701
- const baz = bz - az;
702
-
703
- const n_x = ax + t * bax + r * cax;
704
- const n_y = ay + t * bay + r * cay;
705
- const n_z = az + t * baz + r * caz;
706
-
707
- mesh.lookAt(n_x, n_y, n_z);
708
-
709
- mesh.scale.x = mesh.scale.y = mesh.scale.z = particle_scale;
710
-
711
- mesh.position.x = x;
712
- mesh.position.y = y;
713
- mesh.position.z = z;
714
-
715
- micron_add_object(mesh);
716
-
717
- bvh.insert(x - particle_bounds_radius, y - particle_bounds_radius, z - particle_bounds_radius, x + particle_bounds_radius, y + particle_bounds_radius, z + particle_bounds_radius, i);
718
- }
719
-
720
- shape.updateMatrix();
721
- shape.updateMatrixWorld();
722
-
723
- distributePointsOnMesh(count, shape, shape.matrixWorld, 0, place);
724
- }
725
-
726
- function onDocumentMouseMove(event) {
727
-
728
- mouseX = (event.clientX - windowHalfX) * 4;
729
- mouseY = (event.clientY - windowHalfY) * 4;
730
-
731
- }
732
-
733
- //
734
-
735
- function animate() {
736
-
737
- requestAnimationFrame(animate);
738
-
739
- render();
740
- stats.update();
741
-
742
- }
743
-
744
-
745
- function print_perf_stats() {
746
-
747
- const values = [];
748
-
749
- const stats = new MetricStatistics();
750
- metrics.list().forEach(m => {
751
- const metric = metrics.get(m);
752
-
753
- metric.computeStats(stats);
754
-
755
- values.push(`${m}: ${prettyPrint(stats.mean)}`);
756
- });
757
-
758
- console.log(values.join(", "));
759
-
760
- metrics.clear();
761
- }
762
-
763
- setInterval(print_perf_stats, 2000);
764
-
765
- // scene.onBeforeRender = do_vgrt_update;
766
-
767
- /**
768
- *
769
- * @param {WebGLRenderer} renderer
770
- * @param {Scene} scene
771
- * @param {Camera} camera
772
- */
773
- function do_vgrt_update(renderer, scene, camera) {
774
- if (!camera.isPerspectiveCamera) {
775
- debugger;
776
- }
777
- const t0 = performance.now();
778
- vgtr.update(renderer, camera);
779
- const t1 = performance.now();
780
- vgtr.render();
781
-
782
- const t2 = performance.now();
783
- metrics.get("vg_build").record(t1 - t0);
784
- metrics.get("adapter_update").record(t2 - t1);
785
- }
786
-
787
- shadowmapRenderer.onBeforeRender.add((renderer, camera, scene) => {
788
- vgtr.update(renderer, camera);
789
- vgtr.render();
790
- });
791
-
792
-
793
- function render() {
794
- if (orbitControls !== undefined) {
795
- orbitControls.update();
796
- }
797
- // micron_vis_mesh.traverse(v => {
798
- // if (v.isMesh) {
799
- // v.geometry.dispose();
800
- // }
801
- // });
802
- // micron_vis_mesh.children.splice(0, micron_vis_mesh.children.length);
803
-
804
- const timer = -0.0002 * Date.now();
805
- // const timer = 3;
806
-
807
- pointLight.position.x = 10000 * Math.cos(timer);
808
- pointLight.position.z = 10000 * Math.sin(timer);
809
-
810
- // const resolution = new Vector2();
811
- // renderer.getSize(resolution);
812
- //
813
- // const pixelRatio = renderer.getPixelRatio();
814
- // vg_builder.resolution.set(resolution.x * pixelRatio, resolution.y * pixelRatio);
815
- // vg_builder.setMatricesFromCamera(camera);
816
- // vg_builder.setOutput(vg_instance);
817
-
818
- // vg_builder.build();
819
-
820
- // const active_patches = vg_instance.patches.slice(0, vg_instance.patch_count);
821
-
822
- // micron_vis_mesh.add(buildPatchMesh(active_patches.map(x => x.patch)));
823
- //
824
- // scene.traverse(o => {
825
- // if (o['@micron'] === true) {
826
- // o.update();
827
- // }
828
- // });
829
-
830
- // do_vgrt_update(renderer,scene,camera);
831
- const light = directionalLight;
832
- const shadow = light.shadow;
833
-
834
- // shadow.needsUpdate = true;
835
- // shadowmapRenderer.update(renderer, shadow, scene, camera, light);
836
-
837
- do_vgrt_update(renderer, scene, camera);
838
-
839
- renderer.render(scene, camera);
840
-
841
-
842
- //
843
- // const polycount = active_patches.reduce((v, x) => v + x.patch.polygon_count, 0);
844
-
845
- // console.log(`patches:${active_patches.length}, polycount:${polycount}`);
846
- }
847
-
848
- const raycast_handler = ({ clientX, clientY }) => {
849
- const direction = new Vector3();
850
-
851
- const viewport_size = new Vector2();
852
-
853
- renderer.getSize(viewport_size);
854
-
855
- const v2_nx = (clientX / viewport_size.x) * 2 - 1;
856
- const v2_ny = -(clientY / viewport_size.y) * 2 + 1;
857
-
858
- direction.set(v2_nx, v2_ny, 0.5);
859
-
860
- direction.unproject(camera);
861
-
862
- direction.sub(camera.position);
863
-
864
- direction.normalize();
865
-
866
- const origin_x = camera.position.x;
867
- const origin_y = camera.position.y;
868
- const origin_z = camera.position.z;
869
-
870
- const direction_x = direction.x;
871
- const direction_y = direction.y;
872
- const direction_z = direction.z;
873
-
874
- const hits = [];
875
- scene.traverse(o => {
876
- if (o.isMicronMesh) {
877
- /**
878
- * @type {MicronGeometry}
879
- */
880
- const micron_geo = o.geometry;
881
-
882
- const scratch_m4 = new Float32Array(16);
883
-
884
- // get transform in local space
885
- mat4.invert(scratch_m4, o.matrixWorld);
886
-
887
- // transform ray to local space
888
- const local_origin_x = scratch_m4[0] * origin_x + scratch_m4[4] * origin_y + scratch_m4[8] * origin_z + scratch_m4[12];
889
- const local_origin_y = scratch_m4[1] * origin_x + scratch_m4[5] * origin_y + scratch_m4[9] * origin_z + scratch_m4[13];
890
- const local_origin_z = scratch_m4[2] * origin_x + scratch_m4[6] * origin_y + scratch_m4[10] * origin_z + scratch_m4[14];
891
-
892
- const local_direction_x = scratch_m4[0] * direction_x + scratch_m4[4] * direction_y + scratch_m4[8] * direction_z;
893
- const local_direction_y = scratch_m4[1] * direction_x + scratch_m4[5] * direction_y + scratch_m4[9] * direction_z;
894
- const local_direction_z = scratch_m4[2] * direction_x + scratch_m4[6] * direction_y + scratch_m4[10] * direction_z;
895
- // NOTE: direction is not normalized
896
-
897
- const point = micron_geo.raycast(local_origin_x, local_origin_y, local_origin_z, local_direction_x, local_direction_y, local_direction_z);
898
-
899
- Array.prototype.push.apply(hits, point.map(p => {
900
- return { position: p.position.toJSON(), geometry: micron_geo.id, instance: o.id };
901
- }));
902
- }
903
- });
904
-
905
- if (hits.length > 0) {
906
- console.log(`HITS: ${hits.map(JSON.stringify).join(',')}`);
907
- }
908
- };
909
-
910
- // window.document.body.addEventListener(MouseEvents.Move, raycast_handler);
911
-