-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.d.ts
280 lines (216 loc) · 6.24 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
declare module "bullet-raub" {
type TArr3 = Readonly<[number, number, number]>;
type TObj3 = Readonly<{ x: number; y: number; z: number }>;
type TArr4 = Readonly<[number, number, number, number]>;
type TObj4 = Readonly<{ x: number; y: number; z: number, w: number }>;
type TVec3Either = TArr3 | TObj3;
type TQuatEither = TArr4 | TObj4;
type TVec3Both = TArr3 & TObj3;
type TQuatBoth = TArr4 & TObj4;
type TTraceHit = Readonly<{
hit: boolean;
body: Body;
pos: TVec3Both;
norm: TVec3Both;
}>;
type TTraceHits = ReadonlyArray<TTraceHit>;
type TEvent = {
type: string;
[key: string]: unknown;
};
type TEventCb<T extends TEvent> = (event: T) => (void | boolean);
type EventEmitter = import('node:events').EventEmitter;
type TPropsCommon = EventEmitter & {
/**
* True if `destroy` was called.
*/
readonly isDestroyed: boolean;
/** Stringification helper. */
toString(): string;
/**
* Delete the object and free the resources.
*
* After calling this, the object is **no longer valid** and should not be used from JS.
* Also emits the "destroy" event.
*/
destroy(): void;
};
type TBodyType = 'ball' | 'roll' | 'pill' | 'plane' | 'box'; // + todo: map mesh
type TPropsBody = {
/**
* Body shape type. Default is "box".
*
* Can be changed any time, but is slow. Reinterprets all other props as possible.
*/
type: TBodyType;
/** Position in 3D. Default is `[0, 0, 0]`. */
pos: TVec3Either;
/** Rotation quaternion. Default is `[0, 0, 0, 1]`. */
rot: TQuatEither;
/** Linear velocity. Default is `[0, 0, 0]`. */
vell: TVec3Either;
/** Angular velocity. Default is `[0, 0, 0]`. */
vela: TVec3Either;
/** Bounding box size (or "scale"). Default is `[1, 1, 1]`. */
size: TVec3Either;
/** TODO */
// map: unknown;
/** TODO */
// mesh: unknown;
/** Body mass in KG. Zero is static body. Default is 0 (static). */
mass: number;
/**
* Restitution - bounciness. Default is 0 (no bounce).
*
* @see https://en.wikipedia.org/wiki/Coefficient_of_restitution
*/
rest: number;
/**
* Linear damping. Default is `0.1`.
*
* How quickly the body loses linear velocity due to "air friction".
*/
dampl: number;
/**
* Angular damping. Default is `0.1`.
*
* How quickly the body loses angular velocity due to "air friction".
*/
dampa: number;
/**
* Linear impulse factor. Default is `[1, 1, 1]`.
*
* It can be used to constrain object motion to certain world-frame axes.
* For example: to constrain an object to only move in the XZ plane,
* you would set the Y-component of `factl` to 0, and the XZ components to 1.
*/
factl: number;
/**
* Angular impulse factor. Default is `[1, 1, 1]`.
*
* It can be used to constrain object rotation to certain world-frame axes.
* For example: to constrain an object to only rotate around the Y axis,
* you would set the XZ-components of `facta` to 0, and the Y-component to 1.
*/
facta: number;
/** Surface friction. Default is `0.5`. */
frict: number;
/**
* Allow this body to "sleep". Default is `true`.
*
* Usually should be `true` - this is an optimization for inactive bodies.
*/
sleepy: boolean;
};
export type TOptsBody = (
Readonly<Partial<TPropsBody>> &
Readonly<{ scene: TSceneInstance }>
);
type TBodyInstance = TPropsCommon & TPropsBody;
interface TNewableBody {
new(opts?: TOptsBody): TBodyInstance;
}
/**
* Body
*
* Creates `btRigidBody` and its related components.
*/
export const Body: TNewableBody;
type TPropsJoint = {
/** First connected body. */
a: TBodyInstance | null;
/** Second connected body. */
b: TBodyInstance | null;
/** Is connection broken. */
broken: boolean;
/** Attachment position on body A. */
posa: TVec3Either;
/** Attachment position on body B. */
posb: TVec3Either;
/** Attachment rotation (Euler) on body A. */
rota: TVec3Either;
/** Attachment rotation (Euler) on body B. */
rotb: TVec3Either;
/** Min linear distance between A and B. */
minl: TVec3Either;
/** Max linear distance between A and B. */
maxl: TVec3Either;
/** Min angular distance between A and B. */
mina: TVec3Either;
/** Max angular distance between A and B. */
maxa: TVec3Either;
/** Maximum allowed impulse before breaking the connection. */
maximp: TVec3Either;
/** Linear damping. */
dampl: TVec3Either;
/** Angular damping. */
dampa: TVec3Either;
/** Linear stiffness. */
stifl: TVec3Either;
/** Angular stiffness. */
stifa: TVec3Either;
/** Linear spring force. */
springl: TVec3Either;
/** Angular spring force. */
springa: TVec3Either;
/**
* Linear motor enabled axes.
*
* Values `> 0` mean "enabled".
*/
motorl: TVec3Either;
/**
* Angular motor enabled axes.
*
* Values `> 0` mean "enabled".
*/
motora: TVec3Either;
/** Linear motor force. */
motorlf: TVec3Either;
/** Angular motor force. */
motoraf: TVec3Either;
/** Linear motor velocity. */
motorlv: TVec3Either;
/** Angular motor velocity. */
motorav: TVec3Either;
};
export type TOptsJoint = Readonly<Partial<TPropsJoint>>;
type TJointInstance = TPropsCommon & TPropsJoint;
interface TNewableJoint {
new(opts?: TOptsJoint): TJointInstance;
}
/**
* Joint
*
* Creates `btGeneric6DofSpringConstraint` and its related components.
*/
export const Joint: TNewableJoint;
export type TPropsScene = {
/**
* Scene gravity. Default is `[0, -10, 0]`.
*/
gravity: TVec3Either;
};
export type TOptsScene = Readonly<Partial<TPropsScene>>;
type TSceneInstance = TPropsCommon & TPropsScene & {
/**
* Make a simulation step.
*
* If `deltaTime` is not defined, the realtime delta will be used.
*/
update(deltaTime?: number): void;
/** Detect the **first** hit on a ray trace. */
hit(from: TVec3Either, to: TVec3Either): TTraceHit;
/** Detect **all** hits on a ray trace. */
trace(from: TVec3Either, to: TVec3Either): TTraceHits;
};
interface TNewableScene {
new(opts?: TOptsScene): TSceneInstance;
}
/**
* Scene
*
* Creates a `btDiscreteDynamicsWorld` and its related components.
*/
export const Scene: TNewableScene;
}