@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,34 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
import type { GravityType } from '../../types/types'
|
|
5
|
-
|
|
6
|
-
type AttractorProps = Props<Group> & {
|
|
7
|
-
/**
|
|
8
|
-
* The strength factor applied to the impulse affecting rigid-bodies within range. For newtonian
|
|
9
|
-
* calculations, strength is treated as m1 mass.
|
|
10
|
-
* Default: 1.0
|
|
11
|
-
*/
|
|
12
|
-
strength?: number
|
|
13
|
-
/**
|
|
14
|
-
* The radius for the Attractor's sphere of influence within which rigid-bodies will be affected.
|
|
15
|
-
* Default: 10.0
|
|
16
|
-
*/
|
|
17
|
-
range?: number
|
|
18
|
-
/**
|
|
19
|
-
* The method of calculating gravity on rigid bodies within range.
|
|
20
|
-
* 'static' = the same force (strength) is applied on bodies within range, regardless of distance
|
|
21
|
-
* 'linear' = force is calculated as strength * distance / range (force decreases the farther a body is from the attractor position)
|
|
22
|
-
* 'newtonian' = force is calculated as gravitationalConstant * mass1 * mass2 / Math.pow(distance, 2)
|
|
23
|
-
* Default: 'static'
|
|
24
|
-
*/
|
|
25
|
-
gravityType?: GravityType
|
|
26
|
-
/**
|
|
27
|
-
* The gravitational constant used to calculate force in newtonian calculations. Most people probably won't use this,
|
|
28
|
-
* but it provides an option for more realistic physics simulations.
|
|
29
|
-
* Default: 6.673e-11
|
|
30
|
-
*/
|
|
31
|
-
gravitationalConstant?: number
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export default class Attractor extends SvelteComponent<AttractorProps> {}
|
|
1
|
+
import type { AttractorProps } from './types';
|
|
2
|
+
declare const Attractor: import("svelte").Component<AttractorProps, {}, "ref">;
|
|
3
|
+
export default Attractor;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Props } from '@threlte/core';
|
|
2
|
+
import type { Group } from 'three';
|
|
3
|
+
import type { GravityType } from '../../types/types';
|
|
4
|
+
export type AttractorProps = Props<Group> & {
|
|
5
|
+
/**
|
|
6
|
+
* The strength factor applied to the impulse affecting rigid-bodies within range. For newtonian
|
|
7
|
+
* calculations, strength is treated as m1 mass.
|
|
8
|
+
* Default: 1.0
|
|
9
|
+
*/
|
|
10
|
+
strength?: number;
|
|
11
|
+
/**
|
|
12
|
+
* The radius for the Attractor's sphere of influence within which rigid-bodies will be affected.
|
|
13
|
+
* Default: 10.0
|
|
14
|
+
*/
|
|
15
|
+
range?: number;
|
|
16
|
+
/**
|
|
17
|
+
* The method of calculating gravity on rigid bodies within range.
|
|
18
|
+
* 'static' = the same force (strength) is applied on bodies within range, regardless of distance
|
|
19
|
+
* 'linear' = force is calculated as strength * distance / range (force decreases the farther a body is from the attractor position)
|
|
20
|
+
* 'newtonian' = force is calculated as gravitationalConstant * mass1 * mass2 / Math.pow(distance, 2)
|
|
21
|
+
* Default: 'static'
|
|
22
|
+
*/
|
|
23
|
+
gravityType?: GravityType;
|
|
24
|
+
/**
|
|
25
|
+
* The gravitational constant used to calculate force in newtonian calculations. Most people probably won't use this,
|
|
26
|
+
* but it provides an option for more realistic physics simulations.
|
|
27
|
+
* Default: 6.673e-11
|
|
28
|
+
*/
|
|
29
|
+
gravitationalConstant?: number;
|
|
30
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/components/Colliders/{AutoColliders.svelte → AutoColliders/AutoColliders.svelte}
RENAMED
|
@@ -1,16 +1,19 @@
|
|
|
1
|
-
<script
|
|
2
|
-
|
|
1
|
+
<script
|
|
2
|
+
lang="ts"
|
|
3
|
+
generics="TMassDef extends MassDef"
|
|
4
|
+
>import { ActiveCollisionTypes, CoefficientCombineRule } from '@dimforge/rapier3d-compat';
|
|
5
|
+
import { createParentObject3DContext, useParentObject3D, watch } from '@threlte/core';
|
|
3
6
|
import { onDestroy, onMount } from 'svelte';
|
|
4
7
|
import { Group } from 'three';
|
|
5
|
-
import { useCollisionGroups } from '
|
|
6
|
-
import { useRapier } from '
|
|
7
|
-
import { useRigidBody } from '
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
let { shape = 'convexHull', restitution, restitutionCombineRule, friction, frictionCombineRule, sensor, contactForceEventThreshold, density, mass, centerOfMass, principalAngularInertia, angularInertiaLocalFrame,
|
|
8
|
+
import { useCollisionGroups } from '../../../hooks/useCollisionGroups';
|
|
9
|
+
import { useRapier } from '../../../hooks/useRapier';
|
|
10
|
+
import { useRigidBody } from '../../../hooks/useRigidBody';
|
|
11
|
+
import { applyColliderActiveEvents } from '../../../lib/applyColliderActiveEvents';
|
|
12
|
+
import { createCollidersFromChildren } from '../../../lib/createCollidersFromChildren';
|
|
13
|
+
import { eulerToQuaternion } from '../../../lib/eulerToQuaternion';
|
|
14
|
+
import { useParentRigidbodyObject } from '../../../lib/rigidBodyObjectContext';
|
|
15
|
+
import { useCreateEvent } from '../../../lib/useCreateEvent';
|
|
16
|
+
let { shape = 'convexHull', restitution, restitutionCombineRule, friction, frictionCombineRule, sensor, contactForceEventThreshold, density, mass, centerOfMass, principalAngularInertia, angularInertiaLocalFrame, colliders = $bindable(), oncreate, oncollisionenter, oncollisionexit, oncontact, onsensorenter, onsensorexit, children } = $props();
|
|
14
17
|
const group = new Group();
|
|
15
18
|
const { updateRef } = useCreateEvent(oncreate);
|
|
16
19
|
const rigidBody = useRigidBody();
|
|
@@ -63,6 +66,10 @@ const create = () => {
|
|
|
63
66
|
});
|
|
64
67
|
updateRef(colliders);
|
|
65
68
|
};
|
|
69
|
+
/**
|
|
70
|
+
* Refresh the colliders.
|
|
71
|
+
*/
|
|
72
|
+
export const refresh = () => create();
|
|
66
73
|
onMount(() => {
|
|
67
74
|
create();
|
|
68
75
|
});
|
|
@@ -70,8 +77,14 @@ onMount(() => {
|
|
|
70
77
|
* Cleanup
|
|
71
78
|
*/
|
|
72
79
|
onDestroy(cleanup);
|
|
80
|
+
const parent3DObject = useParentObject3D();
|
|
81
|
+
createParentObject3DContext(group);
|
|
82
|
+
watch(parent3DObject, (parent) => {
|
|
83
|
+
parent?.add(group);
|
|
84
|
+
return () => {
|
|
85
|
+
parent?.remove(group);
|
|
86
|
+
};
|
|
87
|
+
});
|
|
73
88
|
</script>
|
|
74
89
|
|
|
75
|
-
|
|
76
|
-
{@render children?.({ colliders: colliders ?? [], refresh })}
|
|
77
|
-
</SceneGraphObject>
|
|
90
|
+
{@render children?.({ colliders: colliders ?? [], refresh })}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { AutoCollidersProps, MassDef } from './types';
|
|
2
|
+
declare class __sveltets_Render<TMassDef extends MassDef> {
|
|
3
|
+
props(): AutoCollidersProps<TMassDef>;
|
|
4
|
+
events(): {};
|
|
5
|
+
slots(): {};
|
|
6
|
+
bindings(): "colliders";
|
|
7
|
+
exports(): {
|
|
8
|
+
/**
|
|
9
|
+
* Refresh the colliders.
|
|
10
|
+
*/ refresh: () => void;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
interface $$IsomorphicComponent {
|
|
14
|
+
new <TMassDef extends MassDef>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<TMassDef>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<TMassDef>['props']>, ReturnType<__sveltets_Render<TMassDef>['events']>, ReturnType<__sveltets_Render<TMassDef>['slots']>> & {
|
|
15
|
+
$$bindings?: ReturnType<__sveltets_Render<TMassDef>['bindings']>;
|
|
16
|
+
} & ReturnType<__sveltets_Render<TMassDef>['exports']>;
|
|
17
|
+
<TMassDef extends MassDef>(internal: unknown, props: ReturnType<__sveltets_Render<TMassDef>['props']> & {}): ReturnType<__sveltets_Render<TMassDef>['exports']>;
|
|
18
|
+
z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
|
|
19
|
+
}
|
|
20
|
+
declare const AutoColliders: $$IsomorphicComponent;
|
|
21
|
+
type AutoColliders<TMassDef extends MassDef> = InstanceType<typeof AutoColliders<TMassDef>>;
|
|
22
|
+
export default AutoColliders;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { CoefficientCombineRule, Collider } from '@dimforge/rapier3d-compat';
|
|
2
|
+
import { type Snippet } from 'svelte';
|
|
3
|
+
import type { Euler, Vector3 } from 'three';
|
|
4
|
+
import type { AutoCollidersShapes, ColliderEvents, CreateEvent } from '../../../types/types';
|
|
5
|
+
type BaseProps = {
|
|
6
|
+
/**
|
|
7
|
+
* The shape of the collider.
|
|
8
|
+
*/
|
|
9
|
+
shape?: AutoCollidersShapes;
|
|
10
|
+
/** The restitution coefficient of this collider. */
|
|
11
|
+
restitution?: number;
|
|
12
|
+
/** he rule used to combine the restitution coefficients of two colliders involved in a contact. */
|
|
13
|
+
restitutionCombineRule?: CoefficientCombineRule;
|
|
14
|
+
/** The friction coefficient of this collider. */
|
|
15
|
+
friction?: number;
|
|
16
|
+
/** The rule used to combine the friction coefficients of two colliders involved in a contact. */
|
|
17
|
+
frictionCombineRule?: CoefficientCombineRule;
|
|
18
|
+
/** Whether this collider is a sensor. A sensor collider does not generate
|
|
19
|
+
* contacts. They only generate intersection events when one sensor collider
|
|
20
|
+
* and another collider start/stop touching. Sensor colliders are generally
|
|
21
|
+
* used to detect when something enters an area. Note that, for symmetry with
|
|
22
|
+
* non-sensor colliders, sensors do contribute to the mass of a rigid-body
|
|
23
|
+
* they are attached to.
|
|
24
|
+
*/
|
|
25
|
+
sensor?: boolean;
|
|
26
|
+
colliders?: Collider[];
|
|
27
|
+
/** The total force magnitude beyond which a contact force event can be emitted. */
|
|
28
|
+
contactForceEventThreshold?: number;
|
|
29
|
+
};
|
|
30
|
+
type Density = {
|
|
31
|
+
/** The density of this collider. */
|
|
32
|
+
density: number;
|
|
33
|
+
mass?: never;
|
|
34
|
+
centerOfMass?: never;
|
|
35
|
+
principalAngularInertia?: never;
|
|
36
|
+
angularInertiaLocalFrame?: never;
|
|
37
|
+
};
|
|
38
|
+
type Mass = {
|
|
39
|
+
/** The mass of this collider. */
|
|
40
|
+
mass: number;
|
|
41
|
+
density?: never;
|
|
42
|
+
centerOfMass?: never;
|
|
43
|
+
principalAngularInertia?: never;
|
|
44
|
+
angularInertiaLocalFrame?: never;
|
|
45
|
+
};
|
|
46
|
+
type MassProperties = {
|
|
47
|
+
/** The mass of this collider. */
|
|
48
|
+
mass: number;
|
|
49
|
+
/** The center of mass of this collider. */
|
|
50
|
+
centerOfMass: Parameters<Vector3['set']>;
|
|
51
|
+
/** The principal angular inertia of this collider. */
|
|
52
|
+
principalAngularInertia: Parameters<Vector3['set']>;
|
|
53
|
+
/** The angular inertia local frame of this collider. */
|
|
54
|
+
angularInertiaLocalFrame: Parameters<Euler['set']>;
|
|
55
|
+
density?: never;
|
|
56
|
+
};
|
|
57
|
+
type NoMassProperties = {
|
|
58
|
+
density?: never;
|
|
59
|
+
mass?: never;
|
|
60
|
+
centerOfMass?: never;
|
|
61
|
+
principalAngularInertia?: never;
|
|
62
|
+
angularInertiaLocalFrame?: never;
|
|
63
|
+
};
|
|
64
|
+
export type MassDef = Density | Mass | MassProperties | NoMassProperties;
|
|
65
|
+
type MassProps<TMassDef extends MassDef> = TMassDef extends Density ? Density : TMassDef extends MassProperties ? MassProperties : TMassDef extends Mass ? Mass : NoMassProperties;
|
|
66
|
+
export type AutoCollidersProps<TMassDef extends MassDef> = CreateEvent<Collider[]> & ColliderEvents & BaseProps & MassProps<TMassDef> & {
|
|
67
|
+
children?: Snippet<[
|
|
68
|
+
{
|
|
69
|
+
colliders: Collider[];
|
|
70
|
+
refresh: () => void;
|
|
71
|
+
}
|
|
72
|
+
]>;
|
|
73
|
+
};
|
|
74
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,22 +1,20 @@
|
|
|
1
|
-
<script
|
|
2
|
-
|
|
1
|
+
<script
|
|
2
|
+
lang="ts"
|
|
3
|
+
generics="TShape extends Shape, TMassDef extends MassDef"
|
|
4
|
+
>import { ActiveCollisionTypes, CoefficientCombineRule, ColliderDesc } from '@dimforge/rapier3d-compat';
|
|
5
|
+
import { createParentObject3DContext, useParentObject3D, useTask, watch } from '@threlte/core';
|
|
3
6
|
import { onDestroy, onMount, tick } from 'svelte';
|
|
4
7
|
import { Object3D, Quaternion, Vector3 } from 'three';
|
|
5
|
-
import { useCollisionGroups } from '
|
|
6
|
-
import { useRapier } from '
|
|
7
|
-
import { useRigidBody } from '
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
let { shape, args, type, restitution, restitutionCombineRule, friction, frictionCombineRule, sensor, contactForceEventThreshold, density, mass, centerOfMass, principalAngularInertia, angularInertiaLocalFrame, collider = $bindable(),
|
|
15
|
-
if (!collider)
|
|
16
|
-
return;
|
|
17
|
-
collider.setTranslation(getWorldPosition(object));
|
|
18
|
-
collider.setRotation(getWorldQuaternion(object));
|
|
19
|
-
}), oncreate, oncollisionenter, oncollisionexit, oncontact, onsensorenter, onsensorexit, children, } = $props();
|
|
8
|
+
import { useCollisionGroups } from '../../../hooks/useCollisionGroups';
|
|
9
|
+
import { useRapier } from '../../../hooks/useRapier';
|
|
10
|
+
import { useRigidBody } from '../../../hooks/useRigidBody';
|
|
11
|
+
import { applyColliderActiveEvents } from '../../../lib/applyColliderActiveEvents';
|
|
12
|
+
import { eulerToQuaternion } from '../../../lib/eulerToQuaternion';
|
|
13
|
+
import { getWorldPosition, getWorldQuaternion } from '../../../lib/getWorldTransforms';
|
|
14
|
+
import { useParentRigidbodyObject } from '../../../lib/rigidBodyObjectContext';
|
|
15
|
+
import { scaleColliderArgs } from '../../../lib/scaleColliderArgs';
|
|
16
|
+
import { useCreateEvent } from '../../../lib/useCreateEvent';
|
|
17
|
+
let { shape, args, type, restitution, restitutionCombineRule, friction, frictionCombineRule, sensor, contactForceEventThreshold, density, mass, centerOfMass, principalAngularInertia, angularInertiaLocalFrame, collider = $bindable(), oncreate, oncollisionenter, oncollisionexit, oncontact, onsensorenter, onsensorexit, children } = $props();
|
|
20
18
|
const object = new Object3D();
|
|
21
19
|
const { updateRef } = useCreateEvent(oncreate);
|
|
22
20
|
const rigidBody = useRigidBody();
|
|
@@ -108,6 +106,12 @@ $effect.pre(() => {
|
|
|
108
106
|
applyColliderActiveEvents(collider, events, rigidBody?.userData?.events);
|
|
109
107
|
}
|
|
110
108
|
});
|
|
109
|
+
export const refresh = () => {
|
|
110
|
+
if (!collider)
|
|
111
|
+
return;
|
|
112
|
+
collider.setTranslation(getWorldPosition(object));
|
|
113
|
+
collider.setRotation(getWorldQuaternion(object));
|
|
114
|
+
};
|
|
111
115
|
/**
|
|
112
116
|
* If the Collider isAttached (i.e. NOT child of a RigidBody), update the
|
|
113
117
|
* transforms on every frame.
|
|
@@ -134,8 +138,14 @@ onDestroy(() => {
|
|
|
134
138
|
world.removeCollider(collider, true);
|
|
135
139
|
collider = undefined;
|
|
136
140
|
});
|
|
141
|
+
const parent3DObject = useParentObject3D();
|
|
142
|
+
createParentObject3DContext(object);
|
|
143
|
+
watch(parent3DObject, (parent) => {
|
|
144
|
+
parent?.add(object);
|
|
145
|
+
return () => {
|
|
146
|
+
parent?.remove(object);
|
|
147
|
+
};
|
|
148
|
+
});
|
|
137
149
|
</script>
|
|
138
150
|
|
|
139
|
-
|
|
140
|
-
{@render children?.({ collider })}
|
|
141
|
-
</SceneGraphObject>
|
|
151
|
+
{@render children?.({ collider })}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { ColliderProps, MassDef, Shape } from './types';
|
|
2
|
+
declare class __sveltets_Render<TShape extends Shape, TMassDef extends MassDef> {
|
|
3
|
+
props(): ColliderProps<TShape, TMassDef>;
|
|
4
|
+
events(): {};
|
|
5
|
+
slots(): {};
|
|
6
|
+
bindings(): "collider";
|
|
7
|
+
exports(): {
|
|
8
|
+
refresh: () => void;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
interface $$IsomorphicComponent {
|
|
12
|
+
new <TShape extends Shape, TMassDef extends MassDef>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<TShape, TMassDef>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<TShape, TMassDef>['props']>, ReturnType<__sveltets_Render<TShape, TMassDef>['events']>, ReturnType<__sveltets_Render<TShape, TMassDef>['slots']>> & {
|
|
13
|
+
$$bindings?: ReturnType<__sveltets_Render<TShape, TMassDef>['bindings']>;
|
|
14
|
+
} & ReturnType<__sveltets_Render<TShape, TMassDef>['exports']>;
|
|
15
|
+
<TShape extends Shape, TMassDef extends MassDef>(internal: unknown, props: ReturnType<__sveltets_Render<TShape, TMassDef>['props']> & {}): ReturnType<__sveltets_Render<TShape, TMassDef>['exports']>;
|
|
16
|
+
z_$$bindings?: ReturnType<__sveltets_Render<any, any>['bindings']>;
|
|
17
|
+
}
|
|
18
|
+
declare const Collider: $$IsomorphicComponent;
|
|
19
|
+
type Collider<TShape extends Shape, TMassDef extends MassDef> = InstanceType<typeof Collider<TShape, TMassDef>>;
|
|
20
|
+
export default Collider;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import type { CoefficientCombineRule, Collider, ColliderDesc, Collider as RapierCollider } from '@dimforge/rapier3d-compat';
|
|
2
|
+
import { type Snippet } from 'svelte';
|
|
3
|
+
import type { Euler, Vector3 } from 'three';
|
|
4
|
+
import type { ColliderEvents, CreateEvent } from '../../../types/types';
|
|
5
|
+
type Type = 'static' | 'dynamic';
|
|
6
|
+
type BaseProps = {
|
|
7
|
+
/**
|
|
8
|
+
* If a collider is *not* attached to a RigidBody and its type is `static`,
|
|
9
|
+
* its transform is only applied once on initialization. If the transform
|
|
10
|
+
* should be updated every frame, set the type to `dynamic`.
|
|
11
|
+
*/
|
|
12
|
+
type?: Type;
|
|
13
|
+
/** The restitution coefficient of this collider. */
|
|
14
|
+
restitution?: number;
|
|
15
|
+
/** he rule used to combine the restitution coefficients of two colliders involved in a contact. */
|
|
16
|
+
restitutionCombineRule?: CoefficientCombineRule;
|
|
17
|
+
/** The friction coefficient of this collider. */
|
|
18
|
+
friction?: number;
|
|
19
|
+
/** The rule used to combine the friction coefficients of two colliders involved in a contact. */
|
|
20
|
+
frictionCombineRule?: CoefficientCombineRule;
|
|
21
|
+
/** Whether this collider is a sensor. A sensor collider does not generate
|
|
22
|
+
* contacts. They only generate intersection events when one sensor collider
|
|
23
|
+
* and another collider start/stop touching. Sensor colliders are generally
|
|
24
|
+
* used to detect when something enters an area. Note that, for symmetry with
|
|
25
|
+
* non-sensor colliders, sensors do contribute to the mass of a rigid-body
|
|
26
|
+
* they are attached to.
|
|
27
|
+
*/
|
|
28
|
+
sensor?: boolean;
|
|
29
|
+
collider?: RapierCollider;
|
|
30
|
+
/** The total force magnitude beyond which a contact force event can be emitted. */
|
|
31
|
+
contactForceEventThreshold?: number;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* The shape of the collider.
|
|
35
|
+
*/
|
|
36
|
+
export type Shape = 'ball' | 'capsule' | 'segment' | 'triangle' | 'roundTriangle' | 'polyline' | 'trimesh' | 'cuboid' | 'roundCuboid' | 'heightfield' | 'cylinder' | 'roundCylinder' | 'cone' | 'roundCone' | 'convexHull' | 'convexMesh' | 'roundConvexHull' | 'roundConvexMesh';
|
|
37
|
+
type Args<TShape extends Shape> = Parameters<(typeof ColliderDesc)[TShape]>;
|
|
38
|
+
type ShapeProps<TShape extends Shape> = {
|
|
39
|
+
shape: TShape;
|
|
40
|
+
args: Args<TShape>;
|
|
41
|
+
};
|
|
42
|
+
type Density = {
|
|
43
|
+
/** The density of this collider. */
|
|
44
|
+
density: number;
|
|
45
|
+
mass?: never;
|
|
46
|
+
centerOfMass?: never;
|
|
47
|
+
principalAngularInertia?: never;
|
|
48
|
+
angularInertiaLocalFrame?: never;
|
|
49
|
+
};
|
|
50
|
+
type Mass = {
|
|
51
|
+
/** The mass of this collider. */
|
|
52
|
+
mass: number;
|
|
53
|
+
density?: never;
|
|
54
|
+
centerOfMass?: never;
|
|
55
|
+
principalAngularInertia?: never;
|
|
56
|
+
angularInertiaLocalFrame?: never;
|
|
57
|
+
};
|
|
58
|
+
type MassProperties = {
|
|
59
|
+
/** The mass of this collider. */
|
|
60
|
+
mass: number;
|
|
61
|
+
/** The center of mass of this collider. */
|
|
62
|
+
centerOfMass: Parameters<Vector3['set']>;
|
|
63
|
+
/** The principal angular inertia of this collider. */
|
|
64
|
+
principalAngularInertia: Parameters<Vector3['set']>;
|
|
65
|
+
/** The angular inertia local frame of this collider. */
|
|
66
|
+
angularInertiaLocalFrame: Parameters<Euler['set']>;
|
|
67
|
+
density?: never;
|
|
68
|
+
};
|
|
69
|
+
type NoMassProperties = {
|
|
70
|
+
density?: never;
|
|
71
|
+
mass?: never;
|
|
72
|
+
centerOfMass?: never;
|
|
73
|
+
principalAngularInertia?: never;
|
|
74
|
+
angularInertiaLocalFrame?: never;
|
|
75
|
+
};
|
|
76
|
+
export type MassDef = Density | Mass | MassProperties | NoMassProperties;
|
|
77
|
+
type MassProps<TMassDef extends MassDef> = TMassDef extends Density ? Density : TMassDef extends MassProperties ? MassProperties : TMassDef extends Mass ? Mass : NoMassProperties;
|
|
78
|
+
export type ColliderProps<TShape extends Shape, TMassDef extends MassDef> = CreateEvent<Collider> & ColliderEvents & BaseProps & ShapeProps<TShape> & MassProps<TMassDef> & {
|
|
79
|
+
children?: Snippet<[{
|
|
80
|
+
collider?: RapierCollider;
|
|
81
|
+
}]>;
|
|
82
|
+
};
|
|
83
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
<script
|
|
1
|
+
<script
|
|
2
|
+
lang="ts"
|
|
3
|
+
generics="TGroupsDef extends GroupsDef"
|
|
4
|
+
>import { setContext } from 'svelte';
|
|
2
5
|
import { writable } from 'svelte/store';
|
|
3
6
|
import { computeBitMask } from '../../lib/computeBitMask';
|
|
4
7
|
let { groups, filter, memberships, children } = $props();
|
|
@@ -1,35 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
type GroupsProps = {
|
|
10
|
-
groups: N[]
|
|
11
|
-
|
|
12
|
-
filter?: never
|
|
13
|
-
memberships?: never
|
|
14
|
-
|
|
15
|
-
children?: Snippet
|
|
1
|
+
import type { CollisionGroupsProps, GroupsDef } from './types';
|
|
2
|
+
declare class __sveltets_Render<TGroupsDef extends GroupsDef> {
|
|
3
|
+
props(): CollisionGroupsProps<TGroupsDef>;
|
|
4
|
+
events(): {};
|
|
5
|
+
slots(): {};
|
|
6
|
+
bindings(): "";
|
|
7
|
+
exports(): {};
|
|
16
8
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
children?: Snippet
|
|
9
|
+
interface $$IsomorphicComponent {
|
|
10
|
+
new <TGroupsDef extends GroupsDef>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<TGroupsDef>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<TGroupsDef>['props']>, ReturnType<__sveltets_Render<TGroupsDef>['events']>, ReturnType<__sveltets_Render<TGroupsDef>['slots']>> & {
|
|
11
|
+
$$bindings?: ReturnType<__sveltets_Render<TGroupsDef>['bindings']>;
|
|
12
|
+
} & ReturnType<__sveltets_Render<TGroupsDef>['exports']>;
|
|
13
|
+
<TGroupsDef extends GroupsDef>(internal: unknown, props: ReturnType<__sveltets_Render<TGroupsDef>['props']> & {}): ReturnType<__sveltets_Render<TGroupsDef>['exports']>;
|
|
14
|
+
z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
|
|
25
15
|
}
|
|
26
|
-
|
|
27
|
-
type GroupsDef =
|
|
28
|
-
|
|
29
|
-
export type CollisionGroupsProps<TGroupsDef extends GroupsDef> = TGroupsDef extends GroupsProps
|
|
30
|
-
? GroupsProps
|
|
31
|
-
: MembershipsAndFilterProps
|
|
32
|
-
|
|
33
|
-
export default class CollisionGroups<TGroupsDef extends GroupsDef> extends SvelteComponent<
|
|
34
|
-
CollisionGroupsProps<TGroupsDef>
|
|
35
|
-
> {}
|
|
16
|
+
declare const CollisionGroups: $$IsomorphicComponent;
|
|
17
|
+
type CollisionGroups<TGroupsDef extends GroupsDef> = InstanceType<typeof CollisionGroups<TGroupsDef>>;
|
|
18
|
+
export default CollisionGroups;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type Snippet } from 'svelte';
|
|
2
|
+
type N = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15;
|
|
3
|
+
export type Groups = N[];
|
|
4
|
+
export type MembershipsAndFilter = N[];
|
|
5
|
+
type GroupsProps = {
|
|
6
|
+
groups: N[];
|
|
7
|
+
filter?: never;
|
|
8
|
+
memberships?: never;
|
|
9
|
+
children?: Snippet;
|
|
10
|
+
};
|
|
11
|
+
type MembershipsAndFilterProps = {
|
|
12
|
+
filter: N[];
|
|
13
|
+
memberships: N[];
|
|
14
|
+
groups?: never;
|
|
15
|
+
children?: Snippet;
|
|
16
|
+
};
|
|
17
|
+
export type GroupsDef = GroupsProps | MembershipsAndFilterProps;
|
|
18
|
+
export type CollisionGroupsProps<TGroupsDef extends GroupsDef> = TGroupsDef extends GroupsProps ? GroupsProps : MembershipsAndFilterProps;
|
|
19
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
<script lang="ts">import { T, useTask } from '@threlte/core';
|
|
2
2
|
import { onDestroy } from 'svelte';
|
|
3
|
-
import { BufferAttribute, BufferGeometry } from 'three';
|
|
3
|
+
import { BufferAttribute, BufferGeometry, LineSegments } from 'three';
|
|
4
4
|
import { useRapier } from '../../hooks/useRapier';
|
|
5
|
-
let { ref = $bindable(), ...props } = $props();
|
|
5
|
+
let { ref = $bindable(new LineSegments()), ...props } = $props();
|
|
6
6
|
const { world, debug } = useRapier();
|
|
7
7
|
const geometry = new BufferGeometry();
|
|
8
8
|
debug.set(true);
|
|
@@ -18,12 +18,12 @@ onDestroy(() => {
|
|
|
18
18
|
});
|
|
19
19
|
</script>
|
|
20
20
|
|
|
21
|
-
<T
|
|
22
|
-
|
|
21
|
+
<T
|
|
22
|
+
is={ref}
|
|
23
23
|
frustumCulled={false}
|
|
24
24
|
renderOrder={Infinity}
|
|
25
25
|
{...props}
|
|
26
26
|
>
|
|
27
27
|
<T is={geometry} />
|
|
28
28
|
<T.LineBasicMaterial vertexColors />
|
|
29
|
-
</T
|
|
29
|
+
</T>
|
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export type DebugProps = Props<LineSegments>
|
|
6
|
-
|
|
7
|
-
export default class Debug extends SvelteComponent<DebugProps> {}
|
|
1
|
+
import type { DebugProps } from './types';
|
|
2
|
+
declare const Debug: import("svelte").Component<DebugProps, {}, "ref">;
|
|
3
|
+
export default Debug;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,20 +1,23 @@
|
|
|
1
|
-
<script lang="ts">import {
|
|
1
|
+
<script lang="ts">import { createParentObject3DContext, useParentObject3D, watch } from '@threlte/core';
|
|
2
2
|
import { onDestroy, setContext, tick } from 'svelte';
|
|
3
3
|
import { Object3D, Vector3 } from 'three';
|
|
4
4
|
import { useRapier } from '../../hooks/useRapier';
|
|
5
|
+
import { initializeRigidBodyUserData, setInitialRigidBodyState } from '../../lib/createPhysicsTasks';
|
|
5
6
|
import { getWorldPosition, getWorldQuaternion, getWorldScale } from '../../lib/getWorldTransforms';
|
|
6
7
|
import { parseRigidBodyType } from '../../lib/parseRigidBodyType';
|
|
7
8
|
import { setParentRigidbodyObject } from '../../lib/rigidBodyObjectContext';
|
|
8
9
|
import { useCreateEvent } from '../../lib/useCreateEvent';
|
|
10
|
+
import { overrideTeleportMethods } from './overrideTeleportMethods';
|
|
9
11
|
const { world, rapier, addRigidBodyToContext, removeRigidBodyFromContext } = useRapier();
|
|
10
|
-
let { linearVelocity, angularVelocity, type = 'dynamic', canSleep = true, gravityScale = 1, ccd = false, angularDamping = 0, linearDamping = 0, lockRotations = false, lockTranslations = false, enabledRotations = [true, true, true], enabledTranslations = [true, true, true], dominance = 0, enabled = true, userData = {}, rigidBody = $bindable(), oncreate, oncollisionenter, oncollisionexit, oncontact, onsensorenter, onsensorexit, onsleep, onwake } = $props();
|
|
12
|
+
let { linearVelocity, angularVelocity, type = 'dynamic', canSleep = true, gravityScale = 1, ccd = false, angularDamping = 0, linearDamping = 0, lockRotations = false, lockTranslations = false, enabledRotations = [true, true, true], enabledTranslations = [true, true, true], dominance = 0, enabled = true, userData = {}, rigidBody = $bindable(), oncreate, oncollisionenter, oncollisionexit, oncontact, onsensorenter, onsensorexit, onsleep, onwake, children } = $props();
|
|
11
13
|
/**
|
|
12
14
|
* Every RigidBody receives and forwards collision-related events
|
|
13
15
|
*/
|
|
14
16
|
const { updateRef } = useCreateEvent(oncreate);
|
|
15
17
|
const object = new Object3D();
|
|
18
|
+
initializeRigidBodyUserData(object);
|
|
16
19
|
/**
|
|
17
|
-
* isSleeping used for events "sleep" and "wake" in `
|
|
20
|
+
* isSleeping used for events "sleep" and "wake" in `createPhysicsTasks`
|
|
18
21
|
*/
|
|
19
22
|
object.userData.isSleeping = false;
|
|
20
23
|
/**
|
|
@@ -25,6 +28,7 @@ const desc = new rapier.RigidBodyDesc(parseRigidBodyType(type)).setCanSleep(canS
|
|
|
25
28
|
* Temporary RigidBody init
|
|
26
29
|
*/
|
|
27
30
|
let rigidBodyInternal = world.createRigidBody(desc);
|
|
31
|
+
overrideTeleportMethods(rigidBodyInternal, object);
|
|
28
32
|
rigidBody = rigidBodyInternal;
|
|
29
33
|
/**
|
|
30
34
|
* Apply transforms after the parent component added "object" to itself
|
|
@@ -36,6 +40,7 @@ const initPosition = async () => {
|
|
|
36
40
|
const parentWorldScale = object.parent ? getWorldScale(object.parent) : new Vector3(1, 1, 1);
|
|
37
41
|
const worldPosition = getWorldPosition(object).multiply(parentWorldScale);
|
|
38
42
|
const worldQuaternion = getWorldQuaternion(object);
|
|
43
|
+
setInitialRigidBodyState(object, worldPosition, worldQuaternion);
|
|
39
44
|
rigidBodyInternal.setTranslation(worldPosition, true);
|
|
40
45
|
rigidBodyInternal.setRotation(worldQuaternion, true);
|
|
41
46
|
updateRef(rigidBodyInternal);
|
|
@@ -111,8 +116,14 @@ onDestroy(() => {
|
|
|
111
116
|
removeRigidBodyFromContext(rigidBodyInternal);
|
|
112
117
|
world.removeRigidBody(rigidBodyInternal);
|
|
113
118
|
});
|
|
119
|
+
const parent3DObject = useParentObject3D();
|
|
120
|
+
createParentObject3DContext(object);
|
|
121
|
+
watch(parent3DObject, (parent) => {
|
|
122
|
+
parent?.add(object);
|
|
123
|
+
return () => {
|
|
124
|
+
parent?.remove(object);
|
|
125
|
+
};
|
|
126
|
+
});
|
|
114
127
|
</script>
|
|
115
128
|
|
|
116
|
-
|
|
117
|
-
<slot rigidBody={rigidBodyInternal} />
|
|
118
|
-
</SceneGraphObject>
|
|
129
|
+
{@render children?.({ rigidBody: rigidBodyInternal })}
|