Skip to content

feat(Sprite3d): add originPoint anchor support#1538

Open
asadullahbro wants to merge 1 commit into
melonjs:masterfrom
asadullahbro:sprite3d-origin-point
Open

feat(Sprite3d): add originPoint anchor support#1538
asadullahbro wants to merge 1 commit into
melonjs:masterfrom
asadullahbro:sprite3d-origin-point

Conversation

@asadullahbro

@asadullahbro asadullahbro commented Jul 4, 2026

Copy link
Copy Markdown

Adds a settings.originPoint option (preset string or {x,y}) so the quad's pivot can be placed anywhere relative to pos, e.g. bottom-center for ground-anchored 2.5D characters. Baked as a constant local offset applied after flips, so it composes with billboarding and trimmed/rotated atlas frames. Default stays centered — no behavior change for existing code.

Updated the billboard example to anchor the character at its feet instead of using a manual GY offset fudge factor.

Closes #1514

Description

Type of change

  • Bug fix
  • New feature
  • Documentation update
  • Performance improvement
  • Refactoring (no functional changes)

Checklist

  • I have read the Contributing Guide
  • My code follows the existing code style (pnpm lint passes)
  • I have tested my changes locally (pnpm test passes)
  • I have added tests that cover my changes (if applicable)
  • The build succeeds (pnpm build)

Related issues

Adds a settings.originPoint option (preset string or {x,y}) so the
quad's pivot can be placed anywhere relative to pos, e.g. bottom-center
for ground-anchored 2.5D characters. Baked as a constant local offset
applied after flips, so it composes with billboarding and
trimmed/rotated atlas frames. Default stays centered — no behavior
change for existing code.

Updated the billboard example to anchor the character at its feet
instead of using a manual GY offset fudge factor.

Closes melonjs#1514
@obiot

obiot commented Jul 6, 2026

Copy link
Copy Markdown
Member

Hi,

Thanks for the PR, before merging I'm gonna make some further changes however that I think makes it a better fit with the legacy/existing API :

  1. drop originPoint and override the existing anchorPoint instead, so Sprite3d anchors exactly like the 2D Sprite:

    • accept settings.anchorPoint (same key/convention/default as Sprite; your preset strings can stay as sugar)
    • hook the inherited ObservablePoint via setCallback() so runtime changes re-bake the vertices, like the live 2D anchor (but then force applyAnchorTransform = false on both camera paths, so that vertex bake is the single anchor mechanism and nothing leaks into the view matrix)
  2. keep the preset strings you added, but extend them to regular sprite (2d) object.

@asadullahbro

Copy link
Copy Markdown
Author

@obiot thanks for the detailed feedback! Happy to implement this myself, just let me know if you'd rather I push these changes, or if you're planning to handle it on your end. Either way works for me.

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.

Sprite3d: bottom/origin anchor for ground placement (2.5D)

2 participants