@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.
Files changed (94) hide show
  1. package/package.json +1 -1
  2. package/src/engine/graphics/micron/MICRON_GEOMETRY_FIELD.js +0 -1
  3. package/src/engine/graphics/micron/MICRON_URI_FIELD.js +0 -1
  4. package/src/engine/graphics/micron/build/MICRON_PATCH_SIZE_MAX.js +0 -5
  5. package/src/engine/graphics/micron/build/PatchRepresentation.js +0 -424
  6. package/src/engine/graphics/micron/build/buildMicronGeometryFromBufferGeometry.js +0 -311
  7. package/src/engine/graphics/micron/build/build_geometry_info.js +0 -21
  8. package/src/engine/graphics/micron/build/clustering/assignInitialPatchNeighbours.js +0 -63
  9. package/src/engine/graphics/micron/build/clustering/assign_patch_neighbours_from_topology.js +0 -46
  10. package/src/engine/graphics/micron/build/clustering/build_clustering_2.js +0 -37
  11. package/src/engine/graphics/micron/build/clustering/build_leaf_patches.js +0 -326
  12. package/src/engine/graphics/micron/build/clustering/build_leaf_patches_metis.js +0 -76
  13. package/src/engine/graphics/micron/build/clustering/computeBorderLengthChange.js +0 -59
  14. package/src/engine/graphics/micron/build/clustering/computeFaceCurvatureScore.js +0 -57
  15. package/src/engine/graphics/micron/build/clustering/computeOpenFaceFreedom.js +0 -35
  16. package/src/engine/graphics/micron/build/clustering/compute_face_connection_weight.js +0 -35
  17. package/src/engine/graphics/micron/build/clustering/populateOpenFaceNeighboursForPatch.js +0 -56
  18. package/src/engine/graphics/micron/build/clustering/validate_leaf_patch_connectivity.js +0 -44
  19. package/src/engine/graphics/micron/build/compute_micron_buffer_array_constructor.js +0 -24
  20. package/src/engine/graphics/micron/build/compute_vertex_remap_cost.js +0 -29
  21. package/src/engine/graphics/micron/build/debug/build_clustering_info.js +0 -58
  22. package/src/engine/graphics/micron/build/debug/build_graph_info.js +0 -59
  23. package/src/engine/graphics/micron/build/fill_patch_geometry_data.js +0 -270
  24. package/src/engine/graphics/micron/build/hierarchy/buildAbstractPatchHierarchy.js +0 -196
  25. package/src/engine/graphics/micron/build/hierarchy/build_intermediate_patch_topology.js +0 -162
  26. package/src/engine/graphics/micron/build/hierarchy/build_merge_graph.js +0 -89
  27. package/src/engine/graphics/micron/build/hierarchy/computePatchMergeScore.js +0 -146
  28. package/src/engine/graphics/micron/build/hierarchy/compute_patches_shared_vertex_count.js +0 -32
  29. package/src/engine/graphics/micron/build/hierarchy/compute_patches_shared_vertices.js +0 -34
  30. package/src/engine/graphics/micron/build/hierarchy/merge_patches.js +0 -581
  31. package/src/engine/graphics/micron/build/hierarchy/metis_cluster_clusters.js +0 -53
  32. package/src/engine/graphics/micron/build/hierarchy/optimize_graph_partitioning_balance.js +0 -515
  33. package/src/engine/graphics/micron/build/hierarchy/patch_combine.js +0 -180
  34. package/src/engine/graphics/micron/build/hierarchy/patch_fill_holes_by_uncollapse.js +0 -60
  35. package/src/engine/graphics/micron/build/hierarchy/patch_stitch_parent_border.js +0 -320
  36. package/src/engine/graphics/micron/build/hierarchy/qvdr_build_simplified_clusters.js +0 -547
  37. package/src/engine/graphics/micron/build/hierarchy/qvdr_build_tree.js +0 -140
  38. package/src/engine/graphics/micron/buildPatchwork.js +0 -68
  39. package/src/engine/graphics/micron/convert_three_object_to_micron.js +0 -179
  40. package/src/engine/graphics/micron/debug/VirtualGeometryStats.js +0 -42
  41. package/src/engine/graphics/micron/format/MICRON_GEOMETRY_PROPERTY_NAME.js +0 -1
  42. package/src/engine/graphics/micron/format/MicronGeometry.d.ts +0 -21
  43. package/src/engine/graphics/micron/format/MicronGeometry.js +0 -334
  44. package/src/engine/graphics/micron/format/MicronGeometryPatch.d.ts +0 -3
  45. package/src/engine/graphics/micron/format/MicronGeometryPatch.js +0 -205
  46. package/src/engine/graphics/micron/format/MicronGeometryPatchOccurance.js +0 -50
  47. package/src/engine/graphics/micron/format/ThreeMicronMesh.d.ts +0 -10
  48. package/src/engine/graphics/micron/format/ThreeMicronMesh.js +0 -45
  49. package/src/engine/graphics/micron/format/VirtualGeometry.js +0 -158
  50. package/src/engine/graphics/micron/format/micron_build_proxy_geometry.js +0 -205
  51. package/src/engine/graphics/micron/format/serialization/MicronGeometryBinarySerializationAdapter.js +0 -123
  52. package/src/engine/graphics/micron/format/serialization/MicronGeometryBinarySerializationAdapter.spec.js +0 -63
  53. package/src/engine/graphics/micron/format/serialization/collection/geometry_collection_serialization.js +0 -83
  54. package/src/engine/graphics/micron/format/serialization/collection/geometry_collection_serialization.spec.js +0 -51
  55. package/src/engine/graphics/micron/format/serialization/deserialize_attribute_spec.js +0 -25
  56. package/src/engine/graphics/micron/format/serialization/deserialize_patch.js +0 -106
  57. package/src/engine/graphics/micron/format/serialization/serialize_attribute_spec.js +0 -18
  58. package/src/engine/graphics/micron/format/serialization/serialize_patch.js +0 -84
  59. package/src/engine/graphics/micron/format/validate_patch_bounds.js +0 -69
  60. package/src/engine/graphics/micron/plugin/GLTFAssetTransformer.js +0 -265
  61. package/src/engine/graphics/micron/plugin/GLTF_MICRON_ID_FIELD.js +0 -5
  62. package/src/engine/graphics/micron/plugin/MicronRenderPlugin.d.ts +0 -8
  63. package/src/engine/graphics/micron/plugin/MicronRenderPlugin.js +0 -150
  64. package/src/engine/graphics/micron/plugin/serialization/BufferGeometrySerializationAdapter.js +0 -176
  65. package/src/engine/graphics/micron/plugin/shaded_geometry/MicronShadedGeometryRenderAdapter.js +0 -216
  66. package/src/engine/graphics/micron/prototypeMicronProxyBuild.js +0 -227
  67. package/src/engine/graphics/micron/prototypeVirtualGeometry.js +0 -911
  68. package/src/engine/graphics/micron/render/PatchCacheKey.js +0 -79
  69. package/src/engine/graphics/micron/render/VIRTUAL_MESH_FLAG.d.ts +0 -1
  70. package/src/engine/graphics/micron/render/VIRTUAL_MESH_FLAG.js +0 -1
  71. package/src/engine/graphics/micron/render/VirtualGeometryBuilder.js +0 -207
  72. package/src/engine/graphics/micron/render/approximateTriangleArea.js +0 -25
  73. package/src/engine/graphics/micron/render/culling/PatchCullingSystem.js +0 -129
  74. package/src/engine/graphics/micron/render/instanced/PatchDataTextures.js +0 -329
  75. package/src/engine/graphics/micron/render/instanced/ThreeInstancedAdapter.js +0 -175
  76. package/src/engine/graphics/micron/render/instanced/shader/constants.js +0 -3
  77. package/src/engine/graphics/micron/render/instanced/shader/gen_micron_vertex_attribute_texture_name.js +0 -8
  78. package/src/engine/graphics/micron/render/instanced/shader/shader_rewrite_standard.js +0 -250
  79. package/src/engine/graphics/micron/render/makeThreeMeshFromVirtualGeometry.js +0 -37
  80. package/src/engine/graphics/micron/render/refinement/ActivePatchFlags.js +0 -8
  81. package/src/engine/graphics/micron/render/refinement/ActivePatchList.js +0 -241
  82. package/src/engine/graphics/micron/render/refinement/ActivePatchRecord.js +0 -154
  83. package/src/engine/graphics/micron/render/refinement/RefinementSpec.js +0 -84
  84. package/src/engine/graphics/micron/render/refinement/get_geometry_patch_cut.js +0 -133
  85. package/src/engine/graphics/micron/render/refinement/is_patch_facing_back.js +0 -43
  86. package/src/engine/graphics/micron/render/refinement/is_patch_visible.js +0 -37
  87. package/src/engine/graphics/micron/render/v1/MaterialContext.js +0 -150
  88. package/src/engine/graphics/micron/render/v1/MaterialVertexSpec.js +0 -115
  89. package/src/engine/graphics/micron/render/v1/MicronRenderContext.js +0 -145
  90. package/src/engine/graphics/micron/render/v1/ThreeVirtualGeometryAdapter.js +0 -255
  91. package/src/engine/graphics/micron/render/v1/VGThreeRenderer.js +0 -142
  92. package/src/engine/graphics/micron/render/v1/getTransformedPositionsCached.js +0 -54
  93. package/src/engine/graphics/micron/simplifyGeometry.js +0 -26
  94. package/src/engine/graphics/micron/util/patchToBufferGeometry.js +0 -19
@@ -1,84 +0,0 @@
1
- import Vector2 from "../../../../../core/geom/Vector2.js";
2
- import { mat4 } from "gl-matrix";
3
- import {
4
- frustum_from_projection_matrix_array
5
- } from "../../../../../core/geom/3d/frustum/frustum_from_projection_matrix_array.js";
6
-
7
- export class RefinementSpec {
8
- constructor() {
9
-
10
- /**
11
- * Viewport resolution
12
- * @type {Vector2}
13
- */
14
- this.resolution = new Vector2();
15
-
16
- /**
17
- * Number of pixels in the viewport
18
- * @type {number}
19
- */
20
- this.viewport_area = 0;
21
-
22
- /**
23
- * How much error to accept when deciding to subdivide a cluster
24
- * Measured in pixels
25
- * Higher value will result in better performance but more visible artifacts
26
- * @type {number}
27
- */
28
- this.error_threshold = 1;
29
-
30
- /**
31
- * Error threshold as a fraction of the screen area instead of pixels, derived internally from pixel value
32
- * @type {number}
33
- */
34
- this.error_threshold_normalized = 1;
35
-
36
- /**
37
- * Continuous memory region for faster access
38
- * @type {ArrayBuffer}
39
- */
40
- const array_buffer = new ArrayBuffer(160);
41
-
42
- /**
43
- * Contains transformation from camera space to object space
44
- * @type {Float32Array|number[]|mat4}
45
- */
46
- this.projection_matrix = new Float32Array(array_buffer, 0, 16);
47
-
48
- /**
49
- * Object-space camera frustum
50
- * Frustum planes in compact form
51
- * @type {Float32Array}
52
- */
53
- this.frustum_f32 = new Float32Array(array_buffer, 64, 24);
54
- }
55
-
56
- /**
57
- *
58
- * @param {number} x
59
- * @param {number} y
60
- */
61
- setResolution(x, y) {
62
- this.resolution.set(x, y);
63
-
64
- this.viewport_area = x * y;
65
-
66
- this.error_threshold_normalized = this.error_threshold / this.viewport_area;
67
- }
68
-
69
- /**
70
- *
71
- * @param {number[]|mat4|Float32Array|ArrayLike<number>} transform world-space object transform
72
- * @param {number[]|mat4|Float32Array|ArrayLike<number>} view_projection_matrix camera's view projection matrix (projection* world_inverse)
73
- */
74
- build(transform, view_projection_matrix) {
75
-
76
- // build projection matrix
77
- const projection_matrix = this.projection_matrix;
78
-
79
- mat4.multiply(projection_matrix, view_projection_matrix, transform);
80
-
81
- // compute view frustum in model-space
82
- frustum_from_projection_matrix_array(this.frustum_f32, projection_matrix);
83
- }
84
- }
@@ -1,133 +0,0 @@
1
- import { BitSet } from "../../../../../core/binary/BitSet.js";
2
- import {
3
- aabb3_array_intersects_frustum_array
4
- } from "../../../../../core/geom/3d/aabb/aabb3_array_intersects_frustum_array.js";
5
- import { aabb3_estimate_projected_area2 } from "../../../../../core/geom/3d/aabb/aabb3_estimate_projected_area2.js";
6
- import { SCRATCH_UINT32_TRAVERSAL_STACK } from "../../../../../core/collection/SCRATCH_UINT32_TRAVERSAL_STACK.js";
7
-
8
-
9
- /**
10
- *
11
- * @type {BitSet}
12
- */
13
- const scratch_traversal_bitset = new BitSet();
14
- scratch_traversal_bitset.preventShrink();
15
-
16
- const stack = SCRATCH_UINT32_TRAVERSAL_STACK;
17
-
18
- /**
19
- *
20
- * @param {VirtualGeometry} destination
21
- * @param {RefinementSpec} spec
22
- * @param {MicronGeometry} geometry
23
- * @param instance_id
24
- * @param transform
25
- */
26
- export function get_geometry_patch_cut(
27
- destination,
28
- spec,
29
- geometry,
30
- instance_id,
31
- transform
32
- ) {
33
-
34
- const frustum_planes = spec.frustum_f32;
35
- const projection_matrix = spec.projection_matrix;
36
- const error_threshold = spec.error_threshold_normalized;
37
-
38
- const geometry_id = geometry.id;
39
-
40
- let output_patch_cursor = destination.patch_count;
41
-
42
- let i;
43
-
44
- // initialize stack
45
- const root = geometry.root;
46
-
47
- /**
48
- *
49
- * @type {number}
50
- */
51
- const stack_top = stack.pointer++;
52
-
53
- stack[stack_top] = root.id;
54
-
55
- const included_set = scratch_traversal_bitset;
56
- included_set.reset();
57
-
58
- included_set.set(root.id, true);
59
-
60
- const patches = geometry.patches;
61
- const destination_patches = destination.patches;
62
-
63
- while (stack.pointer > stack_top) {
64
- stack.pointer--;
65
-
66
- const patch_id = stack[stack.pointer];
67
- const patch = patches[patch_id];
68
-
69
- /*
70
- check if node is in view frustum
71
- NOTE: following suggestion in "FastMesh: Efficient View-dependent Meshing" by Renato Pajarola et al, we can do a more coarse frustum test approximating frustum as a cone initially
72
- */
73
- const in_view_frustum = aabb3_array_intersects_frustum_array(patch.bounding_box, frustum_planes);
74
-
75
- if (!in_view_frustum) {
76
- continue;
77
- }
78
-
79
- // check if record needs to be split
80
- if (patch.lod > 0) {
81
-
82
- // not the lowest level of LOD, see if subdivision might be necessary
83
-
84
- // compute average triangle area
85
- // const group_screen_area = aabb3_project_to_2d(patch.group_bounding_box_corners, projection_matrix);
86
- const group_screen_area = aabb3_estimate_projected_area2(patch.group_bounding_box, projection_matrix);
87
- const screen_space_error = patch.group_error * group_screen_area;
88
-
89
- if (screen_space_error > error_threshold) {
90
- // error too large, needs to be split
91
-
92
- const children = patch.children;
93
- const child_count = children.length;
94
-
95
- for (i = 0; i < child_count; i++) {
96
- const child = children[i];
97
-
98
- const child_id = child.id;
99
-
100
- if (included_set.getAndSet(child_id)) {
101
- continue;
102
- }
103
-
104
- stack[stack.pointer++] = child_id;
105
- }
106
-
107
- continue;
108
- }
109
- }
110
-
111
-
112
- const target_address = output_patch_cursor * 3;
113
-
114
- destination_patches[target_address] = instance_id;
115
- destination_patches[target_address + 1] = geometry_id;
116
- destination_patches[target_address + 2] = patch_id;
117
-
118
- output_patch_cursor++;
119
-
120
- }
121
-
122
- // this is to make sure geometry container has enough space
123
- // NOTE: capacity grows after attempted patch writes, so some data will be missing, which means we must re-do the work
124
- if (!destination.ensureCapacity(output_patch_cursor)) {
125
- // redo the work
126
- get_geometry_patch_cut(destination, spec, geometry, instance_id, transform);
127
-
128
- } else {
129
-
130
- destination.patch_count = output_patch_cursor;
131
-
132
- }
133
- }
@@ -1,43 +0,0 @@
1
- import { v3_angle_between } from "../../../../../core/geom/v3_angle_between.js";
2
- import { PI_HALF } from "../../../../../core/math/PI_HALF.js";
3
-
4
- /**
5
- *
6
- * @param {RefinementSpec} refinement_spec
7
- * @param {MicronGeometryPatch} patch
8
- * @returns {boolean}
9
- */
10
- function is_patch_facing_back(refinement_spec, patch) {
11
-
12
- const normal_cone = patch.normal_cone;
13
- const normal_cone_angle = normal_cone.angle;
14
-
15
- // Do normal cone check against view angle
16
- if (normal_cone_angle < PI_HALF) {
17
- // compute view direction
18
- // TODO position might be way off from the surface center, as well as patch might curve a lot more than expected, need to account for that
19
-
20
- const bounds_center_x = patch.bounding_sphere[0];
21
- const bounds_center_y = patch.bounding_sphere[1];
22
- const bounds_center_z = patch.bounding_sphere[2];
23
-
24
- const view_direction_x = refinement_spec.view_position[0] - bounds_center_x;
25
- const view_direction_y = refinement_spec.view_position[1] - bounds_center_y;
26
- const view_direction_z = refinement_spec.view_position[2] - bounds_center_z;
27
-
28
- // compute view angle of the bounding sphere
29
- const normal_cone_direction = normal_cone.direction;
30
-
31
- const angle = v3_angle_between(
32
- view_direction_x, view_direction_y, view_direction_z,
33
- normal_cone_direction.x, normal_cone_direction.y, normal_cone_direction.z
34
- );
35
-
36
- if (angle > normal_cone_angle + PI_HALF) {
37
- return false;
38
- }
39
-
40
- }
41
-
42
- return true;
43
- }
@@ -1,37 +0,0 @@
1
- import AABB2 from "../../../../../core/geom/AABB2.js";
2
- import { aabb3_project_to_2d } from "../../../../../core/geom/3d/aabb/aabb3_compute_projected_area.js";
3
-
4
- const scratch_aabb2 = new AABB2();
5
-
6
- /**
7
- *
8
- * @param {RefinementSpec} refinement_spec
9
- * @param {MicronGeometryPatch} node
10
- * @returns {boolean}
11
- */
12
- function is_patch_visible(refinement_spec, node) {
13
-
14
- // check if node is in view frustum
15
- const bounding_box = node.bounding_box;
16
- const in_view_frustum = bounding_box.intersectFrustum(refinement_spec.frustum);
17
-
18
- if (!in_view_frustum) {
19
- // outside of view frustum, cull
20
- return false;
21
- }
22
-
23
-
24
- // compute projected bounds of the patch
25
- aabb3_project_to_2d(scratch_aabb2, bounding_box, refinement_spec.projection_matrix);
26
-
27
- // Cull by screen area
28
- const normalized_screen_area = scratch_aabb2.computeArea();
29
- const patch_screen_area = normalized_screen_area * refinement_spec.viewport_area;
30
-
31
- if (patch_screen_area < refinement_spec.error_threshold) {
32
- // the whole patch is too small, cull
33
- return false;
34
- }
35
-
36
- return true;
37
- }
@@ -1,150 +0,0 @@
1
- import { ThreeInstancedAdapter } from "../instanced/ThreeInstancedAdapter.js";
2
- import { composeCompile } from "../../../material/composeCompile.js";
3
- import { Material, Mesh, MeshDepthMaterial, MeshNormalMaterial, RGBADepthPacking } from "three";
4
- import { VIRTUAL_MESH_FLAG } from "../VIRTUAL_MESH_FLAG.js";
5
-
6
- const MATERIAL_FLAG = '@micron_instanced_rewritten';
7
- const MATERIAL_VERTEX_DISPLACED = '@meep/vertex-displaced';
8
-
9
- export class MaterialContext {
10
- /**
11
- *
12
- * @param {VertexDataSpec} spec
13
- * @param {Material} material
14
- */
15
- constructor(spec, material) {
16
- /**
17
- *
18
- * @type {ThreeInstancedAdapter}
19
- */
20
- this.adapter = new ThreeInstancedAdapter(spec);
21
-
22
- /**
23
- *
24
- * @type {VertexDataSpec}
25
- * @private
26
- */
27
- this.__vertex_spec = spec;
28
-
29
- /**
30
- *
31
- * @type {Material}
32
- */
33
- this.material = material;
34
-
35
- /**
36
- *
37
- * @type {Material|null}
38
- */
39
- this.compiled_material = null;
40
-
41
- /**
42
- *
43
- * @type {Mesh|null}
44
- */
45
- this.mesh = null;
46
-
47
- /**
48
- *
49
- * @type {Set<number>}
50
- */
51
- this.instances = new Set();
52
-
53
- /**
54
- *
55
- * @type {Uint32Array|number[]}
56
- */
57
- this.__patches = [];
58
-
59
- /**
60
- *
61
- * @type {number}
62
- */
63
- this.__patch_count = 0;
64
- }
65
-
66
- init() {
67
-
68
- const material = this.material.clone();
69
-
70
- const rewrite_material = this.adapter.rewriteMaterial.bind(this.adapter);
71
-
72
- if (this.material[MATERIAL_FLAG] === undefined) {
73
- material.onBeforeCompile = composeCompile(this.material.onBeforeCompile, rewrite_material);
74
- material.needsUpdate = true;
75
-
76
- material[MATERIAL_FLAG] = true;
77
- material[MATERIAL_VERTEX_DISPLACED] = true;
78
- } else {
79
- throw new Error(`Material was already processed by micron, this is an illegal state`);
80
- }
81
-
82
- this.compiled_material = material;
83
-
84
-
85
- const m = new Mesh();
86
-
87
- m[VIRTUAL_MESH_FLAG] = true;
88
-
89
- m.name = 'Materialized Micron Mesh';
90
-
91
- m.geometry = null;
92
- m.material = material;
93
-
94
- m.frustumCulled = false;
95
- m.matrixAutoUpdate = false;
96
-
97
- // cast shadow
98
- m.castShadow = true;
99
- m.receiveShadow = true;
100
-
101
- const customDepthMaterial = new MeshDepthMaterial({
102
- depthPacking: RGBADepthPacking
103
- });
104
-
105
- customDepthMaterial.map = material.map;
106
- customDepthMaterial.alphaTest = material.alphaTest;
107
- customDepthMaterial.onBeforeCompile = rewrite_material;
108
-
109
- m.customDepthMaterial = customDepthMaterial;
110
-
111
- const customNormalMaterial = new MeshNormalMaterial({
112
- depthWrite: true
113
- });
114
-
115
- customNormalMaterial.map = material.map;
116
- customNormalMaterial.normalMap = material.normalMap;
117
- customNormalMaterial.normalScale = material.normalScale;
118
- customNormalMaterial.normalMapType = material.normalMapType;
119
-
120
- customNormalMaterial.alphaTest = material.alphaTest;
121
- customNormalMaterial.onBeforeCompile = rewrite_material;
122
-
123
- m.customNormalMaterial = customNormalMaterial;
124
-
125
-
126
- //
127
- this.adapter.onRebuild.add(() => {
128
- m.geometry = this.adapter.__buffer_geometry;
129
- });
130
-
131
- this.mesh = m;
132
- }
133
-
134
- /**
135
- *
136
- * @param {VirtualGeometry} virtual_geometry
137
- */
138
- build(virtual_geometry) {
139
-
140
- if (this.__patch_count === 0) {
141
- this.mesh.visible = false;
142
- return;
143
- } else {
144
- this.mesh.visible = true;
145
- }
146
-
147
- this.adapter.build(this.__patches, this.__patch_count, virtual_geometry);
148
-
149
- }
150
- }
@@ -1,115 +0,0 @@
1
- export const MaterialVertexSpecFlags = {
2
- CastShadow: 1,
3
- ReceiveShadow: 2
4
- };
5
-
6
- export class MaterialVertexSpec {
7
- constructor() {
8
- /**
9
- *
10
- * @type {VertexDataSpec|null}
11
- */
12
- this.spec = null;
13
- /**
14
- *
15
- * @type {THREE.Material|null}
16
- */
17
- this.material = null;
18
-
19
- /**
20
- *
21
- * @type {number}
22
- */
23
- this.flags = 0;
24
- }
25
-
26
- /**
27
- *
28
- * @param {number|MaterialVertexSpecFlags} flag
29
- * @returns {void}
30
- */
31
- setFlag(flag) {
32
- this.flags |= flag;
33
- }
34
-
35
- /**
36
- *
37
- * @param {number|MaterialVertexSpecFlags} flag
38
- * @returns {void}
39
- */
40
- clearFlag(flag) {
41
- this.flags &= ~flag;
42
- }
43
-
44
- /**
45
- *
46
- * @param {number|MaterialVertexSpecFlags} flag
47
- * @param {boolean} value
48
- */
49
- writeFlag(flag, value) {
50
- if (value) {
51
- this.setFlag(flag);
52
- } else {
53
- this.clearFlag(flag);
54
- }
55
- }
56
-
57
- /**
58
- *
59
- * @param {number|MaterialVertexSpecFlags} flag
60
- * @returns {boolean}
61
- */
62
- getFlag(flag) {
63
- return (this.flags & flag) === flag;
64
- }
65
-
66
- /**
67
- *
68
- * @param {MaterialVertexSpec} other
69
- */
70
- copy(other) {
71
- this.spec = other.spec;
72
- this.material = other.material;
73
- this.flags = other.flags;
74
- }
75
-
76
- /**
77
- *
78
- * @return {MaterialVertexSpec}
79
- */
80
- clone() {
81
- const r = new MaterialVertexSpec();
82
-
83
- r.copy(this);
84
-
85
- return r;
86
- }
87
-
88
- /**
89
- * @param {VertexDataSpec} spec
90
- * @param {Material} material
91
- */
92
- static from(spec, material) {
93
- const r = new MaterialVertexSpec();
94
-
95
- r.spec = spec;
96
- r.material = material;
97
-
98
- return r;
99
- }
100
-
101
- hash() {
102
- return this.spec.hash() ^ this.material.id ^ this.flags;
103
- }
104
-
105
- equals(other) {
106
- if (this === other) {
107
- return true;
108
- }
109
-
110
- return this.flags === other.flags
111
- && this.material === other.material
112
- && this.spec.equals(other.spec)
113
- ;
114
- }
115
- }
@@ -1,145 +0,0 @@
1
- import { VirtualGeometry } from "../../format/VirtualGeometry.js";
2
- import { VirtualGeometryBuilder } from "../VirtualGeometryBuilder.js";
3
- import { HashMap } from "../../../../../core/collection/HashMap.js";
4
- import Signal from "../../../../../core/events/signal/Signal.js";
5
- import { MaterialContext } from "./MaterialContext.js";
6
- import { MaterialVertexSpec, MaterialVertexSpecFlags } from "./MaterialVertexSpec.js";
7
-
8
- export class MicronRenderContext {
9
- constructor() {
10
-
11
- this.geometry = new VirtualGeometry();
12
-
13
- this.builder = new VirtualGeometryBuilder();
14
-
15
- /**
16
- *
17
- * @type {Map<MaterialVertexSpec, MaterialContext>}
18
- */
19
- this.material_contexts = new HashMap();
20
-
21
- /**
22
- *
23
- * @type {MaterialContext[]}
24
- * @private
25
- */
26
- this.__contexts_array = [];
27
-
28
- this.on = {
29
- /**
30
- * @type {Signal<MaterialContext>}
31
- */
32
- contextAdded: new Signal()
33
- };
34
- }
35
-
36
- /**
37
- *
38
- * @returns {MaterialContext[]}
39
- */
40
- get contexts_array() {
41
- return this.__contexts_array;
42
- }
43
-
44
- /**
45
- * Enable/disable wireframe rendering
46
- * @param {boolean} x
47
- */
48
- set wireframe(x) {
49
- this.material_contexts.forEach((ctx, mv) => {
50
-
51
-
52
- ctx.compiled_material.wireframe = x;
53
-
54
- });
55
- }
56
-
57
-
58
- /**
59
- *
60
- * @param {MaterialVertexSpec} descriptor
61
- * @returns {MaterialContext}
62
- */
63
- obtain_material(descriptor) {
64
-
65
- const existing = this.material_contexts.get(descriptor);
66
-
67
- if (existing !== undefined) {
68
- return existing;
69
- }
70
-
71
- // create a separate instance to be stored alongside the context
72
- const key = descriptor.clone();
73
-
74
- const ctx = new MaterialContext(descriptor.spec, descriptor.material);
75
-
76
- ctx.init();
77
-
78
- ctx.mesh.castShadow = descriptor.getFlag(MaterialVertexSpecFlags.CastShadow);
79
- ctx.mesh.receiveShadow = descriptor.getFlag(MaterialVertexSpecFlags.ReceiveShadow);
80
-
81
- this.material_contexts.set(key, ctx);
82
- this.__contexts_array.push(ctx);
83
-
84
- this.on.contextAdded.send1(ctx);
85
-
86
- return ctx;
87
- }
88
-
89
- render() {
90
- const render_context = this;
91
- const contexts = render_context.__contexts_array;
92
- const context_count = contexts.length;
93
-
94
- /**
95
- *
96
- * @type {Map<number, MaterialContext>}
97
- */
98
- const instance_to_ctx = new Map();
99
-
100
- let i = 0;
101
-
102
- for (i = 0; i < context_count; i++) {
103
- const ctx = contexts[i];
104
- ctx.__patch_count = 0;
105
-
106
- for (const instance of ctx.instances) {
107
- instance_to_ctx.set(instance, ctx);
108
- }
109
- }
110
-
111
- // sort patches into relevant contexts
112
- const geometry = render_context.geometry;
113
- const patch_count = geometry.patch_count;
114
- const patches = geometry.patches;
115
-
116
- for (i = 0; i < patch_count; i++) {
117
- const i3 = i * 3;
118
-
119
- const instance_id = patches[i3];
120
- const geometry_id = patches[i3 + 1];
121
- const patch_id = patches[i3 + 2];
122
-
123
- const ctx = instance_to_ctx.get(instance_id);
124
-
125
- const target_index = ctx.__patch_count;
126
- const target_address = target_index * 3;
127
-
128
- ctx.__patch_count++;
129
-
130
- const ctx_patches = ctx.__patches;
131
-
132
- ctx_patches[target_address] = instance_id;
133
- ctx_patches[target_address + 1] = geometry_id;
134
- ctx_patches[target_address + 2] = patch_id;
135
- }
136
-
137
- // build each context
138
- for (i = 0; i < context_count; i++) {
139
- const ctx = contexts[i];
140
-
141
- ctx.build(geometry);
142
- }
143
- }
144
-
145
- }