Skip to content

Light3d: take a Vector3d for direction and position - #1663

Merged
obiot merged 1 commit into
masterfrom
feat/light3d-vector-options
Sep 13, 2026
Merged

Light3d: take a Vector3d for direction and position#1663
obiot merged 1 commit into
masterfrom
feat/light3d-vector-options

Conversation

@obiot

@obiot obiot commented Sep 13, 2026

Copy link
Copy Markdown
Member

Closes #1661.

direction and position were [number, number, number] read by index, so a Vector3d — the obvious thing to reach for when an option is named direction in a 3D engine — set all three components to undefined, normalize() kept them NaN, and the light contributed nothing. Silently: no warning, no throw, and the scene still renders with whatever else is lit.

color on the same options object already accepts a Color, a CSS string or an [r, g, b] array, so this makes the object consistent with itself rather than introducing a new idea. Both options now go through one small reader.

The value is read, not retained: the light keeps its own vector, normalized, so moving yours afterwards does not steer it. There is a test for exactly that, because the alternative — aliasing the caller's vector — is the tempting shortcut and would be a different feature.

Backward compatibility

Additive. Widening the union leaves every array call compiling and on the identical path, and the only behaviour that changes is passing a Vector3d, which previously produced no light at all. Nothing can depend on that.

The one caveat from the issue still stands: downstream TypeScript reading Light3dOptions["direction"] directly and assuming an array would need updating, so this belongs in a minor rather than a patch.

Tests

Three, and all three fail without the change — reverting the reader to index-only turns them red with expected NaN to be -0.356… and expected [ undefined, undefined, +0 ]:

  • a Vector3d and the equivalent array produce byte-identical directions
  • same for position
  • the caller's vector is copied, not aliased: mutating it afterwards leaves the light alone, and the light's vectors are not the same object

Full suite 282 files / 6867 passed / 9 skipped. pnpm lint clean.

Docs

The class example gains the vector form, the option docs say the value is read rather than retained, and the 3D skill's "this silently yields NaN" trap is gone — it is no longer true. What remains there is the argument-count trap and the Y-down sign, which this does not change.

Both were `[number, number, number]` read by index, so a `Vector3d` — the
obvious thing to reach for when an option is named `direction` in a 3D engine —
set all three components to `undefined`, `normalize()` kept them `NaN`, and the
light contributed nothing. Silently: no warning, and the scene still renders
with whatever else is lit.

`color` on the same options object already accepts a `Color`, a CSS string or
an array, so this makes the object consistent with itself rather than adding a
new idea. The value is READ, not retained — the light keeps its own normalized
vector, and moving yours afterwards does not steer it.

Additive: widening the union leaves every array call compiling and on the
identical path. The only behaviour that changes is passing a `Vector3d`, which
produced no light at all.

Three shipped examples got this wrong, which is why it is worth the branch.

Closes #1661

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NGvtaUNATVCVxD2qcbiY4t
Copilot AI lite review requested due to automatic review settings September 13, 2026 10:30

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@obiot
obiot merged commit a9ed552 into master Sep 13, 2026
6 checks passed
@obiot
obiot deleted the feat/light3d-vector-options branch September 13, 2026 10:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Light3d: accept a Vector3d for direction and position, as color already accepts a Color

2 participants