@threlte/rapier 3.0.0-next.17 → 3.0.0-next.19

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.
@@ -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,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
+ };
package/dist/index.d.ts CHANGED
@@ -1,11 +1,13 @@
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';
package/dist/index.js CHANGED
@@ -2,12 +2,14 @@
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';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@threlte/rapier",
3
- "version": "3.0.0-next.17",
3
+ "version": "3.0.0-next.19",
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",
@@ -11,7 +11,7 @@
11
11
  "@sveltejs/package": "^2.3.7",
12
12
  "@sveltejs/vite-plugin-svelte": "^4.0.0",
13
13
  "@types/node": "^20.12.7",
14
- "@types/three": "^0.169.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,16 +22,16 @@
22
22
  "prettier-plugin-svelte": "^3.2.2",
23
23
  "publint": "^0.2.7",
24
24
  "rimraf": "^5.0.5",
25
- "svelte": "^5.1.10",
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.170.0",
29
+ "three": "^0.171.0",
30
30
  "tslib": "^2.6.2",
31
31
  "type-fest": "^4.15.0",
32
32
  "typescript": "^5.6.3",
33
33
  "vite": "^5.2.8",
34
- "@threlte/core": "8.0.0-next.33"
34
+ "@threlte/core": "8.0.0-next.36"
35
35
  },
36
36
  "peerDependencies": {
37
37
  "@dimforge/rapier3d-compat": ">=0.14",