Skip to content

refactor(collision): drop shape from shared properties, modernize initialize/clone#8883

Merged
willeastcott merged 2 commits into
mainfrom
refactor-collision-shape-property
Jun 12, 2026
Merged

refactor(collision): drop shape from shared properties, modernize initialize/clone#8883
willeastcott merged 2 commits into
mainfrom
refactor-collision-shape-property

Conversation

@willeastcott

Copy link
Copy Markdown
Contributor

Continues the component-consistency series (#8871, #8876, #8878-#8882).

Changes

  • Removes 'shape' from the shared _properties list in CollisionComponentSystem. shape is runtime state created and owned by the collision type implementation, never component data, so cloneComponent no longer needs its special-case skip and becomes the unconditional loop used by the other refactored systems.
  • Modernizes initializeComponentData: drops the unused third parameter, replaces the slice/splice filtering of conflicting mesh inputs (asset vs model/render) with filter, and switches both loops to for...of, matching RigidBodyComponentSystem.
  • Adds tests pinning the new behavior, plus a shape === null assertion to the existing clone test.

Why this is behavior-preserving

  • Non-mesh types: a user-supplied shape in the addComponent data was always immediately overwritten by CollisionSystemImpl.beforeInitialize, so ignoring it is identical.
  • Mesh types: a user-supplied shape was either Ammo.destroy'd during the initial rebuild or, with a non-Ammo object, threw in the mesh implementation's destroyShape (getNumChildShapes is not a function). One of the new tests fails on main for this reason - the change turns that incidental crash into a silent ignore.
  • cloneComponent already skipped shape, so clone output is unchanged.
  • The conflict-filtering logic is semantically identical to the previous slice/splice version, and the explicit !== undefined check is retained (test-pinned) so class-field defaults survive explicitly-undefined data values.

The undocumented public shape setter on CollisionComponent is intentionally left in place - removing it would be an observable API change (strict-mode throw on assignment, types-visible).

🤖 Generated with Claude Code

…tialize/clone

`shape` is runtime state created and owned by the collision type
implementation, never component data: for non-mesh types a user-supplied
shape was immediately overwritten by beforeInitialize, and for mesh types
it was destroyed (or threw in destroyShape when a non-Ammo object was
passed). Removing it from the shared `_properties` list lets
cloneComponent become the unconditional loop used by the other
refactored systems.

Also modernizes initializeComponentData: drops the unused third
parameter, replaces the slice/splice filtering of conflicting mesh
inputs with filter, and switches both loops to for...of. The explicit
`!== undefined` check is retained (and test-pinned) so class-field
defaults survive explicitly-undefined data values.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

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.

Pull request overview

This PR continues the component-consistency refactors for the collision system by treating shape strictly as runtime-owned state (not component data), simplifying init/clone code paths to match other modernized component systems, and adding tests to lock in the behavior.

Changes:

  • Remove shape from CollisionComponentSystem’s shared _properties list so it is no longer initialized/cloned from user data.
  • Modernize initializeComponentData by dropping the unused third parameter, using filter for mesh input conflict resolution, and switching to for...of loops.
  • Add/extend tests to verify shape passed via addComponent data is ignored (including mesh type) and that clones have shape === null.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/framework/components/collision/system.js Removes shape from shared init/clone properties and simplifies initialization/cloning loops.
test/framework/components/collision/component.test.mjs Adds regression tests asserting shape is ignored from init data and remains null on clones.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@willeastcott willeastcott merged commit e12da6e into main Jun 12, 2026
9 checks passed
@willeastcott willeastcott deleted the refactor-collision-shape-property branch June 12, 2026 11:59
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.

3 participants