@threlte/rapier 1.0.0 → 1.0.2
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
|
@@ -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.2",
|
|
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.
|
|
29
|
+
"@threlte/core": "6.0.1"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"three": "^0.151.3",
|