@react-three/rapier 0.4.0 → 0.4.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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @react-three/rapier
2
2
 
3
+ ## 0.4.1
4
+
5
+ ### Patch Changes
6
+
7
+ - bb7a269: Add useful proxied api methods to rigidbody
8
+
3
9
  ## 0.4.0
4
10
 
5
11
  ### Minor Changes
@@ -1,35 +1,129 @@
1
1
  import { Collider, ColliderDesc, ImpulseJoint, JointData, RigidBody, RigidBodyDesc, World } from "@dimforge/rapier3d-compat";
2
2
  import { Quaternion, Vector3 } from "three";
3
3
  import { RefGetter } from "./types";
4
- export declare const createRigidBodyApi: (ref: RefGetter<RigidBody>) => {
5
- raw: () => RigidBody | undefined;
6
- readonly handle: number;
7
- applyImpulse({ x, y, z }: Vector3): void;
8
- applyTorqueImpulse({ x, y, z }: Vector3): void;
4
+ declare type Vector3Object = {
5
+ x: number;
6
+ y: number;
7
+ z: number;
8
+ };
9
+ export interface RigidBodyApi {
10
+ /**
11
+ * Get the raw RigidBody
12
+ */
13
+ raw(): RigidBody;
14
+ /**
15
+ * The handle of this RigidBody
16
+ */
17
+ handle: number;
18
+ /**
19
+ * The mass of this rigid-body.
20
+ */
21
+ mass(): number;
22
+ /**
23
+ * Applies an impulse at the center-of-mass of this rigid-body.
24
+ */
25
+ applyImpulse(impulseVector: Vector3Object): void;
26
+ /**
27
+ * Applies an impulsive torque at the center-of-mass of this rigid-body.
28
+ */
29
+ applyTorqueImpulse(torqueVector: Vector3Object): void;
30
+ /**
31
+ * Applies an impulse at the given world-space point of this rigid-body.
32
+ */
33
+ applyImpulseAtPoint(impulseVector: Vector3Object, impulsePoint: Vector3Object): void;
34
+ /**
35
+ * Adds a force at the center-of-mass of this rigid-body.
36
+ */
37
+ addForce(force: Vector3Object): void;
38
+ /**
39
+ * Adds a force at the given world-space point of this rigid-body.
40
+ */
41
+ addForceAtPoint(force: Vector3Object, point: Vector3Object): void;
42
+ /**
43
+ * Adds a torque at the center-of-mass of this rigid-body.
44
+ */
45
+ addTorque(torque: Vector3Object): void;
46
+ /**
47
+ * The world-space translation of this rigid-body.
48
+ */
9
49
  translation(): Vector3;
50
+ /**
51
+ * Sets the translation of this rigid-body.
52
+ */
53
+ setTranslation(translation: Vector3Object): void;
54
+ /**
55
+ * The world-space orientation of this rigid-body.
56
+ */
10
57
  rotation(): Quaternion;
11
- setNextKinematicRotation({ x, y, z }: Vector3): void;
12
- setNextKinematicTranslation({ x, y, z }: Vector3): void;
13
- };
58
+ /**
59
+ * Sets the rotation quaternion of this rigid-body.
60
+ */
61
+ setRotation(rotation: Vector3Object): void;
62
+ /**
63
+ * The linear velocity of this rigid-body.
64
+ */
65
+ linvel(): Vector3;
66
+ /**
67
+ * Sets the linear velocity of this rigid-body.
68
+ */
69
+ setLinvel(velocity: Vector3Object): void;
70
+ /**
71
+ * The angular velocity of this rigid-body.
72
+ */
73
+ angvel(): Vector3;
74
+ /**
75
+ * Sets the angular velocity of this rigid-body.
76
+ */
77
+ setAngvel(velocity: Vector3Object): void;
78
+ /**
79
+ * If this rigid body is kinematic, sets its future rotation after the next timestep integration.
80
+ *
81
+ * This should be used instead of rigidBody.setRotation to make the dynamic object interacting with this
82
+ * kinematic body behave as expected. Internally, Rapier will compute an artificial velocity for this
83
+ * rigid-body from its current position and its next kinematic position. This velocity will be used
84
+ * to compute forces on dynamic bodies interacting with this body.
85
+ */
86
+ setNextKinematicRotation(rotation: Vector3Object): void;
87
+ /**
88
+ * If this rigid body is kinematic, sets its future rotation after the next timestep integration.
89
+ *
90
+ * This should be used instead of rigidBody.setRotation to make the dynamic object interacting with
91
+ * this kinematic body behave as expected. Internally, Rapier will compute an artificial velocity
92
+ * for this rigid-body from its current position and its next kinematic position. This velocity
93
+ * will be used to compute forces on dynamic bodies interacting with this body.
94
+ */
95
+ setNextKinematicTranslation(translation: Vector3Object): void;
96
+ /**
97
+ * Resets to zero the user forces (but not torques) applied to this rigid-body.
98
+ */
99
+ resetForces(): void;
100
+ /**
101
+ * Resets to zero the user torques applied to this rigid-body.
102
+ */
103
+ resetTorques(): void;
104
+ }
105
+ export declare const createRigidBodyApi: (ref: RefGetter<RigidBody>) => RigidBodyApi;
14
106
  export declare const createColliderApi: (ref: RefGetter<Collider>) => {
15
107
  raw: () => Collider | undefined;
16
108
  readonly handle: number;
17
109
  };
18
- export declare const createWorldApi: (ref: RefGetter<World>) => {
19
- raw: () => World | undefined;
20
- getCollider: (handle: number) => Collider;
21
- getRigidBody: (handle: number) => RigidBody;
22
- createRigidBody: (desc: RigidBodyDesc) => RigidBody;
23
- createCollider: (desc: ColliderDesc, rigidBody: RigidBody) => Collider;
24
- removeRigidBody: (rigidBody: RigidBody) => void;
25
- removeCollider: (collider: Collider) => void;
26
- createImpulseJoint: (params: JointData, rigidBodyA: RigidBody, rigidBodyB: RigidBody) => ImpulseJoint;
27
- removeImpulseJoint: (joint: ImpulseJoint) => void;
28
- forEachCollider: (callback: (collider: Collider) => void) => void;
29
- };
110
+ export interface WorldApi {
111
+ raw(): World;
112
+ getCollider(handle: number): Collider | undefined;
113
+ getRigidBody(handle: number): RigidBody | undefined;
114
+ createRigidBody(desc: RigidBodyDesc): RigidBody;
115
+ createCollider(desc: ColliderDesc, rigidBody: RigidBody): Collider;
116
+ removeRigidBody(rigidBody: RigidBody): void;
117
+ removeCollider(collider: Collider): void;
118
+ createImpulseJoint(params: JointData, rigidBodyA: RigidBody, rigidBodyB: RigidBody): ImpulseJoint;
119
+ removeImpulseJoint(joint: ImpulseJoint): void;
120
+ forEachCollider(callback: (collider: Collider) => void): void;
121
+ }
122
+ export declare const createWorldApi: (ref: RefGetter<World>) => WorldApi;
30
123
  export declare const createJointApi: (ref: RefGetter<ImpulseJoint>) => {
31
124
  raw: () => ImpulseJoint | undefined;
32
125
  readonly handle: number;
33
126
  configureMotorPosition: (targetPos: number, stiffness: number, damping: number) => void;
34
127
  configureMotorVelocity: (targetVel: number, damping: number) => void;
35
128
  };
129
+ export {};
@@ -1,20 +1,10 @@
1
1
  import React from "react";
2
2
  import { ReactNode } from "react";
3
- import { Vector3 } from "three";
4
3
  import { BallArgs, CapsuleArgs, ConeArgs, ConvexHullArgs, CuboidArgs, CylinderArgs, HeightfieldArgs, RoundCuboidArgs, TrimeshArgs, UseColliderOptions, UseRigidBodyOptions } from "./types";
5
4
  interface RigidBodyProps extends UseRigidBodyOptions {
6
5
  children?: ReactNode;
7
6
  }
8
- export declare const RigidBody: React.ForwardRefExoticComponent<RigidBodyProps & React.RefAttributes<{
9
- raw: () => import("@dimforge/rapier3d-compat/dynamics/rigid_body").RigidBody | undefined;
10
- readonly handle: number;
11
- applyImpulse({ x, y, z }: Vector3): void;
12
- applyTorqueImpulse({ x, y, z }: Vector3): void;
13
- translation(): Vector3;
14
- rotation(): import("three").Quaternion;
15
- setNextKinematicRotation({ x, y, z }: Vector3): void;
16
- setNextKinematicTranslation({ x, y, z }: Vector3): void;
17
- }>>;
7
+ export declare const RigidBody: React.ForwardRefExoticComponent<RigidBodyProps & React.RefAttributes<import("./api").RigidBodyApi>>;
18
8
  declare type UseColliderOptionsRequiredArgs<T> = Omit<UseColliderOptions<T>, "args"> & {
19
9
  args: T;
20
10
  children?: ReactNode;
@@ -1,74 +1,20 @@
1
1
  import React, { MutableRefObject } from "react";
2
2
  import { RapierContext } from "./Physics";
3
- import { Mesh, Object3D, Quaternion, Vector3 } from "three";
3
+ import { Mesh, Object3D } from "three";
4
4
  import type Rapier from "@dimforge/rapier3d-compat";
5
5
  export declare const useRapier: () => RapierContext;
6
6
  import { BallArgs, CapsuleArgs, ConeArgs, ConvexHullArgs, CuboidArgs, CylinderArgs, HeightfieldArgs, PolylineArgs, RoundConvexHullArgs, RoundCuboidArgs, RoundCylinderArgs, TrimeshArgs, UseBodyOptions, UseRigidBodyOptions, UseImpulseJoint, SphericalJointParams, FixedJointParams, PrismaticJointParams, RevoluteJointParams, UseColliderOptions, RapierRigidBody, ConvexMeshArgs, RoundConvexMeshArgs, RigidBodyApi } from "./types";
7
7
  import { RoundCone } from "@dimforge/rapier3d-compat";
8
- export declare const useRigidBody: <O extends Object3D<import("three").Event>>(options?: UseRigidBodyOptions) => [React.MutableRefObject<O>, {
9
- raw: () => Rapier.RigidBody | undefined;
10
- readonly handle: number;
11
- applyImpulse({ x, y, z }: Vector3): void;
12
- applyTorqueImpulse({ x, y, z }: Vector3): void;
13
- translation(): Vector3;
14
- rotation(): Quaternion;
15
- setNextKinematicRotation({ x, y, z }: Vector3): void;
16
- setNextKinematicTranslation({ x, y, z }: Vector3): void;
17
- }];
8
+ export declare const useRigidBody: <O extends Object3D<import("three").Event>>(options?: UseRigidBodyOptions) => [React.MutableRefObject<O>, import("./api").RigidBodyApi];
18
9
  export declare const useCollider: <A>(body: RigidBodyApi, options?: UseColliderOptions<A>) => (React.MutableRefObject<Object3D<import("three").Event> | undefined> | {
19
10
  raw: () => Rapier.Collider | undefined;
20
11
  readonly handle: number;
21
12
  })[];
22
- export declare const useRigidBodyWithCollider: <A, O extends Object3D<import("three").Event> = Object3D<import("three").Event>>(rigidBodyOptions?: UseRigidBodyOptions | undefined, colliderOptions?: UseColliderOptions<A> | undefined) => [ref: React.MutableRefObject<O>, rigidBody: {
23
- raw: () => Rapier.RigidBody | undefined;
24
- readonly handle: number;
25
- applyImpulse({ x, y, z }: Vector3): void;
26
- applyTorqueImpulse({ x, y, z }: Vector3): void;
27
- translation(): Vector3;
28
- rotation(): Quaternion;
29
- setNextKinematicRotation({ x, y, z }: Vector3): void;
30
- setNextKinematicTranslation({ x, y, z }: Vector3): void;
31
- }];
32
- export declare const useCuboid: <T extends Object3D<import("three").Event>>(rigidBodyOptions?: UseBodyOptions, colliderOptions?: UseColliderOptions<CuboidArgs>) => [ref: React.MutableRefObject<T>, rigidBody: {
33
- raw: () => Rapier.RigidBody | undefined;
34
- readonly handle: number;
35
- applyImpulse({ x, y, z }: Vector3): void;
36
- applyTorqueImpulse({ x, y, z }: Vector3): void;
37
- translation(): Vector3;
38
- rotation(): Quaternion;
39
- setNextKinematicRotation({ x, y, z }: Vector3): void;
40
- setNextKinematicTranslation({ x, y, z }: Vector3): void;
41
- }];
42
- export declare const useBall: <T extends Object3D<import("three").Event>>(rigidBodyOptions?: UseBodyOptions, colliderOptions?: UseColliderOptions<BallArgs>) => [ref: React.MutableRefObject<T>, rigidBody: {
43
- raw: () => Rapier.RigidBody | undefined;
44
- readonly handle: number;
45
- applyImpulse({ x, y, z }: Vector3): void;
46
- applyTorqueImpulse({ x, y, z }: Vector3): void;
47
- translation(): Vector3;
48
- rotation(): Quaternion;
49
- setNextKinematicRotation({ x, y, z }: Vector3): void;
50
- setNextKinematicTranslation({ x, y, z }: Vector3): void;
51
- }];
52
- export declare const useCapsule: <T extends Object3D<import("three").Event>>(rigidBodyOptions?: UseBodyOptions, colliderOptions?: UseColliderOptions<CapsuleArgs>) => [ref: React.MutableRefObject<T>, rigidBody: {
53
- raw: () => Rapier.RigidBody | undefined;
54
- readonly handle: number;
55
- applyImpulse({ x, y, z }: Vector3): void;
56
- applyTorqueImpulse({ x, y, z }: Vector3): void;
57
- translation(): Vector3;
58
- rotation(): Quaternion;
59
- setNextKinematicRotation({ x, y, z }: Vector3): void;
60
- setNextKinematicTranslation({ x, y, z }: Vector3): void;
61
- }];
62
- export declare const useHeightfield: <T extends Object3D<import("three").Event>>(rigidBodyOptions?: UseBodyOptions, colliderOptions?: UseColliderOptions<HeightfieldArgs>) => [ref: React.MutableRefObject<T>, rigidBody: {
63
- raw: () => Rapier.RigidBody | undefined;
64
- readonly handle: number;
65
- applyImpulse({ x, y, z }: Vector3): void;
66
- applyTorqueImpulse({ x, y, z }: Vector3): void;
67
- translation(): Vector3;
68
- rotation(): Quaternion;
69
- setNextKinematicRotation({ x, y, z }: Vector3): void;
70
- setNextKinematicTranslation({ x, y, z }: Vector3): void;
71
- }];
13
+ export declare const useRigidBodyWithCollider: <A, O extends Object3D<import("three").Event> = Object3D<import("three").Event>>(rigidBodyOptions?: UseRigidBodyOptions | undefined, colliderOptions?: UseColliderOptions<A> | undefined) => [ref: React.MutableRefObject<O>, rigidBody: import("./api").RigidBodyApi];
14
+ export declare const useCuboid: <T extends Object3D<import("three").Event>>(rigidBodyOptions?: UseBodyOptions, colliderOptions?: UseColliderOptions<CuboidArgs>) => [ref: React.MutableRefObject<T>, rigidBody: import("./api").RigidBodyApi];
15
+ export declare const useBall: <T extends Object3D<import("three").Event>>(rigidBodyOptions?: UseBodyOptions, colliderOptions?: UseColliderOptions<BallArgs>) => [ref: React.MutableRefObject<T>, rigidBody: import("./api").RigidBodyApi];
16
+ export declare const useCapsule: <T extends Object3D<import("three").Event>>(rigidBodyOptions?: UseBodyOptions, colliderOptions?: UseColliderOptions<CapsuleArgs>) => [ref: React.MutableRefObject<T>, rigidBody: import("./api").RigidBodyApi];
17
+ export declare const useHeightfield: <T extends Object3D<import("three").Event>>(rigidBodyOptions?: UseBodyOptions, colliderOptions?: UseColliderOptions<HeightfieldArgs>) => [ref: React.MutableRefObject<T>, rigidBody: import("./api").RigidBodyApi];
72
18
  /**
73
19
  * Create a trimesh collider and rigid body.
74
20
  * Note that Trimeshes don't have mass unless provided.
@@ -76,151 +22,25 @@ export declare const useHeightfield: <T extends Object3D<import("three").Event>>
76
22
  * for available properties.
77
23
  */
78
24
  export declare const useTrimesh: {
79
- <T extends Object3D<import("three").Event>>(rigidBodyOptions?: UseBodyOptions, colliderOptions?: UseColliderOptions<TrimeshArgs>): [ref: React.MutableRefObject<T>, rigidBody: {
80
- raw: () => Rapier.RigidBody | undefined;
81
- readonly handle: number;
82
- applyImpulse({ x, y, z }: Vector3): void;
83
- applyTorqueImpulse({ x, y, z }: Vector3): void;
84
- translation(): Vector3;
85
- rotation(): Quaternion;
86
- setNextKinematicRotation({ x, y, z }: Vector3): void;
87
- setNextKinematicTranslation({ x, y, z }: Vector3): void;
88
- }];
89
- fromMesh<T_1 extends Object3D<import("three").Event>>(mesh: Mesh, rigidBodyOptions?: UseBodyOptions, colliderOptions?: UseColliderOptions<TrimeshArgs>): [ref: React.MutableRefObject<T_1>, rigidBody: {
90
- raw: () => Rapier.RigidBody | undefined;
91
- readonly handle: number;
92
- applyImpulse({ x, y, z }: Vector3): void;
93
- applyTorqueImpulse({ x, y, z }: Vector3): void;
94
- translation(): Vector3;
95
- rotation(): Quaternion;
96
- setNextKinematicRotation({ x, y, z }: Vector3): void;
97
- setNextKinematicTranslation({ x, y, z }: Vector3): void;
98
- }];
25
+ <T extends Object3D<import("three").Event>>(rigidBodyOptions?: UseBodyOptions, colliderOptions?: UseColliderOptions<TrimeshArgs>): [ref: React.MutableRefObject<T>, rigidBody: import("./api").RigidBodyApi];
26
+ fromMesh<T_1 extends Object3D<import("three").Event>>(mesh: Mesh, rigidBodyOptions?: UseBodyOptions, colliderOptions?: UseColliderOptions<TrimeshArgs>): [ref: React.MutableRefObject<T_1>, rigidBody: import("./api").RigidBodyApi];
99
27
  };
100
- export declare const usePolyline: <T extends Object3D<import("three").Event>>(rigidBodyOptions?: UseBodyOptions, colliderOptions?: UseColliderOptions<PolylineArgs>) => [ref: React.MutableRefObject<T>, rigidBody: {
101
- raw: () => Rapier.RigidBody | undefined;
102
- readonly handle: number;
103
- applyImpulse({ x, y, z }: Vector3): void;
104
- applyTorqueImpulse({ x, y, z }: Vector3): void;
105
- translation(): Vector3;
106
- rotation(): Quaternion;
107
- setNextKinematicRotation({ x, y, z }: Vector3): void;
108
- setNextKinematicTranslation({ x, y, z }: Vector3): void;
109
- }];
110
- export declare const useRoundCuboid: <T extends Object3D<import("three").Event>>(rigidBodyOptions?: UseBodyOptions, colliderOptions?: UseColliderOptions<RoundCuboidArgs>) => [ref: React.MutableRefObject<T>, rigidBody: {
111
- raw: () => Rapier.RigidBody | undefined;
112
- readonly handle: number;
113
- applyImpulse({ x, y, z }: Vector3): void;
114
- applyTorqueImpulse({ x, y, z }: Vector3): void;
115
- translation(): Vector3;
116
- rotation(): Quaternion;
117
- setNextKinematicRotation({ x, y, z }: Vector3): void;
118
- setNextKinematicTranslation({ x, y, z }: Vector3): void;
119
- }];
120
- export declare const useCylinder: <T extends Object3D<import("three").Event>>(rigidBodyOptions?: UseBodyOptions, colliderOptions?: UseColliderOptions<CylinderArgs>) => [ref: React.MutableRefObject<T>, rigidBody: {
121
- raw: () => Rapier.RigidBody | undefined;
122
- readonly handle: number;
123
- applyImpulse({ x, y, z }: Vector3): void;
124
- applyTorqueImpulse({ x, y, z }: Vector3): void;
125
- translation(): Vector3;
126
- rotation(): Quaternion;
127
- setNextKinematicRotation({ x, y, z }: Vector3): void;
128
- setNextKinematicTranslation({ x, y, z }: Vector3): void;
129
- }];
130
- export declare const useRoundCylinder: <T extends Object3D<import("three").Event>>(rigidBodyOptions?: UseBodyOptions, colliderOptions?: UseColliderOptions<RoundCylinderArgs>) => [ref: React.MutableRefObject<T>, rigidBody: {
131
- raw: () => Rapier.RigidBody | undefined;
132
- readonly handle: number;
133
- applyImpulse({ x, y, z }: Vector3): void;
134
- applyTorqueImpulse({ x, y, z }: Vector3): void;
135
- translation(): Vector3;
136
- rotation(): Quaternion;
137
- setNextKinematicRotation({ x, y, z }: Vector3): void;
138
- setNextKinematicTranslation({ x, y, z }: Vector3): void;
139
- }];
140
- export declare const useCone: <T extends Object3D<import("three").Event>>(rigidBodyOptions?: UseBodyOptions, colliderOptions?: UseColliderOptions<ConeArgs>) => [ref: React.MutableRefObject<T>, rigidBody: {
141
- raw: () => Rapier.RigidBody | undefined;
142
- readonly handle: number;
143
- applyImpulse({ x, y, z }: Vector3): void;
144
- applyTorqueImpulse({ x, y, z }: Vector3): void;
145
- translation(): Vector3;
146
- rotation(): Quaternion;
147
- setNextKinematicRotation({ x, y, z }: Vector3): void;
148
- setNextKinematicTranslation({ x, y, z }: Vector3): void;
149
- }];
150
- export declare const useRoundCone: <T extends Object3D<import("three").Event>>(rigidBodyOptions?: UseBodyOptions, colliderOptions?: UseColliderOptions<RoundCone>) => [ref: React.MutableRefObject<T>, rigidBody: {
151
- raw: () => Rapier.RigidBody | undefined;
152
- readonly handle: number;
153
- applyImpulse({ x, y, z }: Vector3): void;
154
- applyTorqueImpulse({ x, y, z }: Vector3): void;
155
- translation(): Vector3;
156
- rotation(): Quaternion;
157
- setNextKinematicRotation({ x, y, z }: Vector3): void;
158
- setNextKinematicTranslation({ x, y, z }: Vector3): void;
159
- }];
28
+ export declare const usePolyline: <T extends Object3D<import("three").Event>>(rigidBodyOptions?: UseBodyOptions, colliderOptions?: UseColliderOptions<PolylineArgs>) => [ref: React.MutableRefObject<T>, rigidBody: import("./api").RigidBodyApi];
29
+ export declare const useRoundCuboid: <T extends Object3D<import("three").Event>>(rigidBodyOptions?: UseBodyOptions, colliderOptions?: UseColliderOptions<RoundCuboidArgs>) => [ref: React.MutableRefObject<T>, rigidBody: import("./api").RigidBodyApi];
30
+ export declare const useCylinder: <T extends Object3D<import("three").Event>>(rigidBodyOptions?: UseBodyOptions, colliderOptions?: UseColliderOptions<CylinderArgs>) => [ref: React.MutableRefObject<T>, rigidBody: import("./api").RigidBodyApi];
31
+ export declare const useRoundCylinder: <T extends Object3D<import("three").Event>>(rigidBodyOptions?: UseBodyOptions, colliderOptions?: UseColliderOptions<RoundCylinderArgs>) => [ref: React.MutableRefObject<T>, rigidBody: import("./api").RigidBodyApi];
32
+ export declare const useCone: <T extends Object3D<import("three").Event>>(rigidBodyOptions?: UseBodyOptions, colliderOptions?: UseColliderOptions<ConeArgs>) => [ref: React.MutableRefObject<T>, rigidBody: import("./api").RigidBodyApi];
33
+ export declare const useRoundCone: <T extends Object3D<import("three").Event>>(rigidBodyOptions?: UseBodyOptions, colliderOptions?: UseColliderOptions<RoundCone>) => [ref: React.MutableRefObject<T>, rigidBody: import("./api").RigidBodyApi];
160
34
  export declare const useConvexHull: {
161
- <T extends Object3D<import("three").Event>>(rigidBodyOptions?: UseBodyOptions, colliderOptions?: UseColliderOptions<ConvexHullArgs>): [ref: React.MutableRefObject<T>, rigidBody: {
162
- raw: () => Rapier.RigidBody | undefined;
163
- readonly handle: number;
164
- applyImpulse({ x, y, z }: Vector3): void;
165
- applyTorqueImpulse({ x, y, z }: Vector3): void;
166
- translation(): Vector3;
167
- rotation(): Quaternion;
168
- setNextKinematicRotation({ x, y, z }: Vector3): void;
169
- setNextKinematicTranslation({ x, y, z }: Vector3): void;
170
- }];
171
- fromMesh<T_1 extends Object3D<import("three").Event>>(mesh: Mesh, rigidBodyOptions?: UseBodyOptions, colliderOptions?: Omit<UseColliderOptions<ConvexHullArgs>, "colliderArgs">): [ref: React.MutableRefObject<T_1>, rigidBody: {
172
- raw: () => Rapier.RigidBody | undefined;
173
- readonly handle: number;
174
- applyImpulse({ x, y, z }: Vector3): void;
175
- applyTorqueImpulse({ x, y, z }: Vector3): void;
176
- translation(): Vector3;
177
- rotation(): Quaternion;
178
- setNextKinematicRotation({ x, y, z }: Vector3): void;
179
- setNextKinematicTranslation({ x, y, z }: Vector3): void;
180
- }];
35
+ <T extends Object3D<import("three").Event>>(rigidBodyOptions?: UseBodyOptions, colliderOptions?: UseColliderOptions<ConvexHullArgs>): [ref: React.MutableRefObject<T>, rigidBody: import("./api").RigidBodyApi];
36
+ fromMesh<T_1 extends Object3D<import("three").Event>>(mesh: Mesh, rigidBodyOptions?: UseBodyOptions, colliderOptions?: Omit<UseColliderOptions<ConvexHullArgs>, "colliderArgs">): [ref: React.MutableRefObject<T_1>, rigidBody: import("./api").RigidBodyApi];
181
37
  };
182
- export declare const useRoundConvexHull: <T extends Object3D<import("three").Event>>(rigidBodyOptions?: UseBodyOptions, colliderOptions?: UseColliderOptions<RoundConvexHullArgs>) => [ref: React.MutableRefObject<T>, rigidBody: {
183
- raw: () => Rapier.RigidBody | undefined;
184
- readonly handle: number;
185
- applyImpulse({ x, y, z }: Vector3): void;
186
- applyTorqueImpulse({ x, y, z }: Vector3): void;
187
- translation(): Vector3;
188
- rotation(): Quaternion;
189
- setNextKinematicRotation({ x, y, z }: Vector3): void;
190
- setNextKinematicTranslation({ x, y, z }: Vector3): void;
191
- }];
38
+ export declare const useRoundConvexHull: <T extends Object3D<import("three").Event>>(rigidBodyOptions?: UseBodyOptions, colliderOptions?: UseColliderOptions<RoundConvexHullArgs>) => [ref: React.MutableRefObject<T>, rigidBody: import("./api").RigidBodyApi];
192
39
  export declare const useConvexMesh: {
193
- <T extends Object3D<import("three").Event>>(rigidBodyOptions?: UseBodyOptions, colliderOptions?: UseColliderOptions<ConvexMeshArgs>): [ref: React.MutableRefObject<Object3D<import("three").Event>>, rigidBody: {
194
- raw: () => Rapier.RigidBody | undefined;
195
- readonly handle: number;
196
- applyImpulse({ x, y, z }: Vector3): void;
197
- applyTorqueImpulse({ x, y, z }: Vector3): void;
198
- translation(): Vector3;
199
- rotation(): Quaternion;
200
- setNextKinematicRotation({ x, y, z }: Vector3): void;
201
- setNextKinematicTranslation({ x, y, z }: Vector3): void;
202
- }];
203
- fromMesh<T_1 extends Object3D<import("three").Event>>(mesh: Mesh, rigidBodyOptions?: UseBodyOptions, colliderOptions?: Omit<UseColliderOptions<ConvexMeshArgs>, "colliderArgs">): [ref: React.MutableRefObject<Object3D<import("three").Event>>, rigidBody: {
204
- raw: () => Rapier.RigidBody | undefined;
205
- readonly handle: number;
206
- applyImpulse({ x, y, z }: Vector3): void;
207
- applyTorqueImpulse({ x, y, z }: Vector3): void;
208
- translation(): Vector3;
209
- rotation(): Quaternion;
210
- setNextKinematicRotation({ x, y, z }: Vector3): void;
211
- setNextKinematicTranslation({ x, y, z }: Vector3): void;
212
- }];
40
+ <T extends Object3D<import("three").Event>>(rigidBodyOptions?: UseBodyOptions, colliderOptions?: UseColliderOptions<ConvexMeshArgs>): [ref: React.MutableRefObject<Object3D<import("three").Event>>, rigidBody: import("./api").RigidBodyApi];
41
+ fromMesh<T_1 extends Object3D<import("three").Event>>(mesh: Mesh, rigidBodyOptions?: UseBodyOptions, colliderOptions?: Omit<UseColliderOptions<ConvexMeshArgs>, "colliderArgs">): [ref: React.MutableRefObject<Object3D<import("three").Event>>, rigidBody: import("./api").RigidBodyApi];
213
42
  };
214
- export declare const useRoundConvexMesh: <T extends Object3D<import("three").Event>>(rigidBodyOptions?: UseBodyOptions, colliderOptions?: UseColliderOptions<RoundConvexMeshArgs>) => [ref: React.MutableRefObject<Object3D<import("three").Event>>, rigidBody: {
215
- raw: () => Rapier.RigidBody | undefined;
216
- readonly handle: number;
217
- applyImpulse({ x, y, z }: Vector3): void;
218
- applyTorqueImpulse({ x, y, z }: Vector3): void;
219
- translation(): Vector3;
220
- rotation(): Quaternion;
221
- setNextKinematicRotation({ x, y, z }: Vector3): void;
222
- setNextKinematicTranslation({ x, y, z }: Vector3): void;
223
- }];
43
+ export declare const useRoundConvexMesh: <T extends Object3D<import("three").Event>>(rigidBodyOptions?: UseBodyOptions, colliderOptions?: UseColliderOptions<RoundConvexMeshArgs>) => [ref: React.MutableRefObject<Object3D<import("three").Event>>, rigidBody: import("./api").RigidBodyApi];
224
44
  export declare const useImpulseJoint: <T extends Rapier.ImpulseJoint>(body1: MutableRefObject<RapierRigidBody | undefined | null> | RigidBodyApi, body2: MutableRefObject<RapierRigidBody | undefined | null> | RigidBodyApi, params: Rapier.JointData) => {
225
45
  raw: () => Rapier.ImpulseJoint | undefined;
226
46
  readonly handle: number;
@@ -209,7 +209,47 @@ const scaleVertices = (vertices, scale) => {
209
209
  return scaledVerts;
210
210
  };
211
211
 
212
- // TODO: Flesh this out
212
+ function _defineProperty(obj, key, value) {
213
+ if (key in obj) {
214
+ Object.defineProperty(obj, key, {
215
+ value: value,
216
+ enumerable: true,
217
+ configurable: true,
218
+ writable: true
219
+ });
220
+ } else {
221
+ obj[key] = value;
222
+ }
223
+
224
+ return obj;
225
+ }
226
+
227
+ function ownKeys(object, enumerableOnly) {
228
+ var keys = Object.keys(object);
229
+
230
+ if (Object.getOwnPropertySymbols) {
231
+ var symbols = Object.getOwnPropertySymbols(object);
232
+ enumerableOnly && (symbols = symbols.filter(function (sym) {
233
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
234
+ })), keys.push.apply(keys, symbols);
235
+ }
236
+
237
+ return keys;
238
+ }
239
+
240
+ function _objectSpread2(target) {
241
+ for (var i = 1; i < arguments.length; i++) {
242
+ var source = null != arguments[i] ? arguments[i] : {};
243
+ i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
244
+ _defineProperty(target, key, source[key]);
245
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
246
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
247
+ });
248
+ }
249
+
250
+ return target;
251
+ }
252
+
213
253
  const createRigidBodyApi = ref => {
214
254
  return {
215
255
  raw: () => ref.current(),
@@ -218,30 +258,21 @@ const createRigidBodyApi = ref => {
218
258
  return ref.current().handle;
219
259
  },
220
260
 
221
- applyImpulse({
222
- x,
223
- y,
224
- z
225
- }) {
226
- ref.current().applyImpulse({
227
- x,
228
- y,
229
- z
230
- }, true);
261
+ mass: () => ref.current().mass(),
262
+
263
+ applyImpulse(impulseVector) {
264
+ ref.current().applyImpulse(impulseVector, true);
231
265
  },
232
266
 
233
- applyTorqueImpulse({
234
- x,
235
- y,
236
- z
237
- }) {
238
- ref.current().applyTorqueImpulse({
239
- x,
240
- y,
241
- z
242
- }, true);
267
+ applyTorqueImpulse(torqueVector) {
268
+ ref.current().applyTorqueImpulse(torqueVector, true);
243
269
  },
244
270
 
271
+ applyImpulseAtPoint: (impulseVector, impulsePoint) => ref.current().applyImpulseAtPoint(impulseVector, impulsePoint, true),
272
+ addForce: force => ref.current().addForce(force, true),
273
+ addForceAtPoint: (force, point) => ref.current().addForceAtPoint(force, point, true),
274
+ addTorque: torque => ref.current().addTorque(torque, true),
275
+
245
276
  translation() {
246
277
  const {
247
278
  x,
@@ -251,6 +282,8 @@ const createRigidBodyApi = ref => {
251
282
  return new three.Vector3(x, y, z);
252
283
  },
253
284
 
285
+ setTranslation: translation => ref.current().setTranslation(translation, true),
286
+
254
287
  rotation() {
255
288
  const {
256
289
  x,
@@ -261,31 +294,37 @@ const createRigidBodyApi = ref => {
261
294
  return new three.Quaternion(x, y, z, w);
262
295
  },
263
296
 
264
- setNextKinematicRotation({
265
- x,
266
- y,
267
- z
268
- }) {
269
- ref.current().setNextKinematicRotation({
297
+ setRotation: rotation => ref.current().setRotation(_objectSpread2(_objectSpread2({}, rotation), {}, {
298
+ w: 1
299
+ }), true),
300
+
301
+ linvel() {
302
+ const {
270
303
  x,
271
304
  y,
272
- z,
273
- w: 1
274
- });
305
+ z
306
+ } = ref.current().linvel();
307
+ return new three.Vector3(x, y, z);
275
308
  },
276
309
 
277
- setNextKinematicTranslation({
278
- x,
279
- y,
280
- z
281
- }) {
282
- ref.current().setNextKinematicTranslation({
310
+ setLinvel: velocity => ref.current().setLinvel(velocity, true),
311
+
312
+ angvel() {
313
+ const {
283
314
  x,
284
315
  y,
285
316
  z
286
- });
287
- }
317
+ } = ref.current().angvel();
318
+ return new three.Vector3(x, y, z);
319
+ },
288
320
 
321
+ setAngvel: velocity => ref.current().setAngvel(velocity, true),
322
+ setNextKinematicRotation: rotation => ref.current().setNextKinematicRotation(_objectSpread2(_objectSpread2({}, rotation), {}, {
323
+ w: 1
324
+ })),
325
+ setNextKinematicTranslation: translation => ref.current().setNextKinematicTranslation(translation),
326
+ resetForces: () => ref.current().resetForces(true),
327
+ resetTorques: () => ref.current().resetTorques(true)
289
328
  };
290
329
  }; // TODO: Flesh this out
291
330
 
@@ -485,47 +524,6 @@ const Physics = ({
485
524
  }, children);
486
525
  };
487
526
 
488
- function _defineProperty(obj, key, value) {
489
- if (key in obj) {
490
- Object.defineProperty(obj, key, {
491
- value: value,
492
- enumerable: true,
493
- configurable: true,
494
- writable: true
495
- });
496
- } else {
497
- obj[key] = value;
498
- }
499
-
500
- return obj;
501
- }
502
-
503
- function ownKeys(object, enumerableOnly) {
504
- var keys = Object.keys(object);
505
-
506
- if (Object.getOwnPropertySymbols) {
507
- var symbols = Object.getOwnPropertySymbols(object);
508
- enumerableOnly && (symbols = symbols.filter(function (sym) {
509
- return Object.getOwnPropertyDescriptor(object, sym).enumerable;
510
- })), keys.push.apply(keys, symbols);
511
- }
512
-
513
- return keys;
514
- }
515
-
516
- function _objectSpread2(target) {
517
- for (var i = 1; i < arguments.length; i++) {
518
- var source = null != arguments[i] ? arguments[i] : {};
519
- i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
520
- _defineProperty(target, key, source[key]);
521
- }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
522
- Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
523
- });
524
- }
525
-
526
- return target;
527
- }
528
-
529
527
  const useRapier = () => {
530
528
  return React.useContext(RapierContext);
531
529
  };
@@ -591,7 +589,6 @@ const useRigidBody = (options = {}) => {
591
589
  y: worldPosition.y + y * scale.y,
592
590
  z: worldPosition.z + z * scale.z
593
591
  }, false);
594
- console.log(rigidBody.isKinematic());
595
592
  const eulerAngles = new three.Euler(rx, ry, rz, 'XYZ');
596
593
  const rotation = new three.Quaternion().setFromEuler(eulerAngles).multiply(worldRotation);
597
594
  rigidBody.setRotation({
@@ -608,8 +605,7 @@ const useRigidBody = (options = {}) => {
608
605
  rigidBody.wakeUp();
609
606
  rigidBodyMeshes.set(rigidBody.handle, ref.current);
610
607
  return () => {
611
- const actualBody = world.getRigidBody(rigidBody.handle);
612
- world.removeRigidBody(actualBody);
608
+ world.removeRigidBody(rigidBody);
613
609
  autoColliders.forEach(collider => world.removeCollider(collider));
614
610
  rigidBodyRef.current = undefined;
615
611
  rigidBodyMeshes.delete(rigidBody.handle);
@@ -971,7 +967,7 @@ const AnyCollider = _ref2 => {
971
967
  const ref = React.useRef(null);
972
968
  React.useEffect(() => {
973
969
  const scale = ref.current.getWorldScale(new three.Vector3());
974
- const collider = createColliderFromOptions(props, world, world.getRigidBody(rigidBody.handle), scale, hasCollisionEvents);
970
+ const collider = createColliderFromOptions(props, world, rigidBody.raw(), scale, hasCollisionEvents);
975
971
  return () => {
976
972
  world.removeCollider(collider);
977
973
  };
@@ -209,7 +209,47 @@ const scaleVertices = (vertices, scale) => {
209
209
  return scaledVerts;
210
210
  };
211
211
 
212
- // TODO: Flesh this out
212
+ function _defineProperty(obj, key, value) {
213
+ if (key in obj) {
214
+ Object.defineProperty(obj, key, {
215
+ value: value,
216
+ enumerable: true,
217
+ configurable: true,
218
+ writable: true
219
+ });
220
+ } else {
221
+ obj[key] = value;
222
+ }
223
+
224
+ return obj;
225
+ }
226
+
227
+ function ownKeys(object, enumerableOnly) {
228
+ var keys = Object.keys(object);
229
+
230
+ if (Object.getOwnPropertySymbols) {
231
+ var symbols = Object.getOwnPropertySymbols(object);
232
+ enumerableOnly && (symbols = symbols.filter(function (sym) {
233
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
234
+ })), keys.push.apply(keys, symbols);
235
+ }
236
+
237
+ return keys;
238
+ }
239
+
240
+ function _objectSpread2(target) {
241
+ for (var i = 1; i < arguments.length; i++) {
242
+ var source = null != arguments[i] ? arguments[i] : {};
243
+ i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
244
+ _defineProperty(target, key, source[key]);
245
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
246
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
247
+ });
248
+ }
249
+
250
+ return target;
251
+ }
252
+
213
253
  const createRigidBodyApi = ref => {
214
254
  return {
215
255
  raw: () => ref.current(),
@@ -218,30 +258,21 @@ const createRigidBodyApi = ref => {
218
258
  return ref.current().handle;
219
259
  },
220
260
 
221
- applyImpulse({
222
- x,
223
- y,
224
- z
225
- }) {
226
- ref.current().applyImpulse({
227
- x,
228
- y,
229
- z
230
- }, true);
261
+ mass: () => ref.current().mass(),
262
+
263
+ applyImpulse(impulseVector) {
264
+ ref.current().applyImpulse(impulseVector, true);
231
265
  },
232
266
 
233
- applyTorqueImpulse({
234
- x,
235
- y,
236
- z
237
- }) {
238
- ref.current().applyTorqueImpulse({
239
- x,
240
- y,
241
- z
242
- }, true);
267
+ applyTorqueImpulse(torqueVector) {
268
+ ref.current().applyTorqueImpulse(torqueVector, true);
243
269
  },
244
270
 
271
+ applyImpulseAtPoint: (impulseVector, impulsePoint) => ref.current().applyImpulseAtPoint(impulseVector, impulsePoint, true),
272
+ addForce: force => ref.current().addForce(force, true),
273
+ addForceAtPoint: (force, point) => ref.current().addForceAtPoint(force, point, true),
274
+ addTorque: torque => ref.current().addTorque(torque, true),
275
+
245
276
  translation() {
246
277
  const {
247
278
  x,
@@ -251,6 +282,8 @@ const createRigidBodyApi = ref => {
251
282
  return new three.Vector3(x, y, z);
252
283
  },
253
284
 
285
+ setTranslation: translation => ref.current().setTranslation(translation, true),
286
+
254
287
  rotation() {
255
288
  const {
256
289
  x,
@@ -261,31 +294,37 @@ const createRigidBodyApi = ref => {
261
294
  return new three.Quaternion(x, y, z, w);
262
295
  },
263
296
 
264
- setNextKinematicRotation({
265
- x,
266
- y,
267
- z
268
- }) {
269
- ref.current().setNextKinematicRotation({
297
+ setRotation: rotation => ref.current().setRotation(_objectSpread2(_objectSpread2({}, rotation), {}, {
298
+ w: 1
299
+ }), true),
300
+
301
+ linvel() {
302
+ const {
270
303
  x,
271
304
  y,
272
- z,
273
- w: 1
274
- });
305
+ z
306
+ } = ref.current().linvel();
307
+ return new three.Vector3(x, y, z);
275
308
  },
276
309
 
277
- setNextKinematicTranslation({
278
- x,
279
- y,
280
- z
281
- }) {
282
- ref.current().setNextKinematicTranslation({
310
+ setLinvel: velocity => ref.current().setLinvel(velocity, true),
311
+
312
+ angvel() {
313
+ const {
283
314
  x,
284
315
  y,
285
316
  z
286
- });
287
- }
317
+ } = ref.current().angvel();
318
+ return new three.Vector3(x, y, z);
319
+ },
288
320
 
321
+ setAngvel: velocity => ref.current().setAngvel(velocity, true),
322
+ setNextKinematicRotation: rotation => ref.current().setNextKinematicRotation(_objectSpread2(_objectSpread2({}, rotation), {}, {
323
+ w: 1
324
+ })),
325
+ setNextKinematicTranslation: translation => ref.current().setNextKinematicTranslation(translation),
326
+ resetForces: () => ref.current().resetForces(true),
327
+ resetTorques: () => ref.current().resetTorques(true)
289
328
  };
290
329
  }; // TODO: Flesh this out
291
330
 
@@ -485,47 +524,6 @@ const Physics = ({
485
524
  }, children);
486
525
  };
487
526
 
488
- function _defineProperty(obj, key, value) {
489
- if (key in obj) {
490
- Object.defineProperty(obj, key, {
491
- value: value,
492
- enumerable: true,
493
- configurable: true,
494
- writable: true
495
- });
496
- } else {
497
- obj[key] = value;
498
- }
499
-
500
- return obj;
501
- }
502
-
503
- function ownKeys(object, enumerableOnly) {
504
- var keys = Object.keys(object);
505
-
506
- if (Object.getOwnPropertySymbols) {
507
- var symbols = Object.getOwnPropertySymbols(object);
508
- enumerableOnly && (symbols = symbols.filter(function (sym) {
509
- return Object.getOwnPropertyDescriptor(object, sym).enumerable;
510
- })), keys.push.apply(keys, symbols);
511
- }
512
-
513
- return keys;
514
- }
515
-
516
- function _objectSpread2(target) {
517
- for (var i = 1; i < arguments.length; i++) {
518
- var source = null != arguments[i] ? arguments[i] : {};
519
- i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
520
- _defineProperty(target, key, source[key]);
521
- }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
522
- Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
523
- });
524
- }
525
-
526
- return target;
527
- }
528
-
529
527
  const useRapier = () => {
530
528
  return React.useContext(RapierContext);
531
529
  };
@@ -591,7 +589,6 @@ const useRigidBody = (options = {}) => {
591
589
  y: worldPosition.y + y * scale.y,
592
590
  z: worldPosition.z + z * scale.z
593
591
  }, false);
594
- console.log(rigidBody.isKinematic());
595
592
  const eulerAngles = new three.Euler(rx, ry, rz, 'XYZ');
596
593
  const rotation = new three.Quaternion().setFromEuler(eulerAngles).multiply(worldRotation);
597
594
  rigidBody.setRotation({
@@ -608,8 +605,7 @@ const useRigidBody = (options = {}) => {
608
605
  rigidBody.wakeUp();
609
606
  rigidBodyMeshes.set(rigidBody.handle, ref.current);
610
607
  return () => {
611
- const actualBody = world.getRigidBody(rigidBody.handle);
612
- world.removeRigidBody(actualBody);
608
+ world.removeRigidBody(rigidBody);
613
609
  autoColliders.forEach(collider => world.removeCollider(collider));
614
610
  rigidBodyRef.current = undefined;
615
611
  rigidBodyMeshes.delete(rigidBody.handle);
@@ -971,7 +967,7 @@ const AnyCollider = _ref2 => {
971
967
  const ref = React.useRef(null);
972
968
  React.useEffect(() => {
973
969
  const scale = ref.current.getWorldScale(new three.Vector3());
974
- const collider = createColliderFromOptions(props, world, world.getRigidBody(rigidBody.handle), scale, hasCollisionEvents);
970
+ const collider = createColliderFromOptions(props, world, rigidBody.raw(), scale, hasCollisionEvents);
975
971
  return () => {
976
972
  world.removeCollider(collider);
977
973
  };
@@ -184,7 +184,47 @@ const scaleVertices = (vertices, scale) => {
184
184
  return scaledVerts;
185
185
  };
186
186
 
187
- // TODO: Flesh this out
187
+ function _defineProperty(obj, key, value) {
188
+ if (key in obj) {
189
+ Object.defineProperty(obj, key, {
190
+ value: value,
191
+ enumerable: true,
192
+ configurable: true,
193
+ writable: true
194
+ });
195
+ } else {
196
+ obj[key] = value;
197
+ }
198
+
199
+ return obj;
200
+ }
201
+
202
+ function ownKeys(object, enumerableOnly) {
203
+ var keys = Object.keys(object);
204
+
205
+ if (Object.getOwnPropertySymbols) {
206
+ var symbols = Object.getOwnPropertySymbols(object);
207
+ enumerableOnly && (symbols = symbols.filter(function (sym) {
208
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
209
+ })), keys.push.apply(keys, symbols);
210
+ }
211
+
212
+ return keys;
213
+ }
214
+
215
+ function _objectSpread2(target) {
216
+ for (var i = 1; i < arguments.length; i++) {
217
+ var source = null != arguments[i] ? arguments[i] : {};
218
+ i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
219
+ _defineProperty(target, key, source[key]);
220
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
221
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
222
+ });
223
+ }
224
+
225
+ return target;
226
+ }
227
+
188
228
  const createRigidBodyApi = ref => {
189
229
  return {
190
230
  raw: () => ref.current(),
@@ -193,30 +233,21 @@ const createRigidBodyApi = ref => {
193
233
  return ref.current().handle;
194
234
  },
195
235
 
196
- applyImpulse({
197
- x,
198
- y,
199
- z
200
- }) {
201
- ref.current().applyImpulse({
202
- x,
203
- y,
204
- z
205
- }, true);
236
+ mass: () => ref.current().mass(),
237
+
238
+ applyImpulse(impulseVector) {
239
+ ref.current().applyImpulse(impulseVector, true);
206
240
  },
207
241
 
208
- applyTorqueImpulse({
209
- x,
210
- y,
211
- z
212
- }) {
213
- ref.current().applyTorqueImpulse({
214
- x,
215
- y,
216
- z
217
- }, true);
242
+ applyTorqueImpulse(torqueVector) {
243
+ ref.current().applyTorqueImpulse(torqueVector, true);
218
244
  },
219
245
 
246
+ applyImpulseAtPoint: (impulseVector, impulsePoint) => ref.current().applyImpulseAtPoint(impulseVector, impulsePoint, true),
247
+ addForce: force => ref.current().addForce(force, true),
248
+ addForceAtPoint: (force, point) => ref.current().addForceAtPoint(force, point, true),
249
+ addTorque: torque => ref.current().addTorque(torque, true),
250
+
220
251
  translation() {
221
252
  const {
222
253
  x,
@@ -226,6 +257,8 @@ const createRigidBodyApi = ref => {
226
257
  return new Vector3(x, y, z);
227
258
  },
228
259
 
260
+ setTranslation: translation => ref.current().setTranslation(translation, true),
261
+
229
262
  rotation() {
230
263
  const {
231
264
  x,
@@ -236,31 +269,37 @@ const createRigidBodyApi = ref => {
236
269
  return new Quaternion(x, y, z, w);
237
270
  },
238
271
 
239
- setNextKinematicRotation({
240
- x,
241
- y,
242
- z
243
- }) {
244
- ref.current().setNextKinematicRotation({
272
+ setRotation: rotation => ref.current().setRotation(_objectSpread2(_objectSpread2({}, rotation), {}, {
273
+ w: 1
274
+ }), true),
275
+
276
+ linvel() {
277
+ const {
245
278
  x,
246
279
  y,
247
- z,
248
- w: 1
249
- });
280
+ z
281
+ } = ref.current().linvel();
282
+ return new Vector3(x, y, z);
250
283
  },
251
284
 
252
- setNextKinematicTranslation({
253
- x,
254
- y,
255
- z
256
- }) {
257
- ref.current().setNextKinematicTranslation({
285
+ setLinvel: velocity => ref.current().setLinvel(velocity, true),
286
+
287
+ angvel() {
288
+ const {
258
289
  x,
259
290
  y,
260
291
  z
261
- });
262
- }
292
+ } = ref.current().angvel();
293
+ return new Vector3(x, y, z);
294
+ },
263
295
 
296
+ setAngvel: velocity => ref.current().setAngvel(velocity, true),
297
+ setNextKinematicRotation: rotation => ref.current().setNextKinematicRotation(_objectSpread2(_objectSpread2({}, rotation), {}, {
298
+ w: 1
299
+ })),
300
+ setNextKinematicTranslation: translation => ref.current().setNextKinematicTranslation(translation),
301
+ resetForces: () => ref.current().resetForces(true),
302
+ resetTorques: () => ref.current().resetTorques(true)
264
303
  };
265
304
  }; // TODO: Flesh this out
266
305
 
@@ -460,47 +499,6 @@ const Physics = ({
460
499
  }, children);
461
500
  };
462
501
 
463
- function _defineProperty(obj, key, value) {
464
- if (key in obj) {
465
- Object.defineProperty(obj, key, {
466
- value: value,
467
- enumerable: true,
468
- configurable: true,
469
- writable: true
470
- });
471
- } else {
472
- obj[key] = value;
473
- }
474
-
475
- return obj;
476
- }
477
-
478
- function ownKeys(object, enumerableOnly) {
479
- var keys = Object.keys(object);
480
-
481
- if (Object.getOwnPropertySymbols) {
482
- var symbols = Object.getOwnPropertySymbols(object);
483
- enumerableOnly && (symbols = symbols.filter(function (sym) {
484
- return Object.getOwnPropertyDescriptor(object, sym).enumerable;
485
- })), keys.push.apply(keys, symbols);
486
- }
487
-
488
- return keys;
489
- }
490
-
491
- function _objectSpread2(target) {
492
- for (var i = 1; i < arguments.length; i++) {
493
- var source = null != arguments[i] ? arguments[i] : {};
494
- i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
495
- _defineProperty(target, key, source[key]);
496
- }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
497
- Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
498
- });
499
- }
500
-
501
- return target;
502
- }
503
-
504
502
  const useRapier = () => {
505
503
  return useContext(RapierContext);
506
504
  };
@@ -566,7 +564,6 @@ const useRigidBody = (options = {}) => {
566
564
  y: worldPosition.y + y * scale.y,
567
565
  z: worldPosition.z + z * scale.z
568
566
  }, false);
569
- console.log(rigidBody.isKinematic());
570
567
  const eulerAngles = new Euler(rx, ry, rz, 'XYZ');
571
568
  const rotation = new Quaternion().setFromEuler(eulerAngles).multiply(worldRotation);
572
569
  rigidBody.setRotation({
@@ -583,8 +580,7 @@ const useRigidBody = (options = {}) => {
583
580
  rigidBody.wakeUp();
584
581
  rigidBodyMeshes.set(rigidBody.handle, ref.current);
585
582
  return () => {
586
- const actualBody = world.getRigidBody(rigidBody.handle);
587
- world.removeRigidBody(actualBody);
583
+ world.removeRigidBody(rigidBody);
588
584
  autoColliders.forEach(collider => world.removeCollider(collider));
589
585
  rigidBodyRef.current = undefined;
590
586
  rigidBodyMeshes.delete(rigidBody.handle);
@@ -946,7 +942,7 @@ const AnyCollider = _ref2 => {
946
942
  const ref = useRef(null);
947
943
  useEffect(() => {
948
944
  const scale = ref.current.getWorldScale(new Vector3());
949
- const collider = createColliderFromOptions(props, world, world.getRigidBody(rigidBody.handle), scale, hasCollisionEvents);
945
+ const collider = createColliderFromOptions(props, world, rigidBody.raw(), scale, hasCollisionEvents);
950
946
  return () => {
951
947
  world.removeCollider(collider);
952
948
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-three/rapier",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "source": "src/index.ts",
5
5
  "main": "dist/react-three-rapier.cjs.js",
6
6
  "module": "dist/react-three-rapier.esm.js",