@threlte/rapier 0.5.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.
- package/dist/CHANGELOG.md +6 -0
- package/dist/components/Attractor/Attractor.svelte +17 -13
- package/dist/components/Attractor/Attractor.svelte.d.ts +20 -22
- package/dist/components/Colliders/AutoColliders.svelte +16 -10
- package/dist/components/Colliders/AutoColliders.svelte.d.ts +74 -0
- package/dist/components/Colliders/Collider.svelte +24 -15
- package/dist/components/Colliders/Collider.svelte.d.ts +105 -112
- package/dist/components/CollisionGroups/CollisionGroups.svelte.d.ts +29 -19
- package/dist/components/Debug/Debug.svelte +13 -10
- package/dist/components/Debug/Debug.svelte.d.ts +6 -60
- package/dist/components/RigidBody/RigidBody.svelte +14 -32
- package/dist/components/RigidBody/RigidBody.svelte.d.ts +93 -67
- package/dist/components/World/InnerWorld.svelte +9 -6
- package/dist/components/World/InnerWorld.svelte.d.ts +14 -15
- package/dist/components/World/World.svelte +6 -2
- package/dist/components/World/World.svelte.d.ts +35 -32
- package/dist/hooks/useFixedJoint.d.ts +2 -2
- package/dist/hooks/useFixedJoint.js +6 -3
- package/dist/hooks/usePrismaticJoint.d.ts +2 -2
- package/dist/hooks/usePrismaticJoint.js +5 -2
- package/dist/hooks/useRevoluteJoint.d.ts +2 -2
- package/dist/hooks/useRevoluteJoint.js +5 -2
- package/dist/hooks/useSphericalJoint.d.ts +2 -2
- package/dist/hooks/useSphericalJoint.js +4 -2
- package/dist/index.d.ts +1 -1
- package/dist/lib/applyTransforms.d.ts +2 -3
- package/dist/lib/applyTransforms.js +7 -16
- package/dist/lib/eulerToQuaternion.d.ts +7 -0
- package/dist/lib/eulerToQuaternion.js +12 -0
- package/dist/lib/scaleColliderArgs.js +2 -2
- package/dist/recipes/BasicPlayerController.svelte +12 -6
- package/dist/recipes/BasicPlayerController.svelte.d.ts +2 -2
- package/dist/types/components.d.ts +1 -88
- package/package.json +9 -8
- package/dist/components/Joints/RevoluteJoint.svelte +0 -5
- package/dist/components/Joints/RevoluteJoint.svelte.d.ts +0 -23
- package/dist/lib/positionToVector3.d.ts +0 -3
- package/dist/lib/positionToVector3.js +0 -8
- package/dist/lib/rotationToEuler.d.ts +0 -3
- package/dist/lib/rotationToEuler.js +0 -8
- package/dist/lib/rotationToQuaternion.d.ts +0 -3
- package/dist/lib/rotationToQuaternion.js +0 -10
- package/dist/lib/scaleToVector3.d.ts +0 -3
- package/dist/lib/scaleToVector3.js +0 -16
|
@@ -1,17 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|
};
|
|
@@ -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]
|
|
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 {
|
|
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
|
|
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
|
|
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={
|
|
128
|
+
position={[0, -height / 2 + radius, 0]}
|
|
123
129
|
/>
|
|
124
130
|
</CollisionGroups>
|
|
125
131
|
|
|
126
|
-
<Group position={
|
|
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 {
|
|
2
|
+
import { Vector3 } from 'three';
|
|
3
3
|
import type { CollisionGroupsBitMask } from '../types/types';
|
|
4
4
|
declare const __propDef: {
|
|
5
5
|
props: {
|
|
6
|
-
position?:
|
|
6
|
+
position?: Parameters<Vector3['set']> | undefined;
|
|
7
7
|
height?: number | undefined;
|
|
8
8
|
radius?: number | undefined;
|
|
9
9
|
speed?: number | undefined;
|
|
@@ -1,78 +1,8 @@
|
|
|
1
1
|
import type { CoefficientCombineRule, ColliderDesc } from '@dimforge/rapier3d-compat';
|
|
2
|
-
import type {
|
|
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
|
} | {
|
package/package.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@threlte/rapier",
|
|
3
|
-
"version": "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": "
|
|
10
|
-
"@sveltejs/kit": "next",
|
|
11
|
-
"@threlte/core": "
|
|
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.
|
|
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.
|
|
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,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,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,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,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
|
-
};
|