@threlte/rapier 3.0.0-next.2 → 3.0.0-next.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/Attractor/Attractor.svelte.d.ts +3 -34
- package/dist/components/Attractor/types.d.ts +30 -0
- package/dist/components/Attractor/types.js +1 -0
- package/dist/components/Colliders/{AutoColliders.svelte → AutoColliders/AutoColliders.svelte} +27 -14
- package/dist/components/Colliders/AutoColliders/AutoColliders.svelte.d.ts +22 -0
- package/dist/components/Colliders/AutoColliders/types.d.ts +74 -0
- package/dist/components/Colliders/AutoColliders/types.js +1 -0
- package/dist/components/Colliders/{Collider.svelte → Collider/Collider.svelte} +30 -20
- package/dist/components/Colliders/Collider/Collider.svelte.d.ts +20 -0
- package/dist/components/Colliders/Collider/types.d.ts +83 -0
- package/dist/components/Colliders/Collider/types.js +1 -0
- package/dist/components/CollisionGroups/CollisionGroups.svelte +4 -1
- package/dist/components/CollisionGroups/CollisionGroups.svelte.d.ts +16 -33
- package/dist/components/CollisionGroups/types.d.ts +19 -0
- package/dist/components/CollisionGroups/types.js +1 -0
- package/dist/components/Debug/Debug.svelte +5 -5
- package/dist/components/Debug/Debug.svelte.d.ts +3 -7
- package/dist/components/Debug/types.d.ts +3 -0
- package/dist/components/Debug/types.js +1 -0
- package/dist/components/RigidBody/RigidBody.svelte +17 -6
- package/dist/components/RigidBody/RigidBody.svelte.d.ts +3 -102
- package/dist/components/RigidBody/overrideTeleportMethods.d.ts +14 -0
- package/dist/components/RigidBody/overrideTeleportMethods.js +31 -0
- package/dist/components/RigidBody/types.d.ts +85 -0
- package/dist/components/RigidBody/types.js +1 -0
- package/dist/components/World/InnerWorld.svelte +27 -5
- package/dist/components/World/InnerWorld.svelte.d.ts +3 -21
- package/dist/components/World/World.svelte +9 -57
- package/dist/components/World/World.svelte.d.ts +3 -38
- package/dist/components/World/types.d.ts +32 -0
- package/dist/components/World/types.js +1 -0
- package/dist/hooks/useFixedJoint.d.ts +2 -3
- package/dist/hooks/useJoint.d.ts +0 -1
- package/dist/hooks/usePhysicsTask.d.ts +16 -0
- package/dist/hooks/usePhysicsTask.js +32 -0
- package/dist/hooks/usePrismaticJoint.d.ts +1 -2
- package/dist/hooks/useRevoluteJoint.d.ts +1 -2
- package/dist/hooks/useRopeJoint.d.ts +10 -0
- package/dist/hooks/useRopeJoint.js +14 -0
- package/dist/hooks/useSphericalJoint.d.ts +1 -2
- package/dist/hooks/utils.js +3 -2
- package/dist/index.d.ts +5 -4
- package/dist/index.js +4 -4
- package/dist/lib/applyColliderActiveEvents.d.ts +1 -1
- package/dist/lib/applyTransforms.d.ts +1 -1
- package/dist/lib/createCollidersFromChildren.d.ts +1 -1
- package/dist/lib/createCollidersFromChildren.js +18 -3
- package/dist/lib/createPhysicsStages.d.ts +15 -0
- package/dist/lib/createPhysicsStages.js +43 -0
- package/dist/lib/createPhysicsTasks.d.ts +19 -0
- package/dist/{hooks/useFrameHandler.js → lib/createPhysicsTasks.js} +109 -40
- package/dist/lib/createRapierContext.d.ts +14 -20
- package/dist/lib/createRapierContext.js +35 -11
- package/dist/lib/eulerToQuaternion.d.ts +2 -2
- package/dist/lib/initRapier.svelte.d.ts +1 -0
- package/dist/lib/initRapier.svelte.js +16 -0
- package/dist/lib/keys.d.ts +2 -0
- package/dist/lib/keys.js +2 -0
- package/dist/lib/useCreateEvent.d.ts +2 -2
- package/dist/lib/useCreateEvent.js +3 -5
- package/dist/types/types.d.ts +36 -9
- package/package.json +33 -14
- package/dist/components/Colliders/AutoColliders.svelte.d.ts +0 -84
- package/dist/components/Colliders/Collider.svelte.d.ts +0 -109
- package/dist/hooks/useFrameHandler.d.ts +0 -3
- package/dist/hooks/useHasEventListener.d.ts +0 -3
- package/dist/hooks/useHasEventListener.js +0 -11
- package/dist/recipes/BasicPlayerController.svelte +0 -142
- package/dist/recipes/BasicPlayerController.svelte.d.ts +0 -31
|
@@ -1,102 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import type { RigidBodyTypeString } from '../../lib/parseRigidBodyType'
|
|
5
|
-
import type { RigidBodyEvents } from '../../types/types'
|
|
6
|
-
|
|
7
|
-
export type Boolean3Array = [x: boolean, y: boolean, z: boolean]
|
|
8
|
-
|
|
9
|
-
export type RigidBodyProps = {
|
|
10
|
-
rigidBody?: RapierRigidBody
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Specify the type of this rigid body
|
|
14
|
-
*/
|
|
15
|
-
type?: RigidBodyTypeString
|
|
16
|
-
|
|
17
|
-
/** Whether or not this body can sleep.
|
|
18
|
-
* default: true
|
|
19
|
-
*/
|
|
20
|
-
canSleep?: boolean
|
|
21
|
-
|
|
22
|
-
/** The linear velocity of this body.
|
|
23
|
-
* default: zero velocity
|
|
24
|
-
*/
|
|
25
|
-
linearVelocity?: Parameters<Vector3['set']>
|
|
26
|
-
|
|
27
|
-
/** The angular velocity of this body.
|
|
28
|
-
* Default: zero velocity.
|
|
29
|
-
*/
|
|
30
|
-
angularVelocity?: Parameters<Euler['set']>
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* The scaling factor applied to the gravity affecting the rigid-body.
|
|
34
|
-
* Default: 1.0
|
|
35
|
-
*/
|
|
36
|
-
gravityScale?: number
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Whether or not Continous Collision Detection is enabled for this rigid-body.
|
|
40
|
-
* https://rapier.rs/docs/user_guides/javascript/rigid_bodies#continuous-collision-detection
|
|
41
|
-
* @default false
|
|
42
|
-
*/
|
|
43
|
-
ccd?: boolean
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Locks all rotations that would have resulted from forces on the created rigid-body.
|
|
47
|
-
*/
|
|
48
|
-
lockRotations?: boolean
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Locks all translations that would have resulted from forces on the created rigid-body.
|
|
52
|
-
*/
|
|
53
|
-
lockTranslations?: boolean
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Allow rotation of this rigid-body only along specific axes.
|
|
57
|
-
*/
|
|
58
|
-
enabledRotations?: Boolean3Array
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Allow translations of this rigid-body only along specific axes.
|
|
62
|
-
*/
|
|
63
|
-
enabledTranslations?: Boolean3Array
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Dominance is a non-realistic, but sometimes useful, feature.
|
|
67
|
-
* It can be used to make one rigid-body immune to forces
|
|
68
|
-
* originating from contacts with some other bodies.
|
|
69
|
-
*
|
|
70
|
-
* Number in the range -127 to 127, default is 0
|
|
71
|
-
*/
|
|
72
|
-
dominance?: number
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* Damping lets you slow down a rigid-body automatically. This can be used to
|
|
76
|
-
* achieve a wide variety of effects like fake air friction. Larger values of
|
|
77
|
-
* damping coefficients lead to a stronger slow-downs. Their default
|
|
78
|
-
* values are 0.0 (no damping at all).
|
|
79
|
-
*/
|
|
80
|
-
linearDamping?: number
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Damping lets you slow down a rigid-body automatically. This can be used to
|
|
84
|
-
* achieve a wide variety of effects like fake air friction. Larger values of
|
|
85
|
-
* damping coefficients lead to a stronger slow-downs. Their default
|
|
86
|
-
* values are 0.0 (no damping at all).
|
|
87
|
-
*/
|
|
88
|
-
angularDamping?: number
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Set the rigidBody as enabled or disabled.
|
|
92
|
-
*/
|
|
93
|
-
enabled?: boolean
|
|
94
|
-
/**
|
|
95
|
-
* An arbitrary user-defined object associated with this rigid-body.
|
|
96
|
-
*/
|
|
97
|
-
userData?: Record<string, any>
|
|
98
|
-
|
|
99
|
-
children?: Snippet<[{ rigidBody: RapierRigidBody }]>
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
export default class RigidBody extends SvelteComponent<RigidBodyProps & RigidBodyEvents> {}
|
|
1
|
+
import type { RigidBodyProps } from './types';
|
|
2
|
+
declare const RigidBody: import("svelte").Component<RigidBodyProps, {}, "rigidBody">;
|
|
3
|
+
export default RigidBody;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { RigidBody } from '@dimforge/rapier3d-compat';
|
|
2
|
+
import type { Object3D } from 'three';
|
|
3
|
+
export type ExtractMethods<ObjectType> = Pick<ObjectType, {
|
|
4
|
+
[Method in keyof ObjectType]: ObjectType[Method] extends (...args: any[]) => any ? Method : never;
|
|
5
|
+
}[keyof ObjectType]>;
|
|
6
|
+
/**
|
|
7
|
+
* When using a fixed framerate, Threlte is interpolating the position and
|
|
8
|
+
* rotation of RigidBody objects. Sometimes, this is not desirable, especially
|
|
9
|
+
* when using methods on the rigidbody that teleport the object, e.g. should
|
|
10
|
+
* lead to a sudden change in translation/rotation such as `rb.setTranslation`.
|
|
11
|
+
* These methods are overridden to reset the physics simulation position and
|
|
12
|
+
* rotation to the current object position and rotation.
|
|
13
|
+
*/
|
|
14
|
+
export declare const overrideTeleportMethods: (rb: RigidBody, object: Object3D) => void;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
const overrideMethods = {
|
|
2
|
+
position: ['setTranslation', 'setNextKinematicTranslation'],
|
|
3
|
+
rotation: ['setRotation', 'setNextKinematicRotation']
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* When using a fixed framerate, Threlte is interpolating the position and
|
|
7
|
+
* rotation of RigidBody objects. Sometimes, this is not desirable, especially
|
|
8
|
+
* when using methods on the rigidbody that teleport the object, e.g. should
|
|
9
|
+
* lead to a sudden change in translation/rotation such as `rb.setTranslation`.
|
|
10
|
+
* These methods are overridden to reset the physics simulation position and
|
|
11
|
+
* rotation to the current object position and rotation.
|
|
12
|
+
*/
|
|
13
|
+
export const overrideTeleportMethods = (rb, object) => {
|
|
14
|
+
const originalMethods = {};
|
|
15
|
+
overrideMethods.position.forEach((method) => {
|
|
16
|
+
originalMethods[method] = rb[method].bind(rb);
|
|
17
|
+
const proxy = (...args) => {
|
|
18
|
+
object.userData.physics.resetPosition = true;
|
|
19
|
+
return originalMethods[method](...args);
|
|
20
|
+
};
|
|
21
|
+
rb[method] = proxy;
|
|
22
|
+
});
|
|
23
|
+
overrideMethods.rotation.forEach((method) => {
|
|
24
|
+
originalMethods[method] = rb[method].bind(rb);
|
|
25
|
+
const proxy = (...args) => {
|
|
26
|
+
object.userData.physics.resetRotation = true;
|
|
27
|
+
return originalMethods[method](...args);
|
|
28
|
+
};
|
|
29
|
+
rb[method] = proxy;
|
|
30
|
+
});
|
|
31
|
+
};
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { RigidBody as RapierRigidBody } from '@dimforge/rapier3d-compat';
|
|
2
|
+
import { type Snippet } from 'svelte';
|
|
3
|
+
import type { Euler, Vector3 } from 'three';
|
|
4
|
+
import type { RigidBodyTypeString } from '../../lib/parseRigidBodyType';
|
|
5
|
+
import type { CreateEvent, RigidBodyEvents } from '../../types/types';
|
|
6
|
+
export type Boolean3Array = [x: boolean, y: boolean, z: boolean];
|
|
7
|
+
export type RigidBodyProps = CreateEvent<RapierRigidBody> & RigidBodyEvents & {
|
|
8
|
+
rigidBody?: RapierRigidBody | undefined;
|
|
9
|
+
/**
|
|
10
|
+
* Specify the type of this rigid body
|
|
11
|
+
*/
|
|
12
|
+
type?: RigidBodyTypeString;
|
|
13
|
+
/** Whether or not this body can sleep.
|
|
14
|
+
* default: true
|
|
15
|
+
*/
|
|
16
|
+
canSleep?: boolean;
|
|
17
|
+
/** The linear velocity of this body.
|
|
18
|
+
* default: zero velocity
|
|
19
|
+
*/
|
|
20
|
+
linearVelocity?: Parameters<Vector3['set']>;
|
|
21
|
+
/** The angular velocity of this body.
|
|
22
|
+
* Default: zero velocity.
|
|
23
|
+
*/
|
|
24
|
+
angularVelocity?: Parameters<Euler['set']>;
|
|
25
|
+
/**
|
|
26
|
+
* The scaling factor applied to the gravity affecting the rigid-body.
|
|
27
|
+
* Default: 1.0
|
|
28
|
+
*/
|
|
29
|
+
gravityScale?: number;
|
|
30
|
+
/**
|
|
31
|
+
* Whether or not Continous Collision Detection is enabled for this rigid-body.
|
|
32
|
+
* https://rapier.rs/docs/user_guides/javascript/rigid_bodies#continuous-collision-detection
|
|
33
|
+
* @default false
|
|
34
|
+
*/
|
|
35
|
+
ccd?: boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Locks all rotations that would have resulted from forces on the created rigid-body.
|
|
38
|
+
*/
|
|
39
|
+
lockRotations?: boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Locks all translations that would have resulted from forces on the created rigid-body.
|
|
42
|
+
*/
|
|
43
|
+
lockTranslations?: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Allow rotation of this rigid-body only along specific axes.
|
|
46
|
+
*/
|
|
47
|
+
enabledRotations?: Boolean3Array;
|
|
48
|
+
/**
|
|
49
|
+
* Allow translations of this rigid-body only along specific axes.
|
|
50
|
+
*/
|
|
51
|
+
enabledTranslations?: Boolean3Array;
|
|
52
|
+
/**
|
|
53
|
+
* Dominance is a non-realistic, but sometimes useful, feature.
|
|
54
|
+
* It can be used to make one rigid-body immune to forces
|
|
55
|
+
* originating from contacts with some other bodies.
|
|
56
|
+
*
|
|
57
|
+
* Number in the range -127 to 127, default is 0
|
|
58
|
+
*/
|
|
59
|
+
dominance?: number;
|
|
60
|
+
/**
|
|
61
|
+
* Damping lets you slow down a rigid-body automatically. This can be used to
|
|
62
|
+
* achieve a wide variety of effects like fake air friction. Larger values of
|
|
63
|
+
* damping coefficients lead to a stronger slow-downs. Their default
|
|
64
|
+
* values are 0.0 (no damping at all).
|
|
65
|
+
*/
|
|
66
|
+
linearDamping?: number;
|
|
67
|
+
/**
|
|
68
|
+
* Damping lets you slow down a rigid-body automatically. This can be used to
|
|
69
|
+
* achieve a wide variety of effects like fake air friction. Larger values of
|
|
70
|
+
* damping coefficients lead to a stronger slow-downs. Their default
|
|
71
|
+
* values are 0.0 (no damping at all).
|
|
72
|
+
*/
|
|
73
|
+
angularDamping?: number;
|
|
74
|
+
/**
|
|
75
|
+
* Set the rigidBody as enabled or disabled.
|
|
76
|
+
*/
|
|
77
|
+
enabled?: boolean;
|
|
78
|
+
/**
|
|
79
|
+
* An arbitrary user-defined object associated with this rigid-body.
|
|
80
|
+
*/
|
|
81
|
+
userData?: Record<string, any>;
|
|
82
|
+
children?: Snippet<[{
|
|
83
|
+
rigidBody: RapierRigidBody;
|
|
84
|
+
}]>;
|
|
85
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,19 +1,41 @@
|
|
|
1
1
|
<script lang="ts">import { onDestroy, setContext, tick } from 'svelte';
|
|
2
|
-
import { useFrameHandler } from '../../hooks/useFrameHandler';
|
|
3
2
|
import { createRapierContext } from '../../lib/createRapierContext';
|
|
4
|
-
let { gravity = [0, -9.81, 0], rawIntegrationParameters, rawIslands, rawBroadPhase, rawNarrowPhase, rawBodies, rawColliders, rawImpulseJoints, rawMultibodyJoints, rawCCDSolver, rawQueryPipeline, rawPhysicsPipeline, rawSerializationPipeline, rawDebugRenderPipeline,
|
|
5
|
-
const rapierContext = createRapierContext(
|
|
3
|
+
let { gravity = [0, -9.81, 0], rawIntegrationParameters, rawIslands, rawBroadPhase, rawNarrowPhase, rawBodies, rawColliders, rawImpulseJoints, rawMultibodyJoints, rawCCDSolver, rawQueryPipeline, rawPhysicsPipeline, rawSerializationPipeline, rawDebugRenderPipeline, framerate, autoStart = true, simulationStageOptions, synchronizationStageOptions, children } = $props();
|
|
4
|
+
const rapierContext = createRapierContext([
|
|
5
|
+
{ x: gravity[0], y: gravity[1], z: gravity[2] },
|
|
6
|
+
rawIntegrationParameters,
|
|
7
|
+
rawIslands,
|
|
8
|
+
rawBroadPhase,
|
|
9
|
+
rawNarrowPhase,
|
|
10
|
+
rawBodies,
|
|
11
|
+
rawColliders,
|
|
12
|
+
rawImpulseJoints,
|
|
13
|
+
rawMultibodyJoints,
|
|
14
|
+
rawCCDSolver,
|
|
15
|
+
rawQueryPipeline,
|
|
16
|
+
rawPhysicsPipeline,
|
|
17
|
+
rawSerializationPipeline,
|
|
18
|
+
rawDebugRenderPipeline
|
|
19
|
+
], {
|
|
20
|
+
framerate,
|
|
21
|
+
autoStart,
|
|
22
|
+
simulationStageOptions,
|
|
23
|
+
synchronizationStageOptions
|
|
24
|
+
});
|
|
6
25
|
setContext('threlte-rapier-context', rapierContext);
|
|
7
26
|
$effect.pre(() => {
|
|
8
27
|
if (gravity !== undefined) {
|
|
9
28
|
rapierContext.world.gravity = { x: gravity[0], y: gravity[1], z: gravity[2] };
|
|
10
29
|
}
|
|
11
30
|
});
|
|
12
|
-
|
|
31
|
+
$effect.pre(() => {
|
|
32
|
+
if (framerate !== undefined)
|
|
33
|
+
rapierContext.framerate.set(framerate);
|
|
34
|
+
});
|
|
13
35
|
onDestroy(async () => {
|
|
14
36
|
await tick();
|
|
15
37
|
rapierContext.world.free();
|
|
16
38
|
});
|
|
17
39
|
</script>
|
|
18
40
|
|
|
19
|
-
|
|
41
|
+
{@render children?.()}
|
|
@@ -1,21 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
props: WorldProps & {
|
|
5
|
-
children?: ((this: void) => typeof import("svelte").SnippetReturn & {
|
|
6
|
-
_: "functions passed to {@render ...} tags must use the `Snippet` type imported from \"svelte\"";
|
|
7
|
-
}) | undefined;
|
|
8
|
-
};
|
|
9
|
-
events: {
|
|
10
|
-
[evt: string]: CustomEvent<any>;
|
|
11
|
-
};
|
|
12
|
-
slots: {
|
|
13
|
-
default: {};
|
|
14
|
-
};
|
|
15
|
-
};
|
|
16
|
-
export type InnerWorldProps = typeof __propDef.props;
|
|
17
|
-
export type InnerWorldEvents = typeof __propDef.events;
|
|
18
|
-
export type InnerWorldSlots = typeof __propDef.slots;
|
|
19
|
-
export default class InnerWorld extends SvelteComponent<InnerWorldProps, InnerWorldEvents, InnerWorldSlots> {
|
|
20
|
-
}
|
|
21
|
-
export {};
|
|
1
|
+
import type { WorldProps } from './types';
|
|
2
|
+
declare const InnerWorld: import("svelte").Component<WorldProps, {}, "">;
|
|
3
|
+
export default InnerWorld;
|
|
@@ -1,60 +1,12 @@
|
|
|
1
|
-
<script
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
>import RAPIER from '@dimforge/rapier3d-compat';
|
|
5
|
-
import { onMount } from 'svelte';
|
|
6
|
-
import { writable } from 'svelte/store';
|
|
7
|
-
/**
|
|
8
|
-
* RAPIER.init() should only be called once
|
|
9
|
-
*/
|
|
10
|
-
const initialized = writable(false);
|
|
1
|
+
<script lang="ts">import { initRapier } from '../../lib/initRapier.svelte';
|
|
2
|
+
import InnerWorld from './InnerWorld.svelte';
|
|
3
|
+
let { fallback, children, ...rest } = $props();
|
|
11
4
|
</script>
|
|
12
5
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
* This is passed to the useTask handler.
|
|
17
|
-
* Use this to control when the rapier physics engine is updating the scene.
|
|
18
|
-
* @default undefined
|
|
19
|
-
*/
|
|
20
|
-
stage } = $props();
|
|
21
|
-
let error = $state(false);
|
|
22
|
-
const init = async () => {
|
|
23
|
-
if ($initialized)
|
|
24
|
-
return;
|
|
25
|
-
try {
|
|
26
|
-
await RAPIER.init();
|
|
27
|
-
$initialized = true;
|
|
28
|
-
}
|
|
29
|
-
catch (e) {
|
|
30
|
-
error = true;
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
onMount(init);
|
|
34
|
-
</script>
|
|
35
|
-
|
|
36
|
-
{#if $initialized}
|
|
37
|
-
<InnerWorld
|
|
38
|
-
{gravity}
|
|
39
|
-
{rawIntegrationParameters}
|
|
40
|
-
{rawIslands}
|
|
41
|
-
{rawBroadPhase}
|
|
42
|
-
{rawNarrowPhase}
|
|
43
|
-
{rawBodies}
|
|
44
|
-
{rawColliders}
|
|
45
|
-
{rawImpulseJoints}
|
|
46
|
-
{rawMultibodyJoints}
|
|
47
|
-
{rawCCDSolver}
|
|
48
|
-
{rawQueryPipeline}
|
|
49
|
-
{rawPhysicsPipeline}
|
|
50
|
-
{rawSerializationPipeline}
|
|
51
|
-
{rawDebugRenderPipeline}
|
|
52
|
-
{stage}
|
|
53
|
-
>
|
|
54
|
-
<slot />
|
|
6
|
+
{#await initRapier() then _}
|
|
7
|
+
<InnerWorld {...rest}>
|
|
8
|
+
{@render children?.()}
|
|
55
9
|
</InnerWorld>
|
|
56
|
-
{
|
|
57
|
-
|
|
58
|
-
{
|
|
59
|
-
<slot name="fallback" />
|
|
60
|
-
{/if}
|
|
10
|
+
{:catch error}
|
|
11
|
+
{@render fallback?.(error)}
|
|
12
|
+
{/await}
|
|
@@ -1,38 +1,3 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
RawColliderSet,
|
|
5
|
-
RawDebugRenderPipeline,
|
|
6
|
-
RawImpulseJointSet,
|
|
7
|
-
RawIntegrationParameters,
|
|
8
|
-
RawIslandManager,
|
|
9
|
-
RawMultibodyJointSet,
|
|
10
|
-
RawNarrowPhase,
|
|
11
|
-
RawPhysicsPipeline,
|
|
12
|
-
RawQueryPipeline,
|
|
13
|
-
RawRigidBodySet,
|
|
14
|
-
RawSerializationPipeline
|
|
15
|
-
} from '@dimforge/rapier3d-compat/raw'
|
|
16
|
-
import { SvelteComponent } from 'svelte'
|
|
17
|
-
import type { Vector3 } from 'three'
|
|
18
|
-
import type { Key, Stage } from '@threlte/core'
|
|
19
|
-
|
|
20
|
-
export type WorldProps = {
|
|
21
|
-
gravity?: Parameters<Vector3['set']>
|
|
22
|
-
rawIntegrationParameters?: RawIntegrationParameters
|
|
23
|
-
rawIslands?: RawIslandManager
|
|
24
|
-
rawBroadPhase?: RawBroadPhase
|
|
25
|
-
rawNarrowPhase?: RawNarrowPhase
|
|
26
|
-
rawBodies?: RawRigidBodySet
|
|
27
|
-
rawColliders?: RawColliderSet
|
|
28
|
-
rawImpulseJoints?: RawImpulseJointSet
|
|
29
|
-
rawMultibodyJoints?: RawMultibodyJointSet
|
|
30
|
-
rawCCDSolver?: RawCCDSolver
|
|
31
|
-
rawQueryPipeline?: RawQueryPipeline
|
|
32
|
-
rawPhysicsPipeline?: RawPhysicsPipeline
|
|
33
|
-
rawSerializationPipeline?: RawSerializationPipeline
|
|
34
|
-
rawDebugRenderPipeline?: RawDebugRenderPipeline
|
|
35
|
-
stage?: Key | Stage
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export default class World extends SvelteComponent<WorldProps> {}
|
|
1
|
+
import type { WorldProps } from './types';
|
|
2
|
+
declare const World: import("svelte").Component<WorldProps, {}, "">;
|
|
3
|
+
export default World;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { RawBroadPhase, RawCCDSolver, RawColliderSet, RawDebugRenderPipeline, RawImpulseJointSet, RawIntegrationParameters, RawIslandManager, RawMultibodyJointSet, RawNarrowPhase, RawPhysicsPipeline, RawQueryPipeline, RawRigidBodySet, RawSerializationPipeline } from '@dimforge/rapier3d-compat/raw';
|
|
2
|
+
import type { Key, Stage } from '@threlte/core';
|
|
3
|
+
import { type Snippet } from 'svelte';
|
|
4
|
+
import type { Vector3 } from 'three';
|
|
5
|
+
export type WorldProps = {
|
|
6
|
+
framerate?: number | 'varying';
|
|
7
|
+
autoStart?: boolean;
|
|
8
|
+
gravity?: Parameters<Vector3['set']>;
|
|
9
|
+
rawIntegrationParameters?: RawIntegrationParameters;
|
|
10
|
+
rawIslands?: RawIslandManager;
|
|
11
|
+
rawBroadPhase?: RawBroadPhase;
|
|
12
|
+
rawNarrowPhase?: RawNarrowPhase;
|
|
13
|
+
rawBodies?: RawRigidBodySet;
|
|
14
|
+
rawColliders?: RawColliderSet;
|
|
15
|
+
rawImpulseJoints?: RawImpulseJointSet;
|
|
16
|
+
rawMultibodyJoints?: RawMultibodyJointSet;
|
|
17
|
+
rawCCDSolver?: RawCCDSolver;
|
|
18
|
+
rawQueryPipeline?: RawQueryPipeline;
|
|
19
|
+
rawPhysicsPipeline?: RawPhysicsPipeline;
|
|
20
|
+
rawSerializationPipeline?: RawSerializationPipeline;
|
|
21
|
+
rawDebugRenderPipeline?: RawDebugRenderPipeline;
|
|
22
|
+
simulationStageOptions?: {
|
|
23
|
+
before?: (Key | Stage) | (Key | Stage)[];
|
|
24
|
+
after?: (Key | Stage) | (Key | Stage)[];
|
|
25
|
+
};
|
|
26
|
+
synchronizationStageOptions?: {
|
|
27
|
+
before?: (Key | Stage) | (Key | Stage)[];
|
|
28
|
+
after?: (Key | Stage) | (Key | Stage)[];
|
|
29
|
+
};
|
|
30
|
+
children?: Snippet;
|
|
31
|
+
fallback?: Snippet<[error: any]>;
|
|
32
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
/// <reference types="svelte" />
|
|
2
1
|
import type { FixedImpulseJoint } from '@dimforge/rapier3d-compat';
|
|
3
|
-
import { Euler } from 'three';
|
|
4
|
-
export declare const useFixedJoint: (anchorA: [
|
|
2
|
+
import { Euler, Vector3 } from 'three';
|
|
3
|
+
export declare const useFixedJoint: (anchorA: Parameters<Vector3["set"]>, frameA: Parameters<Euler["set"]> | Euler, anchorB: Parameters<Vector3["set"]>, frameB: Parameters<Euler["set"]> | Euler) => {
|
|
5
4
|
joint: import("svelte/store").Writable<FixedImpulseJoint>;
|
|
6
5
|
rigidBodyA: import("svelte/store").Writable<import("@dimforge/rapier3d-compat").RigidBody | undefined>;
|
|
7
6
|
rigidBodyB: import("svelte/store").Writable<import("@dimforge/rapier3d-compat").RigidBody | undefined>;
|
package/dist/hooks/useJoint.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="svelte" />
|
|
2
1
|
import { MultibodyJoint, type ImpulseJoint, type RigidBody } from '@dimforge/rapier3d-compat';
|
|
3
2
|
import type { RapierContext } from '../types/types';
|
|
4
3
|
export declare const useJoint: <T extends ImpulseJoint | MultibodyJoint>(initializeJoint: (rigidBodyA: RigidBody, rigidBodyB: RigidBody, ctx: RapierContext) => T) => {
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type Key, type ThrelteUseTask, type ThrelteUseTaskOptions } from '@threlte/core';
|
|
2
|
+
/**
|
|
3
|
+
* Adds a handler to the physics simulation. The handler is always executed as
|
|
4
|
+
* part of the simulation stage and before the simulation task.
|
|
5
|
+
*
|
|
6
|
+
* `start` and `stop` functions are returned and the options allow setting the
|
|
7
|
+
* handler to not start automatically.
|
|
8
|
+
*
|
|
9
|
+
* Use the options `after` and `before` to control the order of execution.
|
|
10
|
+
*
|
|
11
|
+
* @param {(delta: number) => void} fn callback function
|
|
12
|
+
* @param {ThrelteUseTaskOptions} options options
|
|
13
|
+
* @returns {ThrelteUseTask}
|
|
14
|
+
*/
|
|
15
|
+
export declare function usePhysicsTask(fn: (delta: number) => void, options?: ThrelteUseTaskOptions): ThrelteUseTask;
|
|
16
|
+
export declare function usePhysicsTask(key: Key, fn: (delta: number) => void, options?: ThrelteUseTaskOptions): ThrelteUseTask;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { useTask } from '@threlte/core';
|
|
2
|
+
import { useRapier } from './useRapier';
|
|
3
|
+
const isKey = (value) => {
|
|
4
|
+
return typeof value === 'string' || typeof value === 'symbol';
|
|
5
|
+
};
|
|
6
|
+
export function usePhysicsTask(keyOrFn, fnOrOptions, options) {
|
|
7
|
+
const { simulationTask, simulationStage } = useRapier();
|
|
8
|
+
let key;
|
|
9
|
+
let fn;
|
|
10
|
+
let opts;
|
|
11
|
+
if (isKey(keyOrFn)) {
|
|
12
|
+
key = keyOrFn;
|
|
13
|
+
fn = fnOrOptions;
|
|
14
|
+
opts = options ?? {};
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
key = Symbol('usePhysicsTask');
|
|
18
|
+
fn = keyOrFn;
|
|
19
|
+
opts = (fnOrOptions ?? {});
|
|
20
|
+
}
|
|
21
|
+
if (opts.before && Array.isArray(opts.before)) {
|
|
22
|
+
opts.before.push(simulationTask);
|
|
23
|
+
}
|
|
24
|
+
else if (opts.before) {
|
|
25
|
+
opts.before = [opts.before, simulationTask];
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
opts.before = [simulationTask];
|
|
29
|
+
}
|
|
30
|
+
opts.stage = simulationStage;
|
|
31
|
+
return useTask(key, fn, opts);
|
|
32
|
+
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
/// <reference types="svelte" />
|
|
2
1
|
import type { PrismaticImpulseJoint } from '@dimforge/rapier3d-compat';
|
|
3
2
|
import { Vector3 } from 'three';
|
|
4
|
-
export declare const usePrismaticJoint: (anchorA: Parameters<Vector3[
|
|
3
|
+
export declare const usePrismaticJoint: (anchorA: Parameters<Vector3["set"]> | Vector3, anchorB: Parameters<Vector3["set"]> | Vector3, axis: Parameters<Vector3["set"]> | Vector3, limits?: [min: number, max: number]) => {
|
|
5
4
|
joint: import("svelte/store").Writable<PrismaticImpulseJoint>;
|
|
6
5
|
rigidBodyA: import("svelte/store").Writable<import("@dimforge/rapier3d-compat").RigidBody | undefined>;
|
|
7
6
|
rigidBodyB: import("svelte/store").Writable<import("@dimforge/rapier3d-compat").RigidBody | undefined>;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
/// <reference types="svelte" />
|
|
2
1
|
import type { RevoluteImpulseJoint } from '@dimforge/rapier3d-compat';
|
|
3
2
|
import { Vector3 } from 'three';
|
|
4
|
-
export declare const useRevoluteJoint: (anchorA: Parameters<Vector3[
|
|
3
|
+
export declare const useRevoluteJoint: (anchorA: Parameters<Vector3["set"]> | Vector3, anchorB: Parameters<Vector3["set"]> | Vector3, axis: Parameters<Vector3["set"]> | Vector3, limits?: [min: number, max: number]) => {
|
|
5
4
|
joint: import("svelte/store").Writable<RevoluteImpulseJoint>;
|
|
6
5
|
rigidBodyA: import("svelte/store").Writable<import("@dimforge/rapier3d-compat").RigidBody | undefined>;
|
|
7
6
|
rigidBodyB: import("svelte/store").Writable<import("@dimforge/rapier3d-compat").RigidBody | undefined>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { RopeImpulseJoint } from '@dimforge/rapier3d-compat';
|
|
2
|
+
import { Vector3 } from 'three';
|
|
3
|
+
/**
|
|
4
|
+
* The rope joint limits the max distance between two bodies.
|
|
5
|
+
*/
|
|
6
|
+
export declare const useRopeJoint: (anchorA: Parameters<Vector3["set"]> | Vector3, anchorB: Parameters<Vector3["set"]> | Vector3, length: number) => {
|
|
7
|
+
joint: import("svelte/store").Writable<RopeImpulseJoint>;
|
|
8
|
+
rigidBodyA: import("svelte/store").Writable<import("@dimforge/rapier3d-compat").RigidBody | undefined>;
|
|
9
|
+
rigidBodyB: import("svelte/store").Writable<import("@dimforge/rapier3d-compat").RigidBody | undefined>;
|
|
10
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Vector3 } from 'three';
|
|
2
|
+
import { useJoint } from './useJoint';
|
|
3
|
+
import { isVector3 } from './utils';
|
|
4
|
+
/**
|
|
5
|
+
* The rope joint limits the max distance between two bodies.
|
|
6
|
+
*/
|
|
7
|
+
export const useRopeJoint = (anchorA, anchorB, length) => {
|
|
8
|
+
return useJoint((rbA, rbB, { world, rapier }) => {
|
|
9
|
+
const jaA = isVector3(anchorA) ? anchorA : new Vector3(...anchorA);
|
|
10
|
+
const jaB = isVector3(anchorB) ? anchorB : new Vector3(...anchorB);
|
|
11
|
+
const params = rapier.JointData.rope(length, jaA, jaB);
|
|
12
|
+
return world.createImpulseJoint(params, rbA, rbB, true);
|
|
13
|
+
});
|
|
14
|
+
};
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
/// <reference types="svelte" />
|
|
2
1
|
import type { SphericalImpulseJoint } from '@dimforge/rapier3d-compat';
|
|
3
2
|
import { Vector3 } from 'three';
|
|
4
|
-
export declare const useSphericalJoint: (anchorA: Parameters<Vector3[
|
|
3
|
+
export declare const useSphericalJoint: (anchorA: Parameters<Vector3["set"]> | Vector3, anchorB: Parameters<Vector3["set"]> | Vector3) => {
|
|
5
4
|
joint: import("svelte/store").Writable<SphericalImpulseJoint>;
|
|
6
5
|
rigidBodyA: import("svelte/store").Writable<import("@dimforge/rapier3d-compat").RigidBody | undefined>;
|
|
7
6
|
rigidBodyB: import("svelte/store").Writable<import("@dimforge/rapier3d-compat").RigidBody | undefined>;
|
package/dist/hooks/utils.js
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
export { useRapier } from './hooks/useRapier';
|
|
2
2
|
export { useCollisionGroups } from './hooks/useCollisionGroups';
|
|
3
3
|
export { useRigidBody } from './hooks/useRigidBody';
|
|
4
|
+
export { usePhysicsTask } from './hooks/usePhysicsTask';
|
|
4
5
|
export { useRevoluteJoint } from './hooks/useRevoluteJoint';
|
|
5
6
|
export { usePrismaticJoint } from './hooks/usePrismaticJoint';
|
|
6
7
|
export { useFixedJoint } from './hooks/useFixedJoint';
|
|
7
8
|
export { useSphericalJoint } from './hooks/useSphericalJoint';
|
|
8
9
|
export { useJoint } from './hooks/useJoint';
|
|
10
|
+
export { useRopeJoint } from './hooks/useRopeJoint';
|
|
9
11
|
export { default as World } from './components/World/World.svelte';
|
|
10
12
|
export { default as RigidBody } from './components/RigidBody/RigidBody.svelte';
|
|
11
13
|
export { default as Debug } from './components/Debug/Debug.svelte';
|
|
12
|
-
export { default as Collider } from './components/Colliders/Collider.svelte';
|
|
13
|
-
export { default as AutoColliders } from './components/Colliders/AutoColliders.svelte';
|
|
14
|
+
export { default as Collider } from './components/Colliders/Collider/Collider.svelte';
|
|
15
|
+
export { default as AutoColliders } from './components/Colliders/AutoColliders/AutoColliders.svelte';
|
|
14
16
|
export { default as CollisionGroups } from './components/CollisionGroups/CollisionGroups.svelte';
|
|
15
17
|
export { default as Attractor } from './components/Attractor/Attractor.svelte';
|
|
16
18
|
export { computeBitMask } from './lib/computeBitMask';
|
|
17
|
-
export {
|
|
18
|
-
export type { CollisionGroupsBitMask, AutoCollidersShapes, ColliderEventDispatcher, ColliderShapes, RapierContext, RigidBodyEventDispatcher, CollisionEnterEvent, CollisionExitEvent, SensorEnterEvent, SensorExitEvent, ContactEvent, GravityType } from './types/types';
|
|
19
|
+
export type { CollisionGroupsBitMask, AutoCollidersShapes, ColliderShapes, RapierContext, CollisionEnterEvent, CollisionExitEvent, SensorEnterEvent, SensorExitEvent, ContactEvent, GravityType, CreateEvent, Framerate } from './types/types';
|
package/dist/index.js
CHANGED
|
@@ -2,21 +2,21 @@
|
|
|
2
2
|
export { useRapier } from './hooks/useRapier';
|
|
3
3
|
export { useCollisionGroups } from './hooks/useCollisionGroups';
|
|
4
4
|
export { useRigidBody } from './hooks/useRigidBody';
|
|
5
|
+
export { usePhysicsTask } from './hooks/usePhysicsTask';
|
|
5
6
|
// Joints
|
|
6
7
|
export { useRevoluteJoint } from './hooks/useRevoluteJoint';
|
|
7
8
|
export { usePrismaticJoint } from './hooks/usePrismaticJoint';
|
|
8
9
|
export { useFixedJoint } from './hooks/useFixedJoint';
|
|
9
10
|
export { useSphericalJoint } from './hooks/useSphericalJoint';
|
|
10
11
|
export { useJoint } from './hooks/useJoint';
|
|
12
|
+
export { useRopeJoint } from './hooks/useRopeJoint';
|
|
11
13
|
// components
|
|
12
14
|
export { default as World } from './components/World/World.svelte';
|
|
13
15
|
export { default as RigidBody } from './components/RigidBody/RigidBody.svelte';
|
|
14
16
|
export { default as Debug } from './components/Debug/Debug.svelte';
|
|
15
|
-
export { default as Collider } from './components/Colliders/Collider.svelte';
|
|
16
|
-
export { default as AutoColliders } from './components/Colliders/AutoColliders.svelte';
|
|
17
|
+
export { default as Collider } from './components/Colliders/Collider/Collider.svelte';
|
|
18
|
+
export { default as AutoColliders } from './components/Colliders/AutoColliders/AutoColliders.svelte';
|
|
17
19
|
export { default as CollisionGroups } from './components/CollisionGroups/CollisionGroups.svelte';
|
|
18
20
|
export { default as Attractor } from './components/Attractor/Attractor.svelte';
|
|
19
21
|
// lib
|
|
20
22
|
export { computeBitMask } from './lib/computeBitMask';
|
|
21
|
-
// recipes
|
|
22
|
-
export { default as BasicPlayerController } from './recipes/BasicPlayerController.svelte';
|