@woosh/meep-engine 2.131.17 → 2.131.20

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.
Files changed (45) hide show
  1. package/README.md +85 -101
  2. package/editor/ecs/component/editors/geom/QuaternionEditor.js +3 -3
  3. package/editor/tools/TransformTool.js +14 -3
  4. package/package.json +1 -1
  5. package/src/core/geom/Quaternion.d.ts +52 -19
  6. package/src/core/geom/Quaternion.d.ts.map +1 -1
  7. package/src/core/geom/Quaternion.js +77 -27
  8. package/src/core/geom/Vector3.d.ts +3 -0
  9. package/src/core/geom/Vector3.d.ts.map +1 -1
  10. package/src/core/geom/Vector3.js +16 -6
  11. package/src/core/math/spline/spline3_hermite.d.ts +1 -1
  12. package/src/core/math/spline/spline3_hermite.js +1 -1
  13. package/src/core/math/spline/spline3_hermite_bounds.d.ts +1 -1
  14. package/src/core/math/spline/spline3_hermite_bounds.js +2 -2
  15. package/src/core/math/spline/spline3_hermite_derivative.d.ts +8 -6
  16. package/src/core/math/spline/spline3_hermite_derivative.d.ts.map +1 -1
  17. package/src/core/math/spline/spline3_hermite_derivative.js +10 -7
  18. package/src/core/math/spline/spline3_hermite_integral.d.ts +14 -0
  19. package/src/core/math/spline/spline3_hermite_integral.d.ts.map +1 -0
  20. package/src/core/math/spline/spline3_hermite_integral.js +35 -0
  21. package/src/core/math/spline/spline3_hermite_subdivide.d.ts +1 -1
  22. package/src/core/math/spline/spline3_hermite_subdivide.js +1 -1
  23. package/src/core/model/node-graph/NodeGraph.d.ts +1 -0
  24. package/src/core/model/node-graph/NodeGraph.d.ts.map +1 -1
  25. package/src/core/model/node-graph/NodeGraph.js +4 -0
  26. package/src/engine/animation/curve/animation_curve_fit.d.ts +17 -0
  27. package/src/engine/animation/curve/animation_curve_fit.d.ts.map +1 -0
  28. package/src/engine/animation/curve/animation_curve_fit.js +195 -0
  29. package/src/engine/animation/curve/animation_curve_optimize.d.ts.map +1 -1
  30. package/src/engine/animation/curve/animation_curve_optimize.js +65 -21
  31. package/src/engine/animation/curve/animation_curve_subdivide.d.ts +4 -2
  32. package/src/engine/animation/curve/animation_curve_subdivide.d.ts.map +1 -1
  33. package/src/engine/animation/curve/animation_curve_subdivide.js +4 -2
  34. package/src/engine/ecs/transform/Transform.d.ts +9 -6
  35. package/src/engine/ecs/transform/Transform.d.ts.map +1 -1
  36. package/src/engine/ecs/transform/Transform.js +15 -8
  37. package/src/engine/graphics/ecs/camera/topdown/ComputeCameraFacingVector.js +1 -1
  38. package/src/engine/graphics/ecs/camera/topdown/TopDownCameraControllerSystem.js +1 -1
  39. package/src/engine/graphics/ecs/mesh-v2/aggregate/prototypeSGMesh.js +1 -1
  40. package/src/engine/graphics/render/forward_plus/plugin/ptototypeFPPlugin.js +1 -1
  41. package/src/generation/markers/transform/MarkerNodeTransformerYRotateByFilter.d.ts.map +1 -1
  42. package/src/generation/markers/transform/MarkerNodeTransformerYRotateByFilter.js +3 -3
  43. package/src/generation/markers/transform/MarkerNodeTransformerYRotateByFilterGradient.d.ts.map +1 -1
  44. package/src/generation/markers/transform/MarkerNodeTransformerYRotateByFilterGradient.js +5 -6
  45. package/src/view/View.d.ts +3 -3
package/README.md CHANGED
@@ -1,126 +1,110 @@
1
1
  # Meep Engine
2
+ **The unopinionated, high-performance ECS engine for code-first developers.**
2
3
 
3
- ## Getting Started
4
+ Meep is a battle-tested JavaScript game engine designed for scale. Built over 10+ years and used in commercial Steam releases, it strips away the bloat of traditional engines to offer a molecular, zero-allocation architecture.
4
5
 
5
- We offer a [minimal project](http://gitlab.company-named.com/travnik/dream-engine-template) with no bells or whistles, just enough to run the engine and get you starter. If you're starting from scratch this is likely the best option.
6
+ It is designed for engineers who want full control, offering performance that rivals native code on the web.
6
7
 
7
- ## Documentation
8
+ [🚀 Quick Start Template](http://gitlab.company-named.com/travnik/dream-engine-template) | [📚 Documentation](http://meep-engine.company-named.com:8080/docs/getting_started/Installation)
8
9
 
9
- [Engine Documentation](http://meep-engine.company-named.com:8080/docs/getting_started/Installation)
10
+ ---
11
+
12
+ ## Why Meep?
13
+ Most web engines are heavy, opinionated, and struggle with garbage collection. Meep is different.
14
+
15
+ * **Pure ECS Architecture:** A true data-oriented foundation that supports complex hierarchies and millions of entities. Unlike hybrid engines, our component queries are instantaneous.
16
+ * **Molecular Modularity:** Distributed as ~3,000 fine-grained modules. Need a lerp function? Import it for a 4-line footprint. You never pay for code you don't use.
17
+ * **Zero-Garbage Architecture:** Custom memory management ensures stable frame rates. Meep handles millions of objects on low-spec mobile hardware without GC spikes.
18
+ * **Code-First:** No GUI. No black boxes. Meep is a programmatic tool designed for software engineers who value architecture and long-term integration.
19
+ * **Battle-Hardened:** Covered by 3,000+ unit tests and extensive assertions. This is not a prototype; it is industrial-grade software.
20
+
21
+ ---
22
+
23
+ ## 💎 Architecture: Pure ECS
24
+ Meep is not yet another Object-Oriented engine with an ECS tacked on; it is a **Pure Entity Component System** engine.
25
+
26
+ While other engines (like Unity) struggle with slow query times and documentation that advises you to use component lookups "sparingly" — Meep thrives on them.
27
+
28
+ * **Strict Data-Oriented Design:** One component instance per type per entity. This guarantees memory layout optimization and cache locality.
29
+ * **The Hierarchy Problem: Solved.** Pure ECS architectures historically struggle with scene graphs and parent-child transforms. Meep solves this natively. You get the composability of a scene graph with the raw speed of a flat array. (Similar to the Rust-based Bevy engine).
30
+ * **Tiered API Access:**
31
+ * **High-Level:** Use convenient abstraction layers for gameplay logic.
32
+ * **Low-Level:** Drop down to raw typed arrays for performance-critical paths.
33
+ * **Uncompromised Speed:** Because the architecture is solid, you can query, filter, and iterate over millions of entities without performance cliffs.
34
+
35
+ ---
36
+
37
+ ## ⚡ High-Performance Rendering
38
+ Meep implements a Clustered Forward+ rendering pipeline, allowing for scenes that traditional web engines choke on.
39
+
40
+ * **Unlimited Lighting:** Render thousands of point lights (muzzle flashes, explosions, torches) with clustered lighting.
41
+
42
+ * **GPU-Driven Decals:** Handle 1,000,000+ decals for persistent battle damage and environmental details.
43
+
44
+ * **Massive Terrain:** Chunk-based, auto-culled terrain system supporting up to 256 layers (vs Unity's 4).
10
45
 
11
- ## Samples
12
- To help get you started, various samples are provided under `/samples` folder. Feel free to use them as a point of reference.
46
+ * **"Particular" Particle Engine:** A zero-allocation particle system with full lighting, soft particles, and automatic atlassing. Compiled into just 4 shaders to eliminate state-switching overhead.
13
47
 
14
- ## Quality
48
+ * **Path Tracing:** Includes a pure JS path tracer utilizing the engine's internal BVH.
15
49
 
16
- ### Testing
17
- Meep is covered by 2,944 handwritten unit tests, reaching 90%+ coverage in `core` and 40%+ coverage total.
50
+ ## 🧠 AI & Simulation Tools
51
+ Meep provides a suite of tools rarely found in JS engines, optimized for complex decision making.
18
52
 
19
- The aim is to [ensure quality](https://about.codecov.io/blog/the-case-against-100-code-coverage/). As a result, the tests are written to cover complex code first and to exhaustively validate critical algorithms.
20
- Most of the test code is significantly larger than the code that is being tested.
53
+ * **Behavior Trees & Blackboards:** Industry-standard tools for state management.
21
54
 
22
- ### Assertions
23
- Meep is covered by 3,968 asserts. [Assertions](https://en.wikipedia.org/wiki/Assertion_(software_development)) provide very extensive pre- and post-condition checks throughout the engine.
24
- Asserts are intended primarily for development builds.
25
- To remove asserts in Vite builds, you can use `@rollup/plugin-strip` package like so:
55
+ * **Monte-Carlo Tree Search:** The same algorithm used in AlphaGo, available for your decision logic.
56
+
57
+ * **Resource Allocation Solver:** Plan optimal actions based on limited resources (ammo, health, currency).
58
+
59
+ * **Spatial Query System:** Highly optimized BVH for Ray, Box, Frustum, and Point queries.
60
+
61
+ * **Inverse Kinematics:** Includes FABRIK solvers and specialized bip/quadruped solvers for uneven terrain adaptation.
62
+
63
+ ## 🛠️ Developer Experience
64
+
65
+ ### Installation & Stripping
66
+
67
+ Meep is designed to be invisible in production.
68
+ ```shell
69
+ npm install @woosh/meep-engine
70
+ ```
71
+
72
+ **Development Mode:** The engine includes ~4,000 assertions to help you catch errors instantly.
73
+
74
+ **Production Mode:** Using @rollup/plugin-strip, Meep compiles to tiny size and runs at the speed of light.
26
75
 
27
76
  ```js
77
+ // vite.config.js
28
78
  import strip from '@rollup/plugin-strip';
29
- import { defineConfig } from 'vite';
30
-
31
79
  export default defineConfig({
32
- plugins: [{
33
- // this will remove all assert statements from the production build
34
- ...strip(),
35
- apply: 'build'
36
- }],
37
- // ... the rest of the config ...
80
+ plugins: [{ ...strip(), apply: 'build' }]
38
81
  });
39
82
  ```
40
83
 
41
- Assertion package can be found under `/src/core/assert.js`.
42
-
43
- ## Package Size
84
+ ### Reliability
85
+ * **Tests:** 2,944 handwritten tests covering critical algorithms and complex edge cases.
44
86
 
45
- Meep is infinitely tree-shakable, you only package what you use.
87
+ * **Coverage:** 90%+ core coverage.
46
88
 
47
- Meep is distributed as a fine-grained set of ~3,000 modules, with an average module being ~70 lines of code.
48
- If you use meep in your project, you add as much or as little to your overall bundle size as you want.
89
+ * **Stability:** Exhaustively tested corner cases over a decade of development.
49
90
 
50
- For example, if you include `core/math/lerp` function, you only add 4 lines of code to your project.
51
-
52
- ## Performance
91
+ ---
53
92
 
54
- Some say that JavaScript is not a viable choice when performance is a factor. I disagree. Meep aims to strike a balance between performance and comfort.
55
- That said, meep is performance-first engine. Various API wrappers are offered for convenience, but you're always welcome to drop down to low-level API.
56
- Meep is written to generate close to 0 garbage and where that would be otherwise impossible - Meep implements custom memory management to make it possible.
57
- The engine is built to handle millions of objects at the same time on even low-spec mobile hardware.
93
+ ## Additional Features
58
94
 
59
- ## Features
95
+ | Category | Features |
96
+ |------------------|-----------------------------------------------------------------------------------------------------------------------|
97
+ | Audio | Custom culling and attenuation; supports 1,000s of positional sources with zero overhead |
98
+ | Input | Unified abstraction for Touch, Mouse, and Keyboard. Event-driven and Query-based APIs |
99
+ | Assets | Web-first asset streaming. The engine runs before assets even load |
100
+ | Serialization | Binary serialization system with version upgrading |
101
+ | UI | High-speed, zero-garbage UI system. Optional—can be replaced with React/Vue if desired |
102
+ | Color Management | Scientific-grade color management toolkit, including spectral-integration tools and modern color spaces such as OKLab |
103
+ | NodeGraph | A building block for node-graph systems, such as shader editors and workflow engines |
104
+ | Achievements | State-of-the-art achievement system, using expressions and blackboards |
105
+ | Inverse Kinematics (IK) | Highly optimized FABRIK inverse kinematics solver even the most complex IK use cases |
60
106
 
61
107
  ---
62
- ## Input
63
- * Touch / Mouse / Keyboard device support
64
- * Unified abstraction of input, offering both query and event-driven APIs
65
- * Input binding implementation via `InputController` component
66
-
67
- ## Rendering & Lighting
68
- ### Automatic instancing
69
- This will minimize the number of draw calls and improve performance.
70
- ### Clustered lighting, aka Forward+
71
- Meep implements clustered lighting technique which allows you to have a pretty much an unlimited number of point lights in your scene. All the other light types are supported as well, but only point lights are clustered for now. Point lights are useful for various effects, like muzzle flashes, grenade explosions, torches, etc.
72
- ### Terrain
73
- The terrain engine is chunk-based, which means that terrain is split into rectangular pieces internally, and they are built on-the-fly inside a web-worker based on camera position. Terrain is automatically culled based on camera position, so you're only drawing the chunks that are in view. Terrain supports layers just like Unity, but unlike Unity - Meep supports up to 256 layers of terrain instead of 4.
74
- ### Path tracer
75
- Pure JS implementation of a path tracer, using engine's BVH (See Physics section)
76
-
77
- ## Visual Effects
78
- ### Decals
79
- Decals in meep are done on the GPU, and as a result you can have a lot of them in your scene. The most I tested in a single scene is 1,000,000 which works quite well. Decals are useful for bullet holes, blood splatter and various scene decorations such as signs and scuff marks.
80
- ### Particles
81
- Meep's particle engine ("Particular") is optimized for game development needs, this means supporting complex effects and being able to spawn/destroy many particle systems every frame. There are a lot of particle engines out there, but they tend to have costly spawning routines, take up a lot of draw calls and not manage memory well, which leads to pretty poor performance in games. My particle engine supports full particle lighting as well, and soft particles. On top of that - all particles are automatically atlassed in the background and are compiled with just 4 shaders. This means that no matter how many particle effects you have - there will be no shader switching and no texture switching, and there will be no delays associated with shader compilation. Particles are culled, so particle systems that are off-screen are not rendered and simulation for them can be paused to save CPU resources (this is automatic behavior)
82
- ### Trails
83
- Meep implements a fairly complex trail system, where a trail can be attached to an entity, and it will create a trail behind.
84
-
85
- ## Audio
86
- ### Sound engine
87
- Meep has a custom sound engine which is culled and has custom attenuation, this allows scenes to have 1000s of positional audio sources without any extra cost in terms of performance
88
-
89
- ## Physics
90
- ### High performance spatial index
91
- Meep features a BVH (bounding volume hierarchy) implementation optimized for speed and memory usage that provides a wide variety of spatial queries, such as:
92
- * Ray
93
- * Box
94
- * Sphere
95
- * Planar
96
- * Frustum
97
- * Point intersection
98
- * Point distance
99
- ### Inverse kinematics
100
- * Meep has 2 very useful IK solvers to fix foot position for characters on uneven terrain or stairs, aligning both the position and orientation of character feet. This works for hands as well if you want and is not limited to bipeds, the system works just as well for, say, spiders.
101
- * Highly optimized FABRIK inverse kinematics solver for more complex IK use cases
102
-
103
- ## Other
104
- ### Asset streaming
105
- Meep in general is a web-first engine, all assets are streamed, meaning that the engine is up and running even before any models/texture are loaded, and you're free to decide when to let the player see your level, wait until everything is loaded or drop them in as soon as you can. There is a pre-loader module in case you want to load some assets in bulk before starting the game.
106
- ### AI tools
107
- including, but not limited to:
108
- * full-fledged Behavior trees
109
- * Blackboard (took for recording information useful for AI to read/write relevant world state, very commonly used with Behavior Trees)
110
- * monte-carlo tree search (same as Google's AlphaGo, useful for decision-making)
111
- * state optimization (useful for decision-making)
112
- * grid-based path finding (optimized for 10,000s of queries per second)
113
- * resource allocation solver (useful for planning, given certain resources such as bullets/grenades/money/health - plan what actions to take to optimize your chances of winning)
114
- * and a number of other useful tools to complement development of game AI and other intelligent behavior use cases.
115
- ### High-performance serialization
116
- Extremely compact binary serialization system. You can save/load your scenes from files. This serialization system supports format changes, so as you develop your game - old saves will be supported and the system will automatically upgrade them to the most recent version, so the player doesn't have to lose any data.
117
- ### Achievements
118
- Achievements work with Blackboard components and are very easy to define. There is an abstraction system that helps connect your achievements to various platforms such as Steam or XBox (you'd have to implement that binding yourself though), by default it comes with a browser backend, storing data in IndexedDB. I also have bindings for Steam and NewGrounds that I can share.
119
- ### UI system
120
- You're free to use it or not, the engine works just fine without it. The system is written for speed, and it offers a few commonly used tools, such as popup windows, notifications and pages. The UI system is optimized for speed, so it generates no garbage, but again - if you want to use, say React - you can ignore this system or integrate it with the system.
121
-
122
-
123
- For more information, please refer to the documentation
124
108
 
125
- ---
126
- Copyright © 2025 Company Named Limited, All Rights Reserved
109
+ ## License & Copyright
110
+ Copyright © 2025 Company Named Limited, All Rights Reserved.
@@ -1,8 +1,8 @@
1
- import { TypeEditor } from "../../TypeEditor.js";
2
1
  import Vector3 from "../../../../../src/core/geom/Vector3.js";
3
- import { makeV3_editor } from "../common/makeV3_editor.js";
4
2
  import { DEG_TO_RAD } from "../../../../../src/core/math/DEG_TO_RAD.js";
5
3
  import { RAD_TO_DEG } from "../../../../../src/core/math/RAD_TO_DEG.js";
4
+ import { TypeEditor } from "../../TypeEditor.js";
5
+ import { makeV3_editor } from "../common/makeV3_editor.js";
6
6
 
7
7
  export class QuaternionEditor extends TypeEditor {
8
8
  build(parent, field, registry) {
@@ -22,7 +22,7 @@ export class QuaternionEditor extends TypeEditor {
22
22
 
23
23
  lock = true;
24
24
 
25
- q.__setFromEuler(
25
+ q.fromEulerAnglesXYZ(
26
26
  euler.x * DEG_TO_RAD,
27
27
  euler.y * DEG_TO_RAD,
28
28
  euler.z * DEG_TO_RAD
@@ -103,7 +103,7 @@ class TransformContainer {
103
103
  allowWriteToSurrogate = false;
104
104
 
105
105
  try {
106
- transform.rotation.__setFromEuler(surrogate.rotation.x, surrogate.rotation.y, surrogate.rotation.z, 'XYZ');
106
+ transform.rotation.fromEulerAnglesXYZ(surrogate.rotation.x, surrogate.rotation.y, surrogate.rotation.z);
107
107
  } catch (e) {
108
108
  console.error(e);
109
109
  }
@@ -131,7 +131,13 @@ class TransformContainer {
131
131
 
132
132
  //set surrogate transform to match component
133
133
  surrogate.position.copy(transform.position);
134
- transform.rotation.__setFromEuler(surrogate.rotation.x, surrogate.rotation.y, surrogate.rotation.z, surrogate.rotation.order);
134
+
135
+ if (surrogate.rotation.order === "XYZ") {
136
+ transform.rotation.fromEulerAnglesXYZ(surrogate.rotation.x, surrogate.rotation.y, surrogate.rotation.z);
137
+ } else {
138
+ throw new Error("Unsupported rotation order");
139
+ }
140
+
135
141
  surrogate.quaternion.copy(transform.rotation);
136
142
  surrogate.scale.copy(transform.scale);
137
143
 
@@ -160,7 +166,12 @@ class TransformContainer {
160
166
  if (allowWriteToSurrogate) {
161
167
  const rotation = transform.rotation;
162
168
 
163
- rotation.__setFromEuler(surrogate.rotation.x, surrogate.rotation.y, surrogate.rotation.z, surrogate.rotation.order);
169
+ if (surrogate.rotation.order === "XYZ") {
170
+ rotation.fromEulerAnglesXYZ(surrogate.rotation.x, surrogate.rotation.y, surrogate.rotation.z);
171
+ } else {
172
+ throw new Error("Unsupported rotation order");
173
+ }
174
+
164
175
 
165
176
  surrogate.quaternion.set(rotation.x, rotation.y, rotation.z, rotation.w);
166
177
  }
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "description": "Pure JavaScript game engine. Fully featured and production ready.",
6
6
  "type": "module",
7
7
  "author": "Alexander Goldring",
8
- "version": "2.131.17",
8
+ "version": "2.131.20",
9
9
  "main": "build/meep.module.js",
10
10
  "module": "build/meep.module.js",
11
11
  "exports": {
@@ -71,7 +71,7 @@ export class Quaternion implements Iterable<number> {
71
71
  */
72
72
  w: number;
73
73
  /**
74
- * Fired when value of the quaternion changes
74
+ * Fires when the value of the quaternion changes
75
75
  * Signature of the signal data is as follows:
76
76
  * (new_x, new_y, new_z, new_w, old_x, old_y, old_z, old_w)
77
77
  * @readonly
@@ -122,6 +122,9 @@ export class Quaternion implements Iterable<number> {
122
122
  * Orient quaternion on a `forward` vector, with the spin matching `up` vector
123
123
  * Useful for `lookAt` operations, such as for camera or inverse kinematics.
124
124
  * Normalizes input, meaning input does not have to be normalized.
125
+ *
126
+ * NOTE: `forward` and `up` vectors being the same is allowed, but you will likely get unexpected rotation along the look axis, so prefer not to do it.
127
+ *
125
128
  * @param {number} fx forward vector
126
129
  * @param {number} fy forward vector
127
130
  * @param {number} fz forward vector
@@ -151,10 +154,20 @@ export class Quaternion implements Iterable<number> {
151
154
  */
152
155
  copyInverse(other: Quaternion): this;
153
156
  /**
154
- * Calculates the inverse
157
+ * Calculates the inverse.
158
+ * Correctly handles unnormalized quaternions.
159
+ *
160
+ * If your quaternion is normalized, you can use {@link conjugate} instead for speed.
155
161
  * @returns {this}
162
+ * @see conjugate
156
163
  */
157
164
  invert(): this;
165
+ /**
166
+ * NOTE: this is the same as {@link invert} if the quaternion is normalized.
167
+ * @returns {this}
168
+ * @see invert
169
+ */
170
+ conjugate(): this;
158
171
  /**
159
172
  * Returns angle between this orientation and another
160
173
  * @param {Quaternion} other
@@ -256,17 +269,14 @@ export class Quaternion implements Iterable<number> {
256
269
  */
257
270
  lookAt(source: Vector3, target: Vector3, up?: Vector3): void;
258
271
  /**
259
- * @deprecated use {@link random} instead
260
- * @param {function():number} random
261
- */
262
- setRandom(random: () => number): void;
263
- /**
272
+ * @deprecated use {@link fromEulerAnglesXYZ} or others specifically.
264
273
  *
265
274
  * @param {number} x
266
275
  * @param {number} y
267
276
  * @param {number} z
268
277
  * @param {String} [order='XYZ'] a combination of capital letters X,Y,Z. Examples: XYZ, YXZ
269
278
  * @returns {this}
279
+ *
270
280
  * @see fromEulerAnglesXYZ
271
281
  * @see fromEulerAnglesYXZ
272
282
  * @see fromEulerAnglesZXY
@@ -291,6 +301,21 @@ export class Quaternion implements Iterable<number> {
291
301
  * @param {Vector3} result
292
302
  */
293
303
  toEulerAnglesZYX(result: Vector3): void;
304
+ /**
305
+ * Set rotation from Euler angles in degrees.
306
+ *
307
+ * Order is explicitly XYZ.
308
+ *
309
+ * Utility shortcut, same as `fromEulerAnglesXYZ(x * π / 180, y * π / 180, z * π / 180)`
310
+ *
311
+ * @param {number} [x] angle in degrees
312
+ * @param {number} [y] angle in degrees
313
+ * @param {number} [z] angle in degrees
314
+ * @returns {this}
315
+ *
316
+ * @see fromEulerAnglesXYZ
317
+ */
318
+ fromDegrees(x?: number, y?: number, z?: number): this;
294
319
  /**
295
320
  * XYZ order
296
321
  * @source: https://stackoverflow.com/questions/12088610/conversion-between-euler-quaternion-like-in-unity3d-engine
@@ -445,11 +470,6 @@ export class Quaternion implements Iterable<number> {
445
470
  * @returns {this}
446
471
  */
447
472
  set(x: number, y: number, z: number, w: number): this;
448
- /**
449
- *
450
- * @returns {this}
451
- */
452
- conjugate(): this;
453
473
  toJSON(): {
454
474
  x: number;
455
475
  y: number;
@@ -488,14 +508,14 @@ export class Quaternion implements Iterable<number> {
488
508
  * @param {number} [offset]
489
509
  * @returns {this}
490
510
  */
491
- readFromArray(array: number[], offset?: number): this;
511
+ fromArray(array: number[], offset?: number): this;
492
512
  /**
493
513
  *
494
514
  * @param {number[]} [array]
495
515
  * @param {number} [offset]
496
516
  * @returns {number[]}
497
517
  */
498
- writeToArray(array?: number[], offset?: number): number[];
518
+ toArray(array?: number[], offset?: number): number[];
499
519
  /**
500
520
  * Strict equality check
501
521
  * @param {Quaternion} other
@@ -525,15 +545,28 @@ export class Quaternion implements Iterable<number> {
525
545
  * @return {boolean}
526
546
  */
527
547
  _roughlyEquals(x: number, y: number, z: number, w: number, tolerance?: number): boolean;
548
+ /**
549
+ * @deprecated use {@link random} instead
550
+ * @param {function():number} random
551
+ */
552
+ setRandom(random: () => number): void;
528
553
  /**
529
554
  * Randomly orient current quaternion
530
- * @param {function():number} [random] Defaults to {@link Math.random}
531
- * @return {Quaternion}
555
+ * @param {function():number} [random=Math.random] Random number generator function.
532
556
  */
533
- random(random?: () => number): Quaternion;
557
+ random(random?: () => number): this;
534
558
  toString(): string;
535
- fromArray: (array: number[], offset?: number) => this;
536
- toArray: (array?: number[], offset?: number) => number[];
559
+ /**
560
+ * @deprecated use `fromArray`
561
+ */
562
+ readFromArray: (array: number[], offset?: number) => this;
563
+ /**
564
+ * @deprecated use `toArray`
565
+ */
566
+ writeToArray: (array?: number[], offset?: number) => number[];
567
+ /**
568
+ * @deprecated use `toArray`
569
+ */
537
570
  asArray: (array?: number[], offset?: number) => number[];
538
571
  fromEulerAngles: (x: number, y: number, z: number) => this;
539
572
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"Quaternion.d.ts","sourceRoot":"","sources":["../../../../src/core/geom/Quaternion.js"],"names":[],"mappings":"AAoBA;;;;;;;;;;;GAWG;AACH,4CALwB,MAAM;IA+R1B;;;;;OAKG;IACH,2BAJW,OAAO,SACP,MAAM,GACJ,UAAU,CAQtB;IAiqCD;;;;OAIG;IACH,kCAFa,UAAU,CAQtB;IAED;;;;;;;OAOG;IACH,0BALW,MAAM,KACN,MAAM,KACN,MAAM,GACJ,UAAU,CAQtB;IAED;;;;;;OAMG;IACH,6BALW,UAAU,QACV,UAAU,MACV,UAAU,aACV,MAAM,QA0BhB;IAlgDD;;;;;;;OAOG;IACH,gBANW,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,EAsChB;IA7BG;;;OAGG;IACH,GAFU,MAAM,CAEN;IACV;;;OAGG;IACH,GAFU,MAAM,CAEN;IACV;;;OAGG;IACH,GAFU,MAAM,CAEN;IACV;;;OAGG;IACH,GAFU,MAAM,CAEN;IAEV;;;;;;OAMG;IACH,oBAFU,OAAO,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAEnD;IAqCjC;;;OAGG;IACH,mBAEC;IAtCD;;;OAGG;IACH,gBAEC;IAkCD;;;OAGG;IACH,mBAEC;IAtCD;;;OAGG;IACH,gBAEC;IAkCD;;;OAGG;IACH,mBAEC;IAtCD;;;OAGG;IACH,gBAEC;IAkCD;;;OAGG;IACH,mBAEC;IAtCD;;;OAGG;IACH,gBAEC;IAgDD;;;;;;;;;;;OAWG;IACH,kBARW,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,GACJ,IAAI,CAqDhB;IAED;;;;;OAKG;IACH,sBAJW,OAAO,OACP,OAAO,GACL,IAAI,C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,MAAM,KACN,MAAM,KACN,MAAM,GACJ,IAAI,CA+BhB;IAED;;;OAGG;IACH,aAFa,IAAI,CAIhB;IAED;;;;;MAOC;IAED;;;;OAIG;IACH,oBAFY,IAAI,CAIf;IAED;;;OAGG;IACH,2CAKC;IAED;;;OAGG;IACH,6CAOC;IAED;;;OAGG;IACH,kDAKC;IAED;;;OAGG;IACH,oDAOC;IAED;;;;;OAKG;IACH,qBAJW,MAAM,EAAE,WACR,MAAM,GACJ,IAAI,CAShB;IAED;;;;;OAKG;IACH,qBAJW,MAAM,EAAE,WACR,MAAM,GACJ,MAAM,EAAE,CASpB;IAED;;;;;OAKG;IACH,cAJW,UAAU,GACR,OAAO,CASnB;IAED;;;OAGG;IACH,QAFa,MAAM,CAQlB;IAED;;;;;OAKG;IACH,qBAJW,UAAU,cACV,MAAM,GACL,OAAO,CAOlB;IAED;;;;;;;;OAQG;IACH,kBAPW,MAAM,KACN,MAAM,KACN,MAAM,KACN,MAAM,cACN,MAAM,GACL,OAAO,CASlB;IAED;;;;OAIG;IACH,sBAHsB,MAAM,GAChB,UAAU,CAuBrB;IAED,mBAEC;IAiEL,mBApLe,MAAM,EAAE,WACR,MAAM,KACJ,IAAI,CAkLS;IAC9B,kBAtKe,MAAM,EAAE,WACR,MAAM,KACJ,MAAM,EAAE,CAoKG;IAC5B,kBAvKe,MAAM,EAAE,WACR,MAAM,KACJ,MAAM,EAAE,CAqKG;IAC5B,qBA3yBe,MAAM,KACN,MAAM,KACN,MAAM,KACJ,IAAI,CAwyBe;IAQpC;;;;OAIG;IACH,uBAFU,OAAO,CAEgB;IAt6C7B;;;OAGG;IACH,qBAFa,UAAU,MAAM,CAAC,CAS7B;CAy4CJ;;kBASS,UAAU;kBAaV,MAAM;;;mBAzjDG,4BAA4B;oBAU3B,cAAc"}
1
+ {"version":3,"file":"Quaternion.d.ts","sourceRoot":"","sources":["../../../../src/core/geom/Quaternion.js"],"names":[],"mappings":"AAqBA;;;;;;;;;;;GAWG;AACH,4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AED;;;OAGG;IACH,2CAKC;IAED;;;OAGG;IACH,6CAOC;IAED;;;OAGG;IACH,kDAKC;IAED;;;OAGG;IACH,oDAOC;IAED;;;;;OAKG;IACH,iBAJW,MAAM,EAAE,WACR,MAAM,GACJ,IAAI,CAYhB;IAED;;;;;OAKG;IACH,gBAJW,MAAM,EAAE,WACR,MAAM,GACJ,MAAM,EAAE,CAYpB;IAED;;;;;OAKG;IACH,cAJW,UAAU,GACR,OAAO,CASnB;IAED;;;OAGG;IACH,QAFa,MAAM,CAQlB;IAED;;;;;OAKG;IACH,qBAJW,UAAU,cACV,MAAM,GACL,OAAO,CAOlB;IAED;;;;;;;;OAQG;IACH,kBAPW,MAAM,KACN,MAAM,KACN,MAAM,KACN,MAAM,cACN,MAAM,GACL,OAAO,CASlB;IAED;;;OAGG;IACH,wBAFsB,MAAM,QAI3B;IAED;;;OAGG;IACH,sBAFsB,MAAM,QAuB3B;IAED,mBAEC;IAiEL;;OAEG;IACH,uBApMe,MAAM,EAAE,WACR,MAAM,KACJ,IAAI,CAkMa;IAElC;;OAEG;IACH,uBAvLe,MAAM,EAAE,WACR,MAAM,KACJ,MAAM,EAAE,CAqLQ;IAEjC;;OAEG;IACH,kBA5Le,MAAM,EAAE,WACR,MAAM,KACJ,MAAM,EAAE,CA0LG;IAC5B,qBA3zBe,MAAM,KACN,MAAM,KACN,MAAM,KACJ,IAAI,CAwzBe;IAQpC;;;;OAIG;IACH,uBAFU,OAAO,CAEgB;IAv9C7B;;;OAGG;IACH,qBAFa,UAAU,MAAM,CAAC,CAS7B;CA+6CJ;;kBAoBS,UAAU;kBAaV,MAAM;;;mBA3mDG,4BAA4B;oBAW3B,cAAc"}
@@ -2,6 +2,7 @@ import { assert } from "../assert.js";
2
2
  import Signal from "../events/signal/Signal.js";
3
3
  import { clamp } from "../math/clamp.js";
4
4
  import { clamp01 } from "../math/clamp01.js";
5
+ import { DEG_TO_RAD } from "../math/DEG_TO_RAD.js";
5
6
  import { EPSILON } from "../math/EPSILON.js";
6
7
  import { epsilonEquals } from "../math/epsilonEquals.js";
7
8
  import { lerp } from "../math/lerp.js";
@@ -67,7 +68,7 @@ export class Quaternion {
67
68
  this.w = w;
68
69
 
69
70
  /**
70
- * Fired when value of the quaternion changes
71
+ * Fires when the value of the quaternion changes
71
72
  * Signature of the signal data is as follows:
72
73
  * (new_x, new_y, new_z, new_w, old_x, old_y, old_z, old_w)
73
74
  * @readonly
@@ -160,6 +161,9 @@ export class Quaternion {
160
161
  * Orient quaternion on a `forward` vector, with the spin matching `up` vector
161
162
  * Useful for `lookAt` operations, such as for camera or inverse kinematics.
162
163
  * Normalizes input, meaning input does not have to be normalized.
164
+ *
165
+ * NOTE: `forward` and `up` vectors being the same is allowed, but you will likely get unexpected rotation along the look axis, so prefer not to do it.
166
+ *
163
167
  * @param {number} fx forward vector
164
168
  * @param {number} fy forward vector
165
169
  * @param {number} fz forward vector
@@ -260,8 +264,12 @@ export class Quaternion {
260
264
  }
261
265
 
262
266
  /**
263
- * Calculates the inverse
267
+ * Calculates the inverse.
268
+ * Correctly handles unnormalized quaternions.
269
+ *
270
+ * If your quaternion is normalized, you can use {@link conjugate} instead for speed.
264
271
  * @returns {this}
272
+ * @see conjugate
265
273
  */
266
274
  invert() {
267
275
  const x = this.x;
@@ -269,14 +277,14 @@ export class Quaternion {
269
277
  const z = this.z;
270
278
  const w = this.w;
271
279
 
272
- const length_sqr = x * x + y * y + z * z + w * w;
280
+ const dot_product = x * x + y * y + z * z + w * w;
273
281
 
274
- if (length_sqr === 0) {
282
+ if (dot_product === 0) {
275
283
  // 0 magnitude, avoid division by 0 and set identity (arbitrage)
276
284
  return this.set(0, 0, 0, 1);
277
285
  }
278
286
 
279
- const invDot = 1.0 / length_sqr;
287
+ const invDot = 1.0 / dot_product;
280
288
 
281
289
  const _x = -x * invDot;
282
290
  const _y = -y * invDot;
@@ -286,6 +294,15 @@ export class Quaternion {
286
294
  return this.set(_x, _y, _z, _w);
287
295
  }
288
296
 
297
+ /**
298
+ * NOTE: this is the same as {@link invert} if the quaternion is normalized.
299
+ * @returns {this}
300
+ * @see invert
301
+ */
302
+ conjugate() {
303
+ return this.set(-this.x, -this.y, -this.z, this.w);
304
+ }
305
+
289
306
  /**
290
307
  * Returns angle between this orientation and another
291
308
  * @param {Quaternion} other
@@ -602,21 +619,16 @@ export class Quaternion {
602
619
  this.lookRotation(forward, up);
603
620
  }
604
621
 
605
- /**
606
- * @deprecated use {@link random} instead
607
- * @param {function():number} random
608
- */
609
- setRandom(random) {
610
- throw new Error("use .random() instead");
611
- }
612
622
 
613
623
  /**
624
+ * @deprecated use {@link fromEulerAnglesXYZ} or others specifically.
614
625
  *
615
626
  * @param {number} x
616
627
  * @param {number} y
617
628
  * @param {number} z
618
629
  * @param {String} [order='XYZ'] a combination of capital letters X,Y,Z. Examples: XYZ, YXZ
619
630
  * @returns {this}
631
+ *
620
632
  * @see fromEulerAnglesXYZ
621
633
  * @see fromEulerAnglesYXZ
622
634
  * @see fromEulerAnglesZXY
@@ -758,6 +770,28 @@ export class Quaternion {
758
770
  result.set(psi, theta, phi);
759
771
  }
760
772
 
773
+ /**
774
+ * Set rotation from Euler angles in degrees.
775
+ *
776
+ * Order is explicitly XYZ.
777
+ *
778
+ * Utility shortcut, same as `fromEulerAnglesXYZ(x * π / 180, y * π / 180, z * π / 180)`
779
+ *
780
+ * @param {number} [x] angle in degrees
781
+ * @param {number} [y] angle in degrees
782
+ * @param {number} [z] angle in degrees
783
+ * @returns {this}
784
+ *
785
+ * @see fromEulerAnglesXYZ
786
+ */
787
+ fromDegrees(x = 0, y = 0, z = 0) {
788
+ return this.fromEulerAnglesXYZ(
789
+ x * DEG_TO_RAD,
790
+ y * DEG_TO_RAD,
791
+ z * DEG_TO_RAD
792
+ );
793
+ }
794
+
761
795
 
762
796
  /**
763
797
  * XYZ order
@@ -1316,14 +1350,6 @@ export class Quaternion {
1316
1350
  return this;
1317
1351
  }
1318
1352
 
1319
- /**
1320
- *
1321
- * @returns {this}
1322
- */
1323
- conjugate() {
1324
- return this.set(-this.x, -this.y, -this.z, this.w);
1325
- }
1326
-
1327
1353
  toJSON() {
1328
1354
  return {
1329
1355
  x: this.x,
@@ -1396,7 +1422,10 @@ export class Quaternion {
1396
1422
  * @param {number} [offset]
1397
1423
  * @returns {this}
1398
1424
  */
1399
- readFromArray(array, offset = 0) {
1425
+ fromArray(array, offset = 0) {
1426
+ assert.defined(array, "array");
1427
+ assert.isNonNegativeInteger(offset, "offset");
1428
+
1400
1429
  return this.set(
1401
1430
  array[offset],
1402
1431
  array[offset + 1],
@@ -1411,7 +1440,10 @@ export class Quaternion {
1411
1440
  * @param {number} [offset]
1412
1441
  * @returns {number[]}
1413
1442
  */
1414
- writeToArray(array = [], offset = 0) {
1443
+ toArray(array = [], offset = 0) {
1444
+ assert.defined(array, 'array');
1445
+ assert.isNonNegativeInteger(offset, "offset");
1446
+
1415
1447
  array[offset] = this.x;
1416
1448
  array[offset + 1] = this.y;
1417
1449
  array[offset + 2] = this.z;
@@ -1477,10 +1509,17 @@ export class Quaternion {
1477
1509
  && epsilonEquals(this.w, w, tolerance);
1478
1510
  }
1479
1511
 
1512
+ /**
1513
+ * @deprecated use {@link random} instead
1514
+ * @param {function():number} random
1515
+ */
1516
+ setRandom(random) {
1517
+ throw new Error("use .random() instead");
1518
+ }
1519
+
1480
1520
  /**
1481
1521
  * Randomly orient current quaternion
1482
- * @param {function():number} [random] Defaults to {@link Math.random}
1483
- * @return {Quaternion}
1522
+ * @param {function():number} [random=Math.random] Random number generator function.
1484
1523
  */
1485
1524
  random(random = Math.random) {
1486
1525
  assert.isFunction(random, 'random');
@@ -1572,9 +1611,20 @@ export class Quaternion {
1572
1611
  }
1573
1612
  }
1574
1613
 
1575
- Quaternion.prototype.fromArray = Quaternion.prototype.readFromArray;
1576
- Quaternion.prototype.toArray = Quaternion.prototype.writeToArray;
1577
- Quaternion.prototype.asArray = Quaternion.prototype.writeToArray;
1614
+ /**
1615
+ * @deprecated use `fromArray`
1616
+ */
1617
+ Quaternion.prototype.readFromArray = Quaternion.prototype.fromArray;
1618
+
1619
+ /**
1620
+ * @deprecated use `toArray`
1621
+ */
1622
+ Quaternion.prototype.writeToArray = Quaternion.prototype.toArray;
1623
+
1624
+ /**
1625
+ * @deprecated use `toArray`
1626
+ */
1627
+ Quaternion.prototype.asArray = Quaternion.prototype.toArray;
1578
1628
  Quaternion.prototype.fromEulerAngles = Quaternion.prototype.fromEulerAnglesXYZ;
1579
1629
 
1580
1630
  /**