Implement the following plan: Fix ConvexCollider misalignment with sprites from Blender…
- User
Implement the following plan:
Fix ConvexCollider misalignment with sprites from Blender pipeline
Context
The store's ConvexCollider (red debug outline) appears tiny and offset. The previous fix attempt (origin offset) made things worse — the root cause is actually missing parent Blender scale on collider child vertices.
Why the origin offset theory was wrong
Both the sprite and collider are anchored at the entity position (= Blender origin).
SpriteBatch.DrawusesSpriteInfo.Originto align the sprite's origin point with the entity position, whileUpdateWorldVerticesadds entity position to model vertices. No additional origin offset is needed — they're already in the same coordinate space.The actual bug: parent Blender scale
The Blender exporter computes collider child vertices via
obj.matrix_local @ v.co, which gives coordinates in the parent's local space (unscaled by parent's scale). The child's own scale/rotation/position ARE baked in viamatrix_local, but the parent's scale is NOT.Meanwhile,
SpriteInfo.Sizeuses BlenderDimensionswhich ARE world-scale (include parent scale). AndTransform.Scaleis(1, 1)— Blender scale is not stored there.Result:
UpdateWorldVerticesappliesTransform.Scale = (1,1)to model vertices, so the collider stays at the unscaled parent-local size. For the store (parent scale 3.0), the collider is ~3x too small and mispositioned.Affected entities (confirmed from JSON)
- store: parent scale (3.0082, 3.0082) — collider ~3x too small
- Pete: parent scale (1.0, 1.0) — unaffected
- Boldo: parent scale (1.0, 1.0) — unaffected
Numerical verification
Store collider vertices span X: -16.61 to -2.45 = 14.16 units (parent-local). Scaled by 3.0082 = 42.6 units ≈ store sprite width (44.27). BoxCollider bounds from
ProcessCollections: left=-51, right=-6, width=45. The scaled collider matches.Fix
File:
MonoDreams/System/Level/BlenderLevelParserSystem.csStep 1: Revert the incorrect origin offset (~line 595-612 in ApplyColliderChild)
Remove the entire
if (parentEntity.Has<SpriteInfo>())block that offsets model vertices by-spriteInfo.Origin * scale. This was wrong.Step 2: Build a name→BlenderObject lookup (~line 110-124, pre-scan loop)
Assistant
Let me read the file to understand the current state before making changes.
Assistant
Now let me check that
BlenderObjecthas aScaleproperty.Assistant
Good,
BlenderObject.Scaleis aVector2JsonwithXandYproperties. Now I'll make all three changes.Assistant
Now update the
ApplyColliderChildmethod — change the signature, remove the origin offset block, and add parent scale logic:Assistant
All three changes are done. Let me build to verify.
Assistant
Build succeeds with 0 errors. Let me run the tests.
Assistant
All 26 tests pass. Here's a summary of the changes made to
BlenderLevelParserSystem.cs:-
Built
nameToObjdictionary in the pre-scan loop (line ~110) — maps object names to theirBlenderObjectso we can look up the parent's Blender scale later. -
Passed
nameToObjtoApplyColliderChild(line ~156) and updated the method signature. -
Removed the incorrect origin offset (the
if (parentEntity.Has<SpriteInfo>())block that shifted model vertices by-origin * scale). Both sprite and collider are already anchored at the entity position — no offset was needed. -
Added parent Blender scale to model vertices. The collider child vertices from
matrix_localare in parent-local space (unscaled by parent). SinceSpriteInfo.Sizeincludes parent scale (from Blender Dimensions) butTransform.Scaleis(1,1), we bake the parent's scale into the model vertices. This fixes the store's collider being ~3x too small.
To verify visually: run the game, press F1, enable "Collider Shapes" — the store's red ConvexCollider outline should now match the storefront size. Pete and Boldo (parent scale 1.0) remain unaffected.
-