refactor(collision): align CollisionComponent with CameraComponent architecture#8871
Merged
Merged
Conversation
…chitecture CollisionComponent now owns its 14 properties as private fields with real setters/getters, inlining the side effects that previously lived in set_* event listeners. CollisionComponentData is reduced to a single enabled field. The system drives initializeComponentData from an explicit _properties list, hoists the type-independent impl remove() and clone() into onRemove/cloneComponent (the post-removal 'remove' event no longer carries type), and builds the enabled accessor via Component._buildAccessors. The old init-time array conversions move into the halfExtents, linearOffset and angularOffset setters (including 3-element euler arrays), so they now also work post-initialization instead of storing raw arrays. Vec3/Quat inputs are copied so caller mutations do not leak; the vec/quat setters have no equality early-return so the documented mutate-then-reassign idiom still rebuilds the shape. The CollisionSystemImpl classes operate on the component directly, writing private fields where a public setter would double-rebuild the shape (mesh loadAsset, asset clearing). Trigger drops its redundant data constructor param and RigidBodyComponent reads the collision offsets via their public getters. Adds a 26-test suite modelled on the ButtonComponent tests. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Public API reportThis PR changes the public API surface (+5 / −5), per the docs' rules (@ignore / @Private / undocumented are excluded). Show API diff-ModelComponent.get type(): "box" | "plane" | "asset" | "sphere" | "capsule" | "cylinder" | "cone" | "torus"
+ModelComponent.get type(): "box" | "plane" | "sphere" | "capsule" | "cylinder" | "cone" | "asset" | "torus"
-ModelComponent.set type(value: "box" | "plane" | "asset" | "sphere" | "capsule" | "cylinder" | "cone" | "torus")
+ModelComponent.set type(value: "box" | "plane" | "sphere" | "capsule" | "cylinder" | "cone" | "asset" | "torus")
-RenderComponent.get type(): "box" | "plane" | "asset" | "sphere" | "capsule" | "cylinder" | "cone" | "torus"
+RenderComponent.get type(): "box" | "plane" | "sphere" | "capsule" | "cylinder" | "cone" | "asset" | "torus"
-RenderComponent.set type(value: "box" | "plane" | "asset" | "sphere" | "capsule" | "cylinder" | "cone" | "torus")
+RenderComponent.set type(value: "box" | "plane" | "sphere" | "capsule" | "cylinder" | "cone" | "asset" | "torus")
-Trigger.constructor(app: AppBase, component: Component, data: any)
+Trigger.constructor(app: AppBase, component: CollisionComponent)Informational only — this never fails the build. |
Contributor
There was a problem hiding this comment.
Pull request overview
Refactors CollisionComponent to follow the “component owns its state via private fields + real accessors” architecture used by CameraComponent and subsequent component migrations, reducing reliance on *ComponentData property bags and moving shape-recreation side effects into property setters.
Changes:
- Migrates
CollisionComponentstate into private fields with explicit getters/setters and removes the old_setValue+set_*listener plumbing. - Updates
CollisionComponentSystemand per-type implementations to operate directly on the component fields (and hoists removal/clone behavior into the system). - Adds a new collision component test suite and updates dependent code (
Trigger,RigidBodyComponent) to use the new accessors.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| test/framework/components/collision/component.test.mjs | Adds a comprehensive regression suite for defaults, conversions, cloning, offsets, lifecycle, and shape recreation behavior. |
| src/framework/components/rigid-body/component.js | Switches offset reads from collision.data.* to collision.* accessors. |
| src/framework/components/collision/trigger.js | Removes the redundant data parameter and reads component.shape directly. |
| src/framework/components/collision/system.js | Refactors initialization/clone/removal and per-type implementations to operate on component fields; builds enabled accessor via schema. |
| src/framework/components/collision/data.js | Reduces the data class to enabled only. |
| src/framework/components/collision/component.js | Introduces private fields + real setters/getters and inlines side effects previously handled by set_* event handlers. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
The old initializer defaulted falsy type inputs (null, empty string) to the current data type; the migrated code applied any defined value, letting null reach _createImplementation and crash on impl.beforeInitialize. Resolve type solely up front with a truthiness guard and drop it from _properties - leaving it in the generic loop would push a falsy-but-defined value through the type setter and fire changeType pre-init. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Migrates CollisionComponent to the architecture established by CameraComponent and applied in #8666 (light), #8693 (scrollbar), #8777 (scrollview) and #8870 (button).
What changed
_setValueindirection, the 12set_*listener registrations and allonSet*handlers are gone; side effects are inlined in the setters, gated on_initialized. The init-time array conversions move into thehalfExtents/linearOffset/angularOffsetsetters (including 3-element euler arrays forangularOffset), so they now also work post-initialization instead of storing raw arrays. Vec3/Quat inputs are copied so caller mutations do not leak; these setters have no equality early-return, so the documented mutate-then-reassign idiom still rebuilds the shape.CollisionSystemImplclasses operate on the component directly instead of a separate data object, writing private fields where a public setter would double-rebuild the shape (meshloadAsset, asset clearing). The type-independent implremove()/clone()are hoisted into the system asonRemove/cloneComponent— necessary because the post-removalremoveevent payload no longer carriestype.initializeComponentDatapreserves the load-bearing ordering: type resolved first via a direct private write, asset-over-model/render pruning, property loop through inert setters,beforeInitialize, enabled viasuper, thenafterInitialize. Theenabledaccessor is generated byComponent._buildAccessors.enabledfield.dataconstructor param and readscomponent.shape(Trigger is not publicly exported)._updateDynamicreads the collision offsets via their public getters instead ofcollision.data.Adds a 26-test suite modelled on the ButtonComponent tests (defaults, round-trips, array conversions, asset id normalization and listener cleanup, type changes, per-type shape-recreation gating, offsets, clone fidelity, removal lifecycle).
Notes for reviewers
if (!component.rigidbody)check inrecreatePhysicalShapes(almost certainly meantentity.rigidbody) is preserved verbatim — fixing it changes compound physics behavior and belongs in its own PR.model/render(the clone data always carries anassetkey, which wins the priority pruning) — preserved bug-for-bug.tsccheck. Node tests cannot load Ammo, so a browser pass of physics/falling-shapes, physics/compound-collision and physics/offset-collision is recommended before merge.Checklist
🤖 Generated with Claude Code