@threlte/rapier 0.5.0 → 1.0.0-next.1
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/CHANGELOG.md +12 -0
- package/dist/components/Attractor/Attractor.svelte +17 -13
- package/dist/components/Attractor/Attractor.svelte.d.ts +20 -22
- package/dist/components/Colliders/AutoColliders.svelte +52 -50
- package/dist/components/Colliders/AutoColliders.svelte.d.ts +80 -0
- package/dist/components/Colliders/Collider.svelte +40 -30
- package/dist/components/Colliders/Collider.svelte.d.ts +110 -112
- package/dist/components/CollisionGroups/CollisionGroups.svelte +1 -20
- package/dist/components/CollisionGroups/CollisionGroups.svelte.d.ts +29 -19
- package/dist/components/Debug/Debug.svelte +13 -10
- package/dist/components/Debug/Debug.svelte.d.ts +6 -60
- package/dist/components/RigidBody/RigidBody.svelte +23 -58
- package/dist/components/RigidBody/RigidBody.svelte.d.ts +94 -67
- package/dist/components/World/InnerWorld.svelte +11 -7
- package/dist/components/World/InnerWorld.svelte.d.ts +15 -15
- package/dist/components/World/World.svelte +13 -2
- package/dist/components/World/World.svelte.d.ts +36 -32
- package/dist/hooks/useFixedJoint.d.ts +2 -2
- package/dist/hooks/useFixedJoint.js +6 -3
- package/dist/hooks/useFrameHandler.d.ts +1 -1
- package/dist/hooks/useFrameHandler.js +9 -8
- package/dist/hooks/usePrismaticJoint.d.ts +2 -2
- package/dist/hooks/usePrismaticJoint.js +5 -2
- package/dist/hooks/useRevoluteJoint.d.ts +2 -2
- package/dist/hooks/useRevoluteJoint.js +5 -2
- package/dist/hooks/useSphericalJoint.d.ts +2 -2
- package/dist/hooks/useSphericalJoint.js +4 -2
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -0
- package/dist/lib/applyTransforms.d.ts +2 -3
- package/dist/lib/applyTransforms.js +7 -16
- package/dist/lib/computeBitMask.d.ts +5 -0
- package/dist/lib/computeBitMask.js +20 -0
- package/dist/lib/createRapierContext.d.ts +3 -0
- package/dist/lib/createRapierContext.js +10 -1
- package/dist/lib/eulerToQuaternion.d.ts +7 -0
- package/dist/lib/eulerToQuaternion.js +12 -0
- package/dist/lib/scaleColliderArgs.js +3 -3
- package/dist/recipes/BasicPlayerController.svelte +28 -27
- package/dist/recipes/BasicPlayerController.svelte.d.ts +2 -5
- package/dist/types/components.d.ts +1 -88
- package/dist/types/types.d.ts +5 -5
- package/package.json +10 -9
- package/dist/components/Joints/RevoluteJoint.svelte +0 -5
- package/dist/components/Joints/RevoluteJoint.svelte.d.ts +0 -23
- package/dist/lib/positionToVector3.d.ts +0 -3
- package/dist/lib/positionToVector3.js +0 -8
- package/dist/lib/rotationToEuler.d.ts +0 -3
- package/dist/lib/rotationToEuler.js +0 -8
- package/dist/lib/rotationToQuaternion.d.ts +0 -3
- package/dist/lib/rotationToQuaternion.js +0 -10
- package/dist/lib/scaleToVector3.d.ts +0 -3
- package/dist/lib/scaleToVector3.js +0 -16
|
@@ -1,68 +1,95 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import type {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
1
|
+
import { RigidBody as RapierRigidBody } from '@dimforge/rapier3d-compat'
|
|
2
|
+
import { SvelteComponentTyped } from 'svelte'
|
|
3
|
+
import type { Euler, Vector3 } from 'three'
|
|
4
|
+
import type { RigidBodyTypeString } from '../../lib/parseRigidBodyType'
|
|
5
|
+
|
|
6
|
+
export type Boolean3Array = [x: boolean, y: boolean, z: boolean]
|
|
7
|
+
|
|
8
|
+
export type RigidBodyProps = {
|
|
9
|
+
rigidBody?: RapierRigidBody
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Specify the type of this rigid body
|
|
13
|
+
*/
|
|
14
|
+
type?: RigidBodyTypeString
|
|
15
|
+
|
|
16
|
+
/** Whether or not this body can sleep.
|
|
17
|
+
* default: true
|
|
18
|
+
*/
|
|
19
|
+
canSleep?: boolean
|
|
20
|
+
|
|
21
|
+
/** The linear velocity of this body.
|
|
22
|
+
* default: zero velocity
|
|
23
|
+
*/
|
|
24
|
+
linearVelocity?: Parameters<Vector3['set']>
|
|
25
|
+
|
|
26
|
+
/** The angular velocity of this body.
|
|
27
|
+
* Default: zero velocity.
|
|
28
|
+
*/
|
|
29
|
+
angularVelocity?: Parameters<Euler['set']>
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* The scaling factor applied to the gravity affecting the rigid-body.
|
|
33
|
+
* Default: 1.0
|
|
34
|
+
*/
|
|
35
|
+
gravityScale?: number
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Whether or not Continous Collision Detection is enabled for this rigid-body.
|
|
39
|
+
* https://rapier.rs/docs/user_guides/javascript/rigid_bodies#continuous-collision-detection
|
|
40
|
+
* @default false
|
|
41
|
+
*/
|
|
42
|
+
ccd?: boolean
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Locks all rotations that would have resulted from forces on the created rigid-body.
|
|
46
|
+
*/
|
|
47
|
+
lockRotations?: boolean
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Locks all translations that would have resulted from forces on the created rigid-body.
|
|
51
|
+
*/
|
|
52
|
+
lockTranslations?: boolean
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Allow rotation of this rigid-body only along specific axes.
|
|
56
|
+
*/
|
|
57
|
+
enabledRotations?: Boolean3Array
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Allow rotation of this rigid-body only along specific axes.
|
|
61
|
+
*/
|
|
62
|
+
enabledTranslations?: Boolean3Array
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Dominance is a non-realistic, but sometimes useful, feature.
|
|
66
|
+
* It can be used to make one rigid-body immune to forces
|
|
67
|
+
* originating from contacts with some other bodies.
|
|
68
|
+
*
|
|
69
|
+
* Number in the range -127 to 127, default is 0
|
|
70
|
+
*/
|
|
71
|
+
dominance?: number
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Damping lets you slow down a rigid-body automatically. This can be used to
|
|
75
|
+
* achieve a wide variety of effects like fake air friction. Larger values of
|
|
76
|
+
* damping coefficients lead to a stronger slow-downs. Their default
|
|
77
|
+
* values are 0.0 (no damping at all).
|
|
78
|
+
*/
|
|
79
|
+
linearDamping?: number
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Damping lets you slow down a rigid-body automatically. This can be used to
|
|
83
|
+
* achieve a wide variety of effects like fake air friction. Larger values of
|
|
84
|
+
* damping coefficients lead to a stronger slow-downs. Their default
|
|
85
|
+
* values are 0.0 (no damping at all).
|
|
86
|
+
*/
|
|
87
|
+
angularDamping?: number
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Set the rigidBody as enabled or disabled.
|
|
91
|
+
*/
|
|
92
|
+
enabled?: boolean
|
|
67
93
|
}
|
|
68
|
-
|
|
94
|
+
|
|
95
|
+
export default class RigidBody extends SvelteComponentTyped<RigidBodyProps> {}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
<script
|
|
1
|
+
<script
|
|
2
|
+
context="module"
|
|
3
|
+
|
|
4
|
+
>import { onDestroy, setContext, tick } from 'svelte';
|
|
2
5
|
import { useFrameHandler } from '../../hooks/useFrameHandler';
|
|
3
6
|
import { createRapierContext } from '../../lib/createRapierContext';
|
|
4
7
|
</script>
|
|
5
8
|
|
|
6
|
-
<script>
|
|
7
|
-
export let gravity = { y: -9.81 };
|
|
9
|
+
<script>export let gravity = [0, -9.81, 0];
|
|
8
10
|
export let rawIntegrationParameters = undefined;
|
|
9
11
|
export let rawIslands = undefined;
|
|
10
12
|
export let rawBroadPhase = undefined;
|
|
@@ -18,11 +20,13 @@ export let rawQueryPipeline = undefined;
|
|
|
18
20
|
export let rawPhysicsPipeline = undefined;
|
|
19
21
|
export let rawSerializationPipeline = undefined;
|
|
20
22
|
export let rawDebugRenderPipeline = undefined;
|
|
21
|
-
|
|
23
|
+
export let order = undefined;
|
|
24
|
+
const rapierContext = createRapierContext({ x: gravity[0], y: gravity[1], z: gravity[2] }, rawIntegrationParameters, rawIslands, rawBroadPhase, rawNarrowPhase, rawBodies, rawColliders, rawImpulseJoints, rawMultibodyJoints, rawCCDSolver, rawQueryPipeline, rawPhysicsPipeline, rawSerializationPipeline, rawDebugRenderPipeline);
|
|
22
25
|
setContext('threlte-rapier-context', rapierContext);
|
|
23
|
-
$: if (gravity !== undefined)
|
|
24
|
-
rapierContext.world.gravity =
|
|
25
|
-
|
|
26
|
+
$: if (gravity !== undefined) {
|
|
27
|
+
rapierContext.world.gravity = { x: gravity[0], y: gravity[1], z: gravity[2] };
|
|
28
|
+
}
|
|
29
|
+
useFrameHandler(rapierContext, order);
|
|
26
30
|
onDestroy(async () => {
|
|
27
31
|
await tick();
|
|
28
32
|
rapierContext.world.free();
|
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import { SvelteComponentTyped } from "svelte";
|
|
2
|
-
import type { InnerWorldProperties } from '../../types/components';
|
|
3
2
|
declare const __propDef: {
|
|
4
3
|
props: {
|
|
5
|
-
gravity?:
|
|
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?:
|
|
4
|
+
gravity?: [x: number, y: number, z: number] | undefined;
|
|
5
|
+
rawIntegrationParameters?: import("@dimforge/rapier3d-compat/rapier_wasm3d").RawIntegrationParameters | undefined;
|
|
6
|
+
rawIslands?: import("@dimforge/rapier3d-compat/rapier_wasm3d").RawIslandManager | undefined;
|
|
7
|
+
rawBroadPhase?: import("@dimforge/rapier3d-compat/rapier_wasm3d").RawBroadPhase | undefined;
|
|
8
|
+
rawNarrowPhase?: import("@dimforge/rapier3d-compat/rapier_wasm3d").RawNarrowPhase | undefined;
|
|
9
|
+
rawBodies?: import("@dimforge/rapier3d-compat/rapier_wasm3d").RawRigidBodySet | undefined;
|
|
10
|
+
rawColliders?: import("@dimforge/rapier3d-compat/rapier_wasm3d").RawColliderSet | undefined;
|
|
11
|
+
rawImpulseJoints?: import("@dimforge/rapier3d-compat/rapier_wasm3d").RawImpulseJointSet | undefined;
|
|
12
|
+
rawMultibodyJoints?: import("@dimforge/rapier3d-compat/rapier_wasm3d").RawMultibodyJointSet | undefined;
|
|
13
|
+
rawCCDSolver?: import("@dimforge/rapier3d-compat/rapier_wasm3d").RawCCDSolver | undefined;
|
|
14
|
+
rawQueryPipeline?: import("@dimforge/rapier3d-compat/rapier_wasm3d").RawQueryPipeline | undefined;
|
|
15
|
+
rawPhysicsPipeline?: import("@dimforge/rapier3d-compat/rapier_wasm3d").RawPhysicsPipeline | undefined;
|
|
16
|
+
rawSerializationPipeline?: import("@dimforge/rapier3d-compat/rapier_wasm3d").RawSerializationPipeline | undefined;
|
|
17
|
+
rawDebugRenderPipeline?: import("@dimforge/rapier3d-compat/rapier_wasm3d").RawDebugRenderPipeline | undefined;
|
|
18
|
+
order?: number | undefined;
|
|
19
19
|
};
|
|
20
20
|
events: {
|
|
21
21
|
[evt: string]: CustomEvent<any>;
|
|
@@ -1,13 +1,17 @@
|
|
|
1
|
-
<script
|
|
1
|
+
<script
|
|
2
|
+
context="module"
|
|
3
|
+
|
|
4
|
+
>import RAPIER from '@dimforge/rapier3d-compat';
|
|
2
5
|
import { onMount } from 'svelte';
|
|
3
6
|
import { writable } from 'svelte/store';
|
|
4
7
|
/**
|
|
5
8
|
* RAPIER.init() should only be called once
|
|
6
9
|
*/
|
|
7
|
-
|
|
10
|
+
const initialized = writable(false);
|
|
8
11
|
</script>
|
|
9
12
|
|
|
10
13
|
<script>import InnerWorld from './InnerWorld.svelte';
|
|
14
|
+
// self
|
|
11
15
|
export let gravity = undefined;
|
|
12
16
|
export let rawIntegrationParameters = undefined;
|
|
13
17
|
export let rawIslands = undefined;
|
|
@@ -22,6 +26,12 @@ export let rawQueryPipeline = undefined;
|
|
|
22
26
|
export let rawPhysicsPipeline = undefined;
|
|
23
27
|
export let rawSerializationPipeline = undefined;
|
|
24
28
|
export let rawDebugRenderPipeline = undefined;
|
|
29
|
+
/**
|
|
30
|
+
* The property order is passed to the useFrame handler.
|
|
31
|
+
* Use this to control when the rapier physics engine is updating the scene.
|
|
32
|
+
* @default undefined
|
|
33
|
+
*/
|
|
34
|
+
export let order = undefined;
|
|
25
35
|
let error = false;
|
|
26
36
|
const init = async () => {
|
|
27
37
|
if ($initialized)
|
|
@@ -53,6 +63,7 @@ onMount(init);
|
|
|
53
63
|
{rawPhysicsPipeline}
|
|
54
64
|
{rawSerializationPipeline}
|
|
55
65
|
{rawDebugRenderPipeline}
|
|
66
|
+
{order}
|
|
56
67
|
>
|
|
57
68
|
<slot />
|
|
58
69
|
</InnerWorld>
|
|
@@ -1,33 +1,37 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
1
|
+
import type {
|
|
2
|
+
RawBroadPhase,
|
|
3
|
+
RawCCDSolver,
|
|
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 { SvelteComponentTyped } from 'svelte'
|
|
17
|
+
import type { Vector3 } from 'three'
|
|
18
|
+
|
|
19
|
+
export type WorldProps = {
|
|
20
|
+
gravity?: Parameters<Vector3['set']>
|
|
21
|
+
rawIntegrationParameters?: RawIntegrationParameters
|
|
22
|
+
rawIslands?: RawIslandManager
|
|
23
|
+
rawBroadPhase?: RawBroadPhase
|
|
24
|
+
rawNarrowPhase?: RawNarrowPhase
|
|
25
|
+
rawBodies?: RawRigidBodySet
|
|
26
|
+
rawColliders?: RawColliderSet
|
|
27
|
+
rawImpulseJoints?: RawImpulseJointSet
|
|
28
|
+
rawMultibodyJoints?: RawMultibodyJointSet
|
|
29
|
+
rawCCDSolver?: RawCCDSolver
|
|
30
|
+
rawQueryPipeline?: RawQueryPipeline
|
|
31
|
+
rawPhysicsPipeline?: RawPhysicsPipeline
|
|
32
|
+
rawSerializationPipeline?: RawSerializationPipeline
|
|
33
|
+
rawDebugRenderPipeline?: RawDebugRenderPipeline
|
|
34
|
+
order?: number
|
|
32
35
|
}
|
|
33
|
-
|
|
36
|
+
|
|
37
|
+
export default class World extends SvelteComponentTyped<WorldProps> {}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { FixedImpulseJoint } from '@dimforge/rapier3d-compat';
|
|
2
|
-
import
|
|
3
|
-
export declare const useFixedJoint: (anchorA:
|
|
2
|
+
import { Euler } from 'three';
|
|
3
|
+
export declare const useFixedJoint: (anchorA: [x: number, y: number, z: number], frameA: Parameters<Euler['set']> | Euler, anchorB: [x: number, y: number, z: number], frameB: Parameters<Euler['set']> | Euler) => {
|
|
4
4
|
joint: import("svelte/store").Writable<FixedImpulseJoint>;
|
|
5
5
|
rigidBodyA: import("svelte/store").Writable<import("@dimforge/rapier3d-compat").RigidBody | undefined>;
|
|
6
6
|
rigidBodyB: import("svelte/store").Writable<import("@dimforge/rapier3d-compat").RigidBody | undefined>;
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { rotationToQuaternion } from '../lib/rotationToQuaternion';
|
|
1
|
+
import { Euler, Quaternion, Vector3 } from 'three';
|
|
3
2
|
import { useJoint } from './useJoint';
|
|
4
3
|
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
5
4
|
export const useFixedJoint = (anchorA, frameA, anchorB, frameB) => {
|
|
5
|
+
const jaA = anchorA instanceof Vector3 ? anchorA : new Vector3(...anchorA);
|
|
6
|
+
const jfA = new Quaternion().setFromEuler(frameA instanceof Euler ? frameA : new Euler(...frameA));
|
|
7
|
+
const jaB = anchorB instanceof Vector3 ? anchorB : new Vector3(...anchorB);
|
|
8
|
+
const jfB = new Quaternion().setFromEuler(frameB instanceof Euler ? frameB : new Euler(...frameB));
|
|
6
9
|
return useJoint((rbA, rbB, { world, rapier }) => {
|
|
7
|
-
const params = rapier.JointData.fixed(
|
|
10
|
+
const params = rapier.JointData.fixed(jaA, jfA, jaB, jfB);
|
|
8
11
|
return world.createImpulseJoint(params, rbA, rbB, true);
|
|
9
12
|
});
|
|
10
13
|
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { RapierContext } from '../types/types';
|
|
2
|
-
export declare const useFrameHandler: (ctx: RapierContext) => void;
|
|
2
|
+
export declare const useFrameHandler: (ctx: RapierContext, order?: number) => void;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Collider, EventQueue } from '@dimforge/rapier3d-compat';
|
|
2
2
|
import { useFrame } from '@threlte/core';
|
|
3
|
+
import { derived } from 'svelte/store';
|
|
3
4
|
import { Object3D, Quaternion, Vector3 } from 'three';
|
|
4
5
|
const tempObject = new Object3D();
|
|
5
6
|
const tempVector3 = new Vector3();
|
|
@@ -22,17 +23,14 @@ const getEventDispatchers = (ctx, collider1, collider2) => {
|
|
|
22
23
|
rigidBodyDispatcher2
|
|
23
24
|
};
|
|
24
25
|
};
|
|
25
|
-
export const useFrameHandler = (ctx) => {
|
|
26
|
+
export const useFrameHandler = (ctx, order) => {
|
|
26
27
|
const eventQueue = new EventQueue(false);
|
|
27
|
-
|
|
28
|
-
useFrame(() => {
|
|
28
|
+
const { start, started, stop } = useFrame((_, delta) => {
|
|
29
29
|
// if (!eventQueue) return
|
|
30
30
|
const { world } = ctx;
|
|
31
31
|
// Set timestep to current delta, to allow for variable frame rates
|
|
32
32
|
// We cap the delta at 100, so that the physics simulation doesn't get wild
|
|
33
|
-
|
|
34
|
-
const delta = Math.min(100, now - time);
|
|
35
|
-
world.timestep = delta / 1000;
|
|
33
|
+
world.timestep = Math.min(0.1, delta);
|
|
36
34
|
world.step(eventQueue);
|
|
37
35
|
// Update meshes
|
|
38
36
|
ctx.rigidBodyObjects.forEach((mesh, handle) => {
|
|
@@ -227,6 +225,9 @@ export const useFrameHandler = (ctx) => {
|
|
|
227
225
|
});
|
|
228
226
|
}
|
|
229
227
|
});
|
|
230
|
-
|
|
231
|
-
|
|
228
|
+
}, { order });
|
|
229
|
+
// replacing the original pause and resume functions as well as the paused property
|
|
230
|
+
ctx.pause = () => stop();
|
|
231
|
+
ctx.resume = () => start();
|
|
232
|
+
ctx.paused = derived(started, (started) => !started);
|
|
232
233
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { PrismaticImpulseJoint } from '@dimforge/rapier3d-compat';
|
|
2
|
-
import
|
|
3
|
-
export declare const usePrismaticJoint: (anchorA:
|
|
2
|
+
import { Vector3 } from 'three';
|
|
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]) => {
|
|
4
4
|
joint: import("svelte/store").Writable<PrismaticImpulseJoint>;
|
|
5
5
|
rigidBodyA: import("svelte/store").Writable<import("@dimforge/rapier3d-compat").RigidBody | undefined>;
|
|
6
6
|
rigidBodyB: import("svelte/store").Writable<import("@dimforge/rapier3d-compat").RigidBody | undefined>;
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Vector3 } from 'three';
|
|
2
2
|
import { useJoint } from './useJoint';
|
|
3
3
|
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
4
4
|
export const usePrismaticJoint = (anchorA, anchorB, axis, limits) => {
|
|
5
5
|
return useJoint((rbA, rbB, { world, rapier }) => {
|
|
6
|
-
const
|
|
6
|
+
const jaA = anchorA instanceof Vector3 ? anchorA : new Vector3(...anchorA);
|
|
7
|
+
const jaB = anchorB instanceof Vector3 ? anchorB : new Vector3(...anchorB);
|
|
8
|
+
const jAxis = (axis instanceof Vector3 ? axis : new Vector3(...axis)).normalize();
|
|
9
|
+
const params = rapier.JointData.prismatic(jaA, jaB, jAxis);
|
|
7
10
|
if (limits) {
|
|
8
11
|
params.limitsEnabled = true;
|
|
9
12
|
params.limits = limits;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { RevoluteImpulseJoint } from '@dimforge/rapier3d-compat';
|
|
2
|
-
import
|
|
3
|
-
export declare const useRevoluteJoint: (anchorA:
|
|
2
|
+
import { Vector3 } from 'three';
|
|
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]) => {
|
|
4
4
|
joint: import("svelte/store").Writable<RevoluteImpulseJoint>;
|
|
5
5
|
rigidBodyA: import("svelte/store").Writable<import("@dimforge/rapier3d-compat").RigidBody | undefined>;
|
|
6
6
|
rigidBodyB: import("svelte/store").Writable<import("@dimforge/rapier3d-compat").RigidBody | undefined>;
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Vector3 } from 'three';
|
|
2
2
|
import { useJoint } from './useJoint';
|
|
3
3
|
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
4
4
|
export const useRevoluteJoint = (anchorA, anchorB, axis, limits) => {
|
|
5
5
|
return useJoint((rbA, rbB, { world, rapier }) => {
|
|
6
|
-
const
|
|
6
|
+
const jaA = anchorA instanceof Vector3 ? anchorA : new Vector3(...anchorA);
|
|
7
|
+
const jaB = anchorB instanceof Vector3 ? anchorB : new Vector3(...anchorB);
|
|
8
|
+
const jAxis = (axis instanceof Vector3 ? axis : new Vector3(...axis)).normalize();
|
|
9
|
+
const params = rapier.JointData.revolute(jaA, jaB, jAxis);
|
|
7
10
|
if (limits) {
|
|
8
11
|
params.limitsEnabled = true;
|
|
9
12
|
params.limits = limits;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { SphericalImpulseJoint } from '@dimforge/rapier3d-compat';
|
|
2
|
-
import
|
|
3
|
-
export declare const useSphericalJoint: (anchorA:
|
|
2
|
+
import { Vector3 } from 'three';
|
|
3
|
+
export declare const useSphericalJoint: (anchorA: Parameters<Vector3['set']> | Vector3, anchorB: Parameters<Vector3['set']> | Vector3) => {
|
|
4
4
|
joint: import("svelte/store").Writable<SphericalImpulseJoint>;
|
|
5
5
|
rigidBodyA: import("svelte/store").Writable<import("@dimforge/rapier3d-compat").RigidBody | undefined>;
|
|
6
6
|
rigidBodyB: import("svelte/store").Writable<import("@dimforge/rapier3d-compat").RigidBody | undefined>;
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Vector3 } from 'three';
|
|
2
2
|
import { useJoint } from './useJoint';
|
|
3
3
|
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
4
4
|
export const useSphericalJoint = (anchorA, anchorB) => {
|
|
5
5
|
return useJoint((rbA, rbB, { world, rapier }) => {
|
|
6
|
-
const
|
|
6
|
+
const jaA = anchorA instanceof Vector3 ? anchorA : new Vector3(...anchorA);
|
|
7
|
+
const jaB = anchorB instanceof Vector3 ? anchorB : new Vector3(...anchorB);
|
|
8
|
+
const params = rapier.JointData.spherical(jaA, jaB);
|
|
7
9
|
return world.createImpulseJoint(params, rbA, rbB, true);
|
|
8
10
|
});
|
|
9
11
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ export { default as Collider } from './components/Colliders/Collider.svelte';
|
|
|
13
13
|
export { default as AutoColliders } from './components/Colliders/AutoColliders.svelte';
|
|
14
14
|
export { default as CollisionGroups } from './components/CollisionGroups/CollisionGroups.svelte';
|
|
15
15
|
export { default as Attractor } from './components/Attractor/Attractor.svelte';
|
|
16
|
+
export { computeBitMask } from './lib/computeBitMask';
|
|
16
17
|
export { default as BasicPlayerController } from './recipes/BasicPlayerController.svelte';
|
|
17
|
-
export type { AutoCollidersProperties,
|
|
18
|
+
export type { AutoCollidersProperties, AttractorProperties } from './types/components';
|
|
18
19
|
export type { CollisionGroupsBitMask, AutoCollidersShapes, ColliderEventDispatcher, ColliderShapes, RapierContext, RigidBodyEventDispatcher, CollisionEnterEvent, CollisionExitEvent, SensorEnterEvent, SensorExitEvent, ContactEvent } from './types/types';
|
package/dist/index.js
CHANGED
|
@@ -16,5 +16,7 @@ export { default as Collider } from './components/Colliders/Collider.svelte';
|
|
|
16
16
|
export { default as AutoColliders } from './components/Colliders/AutoColliders.svelte';
|
|
17
17
|
export { default as CollisionGroups } from './components/CollisionGroups/CollisionGroups.svelte';
|
|
18
18
|
export { default as Attractor } from './components/Attractor/Attractor.svelte';
|
|
19
|
+
// lib
|
|
20
|
+
export { computeBitMask } from './lib/computeBitMask';
|
|
19
21
|
// recipes
|
|
20
22
|
export { default as BasicPlayerController } from './recipes/BasicPlayerController.svelte';
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
export declare const applyTransforms: (object: Object3D, position?: Position, rotation?: Rotation, scale?: Scale, lookAt?: LookAt) => void;
|
|
1
|
+
import type { Euler, Object3D, Vector3 } from 'three';
|
|
2
|
+
export declare const applyTransforms: (object: Object3D, position?: Parameters<Vector3['set']>, rotation?: Parameters<Euler['set']>, scale?: Parameters<Vector3['set']>) => void;
|
|
@@ -1,17 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
object.lookAt(lookAt.getWorldPosition(new Vector3()));
|
|
9
|
-
}
|
|
10
|
-
else if (lookAt) {
|
|
11
|
-
object.lookAt(positionToVector3(lookAt));
|
|
12
|
-
}
|
|
13
|
-
else {
|
|
14
|
-
object.rotation.copy(rotationToEuler(rotation));
|
|
15
|
-
}
|
|
16
|
-
object.scale.copy(scaleToVector3(scale));
|
|
1
|
+
export const applyTransforms = (object, position, rotation, scale) => {
|
|
2
|
+
if (position)
|
|
3
|
+
object.position.set(...position);
|
|
4
|
+
if (rotation)
|
|
5
|
+
object.rotation.set(...rotation);
|
|
6
|
+
if (scale)
|
|
7
|
+
object.scale.set(...scale);
|
|
17
8
|
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
declare type N = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15;
|
|
2
|
+
export declare type Groups = N[];
|
|
3
|
+
export declare type MembershipsAndFilter = N[];
|
|
4
|
+
export declare const computeBitMask: (groups: Groups, filter: MembershipsAndFilter, memberships: MembershipsAndFilter) => number;
|
|
5
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export const computeBitMask = (groups, filter, memberships) => {
|
|
2
|
+
if (groups !== undefined) {
|
|
3
|
+
// groups is setting the filter and memberships at once
|
|
4
|
+
const g = groups;
|
|
5
|
+
const mask = g.reduce((acc, f) => {
|
|
6
|
+
return acc | (1 << f);
|
|
7
|
+
}, 0) |
|
|
8
|
+
g.reduce((acc, m) => {
|
|
9
|
+
return acc | (1 << (m + 16));
|
|
10
|
+
}, 0);
|
|
11
|
+
return mask;
|
|
12
|
+
}
|
|
13
|
+
const mask = memberships.reduce((acc, f) => {
|
|
14
|
+
return acc | (1 << f);
|
|
15
|
+
}, 0) |
|
|
16
|
+
filter.reduce((acc, m) => {
|
|
17
|
+
return acc | (1 << (m + 16));
|
|
18
|
+
}, 0);
|
|
19
|
+
return mask;
|
|
20
|
+
};
|
|
@@ -14,4 +14,7 @@ export declare const createRapierContext: (gravity: RAPIER.Vector, rawIntegratio
|
|
|
14
14
|
addRigidBodyToContext: (rigidBody: RigidBody, object: Object3D, eventDispatcher: RigidBodyEventDispatcher) => void;
|
|
15
15
|
removeRigidBodyFromContext: (rigidBody: RigidBody) => void;
|
|
16
16
|
debug: import("svelte/store").Writable<boolean>;
|
|
17
|
+
pause: () => void;
|
|
18
|
+
resume: () => void;
|
|
19
|
+
paused: import("svelte/store").Readable<boolean>;
|
|
17
20
|
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import RAPIER from '@dimforge/rapier3d-compat';
|
|
2
|
-
import {
|
|
2
|
+
import { currentWritable } from '@threlte/core';
|
|
3
|
+
import { readable, writable } from 'svelte/store';
|
|
3
4
|
export const createRapierContext = (...args) => {
|
|
4
5
|
const world = new RAPIER.World(...args);
|
|
5
6
|
const colliderObjects = new Map();
|
|
@@ -42,6 +43,11 @@ export const createRapierContext = (...args) => {
|
|
|
42
43
|
rigidBodyObjects.delete(rigidBody.handle);
|
|
43
44
|
rigidBodyEventDispatchers.delete(rigidBody.handle);
|
|
44
45
|
};
|
|
46
|
+
// Dummy functions, will be replaced by useFrameHandler fn
|
|
47
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
48
|
+
const pause = () => { };
|
|
49
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
50
|
+
const resume = () => { };
|
|
45
51
|
return {
|
|
46
52
|
rapier: RAPIER,
|
|
47
53
|
world,
|
|
@@ -54,5 +60,8 @@ export const createRapierContext = (...args) => {
|
|
|
54
60
|
addRigidBodyToContext,
|
|
55
61
|
removeRigidBodyFromContext,
|
|
56
62
|
debug: writable(false),
|
|
63
|
+
pause,
|
|
64
|
+
resume,
|
|
65
|
+
paused: readable(false)
|
|
57
66
|
};
|
|
58
67
|
};
|