The native runtime for three.js: three.js, down to the metal. 45× smaller than Electron, on a Sony PS3, and path-traced at 60 fps on ray-tracing GPUs.
Rust electron-alternativegame-engineglobal-illuminationgraphicsjavascript-runtimemetalpath-tracingray-tracingreal-time-renderingrenderingrustthreejstypescriptvoxelvulkanwebgpuwgpu
Scene: Quaternion.rotateTowards, as three.js has it (#113)
Kevin Rajan596ca099a0a5
diff --git a/packages/scene/src/math.ts b/packages/scene/src/math.tsindex de9dd72..313d094 100644--- a/packages/scene/src/math.ts+++ b/packages/scene/src/math.ts@@ -232,6 +232,12 @@ export class Quaternion {angleTo(q: Quaternion): number {return 2 * Math.acos(Math.min(1, Math.abs(this.dot(q))));}+ /** Rotate toward a unit quaternion by at most `step` radians (three.js). */+ rotateTowards(q: Quaternion, step: number): this {+ const angle = this.angleTo(q);+ if (angle === 0) return this;+ return this.slerp(q, Math.min(1, step / angle));+ }/** The inverse rotation (of a unit quaternion). */invert(): this {return this.set(-this._x, -this._y, -this._z, this._w);diff --git a/packages/scene/test/three-compat.test.ts b/packages/scene/test/three-compat.test.tsindex 1f8fe93..dfa1a50 100644--- a/packages/scene/test/three-compat.test.ts+++ b/packages/scene/test/three-compat.test.ts@@ -112,6 +112,20 @@ test("vertex colours: the geometry's `color` attribute (RGB, RGBA, normalized byassert.deepEqual(compatNotes().slice(before).filter((n) => n.startsWith("unsupported:")), []);});+test("Quaternion.rotateTowards: bounded angular step and no overshoot, as three.js does", () => {+ const current = new THREE.Quaternion();+ const target = new THREE.Quaternion().setFromAxisAngle(new THREE.Vector3(0, 1, 0), Math.PI);+ assert.equal(current.rotateTowards(target, Math.PI / 2), current);+ assert.ok(Math.abs(current.y - Math.SQRT1_2) < 1e-12, "90-degree yaw has sin(pi/4)");+ assert.ok(Math.abs(current.w - Math.SQRT1_2) < 1e-12, "90-degree yaw has cos(pi/4)");+ assert.ok(Math.abs(current.angleTo(target) - Math.PI / 2) < 1e-12, "90 degrees remain");+ assert.equal(current.rotateTowards(target, 4 * Math.PI), current);+ assert.ok(current.angleTo(target) < 1e-12, "a large step stops at the target");+ const arrived = current.toArray();+ assert.equal(current.rotateTowards(target, Math.PI / 8), current);+ assert.deepEqual(current.toArray(), arrived, "already at the target does not change");+});+test("Object3D: clone (geometry shared, own id), attach (world transform kept), local moves, world / local", () => {const a = new THREE.Mesh(new THREE.BoxGeometry(), new THREE.MeshStandardMaterial());a.position.set(1, 2, 3);