@threlte/rapier 1.0.0-next.4 → 1.0.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.
package/README.md
CHANGED
|
@@ -8,12 +8,12 @@
|
|
|
8
8
|
<a href="https://discord.com/channels/985983540804091964">
|
|
9
9
|
<img alt="discord" src="https://img.shields.io/discord/985983540804091964?label=discord&color=fe4100&labelColor=171d27&logo=discord&logoColor=white"/>
|
|
10
10
|
</a>
|
|
11
|
-
<a href="https://
|
|
11
|
+
<a href="https://threlte.xyz">
|
|
12
12
|
<img alt="docs" src="https://img.shields.io/website?down_color=red&down_message=offline&label=docs&color=fe4100&labelColor=171d27&up_message=online&url=https%3A%2F%2Fthrelte.xyz&logo=svelte&logoColor=white"/>
|
|
13
13
|
</a>
|
|
14
14
|
</div>
|
|
15
15
|
|
|
16
|
-
<a href="https://
|
|
16
|
+
<a href="https://threlte.xyz">
|
|
17
17
|
<img src="./threlte-banner.jpg"/>
|
|
18
18
|
</a>
|
|
19
19
|
|
|
@@ -23,11 +23,11 @@ Threlte is a [Svelte](https://svelte.dev/) library that simplifies creating 3D a
|
|
|
23
23
|
|
|
24
24
|
Threlte's **3D rendering** is powered by [Three.js](https://threejs.org/), and it also provides a **physics engine** through [Rapier](https://rapier.rs/) and an **animation studio** via [Theatre.js](https://www.theatrejs.com/); see [packages](#packages) for details.
|
|
25
25
|
|
|
26
|
-
Check out our **[documentation](https://
|
|
26
|
+
Check out our **[documentation](https://threlte.xyz)** and our **[Discord community](https://discord.gg/EqUBCfCaGm)**.
|
|
27
27
|
|
|
28
28
|
## @threlte/rapier
|
|
29
29
|
|
|
30
|
-
[@threlte/rapier](https://
|
|
30
|
+
[@threlte/rapier](https://threlte.xyz/docs/reference/rapier/getting-started) enables performant physics in your Threlte app through the [Rapier engine](https://rapier.rs/).
|
|
31
31
|
|
|
32
32
|
This is a great way to implement key features of games or simulators, such as collisions, gravity and attraction fields.
|
|
33
33
|
|
|
@@ -42,7 +42,7 @@ npm create threlte my-project
|
|
|
42
42
|
```
|
|
43
43
|
and select the `@threlte/rapier` option.
|
|
44
44
|
|
|
45
|
-
Alternatively you can check out the full [installation instructions](https://
|
|
45
|
+
Alternatively you can check out the full [installation instructions](https://threlte.xyz/docs/learn/getting-started/installation).
|
|
46
46
|
|
|
47
47
|
### Support
|
|
48
48
|
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { Euler, Quaternion, Vector3 } from 'three';
|
|
2
2
|
import { useJoint } from './useJoint';
|
|
3
|
+
import { isEuler, isVector3 } from './utils';
|
|
3
4
|
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
4
5
|
export const useFixedJoint = (anchorA, frameA, anchorB, frameB) => {
|
|
5
|
-
const jaA = anchorA
|
|
6
|
-
const jfA = new Quaternion().setFromEuler(frameA
|
|
7
|
-
const jaB = anchorB
|
|
8
|
-
const jfB = new Quaternion().setFromEuler(frameB
|
|
6
|
+
const jaA = isVector3(anchorA) ? anchorA : new Vector3(...anchorA);
|
|
7
|
+
const jfA = new Quaternion().setFromEuler(isEuler(frameA) ? frameA : new Euler(...frameA));
|
|
8
|
+
const jaB = isVector3(anchorB) ? anchorB : new Vector3(...anchorB);
|
|
9
|
+
const jfB = new Quaternion().setFromEuler(isEuler(frameB) ? frameB : new Euler(...frameB));
|
|
9
10
|
return useJoint((rbA, rbB, { world, rapier }) => {
|
|
10
11
|
const params = rapier.JointData.fixed(jaA, jfA, jaB, jfB);
|
|
11
12
|
return world.createImpulseJoint(params, rbA, rbB, true);
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { Vector3 } from 'three';
|
|
2
2
|
import { useJoint } from './useJoint';
|
|
3
|
+
import { isVector3 } from './utils';
|
|
3
4
|
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
4
5
|
export const usePrismaticJoint = (anchorA, anchorB, axis, limits) => {
|
|
5
6
|
return useJoint((rbA, rbB, { world, rapier }) => {
|
|
6
|
-
const jaA = anchorA
|
|
7
|
-
const jaB = anchorB
|
|
8
|
-
const jAxis = (axis
|
|
7
|
+
const jaA = isVector3(anchorA) ? anchorA : new Vector3(...anchorA);
|
|
8
|
+
const jaB = isVector3(anchorB) ? anchorB : new Vector3(...anchorB);
|
|
9
|
+
const jAxis = (isVector3(axis) ? axis : new Vector3(...axis)).normalize();
|
|
9
10
|
const params = rapier.JointData.prismatic(jaA, jaB, jAxis);
|
|
10
11
|
if (limits) {
|
|
11
12
|
params.limitsEnabled = true;
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { Vector3 } from 'three';
|
|
2
2
|
import { useJoint } from './useJoint';
|
|
3
|
+
import { isVector3 } from './utils';
|
|
3
4
|
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
4
5
|
export const useRevoluteJoint = (anchorA, anchorB, axis, limits) => {
|
|
5
6
|
return useJoint((rbA, rbB, { world, rapier }) => {
|
|
6
|
-
const jaA = anchorA
|
|
7
|
-
const jaB = anchorB
|
|
8
|
-
const jAxis = (axis
|
|
7
|
+
const jaA = isVector3(anchorA) ? anchorA : new Vector3(...anchorA);
|
|
8
|
+
const jaB = isVector3(anchorB) ? anchorB : new Vector3(...anchorB);
|
|
9
|
+
const jAxis = (isVector3(axis) ? axis : new Vector3(...axis)).normalize();
|
|
9
10
|
const params = rapier.JointData.revolute(jaA, jaB, jAxis);
|
|
10
11
|
if (limits) {
|
|
11
12
|
params.limitsEnabled = true;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { Vector3 } from 'three';
|
|
2
2
|
import { useJoint } from './useJoint';
|
|
3
|
+
import { isVector3 } from './utils';
|
|
3
4
|
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
4
5
|
export const useSphericalJoint = (anchorA, anchorB) => {
|
|
5
6
|
return useJoint((rbA, rbB, { world, rapier }) => {
|
|
6
|
-
const jaA = anchorA
|
|
7
|
-
const jaB = anchorB
|
|
7
|
+
const jaA = isVector3(anchorA) ? anchorA : new Vector3(...anchorA);
|
|
8
|
+
const jaB = isVector3(anchorB) ? anchorB : new Vector3(...anchorB);
|
|
8
9
|
const params = rapier.JointData.spherical(jaA, jaB);
|
|
9
10
|
return world.createImpulseJoint(params, rbA, rbB, true);
|
|
10
11
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@threlte/rapier",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"author": "Grischa Erbe <hello@legrisch.com> (https://legrisch.com)",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"devDependencies": {
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"type-fest": "^2.13.0",
|
|
27
27
|
"typescript": "^5.0.0",
|
|
28
28
|
"vite": "^4.3.6",
|
|
29
|
-
"@threlte/core": "6.0.0
|
|
29
|
+
"@threlte/core": "6.0.0"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"three": "^0.151.3",
|