@threlte/rapier 3.0.0-next.9 → 3.1.0

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.
Files changed (55) hide show
  1. package/README.md +1 -8
  2. package/dist/components/Attractor/Attractor.svelte.d.ts +3 -34
  3. package/dist/components/Attractor/types.d.ts +30 -0
  4. package/dist/components/Attractor/types.js +1 -0
  5. package/dist/components/Colliders/{AutoColliders.svelte → AutoColliders/AutoColliders.svelte} +17 -10
  6. package/dist/components/Colliders/AutoColliders/AutoColliders.svelte.d.ts +22 -0
  7. package/dist/components/Colliders/AutoColliders/types.d.ts +74 -0
  8. package/dist/components/Colliders/AutoColliders/types.js +1 -0
  9. package/dist/components/Colliders/{Collider.svelte → Collider/Collider.svelte} +20 -16
  10. package/dist/components/Colliders/Collider/Collider.svelte.d.ts +20 -0
  11. package/dist/components/Colliders/Collider/types.d.ts +83 -0
  12. package/dist/components/Colliders/Collider/types.js +1 -0
  13. package/dist/components/CollisionGroups/CollisionGroups.svelte +4 -1
  14. package/dist/components/CollisionGroups/CollisionGroups.svelte.d.ts +16 -33
  15. package/dist/components/CollisionGroups/types.d.ts +19 -0
  16. package/dist/components/CollisionGroups/types.js +1 -0
  17. package/dist/components/Debug/Debug.svelte +5 -5
  18. package/dist/components/Debug/Debug.svelte.d.ts +3 -7
  19. package/dist/components/Debug/types.d.ts +3 -0
  20. package/dist/components/Debug/types.js +1 -0
  21. package/dist/components/RigidBody/RigidBody.svelte.d.ts +3 -102
  22. package/dist/components/RigidBody/types.d.ts +85 -0
  23. package/dist/components/RigidBody/types.js +2 -0
  24. package/dist/components/World/InnerWorld.svelte.d.ts +3 -15
  25. package/dist/components/World/World.svelte.d.ts +3 -49
  26. package/dist/components/World/types.d.ts +32 -0
  27. package/dist/components/World/types.js +1 -0
  28. package/dist/hooks/useFixedJoint.d.ts +7 -0
  29. package/dist/hooks/useJoint.d.ts +7 -0
  30. package/dist/hooks/usePhysicsTask.d.ts +16 -0
  31. package/dist/hooks/usePhysicsTask.js +32 -0
  32. package/dist/hooks/usePrismaticJoint.d.ts +7 -0
  33. package/dist/hooks/useRevoluteJoint.d.ts +7 -0
  34. package/dist/hooks/useRopeJoint.d.ts +10 -0
  35. package/dist/hooks/useRopeJoint.js +14 -0
  36. package/dist/hooks/useSphericalJoint.d.ts +7 -0
  37. package/dist/hooks/utils.js +3 -2
  38. package/dist/index.d.ts +5 -4
  39. package/dist/index.js +4 -4
  40. package/dist/lib/applyTransforms.d.ts +1 -1
  41. package/dist/lib/createCollidersFromChildren.d.ts +1 -1
  42. package/dist/lib/createCollidersFromChildren.js +24 -5
  43. package/dist/lib/createPhysicsTasks.js +1 -1
  44. package/dist/lib/createRapierContext.d.ts +1 -1
  45. package/dist/lib/eulerToQuaternion.d.ts +2 -2
  46. package/dist/lib/getWorldTransforms.js +1 -1
  47. package/dist/lib/useCreateEvent.d.ts +2 -2
  48. package/dist/lib/useCreateEvent.js +3 -5
  49. package/dist/types/types.d.ts +3 -5
  50. package/dist/types/types.js +2 -1
  51. package/package.json +12 -12
  52. package/dist/components/Colliders/AutoColliders.svelte.d.ts +0 -84
  53. package/dist/components/Colliders/Collider.svelte.d.ts +0 -109
  54. package/dist/recipes/BasicPlayerController.svelte +0 -142
  55. package/dist/recipes/BasicPlayerController.svelte.d.ts +0 -29
@@ -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,2 @@
1
+ import { RigidBody as RapierRigidBody } from '@dimforge/rapier3d-compat';
2
+ import {} from 'svelte';
@@ -1,15 +1,3 @@
1
- import { SvelteComponent } from "svelte";
2
- import type { WorldProps } from './World.svelte';
3
- declare const __propDef: {
4
- props: WorldProps;
5
- events: {
6
- [evt: string]: CustomEvent<any>;
7
- };
8
- slots: {};
9
- };
10
- export type InnerWorldProps = typeof __propDef.props;
11
- export type InnerWorldEvents = typeof __propDef.events;
12
- export type InnerWorldSlots = typeof __propDef.slots;
13
- export default class InnerWorld extends SvelteComponent<InnerWorldProps, InnerWorldEvents, InnerWorldSlots> {
14
- }
15
- export {};
1
+ import type { WorldProps } from './types';
2
+ declare const InnerWorld: import("svelte").Component<WorldProps, {}, "">;
3
+ export default InnerWorld;
@@ -1,49 +1,3 @@
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 { SvelteComponent, type Snippet } from 'svelte'
17
- import type { Vector3 } from 'three'
18
- import type { Key, Stage } from '@threlte/core'
19
-
20
- export type WorldProps = {
21
- framerate?: number | 'varying'
22
- autoStart?: boolean
23
- gravity?: Parameters<Vector3['set']>
24
- rawIntegrationParameters?: RawIntegrationParameters
25
- rawIslands?: RawIslandManager
26
- rawBroadPhase?: RawBroadPhase
27
- rawNarrowPhase?: RawNarrowPhase
28
- rawBodies?: RawRigidBodySet
29
- rawColliders?: RawColliderSet
30
- rawImpulseJoints?: RawImpulseJointSet
31
- rawMultibodyJoints?: RawMultibodyJointSet
32
- rawCCDSolver?: RawCCDSolver
33
- rawQueryPipeline?: RawQueryPipeline
34
- rawPhysicsPipeline?: RawPhysicsPipeline
35
- rawSerializationPipeline?: RawSerializationPipeline
36
- rawDebugRenderPipeline?: RawDebugRenderPipeline
37
- simulationStageOptions?: {
38
- before?: (Key | Stage) | (Key | Stage)[]
39
- after?: (Key | Stage) | (Key | Stage)[]
40
- }
41
- synchronizationStageOptions?: {
42
- before?: (Key | Stage) | (Key | Stage)[]
43
- after?: (Key | Stage) | (Key | Stage)[]
44
- }
45
- children?: Snippet
46
- fallback?: Snippet<[error: any]>
47
- }
48
-
49
- 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
+ import {} from 'svelte';
@@ -0,0 +1,7 @@
1
+ import type { FixedImpulseJoint } from '@dimforge/rapier3d-compat';
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) => {
4
+ joint: import("svelte/store").Writable<FixedImpulseJoint>;
5
+ rigidBodyA: import("svelte/store").Writable<import("@dimforge/rapier3d-compat").RigidBody | undefined>;
6
+ rigidBodyB: import("svelte/store").Writable<import("@dimforge/rapier3d-compat").RigidBody | undefined>;
7
+ };
@@ -0,0 +1,7 @@
1
+ import { MultibodyJoint, type ImpulseJoint, type RigidBody } from '@dimforge/rapier3d-compat';
2
+ import type { RapierContext } from '../types/types';
3
+ export declare const useJoint: <T extends ImpulseJoint | MultibodyJoint>(initializeJoint: (rigidBodyA: RigidBody, rigidBodyB: RigidBody, ctx: RapierContext) => T) => {
4
+ joint: import("svelte/store").Writable<T>;
5
+ rigidBodyA: import("svelte/store").Writable<RigidBody | undefined>;
6
+ rigidBodyB: import("svelte/store").Writable<RigidBody | undefined>;
7
+ };
@@ -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
+ }
@@ -0,0 +1,7 @@
1
+ import type { PrismaticImpulseJoint } from '@dimforge/rapier3d-compat';
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
+ joint: import("svelte/store").Writable<PrismaticImpulseJoint>;
5
+ rigidBodyA: import("svelte/store").Writable<import("@dimforge/rapier3d-compat").RigidBody | undefined>;
6
+ rigidBodyB: import("svelte/store").Writable<import("@dimforge/rapier3d-compat").RigidBody | undefined>;
7
+ };
@@ -0,0 +1,7 @@
1
+ import type { RevoluteImpulseJoint } from '@dimforge/rapier3d-compat';
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
+ joint: import("svelte/store").Writable<RevoluteImpulseJoint>;
5
+ rigidBodyA: import("svelte/store").Writable<import("@dimforge/rapier3d-compat").RigidBody | undefined>;
6
+ rigidBodyB: import("svelte/store").Writable<import("@dimforge/rapier3d-compat").RigidBody | undefined>;
7
+ };
@@ -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
+ };
@@ -0,0 +1,7 @@
1
+ import type { SphericalImpulseJoint } from '@dimforge/rapier3d-compat';
2
+ import { Vector3 } from 'three';
3
+ export declare const useSphericalJoint: (anchorA: Parameters<Vector3["set"]> | Vector3, anchorB: Parameters<Vector3["set"]> | Vector3) => {
4
+ joint: import("svelte/store").Writable<SphericalImpulseJoint>;
5
+ rigidBodyA: import("svelte/store").Writable<import("@dimforge/rapier3d-compat").RigidBody | undefined>;
6
+ rigidBodyB: import("svelte/store").Writable<import("@dimforge/rapier3d-compat").RigidBody | undefined>;
7
+ };
@@ -1,6 +1,7 @@
1
+ import { isInstanceOf } from '@threlte/core';
1
2
  export const isVector3 = (v) => {
2
- return v.isVector3;
3
+ return isInstanceOf(v, 'Vector3');
3
4
  };
4
5
  export const isEuler = (v) => {
5
- return v.isEuler;
6
+ return isInstanceOf(v, 'Euler');
6
7
  };
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 { default as BasicPlayerController } from './recipes/BasicPlayerController.svelte';
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';
@@ -1,2 +1,2 @@
1
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;
2
+ export declare const applyTransforms: (object: Object3D, position?: Parameters<Vector3["set"]>, rotation?: Parameters<Euler["set"]>, scale?: Parameters<Vector3["set"]>) => void;
@@ -1,4 +1,4 @@
1
- import { Collider, World, RigidBody } from '@dimforge/rapier3d-compat';
1
+ import { Collider, RigidBody, World } from '@dimforge/rapier3d-compat';
2
2
  import { type Object3D } from 'three';
3
3
  import type { AutoCollidersShapes } from '../types/types';
4
4
  /**
@@ -1,5 +1,6 @@
1
- import { ActiveEvents, ColliderDesc } from '@dimforge/rapier3d-compat';
2
- import { Quaternion, Vector3 } from 'three';
1
+ import { ActiveEvents, Collider, ColliderDesc, RigidBody, World } from '@dimforge/rapier3d-compat';
2
+ import { isInstanceOf } from '@threlte/core';
3
+ import { Mesh, Quaternion, Vector3 } from 'three';
3
4
  const offset = new Vector3();
4
5
  const worldPosition = new Vector3();
5
6
  const worldQuaternion = new Quaternion();
@@ -33,7 +34,7 @@ export const createCollidersFromChildren = (object, collidersType, world, rigidB
33
34
  rigidBodyParentObject?.getWorldPosition(rigidBodyWorldPos);
34
35
  rigidBodyParentObject?.getWorldQuaternion(rigidBodyWorldQuatInversed).invert();
35
36
  object.traverse((child) => {
36
- if ('isMesh' in child) {
37
+ if (isInstanceOf(child, 'Mesh')) {
37
38
  const { geometry } = child;
38
39
  const worldPos = child.getWorldPosition(worldPosition);
39
40
  const translation = worldPos.sub(rigidBodyWorldPos);
@@ -62,7 +63,16 @@ export const createCollidersFromChildren = (object, collidersType, world, rigidB
62
63
  break;
63
64
  case 'trimesh':
64
65
  {
65
- description = ColliderDesc.trimesh(new Float32Array(geometry.attributes.position.array), new Uint32Array(geometry.index?.array ?? []));
66
+ const { x: scaleX, y: scaleY, z: scaleZ } = scale;
67
+ const vertices = new Float32Array(geometry.attributes.position.array);
68
+ if (scaleX !== 1 || scaleY !== 1 || scaleZ !== 1) {
69
+ for (let i = 0; i < vertices.length; i += 3) {
70
+ vertices[i] *= scaleX;
71
+ vertices[i + 1] *= scaleY;
72
+ vertices[i + 2] *= scaleZ;
73
+ }
74
+ }
75
+ description = ColliderDesc.trimesh(vertices, new Uint32Array(geometry.index?.array ?? Uint32Array.from(Array(vertices.length / 3).keys())));
66
76
  }
67
77
  break;
68
78
  case 'capsule':
@@ -77,7 +87,16 @@ export const createCollidersFromChildren = (object, collidersType, world, rigidB
77
87
  break;
78
88
  case 'convexHull':
79
89
  {
80
- description = ColliderDesc.convexHull(new Float32Array(geometry.attributes.position.array));
90
+ const { x: scaleX, y: scaleY, z: scaleZ } = scale;
91
+ const vertices = new Float32Array(geometry.attributes.position.array);
92
+ if (scaleX !== 1 || scaleY !== 1 || scaleZ !== 1) {
93
+ for (let i = 0; i < vertices.length; i += 3) {
94
+ vertices[i] *= scaleX;
95
+ vertices[i + 1] *= scaleY;
96
+ vertices[i + 2] *= scaleZ;
97
+ }
98
+ }
99
+ description = ColliderDesc.convexHull(vertices);
81
100
  }
82
101
  break;
83
102
  }
@@ -1,4 +1,4 @@
1
- import { EventQueue } from '@dimforge/rapier3d-compat';
1
+ import { Collider, EventQueue } from '@dimforge/rapier3d-compat';
2
2
  import { useTask } from '@threlte/core';
3
3
  import { Object3D, Quaternion, Vector3 } from 'three';
4
4
  import { simulationKey, synchronizationKey } from './keys';
@@ -1,7 +1,7 @@
1
1
  import RAPIER from '@dimforge/rapier3d-compat';
2
2
  import { type Key, type Stage } from '@threlte/core';
3
3
  import type { Framerate, RapierContext } from '../types/types';
4
- export declare const createRapierContext: (worldArgs: [gravity: RAPIER.Vector, rawIntegrationParameters?: import("@dimforge/rapier3d-compat/rapier_wasm3d").RawIntegrationParameters | undefined, rawIslands?: import("@dimforge/rapier3d-compat/rapier_wasm3d").RawIslandManager | undefined, rawBroadPhase?: import("@dimforge/rapier3d-compat/rapier_wasm3d").RawBroadPhase | undefined, rawNarrowPhase?: import("@dimforge/rapier3d-compat/rapier_wasm3d").RawNarrowPhase | undefined, rawBodies?: import("@dimforge/rapier3d-compat/rapier_wasm3d").RawRigidBodySet | undefined, rawColliders?: import("@dimforge/rapier3d-compat/rapier_wasm3d").RawColliderSet | undefined, rawImpulseJoints?: import("@dimforge/rapier3d-compat/rapier_wasm3d").RawImpulseJointSet | undefined, rawMultibodyJoints?: import("@dimforge/rapier3d-compat/rapier_wasm3d").RawMultibodyJointSet | undefined, rawCCDSolver?: import("@dimforge/rapier3d-compat/rapier_wasm3d").RawCCDSolver | undefined, rawQueryPipeline?: import("@dimforge/rapier3d-compat/rapier_wasm3d").RawQueryPipeline | undefined, rawPhysicsPipeline?: import("@dimforge/rapier3d-compat/rapier_wasm3d").RawPhysicsPipeline | undefined, rawSerializationPipeline?: import("@dimforge/rapier3d-compat/rapier_wasm3d").RawSerializationPipeline | undefined, rawDebugRenderPipeline?: import("@dimforge/rapier3d-compat/rapier_wasm3d").RawDebugRenderPipeline | undefined], options: {
4
+ export declare const createRapierContext: (worldArgs: ConstructorParameters<typeof RAPIER.World>, options: {
5
5
  framerate?: Framerate;
6
6
  autoStart?: boolean;
7
7
  simulationStageOptions?: {
@@ -1,7 +1,7 @@
1
- import { Quaternion } from 'three';
1
+ import { Euler, Quaternion } from 'three';
2
2
  /**
3
3
  * Sets the values of a temporary Euler and returns the quaternion from that
4
4
  * @param values
5
5
  * @returns
6
6
  */
7
- export declare const eulerToQuaternion: (values: [x: number, y: number, z: number, order?: import("three").EulerOrder | undefined]) => Quaternion;
7
+ export declare const eulerToQuaternion: (values: Parameters<Euler["set"]>) => Quaternion;
@@ -1,4 +1,4 @@
1
- import { Euler, Quaternion, Vector3 } from 'three';
1
+ import { Euler, Object3D, Quaternion, Vector3 } from 'three';
2
2
  const tempPosition = new Vector3();
3
3
  const tempQuaternion = new Quaternion();
4
4
  const tempRotation = new Euler();
@@ -1,4 +1,4 @@
1
- import type { ColliderEvents } from '../types/types';
2
- export declare const useCreateEvent: <T>(oncreate?: ColliderEvents['oncreate']) => {
1
+ import type { CreateEvent } from '../types/types';
2
+ export declare const useCreateEvent: <T>(oncreate?: CreateEvent<T>["oncreate"]) => {
3
3
  updateRef: (newRef: T) => void;
4
4
  };
@@ -7,13 +7,11 @@ export const useCreateEvent = (oncreate) => {
7
7
  cleanupFunctions.forEach((cleanup) => cleanup());
8
8
  // clear the cleanup functions array
9
9
  cleanupFunctions.length = 0;
10
- const cleanup = (callback) => {
11
- // add cleanup function to array
12
- cleanupFunctions.push(callback);
13
- };
14
10
  if (ref === undefined)
15
11
  return;
16
- oncreate?.({ ref, cleanup });
12
+ const cleanup = oncreate?.(ref);
13
+ if (cleanup)
14
+ cleanupFunctions.push(cleanup);
17
15
  };
18
16
  const updateRef = (newRef) => {
19
17
  ref = newRef;
@@ -1,4 +1,3 @@
1
- /// <reference types="svelte" />
2
1
  import { World, type Collider, type RigidBody, type TempContactManifold, type Vector } from '@dimforge/rapier3d-compat';
3
2
  import RAPIER from '@dimforge/rapier3d-compat';
4
3
  import type { CurrentWritable, Stage, Task } from '@threlte/core';
@@ -6,11 +5,10 @@ import type { Readable, Writable } from 'svelte/store';
6
5
  import type { Object3D } from 'three';
7
6
  export type ColliderShapes = 'ball' | 'capsule' | 'segment' | 'triangle' | 'roundTriangle' | 'polyline' | 'trimesh' | 'cuboid' | 'roundCuboid' | 'heightfield' | 'cylinder' | 'roundCylinder' | 'cone' | 'roundCone' | 'convexHull' | 'convexMesh' | 'roundConvexHull' | 'roundConvexMesh';
8
7
  export type AutoCollidersShapes = 'cuboid' | 'ball' | 'trimesh' | 'convexHull' | 'capsule';
8
+ export type CreateEvent<T> = {
9
+ oncreate?: (ref: T) => void | (() => void);
10
+ };
9
11
  export type ColliderEvents = {
10
- oncreate?: (event: {
11
- ref: Collider;
12
- cleanup: (callback: () => void) => void;
13
- }) => void;
14
12
  oncollisionenter?: (event: {
15
13
  targetCollider: Collider;
16
14
  targetRigidBody: RigidBody | null;
@@ -1 +1,2 @@
1
- export {};
1
+ import { World } from '@dimforge/rapier3d-compat';
2
+ import RAPIER from '@dimforge/rapier3d-compat';
package/package.json CHANGED
@@ -1,17 +1,17 @@
1
1
  {
2
2
  "name": "@threlte/rapier",
3
- "version": "3.0.0-next.9",
3
+ "version": "3.1.0",
4
4
  "author": "Grischa Erbe <hello@legrisch.com> (https://legrisch.com)",
5
5
  "license": "MIT",
6
6
  "description": "Components and hooks to use the Rapier physics engine in Threlte",
7
7
  "devDependencies": {
8
- "@dimforge/rapier3d-compat": "^0.13.1",
9
- "@sveltejs/adapter-auto": "^3.2.0",
10
- "@sveltejs/kit": "^2.5.5",
11
- "@sveltejs/package": "^2.3.1",
12
- "@sveltejs/vite-plugin-svelte": "^3.1.0",
8
+ "@dimforge/rapier3d-compat": "^0.14.0",
9
+ "@sveltejs/adapter-auto": "^3.3.1",
10
+ "@sveltejs/kit": "^2.7.7",
11
+ "@sveltejs/package": "^2.3.7",
12
+ "@sveltejs/vite-plugin-svelte": "^4.0.0",
13
13
  "@types/node": "^20.12.7",
14
- "@types/three": "^0.166.0",
14
+ "@types/three": "^0.171.0",
15
15
  "@typescript-eslint/eslint-plugin": "^7.6.0",
16
16
  "@typescript-eslint/parser": "^7.6.0",
17
17
  "@yushijinhun/three-minifier-rollup": "^0.4.0",
@@ -22,19 +22,19 @@
22
22
  "prettier-plugin-svelte": "^3.2.2",
23
23
  "publint": "^0.2.7",
24
24
  "rimraf": "^5.0.5",
25
- "svelte": "5.0.0-next.181",
25
+ "svelte": "^5.14.4",
26
26
  "svelte-check": "^3.6.9",
27
27
  "svelte-preprocess": "^5.1.3",
28
28
  "svelte2tsx": "^0.7.6",
29
- "three": "^0.166.1",
29
+ "three": "^0.171.0",
30
30
  "tslib": "^2.6.2",
31
31
  "type-fest": "^4.15.0",
32
- "typescript": "^5.4.5",
32
+ "typescript": "^5.6.3",
33
33
  "vite": "^5.2.8",
34
- "@threlte/core": "8.0.0-next.17"
34
+ "@threlte/core": "8.0.1"
35
35
  },
36
36
  "peerDependencies": {
37
- "@dimforge/rapier3d-compat": ">=0.12",
37
+ "@dimforge/rapier3d-compat": ">=0.14",
38
38
  "svelte": ">=5",
39
39
  "three": ">=0.152"
40
40
  },