@gg-web-engine/rapier3d 0.0.24
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 +17 -0
- package/dist/components/rapier-3d-rigid-body.component.d.ts +26 -0
- package/dist/components/rapier-3d-rigid-body.component.js +88 -0
- package/dist/components/rapier-3d-trigger.component.d.ts +17 -0
- package/dist/components/rapier-3d-trigger.component.js +41 -0
- package/dist/components/rapier-3d-world.component.d.ts +27 -0
- package/dist/components/rapier-3d-world.component.js +81 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +6 -0
- package/dist/rapier-3d-factory.d.ts +22 -0
- package/dist/rapier-3d-factory.js +89 -0
- package/dist/rapier-3d-loader.d.ts +6 -0
- package/dist/rapier-3d-loader.js +7 -0
- package/etc/@dimforge/rapier3d/LICENSE +201 -0
- package/etc/@dimforge/rapier3d/README.md +33 -0
- package/etc/@dimforge/rapier3d/coarena.d.ts +15 -0
- package/etc/@dimforge/rapier3d/coarena.js +61 -0
- package/etc/@dimforge/rapier3d/coarena.js.map +1 -0
- package/etc/@dimforge/rapier3d/control/character_controller.d.ts +188 -0
- package/etc/@dimforge/rapier3d/control/character_controller.js +256 -0
- package/etc/@dimforge/rapier3d/control/character_controller.js.map +1 -0
- package/etc/@dimforge/rapier3d/control/index.d.ts +2 -0
- package/etc/@dimforge/rapier3d/control/index.js +5 -0
- package/etc/@dimforge/rapier3d/control/index.js.map +1 -0
- package/etc/@dimforge/rapier3d/control/ray_cast_vehicle_controller.d.ts +240 -0
- package/etc/@dimforge/rapier3d/control/ray_cast_vehicle_controller.js +362 -0
- package/etc/@dimforge/rapier3d/control/ray_cast_vehicle_controller.js.map +1 -0
- package/etc/@dimforge/rapier3d/dynamics/ccd_solver.d.ts +15 -0
- package/etc/@dimforge/rapier3d/dynamics/ccd_solver.js +22 -0
- package/etc/@dimforge/rapier3d/dynamics/ccd_solver.js.map +1 -0
- package/etc/@dimforge/rapier3d/dynamics/coefficient_combine_rule.d.ts +13 -0
- package/etc/@dimforge/rapier3d/dynamics/coefficient_combine_rule.js +15 -0
- package/etc/@dimforge/rapier3d/dynamics/coefficient_combine_rule.js.map +1 -0
- package/etc/@dimforge/rapier3d/dynamics/impulse_joint.d.ts +204 -0
- package/etc/@dimforge/rapier3d/dynamics/impulse_joint.js +335 -0
- package/etc/@dimforge/rapier3d/dynamics/impulse_joint.js.map +1 -0
- package/etc/@dimforge/rapier3d/dynamics/impulse_joint_set.d.ts +79 -0
- package/etc/@dimforge/rapier3d/dynamics/impulse_joint_set.js +123 -0
- package/etc/@dimforge/rapier3d/dynamics/impulse_joint_set.js.map +1 -0
- package/etc/@dimforge/rapier3d/dynamics/index.d.ts +10 -0
- package/etc/@dimforge/rapier3d/dynamics/index.js +11 -0
- package/etc/@dimforge/rapier3d/dynamics/index.js.map +1 -0
- package/etc/@dimforge/rapier3d/dynamics/integration_parameters.d.ts +55 -0
- package/etc/@dimforge/rapier3d/dynamics/integration_parameters.js +98 -0
- package/etc/@dimforge/rapier3d/dynamics/integration_parameters.js.map +1 -0
- package/etc/@dimforge/rapier3d/dynamics/island_manager.d.ts +24 -0
- package/etc/@dimforge/rapier3d/dynamics/island_manager.js +32 -0
- package/etc/@dimforge/rapier3d/dynamics/island_manager.js.map +1 -0
- package/etc/@dimforge/rapier3d/dynamics/multibody_joint.d.ts +42 -0
- package/etc/@dimforge/rapier3d/dynamics/multibody_joint.js +124 -0
- package/etc/@dimforge/rapier3d/dynamics/multibody_joint.js.map +1 -0
- package/etc/@dimforge/rapier3d/dynamics/multibody_joint_set.d.ts +76 -0
- package/etc/@dimforge/rapier3d/dynamics/multibody_joint_set.js +118 -0
- package/etc/@dimforge/rapier3d/dynamics/multibody_joint_set.js.map +1 -0
- package/etc/@dimforge/rapier3d/dynamics/rigid_body.d.ts +679 -0
- package/etc/@dimforge/rapier3d/dynamics/rigid_body.js +960 -0
- package/etc/@dimforge/rapier3d/dynamics/rigid_body.js.map +1 -0
- package/etc/@dimforge/rapier3d/dynamics/rigid_body_set.d.ts +78 -0
- package/etc/@dimforge/rapier3d/dynamics/rigid_body_set.js +147 -0
- package/etc/@dimforge/rapier3d/dynamics/rigid_body_set.js.map +1 -0
- package/etc/@dimforge/rapier3d/exports.d.ts +7 -0
- package/etc/@dimforge/rapier3d/exports.js +11 -0
- package/etc/@dimforge/rapier3d/exports.js.map +1 -0
- package/etc/@dimforge/rapier3d/geometry/broad_phase.d.ts +15 -0
- package/etc/@dimforge/rapier3d/geometry/broad_phase.js +22 -0
- package/etc/@dimforge/rapier3d/geometry/broad_phase.js.map +1 -0
- package/etc/@dimforge/rapier3d/geometry/collider.d.ts +763 -0
- package/etc/@dimforge/rapier3d/geometry/collider.js +1140 -0
- package/etc/@dimforge/rapier3d/geometry/collider.js.map +1 -0
- package/etc/@dimforge/rapier3d/geometry/collider_set.d.ts +72 -0
- package/etc/@dimforge/rapier3d/geometry/collider_set.js +144 -0
- package/etc/@dimforge/rapier3d/geometry/collider_set.js.map +1 -0
- package/etc/@dimforge/rapier3d/geometry/contact.d.ts +31 -0
- package/etc/@dimforge/rapier3d/geometry/contact.js +21 -0
- package/etc/@dimforge/rapier3d/geometry/contact.js.map +1 -0
- package/etc/@dimforge/rapier3d/geometry/feature.d.ts +6 -0
- package/etc/@dimforge/rapier3d/geometry/feature.js +10 -0
- package/etc/@dimforge/rapier3d/geometry/feature.js.map +1 -0
- package/etc/@dimforge/rapier3d/geometry/index.d.ts +11 -0
- package/etc/@dimforge/rapier3d/geometry/index.js +12 -0
- package/etc/@dimforge/rapier3d/geometry/index.js.map +1 -0
- package/etc/@dimforge/rapier3d/geometry/interaction_groups.d.ts +18 -0
- package/etc/@dimforge/rapier3d/geometry/interaction_groups.js +2 -0
- package/etc/@dimforge/rapier3d/geometry/interaction_groups.js.map +1 -0
- package/etc/@dimforge/rapier3d/geometry/narrow_phase.d.ts +71 -0
- package/etc/@dimforge/rapier3d/geometry/narrow_phase.js +148 -0
- package/etc/@dimforge/rapier3d/geometry/narrow_phase.js.map +1 -0
- package/etc/@dimforge/rapier3d/geometry/point.d.ts +47 -0
- package/etc/@dimforge/rapier3d/geometry/point.js +48 -0
- package/etc/@dimforge/rapier3d/geometry/point.js.map +1 -0
- package/etc/@dimforge/rapier3d/geometry/ray.d.ts +97 -0
- package/etc/@dimforge/rapier3d/geometry/ray.js +100 -0
- package/etc/@dimforge/rapier3d/geometry/ray.js.map +1 -0
- package/etc/@dimforge/rapier3d/geometry/shape.d.ts +489 -0
- package/etc/@dimforge/rapier3d/geometry/shape.js +686 -0
- package/etc/@dimforge/rapier3d/geometry/shape.js.map +1 -0
- package/etc/@dimforge/rapier3d/geometry/toi.d.ts +46 -0
- package/etc/@dimforge/rapier3d/geometry/toi.js +37 -0
- package/etc/@dimforge/rapier3d/geometry/toi.js.map +1 -0
- package/etc/@dimforge/rapier3d/init.d.ts +1 -0
- package/etc/@dimforge/rapier3d/init.js +2 -0
- package/etc/@dimforge/rapier3d/init.js.map +1 -0
- package/etc/@dimforge/rapier3d/math.d.ts +94 -0
- package/etc/@dimforge/rapier3d/math.js +138 -0
- package/etc/@dimforge/rapier3d/math.js.map +1 -0
- package/etc/@dimforge/rapier3d/package.json +33 -0
- package/etc/@dimforge/rapier3d/pipeline/debug_render_pipeline.d.ts +39 -0
- package/etc/@dimforge/rapier3d/pipeline/debug_render_pipeline.js +38 -0
- package/etc/@dimforge/rapier3d/pipeline/debug_render_pipeline.js.map +1 -0
- package/etc/@dimforge/rapier3d/pipeline/event_queue.d.ts +101 -0
- package/etc/@dimforge/rapier3d/pipeline/event_queue.js +135 -0
- package/etc/@dimforge/rapier3d/pipeline/event_queue.js.map +1 -0
- package/etc/@dimforge/rapier3d/pipeline/index.d.ts +7 -0
- package/etc/@dimforge/rapier3d/pipeline/index.js +8 -0
- package/etc/@dimforge/rapier3d/pipeline/index.js.map +1 -0
- package/etc/@dimforge/rapier3d/pipeline/physics_hooks.d.ts +39 -0
- package/etc/@dimforge/rapier3d/pipeline/physics_hooks.js +13 -0
- package/etc/@dimforge/rapier3d/pipeline/physics_hooks.js.map +1 -0
- package/etc/@dimforge/rapier3d/pipeline/physics_pipeline.d.ts +12 -0
- package/etc/@dimforge/rapier3d/pipeline/physics_pipeline.js +24 -0
- package/etc/@dimforge/rapier3d/pipeline/physics_pipeline.js.map +1 -0
- package/etc/@dimforge/rapier3d/pipeline/query_pipeline.d.ts +190 -0
- package/etc/@dimforge/rapier3d/pipeline/query_pipeline.js +271 -0
- package/etc/@dimforge/rapier3d/pipeline/query_pipeline.js.map +1 -0
- package/etc/@dimforge/rapier3d/pipeline/serialization_pipeline.d.ts +37 -0
- package/etc/@dimforge/rapier3d/pipeline/serialization_pipeline.js +49 -0
- package/etc/@dimforge/rapier3d/pipeline/serialization_pipeline.js.map +1 -0
- package/etc/@dimforge/rapier3d/pipeline/world.d.ts +419 -0
- package/etc/@dimforge/rapier3d/pipeline/world.js +581 -0
- package/etc/@dimforge/rapier3d/pipeline/world.js.map +1 -0
- package/etc/@dimforge/rapier3d/rapier.d.ts +3 -0
- package/etc/@dimforge/rapier3d/rapier.js +4 -0
- package/etc/@dimforge/rapier3d/rapier.js.map +1 -0
- package/etc/@dimforge/rapier3d/rapier_wasm3d.d.ts +2921 -0
- package/etc/@dimforge/rapier3d/rapier_wasm3d.js +2 -0
- package/etc/@dimforge/rapier3d/rapier_wasm3d_bg.js +5585 -0
- package/etc/@dimforge/rapier3d/rapier_wasm3d_bg.wasm +0 -0
- package/etc/@dimforge/rapier3d/rapier_wasm3d_bg.wasm.d.ts +486 -0
- package/etc/@dimforge/rapier3d/raw.d.ts +1 -0
- package/etc/@dimforge/rapier3d/raw.js +2 -0
- package/etc/@dimforge/rapier3d/raw.js.map +1 -0
- package/package.json +43 -0
- package/tsconfig.json +8 -0
|
@@ -0,0 +1,960 @@
|
|
|
1
|
+
import { RotationOps, VectorOps } from "../math";
|
|
2
|
+
// #if DIM3
|
|
3
|
+
import { SdpMatrix3Ops } from "../math";
|
|
4
|
+
/**
|
|
5
|
+
* The simulation status of a rigid-body.
|
|
6
|
+
*/
|
|
7
|
+
// TODO: rename this to RigidBodyType
|
|
8
|
+
export var RigidBodyType;
|
|
9
|
+
(function (RigidBodyType) {
|
|
10
|
+
/**
|
|
11
|
+
* A `RigidBodyType::Dynamic` body can be affected by all external forces.
|
|
12
|
+
*/
|
|
13
|
+
RigidBodyType[RigidBodyType["Dynamic"] = 0] = "Dynamic";
|
|
14
|
+
/**
|
|
15
|
+
* A `RigidBodyType::Fixed` body cannot be affected by external forces.
|
|
16
|
+
*/
|
|
17
|
+
RigidBodyType[RigidBodyType["Fixed"] = 1] = "Fixed";
|
|
18
|
+
/**
|
|
19
|
+
* A `RigidBodyType::KinematicPositionBased` body cannot be affected by any external forces but can be controlled
|
|
20
|
+
* by the user at the position level while keeping realistic one-way interaction with dynamic bodies.
|
|
21
|
+
*
|
|
22
|
+
* One-way interaction means that a kinematic body can push a dynamic body, but a kinematic body
|
|
23
|
+
* cannot be pushed by anything. In other words, the trajectory of a kinematic body can only be
|
|
24
|
+
* modified by the user and is independent from any contact or joint it is involved in.
|
|
25
|
+
*/
|
|
26
|
+
RigidBodyType[RigidBodyType["KinematicPositionBased"] = 2] = "KinematicPositionBased";
|
|
27
|
+
/**
|
|
28
|
+
* A `RigidBodyType::KinematicVelocityBased` body cannot be affected by any external forces but can be controlled
|
|
29
|
+
* by the user at the velocity level while keeping realistic one-way interaction with dynamic bodies.
|
|
30
|
+
*
|
|
31
|
+
* One-way interaction means that a kinematic body can push a dynamic body, but a kinematic body
|
|
32
|
+
* cannot be pushed by anything. In other words, the trajectory of a kinematic body can only be
|
|
33
|
+
* modified by the user and is independent from any contact or joint it is involved in.
|
|
34
|
+
*/
|
|
35
|
+
RigidBodyType[RigidBodyType["KinematicVelocityBased"] = 3] = "KinematicVelocityBased";
|
|
36
|
+
})(RigidBodyType || (RigidBodyType = {}));
|
|
37
|
+
/**
|
|
38
|
+
* A rigid-body.
|
|
39
|
+
*/
|
|
40
|
+
export class RigidBody {
|
|
41
|
+
constructor(rawSet, colliderSet, handle) {
|
|
42
|
+
this.rawSet = rawSet;
|
|
43
|
+
this.colliderSet = colliderSet;
|
|
44
|
+
this.handle = handle;
|
|
45
|
+
}
|
|
46
|
+
/** @internal */
|
|
47
|
+
finalizeDeserialization(colliderSet) {
|
|
48
|
+
this.colliderSet = colliderSet;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Checks if this rigid-body is still valid (i.e. that it has
|
|
52
|
+
* not been deleted from the rigid-body set yet.
|
|
53
|
+
*/
|
|
54
|
+
isValid() {
|
|
55
|
+
return this.rawSet.contains(this.handle);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Locks or unlocks the ability of this rigid-body to translate.
|
|
59
|
+
*
|
|
60
|
+
* @param locked - If `true`, this rigid-body will no longer translate due to forces and impulses.
|
|
61
|
+
* @param wakeUp - If `true`, this rigid-body will be automatically awaken if it is currently asleep.
|
|
62
|
+
*/
|
|
63
|
+
lockTranslations(locked, wakeUp) {
|
|
64
|
+
return this.rawSet.rbLockTranslations(this.handle, locked, wakeUp);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Locks or unlocks the ability of this rigid-body to rotate.
|
|
68
|
+
*
|
|
69
|
+
* @param locked - If `true`, this rigid-body will no longer rotate due to torques and impulses.
|
|
70
|
+
* @param wakeUp - If `true`, this rigid-body will be automatically awaken if it is currently asleep.
|
|
71
|
+
*/
|
|
72
|
+
lockRotations(locked, wakeUp) {
|
|
73
|
+
return this.rawSet.rbLockRotations(this.handle, locked, wakeUp);
|
|
74
|
+
}
|
|
75
|
+
// #if DIM3
|
|
76
|
+
/**
|
|
77
|
+
* Locks or unlocks the ability of this rigid-body to translate along individual coordinate axes.
|
|
78
|
+
*
|
|
79
|
+
* @param enableX - If `false`, this rigid-body will no longer translate due to torques and impulses, along the X coordinate axis.
|
|
80
|
+
* @param enableY - If `false`, this rigid-body will no longer translate due to torques and impulses, along the Y coordinate axis.
|
|
81
|
+
* @param enableZ - If `false`, this rigid-body will no longer translate due to torques and impulses, along the Z coordinate axis.
|
|
82
|
+
* @param wakeUp - If `true`, this rigid-body will be automatically awaken if it is currently asleep.
|
|
83
|
+
*/
|
|
84
|
+
setEnabledTranslations(enableX, enableY, enableZ, wakeUp) {
|
|
85
|
+
return this.rawSet.rbSetEnabledTranslations(this.handle, enableX, enableY, enableZ, wakeUp);
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Locks or unlocks the ability of this rigid-body to translate along individual coordinate axes.
|
|
89
|
+
*
|
|
90
|
+
* @param enableX - If `false`, this rigid-body will no longer translate due to torques and impulses, along the X coordinate axis.
|
|
91
|
+
* @param enableY - If `false`, this rigid-body will no longer translate due to torques and impulses, along the Y coordinate axis.
|
|
92
|
+
* @param enableZ - If `false`, this rigid-body will no longer translate due to torques and impulses, along the Z coordinate axis.
|
|
93
|
+
* @param wakeUp - If `true`, this rigid-body will be automatically awaken if it is currently asleep.
|
|
94
|
+
* @deprecated use `this.setEnabledTranslations` with the same arguments instead.
|
|
95
|
+
*/
|
|
96
|
+
restrictTranslations(enableX, enableY, enableZ, wakeUp) {
|
|
97
|
+
this.setEnabledTranslations(enableX, enableY, enableZ, wakeUp);
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Locks or unlocks the ability of this rigid-body to rotate along individual coordinate axes.
|
|
101
|
+
*
|
|
102
|
+
* @param enableX - If `false`, this rigid-body will no longer rotate due to torques and impulses, along the X coordinate axis.
|
|
103
|
+
* @param enableY - If `false`, this rigid-body will no longer rotate due to torques and impulses, along the Y coordinate axis.
|
|
104
|
+
* @param enableZ - If `false`, this rigid-body will no longer rotate due to torques and impulses, along the Z coordinate axis.
|
|
105
|
+
* @param wakeUp - If `true`, this rigid-body will be automatically awaken if it is currently asleep.
|
|
106
|
+
*/
|
|
107
|
+
setEnabledRotations(enableX, enableY, enableZ, wakeUp) {
|
|
108
|
+
return this.rawSet.rbSetEnabledRotations(this.handle, enableX, enableY, enableZ, wakeUp);
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Locks or unlocks the ability of this rigid-body to rotate along individual coordinate axes.
|
|
112
|
+
*
|
|
113
|
+
* @param enableX - If `false`, this rigid-body will no longer rotate due to torques and impulses, along the X coordinate axis.
|
|
114
|
+
* @param enableY - If `false`, this rigid-body will no longer rotate due to torques and impulses, along the Y coordinate axis.
|
|
115
|
+
* @param enableZ - If `false`, this rigid-body will no longer rotate due to torques and impulses, along the Z coordinate axis.
|
|
116
|
+
* @param wakeUp - If `true`, this rigid-body will be automatically awaken if it is currently asleep.
|
|
117
|
+
* @deprecated use `this.setEnabledRotations` with the same arguments instead.
|
|
118
|
+
*/
|
|
119
|
+
restrictRotations(enableX, enableY, enableZ, wakeUp) {
|
|
120
|
+
this.setEnabledRotations(enableX, enableY, enableZ, wakeUp);
|
|
121
|
+
}
|
|
122
|
+
// #endif
|
|
123
|
+
/**
|
|
124
|
+
* The dominance group, in [-127, +127] this rigid-body is part of.
|
|
125
|
+
*/
|
|
126
|
+
dominanceGroup() {
|
|
127
|
+
return this.rawSet.rbDominanceGroup(this.handle);
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Sets the dominance group of this rigid-body.
|
|
131
|
+
*
|
|
132
|
+
* @param group - The dominance group of this rigid-body. Must be a signed integer in the range [-127, +127].
|
|
133
|
+
*/
|
|
134
|
+
setDominanceGroup(group) {
|
|
135
|
+
this.rawSet.rbSetDominanceGroup(this.handle, group);
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Enable or disable CCD (Continuous Collision Detection) for this rigid-body.
|
|
139
|
+
*
|
|
140
|
+
* @param enabled - If `true`, CCD will be enabled for this rigid-body.
|
|
141
|
+
*/
|
|
142
|
+
enableCcd(enabled) {
|
|
143
|
+
this.rawSet.rbEnableCcd(this.handle, enabled);
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* The world-space translation of this rigid-body.
|
|
147
|
+
*/
|
|
148
|
+
translation() {
|
|
149
|
+
let res = this.rawSet.rbTranslation(this.handle);
|
|
150
|
+
return VectorOps.fromRaw(res);
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* The world-space orientation of this rigid-body.
|
|
154
|
+
*/
|
|
155
|
+
rotation() {
|
|
156
|
+
let res = this.rawSet.rbRotation(this.handle);
|
|
157
|
+
return RotationOps.fromRaw(res);
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* The world-space next translation of this rigid-body.
|
|
161
|
+
*
|
|
162
|
+
* If this rigid-body is kinematic this value is set by the `setNextKinematicTranslation`
|
|
163
|
+
* method and is used for estimating the kinematic body velocity at the next timestep.
|
|
164
|
+
* For non-kinematic bodies, this value is currently unspecified.
|
|
165
|
+
*/
|
|
166
|
+
nextTranslation() {
|
|
167
|
+
let res = this.rawSet.rbNextTranslation(this.handle);
|
|
168
|
+
return VectorOps.fromRaw(res);
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* The world-space next orientation of this rigid-body.
|
|
172
|
+
*
|
|
173
|
+
* If this rigid-body is kinematic this value is set by the `setNextKinematicRotation`
|
|
174
|
+
* method and is used for estimating the kinematic body velocity at the next timestep.
|
|
175
|
+
* For non-kinematic bodies, this value is currently unspecified.
|
|
176
|
+
*/
|
|
177
|
+
nextRotation() {
|
|
178
|
+
let res = this.rawSet.rbNextRotation(this.handle);
|
|
179
|
+
return RotationOps.fromRaw(res);
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Sets the translation of this rigid-body.
|
|
183
|
+
*
|
|
184
|
+
* @param tra - The world-space position of the rigid-body.
|
|
185
|
+
* @param wakeUp - Forces the rigid-body to wake-up so it is properly affected by forces if it
|
|
186
|
+
* wasn't moving before modifying its position.
|
|
187
|
+
*/
|
|
188
|
+
setTranslation(tra, wakeUp) {
|
|
189
|
+
// #if DIM3
|
|
190
|
+
this.rawSet.rbSetTranslation(this.handle, tra.x, tra.y, tra.z, wakeUp);
|
|
191
|
+
// #endif
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Sets the linear velocity of this rigid-body.
|
|
195
|
+
*
|
|
196
|
+
* @param vel - The linear velocity to set.
|
|
197
|
+
* @param wakeUp - Forces the rigid-body to wake-up if it was asleep.
|
|
198
|
+
*/
|
|
199
|
+
setLinvel(vel, wakeUp) {
|
|
200
|
+
let rawVel = VectorOps.intoRaw(vel);
|
|
201
|
+
this.rawSet.rbSetLinvel(this.handle, rawVel, wakeUp);
|
|
202
|
+
rawVel.free();
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* The scale factor applied to the gravity affecting
|
|
206
|
+
* this rigid-body.
|
|
207
|
+
*/
|
|
208
|
+
gravityScale() {
|
|
209
|
+
return this.rawSet.rbGravityScale(this.handle);
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Sets the scale factor applied to the gravity affecting
|
|
213
|
+
* this rigid-body.
|
|
214
|
+
*
|
|
215
|
+
* @param factor - The scale factor to set. A value of 0.0 means
|
|
216
|
+
* that this rigid-body will on longer be affected by gravity.
|
|
217
|
+
* @param wakeUp - Forces the rigid-body to wake-up if it was asleep.
|
|
218
|
+
*/
|
|
219
|
+
setGravityScale(factor, wakeUp) {
|
|
220
|
+
this.rawSet.rbSetGravityScale(this.handle, factor, wakeUp);
|
|
221
|
+
}
|
|
222
|
+
// #if DIM3
|
|
223
|
+
/**
|
|
224
|
+
* Sets the rotation quaternion of this rigid-body.
|
|
225
|
+
*
|
|
226
|
+
* This does nothing if a zero quaternion is provided.
|
|
227
|
+
*
|
|
228
|
+
* @param rotation - The rotation to set.
|
|
229
|
+
* @param wakeUp - Forces the rigid-body to wake-up so it is properly affected by forces if it
|
|
230
|
+
* wasn't moving before modifying its position.
|
|
231
|
+
*/
|
|
232
|
+
setRotation(rot, wakeUp) {
|
|
233
|
+
this.rawSet.rbSetRotation(this.handle, rot.x, rot.y, rot.z, rot.w, wakeUp);
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Sets the angular velocity fo this rigid-body.
|
|
237
|
+
*
|
|
238
|
+
* @param vel - The angular velocity to set.
|
|
239
|
+
* @param wakeUp - Forces the rigid-body to wake-up if it was asleep.
|
|
240
|
+
*/
|
|
241
|
+
setAngvel(vel, wakeUp) {
|
|
242
|
+
let rawVel = VectorOps.intoRaw(vel);
|
|
243
|
+
this.rawSet.rbSetAngvel(this.handle, rawVel, wakeUp);
|
|
244
|
+
rawVel.free();
|
|
245
|
+
}
|
|
246
|
+
// #endif
|
|
247
|
+
/**
|
|
248
|
+
* If this rigid body is kinematic, sets its future translation after the next timestep integration.
|
|
249
|
+
*
|
|
250
|
+
* This should be used instead of `rigidBody.setTranslation` to make the dynamic object
|
|
251
|
+
* interacting with this kinematic body behave as expected. Internally, Rapier will compute
|
|
252
|
+
* an artificial velocity for this rigid-body from its current position and its next kinematic
|
|
253
|
+
* position. This velocity will be used to compute forces on dynamic bodies interacting with
|
|
254
|
+
* this body.
|
|
255
|
+
*
|
|
256
|
+
* @param t - The kinematic translation to set.
|
|
257
|
+
*/
|
|
258
|
+
setNextKinematicTranslation(t) {
|
|
259
|
+
// #if DIM3
|
|
260
|
+
this.rawSet.rbSetNextKinematicTranslation(this.handle, t.x, t.y, t.z);
|
|
261
|
+
// #endif
|
|
262
|
+
}
|
|
263
|
+
// #if DIM3
|
|
264
|
+
/**
|
|
265
|
+
* If this rigid body is kinematic, sets its future rotation after the next timestep integration.
|
|
266
|
+
*
|
|
267
|
+
* This should be used instead of `rigidBody.setRotation` to make the dynamic object
|
|
268
|
+
* interacting with this kinematic body behave as expected. Internally, Rapier will compute
|
|
269
|
+
* an artificial velocity for this rigid-body from its current position and its next kinematic
|
|
270
|
+
* position. This velocity will be used to compute forces on dynamic bodies interacting with
|
|
271
|
+
* this body.
|
|
272
|
+
*
|
|
273
|
+
* @param rot - The kinematic rotation to set.
|
|
274
|
+
*/
|
|
275
|
+
setNextKinematicRotation(rot) {
|
|
276
|
+
this.rawSet.rbSetNextKinematicRotation(this.handle, rot.x, rot.y, rot.z, rot.w);
|
|
277
|
+
}
|
|
278
|
+
// #endif
|
|
279
|
+
/**
|
|
280
|
+
* The linear velocity of this rigid-body.
|
|
281
|
+
*/
|
|
282
|
+
linvel() {
|
|
283
|
+
return VectorOps.fromRaw(this.rawSet.rbLinvel(this.handle));
|
|
284
|
+
}
|
|
285
|
+
// #if DIM3
|
|
286
|
+
/**
|
|
287
|
+
* The angular velocity of this rigid-body.
|
|
288
|
+
*/
|
|
289
|
+
angvel() {
|
|
290
|
+
return VectorOps.fromRaw(this.rawSet.rbAngvel(this.handle));
|
|
291
|
+
}
|
|
292
|
+
// #endif
|
|
293
|
+
/**
|
|
294
|
+
* The mass of this rigid-body.
|
|
295
|
+
*/
|
|
296
|
+
mass() {
|
|
297
|
+
return this.rawSet.rbMass(this.handle);
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* The inverse mass taking into account translation locking.
|
|
301
|
+
*/
|
|
302
|
+
effectiveInvMass() {
|
|
303
|
+
return VectorOps.fromRaw(this.rawSet.rbEffectiveInvMass(this.handle));
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* The inverse of the mass of a rigid-body.
|
|
307
|
+
*
|
|
308
|
+
* If this is zero, the rigid-body is assumed to have infinite mass.
|
|
309
|
+
*/
|
|
310
|
+
invMass() {
|
|
311
|
+
return this.rawSet.rbInvMass(this.handle);
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* The center of mass of a rigid-body expressed in its local-space.
|
|
315
|
+
*/
|
|
316
|
+
localCom() {
|
|
317
|
+
return VectorOps.fromRaw(this.rawSet.rbLocalCom(this.handle));
|
|
318
|
+
}
|
|
319
|
+
/**
|
|
320
|
+
* The world-space center of mass of the rigid-body.
|
|
321
|
+
*/
|
|
322
|
+
worldCom() {
|
|
323
|
+
return VectorOps.fromRaw(this.rawSet.rbWorldCom(this.handle));
|
|
324
|
+
}
|
|
325
|
+
// #if DIM3
|
|
326
|
+
/**
|
|
327
|
+
* The inverse of the principal angular inertia of the rigid-body.
|
|
328
|
+
*
|
|
329
|
+
* Components set to zero are assumed to be infinite along the corresponding principal axis.
|
|
330
|
+
*/
|
|
331
|
+
invPrincipalInertiaSqrt() {
|
|
332
|
+
return VectorOps.fromRaw(this.rawSet.rbInvPrincipalInertiaSqrt(this.handle));
|
|
333
|
+
}
|
|
334
|
+
// #endif
|
|
335
|
+
// #if DIM3
|
|
336
|
+
/**
|
|
337
|
+
* The angular inertia along the principal inertia axes of the rigid-body.
|
|
338
|
+
*/
|
|
339
|
+
principalInertia() {
|
|
340
|
+
return VectorOps.fromRaw(this.rawSet.rbPrincipalInertia(this.handle));
|
|
341
|
+
}
|
|
342
|
+
// #endif
|
|
343
|
+
// #if DIM3
|
|
344
|
+
/**
|
|
345
|
+
* The principal vectors of the local angular inertia tensor of the rigid-body.
|
|
346
|
+
*/
|
|
347
|
+
principalInertiaLocalFrame() {
|
|
348
|
+
return RotationOps.fromRaw(this.rawSet.rbPrincipalInertiaLocalFrame(this.handle));
|
|
349
|
+
}
|
|
350
|
+
// #endif
|
|
351
|
+
// #if DIM3
|
|
352
|
+
/**
|
|
353
|
+
* The square-root of the world-space inverse angular inertia tensor of the rigid-body,
|
|
354
|
+
* taking into account rotation locking.
|
|
355
|
+
*/
|
|
356
|
+
effectiveWorldInvInertiaSqrt() {
|
|
357
|
+
return SdpMatrix3Ops.fromRaw(this.rawSet.rbEffectiveWorldInvInertiaSqrt(this.handle));
|
|
358
|
+
}
|
|
359
|
+
// #endif
|
|
360
|
+
// #if DIM3
|
|
361
|
+
/**
|
|
362
|
+
* The effective world-space angular inertia (that takes the potential rotation locking into account) of
|
|
363
|
+
* this rigid-body.
|
|
364
|
+
*/
|
|
365
|
+
effectiveAngularInertia() {
|
|
366
|
+
return SdpMatrix3Ops.fromRaw(this.rawSet.rbEffectiveAngularInertia(this.handle));
|
|
367
|
+
}
|
|
368
|
+
// #endif
|
|
369
|
+
/**
|
|
370
|
+
* Put this rigid body to sleep.
|
|
371
|
+
*
|
|
372
|
+
* A sleeping body no longer moves and is no longer simulated by the physics engine unless
|
|
373
|
+
* it is waken up. It can be woken manually with `this.wakeUp()` or automatically due to
|
|
374
|
+
* external forces like contacts.
|
|
375
|
+
*/
|
|
376
|
+
sleep() {
|
|
377
|
+
this.rawSet.rbSleep(this.handle);
|
|
378
|
+
}
|
|
379
|
+
/**
|
|
380
|
+
* Wakes this rigid-body up.
|
|
381
|
+
*
|
|
382
|
+
* A dynamic rigid-body that does not move during several consecutive frames will
|
|
383
|
+
* be put to sleep by the physics engine, i.e., it will stop being simulated in order
|
|
384
|
+
* to avoid useless computations.
|
|
385
|
+
* This methods forces a sleeping rigid-body to wake-up. This is useful, e.g., before modifying
|
|
386
|
+
* the position of a dynamic body so that it is properly simulated afterwards.
|
|
387
|
+
*/
|
|
388
|
+
wakeUp() {
|
|
389
|
+
this.rawSet.rbWakeUp(this.handle);
|
|
390
|
+
}
|
|
391
|
+
/**
|
|
392
|
+
* Is CCD enabled for this rigid-body?
|
|
393
|
+
*/
|
|
394
|
+
isCcdEnabled() {
|
|
395
|
+
return this.rawSet.rbIsCcdEnabled(this.handle);
|
|
396
|
+
}
|
|
397
|
+
/**
|
|
398
|
+
* The number of colliders attached to this rigid-body.
|
|
399
|
+
*/
|
|
400
|
+
numColliders() {
|
|
401
|
+
return this.rawSet.rbNumColliders(this.handle);
|
|
402
|
+
}
|
|
403
|
+
/**
|
|
404
|
+
* Retrieves the `i-th` collider attached to this rigid-body.
|
|
405
|
+
*
|
|
406
|
+
* @param i - The index of the collider to retrieve. Must be a number in `[0, this.numColliders()[`.
|
|
407
|
+
* This index is **not** the same as the unique identifier of the collider.
|
|
408
|
+
*/
|
|
409
|
+
collider(i) {
|
|
410
|
+
return this.colliderSet.get(this.rawSet.rbCollider(this.handle, i));
|
|
411
|
+
}
|
|
412
|
+
/**
|
|
413
|
+
* Sets whether this rigid-body is enabled or not.
|
|
414
|
+
*
|
|
415
|
+
* @param enabled - Set to `false` to disable this rigid-body and all its attached colliders.
|
|
416
|
+
*/
|
|
417
|
+
setEnabled(enabled) {
|
|
418
|
+
this.rawSet.rbSetEnabled(this.handle, enabled);
|
|
419
|
+
}
|
|
420
|
+
/**
|
|
421
|
+
* Is this rigid-body enabled?
|
|
422
|
+
*/
|
|
423
|
+
isEnabled() {
|
|
424
|
+
return this.rawSet.rbIsEnabled(this.handle);
|
|
425
|
+
}
|
|
426
|
+
/**
|
|
427
|
+
* The status of this rigid-body: static, dynamic, or kinematic.
|
|
428
|
+
*/
|
|
429
|
+
bodyType() {
|
|
430
|
+
return this.rawSet.rbBodyType(this.handle);
|
|
431
|
+
}
|
|
432
|
+
/**
|
|
433
|
+
* Set a new status for this rigid-body: static, dynamic, or kinematic.
|
|
434
|
+
*/
|
|
435
|
+
setBodyType(type, wakeUp) {
|
|
436
|
+
return this.rawSet.rbSetBodyType(this.handle, type, wakeUp);
|
|
437
|
+
}
|
|
438
|
+
/**
|
|
439
|
+
* Is this rigid-body sleeping?
|
|
440
|
+
*/
|
|
441
|
+
isSleeping() {
|
|
442
|
+
return this.rawSet.rbIsSleeping(this.handle);
|
|
443
|
+
}
|
|
444
|
+
/**
|
|
445
|
+
* Is the velocity of this rigid-body not zero?
|
|
446
|
+
*/
|
|
447
|
+
isMoving() {
|
|
448
|
+
return this.rawSet.rbIsMoving(this.handle);
|
|
449
|
+
}
|
|
450
|
+
/**
|
|
451
|
+
* Is this rigid-body static?
|
|
452
|
+
*/
|
|
453
|
+
isFixed() {
|
|
454
|
+
return this.rawSet.rbIsFixed(this.handle);
|
|
455
|
+
}
|
|
456
|
+
/**
|
|
457
|
+
* Is this rigid-body kinematic?
|
|
458
|
+
*/
|
|
459
|
+
isKinematic() {
|
|
460
|
+
return this.rawSet.rbIsKinematic(this.handle);
|
|
461
|
+
}
|
|
462
|
+
/**
|
|
463
|
+
* Is this rigid-body dynamic?
|
|
464
|
+
*/
|
|
465
|
+
isDynamic() {
|
|
466
|
+
return this.rawSet.rbIsDynamic(this.handle);
|
|
467
|
+
}
|
|
468
|
+
/**
|
|
469
|
+
* The linear damping coefficient of this rigid-body.
|
|
470
|
+
*/
|
|
471
|
+
linearDamping() {
|
|
472
|
+
return this.rawSet.rbLinearDamping(this.handle);
|
|
473
|
+
}
|
|
474
|
+
/**
|
|
475
|
+
* The angular damping coefficient of this rigid-body.
|
|
476
|
+
*/
|
|
477
|
+
angularDamping() {
|
|
478
|
+
return this.rawSet.rbAngularDamping(this.handle);
|
|
479
|
+
}
|
|
480
|
+
/**
|
|
481
|
+
* Sets the linear damping factor applied to this rigid-body.
|
|
482
|
+
*
|
|
483
|
+
* @param factor - The damping factor to set.
|
|
484
|
+
*/
|
|
485
|
+
setLinearDamping(factor) {
|
|
486
|
+
this.rawSet.rbSetLinearDamping(this.handle, factor);
|
|
487
|
+
}
|
|
488
|
+
/**
|
|
489
|
+
* Recompute the mass-properties of this rigid-bodies based on its currently attached colliders.
|
|
490
|
+
*/
|
|
491
|
+
recomputeMassPropertiesFromColliders() {
|
|
492
|
+
this.rawSet.rbRecomputeMassPropertiesFromColliders(this.handle, this.colliderSet.raw);
|
|
493
|
+
}
|
|
494
|
+
/**
|
|
495
|
+
* Sets the rigid-body's additional mass.
|
|
496
|
+
*
|
|
497
|
+
* The total angular inertia of the rigid-body will be scaled automatically based on this additional mass. If this
|
|
498
|
+
* scaling effect isn’t desired, use Self::additional_mass_properties instead of this method.
|
|
499
|
+
*
|
|
500
|
+
* This is only the "additional" mass because the total mass of the rigid-body is equal to the sum of this
|
|
501
|
+
* additional mass and the mass computed from the colliders (with non-zero densities) attached to this rigid-body.
|
|
502
|
+
*
|
|
503
|
+
* That total mass (which includes the attached colliders’ contributions) will be updated at the name physics step,
|
|
504
|
+
* or can be updated manually with `this.recomputeMassPropertiesFromColliders`.
|
|
505
|
+
*
|
|
506
|
+
* This will override any previous additional mass-properties set by `this.setAdditionalMass`,
|
|
507
|
+
* `this.setAdditionalMassProperties`, `RigidBodyDesc::setAdditionalMass`, or
|
|
508
|
+
* `RigidBodyDesc.setAdditionalMassfProperties` for this rigid-body.
|
|
509
|
+
*
|
|
510
|
+
* @param mass - The additional mass to set.
|
|
511
|
+
* @param wakeUp - If `true` then the rigid-body will be woken up if it was put to sleep because it did not move for a while.
|
|
512
|
+
*/
|
|
513
|
+
setAdditionalMass(mass, wakeUp) {
|
|
514
|
+
this.rawSet.rbSetAdditionalMass(this.handle, mass, wakeUp);
|
|
515
|
+
}
|
|
516
|
+
// #if DIM3
|
|
517
|
+
/**
|
|
518
|
+
* Sets the rigid-body's additional mass-properties.
|
|
519
|
+
*
|
|
520
|
+
* This is only the "additional" mass-properties because the total mass-properties of the rigid-body is equal to the
|
|
521
|
+
* sum of this additional mass-properties and the mass computed from the colliders (with non-zero densities) attached
|
|
522
|
+
* to this rigid-body.
|
|
523
|
+
*
|
|
524
|
+
* That total mass-properties (which include the attached colliders’ contributions) will be updated at the name
|
|
525
|
+
* physics step, or can be updated manually with `this.recomputeMassPropertiesFromColliders`.
|
|
526
|
+
*
|
|
527
|
+
* This will override any previous mass-properties set by `this.setAdditionalMass`,
|
|
528
|
+
* `this.setAdditionalMassProperties`, `RigidBodyDesc.setAdditionalMass`, or `RigidBodyDesc.setAdditionalMassProperties`
|
|
529
|
+
* for this rigid-body.
|
|
530
|
+
*
|
|
531
|
+
* If `wake_up` is true then the rigid-body will be woken up if it was put to sleep because it did not move for a while.
|
|
532
|
+
*/
|
|
533
|
+
setAdditionalMassProperties(mass, centerOfMass, principalAngularInertia, angularInertiaLocalFrame, wakeUp) {
|
|
534
|
+
let rawCom = VectorOps.intoRaw(centerOfMass);
|
|
535
|
+
let rawPrincipalInertia = VectorOps.intoRaw(principalAngularInertia);
|
|
536
|
+
let rawInertiaFrame = RotationOps.intoRaw(angularInertiaLocalFrame);
|
|
537
|
+
this.rawSet.rbSetAdditionalMassProperties(this.handle, mass, rawCom, rawPrincipalInertia, rawInertiaFrame, wakeUp);
|
|
538
|
+
rawCom.free();
|
|
539
|
+
rawPrincipalInertia.free();
|
|
540
|
+
rawInertiaFrame.free();
|
|
541
|
+
}
|
|
542
|
+
// #endif
|
|
543
|
+
/**
|
|
544
|
+
* Sets the linear damping factor applied to this rigid-body.
|
|
545
|
+
*
|
|
546
|
+
* @param factor - The damping factor to set.
|
|
547
|
+
*/
|
|
548
|
+
setAngularDamping(factor) {
|
|
549
|
+
this.rawSet.rbSetAngularDamping(this.handle, factor);
|
|
550
|
+
}
|
|
551
|
+
/**
|
|
552
|
+
* Resets to zero the user forces (but not torques) applied to this rigid-body.
|
|
553
|
+
*
|
|
554
|
+
* @param wakeUp - should the rigid-body be automatically woken-up?
|
|
555
|
+
*/
|
|
556
|
+
resetForces(wakeUp) {
|
|
557
|
+
this.rawSet.rbResetForces(this.handle, wakeUp);
|
|
558
|
+
}
|
|
559
|
+
/**
|
|
560
|
+
* Resets to zero the user torques applied to this rigid-body.
|
|
561
|
+
*
|
|
562
|
+
* @param wakeUp - should the rigid-body be automatically woken-up?
|
|
563
|
+
*/
|
|
564
|
+
resetTorques(wakeUp) {
|
|
565
|
+
this.rawSet.rbResetTorques(this.handle, wakeUp);
|
|
566
|
+
}
|
|
567
|
+
/**
|
|
568
|
+
* Adds a force at the center-of-mass of this rigid-body.
|
|
569
|
+
*
|
|
570
|
+
* @param force - the world-space force to add to the rigid-body.
|
|
571
|
+
* @param wakeUp - should the rigid-body be automatically woken-up?
|
|
572
|
+
*/
|
|
573
|
+
addForce(force, wakeUp) {
|
|
574
|
+
const rawForce = VectorOps.intoRaw(force);
|
|
575
|
+
this.rawSet.rbAddForce(this.handle, rawForce, wakeUp);
|
|
576
|
+
rawForce.free();
|
|
577
|
+
}
|
|
578
|
+
/**
|
|
579
|
+
* Applies an impulse at the center-of-mass of this rigid-body.
|
|
580
|
+
*
|
|
581
|
+
* @param impulse - the world-space impulse to apply on the rigid-body.
|
|
582
|
+
* @param wakeUp - should the rigid-body be automatically woken-up?
|
|
583
|
+
*/
|
|
584
|
+
applyImpulse(impulse, wakeUp) {
|
|
585
|
+
const rawImpulse = VectorOps.intoRaw(impulse);
|
|
586
|
+
this.rawSet.rbApplyImpulse(this.handle, rawImpulse, wakeUp);
|
|
587
|
+
rawImpulse.free();
|
|
588
|
+
}
|
|
589
|
+
// #if DIM3
|
|
590
|
+
/**
|
|
591
|
+
* Adds a torque at the center-of-mass of this rigid-body.
|
|
592
|
+
*
|
|
593
|
+
* @param torque - the world-space torque to add to the rigid-body.
|
|
594
|
+
* @param wakeUp - should the rigid-body be automatically woken-up?
|
|
595
|
+
*/
|
|
596
|
+
addTorque(torque, wakeUp) {
|
|
597
|
+
const rawTorque = VectorOps.intoRaw(torque);
|
|
598
|
+
this.rawSet.rbAddTorque(this.handle, rawTorque, wakeUp);
|
|
599
|
+
rawTorque.free();
|
|
600
|
+
}
|
|
601
|
+
// #endif
|
|
602
|
+
// #if DIM3
|
|
603
|
+
/**
|
|
604
|
+
* Applies an impulsive torque at the center-of-mass of this rigid-body.
|
|
605
|
+
*
|
|
606
|
+
* @param torqueImpulse - the world-space torque impulse to apply on the rigid-body.
|
|
607
|
+
* @param wakeUp - should the rigid-body be automatically woken-up?
|
|
608
|
+
*/
|
|
609
|
+
applyTorqueImpulse(torqueImpulse, wakeUp) {
|
|
610
|
+
const rawTorqueImpulse = VectorOps.intoRaw(torqueImpulse);
|
|
611
|
+
this.rawSet.rbApplyTorqueImpulse(this.handle, rawTorqueImpulse, wakeUp);
|
|
612
|
+
rawTorqueImpulse.free();
|
|
613
|
+
}
|
|
614
|
+
// #endif
|
|
615
|
+
/**
|
|
616
|
+
* Adds a force at the given world-space point of this rigid-body.
|
|
617
|
+
*
|
|
618
|
+
* @param force - the world-space force to add to the rigid-body.
|
|
619
|
+
* @param point - the world-space point where the impulse is to be applied on the rigid-body.
|
|
620
|
+
* @param wakeUp - should the rigid-body be automatically woken-up?
|
|
621
|
+
*/
|
|
622
|
+
addForceAtPoint(force, point, wakeUp) {
|
|
623
|
+
const rawForce = VectorOps.intoRaw(force);
|
|
624
|
+
const rawPoint = VectorOps.intoRaw(point);
|
|
625
|
+
this.rawSet.rbAddForceAtPoint(this.handle, rawForce, rawPoint, wakeUp);
|
|
626
|
+
rawForce.free();
|
|
627
|
+
rawPoint.free();
|
|
628
|
+
}
|
|
629
|
+
/**
|
|
630
|
+
* Applies an impulse at the given world-space point of this rigid-body.
|
|
631
|
+
*
|
|
632
|
+
* @param impulse - the world-space impulse to apply on the rigid-body.
|
|
633
|
+
* @param point - the world-space point where the impulse is to be applied on the rigid-body.
|
|
634
|
+
* @param wakeUp - should the rigid-body be automatically woken-up?
|
|
635
|
+
*/
|
|
636
|
+
applyImpulseAtPoint(impulse, point, wakeUp) {
|
|
637
|
+
const rawImpulse = VectorOps.intoRaw(impulse);
|
|
638
|
+
const rawPoint = VectorOps.intoRaw(point);
|
|
639
|
+
this.rawSet.rbApplyImpulseAtPoint(this.handle, rawImpulse, rawPoint, wakeUp);
|
|
640
|
+
rawImpulse.free();
|
|
641
|
+
rawPoint.free();
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
export class RigidBodyDesc {
|
|
645
|
+
constructor(status) {
|
|
646
|
+
this.enabled = true;
|
|
647
|
+
this.status = status;
|
|
648
|
+
this.translation = VectorOps.zeros();
|
|
649
|
+
this.rotation = RotationOps.identity();
|
|
650
|
+
this.gravityScale = 1.0;
|
|
651
|
+
this.linvel = VectorOps.zeros();
|
|
652
|
+
this.mass = 0.0;
|
|
653
|
+
this.massOnly = false;
|
|
654
|
+
this.centerOfMass = VectorOps.zeros();
|
|
655
|
+
this.translationsEnabledX = true;
|
|
656
|
+
this.translationsEnabledY = true;
|
|
657
|
+
// #if DIM3
|
|
658
|
+
this.angvel = VectorOps.zeros();
|
|
659
|
+
this.principalAngularInertia = VectorOps.zeros();
|
|
660
|
+
this.angularInertiaLocalFrame = RotationOps.identity();
|
|
661
|
+
this.translationsEnabledZ = true;
|
|
662
|
+
this.rotationsEnabledX = true;
|
|
663
|
+
this.rotationsEnabledY = true;
|
|
664
|
+
this.rotationsEnabledZ = true;
|
|
665
|
+
// #endif
|
|
666
|
+
this.linearDamping = 0.0;
|
|
667
|
+
this.angularDamping = 0.0;
|
|
668
|
+
this.canSleep = true;
|
|
669
|
+
this.sleeping = false;
|
|
670
|
+
this.ccdEnabled = false;
|
|
671
|
+
this.dominanceGroup = 0;
|
|
672
|
+
}
|
|
673
|
+
/**
|
|
674
|
+
* A rigid-body descriptor used to build a dynamic rigid-body.
|
|
675
|
+
*/
|
|
676
|
+
static dynamic() {
|
|
677
|
+
return new RigidBodyDesc(RigidBodyType.Dynamic);
|
|
678
|
+
}
|
|
679
|
+
/**
|
|
680
|
+
* A rigid-body descriptor used to build a position-based kinematic rigid-body.
|
|
681
|
+
*/
|
|
682
|
+
static kinematicPositionBased() {
|
|
683
|
+
return new RigidBodyDesc(RigidBodyType.KinematicPositionBased);
|
|
684
|
+
}
|
|
685
|
+
/**
|
|
686
|
+
* A rigid-body descriptor used to build a velocity-based kinematic rigid-body.
|
|
687
|
+
*/
|
|
688
|
+
static kinematicVelocityBased() {
|
|
689
|
+
return new RigidBodyDesc(RigidBodyType.KinematicVelocityBased);
|
|
690
|
+
}
|
|
691
|
+
/**
|
|
692
|
+
* A rigid-body descriptor used to build a fixed rigid-body.
|
|
693
|
+
*/
|
|
694
|
+
static fixed() {
|
|
695
|
+
return new RigidBodyDesc(RigidBodyType.Fixed);
|
|
696
|
+
}
|
|
697
|
+
/**
|
|
698
|
+
* A rigid-body descriptor used to build a dynamic rigid-body.
|
|
699
|
+
*
|
|
700
|
+
* @deprecated The method has been renamed to `.dynamic()`.
|
|
701
|
+
*/
|
|
702
|
+
static newDynamic() {
|
|
703
|
+
return new RigidBodyDesc(RigidBodyType.Dynamic);
|
|
704
|
+
}
|
|
705
|
+
/**
|
|
706
|
+
* A rigid-body descriptor used to build a position-based kinematic rigid-body.
|
|
707
|
+
*
|
|
708
|
+
* @deprecated The method has been renamed to `.kinematicPositionBased()`.
|
|
709
|
+
*/
|
|
710
|
+
static newKinematicPositionBased() {
|
|
711
|
+
return new RigidBodyDesc(RigidBodyType.KinematicPositionBased);
|
|
712
|
+
}
|
|
713
|
+
/**
|
|
714
|
+
* A rigid-body descriptor used to build a velocity-based kinematic rigid-body.
|
|
715
|
+
*
|
|
716
|
+
* @deprecated The method has been renamed to `.kinematicVelocityBased()`.
|
|
717
|
+
*/
|
|
718
|
+
static newKinematicVelocityBased() {
|
|
719
|
+
return new RigidBodyDesc(RigidBodyType.KinematicVelocityBased);
|
|
720
|
+
}
|
|
721
|
+
/**
|
|
722
|
+
* A rigid-body descriptor used to build a fixed rigid-body.
|
|
723
|
+
*
|
|
724
|
+
* @deprecated The method has been renamed to `.fixed()`.
|
|
725
|
+
*/
|
|
726
|
+
static newStatic() {
|
|
727
|
+
return new RigidBodyDesc(RigidBodyType.Fixed);
|
|
728
|
+
}
|
|
729
|
+
setDominanceGroup(group) {
|
|
730
|
+
this.dominanceGroup = group;
|
|
731
|
+
return this;
|
|
732
|
+
}
|
|
733
|
+
/**
|
|
734
|
+
* Sets whether the created rigid-body will be enabled or disabled.
|
|
735
|
+
* @param enabled − If set to `false` the rigid-body will be disabled at creation.
|
|
736
|
+
*/
|
|
737
|
+
setEnabled(enabled) {
|
|
738
|
+
this.enabled = enabled;
|
|
739
|
+
return this;
|
|
740
|
+
}
|
|
741
|
+
// #if DIM3
|
|
742
|
+
/**
|
|
743
|
+
* Sets the initial translation of the rigid-body to create.
|
|
744
|
+
*
|
|
745
|
+
* @param tra - The translation to set.
|
|
746
|
+
*/
|
|
747
|
+
setTranslation(x, y, z) {
|
|
748
|
+
if (typeof x != "number" ||
|
|
749
|
+
typeof y != "number" ||
|
|
750
|
+
typeof z != "number")
|
|
751
|
+
throw TypeError("The translation components must be numbers.");
|
|
752
|
+
this.translation = { x: x, y: y, z: z };
|
|
753
|
+
return this;
|
|
754
|
+
}
|
|
755
|
+
// #endif
|
|
756
|
+
/**
|
|
757
|
+
* Sets the initial rotation of the rigid-body to create.
|
|
758
|
+
*
|
|
759
|
+
* @param rot - The rotation to set.
|
|
760
|
+
*/
|
|
761
|
+
setRotation(rot) {
|
|
762
|
+
// #if DIM3
|
|
763
|
+
RotationOps.copy(this.rotation, rot);
|
|
764
|
+
// #endif
|
|
765
|
+
return this;
|
|
766
|
+
}
|
|
767
|
+
/**
|
|
768
|
+
* Sets the scale factor applied to the gravity affecting
|
|
769
|
+
* the rigid-body being built.
|
|
770
|
+
*
|
|
771
|
+
* @param scale - The scale factor. Set this to `0.0` if the rigid-body
|
|
772
|
+
* needs to ignore gravity.
|
|
773
|
+
*/
|
|
774
|
+
setGravityScale(scale) {
|
|
775
|
+
this.gravityScale = scale;
|
|
776
|
+
return this;
|
|
777
|
+
}
|
|
778
|
+
/**
|
|
779
|
+
* Sets the initial mass of the rigid-body being built, before adding colliders' contributions.
|
|
780
|
+
*
|
|
781
|
+
* @param mass − The initial mass of the rigid-body to create.
|
|
782
|
+
*/
|
|
783
|
+
setAdditionalMass(mass) {
|
|
784
|
+
this.mass = mass;
|
|
785
|
+
this.massOnly = true;
|
|
786
|
+
return this;
|
|
787
|
+
}
|
|
788
|
+
// #if DIM3
|
|
789
|
+
/**
|
|
790
|
+
* Sets the initial linear velocity of the rigid-body to create.
|
|
791
|
+
*
|
|
792
|
+
* @param x - The linear velocity to set along the `x` axis.
|
|
793
|
+
* @param y - The linear velocity to set along the `y` axis.
|
|
794
|
+
* @param z - The linear velocity to set along the `z` axis.
|
|
795
|
+
*/
|
|
796
|
+
setLinvel(x, y, z) {
|
|
797
|
+
if (typeof x != "number" ||
|
|
798
|
+
typeof y != "number" ||
|
|
799
|
+
typeof z != "number")
|
|
800
|
+
throw TypeError("The linvel components must be numbers.");
|
|
801
|
+
this.linvel = { x: x, y: y, z: z };
|
|
802
|
+
return this;
|
|
803
|
+
}
|
|
804
|
+
/**
|
|
805
|
+
* Sets the initial angular velocity of the rigid-body to create.
|
|
806
|
+
*
|
|
807
|
+
* @param vel - The angular velocity to set.
|
|
808
|
+
*/
|
|
809
|
+
setAngvel(vel) {
|
|
810
|
+
VectorOps.copy(this.angvel, vel);
|
|
811
|
+
return this;
|
|
812
|
+
}
|
|
813
|
+
/**
|
|
814
|
+
* Sets the mass properties of the rigid-body being built.
|
|
815
|
+
*
|
|
816
|
+
* Note that the final mass properties of the rigid-bodies depends
|
|
817
|
+
* on the initial mass-properties of the rigid-body (set by this method)
|
|
818
|
+
* to which is added the contributions of all the colliders with non-zero density
|
|
819
|
+
* attached to this rigid-body.
|
|
820
|
+
*
|
|
821
|
+
* Therefore, if you want your provided mass properties to be the final
|
|
822
|
+
* mass properties of your rigid-body, don't attach colliders to it, or
|
|
823
|
+
* only attach colliders with densities equal to zero.
|
|
824
|
+
*
|
|
825
|
+
* @param mass − The initial mass of the rigid-body to create.
|
|
826
|
+
* @param centerOfMass − The initial center-of-mass of the rigid-body to create.
|
|
827
|
+
* @param principalAngularInertia − The initial principal angular inertia of the rigid-body to create.
|
|
828
|
+
* These are the eigenvalues of the angular inertia matrix.
|
|
829
|
+
* @param angularInertiaLocalFrame − The initial local angular inertia frame of the rigid-body to create.
|
|
830
|
+
* These are the eigenvectors of the angular inertia matrix.
|
|
831
|
+
*/
|
|
832
|
+
setAdditionalMassProperties(mass, centerOfMass, principalAngularInertia, angularInertiaLocalFrame) {
|
|
833
|
+
this.mass = mass;
|
|
834
|
+
VectorOps.copy(this.centerOfMass, centerOfMass);
|
|
835
|
+
VectorOps.copy(this.principalAngularInertia, principalAngularInertia);
|
|
836
|
+
RotationOps.copy(this.angularInertiaLocalFrame, angularInertiaLocalFrame);
|
|
837
|
+
this.massOnly = false;
|
|
838
|
+
return this;
|
|
839
|
+
}
|
|
840
|
+
/**
|
|
841
|
+
* Allow translation of this rigid-body only along specific axes.
|
|
842
|
+
* @param translationsEnabledX - Are translations along the X axis enabled?
|
|
843
|
+
* @param translationsEnabledY - Are translations along the y axis enabled?
|
|
844
|
+
* @param translationsEnabledZ - Are translations along the Z axis enabled?
|
|
845
|
+
*/
|
|
846
|
+
enabledTranslations(translationsEnabledX, translationsEnabledY, translationsEnabledZ) {
|
|
847
|
+
this.translationsEnabledX = translationsEnabledX;
|
|
848
|
+
this.translationsEnabledY = translationsEnabledY;
|
|
849
|
+
this.translationsEnabledZ = translationsEnabledZ;
|
|
850
|
+
return this;
|
|
851
|
+
}
|
|
852
|
+
/**
|
|
853
|
+
* Allow translation of this rigid-body only along specific axes.
|
|
854
|
+
* @param translationsEnabledX - Are translations along the X axis enabled?
|
|
855
|
+
* @param translationsEnabledY - Are translations along the y axis enabled?
|
|
856
|
+
* @param translationsEnabledZ - Are translations along the Z axis enabled?
|
|
857
|
+
* @deprecated use `this.enabledTranslations` with the same arguments instead.
|
|
858
|
+
*/
|
|
859
|
+
restrictTranslations(translationsEnabledX, translationsEnabledY, translationsEnabledZ) {
|
|
860
|
+
return this.enabledTranslations(translationsEnabledX, translationsEnabledY, translationsEnabledZ);
|
|
861
|
+
}
|
|
862
|
+
/**
|
|
863
|
+
* Locks all translations that would have resulted from forces on
|
|
864
|
+
* the created rigid-body.
|
|
865
|
+
*/
|
|
866
|
+
lockTranslations() {
|
|
867
|
+
return this.enabledTranslations(false, false, false);
|
|
868
|
+
}
|
|
869
|
+
/**
|
|
870
|
+
* Allow rotation of this rigid-body only along specific axes.
|
|
871
|
+
* @param rotationsEnabledX - Are rotations along the X axis enabled?
|
|
872
|
+
* @param rotationsEnabledY - Are rotations along the y axis enabled?
|
|
873
|
+
* @param rotationsEnabledZ - Are rotations along the Z axis enabled?
|
|
874
|
+
*/
|
|
875
|
+
enabledRotations(rotationsEnabledX, rotationsEnabledY, rotationsEnabledZ) {
|
|
876
|
+
this.rotationsEnabledX = rotationsEnabledX;
|
|
877
|
+
this.rotationsEnabledY = rotationsEnabledY;
|
|
878
|
+
this.rotationsEnabledZ = rotationsEnabledZ;
|
|
879
|
+
return this;
|
|
880
|
+
}
|
|
881
|
+
/**
|
|
882
|
+
* Allow rotation of this rigid-body only along specific axes.
|
|
883
|
+
* @param rotationsEnabledX - Are rotations along the X axis enabled?
|
|
884
|
+
* @param rotationsEnabledY - Are rotations along the y axis enabled?
|
|
885
|
+
* @param rotationsEnabledZ - Are rotations along the Z axis enabled?
|
|
886
|
+
* @deprecated use `this.enabledRotations` with the same arguments instead.
|
|
887
|
+
*/
|
|
888
|
+
restrictRotations(rotationsEnabledX, rotationsEnabledY, rotationsEnabledZ) {
|
|
889
|
+
return this.enabledRotations(rotationsEnabledX, rotationsEnabledY, rotationsEnabledZ);
|
|
890
|
+
}
|
|
891
|
+
/**
|
|
892
|
+
* Locks all rotations that would have resulted from forces on
|
|
893
|
+
* the created rigid-body.
|
|
894
|
+
*/
|
|
895
|
+
lockRotations() {
|
|
896
|
+
return this.restrictRotations(false, false, false);
|
|
897
|
+
}
|
|
898
|
+
// #endif
|
|
899
|
+
/**
|
|
900
|
+
* Sets the linear damping of the rigid-body to create.
|
|
901
|
+
*
|
|
902
|
+
* This will progressively slowdown the translational movement of the rigid-body.
|
|
903
|
+
*
|
|
904
|
+
* @param damping - The angular damping coefficient. Should be >= 0. The higher this
|
|
905
|
+
* value is, the stronger the translational slowdown will be.
|
|
906
|
+
*/
|
|
907
|
+
setLinearDamping(damping) {
|
|
908
|
+
this.linearDamping = damping;
|
|
909
|
+
return this;
|
|
910
|
+
}
|
|
911
|
+
/**
|
|
912
|
+
* Sets the angular damping of the rigid-body to create.
|
|
913
|
+
*
|
|
914
|
+
* This will progressively slowdown the rotational movement of the rigid-body.
|
|
915
|
+
*
|
|
916
|
+
* @param damping - The angular damping coefficient. Should be >= 0. The higher this
|
|
917
|
+
* value is, the stronger the rotational slowdown will be.
|
|
918
|
+
*/
|
|
919
|
+
setAngularDamping(damping) {
|
|
920
|
+
this.angularDamping = damping;
|
|
921
|
+
return this;
|
|
922
|
+
}
|
|
923
|
+
/**
|
|
924
|
+
* Sets whether or not the rigid-body to create can sleep.
|
|
925
|
+
*
|
|
926
|
+
* @param can - true if the rigid-body can sleep, false if it can't.
|
|
927
|
+
*/
|
|
928
|
+
setCanSleep(can) {
|
|
929
|
+
this.canSleep = can;
|
|
930
|
+
return this;
|
|
931
|
+
}
|
|
932
|
+
/**
|
|
933
|
+
* Sets whether or not the rigid-body is to be created asleep.
|
|
934
|
+
*
|
|
935
|
+
* @param can - true if the rigid-body should be in sleep, default false.
|
|
936
|
+
*/
|
|
937
|
+
setSleeping(sleeping) {
|
|
938
|
+
this.sleeping = sleeping;
|
|
939
|
+
return this;
|
|
940
|
+
}
|
|
941
|
+
/**
|
|
942
|
+
* Sets whether Continuous Collision Detection (CCD) is enabled for this rigid-body.
|
|
943
|
+
*
|
|
944
|
+
* @param enabled - true if the rigid-body has CCD enabled.
|
|
945
|
+
*/
|
|
946
|
+
setCcdEnabled(enabled) {
|
|
947
|
+
this.ccdEnabled = enabled;
|
|
948
|
+
return this;
|
|
949
|
+
}
|
|
950
|
+
/**
|
|
951
|
+
* Sets the user-defined object of this rigid-body.
|
|
952
|
+
*
|
|
953
|
+
* @param userData - The user-defined object to set.
|
|
954
|
+
*/
|
|
955
|
+
setUserData(data) {
|
|
956
|
+
this.userData = data;
|
|
957
|
+
return this;
|
|
958
|
+
}
|
|
959
|
+
}
|
|
960
|
+
//# sourceMappingURL=rigid_body.js.map
|