@woosh/meep-engine 2.33.36 → 2.33.40
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/binary/2/BinaryUint32BVH.js +3 -3
- package/core/collection/HashMap.js +19 -12
- package/core/collection/array/typed/typed_array_copy.js +2 -2
- package/core/collection/table/RowFirstTable.js +13 -8
- package/core/collection/table/RowFirstTableSpec.js +6 -0
- package/core/color/Color.js +5 -9
- package/core/color/ColorUtils.js +4 -150
- package/core/color/YCbCr_to_rgb_uint24.js +20 -0
- package/core/color/hsv2rgb.js +54 -0
- package/core/color/int2rgb.js +12 -0
- package/core/color/parseHex.js +18 -0
- package/core/color/rgb2hex.js +16 -0
- package/core/color/rgb2hsv.js +47 -0
- package/core/color/rgb2uint24.js +17 -0
- package/core/color/rgb_to_YCbCr_uint24.js +18 -0
- package/core/geom/3d/aabb/aabb3_matrix4_project_by_corners.js +1 -1
- package/core/geom/3d/aabb/compute_aabb_from_points.js +28 -0
- package/core/geom/3d/morton/mortonEncode_magicbits.js +7 -6
- package/core/geom/3d/morton/v3_morton_encode_transformed.js +15 -11
- package/core/geom/3d/plane/orient3d_fast.js +51 -0
- package/core/geom/3d/plane/plane_computeConvex3PlaneIntersection.js +5 -0
- package/core/geom/3d/tetrahedra/GetDepthForTetrahedronProbe.glsl +43 -0
- package/core/geom/3d/tetrahedra/compute_bounding_simplex_3d.js +177 -0
- package/core/geom/3d/tetrahedra/compute_bounding_simplex_3d.spec.js +66 -0
- package/core/geom/3d/tetrahedra/compute_circumsphere.js +271 -0
- package/core/geom/3d/tetrahedra/compute_delaunay_tetrahedral_mesh.js +50 -0
- package/core/geom/3d/tetrahedra/compute_delaunay_tetrahedral_mesh.spec.js +14 -0
- package/core/geom/3d/tetrahedra/point_in_tetrahedron_circumsphere.js +77 -0
- package/core/geom/3d/tetrahedra/tetrahedra_collection.js +454 -0
- package/core/geom/3d/tetrahedra/tetrahedron_contains_point.js +26 -0
- package/core/geom/Quaternion.js +4 -0
- package/core/math/hash/murmur3_32.js +39 -0
- package/core/process/undo/ActionProcessor.d.ts +2 -0
- package/core/process/undo/ActionProcessor.js +15 -4
- package/editor/tools/FoliagePaintTool.js +1 -1
- package/editor/tools/GridPaintTool.js +1 -1
- package/engine/asset/loaders/GLTFAssetLoader.js +4 -8
- package/engine/ecs/System.d.ts +24 -1
- package/engine/ecs/foliage/InstancedFoliage.js +45 -0
- package/engine/ecs/foliage/ecs/InstancedMeshLayer.js +4 -0
- package/engine/ecs/storage/BinaryBufferSerializer.js +48 -38
- package/engine/ecs/storage/binary/collection/BinaryCollectionSerializer.js +1 -1
- package/engine/ecs/terrain/ecs/splat/SplatMapOptimizerDebugger.js +1 -1
- package/engine/ecs/terrain/tiles/TerrainTile.js +1 -1
- package/engine/graphics/GraphicsEngine.js +7 -0
- package/engine/graphics/ecs/light/binding/fp/FPLightBinding.js +1 -1
- package/engine/graphics/ecs/mesh/Mesh.js +2 -2
- package/engine/graphics/ecs/mesh-v2/ShadedGeometry.js +13 -0
- package/engine/graphics/geometry/instancing/InstancedMeshGroup.js +339 -314
- package/engine/graphics/micron/prototypeVirtualGeometry.js +4 -1
- package/engine/graphics/micron/render/v1/VGThreeRenderer.js +6 -2
- package/engine/graphics/particles/node-based/rendering/billboard/ParticleBillboardShader.js +1 -1
- package/engine/graphics/particles/particular/engine/parameter/ParameterLookupTable.js +20 -24
- package/engine/graphics/particles/particular/engine/renderers/billboard/ParticleBillboardMaterial.js +100 -55
- package/engine/graphics/particles/particular/engine/shader/ShaderManager.js +7 -2
- package/engine/graphics/particles/particular/engine/utils/volume/ParticleVolume.js +1 -0
- package/engine/graphics/particles/particular/engine/utils/volume/prototypeParticleVolume.js +2 -2
- package/engine/graphics/render/buffer/simple-fx/DepthLimitedBlur.js +9 -4
- package/engine/graphics/render/buffer/simple-fx/ao/AmbientOcclusionPostProcessEffect.js +7 -1
- package/engine/graphics/render/forward_plus/LightManager.js +295 -51
- package/engine/graphics/render/forward_plus/LightManager.spec.js +1 -1
- package/engine/graphics/render/forward_plus/PointLightData.js +9 -13
- package/engine/graphics/render/forward_plus/cluster/compute_light_data_hash_0.js +1 -1
- package/engine/graphics/render/forward_plus/data/TextureBackedMemoryRegion.js +10 -1
- package/engine/graphics/render/forward_plus/debug/LightClusterVolumeMaterial.js +1 -1
- package/engine/graphics/render/forward_plus/debug/buildLightClusterWidget.js +3 -1
- package/engine/graphics/render/forward_plus/materials/FP_SHADER_CHUNK_ACCUMULATION.js +31 -18
- package/engine/graphics/render/forward_plus/materials/fp_build_fragment_shader.js +18 -4
- package/engine/graphics/render/forward_plus/model/AbstractLight.js +50 -0
- package/engine/graphics/render/forward_plus/model/Decal.js +68 -0
- package/engine/graphics/render/forward_plus/{PointLight.js → model/PointLight.js} +19 -11
- package/engine/graphics/render/forward_plus/{SpotLight.js → model/SpotLight.js} +20 -12
- package/engine/graphics/render/forward_plus/plugin/ForwardPlusRenderingPlugin.js +1 -1
- package/engine/graphics/render/forward_plus/plugin/ptototypeFPPlugin.js +6 -5
- package/engine/graphics/render/forward_plus/{prototypeLightManager.js → prototype/prototypeLightManager.js} +100 -25
- package/engine/graphics/render/forward_plus/query/query_bvh_frustum_from_texture.js +29 -20
- package/engine/graphics/render/visibility/IncrementalDeltaSet.d.ts +2 -0
- package/engine/graphics/render/visibility/IncrementalDeltaSet.js +1 -0
- package/engine/graphics/render/visibility/VisibilityComputer.js +8 -7
- package/engine/graphics/shaders/TerrainShader.js +5 -5
- package/engine/graphics/shadows/testShadowMapRendering.js +192 -0
- package/engine/graphics/texture/atlas/AbstractTextureAtlas.js +19 -0
- package/engine/graphics/texture/atlas/CachingTextureAtlas.js +99 -0
- package/engine/graphics/texture/atlas/ManagedTextureAtlas.js +19 -39
- package/engine/graphics/texture/atlas/ReferencedTextureAtlas.js +75 -0
- package/engine/graphics/texture/atlas/TextureAtlas.js +22 -2
- package/engine/reference/v2/Reference.d.ts +4 -0
- package/engine/reference/v2/Reference.js +3 -1
- package/package.json +2 -1
- package/view/elements/ColorPickerView.js +2 -1
|
@@ -434,11 +434,11 @@ export class BinaryUint32BVH {
|
|
|
434
434
|
* Assemble leaf nodes into hierarchy, set binary node bounds iteratively bottom up
|
|
435
435
|
*/
|
|
436
436
|
build() {
|
|
437
|
-
const
|
|
437
|
+
const binary_node_count = this.__node_count_binary;
|
|
438
438
|
|
|
439
|
-
const leaf_node_block_address =
|
|
439
|
+
const leaf_node_block_address = binary_node_count * BVH_BINARY_NODE_SIZE;
|
|
440
440
|
|
|
441
|
-
let level = Math.floor(Math.log(
|
|
441
|
+
let level = Math.floor(Math.log(binary_node_count) / Math.log(2));
|
|
442
442
|
|
|
443
443
|
let i, offset, level_node_count;
|
|
444
444
|
//NOTE: building first level separately allows to avoid some switching logic needed to determine what is the type of lower level node
|
|
@@ -57,8 +57,9 @@ export class HashMap {
|
|
|
57
57
|
capacity = DEFAULT_INITIAL_CAPACITY,
|
|
58
58
|
loadFactor = DEFAULT_LOAD_FACTOR
|
|
59
59
|
} = {}) {
|
|
60
|
-
|
|
61
|
-
assert.
|
|
60
|
+
|
|
61
|
+
assert.isFunction(keyHashFunction, 'keyHashFunction');
|
|
62
|
+
assert.isFunction(keyEqualityFunction, 'keyEqualityFunction');
|
|
62
63
|
|
|
63
64
|
/**
|
|
64
65
|
*
|
|
@@ -77,6 +78,10 @@ export class HashMap {
|
|
|
77
78
|
*/
|
|
78
79
|
this.records = [];
|
|
79
80
|
|
|
81
|
+
/**
|
|
82
|
+
*
|
|
83
|
+
* @type {number}
|
|
84
|
+
*/
|
|
80
85
|
this.size = 0;
|
|
81
86
|
|
|
82
87
|
|
|
@@ -245,21 +250,23 @@ export class HashMap {
|
|
|
245
250
|
const bucket_index = this.__compute_bucket_index(raw_hash);
|
|
246
251
|
const bucket = this.records[bucket_index];
|
|
247
252
|
|
|
248
|
-
if (bucket
|
|
249
|
-
return undefined;
|
|
250
|
-
}
|
|
253
|
+
if (bucket !== undefined) {
|
|
251
254
|
|
|
252
|
-
|
|
255
|
+
const bucketSize = bucket.length;
|
|
253
256
|
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
+
//check if key already exists
|
|
258
|
+
for (let i = 0; i < bucketSize; i++) {
|
|
259
|
+
const entry = bucket[i];
|
|
257
260
|
|
|
258
|
-
|
|
259
|
-
if (entryKey === key || this.keyEqualityFunction(entryKey, key)) {
|
|
261
|
+
const entryKey = entry.key;
|
|
260
262
|
|
|
261
|
-
|
|
263
|
+
if (entryKey === key || this.keyEqualityFunction(entryKey, key)) {
|
|
264
|
+
|
|
265
|
+
return entry.value;
|
|
266
|
+
|
|
267
|
+
}
|
|
262
268
|
}
|
|
269
|
+
|
|
263
270
|
}
|
|
264
271
|
|
|
265
272
|
//not found
|
|
@@ -3,8 +3,8 @@ import { array_copy } from "../copyArray.js";
|
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Assumes arrays have the same type
|
|
6
|
-
* @param {TypedArray|Float32Array} source
|
|
7
|
-
* @param {TypedArray|Float32Array} destination
|
|
6
|
+
* @param {TypedArray|Float32Array|Uint8Array} source
|
|
7
|
+
* @param {TypedArray|Float32Array|Uint8Array} destination
|
|
8
8
|
*/
|
|
9
9
|
export function typed_array_copy(source, destination) {
|
|
10
10
|
const destination_size = destination.length;
|
|
@@ -6,8 +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 { RowFirstTableSpec } from "./RowFirstTableSpec.js";
|
|
10
|
-
|
|
11
9
|
|
|
12
10
|
/**
|
|
13
11
|
*
|
|
@@ -15,9 +13,9 @@ import { RowFirstTableSpec } from "./RowFirstTableSpec.js";
|
|
|
15
13
|
* @constructor
|
|
16
14
|
*/
|
|
17
15
|
function RowFirstTable(spec) {
|
|
18
|
-
assert.
|
|
19
|
-
assert.
|
|
20
|
-
assert.
|
|
16
|
+
assert.defined(spec, 'spec');
|
|
17
|
+
assert.notNull(spec, 'spec');
|
|
18
|
+
assert.equal(spec.isRowFirstTableSpec, true, 'spec.isRowFirstTableSpec !== true');
|
|
21
19
|
|
|
22
20
|
/**
|
|
23
21
|
*
|
|
@@ -81,6 +79,10 @@ RowFirstTable.prototype.initialize = function () {
|
|
|
81
79
|
this.writeRowMethod = spec.writeRowMethod;
|
|
82
80
|
};
|
|
83
81
|
|
|
82
|
+
/**
|
|
83
|
+
*
|
|
84
|
+
* @returns {number}
|
|
85
|
+
*/
|
|
84
86
|
RowFirstTable.prototype.hash = function () {
|
|
85
87
|
// to keep hash calculation fast, do a fixed number evenly spaced taps inside the data table
|
|
86
88
|
|
|
@@ -97,7 +99,7 @@ RowFirstTable.prototype.hash = function () {
|
|
|
97
99
|
|
|
98
100
|
const dataView = this.dataView;
|
|
99
101
|
|
|
100
|
-
let result =
|
|
102
|
+
let result = byteLength;
|
|
101
103
|
|
|
102
104
|
for (let i = 0; i < step_count; i++) {
|
|
103
105
|
const address = i * step_size * 4;
|
|
@@ -285,7 +287,7 @@ RowFirstTable.prototype.addRow = function (values) {
|
|
|
285
287
|
|
|
286
288
|
this.writeRowMethod(this.dataView, this.bytesPerRecord * rowIndex, values);
|
|
287
289
|
|
|
288
|
-
this.on.added.
|
|
290
|
+
this.on.added.send2(rowIndex, values);
|
|
289
291
|
};
|
|
290
292
|
|
|
291
293
|
/**
|
|
@@ -311,7 +313,7 @@ RowFirstTable.prototype.addRows = function (count, valueSupplier) {
|
|
|
311
313
|
|
|
312
314
|
function addOneSignaling(index) {
|
|
313
315
|
addOneSilent(index);
|
|
314
|
-
onAdded.
|
|
316
|
+
onAdded.send2(index, row);
|
|
315
317
|
}
|
|
316
318
|
|
|
317
319
|
function addOneSilent(i) {
|
|
@@ -432,6 +434,9 @@ RowFirstTable.prototype.toRowArray = function () {
|
|
|
432
434
|
|
|
433
435
|
};
|
|
434
436
|
|
|
437
|
+
/**
|
|
438
|
+
* Print the table to console
|
|
439
|
+
*/
|
|
435
440
|
RowFirstTable.prototype.printToConsole = function () {
|
|
436
441
|
const rows = this.toRowArray();
|
|
437
442
|
|
|
@@ -237,6 +237,12 @@ RowFirstTableSpec.prototype.equals = function (other) {
|
|
|
237
237
|
return isArrayEqualStrict(this.types, other.types);
|
|
238
238
|
};
|
|
239
239
|
|
|
240
|
+
/**
|
|
241
|
+
* @readonly
|
|
242
|
+
* @type {boolean}
|
|
243
|
+
*/
|
|
244
|
+
RowFirstTableSpec.prototype.isRowFirstTableSpec = true;
|
|
245
|
+
|
|
240
246
|
|
|
241
247
|
const cache = new Cache({
|
|
242
248
|
keyHashFunction: computeStringHash
|
package/core/color/Color.js
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { assert } from "../assert.js";
|
|
2
2
|
import Signal from "../events/signal/Signal.js";
|
|
3
|
-
import { parseColor
|
|
3
|
+
import { parseColor } from "./ColorUtils.js";
|
|
4
4
|
import { clamp } from "../math/clamp.js";
|
|
5
5
|
import { min2 } from "../math/min2.js";
|
|
6
6
|
import { max2 } from "../math/max2.js";
|
|
7
7
|
import { min3 } from "../math/min3.js";
|
|
8
8
|
import { computeHashIntegerArray } from "../collection/array/computeHashIntegerArray.js";
|
|
9
9
|
import { computeHashFloat } from "../math/hash/computeHashFloat.js";
|
|
10
|
+
import { rgb2hsv } from "./rgb2hsv.js";
|
|
11
|
+
import { rgb2uint24 } from "./rgb2uint24.js";
|
|
10
12
|
|
|
11
13
|
class Color {
|
|
12
14
|
/**
|
|
@@ -273,14 +275,8 @@ class Color {
|
|
|
273
275
|
* @returns {number}
|
|
274
276
|
*/
|
|
275
277
|
toUint() {
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
const b = Math.round(this.b * 255);
|
|
279
|
-
|
|
280
|
-
return (b & 0xFF)
|
|
281
|
-
| (g & 0xFF) << 8
|
|
282
|
-
| (r & 0xFF) << 16
|
|
283
|
-
;
|
|
278
|
+
|
|
279
|
+
return rgb2uint24(this.r, this.g, this.b);
|
|
284
280
|
}
|
|
285
281
|
|
|
286
282
|
/**
|
package/core/color/ColorUtils.js
CHANGED
|
@@ -2,149 +2,9 @@
|
|
|
2
2
|
* Created by Alex on 02/05/2016.
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { hsv2rgb } from "./hsv2rgb.js";
|
|
6
|
+
import { parseHex } from "./parseHex.js";
|
|
6
7
|
|
|
7
|
-
/**
|
|
8
|
-
*
|
|
9
|
-
* @param {number} h from 0 to 1
|
|
10
|
-
* @param {number} s from 0 to 1
|
|
11
|
-
* @param {number} v from 0 to 1
|
|
12
|
-
* @returns {{r: number, g: number, b: number}}
|
|
13
|
-
*/
|
|
14
|
-
function hsv2rgb(h, s, v) {
|
|
15
|
-
|
|
16
|
-
let _h = h % 1;
|
|
17
|
-
|
|
18
|
-
if (_h < 0) {
|
|
19
|
-
_h = h + 1;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const _s = clamp(s, 0, 1);
|
|
23
|
-
const _v = clamp(v, 0, 1);
|
|
24
|
-
|
|
25
|
-
let r, g, b, i, f, p, q, t;
|
|
26
|
-
|
|
27
|
-
i = Math.floor(h * 6);
|
|
28
|
-
f = _h * 6 - i;
|
|
29
|
-
p = _v * (1 - _s);
|
|
30
|
-
q = _v * (1 - f * _s);
|
|
31
|
-
t = _v * (1 - (1 - f) * _s);
|
|
32
|
-
switch (i % 6) {
|
|
33
|
-
case 0:
|
|
34
|
-
r = _v, g = t, b = p;
|
|
35
|
-
break;
|
|
36
|
-
case 1:
|
|
37
|
-
r = q, g = _v, b = p;
|
|
38
|
-
break;
|
|
39
|
-
case 2:
|
|
40
|
-
r = p, g = _v, b = t;
|
|
41
|
-
break;
|
|
42
|
-
case 3:
|
|
43
|
-
r = p, g = q, b = _v;
|
|
44
|
-
break;
|
|
45
|
-
case 4:
|
|
46
|
-
r = t, g = p, b = _v;
|
|
47
|
-
break;
|
|
48
|
-
case 5:
|
|
49
|
-
r = _v, g = p, b = q;
|
|
50
|
-
break;
|
|
51
|
-
}
|
|
52
|
-
return {
|
|
53
|
-
r: Math.round(r * 255),
|
|
54
|
-
g: Math.round(g * 255),
|
|
55
|
-
b: Math.round(b * 255)
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
*
|
|
61
|
-
* @param {number} r 0 to 255
|
|
62
|
-
* @param {number} g 0 to 255
|
|
63
|
-
* @param {number} b 0 to 255
|
|
64
|
-
* @returns {{h: number, s: number, v: number}}
|
|
65
|
-
*/
|
|
66
|
-
export function rgb2hsv(r, g, b) {
|
|
67
|
-
|
|
68
|
-
r /= 255;
|
|
69
|
-
g /= 255;
|
|
70
|
-
b /= 255;
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
const max = Math.max(r, g, b);
|
|
74
|
-
const min = Math.min(r, g, b);
|
|
75
|
-
|
|
76
|
-
var h, s, v = max;
|
|
77
|
-
|
|
78
|
-
var d = max - min;
|
|
79
|
-
|
|
80
|
-
s = max === 0 ? 0 : d / max;
|
|
81
|
-
|
|
82
|
-
if (max === min) {
|
|
83
|
-
h = 0; // achromatic
|
|
84
|
-
} else {
|
|
85
|
-
switch (max) {
|
|
86
|
-
case r:
|
|
87
|
-
h = (g - b) / d + (g < b ? 6 : 0);
|
|
88
|
-
break;
|
|
89
|
-
case g:
|
|
90
|
-
h = (b - r) / d + 2;
|
|
91
|
-
break;
|
|
92
|
-
case b:
|
|
93
|
-
h = (r - g) / d + 4;
|
|
94
|
-
break;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
h /= 6;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
return {
|
|
101
|
-
h,
|
|
102
|
-
s,
|
|
103
|
-
v
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
*
|
|
109
|
-
* @param {string} hex
|
|
110
|
-
* @returns {{r: Number, g: Number, b: Number}} rgb
|
|
111
|
-
*/
|
|
112
|
-
function parseHex(hex) {
|
|
113
|
-
function hex2dec(v) {
|
|
114
|
-
return parseInt(v, 16)
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
return {
|
|
118
|
-
r: hex2dec(hex.slice(1, 3)),
|
|
119
|
-
g: hex2dec(hex.slice(3, 5)),
|
|
120
|
-
b: hex2dec(hex.slice(5))
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
*
|
|
127
|
-
* @param r
|
|
128
|
-
* @param g
|
|
129
|
-
* @param b
|
|
130
|
-
* @returns {string}
|
|
131
|
-
*/
|
|
132
|
-
function rgb2hex(r, g, b) {
|
|
133
|
-
function dec2hex(c) {
|
|
134
|
-
const hex = c.toString(16);
|
|
135
|
-
return hex.length === 1 ? "0" + hex : hex;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
return dec2hex(r) + dec2hex(g) + dec2hex(b);
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
function int2rgb(value) {
|
|
142
|
-
return {
|
|
143
|
-
r: (value >> 16) & 255,
|
|
144
|
-
g: (value >> 8) & 255,
|
|
145
|
-
b: (value) & 255
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
8
|
|
|
149
9
|
const rgbRegEx = /rgb\(([0-9]+),\s*([0-9]+),\s*([0-9]+)\)/;
|
|
150
10
|
const hsvRegEx = /hsv\(([0-9]+(?:\.[0-9]*)?),\s*([0-9]+(?:\.[0-9]*)?),\s*([0-9]+(?:\.[0-9]*)?)\)/;
|
|
@@ -152,7 +12,7 @@ const hsvRegEx = /hsv\(([0-9]+(?:\.[0-9]*)?),\s*([0-9]+(?:\.[0-9]*)?),\s*([0-9]+
|
|
|
152
12
|
/**
|
|
153
13
|
*
|
|
154
14
|
* @param {string|number} c
|
|
155
|
-
* @returns {number[]} Numeric array, values are in
|
|
15
|
+
* @returns {number[]} Numeric array, values are in Uint8 range (0...255)
|
|
156
16
|
*/
|
|
157
17
|
export function parseColor(c) {
|
|
158
18
|
|
|
@@ -194,7 +54,7 @@ export function parseColor(c) {
|
|
|
194
54
|
} else {
|
|
195
55
|
throw new Error(`Failed to decode color string '${c}' `);
|
|
196
56
|
}
|
|
197
|
-
} else if(type_of_code === 'number'){
|
|
57
|
+
} else if (type_of_code === 'number') {
|
|
198
58
|
|
|
199
59
|
result[0] = c >> 16;
|
|
200
60
|
result[1] = (c >> 8) & 0xFF;
|
|
@@ -207,9 +67,3 @@ export function parseColor(c) {
|
|
|
207
67
|
return result;
|
|
208
68
|
}
|
|
209
69
|
|
|
210
|
-
export {
|
|
211
|
-
hsv2rgb,
|
|
212
|
-
parseHex,
|
|
213
|
-
rgb2hex,
|
|
214
|
-
int2rgb
|
|
215
|
-
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @see https://en.wikipedia.org/wiki/YUV
|
|
3
|
+
* @param {number} Y
|
|
4
|
+
* @param {number} Cb
|
|
5
|
+
* @param {number} Cr
|
|
6
|
+
* @returns {number}
|
|
7
|
+
*/
|
|
8
|
+
export function YCbCr_to_rgb_uint24(Y, Cb, Cr) {
|
|
9
|
+
const _Cr = Cr - 128;
|
|
10
|
+
const _Cb = Cb - 128;
|
|
11
|
+
|
|
12
|
+
const r = Y + _Cr + (_Cr >> 2) + (_Cr >> 3) + (_Cr >> 5);
|
|
13
|
+
const g = Y - ((_Cb >> 2) + (_Cb >> 4) + (_Cb >> 5)) - ((_Cr >> 1) + (_Cr >> 3) + (_Cr >> 4) + (_Cr >> 5));
|
|
14
|
+
const b = Y + _Cb + (_Cb >> 1) + (_Cb >> 2) + (_Cb >> 6);
|
|
15
|
+
|
|
16
|
+
return (b & 0xFF)
|
|
17
|
+
| (g & 0xFF) << 8
|
|
18
|
+
| (r & 0xFF) << 16
|
|
19
|
+
;
|
|
20
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { clamp } from "../math/clamp.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* @param {number} h from 0 to 1
|
|
6
|
+
* @param {number} s from 0 to 1
|
|
7
|
+
* @param {number} v from 0 to 1
|
|
8
|
+
* @returns {{r: number, g: number, b: number}}
|
|
9
|
+
*/
|
|
10
|
+
export function hsv2rgb(h, s, v) {
|
|
11
|
+
|
|
12
|
+
let _h = h % 1;
|
|
13
|
+
|
|
14
|
+
if (_h < 0) {
|
|
15
|
+
_h = h + 1;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const _s = clamp(s, 0, 1);
|
|
19
|
+
const _v = clamp(v, 0, 1);
|
|
20
|
+
|
|
21
|
+
let r, g, b, i, f, p, q, t;
|
|
22
|
+
|
|
23
|
+
i = Math.floor(h * 6);
|
|
24
|
+
f = _h * 6 - i;
|
|
25
|
+
p = _v * (1 - _s);
|
|
26
|
+
q = _v * (1 - f * _s);
|
|
27
|
+
t = _v * (1 - (1 - f) * _s);
|
|
28
|
+
switch (i % 6) {
|
|
29
|
+
case 0:
|
|
30
|
+
r = _v, g = t, b = p;
|
|
31
|
+
break;
|
|
32
|
+
case 1:
|
|
33
|
+
r = q, g = _v, b = p;
|
|
34
|
+
break;
|
|
35
|
+
case 2:
|
|
36
|
+
r = p, g = _v, b = t;
|
|
37
|
+
break;
|
|
38
|
+
case 3:
|
|
39
|
+
r = p, g = q, b = _v;
|
|
40
|
+
break;
|
|
41
|
+
case 4:
|
|
42
|
+
r = t, g = p, b = _v;
|
|
43
|
+
break;
|
|
44
|
+
case 5:
|
|
45
|
+
r = _v, g = p, b = q;
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
return {
|
|
49
|
+
r: Math.round(r * 255),
|
|
50
|
+
g: Math.round(g * 255),
|
|
51
|
+
b: Math.round(b * 255)
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
function hex2dec(v) {
|
|
2
|
+
return parseInt(v, 16)
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
*
|
|
7
|
+
* @param {string} hex
|
|
8
|
+
* @returns {{r: Number, g: Number, b: Number}} rgb
|
|
9
|
+
*/
|
|
10
|
+
export function parseHex(hex) {
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
return {
|
|
14
|
+
r: hex2dec(hex.slice(1, 3)),
|
|
15
|
+
g: hex2dec(hex.slice(3, 5)),
|
|
16
|
+
b: hex2dec(hex.slice(5))
|
|
17
|
+
};
|
|
18
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
function dec2hex(c) {
|
|
2
|
+
const hex = c.toString(16);
|
|
3
|
+
return hex.length === 1 ? "0" + hex : hex;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
*
|
|
8
|
+
* @param {number} r
|
|
9
|
+
* @param {number} g
|
|
10
|
+
* @param {number} b
|
|
11
|
+
* @returns {string}
|
|
12
|
+
*/
|
|
13
|
+
export function rgb2hex(r, g, b) {
|
|
14
|
+
|
|
15
|
+
return dec2hex(r) + dec2hex(g) + dec2hex(b);
|
|
16
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* @param {number} r 0 to 255
|
|
4
|
+
* @param {number} g 0 to 255
|
|
5
|
+
* @param {number} b 0 to 255
|
|
6
|
+
* @returns {{h: number, s: number, v: number}}
|
|
7
|
+
*/
|
|
8
|
+
export function rgb2hsv(r, g, b) {
|
|
9
|
+
|
|
10
|
+
r /= 255;
|
|
11
|
+
g /= 255;
|
|
12
|
+
b /= 255;
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
const max = Math.max(r, g, b);
|
|
16
|
+
const min = Math.min(r, g, b);
|
|
17
|
+
|
|
18
|
+
var h, s, v = max;
|
|
19
|
+
|
|
20
|
+
var d = max - min;
|
|
21
|
+
|
|
22
|
+
s = max === 0 ? 0 : d / max;
|
|
23
|
+
|
|
24
|
+
if (max === min) {
|
|
25
|
+
h = 0; // achromatic
|
|
26
|
+
} else {
|
|
27
|
+
switch (max) {
|
|
28
|
+
case r:
|
|
29
|
+
h = (g - b) / d + (g < b ? 6 : 0);
|
|
30
|
+
break;
|
|
31
|
+
case g:
|
|
32
|
+
h = (b - r) / d + 2;
|
|
33
|
+
break;
|
|
34
|
+
case b:
|
|
35
|
+
h = (r - g) / d + 4;
|
|
36
|
+
break;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
h /= 6;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return {
|
|
43
|
+
h,
|
|
44
|
+
s,
|
|
45
|
+
v
|
|
46
|
+
};
|
|
47
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* @param {number} r
|
|
4
|
+
* @param {number} g
|
|
5
|
+
* @param {number} b
|
|
6
|
+
* @returns {number}
|
|
7
|
+
*/
|
|
8
|
+
export function rgb2uint24(r,g,b){
|
|
9
|
+
const _r = Math.round(r * 255);
|
|
10
|
+
const _g = Math.round(g * 255);
|
|
11
|
+
const _b = Math.round(b * 255);
|
|
12
|
+
|
|
13
|
+
return (_b & 0xFF)
|
|
14
|
+
| (_g & 0xFF) << 8
|
|
15
|
+
| (_r & 0xFF) << 16
|
|
16
|
+
;
|
|
17
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* @see https://en.wikipedia.org/wiki/YUV
|
|
4
|
+
* @param {number} r
|
|
5
|
+
* @param {number} g
|
|
6
|
+
* @param {number} b
|
|
7
|
+
* @returns {number}
|
|
8
|
+
*/
|
|
9
|
+
export function rgb_to_YCbCr_uint24(r, g, b) {
|
|
10
|
+
const Y = 0.299 * r + 0.587 * g + 0.114 * b;
|
|
11
|
+
const Cb = -0.169 * r - 0.331 * g + 0.499 * b + 128;
|
|
12
|
+
const Cr = 0.499 * g - 0.418 * g - 0.0813 * b + 128;
|
|
13
|
+
|
|
14
|
+
return (Cr & 0xFF)
|
|
15
|
+
| (Cb & 0xFF) << 8
|
|
16
|
+
| (Y & 0xFF) << 16
|
|
17
|
+
;
|
|
18
|
+
}
|
|
@@ -4,7 +4,7 @@ import { assert } from "../../../assert.js";
|
|
|
4
4
|
*
|
|
5
5
|
* @param {number[]|Float32Array} result
|
|
6
6
|
* @param {number[]|Float32Array|Float64Array} aabb_corners
|
|
7
|
-
* @param {number[]|Float32Array} projection_matrix
|
|
7
|
+
* @param {number[]|Float32Array|mat4} projection_matrix
|
|
8
8
|
*/
|
|
9
9
|
export function aabb3_matrix4_project_by_corners(result, aabb_corners, projection_matrix) {
|
|
10
10
|
assert.greaterThanOrEqual(result.length, 6, 'result.length must >= 6');
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { min2 } from "../../../math/min2.js";
|
|
2
|
+
import { max2 } from "../../../math/max2.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
*
|
|
6
|
+
* @param {number[]} result
|
|
7
|
+
* @param {number[]} input
|
|
8
|
+
* @param {number} input_count
|
|
9
|
+
* @param {number} d number of dimensions
|
|
10
|
+
*/
|
|
11
|
+
export function compute_aabb_from_points(result, input, input_count, d) {
|
|
12
|
+
let i = 0;
|
|
13
|
+
let j = 0;
|
|
14
|
+
|
|
15
|
+
for (; i < d; i++) {
|
|
16
|
+
result[i] = Infinity;
|
|
17
|
+
result[i + d] = -Infinity;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
for (i = 0; i < input_count; i++) {
|
|
21
|
+
for (j = 0; j < d; j++) {
|
|
22
|
+
const v = input[j];
|
|
23
|
+
|
|
24
|
+
result[j] = min2(result[j], v);
|
|
25
|
+
result[j + d] = max2(result[j + d], v);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* method to separate bits from a given integer 3 positions apart
|
|
3
3
|
* we only look at the first 10 bits
|
|
4
|
+
*
|
|
5
|
+
* @example when input is ABC, output bits are A00B00C
|
|
4
6
|
* @param {number} a
|
|
5
7
|
* @returns {number}
|
|
6
8
|
*/
|
|
7
|
-
function
|
|
9
|
+
function split_by_3(a) {
|
|
8
10
|
let x = a;
|
|
9
11
|
x = (x | x << 16) & 0x30000ff;
|
|
10
12
|
x = (x | x << 8) & 0x0300f00f;
|
|
@@ -25,10 +27,9 @@ function splitBy3(a) {
|
|
|
25
27
|
*/
|
|
26
28
|
export function mortonEncode_magicbits(x, y, z) {
|
|
27
29
|
|
|
28
|
-
const x_bits =
|
|
29
|
-
const y_bits =
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
return x_bits | y_bits | z_bit;
|
|
30
|
+
const x_bits = split_by_3(x);
|
|
31
|
+
const y_bits = split_by_3(y) << 1;
|
|
32
|
+
const z_bits = split_by_3(z) << 2;
|
|
33
33
|
|
|
34
|
+
return x_bits | y_bits | z_bits;
|
|
34
35
|
}
|