@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.
Files changed (53) hide show
  1. package/dist/CHANGELOG.md +12 -0
  2. package/dist/components/Attractor/Attractor.svelte +17 -13
  3. package/dist/components/Attractor/Attractor.svelte.d.ts +20 -22
  4. package/dist/components/Colliders/AutoColliders.svelte +52 -50
  5. package/dist/components/Colliders/AutoColliders.svelte.d.ts +80 -0
  6. package/dist/components/Colliders/Collider.svelte +40 -30
  7. package/dist/components/Colliders/Collider.svelte.d.ts +110 -112
  8. package/dist/components/CollisionGroups/CollisionGroups.svelte +1 -20
  9. package/dist/components/CollisionGroups/CollisionGroups.svelte.d.ts +29 -19
  10. package/dist/components/Debug/Debug.svelte +13 -10
  11. package/dist/components/Debug/Debug.svelte.d.ts +6 -60
  12. package/dist/components/RigidBody/RigidBody.svelte +23 -58
  13. package/dist/components/RigidBody/RigidBody.svelte.d.ts +94 -67
  14. package/dist/components/World/InnerWorld.svelte +11 -7
  15. package/dist/components/World/InnerWorld.svelte.d.ts +15 -15
  16. package/dist/components/World/World.svelte +13 -2
  17. package/dist/components/World/World.svelte.d.ts +36 -32
  18. package/dist/hooks/useFixedJoint.d.ts +2 -2
  19. package/dist/hooks/useFixedJoint.js +6 -3
  20. package/dist/hooks/useFrameHandler.d.ts +1 -1
  21. package/dist/hooks/useFrameHandler.js +9 -8
  22. package/dist/hooks/usePrismaticJoint.d.ts +2 -2
  23. package/dist/hooks/usePrismaticJoint.js +5 -2
  24. package/dist/hooks/useRevoluteJoint.d.ts +2 -2
  25. package/dist/hooks/useRevoluteJoint.js +5 -2
  26. package/dist/hooks/useSphericalJoint.d.ts +2 -2
  27. package/dist/hooks/useSphericalJoint.js +4 -2
  28. package/dist/index.d.ts +2 -1
  29. package/dist/index.js +2 -0
  30. package/dist/lib/applyTransforms.d.ts +2 -3
  31. package/dist/lib/applyTransforms.js +7 -16
  32. package/dist/lib/computeBitMask.d.ts +5 -0
  33. package/dist/lib/computeBitMask.js +20 -0
  34. package/dist/lib/createRapierContext.d.ts +3 -0
  35. package/dist/lib/createRapierContext.js +10 -1
  36. package/dist/lib/eulerToQuaternion.d.ts +7 -0
  37. package/dist/lib/eulerToQuaternion.js +12 -0
  38. package/dist/lib/scaleColliderArgs.js +3 -3
  39. package/dist/recipes/BasicPlayerController.svelte +28 -27
  40. package/dist/recipes/BasicPlayerController.svelte.d.ts +2 -5
  41. package/dist/types/components.d.ts +1 -88
  42. package/dist/types/types.d.ts +5 -5
  43. package/package.json +10 -9
  44. package/dist/components/Joints/RevoluteJoint.svelte +0 -5
  45. package/dist/components/Joints/RevoluteJoint.svelte.d.ts +0 -23
  46. package/dist/lib/positionToVector3.d.ts +0 -3
  47. package/dist/lib/positionToVector3.js +0 -8
  48. package/dist/lib/rotationToEuler.d.ts +0 -3
  49. package/dist/lib/rotationToEuler.js +0 -8
  50. package/dist/lib/rotationToQuaternion.d.ts +0 -3
  51. package/dist/lib/rotationToQuaternion.js +0 -10
  52. package/dist/lib/scaleToVector3.d.ts +0 -3
  53. package/dist/lib/scaleToVector3.js +0 -16
@@ -0,0 +1,7 @@
1
+ import { Quaternion } from 'three';
2
+ /**
3
+ * Sets the values of a temporary Euler and returns the quaternion from that
4
+ * @param values
5
+ * @returns
6
+ */
7
+ export declare const eulerToQuaternion: (values: [x: number, y: number, z: number, order?: string | undefined]) => Quaternion;
@@ -0,0 +1,12 @@
1
+ import { Euler, Quaternion } from 'three';
2
+ const e = new Euler();
3
+ const q = new Quaternion();
4
+ /**
5
+ * Sets the values of a temporary Euler and returns the quaternion from that
6
+ * @param values
7
+ * @returns
8
+ */
9
+ export const eulerToQuaternion = (values) => {
10
+ e.set(...values);
11
+ return q.setFromEuler(e);
12
+ };
@@ -11,8 +11,8 @@ export const scaleColliderArgs = (shape, args, scale) => {
11
11
  // Heightfield only scales the last arg
12
12
  const newArgs = args.slice();
13
13
  if (shape === 'heightfield') {
14
- ;
15
- newArgs[3] *= scale.x;
14
+ // Is this for auto scaling heightfield to THREE scale of the object?
15
+ // ;(newArgs[3] as number) = scale.x
16
16
  return newArgs;
17
17
  }
18
18
  // Trimesh and convex scale the vertices
@@ -21,5 +21,5 @@ export const scaleColliderArgs = (shape, args, scale) => {
21
21
  return newArgs;
22
22
  }
23
23
  const scaleArray = [scale.x, scale.y, scale.z];
24
- return newArgs.map((arg, index) => scaleArray[index] * arg);
24
+ return newArgs.map((arg, index) => (scaleArray[index] ?? 1) * arg);
25
25
  };
@@ -1,5 +1,4 @@
1
- <script>import { Group, useFrame, useThrelte } from '@threlte/core';
2
- import { createEventDispatcher } from 'svelte';
1
+ <script>import { createRawEventDispatcher, T, useFrame, useThrelte } from '@threlte/core';
3
2
  import { Vector2, Vector3 } from 'three';
4
3
  import Collider from '../components/Colliders/Collider.svelte';
5
4
  import CollisionGroups from '../components/CollisionGroups/CollisionGroups.svelte';
@@ -23,7 +22,7 @@ const keys = {
23
22
  };
24
23
  const t = new Vector3();
25
24
  const t2 = new Vector2();
26
- const dispatch = createEventDispatcher();
25
+ const dispatch = createRawEventDispatcher();
27
26
  let grounded = false;
28
27
  let groundsSensored = 0;
29
28
  $: {
@@ -101,29 +100,31 @@ const onKeyUp = (e) => {
101
100
 
102
101
  <svelte:window on:keydown|preventDefault={onKeyDown} on:keyup|preventDefault={onKeyUp} />
103
102
 
104
- <RigidBody
105
- dominance={127}
106
- enabledRotations={[false, false, false]}
107
- bind:rigidBody
108
- {position}
109
- type={'dynamic'}
110
- >
111
- <CollisionGroups groups={playerCollisionGroups}>
112
- <Collider shape={'capsule'} args={[height / 2 - radius, radius]} />
113
- </CollisionGroups>
103
+ <T.Group {position}>
104
+ <RigidBody
105
+ dominance={127}
106
+ enabledRotations={[false, false, false]}
107
+ bind:rigidBody
108
+ type={'dynamic'}
109
+ >
110
+ <CollisionGroups groups={playerCollisionGroups}>
111
+ <Collider shape={'capsule'} args={[height / 2 - radius, radius]} />
112
+ </CollisionGroups>
114
113
 
115
- <CollisionGroups groups={groundCollisionGroups}>
116
- <Collider
117
- sensor
118
- on:sensorenter={() => (groundsSensored += 1)}
119
- on:sensorexit={() => (groundsSensored -= 1)}
120
- shape={'ball'}
121
- args={[radius * 1.2]}
122
- position={{ y: -height / 2 + radius }}
123
- />
124
- </CollisionGroups>
114
+ <CollisionGroups groups={groundCollisionGroups}>
115
+ <T.Group position={[0, -height / 2 + radius, 0]}>
116
+ <Collider
117
+ sensor
118
+ on:sensorenter={() => (groundsSensored += 1)}
119
+ on:sensorexit={() => (groundsSensored -= 1)}
120
+ shape={'ball'}
121
+ args={[radius * 1.2]}
122
+ />
123
+ </T.Group>
124
+ </CollisionGroups>
125
125
 
126
- <Group position={{ y: -height / 2 }}>
127
- <slot />
128
- </Group>
129
- </RigidBody>
126
+ <T.Group position.y={-height / 2}>
127
+ <slot />
128
+ </T.Group>
129
+ </RigidBody>
130
+ </T.Group>
@@ -1,9 +1,9 @@
1
1
  import { SvelteComponentTyped } from "svelte";
2
- import { type Position } from '@threlte/core';
2
+ import { Vector3 } from 'three';
3
3
  import type { CollisionGroupsBitMask } from '../types/types';
4
4
  declare const __propDef: {
5
5
  props: {
6
- position?: Position | undefined;
6
+ position?: Parameters<Vector3['set']> | undefined;
7
7
  height?: number | undefined;
8
8
  radius?: number | undefined;
9
9
  speed?: number | undefined;
@@ -12,9 +12,6 @@ declare const __propDef: {
12
12
  groundCollisionGroups?: CollisionGroupsBitMask | undefined;
13
13
  };
14
14
  events: {
15
- groundenter: CustomEvent<void>;
16
- groundexit: CustomEvent<void>;
17
- } & {
18
15
  [evt: string]: CustomEvent<any>;
19
16
  };
20
17
  slots: {
@@ -1,78 +1,8 @@
1
1
  import type { CoefficientCombineRule, ColliderDesc } from '@dimforge/rapier3d-compat';
2
- import type { RawBroadPhase, RawCCDSolver, RawColliderSet, RawDebugRenderPipeline, RawImpulseJointSet, RawIntegrationParameters, RawIslandManager, RawMultibodyJointSet, RawNarrowPhase, RawPhysicsPipeline, RawQueryPipeline, RawRigidBodySet, RawSerializationPipeline } from '@dimforge/rapier3d-compat/raw';
3
- import type { Position, Rotation, TransformableObjectProperties } from '@threlte/core';
4
- import type { RigidBodyTypeString } from '../lib/parseRigidBodyType';
2
+ import type { Position, TransformableObjectProperties } from '@threlte/core';
5
3
  import type { AutoCollidersShapes, ColliderShapes, CollisionGroupsBitMask } from './types';
6
- export declare type Boolean3Array = [x: boolean, y: boolean, z: boolean];
7
4
  export declare type Vector3Array = [x: number, y: number, z: number];
8
5
  export declare type GravityType = 'static' | 'linear' | 'newtonian';
9
- export declare type RigidBodyProperties = Omit<TransformableObjectProperties, 'object'> & {
10
- /**
11
- * Specify the type of this rigid body
12
- */
13
- type?: RigidBodyTypeString;
14
- /** Whether or not this body can sleep.
15
- * default: true
16
- */
17
- canSleep?: boolean;
18
- /** The linear velocity of this body.
19
- * default: zero velocity
20
- */
21
- linearVelocity?: Position;
22
- /** The angular velocity of this body.
23
- * Default: zero velocity.
24
- */
25
- angularVelocity?: Rotation;
26
- /**
27
- * The scaling factor applied to the gravity affecting the rigid-body.
28
- * Default: 1.0
29
- */
30
- gravityScale?: number;
31
- /**
32
- * Whether or not Continous Collision Detection is enabled for this rigid-body.
33
- * https://rapier.rs/docs/user_guides/javascript/rigid_bodies#continuous-collision-detection
34
- * @default false
35
- */
36
- ccd?: boolean;
37
- /**
38
- * Locks all rotations that would have resulted from forces on the created rigid-body.
39
- */
40
- lockRotations?: boolean;
41
- /**
42
- * Locks all translations that would have resulted from forces on the created rigid-body.
43
- */
44
- lockTranslations?: boolean;
45
- /**
46
- * Allow rotation of this rigid-body only along specific axes.
47
- */
48
- enabledRotations?: Boolean3Array;
49
- /**
50
- * Allow rotation of this rigid-body only along specific axes.
51
- */
52
- enabledTranslations?: Boolean3Array;
53
- /**
54
- * Dominance is a non-realistic, but sometimes useful, feature.
55
- * It can be used to make one rigid-body immune to forces
56
- * originating from contacts with some other bodies.
57
- *
58
- * Number in the range -127 to 127, default is 0
59
- */
60
- dominance?: number;
61
- /**
62
- * Damping lets you slow down a rigid-body automatically. This can be used to
63
- * achieve a wide variety of effects like fake air friction. Larger values of
64
- * damping coefficients lead to a stronger slow-downs. Their default
65
- * values are 0.0 (no damping at all).
66
- */
67
- linearDamping?: number;
68
- /**
69
- * Damping lets you slow down a rigid-body automatically. This can be used to
70
- * achieve a wide variety of effects like fake air friction. Larger values of
71
- * damping coefficients lead to a stronger slow-downs. Their default
72
- * values are 0.0 (no damping at all).
73
- */
74
- angularDamping?: number;
75
- };
76
6
  export declare type ColliderProperties<Shape extends ColliderShapes> = Omit<TransformableObjectProperties, 'object'> & {
77
7
  shape: Shape;
78
8
  /**
@@ -122,23 +52,6 @@ export declare type ColliderProperties<Shape extends ColliderShapes> = Omit<Tran
122
52
  sensor?: boolean;
123
53
  };
124
54
  export declare type AutoCollidersProperties = Omit<ColliderProperties<AutoCollidersShapes>, 'args'>;
125
- export declare type InnerWorldProperties = {
126
- gravity?: Position;
127
- rawIntegrationParameters?: RawIntegrationParameters;
128
- rawIslands?: RawIslandManager;
129
- rawBroadPhase?: RawBroadPhase;
130
- rawNarrowPhase?: RawNarrowPhase;
131
- rawBodies?: RawRigidBodySet;
132
- rawColliders?: RawColliderSet;
133
- rawImpulseJoints?: RawImpulseJointSet;
134
- rawMultibodyJoints?: RawMultibodyJointSet;
135
- rawCCDSolver?: RawCCDSolver;
136
- rawQueryPipeline?: RawQueryPipeline;
137
- rawPhysicsPipeline?: RawPhysicsPipeline;
138
- rawSerializationPipeline?: RawSerializationPipeline;
139
- rawDebugRenderPipeline?: RawDebugRenderPipeline;
140
- };
141
- export declare type WorldProperties = InnerWorldProperties;
142
55
  export declare type CollisionGroupsProperties = {
143
56
  groups: CollisionGroupsBitMask;
144
57
  } | {
@@ -1,8 +1,8 @@
1
- import type { createEventDispatcher } from 'svelte';
2
- import type { RigidBody, RigidBodyHandle, TempContactManifold, ColliderHandle, Collider, Vector } from '@dimforge/rapier3d-compat';
3
- import type { createRapierContext } from '../lib/createRapierContext';
1
+ import type { Collider, ColliderHandle, RigidBody, RigidBodyHandle, TempContactManifold, Vector } from '@dimforge/rapier3d-compat';
2
+ import type { createRawEventDispatcher } from '@threlte/core';
4
3
  import type { Writable } from 'svelte/store';
5
4
  import type { useHasEventListeners } from '../hooks/useHasEventListener';
5
+ import type { createRapierContext } from '../lib/createRapierContext';
6
6
  export declare type ColliderShapes = 'ball' | 'capsule' | 'segment' | 'triangle' | 'roundTriangle' | 'polyline' | 'trimesh' | 'cuboid' | 'roundCuboid' | 'heightfield' | 'cylinder' | 'roundCylinder' | 'cone' | 'roundCone' | 'convexHull' | 'convexMesh' | 'roundConvexHull' | 'roundConvexMesh';
7
7
  export declare type AutoCollidersShapes = 'cuboid' | 'ball' | 'trimesh' | 'convexHull' | 'capsule';
8
8
  export declare type ColliderEventMap = {
@@ -42,8 +42,8 @@ export declare type RigidBodyEventMap = ColliderEventMap & {
42
42
  sleep: void;
43
43
  wake: void;
44
44
  };
45
- export declare type RigidBodyEventDispatcher = ReturnType<typeof createEventDispatcher<RigidBodyEventMap>>;
46
- export declare type ColliderEventDispatcher = ReturnType<typeof createEventDispatcher<ColliderEventMap>>;
45
+ export declare type RigidBodyEventDispatcher = ReturnType<typeof createRawEventDispatcher<RigidBodyEventMap>>;
46
+ export declare type ColliderEventDispatcher = ReturnType<typeof createRawEventDispatcher<ColliderEventMap>>;
47
47
  export declare type RigidBodyEventDispatchers = Map<RigidBodyHandle, RigidBodyEventDispatcher>;
48
48
  export declare type ColliderEventDispatchers = Map<ColliderHandle, ColliderEventDispatcher>;
49
49
  export declare type RapierContext = ReturnType<typeof createRapierContext>;
package/package.json CHANGED
@@ -1,16 +1,16 @@
1
1
  {
2
2
  "name": "@threlte/rapier",
3
- "version": "0.5.0",
3
+ "version": "1.0.0-next.1",
4
4
  "author": "Grischa Erbe <hello@legrisch.com> (https://legrisch.com)",
5
5
  "license": "MIT",
6
6
  "devDependencies": {
7
- "@dimforge/rapier3d-compat": "^0.9.0",
8
- "@sveltejs/adapter-auto": "next",
9
- "@sveltejs/adapter-static": "^1.0.0-next.29",
10
- "@sveltejs/kit": "next",
11
- "@threlte/core": "4.3.2",
7
+ "@dimforge/rapier3d-compat": "^0.11.2",
8
+ "@sveltejs/adapter-auto": "1.0.0-next.61",
9
+ "@sveltejs/adapter-static": "1.0.0-next.35",
10
+ "@sveltejs/kit": "1.0.0-next.377",
11
+ "@threlte/core": "6.0.0-next.2",
12
12
  "@types/node": "^18.0.3",
13
- "@types/three": "^0.140.0",
13
+ "@types/three": "^0.144.0",
14
14
  "@typescript-eslint/eslint-plugin": "^4.31.1",
15
15
  "@typescript-eslint/parser": "^4.31.1",
16
16
  "@yushijinhun/three-minifier-rollup": "^0.3.1",
@@ -23,7 +23,7 @@
23
23
  "svelte-check": "^2.7.0",
24
24
  "svelte-preprocess": "^4.10.5",
25
25
  "svelte2tsx": "^0.5.9",
26
- "three": "^0.140.2",
26
+ "three": "^0.151.3",
27
27
  "ts-node": "^10.8.2",
28
28
  "tsafe": "^0.9.0",
29
29
  "tslib": "^2.3.1",
@@ -45,6 +45,7 @@
45
45
  "check": "svelte-check --tsconfig ./tsconfig.json",
46
46
  "check:watch": "svelte-check --tsconfig ./tsconfig.json --watch",
47
47
  "lint": "prettier --check --plugin-search-dir=. . && eslint .",
48
- "format": "prettier --write --plugin-search-dir=. ."
48
+ "format": "prettier --write --plugin-search-dir=. .",
49
+ "cleanup": "rm -rf node_modules && rm -rf .svelte-kit"
49
50
  }
50
51
  }
@@ -1,5 +0,0 @@
1
- <script>import { useRevoluteJoint } from '../../hooks/useRevoluteJoint';
2
- export const { joint, rigidBodyA, rigidBodyB } = useRevoluteJoint();
3
- </script>
4
-
5
- <slot {rigidBodyA} {rigidBodyB} />
@@ -1,23 +0,0 @@
1
- import { SvelteComponentTyped } from "svelte";
2
- declare const __propDef: {
3
- props: {
4
- joint?: import("svelte/store").Writable<import("@dimforge/rapier3d-compat").RevoluteImpulseJoint> | undefined;
5
- rigidBodyA?: import("svelte/store").Writable<import("@dimforge/rapier3d-compat").RigidBody | undefined> | undefined;
6
- rigidBodyB?: import("svelte/store").Writable<import("@dimforge/rapier3d-compat").RigidBody | undefined> | undefined;
7
- };
8
- events: {
9
- [evt: string]: CustomEvent<any>;
10
- };
11
- slots: {
12
- default: {
13
- rigidBodyA: import("svelte/store").Writable<import("@dimforge/rapier3d-compat").RigidBody | undefined>;
14
- rigidBodyB: import("svelte/store").Writable<import("@dimforge/rapier3d-compat").RigidBody | undefined>;
15
- };
16
- };
17
- };
18
- export declare type RevoluteJointProps = typeof __propDef.props;
19
- export declare type RevoluteJointEvents = typeof __propDef.events;
20
- export declare type RevoluteJointSlots = typeof __propDef.slots;
21
- export default class RevoluteJoint extends SvelteComponentTyped<RevoluteJointProps, RevoluteJointEvents, RevoluteJointSlots> {
22
- }
23
- export {};
@@ -1,3 +0,0 @@
1
- import type { Position } from '@threlte/core';
2
- import { Vector3 } from 'three';
3
- export declare const positionToVector3: (position?: Position, v3?: Vector3) => Vector3;
@@ -1,8 +0,0 @@
1
- import { Vector3 } from 'three';
2
- export const positionToVector3 = (position, v3) => {
3
- if (v3) {
4
- v3.set(position?.x ?? 0, position?.y ?? 0, position?.z ?? 0);
5
- return v3;
6
- }
7
- return new Vector3(position?.x ?? 0, position?.y ?? 0, position?.z ?? 0);
8
- };
@@ -1,3 +0,0 @@
1
- import type { Rotation } from '@threlte/core';
2
- import { Euler } from 'three';
3
- export declare const rotationToEuler: (rotation?: Rotation, euler?: Euler) => Euler;
@@ -1,8 +0,0 @@
1
- import { Euler } from 'three';
2
- export const rotationToEuler = (rotation, euler) => {
3
- if (euler) {
4
- euler.set(rotation?.x ?? 0, rotation?.y ?? 0, rotation?.z ?? 0);
5
- return euler;
6
- }
7
- return new Euler(rotation?.x ?? 0, rotation?.y ?? 0, rotation?.z ?? 0);
8
- };
@@ -1,3 +0,0 @@
1
- import type { Rotation } from '@threlte/core';
2
- import { Quaternion } from 'three';
3
- export declare const rotationToQuaternion: (rotation?: Rotation, quaternion?: Quaternion) => Quaternion;
@@ -1,10 +0,0 @@
1
- import { Quaternion } from 'three';
2
- import { rotationToEuler } from './rotationToEuler';
3
- export const rotationToQuaternion = (rotation, quaternion) => {
4
- const euler = rotationToEuler(rotation);
5
- if (quaternion) {
6
- quaternion.setFromEuler(euler);
7
- return quaternion;
8
- }
9
- return new Quaternion().setFromEuler(euler);
10
- };
@@ -1,3 +0,0 @@
1
- import type { Scale } from '@threlte/core';
2
- import { Vector3 } from 'three';
3
- export declare const scaleToVector3: (scale?: Scale, v3?: Vector3) => Vector3;
@@ -1,16 +0,0 @@
1
- import { Vector3 } from 'three';
2
- export const scaleToVector3 = (scale, v3) => {
3
- if (v3) {
4
- if (typeof scale === 'number') {
5
- v3.set(scale, scale, scale);
6
- }
7
- else {
8
- v3.set(scale?.x ?? 1, scale?.y ?? 1, scale?.z ?? 1);
9
- }
10
- return v3;
11
- }
12
- if (typeof scale === 'number') {
13
- return new Vector3(scale, scale, scale);
14
- }
15
- return new Vector3(scale?.x ?? 1, scale?.y ?? 1, scale?.z ?? 1);
16
- };