@threlte/rapier 0.4.0 → 1.0.0-next.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 (47) hide show
  1. package/dist/CHANGELOG.md +12 -0
  2. package/dist/components/Attractor/Attractor.svelte +54 -0
  3. package/dist/components/Attractor/Attractor.svelte.d.ts +21 -0
  4. package/dist/components/Colliders/AutoColliders.svelte +16 -10
  5. package/dist/components/Colliders/AutoColliders.svelte.d.ts +74 -0
  6. package/dist/components/Colliders/Collider.svelte +24 -15
  7. package/dist/components/Colliders/Collider.svelte.d.ts +105 -112
  8. package/dist/components/CollisionGroups/CollisionGroups.svelte.d.ts +29 -19
  9. package/dist/components/Debug/Debug.svelte +15 -10
  10. package/dist/components/Debug/Debug.svelte.d.ts +6 -60
  11. package/dist/components/RigidBody/RigidBody.svelte +14 -32
  12. package/dist/components/RigidBody/RigidBody.svelte.d.ts +93 -67
  13. package/dist/components/World/InnerWorld.svelte +9 -6
  14. package/dist/components/World/InnerWorld.svelte.d.ts +14 -15
  15. package/dist/components/World/World.svelte +6 -2
  16. package/dist/components/World/World.svelte.d.ts +35 -32
  17. package/dist/hooks/useFixedJoint.d.ts +2 -2
  18. package/dist/hooks/useFixedJoint.js +6 -3
  19. package/dist/hooks/usePrismaticJoint.d.ts +2 -2
  20. package/dist/hooks/usePrismaticJoint.js +5 -2
  21. package/dist/hooks/useRevoluteJoint.d.ts +2 -2
  22. package/dist/hooks/useRevoluteJoint.js +5 -2
  23. package/dist/hooks/useSphericalJoint.d.ts +2 -2
  24. package/dist/hooks/useSphericalJoint.js +4 -2
  25. package/dist/index.d.ts +2 -1
  26. package/dist/index.js +1 -0
  27. package/dist/lib/applyTransforms.d.ts +2 -3
  28. package/dist/lib/applyTransforms.js +7 -16
  29. package/dist/lib/createRapierContext.d.ts +1 -0
  30. package/dist/lib/createRapierContext.js +3 -1
  31. package/dist/lib/eulerToQuaternion.d.ts +7 -0
  32. package/dist/lib/eulerToQuaternion.js +12 -0
  33. package/dist/lib/scaleColliderArgs.js +2 -2
  34. package/dist/recipes/BasicPlayerController.svelte +12 -6
  35. package/dist/recipes/BasicPlayerController.svelte.d.ts +2 -2
  36. package/dist/types/components.d.ts +29 -88
  37. package/package.json +9 -8
  38. package/dist/components/Joints/RevoluteJoint.svelte +0 -5
  39. package/dist/components/Joints/RevoluteJoint.svelte.d.ts +0 -23
  40. package/dist/lib/positionToVector3.d.ts +0 -3
  41. package/dist/lib/positionToVector3.js +0 -8
  42. package/dist/lib/rotationToEuler.d.ts +0 -3
  43. package/dist/lib/rotationToEuler.js +0 -8
  44. package/dist/lib/rotationToQuaternion.d.ts +0 -3
  45. package/dist/lib/rotationToQuaternion.js +0 -10
  46. package/dist/lib/scaleToVector3.d.ts +0 -3
  47. package/dist/lib/scaleToVector3.js +0 -16
@@ -1,17 +1,8 @@
1
- import { Object3D, Vector3 } from 'three';
2
- import { positionToVector3 } from './positionToVector3';
3
- import { rotationToEuler } from './rotationToEuler';
4
- import { scaleToVector3 } from './scaleToVector3';
5
- export const applyTransforms = (object, position, rotation, scale, lookAt) => {
6
- object.position.copy(positionToVector3(position));
7
- if (lookAt instanceof Object3D) {
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
  };
@@ -13,4 +13,5 @@ export declare const createRapierContext: (gravity: RAPIER.Vector, rawIntegratio
13
13
  removeColliderFromContext: (collider: Collider) => void;
14
14
  addRigidBodyToContext: (rigidBody: RigidBody, object: Object3D, eventDispatcher: RigidBodyEventDispatcher) => void;
15
15
  removeRigidBodyFromContext: (rigidBody: RigidBody) => void;
16
+ debug: import("svelte/store").Writable<boolean>;
16
17
  };
@@ -1,4 +1,5 @@
1
1
  import RAPIER from '@dimforge/rapier3d-compat';
2
+ import { writable } from 'svelte/store';
2
3
  export const createRapierContext = (...args) => {
3
4
  const world = new RAPIER.World(...args);
4
5
  const colliderObjects = new Map();
@@ -51,6 +52,7 @@ export const createRapierContext = (...args) => {
51
52
  addColliderToContext,
52
53
  removeColliderFromContext,
53
54
  addRigidBodyToContext,
54
- removeRigidBodyFromContext
55
+ removeRigidBodyFromContext,
56
+ debug: writable(false),
55
57
  };
56
58
  };
@@ -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
@@ -1,4 +1,4 @@
1
- <script>import { Group, useFrame, useThrelte } from '@threlte/core';
1
+ <script>import { T, useFrame, useThrelte } from '@threlte/core';
2
2
  import { createEventDispatcher } from 'svelte';
3
3
  import { Vector2, Vector3 } from 'three';
4
4
  import Collider from '../components/Colliders/Collider.svelte';
@@ -99,7 +99,10 @@ const onKeyUp = (e) => {
99
99
  };
100
100
  </script>
101
101
 
102
- <svelte:window on:keydown|preventDefault={onKeyDown} on:keyup|preventDefault={onKeyUp} />
102
+ <svelte:window
103
+ on:keydown|preventDefault={onKeyDown}
104
+ on:keyup|preventDefault={onKeyUp}
105
+ />
103
106
 
104
107
  <RigidBody
105
108
  dominance={127}
@@ -109,7 +112,10 @@ const onKeyUp = (e) => {
109
112
  type={'dynamic'}
110
113
  >
111
114
  <CollisionGroups groups={playerCollisionGroups}>
112
- <Collider shape={'capsule'} args={[height / 2 - radius, radius]} />
115
+ <Collider
116
+ shape={'capsule'}
117
+ args={[height / 2 - radius, radius]}
118
+ />
113
119
  </CollisionGroups>
114
120
 
115
121
  <CollisionGroups groups={groundCollisionGroups}>
@@ -119,11 +125,11 @@ const onKeyUp = (e) => {
119
125
  on:sensorexit={() => (groundsSensored -= 1)}
120
126
  shape={'ball'}
121
127
  args={[radius * 1.2]}
122
- position={{ y: -height / 2 + radius }}
128
+ position={[0, -height / 2 + radius, 0]}
123
129
  />
124
130
  </CollisionGroups>
125
131
 
126
- <Group position={{ y: -height / 2 }}>
132
+ <T.Group position.y={-height / 2}>
127
133
  <slot />
128
- </Group>
134
+ </T.Group>
129
135
  </RigidBody>
@@ -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;
@@ -1,77 +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
- export declare type RigidBodyProperties = Omit<TransformableObjectProperties, 'object'> & {
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?: Position;
21
- /** The angular velocity of this body.
22
- * Default: zero velocity.
23
- */
24
- angularVelocity?: Rotation;
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 rotation 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
- };
5
+ export declare type GravityType = 'static' | 'linear' | 'newtonian';
75
6
  export declare type ColliderProperties<Shape extends ColliderShapes> = Omit<TransformableObjectProperties, 'object'> & {
76
7
  shape: Shape;
77
8
  /**
@@ -121,26 +52,36 @@ export declare type ColliderProperties<Shape extends ColliderShapes> = Omit<Tran
121
52
  sensor?: boolean;
122
53
  };
123
54
  export declare type AutoCollidersProperties = Omit<ColliderProperties<AutoCollidersShapes>, 'args'>;
124
- export declare type InnerWorldProperties = {
125
- gravity?: Position;
126
- rawIntegrationParameters?: RawIntegrationParameters;
127
- rawIslands?: RawIslandManager;
128
- rawBroadPhase?: RawBroadPhase;
129
- rawNarrowPhase?: RawNarrowPhase;
130
- rawBodies?: RawRigidBodySet;
131
- rawColliders?: RawColliderSet;
132
- rawImpulseJoints?: RawImpulseJointSet;
133
- rawMultibodyJoints?: RawMultibodyJointSet;
134
- rawCCDSolver?: RawCCDSolver;
135
- rawQueryPipeline?: RawQueryPipeline;
136
- rawPhysicsPipeline?: RawPhysicsPipeline;
137
- rawSerializationPipeline?: RawSerializationPipeline;
138
- rawDebugRenderPipeline?: RawDebugRenderPipeline;
139
- };
140
- export declare type WorldProperties = InnerWorldProperties;
141
55
  export declare type CollisionGroupsProperties = {
142
56
  groups: CollisionGroupsBitMask;
143
57
  } | {
144
58
  filter: CollisionGroupsBitMask;
145
59
  memberships: CollisionGroupsBitMask;
146
60
  };
61
+ export declare type AttractorProperties = Omit<TransformableObjectProperties, 'object'> & {
62
+ /**
63
+ * The radius for the Attractor's sphere of influence within which rigid-bodies will be affected.
64
+ * Default: 10.0
65
+ */
66
+ range?: number;
67
+ /**
68
+ * The strength factor applied to the impulse affecting rigid-bodies within range. For newtonian
69
+ * calculations, strength is treated as m1 mass.
70
+ * Default: 1.0
71
+ */
72
+ strength?: number;
73
+ /**
74
+ * The method of calculating gravity on rigid bodies within range.
75
+ * 'static' = the same force (strength) is applied on bodies within range, regardless of distance
76
+ * 'linear' = force is calculated as strength * distance / range (force decreases the farther a body is from the attractor position)
77
+ * 'newtonian' = force is calculated as gravitationalConstant * mass1 * mass2 / Math.pow(distance, 2)
78
+ * Default: 'static'
79
+ */
80
+ gravityType?: GravityType;
81
+ /**
82
+ * The gravitational constant used to calculate force in newtonian calculations. Most people probably won't use this,
83
+ * but it provides an option for more realistic physics simulations.
84
+ * Default: 6.673e-11
85
+ */
86
+ gravitationalConstant?: number;
87
+ };
package/package.json CHANGED
@@ -1,16 +1,16 @@
1
1
  {
2
2
  "name": "@threlte/rapier",
3
- "version": "0.4.0",
3
+ "version": "1.0.0-next.0",
4
4
  "author": "Grischa Erbe <hello@legrisch.com> (https://legrisch.com)",
5
5
  "license": "MIT",
6
6
  "devDependencies": {
7
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",
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.0",
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.145.0",
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
- };