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.

feat(physics3d): a box, sphere or capsule collider can sit off its entity origin (center), and the Cocos BoxCollider centre maps onto it

yhh9a16d4bcbee0
diff --git a/CHANGELOG.md b/CHANGELOG.md
index f033d3018..82568b5c3 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -20,6 +20,7 @@ published separately; it ships inside the editor.
- **Scroll areas can be pulled past an end and spring back.** A scroll area whose movement is Elastic now does what the setting always said: a drag past an end is stiffer the further out it goes, letting go returns the content, and a flick that reaches an end bounces off it. It is opt-in per area (`ScrollMovement.Elastic`; Clamped, the default, behaves as before), and the gesture model (`ScrollMotion`, with `ScrollContainer.dragTo` and `getOverscroll`) is exported for scrolling anything else the same way.
- **More easing curves.** Sine, quart, quint, expo and circ (each in, out and in-out), bounce in and in-out, and smoothstep and smootherstep join the quad, cubic, back, elastic and out-bounce curves. They are new `EasingType` members after the existing ones, so a saved tween keeps its curve, and they ease the same in a C++ tween and a script value tween.
- **World content has a rectangle: `ContentRect`.** A size and the pivot the entity's transform sits on, which the `Sprite` and `Text` on the entity follow and which a `UIMask` on it clips to — no `UINode` needed, so a clipping region or a scroll viewport can stand in the world. `contentRectContains` tests a world point against it.
+- **A 3D collider can sit off its entity.** `BoxCollider3D`, `SphereCollider3D` and `CapsuleCollider3D` take an optional `center`, the shape's place from the entity origin in world units. The body stays at the entity, so a dynamic body turns about its origin and the shape swings round it.
- **Text can underline, and a box can grow to its text.** `Text.underline` draws a bar under each line, taken from the font's own underscore. `TextOverflow.ResizeHeight` keeps every line and sets the entity's `ContentRect` height to the height they take, so what sits below a paragraph can follow it.
- **An emitter runs on its own clock.** `ParticleEmitter.simulationSpeed` scales how fast that emitter's time runs: 2 plays it twice as fast, 0.5 at half, 0 holds it. Emission, lifetimes and motion all follow it. The default, 1, is the behaviour before.
- **An animator state can play at the speed of a parameter.** `speedParameter` on an `AnimatorState` names a float parameter; the state's clock advances by `dt` times its value, so a run clip follows a character's speed and a value of 0 holds the pose. It applies to every kind of motion, since it is the state's own clock that is scaled.
diff --git a/docs/astro/src/data/components.generated.json b/docs/astro/src/data/components.generated.json
index 234f3ee66..9aec29a02 100644
--- a/docs/astro/src/data/components.generated.json
+++ b/docs/astro/src/data/components.generated.json
@@ -6449,7 +6449,8 @@
"Visible",
"Clip",
"Ellipsis",
- "Shrink"
+ "Shrink",
+ "ResizeHeight"
]
},
{
diff --git a/pipeline/src/import/cocos/components.ts b/pipeline/src/import/cocos/components.ts
index d143a1be1..65c80e3d4 100644
--- a/pipeline/src/import/cocos/components.ts
+++ b/pipeline/src/import/cocos/components.ts
@@ -721,22 +721,16 @@ function spineSkeleton(c: CocosComponent, ctx: ComponentContext, where: string):
/**
* `cc.BoxCollider`: the engine's box, half the node-scaled size on each side. A Cocos collider with no rigid body is a static one, which the engine
- * spells as a static body beside the box. The engine's box is centred on the entity, so a collider that sits off-centre keeps its size and loses
- * where it stood, which is counted.
+ * spells as a static body beside the box. Where the box stood from the node's origin (`_center`, scaled by the node) is the collider's `center`.
*/
-function boxCollider(c: CocosComponent, node: CocosNode, ctx: ComponentContext, where: string, extra: ComponentData[]): ComponentData {
+function boxCollider(c: CocosComponent, node: CocosNode, ctx: ComponentContext, extra: ComponentData[]): ComponentData {
const size = isObj(c.data._size) ? c.data._size : {};
const center = isObj(c.data._center) ? c.data._center : {};
const half = (axis: 'x' | 'y' | 'z'): number => Math.abs(num(size[axis], 1) * (node.scale[axis] ?? 1)) / 2;
- const off = Math.abs(num(center.x, 0)) + Math.abs(num(center.y, 0)) + Math.abs(num(center.z, 0));
- if (off > 1e-6) {
- ctx.report.component('cc.BoxCollider', 'partial');
- ctx.report.note('collider-center-dropped', where);
- } else {
- ctx.report.component('cc.BoxCollider', 'mapped');
- }
+ ctx.report.component('cc.BoxCollider', 'mapped');
if (!node.components.some((n) => n.type === 'cc.RigidBody') && !extra.some((e) => e.type === 'RigidBody3D')) extra.push({ type: 'RigidBody3D', data: { bodyType: 0 } });
- return { type: 'BoxCollider3D', data: { halfExtents: { x: half('x'), y: half('y'), z: half('z') }, isSensor: c.data._isTrigger === true, enabled: c.enabled } };
+ const at = (axis: 'x' | 'y' | 'z'): number => num(center[axis], 0) * (node.scale[axis] ?? 1);
+ return { type: 'BoxCollider3D', data: { halfExtents: { x: half('x'), y: half('y'), z: half('z') }, center: { x: at('x'), y: at('y'), z: at('z') }, isSensor: c.data._isTrigger === true, enabled: c.enabled } };
}
/** `cc.PageView`: a scroll view whose content is pages, and the page it settles on. */
@@ -928,7 +922,7 @@ export function convertNode(node: CocosNode, ctx: ComponentContext, where: strin
out = line(c, ctx, where);
break;
case 'cc.BoxCollider':
- out = boxCollider(c, node, ctx, where, extra);
+ out = boxCollider(c, node, ctx, extra);
break;
case 'cc.PageView':
out = pageView(c, ctx);
diff --git a/pipeline/tests/cocos-import-collider.test.ts b/pipeline/tests/cocos-import-collider.test.ts
new file mode 100644
index 000000000..395d06a03
--- /dev/null
+++ b/pipeline/tests/cocos-import-collider.test.ts
@@ -0,0 +1,50 @@
+// SPDX-License-Identifier: Apache-2.0
+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
+/**
+ * @file A Cocos BoxCollider keeps where it stood: `_center`, scaled by the node, becomes the engine collider's `center`.
+ */
+import { mkdtempSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
+import { tmpdir } from 'node:os';
+import path from 'node:path';
+import { afterAll, beforeAll, describe, expect, it } from 'vitest';
+import { importCocosProject } from '../src/import/cocos';
+
+const vec = (x: number, y: number, z: number) => ({ __type__: 'cc.Vec3', x, y, z });
+const scene = [
+ { __type__: 'cc.SceneAsset', _name: 'main', scene: { __id__: 1 } },
+ { __type__: 'cc.Scene', _name: 'main', _children: [{ __id__: 2 }] },
+ {
+ __type__: 'cc.Node', _name: 'Crate', _parent: { __id__: 1 }, _children: [], _active: true, _components: [{ __id__: 3 }], _prefab: null,
+ _lpos: vec(0, 0, 0), _lrot: { __type__: 'cc.Quat', x: 0, y: 0, z: 0, w: 1 }, _lscale: vec(2, 3, 1), _layer: 1,
+ },
+ { __type__: 'cc.BoxCollider', node: { __id__: 2 }, _enabled: true, _isTrigger: false, _size: vec(1, 1, 1), _center: vec(0.5, 1, -2) },
+];
+
+describe('a Cocos box collider off its node\'s origin', () => {
+ let root: string;
+ let crate: { components: Array<{ type: string; data: Record<string, any> }> };
+ let report: Awaited<ReturnType<typeof importCocosProject>>;
+
+ beforeAll(async () => {
+ root = mkdtempSync(path.join(tmpdir(), 'cocos-collider-'));
+ const dir = path.join(root, 'creator', 'assets');
+ mkdirSync(dir, { recursive: true });
+ writeFileSync(path.join(dir, 'main.scene'), JSON.stringify(scene));
+ writeFileSync(path.join(dir, 'main.scene.meta'), JSON.stringify({ ver: '1', importer: 'scene', uuid: 'dddddddd-dddd-4ddd-8ddd-dddddddddddd', subMetas: {}, userData: {} }));
+ report = await importCocosProject({ source: path.join(root, 'creator'), out: path.join(root, 'out') });
+ const doc = JSON.parse(readFileSync(path.join(root, 'out', 'assets', 'cocos', 'main.esscene'), 'utf8'));
+ crate = doc.entities.find((e: { name: string }) => e.name === 'Crate');
+ });
+ afterAll(() => rmSync(root, { recursive: true, force: true, maxRetries: 10, retryDelay: 50 }));
+
+ it('carries the centre, scaled by the node, and the scaled half size', () => {
+ const box = crate.components.find((c) => c.type === 'BoxCollider3D')!;
+ expect(box.data.halfExtents).toEqual({ x: 1, y: 1.5, z: 0.5 });
+ expect(box.data.center).toEqual({ x: 1, y: 3, z: -2 });
+ });
+
+ it('counts the collider as fully mapped', () => {
+ expect(report.components['cc.BoxCollider']).toEqual(expect.objectContaining({ mapped: 1 }));
+ expect(report.components['cc.BoxCollider']?.partial ?? 0).toBe(0);
+ });
+});
diff --git a/sdk/etc/index.api.md b/sdk/etc/index.api.md
index 0b82f341e..3b942e81f 100644
--- a/sdk/etc/index.api.md
+++ b/sdk/etc/index.api.md
@@ -5,7 +5,7 @@ Symbols: 115 public · 161 beta · 1966 experimental · 3 deprecated
## ABI_LAYOUT_HASH — const @experimental
```
-"63a00195ad788bd8"
+"790a68ffa2098d35"
```
## ANCHOR_AXES — const @experimental
@@ -1802,6 +1802,7 @@ BuiltinComponentDef<BoxCollider3DData>
## BoxCollider3DData — interface @experimental
```
+center: Vec3 | undefined
enabled: boolean
friction: number
halfExtents: Vec3
@@ -2217,6 +2218,7 @@ BuiltinComponentDef<CapsuleCollider3DData>
## CapsuleCollider3DData — interface @experimental
```
+center: Vec3 | undefined
enabled: boolean
friction: number
halfHeight: number
@@ -9725,6 +9727,7 @@ BuiltinComponentDef<SphereCollider3DData>
## SphereCollider3DData — interface @experimental
```
+center: Vec3 | undefined
enabled: boolean
friction: number
isSensor: boolean
diff --git a/sdk/etc/index.native.api.md b/sdk/etc/index.native.api.md
index 4ca16ee84..f4d3b5cad 100644
--- a/sdk/etc/index.native.api.md
+++ b/sdk/etc/index.native.api.md
@@ -5,7 +5,7 @@ Symbols: 115 public · 166 beta · 1985 experimental · 3 deprecated
## ABI_LAYOUT_HASH — const @experimental
```
-"63a00195ad788bd8"
+"790a68ffa2098d35"
```
## ANCHOR_AXES — const @experimental
@@ -1802,6 +1802,7 @@ BuiltinComponentDef<BoxCollider3DData>
## BoxCollider3DData — interface @experimental
```
+center: Vec3 | undefined
enabled: boolean
friction: number
halfExtents: Vec3
@@ -2217,6 +2218,7 @@ BuiltinComponentDef<CapsuleCollider3DData>
## CapsuleCollider3DData — interface @experimental
```
+center: Vec3 | undefined
enabled: boolean
friction: number
halfHeight: number
@@ -9938,6 +9940,7 @@ BuiltinComponentDef<SphereCollider3DData>
## SphereCollider3DData — interface @experimental
```
+center: Vec3 | undefined
enabled: boolean
friction: number
isSensor: boolean
diff --git a/sdk/etc/index.node.api.md b/sdk/etc/index.node.api.md
index 3194430cb..63f900ce9 100644
--- a/sdk/etc/index.node.api.md
+++ b/sdk/etc/index.node.api.md
@@ -1797,6 +1797,7 @@ BuiltinComponentDef<BoxCollider3DData>
## BoxCollider3DData — interface @experimental
```
+center: Vec3 | undefined
enabled: boolean
friction: number
halfExtents: Vec3
@@ -2212,6 +2213,7 @@ BuiltinComponentDef<CapsuleCollider3DData>
## CapsuleCollider3DData — interface @experimental
```
+center: Vec3 | undefined
enabled: boolean
friction: number
halfHeight: number
@@ -9720,6 +9722,7 @@ BuiltinComponentDef<SphereCollider3DData>
## SphereCollider3DData — interface @experimental
```
+center: Vec3 | undefined
enabled: boolean
friction: number
isSensor: boolean
diff --git a/sdk/etc/minigame.api.md b/sdk/etc/minigame.api.md
index 4379e431b..eac5fa468 100644
--- a/sdk/etc/minigame.api.md
+++ b/sdk/etc/minigame.api.md
@@ -1797,6 +1797,7 @@ BuiltinComponentDef<BoxCollider3DData>
## BoxCollider3DData — interface @experimental
```
+center: Vec3 | undefined
enabled: boolean
friction: number
halfExtents: Vec3
@@ -2212,6 +2213,7 @@ BuiltinComponentDef<CapsuleCollider3DData>
## CapsuleCollider3DData — interface @experimental
```
+center: Vec3 | undefined
enabled: boolean
friction: number
halfHeight: number
@@ -10015,6 +10017,7 @@ BuiltinComponentDef<SphereCollider3DData>
## SphereCollider3DData — interface @experimental
```
+center: Vec3 | undefined
enabled: boolean
friction: number
isSensor: boolean
diff --git a/sdk/etc/physics3d.api.md b/sdk/etc/physics3d.api.md
index 17a999593..ff1850e38 100644
--- a/sdk/etc/physics3d.api.md
+++ b/sdk/etc/physics3d.api.md
@@ -10,6 +10,7 @@ BuiltinComponentDef<BoxCollider3DData>
## BoxCollider3DData — interface @experimental
```
+center: Vec3 | undefined
enabled: boolean
friction: number
halfExtents: Vec3
@@ -29,6 +30,7 @@ BuiltinComponentDef<CapsuleCollider3DData>
## CapsuleCollider3DData — interface @experimental
```
+center: Vec3 | undefined
enabled: boolean
friction: number
halfHeight: number
@@ -299,8 +301,8 @@ HEAPF32: Float32Array<ArrayBufferLike>
HEAPU32: Uint32Array<ArrayBufferLike>
_free: (ptr: number) => void
_malloc: (bytes: number) => number
-_physics3d_addBox: (entity: number, hx: number, hy: number, hz: number, px: number, py: number, pz: number, qx: number, qy: number, qz: number, qw: number, motion: number, gravityScale: number, linearDamping: number, angularDamping: number, fixedRotation: number, layer: number, continuous: number, friction: number, restitution: number, isSensor: number) => number
-_physics3d_addCapsule: (entity: number, radius: number, halfHeight: number, px: number, py: number, pz: number, qx: number, qy: number, qz: number, qw: number, motion: number, gravityScale: number, linearDamping: number, angularDamping: number, fixedRotation: number, layer: number, continuous: number, friction: number, restitution: number, isSensor: number) => number
+_physics3d_addBox: (entity: number, hx: number, hy: number, hz: number, px: number, py: number, pz: number, qx: number, qy: number, qz: number, qw: number, motion: number, gravityScale: number, linearDamping: number, angularDamping: number, fixedRotation: number, layer: number, continuous: number, friction: number, restitution: number, isSensor: number, cx: number, cy: number, cz: number) => number
+_physics3d_addCapsule: (entity: number, radius: number, halfHeight: number, px: number, py: number, pz: number, qx: number, qy: number, qz: number, qw: number, motion: number, gravityScale: number, linearDamping: number, angularDamping: number, fixedRotation: number, layer: number, continuous: number, friction: number, restitution: number, isSensor: number, cx: number, cy: number, cz: number) => number
_physics3d_addCharacter: (entity: number, radius: number, halfHeight: number, px: number, py: number, pz: number, maxSlope: number, mass: number, layer: number, pushForce: number) => number
_physics3d_addConvexBody: (entity: number, vertexPtr: number, vertexCount: number, px: number, py: number, pz: number, qx: number, qy: number, qz: number, qw: number, motion: number, gravityScale: number, linearDamping: number, angularDamping: number, fixedRotation: number, layer: number, continuous: number, friction: number, restitution: number, isSensor: number) => number
_physics3d_addDistanceJoint: (entity: number, bodyA: number, bodyB: number, ax: number, ay: number, az: number, bx: number, by: number, bz: number, minLength: number, maxLength: number, frequency: number, damping: number, collideConnected: number) => number
@@ -311,7 +313,7 @@ _physics3d_addMeshBody: (entity: number, vertexPtr: number, vertexCount: number,
_physics3d_addPointJoint: (entity: number, bodyA: number, bodyB: number, px: number, py: number, pz: number, collideConnected: number) => number
_physics3d_addSixDOFJoint: (entity: number, bodyA: number, bodyB: number, px: number, py: number, pz: number, ax: number, ay: number, az: number, nx: number, ny: number, nz: number, translationMotion: number, rotationMotion: number, lx: number, ly: number, lz: number, hx: number, hy: number, hz: number, rx: number, ry: number, rz: number, sx: number, sy: number, sz: number, collideConnected: number) => number
_physics3d_addSliderJoint: (entity: number, bodyA: number, bodyB: number, px: number, py: number, pz: number, ax: number, ay: number, az: number, enableLimit: number, lower: number, upper: number, enableMotor: number, motorSpeed: number, maxForce: number, collideConnected: number) => number
-_physics3d_addSphere: (entity: number, radius: number, px: number, py: number, pz: number, qx: number, qy: number, qz: number, qw: number, motion: number, gravityScale: number, linearDamping: number, angularDamping: number, fixedRotation: number, layer: number, continuous: number, friction: number, restitution: number, isSensor: number) => number
+_physics3d_addSphere: (entity: number, radius: number, px: number, py: number, pz: number, qx: number, qy: number, qz: number, qw: number, motion: number, gravityScale: number, linearDamping: number, angularDamping: number, fixedRotation: number, layer: number, continuous: number, friction: number, restitution: number, isSensor: number, cx: number, cy: number, cz: number) => number
_physics3d_addSwingTwistJoint: (entity: number, bodyA: number, bodyB: number, px: number, py: number, pz: number, ax: number, ay: number, az: number, nx: number, ny: number, nz: number, normalHalf: number, planeHalf: number, twistMin: number, twistMax: number, collideConnected: number) => number
_physics3d_addTorque: ((bodyId: number, tx: number, ty: number, tz: number) => void) | undefined
_physics3d_contactEnters: () => number
@@ -440,6 +442,7 @@ BuiltinComponentDef<SphereCollider3DData>
## SphereCollider3DData — interface @experimental
```
+center: Vec3 | undefined
enabled: boolean
friction: number
isSensor: boolean
diff --git a/sdk/etc/wechat.api.md b/sdk/etc/wechat.api.md
index d42314197..2313811ba 100644
--- a/sdk/etc/wechat.api.md
+++ b/sdk/etc/wechat.api.md
@@ -1797,6 +1797,7 @@ BuiltinComponentDef<BoxCollider3DData>
## BoxCollider3DData — interface @experimental
```
+center: Vec3 | undefined
enabled: boolean
friction: number
halfExtents: Vec3
@@ -2212,6 +2213,7 @@ BuiltinComponentDef<CapsuleCollider3DData>
## CapsuleCollider3DData — interface @experimental
```
+center: Vec3 | undefined
enabled: boolean
friction: number
halfHeight: number
@@ -9727,6 +9729,7 @@ BuiltinComponentDef<SphereCollider3DData>
## SphereCollider3DData — interface @experimental
```
+center: Vec3 | undefined
enabled: boolean
friction: number
isSensor: boolean
diff --git a/sdk/src/ecs/bridge/ptrAccessors.generated.ts b/sdk/src/ecs/bridge/ptrAccessors.generated.ts
index fd8b4c561..5021c8584 100644
--- a/sdk/src/ecs/bridge/ptrAccessors.generated.ts
+++ b/sdk/src/ecs/bridge/ptrAccessors.generated.ts
@@ -119,6 +119,7 @@ export function createBoxCollider2DData(): BoxCollider2DPtrData {
export interface BoxCollider3DPtrData {
halfExtents: Vec3;
+ center: Vec3;
friction: number;
restitution: number;
isSensor: boolean;
@@ -130,10 +131,11 @@ export function fillBoxCollider3D(
ptr: number, out: BoxCollider3DPtrData,
): void {
const halfExtents_ = out.halfExtents; halfExtents_.x = f32[ptr >> 2]; halfExtents_.y = f32[(ptr >> 2) + 1]; halfExtents_.z = f32[(ptr >> 2) + 2];
- out.friction = f32[(ptr + 12) >> 2];
- out.restitution = f32[(ptr + 16) >> 2];
- out.isSensor = u8[ptr + 20] !== 0;
- out.enabled = u8[ptr + 21] !== 0;
+ const center_ = out.center; center_.x = f32[(ptr + 12) >> 2]; center_.y = f32[((ptr + 12) >> 2) + 1]; center_.z = f32[((ptr + 12) >> 2) + 2];
+ out.friction = f32[(ptr + 24) >> 2];
+ out.restitution = f32[(ptr + 28) >> 2];
+ out.isSensor = u8[ptr + 32] !== 0;
+ out.enabled = u8[ptr + 33] !== 0;
}
export function writeBoxCollider3D(
@@ -141,15 +143,17 @@ export function writeBoxCollider3D(
ptr: number, data: BoxCollider3DPtrData,
): void {
f32[ptr >> 2] = data.halfExtents.x; f32[(ptr >> 2) + 1] = data.halfExtents.y; f32[(ptr >> 2) + 2] = data.halfExtents.z;
- f32[(ptr + 12) >> 2] = data.friction;
- f32[(ptr + 16) >> 2] = data.restitution;
- u8[ptr + 20] = data.isSensor ? 1 : 0;
- u8[ptr + 21] = data.enabled ? 1 : 0;
+ f32[(ptr + 12) >> 2] = data.center.x; f32[((ptr + 12) >> 2) + 1] = data.center.y; f32[((ptr + 12) >> 2) + 2] = data.center.z;
+ f32[(ptr + 24) >> 2] = data.friction;
+ f32[(ptr + 28) >> 2] = data.restitution;
+ u8[ptr + 32] = data.isSensor ? 1 : 0;
+ u8[ptr + 33] = data.enabled ? 1 : 0;
}
export function createBoxCollider3DData(): BoxCollider3DPtrData {
return {
halfExtents: { x: 0, y: 0, z: 0 },
+ center: { x: 0, y: 0, z: 0 },
friction: 0,
restitution: 0,
isSensor: false,
@@ -336,6 +340,7 @@ export function createCapsuleCollider2DData(): CapsuleCollider2DPtrData {
export interface CapsuleCollider3DPtrData {
radius: number;
halfHeight: number;
+ center: Vec3;
friction: number;
restitution: number;
isSensor: boolean;
@@ -348,10 +353,11 @@ export function fillCapsuleCollider3D(
): void {
out.radius = f32[ptr >> 2];
out.halfHeight = f32[(ptr + 4) >> 2];
- out.friction = f32[(ptr + 8) >> 2];
- out.restitution = f32[(ptr + 12) >> 2];
- out.isSensor = u8[ptr + 16] !== 0;
- out.enabled = u8[ptr + 17] !== 0;
+ const center_ = out.center; center_.x = f32[(ptr + 8) >> 2]; center_.y = f32[((ptr + 8) >> 2) + 1]; center_.z = f32[((ptr + 8) >> 2) + 2];
+ out.friction = f32[(ptr + 20) >> 2];
+ out.restitution = f32[(ptr + 24) >> 2];
+ out.isSensor = u8[ptr + 28] !== 0;
+ out.enabled = u8[ptr + 29] !== 0;
}
export function writeCapsuleCollider3D(
@@ -360,16 +366,18 @@ export function writeCapsuleCollider3D(
): void {
f32[ptr >> 2] = data.radius;
f32[(ptr + 4) >> 2] = data.halfHeight;
- f32[(ptr + 8) >> 2] = data.friction;
- f32[(ptr + 12) >> 2] = data.restitution;
- u8[ptr + 16] = data.isSensor ? 1 : 0;
- u8[ptr + 17] = data.enabled ? 1 : 0;
+ f32[(ptr + 8) >> 2] = data.center.x; f32[((ptr + 8) >> 2) + 1] = data.center.y; f32[((ptr + 8) >> 2) + 2] = data.center.z;
+ f32[(ptr + 20) >> 2] = data.friction;
+ f32[(ptr + 24) >> 2] = data.restitution;
+ u8[ptr + 28] = data.isSensor ? 1 : 0;
+ u8[ptr + 29] = data.enabled ? 1 : 0;
}
export function createCapsuleCollider3DData(): CapsuleCollider3DPtrData {
return {
radius: 0,
halfHeight: 0,
+ center: { x: 0, y: 0, z: 0 },
friction: 0,
restitution: 0,
isSensor: false,
@@ -1947,6 +1955,7 @@ export function createSortingGroupData(): SortingGroupPtrData {
export interface SphereCollider3DPtrData {
radius: number;
+ center: Vec3;
friction: number;
restitution: number;
isSensor: boolean;
@@ -1958,10 +1967,11 @@ export function fillSphereCollider3D(
ptr: number, out: SphereCollider3DPtrData,
): void {
out.radius = f32[ptr >> 2];
- out.friction = f32[(ptr + 4) >> 2];
- out.restitution = f32[(ptr + 8) >> 2];
- out.isSensor = u8[ptr + 12] !== 0;
- out.enabled = u8[ptr + 13] !== 0;
+ const center_ = out.center; center_.x = f32[(ptr + 4) >> 2]; center_.y = f32[((ptr + 4) >> 2) + 1]; center_.z = f32[((ptr + 4) >> 2) + 2];
+ out.friction = f32[(ptr + 16) >> 2];
+ out.restitution = f32[(ptr + 20) >> 2];
+ out.isSensor = u8[ptr + 24] !== 0;
+ out.enabled = u8[ptr + 25] !== 0;
}
export function writeSphereCollider3D(
@@ -1969,15 +1979,17 @@ export function writeSphereCollider3D(
ptr: number, data: SphereCollider3DPtrData,
): void {
f32[ptr >> 2] = data.radius;
- f32[(ptr + 4) >> 2] = data.friction;
- f32[(ptr + 8) >> 2] = data.restitution;
- u8[ptr + 12] = data.isSensor ? 1 : 0;
- u8[ptr + 13] = data.enabled ? 1 : 0;
+ f32[(ptr + 4) >> 2] = data.center.x; f32[((ptr + 4) >> 2) + 1] = data.center.y; f32[((ptr + 4) >> 2) + 2] = data.center.z;
+ f32[(ptr + 16) >> 2] = data.friction;
+ f32[(ptr + 20) >> 2] = data.restitution;
+ u8[ptr + 24] = data.isSensor ? 1 : 0;
+ u8[ptr + 25] = data.enabled ? 1 : 0;
}
export function createSphereCollider3DData(): SphereCollider3DPtrData {
return {
radius: 0,
+ center: { x: 0, y: 0, z: 0 },
friction: 0,
restitution: 0,
isSensor: false,
diff --git a/sdk/src/ecs/component.generated.ts b/sdk/src/ecs/component.generated.ts
index d67ed7780..ae5eefb3d 100644
--- a/sdk/src/ecs/component.generated.ts
+++ b/sdk/src/ecs/component.generated.ts
@@ -15,7 +15,7 @@ import type { AlignContent, AlignItems, AlignSelf, BodyType, CanvasScaleMode, Cl
* getAbiLayoutHash(); BuiltinBridge.connect() compares them and refuses to
* run on mismatch, because mismatched offsets read the wrong heap bytes.
*/
-export const ABI_LAYOUT_HASH = '63a00195ad788bd8';
+export const ABI_LAYOUT_HASH = '790a68ffa2098d35';
/**
* One asset-valued field of a component: which field, and what kind of
@@ -147,6 +147,7 @@ export const COMPONENT_META: Record<string, ComponentMetaEntry> = {
BoxCollider3D: {
defaults: {
halfExtents: { x: 0.5, y: 0.5, z: 0.5 },
+ center: { x: 0, y: 0, z: 0 },
friction: 0.3,
restitution: 0,
isSensor: false,
@@ -243,6 +244,7 @@ export const COMPONENT_META: Record<string, ComponentMetaEntry> = {
defaults: {
radius: 0.3,
halfHeight: 0.5,
+ center: { x: 0, y: 0, z: 0 },
friction: 0.3,
restitution: 0,
isSensor: false,
@@ -1041,6 +1043,7 @@ export const COMPONENT_META: Record<string, ComponentMetaEntry> = {
SphereCollider3D: {
defaults: {
radius: 0.5,
+ center: { x: 0, y: 0, z: 0 },
friction: 0.3,
restitution: 0,
isSensor: false,
@@ -1446,6 +1449,7 @@ export interface BoxCollider2DData {
export interface BoxCollider3DData {
halfExtents: Vec3;
+ center?: Vec3;
friction: number;
restitution: number;
isSensor: boolean;
@@ -1493,6 +1497,7 @@ export interface CapsuleCollider2DData {
export interface CapsuleCollider3DData {
radius: number;
halfHeight: number;
+ center?: Vec3;
friction: number;
restitution: number;
isSensor: boolean;
@@ -1920,6 +1925,7 @@ export interface SortingGroupData {
export interface SphereCollider3DData {
radius: number;
+ center?: Vec3;
friction: number;
restitution: number;
isSensor: boolean;
diff --git a/sdk/src/physics3d/ColliderShape3D.ts b/sdk/src/physics3d/ColliderShape3D.ts
index 4bd653958..dd1d63e3b 100644
--- a/sdk/src/physics3d/ColliderShape3D.ts
+++ b/sdk/src/physics3d/ColliderShape3D.ts
@@ -38,8 +38,8 @@ export const COLLIDER3D_RING_SEGMENTS = 24;
/** A 3D collider's geometry in entity-local space, in world units. */
export type Collider3DShape =
| { kind: 'box'; halfExtents: Vec3; center: Vec3 }
- | { kind: 'sphere'; radius: number }
- | { kind: 'capsule'; radius: number; halfHeight: number };
+ | { kind: 'sphere'; radius: number; center?: Vec3 }
+ | { kind: 'capsule'; radius: number; halfHeight: number; center?: Vec3 };
/** Which component authored a shape — the Inspector target behind a gizmo. */
export type Collider3DComponent =
@@ -105,7 +105,7 @@ export function readCollider3DShapes(world: World, entity: number): Collider3DIn
if (chosen) taken = true;
out.push({
component: 'BoxCollider3D',
- shape: { kind: 'box', halfExtents: box.halfExtents, center: ZERO },
+ shape: { kind: 'box', halfExtents: box.halfExtents, center: box.center ?? ZERO },
isSensor: box.isSensor === true,
active: chosen && bodyLive,
});
@@ -118,7 +118,7 @@ export function readCollider3DShapes(world: World, entity: number): Collider3DIn
if (chosen) taken = true;
out.push({
component: 'SphereCollider3D',
- shape: { kind: 'sphere', radius: sphere.radius },
+ shape: { kind: 'sphere', radius: sphere.radius, ...(sphere.center ? { center: sphere.center } : {}) },
isSensor: sphere.isSensor === true,
active: chosen && bodyLive,
});
@@ -165,7 +165,7 @@ export function readCollider3DShapes(world: World, entity: number): Collider3DIn
if (chosen) taken = true;
out.push({
component: 'CapsuleCollider3D',
- shape: { kind: 'capsule', radius: capsule.radius, halfHeight: capsule.halfHeight },
+ shape: { kind: 'capsule', radius: capsule.radius, halfHeight: capsule.halfHeight, ...(capsule.center ? { center: capsule.center } : {}) },
isSensor: capsule.isSensor === true,
active: chosen && bodyLive,
});
@@ -220,6 +220,12 @@ function arc(radius: number, axis: 'xy' | 'zy', offset: Vec3, sign: 1 | -1, segm
* four caps and the four lines between them.
*/
export function collider3DWireframe(shape: Collider3DShape, segments = COLLIDER3D_RING_SEGMENTS): Vec3[][] {
+ const lines = centredWireframe(shape, segments);
+ const c = shape.kind === 'box' ? undefined : shape.center;
+ return c ? lines.map((line) => line.map((p) => ({ x: p.x + c.x, y: p.y + c.y, z: p.z + c.z }))) : lines;
+}
+
+function centredWireframe(shape: Collider3DShape, segments: number): Vec3[][] {
if (shape.kind === 'box') {
const { center: c, halfExtents: h } = shape;
const corner = (sx: number, sy: number, sz: number): Vec3 =>
@@ -314,6 +320,7 @@ export function collider3DTriangles(
// appears twice, which is what makes the straight wall between them.
const radius = shape.radius;
const halfHeight = shape.kind === 'capsule' ? shape.halfHeight : 0;
+ const off = shape.center ?? ZERO;
const rings = SOLID_SEGMENTS;
const segs = SOLID_SEGMENTS;
const rows = rings + 2;
@@ -326,9 +333,9 @@ export function collider3DTriangles(
const ringRadius = Math.sin(phi) * radius;
for (let s = 0; s <= segs; s++) {
const theta = (s / segs) * Math.PI * 2;
- positions[n++] = Math.cos(theta) * ringRadius;
- positions[n++] = y;
- positions[n++] = Math.sin(theta) * ringRadius;
+ positions[n++] = Math.cos(theta) * ringRadius + off.x;
+ positions[n++] = y + off.y;
+ positions[n++] = Math.sin(theta) * ringRadius + off.z;
}
}
const indices: number[] = [];
diff --git a/sdk/src/physics3d/Physics3DComponents.ts b/sdk/src/physics3d/Physics3DComponents.ts
index 55aa2f337..cd34e81bb 100644
--- a/sdk/src/physics3d/Physics3DComponents.ts
+++ b/sdk/src/physics3d/Physics3DComponents.ts
@@ -39,6 +39,7 @@ export const RigidBody3D = defineBuiltin<RigidBody3DData>('RigidBody3D', {
export const BoxCollider3D = defineBuiltin<BoxCollider3DData>('BoxCollider3D', {
halfExtents: { x: 0.5, y: 0.5, z: 0.5 },
+ center: { x: 0, y: 0, z: 0 },
friction: 0.3,
restitution: 0.0,
isSensor: false,
@@ -47,6 +48,7 @@ export const BoxCollider3D = defineBuiltin<BoxCollider3DData>('BoxCollider3D', {
export const SphereCollider3D = defineBuiltin<SphereCollider3DData>('SphereCollider3D', {
radius: 0.5,
+ center: { x: 0, y: 0, z: 0 },
friction: 0.3,
restitution: 0.0,
isSensor: false,
@@ -56,6 +58,7 @@ export const SphereCollider3D = defineBuiltin<SphereCollider3DData>('SphereColli
export const CapsuleCollider3D = defineBuiltin<CapsuleCollider3DData>('CapsuleCollider3D', {
radius: 0.3,
halfHeight: 0.5,
+ center: { x: 0, y: 0, z: 0 },
friction: 0.3,
restitution: 0.0,
isSensor: false,
diff --git a/sdk/src/physics3d/Physics3DModule.ts b/sdk/src/physics3d/Physics3DModule.ts
index 5ed193423..a1d9e827b 100644
--- a/sdk/src/physics3d/Physics3DModule.ts
+++ b/sdk/src/physics3d/Physics3DModule.ts
@@ -26,21 +26,21 @@ export interface Physics3DWasmModule {
motion: number, gravityScale: number, linearDamping: number,
angularDamping: number, fixedRotation: number, layer: number,
continuous: number, friction: number, restitution: number,
- isSensor: number): number;
+ isSensor: number, cx: number, cy: number, cz: number): number;
_physics3d_addSphere(entity: number, radius: number,
px: number, py: number, pz: number,
qx: number, qy: number, qz: number, qw: number,
motion: number, gravityScale: number, linearDamping: number,
angularDamping: number, fixedRotation: number, layer: number,
continuous: number, friction: number, restitution: number,
- isSensor: number): number;
+ isSensor: number, cx: number, cy: number, cz: number): number;
_physics3d_addCapsule(entity: number, radius: number, halfHeight: number,
px: number, py: number, pz: number,
qx: number, qy: number, qz: number, qw: number,
motion: number, gravityScale: number, linearDamping: number,
angularDamping: number, fixedRotation: number, layer: number,
continuous: number, friction: number, restitution: number,
- isSensor: number): number;
+ isSensor: number, cx: number, cy: number, cz: number): number;
_physics3d_addMeshBody(entity: number, vertexPtr: number, vertexCount: number,
indexPtr: number, indexCount: number,
px: number, py: number, pz: number,
diff --git a/sdk/src/physics3d/Physics3DSystem.ts b/sdk/src/physics3d/Physics3DSystem.ts
index 44e209688..71d8e170b 100644
--- a/sdk/src/physics3d/Physics3DSystem.ts
+++ b/sdk/src/physics3d/Physics3DSystem.ts
@@ -160,6 +160,11 @@ function motionOf(body: RigidBody3DData): number {
: body.bodyType === 1 ? MOTION.Kinematic : MOTION.Dynamic;
}
+/** Where a collider sits from the entity's origin, in metres. Absent means at the origin. */
+function centreOf(center: { x: number; y: number; z: number } | undefined, ppu: number): [number, number, number] {
+ return center ? [center.x / ppu, center.y / ppu, center.z / ppu] : [0, 0, 0];
+}
+
/**
* Create the body an entity's collider describes.
* @returns the module's body id, or 0 when the entity carries no 3D collider.
@@ -185,14 +190,14 @@ function createBody(app: App, module: Physics3DWasmModule, entity: Entity,
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);
+ ...how, box.friction, box.restitution, box.isSensor ? 1 : 0, ...centreOf(box.center, ppu));
}
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);
+ ...how, sphere.friction, sphere.restitution, sphere.isSensor ? 1 : 0, ...centreOf(sphere.center, ppu));
}
const meshCollider = has(MeshCollider3D)
? app.world.get(entity, MeshCollider3D) as MeshCollider3DData : undefined;
@@ -210,7 +215,7 @@ function createBody(app: App, module: Physics3DWasmModule, entity: Entity,
return module._physics3d_addCapsule(
entity as number, capsule.radius / ppu, capsule.halfHeight / ppu,
px, py, pz, r.x, r.y, r.z, r.w,
- ...how, capsule.friction, capsule.restitution, capsule.isSensor ? 1 : 0);
+ ...how, capsule.friction, capsule.restitution, capsule.isSensor ? 1 : 0, ...centreOf(capsule.center, ppu));
}
// A body with no shape has no extent to collide with, so it is not registered
// at all — the alternative is an invisible point that falls forever.
diff --git a/sdk/src/wasm/ptrLayouts.generated.ts b/sdk/src/wasm/ptrLayouts.generated.ts
index 219297d10..c53451ae8 100644
--- a/sdk/src/wasm/ptrLayouts.generated.ts
+++ b/sdk/src/wasm/ptrLayouts.generated.ts
@@ -58,10 +58,11 @@ export const PTR_LAYOUTS: Record<string, PtrLayout> = {
ptrFn: 'getBoxCollider3DPtr',
fields: [
{ name: 'halfExtents', type: 'vec3', offset: 0 },
- { name: 'friction', type: 'f32', offset: 12 },
- { name: 'restitution', type: 'f32', offset: 16 },
- { name: 'isSensor', type: 'bool', offset: 20 },
- { name: 'enabled', type: 'bool', offset: 21 },
+ { name: 'center', type: 'vec3', offset: 12 },
+ { name: 'friction', type: 'f32', offset: 24 },
+ { name: 'restitution', type: 'f32', offset: 28 },
+ { name: 'isSensor', type: 'bool', offset: 32 },
+ { name: 'enabled', type: 'bool', offset: 33 },
],
},
Camera: {
@@ -113,10 +114,11 @@ export const PTR_LAYOUTS: Record<string, PtrLayout> = {
fields: [
{ name: 'radius', type: 'f32', offset: 0 },
{ name: 'halfHeight', type: 'f32', offset: 4 },
- { name: 'friction', type: 'f32', offset: 8 },
- { name: 'restitution', type: 'f32', offset: 12 },
- { name: 'isSensor', type: 'bool', offset: 16 },
- { name: 'enabled', type: 'bool', offset: 17 },
+ { name: 'center', type: 'vec3', offset: 8 },
+ { name: 'friction', type: 'f32', offset: 20 },
+ { name: 'restitution', type: 'f32', offset: 24 },
+ { name: 'isSensor', type: 'bool', offset: 28 },
+ { name: 'enabled', type: 'bool', offset: 29 },
],
},
CharacterController3D: {
@@ -515,10 +517,11 @@ export const PTR_LAYOUTS: Record<string, PtrLayout> = {
ptrFn: 'getSphereCollider3DPtr',
fields: [
{ name: 'radius', type: 'f32', offset: 0 },
- { name: 'friction', type: 'f32', offset: 4 },
- { name: 'restitution', type: 'f32', offset: 8 },
- { name: 'isSensor', type: 'bool', offset: 12 },
- { name: 'enabled', type: 'bool', offset: 13 },
+ { name: 'center', type: 'vec3', offset: 4 },
+ { name: 'friction', type: 'f32', offset: 16 },
+ { name: 'restitution', type: 'f32', offset: 20 },
+ { name: 'isSensor', type: 'bool', offset: 24 },
+ { name: 'enabled', type: 'bool', offset: 25 },
],
},
SpineAnimation: {
diff --git a/sdk/src/wasm/wasm.generated.ts b/sdk/src/wasm/wasm.generated.ts
index ac971e6ca..8a02ed96e 100644
--- a/sdk/src/wasm/wasm.generated.ts
+++ b/sdk/src/wasm/wasm.generated.ts
@@ -483,6 +483,7 @@ export interface BoxCollider2D {
export interface BoxCollider3D {
halfExtents: Vec3;
+ center: Vec3;
friction: number;
restitution: number;
isSensor: boolean;
@@ -530,6 +531,7 @@ export interface CapsuleCollider2D {
export interface CapsuleCollider3D {
radius: number;
halfHeight: number;
+ center: Vec3;
friction: number;
restitution: number;
isSensor: boolean;
@@ -897,6 +899,7 @@ export interface SortingGroup {
export interface SphereCollider3D {
radius: number;
+ center: Vec3;
friction: number;
restitution: number;
isSensor: boolean;
diff --git a/sdk/tests/physics3d-ecs.test.ts b/sdk/tests/physics3d-ecs.test.ts
index cab3f0c1f..5253bbe84 100644
--- a/sdk/tests/physics3d-ecs.test.ts
+++ b/sdk/tests/physics3d-ecs.test.ts
@@ -236,6 +236,21 @@ describe('the 3D world and the ECS', () => {
expect(call!.args[3]).toBeCloseTo(1.5, 6);
});
+ it('hands the solver where a collider sits from its entity, in metres', () => {
+ const e = spawn();
+ world.insert(e, BoxCollider3D);
+ world.update(e, BoxCollider3D, (c) => { (c as { center: { x: number; y: number; z: number } }).center = { x: 100, y: 250, z: -50 }; });
+ const plain = spawn();
+ world.insert(plain, BoxCollider3D);
+
+ stepPhysics3D(app, module, bodies, DEFAULT_PHYSICS3D_CONFIG);
+
+ const [off, centred] = called('addBox');
+ // The last three arguments are the offset: the shape moves, the body stays at the entity.
+ expect(off!.args.slice(-3)).toEqual([1, 2.5, -0.5]);
+ expect(centred!.args.slice(-3)).toEqual([0, 0, 0]);
+ });
+
it('writes the solver’s answer back in world units', () => {
const e = spawn();
world.insert(e, BoxCollider3D);
diff --git a/sdk/tests/physics3d-smoke.mjs b/sdk/tests/physics3d-smoke.mjs
index ba7884882..0072c8727 100644
--- a/sdk/tests/physics3d-smoke.mjs
+++ b/sdk/tests/physics3d-smoke.mjs
@@ -81,8 +81,8 @@ check('the world reports itself ready', m._physics3d_isReady() === 1);
// Floor spans y in [-1, 0]; a sphere of radius 0.5 dropped from y=4 comes to rest
// with its CENTRE at 0.5 — the one number that says contact resolution ran.
const FLOOR = 1, BALL = 2;
-m._physics3d_addBox(FLOOR, 50, 0.5, 50, 0, -0.5, 0, ...IDENTITY, ...FREE(STATIC), 0.5, 0, 0);
-const ballId = m._physics3d_addSphere(BALL, 0.5, 0, 4, 0, ...IDENTITY, ...FREE(DYNAMIC), 0.5, 0, 0);
+m._physics3d_addBox(FLOOR, 50, 0.5, 50, 0, -0.5, 0, ...IDENTITY, ...FREE(STATIC), 0.5, 0, 0, 0, 0, 0);
+const ballId = m._physics3d_addSphere(BALL, 0.5, 0, 4, 0, ...IDENTITY, ...FREE(DYNAMIC), 0.5, 0, 0, 0, 0, 0);
m._physics3d_optimize();
check('a body id is handed back', ballId !== 0, `id=${ballId}`);
@@ -116,7 +116,7 @@ check('a ray into empty space misses', raycast(0, 10, 0, 0, 20, 0) === null);
// ── 3) Static bodies stay put, kinematic ones are moved by hand ─────────────
const PLATFORM = 3;
const platformId = m._physics3d_addBox(PLATFORM, 1, 0.25, 1, 5, 2, 0, ...IDENTITY,
- ...FREE(KINEMATIC), 0.5, 0, 0);
+ ...FREE(KINEMATIC), 0.5, 0, 0, 0, 0, 0);
step(60);
const platform = bodyState(platformId);
check('a kinematic body ignores gravity', platform && near(platform.y, 2, 1e-3),
@@ -738,6 +738,15 @@ if (before) {
check('a torque turns it too', dynamics().wz !== spin1.wz, `wz ${dynamics().wz.toFixed(3)}`);
}
+// ── Collider centre: a shape off the entity's origin ────────────────────────
+// A static box whose body sits at y=0 but whose shape is centred 3 above it: a ball dropped onto it rests on the SHAPE (top at 3.5), not on the body origin.
+const OFFSET_BOX = 700, OFFSET_BALL = 701;
+m._physics3d_addBox(OFFSET_BOX, 2, 0.5, 2, 700, 0, 0, ...IDENTITY, ...FREE(STATIC), 0.5, 0, 0, 0, 3, 0);
+const offsetBall = m._physics3d_addSphere(OFFSET_BALL, 0.5, 700, 8, 0, ...IDENTITY, ...FREE(DYNAMIC), 0.5, 0, 0, 0, 0, 0);
+step(180);
+const offsetRest = bodyState(offsetBall);
+check('a box centred above its body holds a ball at the shape, not the origin', offsetRest && near(offsetRest.y, 4, 0.05), `y=${offsetRest?.y.toFixed(3)}`);
+
m._physics3d_shutdown();
check('the world reports itself gone', m._physics3d_isReady() === 0);
diff --git a/sdk/tests/physics3d-wireframe.test.ts b/sdk/tests/physics3d-wireframe.test.ts
index 90ddcbc0c..f576bb557 100644
--- a/sdk/tests/physics3d-wireframe.test.ts
+++ b/sdk/tests/physics3d-wireframe.test.ts
@@ -272,6 +272,15 @@ describe('what a 3D collider looks like', () => {
expect(size(lines)).toEqual({ x: 14, y: 14, z: 14 });
});
+ it('moves a sphere and a capsule to where their collider sits', () => {
+ const center = { x: 10, y: -20, z: 30 };
+ for (const shape of [{ kind: 'sphere', radius: 7, center }, { kind: 'capsule', radius: 7, halfHeight: 5, center }] as const) {
+ const points = collider3DWireframe(shape).flat();
+ const mid = (axis: 'x' | 'y' | 'z') => (Math.min(...points.map((p) => p[axis])) + Math.max(...points.map((p) => p[axis]))) / 2;
+ expect([mid('x'), mid('y'), mid('z')]).toEqual([10, -20, 30]);
+ }
+ });
+
it('is as tall AND as wide as the capsule', () => {
// Height alone cannot tell radius from halfHeight: 30 + 50 and 50 + 30
// stand the same. The width is what separates them.
diff --git a/src/esengine/bindings/EditorAPI.generated.cpp b/src/esengine/bindings/EditorAPI.generated.cpp
index 2c63239d5..aac13772f 100644
--- a/src/esengine/bindings/EditorAPI.generated.cpp
+++ b/src/esengine/bindings/EditorAPI.generated.cpp
@@ -2,10 +2,10 @@
* @file EditorAPI.generated.cpp
* @brief Auto-generated editor API with string-dispatched component access
* @details Generated by EHT - DO NOT EDIT
- * @schema_hash 9262d1e85b95eb6a
+ * @schema_hash f91ae5c2af80fca7
*/
-#define ES_EDITOR_API_SCHEMA_HASH "9262d1e85b95eb6a"
+#define ES_EDITOR_API_SCHEMA_HASH "f91ae5c2af80fca7"
#include <emscripten/bind.h>
#include <string>
@@ -164,6 +164,9 @@ std::string editor_getComponentSchema(const std::string& name) {
{"key":"halfExtents.x","type":"float","group":"BoxCollider3D"},
{"key":"halfExtents.y","type":"float","group":"BoxCollider3D"},
{"key":"halfExtents.z","type":"float","group":"BoxCollider3D"},
+ {"key":"center.x","type":"float","group":"BoxCollider3D"},
+ {"key":"center.y","type":"float","group":"BoxCollider3D"},
+ {"key":"center.z","type":"float","group":"BoxCollider3D"},
{"key":"friction","type":"float","group":"BoxCollider3D"},
{"key":"restitution","type":"float","group":"BoxCollider3D"},
{"key":"isSensor","type":"bool","group":"BoxCollider3D"},
@@ -219,6 +222,9 @@ std::string editor_getComponentSchema(const std::string& name) {
return R"JSON([
{"key":"radius","type":"float","group":"CapsuleCollider3D"},
{"key":"halfHeight","type":"float","group":"CapsuleCollider3D"},
+ {"key":"center.x","type":"float","group":"CapsuleCollider3D"},
+ {"key":"center.y","type":"float","group":"CapsuleCollider3D"},
+ {"key":"center.z","type":"float","group":"CapsuleCollider3D"},
{"key":"friction","type":"float","group":"CapsuleCollider3D"},
{"key":"restitution","type":"float","group":"CapsuleCollider3D"},
{"key":"isSensor","type":"bool","group":"CapsuleCollider3D"},
@@ -646,6 +652,9 @@ std::string editor_getComponentSchema(const std::string& name) {
} else if (name == "SphereCollider3D") {
return R"JSON([
{"key":"radius","type":"float","group":"SphereCollider3D"},
+ {"key":"center.x","type":"float","group":"SphereCollider3D"},
+ {"key":"center.y","type":"float","group":"SphereCollider3D"},
+ {"key":"center.z","type":"float","group":"SphereCollider3D"},
{"key":"friction","type":"float","group":"SphereCollider3D"},
{"key":"restitution","type":"float","group":"SphereCollider3D"},
{"key":"isSensor","type":"bool","group":"SphereCollider3D"},
@@ -1334,6 +1343,9 @@ bool editor_setFloat(Registry& reg, u32 e, const std::string& comp, const std::s
if (field == "halfExtents.x") { c.halfExtents.x = value; }
else if (field == "halfExtents.y") { c.halfExtents.y = value; }
else if (field == "halfExtents.z") { c.halfExtents.z = value; }
+ else if (field == "center.x") { c.center.x = value; }
+ else if (field == "center.y") { c.center.y = value; }
+ else if (field == "center.z") { c.center.z = value; }
else if (field == "friction") { c.friction = value; }
else if (field == "restitution") { c.restitution = value; }
else { return false; }
@@ -1380,6 +1392,9 @@ bool editor_setFloat(Registry& reg, u32 e, const std::string& comp, const std::s
auto& c = reg.get<esengine::ecs::CapsuleCollider3D>(entity);
if (field == "radius") { c.radius = value; }
else if (field == "halfHeight") { c.halfHeight = value; }
+ else if (field == "center.x") { c.center.x = value; }
+ else if (field == "center.y") { c.center.y = value; }
+ else if (field == "center.z") { c.center.z = value; }
else if (field == "friction") { c.friction = value; }
else if (field == "restitution") { c.restitution = value; }
else { return false; }
@@ -1706,6 +1721,9 @@ bool editor_setFloat(Registry& reg, u32 e, const std::string& comp, const std::s
if (!reg.has<esengine::ecs::SphereCollider3D>(entity)) return false;
auto& c = reg.get<esengine::ecs::SphereCollider3D>(entity);
if (field == "radius") { c.radius = value; }
+ else if (field == "center.x") { c.center.x = value; }
+ else if (field == "center.y") { c.center.y = value; }
+ else if (field == "center.z") { c.center.z = value; }
else if (field == "friction") { c.friction = value; }
else if (field == "restitution") { c.restitution = value; }
else { return false; }
@@ -1957,6 +1975,9 @@ f32 editor_getFloat(Registry& reg, u32 e, const std::string& comp, const std::st
if (field == "halfExtents.x") { return c.halfExtents.x; }
else if (field == "halfExtents.y") { return c.halfExtents.y; }
else if (field == "halfExtents.z") { return c.halfExtents.z; }
+ else if (field == "center.x") { return c.center.x; }
+ else if (field == "center.y") { return c.center.y; }
+ else if (field == "center.z") { return c.center.z; }
else if (field == "friction") { return c.friction; }
else if (field == "restitution") { return c.restitution; }
} else if (comp == "Camera") {
@@ -1995,6 +2016,9 @@ f32 editor_getFloat(Registry& reg, u32 e, const std::string& comp, const std::st
const auto& c = reg.get<esengine::ecs::CapsuleCollider3D>(entity);
if (field == "radius") { return c.radius; }
else if (field == "halfHeight") { return c.halfHeight; }
+ else if (field == "center.x") { return c.center.x; }
+ else if (field == "center.y") { return c.center.y; }
+ else if (field == "center.z") { return c.center.z; }
else if (field == "friction") { return c.friction; }
else if (field == "restitution") { return c.restitution; }
} else if (comp == "CharacterController3D") {
@@ -2269,6 +2293,9 @@ f32 editor_getFloat(Registry& reg, u32 e, const std::string& comp, const std::st
if (!reg.has<esengine::ecs::SphereCollider3D>(entity)) return 0.0f;
const auto& c = reg.get<esengine::ecs::SphereCollider3D>(entity);
if (field == "radius") { return c.radius; }
+ else if (field == "center.x") { return c.center.x; }
+ else if (field == "center.y") { return c.center.y; }
+ else if (field == "center.z") { return c.center.z; }
else if (field == "friction") { return c.friction; }
else if (field == "restitution") { return c.restitution; }
} else if (comp == "SpineAnimation") {
diff --git a/src/esengine/bindings/WebBindings.generated.cpp b/src/esengine/bindings/WebBindings.generated.cpp
index 987132316..4e413cb45 100644
--- a/src/esengine/bindings/WebBindings.generated.cpp
+++ b/src/esengine/bindings/WebBindings.generated.cpp
@@ -1859,6 +1859,7 @@ EMSCRIPTEN_BINDINGS(esengine_components) {
value_object<esengine::ecs::BoxCollider3D>("BoxCollider3D")
.field("halfExtents", &esengine::ecs::BoxCollider3D::halfExtents)
+ .field("center", &esengine::ecs::BoxCollider3D::center)
.field("friction", &esengine::ecs::BoxCollider3D::friction)
.field("restitution", &esengine::ecs::BoxCollider3D::restitution)
.field("isSensor", &esengine::ecs::BoxCollider3D::isSensor)
@@ -1902,6 +1903,7 @@ EMSCRIPTEN_BINDINGS(esengine_components) {
value_object<esengine::ecs::CapsuleCollider3D>("CapsuleCollider3D")
.field("radius", &esengine::ecs::CapsuleCollider3D::radius)
.field("halfHeight", &esengine::ecs::CapsuleCollider3D::halfHeight)
+ .field("center", &esengine::ecs::CapsuleCollider3D::center)
.field("friction", &esengine::ecs::CapsuleCollider3D::friction)
.field("restitution", &esengine::ecs::CapsuleCollider3D::restitution)
.field("isSensor", &esengine::ecs::CapsuleCollider3D::isSensor)
@@ -2237,6 +2239,7 @@ EMSCRIPTEN_BINDINGS(esengine_components) {
value_object<esengine::ecs::SphereCollider3D>("SphereCollider3D")
.field("radius", &esengine::ecs::SphereCollider3D::radius)
+ .field("center", &esengine::ecs::SphereCollider3D::center)
.field("friction", &esengine::ecs::SphereCollider3D::friction)
.field("restitution", &esengine::ecs::SphereCollider3D::restitution)
.field("isSensor", &esengine::ecs::SphereCollider3D::isSensor)
@@ -3858,10 +3861,11 @@ static_assert(offsetof(esengine::ecs::BoxCollider2D, enabled) == 29, "ABI offset
static_assert(offsetof(esengine::ecs::BoxCollider2D, categoryBits) == 32, "ABI offset drift: esengine::ecs::BoxCollider2D.categoryBits (EHT expected 32)");
static_assert(offsetof(esengine::ecs::BoxCollider2D, maskBits) == 36, "ABI offset drift: esengine::ecs::BoxCollider2D.maskBits (EHT expected 36)");
static_assert(offsetof(esengine::ecs::BoxCollider3D, halfExtents) == 0, "ABI offset drift: esengine::ecs::BoxCollider3D.halfExtents (EHT expected 0)");
-static_assert(offsetof(esengine::ecs::BoxCollider3D, friction) == 12, "ABI offset drift: esengine::ecs::BoxCollider3D.friction (EHT expected 12)");
-static_assert(offsetof(esengine::ecs::BoxCollider3D, restitution) == 16, "ABI offset drift: esengine::ecs::BoxCollider3D.restitution (EHT expected 16)");
-static_assert(offsetof(esengine::ecs::BoxCollider3D, isSensor) == 20, "ABI offset drift: esengine::ecs::BoxCollider3D.isSensor (EHT expected 20)");
-static_assert(offsetof(esengine::ecs::BoxCollider3D, enabled) == 21, "ABI offset drift: esengine::ecs::BoxCollider3D.enabled (EHT expected 21)");
+static_assert(offsetof(esengine::ecs::BoxCollider3D, center) == 12, "ABI offset drift: esengine::ecs::BoxCollider3D.center (EHT expected 12)");
+static_assert(offsetof(esengine::ecs::BoxCollider3D, friction) == 24, "ABI offset drift: esengine::ecs::BoxCollider3D.friction (EHT expected 24)");
+static_assert(offsetof(esengine::ecs::BoxCollider3D, restitution) == 28, "ABI offset drift: esengine::ecs::BoxCollider3D.restitution (EHT expected 28)");
+static_assert(offsetof(esengine::ecs::BoxCollider3D, isSensor) == 32, "ABI offset drift: esengine::ecs::BoxCollider3D.isSensor (EHT expected 32)");
+static_assert(offsetof(esengine::ecs::BoxCollider3D, enabled) == 33, "ABI offset drift: esengine::ecs::BoxCollider3D.enabled (EHT expected 33)");
static_assert(offsetof(esengine::ecs::Camera, projectionType) == 0, "ABI offset drift: esengine::ecs::Camera.projectionType (EHT expected 0)");
static_assert(offsetof(esengine::ecs::Camera, fov) == 4, "ABI offset drift: esengine::ecs::Camera.fov (EHT expected 4)");
static_assert(offsetof(esengine::ecs::Camera, orthoSize) == 8, "ABI offset drift: esengine::ecs::Camera.orthoSize (EHT expected 8)");
@@ -3893,10 +3897,11 @@ static_assert(offsetof(esengine::ecs::CapsuleCollider2D, categoryBits) == 32, "A
static_assert(offsetof(esengine::ecs::CapsuleCollider2D, maskBits) == 36, "ABI offset drift: esengine::ecs::CapsuleCollider2D.maskBits (EHT expected 36)");
static_assert(offsetof(esengine::ecs::CapsuleCollider3D, radius) == 0, "ABI offset drift: esengine::ecs::CapsuleCollider3D.radius (EHT expected 0)");
static_assert(offsetof(esengine::ecs::CapsuleCollider3D, halfHeight) == 4, "ABI offset drift: esengine::ecs::CapsuleCollider3D.halfHeight (EHT expected 4)");
-static_assert(offsetof(esengine::ecs::CapsuleCollider3D, friction) == 8, "ABI offset drift: esengine::ecs::CapsuleCollider3D.friction (EHT expected 8)");
-static_assert(offsetof(esengine::ecs::CapsuleCollider3D, restitution) == 12, "ABI offset drift: esengine::ecs::CapsuleCollider3D.restitution (EHT expected 12)");
-static_assert(offsetof(esengine::ecs::CapsuleCollider3D, isSensor) == 16, "ABI offset drift: esengine::ecs::CapsuleCollider3D.isSensor (EHT expected 16)");
-static_assert(offsetof(esengine::ecs::CapsuleCollider3D, enabled) == 17, "ABI offset drift: esengine::ecs::CapsuleCollider3D.enabled (EHT expected 17)");
+static_assert(offsetof(esengine::ecs::CapsuleCollider3D, center) == 8, "ABI offset drift: esengine::ecs::CapsuleCollider3D.center (EHT expected 8)");
+static_assert(offsetof(esengine::ecs::CapsuleCollider3D, friction) == 20, "ABI offset drift: esengine::ecs::CapsuleCollider3D.friction (EHT expected 20)");
+static_assert(offsetof(esengine::ecs::CapsuleCollider3D, restitution) == 24, "ABI offset drift: esengine::ecs::CapsuleCollider3D.restitution (EHT expected 24)");
+static_assert(offsetof(esengine::ecs::CapsuleCollider3D, isSensor) == 28, "ABI offset drift: esengine::ecs::CapsuleCollider3D.isSensor (EHT expected 28)");
+static_assert(offsetof(esengine::ecs::CapsuleCollider3D, enabled) == 29, "ABI offset drift: esengine::ecs::CapsuleCollider3D.enabled (EHT expected 29)");
static_assert(offsetof(esengine::ecs::CharacterController3D, velocity) == 0, "ABI offset drift: esengine::ecs::CharacterController3D.velocity (EHT expected 0)");
static_assert(offsetof(esengine::ecs::CharacterController3D, radius) == 12, "ABI offset drift: esengine::ecs::CharacterController3D.radius (EHT expected 12)");
static_assert(offsetof(esengine::ecs::CharacterController3D, halfHeight) == 16, "ABI offset drift: esengine::ecs::CharacterController3D.halfHeight (EHT expected 16)");
@@ -4155,10 +4160,11 @@ static_assert(offsetof(esengine::ecs::SortingGroup, layer) == 0, "ABI offset dri
static_assert(offsetof(esengine::ecs::SortingGroup, order) == 4, "ABI offset drift: esengine::ecs::SortingGroup.order (EHT expected 4)");
static_assert(offsetof(esengine::ecs::SortingGroup, enabled) == 8, "ABI offset drift: esengine::ecs::SortingGroup.enabled (EHT expected 8)");
static_assert(offsetof(esengine::ecs::SphereCollider3D, radius) == 0, "ABI offset drift: esengine::ecs::SphereCollider3D.radius (EHT expected 0)");
-static_assert(offsetof(esengine::ecs::SphereCollider3D, friction) == 4, "ABI offset drift: esengine::ecs::SphereCollider3D.friction (EHT expected 4)");
-static_assert(offsetof(esengine::ecs::SphereCollider3D, restitution) == 8, "ABI offset drift: esengine::ecs::SphereCollider3D.restitution (EHT expected 8)");
-static_assert(offsetof(esengine::ecs::SphereCollider3D, isSensor) == 12, "ABI offset drift: esengine::ecs::SphereCollider3D.isSensor (EHT expected 12)");
-static_assert(offsetof(esengine::ecs::SphereCollider3D, enabled) == 13, "ABI offset drift: esengine::ecs::SphereCollider3D.enabled (EHT expected 13)");
+static_assert(offsetof(esengine::ecs::SphereCollider3D, center) == 4, "ABI offset drift: esengine::ecs::SphereCollider3D.center (EHT expected 4)");
+static_assert(offsetof(esengine::ecs::SphereCollider3D, friction) == 16, "ABI offset drift: esengine::ecs::SphereCollider3D.friction (EHT expected 16)");
+static_assert(offsetof(esengine::ecs::SphereCollider3D, restitution) == 20, "ABI offset drift: esengine::ecs::SphereCollider3D.restitution (EHT expected 20)");
+static_assert(offsetof(esengine::ecs::SphereCollider3D, isSensor) == 24, "ABI offset drift: esengine::ecs::SphereCollider3D.isSensor (EHT expected 24)");
+static_assert(offsetof(esengine::ecs::SphereCollider3D, enabled) == 25, "ABI offset drift: esengine::ecs::SphereCollider3D.enabled (EHT expected 25)");
static_assert(offsetof(esengine::ecs::SpineAnimation, timeScale) == 48, "ABI offset drift: esengine::ecs::SpineAnimation.timeScale (EHT expected 48)");
static_assert(offsetof(esengine::ecs::SpineAnimation, loop) == 52, "ABI offset drift: esengine::ecs::SpineAnimation.loop (EHT expected 52)");
static_assert(offsetof(esengine::ecs::SpineAnimation, playing) == 53, "ABI offset drift: esengine::ecs::SpineAnimation.playing (EHT expected 53)");
@@ -4295,7 +4301,7 @@ static_assert(offsetof(esengine::ecs::Velocity, angular) == 12, "ABI offset drif
// ABI Hash -- runtime handshake against the SDK bundle
// =============================================================================
-static const char* kEsAbiLayoutHash = "63a00195ad788bd8";
+static const char* kEsAbiLayoutHash = "790a68ffa2098d35";
std::string esengineGetAbiLayoutHash() {
return std::string(kEsAbiLayoutHash);
diff --git a/src/esengine/bindings/modules/physics3d/Physics3DBindings.hpp b/src/esengine/bindings/modules/physics3d/Physics3DBindings.hpp
index 19f6e9562..12eec9a0b 100644
--- a/src/esengine/bindings/modules/physics3d/Physics3DBindings.hpp
+++ b/src/esengine/bindings/modules/physics3d/Physics3DBindings.hpp
@@ -43,19 +43,22 @@ uint32_t physics3d_addBox(uint32_t entity, float hx, float hy, float hz,
float qx, float qy, float qz, float qw,
int motion, float gravityScale, float linearDamping,
float angularDamping, int fixedRotation, uint32_t layer,
- int continuous, float friction, float restitution, int isSensor);
+ int continuous, float friction, float restitution, int isSensor,
+ float cx, float cy, float cz);
uint32_t physics3d_addSphere(uint32_t entity, float radius,
float px, float py, float pz,
float qx, float qy, float qz, float qw,
int motion, float gravityScale, float linearDamping,
float angularDamping, int fixedRotation, uint32_t layer,
- int continuous, float friction, float restitution, int isSensor);
+ int continuous, float friction, float restitution, int isSensor,
+ float cx, float cy, float cz);
uint32_t physics3d_addCapsule(uint32_t entity, float radius, float halfHeight,
float px, float py, float pz,
float qx, float qy, float qz, float qw,
int motion, float gravityScale, float linearDamping,
float angularDamping, int fixedRotation, uint32_t layer,
- int continuous, float friction, float restitution, int isSensor);
+ int continuous, float friction, float restitution, int isSensor,
+ float cx, float cy, float cz);
uint32_t physics3d_addMeshBody(uint32_t entity, uintptr_t vertexPtr, uint32_t vertexCount,
uintptr_t indexPtr, uint32_t indexCount,
float px, float py, float pz,
diff --git a/src/esengine/bindings/modules/physics3d/Physics3DModuleEntry.cpp b/src/esengine/bindings/modules/physics3d/Physics3DModuleEntry.cpp
index 4a4dc6f16..2170a880b 100644
--- a/src/esengine/bindings/modules/physics3d/Physics3DModuleEntry.cpp
+++ b/src/esengine/bindings/modules/physics3d/Physics3DModuleEntry.cpp
@@ -23,6 +23,7 @@
#include <Jolt/Physics/Collision/Shape/CapsuleShape.h>
#include <Jolt/Physics/Collision/Shape/ConvexHullShape.h>
#include <Jolt/Physics/Collision/Shape/MeshShape.h>
+#include <Jolt/Physics/Collision/Shape/RotatedTranslatedShape.h>
#include <Jolt/Physics/Collision/Shape/SphereShape.h>
#include <Jolt/Physics/Character/CharacterVirtual.h>
#include <Jolt/Physics/Collision/CollideShape.h>
@@ -155,10 +156,19 @@ ContactRecorder& recorder() {
/// Register a shape as a body, and remember which entity it speaks for.
uint32_t addBody(uint32_t entity, const Ref<Shape>& shape, float px, float py, float pz,
float qx, float qy, float qz, float qw, const BodyMotion& how,
- float friction, float restitution, int isSensor) {
+ float friction, float restitution, int isSensor,
+ float cx = 0.0f, float cy = 0.0f, float cz = 0.0f) {
if (!g().isValid()) return 0;
+ // A collider off the entity's origin: the shape is carried by a translated wrapper, so the body (and what a dynamic one rotates about)
+ // stays at the entity.
+ Ref<Shape> placed = shape;
+ // `> 0` is false for NaN too, so a caller that leaves the offset off gets a body at the origin.
+ if (cx * cx + cy * cy + cz * cz > 0.0f) {
+ const ShapeSettings::ShapeResult r = RotatedTranslatedShapeSettings(Vec3(cx, cy, cz), Quat::sIdentity(), shape).Create();
+ if (r.IsValid()) placed = r.Get();
+ }
const EMotionType motionType = motionTypeOf(how.motion);
- BodyCreationSettings settings(shape, RVec3(px, py, pz), Quat(qx, qy, qz, qw).Normalized(),
+ BodyCreationSettings settings(placed, RVec3(px, py, pz), Quat(qx, qy, qz, qw).Normalized(),
motionType, layerOf(motionType, how.layer));
settings.mFriction = friction;
settings.mRestitution = restitution;
@@ -301,11 +311,12 @@ uint32_t physics3d_addBox(uint32_t entity, float hx, float hy, float hz,
float qx, float qy, float qz, float qw,
int motion, float gravityScale, float linearDamping,
float angularDamping, int fixedRotation, uint32_t layer,
- int continuous, float friction, float restitution, int isSensor) {
+ int continuous, float friction, float restitution, int isSensor,
+ float cx, float cy, float cz) {
return addBody(entity, new BoxShape(Vec3(hx, hy, hz)), px, py, pz, qx, qy, qz, qw,
{motion, gravityScale, linearDamping, angularDamping, fixedRotation, layer,
continuous},
- friction, restitution, isSensor);
+ friction, restitution, isSensor, cx, cy, cz);
}
EMSCRIPTEN_KEEPALIVE
@@ -314,11 +325,12 @@ uint32_t physics3d_addSphere(uint32_t entity, float radius,
float qx, float qy, float qz, float qw,
int motion, float gravityScale, float linearDamping,
float angularDamping, int fixedRotation, uint32_t layer,
- int continuous, float friction, float restitution, int isSensor) {
+ int continuous, float friction, float restitution, int isSensor,
+ float cx, float cy, float cz) {
return addBody(entity, new SphereShape(radius), px, py, pz, qx, qy, qz, qw,
{motion, gravityScale, linearDamping, angularDamping, fixedRotation, layer,
continuous},
- friction, restitution, isSensor);
+ friction, restitution, isSensor, cx, cy, cz);
}
/// `halfHeight` is the cylinder half-height, so the capsule is `2*halfHeight + 2*radius`
@@ -329,11 +341,12 @@ uint32_t physics3d_addCapsule(uint32_t entity, float radius, float halfHeight,
float qx, float qy, float qz, float qw,
int motion, float gravityScale, float linearDamping,
float angularDamping, int fixedRotation, uint32_t layer,
- int continuous, float friction, float restitution, int isSensor) {
+ int continuous, float friction, float restitution, int isSensor,
+ float cx, float cy, float cz) {
return addBody(entity, new CapsuleShape(halfHeight, radius), px, py, pz, qx, qy, qz, qw,
{motion, gravityScale, linearDamping, angularDamping, fixedRotation, layer,
continuous},
- friction, restitution, isSensor);
+ friction, restitution, isSensor, cx, cy, cz);
}
/**
diff --git a/src/esengine/ecs/components/RigidBody3D.hpp b/src/esengine/ecs/components/RigidBody3D.hpp
index 062af841f..c6a40ee4d 100644
--- a/src/esengine/ecs/components/RigidBody3D.hpp
+++ b/src/esengine/ecs/components/RigidBody3D.hpp
@@ -77,6 +77,10 @@ struct BoxCollider3D {
ES_PROPERTY()
glm::vec3 halfExtents{0.5f, 0.5f, 0.5f};
+ /** @brief Where the shape sits from the entity's origin, in world units; zero is centred on it. */
+ ES_PROPERTY(optional)
+ glm::vec3 center{0.0f, 0.0f, 0.0f};
+
ES_PROPERTY(min=0)
f32 friction{0.3f};
@@ -96,6 +100,10 @@ struct SphereCollider3D {
ES_PROPERTY(min=0)
f32 radius{0.5f};
+ /** @brief Where the shape sits from the entity's origin, in world units; zero is centred on it. */
+ ES_PROPERTY(optional)
+ glm::vec3 center{0.0f, 0.0f, 0.0f};
+
ES_PROPERTY(min=0)
f32 friction{0.3f};
@@ -124,6 +132,10 @@ struct CapsuleCollider3D {
ES_PROPERTY(min=0)
f32 halfHeight{0.5f};
+ /** @brief Where the shape sits from the entity's origin, in world units; zero is centred on it. */
+ ES_PROPERTY(optional)
+ glm::vec3 center{0.0f, 0.0f, 0.0f};
+
ES_PROPERTY(min=0)
f32 friction{0.3f};
diff --git a/tests/aot/generated/conformance/handshake.h b/tests/aot/generated/conformance/handshake.h
index 73a9240cb..3584a80cd 100644
--- a/tests/aot/generated/conformance/handshake.h
+++ b/tests/aot/generated/conformance/handshake.h
@@ -1,5 +1,5 @@
/* GENERATED by sdk/tests/aot-conformance.test.ts — do not edit. */
/* The contract half of the handshake. The width half is the harness. */
-#define ES_CONF_EXPECTED_CONTRACT_HASH 0xb71d1ed9cc346220ULL
+#define ES_CONF_EXPECTED_CONTRACT_HASH 0x57b9f31fef78b5a7ULL
/* And which BUILD the artifact beside this one is. */
#define ES_CONF_EXPECTED_MODULE_CONTRACT 0xc3d0e057d5701a2eULL
diff --git a/tests/aot/generated/conformance/systems_decl.c b/tests/aot/generated/conformance/systems_decl.c
index 6ae19b4e7..24bc0407b 100644
--- a/tests/aot/generated/conformance/systems_decl.c
+++ b/tests/aot/generated/conformance/systems_decl.c
@@ -10,7 +10,7 @@
answer, it is a read of a different field. The address width belongs
to the MACHINE, so it mixes in here rather than in the compiler and a
32-bit artifact cannot load into a 64-bit host. */
-#define ES_ABI_ENGINE_DIGEST 0xb71d1ed9cc346220ULL
+#define ES_ABI_ENGINE_DIGEST 0x57b9f31fef78b5a7ULL
ES_EXPORT const uint64_t es_abi_hash =
ES_ABI_ENGINE_DIGEST ^ (0x9e3779b97f4a7c15ULL * (uint64_t)sizeof(es_addr_t));
diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjs
index 5222436f9..71a11d2ff 100644
--- a/tools/releaseNotes.mjs
+++ b/tools/releaseNotes.mjs
@@ -28,6 +28,8 @@ export const NOTES_FLOOR = 'v0.65.0';
* the reader recognises anyway.
*/
export const NOTED = {
+ 'feat(physics3d): a box, sphere or capsule collider can sit off its entity origin (center), and the Cocos BoxCollider centre maps onto it':
+ {"note":"A 3D collider can sit off its entity."},
'feat(text): Text can underline its lines and grow its box to its text (ResizeHeight), and the Cocos Label maps onto both':
{"note":"Text can underline, and a box can grow to its text."},
'feat(cocos): a project effect is judged by its fragment stage and the features a material switches on, and a sprite-stencil mask maps to the engine stencil mask':