@woosh/meep-engine 2.33.6 → 2.33.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/core/binary/BinaryBuffer.js +26 -2
- package/core/bvh2/LeafNode.js +6 -1
- package/core/bvh2/aabb3/AABB3.js +17 -0
- package/core/collection/set/compute_set_difference.js +32 -0
- package/core/collection/set/compute_set_intersection.js +22 -0
- package/core/collection/set/set_remove.js +15 -0
- package/core/collection/table/DataType2TypedArrayConstructorMapping.js +2 -0
- package/core/collection/table/DataTypeByteSizes.js +21 -0
- package/core/collection/table/RowFirstTable.js +1 -88
- package/core/collection/table/RowFirstTable.spec.js +3 -1
- package/core/collection/table/RowFirstTableSpec.js +1 -19
- package/core/collection/table/computeDataTypeByIndex.js +21 -0
- package/core/collection/table/deserializeRowFirstTable.js +48 -0
- package/core/collection/table/serializeRowFirstTable.js +27 -0
- package/core/color/Color.js +1 -0
- package/core/color/ColorUtils.js +12 -3
- package/core/geom/3d/aabb/aabb3_from_min_max.js +15 -0
- package/core/geom/3d/aabb/aabb3_matrix4_project_by_corners.js +96 -0
- package/{engine/graphics/micron/render/v1 → core/geom/3d}/apply_mat4_transform_to_v3_array.js +0 -0
- package/{engine/graphics/micron/build/bounds → core/geom/3d}/compute_bounding_cone_of_2_cones.js +3 -3
- package/{engine/graphics/micron/build/bounds → core/geom/3d}/compute_bounding_cone_of_2_cones.spec.js +1 -1
- package/{engine/graphics/micron/build/bounds → core/geom/3d}/compute_bounding_sphere_of_2_spheres.js +3 -3
- package/{engine/graphics/micron/util → core/geom/3d}/encode_unit3_hemioct.js +0 -0
- package/{engine/graphics/micron/render/refinement → core/geom/3d/frustum}/array_normalize_plane.js +1 -1
- package/{engine/graphics/micron/render/refinement → core/geom/3d/frustum}/array_setFromProjectionMatrix.js +2 -2
- package/{engine/graphics/micron/util → core/geom/3d}/unit_hemioct.spec.js +1 -1
- package/{engine/graphics/micron/build → core}/graph/MultiNode.js +0 -0
- package/{engine/graphics/micron/build → core}/graph/SquareMatrix.js +2 -2
- package/{engine/graphics/micron/build → core}/graph/SquareMatrix.spec.js +1 -1
- package/{engine/graphics/micron/build → core}/graph/WeightedEdge.js +1 -1
- package/{engine/graphics/micron/build → core}/graph/build_face_graph_from_mesh.js +2 -2
- package/{engine/graphics/micron/build/clustering → core/graph}/cluster_mesh_metis.js +2 -6
- package/{engine/graphics/micron/build → core}/graph/coarsen_graph.js +1 -1
- package/{engine/graphics/micron/build → core}/graph/coarsen_graph.spec.js +1 -1
- package/{engine/graphics/micron/build → core}/graph/eigen/eigen.js +0 -0
- package/{engine/graphics/micron/build → core}/graph/eigen/eigen.spec.js +1 -1
- package/{engine/graphics/micron/build/hierarchy → core/graph/eigen}/eigen_values_find_spectral_gap.js +0 -0
- package/{engine/graphics/micron/build → core}/graph/graph_adjacency_matrix.js +0 -0
- package/{engine/graphics/micron/build → core}/graph/graph_compute_disconnected_clusters.js +0 -0
- package/{engine/graphics/micron/build → core}/graph/graph_degree_matrix.js +0 -0
- package/{engine/graphics/micron/build → core}/graph/graph_k_means_cluster.js +5 -5
- package/{engine/graphics/micron/build → core}/graph/graph_laplacian_matrix.js +1 -1
- package/{engine/graphics/micron/build → core}/graph/metis/metis.js +2 -2
- package/{engine/graphics/micron/build → core}/graph/metis/metis_options.js +0 -0
- package/{engine/graphics/micron/build → core}/graph/mn_graph_collapse_weighted_edge.js +0 -0
- package/core/process/worker/WorkerBuilder.js +21 -6
- package/engine/Engine.d.ts +2 -0
- package/engine/EngineHarness.js +4 -4
- package/engine/ecs/foliage/InstancedFoliage.js +3 -5
- package/engine/ecs/fow/serialization/FogOfWarSerializationAdapter.js +2 -1
- package/engine/ecs/transform/Transform.js +2 -1
- package/engine/graphics/ecs/mesh/updateNodeByTransformAndBBB.js +22 -37
- package/engine/graphics/ecs/mesh-v2/ShadedGeometry.js +155 -0
- package/engine/graphics/ecs/mesh-v2/ShadedGeometrySystem.js +68 -0
- package/engine/graphics/ecs/mesh-v2/prototypeShadedGeometry.js +31 -0
- package/engine/graphics/{micron → geometry}/aabb3_to_buffer_geometry.js +0 -0
- package/engine/graphics/{micron/build → geometry/buffered}/compute_buffer_geometry_byte_size.js +0 -0
- package/engine/graphics/micron/build/buildMicronGeometryFromBufferGeometry.js +1 -1
- package/engine/graphics/micron/build/clustering/build_clustering_2.js +2 -2
- package/engine/graphics/micron/build/clustering/build_leaf_patches_metis.js +1 -1
- package/engine/graphics/micron/build/hierarchy/buildAbstractPatchHierarchy.js +3 -3
- package/engine/graphics/micron/build/hierarchy/build_intermediate_patch_topology.js +0 -72
- package/engine/graphics/micron/build/hierarchy/build_merge_graph.js +2 -2
- package/engine/graphics/micron/build/hierarchy/computePatchMergeScore.js +3 -3
- package/engine/graphics/micron/build/hierarchy/merge_patches.js +6 -3
- package/engine/graphics/micron/build/hierarchy/metis_cluster_clusters.js +1 -1
- package/engine/graphics/micron/build/hierarchy/optimize_graph_partitioning_balance.js +1 -1
- package/engine/graphics/micron/build/hierarchy/patch_combine.js +2 -2
- package/engine/graphics/micron/build/hierarchy/qvdr_build_simplified_clusters.js +2 -1
- package/engine/graphics/micron/format/MicronGeometry.js +12 -0
- package/engine/graphics/micron/format/MicronGeometryBufferAttributeSpec.js +1 -1
- package/engine/graphics/micron/format/MicronGeometryPatch.js +6 -6
- package/engine/graphics/micron/format/serialization/MicronGeometryBinarySerializationAdapter.js +101 -0
- package/engine/graphics/micron/format/serialization/deserialize_attribute_spec.js +25 -0
- package/engine/graphics/micron/format/serialization/deserialize_patch.js +104 -0
- package/engine/graphics/micron/format/serialization/serialize_attribute_spec.js +18 -0
- package/engine/graphics/micron/format/serialization/serialize_patch.js +84 -0
- package/engine/graphics/micron/render/culling/{PathCullingSystem.js → PatchCullingSystem.js} +1 -1
- package/engine/graphics/micron/render/instanced/AttributeDataTexture.js +1 -1
- package/engine/graphics/micron/render/refinement/RefinementSpec.js +1 -1
- package/engine/graphics/micron/render/v1/getTransformedPositionsCached.js +1 -1
- package/engine/graphics/render/forward_plus/data/TextureBackedMemoryRegion.js +1 -1
- package/engine/graphics/render/visibility/hiz/prototypeHiZ.js +11 -6
- package/engine/graphics/texture/sampler/TextureBinaryBufferSerializer.js +1 -1
- package/engine/network/convertPathToURL.js +7 -1
- package/engine/plugin/EnginePluginManager.d.ts +9 -0
- package/engine/reference/v2/Reference.d.ts +7 -0
- package/package.json +1 -1
- package/engine/graphics/micron/build/clustering/cluster_mesh_vertices.js +0 -3
|
@@ -342,7 +342,7 @@ BinaryBuffer.prototype.readInt32Array = function (destination, destination_offse
|
|
|
342
342
|
*
|
|
343
343
|
* @param {number} destination_offset starting index in the destination array
|
|
344
344
|
* @param {number} length number of elements to read
|
|
345
|
-
* @param {Float32Array} destination
|
|
345
|
+
* @param {Float32Array|number[]} destination
|
|
346
346
|
*/
|
|
347
347
|
BinaryBuffer.prototype.readFloat32Array = function (destination, destination_offset, length) {
|
|
348
348
|
for (let i = 0; i < length; i++) {
|
|
@@ -366,7 +366,7 @@ BinaryBuffer.prototype.readFloat64Array = function (destination, destination_off
|
|
|
366
366
|
*
|
|
367
367
|
* @param {number} source_offset starting index in the source array
|
|
368
368
|
* @param {number} length number of elements to read
|
|
369
|
-
* @param {Float32Array} source
|
|
369
|
+
* @param {Float32Array|number[]} source
|
|
370
370
|
*/
|
|
371
371
|
BinaryBuffer.prototype.writeFloat32Array = function (source, source_offset, length) {
|
|
372
372
|
for (let i = 0; i < length; i++) {
|
|
@@ -452,6 +452,18 @@ BinaryBuffer.prototype.writeUint8 = function (value) {
|
|
|
452
452
|
this.position = end;
|
|
453
453
|
};
|
|
454
454
|
|
|
455
|
+
/**
|
|
456
|
+
*
|
|
457
|
+
* @param {Uint8Array|number[]} source
|
|
458
|
+
* @param {number} source_offset
|
|
459
|
+
* @param {number} length
|
|
460
|
+
*/
|
|
461
|
+
BinaryBuffer.prototype.writeUint8Array = function (source, source_offset, length) {
|
|
462
|
+
for (let i = 0; i < length; i++) {
|
|
463
|
+
this.writeUint8(source[source_offset + i]);
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
|
|
455
467
|
/**
|
|
456
468
|
*
|
|
457
469
|
* @param {number} value
|
|
@@ -491,6 +503,18 @@ BinaryBuffer.prototype.writeUint16LE = function (value) {
|
|
|
491
503
|
this.position = end;
|
|
492
504
|
};
|
|
493
505
|
|
|
506
|
+
/**
|
|
507
|
+
*
|
|
508
|
+
* @param {Uint16Array|number[]} source
|
|
509
|
+
* @param {number} source_offset
|
|
510
|
+
* @param {number} length
|
|
511
|
+
*/
|
|
512
|
+
BinaryBuffer.prototype.writeUint16Array = function (source, source_offset, length) {
|
|
513
|
+
for (let i = 0; i < length; i++) {
|
|
514
|
+
this.writeUint16(source[source_offset + i]);
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
|
|
494
518
|
/**
|
|
495
519
|
*
|
|
496
520
|
* @param {number} value
|
package/core/bvh2/LeafNode.js
CHANGED
|
@@ -83,10 +83,15 @@ LeafNode.prototype.move = function (dx, dy, dz) {
|
|
|
83
83
|
LeafNode.prototype.resize = function (x0, y0, z0, x1, y1, z1) {
|
|
84
84
|
this.setBounds(x0, y0, z0, x1, y1, z1);
|
|
85
85
|
|
|
86
|
+
this.bubbleRefit();
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
LeafNode.prototype.bubbleRefit = function (){
|
|
90
|
+
|
|
86
91
|
if (this.parentNode !== null) {
|
|
87
92
|
this.parentNode.bubbleRefit();
|
|
88
93
|
}
|
|
89
|
-
}
|
|
94
|
+
}
|
|
90
95
|
|
|
91
96
|
/**
|
|
92
97
|
*
|
package/core/bvh2/aabb3/AABB3.js
CHANGED
|
@@ -736,6 +736,23 @@ AABB3.prototype.writeToArray = function (result, offset) {
|
|
|
736
736
|
result[offset + 5] = this.z1;
|
|
737
737
|
};
|
|
738
738
|
|
|
739
|
+
/**
|
|
740
|
+
*
|
|
741
|
+
* @param {number[]|Float32Array|Float64Array} source
|
|
742
|
+
* @param {number} offset
|
|
743
|
+
*/
|
|
744
|
+
AABB3.prototype.readFromArray = function (source, offset) {
|
|
745
|
+
assert.isNonNegativeInteger(offset, 'offset');
|
|
746
|
+
|
|
747
|
+
this.x0 = source[offset];
|
|
748
|
+
this.y0 = source[offset + 1];
|
|
749
|
+
this.z0 = source[offset + 2];
|
|
750
|
+
|
|
751
|
+
this.x1 = source[offset + 3];
|
|
752
|
+
this.y1 = source[offset + 4];
|
|
753
|
+
this.z1 = source[offset + 5];
|
|
754
|
+
};
|
|
755
|
+
|
|
739
756
|
/**
|
|
740
757
|
* @param {THREE.Plane} plane
|
|
741
758
|
* @returns {int} 2,0,or -2; 2: above, -2 : below, 0 : intersects plane
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @template T
|
|
3
|
+
* @returns Set<T>
|
|
4
|
+
* @param {Set<T>} a
|
|
5
|
+
* @param {Set<T>} b
|
|
6
|
+
*/
|
|
7
|
+
export function compute_set_difference(a, b) {
|
|
8
|
+
const result = new Set();
|
|
9
|
+
|
|
10
|
+
const a_array = Array.from(a);
|
|
11
|
+
const a_count = a_array.length;
|
|
12
|
+
for (let i = 0; i < a_count; i++) {
|
|
13
|
+
const t = a_array[i];
|
|
14
|
+
|
|
15
|
+
if (!b.has(t)) {
|
|
16
|
+
result.add(t);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const b_array = Array.from(b);
|
|
21
|
+
const b_count = b_array.length;
|
|
22
|
+
for (let i = 0; i < b_count; i++) {
|
|
23
|
+
const t = b_array[i];
|
|
24
|
+
|
|
25
|
+
if (!a.has(t)) {
|
|
26
|
+
result.add(t);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
return result;
|
|
32
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @template T
|
|
3
|
+
* @returns Set<T>
|
|
4
|
+
* @param {Set<T>} a
|
|
5
|
+
* @param {Set<T>} b
|
|
6
|
+
*/
|
|
7
|
+
export function compute_set_intersection(a, b) {
|
|
8
|
+
const result = new Set();
|
|
9
|
+
|
|
10
|
+
const a_array = Array.from(a);
|
|
11
|
+
|
|
12
|
+
const n = a_array.length;
|
|
13
|
+
for (let i = 0; i < n; i++) {
|
|
14
|
+
const t = a_array[i];
|
|
15
|
+
|
|
16
|
+
if (b.has(t)) {
|
|
17
|
+
result.add(t);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return result;
|
|
22
|
+
}
|
|
@@ -12,6 +12,8 @@ export const DataType2TypedArrayConstructorMapping = {
|
|
|
12
12
|
[DataType.Int8]: Int8Array,
|
|
13
13
|
[DataType.Int16]: Int16Array,
|
|
14
14
|
[DataType.Int32]: Int32Array,
|
|
15
|
+
// No float16 array type, using uint16 as a backing instead
|
|
16
|
+
[DataType.Float16]: Uint16Array,
|
|
15
17
|
[DataType.Float32]: Float32Array,
|
|
16
18
|
[DataType.Float64]: Float64Array,
|
|
17
19
|
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { DataType } from "./DataType.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @readonly
|
|
5
|
+
* @enum {number}
|
|
6
|
+
*/
|
|
7
|
+
export const DataTypeByteSizes = {
|
|
8
|
+
[DataType.Uint8]: 1,
|
|
9
|
+
[DataType.Uint16]: 2,
|
|
10
|
+
[DataType.Uint32]: 4,
|
|
11
|
+
[DataType.Uint64]: 8,
|
|
12
|
+
|
|
13
|
+
[DataType.Int8]: 1,
|
|
14
|
+
[DataType.Int16]: 2,
|
|
15
|
+
[DataType.Int32]: 4,
|
|
16
|
+
[DataType.Int64]: 8,
|
|
17
|
+
|
|
18
|
+
[DataType.Float16]: 2,
|
|
19
|
+
[DataType.Float32]: 4,
|
|
20
|
+
[DataType.Float64]: 8
|
|
21
|
+
};
|
|
@@ -6,7 +6,6 @@
|
|
|
6
6
|
import { assert } from "../../assert.js";
|
|
7
7
|
import Signal from "../../events/signal/Signal.js";
|
|
8
8
|
import { max2 } from "../../math/max2.js";
|
|
9
|
-
import { DataTypeIndices } from "./DataTypeIndices.js";
|
|
10
9
|
import { RowFirstTableSpec } from "./RowFirstTableSpec.js";
|
|
11
10
|
|
|
12
11
|
|
|
@@ -439,92 +438,6 @@ RowFirstTable.prototype.printToConsole = function () {
|
|
|
439
438
|
console.table(rows);
|
|
440
439
|
};
|
|
441
440
|
|
|
442
|
-
/**
|
|
443
|
-
*
|
|
444
|
-
* @param {BinaryBuffer} buffer
|
|
445
|
-
* @param {RowFirstTable} table
|
|
446
|
-
*/
|
|
447
|
-
function serializeRowFirstTable(buffer, table) {
|
|
448
|
-
//write types
|
|
449
|
-
buffer.writeUint16(table.types.length);
|
|
450
|
-
table.types.forEach(function (type) {
|
|
451
|
-
const typeIndex = DataTypeIndices[type];
|
|
452
|
-
buffer.writeUint8(typeIndex);
|
|
453
|
-
});
|
|
454
|
-
|
|
455
|
-
//write record length
|
|
456
|
-
buffer.writeUint32(table.bytesPerRecord);
|
|
457
|
-
|
|
458
|
-
//write number of records
|
|
459
|
-
buffer.writeUint32(table.length);
|
|
460
|
-
|
|
461
|
-
//write data
|
|
462
|
-
const numDataBytes = table.length * table.bytesPerRecord;
|
|
463
|
-
buffer.writeBytes(new Uint8Array(table.data), 0, numDataBytes);
|
|
464
|
-
}
|
|
465
|
-
|
|
466
|
-
/**
|
|
467
|
-
*
|
|
468
|
-
* @param {BinaryBuffer} buffer
|
|
469
|
-
* @param {RowFirstTable} table
|
|
470
|
-
*/
|
|
471
|
-
function deserializeRowFirstTable(buffer, table) {
|
|
472
|
-
/**
|
|
473
|
-
*
|
|
474
|
-
* @param {number} index
|
|
475
|
-
* @returns {DataType|null}
|
|
476
|
-
*/
|
|
477
|
-
function typeByIndex(index) {
|
|
478
|
-
for (let type in DataTypeIndices) {
|
|
479
|
-
if (!DataTypeIndices.hasOwnProperty(type)) {
|
|
480
|
-
continue;
|
|
481
|
-
}
|
|
482
|
-
|
|
483
|
-
const typeIndex = DataTypeIndices[type];
|
|
484
|
-
if (typeIndex === index) {
|
|
485
|
-
return type;
|
|
486
|
-
}
|
|
487
|
-
}
|
|
488
|
-
|
|
489
|
-
return null;
|
|
490
|
-
}
|
|
491
|
-
|
|
492
|
-
//read types
|
|
493
|
-
const numTypes = buffer.readUint16();
|
|
494
|
-
const types = [];
|
|
495
|
-
for (let i = 0; i < numTypes; i++) {
|
|
496
|
-
const typeIndex = buffer.readUint8();
|
|
497
|
-
const type = typeByIndex(typeIndex);
|
|
498
|
-
if (type === null) {
|
|
499
|
-
throw new Error(`Unknown DataType index ${typeIndex}`);
|
|
500
|
-
}
|
|
501
|
-
types[i] = type;
|
|
502
|
-
}
|
|
503
|
-
|
|
504
|
-
//record size
|
|
505
|
-
const bytesPerRecord = buffer.readUint32();
|
|
506
|
-
|
|
507
|
-
//read number of records
|
|
508
|
-
const numRecords = buffer.readUint32();
|
|
509
|
-
|
|
510
|
-
const numDataBytes = bytesPerRecord * numRecords;
|
|
511
|
-
const data = new Uint8Array(numDataBytes);
|
|
512
|
-
|
|
513
|
-
//read data
|
|
514
|
-
buffer.readBytes(data, 0, numDataBytes);
|
|
515
|
-
|
|
516
|
-
//update table
|
|
517
|
-
table.spec = RowFirstTableSpec.get(types);
|
|
518
|
-
table.length = numRecords;
|
|
519
|
-
table.capacity = numRecords;
|
|
520
|
-
table.data = data.buffer;
|
|
521
|
-
table.dataView = new DataView(table.data);
|
|
522
|
-
|
|
523
|
-
table.initialize();
|
|
524
|
-
}
|
|
525
|
-
|
|
526
441
|
export {
|
|
527
|
-
RowFirstTable
|
|
528
|
-
serializeRowFirstTable,
|
|
529
|
-
deserializeRowFirstTable
|
|
442
|
+
RowFirstTable
|
|
530
443
|
};
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { BinaryBuffer } from "../../binary/BinaryBuffer.js";
|
|
2
2
|
import { DataType } from "./DataType.js";
|
|
3
|
-
import {
|
|
3
|
+
import { RowFirstTable } from "./RowFirstTable.js";
|
|
4
4
|
import { RowFirstTableSpec } from "./RowFirstTableSpec.js";
|
|
5
|
+
import { serializeRowFirstTable } from "./serializeRowFirstTable.js";
|
|
6
|
+
import { deserializeRowFirstTable } from "./deserializeRowFirstTable.js";
|
|
5
7
|
|
|
6
8
|
test("constructor doesn't throw", () => {
|
|
7
9
|
new RowFirstTable(new RowFirstTableSpec([]));
|
|
@@ -8,6 +8,7 @@ import { FunctionCompiler } from "../../function/FunctionCompiler.js";
|
|
|
8
8
|
import { computeStringHash } from "../../primitives/strings/computeStringHash.js";
|
|
9
9
|
import { isArrayEqualStrict } from "../array/isArrayEqualStrict.js";
|
|
10
10
|
import { DataType } from "./DataType.js";
|
|
11
|
+
import { DataTypeByteSizes } from "./DataTypeByteSizes.js";
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
14
|
* @readonly
|
|
@@ -47,25 +48,6 @@ export const DataType2DataViewWriters = {
|
|
|
47
48
|
"float64": "setFloat64"
|
|
48
49
|
};
|
|
49
50
|
|
|
50
|
-
/**
|
|
51
|
-
* @readonly
|
|
52
|
-
* @enum {number}
|
|
53
|
-
*/
|
|
54
|
-
export const DataTypeByteSizes = {
|
|
55
|
-
[DataType.Uint8]: 1,
|
|
56
|
-
[DataType.Uint16]: 2,
|
|
57
|
-
[DataType.Uint32]: 4,
|
|
58
|
-
[DataType.Uint64]: 8,
|
|
59
|
-
|
|
60
|
-
[DataType.Int8]: 1,
|
|
61
|
-
[DataType.Int16]: 2,
|
|
62
|
-
[DataType.Int32]: 4,
|
|
63
|
-
[DataType.Int64]: 8,
|
|
64
|
-
|
|
65
|
-
[DataType.Float32]: 4,
|
|
66
|
-
[DataType.Float64]: 8
|
|
67
|
-
};
|
|
68
|
-
|
|
69
51
|
/**
|
|
70
52
|
*
|
|
71
53
|
* @param {DataType[]} types
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { DataTypeIndices } from "./DataTypeIndices.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* @param {number} index
|
|
6
|
+
* @returns {DataType|undefined}
|
|
7
|
+
*/
|
|
8
|
+
export function computeDataTypeByIndex(index) {
|
|
9
|
+
for (let type in DataTypeIndices) {
|
|
10
|
+
if (!DataTypeIndices.hasOwnProperty(type)) {
|
|
11
|
+
continue;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const typeIndex = DataTypeIndices[type];
|
|
15
|
+
if (typeIndex === index) {
|
|
16
|
+
return type;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { RowFirstTableSpec } from "./RowFirstTableSpec.js";
|
|
2
|
+
import { computeDataTypeByIndex } from "./computeDataTypeByIndex.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
*
|
|
6
|
+
* @param {BinaryBuffer} buffer
|
|
7
|
+
* @param {RowFirstTable} table
|
|
8
|
+
*/
|
|
9
|
+
function deserializeRowFirstTable(buffer, table) {
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
//read types
|
|
13
|
+
const numTypes = buffer.readUint16();
|
|
14
|
+
const types = [];
|
|
15
|
+
for (let i = 0; i < numTypes; i++) {
|
|
16
|
+
const typeIndex = buffer.readUint8();
|
|
17
|
+
|
|
18
|
+
const type = computeDataTypeByIndex(typeIndex);
|
|
19
|
+
|
|
20
|
+
if (type === undefined) {
|
|
21
|
+
throw new Error(`Unknown DataType index ${typeIndex}`);
|
|
22
|
+
}
|
|
23
|
+
types[i] = type;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
//record size
|
|
27
|
+
const bytesPerRecord = buffer.readUint32();
|
|
28
|
+
|
|
29
|
+
//read number of records
|
|
30
|
+
const numRecords = buffer.readUint32();
|
|
31
|
+
|
|
32
|
+
const numDataBytes = bytesPerRecord * numRecords;
|
|
33
|
+
const data = new Uint8Array(numDataBytes);
|
|
34
|
+
|
|
35
|
+
//read data
|
|
36
|
+
buffer.readBytes(data, 0, numDataBytes);
|
|
37
|
+
|
|
38
|
+
//update table
|
|
39
|
+
table.spec = RowFirstTableSpec.get(types);
|
|
40
|
+
table.length = numRecords;
|
|
41
|
+
table.capacity = numRecords;
|
|
42
|
+
table.data = data.buffer;
|
|
43
|
+
table.dataView = new DataView(table.data);
|
|
44
|
+
|
|
45
|
+
table.initialize();
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export { deserializeRowFirstTable };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { DataTypeIndices } from "./DataTypeIndices.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* @param {BinaryBuffer} buffer
|
|
6
|
+
* @param {RowFirstTable} table
|
|
7
|
+
*/
|
|
8
|
+
function serializeRowFirstTable(buffer, table) {
|
|
9
|
+
//write types
|
|
10
|
+
buffer.writeUint16(table.types.length);
|
|
11
|
+
table.types.forEach(function (type) {
|
|
12
|
+
const typeIndex = DataTypeIndices[type];
|
|
13
|
+
buffer.writeUint8(typeIndex);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
//write record length
|
|
17
|
+
buffer.writeUint32(table.bytesPerRecord);
|
|
18
|
+
|
|
19
|
+
//write number of records
|
|
20
|
+
buffer.writeUint32(table.length);
|
|
21
|
+
|
|
22
|
+
//write data
|
|
23
|
+
const numDataBytes = table.length * table.bytesPerRecord;
|
|
24
|
+
buffer.writeBytes(new Uint8Array(table.data), 0, numDataBytes);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export { serializeRowFirstTable };
|
package/core/color/Color.js
CHANGED
package/core/color/ColorUtils.js
CHANGED
|
@@ -146,18 +146,21 @@ function int2rgb(value) {
|
|
|
146
146
|
}
|
|
147
147
|
}
|
|
148
148
|
|
|
149
|
+
const rgbRegEx = /rgb\(([0-9]+),\s*([0-9]+),\s*([0-9]+)\)/;
|
|
150
|
+
const hsvRegEx = /hsv\(([0-9]+(?:\.[0-9]*)?),\s*([0-9]+(?:\.[0-9]*)?),\s*([0-9]+(?:\.[0-9]*)?)\)/;
|
|
151
|
+
|
|
149
152
|
/**
|
|
150
153
|
*
|
|
151
154
|
* @param {string|number} c
|
|
152
155
|
* @returns {number[]} Numeric array, values are in Uint range
|
|
153
156
|
*/
|
|
154
157
|
export function parseColor(c) {
|
|
155
|
-
const rgbRegEx = /rgb\(([0-9]+),\s*([0-9]+),\s*([0-9]+)\)/;
|
|
156
|
-
const hsvRegEx = /hsv\(([0-9]+(?:\.[0-9]*)?),\s*([0-9]+(?:\.[0-9]*)?),\s*([0-9]+(?:\.[0-9]*)?)\)/;
|
|
157
158
|
|
|
158
159
|
const result = [];
|
|
159
160
|
|
|
160
|
-
|
|
161
|
+
const type_of_code = typeof c;
|
|
162
|
+
|
|
163
|
+
if (type_of_code === "string") {
|
|
161
164
|
const cL = c.toLowerCase();
|
|
162
165
|
|
|
163
166
|
let match;
|
|
@@ -191,6 +194,12 @@ export function parseColor(c) {
|
|
|
191
194
|
} else {
|
|
192
195
|
throw new Error(`Failed to decode color string '${c}' `);
|
|
193
196
|
}
|
|
197
|
+
} else if(type_of_code === 'number'){
|
|
198
|
+
|
|
199
|
+
result[0] = c >> 16;
|
|
200
|
+
result[1] = (c >> 8) & 0xFF;
|
|
201
|
+
result[2] = (c) & 0xFF;
|
|
202
|
+
|
|
194
203
|
} else {
|
|
195
204
|
throw new Error(`Failed to decode color '${c}'`);
|
|
196
205
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* @param {number[]|Float32Array|Float64Array} result
|
|
4
|
+
* @param {{x:number,y:number,z:number}} min
|
|
5
|
+
* @param {{x:number,y:number,z:number}} max
|
|
6
|
+
*/
|
|
7
|
+
export function aabb3_from_min_max(result, min, max) {
|
|
8
|
+
result[0] = min.x;
|
|
9
|
+
result[1] = min.y;
|
|
10
|
+
result[2] = min.z;
|
|
11
|
+
|
|
12
|
+
result[3] = max.x;
|
|
13
|
+
result[4] = max.y;
|
|
14
|
+
result[5] = max.z;
|
|
15
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { assert } from "../../../assert.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* @param {number[]|Float32Array} result
|
|
6
|
+
* @param {number[]|Float32Array|Float64Array} aabb_corners
|
|
7
|
+
* @param {number[]|Float32Array} projection_matrix
|
|
8
|
+
*/
|
|
9
|
+
export function aabb3_matrix4_project_by_corners(result, aabb_corners, projection_matrix) {
|
|
10
|
+
assert.greaterThanOrEqual(result.length, 6, 'result.length must >= 6');
|
|
11
|
+
assert.greaterThanOrEqual(aabb_corners.length, 24, 'aabb_corners.length must >= 24');
|
|
12
|
+
assert.greaterThanOrEqual(projection_matrix.length, 16, 'projection_matrix.length must >= 16');
|
|
13
|
+
|
|
14
|
+
// read matrix into local variables for speed
|
|
15
|
+
const a0 = projection_matrix[0];
|
|
16
|
+
const a1 = projection_matrix[1];
|
|
17
|
+
const a2 = projection_matrix[2];
|
|
18
|
+
const a3 = projection_matrix[3];
|
|
19
|
+
|
|
20
|
+
const b0 = projection_matrix[4];
|
|
21
|
+
const b1 = projection_matrix[5];
|
|
22
|
+
const b2 = projection_matrix[6];
|
|
23
|
+
const b3 = projection_matrix[7];
|
|
24
|
+
|
|
25
|
+
const c0 = projection_matrix[8];
|
|
26
|
+
const c1 = projection_matrix[9];
|
|
27
|
+
const c2 = projection_matrix[10];
|
|
28
|
+
const c3 = projection_matrix[11];
|
|
29
|
+
|
|
30
|
+
const d0 = projection_matrix[12];
|
|
31
|
+
const d1 = projection_matrix[13];
|
|
32
|
+
const d2 = projection_matrix[14];
|
|
33
|
+
const d3 = projection_matrix[15];
|
|
34
|
+
|
|
35
|
+
// initialize bounds
|
|
36
|
+
let x0 = Number.POSITIVE_INFINITY;
|
|
37
|
+
let y0 = Number.POSITIVE_INFINITY;
|
|
38
|
+
let z0 = Number.POSITIVE_INFINITY;
|
|
39
|
+
|
|
40
|
+
let x1 = Number.NEGATIVE_INFINITY;
|
|
41
|
+
let y1 = Number.NEGATIVE_INFINITY;
|
|
42
|
+
let z1 = Number.NEGATIVE_INFINITY;
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
for (let i = 0; i < 24; i += 3) {
|
|
46
|
+
|
|
47
|
+
// read corner
|
|
48
|
+
const _x = aabb_corners[i];
|
|
49
|
+
const _y = aabb_corners[i + 1];
|
|
50
|
+
const _z = aabb_corners[i + 2];
|
|
51
|
+
|
|
52
|
+
// apply transform
|
|
53
|
+
const t_x = a0 * _x + b0 * _y + c0 * _z + d0;
|
|
54
|
+
const t_y = a1 * _x + b1 * _y + c1 * _z + d1;
|
|
55
|
+
const t_z = a2 * _x + b2 * _y + c2 * _z + d2;
|
|
56
|
+
const t_w = a3 * _x + b3 * _y + c3 * _z + d3;
|
|
57
|
+
|
|
58
|
+
// perspective divide and normalization (-1,1 space projected to -0.5,0.5)
|
|
59
|
+
const d = 1 / t_w;
|
|
60
|
+
|
|
61
|
+
// finally compute screen-space coordinates of the corner
|
|
62
|
+
const x = t_x * d;
|
|
63
|
+
const y = t_y * d;
|
|
64
|
+
const z = t_z * d;
|
|
65
|
+
|
|
66
|
+
if (x0 > x) {
|
|
67
|
+
x0 = x;
|
|
68
|
+
}
|
|
69
|
+
if (x1 < x) {
|
|
70
|
+
x1 = x;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (y0 > y) {
|
|
74
|
+
y0 = y;
|
|
75
|
+
}
|
|
76
|
+
if (y1 < y) {
|
|
77
|
+
y1 = y;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (z0 > z) {
|
|
81
|
+
z0 = z;
|
|
82
|
+
}
|
|
83
|
+
if (z1 < z) {
|
|
84
|
+
z1 = z;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
result[0] = x0;
|
|
90
|
+
result[1] = y0;
|
|
91
|
+
result[2] = z0;
|
|
92
|
+
|
|
93
|
+
result[3] = x1;
|
|
94
|
+
result[4] = y1;
|
|
95
|
+
result[5] = z1;
|
|
96
|
+
}
|
package/{engine/graphics/micron/render/v1 → core/geom/3d}/apply_mat4_transform_to_v3_array.js
RENAMED
|
File without changes
|
package/{engine/graphics/micron/build/bounds → core/geom/3d}/compute_bounding_cone_of_2_cones.js
RENAMED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
//
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
import Vector3 from "
|
|
5
|
-
import Quaternion, { quat3_createFromAxisAngle } from "
|
|
6
|
-
import { max2 } from "
|
|
4
|
+
import Vector3 from "../Vector3.js";
|
|
5
|
+
import Quaternion, { quat3_createFromAxisAngle } from "../Quaternion.js";
|
|
6
|
+
import { max2 } from "../../math/max2.js";
|
|
7
7
|
|
|
8
8
|
const tangent = new Vector3();
|
|
9
9
|
|
package/{engine/graphics/micron/build/bounds → core/geom/3d}/compute_bounding_sphere_of_2_spheres.js
RENAMED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
import { vec3 } from "gl-matrix";
|
|
5
|
-
import { Miniball } from "
|
|
6
|
-
import { PointSet } from "
|
|
7
|
-
import { max2 } from "
|
|
5
|
+
import { Miniball } from "../packing/miniball/Miniball.js";
|
|
6
|
+
import { PointSet } from "../packing/miniball/PointSet.js";
|
|
7
|
+
import { max2 } from "../../math/max2.js";
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
*
|
|
File without changes
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { v3_length } from "
|
|
1
|
+
import { v3_length } from "../../Vector3.js";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
*
|
|
@@ -21,7 +21,7 @@ function array_set_plane_normalized(destination, destination_offset, x, y, z, w)
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
/**
|
|
24
|
-
*
|
|
24
|
+
* Set frustum from projection matrix
|
|
25
25
|
* @param {number[]|Float32Array} frustum_planes
|
|
26
26
|
* @param {number[]} me
|
|
27
27
|
*/
|
|
File without changes
|