@woosh/meep-engine 2.47.34 → 2.47.36
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/build/bundle-worker-terrain.js +1 -1
- package/build/meep.cjs +43 -21
- package/build/meep.min.js +1 -1
- package/build/meep.module.js +43 -21
- package/editor/tools/FoliagePaintTool.js +3 -3
- package/editor/tools/GridPaintTool.js +2 -2
- package/package.json +1 -1
- package/src/core/binary/dec2hex.js +9 -0
- package/src/core/binary/hex2dec.js +8 -0
- package/src/core/color/Color.js +8 -0
- package/src/core/color/ColorUtils.js +2 -2
- package/src/core/color/{parseHex.js → hex2rgb.js} +3 -5
- package/src/core/color/rgb2hex.js +1 -4
- package/src/core/geom/3d/aabb/aabb3_intersects_aabb3.js +1 -1
- package/src/core/geom/3d/aabb/aabb3_transformed_compute_plane_side.js +65 -0
- package/src/core/geom/3d/topology/struct/TopoMesh.js +9 -3
- package/src/core/geom/AABB2.js +1 -1
- package/src/core/geom/Rectangle.js +2 -2
- package/src/core/math/computeGreatestCommonDivisor.js +30 -3
- package/src/core/math/{intersects1D.js → interval/intersects1D.js} +1 -1
- package/src/core/math/{overlap1D.js → interval/overlap1D.js} +1 -1
- package/src/core/math/mix.js +5 -7
- package/src/core/math/random/randomUint8.js +10 -0
- package/src/core/math/spline/spline_bezier3.js +26 -0
- package/src/core/math/spline/spline_bezier3_bounds.js +87 -0
- package/src/core/model/node-graph/node/NodeInstance.js +1 -0
- package/src/core/process/task/Task.js +8 -6
- package/src/engine/achievements/AchievementManager.js +1 -1
- package/src/engine/animation/TransitionFunctions.js +1 -1
- package/src/engine/animation/curve/AnimationCurve.js +93 -1
- package/src/engine/animation/curve/Keyframe.js +20 -0
- package/src/engine/animation/curve/compression/prototypeCurveCompression.js +3 -1
- package/src/engine/ecs/components/MeshCollider.js +5 -0
- package/src/engine/ecs/components/MonsterAI.js +5 -0
- package/src/engine/ecs/fow/shader/FogOfWarRenderer.js +1 -1
- package/src/engine/ecs/guid/GUID.js +257 -0
- package/src/engine/ecs/guid/GUID.spec.js +41 -0
- package/src/engine/ecs/guid/GUIDSerializationAdapter.js +25 -0
- package/src/engine/ecs/storage/binary/BinaryClassSerializationAdapter.js +11 -12
- package/src/engine/ecs/terrain/util/loadVisibleTerrainTiles.js +23 -9
- package/src/engine/graphics/camera/CameraShake.js +1 -1
- package/src/engine/graphics/ecs/camera/CameraClippingPlaneComputer.js +1 -1
- package/src/engine/graphics/ecs/decal/v2/Decal.js +8 -6
- package/src/engine/graphics/ecs/decal/v2/FPDecalSystem.d.ts +3 -0
- package/src/engine/graphics/ecs/decal/v2/FPDecalSystem.js +76 -0
- package/src/engine/intelligence/behavior/behavior_to_dot.js +11 -1
- package/src/engine/intelligence/behavior/decorator/AbstractDecoratorBehavior.js +6 -0
- package/src/engine/intelligence/behavior/util/behavior_traverse_tree.js +35 -0
- package/src/engine/scene/transitionToScene.js +4 -1
- package/src/view/elements/radial/RadialText.js +1 -1
- package/src/core/math/bezierCurve.js +0 -22
- /package/src/core/math/{isValueBetween.js → interval/isValueBetween.js} +0 -0
- /package/src/core/math/{isValueBetween.spec.js → interval/isValueBetween.spec.js} +0 -0
- /package/src/core/math/{isValueBetweenInclusive.js → interval/isValueBetweenInclusive.js} +0 -0
- /package/src/core/math/{isValueBetweenInclusive.spec.js → interval/isValueBetweenInclusive.spec.js} +0 -0
- /package/src/core/math/{overlap1D.spec.js → interval/overlap1D.spec.js} +0 -0
- /package/src/core/math/{cubicCurve.js → spline/cubicCurve.js} +0 -0
- /package/src/core/math/{cubicCurve.spec.js → spline/cubicCurve.spec.js} +0 -0
- /package/src/core/math/{makeCubicCurve.js → spline/makeCubicCurve.js} +0 -0
- /package/src/core/math/{makeCubicCurve.spec.js → spline/makeCubicCurve.spec.js} +0 -0
- /package/src/core/math/{quadraticCurve.js → spline/quadraticCurve.js} +0 -0
- /package/src/core/math/{quadraticCurve.spec.js → spline/quadraticCurve.spec.js} +0 -0
package/build/meep.module.js
CHANGED
|
@@ -47691,15 +47691,11 @@ function max2(a, b) {
|
|
|
47691
47691
|
}
|
|
47692
47692
|
|
|
47693
47693
|
/**
|
|
47694
|
+
*
|
|
47694
47695
|
* Produces a proportional mix of 2 values, a*(1-portion) + b*portion
|
|
47695
|
-
*
|
|
47696
|
-
* @param {number} b
|
|
47697
|
-
* @param {number} portion
|
|
47698
|
-
* @returns {number}
|
|
47696
|
+
* Same as lerp
|
|
47699
47697
|
*/
|
|
47700
|
-
|
|
47701
|
-
return a * (1 - portion) + b * portion;
|
|
47702
|
-
}
|
|
47698
|
+
const mix = lerp$1;
|
|
47703
47699
|
|
|
47704
47700
|
/**
|
|
47705
47701
|
* Color blending modes
|
|
@@ -57876,16 +57872,21 @@ function hsv2rgb(h, s, v) {
|
|
|
57876
57872
|
};
|
|
57877
57873
|
}
|
|
57878
57874
|
|
|
57875
|
+
/**
|
|
57876
|
+
* Converts string hex representation to a decimal integer
|
|
57877
|
+
* @param {string} v
|
|
57878
|
+
* @returns {number}
|
|
57879
|
+
*/
|
|
57879
57880
|
function hex2dec(v) {
|
|
57880
57881
|
return parseInt(v, 16)
|
|
57881
|
-
}
|
|
57882
|
-
|
|
57882
|
+
}
|
|
57883
|
+
|
|
57883
57884
|
/**
|
|
57884
57885
|
*
|
|
57885
|
-
* @param {string} hex
|
|
57886
|
+
* @param {string} hex expect form #FFFFFF or #FFFFFFFF for RGBA
|
|
57886
57887
|
* @returns {{r: number, g: number, b: number, a:number}} rgb
|
|
57887
57888
|
*/
|
|
57888
|
-
function
|
|
57889
|
+
function hex2rgb(hex) {
|
|
57889
57890
|
|
|
57890
57891
|
|
|
57891
57892
|
const result = {
|
|
@@ -57957,7 +57958,7 @@ function parseColor(c) {
|
|
|
57957
57958
|
|
|
57958
57959
|
} else if (cL.startsWith('#')) {
|
|
57959
57960
|
|
|
57960
|
-
const rgb =
|
|
57961
|
+
const rgb = hex2rgb(cL);
|
|
57961
57962
|
|
|
57962
57963
|
r = rgb.r;
|
|
57963
57964
|
g = rgb.g;
|
|
@@ -58072,11 +58073,16 @@ function rgb2uint24(r, g, b) {
|
|
|
58072
58073
|
;
|
|
58073
58074
|
}
|
|
58074
58075
|
|
|
58076
|
+
/**
|
|
58077
|
+
* Convert a decimal value to hex
|
|
58078
|
+
* @param {number} c generally expects b byte value, 0-255
|
|
58079
|
+
* @returns {string}
|
|
58080
|
+
*/
|
|
58075
58081
|
function dec2hex(c) {
|
|
58076
58082
|
const hex = Math.round(c).toString(16);
|
|
58077
58083
|
return hex.length === 1 ? "0" + hex : hex;
|
|
58078
|
-
}
|
|
58079
|
-
|
|
58084
|
+
}
|
|
58085
|
+
|
|
58080
58086
|
/**
|
|
58081
58087
|
*
|
|
58082
58088
|
* @param {number} r
|
|
@@ -58248,6 +58254,14 @@ class Color {
|
|
|
58248
58254
|
this.set(r, g, b, this.a);
|
|
58249
58255
|
}
|
|
58250
58256
|
|
|
58257
|
+
/**
|
|
58258
|
+
* set alpha
|
|
58259
|
+
* @param {number} a
|
|
58260
|
+
*/
|
|
58261
|
+
setA(a) {
|
|
58262
|
+
this.set(this.r, this.g, this.b, a);
|
|
58263
|
+
}
|
|
58264
|
+
|
|
58251
58265
|
/**
|
|
58252
58266
|
*
|
|
58253
58267
|
* @param {number} r
|
|
@@ -63944,17 +63958,17 @@ const TaskState = {
|
|
|
63944
63958
|
class Task {
|
|
63945
63959
|
/**
|
|
63946
63960
|
*
|
|
63947
|
-
* @param {string} name
|
|
63948
|
-
* @param {function(Task, executor:ConcurrentExecutor)} [initializer]
|
|
63961
|
+
* @param {string} [name] useful for identifying the task later on, for various UI and debug purposes
|
|
63962
|
+
* @param {function(Task, executor:ConcurrentExecutor)} [initializer] function to be executed just before task starts
|
|
63949
63963
|
* @param {function():TaskSignal} cycleFunction
|
|
63950
63964
|
* @param {function():number} [computeProgress]
|
|
63951
63965
|
* @param {Task[]} [dependencies=[]]
|
|
63952
|
-
* @param {number} [estimatedDuration=1]
|
|
63966
|
+
* @param {number} [estimatedDuration=1] in seconds
|
|
63953
63967
|
* @constructor
|
|
63954
63968
|
*/
|
|
63955
63969
|
constructor(
|
|
63956
63970
|
{
|
|
63957
|
-
name,
|
|
63971
|
+
name = "Unnamed",
|
|
63958
63972
|
initializer = noop,
|
|
63959
63973
|
cycleFunction,
|
|
63960
63974
|
computeProgress,
|
|
@@ -64108,6 +64122,8 @@ class Task {
|
|
|
64108
64122
|
executeSync() {
|
|
64109
64123
|
this.initialize();
|
|
64110
64124
|
|
|
64125
|
+
this.on.started.send0();
|
|
64126
|
+
|
|
64111
64127
|
let s = this.cycle();
|
|
64112
64128
|
|
|
64113
64129
|
for (; s !== TaskSignal.EndSuccess && s !== TaskSignal.EndFailure; s = this.cycle()) {
|
|
@@ -64115,9 +64131,9 @@ class Task {
|
|
|
64115
64131
|
}
|
|
64116
64132
|
|
|
64117
64133
|
if (s === TaskSignal.EndSuccess) {
|
|
64118
|
-
this.on.completed.
|
|
64134
|
+
this.on.completed.send0();
|
|
64119
64135
|
} else if (s === TaskSignal.EndFailure) {
|
|
64120
|
-
this.on.failed.
|
|
64136
|
+
this.on.failed.send0();
|
|
64121
64137
|
}
|
|
64122
64138
|
|
|
64123
64139
|
return s;
|
|
@@ -100147,7 +100163,13 @@ class AbstractDecoratorBehavior extends Behavior {
|
|
|
100147
100163
|
|
|
100148
100164
|
this.__source.finalize();
|
|
100149
100165
|
}
|
|
100150
|
-
}
|
|
100166
|
+
}
|
|
100167
|
+
|
|
100168
|
+
/**
|
|
100169
|
+
* @readonly
|
|
100170
|
+
* @type {boolean}
|
|
100171
|
+
*/
|
|
100172
|
+
AbstractDecoratorBehavior.prototype.isDecoratorBehavior = true;
|
|
100151
100173
|
|
|
100152
100174
|
/**
|
|
100153
100175
|
* @extends {Behavior}
|
|
@@ -5,7 +5,7 @@ import Vector4 from "../../src/core/geom/Vector4.js";
|
|
|
5
5
|
import loadSampler2D from "../../src/engine/graphics/texture/sampler/loadSampler2D.js";
|
|
6
6
|
import convertSampler2D2Canvas from "../../src/engine/graphics/texture/sampler/Sampler2D2Canvas.js";
|
|
7
7
|
import { InstancedMeshComponent } from "../../src/engine/ecs/foliage/ecs/InstancedMeshComponent.js";
|
|
8
|
-
import {
|
|
8
|
+
import { hex2rgb } from "../../src/core/color/hex2rgb.js";
|
|
9
9
|
import { obtainTerrain } from "../../src/engine/ecs/terrain/util/obtainTerrain.js";
|
|
10
10
|
|
|
11
11
|
class FoliagePaintTool extends Tool {
|
|
@@ -32,7 +32,7 @@ class FoliagePaintTool extends Tool {
|
|
|
32
32
|
buildColor() {
|
|
33
33
|
|
|
34
34
|
const color = new Vector4();
|
|
35
|
-
const baseColor =
|
|
35
|
+
const baseColor = hex2rgb(this.settings.color.get());
|
|
36
36
|
color.set(baseColor.r, baseColor.g, baseColor.b, 0);
|
|
37
37
|
color.multiplyScalar(1 / 255);
|
|
38
38
|
|
|
@@ -42,7 +42,7 @@ class FoliagePaintTool extends Tool {
|
|
|
42
42
|
buildBaseColor() {
|
|
43
43
|
|
|
44
44
|
const color = new Vector4();
|
|
45
|
-
const baseColor =
|
|
45
|
+
const baseColor = hex2rgb(this.settings.baseColor.get());
|
|
46
46
|
color.set(baseColor.r, baseColor.g, baseColor.b, 0);
|
|
47
47
|
color.multiplyScalar(1 / 255);
|
|
48
48
|
|
|
@@ -10,7 +10,7 @@ import { decodeMouseEventButtons, PointerDevice } from "../../src/engine/input/d
|
|
|
10
10
|
import Vector2 from "../../src/core/geom/Vector2.js";
|
|
11
11
|
import TopDownCameraControllerSystem
|
|
12
12
|
from "../../src/engine/graphics/ecs/camera/topdown/TopDownCameraControllerSystem.js";
|
|
13
|
-
import {
|
|
13
|
+
import { hex2rgb } from "../../src/core/color/hex2rgb.js";
|
|
14
14
|
import { obtainTerrain } from "../../src/engine/ecs/terrain/util/obtainTerrain.js";
|
|
15
15
|
import { pick } from "../../src/ecs/grid/pick.js";
|
|
16
16
|
|
|
@@ -55,7 +55,7 @@ class GridPaintTool extends Tool {
|
|
|
55
55
|
buildColor() {
|
|
56
56
|
|
|
57
57
|
const color = new Vector4();
|
|
58
|
-
const baseColor =
|
|
58
|
+
const baseColor = hex2rgb(this.settings.color.get());
|
|
59
59
|
color.set(baseColor.r, baseColor.g, baseColor.b, 0);
|
|
60
60
|
color.multiplyScalar(1 / 255);
|
|
61
61
|
|
package/package.json
CHANGED
package/src/core/color/Color.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import { hsv2rgb } from "./hsv2rgb.js";
|
|
6
|
-
import {
|
|
6
|
+
import { hex2rgb } from "./hex2rgb.js";
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
const rgbRegEx = /rgb\(\s*([0-9]+),\s*([0-9]+),\s*([0-9]+)\s*\)/;
|
|
@@ -55,7 +55,7 @@ export function parseColor(c) {
|
|
|
55
55
|
|
|
56
56
|
} else if (cL.startsWith('#')) {
|
|
57
57
|
|
|
58
|
-
const rgb =
|
|
58
|
+
const rgb = hex2rgb(cL);
|
|
59
59
|
|
|
60
60
|
r = rgb.r;
|
|
61
61
|
g = rgb.g;
|
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
return parseInt(v, 16)
|
|
3
|
-
}
|
|
1
|
+
import { hex2dec } from "../binary/hex2dec.js";
|
|
4
2
|
|
|
5
3
|
/**
|
|
6
4
|
*
|
|
7
|
-
* @param {string} hex
|
|
5
|
+
* @param {string} hex expect form #FFFFFF or #FFFFFFFF for RGBA
|
|
8
6
|
* @returns {{r: number, g: number, b: number, a:number}} rgb
|
|
9
7
|
*/
|
|
10
|
-
export function
|
|
8
|
+
export function hex2rgb(hex) {
|
|
11
9
|
|
|
12
10
|
|
|
13
11
|
const result = {
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { aabb3_build_corners } from "./aabb3_build_corners.js";
|
|
2
|
+
import { aabb3_matrix4_project_by_corners } from "./aabb3_matrix4_project_by_corners.js";
|
|
3
|
+
import { v3_distance_above_plane } from "../../v3_distance_above_plane.js";
|
|
4
|
+
|
|
5
|
+
const scratch_corners = new Float32Array(24);
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
*
|
|
9
|
+
* 2,0,or -2; 2: above, -2 : below, 0 : intersects plane
|
|
10
|
+
* @param {number} x0
|
|
11
|
+
* @param {number} y0
|
|
12
|
+
* @param {number} z0
|
|
13
|
+
* @param {number} x1
|
|
14
|
+
* @param {number} y1
|
|
15
|
+
* @param {number} z1
|
|
16
|
+
* @param {number} plane_normal_x
|
|
17
|
+
* @param {number} plane_normal_y
|
|
18
|
+
* @param {number} plane_normal_z
|
|
19
|
+
* @param {number} plane_offset
|
|
20
|
+
* @param {number[]|Float32Array} transform_matrix
|
|
21
|
+
* @returns {number}
|
|
22
|
+
*/
|
|
23
|
+
export function aabb3_transformed_compute_plane_side(
|
|
24
|
+
x0, y0, z0, x1, y1, z1,
|
|
25
|
+
plane_normal_x, plane_normal_y, plane_normal_z, plane_offset,
|
|
26
|
+
transform_matrix
|
|
27
|
+
) {
|
|
28
|
+
|
|
29
|
+
aabb3_build_corners(
|
|
30
|
+
scratch_corners, 0,
|
|
31
|
+
x0, y0, z0, x1, y1, z1
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
aabb3_matrix4_project_by_corners(
|
|
35
|
+
scratch_corners,
|
|
36
|
+
scratch_corners,
|
|
37
|
+
transform_matrix
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
let has_above = false, has_below = false;
|
|
41
|
+
|
|
42
|
+
for (let i = 0; i < 8; i++) {
|
|
43
|
+
const i3 = i * 3;
|
|
44
|
+
const x = scratch_corners[i3];
|
|
45
|
+
const y = scratch_corners[i3 + 1];
|
|
46
|
+
const z = scratch_corners[i3 + 2];
|
|
47
|
+
|
|
48
|
+
if (v3_distance_above_plane(x, y, z, plane_normal_x, plane_normal_y, plane_normal_z, plane_offset)) {
|
|
49
|
+
has_above = true;
|
|
50
|
+
} else {
|
|
51
|
+
has_below = true;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
let result = 0;
|
|
56
|
+
|
|
57
|
+
if (has_above) {
|
|
58
|
+
result += 2;
|
|
59
|
+
}
|
|
60
|
+
if (has_below) {
|
|
61
|
+
result -= 2;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return result;
|
|
65
|
+
}
|
|
@@ -572,11 +572,17 @@ export class TopoMesh {
|
|
|
572
572
|
/**
|
|
573
573
|
*
|
|
574
574
|
* @param {Float32Array} vertices
|
|
575
|
-
* @param {Uint16Array} faces
|
|
575
|
+
* @param {Uint32Array|Uint16Array|Uint8Array|number[]} faces
|
|
576
576
|
*/
|
|
577
577
|
build(vertices, faces) {
|
|
578
578
|
|
|
579
|
-
const
|
|
579
|
+
const face_array_size = faces.length;
|
|
580
|
+
const vertex_array_size = vertices.length;
|
|
581
|
+
|
|
582
|
+
assert.equal(face_array_size % 3, 0, `Face array size must be multiple of 3, instead was ${face_array_size}`)
|
|
583
|
+
assert.equal(vertex_array_size % 3, 0, `Vertex array size must be multiple of 3, instead was ${vertex_array_size}`)
|
|
584
|
+
|
|
585
|
+
const nVertices = vertex_array_size / 3;
|
|
580
586
|
|
|
581
587
|
//populate vertices
|
|
582
588
|
const topoVertices = this.vertices;
|
|
@@ -596,7 +602,7 @@ export class TopoMesh {
|
|
|
596
602
|
topoVertices[i] = v;
|
|
597
603
|
}
|
|
598
604
|
|
|
599
|
-
const nFaces =
|
|
605
|
+
const nFaces = face_array_size / 3;
|
|
600
606
|
|
|
601
607
|
// populate faces
|
|
602
608
|
const topoFaces = this.getFaces();
|
package/src/core/geom/AABB2.js
CHANGED
|
@@ -10,7 +10,7 @@ import { max2 } from "../math/max2.js";
|
|
|
10
10
|
import { min2 } from "../math/min2.js";
|
|
11
11
|
import LineSegment2 from "./LineSegment2.js";
|
|
12
12
|
import Vector2 from "./Vector2.js";
|
|
13
|
-
import { overlap1D } from "../math/overlap1D.js";
|
|
13
|
+
import { overlap1D } from "../math/interval/overlap1D.js";
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
*
|
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
import { max2 } from "../math/max2.js";
|
|
5
5
|
import { min2 } from "../math/min2.js";
|
|
6
6
|
import Vector2 from "./Vector2.js";
|
|
7
|
-
import { intersects1D } from "../math/intersects1D.js";
|
|
8
|
-
import { overlap1D } from "../math/overlap1D.js";
|
|
7
|
+
import { intersects1D } from "../math/interval/intersects1D.js";
|
|
8
|
+
import { overlap1D } from "../math/interval/overlap1D.js";
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
class Rectangle {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { assert } from "../assert.js";
|
|
2
2
|
import { min2 } from "./min2.js";
|
|
3
|
+
import { max2 } from "./max2.js";
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* Find the greatest common divisor (denominator/factor)
|
|
@@ -7,9 +8,9 @@ import { min2 } from "./min2.js";
|
|
|
7
8
|
* @param {number} b
|
|
8
9
|
* @returns {number}
|
|
9
10
|
*/
|
|
10
|
-
|
|
11
|
-
assert.
|
|
12
|
-
assert.
|
|
11
|
+
function computeGreatestCommonDivisor_Naive(a, b) {
|
|
12
|
+
assert.isNumber(a, 'a');
|
|
13
|
+
assert.isNumber(b, 'b');
|
|
13
14
|
|
|
14
15
|
// start with the lowest of the two as a guess
|
|
15
16
|
let result = min2(a, b);
|
|
@@ -26,3 +27,29 @@ export function computeGreatestCommonDivisor(a, b) {
|
|
|
26
27
|
|
|
27
28
|
return result;
|
|
28
29
|
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* @see https://en.wikipedia.org/wiki/Euclidean_algorithm
|
|
33
|
+
* @param {number} a
|
|
34
|
+
* @param {number} b
|
|
35
|
+
* @returns {number}
|
|
36
|
+
*/
|
|
37
|
+
function computeGreatestCommonDivisor_Euclid(a, b) {
|
|
38
|
+
assert.isNumber(a, 'a');
|
|
39
|
+
assert.isNumber(b, 'b');
|
|
40
|
+
|
|
41
|
+
let _a = max2(a, b);
|
|
42
|
+
let _b = min2(a, b);
|
|
43
|
+
|
|
44
|
+
while (_b !== 0) {
|
|
45
|
+
const t = _b;
|
|
46
|
+
_b = _a % _b;
|
|
47
|
+
|
|
48
|
+
_a = t;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return _a;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
export const computeGreatestCommonDivisor = computeGreatestCommonDivisor_Euclid;
|
package/src/core/math/mix.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
+
import { lerp } from "./lerp.js";
|
|
2
|
+
|
|
1
3
|
/**
|
|
4
|
+
*
|
|
2
5
|
* Produces a proportional mix of 2 values, a*(1-portion) + b*portion
|
|
3
|
-
*
|
|
4
|
-
* @param {number} b
|
|
5
|
-
* @param {number} portion
|
|
6
|
-
* @returns {number}
|
|
6
|
+
* Same as lerp
|
|
7
7
|
*/
|
|
8
|
-
export
|
|
9
|
-
return a * (1 - portion) + b * portion;
|
|
10
|
-
}
|
|
8
|
+
export const mix = lerp;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 3-rd (cubic) degree bezier curve
|
|
3
|
+
* @see https://www.youtube.com/watch?v=jvPPXbo87ds&t=234s
|
|
4
|
+
* @see https://en.wikipedia.org/wiki/B%C3%A9zier_curve
|
|
5
|
+
* @param {number} t factor value between 0..1
|
|
6
|
+
* @param {number} p0 start point
|
|
7
|
+
* @param {number} p1 control point
|
|
8
|
+
* @param {number} p2 control point
|
|
9
|
+
* @param {number} p3 end point
|
|
10
|
+
* @returns {number}
|
|
11
|
+
*/
|
|
12
|
+
function spline_bezier3(t, p0, p1, p2, p3) {
|
|
13
|
+
// first we compute necessary factors for each point
|
|
14
|
+
const nt = 1 - t;
|
|
15
|
+
|
|
16
|
+
const nt_2 = nt * nt;
|
|
17
|
+
|
|
18
|
+
const nt_3 = nt_2 * nt;
|
|
19
|
+
|
|
20
|
+
const t_2 = t * t;
|
|
21
|
+
|
|
22
|
+
const t_3 = t_2 * t;
|
|
23
|
+
|
|
24
|
+
// combine factors with point values to produce final result
|
|
25
|
+
return nt_3 * p0 + 3 * nt_2 * t * p1 + 3 * nt * t_2 * p2 + t_3 * p3;
|
|
26
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { min2 } from "../min2.js";
|
|
2
|
+
import { max2 } from "../max2.js";
|
|
3
|
+
import { assert } from "../../assert.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Compute bounds of a 3-rd degree bezier curve
|
|
7
|
+
* Note that this is a 1d case solver
|
|
8
|
+
* Lower bound will be written into result[offset], upper bounds will be written into result[offset+result_stride]
|
|
9
|
+
* @see https://github.com/adobe-webplatform/Snap.svg/blob/c8e483c9694517e24b282f8f59f985629f4994ce/src/path.js#L856
|
|
10
|
+
* @param {number[]|Float32Array} result
|
|
11
|
+
* @param {number} result_offset offset into the result array
|
|
12
|
+
* @param {number} result_stride
|
|
13
|
+
* @param {number} p0
|
|
14
|
+
* @param {number} p1
|
|
15
|
+
* @param {number} p2
|
|
16
|
+
* @param {number} p3
|
|
17
|
+
*/
|
|
18
|
+
function spline_bezier3_bounds(result, result_offset, result_stride, p0, p1, p2, p3) {
|
|
19
|
+
assert.greaterThan(result_stride, 0, 'result_stride must be greater than 0');
|
|
20
|
+
assert.isInteger(result_stride, 'result_stride');
|
|
21
|
+
|
|
22
|
+
const b = 6 * p0 - 12 * p1 + 6 * p2;
|
|
23
|
+
const a = -3 * p0 + 9 * p1 - 9 * p2 + 3 * p3;
|
|
24
|
+
const c = 3 * p1 - 3 * p0;
|
|
25
|
+
|
|
26
|
+
let min = min2(p0, p3);
|
|
27
|
+
let max = max2(p0, p3);
|
|
28
|
+
|
|
29
|
+
if (Math.abs(a) < 1e-12) {
|
|
30
|
+
|
|
31
|
+
if (Math.abs(b) >= 1e-12) {
|
|
32
|
+
const t = -c / b;
|
|
33
|
+
|
|
34
|
+
if (0 < t && t < 1) {
|
|
35
|
+
const value = spline_bezier3(t, p0, p1, p2, p3);
|
|
36
|
+
|
|
37
|
+
if (value < min) {
|
|
38
|
+
min = value;
|
|
39
|
+
}
|
|
40
|
+
if (value > max) {
|
|
41
|
+
max = value;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
} else {
|
|
49
|
+
|
|
50
|
+
const b2ac = b * b - 4 * c * a;
|
|
51
|
+
const sqrtb2ac = Math.sqrt(b2ac);
|
|
52
|
+
|
|
53
|
+
if (b2ac >= 0) {
|
|
54
|
+
|
|
55
|
+
const t1 = (-b + sqrtb2ac) / (2 * a);
|
|
56
|
+
|
|
57
|
+
if (0 < t1 && t1 < 1) {
|
|
58
|
+
const value = spline_bezier3(t1, p0, p1, p2, p3);
|
|
59
|
+
|
|
60
|
+
if (value < min) {
|
|
61
|
+
min = value;
|
|
62
|
+
}
|
|
63
|
+
if (value > max) {
|
|
64
|
+
max = value;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const t2 = (-b - sqrtb2ac) / (2 * a);
|
|
69
|
+
|
|
70
|
+
if (0 < t2 && t2 < 1) {
|
|
71
|
+
const value = spline_bezier3(t2, p0, p1, p2, p3);
|
|
72
|
+
|
|
73
|
+
if (value < min) {
|
|
74
|
+
min = value;
|
|
75
|
+
}
|
|
76
|
+
if (value > max) {
|
|
77
|
+
max = value;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
result[result_offset] = min;
|
|
86
|
+
result[result_offset + result_stride] = max;
|
|
87
|
+
}
|
|
@@ -53,6 +53,7 @@ export class NodeInstance {
|
|
|
53
53
|
/**
|
|
54
54
|
* Extra ports that are present just on this instance, these exist in addition to ports from the description
|
|
55
55
|
* IDs of these ports must not collide with IDs of ports on the description
|
|
56
|
+
* TODO implement functionality
|
|
56
57
|
* @protected
|
|
57
58
|
* @type {Port[]}
|
|
58
59
|
*/
|
|
@@ -14,17 +14,17 @@ import TaskState from "./TaskState.js";
|
|
|
14
14
|
class Task {
|
|
15
15
|
/**
|
|
16
16
|
*
|
|
17
|
-
* @param {string} name
|
|
18
|
-
* @param {function(Task, executor:ConcurrentExecutor)} [initializer]
|
|
17
|
+
* @param {string} [name] useful for identifying the task later on, for various UI and debug purposes
|
|
18
|
+
* @param {function(Task, executor:ConcurrentExecutor)} [initializer] function to be executed just before task starts
|
|
19
19
|
* @param {function():TaskSignal} cycleFunction
|
|
20
20
|
* @param {function():number} [computeProgress]
|
|
21
21
|
* @param {Task[]} [dependencies=[]]
|
|
22
|
-
* @param {number} [estimatedDuration=1]
|
|
22
|
+
* @param {number} [estimatedDuration=1] in seconds
|
|
23
23
|
* @constructor
|
|
24
24
|
*/
|
|
25
25
|
constructor(
|
|
26
26
|
{
|
|
27
|
-
name,
|
|
27
|
+
name = "Unnamed",
|
|
28
28
|
initializer = noop,
|
|
29
29
|
cycleFunction,
|
|
30
30
|
computeProgress,
|
|
@@ -178,6 +178,8 @@ class Task {
|
|
|
178
178
|
executeSync() {
|
|
179
179
|
this.initialize();
|
|
180
180
|
|
|
181
|
+
this.on.started.send0();
|
|
182
|
+
|
|
181
183
|
let s = this.cycle();
|
|
182
184
|
|
|
183
185
|
for (; s !== TaskSignal.EndSuccess && s !== TaskSignal.EndFailure; s = this.cycle()) {
|
|
@@ -185,9 +187,9 @@ class Task {
|
|
|
185
187
|
}
|
|
186
188
|
|
|
187
189
|
if (s === TaskSignal.EndSuccess) {
|
|
188
|
-
this.on.completed.
|
|
190
|
+
this.on.completed.send0();
|
|
189
191
|
} else if (s === TaskSignal.EndFailure) {
|
|
190
|
-
this.on.failed.
|
|
192
|
+
this.on.failed.send0();
|
|
191
193
|
}
|
|
192
194
|
|
|
193
195
|
return s;
|
|
@@ -23,7 +23,7 @@ import { globalMetrics } from "../metrics/GlobalMetrics.js";
|
|
|
23
23
|
import { MetricsCategory } from "../metrics/MetricsCategory.js";
|
|
24
24
|
import { ClockChannelType } from "../intelligence/behavior/ecs/ClockChannelType.js";
|
|
25
25
|
import { EnginePlugin } from "../plugin/EnginePlugin.js";
|
|
26
|
-
import { makeCubicCurve } from "../../core/math/makeCubicCurve.js";
|
|
26
|
+
import { makeCubicCurve } from "../../core/math/spline/makeCubicCurve.js";
|
|
27
27
|
import { logger } from "../logging/GlobalLogger.js";
|
|
28
28
|
import { assert } from "../../core/assert.js";
|
|
29
29
|
|