Skip to content

fix(conversions): re-center mesh/polyhedron geometry so TransformControls attaches at the visual center - #33

Merged
ericgozzi merged 1 commit into
fix/viewer-connection-frame-budgeted-drainfrom
fix/center-geometry-transform-controls
Oct 13, 2026
Merged

ericgozzi merged 1 commit into
fix/viewer-connection-frame-budgeted-drainfrom
fix/center-geometry-transform-controls

Conversation

@ericgozzi

@ericgozzi ericgozzi commented Sep 23, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • mesh.vertices/polyhedron.vertices arrive as absolute world coordinates and were written into the BufferGeometry unchanged, so the resulting THREE.Mesh always had its .position at the world origin. That renders correctly, but anything that reads .position/matrixWorld breaks. In particular, TransformControls.attach put the gizmo at the world origin instead of at the mesh.
  • New centerGeometry(), used by both meshToThreeJS and polyhedronToThreeJS, moves the geometry by -center and sets mesh.position = center. Every vertex stays at the same world position, and the object's origin is now at its visual center.

Stacked on #32; merge that first. Backend counterpart: compas-dev/compas_threejs#59 (scale-mode object_transform pivot fix).

Test plan

  • new tests/datastructures.test.ts (both conversions)
  • format, lint, typecheck, test, build:app, build:library

🤖 Generated with Claude Code

@gonzalocasas gonzalocasas left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lgtm! although I have to say it's not 100% clear to me which cases are affected by this

@gonzalocasas

Copy link
Copy Markdown
Member

ahh nevermind, I think i get it :P

…rols attaches at the visual center

mesh.vertices/polyhedron.vertices arrive as absolute world coordinates and
get written into the BufferGeometry as-is, so the returned THREE.Mesh's own
.position stayed at the world origin no matter where the mesh actually sits.
That's invisible for rendering (the geometry itself is already in the right
place), but it broke anything reading .position/matrixWorld instead of the
geometry - notably TransformControls.attach, which planted the transform
gizmo at the world origin instead of the mesh's visual center.

Adds centerGeometry(), used by both meshToThreeJS and polyhedronToThreeJS:
translates the geometry by -center and sets mesh.position to that center,
keeping every rendered vertex at the same world position while giving the
object an origin a gizmo (or anything else keyed off object position) finds
where the mesh actually is.

Adds tests/datastructures.test.ts, covering both conversions.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@ericgozzi
ericgozzi force-pushed the fix/center-geometry-transform-controls branch from c5639b4 to 54079dd Compare October 13, 2026 08:52
@ericgozzi
ericgozzi merged commit 71e4d1c into main Oct 13, 2026
2 checks passed
@ericgozzi
ericgozzi deleted the fix/center-geometry-transform-controls branch October 13, 2026 08:54
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