Skip to content

utilMath JS module#1980

Open
ada-tv wants to merge 1 commit intooverte-org:masterfrom
ada-tv:feature/utilMath-module
Open

utilMath JS module#1980
ada-tv wants to merge 1 commit intooverte-org:masterfrom
ada-tv:feature/utilMath-module

Conversation

@ada-tv
Copy link
Collaborator

@ada-tv ada-tv commented Jan 1, 2026

A JS-native math library that should be easier to extend in the future and should have less marshalling overhead than the Vec3 and Quat APIs when doing lots of vector math (though I haven't profiled it, and it won't be any faster or slower when reading/writing from native properties like MyAvatar or Entities)

Helper functions

  • lerp
  • clamp
  • quantize - Like Number.toFixed but without any stringification
  • withinEpsilon - Like Vec3.withinEpsilon, generalised for Number
  • durationMillis - Milliseconds (for offsetting with Date.now for example) from a human-readable object
  • vec3 - Shorthand for new Vector3
  • quat - Shorthand for new Quaternion
  • euler - Shorthand for Quaternion.fromPitchYawRollDegrees
  • color - Shorthand for new Color8

New types

  • Vector3 - Fully compatible with the existing Vec3 API (though Vec3s are plain objects and don't have the Vector3 prototype, so they won't have any methods like add, length, or lerpTo unless you wrap them in new Vector3)
  • Quaternion - Fully compatible with the existing Quat API (same deal as Vec3, compatible but needs to be wrapped to get the new prototype)
  • Color8 - 0-255 RGBA color, includes HSV, HSL, oklab, and oklch helpers (though the old deprecated Overlays API is the only place we use color objects with alpha at the moment)
  • ColorF - 0-1 RGBA color (PolyLine vertex colors are the only thing that uses these natively as far as I know)

Demo scripts

(don't mind the scary names, I ended up accidentally finding some new bugs while writing these)

  • large_polyline.js - Spawns a colorful swirling ball made of PolyLines around your avatar, tests Quaternion
  • hsvcube_octree_lag.js - Spawns a lattice of colored cubes covering the HSV coordinate space, tests Color8. Might lag you when moving around because of octree shenanigans
  • slerpedArrow_avatarEntityLag.js - An arrow that rotates towards a random rotation every 2.5 seconds, tests Quaternion.slerpTo

@ada-tv ada-tv added enhancement New feature or request needs CR This pull request needs to be code reviewed labels Jan 1, 2026
@ksuprynowicz
Copy link
Member

Does it show in apidocs?

@ada-tv
Copy link
Collaborator Author

ada-tv commented Jan 4, 2026

Does it show in apidocs?

No, the JSDoc builder currently only pulls from C++ files. It could maybe be extended to read from scripts/modules too in another PR.

The JSDoc in utilMath.js is mainly for language server support in editors/IDEs. (hence why some doc comments are only @returns and @param for type checking, and also why the doc comments use Markdown formatting instead of HTML)

@ada-tv ada-tv mentioned this pull request Feb 19, 2026
7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request needs CR This pull request needs to be code reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants