aether-physics 0.1.0 → 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 CHANGED
@@ -1,21 +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.
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,79 +1,95 @@
1
- # Aether
2
-
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
- It's early: so far the package has the math library and a fixed-timestep loop. Physics arrives with the later phases below, and the API can change in any 0.x release.
27
-
28
- ## Running it
29
-
30
- ```sh
31
- npm install
32
- npm run dev # playground at http://localhost:5173
33
- npm test # Vitest in watch mode
34
- npm run test:run # Vitest once
35
- npm run typecheck # tsc, no emit
36
- npm run build # typecheck, then production build of the playground to dist-playground/
37
- npm run build:lib # build the npm package to dist/
38
- ```
39
-
40
- Keyboard: **Space** pauses, **.** steps once while paused, **R** resets the demo.
41
-
42
- ## Layout
43
-
44
- ```
45
- src/
46
- math/ Vec3, Mat3, Mat4, Quat Phase 1
47
- engine/ game loop, Particle, RigidBody, World Phases 0, 2, 4, 7
48
- forces/ force generators Phases 3, 4
49
- collision/ shapes, broadphase, narrowphase Phase 5
50
- constraints/ contact solver, joints Phases 6, 7
51
- playground/ the app in the browser, which uses the engine only through "aether-physics"
52
- demos/ one file per demo (the only engine + Three.js code)
53
- ui/ Lit components
54
- ```
55
-
56
- ## Rules
57
-
58
- - The engine (`math`, `engine`, `forces`, `collision`, `constraints`) never imports `three` or touches the DOM. Demos are the bridge.
59
- - Physics runs on a fixed timestep; rendering interpolates between steps.
60
- - TypeScript runs with `erasableSyntaxOnly`: no `enum`, `namespace` or parameter properties.
61
- - Lit components use `static properties` with `declare` fields and `customElements.define`, never decorators.
62
-
63
- ## Progress
64
-
65
- | Phase | Topic | Status |
66
- |---|---|---|
67
- | 0 | Scaffold and game loop | ✅ |
68
- | 1 | Math library | ✅ |
69
- | 2 | Particles and integration | |
70
- | 3 | Forces, springs and mass aggregates | |
71
- | 4 | Rigid bodies | |
72
- | 5 | Collision detection | |
73
- | 6 | Collision response and friction | |
74
- | 7 | Joints, sleeping and stability | |
75
- | 8 | Stretch goals | |
76
-
77
- ## License
78
-
79
- [MIT](LICENSE)
1
+ # Aether
2
+
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 CHANGED
@@ -51,6 +51,38 @@ var s = .25, c = class {
51
51
  droppedTime: o
52
52
  };
53
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
+ }
54
86
  };
55
87
  //#endregion
56
- export { e as EPSILON, c as FixedStepLoop, i as Mat3x3, n as Mat3x4, o as Quaternion, t as Vec3, r as approxEqual, a as clamp };
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 };
@@ -0,0 +1,4 @@
1
+ export { FixedStepLoop } from "./loop.js";
2
+ export type { FrameResult } from "./loop.js";
3
+ export { Particle } from "./particle.js";
4
+ export { ParticleWorld } from "./particle-world.js";
@@ -0,0 +1,13 @@
1
+ import type { Particle } from "./particle.js";
2
+ /** A collection of particles stepped together. */
3
+ export declare class ParticleWorld {
4
+ /** Particles in this world, integrated in array order. Add and remove them directly. */
5
+ readonly particles: Particle[];
6
+ /**
7
+ * Integrates every particle by one step.
8
+ *
9
+ * @param dt Step length in seconds.
10
+ * @throws RangeError If `dt` is not positive and the world has particles.
11
+ */
12
+ step(dt: number): void;
13
+ }
@@ -0,0 +1,51 @@
1
+ import { Vec3, type Vec3Like } from "../math/index.js";
2
+ /**
3
+ * A point mass integrated with semi-implicit Euler.
4
+ *
5
+ * Mass is stored as its inverse, so `inverseMass = 0` represents an immovable particle.
6
+ * Vector fields are `readonly` references: change them in place, e.g.
7
+ * `particle.position.set(0, 1, 0)`.
8
+ */
9
+ export declare class Particle {
10
+ /** Position in meters. */
11
+ readonly position: Vec3;
12
+ /** Velocity in meters per second. */
13
+ readonly velocity: Vec3;
14
+ /** Constant acceleration in m/s², independent of mass. Typically gravity. */
15
+ readonly acceleration: Vec3;
16
+ /** Sum of forces in newtons applied since the last `integrate`. */
17
+ readonly forceAccum: Vec3;
18
+ /** Fraction of velocity kept per second, in [0, 1]. `1` disables damping. */
19
+ damping: number;
20
+ /** Reciprocal of mass in 1/kg. `0` makes the particle immovable. */
21
+ inverseMass: number;
22
+ /** Mass in kilograms. `Infinity` when `inverseMass` is `0`. */
23
+ get mass(): number;
24
+ /**
25
+ * Sets the mass.
26
+ *
27
+ * @param mass Mass in kilograms. `Infinity` makes the particle immovable.
28
+ * @throws RangeError If `mass` is not positive.
29
+ */
30
+ setMass(mass: number): void;
31
+ /** Whether forces and integration can move this particle. */
32
+ hasFiniteMass(): boolean;
33
+ /**
34
+ * Adds a force for the next `integrate`.
35
+ *
36
+ * @param force Force in newtons.
37
+ */
38
+ addForce(force: Vec3Like): void;
39
+ /** Discards all accumulated forces. */
40
+ clearAccumulator(): void;
41
+ /**
42
+ * Advances the particle by one step and clears the force accumulator.
43
+ *
44
+ * Velocity is updated first and the new velocity moves the position. A particle with
45
+ * `inverseMass = 0` does not move, whatever its velocity.
46
+ *
47
+ * @param dt Step length in seconds.
48
+ * @throws RangeError If `dt` is not positive.
49
+ */
50
+ integrate(dt: number): void;
51
+ }
@@ -1,4 +1,4 @@
1
- export { FixedStepLoop } from './engine/loop.js';
2
- export type { FrameResult } from './engine/loop.js';
1
+ export { FixedStepLoop, Particle, ParticleWorld } from './engine/index.js';
2
+ export type { FrameResult } from './engine/index.js';
3
3
  export { EPSILON, approxEqual, clamp, Vec3, Mat3x3, Mat3x4, Quaternion } from './math/index.js';
4
4
  export type { QuatLike, Vec3Like } from './math/index.js';
package/package.json CHANGED
@@ -1,48 +1,60 @@
1
- {
2
- "name": "aether-physics",
3
- "version": "0.1.0",
4
- "description": "A 3D rigid-body physics engine built from scratch in TypeScript, with a Lit + Three.js playground.",
5
- "license": "MIT",
6
- "author": "Brandon Berisford",
7
- "keywords": ["physics", "physics-engine", "rigid-body", "quaternion", "typescript"],
8
- "homepage": "https://beyondbelief96.github.io/aether/",
9
- "repository": {
10
- "type": "git",
11
- "url": "git+https://github.com/BeyondBelief96/aether.git"
12
- },
13
- "bugs": "https://github.com/BeyondBelief96/aether/issues",
14
- "type": "module",
15
- "sideEffects": ["./src/playground/**"],
16
- "files": ["dist"],
17
- "types": "./dist/types/index.d.ts",
18
- "exports": {
19
- ".": {
20
- "types": "./dist/types/index.d.ts",
21
- "default": "./dist/index.js"
22
- },
23
- "./math": {
24
- "types": "./dist/types/math/index.d.ts",
25
- "default": "./dist/math.js"
26
- }
27
- },
28
- "scripts": {
29
- "dev": "vite",
30
- "build": "tsc && vite build",
31
- "preview": "vite preview",
32
- "build:lib": "vite build --config vite.lib.config.ts && tsc -p tsconfig.build.json",
33
- "prepublishOnly": "npm run typecheck && npm run test:run && npm run build:lib",
34
- "typecheck": "tsc",
35
- "test": "vitest",
36
- "test:run": "vitest run"
37
- },
38
- "devEngines": {},
39
- "devDependencies": {
40
- "@types/three": "^0.186.0",
41
- "fast-check": "^4.10.2",
42
- "lit": "^3.3.3",
43
- "three": "^0.186.1",
44
- "typescript": "^7.0.2",
45
- "vite": "^8.3.4",
46
- "vitest": "^5.0.3"
47
- }
48
- }
1
+ {
2
+ "name": "aether-physics",
3
+ "version": "0.2.0",
4
+ "description": "A 3D rigid-body physics engine built from scratch in TypeScript, with a Lit + Three.js playground.",
5
+ "license": "MIT",
6
+ "author": "Brandon Berisford",
7
+ "keywords": [
8
+ "physics",
9
+ "physics-engine",
10
+ "rigid-body",
11
+ "quaternion",
12
+ "typescript"
13
+ ],
14
+ "homepage": "https://beyondbelief96.github.io/aether/",
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/BeyondBelief96/aether.git"
18
+ },
19
+ "bugs": "https://github.com/BeyondBelief96/aether/issues",
20
+ "type": "module",
21
+ "sideEffects": [
22
+ "./src/playground/**"
23
+ ],
24
+ "files": [
25
+ "dist"
26
+ ],
27
+ "types": "./dist/types/index.d.ts",
28
+ "exports": {
29
+ ".": {
30
+ "types": "./dist/types/index.d.ts",
31
+ "default": "./dist/index.js"
32
+ },
33
+ "./math": {
34
+ "types": "./dist/types/math/index.d.ts",
35
+ "default": "./dist/math.js"
36
+ }
37
+ },
38
+ "scripts": {
39
+ "dev": "vite",
40
+ "build": "tsc && vite build",
41
+ "preview": "vite preview",
42
+ "build:lib": "vite build --config vite.lib.config.ts && tsc -p tsconfig.build.json",
43
+ "prepublishOnly": "npm run typecheck && npm run test:run && npm run build:lib",
44
+ "typecheck": "tsc",
45
+ "test": "vitest",
46
+ "test:run": "vitest run",
47
+ "test:smoke": "node scripts/smoke-test.mjs"
48
+ },
49
+ "devEngines": {},
50
+ "devDependencies": {
51
+ "@types/three": "^0.186.0",
52
+ "fast-check": "^4.10.2",
53
+ "lit": "^3.3.3",
54
+ "playwright-core": "^1.58.0",
55
+ "three": "^0.186.1",
56
+ "typescript": "^7.0.2",
57
+ "vite": "^8.3.4",
58
+ "vitest": "^5.0.3"
59
+ }
60
+ }