@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,123 +0,0 @@
1
- import { BinaryClassSerializationAdapter } from "../../../../ecs/storage/binary/BinaryClassSerializationAdapter.js";
2
- import { MicronGeometry } from "../MicronGeometry.js";
3
- import { AttributeSpec } from "../../../geometry/AttributeSpec.js";
4
- import { MicronGeometryPatch } from "../MicronGeometryPatch.js";
5
- import { serialize_patch } from "./serialize_patch.js";
6
- import { deserialize_patch } from "./deserialize_patch.js";
7
- import { serialize_attribute_spec } from "./serialize_attribute_spec.js";
8
- import { deserialize_attribute_spec } from "./deserialize_attribute_spec.js";
9
-
10
- export class MicronGeometryBinarySerializationAdapter extends BinaryClassSerializationAdapter {
11
- constructor() {
12
- super();
13
-
14
- this.klass = MicronGeometry;
15
- this.version = 0;
16
- }
17
-
18
- /**
19
- *
20
- * @param {BinaryBuffer} buffer
21
- * @param {MicronGeometry} value
22
- */
23
- serialize(buffer, value) {
24
- const spec = value.vertex_spec;
25
-
26
- // serialize vertex spec
27
- const attributes = spec.attributes;
28
- const attribute_count = attributes.length;
29
- buffer.writeUintVar(attribute_count);
30
- for (let i = 0; i < attribute_count; i++) {
31
- const attribute = attributes[i];
32
-
33
- serialize_attribute_spec(buffer, attribute);
34
- }
35
-
36
- // serialize patches
37
-
38
- /**
39
- *
40
- * @type {MicronGeometryPatch[]}
41
- */
42
- const patches = value.patches;
43
- const patch_count = patches.length;
44
-
45
- const root_patch_index = patches.indexOf(value.root);
46
-
47
- buffer.writeUintVar(root_patch_index);
48
-
49
- buffer.writeUintVar(patch_count);
50
-
51
- for (let i = 0; i < patch_count; i++) {
52
- serialize_patch(buffer, patches[i], spec, patches);
53
- }
54
- }
55
-
56
- /**
57
- *
58
- * @param {BinaryBuffer} buffer
59
- * @param {MicronGeometry} value
60
- */
61
- deserialize(buffer, value) {
62
- // read spec
63
- const attribute_count = buffer.readUintVar();
64
- const attributes = [];
65
- for (let i = 0; i < attribute_count; i++) {
66
- const spec = new AttributeSpec();
67
-
68
- deserialize_attribute_spec(buffer, spec);
69
- attributes[i] = spec;
70
- }
71
-
72
- const vertex_spec = value.vertex_spec;
73
- vertex_spec.setAttributes(attributes);
74
-
75
- // read patches
76
- const root_patch_index = buffer.readUintVar();
77
-
78
- const patch_count = buffer.readUintVar();
79
-
80
- /**
81
- *
82
- * @type {MicronGeometryPatch[]}
83
- */
84
- const patches = [];
85
-
86
- // for the sake of speed, we will allocate all metadata in the same piece of memory to make traversal of patch hierarchy faster
87
- const md_buffer = new ArrayBuffer(patch_count * 144);
88
- let md_buffer_offset = 0;
89
-
90
- // build initial patches
91
- for (let i = 0; i < patch_count; i++) {
92
- const patch = new MicronGeometryPatch();
93
-
94
- patch.id = i;
95
-
96
- md_buffer_offset += patch.allocate_metadata(md_buffer, md_buffer_offset);
97
-
98
- patches[i] = patch;
99
- }
100
-
101
- let source_triangle_count = 0;
102
- // NOTE: we can't easily find out source vertex count as vertices are duplicated across patches
103
-
104
-
105
- //read patches
106
- for (let i = 0; i < patch_count; i++) {
107
- const patch = patches[i];
108
-
109
- deserialize_patch(buffer, patch, vertex_spec, patches);
110
-
111
- // collect source metadata
112
- if (patch.lod === 0) {
113
- source_triangle_count += patch.polygon_count;
114
- }
115
- }
116
-
117
- value.patches = patches;
118
- value.root = patches[root_patch_index];
119
-
120
- // write source metadata
121
- value.source_triangle_count = source_triangle_count;
122
- }
123
- }
@@ -1,63 +0,0 @@
1
- import { MicronGeometryPatch } from "../MicronGeometryPatch.js";
2
- import { BinaryBuffer } from "../../../../../core/binary/BinaryBuffer.js";
3
- import { MicronGeometry } from "../MicronGeometry.js";
4
- import { VertexDataSpec } from "../../../geometry/VertexDataSpec.js";
5
- import { AttributeSpec } from "../../../geometry/AttributeSpec.js";
6
- import { BinaryDataType } from "../../../../../core/binary/type/BinaryDataType.js";
7
- import { MicronGeometryBinarySerializationAdapter } from "./MicronGeometryBinarySerializationAdapter.js";
8
-
9
- function sampleGeometry() {
10
- const a = new MicronGeometryPatch();
11
-
12
- a.vertex_attribute_arrays[0] = new Uint8Array([
13
- 7, 11, 13,
14
- 17, 23, 29,
15
- 31, 39, 43
16
- ]);
17
- a.vertex_count = 3;
18
-
19
- a.face_indices = new Uint8Array([1, 2, 3]);
20
- a.polygon_count = 1;
21
-
22
- a.group_error = 1.234;
23
-
24
- a.bounding_box.set([7, 11, 13, 31, 39, 43]);
25
- a.group_bounding_box.set([7, 11, 13, 31, 39, 43]);
26
- a.bounding_sphere.set([19, 25, 28, 50.1]);
27
- a.group_bounding_sphere.set([19, 25, 28, 50.1]);
28
-
29
- const g_a = new MicronGeometry();
30
-
31
- const vertex_spec = new VertexDataSpec();
32
- vertex_spec.add(AttributeSpec.fromJSON({
33
- name: 'position',
34
- type: BinaryDataType.Uint8,
35
- itemSize: 3,
36
- normalized: false
37
- }));
38
-
39
- g_a.vertex_spec = vertex_spec;
40
- g_a.root = a;
41
- g_a.initialize();
42
-
43
- return g_a;
44
- }
45
-
46
- test("serialization/deserialization consistency", () => {
47
- const g_a = sampleGeometry();
48
-
49
- const buffer = new BinaryBuffer();
50
-
51
- const adapter = new MicronGeometryBinarySerializationAdapter();
52
-
53
- adapter.serialize(buffer, g_a);
54
-
55
-
56
- const g_b = new MicronGeometry();
57
-
58
- buffer.position = 0;
59
- adapter.deserialize(buffer, g_b);
60
-
61
- expect(g_b.vertex_spec.equals(g_a.vertex_spec)).toBe(true);
62
- expect(g_b.patches.length).toEqual(g_a.patches.length);
63
- });
@@ -1,83 +0,0 @@
1
- import { MicronGeometryBinarySerializationAdapter } from "../MicronGeometryBinarySerializationAdapter.js";
2
- import { MicronGeometry } from "../../MicronGeometry.js";
3
-
4
- const SUPPORTED_ADAPTER_VERSION = 0;
5
- const HEADER_MAGIC_TEXT = 'MICRON#001';
6
-
7
- function obtain_micron_adapter() {
8
-
9
- const ga = new MicronGeometryBinarySerializationAdapter();
10
-
11
- if (ga.version !== SUPPORTED_ADAPTER_VERSION) {
12
- throw new Error(`Incorrect version of serialization adapter, expected ${SUPPORTED_ADAPTER_VERSION}, instead got ${ga.version}`);
13
- }
14
-
15
- return ga;
16
- }
17
-
18
- /**
19
- *
20
- * @param {MicronGeometry[]} destination
21
- * @param {BinaryBuffer} buffer
22
- * @returns {number} how many geometries were read
23
- */
24
- export function deserialize_geometry_collection(destination, buffer) {
25
- // read header
26
- const header_text = buffer.readASCIICharacters(HEADER_MAGIC_TEXT.length);
27
-
28
- if (header_text !== HEADER_MAGIC_TEXT) {
29
- throw new Error(`Wrong header magic, expected '${HEADER_MAGIC_TEXT}', instead got '${header_text}'`);
30
- }
31
-
32
- // read how many geometries we're expecting
33
- const geometry_occupies_count = buffer.readUint32();
34
-
35
- const ga = obtain_micron_adapter();
36
-
37
- for (let i = 0; i < geometry_occupies_count; i++) {
38
- // read key
39
- const key = buffer.readUint32();
40
-
41
- const geometry = new MicronGeometry();
42
-
43
- ga.deserialize(buffer, geometry);
44
-
45
- destination[key] = geometry;
46
- }
47
-
48
- return geometry_occupies_count;
49
- }
50
-
51
- /**
52
- *
53
- * @param {MicronGeometry[]} geometries
54
- * @param {BinaryBuffer} buffer
55
- */
56
- export function serialize_geometry_collection(geometries, buffer) {
57
- // write header
58
- buffer.writeASCIIString(HEADER_MAGIC_TEXT); // magic bytes
59
-
60
- // count geometries
61
- let geometry_occupied_count = 0;
62
- const geometry_count = geometries.length;
63
- for (let i = 0; i < geometry_count; i++) {
64
- if (geometries[i] !== undefined) {
65
- geometry_occupied_count++;
66
- }
67
- }
68
-
69
- buffer.writeUint32(geometry_occupied_count); // how many geometries to expect
70
-
71
- const ga = obtain_micron_adapter();
72
-
73
- for (let i = 0; i < geometry_count; i++) {
74
- const geometry = geometries[i];
75
- if (geometry === undefined) {
76
- continue;
77
- }
78
-
79
- buffer.writeUint32(i); // key
80
-
81
- ga.serialize(buffer, geometry);
82
- }
83
- }
@@ -1,51 +0,0 @@
1
- import { deserialize_geometry_collection, serialize_geometry_collection } from "./geometry_collection_serialization.js";
2
- import { BinaryBuffer } from "../../../../../../core/binary/BinaryBuffer.js";
3
- import { MicronGeometry } from "../../MicronGeometry.js";
4
- import { MicronGeometryPatch } from "../../MicronGeometryPatch.js";
5
-
6
- function sample_geo() {
7
-
8
- const geometry = new MicronGeometry();
9
-
10
- geometry.root = new MicronGeometryPatch();
11
- geometry.patches.push(geometry.root);
12
-
13
- return geometry;
14
- }
15
-
16
- test('serialize empty', () => {
17
- const bb = new BinaryBuffer();
18
-
19
- expect(() => {
20
- serialize_geometry_collection([], bb);
21
- }).not.toThrow();
22
-
23
- });
24
-
25
- test('serialize/deserialize empty', () => {
26
- const bb = new BinaryBuffer();
27
-
28
- serialize_geometry_collection([], bb);
29
-
30
- bb.position = 0;
31
-
32
- const destination = [];
33
- deserialize_geometry_collection(destination, bb);
34
-
35
- expect(destination.length).toBe(0);
36
- });
37
-
38
- test('serialize/deserialize 1', () => {
39
- const bb = new BinaryBuffer();
40
-
41
- const geometry = sample_geo();
42
-
43
- serialize_geometry_collection([geometry], bb);
44
-
45
- bb.position = 0;
46
-
47
- const destination = [];
48
- deserialize_geometry_collection(destination, bb);
49
-
50
- expect(destination.length).toBe(1);
51
- });
@@ -1,25 +0,0 @@
1
- import { computeDataTypeByIndex } from "../../../../../core/binary/type/computeDataTypeByIndex.js";
2
-
3
- /**
4
- *
5
- * @param {BinaryBuffer} buffer
6
- * @param {AttributeSpec} spec
7
- */
8
- export function deserialize_attribute_spec(buffer, spec) {
9
-
10
- spec.name = buffer.readUTF8String();
11
- spec.itemSize = buffer.readUintVar();
12
-
13
- const type_index = buffer.readUint8();
14
- const type = computeDataTypeByIndex(type_index);
15
-
16
- if (type === undefined) {
17
- throw new Error(`Unknown data type marker '${type_index}'`);
18
- }
19
-
20
- spec.type = type;
21
-
22
- const flags = buffer.readUint8();
23
-
24
- spec.normalized = (flags & 0x1) !== 0;
25
- }
@@ -1,106 +0,0 @@
1
- import { aabb3_build_corners } from "../../../../../core/geom/3d/aabb/aabb3_build_corners.js";
2
- import { DataTypeByteSizes } from "../../../../../core/binary/type/DataTypeByteSizes.js";
3
- import {
4
- DataType2TypedArrayConstructorMapping
5
- } from "../../../../../core/binary/type/DataType2TypedArrayConstructorMapping.js";
6
-
7
- /**
8
- *
9
- * @param {BinaryBuffer} buffer
10
- * @param {MicronGeometryPatch} patch
11
- * @param {VertexDataSpec} vertex_spec
12
- * @param {MicronGeometryPatch[]} patch_array
13
- */
14
- export function deserialize_patch(buffer, patch, vertex_spec, patch_array) {
15
- // METADATA
16
- buffer.readFloat32Array(patch.bounding_box, 0, 6);
17
- buffer.readFloat32Array(patch.bounding_sphere, 0, 4);
18
-
19
- const gbb = patch.group_bounding_box;
20
- buffer.readFloat32Array(gbb, 0, 6);
21
- buffer.readFloat32Array(patch.group_bounding_sphere, 0, 4);
22
-
23
- patch.group_error = buffer.readFloat32();
24
- patch.lod = buffer.readUintVar();
25
- patch.polygon_count = buffer.readUintVar();
26
- patch.vertex_count = buffer.readUintVar();
27
-
28
- // parents
29
- const parents = [];
30
- const parent_count = buffer.readUintVar();
31
-
32
- for (let i = 0; i < parent_count; i++) {
33
- const parent_index = buffer.readUintVar();
34
-
35
- if (patch_array.length <= parent_index || parent_index < 0) {
36
- throw new Error(`out of bounds parent index '${parent_index}'`);
37
- }
38
-
39
- parents[i] = patch_array[parent_index];
40
- }
41
-
42
- patch.parents = parents;
43
-
44
- // children
45
- const children = [];
46
- const child_count = buffer.readUintVar();
47
-
48
- for (let i = 0; i < child_count; i++) {
49
- const child_index = buffer.readUintVar();
50
-
51
- if (patch_array.length <= child_index || child_index < 0) {
52
- throw new Error(`out of bounds child index '${child_index}'`);
53
- }
54
-
55
- children[i] = patch_array[child_index];
56
- }
57
-
58
- patch.children = children;
59
-
60
- // INDICES
61
- const index_count = patch.polygon_count * 3;
62
-
63
- if (patch.vertex_count <= 256) {
64
- patch.face_indices = new Uint8Array(index_count);
65
- buffer.readUint8Array(patch.face_indices, 0, index_count);
66
- } else if (patch.vertex_count <= 65536) {
67
- patch.face_indices = new Uint16Array(index_count);
68
- buffer.readUint16Array(patch.face_indices, 0, index_count);
69
- } else {
70
- throw new Error(`Unsupported vertex count '${patch.vertex_count}'`);
71
- }
72
-
73
- // VERTICES
74
- const attributes = vertex_spec.attributes;
75
- const attribute_count = attributes.length;
76
-
77
- for (let i = 0; i < attribute_count; i++) {
78
- const spec = attributes[i];
79
-
80
- const data_type = spec.type;
81
- const item_size = spec.itemSize;
82
-
83
- const byte_size = DataTypeByteSizes[data_type];
84
-
85
- const ArrayConstructor = DataType2TypedArrayConstructorMapping[data_type];
86
-
87
- const elment_count = item_size * patch.vertex_count;
88
- const array = new ArrayConstructor(elment_count);
89
-
90
- buffer.readUint8Array(new Uint8Array(array.buffer), 0, byte_size * elment_count);
91
-
92
- patch.vertex_attribute_arrays[i] = array;
93
- }
94
-
95
- // reconstruct corners
96
- aabb3_build_corners(
97
- patch.group_bounding_box_corners,
98
- 0,
99
- gbb[0],
100
- gbb[1],
101
- gbb[2],
102
- gbb[3],
103
- gbb[4],
104
- gbb[5]
105
- );
106
- }
@@ -1,18 +0,0 @@
1
- import { DataTypeIndices } from "../../../../../core/binary/type/DataTypeIndices.js";
2
-
3
- /**
4
- *
5
- * @param {BinaryBuffer} buffer
6
- * @param {AttributeSpec} spec
7
- */
8
- export function serialize_attribute_spec(buffer, spec) {
9
- buffer.writeUTF8String(spec.name);
10
- buffer.writeUintVar(spec.itemSize);
11
-
12
- const dataTypeIndex = DataTypeIndices[spec.type];
13
- buffer.writeUint8(dataTypeIndex);
14
-
15
- const flags = spec.normalized ? 1 : 0;
16
-
17
- buffer.writeUint8(flags);// flags
18
- }
@@ -1,84 +0,0 @@
1
- import { DataTypeByteSizes } from "../../../../../core/binary/type/DataTypeByteSizes.js";
2
-
3
- /**
4
- *
5
- * @param {BinaryBuffer} buffer
6
- * @param {MicronGeometryPatch} patch
7
- * @param {VertexDataSpec} vertex_spec
8
- * @param {MicronGeometryPatch[]} patch_array
9
- */
10
- export function serialize_patch(buffer, patch, vertex_spec, patch_array) {
11
- // METADATA
12
- buffer.writeFloat32Array(patch.bounding_box, 0, 6);
13
- buffer.writeFloat32Array(patch.bounding_sphere, 0, 4);
14
-
15
- buffer.writeFloat32Array(patch.group_bounding_box, 0, 6);
16
- buffer.writeFloat32Array(patch.group_bounding_sphere, 0, 4);
17
-
18
- buffer.writeFloat32(patch.group_error);
19
- buffer.writeUintVar(patch.lod);
20
- buffer.writeUintVar(patch.polygon_count);
21
- buffer.writeUintVar(patch.vertex_count);
22
-
23
- // write parents
24
- const parents = patch.parents;
25
- const parent_count = parents.length;
26
-
27
- buffer.writeUintVar(parent_count);
28
-
29
- for (let i = 0; i < parent_count; i++) {
30
- const parent = parents[i];
31
-
32
- const parent_index = patch_array.indexOf(parent);
33
-
34
- if (parent_index === -1) {
35
- throw new Error(`Patch '${parent.id}' not found in the lookup table`);
36
- }
37
-
38
- buffer.writeUintVar(parent_index);
39
- }
40
-
41
- // write children
42
- const children = patch.children;
43
- const child_count = children.length;
44
-
45
- buffer.writeUintVar(child_count);
46
-
47
- for (let i = 0; i < child_count; i++) {
48
- const child = children[i];
49
-
50
- const child_index = patch_array.indexOf(child);
51
-
52
- if (child_index === -1) {
53
- throw new Error(`Patch '${child.id}' not found in the lookup table`);
54
- }
55
-
56
- buffer.writeUintVar(child_index);
57
- }
58
-
59
- // INDICES
60
- if (patch.vertex_count <= 256) {
61
- buffer.writeUint8Array(patch.face_indices, 0, patch.polygon_count * 3);
62
- } else if (patch.vertex_count <= 65536) {
63
- buffer.writeUint16Array(patch.face_indices, 0, patch.polygon_count * 3);
64
- } else {
65
- throw new Error(`Unsupported vertex count '${patch.vertex_count}'`);
66
- }
67
-
68
- // VERTICES
69
- const attributes = vertex_spec.attributes;
70
- const attribute_count = attributes.length;
71
-
72
- for (let i = 0; i < attribute_count; i++) {
73
- const spec = attributes[i];
74
-
75
- const data_type = spec.type;
76
- const item_size = spec.itemSize;
77
-
78
- const byte_size = DataTypeByteSizes[data_type];
79
-
80
- const attribute_values = patch.vertex_attribute_arrays[i];
81
-
82
- buffer.writeUint8Array(new Uint8Array(attribute_values.buffer), 0, item_size * byte_size * patch.vertex_count);
83
- }
84
- }
@@ -1,69 +0,0 @@
1
- import { noop } from "../../../../core/function/Functions.js";
2
- import { aabb3_array_contains_point } from "../../../../core/geom/3d/aabb/aabb3_array_contains_point.js";
3
- import { sphere_array_intersects_point } from "../../../../core/geom/3d/sphere/sphere_array_intersects_point.js";
4
-
5
- /**
6
- *
7
- * @param {MicronGeometryPatch} patch
8
- * @param {VertexDataSpec} vertex_spec
9
- * @param {function(string)} [error_consumer]
10
- * @returns {boolean}
11
- */
12
- export function validate_patch_bounds(patch, vertex_spec, error_consumer = noop) {
13
- const position_attribute_index = vertex_spec.getAttributeIndexByName('position');
14
-
15
- if (position_attribute_index === -1) {
16
- error_consumer(`No 'position' attribute found`);
17
- // technically any bounds are valid if there is no position
18
- return true;
19
- }
20
-
21
- const position_data = patch.vertex_attribute_arrays[position_attribute_index];
22
-
23
- let b_sphere_valid = true;
24
- let b_box_valid = true;
25
- let gb_sphere_valid = true;
26
- let gb_box_valid = true;
27
-
28
- for (let i = 0; i < this.vertex_count; i++) {
29
- const i3 = i * 3;
30
-
31
- const x = position_data[i3];
32
- const y = position_data[i3 + 1];
33
- const z = position_data[i3 + 2];
34
-
35
- if (!aabb3_array_contains_point(patch.bounding_box, x, y, z)) {
36
- b_box_valid = false;
37
- }
38
-
39
- if (!aabb3_array_contains_point(patch.group_bounding_box, x, y, z)) {
40
- gb_box_valid = false;
41
- }
42
-
43
- if (!sphere_array_intersects_point(patch.bounding_sphere, x, y, z)) {
44
- b_sphere_valid = false;
45
- }
46
-
47
- if (!sphere_array_intersects_point(patch.group_bounding_sphere, x, y, z)) {
48
- gb_sphere_valid = false;
49
- }
50
- }
51
-
52
- if (!b_sphere_valid) {
53
- error_consumer('.bounding_sphere is violated');
54
- }
55
-
56
- if (!gb_sphere_valid) {
57
- error_consumer('.group_bounding_sphere is violated');
58
- }
59
-
60
- if (!b_box_valid) {
61
- error_consumer('.bounding_box is violated');
62
- }
63
-
64
- if (!gb_box_valid) {
65
- error_consumer('.group_bounding_box is violated');
66
- }
67
-
68
- return b_sphere_valid && gb_sphere_valid && b_box_valid && gb_box_valid;
69
- }