Skip to content

Typings: setUniform accepts a scalar - #1664

Merged
obiot merged 3 commits into
masterfrom
fix/setuniform-scalar-typing
Sep 14, 2026
Merged

Typings: setUniform accepts a scalar#1664
obiot merged 3 commits into
masterfrom
fix/setuniform-scalar-typing

Conversation

@obiot

@obiot obiot commented Sep 14, 2026

Copy link
Copy Markdown
Member

setUniform was typed object|Float32Array, so passing a number — the commonest case by far — did not compile from TypeScript:

Argument of type 'number' is not assignable to parameter of type 'object | Float32Array'

The type was wrong rather than deliberately narrow. Three things establish that:

  • the method's own JSDoc examples pass numbers — setUniform("uStrength", 0.5), setUniform("uTime", time), setUniform("uIntensity", 0.9)
  • the engine passes numbers internallyuUVYDir (±1) and uTime (seconds)
  • the implementation has an explicit scalar branch: it tests typeof value === "object", and the else exists precisely to handle numbers

Widened to number|boolean|number[]|Float32Array|object on both ShaderEffect and GLShader, where the same wrong type had been copy-pasted, plus documentation of which form goes with which GLSL type and a scalar example.

JSDoc only — no runtime change. It reaches users through the emitted .d.ts:

setUniform(name: string, value: number | boolean | number[] | Float32Array | object): void;

Also: one skill gap

The effects skill said an effect attaches to a renderable or a camera "for full-screen grading", without saying that a camera's post-effect brackets the entire world draw — floating children included. Written the obvious way, a full-screen pass washes over every HUD label in that world. The skill now documents hosting the effect on a screen-filling floating renderable ordered below the HUD's z, why such a quad needs none of the screen_uv / screen_texture builtins, and that a higher z draws later.

Found while building a lens flare that had to run after the world and before the HUD.

Verification

  • biome check clean; pre-commit hook passed
  • pnpm -F melonjs doc — 0 errors, and the rendered ShaderEffect page shows the corrected signature with all four {@link}s resolving
  • check-doc-readme guard passes

🤖 Generated with Claude Code

https://claude.ai/code/session_01NGvtaUNATVCVxD2qcbiY4t

obiot and others added 3 commits September 13, 2026 21:46
All four are things the engine already does and the types denied.

`GLTFData.nodes` was `object[]` with every field named in prose, so reading
`node.vertices` to feed a `Mesh` — which is why the descriptor is exposed at
all — did not compile. Typed as `GLTFNode[]`.

`Mesh`'s `texture` resolves a `Texture2d` at mesh.js:101, deliberately, so a
procedural `NoiseTexture2d` can skin geometry; the type listed only images,
canvases, atlases and names.

`Mesh`'s `indices` preserves a `Uint32Array` on purpose — there is a comment
saying truncating one would silently corrupt any mesh past 65535 vertices, and
that the glTF parser emits them for exactly that case — while the type said
`Uint16Array|number[]`.

A shader `Asset` may carry `{glsl, wgsl}` so one asset serves both backends,
which the parser has handled since the dual-language work; `data` was `string`.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NGvtaUNATVCVxD2qcbiY4t
`setUniform` was typed `object|Float32Array`, so passing a number — the
commonest case by far — did not compile from TypeScript. The type was
wrong rather than deliberately narrow: the method's own JSDoc examples
pass numbers (`setUniform("uStrength", 0.5)`), the engine passes them
internally (`uUVYDir`, `uTime`), and the implementation has an explicit
scalar branch that exists to handle them.

Widened to `number|boolean|number[]|Float32Array|object` on both
`ShaderEffect` and `GLShader`, where the same wrong type had been
copy-pasted, and documented which form goes with which GLSL type.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NGvtaUNATVCVxD2qcbiY4t
The effects skill said an effect attaches to a renderable or to a camera
"for full-screen grading", without saying that a camera's post-effect
brackets the entire world draw — floating children included. Written the
obvious way, a full-screen pass washes over every HUD label in that
world.

Documents the alternative (host the effect on a screen-filling floating
renderable ordered below the HUD's z), why such a quad needs none of the
screen_uv / screen_texture builtins, and that a higher z draws later.

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 14, 2026 07:43

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 24a1805 into master Sep 14, 2026
6 checks passed
@obiot
obiot deleted the fix/setuniform-scalar-typing branch September 14, 2026 07:48
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.

2 participants