Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

fix(physics3d): a body is the shape its collider names, not the box beside it

esenginee8f8a2913455
diff --git a/CHANGELOG.md b/CHANGELOG.md
index ad11a20fa..0a494c5bc 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -16,6 +16,13 @@ published separately; it ships inside the editor.
### Added
+- **Every 3D collider shape and joint, authored in a scene.** physics-3d carried
+ 45 boxes and one hinge, and that was the whole corpus: the sphere, capsule,
+ convex and mesh colliders and four of the five joints shipped with no instance
+ in any scene anywhere, not even a fixture. The example now rolls a ball down a
+ mesh ramp, topples a capsule, hangs a lamp on a distance joint, welds two
+ crates together, pins a ball-and-socket and runs a lift along a slider.
+
- **The UI controls demo authors its widgets instead of building them.** Every
built-in widget shipped twice — a factory a game calls, and a prefab the
editor's *Create → UI* menu drops, generated from that factory — and only the
@@ -25,6 +32,16 @@ published separately; it ships inside the editor.
places all nine, exclusivity included (a `UIToggleGroup` on the toggles'
common ancestor), and its code answers what they do rather than building them.
+- **A 3D body is the shape its collider names.** Only `BoxCollider3D` had ever
+ worked. Reading a builtin component off an entity that does not carry one
+ answers with a default-constructed value rather than nothing — and its
+ `enabled` is `true`, so the body builder took the box branch for every entity
+ and built a sphere, a capsule, a hull and a mesh alike as a 0.5-metre box.
+ Nothing noticed because no scene in the corpus had ever authored any other
+ shape: a ball sank to the floor and sat there, and a capsule stood where it
+ landed. Every collider read is now behind the `has` check its sibling in
+ `ColliderShape3D` already had.
+
- **A ScrollView scrolls where the editor drops it.** The widget builds its
parts and its behaviour together in code, so the prefab behind *Create → UI →
ScrollView* carried only the parts: a box that clipped its content and never
diff --git a/desktop b/desktop
index a86874285..6a7d707e1 160000
--- a/desktop
+++ b/desktop
@@ -1 +1 @@
-Subproject commit a86874285b492d918ccffd3bf20d390567a95723
+Subproject commit 6a7d707e1750e2eae18dfb821d4f1a149e2168be
diff --git a/examples/physics-3d/assets/scenes/main.esscene b/examples/physics-3d/assets/scenes/main.esscene
index e1ccd21ca..b7f7aa32d 100644
--- a/examples/physics-3d/assets/scenes/main.esscene
+++ b/examples/physics-3d/assets/scenes/main.esscene
@@ -48,9 +48,9 @@
"z": 0
},
"scale": {
- "x": 14.0,
+ "x": 14,
"y": 0.4,
- "z": 10.0
+ "z": 10
}
}
},
@@ -106,7 +106,7 @@
"scale": {
"x": 2.4,
"y": 0.3,
- "z": 3.0
+ "z": 3
}
}
},
@@ -162,7 +162,7 @@
"scale": {
"x": 2.4,
"y": 0.9,
- "z": 3.0
+ "z": 3
}
}
},
@@ -217,8 +217,8 @@
},
"scale": {
"x": 0.4,
- "y": 2.0,
- "z": 8.0
+ "y": 2,
+ "z": 8
}
}
},
@@ -682,6 +682,722 @@
}
],
"visible": true
+ },
+ {
+ "id": 33,
+ "name": "Ball",
+ "parent": null,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": 250,
+ "y": 260,
+ "z": -300
+ },
+ "scale": {
+ "x": 0.6,
+ "y": 0.6,
+ "z": 0.6
+ }
+ }
+ },
+ {
+ "type": "RigidBody3D",
+ "data": {
+ "bodyType": 2,
+ "linearDamping": 0.05,
+ "angularDamping": 0.05
+ }
+ },
+ {
+ "type": "SphereCollider3D",
+ "data": {
+ "radius": 30,
+ "friction": 0.25,
+ "restitution": 0.35
+ }
+ },
+ {
+ "type": "MeshRenderer",
+ "data": {
+ "mesh": "builtin:sphere",
+ "lit": true,
+ "opaque": true,
+ "cullBackfaces": true,
+ "color": {
+ "r": 0.82,
+ "g": 0.62,
+ "b": 0.26,
+ "a": 1
+ }
+ }
+ }
+ ]
+ },
+ {
+ "id": 34,
+ "name": "Barrel",
+ "parent": null,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": 300,
+ "y": 120,
+ "z": -300
+ },
+ "rotation": {
+ "x": 0,
+ "y": 0,
+ "z": 0.1045,
+ "w": 0.9945
+ },
+ "scale": {
+ "x": 0.8,
+ "y": 0.8,
+ "z": 0.8
+ }
+ }
+ },
+ {
+ "type": "RigidBody3D",
+ "data": {
+ "bodyType": 2,
+ "linearDamping": 0.1,
+ "angularDamping": 0.1
+ }
+ },
+ {
+ "type": "CapsuleCollider3D",
+ "data": {
+ "radius": 20,
+ "halfHeight": 40,
+ "friction": 0.4
+ }
+ },
+ {
+ "type": "MeshRenderer",
+ "data": {
+ "mesh": "builtin:capsule",
+ "lit": true,
+ "opaque": true,
+ "cullBackfaces": true,
+ "color": {
+ "r": 0.28,
+ "g": 0.7,
+ "b": 0.66,
+ "a": 1
+ }
+ }
+ }
+ ]
+ },
+ {
+ "id": 35,
+ "name": "Cone",
+ "parent": null,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": 420,
+ "y": 200,
+ "z": -300
+ },
+ "scale": {
+ "x": 0.8,
+ "y": 0.8,
+ "z": 0.8
+ }
+ }
+ },
+ {
+ "type": "RigidBody3D",
+ "data": {
+ "bodyType": 2,
+ "linearDamping": 0.05,
+ "angularDamping": 0.1
+ }
+ },
+ {
+ "type": "ConvexCollider3D",
+ "data": {
+ "mesh": "builtin:cone",
+ "friction": 0.4
+ }
+ },
+ {
+ "type": "MeshRenderer",
+ "data": {
+ "mesh": "builtin:cone",
+ "lit": true,
+ "opaque": true,
+ "cullBackfaces": true,
+ "color": {
+ "r": 0.6,
+ "g": 0.42,
+ "b": 0.72,
+ "a": 1
+ }
+ }
+ }
+ ]
+ },
+ {
+ "id": 36,
+ "name": "Ramp",
+ "parent": null,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": 180,
+ "y": 0,
+ "z": -300
+ },
+ "scale": {
+ "x": 3,
+ "y": 1.2,
+ "z": 2
+ }
+ }
+ },
+ {
+ "type": "RigidBody3D",
+ "data": {
+ "bodyType": 0
+ }
+ },
+ {
+ "type": "MeshCollider3D",
+ "data": {
+ "mesh": "builtin:cone",
+ "friction": 0.5
+ }
+ },
+ {
+ "type": "MeshRenderer",
+ "data": {
+ "mesh": "builtin:cone",
+ "lit": true,
+ "opaque": true,
+ "cullBackfaces": true,
+ "color": {
+ "r": 0.55,
+ "g": 0.57,
+ "b": 0.62,
+ "a": 1
+ }
+ }
+ }
+ ]
+ },
+ {
+ "id": 37,
+ "name": "LampAnchor",
+ "parent": null,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": -520,
+ "y": 300,
+ "z": 200
+ },
+ "scale": {
+ "x": 0.5,
+ "y": 0.2,
+ "z": 0.5
+ }
+ }
+ },
+ {
+ "type": "RigidBody3D",
+ "data": {
+ "bodyType": 0
+ }
+ },
+ {
+ "type": "BoxCollider3D",
+ "data": {
+ "halfExtents": {
+ "x": 25,
+ "y": 10,
+ "z": 25
+ }
+ }
+ },
+ {
+ "type": "MeshRenderer",
+ "data": {
+ "mesh": "builtin:cube",
+ "lit": true,
+ "opaque": true,
+ "cullBackfaces": true,
+ "color": {
+ "r": 0.55,
+ "g": 0.57,
+ "b": 0.62,
+ "a": 1
+ }
+ }
+ }
+ ]
+ },
+ {
+ "id": 38,
+ "name": "Lamp",
+ "parent": null,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": -520,
+ "y": 250,
+ "z": 200
+ },
+ "scale": {
+ "x": 0.5,
+ "y": 0.5,
+ "z": 0.5
+ }
+ }
+ },
+ {
+ "type": "RigidBody3D",
+ "data": {
+ "bodyType": 2,
+ "linearDamping": 0.1,
+ "angularDamping": 0.2
+ }
+ },
+ {
+ "type": "SphereCollider3D",
+ "data": {
+ "radius": 25
+ }
+ },
+ {
+ "type": "DistanceJoint3D",
+ "data": {
+ "connectedEntity": 37,
+ "anchor": {
+ "x": 0,
+ "y": 0,
+ "z": 0
+ },
+ "connectedAnchor": {
+ "x": 0,
+ "y": 0,
+ "z": 0
+ },
+ "minLength": 0,
+ "maxLength": 120,
+ "damping": 0.4
+ }
+ },
+ {
+ "type": "MeshRenderer",
+ "data": {
+ "mesh": "builtin:sphere",
+ "lit": true,
+ "opaque": true,
+ "cullBackfaces": true,
+ "color": {
+ "r": 0.82,
+ "g": 0.62,
+ "b": 0.26,
+ "a": 1
+ }
+ }
+ }
+ ]
+ },
+ {
+ "id": 39,
+ "name": "WeldA",
+ "parent": null,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": -300,
+ "y": 200,
+ "z": 200
+ },
+ "scale": {
+ "x": 0.5,
+ "y": 0.5,
+ "z": 0.5
+ }
+ }
+ },
+ {
+ "type": "RigidBody3D",
+ "data": {
+ "bodyType": 2,
+ "linearDamping": 0.1
+ }
+ },
+ {
+ "type": "BoxCollider3D",
+ "data": {
+ "halfExtents": {
+ "x": 25,
+ "y": 25,
+ "z": 25
+ }
+ }
+ },
+ {
+ "type": "MeshRenderer",
+ "data": {
+ "mesh": "builtin:cube",
+ "lit": true,
+ "opaque": true,
+ "cullBackfaces": true,
+ "color": {
+ "r": 0.28,
+ "g": 0.7,
+ "b": 0.66,
+ "a": 1
+ }
+ }
+ }
+ ]
+ },
+ {
+ "id": 40,
+ "name": "WeldB",
+ "parent": null,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": -240,
+ "y": 200,
+ "z": 200
+ },
+ "scale": {
+ "x": 0.5,
+ "y": 0.5,
+ "z": 0.5
+ }
+ }
+ },
+ {
+ "type": "RigidBody3D",
+ "data": {
+ "bodyType": 2,
+ "linearDamping": 0.1
+ }
+ },
+ {
+ "type": "BoxCollider3D",
+ "data": {
+ "halfExtents": {
+ "x": 25,
+ "y": 25,
+ "z": 25
+ }
+ }
+ },
+ {
+ "type": "FixedJoint3D",
+ "data": {
+ "connectedEntity": 39
+ }
+ },
+ {
+ "type": "MeshRenderer",
+ "data": {
+ "mesh": "builtin:cube",
+ "lit": true,
+ "opaque": true,
+ "cullBackfaces": true,
+ "color": {
+ "r": 0.6,
+ "g": 0.42,
+ "b": 0.72,
+ "a": 1
+ }
+ }
+ }
+ ]
+ },
+ {
+ "id": 41,
+ "name": "ChainAnchor",
+ "parent": null,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": -400,
+ "y": 300,
+ "z": 350
+ },
+ "scale": {
+ "x": 0.4,
+ "y": 0.2,
+ "z": 0.4
+ }
+ }
+ },
+ {
+ "type": "RigidBody3D",
+ "data": {
+ "bodyType": 0
+ }
+ },
+ {
+ "type": "BoxCollider3D",
+ "data": {
+ "halfExtents": {
+ "x": 20,
+ "y": 10,
+ "z": 20
+ }
+ }
+ },
+ {
+ "type": "MeshRenderer",
+ "data": {
+ "mesh": "builtin:cube",
+ "lit": true,
+ "opaque": true,
+ "cullBackfaces": true,
+ "color": {
+ "r": 0.55,
+ "g": 0.57,
+ "b": 0.62,
+ "a": 1
+ }
+ }
+ }
+ ]
+ },
+ {
+ "id": 42,
+ "name": "ChainBall",
+ "parent": null,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": -400,
+ "y": 220,
+ "z": 350
+ },
+ "scale": {
+ "x": 0.45,
+ "y": 0.45,
+ "z": 0.45
+ }
+ }
+ },
+ {
+ "type": "RigidBody3D",
+ "data": {
+ "bodyType": 2,
+ "linearDamping": 0.05,
+ "angularDamping": 0.05
+ }
+ },
+ {
+ "type": "SphereCollider3D",
+ "data": {
+ "radius": 22
+ }
+ },
+ {
+ "type": "PointJoint3D",
+ "data": {
+ "connectedEntity": 41,
+ "anchor": {
+ "x": 0,
+ "y": 80,
+ "z": 0
+ }
+ }
+ },
+ {
+ "type": "MeshRenderer",
+ "data": {
+ "mesh": "builtin:sphere",
+ "lit": true,
+ "opaque": true,
+ "cullBackfaces": true,
+ "color": {
+ "r": 0.6,
+ "g": 0.42,
+ "b": 0.72,
+ "a": 1
+ }
+ }
+ }
+ ]
+ },
+ {
+ "id": 43,
+ "name": "LiftAnchor",
+ "parent": null,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": -160,
+ "y": 320,
+ "z": 320
+ },
+ "scale": {
+ "x": 0.3,
+ "y": 0.3,
+ "z": 0.3
+ }
+ }
+ },
+ {
+ "type": "RigidBody3D",
+ "data": {
+ "bodyType": 0
+ }
+ },
+ {
+ "type": "BoxCollider3D",
+ "data": {
+ "halfExtents": {
+ "x": 15,
+ "y": 15,
+ "z": 15
+ }
+ }
+ },
+ {
+ "type": "MeshRenderer",
+ "data": {
+ "mesh": "builtin:cube",
+ "lit": true,
+ "opaque": true,
+ "cullBackfaces": true,
+ "color": {
+ "r": 0.55,
+ "g": 0.57,
+ "b": 0.62,
+ "a": 1
+ }
+ }
+ }
+ ]
+ },
+ {
+ "id": 44,
+ "name": "Lift",
+ "parent": null,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": -160,
+ "y": 240,
+ "z": 320
+ },
+ "scale": {
+ "x": 1.2,
+ "y": 0.2,
+ "z": 1.2
+ }
+ }
+ },
+ {
+ "type": "RigidBody3D",
+ "data": {
+ "bodyType": 2,
+ "linearDamping": 0.2
+ }
+ },
+ {
+ "type": "BoxCollider3D",
+ "data": {
+ "halfExtents": {
+ "x": 60,
+ "y": 10,
+ "z": 60
+ }
+ }
+ },
+ {
+ "type": "SliderJoint3D",
+ "data": {
+ "connectedEntity": 43,
+ "anchor": {
+ "x": 0,
+ "y": 80,
+ "z": 0
+ },
+ "axis": {
+ "x": 0,
+ "y": 1,
+ "z": 0
+ },
+ "enableLimit": true,
+ "lowerTranslation": -140,
+ "upperTranslation": 140
+ }
+ },
+ {
+ "type": "MeshRenderer",
+ "data": {
+ "mesh": "builtin:cube",
+ "lit": true,
+ "opaque": true,
+ "cullBackfaces": true,
+ "color": {
+ "r": 0.28,
+ "g": 0.7,
+ "b": 0.66,
+ "a": 1
+ }
+ }
+ }
+ ]
}
]
}
diff --git a/sdk/src/physics3d/Physics3DSystem.ts b/sdk/src/physics3d/Physics3DSystem.ts
index 5030e442a..fd9a56693 100644
--- a/sdk/src/physics3d/Physics3DSystem.ts
+++ b/sdk/src/physics3d/Physics3DSystem.ts
@@ -171,28 +171,37 @@ function createBody(app: App, module: Physics3DWasmModule, entity: Entity,
body.angularDamping, body.fixedRotation ? 1 : 0, body.layer,
body.continuousCollision ? 1 : 0] as const;
- const box = app.world.get(entity, BoxCollider3D) as BoxCollider3DData | undefined;
+ // `has` before `get`: a builtin read on an entity that does not carry the
+ // component answers with a default-constructed one, `enabled` and all — so
+ // every sphere, capsule, hull and mesh was built as the default box.
+ const has = (c: Parameters<typeof app.world.has>[1]) => app.world.has(entity, c);
+ const box = has(BoxCollider3D)
+ ? app.world.get(entity, BoxCollider3D) as BoxCollider3DData : undefined;
if (box?.enabled) {
return module._physics3d_addBox(
entity as number, box.halfExtents.x / ppu, box.halfExtents.y / ppu,
box.halfExtents.z / ppu, px, py, pz, r.x, r.y, r.z, r.w,
...how, box.friction, box.restitution, box.isSensor ? 1 : 0);
}
- const sphere = app.world.get(entity, SphereCollider3D) as SphereCollider3DData | undefined;
+ const sphere = has(SphereCollider3D)
+ ? app.world.get(entity, SphereCollider3D) as SphereCollider3DData : undefined;
if (sphere?.enabled) {
return module._physics3d_addSphere(
entity as number, sphere.radius / ppu, px, py, pz, r.x, r.y, r.z, r.w,
...how, sphere.friction, sphere.restitution, sphere.isSensor ? 1 : 0);
}
- const meshCollider = app.world.get(entity, MeshCollider3D) as MeshCollider3DData | undefined;
+ const meshCollider = has(MeshCollider3D)
+ ? app.world.get(entity, MeshCollider3D) as MeshCollider3DData : undefined;
if (meshCollider?.enabled && meshCollider.mesh !== 0) {
return addMeshBody(module, entity, meshCollider, px, py, pz, r, ppu, body.layer);
}
- const hull = app.world.get(entity, ConvexCollider3D) as ConvexCollider3DData | undefined;
+ const hull = has(ConvexCollider3D)
+ ? app.world.get(entity, ConvexCollider3D) as ConvexCollider3DData : undefined;
if (hull?.enabled && hull.mesh !== 0) {
return addConvexBody(module, entity, hull, px, py, pz, r, ppu, how);
}
- const capsule = app.world.get(entity, CapsuleCollider3D) as CapsuleCollider3DData | undefined;
+ const capsule = has(CapsuleCollider3D)
+ ? app.world.get(entity, CapsuleCollider3D) as CapsuleCollider3DData : undefined;
if (capsule?.enabled) {
return module._physics3d_addCapsule(
entity as number, capsule.radius / ppu, capsule.halfHeight / ppu,
diff --git a/tools/check-corpus-authoring.mjs b/tools/check-corpus-authoring.mjs
index d80d56dbd..fd745f772 100644
--- a/tools/check-corpus-authoring.mjs
+++ b/tools/check-corpus-authoring.mjs
@@ -122,17 +122,9 @@ const DISPOSITION = {
ChainCollider2D: ['owed', 'physics-spinner builds its chain in code — the one 2D shape whose authored form (a point list) the editor actually has an editing mode for'],
PolygonCollider2D: ['owed', 'no project authors a polygon collider, in code or in a scene'],
SegmentCollider2D: ['owed', 'no project authors a segment collider, in code or in a scene'],
- SphereCollider3D: ['owed', 'physics-3d authors 45 boxes and no other 3D shape; the whole shape family rests on BoxCollider3D'],
- CapsuleCollider3D: ['owed', 'the shape a character body actually uses, and physics-3d authors none'],
- MeshCollider3D: ['owed', 'static level geometry collides against meshes; Jolt ships the single-sided MeshShape and no corpus scene authors one'],
- ConvexCollider3D: ['owed', 'the shape a dynamic prop needs, absent everywhere'],
DistanceJoint2D: ['owed', 'physics-playground authors Hinge/Motor/Slider and stops there'],
FixedJoint2D: ['owed', 'same scene, same gap'],
WheelJoint2D: ['owed', 'a vehicle is the demonstration, and the corpus has no vehicle'],
- DistanceJoint3D: ['owed', 'physics-3d authors HingeJoint3D alone; four 3D joints ship with no instance anywhere, not even a fixture'],
- FixedJoint3D: ['owed', 'ships with no instance anywhere, not even a fixture'],
- PointJoint3D: ['owed', 'ships with no instance anywhere, not even a fixture'],
- SliderJoint3D: ['owed', 'ships with no instance anywhere, not even a fixture'],
SortingGroup: ['owed', 'the component that makes a subtree sort as one unit — the fix for every "my character\'s sword draws behind the wrong prop", demonstrated nowhere'],
CacheAsBitmap: ['owed', 'flattening a static subtree into one texture is a performance decision with no example showing when to take it'],