@threlte/rapier 1.0.0 → 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.
@@ -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 instanceof Vector3 ? anchorA : new Vector3(...anchorA);
6
- const jfA = new Quaternion().setFromEuler(frameA instanceof Euler ? frameA : new Euler(...frameA));
7
- const jaB = anchorB instanceof Vector3 ? anchorB : new Vector3(...anchorB);
8
- const jfB = new Quaternion().setFromEuler(frameB instanceof Euler ? frameB : new Euler(...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 instanceof Vector3 ? anchorA : new Vector3(...anchorA);
7
- const jaB = anchorB instanceof Vector3 ? anchorB : new Vector3(...anchorB);
8
- const jAxis = (axis instanceof Vector3 ? axis : new Vector3(...axis)).normalize();
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 instanceof Vector3 ? anchorA : new Vector3(...anchorA);
7
- const jaB = anchorB instanceof Vector3 ? anchorB : new Vector3(...anchorB);
8
- const jAxis = (axis instanceof Vector3 ? axis : new Vector3(...axis)).normalize();
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 instanceof Vector3 ? anchorA : new Vector3(...anchorA);
7
- const jaB = anchorB instanceof Vector3 ? anchorB : new Vector3(...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
  });
@@ -0,0 +1,3 @@
1
+ import type { Euler, Vector3 } from 'three';
2
+ export declare const isVector3: (v: any) => v is Vector3;
3
+ export declare const isEuler: (v: any) => v is Euler;
@@ -0,0 +1,6 @@
1
+ export const isVector3 = (v) => {
2
+ return v.isVector3;
3
+ };
4
+ export const isEuler = (v) => {
5
+ return v.isEuler;
6
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@threlte/rapier",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "author": "Grischa Erbe <hello@legrisch.com> (https://legrisch.com)",
5
5
  "license": "MIT",
6
6
  "devDependencies": {