aether-physics 0.0.0-stage → 0.2.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Brandon Berisford
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,95 @@
1
- # Temporary Holding Version
1
+ # Aether
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ A 3D rigid-body physics engine written from scratch in TypeScript, with a browser playground built on Lit and Three.js.
4
+
5
+ This is a learning project. The engine is built in phases, from vectors to stacking boxes to ragdolls, following Ian Millington's *Game Physics Engine Development*, Erin Catto's solver talks, and the resources collected at [brm.io/game-physics-for-beginners](https://brm.io/game-physics-for-beginners/).
6
+
7
+ - **[docs/PLAN.md](docs/PLAN.md):** the phased build plan, with goals, checklists, tests and demos for each phase
8
+ - **[docs/RESOURCES.md](docs/RESOURCES.md):** books, articles, talks and reference engines for each phase
9
+ - **[docs/DEMOS.md](docs/DEMOS.md):** how to build a demo: templates, using the engine from Three.js, demo controls and UI style
10
+
11
+ **[Try the playground](https://beyondbelief96.github.io/aether/)**. Each push to `main` deploys it to GitHub Pages.
12
+
13
+ ## Using the package
14
+
15
+ ```sh
16
+ npm install aether-physics
17
+ ```
18
+
19
+ ```ts
20
+ import { Quaternion, Vec3 } from 'aether-physics';
21
+
22
+ const q = new Quaternion().setFromAxisAngle({ x: 0, y: 1, z: 0 }, Math.PI / 2);
23
+ q.rotateVec3({ x: 1, y: 0, z: 0 }, new Vec3()); // about (0, 0, -1)
24
+ ```
25
+
26
+ Point masses move under forces in a fixed-timestep world:
27
+
28
+ ```ts
29
+ import { Particle, ParticleWorld } from 'aether-physics';
30
+
31
+ const ball = new Particle();
32
+ ball.position.set(0, 10, 0);
33
+ ball.velocity.set(3, 4, 0);
34
+ ball.acceleration.set(0, -9.81, 0);
35
+
36
+ const world = new ParticleWorld();
37
+ world.particles.push(ball);
38
+ for (let i = 0; i < 60; i++) world.step(1 / 60); // one simulated second
39
+ ```
40
+
41
+ It's early: so far the package has the math library, a fixed-timestep loop and particles. Rigid bodies and collisions arrive with the later phases below, and the API can change in any 0.x release. See the [engine API guide](src/engine/README.md) and the [math API guide](src/math/README.md).
42
+
43
+ ## Running it
44
+
45
+ ```sh
46
+ npm install
47
+ npm run dev # playground at http://localhost:5173
48
+ npm test # Vitest in watch mode
49
+ npm run test:run # Vitest once
50
+ npm run test:smoke # load the built playground in Chrome (run npm run build first)
51
+ npm run typecheck # tsc, no emit
52
+ npm run build # typecheck, then production build of the playground to dist-playground/
53
+ npm run build:lib # build the npm package to dist/
54
+ ```
55
+
56
+ Keyboard: **Space** pauses, **.** steps once while paused, **R** resets the demo.
57
+
58
+ ## Layout
59
+
60
+ ```
61
+ src/
62
+ math/ Vec3, Mat3, Mat4, Quat Phase 1
63
+ engine/ game loop, Particle, RigidBody, World Phases 0, 2, 4, 7
64
+ forces/ force generators Phases 3, 4
65
+ collision/ shapes, broadphase, narrowphase Phase 5
66
+ constraints/ contact solver, joints Phases 6, 7
67
+ playground/ the app in the browser, which uses the engine only through "aether-physics"
68
+ demos/ one file per demo (the only engine + Three.js code)
69
+ ui/ Lit components
70
+ ```
71
+
72
+ ## Rules
73
+
74
+ - The engine (`math`, `engine`, `forces`, `collision`, `constraints`) never imports `three` or touches the DOM. Demos are the bridge.
75
+ - Physics runs on a fixed timestep; rendering interpolates between steps.
76
+ - TypeScript runs with `erasableSyntaxOnly`: no `enum`, `namespace` or parameter properties.
77
+ - Lit components use `static properties` with `declare` fields and `customElements.define`, never decorators.
78
+
79
+ ## Progress
80
+
81
+ | Phase | Topic | Status |
82
+ |---|---|---|
83
+ | 0 | Scaffold and game loop | ✅ |
84
+ | 1 | Math library | ✅ |
85
+ | 2 | Particles and integration | ✅ |
86
+ | 3 | Forces, springs and mass aggregates | |
87
+ | 4 | Rigid bodies | |
88
+ | 5 | Collision detection | |
89
+ | 6 | Collision response and friction | |
90
+ | 7 | Joints, sleeping and stability | |
91
+ | 8 | Stretch goals | |
92
+
93
+ ## License
94
+
95
+ [MIT](LICENSE)
package/dist/index.js ADDED
@@ -0,0 +1,88 @@
1
+ import { a as e, i as t, n, o as r, r as i, s as a, t as o } from "./math-DrI-pge3.js";
2
+ //#region src/engine/loop.ts
3
+ var s = .25, c = class {
4
+ timeScale = 1;
5
+ paused = !1;
6
+ maxStepsPerFrame = 8;
7
+ #e;
8
+ #t = 0;
9
+ #n = null;
10
+ #r = 0;
11
+ #i = 0;
12
+ constructor(e = 60) {
13
+ this.#e = 1 / e;
14
+ }
15
+ get dt() {
16
+ return this.#e;
17
+ }
18
+ get hz() {
19
+ return 1 / this.#e;
20
+ }
21
+ set hz(e) {
22
+ if (!(e > 0)) throw RangeError(`hz must be positive, got ${e}`);
23
+ this.#e = 1 / e;
24
+ }
25
+ get simTime() {
26
+ return this.#r;
27
+ }
28
+ stepOnce() {
29
+ this.#i++;
30
+ }
31
+ reset() {
32
+ this.#t = 0, this.#n = null, this.#r = 0, this.#i = 0;
33
+ }
34
+ advance(e, t) {
35
+ let n = this.#n;
36
+ this.#n = e;
37
+ let r = n === null ? 0 : Math.min((e - n) / 1e3, s), i = 0, a = () => {
38
+ t(this.#e), this.#r += this.#e, i++;
39
+ };
40
+ for (; this.#i > 0; this.#i--) a();
41
+ if (this.paused) return {
42
+ steps: i,
43
+ alpha: 1,
44
+ droppedTime: !1
45
+ };
46
+ for (this.#t += r * this.timeScale; this.#t >= this.#e && i < this.maxStepsPerFrame;) a(), this.#t -= this.#e;
47
+ let o = !1;
48
+ return this.#t >= this.#e && (this.#t %= this.#e, o = !0), {
49
+ steps: i,
50
+ alpha: this.#t / this.#e,
51
+ droppedTime: o
52
+ };
53
+ }
54
+ }, l = class {
55
+ position = new t();
56
+ velocity = new t();
57
+ acceleration = new t();
58
+ forceAccum = new t();
59
+ damping = .99;
60
+ inverseMass = 1;
61
+ get mass() {
62
+ return this.inverseMass === 0 ? Infinity : 1 / this.inverseMass;
63
+ }
64
+ setMass(e) {
65
+ if (!(e > 0)) throw RangeError(`mass must be positive, got ${e}`);
66
+ this.inverseMass = 1 / e;
67
+ }
68
+ hasFiniteMass() {
69
+ return this.inverseMass > 0;
70
+ }
71
+ addForce(e) {
72
+ this.forceAccum.add(e);
73
+ }
74
+ clearAccumulator() {
75
+ this.forceAccum.set(0, 0, 0);
76
+ }
77
+ integrate(e) {
78
+ if (!(e > 0)) throw RangeError(`dt must be positive, got ${e}`);
79
+ this.inverseMass > 0 && (this.velocity.addScaled(this.acceleration, e).addScaled(this.forceAccum, this.inverseMass * e).scale(this.damping ** +e), this.position.addScaled(this.velocity, e)), this.clearAccumulator();
80
+ }
81
+ }, u = class {
82
+ particles = [];
83
+ step(e) {
84
+ for (let t of this.particles) t.integrate(e);
85
+ }
86
+ };
87
+ //#endregion
88
+ export { e as EPSILON, c as FixedStepLoop, i as Mat3x3, n as Mat3x4, l as Particle, u as ParticleWorld, o as Quaternion, t as Vec3, r as approxEqual, a as clamp };