@woosh/meep-engine 2.56.1 → 2.57.0
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/editor/ecs/component/editors/ColorEditor.js +1 -1
- package/editor/ecs/component/editors/ImagePathEditor.js +2 -2
- package/editor/ecs/component/editors/{LargeStrongEditor.js → LargeStringEditor.js} +1 -1
- package/editor/tools/GridPaintTool.js +3 -3
- package/editor/tools/TopDownCameraControlTool.js +1 -1
- package/editor/tools/TransformTool.js +1 -1
- package/editor/tools/engine/Tool.js +9 -23
- package/editor/tools/engine/ToolEngine.js +5 -7
- package/editor/tools/paint/TerrainHeightPaintTool.js +2 -2
- package/editor/tools/paint/TerrainPaintTool.js +2 -2
- package/editor/tools/paint/TerrainTexturePaintTool.js +2 -2
- package/package.json +1 -1
- package/src/core/bvh2/bvh3/query/compute_tight_near_far_clipping_planes.js +1 -1
- package/src/core/bvh2/traversal/ThreeClippingPlaneComputingBVHVisitor.js +1 -1
- package/src/core/bvh2/traversal/__process_point_if_within_planes.js +1 -1
- package/src/core/cache/LoadingCache.js +3 -2
- package/src/core/collection/array/arraySetSortingDiff.spec.js +12 -12
- package/src/core/collection/array/weightedRandomFromArray.js +2 -2
- package/src/core/color/Color.js +6 -6
- package/src/core/color/YCbCr/YCbCr.spec.js +16 -0
- package/src/core/color/{YCbCr_to_rgb_uint24.js → YCbCr/YCbCr_to_rgb_uint24.js} +6 -6
- package/src/core/color/YCbCr/rgb_to_YCbCr_uint24.js +16 -0
- package/src/core/color/{hex2rgb.js → hex/hex2rgb.js} +1 -1
- package/src/core/color/{rgb2hex.js → hex/rgb2hex.js} +1 -1
- package/src/core/color/{hsv2rgb.js → hsv/hsv2rgb.js} +3 -3
- package/src/core/color/hsv/rgb2hsv.js +49 -0
- package/src/core/color/{kelvin_to_rgb.js → kelvin/kelvin_to_rgb.js} +1 -1
- package/src/core/color/{kelvin_to_rgb.spec.js → kelvin/kelvin_to_rgb.spec.js} +2 -2
- package/src/core/color/{prototype_kelvin_to_rgb.js → kelvin/prototype_kelvin_to_rgb.js} +5 -5
- package/src/core/color/{rgb_to_kelvin.spec.js → kelvin/rgb_to_kelvin.spec.js} +1 -1
- package/src/core/color/{parseColor.js → parse_color.js} +4 -4
- package/src/core/color/parse_color.spec.js +18 -0
- package/src/core/color/rgb2uint24.js +3 -3
- package/src/core/color/sRGB/sRGB.spec.js +16 -0
- package/src/core/color/xyz/XYZ.spec.js +16 -0
- package/src/core/color/xyz/rgb_to_xyz.js +15 -0
- package/src/core/color/xyz/xyz_to_rgb.js +14 -0
- package/src/core/events/signal/Signal.js +5 -0
- package/src/core/events/signal/{signalAggregateByTimeWindow.js → signal_aggregate_by_time_window.js} +1 -1
- package/src/core/events/signal/{SignalUtils.js → signal_filter.js} +1 -2
- package/src/core/geom/2d/spline_bezier2_2d.js +26 -0
- package/src/core/geom/2d/spline_bezier2_2d.spec.js +16 -0
- package/src/core/geom/3d/SurfacePoint3.js +1 -1
- package/src/core/geom/3d/aabb/aabb3_compute_plane_side.js +1 -1
- package/src/core/geom/3d/aabb/aabb3_detailed_volume_intersection.js +1 -1
- package/src/core/geom/3d/aabb/aabb3_transformed_compute_plane_side.js +1 -1
- package/src/core/geom/3d/compute_circle_bounding_box.js +1 -1
- package/src/core/geom/3d/cone/computeConeBoundingBox.js +1 -1
- package/src/core/geom/3d/frustum/frustum3_computeNearestPointToPoint.js +1 -1
- package/src/core/geom/3d/line/line3_computeSegmentPointDistance_sqr.js +1 -1
- package/src/core/geom/3d/line/line3_compute_nearest_point_to_point.js +1 -1
- package/src/core/geom/3d/normal/hemioct/unit_hemioct.spec.js +1 -1
- package/src/core/geom/3d/normal/spherical/sphere_map_transform.js +1 -1
- package/src/core/geom/3d/plane/is_point_within_planes.js +1 -1
- package/src/core/geom/3d/plane/lerp_planes_to_array.js +1 -1
- package/src/core/geom/3d/plane/plane3_compute_convex_3_plane_intersection.js +1 -1
- package/src/core/geom/3d/plane/plane3_compute_line_segment_intersection.js +1 -1
- package/src/core/geom/3d/plane/plane3_compute_ray_intersection.js +1 -1
- package/src/core/geom/3d/plane/plane3_lerp.js +2 -2
- package/src/core/geom/3d/plane/plane3_projectPoint.js +1 -1
- package/src/core/geom/3d/plane/plane3_slerp.js +3 -3
- package/src/core/geom/3d/ray/ray_computeNearestPointToPoint.js +1 -1
- package/src/core/geom/3d/ray/ray_distance_to_point.js +1 -1
- package/src/core/geom/3d/shape/UnionShape3D.js +3 -3
- package/src/core/geom/3d/shape/UnitCubeShape3D.js +1 -1
- package/src/core/geom/3d/shape/UnitSphereShape3D.js +1 -1
- package/src/core/geom/3d/sphere/sphere_intersects_ray.js +1 -1
- package/src/core/geom/3d/tetrahedra/TetrahedralMesh.js +6 -0
- package/src/core/geom/3d/tetrahedra/compute_bounding_simplex_3d.js +1 -1
- package/src/core/geom/3d/tetrahedra/compute_bounding_simplex_3d.spec.js +1 -1
- package/src/core/geom/3d/tetrahedra/compute_circumsphere.js +1 -1
- package/src/core/geom/3d/tetrahedra/delaunay/compute_delaunay_tetrahedral_mesh.js +1 -0
- package/src/core/geom/3d/tetrahedra/delaunay/compute_delaunay_tetrahedral_mesh.spec.js +10 -2
- package/src/core/geom/3d/topology/bounds/computeTriangleClusterNormalBoundingCone.js +1 -1
- package/src/core/geom/3d/topology/samples/sampleFloodFill.js +1 -1
- package/src/core/geom/3d/topology/simplify/compute_face_normal_change_dot_product.js +1 -1
- package/src/core/geom/3d/topology/simplify/quadratic/Quadratic3.js +1 -1
- package/src/core/geom/3d/topology/simplify/tm_edge_collapse_is_degenerate_flip.js +2 -2
- package/src/core/geom/3d/topology/struct/TopoVertex.js +1 -1
- package/src/core/geom/3d/topology/util/compute_face_connection_weight.js +2 -2
- package/src/core/geom/3d/triangle/computeTrianglePlaneSide.js +1 -1
- package/src/core/geom/3d/triangle/computeTriangleRayIntersection.js +1 -1
- package/src/core/geom/3d/triangle/computeTriangleRayIntersectionBarycentricEdge.js +1 -1
- package/src/core/geom/3d/v3_compute_triangle_normal.js +1 -1
- package/src/core/geom/Quaternion.js +1 -1
- package/src/core/geom/Vector3.js +7 -7
- package/src/core/geom/Vector3.spec.js +68 -1
- package/src/core/geom/mat2/m2_add.js +17 -0
- package/src/core/geom/mat2/m2_determinant.js +8 -0
- package/src/core/geom/mat2/m2_multiply.js +17 -0
- package/src/core/geom/mat2/m2_multiply_scalar.js +18 -0
- package/src/core/geom/mat2/m2_multiply_transposed.js +18 -0
- package/src/core/geom/mat2/m2_sub_transposed.js +17 -0
- package/src/{view → core/geom/mat3}/m3_cm_compose_transform.js +0 -29
- package/src/core/geom/mat3/m3_cm_extract_rotation.js +8 -0
- package/src/core/geom/mat3/m3_cm_from_translation.js +19 -0
- package/src/{view/multiplyMatrices3.js → core/geom/mat3/m3_multiply.js} +2 -2
- package/src/{view → core/geom/mat3}/m3_rm_compose_transform.js +0 -9
- package/src/core/geom/mat3/m3_rm_extract_scale.js +7 -0
- package/src/core/geom/{3d/vector/allocate_v3.js → vec3/v3_allocate.js} +1 -1
- package/src/core/geom/{v3_angle_between.js → vec3/v3_angle_between.js} +1 -1
- package/src/core/geom/vec3/v3_dot_array_array.js +20 -0
- package/src/core/geom/{v3_lerp.js → vec3/v3_lerp.js} +1 -1
- package/src/core/graph/SquareMatrix.js +26 -3
- package/src/core/graph/SquareMatrix.spec.js +52 -2
- package/src/core/math/clamp01.js +1 -0
- package/src/core/math/fract.js +3 -1
- package/src/core/math/inverseLerp.js +7 -5
- package/src/core/math/lerp.js +5 -5
- package/src/core/math/physics/spring/computeHookeForce.js +9 -0
- package/src/core/math/remap.js +19 -0
- package/src/core/math/remap.spec.js +15 -0
- package/src/core/math/smoothStep.spec.js +16 -0
- package/src/core/math/spline/spline_bezier2.js +13 -0
- package/src/core/math/spline/spline_bezier2.spec.js +13 -0
- package/src/core/model/object/compareValues.js +2 -2
- package/src/core/model/object/read_property.js +10 -2
- package/src/core/model/object/write_property.js +3 -23
- package/src/core/model/object/write_property.spec.js +26 -0
- package/src/core/primitives/numbers/number_pretty_print.spec.js +19 -0
- package/src/engine/ecs/ik/OneBoneSurfaceAlignmentSolver.js +2 -2
- package/src/engine/ecs/ik/TwoBoneInverseKinematicsSolver.js +2 -2
- package/src/engine/ecs/systems/SteeringSystem.js +1 -1
- package/src/engine/ecs/terrain/ecs/splat/SplatMapOptimizerDebugger.js +1 -1
- package/src/engine/graphics/ecs/camera/Camera.js +1 -1
- package/src/engine/graphics/ecs/camera/CameraClippingPlaneComputer.js +1 -1
- package/src/engine/graphics/ecs/decal/v2/FPDecalSystem.js +3 -11
- package/src/engine/graphics/ecs/highlight/Highlight.js +20 -102
- package/src/engine/graphics/ecs/mesh/Mesh.js +12 -18
- package/src/engine/graphics/ecs/mesh/MeshSystem.js +41 -26
- package/src/engine/graphics/ecs/mesh-v2/ShadedGeometrySystem.js +1 -1
- package/src/engine/graphics/ecs/path/tube/build/TubePathBuilder.js +1 -1
- package/src/engine/graphics/ecs/path/tube/build/makeTubeGeometry.js +1 -1
- package/src/engine/graphics/ecs/path/tube/build/make_cap.js +3 -3
- package/src/engine/graphics/ecs/path/tube/build/make_ring_vertices.js +1 -1
- package/src/engine/graphics/geometry/MikkT/InitTriInfo.js +5 -6
- package/src/engine/graphics/geometry/MikkT/MikkTSpace.js +3 -3
- package/src/engine/graphics/geometry/MikkT/NormalizeSafe.js +1 -2
- package/src/engine/graphics/geometry/MikkT/STSpace.js +3 -3
- package/src/engine/graphics/geometry/MikkT/v3_scale_dot_sub_normalize.js +2 -2
- package/src/engine/graphics/geometry/bvh/buffered/BVHGeometryRaycaster.js +1 -1
- package/src/engine/graphics/geometry/clipping/ClippedGeometry.js +1 -1
- package/src/engine/graphics/particles/particular/engine/emitter/ParticleEmitter.js +102 -95
- package/src/engine/graphics/particles/particular/engine/emitter/ParticleLayer.spec.js +25 -0
- package/src/engine/graphics/particles/particular/engine/emitter/ParticlePool.js +0 -35
- package/src/engine/graphics/particles/particular/engine/emitter/ParticlePool.spec.js +39 -2
- package/src/engine/graphics/particles/particular/engine/shader/ShaderManager.js +22 -6
- package/src/engine/graphics/render/forward_plus/LightManager.js +1 -1
- package/src/engine/graphics/render/forward_plus/plugin/ptototypeFPPlugin.js +2 -2
- package/src/engine/graphics/render/forward_plus/prototype/prototypeLightManager.js +3 -3
- package/src/engine/graphics/render/forward_plus/query/detailed_sphere_frustum_intersection_test.js +1 -1
- package/src/engine/graphics/render/layers/RenderLayerUtils.js +1 -1
- package/src/engine/graphics/render/visibility/hiz/prototypeHiZ.js +3 -2
- package/src/engine/graphics/sh3/LightProbeVolume.js +1 -1
- package/src/engine/graphics/sh3/path_tracer/PathTracer.js +2 -2
- package/src/engine/graphics/sh3/path_tracer/prototypePathTracer.js +2 -2
- package/src/engine/graphics/sh3/path_tracer/random_in_hemisphere.js +1 -1
- package/src/engine/graphics/sh3/path_tracer/ray_hit_apply_transform.js +1 -1
- package/src/engine/graphics/sh3/path_tracer/ray_reflect.js +1 -1
- package/src/engine/graphics/sh3/sky/hosek/data.js +3744 -0
- package/src/engine/graphics/sh3/sky/hosek/sky_hosek_compute_irradiance_by_direction.js +10 -3786
- package/src/engine/graphics/texture/atlas/AbstractTextureAtlas.js +1 -1
- package/src/engine/graphics/texture/atlas/AtlasPatch.js +0 -1
- package/src/engine/graphics/texture/atlas/AtlasPatchFlag.js +8 -1
- package/src/engine/graphics/texture/atlas/CachingTextureAtlas.js +25 -0
- package/src/engine/graphics/texture/atlas/CachingTextureAtlas.spec.js +54 -0
- package/src/engine/graphics/texture/atlas/ManagedTextureAtlas.js +101 -160
- package/src/engine/graphics/texture/atlas/TextureAtlas.js +18 -1
- package/src/engine/graphics/texture/sampler/sampler2d_ensure_uint8_RGBA.js +22 -0
- package/src/engine/graphics/util/projectSphere.js +1 -1
- package/src/engine/navigation/ecs/components/Path.js +1 -1
- package/src/engine/physics/mls-mpm/MLS_MPM.js +11 -106
- package/src/engine/reference/v2/Reference.js +6 -2
- package/src/engine/sound/ecs/emitter/SoundEmitter.js +7 -7
- package/src/engine/sound/ecs/emitter/SoundTrack.js +6 -6
- package/src/generation/filtering/numeric/complex/CellFilterAngleToNormal.js +1 -1
- package/src/generation/grid/generation/road/GridTaskGenerateRoads.js +2 -4
- package/src/generation/placement/action/random/weighted/CellActionSelectWeightedRandom.js +2 -2
- package/src/generation/theme/ThemeEngine.js +2 -2
- package/src/generation/theme/ThemeEngine.spec.js +7 -0
- package/src/view/View.js +21 -13
- package/src/view/elements/ColorPickerView.js +2 -2
- package/src/view/minimap/gl/MarkerGL.js +20 -18
- package/src/view/minimap/gl/MinimapMarkersGL.js +2 -1
- package/editor/tools/FoliagePaintTool.js +0 -168
- package/editor/tools/engine/ToolStateMachine.js +0 -53
- package/src/core/NumberFormat.js +0 -4
- package/src/core/color/rgb2hsv.js +0 -47
- package/src/core/color/rgb_to_YCbCr_uint24.js +0 -16
- package/src/core/fsm/StateMachine.js +0 -440
- package/src/core/fsm/Transition.js +0 -65
- package/src/core/geom/Bezier.js +0 -24
- package/src/core/geom/Bezier.spec.js +0 -16
- package/src/core/math/spline/quadraticCurve.js +0 -11
- package/src/core/math/spline/quadraticCurve.spec.js +0 -13
- package/src/core/primitives/numbers/compareNumbers.js +0 -9
- package/src/engine/graphics/ecs/decal/Decal.js +0 -10
- package/src/engine/graphics/ecs/decal/DecalSystem.js +0 -99
- package/src/engine/graphics/ecs/decal/threejs/DecalGeometry.js +0 -298
- package/src/engine/graphics/ecs/trail/Trail.js +0 -83
- package/src/engine/graphics/ecs/trail/TrailMaterial.js +0 -67
- package/src/engine/graphics/ecs/trail/TrailMaterial2.js +0 -73
- package/src/engine/graphics/ecs/trail/TrailSystem.js +0 -162
- package/src/engine/graphics/ecs/water2/NodeWaterShader1.js +0 -213
- package/src/engine/graphics/ecs/water2/shader/JBWaterShader.js +0 -315
- package/src/engine/graphics/geometry/MikkT/Length.js +0 -10
- package/src/engine/graphics/texture/ImageLoader.js +0 -33
- package/src/engine/graphics/three/DDSLoader.js +0 -286
- package/src/engine/graphics/three/Water2.js +0 -343
- package/src/engine/physics/spring/computeHookeForce.js +0 -9
- package/src/engine/reference/v1/ReferenceManager.js +0 -124
- /package/src/core/color/{hex2rgb.spec.js → hex/hex2rgb.spec.js} +0 -0
- /package/src/core/color/{rgb2hex.spec.js → hex/rgb2hex.spec.js} +0 -0
- /package/src/core/color/{hsv2rgb.spec.js → hsv/hsv2rgb.spec.js} +0 -0
- /package/src/core/color/{rgb_to_kelvin.js → kelvin/rgb_to_kelvin.js} +0 -0
- /package/src/core/color/{linear_to_sRGB.js → sRGB/linear_to_sRGB.js} +0 -0
- /package/src/core/color/{sRGB_to_linear.js → sRGB/sRGB_to_linear.js} +0 -0
- /package/src/core/geom/{m3_determinant.js → mat3/m3_determinant.js} +0 -0
- /package/src/core/geom/{v3_distance.js → vec3/v3_distance.js} +0 -0
- /package/src/core/geom/{v3_distance_above_plane.js → vec3/v3_distance_above_plane.js} +0 -0
- /package/src/core/geom/{v3_distance_above_plane.spec.js → vec3/v3_distance_above_plane.spec.js} +0 -0
- /package/src/core/geom/{v3_distance_sqr.d.ts → vec3/v3_distance_sqr.d.ts} +0 -0
- /package/src/core/geom/{v3_distance_sqr.js → vec3/v3_distance_sqr.js} +0 -0
- /package/src/core/geom/{v3_dot.js → vec3/v3_dot.js} +0 -0
- /package/src/core/geom/{v3_length.js → vec3/v3_length.js} +0 -0
- /package/src/core/geom/{v3_length_sqr.js → vec3/v3_length_sqr.js} +0 -0
- /package/src/core/geom/{v3_slerp.js → vec3/v3_slerp.js} +0 -0
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import Vector3 from "./Vector3.js";
|
|
2
|
-
import { v3_slerp } from "./v3_slerp.js";
|
|
2
|
+
import { v3_slerp } from "./vec3/v3_slerp.js";
|
|
3
|
+
import { MATRIX_4_IDENTITY } from "./3d/matrix/MATRIX_4_IDENTITY.js";
|
|
3
4
|
|
|
4
5
|
test('slerp', () => {
|
|
5
6
|
|
|
@@ -105,3 +106,69 @@ test("roughlyEquals", () => {
|
|
|
105
106
|
expect(new Vector3(1, -2, 3).roughlyEquals(new Vector3(1, -2, 3.11), 0.1))
|
|
106
107
|
.toBe(false);
|
|
107
108
|
});
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
test("asArray", () => {
|
|
112
|
+
const v = new Vector3(2, 5, 7);
|
|
113
|
+
|
|
114
|
+
expect(v.asArray()).toEqual([2, 5, 7])
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
test("fromScalar", () => {
|
|
118
|
+
expect(Vector3.fromScalar(7).asArray()).toEqual([7, 7, 7])
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
test("iterator symbol", () => {
|
|
122
|
+
const v = new Vector3(5, 7, 11);
|
|
123
|
+
|
|
124
|
+
const iterator = v[Symbol.iterator]();
|
|
125
|
+
|
|
126
|
+
expect(iterator.next()).toEqual({ value: 5, done: false })
|
|
127
|
+
expect(iterator.next()).toEqual({ value: 7, done: false })
|
|
128
|
+
expect(iterator.next()).toEqual({ value: 11, done: false })
|
|
129
|
+
expect(iterator.next()).toEqual({ done: true })
|
|
130
|
+
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
test("array-style getters", () => {
|
|
134
|
+
|
|
135
|
+
const v = new Vector3(5, 7, 11);
|
|
136
|
+
|
|
137
|
+
expect(v[0]).toEqual(5);
|
|
138
|
+
expect(v[1]).toEqual(7);
|
|
139
|
+
expect(v[2]).toEqual(11);
|
|
140
|
+
});
|
|
141
|
+
test("array-style setters", () => {
|
|
142
|
+
|
|
143
|
+
const v = new Vector3();
|
|
144
|
+
|
|
145
|
+
v[0] = 5;
|
|
146
|
+
v[1] = 7;
|
|
147
|
+
v[2] = 11;
|
|
148
|
+
|
|
149
|
+
expect(v.x).toEqual(5);
|
|
150
|
+
expect(v.y).toEqual(7);
|
|
151
|
+
expect(v.z).toEqual(11);
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
test("fromJSON as scalar", () => {
|
|
155
|
+
|
|
156
|
+
const v = new Vector3();
|
|
157
|
+
|
|
158
|
+
v.fromJSON(7);
|
|
159
|
+
|
|
160
|
+
expect(v.asArray()).toEqual([7, 7, 7])
|
|
161
|
+
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
test("applyMatrix with identity", () => {
|
|
165
|
+
|
|
166
|
+
const v = new Vector3(3, 7, 11);
|
|
167
|
+
|
|
168
|
+
v.applyMatrix4(MATRIX_4_IDENTITY);
|
|
169
|
+
|
|
170
|
+
expect(v.x).toEqual(3);
|
|
171
|
+
expect(v.y).toEqual(7);
|
|
172
|
+
expect(v.z).toEqual(11);
|
|
173
|
+
|
|
174
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* @param {number[]} result
|
|
4
|
+
* @param {number[]} a
|
|
5
|
+
* @param {number[]} b
|
|
6
|
+
*/
|
|
7
|
+
export function m2_add(result, a, b) {
|
|
8
|
+
const v0 = a[0] + b[0];
|
|
9
|
+
const v1 = a[1] + b[1];
|
|
10
|
+
const v2 = a[2] + b[2];
|
|
11
|
+
const v3 = a[3] + b[3];
|
|
12
|
+
|
|
13
|
+
result[0] = v0;
|
|
14
|
+
result[1] = v1;
|
|
15
|
+
result[2] = v2;
|
|
16
|
+
result[3] = v3;
|
|
17
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Multiplication of 2x2 matrices
|
|
3
|
+
* @param {number[]} result
|
|
4
|
+
* @param {number[]} a
|
|
5
|
+
* @param {number[]} b
|
|
6
|
+
*/
|
|
7
|
+
export function m2_multiply(result, a, b) {
|
|
8
|
+
const v0 = a[0] * b[0] + a[1] * b[2];
|
|
9
|
+
const v1 = a[0] * b[1] + a[1] * b[3];
|
|
10
|
+
const v2 = a[2] * b[0] + a[3] * b[2];
|
|
11
|
+
const v3 = a[2] * b[1] + a[3] * b[3];
|
|
12
|
+
|
|
13
|
+
result[0] = v0;
|
|
14
|
+
result[1] = v1;
|
|
15
|
+
result[2] = v2;
|
|
16
|
+
result[3] = v3;
|
|
17
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* @param {number[]} result
|
|
4
|
+
* @param {number[]} a
|
|
5
|
+
* @param {number} scalar
|
|
6
|
+
*/
|
|
7
|
+
export function m2_multiply_scalar(result, a, scalar) {
|
|
8
|
+
|
|
9
|
+
const v0 = a[0] * scalar;
|
|
10
|
+
const v1 = a[1] * scalar;
|
|
11
|
+
const v2 = a[2] * scalar;
|
|
12
|
+
const v3 = a[3] * scalar;
|
|
13
|
+
|
|
14
|
+
result[0] = v0;
|
|
15
|
+
result[1] = v1;
|
|
16
|
+
result[2] = v2;
|
|
17
|
+
result[3] = v3;
|
|
18
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Transposed multiplication of 2x2 matrices
|
|
3
|
+
* Second argument will be transposed before multiplication
|
|
4
|
+
* @param {number[]} result
|
|
5
|
+
* @param {number[]} a
|
|
6
|
+
* @param {number[]} b
|
|
7
|
+
*/
|
|
8
|
+
export function m2_multiply_transposed(result, a, b) {
|
|
9
|
+
const v0 = a[0] * b[0] + a[1] * b[1];
|
|
10
|
+
const v1 = a[0] * b[2] + a[1] * b[3];
|
|
11
|
+
const v2 = a[2] * b[0] + a[3] * b[1];
|
|
12
|
+
const v3 = a[2] * b[2] + a[3] * b[3];
|
|
13
|
+
|
|
14
|
+
result[0] = v0;
|
|
15
|
+
result[1] = v1;
|
|
16
|
+
result[2] = v2;
|
|
17
|
+
result[3] = v3;
|
|
18
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Transposes second matrix before subtraction
|
|
3
|
+
* @param {number[]} result
|
|
4
|
+
* @param {number[]} a
|
|
5
|
+
* @param {number[]} b
|
|
6
|
+
*/
|
|
7
|
+
export function m2_sub_transposed(result, a, b) {
|
|
8
|
+
const v0 = a[0] - b[0];
|
|
9
|
+
const v1 = a[2] - b[1];
|
|
10
|
+
const v2 = a[1] - b[2];
|
|
11
|
+
const v3 = a[3] - b[3];
|
|
12
|
+
|
|
13
|
+
result[0] = v0;
|
|
14
|
+
result[1] = v1;
|
|
15
|
+
result[2] = v2;
|
|
16
|
+
result[3] = v3;
|
|
17
|
+
}
|
|
@@ -35,32 +35,3 @@ export function m3_cm_compose_transform(
|
|
|
35
35
|
result[7] = 0;
|
|
36
36
|
result[8] = 1;
|
|
37
37
|
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
*
|
|
41
|
-
* @param {number[]|Float32Array} result
|
|
42
|
-
* @param {number} tX
|
|
43
|
-
* @param {number} tY
|
|
44
|
-
*/
|
|
45
|
-
export function m3_cm_from_translation(result, tX, tY) {
|
|
46
|
-
result[0] = 1;
|
|
47
|
-
result[1] = 0;
|
|
48
|
-
result[2] = tX;
|
|
49
|
-
|
|
50
|
-
result[3] = 0;
|
|
51
|
-
result[4] = 1;
|
|
52
|
-
result[5] = tY;
|
|
53
|
-
|
|
54
|
-
result[6] = 0;
|
|
55
|
-
result[7] = 0;
|
|
56
|
-
result[8] = 1;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* @see https://stackoverflow.com/questions/45159314/decompose-2d-transformation-matrix
|
|
61
|
-
* @param {mat3|number[]|Float32Array} m3
|
|
62
|
-
* @returns {number}
|
|
63
|
-
*/
|
|
64
|
-
export function m3_cm_extract_rotation(m3) {
|
|
65
|
-
return Math.atan2(m3[3], m3[0]);
|
|
66
|
-
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* @param {number[]|Float32Array} result
|
|
4
|
+
* @param {number} tX
|
|
5
|
+
* @param {number} tY
|
|
6
|
+
*/
|
|
7
|
+
export function m3_cm_from_translation(result, tX, tY) {
|
|
8
|
+
result[0] = 1;
|
|
9
|
+
result[1] = 0;
|
|
10
|
+
result[2] = tX;
|
|
11
|
+
|
|
12
|
+
result[3] = 0;
|
|
13
|
+
result[4] = 1;
|
|
14
|
+
result[5] = tY;
|
|
15
|
+
|
|
16
|
+
result[6] = 0;
|
|
17
|
+
result[7] = 0;
|
|
18
|
+
result[8] = 1;
|
|
19
|
+
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Performs matrix multiplication of 3x3 matrices
|
|
3
3
|
* r = a * b
|
|
4
|
+
* @param {number[]|Float32Array} r result matrix
|
|
4
5
|
* @param {number[]|Float32Array} a first matrix
|
|
5
6
|
* @param {number[]|Float32Array} b second matrix
|
|
6
|
-
* @param {number[]|Float32Array} r result matrix
|
|
7
7
|
*/
|
|
8
|
-
export function m3_multiply(a, b
|
|
8
|
+
export function m3_multiply(r, a, b) {
|
|
9
9
|
//read out values of input matrices to support the case where result is written back into one of the inputs
|
|
10
10
|
const a0 = a[0];
|
|
11
11
|
const a1 = a[1];
|
|
@@ -34,12 +34,3 @@ export function m3_rm_compose_transform(
|
|
|
34
34
|
result[5] = 0;
|
|
35
35
|
result[8] = 1;
|
|
36
36
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
export function m3_rm_extract_scale(result, m3) {
|
|
40
|
-
const scale_x = Math.hypot(m3[0], m3[3]);
|
|
41
|
-
const scale_y = Math.hypot(m3[1], m3[4]);
|
|
42
|
-
|
|
43
|
-
result[0] = scale_x;
|
|
44
|
-
result[1] = scale_y;
|
|
45
|
-
}
|
|
@@ -23,7 +23,7 @@ const ELEMENT_BYTE_SIZE = 4 * 3;
|
|
|
23
23
|
* custom Float32Array allocator, allocated memory in continuous chunks
|
|
24
24
|
* @returns {Float32Array}
|
|
25
25
|
*/
|
|
26
|
-
export function
|
|
26
|
+
export function v3_allocate() {
|
|
27
27
|
if (bucket_cursor >= ALLOCATOR_BUCKET_CAPACITY) {
|
|
28
28
|
bucket = new ArrayBuffer(ALLOCATOR_BUCKET_CAPACITY * ELEMENT_BYTE_SIZE);
|
|
29
29
|
bucket_cursor = 0;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* @param {number[]|Float32Array} a
|
|
4
|
+
* @param {number} a_offset
|
|
5
|
+
* @param {number[]|Float32Array} b
|
|
6
|
+
* @param {number} b_offset
|
|
7
|
+
* @returns {number}
|
|
8
|
+
*/
|
|
9
|
+
export function v3_dot_array_array(a, a_offset, b, b_offset) {
|
|
10
|
+
|
|
11
|
+
const a_x = a[a_offset];
|
|
12
|
+
const a_y = a[a_offset + 1];
|
|
13
|
+
const a_z = a[a_offset + 2];
|
|
14
|
+
|
|
15
|
+
const b_x = b[b_offset];
|
|
16
|
+
const b_y = b[b_offset + 1];
|
|
17
|
+
const b_z = b[b_offset + 2];
|
|
18
|
+
|
|
19
|
+
return a_x * b_x + a_y * b_y + a_z * b_z;
|
|
20
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { DataType2TypedArrayConstructorMapping } from "../binary/type/DataType2TypedArrayConstructorMapping.js";
|
|
2
2
|
import { assert } from "../assert.js";
|
|
3
|
+
import { array_copy } from "../collection/array/array_copy.js";
|
|
3
4
|
|
|
4
5
|
export class SquareMatrix {
|
|
5
6
|
/**
|
|
@@ -44,7 +45,7 @@ export class SquareMatrix {
|
|
|
44
45
|
return this.data;
|
|
45
46
|
}
|
|
46
47
|
|
|
47
|
-
fill(v){
|
|
48
|
+
fill(v) {
|
|
48
49
|
this.data.fill(v);
|
|
49
50
|
}
|
|
50
51
|
|
|
@@ -53,16 +54,20 @@ export class SquareMatrix {
|
|
|
53
54
|
* @param {SquareMatrix} other
|
|
54
55
|
*/
|
|
55
56
|
subtract(other) {
|
|
56
|
-
this.subtractMatrices(this,other);
|
|
57
|
+
this.subtractMatrices(this, other);
|
|
57
58
|
}
|
|
58
59
|
|
|
59
60
|
/**
|
|
60
|
-
*
|
|
61
|
+
* Component-size subtraction
|
|
61
62
|
* @param {SquareMatrix} a
|
|
62
63
|
* @param {SquareMatrix} b
|
|
63
64
|
*/
|
|
64
65
|
subtractMatrices(a, b) {
|
|
65
66
|
const size = this.size;
|
|
67
|
+
|
|
68
|
+
assert.equal(a.size, size, 'a is of wrong size');
|
|
69
|
+
assert.equal(b.size, size, 'b is of wrong size');
|
|
70
|
+
|
|
66
71
|
const data_length = size * size;
|
|
67
72
|
|
|
68
73
|
const a_data = a.data;
|
|
@@ -152,6 +157,17 @@ export class SquareMatrix {
|
|
|
152
157
|
this.data.set(arr);
|
|
153
158
|
}
|
|
154
159
|
|
|
160
|
+
/**
|
|
161
|
+
*
|
|
162
|
+
* @param {number[]} [destination]
|
|
163
|
+
* @param {number} [offset]
|
|
164
|
+
*/
|
|
165
|
+
toArray(destination = new Array(this.length), offset=0) {
|
|
166
|
+
array_copy(this.data, 0, destination, offset, this.length);
|
|
167
|
+
|
|
168
|
+
return destination;
|
|
169
|
+
}
|
|
170
|
+
|
|
155
171
|
/**
|
|
156
172
|
*
|
|
157
173
|
* @param {number} row_index
|
|
@@ -177,6 +193,13 @@ export class SquareMatrix {
|
|
|
177
193
|
* @return {number}
|
|
178
194
|
*/
|
|
179
195
|
getCellValue(row_index, column_index) {
|
|
196
|
+
assert.isNonNegativeInteger(row_index, 'row_index');
|
|
197
|
+
assert.isNonNegativeInteger(column_index, 'row_index');
|
|
198
|
+
|
|
199
|
+
assert.lessThan(row_index, this.size, 'row overflow');
|
|
200
|
+
assert.lessThan(column_index, this.size, 'column overflow');
|
|
201
|
+
|
|
202
|
+
|
|
180
203
|
return this.data[this.size * column_index + row_index];
|
|
181
204
|
}
|
|
182
205
|
|
|
@@ -33,7 +33,7 @@ test('transpose', () => {
|
|
|
33
33
|
});
|
|
34
34
|
|
|
35
35
|
|
|
36
|
-
test('copy', ()=>{
|
|
36
|
+
test('copy', () => {
|
|
37
37
|
const m = new SquareMatrix(2, BinaryDataType.Uint8);
|
|
38
38
|
|
|
39
39
|
m.setCellValue(0, 0, 7);
|
|
@@ -41,7 +41,7 @@ test('copy', ()=>{
|
|
|
41
41
|
m.setCellValue(0, 1, 13);
|
|
42
42
|
m.setCellValue(1, 1, 19);
|
|
43
43
|
|
|
44
|
-
const b = new SquareMatrix(2,BinaryDataType.Uint8);
|
|
44
|
+
const b = new SquareMatrix(2, BinaryDataType.Uint8);
|
|
45
45
|
|
|
46
46
|
b.copy(m);
|
|
47
47
|
|
|
@@ -50,3 +50,53 @@ test('copy', ()=>{
|
|
|
50
50
|
expect(b.getCellValue(0, 1)).toBe(13);
|
|
51
51
|
expect(b.getCellValue(1, 1)).toBe(19);
|
|
52
52
|
});
|
|
53
|
+
|
|
54
|
+
test("eye", () => {
|
|
55
|
+
const m = new SquareMatrix(2, BinaryDataType.Uint8);
|
|
56
|
+
|
|
57
|
+
m.eye();
|
|
58
|
+
|
|
59
|
+
expect(m.getCellValue(0, 0)).toBe(1);
|
|
60
|
+
expect(m.getCellValue(1, 0)).toBe(0);
|
|
61
|
+
expect(m.getCellValue(0, 1)).toBe(0);
|
|
62
|
+
expect(m.getCellValue(1, 1)).toBe(1);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
test("negate", () => {
|
|
66
|
+
const m = new SquareMatrix(2, BinaryDataType.Int8);
|
|
67
|
+
|
|
68
|
+
m.fromArray([
|
|
69
|
+
-3, 5,
|
|
70
|
+
7, -11
|
|
71
|
+
]);
|
|
72
|
+
|
|
73
|
+
m.negate();
|
|
74
|
+
|
|
75
|
+
expect(m.toArray()).toEqual([
|
|
76
|
+
3, -5,
|
|
77
|
+
-7, 11
|
|
78
|
+
]);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
test("subtract", () => {
|
|
82
|
+
const a = new SquareMatrix(2, BinaryDataType.Int8);
|
|
83
|
+
const b = new SquareMatrix(2, BinaryDataType.Int8);
|
|
84
|
+
|
|
85
|
+
a.fromArray([
|
|
86
|
+
1, 3,
|
|
87
|
+
5, 7
|
|
88
|
+
]);
|
|
89
|
+
|
|
90
|
+
b.fromArray([
|
|
91
|
+
-11, 13,
|
|
92
|
+
17, 23
|
|
93
|
+
]);
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
a.subtract(b);
|
|
97
|
+
|
|
98
|
+
expect(a.toArray()).toEqual([
|
|
99
|
+
12, -10,
|
|
100
|
+
-12, -16
|
|
101
|
+
]);
|
|
102
|
+
});
|
package/src/core/math/clamp01.js
CHANGED
package/src/core/math/fract.js
CHANGED
|
@@ -10,11 +10,13 @@ export function inverseLerp(a, b, value) {
|
|
|
10
10
|
const scaledValue = value - a;
|
|
11
11
|
|
|
12
12
|
if (range === 0) {
|
|
13
|
-
|
|
13
|
+
|
|
14
|
+
// avoid division by zero error
|
|
15
|
+
|
|
16
|
+
// this is arbitrary output, as actual answer is undefined
|
|
17
|
+
|
|
14
18
|
return 0;
|
|
15
19
|
}
|
|
16
20
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
return fraction;
|
|
20
|
-
}
|
|
21
|
+
return scaledValue / range;
|
|
22
|
+
}
|
package/src/core/math/lerp.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Linear interpolation between two values controlled by a given fraction
|
|
3
|
-
* @param {
|
|
4
|
-
* @param {
|
|
5
|
-
* @param {
|
|
6
|
-
* @return {
|
|
3
|
+
* @param {number} a
|
|
4
|
+
* @param {number} b
|
|
5
|
+
* @param {number} fraction Floating point value between 0 and 1
|
|
6
|
+
* @return {number}
|
|
7
7
|
*/
|
|
8
8
|
export function lerp(a, b, fraction) {
|
|
9
9
|
return (b - a) * fraction + a;
|
|
10
|
-
}
|
|
10
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Spring force calculation
|
|
3
|
+
* @param {number} displacement how far the spring is being stretched from its resting state
|
|
4
|
+
* @param {number} stiffness how still is the spring
|
|
5
|
+
* @return {number} force in the direction of displacement exerted by the spring trying to pull back
|
|
6
|
+
*/
|
|
7
|
+
export function computeHookeForce(displacement, stiffness) {
|
|
8
|
+
return -stiffness * displacement;
|
|
9
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { inverseLerp } from "./inverseLerp.js";
|
|
2
|
+
import { lerp } from "./lerp.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Returns linear remapping of {@link value} from source range [source_first, source_second] to target range [target_first, target_second]
|
|
6
|
+
* This method is non-clamping, meaning that if your input is outside the source range - output will be outside the target range as well
|
|
7
|
+
* @param {number} source_first
|
|
8
|
+
* @param {number} source_second
|
|
9
|
+
* @param {number} target_first
|
|
10
|
+
* @param {number} target_second
|
|
11
|
+
* @param {number} value
|
|
12
|
+
* @return {number}
|
|
13
|
+
*/
|
|
14
|
+
export function remap(source_first, source_second, target_first, target_second, value) {
|
|
15
|
+
|
|
16
|
+
const relative = inverseLerp(source_first, source_second, value);
|
|
17
|
+
|
|
18
|
+
return lerp(target_first, target_second, relative);
|
|
19
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { remap } from "./remap.js";
|
|
2
|
+
|
|
3
|
+
test("basics", () => {
|
|
4
|
+
expect(remap(0, 0, 0, 0, 0)).toEqual(0);
|
|
5
|
+
|
|
6
|
+
expect(remap(0, 1, 0, 1, 0)).toEqual(0);
|
|
7
|
+
|
|
8
|
+
expect(remap(0, 1, 1, 5, 0)).toEqual(1);
|
|
9
|
+
|
|
10
|
+
expect(remap(0, 1, 1, 5, 1)).toEqual(5);
|
|
11
|
+
|
|
12
|
+
expect(remap(0, 1, 1, 5, 0.5)).toEqual(3);
|
|
13
|
+
|
|
14
|
+
expect(remap(1, 5, 0, 1, 3)).toEqual(0.5);
|
|
15
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { smoothStep } from "./smoothStep.js";
|
|
2
|
+
|
|
3
|
+
test("basics", () => {
|
|
4
|
+
expect(smoothStep(0, 1, 1)).toEqual(1);
|
|
5
|
+
expect(smoothStep(1, 2, 2)).toEqual(1);
|
|
6
|
+
|
|
7
|
+
expect(smoothStep(0, 1, 0)).toEqual(0);
|
|
8
|
+
expect(smoothStep(1, 2, 1)).toEqual(0);
|
|
9
|
+
|
|
10
|
+
expect(smoothStep(0, 1, 0.5)).toBeCloseTo(0.5);
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
test("clamping",()=>{
|
|
14
|
+
expect(smoothStep(1, 2, 0)).toEqual(0);
|
|
15
|
+
expect(smoothStep(1, 2, 3)).toEqual(1);
|
|
16
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 2-nd (quadratic) degree bezier curve
|
|
3
|
+
* @param {number} t
|
|
4
|
+
* @param {number} p0
|
|
5
|
+
* @param {number} p1
|
|
6
|
+
* @param {number} p2
|
|
7
|
+
* @return {number}
|
|
8
|
+
*/
|
|
9
|
+
export function spline_bezier2(t, p0, p1, p2) {
|
|
10
|
+
const inv_t = 1 - t;
|
|
11
|
+
|
|
12
|
+
return inv_t * inv_t * p0 + 2 * inv_t * t * p1 + t * t * p2;
|
|
13
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { spline_bezier2 } from "./spline_bezier2.js";
|
|
2
|
+
|
|
3
|
+
test("spline_bezier2", () => {
|
|
4
|
+
expect(spline_bezier2(2, 0.1, 0.2, 3)).toBe(11.3);
|
|
5
|
+
|
|
6
|
+
expect(spline_bezier2(1, -1, -2, -3)).toBe(-3);
|
|
7
|
+
|
|
8
|
+
expect(spline_bezier2(-1, -1, 0, 0)).toBe(-4);
|
|
9
|
+
|
|
10
|
+
expect(spline_bezier2(-1, -1, 1, 0)).toBe(-8);
|
|
11
|
+
|
|
12
|
+
expect(spline_bezier2(-1, 0, 0, 0)).toBe(0);
|
|
13
|
+
});
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { compareStrings } from "../../primitives/strings/compareStrings.js";
|
|
2
|
-
import { compareNumbers } from "../../primitives/numbers/compareNumbers.js";
|
|
3
2
|
import { compareBooleans } from "../../primitives/boolean/compareBooleans.js";
|
|
4
3
|
import { extractFunctionBody } from "../../function/extractFunctionBody.js";
|
|
5
4
|
import { compareArrays } from "../../primitives/array/compareArrays.js";
|
|
5
|
+
import { number_compare_ascending } from "../../primitives/numbers/number_compare_ascending.js";
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
*
|
|
@@ -25,7 +25,7 @@ export function compareValues(a, b) {
|
|
|
25
25
|
if (aType === "string") {
|
|
26
26
|
return compareStrings(a, b);
|
|
27
27
|
} else if (aType === "number") {
|
|
28
|
-
return
|
|
28
|
+
return number_compare_ascending(a, b);
|
|
29
29
|
} else if (aType === "boolean") {
|
|
30
30
|
return compareBooleans(a, b);
|
|
31
31
|
} else if (aType === "function") {
|
|
@@ -6,9 +6,14 @@ import { string_capitalize } from "../../primitives/strings/string_capitalize.js
|
|
|
6
6
|
* @param {string[]} parts
|
|
7
7
|
* @param {number} part_offset
|
|
8
8
|
* @param {number} part_count
|
|
9
|
+
* @param {boolean} [throw_on_missing] will throw an exception if property is not found
|
|
9
10
|
* @returns {undefined|T}
|
|
10
11
|
*/
|
|
11
|
-
export function read_property(
|
|
12
|
+
export function read_property(
|
|
13
|
+
root,
|
|
14
|
+
parts, part_offset, part_count,
|
|
15
|
+
throw_on_missing = false
|
|
16
|
+
) {
|
|
12
17
|
|
|
13
18
|
let thing = root;
|
|
14
19
|
|
|
@@ -25,7 +30,10 @@ export function read_property(root, parts, part_offset, part_count) {
|
|
|
25
30
|
if (typeof getter === "function") {
|
|
26
31
|
// resolve via getter
|
|
27
32
|
thing = getter.call(thing);
|
|
28
|
-
} else {
|
|
33
|
+
} else if(throw_on_missing){
|
|
34
|
+
// no getter
|
|
35
|
+
throw new Error(`No no property or getter found for '${part}' on [${i}]'${parts.slice(part_offset, part_offset + part_count).join('/')}'`);
|
|
36
|
+
}else{
|
|
29
37
|
// no getter
|
|
30
38
|
return undefined;
|
|
31
39
|
}
|