@woosh/meep-engine 2.33.3 → 2.33.8
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/bvh2/LeafNode.js +6 -1
- package/core/bvh2/aabb3/AABB3.js +21 -1
- package/core/bvh2/aabb3/aabb3_intersects_frustum.js +10 -2
- package/core/collection/RingBuffer.js +40 -10
- package/core/collection/array/copyArray.js +2 -2
- package/core/collection/array/typed/typed_array_copy.js +2 -2
- 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/RowFirstTableSpec.js +8 -0
- package/core/color/Color.js +1 -0
- package/core/color/ColorUtils.js +12 -3
- package/core/geom/3d/aabb/aabb3_compute_projected_area.js +6 -4
- package/core/geom/3d/aabb/aabb3_estimate_projected_area2.js +59 -0
- package/core/geom/3d/aabb/aabb3_from_min_max.js +15 -0
- package/core/geom/3d/aabb/aabb3_matrix4_project.js +33 -0
- package/core/geom/3d/aabb/aabb3_matrix4_project.spec.js +41 -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/core/geom/3d/frustum/array_normalize_plane.js +25 -0
- package/core/geom/3d/frustum/array_setFromProjectionMatrix.js +60 -0
- 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/undo/ActionProcessor.d.ts +2 -0
- package/core/process/undo/ActionProcessor.js +59 -1
- package/core/process/undo/ActionProcessor.spec.js +59 -0
- package/core/process/undo/Mark.js +2 -1
- package/engine/Engine.d.ts +2 -0
- package/engine/EngineHarness.js +4 -4
- package/engine/asset/loaders/material/bitmap2sampler_gl.js +19 -0
- package/engine/asset/loaders/material/computeImageBitmapEquality.js +7 -19
- package/engine/ecs/transform/Transform.js +2 -1
- package/engine/graphics/GraphicsEngine.js +9 -116
- 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/filter/FlipArrayInPlace.js +25 -0
- package/engine/graphics/filter/FlipArrayViaCanvas.js +13 -0
- package/engine/graphics/filter/ImageFilter.js +20 -51
- 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/geometry/instancing/InstancedMeshGroup.js +25 -16
- package/engine/graphics/material/SplatMaterial.js +4 -97
- package/engine/graphics/micron/build/buildMicronGeometryFromBufferGeometry.js +2 -6
- 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/fill_patch_geometry_data.js +2 -0
- 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/MicronGeometryBufferAttributeSpec.js +1 -1
- package/engine/graphics/micron/format/MicronGeometryPatch.js +11 -3
- package/engine/graphics/micron/format/MicronVertexDataSpec.js +25 -3
- package/engine/graphics/micron/prototypeVirtualGeometry.js +4 -4
- package/engine/graphics/micron/render/VirtualGeometryBuilder.js +28 -26
- package/engine/graphics/micron/render/culling/{PathCullingSystem.js → PatchCullingSystem.js} +1 -1
- package/engine/graphics/micron/render/instanced/AttributeDataTexture.js +2 -4
- package/engine/graphics/micron/render/refinement/ActivePatchList.js +40 -80
- package/engine/graphics/micron/render/refinement/ActivePatchRecord.js +4 -2
- package/engine/graphics/micron/render/refinement/RefinementSpec.js +98 -0
- package/engine/graphics/micron/render/v1/MaterialVertexSpec.js +21 -0
- package/engine/graphics/micron/render/v1/VGThreeRenderer.js +12 -9
- package/engine/graphics/micron/render/v1/getTransformedPositionsCached.js +1 -1
- package/engine/graphics/render/buffer/buffers/ColorAndDepthFrameBuffer.js +5 -3
- package/engine/graphics/render/buffer/buffers/prototypeNormalFrameBuffer.js +8 -10
- package/engine/graphics/render/forward_plus/LightManager.js +5 -7
- package/engine/graphics/render/forward_plus/data/NumericType.js +9 -0
- package/engine/graphics/render/forward_plus/{TextureBackedMemoryRegion.js → data/TextureBackedMemoryRegion.js} +11 -190
- package/engine/graphics/render/forward_plus/data/channelCountToThreIntegerTextureType.js +16 -0
- package/engine/graphics/render/forward_plus/data/computeDataType.js +36 -0
- package/engine/graphics/render/forward_plus/data/computeThreeTextureFormat.js +18 -0
- package/engine/graphics/render/forward_plus/data/computeThreeTextureInternalFormatFromDataType.js +63 -0
- package/engine/graphics/render/forward_plus/data/computeThreeTextureTypeFromDataType.js +41 -0
- package/engine/graphics/render/forward_plus/plugin/ptototypeFPPlugin.js +1 -1
- package/engine/graphics/render/forward_plus/prototypeLightManager.js +1 -1
- package/engine/graphics/render/visibility/hiz/buffer/HierarchicalZBuffer.js +198 -0
- package/engine/graphics/render/visibility/hiz/buffer/ReductionShader.js +51 -0
- package/engine/graphics/render/visibility/hiz/buildCanvasViewFromTexture.js +179 -0
- package/engine/graphics/render/visibility/hiz/prototypeHiZ.js +435 -0
- package/engine/graphics/render/visibility/hiz/query/BatchOcclusionQuery.js +174 -0
- package/engine/graphics/render/visibility/hiz/query/QueryShader.js +173 -0
- package/engine/graphics/shadows/ShadowMapRenderer.js +12 -2
- package/engine/graphics/texture/cubemap/buildCubeURLs.js +13 -0
- package/engine/graphics/texture/cubemap/load_environment_map.d.ts +8 -0
- package/engine/graphics/texture/cubemap/load_environment_map.js +163 -0
- package/engine/graphics/texture/sampler/Sampler2D.js +18 -62
- package/engine/graphics/texture/sampler/convertTexture2Sampler2D.js +3 -2
- package/engine/graphics/texture/sampler/debug/paintSamplerOnHTML.js +3 -2
- package/engine/graphics/texture/sampler/differenceSampler.js +31 -0
- package/engine/graphics/texture/sampler/typedArrayConstructorByInstance.js +25 -0
- package/engine/graphics/texture/sampler/util/drawSamplerHTML.js +3 -2
- package/engine/graphics/texture/virtual/v2/ShaderUsage.js +6 -5
- package/engine/graphics/texture/virtual/v2/prototype.js +16 -6
- package/engine/plugin/EnginePluginManager.d.ts +9 -0
- package/engine/reference/v2/Reference.d.ts +7 -0
- package/package.json +1 -1
- package/view/minimap/gl/MinimapMarkersGL.js +2 -2
- package/engine/graphics/micron/build/clustering/cluster_mesh_vertices.js +0 -3
- package/engine/graphics/micron/render/RefinementSpec.js +0 -159
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
|
@@ -8,6 +8,7 @@ import { computeAABB3PlaneSide } from "../../geom/3d/aabb/computeAABB3PlaneSide.
|
|
|
8
8
|
import computeMortonCode from "../../geom/3d/morton/Morton.js";
|
|
9
9
|
import { _boxSurfaceArea2, intersectRay, intersectSegment } from "./AABB3Math.js";
|
|
10
10
|
import { aabb3_build_corners } from "../../geom/3d/aabb/aabb3_build_corners.js";
|
|
11
|
+
import { assert } from "../../assert.js";
|
|
11
12
|
|
|
12
13
|
|
|
13
14
|
/**
|
|
@@ -724,7 +725,9 @@ AABB3.prototype.getCorners = function (result) {
|
|
|
724
725
|
* @param {number} offset
|
|
725
726
|
*/
|
|
726
727
|
AABB3.prototype.writeToArray = function (result, offset) {
|
|
727
|
-
|
|
728
|
+
assert.isNonNegativeInteger(offset, 'offset');
|
|
729
|
+
|
|
730
|
+
result[offset] = this.x0;
|
|
728
731
|
result[offset + 1] = this.y0;
|
|
729
732
|
result[offset + 2] = this.z0;
|
|
730
733
|
|
|
@@ -733,6 +736,23 @@ AABB3.prototype.writeToArray = function (result, offset) {
|
|
|
733
736
|
result[offset + 5] = this.z1;
|
|
734
737
|
};
|
|
735
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
|
+
|
|
736
756
|
/**
|
|
737
757
|
* @param {THREE.Plane} plane
|
|
738
758
|
* @returns {int} 2,0,or -2; 2: above, -2 : below, 0 : intersects plane
|
|
@@ -7,6 +7,14 @@ import { aabb3_computeDistanceAbovePlane } from "../../geom/3d/aabb/aabb3_comput
|
|
|
7
7
|
* @return {boolean}
|
|
8
8
|
*/
|
|
9
9
|
export function aabb3_intersects_frustum(aabb, frustum) {
|
|
10
|
+
|
|
11
|
+
const x0 = aabb[0];
|
|
12
|
+
const y0 = aabb[1];
|
|
13
|
+
const z0 = aabb[2];
|
|
14
|
+
const x1 = aabb[3];
|
|
15
|
+
const y1 = aabb[4];
|
|
16
|
+
const z1 = aabb[5];
|
|
17
|
+
|
|
10
18
|
for (let i = 0; i < 24; i += 4) {
|
|
11
19
|
|
|
12
20
|
const plane_n_x = frustum[i];
|
|
@@ -16,8 +24,8 @@ export function aabb3_intersects_frustum(aabb, frustum) {
|
|
|
16
24
|
|
|
17
25
|
const plane_distance = aabb3_computeDistanceAbovePlane(
|
|
18
26
|
plane_n_x, plane_n_y, plane_n_z, plane_constant,
|
|
19
|
-
|
|
20
|
-
|
|
27
|
+
x0, y0, z0,
|
|
28
|
+
x1, y1, z1
|
|
21
29
|
);
|
|
22
30
|
|
|
23
31
|
if (plane_distance < 0) {
|
|
@@ -7,14 +7,32 @@ export class RingBuffer {
|
|
|
7
7
|
* @constructor
|
|
8
8
|
*/
|
|
9
9
|
constructor(size) {
|
|
10
|
-
assert.
|
|
10
|
+
assert.isNumber(size, 'size');
|
|
11
11
|
assert.greaterThan(size, 0, `size`);
|
|
12
|
+
assert.isNonNegativeInteger(size, 'size');
|
|
12
13
|
|
|
14
|
+
/**
|
|
15
|
+
*
|
|
16
|
+
* @type {number}
|
|
17
|
+
*/
|
|
13
18
|
this.size = size;
|
|
14
19
|
|
|
20
|
+
/**
|
|
21
|
+
*
|
|
22
|
+
* @type {number}
|
|
23
|
+
*/
|
|
15
24
|
this.head = 0;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
*
|
|
28
|
+
* @type {number}
|
|
29
|
+
*/
|
|
16
30
|
this.tail = 0;
|
|
17
31
|
|
|
32
|
+
/**
|
|
33
|
+
*
|
|
34
|
+
* @type {number}
|
|
35
|
+
*/
|
|
18
36
|
this.count = 0;
|
|
19
37
|
|
|
20
38
|
/**
|
|
@@ -62,13 +80,15 @@ export class RingBuffer {
|
|
|
62
80
|
|
|
63
81
|
this.data[head] = element;
|
|
64
82
|
|
|
65
|
-
const
|
|
83
|
+
const size = this.size;
|
|
84
|
+
|
|
85
|
+
const newHead = (head + 1) % size;
|
|
66
86
|
|
|
67
87
|
this.head = newHead;
|
|
68
88
|
|
|
69
|
-
if (this.count ===
|
|
89
|
+
if (this.count === size) {
|
|
70
90
|
//update tail
|
|
71
|
-
this.tail = (this.tail + 1) %
|
|
91
|
+
this.tail = (this.tail + 1) % size;
|
|
72
92
|
} else {
|
|
73
93
|
this.count++;
|
|
74
94
|
}
|
|
@@ -130,11 +150,15 @@ export class RingBuffer {
|
|
|
130
150
|
* @returns {V|undefined}
|
|
131
151
|
*/
|
|
132
152
|
removeIf(condition, thisArg) {
|
|
153
|
+
const count = this.count;
|
|
154
|
+
const size = this.size;
|
|
133
155
|
|
|
134
|
-
|
|
135
|
-
|
|
156
|
+
const tail = this.tail;
|
|
157
|
+
const data = this.data;
|
|
136
158
|
|
|
137
|
-
|
|
159
|
+
for (let i = 0; i < count; i++) {
|
|
160
|
+
const index = (tail + i) % size;
|
|
161
|
+
const el = data[index];
|
|
138
162
|
|
|
139
163
|
if (condition.call(thisArg, el)) {
|
|
140
164
|
|
|
@@ -151,10 +175,16 @@ export class RingBuffer {
|
|
|
151
175
|
* @param {*} [thisArg]
|
|
152
176
|
*/
|
|
153
177
|
forEach(visitor, thisArg) {
|
|
154
|
-
|
|
155
|
-
|
|
178
|
+
const count = this.count;
|
|
179
|
+
const size = this.size;
|
|
180
|
+
|
|
181
|
+
const tail = this.tail;
|
|
182
|
+
const data = this.data;
|
|
183
|
+
|
|
184
|
+
for (let i = 0; i < count; i++) {
|
|
156
185
|
|
|
157
|
-
const
|
|
186
|
+
const index = (tail + i) % size;
|
|
187
|
+
const el = data[index];
|
|
158
188
|
|
|
159
189
|
visitor.call(thisArg, el);
|
|
160
190
|
}
|
|
@@ -25,9 +25,9 @@ export function copyArray(source, target) {
|
|
|
25
25
|
* Follows Java System.arraycopy interface
|
|
26
26
|
* Copy data from one array to another
|
|
27
27
|
* @template T
|
|
28
|
-
* @param {T[]|ArrayLike<T>|TypedArray} source The source array
|
|
28
|
+
* @param {T[]|ArrayLike<T>|TypedArray|Uint8ClampedArray|Uint8Array} source The source array
|
|
29
29
|
* @param {number} source_position Starting position where to copy from inside the source array
|
|
30
|
-
* @param {T[]|ArrayLike<T>|TypedArray} destination The destination array
|
|
30
|
+
* @param {T[]|ArrayLike<T>|TypedArray|Uint8ClampedArray|Uint8Array} destination The destination array
|
|
31
31
|
* @param {number} destination_position Starting position where to copy to inside the destination array
|
|
32
32
|
* @param {number} length How many elements should be copied
|
|
33
33
|
*/
|
|
@@ -3,8 +3,8 @@ import { array_copy } from "../copyArray.js";
|
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
*
|
|
6
|
-
* @param {TypedArray} source
|
|
7
|
-
* @param {TypedArray} destination
|
|
6
|
+
* @param {TypedArray|Float32Array} source
|
|
7
|
+
* @param {TypedArray|Float32Array} destination
|
|
8
8
|
*/
|
|
9
9
|
export function typed_array_copy(source, destination) {
|
|
10
10
|
const destination_size = destination.length;
|
|
@@ -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
|
+
}
|
|
@@ -234,6 +234,14 @@ export function RowFirstTableSpec(types, endianType = EndianType.BigEndian) {
|
|
|
234
234
|
}
|
|
235
235
|
}
|
|
236
236
|
|
|
237
|
+
/**
|
|
238
|
+
*
|
|
239
|
+
* @return {number}
|
|
240
|
+
*/
|
|
241
|
+
RowFirstTableSpec.prototype.getColumnCount = function () {
|
|
242
|
+
return this.types.length;
|
|
243
|
+
}
|
|
244
|
+
|
|
237
245
|
/**
|
|
238
246
|
*
|
|
239
247
|
* @param {RowFirstTableSpec} other
|
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
|
}
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
|
+
* NOTE: Consider using an optimized aabb projection method based on Jim Arvo's Graphics Gems algorithm: https://stackoverflow.com/a/58630206/3973586
|
|
13
14
|
* Almost everything is inlined for speed
|
|
14
15
|
* @param {number[]} aabb_corners
|
|
15
16
|
* @param {number[]|mat4|Float32Array} projection_matrix
|
|
@@ -55,7 +56,7 @@ export function aabb3_project_to_2d(aabb_corners, projection_matrix) {
|
|
|
55
56
|
const t_w = a3 * _x + b3 * _y + c3 * _z + d3;
|
|
56
57
|
|
|
57
58
|
// perspective divide and normalization (-1,1 space projected to -0.5,0.5)
|
|
58
|
-
const d = 0.5 /
|
|
59
|
+
const d = 0.5 / t_w;
|
|
59
60
|
|
|
60
61
|
// finally compute screen-space coordinates of the corner
|
|
61
62
|
const x = t_x * d;
|
|
@@ -64,13 +65,14 @@ export function aabb3_project_to_2d(aabb_corners, projection_matrix) {
|
|
|
64
65
|
if (x0 > x) {
|
|
65
66
|
x0 = x;
|
|
66
67
|
}
|
|
67
|
-
if (y0 > y) {
|
|
68
|
-
y0 = y;
|
|
69
|
-
}
|
|
70
68
|
|
|
71
69
|
if (x1 < x) {
|
|
72
70
|
x1 = x;
|
|
73
71
|
}
|
|
72
|
+
|
|
73
|
+
if (y0 > y) {
|
|
74
|
+
y0 = y;
|
|
75
|
+
}
|
|
74
76
|
if (y1 < y) {
|
|
75
77
|
y1 = y;
|
|
76
78
|
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
const scratch_aabb = new Float32Array(4);
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* NOTE: tends to overestimate the area
|
|
6
|
+
* @param {number[]} aabb
|
|
7
|
+
* @param {number[]} matrix
|
|
8
|
+
* @return {number}
|
|
9
|
+
*/
|
|
10
|
+
export function aabb3_estimate_projected_area2(aabb, matrix) {
|
|
11
|
+
// extract translation from matrix
|
|
12
|
+
scratch_aabb[0] = scratch_aabb[2] = matrix[12];
|
|
13
|
+
scratch_aabb[1] = scratch_aabb[3] = matrix[13];
|
|
14
|
+
|
|
15
|
+
// apply 3x3 matrix transform
|
|
16
|
+
for (let i = 0; i < 2; i++) {
|
|
17
|
+
for (let j = 0; j < 3; j++) {
|
|
18
|
+
|
|
19
|
+
const m_a = i * 4 + j;
|
|
20
|
+
const m_v = matrix[m_a];
|
|
21
|
+
|
|
22
|
+
const a = m_v * aabb[j];
|
|
23
|
+
const b = m_v * aabb[j + 3];
|
|
24
|
+
|
|
25
|
+
if (a < b) {
|
|
26
|
+
scratch_aabb[i] += a;
|
|
27
|
+
scratch_aabb[i + 2] += b;
|
|
28
|
+
} else {
|
|
29
|
+
scratch_aabb[i] += b;
|
|
30
|
+
scratch_aabb[i + 2] += a;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
const x1 = scratch_aabb[2];
|
|
37
|
+
const x0 = scratch_aabb[0];
|
|
38
|
+
|
|
39
|
+
const dx = x1 - x0;
|
|
40
|
+
|
|
41
|
+
const y1 = scratch_aabb[3];
|
|
42
|
+
const y0 = scratch_aabb[1];
|
|
43
|
+
|
|
44
|
+
const dy = y1 - y0;
|
|
45
|
+
const a = dx * dy;
|
|
46
|
+
|
|
47
|
+
const cx = (aabb[0] + aabb[3]) * 0.5;
|
|
48
|
+
const cy = (aabb[1] + aabb[4]) * 0.5;
|
|
49
|
+
const cz = (aabb[2] + aabb[5]) * 0.5;
|
|
50
|
+
|
|
51
|
+
/* compute W projection value, using conservative estimate
|
|
52
|
+
@see https://twitter.com/SebAaltonen/status/1332332808979832832
|
|
53
|
+
@see https://gist.github.com/slembcke/b2b2af4dede1d5702a635dc2d0e45d54
|
|
54
|
+
*/
|
|
55
|
+
const w = matrix[3] * cx + matrix[7] * cy + matrix[11] * cz + matrix[15];
|
|
56
|
+
const d = 0.5 / Math.abs(w);
|
|
57
|
+
|
|
58
|
+
return a * d * d;
|
|
59
|
+
}
|
|
@@ -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,33 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* NOTE: Based on Transforming Axis-Aligned Bounding Boxes by Jim Arvo from "Graphics Gems", Academic Press, 1990
|
|
4
|
+
* @param {number[]} result
|
|
5
|
+
* @param {number[]} aabb
|
|
6
|
+
* @param {number[]} matrix 4x4 matrix
|
|
7
|
+
*/
|
|
8
|
+
export function aabb3_matrix4_project(result, aabb, matrix) {
|
|
9
|
+
// extract translation from matrix
|
|
10
|
+
result[0] = result[3] = matrix[12];
|
|
11
|
+
result[1] = result[4] = matrix[13];
|
|
12
|
+
result[2] = result[5] = matrix[14];
|
|
13
|
+
|
|
14
|
+
// apply 3x3 matrix transform
|
|
15
|
+
for (let i = 0; i < 3; i++) {
|
|
16
|
+
for (let j = 0; j < 3; j++) {
|
|
17
|
+
|
|
18
|
+
const m_a = i * 4 + j;
|
|
19
|
+
const m_v = matrix[m_a];
|
|
20
|
+
|
|
21
|
+
const a = m_v * aabb[j];
|
|
22
|
+
const b = m_v * aabb[j + 3];
|
|
23
|
+
|
|
24
|
+
if (a < b) {
|
|
25
|
+
result[i] += a;
|
|
26
|
+
result[i + 3] += b;
|
|
27
|
+
} else {
|
|
28
|
+
result[i] += b;
|
|
29
|
+
result[i + 3] += a;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { aabb3_matrix4_project } from "./aabb3_matrix4_project.js";
|
|
2
|
+
|
|
3
|
+
test('identity', () => {
|
|
4
|
+
const r = [];
|
|
5
|
+
|
|
6
|
+
aabb3_matrix4_project(r, [1, 2, 3, 5, 7, 9], [
|
|
7
|
+
1, 0, 0, 0,
|
|
8
|
+
0, 1, 0, 0,
|
|
9
|
+
0, 0, 1, 0,
|
|
10
|
+
0, 0, 0, 1
|
|
11
|
+
]);
|
|
12
|
+
|
|
13
|
+
expect(r).toEqual([1, 2, 3, 5, 7, 9]);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
test('translation case', () => {
|
|
17
|
+
const r = [];
|
|
18
|
+
|
|
19
|
+
aabb3_matrix4_project(r, [1, 2, 3, 5, 7, 9], [
|
|
20
|
+
1, 0, 0, 0,
|
|
21
|
+
0, 1, 0, 0,
|
|
22
|
+
0, 0, 1, 0,
|
|
23
|
+
13, -17, 23, 1
|
|
24
|
+
]);
|
|
25
|
+
|
|
26
|
+
expect(r).toEqual([14, -15, 26, 18, -10, 32]);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
test('scale case', () => {
|
|
31
|
+
const r = [];
|
|
32
|
+
|
|
33
|
+
aabb3_matrix4_project(r, [1, 2, 3, 5, 7, 9], [
|
|
34
|
+
-1, 0, 0, 0,
|
|
35
|
+
0, 2, 0, 0,
|
|
36
|
+
0, 0, -3, 0,
|
|
37
|
+
0, 0, 0, 1
|
|
38
|
+
]);
|
|
39
|
+
|
|
40
|
+
expect(r).toEqual([-5, 4, -27, -1, 14, -9]);
|
|
41
|
+
});
|
|
@@ -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
|