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.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
feat(physics3d): RagdollJoint gives a bone no body or limits of its own; the ragdoll plan is shared with the editor, which draws it
yhh8a357b315085
diff --git a/desktop b/desktopindex 840d5a5d6..6a6b62b26 160000--- a/desktop+++ b/desktop@@ -1 +1 @@-Subproject commit 840d5a5d6ca5a04a84714709580953803d41abd0+Subproject commit 6a6b62b26c950c2ad2e30ea61b74cc92129c0cb4diff --git a/pipeline/src/project/targetSupport.ts b/pipeline/src/project/targetSupport.tsindex 4d0be7e9a..e8d9b707e 100644--- a/pipeline/src/project/targetSupport.ts+++ b/pipeline/src/project/targetSupport.ts@@ -61,7 +61,7 @@ export const SUBSYSTEM_COMPONENTS: Readonly<Record<Subsystem, readonly string[]>physics3d: ['RigidBody3D', 'BoxCollider3D', 'SphereCollider3D', 'CapsuleCollider3D','MeshCollider3D', 'ConvexCollider3D', 'CharacterController3D',- 'HingeJoint3D', 'DistanceJoint3D', 'SliderJoint3D', 'FixedJoint3D', 'PointJoint3D', 'SwingTwistJoint3D', 'SixDOFJoint3D', 'Ragdoll',+ 'HingeJoint3D', 'DistanceJoint3D', 'SliderJoint3D', 'FixedJoint3D', 'PointJoint3D', 'SwingTwistJoint3D', 'SixDOFJoint3D', 'Ragdoll', 'RagdollJoint',],spine: ['SpineAnimation'],dragonbones: ['DragonBonesAnimation'],diff --git a/sdk/etc/index.api.md b/sdk/etc/index.api.mdindex 07c601b01..1c538dddc 100644--- a/sdk/etc/index.api.md+++ b/sdk/etc/index.api.md@@ -1,7 +1,7 @@# API surface — esengine/index<!-- Generated by tools/api-surface.mjs — do not edit. Run --update to accept changes. -->-Symbols: 115 public · 161 beta · 1987 experimental · 3 deprecated+Symbols: 115 public · 161 beta · 1998 experimental · 3 deprecated## ABI_LAYOUT_HASH — const @experimental```@@ -1413,6 +1413,11 @@ type: number | undefined{ atlasSize: number; texelsPerUnit: number; bounces: number; samples: number; ambient: readonly [number, number, number]; dilate: number; probeGrids: readonly ProbeGrid[]; probeSamples: number; reflectionProbes: readonly (readonly [number, number, number])[]; reflectionWidth: number; }```+## BONE_LIMITS — const @experimental+```+Readonly<Record<BoneClass, { swing: number; twist: number; }>>+```+## BUILTIN_AUDIO_BUSES — const @experimental```readonly [{ readonly name: "master"; readonly parent: null; readonly volume: 1; }, { readonly name: "music"; readonly parent: "master"; readonly volume: 0.8; }, { readonly name: "sfx"; readonly parent: "master"; readonly volume: 1; }, { readonly name: "ui"; readonly parent: "master"; readonly volume: 1; }, { readonly name: "voice"; readonly parent: "master"; readonly volume: 1; }]@@ -1798,6 +1803,11 @@ Kinematic = 1Static = 0```+## BoneClass — type @experimental+```+'spine' | 'neck' | 'head' | 'shoulder' | 'upperArm' | 'forearm' | 'hand' | 'thigh' | 'shin' | 'foot' | 'toe' | 'other'+```+## BoxCollider2D — const @experimental```BuiltinComponentDef<BoxCollider2DData>@@ -8113,6 +8123,58 @@ ReadonlySet<string>Readonly<Required<RuntimeBuildConfig>>```+## Ragdoll — const @experimental+```+ComponentDef<RagdollData>+```++## RagdollData — interface @experimental+```+active: boolean+bend: number+facing: number+friction: number+minBoneLength: number+profile: number+recoverTime: number+skin: number+swing: number+thickness: number+twist: number+```++## RagdollFacing — const @experimental+```+{ readonly PlusZ: 0; readonly MinusZ: 1; readonly PlusX: 2; readonly MinusX: 3; }+```++## RagdollJoint — const @experimental+```+ComponentDef<RagdollJointData>+```++## RagdollJointData — interface @experimental+```+bend: number+body: boolean+custom: boolean+fold: number+swing: number+twist: number+```++## RagdollPlan — interface @experimental+```+bones: number[]+limbs: { limb: RagdollLimb; joint: { kind: "swingTwist"; data: SwingTwistJoint3DData; } | { kind: "sixDOF"; data: SixDOFJoint3DData; } | null; }[]+skin: number+```++## RagdollProfile — const @experimental+```+{ readonly Uniform: 0; readonly Humanoid: 1; }+```+## RainShelter — const @experimental```ComponentDef<RainShelterData>@@ -13790,6 +13852,11 @@ MotionDriver<AnimatorBlend2DMotion>(cx: number, cy: number, radius: number, segments?: number, startAngle?: number, endAngle?: number): Vec2[]```+## classifyBone — function @experimental+```+(name: string | undefined): BoneClass+```+## clearAnimatorControllerStore — function @experimental```(): void@@ -15885,6 +15952,11 @@ PrefabsPlugin(rz: number, rw: number): number```+## ragdollPlan — function @experimental+```+(world: World, entity: Entity, data: RagdollData): RagdollPlan | null+```+## rankPickCandidates — function @experimental```<T>(candidates: ReadonlyArray<PickCandidate<T>>): T[]diff --git a/sdk/etc/index.native.api.md b/sdk/etc/index.native.api.mdindex 5fc572aab..6657a153b 100644--- a/sdk/etc/index.native.api.md+++ b/sdk/etc/index.native.api.md@@ -1,7 +1,7 @@# API surface — esengine/index.native<!-- Generated by tools/api-surface.mjs — do not edit. Run --update to accept changes. -->-Symbols: 115 public · 166 beta · 2006 experimental · 3 deprecated+Symbols: 115 public · 166 beta · 2017 experimental · 3 deprecated## ABI_LAYOUT_HASH — const @experimental```@@ -1413,6 +1413,11 @@ type: number | undefined{ atlasSize: number; texelsPerUnit: number; bounces: number; samples: number; ambient: readonly [number, number, number]; dilate: number; probeGrids: readonly ProbeGrid[]; probeSamples: number; reflectionProbes: readonly (readonly [number, number, number])[]; reflectionWidth: number; }```+## BONE_LIMITS — const @experimental+```+Readonly<Record<BoneClass, { swing: number; twist: number; }>>+```+## BUILTIN_AUDIO_BUSES — const @experimental```readonly [{ readonly name: "master"; readonly parent: null; readonly volume: 1; }, { readonly name: "music"; readonly parent: "master"; readonly volume: 0.8; }, { readonly name: "sfx"; readonly parent: "master"; readonly volume: 1; }, { readonly name: "ui"; readonly parent: "master"; readonly volume: 1; }, { readonly name: "voice"; readonly parent: "master"; readonly volume: 1; }]@@ -1798,6 +1803,11 @@ Kinematic = 1Static = 0```+## BoneClass — type @experimental+```+'spine' | 'neck' | 'head' | 'shoulder' | 'upperArm' | 'forearm' | 'hand' | 'thigh' | 'shin' | 'foot' | 'toe' | 'other'+```+## BoxCollider2D — const @experimental```BuiltinComponentDef<BoxCollider2DData>@@ -8326,6 +8336,58 @@ ReadonlySet<string>Readonly<Required<RuntimeBuildConfig>>```+## Ragdoll — const @experimental+```+ComponentDef<RagdollData>+```++## RagdollData — interface @experimental+```+active: boolean+bend: number+facing: number+friction: number+minBoneLength: number+profile: number+recoverTime: number+skin: number+swing: number+thickness: number+twist: number+```++## RagdollFacing — const @experimental+```+{ readonly PlusZ: 0; readonly MinusZ: 1; readonly PlusX: 2; readonly MinusX: 3; }+```++## RagdollJoint — const @experimental+```+ComponentDef<RagdollJointData>+```++## RagdollJointData — interface @experimental+```+bend: number+body: boolean+custom: boolean+fold: number+swing: number+twist: number+```++## RagdollPlan — interface @experimental+```+bones: number[]+limbs: { limb: RagdollLimb; joint: { kind: "swingTwist"; data: SwingTwistJoint3DData; } | { kind: "sixDOF"; data: SixDOFJoint3DData; } | null; }[]+skin: number+```++## RagdollProfile — const @experimental+```+{ readonly Uniform: 0; readonly Humanoid: 1; }+```+## RainShelter — const @experimental```ComponentDef<RainShelterData>@@ -14018,6 +14080,11 @@ MotionDriver<AnimatorBlend2DMotion>(cx: number, cy: number, radius: number, segments?: number, startAngle?: number, endAngle?: number): Vec2[]```+## classifyBone — function @experimental+```+(name: string | undefined): BoneClass+```+## clearAnimatorControllerStore — function @experimental```(): void@@ -16148,6 +16215,11 @@ PrefabsPlugin(rz: number, rw: number): number```+## ragdollPlan — function @experimental+```+(world: World, entity: Entity, data: RagdollData): RagdollPlan | null+```+## rankPickCandidates — function @experimental```<T>(candidates: ReadonlyArray<PickCandidate<T>>): T[]diff --git a/sdk/etc/index.node.api.md b/sdk/etc/index.node.api.mdindex 80c4f3477..e2fc03a8e 100644--- a/sdk/etc/index.node.api.md+++ b/sdk/etc/index.node.api.md@@ -1,7 +1,7 @@# API surface — esengine/index.node<!-- Generated by tools/api-surface.mjs — do not edit. Run --update to accept changes. -->-Symbols: 115 public · 163 beta · 1986 experimental · 3 deprecated+Symbols: 115 public · 163 beta · 1997 experimental · 3 deprecated## ANCHOR_AXES — const @experimental```@@ -1408,6 +1408,11 @@ type: number | undefined{ atlasSize: number; texelsPerUnit: number; bounces: number; samples: number; ambient: readonly [number, number, number]; dilate: number; probeGrids: readonly ProbeGrid[]; probeSamples: number; reflectionProbes: readonly (readonly [number, number, number])[]; reflectionWidth: number; }```+## BONE_LIMITS — const @experimental+```+Readonly<Record<BoneClass, { swing: number; twist: number; }>>+```+## BUILTIN_AUDIO_BUSES — const @experimental```readonly [{ readonly name: "master"; readonly parent: null; readonly volume: 1; }, { readonly name: "music"; readonly parent: "master"; readonly volume: 0.8; }, { readonly name: "sfx"; readonly parent: "master"; readonly volume: 1; }, { readonly name: "ui"; readonly parent: "master"; readonly volume: 1; }, { readonly name: "voice"; readonly parent: "master"; readonly volume: 1; }]@@ -1793,6 +1798,11 @@ Kinematic = 1Static = 0```+## BoneClass — type @experimental+```+'spine' | 'neck' | 'head' | 'shoulder' | 'upperArm' | 'forearm' | 'hand' | 'thigh' | 'shin' | 'foot' | 'toe' | 'other'+```+## BoxCollider2D — const @experimental```BuiltinComponentDef<BoxCollider2DData>@@ -8108,6 +8118,58 @@ ReadonlySet<string>Readonly<Required<RuntimeBuildConfig>>```+## Ragdoll — const @experimental+```+ComponentDef<RagdollData>+```++## RagdollData — interface @experimental+```+active: boolean+bend: number+facing: number+friction: number+minBoneLength: number+profile: number+recoverTime: number+skin: number+swing: number+thickness: number+twist: number+```++## RagdollFacing — const @experimental+```+{ readonly PlusZ: 0; readonly MinusZ: 1; readonly PlusX: 2; readonly MinusX: 3; }+```++## RagdollJoint — const @experimental+```+ComponentDef<RagdollJointData>+```++## RagdollJointData — interface @experimental+```+bend: number+body: boolean+custom: boolean+fold: number+swing: number+twist: number+```++## RagdollPlan — interface @experimental+```+bones: number[]+limbs: { limb: RagdollLimb; joint: { kind: "swingTwist"; data: SwingTwistJoint3DData; } | { kind: "sixDOF"; data: SixDOFJoint3DData; } | null; }[]+skin: number+```++## RagdollProfile — const @experimental+```+{ readonly Uniform: 0; readonly Humanoid: 1; }+```+## RainShelter — const @experimental```ComponentDef<RainShelterData>@@ -13785,6 +13847,11 @@ MotionDriver<AnimatorBlend2DMotion>(cx: number, cy: number, radius: number, segments?: number, startAngle?: number, endAngle?: number): Vec2[]```+## classifyBone — function @experimental+```+(name: string | undefined): BoneClass+```+## clearAnimatorControllerStore — function @experimental```(): void@@ -15890,6 +15957,11 @@ PrefabsPlugin(rz: number, rw: number): number```+## ragdollPlan — function @experimental+```+(world: World, entity: Entity, data: RagdollData): RagdollPlan | null+```+## rankPickCandidates — function @experimental```<T>(candidates: ReadonlyArray<PickCandidate<T>>): T[]diff --git a/sdk/etc/minigame.api.md b/sdk/etc/minigame.api.mdindex e643219dc..1eed741e1 100644--- a/sdk/etc/minigame.api.md+++ b/sdk/etc/minigame.api.md@@ -1,7 +1,7 @@# API surface — esengine/minigame<!-- Generated by tools/api-surface.mjs — do not edit. Run --update to accept changes. -->-Symbols: 115 public · 161 beta · 2008 experimental · 3 deprecated+Symbols: 115 public · 161 beta · 2019 experimental · 3 deprecated## ANCHOR_AXES — const @experimental```@@ -1408,6 +1408,11 @@ type: number | undefined{ atlasSize: number; texelsPerUnit: number; bounces: number; samples: number; ambient: readonly [number, number, number]; dilate: number; probeGrids: readonly ProbeGrid[]; probeSamples: number; reflectionProbes: readonly (readonly [number, number, number])[]; reflectionWidth: number; }```+## BONE_LIMITS — const @experimental+```+Readonly<Record<BoneClass, { swing: number; twist: number; }>>+```+## BUILTIN_AUDIO_BUSES — const @experimental```readonly [{ readonly name: "master"; readonly parent: null; readonly volume: 1; }, { readonly name: "music"; readonly parent: "master"; readonly volume: 0.8; }, { readonly name: "sfx"; readonly parent: "master"; readonly volume: 1; }, { readonly name: "ui"; readonly parent: "master"; readonly volume: 1; }, { readonly name: "voice"; readonly parent: "master"; readonly volume: 1; }]@@ -1793,6 +1798,11 @@ Kinematic = 1Static = 0```+## BoneClass — type @experimental+```+'spine' | 'neck' | 'head' | 'shoulder' | 'upperArm' | 'forearm' | 'hand' | 'thigh' | 'shin' | 'foot' | 'toe' | 'other'+```+## BoxCollider2D — const @experimental```BuiltinComponentDef<BoxCollider2DData>@@ -8403,6 +8413,58 @@ ReadonlySet<string>Readonly<Required<RuntimeBuildConfig>>```+## Ragdoll — const @experimental+```+ComponentDef<RagdollData>+```++## RagdollData — interface @experimental+```+active: boolean+bend: number+facing: number+friction: number+minBoneLength: number+profile: number+recoverTime: number+skin: number+swing: number+thickness: number+twist: number+```++## RagdollFacing — const @experimental+```+{ readonly PlusZ: 0; readonly MinusZ: 1; readonly PlusX: 2; readonly MinusX: 3; }+```++## RagdollJoint — const @experimental+```+ComponentDef<RagdollJointData>+```++## RagdollJointData — interface @experimental+```+bend: number+body: boolean+custom: boolean+fold: number+swing: number+twist: number+```++## RagdollPlan — interface @experimental+```+bones: number[]+limbs: { limb: RagdollLimb; joint: { kind: "swingTwist"; data: SwingTwistJoint3DData; } | { kind: "sixDOF"; data: SixDOFJoint3DData; } | null; }[]+skin: number+```++## RagdollProfile — const @experimental+```+{ readonly Uniform: 0; readonly Humanoid: 1; }+```+## RainShelter — const @experimental```ComponentDef<RainShelterData>@@ -14086,6 +14148,11 @@ MotionDriver<AnimatorBlend2DMotion>(cx: number, cy: number, radius: number, segments?: number, startAngle?: number, endAngle?: number): Vec2[]```+## classifyBone — function @experimental+```+(name: string | undefined): BoneClass+```+## clearAnimatorControllerStore — function @experimental```(): void@@ -16196,6 +16263,11 @@ PrefabsPlugin(rz: number, rw: number): number```+## ragdollPlan — function @experimental+```+(world: World, entity: Entity, data: RagdollData): RagdollPlan | null+```+## rankPickCandidates — function @experimental```<T>(candidates: ReadonlyArray<PickCandidate<T>>): T[]diff --git a/sdk/etc/physics3d.api.md b/sdk/etc/physics3d.api.mdindex 197f7eb53..c6c7a367f 100644--- a/sdk/etc/physics3d.api.md+++ b/sdk/etc/physics3d.api.md@@ -1,7 +1,7 @@# API surface — esengine/physics3d<!-- Generated by tools/api-surface.mjs — do not edit. Run --update to accept changes. -->-Symbols: 0 public · 0 beta · 74 experimental · 0 deprecated+Symbols: 0 public · 0 beta · 78 experimental · 0 deprecated## BONE_LIMITS — const @experimental```@@ -384,6 +384,7 @@ ComponentDef<RagdollData>```id: numbername: string | undefined+override: { body?: boolean; swing?: number; twist?: number; bend?: number; fold?: number; } | undefinedparent: number | nullposition: Vec3rotation: Quat@@ -409,6 +410,21 @@ twist: number{ readonly PlusZ: 0; readonly MinusZ: 1; readonly PlusX: 2; readonly MinusX: 3; }```+## RagdollJoint — const @experimental+```+ComponentDef<RagdollJointData>+```++## RagdollJointData — interface @experimental+```+bend: number+body: boolean+custom: boolean+fold: number+swing: number+twist: number+```+## RagdollLimb — interface @experimental```axis: Vec3@@ -419,7 +435,16 @@ halfExtents: Vec3hinge: { axis: Vec3; normalAxis: Vec3; lower: number; upper: number; } | undefinednormalAxis: Vec3swing: number+swingDeg: number | undefinedtwist: number+twistDeg: number | undefined+```++## RagdollPlan — interface @experimental+```+bones: number[]+limbs: { limb: RagdollLimb; joint: { kind: "swingTwist"; data: SwingTwistJoint3DData; } | { kind: "sixDOF"; data: SixDOFJoint3DData; } | null; }[]+skin: number```## RagdollProfile — const @experimental@@ -584,6 +609,11 @@ twistMinAngle: number(bones: readonly RagdollBone[], options: { thickness: number; minBoneLength: number; profile?: number; bend?: number; forward?: Vec3; }): RagdollLimb[]```+## ragdollPlan — function @experimental+```+(world: World, entity: Entity, data: RagdollData): RagdollPlan | null+```+## readCollider3DShapes — function @experimental```(world: World, entity: number): Collider3DInstance[]diff --git a/sdk/etc/wechat.api.md b/sdk/etc/wechat.api.mdindex f6ced4113..1dbe29294 100644--- a/sdk/etc/wechat.api.md+++ b/sdk/etc/wechat.api.md@@ -1,7 +1,7 @@# API surface — esengine/wechat<!-- Generated by tools/api-surface.mjs — do not edit. Run --update to accept changes. -->-Symbols: 115 public · 161 beta · 1999 experimental · 3 deprecated+Symbols: 115 public · 161 beta · 2010 experimental · 3 deprecated## ANCHOR_AXES — const @experimental```@@ -1408,6 +1408,11 @@ type: number | undefined{ atlasSize: number; texelsPerUnit: number; bounces: number; samples: number; ambient: readonly [number, number, number]; dilate: number; probeGrids: readonly ProbeGrid[]; probeSamples: number; reflectionProbes: readonly (readonly [number, number, number])[]; reflectionWidth: number; }```+## BONE_LIMITS — const @experimental+```+Readonly<Record<BoneClass, { swing: number; twist: number; }>>+```+## BUILTIN_AUDIO_BUSES — const @experimental```readonly [{ readonly name: "master"; readonly parent: null; readonly volume: 1; }, { readonly name: "music"; readonly parent: "master"; readonly volume: 0.8; }, { readonly name: "sfx"; readonly parent: "master"; readonly volume: 1; }, { readonly name: "ui"; readonly parent: "master"; readonly volume: 1; }, { readonly name: "voice"; readonly parent: "master"; readonly volume: 1; }]@@ -1793,6 +1798,11 @@ Kinematic = 1Static = 0```+## BoneClass — type @experimental+```+'spine' | 'neck' | 'head' | 'shoulder' | 'upperArm' | 'forearm' | 'hand' | 'thigh' | 'shin' | 'foot' | 'toe' | 'other'+```+## BoxCollider2D — const @experimental```BuiltinComponentDef<BoxCollider2DData>@@ -8115,6 +8125,58 @@ ReadonlySet<string>Readonly<Required<RuntimeBuildConfig>>```+## Ragdoll — const @experimental+```+ComponentDef<RagdollData>+```++## RagdollData — interface @experimental+```+active: boolean+bend: number+facing: number+friction: number+minBoneLength: number+profile: number+recoverTime: number+skin: number+swing: number+thickness: number+twist: number+```++## RagdollFacing — const @experimental+```+{ readonly PlusZ: 0; readonly MinusZ: 1; readonly PlusX: 2; readonly MinusX: 3; }+```++## RagdollJoint — const @experimental+```+ComponentDef<RagdollJointData>+```++## RagdollJointData — interface @experimental+```+bend: number+body: boolean+custom: boolean+fold: number+swing: number+twist: number+```++## RagdollPlan — interface @experimental+```+bones: number[]+limbs: { limb: RagdollLimb; joint: { kind: "swingTwist"; data: SwingTwistJoint3DData; } | { kind: "sixDOF"; data: SixDOFJoint3DData; } | null; }[]+skin: number+```++## RagdollProfile — const @experimental+```+{ readonly Uniform: 0; readonly Humanoid: 1; }+```+## RainShelter — const @experimental```ComponentDef<RainShelterData>@@ -13817,6 +13879,11 @@ MotionDriver<AnimatorBlend2DMotion>(cx: number, cy: number, radius: number, segments?: number, startAngle?: number, endAngle?: number): Vec2[]```+## classifyBone — function @experimental+```+(name: string | undefined): BoneClass+```+## clearAnimatorControllerStore — function @experimental```(): void@@ -15922,6 +15989,11 @@ PrefabsPlugin(rz: number, rw: number): number```+## ragdollPlan — function @experimental+```+(world: World, entity: Entity, data: RagdollData): RagdollPlan | null+```+## rankPickCandidates — function @experimental```<T>(candidates: ReadonlyArray<PickCandidate<T>>): T[]diff --git a/sdk/src/core-runtime.ts b/sdk/src/core-runtime.tsindex 0c270ca57..101b01a63 100644--- a/sdk/src/core-runtime.ts+++ b/sdk/src/core-runtime.ts@@ -257,6 +257,10 @@ export {readJoint3D,type Joint3DShape,} from './physics3d/Physics3DJoints';+export {+ Ragdoll, RagdollJoint, RagdollProfile, RagdollFacing, ragdollPlan, classifyBone, BONE_LIMITS,+ type RagdollData, type RagdollJointData, type RagdollPlan, type BoneClass,+} from './physics3d/ragdoll';export {Physics3DDebugDraw,diff --git a/sdk/src/physics3d/index.ts b/sdk/src/physics3d/index.tsindex 65de03565..48ea7de50 100644--- a/sdk/src/physics3d/index.ts+++ b/sdk/src/physics3d/index.ts@@ -107,6 +107,6 @@ export {// Importing this subpath INSTALLS 3D physics — see spine/index.ts.import { registerPhysics3DSupport } from './physics3dSupport';-export { Ragdoll, RagdollProfile, RagdollFacing, classifyBone, BONE_LIMITS, planRagdoll, type BoneClass, type RagdollData, type RagdollBone, type RagdollLimb } from './ragdoll';+export { Ragdoll, RagdollJoint, ragdollPlan, RagdollProfile, RagdollFacing, classifyBone, BONE_LIMITS, planRagdoll, type BoneClass, type RagdollJointData, type RagdollPlan, type RagdollData, type RagdollBone, type RagdollLimb } from './ragdoll';registerPhysics3DSupport();diff --git a/sdk/src/physics3d/ragdoll.ts b/sdk/src/physics3d/ragdoll.tsindex fa455fbde..cf311f979 100644--- a/sdk/src/physics3d/ragdoll.ts+++ b/sdk/src/physics3d/ragdoll.ts@@ -16,6 +16,7 @@*/import type { App } from '../app/app';import type { Entity, Quat, Vec3 } from '../types';+import type { World } from '../ecs/world';import { defineSystem, Schedule } from '../ecs/system';import { Res, Time, type TimeData } from '../ecs/resource';import { playModeOnly } from '../ecs/env';@@ -25,7 +26,7 @@ import { q } from '../math/quat';import { log } from '../util/logger';import { v3 } from '../math/vec3';import { RigidBody3D, BoxCollider3D } from './Physics3DComponents';-import { SwingTwistJoint3D, SixDOFJoint3D, JointMotion3D } from './AdvancedJoint3D';+import { SwingTwistJoint3D, SixDOFJoint3D, JointMotion3D, type SwingTwistJoint3DData, type SixDOFJoint3DData } from './AdvancedJoint3D';/** How a ragdoll's joints are limited. */export const RagdollProfile = {@@ -87,11 +88,47 @@ export const Ragdoll: ComponentDef<RagdollData> = defineComponent<RagdollData>('},});+/** The fields of the `RagdollJoint` component. @experimental */+export interface RagdollJointData {+ /** Whether this bone gets a body of its own. Off, the bone above carries it. */+ body: boolean;+ /** Whether the limits below stand in for the ones the profile would give this joint. */+ custom: boolean;+ /** How far the limb may swing from its bone's line, in degrees, either way. */+ swing: number;+ /** How far the limb may twist about its own line, in degrees, either way. */+ twist: number;+ /** How far it may bend, in degrees, one way only (a knee, an elbow). 0 is an ordinary swing and twist joint. */+ bend: number;+ /** Which way a bend goes where the bone's name does not say: 0 as its name says (a shin back, a forearm forward), 1 toward the way the character faces, -1 away from it. */+ fold: number;+}++/**+ * What the author says of one bone of a ragdoll: that it gets no body, or limits of its own. Put it on the bone's entity.+ *+ * @experimental+ */+export const RagdollJoint: ComponentDef<RagdollJointData> = defineComponent<RagdollJointData>('RagdollJoint', {+ body: true, custom: false, swing: 70, twist: 40, bend: 0, fold: 0,+}, {+ fields: {+ body: { category: 'Ragdoll', tooltip: 'Whether this bone gets a body of its own. Off, the bone above carries it.' },+ custom: { category: 'Limits', tooltip: 'Use the limits below instead of the ones the ragdoll\'s profile gives this joint.' },+ swing: { min: 0, max: 175, category: 'Limits', tooltip: 'How far the limb may swing from its bone\'s line, in degrees, either way.', shownWhen: { field: 'custom', values: [1] } },+ twist: { min: 0, max: 175, category: 'Limits', tooltip: 'How far the limb may twist about its own line, in degrees, either way.', shownWhen: { field: 'custom', values: [1] } },+ bend: { min: 0, max: 175, category: 'Limits', tooltip: 'How far it may bend, in degrees, one way only (a knee, an elbow). 0 is an ordinary swing and twist joint.', shownWhen: { field: 'custom', values: [1] } },+ fold: { enum: [{ label: 'As its name says', value: 0 }, { label: 'Toward the facing', value: 1 }, { label: 'Away from the facing', value: -1 }], category: 'Limits', tooltip: 'Which way a bend goes where the bone\'s name does not say.', shownWhen: { field: 'custom', values: [1] } },+ },+});+/** A bone as the plan reads it: where it is in the world, and the nearest bone above it. */export interface RagdollBone {id: number;/** What the bone is called, which is how the humanoid profile tells a knee from a shoulder. */name?: string;+ /** What the author said of this bone in a {@link RagdollJoint}: no body, or limits of its own, in degrees. */+ override?: { body?: boolean; swing?: number; twist?: number; bend?: number; fold?: number };parent: number | null;position: Vec3;rotation: Quat;@@ -110,6 +147,9 @@ export interface RagdollLimb {/** The share (0 to 1) of the component's swing and twist this joint gets. */swing: number;twist: number;+ /** Limits the author gave this bone in degrees, which stand in for the share of the component's. */+ swingDeg?: number;+ twistDeg?: number;/*** Set where the joint is a one-way hinge (a knee, an elbow): the hinge axis and a reference perpendicular to it, in this bone's own frame, and* how far the bone may turn about it either way from the pose it is in when the joint is made, in radians (the lower is at most 0, the upper at least 0).@@ -198,6 +238,8 @@ export function planRagdoll(bones: readonly RagdollBone[], options: { thickness:for (const r of roots) visit(r);for (const bone of order) {+ // A bone the author gave no body is carried by the one above, as a bone too short for one is.+ if (bone.override?.body === false) continue;// Where the bone points: at its longest child, else on along the line its parent came in by.let target: Vec3 | null = null, length = 0;for (const c of children.get(bone.id) ?? []) {@@ -237,8 +279,13 @@ export function planRagdoll(bones: readonly RagdollBone[], options: { thickness:// A knee folds back and an elbow folds forward, from the straight line the bone above makes: the hinge is across that line and the way the character faces, and what it may do// is measured from the pose it is in now, so the allowance is the bend left and the extension it already has.const kind = classifyBone(bone.name);- if (options.profile !== RagdollProfile.Uniform && options.bend && options.bend > 0 && options.forward && above && (kind === 'shin' || kind === 'forearm')) {- const hinge = hingeFor(bone, above, target, kind === 'shin' ? -1 : 1, options.forward, (options.bend * Math.PI) / 180);+ const ov = bone.override;+ if (ov?.swing !== undefined) limb.swingDeg = ov.swing;+ if (ov?.twist !== undefined) limb.twistDeg = ov.twist;+ const bend = ov?.bend ?? (options.profile !== RagdollProfile.Uniform ? options.bend : 0) ?? 0;+ const side = ov?.fold ? (ov.fold > 0 ? 1 : -1) : kind === 'shin' ? -1 : kind === 'forearm' ? 1 : 0;+ if (bend > 0 && side !== 0 && options.forward && above) {+ const hinge = hingeFor(bone, above, target, side as 1 | -1, options.forward, (bend * Math.PI) / 180);if (hinge) limb.hinge = hinge;}limbs.push(limb);@@ -294,6 +341,98 @@ function nlerp(a: Quat, b: Quat, t: number): Quat {return q.normalize({ w: a.w + (s * b.w - a.w) * t, x: a.x + (s * b.x - a.x) * t, y: a.y + (s * b.y - a.y) * t, z: a.z + (s * b.z - a.z) * t });}+/** What a ragdoll is made of: the skeleton it reads, and what each limb gets (a body, and a joint to the limb above). */+export interface RagdollPlan {+ skin: Entity;+ bones: Entity[];+ limbs: Array<{+ limb: RagdollLimb;+ /** The joint it is given: swing and twist, or a one-way hinge as a six-axis joint. Absent for the topmost limb. */+ joint: { kind: 'swingTwist'; data: SwingTwistJoint3DData } | { kind: 'sixDOF'; data: SixDOFJoint3DData } | null;+ }>;+}++/** The skinned mesh a ragdoll reads its skeleton from: the entity named, or this one, or the first thing below it that is skinned. */+function skinOf(world: World, entity: Entity, data: RagdollData): { skin: Entity; joints: Entity[] } | null {+ // By name: the skin's joints are a variable-length list the component table has no layout for.+ const skinDef = getComponent('MeshSkin');+ if (!skinDef) return null;+ let skin: Entity | null = null;+ if (data.skin > 0 && world.valid(data.skin as Entity) && world.has(data.skin as Entity, skinDef)) skin = data.skin as Entity;+ const queue: Entity[] = data.skin > 0 ? [] : [entity];+ for (let i = 0; skin === null && i < queue.length && i < 4096; i++) {+ const e = queue[i]!;+ if (!world.valid(e)) continue;+ if (world.has(e, skinDef)) { skin = e; break; }+ if (world.has(e, Children)) queue.push(...(world.get(e, Children) as ChildrenData).entities);+ }+ if (skin === null) return null;+ const joints = (world.get(skin, skinDef) as MeshSkinData).joints.filter((j) => world.valid(j) && world.has(j, Transform));+ return joints.length > 0 ? { skin, joints } : null;+}++/**+ * What `entity`'s ragdoll would be made of from the pose its skeleton is in now: the same answer the ragdoll builds its bodies from, so the editor can draw it before anything runs.+ * Null where there is no skinned mesh to read.+ *+ * @experimental+ */+export function ragdollPlan(world: World, entity: Entity, data: RagdollData): RagdollPlan | null {+ const rig = skinOf(world, entity, data);+ if (!rig) return null;+ world.ensureTransformsComposed();+ const set = new Set<number>(rig.joints as number[]);+ const nearestBone = (e: Entity): number | null => {+ let p = world.has(e, Parent) ? (world.get(e, Parent) as ParentData).entity : undefined;+ for (let guard = 0; p !== undefined && world.valid(p) && guard < 256; guard++) {+ if (set.has(p)) return p as number;+ p = world.has(p, Parent) ? (world.get(p, Parent) as ParentData).entity : undefined;+ }+ return null;+ };+ const bones: RagdollBone[] = rig.joints.map((j) => {+ const t = world.get(j, Transform) as TransformData;+ const mark = world.has(j, RagdollJoint) ? world.get(j, RagdollJoint) as RagdollJointData : null;+ return {+ id: j as number, parent: nearestBone(j),+ name: world.has(j, Name) ? (world.get(j, Name) as { value: string }).value : undefined,+ position: { x: t.worldPosition.x, y: t.worldPosition.y, z: t.worldPosition.z },+ rotation: { w: t.worldRotation.w, x: t.worldRotation.x, y: t.worldRotation.y, z: t.worldRotation.z },+ ...(mark ? { override: { body: mark.body, fold: mark.fold, ...(mark.custom ? { swing: mark.swing, twist: mark.twist, bend: mark.bend } : {}) } } : {}),+ };+ });+ const facing = [{ x: 0, y: 0, z: 1 }, { x: 0, y: 0, z: -1 }, { x: 1, y: 0, z: 0 }, { x: -1, y: 0, z: 0 }][data.facing] ?? { x: 0, y: 0, z: 1 };+ const rootT = world.get(entity, Transform) as TransformData;+ const forward = q.rotate({ w: rootT.worldRotation.w, x: rootT.worldRotation.x, y: rootT.worldRotation.y, z: rootT.worldRotation.z }, facing);+ const limbs = planRagdoll(bones, { thickness: data.thickness, minBoneLength: data.minBoneLength, profile: data.profile, bend: data.bend, forward });+ const rad = (deg: number): number => (Math.min(Math.max(deg, 0), 175) * Math.PI) / 180;+ const none = { x: 0, y: 0, z: 0 };+ return {+ skin: rig.skin, bones: rig.joints,+ limbs: limbs.map((limb) => {+ if (limb.connected === null) return { limb, joint: null };+ if (limb.hinge) {+ // The joint is made on this bone and names the bone above, so the rotation it limits is the bone above's relative to this one: the hinge's turn, the other way round.+ const h = limb.hinge;+ return { limb, joint: { kind: 'sixDOF' as const, data: {+ connectedEntity: limb.connected, anchor: none, axis: h.axis, normalAxis: h.normalAxis,+ enableMotor: false, angularVelocity: none, maxMotorTorque: 10, collideConnected: false, enabled: true,+ translationMotion: none, rotationMotion: { x: JointMotion3D.Limited, y: JointMotion3D.Locked, z: JointMotion3D.Locked },+ translationLower: none, translationUpper: none,+ rotationLower: { x: -h.upper, y: 0, z: 0 }, rotationUpper: { x: -h.lower, y: 0, z: 0 },+ linearVelocity: none, maxMotorForce: 0,+ } } };+ }+ const swing = rad(limb.swingDeg ?? data.swing * limb.swing), twist = rad(limb.twistDeg ?? data.twist * limb.twist);+ return { limb, joint: { kind: 'swingTwist' as const, data: {+ connectedEntity: limb.connected, anchor: none, axis: limb.axis, normalAxis: limb.normalAxis,+ enableMotor: false, angularVelocity: none, maxMotorTorque: 10, collideConnected: false, enabled: true,+ normalHalfConeAngle: swing, planeHalfConeAngle: swing, twistMinAngle: -twist, twistMaxAngle: twist,+ } } };+ }),+ };+}+/*** Installs the systems that turn a `Ragdoll`'s switch into bodies and back. Called once by the 3D physics plugin.*@@ -307,25 +446,6 @@ export function installRagdolls(app: App): void {const recovering = new Map<Entity, Recovery>();const world = app.world;- const skeletonOf = (entity: Entity, data: RagdollData): { skin: Entity; joints: Entity[] } | null => {- // By name: the skin's joints are a variable-length list the component table has no layout for.- const skinDef = getComponent('MeshSkin');- if (!skinDef) return null;- // The named entity, or else this one, or else the first thing below it that is skinned (an imported character keeps its mesh on a child).- let skin: Entity | null = null;- if (data.skin > 0 && world.valid(data.skin as Entity) && world.has(data.skin as Entity, skinDef)) skin = data.skin as Entity;- const queue: Entity[] = data.skin > 0 ? [] : [entity];- for (let i = 0; skin === null && i < queue.length && i < 4096; i++) {- const e = queue[i]!;- if (!world.valid(e)) continue;- if (world.has(e, skinDef)) { skin = e; break; }- if (world.has(e, Children)) queue.push(...(world.get(e, Children) as ChildrenData).entities);- }- if (skin === null) return null;- const joints = (world.get(skin, skinDef) as MeshSkinData).joints.filter((j) => world.valid(j) && world.has(j, Transform));- return joints.length > 0 ? { skin, joints } : null;- };-const localPose = (bone: Entity): Pose => {const t = world.get(bone, Transform) as TransformData;return {@@ -342,62 +462,21 @@ export function installRagdolls(app: App): void {};const activate = (entity: Entity, data: RagdollData): void => {- const rig = skeletonOf(entity, data);- if (!rig) {+ const plan = ragdollPlan(world, entity, data);+ if (!plan) {log.warn('physics3d', `Ragdoll on entity ${entity} found no skinned mesh with joints on it or below it`);return;}- world.ensureTransformsComposed();- const set = new Set<number>(rig.joints as number[]);- const nearestBone = (e: Entity): number | null => {- let p = world.has(e, Parent) ? (world.get(e, Parent) as ParentData).entity : undefined;- for (let guard = 0; p !== undefined && world.valid(p) && guard < 256; guard++) {- if (set.has(p)) return p as number;- p = world.has(p, Parent) ? (world.get(p, Parent) as ParentData).entity : undefined;- }- return null;- };- const bones: RagdollBone[] = rig.joints.map((j) => {- const t = world.get(j, Transform) as TransformData;- return {- id: j as number, parent: nearestBone(j),- name: world.has(j, Name) ? (world.get(j, Name) as { value: string }).value : undefined,- position: { x: t.worldPosition.x, y: t.worldPosition.y, z: t.worldPosition.z },- rotation: { w: t.worldRotation.w, x: t.worldRotation.x, y: t.worldRotation.y, z: t.worldRotation.z },- };- });- const facing = [{ x: 0, y: 0, z: 1 }, { x: 0, y: 0, z: -1 }, { x: 1, y: 0, z: 0 }, { x: -1, y: 0, z: 0 }][data.facing] ?? { x: 0, y: 0, z: 1 };- const rootT = world.get(entity, Transform) as TransformData;- const forward = q.rotate({ w: rootT.worldRotation.w, x: rootT.worldRotation.x, y: rootT.worldRotation.y, z: rootT.worldRotation.z }, facing);- const limbs = planRagdoll(bones, { thickness: data.thickness, minBoneLength: data.minBoneLength, profile: data.profile, bend: data.bend, forward });- log.info('physics3d', `Ragdoll on entity ${entity}: ${limbs.length} limbs from ${bones.length} bones`);- const rad = (deg: number): number => (Math.min(Math.max(deg, 0), 175) * Math.PI) / 180;- for (const limb of limbs) {+ log.info('physics3d', `Ragdoll on entity ${entity}: ${plan.limbs.length} limbs from ${plan.bones.length} bones`);+ for (const { limb, joint } of plan.limbs) {const e = limb.entity as Entity;world.insert(e, RigidBody3D, { bodyType: 2, enabled: true });world.insert(e, BoxCollider3D, { halfExtents: limb.halfExtents, center: limb.center, friction: data.friction, restitution: 0, isSensor: false, enabled: true });- if (limb.connected !== null && limb.hinge) {- // The joint is made on this bone and names the bone above, so the rotation it limits is the bone above's relative to this one: the hinge's turn, the other way round.- const h = limb.hinge, none = { x: 0, y: 0, z: 0 };- world.insert(e, SixDOFJoint3D, {- connectedEntity: limb.connected, anchor: none, axis: h.axis, normalAxis: h.normalAxis,- enableMotor: false, angularVelocity: none, maxMotorTorque: 10, collideConnected: false, enabled: true,- translationMotion: none, rotationMotion: { x: JointMotion3D.Limited, y: JointMotion3D.Locked, z: JointMotion3D.Locked },- translationLower: none, translationUpper: none,- rotationLower: { x: -h.upper, y: 0, z: 0 }, rotationUpper: { x: -h.lower, y: 0, z: 0 },- linearVelocity: none, maxMotorForce: 0,- });- } else if (limb.connected !== null) {- world.insert(e, SwingTwistJoint3D, {- connectedEntity: limb.connected, anchor: { x: 0, y: 0, z: 0 }, axis: limb.axis, normalAxis: limb.normalAxis,- enableMotor: false, angularVelocity: { x: 0, y: 0, z: 0 }, maxMotorTorque: 10, collideConnected: false, enabled: true,- normalHalfConeAngle: rad(data.swing * limb.swing), planeHalfConeAngle: rad(data.swing * limb.swing),- twistMinAngle: -rad(data.twist * limb.twist), twistMaxAngle: rad(data.twist * limb.twist),- });- }+ if (joint?.kind === 'sixDOF') world.insert(e, SixDOFJoint3D, joint.data);+ else if (joint) world.insert(e, SwingTwistJoint3D, joint.data);}recovering.delete(entity);- limp.set(entity, { limbs: limbs.map((l) => l.entity as Entity), posed: new Map() });+ limp.set(entity, { limbs: plan.limbs.map((l) => l.limb.entity as Entity), posed: new Map() });};const deactivate = (entity: Entity, data: RagdollData): void => {diff --git a/sdk/tests/ragdoll.test.ts b/sdk/tests/ragdoll.test.tsindex e154861c3..d982e641c 100644--- a/sdk/tests/ragdoll.test.ts+++ b/sdk/tests/ragdoll.test.ts@@ -306,3 +306,38 @@ describe.skipIf(!HAS_SOLVER)('a knee under the real solver', () => {expect(r.foot).toBeGreaterThan(0.3);});});++describe('a bone the author has a say in', () => {+ const named = (id: number, parent: number | null, y: number, name: string, override?: RagdollBone['override']): RagdollBone => ({ ...bone(id, parent, 0, y), name, ...(override ? { override } : {}) });+ const forwardZ = { x: 0, y: 0, z: 1 };++ it('gets no body when it is told none, and the bone below is joined to the one above', () => {+ const limbs = planRagdoll([named(1, null, 0, 'DEF-hips'), named(2, 1, 1, 'DEF-spine.001', { body: false }), named(3, 2, 2, 'DEF-spine.002'), named(4, 3, 3, 'DEF-neck')], options);+ expect(limbs.some((l) => l.entity === 2)).toBe(false);+ expect(limbs.find((l) => l.entity === 3)!.connected).toBe(1);+ });++ it('is limited in the degrees it was given, not by its part of the body', () => {+ const limbs = planRagdoll([named(1, null, 0, 'DEF-hips'), named(2, 1, 1, 'DEF-spine.001', { swing: 12, twist: 7 }), named(3, 2, 2, 'DEF-neck')], options);+ const spine = limbs.find((l) => l.entity === 2)!;+ expect(spine.swingDeg).toBe(12);+ expect(spine.twistDeg).toBe(7);+ expect(limbs.find((l) => l.entity === 3)!.swingDeg).toBeUndefined();+ });++ it('is a one-way hinge where it is given a bend and a side, whatever it is called', () => {+ // A tail bone that folds toward the facing, 90 degrees.+ const chain = [named(1, null, 0, 'root'), named(2, 1, 1, 'tail_1'), named(3, 2, 2, 'tail_2', { bend: 90, fold: 1 }), named(4, 3, 3, 'tail_3')];+ const bent = planRagdoll(chain, { ...options, forward: forwardZ });+ expect(bent.find((l) => l.entity === 3)!.hinge).toBeDefined();+ const plain = planRagdoll(chain, { ...options, forward: forwardZ, bend: 130 });+ expect(plain.find((l) => l.entity === 2)!.hinge).toBeUndefined();+ });++ it('turns a hinge off where its bend is 0', () => {+ const chain = [named(1, null, 0, 'DEF-hips'), named(2, 1, 1, 'DEF-thigh.L'), named(3, 2, 2, 'DEF-shin.L', { bend: 0, swing: 50, twist: 10 }), named(4, 3, 3, 'DEF-foot.L')];+ const limbs = planRagdoll(chain, { ...options, forward: forwardZ, bend: 130 });+ expect(limbs.find((l) => l.entity === 3)!.hinge).toBeUndefined();+ expect(planRagdoll(chain.map((b) => ({ ...b, override: undefined })), { ...options, forward: forwardZ, bend: 130 }).find((l) => l.entity === 3)!.hinge).toBeDefined();+ });+});