cannon-es.d.ts 71 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603
  1. declare module "utils/EventTarget" {
  2. export class EventTarget {
  3. private _listeners;
  4. addEventListener(type: string, listener: Function): EventTarget;
  5. hasEventListener(type: string, listener: Function): boolean;
  6. hasAnyEventListener(type: string): boolean;
  7. removeEventListener(type: string, listener: Function): EventTarget;
  8. dispatchEvent(event: any): EventTarget;
  9. }
  10. }
  11. declare module "math/Quaternion" {
  12. import { Vec3 } from "math/Vec3";
  13. export class Quaternion {
  14. x: number;
  15. y: number;
  16. z: number;
  17. w: number;
  18. constructor(x?: number, y?: number, z?: number, w?: number);
  19. set(x: number, y: number, z: number, w: number): Quaternion;
  20. toString(): string;
  21. toArray(): [number, number, number, number];
  22. setFromAxisAngle(vector: Vec3, angle: number): Quaternion;
  23. toAxisAngle(targetAxis?: Vec3): [Vec3, number];
  24. setFromVectors(u: Vec3, v: Vec3): Quaternion;
  25. mult(quat: Quaternion, target?: Quaternion): Quaternion;
  26. inverse(target?: Quaternion): Quaternion;
  27. conjugate(target?: Quaternion): Quaternion;
  28. normalize(): Quaternion;
  29. normalizeFast(): Quaternion;
  30. vmult(v: Vec3, target?: Vec3): Vec3;
  31. copy(quat: Quaternion): Quaternion;
  32. toEuler(target: Vec3, order?: string): void;
  33. setFromEuler(x: number, y: number, z: number, order?: string): Quaternion;
  34. clone(): Quaternion;
  35. slerp(toQuat: Quaternion, t: number, target?: Quaternion): Quaternion;
  36. integrate(angularVelocity: Vec3, dt: number, angularFactor: Vec3, target?: Quaternion): Quaternion;
  37. }
  38. }
  39. declare module "math/Mat3" {
  40. import { Vec3 } from "math/Vec3";
  41. import type { Quaternion } from "math/Quaternion";
  42. export class Mat3 {
  43. elements: number[];
  44. constructor(elements?: number[]);
  45. identity(): void;
  46. setZero(): void;
  47. setTrace(vector: Vec3): void;
  48. getTrace(target?: Vec3): Vec3;
  49. vmult(v: Vec3, target?: Vec3): Vec3;
  50. smult(s: number): void;
  51. mmult(matrix: Mat3, target?: Mat3): Mat3;
  52. scale(vector: Vec3, target?: Mat3): Mat3;
  53. solve(b: Vec3, target?: Vec3): Vec3;
  54. e(row: number, column: number): number;
  55. e(row: number, column: number, value: number): void;
  56. copy(matrix: Mat3): Mat3;
  57. toString(): string;
  58. reverse(target?: Mat3): Mat3;
  59. setRotationFromQuaternion(q: Quaternion): Mat3;
  60. transpose(target?: Mat3): Mat3;
  61. }
  62. }
  63. declare module "math/Vec3" {
  64. import { Mat3 } from "math/Mat3";
  65. export class Vec3 {
  66. x: number;
  67. y: number;
  68. z: number;
  69. static ZERO: Vec3;
  70. static UNIT_X: Vec3;
  71. static UNIT_Y: Vec3;
  72. static UNIT_Z: Vec3;
  73. constructor(x?: number, y?: number, z?: number);
  74. cross(vector: Vec3, target?: Vec3): Vec3;
  75. set(x: number, y: number, z: number): Vec3;
  76. setZero(): void;
  77. vadd(vector: Vec3): Vec3;
  78. vadd(vector: Vec3, target: Vec3): void;
  79. vsub(vector: Vec3): Vec3;
  80. vsub(vector: Vec3, target: Vec3): void;
  81. crossmat(): Mat3;
  82. normalize(): number;
  83. unit(target?: Vec3): Vec3;
  84. length(): number;
  85. lengthSquared(): number;
  86. distanceTo(p: Vec3): number;
  87. distanceSquared(p: Vec3): number;
  88. scale(scalar: number, target?: Vec3): Vec3;
  89. vmul(vector: Vec3, target?: Vec3): Vec3;
  90. addScaledVector(scalar: number, vector: Vec3, target?: Vec3): Vec3;
  91. dot(vector: Vec3): number;
  92. isZero(): boolean;
  93. negate(target?: Vec3): Vec3;
  94. tangents(t1: Vec3, t2: Vec3): void;
  95. toString(): string;
  96. toArray(): [number, number, number];
  97. copy(vector: Vec3): Vec3;
  98. lerp(vector: Vec3, t: number, target: Vec3): void;
  99. almostEquals(vector: Vec3, precision?: number): boolean;
  100. almostZero(precision?: number): boolean;
  101. isAntiparallelTo(vector: Vec3, precision?: number): boolean;
  102. clone(): Vec3;
  103. }
  104. }
  105. declare module "math/Transform" {
  106. import { Vec3 } from "math/Vec3";
  107. import { Quaternion } from "math/Quaternion";
  108. export type TransformOptions = ConstructorParameters<typeof Transform>[0];
  109. export class Transform {
  110. position: Vec3;
  111. quaternion: Quaternion;
  112. constructor(options?: {
  113. position?: Vec3;
  114. quaternion?: Quaternion;
  115. });
  116. pointToLocal(worldPoint: Vec3, result?: Vec3): Vec3;
  117. pointToWorld(localPoint: Vec3, result?: Vec3): Vec3;
  118. vectorToWorldFrame(localVector: Vec3, result?: Vec3): Vec3;
  119. static pointToLocalFrame(position: Vec3, quaternion: Quaternion, worldPoint: Vec3, result?: Vec3): Vec3;
  120. static pointToWorldFrame(position: Vec3, quaternion: Quaternion, localPoint: Vec3, result?: Vec3): Vec3;
  121. static vectorToWorldFrame(quaternion: Quaternion, localVector: Vec3, result?: Vec3): Vec3;
  122. static vectorToLocalFrame(position: Vec3, quaternion: Quaternion, worldVector: Vec3, result?: Vec3): Vec3;
  123. }
  124. }
  125. declare module "material/Material" {
  126. export type MaterialOptions = ConstructorParameters<typeof Material>[0];
  127. export class Material {
  128. name: string;
  129. id: number;
  130. friction: number;
  131. restitution: number;
  132. static idCounter: number;
  133. constructor(options?: {
  134. friction?: number;
  135. restitution?: number;
  136. } | string);
  137. }
  138. }
  139. declare module "shapes/Shape" {
  140. import type { Vec3 } from "math/Vec3";
  141. import type { Quaternion } from "math/Quaternion";
  142. import type { Body } from "objects/Body";
  143. import type { Material } from "material/Material";
  144. export const SHAPE_TYPES: {
  145. readonly SPHERE: 1;
  146. readonly PLANE: 2;
  147. readonly BOX: 4;
  148. readonly COMPOUND: 8;
  149. readonly CONVEXPOLYHEDRON: 16;
  150. readonly HEIGHTFIELD: 32;
  151. readonly PARTICLE: 64;
  152. readonly CYLINDER: 128;
  153. readonly TRIMESH: 256;
  154. };
  155. export type ShapeType = typeof SHAPE_TYPES[keyof typeof SHAPE_TYPES];
  156. export type ShapeOptions = ConstructorParameters<typeof Shape>[0];
  157. export class Shape {
  158. id: number;
  159. type: ShapeType | 0;
  160. boundingSphereRadius: number;
  161. collisionResponse: boolean;
  162. collisionFilterGroup: number;
  163. collisionFilterMask: number;
  164. material: Material | null;
  165. body: Body | null;
  166. static idCounter: number;
  167. static types: {
  168. readonly SPHERE: 1;
  169. readonly PLANE: 2;
  170. readonly BOX: 4;
  171. readonly COMPOUND: 8;
  172. readonly CONVEXPOLYHEDRON: 16;
  173. readonly HEIGHTFIELD: 32;
  174. readonly PARTICLE: 64;
  175. readonly CYLINDER: 128;
  176. readonly TRIMESH: 256;
  177. };
  178. constructor(options?: {
  179. type?: ShapeType;
  180. collisionResponse?: boolean;
  181. collisionFilterGroup?: number;
  182. collisionFilterMask?: number;
  183. material?: Material;
  184. });
  185. updateBoundingSphereRadius(): void;
  186. volume(): number;
  187. calculateLocalInertia(mass: number, target: Vec3): void;
  188. calculateWorldAABB(pos: Vec3, quat: Quaternion, min: Vec3, max: Vec3): void;
  189. }
  190. }
  191. declare module "collision/RaycastResult" {
  192. import { Vec3 } from "math/Vec3";
  193. import type { Body } from "objects/Body";
  194. import type { Shape } from "shapes/Shape";
  195. export class RaycastResult {
  196. rayFromWorld: Vec3;
  197. rayToWorld: Vec3;
  198. hitNormalWorld: Vec3;
  199. hitPointWorld: Vec3;
  200. hasHit: boolean;
  201. shape: Shape | null;
  202. body: Body | null;
  203. hitFaceIndex: number;
  204. distance: number;
  205. shouldStop: boolean;
  206. constructor();
  207. reset(): void;
  208. abort(): void;
  209. set(rayFromWorld: Vec3, rayToWorld: Vec3, hitNormalWorld: Vec3, hitPointWorld: Vec3, shape: Shape, body: Body, distance: number): void;
  210. }
  211. }
  212. declare module "shapes/Sphere" {
  213. import { Shape } from "shapes/Shape";
  214. import { Vec3 } from "math/Vec3";
  215. import type { Quaternion } from "math/Quaternion";
  216. export class Sphere extends Shape {
  217. radius: number;
  218. constructor(radius: number);
  219. calculateLocalInertia(mass: number, target?: Vec3): Vec3;
  220. volume(): number;
  221. updateBoundingSphereRadius(): void;
  222. calculateWorldAABB(pos: Vec3, quat: Quaternion, min: Vec3, max: Vec3): void;
  223. }
  224. }
  225. declare module "shapes/ConvexPolyhedron" {
  226. import { Shape } from "shapes/Shape";
  227. import { Vec3 } from "math/Vec3";
  228. import type { Quaternion } from "math/Quaternion";
  229. export type ConvexPolyhedronContactPoint = {
  230. point: Vec3;
  231. normal: Vec3;
  232. depth: number;
  233. };
  234. export class ConvexPolyhedron extends Shape {
  235. vertices: Vec3[];
  236. faces: number[][];
  237. faceNormals: Vec3[];
  238. worldVertices: Vec3[];
  239. worldVerticesNeedsUpdate: boolean;
  240. worldFaceNormals: Vec3[];
  241. worldFaceNormalsNeedsUpdate: boolean;
  242. uniqueAxes: Vec3[] | null;
  243. uniqueEdges: Vec3[];
  244. constructor(props?: {
  245. vertices?: Vec3[];
  246. faces?: number[][];
  247. normals?: Vec3[];
  248. axes?: Vec3[];
  249. boundingSphereRadius?: number;
  250. });
  251. computeEdges(): void;
  252. computeNormals(): void;
  253. getFaceNormal(i: number, target: Vec3): void;
  254. static computeNormal(va: Vec3, vb: Vec3, vc: Vec3, target: Vec3): void;
  255. clipAgainstHull(posA: Vec3, quatA: Quaternion, hullB: ConvexPolyhedron, posB: Vec3, quatB: Quaternion, separatingNormal: Vec3, minDist: number, maxDist: number, result: ConvexPolyhedronContactPoint[]): void;
  256. findSeparatingAxis(hullB: ConvexPolyhedron, posA: Vec3, quatA: Quaternion, posB: Vec3, quatB: Quaternion, target: Vec3, faceListA?: number[] | null, faceListB?: number[] | null): boolean;
  257. testSepAxis(axis: Vec3, hullB: ConvexPolyhedron, posA: Vec3, quatA: Quaternion, posB: Vec3, quatB: Quaternion): number | false;
  258. calculateLocalInertia(mass: number, target: Vec3): void;
  259. getPlaneConstantOfFace(face_i: number): number;
  260. clipFaceAgainstHull(separatingNormal: Vec3, posA: Vec3, quatA: Quaternion, worldVertsB1: Vec3[], minDist: number, maxDist: number, result: ConvexPolyhedronContactPoint[]): void;
  261. clipFaceAgainstPlane(inVertices: Vec3[], outVertices: Vec3[], planeNormal: Vec3, planeConstant: number): Vec3[];
  262. computeWorldVertices(position: Vec3, quat: Quaternion): void;
  263. computeLocalAABB(aabbmin: Vec3, aabbmax: Vec3): void;
  264. computeWorldFaceNormals(quat: Quaternion): void;
  265. updateBoundingSphereRadius(): void;
  266. calculateWorldAABB(pos: Vec3, quat: Quaternion, min: Vec3, max: Vec3): void;
  267. volume(): number;
  268. getAveragePointLocal(target?: Vec3): Vec3;
  269. transformAllPoints(offset: Vec3, quat: Quaternion): void;
  270. pointIsInside(p: Vec3): 1 | -1 | false;
  271. static project(shape: ConvexPolyhedron, axis: Vec3, pos: Vec3, quat: Quaternion, result: number[]): void;
  272. }
  273. }
  274. declare module "shapes/Box" {
  275. import { Shape } from "shapes/Shape";
  276. import { Vec3 } from "math/Vec3";
  277. import { ConvexPolyhedron } from "shapes/ConvexPolyhedron";
  278. import type { Quaternion } from "math/Quaternion";
  279. export class Box extends Shape {
  280. halfExtents: Vec3;
  281. convexPolyhedronRepresentation: ConvexPolyhedron;
  282. constructor(halfExtents: Vec3);
  283. updateConvexPolyhedronRepresentation(): void;
  284. calculateLocalInertia(mass: number, target?: Vec3): Vec3;
  285. static calculateInertia(halfExtents: Vec3, mass: number, target: Vec3): void;
  286. getSideNormals(sixTargetVectors: Vec3[], quat: Quaternion): Vec3[];
  287. volume(): number;
  288. updateBoundingSphereRadius(): void;
  289. forEachWorldCorner(pos: Vec3, quat: Quaternion, callback: (x: number, y: number, z: number) => void): void;
  290. calculateWorldAABB(pos: Vec3, quat: Quaternion, min: Vec3, max: Vec3): void;
  291. }
  292. }
  293. declare module "shapes/Plane" {
  294. import { Shape } from "shapes/Shape";
  295. import { Vec3 } from "math/Vec3";
  296. import type { Quaternion } from "math/Quaternion";
  297. export class Plane extends Shape {
  298. worldNormal: Vec3;
  299. worldNormalNeedsUpdate: boolean;
  300. boundingSphereRadius: number;
  301. constructor();
  302. computeWorldNormal(quat: Quaternion): void;
  303. calculateLocalInertia(mass: number, target?: Vec3): Vec3;
  304. volume(): number;
  305. calculateWorldAABB(pos: Vec3, quat: Quaternion, min: Vec3, max: Vec3): void;
  306. updateBoundingSphereRadius(): void;
  307. }
  308. }
  309. declare module "utils/Utils" {
  310. export class Utils {
  311. static defaults(options: Record<string, any> | undefined, defaults: Record<string, any>): Record<string, any>;
  312. }
  313. }
  314. declare module "shapes/Heightfield" {
  315. import { Shape } from "shapes/Shape";
  316. import { ConvexPolyhedron } from "shapes/ConvexPolyhedron";
  317. import { Vec3 } from "math/Vec3";
  318. import type { AABB } from "collision/AABB";
  319. import type { Quaternion } from "math/Quaternion";
  320. export type HeightfieldOptions = ConstructorParameters<typeof Heightfield>[1];
  321. type HeightfieldPillar = {
  322. convex: any;
  323. offset: any;
  324. };
  325. export class Heightfield extends Shape {
  326. data: number[][];
  327. maxValue: number | null;
  328. minValue: number | null;
  329. elementSize: number;
  330. cacheEnabled: boolean;
  331. pillarConvex: ConvexPolyhedron;
  332. pillarOffset: Vec3;
  333. private _cachedPillars;
  334. constructor(data: number[][], options?: {
  335. maxValue?: number | null;
  336. minValue?: number | null;
  337. elementSize?: number;
  338. });
  339. update(): void;
  340. updateMinValue(): void;
  341. updateMaxValue(): void;
  342. setHeightValueAtIndex(xi: number, yi: number, value: number): void;
  343. getRectMinMax(iMinX: number, iMinY: number, iMaxX: number, iMaxY: number, result?: number[]): void;
  344. getIndexOfPosition(x: number, y: number, result: number[], clamp: boolean): boolean;
  345. getTriangleAt(x: number, y: number, edgeClamp: boolean, a: Vec3, b: Vec3, c: Vec3): boolean;
  346. getNormalAt(x: number, y: number, edgeClamp: boolean, result: Vec3): void;
  347. getAabbAtIndex(xi: number, yi: number, { lowerBound, upperBound }: AABB): void;
  348. getHeightAt(x: number, y: number, edgeClamp: boolean): number;
  349. getCacheConvexTrianglePillarKey(xi: number, yi: number, getUpperTriangle: boolean): string;
  350. getCachedConvexTrianglePillar(xi: number, yi: number, getUpperTriangle: boolean): HeightfieldPillar;
  351. setCachedConvexTrianglePillar(xi: number, yi: number, getUpperTriangle: boolean, convex: ConvexPolyhedron, offset: Vec3): void;
  352. clearCachedConvexTrianglePillar(xi: number, yi: number, getUpperTriangle: boolean): void;
  353. getTriangle(xi: number, yi: number, upper: boolean, a: Vec3, b: Vec3, c: Vec3): void;
  354. getConvexTrianglePillar(xi: number, yi: number, getUpperTriangle: boolean): void;
  355. calculateLocalInertia(mass: number, target?: Vec3): Vec3;
  356. volume(): number;
  357. calculateWorldAABB(pos: Vec3, quat: Quaternion, min: Vec3, max: Vec3): void;
  358. updateBoundingSphereRadius(): void;
  359. setHeightsFromImage(image: HTMLImageElement, scale: Vec3): void;
  360. }
  361. }
  362. declare module "utils/Octree" {
  363. import { AABB } from "collision/AABB";
  364. import type { Transform } from "math/Transform";
  365. import type { Ray } from "collision/Ray";
  366. class OctreeNode {
  367. root: OctreeNode | null;
  368. aabb: AABB;
  369. data: number[];
  370. children: OctreeNode[];
  371. constructor(options?: {
  372. root?: Octree | null;
  373. aabb?: AABB;
  374. });
  375. reset(): void;
  376. insert(aabb: AABB, elementData: number, level?: number): boolean;
  377. subdivide(): void;
  378. aabbQuery(aabb: AABB, result: number[]): number[];
  379. rayQuery(ray: Ray, treeTransform: Transform, result: number[]): number[];
  380. removeEmptyNodes(): void;
  381. }
  382. export class Octree extends OctreeNode {
  383. maxDepth: number;
  384. constructor(aabb?: AABB, options?: {
  385. maxDepth?: number;
  386. });
  387. }
  388. }
  389. declare module "shapes/Trimesh" {
  390. import { Shape } from "shapes/Shape";
  391. import { Vec3 } from "math/Vec3";
  392. import { AABB } from "collision/AABB";
  393. import { Octree } from "utils/Octree";
  394. import type { Quaternion } from "math/Quaternion";
  395. export class Trimesh extends Shape {
  396. vertices: Float32Array;
  397. indices: Int16Array;
  398. normals: Float32Array;
  399. aabb: AABB;
  400. edges: Int16Array | null;
  401. scale: Vec3;
  402. tree: Octree;
  403. constructor(vertices: number[], indices: number[]);
  404. updateTree(): void;
  405. getTrianglesInAABB(aabb: AABB, result: number[]): number[];
  406. setScale(scale: Vec3): void;
  407. updateNormals(): void;
  408. updateEdges(): void;
  409. getEdgeVertex(edgeIndex: number, firstOrSecond: number, vertexStore: Vec3): void;
  410. getEdgeVector(edgeIndex: number, vectorStore: Vec3): void;
  411. static computeNormal(va: Vec3, vb: Vec3, vc: Vec3, target: Vec3): void;
  412. getVertex(i: number, out: Vec3): Vec3;
  413. private _getUnscaledVertex;
  414. getWorldVertex(i: number, pos: Vec3, quat: Quaternion, out: Vec3): Vec3;
  415. getTriangleVertices(i: number, a: Vec3, b: Vec3, c: Vec3): void;
  416. getNormal(i: number, target: Vec3): Vec3;
  417. calculateLocalInertia(mass: number, target: Vec3): Vec3;
  418. computeLocalAABB(aabb: AABB): void;
  419. updateAABB(): void;
  420. updateBoundingSphereRadius(): void;
  421. calculateWorldAABB(pos: Vec3, quat: Quaternion, min: Vec3, max: Vec3): void;
  422. volume(): number;
  423. static createTorus(radius?: number, tube?: number, radialSegments?: number, tubularSegments?: number, arc?: number): Trimesh;
  424. }
  425. }
  426. declare module "math/JacobianElement" {
  427. import { Vec3 } from "math/Vec3";
  428. export class JacobianElement {
  429. spatial: Vec3;
  430. rotational: Vec3;
  431. constructor();
  432. multiplyElement(element: JacobianElement): number;
  433. multiplyVectors(spatial: Vec3, rotational: Vec3): number;
  434. }
  435. }
  436. declare module "equations/Equation" {
  437. import { JacobianElement } from "math/JacobianElement";
  438. import type { Body } from "objects/Body";
  439. import type { Shape } from "shapes/Shape";
  440. export class Equation {
  441. id: number;
  442. minForce: number;
  443. maxForce: number;
  444. bi: Body;
  445. bj: Body;
  446. si: Shape;
  447. sj: Shape;
  448. a: number;
  449. b: number;
  450. eps: number;
  451. jacobianElementA: JacobianElement;
  452. jacobianElementB: JacobianElement;
  453. enabled: boolean;
  454. multiplier: number;
  455. static idCounter: number;
  456. constructor(bi: Body, bj: Body, minForce?: number, maxForce?: number);
  457. setSpookParams(stiffness: number, relaxation: number, timeStep: number): void;
  458. computeB(a: number, b: number, h: number): number;
  459. computeGq(): number;
  460. computeGW(): number;
  461. computeGWlambda(): number;
  462. computeGiMf(): number;
  463. computeGiMGt(): number;
  464. addToWlambda(deltalambda: number): void;
  465. computeC(): number;
  466. }
  467. }
  468. declare module "solver/Solver" {
  469. import type { Equation } from "equations/Equation";
  470. import type { World } from "world/World";
  471. export class Solver {
  472. equations: Equation[];
  473. constructor();
  474. solve(dt: number, world: World): number;
  475. addEquation(eq: Equation): void;
  476. removeEquation(eq: Equation): void;
  477. removeAllEquations(): void;
  478. }
  479. }
  480. declare module "solver/GSSolver" {
  481. import { Solver } from "solver/Solver";
  482. import type { World } from "world/World";
  483. export class GSSolver extends Solver {
  484. iterations: number;
  485. tolerance: number;
  486. constructor();
  487. solve(dt: number, world: World): number;
  488. }
  489. }
  490. declare module "collision/Broadphase" {
  491. import { Body } from "objects/Body";
  492. import type { AABB } from "collision/AABB";
  493. import type { World } from "world/World";
  494. export class Broadphase {
  495. world: World | null;
  496. useBoundingBoxes: boolean;
  497. dirty: boolean;
  498. constructor();
  499. collisionPairs(world: World, p1: Body[], p2: Body[]): void;
  500. needBroadphaseCollision(bodyA: Body, bodyB: Body): boolean;
  501. intersectionTest(bodyA: Body, bodyB: Body, pairs1: Body[], pairs2: Body[]): void;
  502. doBoundingSphereBroadphase(bodyA: Body, bodyB: Body, pairs1: Body[], pairs2: Body[]): void;
  503. doBoundingBoxBroadphase(bodyA: Body, bodyB: Body, pairs1: Body[], pairs2: Body[]): void;
  504. makePairsUnique(pairs1: Body[], pairs2: Body[]): void;
  505. setWorld(world: World): void;
  506. static boundingSphereCheck(bodyA: Body, bodyB: Body): boolean;
  507. aabbQuery(world: World, aabb: AABB, result: Body[]): Body[];
  508. }
  509. }
  510. declare module "collision/NaiveBroadphase" {
  511. import { Broadphase } from "collision/Broadphase";
  512. import type { AABB } from "collision/AABB";
  513. import type { Body } from "objects/Body";
  514. import type { World } from "world/World";
  515. export class NaiveBroadphase extends Broadphase {
  516. constructor();
  517. collisionPairs(world: World, pairs1: Body[], pairs2: Body[]): void;
  518. aabbQuery(world: World, aabb: AABB, result?: Body[]): Body[];
  519. }
  520. }
  521. declare module "utils/Pool" {
  522. export class Pool {
  523. objects: any[];
  524. type: any;
  525. release(...args: any[]): Pool;
  526. get(): any;
  527. constructObject(): void;
  528. resize(size: number): Pool;
  529. }
  530. }
  531. declare module "utils/Vec3Pool" {
  532. import { Pool } from "utils/Pool";
  533. import { Vec3 } from "math/Vec3";
  534. export class Vec3Pool extends Pool {
  535. type: typeof Vec3;
  536. constructObject(): Vec3;
  537. }
  538. }
  539. declare module "equations/ContactEquation" {
  540. import { Equation } from "equations/Equation";
  541. import { Vec3 } from "math/Vec3";
  542. import type { Body } from "objects/Body";
  543. export class ContactEquation extends Equation {
  544. restitution: number;
  545. ri: Vec3;
  546. rj: Vec3;
  547. ni: Vec3;
  548. constructor(bodyA: Body, bodyB: Body, maxForce?: number);
  549. computeB(h: number): number;
  550. getImpactVelocityAlongNormal(): number;
  551. }
  552. }
  553. declare module "equations/FrictionEquation" {
  554. import { Equation } from "equations/Equation";
  555. import { Vec3 } from "math/Vec3";
  556. import type { Body } from "objects/Body";
  557. export class FrictionEquation extends Equation {
  558. ri: Vec3;
  559. rj: Vec3;
  560. t: Vec3;
  561. constructor(bodyA: Body, bodyB: Body, slipForce: number);
  562. computeB(h: number): number;
  563. }
  564. }
  565. declare module "shapes/Particle" {
  566. import { Shape } from "shapes/Shape";
  567. import { Vec3 } from "math/Vec3";
  568. import type { Quaternion } from "math/Quaternion";
  569. export class Particle extends Shape {
  570. constructor();
  571. calculateLocalInertia(mass: number, target?: Vec3): Vec3;
  572. volume(): number;
  573. updateBoundingSphereRadius(): void;
  574. calculateWorldAABB(pos: Vec3, quat: Quaternion, min: Vec3, max: Vec3): void;
  575. }
  576. }
  577. declare module "shapes/Cylinder" {
  578. import { ConvexPolyhedron } from "shapes/ConvexPolyhedron";
  579. export class Cylinder extends ConvexPolyhedron {
  580. radiusTop: number;
  581. radiusBottom: number;
  582. height: number;
  583. numSegments: number;
  584. constructor(radiusTop?: number, radiusBottom?: number, height?: number, numSegments?: number);
  585. }
  586. }
  587. declare module "material/ContactMaterial" {
  588. import type { Material } from "material/Material";
  589. export type ContactMaterialOptions = ConstructorParameters<typeof ContactMaterial>[2];
  590. export class ContactMaterial {
  591. id: number;
  592. materials: [Material, Material];
  593. friction: number;
  594. restitution: number;
  595. contactEquationStiffness: number;
  596. contactEquationRelaxation: number;
  597. frictionEquationStiffness: number;
  598. frictionEquationRelaxation: number;
  599. static idCounter: number;
  600. constructor(m1: Material, m2: Material, options: {
  601. friction?: number;
  602. restitution?: number;
  603. contactEquationStiffness?: number;
  604. contactEquationRelaxation?: number;
  605. frictionEquationStiffness?: number;
  606. frictionEquationRelaxation?: number;
  607. });
  608. }
  609. }
  610. declare module "world/Narrowphase" {
  611. import { Shape } from "shapes/Shape";
  612. import { Vec3 } from "math/Vec3";
  613. import { Quaternion } from "math/Quaternion";
  614. import { Body } from "objects/Body";
  615. import { Vec3Pool } from "utils/Vec3Pool";
  616. import { ContactEquation } from "equations/ContactEquation";
  617. import { FrictionEquation } from "equations/FrictionEquation";
  618. import type { Box } from "shapes/Box";
  619. import type { Sphere } from "shapes/Sphere";
  620. import type { ConvexPolyhedron } from "shapes/ConvexPolyhedron";
  621. import type { Particle } from "shapes/Particle";
  622. import type { Plane } from "shapes/Plane";
  623. import type { Trimesh } from "shapes/Trimesh";
  624. import type { Heightfield } from "shapes/Heightfield";
  625. import { Cylinder } from "shapes/Cylinder";
  626. import type { ContactMaterial } from "material/ContactMaterial";
  627. import type { World } from "world/World";
  628. export const COLLISION_TYPES: {
  629. sphereSphere: 1;
  630. spherePlane: 3;
  631. boxBox: 4;
  632. sphereBox: 5;
  633. planeBox: 6;
  634. convexConvex: 16;
  635. sphereConvex: 17;
  636. planeConvex: 18;
  637. boxConvex: 20;
  638. sphereHeightfield: 33;
  639. boxHeightfield: 36;
  640. convexHeightfield: 48;
  641. sphereParticle: 65;
  642. planeParticle: 66;
  643. boxParticle: 68;
  644. convexParticle: 80;
  645. cylinderCylinder: 128;
  646. sphereCylinder: 129;
  647. planeCylinder: 130;
  648. boxCylinder: 132;
  649. convexCylinder: 144;
  650. heightfieldCylinder: 160;
  651. particleCylinder: 192;
  652. sphereTrimesh: 257;
  653. planeTrimesh: 258;
  654. };
  655. export type CollisionType = typeof COLLISION_TYPES[keyof typeof COLLISION_TYPES];
  656. export class Narrowphase {
  657. contactPointPool: ContactEquation[];
  658. frictionEquationPool: FrictionEquation[];
  659. result: ContactEquation[];
  660. frictionResult: FrictionEquation[];
  661. v3pool: Vec3Pool;
  662. world: World;
  663. currentContactMaterial: ContactMaterial;
  664. enableFrictionReduction: boolean;
  665. get [COLLISION_TYPES.sphereSphere](): (si: Sphere, sj: Sphere, xi: Vec3, xj: Vec3, qi: Quaternion, qj: Quaternion, bi: Body, bj: Body, rsi?: Shape | null | undefined, rsj?: Shape | null | undefined, justTest?: boolean | undefined) => boolean | void;
  666. get [COLLISION_TYPES.spherePlane](): (si: Sphere, sj: Plane, xi: Vec3, xj: Vec3, qi: Quaternion, qj: Quaternion, bi: Body, bj: Body, rsi?: Shape | null | undefined, rsj?: Shape | null | undefined, justTest?: boolean | undefined) => true | void;
  667. get [COLLISION_TYPES.boxBox](): (si: Box, sj: Box, xi: Vec3, xj: Vec3, qi: Quaternion, qj: Quaternion, bi: Body, bj: Body, rsi?: Shape | null | undefined, rsj?: Shape | null | undefined, justTest?: boolean | undefined) => true | void;
  668. get [COLLISION_TYPES.sphereBox](): (si: Sphere, sj: Box, xi: Vec3, xj: Vec3, qi: Quaternion, qj: Quaternion, bi: Body, bj: Body, rsi?: Shape | null | undefined, rsj?: Shape | null | undefined, justTest?: boolean | undefined) => true | void;
  669. get [COLLISION_TYPES.planeBox](): (si: Plane, sj: Box, xi: Vec3, xj: Vec3, qi: Quaternion, qj: Quaternion, bi: Body, bj: Body, rsi?: Shape | null | undefined, rsj?: Shape | null | undefined, justTest?: boolean | undefined) => true | void;
  670. get [COLLISION_TYPES.convexConvex](): (si: ConvexPolyhedron, sj: ConvexPolyhedron, xi: Vec3, xj: Vec3, qi: Quaternion, qj: Quaternion, bi: Body, bj: Body, rsi?: Shape | null | undefined, rsj?: Shape | null | undefined, justTest?: boolean | undefined, faceListA?: number[] | null | undefined, faceListB?: number[] | null | undefined) => true | void;
  671. get [COLLISION_TYPES.sphereConvex](): (si: Sphere, sj: ConvexPolyhedron, xi: Vec3, xj: Vec3, qi: Quaternion, qj: Quaternion, bi: Body, bj: Body, rsi?: Shape | null | undefined, rsj?: Shape | null | undefined, justTest?: boolean | undefined) => true | void;
  672. get [COLLISION_TYPES.planeConvex](): (planeShape: Plane, convexShape: ConvexPolyhedron, planePosition: Vec3, convexPosition: Vec3, planeQuat: Quaternion, convexQuat: Quaternion, planeBody: Body, convexBody: Body, si?: Shape | undefined, sj?: Shape | undefined, justTest?: boolean | undefined) => true | void;
  673. get [COLLISION_TYPES.boxConvex](): (si: Box, sj: ConvexPolyhedron, xi: Vec3, xj: Vec3, qi: Quaternion, qj: Quaternion, bi: Body, bj: Body, rsi?: Shape | null | undefined, rsj?: Shape | null | undefined, justTest?: boolean | undefined) => true | void;
  674. get [COLLISION_TYPES.sphereHeightfield](): (sphereShape: Sphere, hfShape: Heightfield, spherePos: Vec3, hfPos: Vec3, sphereQuat: Quaternion, hfQuat: Quaternion, sphereBody: Body, hfBody: Body, rsi?: Shape | null | undefined, rsj?: Shape | null | undefined, justTest?: boolean | undefined) => true | void;
  675. get [COLLISION_TYPES.boxHeightfield](): (si: Box, sj: Heightfield, xi: Vec3, xj: Vec3, qi: Quaternion, qj: Quaternion, bi: Body, bj: Body, rsi?: Shape | null | undefined, rsj?: Shape | null | undefined, justTest?: boolean | undefined) => true | void;
  676. get [COLLISION_TYPES.convexHeightfield](): (convexShape: ConvexPolyhedron, hfShape: Heightfield, convexPos: Vec3, hfPos: Vec3, convexQuat: Quaternion, hfQuat: Quaternion, convexBody: Body, hfBody: Body, rsi?: Shape | null | undefined, rsj?: Shape | null | undefined, justTest?: boolean | undefined) => true | void;
  677. get [COLLISION_TYPES.sphereParticle](): (sj: Sphere, si: Particle, xj: Vec3, xi: Vec3, qj: Quaternion, qi: Quaternion, bj: Body, bi: Body, rsi?: Shape | null | undefined, rsj?: Shape | null | undefined, justTest?: boolean | undefined) => true | void;
  678. get [COLLISION_TYPES.planeParticle](): (sj: Plane, si: Particle, xj: Vec3, xi: Vec3, qj: Quaternion, qi: Quaternion, bj: Body, bi: Body, rsi?: Shape | null | undefined, rsj?: Shape | null | undefined, justTest?: boolean | undefined) => true | void;
  679. get [COLLISION_TYPES.boxParticle](): (si: Box, sj: Particle, xi: Vec3, xj: Vec3, qi: Quaternion, qj: Quaternion, bi: Body, bj: Body, rsi?: Shape | null | undefined, rsj?: Shape | null | undefined, justTest?: boolean | undefined) => true | void;
  680. get [COLLISION_TYPES.convexParticle](): (sj: ConvexPolyhedron, si: Particle, xj: Vec3, xi: Vec3, qj: Quaternion, qi: Quaternion, bj: Body, bi: Body, rsi?: Shape | null | undefined, rsj?: Shape | null | undefined, justTest?: boolean | undefined) => true | void;
  681. get [COLLISION_TYPES.cylinderCylinder](): (si: ConvexPolyhedron, sj: ConvexPolyhedron, xi: Vec3, xj: Vec3, qi: Quaternion, qj: Quaternion, bi: Body, bj: Body, rsi?: Shape | null | undefined, rsj?: Shape | null | undefined, justTest?: boolean | undefined, faceListA?: number[] | null | undefined, faceListB?: number[] | null | undefined) => true | void;
  682. get [COLLISION_TYPES.sphereCylinder](): (si: Sphere, sj: ConvexPolyhedron, xi: Vec3, xj: Vec3, qi: Quaternion, qj: Quaternion, bi: Body, bj: Body, rsi?: Shape | null | undefined, rsj?: Shape | null | undefined, justTest?: boolean | undefined) => true | void;
  683. get [COLLISION_TYPES.planeCylinder](): (planeShape: Plane, convexShape: ConvexPolyhedron, planePosition: Vec3, convexPosition: Vec3, planeQuat: Quaternion, convexQuat: Quaternion, planeBody: Body, convexBody: Body, si?: Shape | undefined, sj?: Shape | undefined, justTest?: boolean | undefined) => true | void;
  684. get [COLLISION_TYPES.boxCylinder](): (si: Box, sj: ConvexPolyhedron, xi: Vec3, xj: Vec3, qi: Quaternion, qj: Quaternion, bi: Body, bj: Body, rsi?: Shape | null | undefined, rsj?: Shape | null | undefined, justTest?: boolean | undefined) => true | void;
  685. get [COLLISION_TYPES.convexCylinder](): (si: ConvexPolyhedron, sj: ConvexPolyhedron, xi: Vec3, xj: Vec3, qi: Quaternion, qj: Quaternion, bi: Body, bj: Body, rsi?: Shape | null | undefined, rsj?: Shape | null | undefined, justTest?: boolean | undefined, faceListA?: number[] | null | undefined, faceListB?: number[] | null | undefined) => true | void;
  686. get [COLLISION_TYPES.heightfieldCylinder](): (hfShape: Heightfield, convexShape: Cylinder, hfPos: Vec3, convexPos: Vec3, hfQuat: Quaternion, convexQuat: Quaternion, hfBody: Body, convexBody: Body, rsi?: Shape | null | undefined, rsj?: Shape | null | undefined, justTest?: boolean | undefined) => true | void;
  687. get [COLLISION_TYPES.particleCylinder](): (si: Particle, sj: Cylinder, xi: Vec3, xj: Vec3, qi: Quaternion, qj: Quaternion, bi: Body, bj: Body, rsi?: Shape | null | undefined, rsj?: Shape | null | undefined, justTest?: boolean | undefined) => true | void;
  688. get [COLLISION_TYPES.sphereTrimesh](): (sphereShape: Sphere, trimeshShape: Trimesh, spherePos: Vec3, trimeshPos: Vec3, sphereQuat: Quaternion, trimeshQuat: Quaternion, sphereBody: Body, trimeshBody: Body, rsi?: Shape | null | undefined, rsj?: Shape | null | undefined, justTest?: boolean | undefined) => true | void;
  689. get [COLLISION_TYPES.planeTrimesh](): (planeShape: Plane, trimeshShape: Trimesh, planePos: Vec3, trimeshPos: Vec3, planeQuat: Quaternion, trimeshQuat: Quaternion, planeBody: Body, trimeshBody: Body, rsi?: Shape | null | undefined, rsj?: Shape | null | undefined, justTest?: boolean | undefined) => true | void;
  690. constructor(world: World);
  691. createContactEquation(bi: Body, bj: Body, si: Shape, sj: Shape, overrideShapeA?: Shape | null, overrideShapeB?: Shape | null): ContactEquation;
  692. createFrictionEquationsFromContact(contactEquation: ContactEquation, outArray: FrictionEquation[]): boolean;
  693. createFrictionFromAverage(numContacts: number): void;
  694. getContacts(p1: Body[], p2: Body[], world: World, result: ContactEquation[], oldcontacts: ContactEquation[], frictionResult: FrictionEquation[], frictionPool: FrictionEquation[]): void;
  695. sphereSphere(si: Sphere, sj: Sphere, xi: Vec3, xj: Vec3, qi: Quaternion, qj: Quaternion, bi: Body, bj: Body, rsi?: Shape | null, rsj?: Shape | null, justTest?: boolean): boolean | void;
  696. spherePlane(si: Sphere, sj: Plane, xi: Vec3, xj: Vec3, qi: Quaternion, qj: Quaternion, bi: Body, bj: Body, rsi?: Shape | null, rsj?: Shape | null, justTest?: boolean): true | void;
  697. boxBox(si: Box, sj: Box, xi: Vec3, xj: Vec3, qi: Quaternion, qj: Quaternion, bi: Body, bj: Body, rsi?: Shape | null, rsj?: Shape | null, justTest?: boolean): true | void;
  698. sphereBox(si: Sphere, sj: Box, xi: Vec3, xj: Vec3, qi: Quaternion, qj: Quaternion, bi: Body, bj: Body, rsi?: Shape | null, rsj?: Shape | null, justTest?: boolean): true | void;
  699. planeBox(si: Plane, sj: Box, xi: Vec3, xj: Vec3, qi: Quaternion, qj: Quaternion, bi: Body, bj: Body, rsi?: Shape | null, rsj?: Shape | null, justTest?: boolean): true | void;
  700. convexConvex(si: ConvexPolyhedron, sj: ConvexPolyhedron, xi: Vec3, xj: Vec3, qi: Quaternion, qj: Quaternion, bi: Body, bj: Body, rsi?: Shape | null, rsj?: Shape | null, justTest?: boolean, faceListA?: number[] | null, faceListB?: number[] | null): true | void;
  701. sphereConvex(si: Sphere, sj: ConvexPolyhedron, xi: Vec3, xj: Vec3, qi: Quaternion, qj: Quaternion, bi: Body, bj: Body, rsi?: Shape | null, rsj?: Shape | null, justTest?: boolean): true | void;
  702. planeConvex(planeShape: Plane, convexShape: ConvexPolyhedron, planePosition: Vec3, convexPosition: Vec3, planeQuat: Quaternion, convexQuat: Quaternion, planeBody: Body, convexBody: Body, si?: Shape, sj?: Shape, justTest?: boolean): true | void;
  703. boxConvex(si: Box, sj: ConvexPolyhedron, xi: Vec3, xj: Vec3, qi: Quaternion, qj: Quaternion, bi: Body, bj: Body, rsi?: Shape | null, rsj?: Shape | null, justTest?: boolean): true | void;
  704. sphereHeightfield(sphereShape: Sphere, hfShape: Heightfield, spherePos: Vec3, hfPos: Vec3, sphereQuat: Quaternion, hfQuat: Quaternion, sphereBody: Body, hfBody: Body, rsi?: Shape | null, rsj?: Shape | null, justTest?: boolean): true | void;
  705. boxHeightfield(si: Box, sj: Heightfield, xi: Vec3, xj: Vec3, qi: Quaternion, qj: Quaternion, bi: Body, bj: Body, rsi?: Shape | null, rsj?: Shape | null, justTest?: boolean): true | void;
  706. convexHeightfield(convexShape: ConvexPolyhedron, hfShape: Heightfield, convexPos: Vec3, hfPos: Vec3, convexQuat: Quaternion, hfQuat: Quaternion, convexBody: Body, hfBody: Body, rsi?: Shape | null, rsj?: Shape | null, justTest?: boolean): true | void;
  707. sphereParticle(sj: Sphere, si: Particle, xj: Vec3, xi: Vec3, qj: Quaternion, qi: Quaternion, bj: Body, bi: Body, rsi?: Shape | null, rsj?: Shape | null, justTest?: boolean): true | void;
  708. planeParticle(sj: Plane, si: Particle, xj: Vec3, xi: Vec3, qj: Quaternion, qi: Quaternion, bj: Body, bi: Body, rsi?: Shape | null, rsj?: Shape | null, justTest?: boolean): true | void;
  709. boxParticle(si: Box, sj: Particle, xi: Vec3, xj: Vec3, qi: Quaternion, qj: Quaternion, bi: Body, bj: Body, rsi?: Shape | null, rsj?: Shape | null, justTest?: boolean): true | void;
  710. convexParticle(sj: ConvexPolyhedron, si: Particle, xj: Vec3, xi: Vec3, qj: Quaternion, qi: Quaternion, bj: Body, bi: Body, rsi?: Shape | null, rsj?: Shape | null, justTest?: boolean): true | void;
  711. heightfieldCylinder(hfShape: Heightfield, convexShape: Cylinder, hfPos: Vec3, convexPos: Vec3, hfQuat: Quaternion, convexQuat: Quaternion, hfBody: Body, convexBody: Body, rsi?: Shape | null, rsj?: Shape | null, justTest?: boolean): true | void;
  712. particleCylinder(si: Particle, sj: Cylinder, xi: Vec3, xj: Vec3, qi: Quaternion, qj: Quaternion, bi: Body, bj: Body, rsi?: Shape | null, rsj?: Shape | null, justTest?: boolean): true | void;
  713. sphereTrimesh(sphereShape: Sphere, trimeshShape: Trimesh, spherePos: Vec3, trimeshPos: Vec3, sphereQuat: Quaternion, trimeshQuat: Quaternion, sphereBody: Body, trimeshBody: Body, rsi?: Shape | null, rsj?: Shape | null, justTest?: boolean): true | void;
  714. planeTrimesh(planeShape: Plane, trimeshShape: Trimesh, planePos: Vec3, trimeshPos: Vec3, planeQuat: Quaternion, trimeshQuat: Quaternion, planeBody: Body, trimeshBody: Body, rsi?: Shape | null, rsj?: Shape | null, justTest?: boolean): true | void;
  715. }
  716. }
  717. declare module "collision/ArrayCollisionMatrix" {
  718. import type { Body } from "objects/Body";
  719. export class ArrayCollisionMatrix {
  720. matrix: number[];
  721. constructor();
  722. get(bi: Body, bj: Body): number;
  723. set(bi: Body, bj: Body, value: boolean): void;
  724. reset(): void;
  725. setNumObjects(n: number): void;
  726. }
  727. }
  728. declare module "collision/OverlapKeeper" {
  729. export class OverlapKeeper {
  730. current: number[];
  731. previous: number[];
  732. constructor();
  733. getKey(i: number, j: number): number;
  734. set(i: number, j: number): void;
  735. tick(): void;
  736. getDiff(additions: number[], removals: number[]): void;
  737. }
  738. }
  739. declare module "utils/TupleDictionary" {
  740. export class TupleDictionary {
  741. data: {
  742. [id: string]: any;
  743. keys: string[];
  744. };
  745. get(i: number, j: number): any;
  746. set(i: number, j: number, value: any): void;
  747. delete(i: number, j: number): void;
  748. reset(): void;
  749. }
  750. }
  751. declare module "constraints/Constraint" {
  752. import type { Body } from "objects/Body";
  753. import type { Equation } from "equations/Equation";
  754. export type ConstraintOptions = ConstructorParameters<typeof Constraint>[2];
  755. export class Constraint {
  756. equations: Equation[];
  757. bodyA: Body;
  758. bodyB: Body;
  759. id: number;
  760. collideConnected: boolean;
  761. static idCounter: number;
  762. constructor(bodyA: Body, bodyB: Body, options?: {
  763. collideConnected?: boolean;
  764. wakeUpBodies?: boolean;
  765. });
  766. update(): void;
  767. enable(): void;
  768. disable(): void;
  769. }
  770. }
  771. declare module "world/World" {
  772. import { EventTarget } from "utils/EventTarget";
  773. import { Narrowphase } from "world/Narrowphase";
  774. import { Vec3 } from "math/Vec3";
  775. import { Material } from "material/Material";
  776. import { ContactMaterial } from "material/ContactMaterial";
  777. import { ArrayCollisionMatrix } from "collision/ArrayCollisionMatrix";
  778. import { OverlapKeeper } from "collision/OverlapKeeper";
  779. import { TupleDictionary } from "utils/TupleDictionary";
  780. import { RaycastResult } from "collision/RaycastResult";
  781. import { Body } from "objects/Body";
  782. import type { Broadphase } from "collision/Broadphase";
  783. import type { Solver } from "solver/Solver";
  784. import type { ContactEquation } from "equations/ContactEquation";
  785. import type { FrictionEquation } from "equations/FrictionEquation";
  786. import type { RayOptions, RaycastCallback } from "collision/Ray";
  787. import type { Constraint } from "constraints/Constraint";
  788. import type { Shape } from "shapes/Shape";
  789. export type WorldOptions = ConstructorParameters<typeof World>[0];
  790. export class World extends EventTarget {
  791. dt: number;
  792. allowSleep: boolean;
  793. contacts: ContactEquation[];
  794. frictionEquations: FrictionEquation[];
  795. quatNormalizeSkip: number;
  796. quatNormalizeFast: boolean;
  797. time: number;
  798. stepnumber: number;
  799. default_dt: number;
  800. nextId: number;
  801. gravity: Vec3;
  802. frictionGravity?: Vec3;
  803. broadphase: Broadphase;
  804. bodies: Body[];
  805. hasActiveBodies: boolean;
  806. solver: Solver;
  807. constraints: Constraint[];
  808. narrowphase: Narrowphase;
  809. collisionMatrix: ArrayCollisionMatrix;
  810. collisionMatrixPrevious: ArrayCollisionMatrix;
  811. bodyOverlapKeeper: OverlapKeeper;
  812. shapeOverlapKeeper: OverlapKeeper;
  813. contactmaterials: ContactMaterial[];
  814. contactMaterialTable: TupleDictionary;
  815. defaultMaterial: Material;
  816. defaultContactMaterial: ContactMaterial;
  817. doProfiling: boolean;
  818. profile: {
  819. solve: number;
  820. makeContactConstraints: number;
  821. broadphase: number;
  822. integrate: number;
  823. narrowphase: number;
  824. };
  825. accumulator: number;
  826. subsystems: any[];
  827. addBodyEvent: {
  828. type: 'addBody';
  829. body: Body | null;
  830. };
  831. removeBodyEvent: {
  832. type: 'removeBody';
  833. body: Body | null;
  834. };
  835. idToBodyMap: {
  836. [id: number]: Body;
  837. };
  838. lastCallTime?: number;
  839. constructor(options?: {
  840. gravity?: Vec3;
  841. frictionGravity?: Vec3;
  842. allowSleep?: boolean;
  843. broadphase?: Broadphase;
  844. solver?: Solver;
  845. quatNormalizeFast?: boolean;
  846. quatNormalizeSkip?: number;
  847. });
  848. getContactMaterial(m1: Material, m2: Material): ContactMaterial;
  849. collisionMatrixTick(): void;
  850. addConstraint(c: Constraint): void;
  851. removeConstraint(c: Constraint): void;
  852. rayTest(from: Vec3, to: Vec3, result: RaycastResult | RaycastCallback): void;
  853. raycastAll(from?: Vec3, to?: Vec3, options?: RayOptions, callback?: RaycastCallback): boolean;
  854. raycastAny(from?: Vec3, to?: Vec3, options?: RayOptions, result?: RaycastResult): boolean;
  855. raycastClosest(from?: Vec3, to?: Vec3, options?: RayOptions, result?: RaycastResult): boolean;
  856. addBody(body: Body): void;
  857. removeBody(body: Body): void;
  858. getBodyById(id: number): Body;
  859. getShapeById(id: number): Shape | null;
  860. addContactMaterial(cmat: ContactMaterial): void;
  861. removeContactMaterial(cmat: ContactMaterial): void;
  862. fixedStep(dt?: number, maxSubSteps?: number): void;
  863. step(dt: number, timeSinceLastCalled?: number, maxSubSteps?: number): void;
  864. internalStep(dt: number): void;
  865. emitContactEvents(): void;
  866. clearForces(): void;
  867. }
  868. }
  869. declare module "collision/Ray" {
  870. import { Vec3 } from "math/Vec3";
  871. import { Quaternion } from "math/Quaternion";
  872. import { RaycastResult } from "collision/RaycastResult";
  873. import { Shape } from "shapes/Shape";
  874. import { AABB } from "collision/AABB";
  875. import type { Body } from "objects/Body";
  876. import type { Sphere } from "shapes/Sphere";
  877. import type { Box } from "shapes/Box";
  878. import type { Plane } from "shapes/Plane";
  879. import type { Heightfield } from "shapes/Heightfield";
  880. import type { ConvexPolyhedron } from "shapes/ConvexPolyhedron";
  881. import type { Trimesh } from "shapes/Trimesh";
  882. import type { World } from "world/World";
  883. export const RAY_MODES: {
  884. readonly CLOSEST: 1;
  885. readonly ANY: 2;
  886. readonly ALL: 4;
  887. };
  888. export type RayMode = typeof RAY_MODES[keyof typeof RAY_MODES];
  889. export type RayOptions = {
  890. from?: Vec3;
  891. to?: Vec3;
  892. mode?: RayMode;
  893. result?: RaycastResult;
  894. skipBackfaces?: boolean;
  895. collisionFilterMask?: number;
  896. collisionFilterGroup?: number;
  897. checkCollisionResponse?: boolean;
  898. callback?: RaycastCallback;
  899. };
  900. export type RaycastCallback = (result: RaycastResult) => void;
  901. export class Ray {
  902. from: Vec3;
  903. to: Vec3;
  904. direction: Vec3;
  905. precision: number;
  906. checkCollisionResponse: boolean;
  907. skipBackfaces: boolean;
  908. collisionFilterMask: number;
  909. collisionFilterGroup: number;
  910. mode: number;
  911. result: RaycastResult;
  912. hasHit: boolean;
  913. callback: RaycastCallback;
  914. static CLOSEST: 1;
  915. static ANY: 2;
  916. static ALL: 4;
  917. get [Shape.types.SPHERE](): (sphere: Sphere, quat: Quaternion, position: Vec3, body: Body, reportedShape: Shape) => void;
  918. get [Shape.types.PLANE](): (shape: Plane, quat: Quaternion, position: Vec3, body: Body, reportedShape: Shape) => void;
  919. get [Shape.types.BOX](): (box: Box, quat: Quaternion, position: Vec3, body: Body, reportedShape: Shape) => void;
  920. get [Shape.types.CYLINDER](): (shape: ConvexPolyhedron, quat: Quaternion, position: Vec3, body: Body, reportedShape: Shape, options?: {
  921. faceList: number[];
  922. } | undefined) => void;
  923. get [Shape.types.CONVEXPOLYHEDRON](): (shape: ConvexPolyhedron, quat: Quaternion, position: Vec3, body: Body, reportedShape: Shape, options?: {
  924. faceList: number[];
  925. } | undefined) => void;
  926. get [Shape.types.HEIGHTFIELD](): (shape: Heightfield, quat: Quaternion, position: Vec3, body: Body, reportedShape: Shape) => void;
  927. get [Shape.types.TRIMESH](): (mesh: Trimesh, quat: Quaternion, position: Vec3, body: Body, reportedShape: Shape, options?: {
  928. faceList?: any[] | undefined;
  929. } | undefined) => void;
  930. constructor(from?: Vec3, to?: Vec3);
  931. intersectWorld(world: World, options: RayOptions): boolean;
  932. intersectBody(body: Body, result?: RaycastResult): void;
  933. intersectBodies(bodies: Body[], result?: RaycastResult): void;
  934. private updateDirection;
  935. private intersectShape;
  936. _intersectBox(box: Box, quat: Quaternion, position: Vec3, body: Body, reportedShape: Shape): void;
  937. _intersectPlane(shape: Plane, quat: Quaternion, position: Vec3, body: Body, reportedShape: Shape): void;
  938. getAABB(aabb: AABB): void;
  939. _intersectHeightfield(shape: Heightfield, quat: Quaternion, position: Vec3, body: Body, reportedShape: Shape): void;
  940. _intersectSphere(sphere: Sphere, quat: Quaternion, position: Vec3, body: Body, reportedShape: Shape): void;
  941. _intersectConvex(shape: ConvexPolyhedron, quat: Quaternion, position: Vec3, body: Body, reportedShape: Shape, options?: {
  942. faceList: number[];
  943. }): void;
  944. _intersectTrimesh(mesh: Trimesh, quat: Quaternion, position: Vec3, body: Body, reportedShape: Shape, options?: {
  945. faceList?: any[];
  946. }): void;
  947. private reportIntersection;
  948. static pointInTriangle(p: Vec3, a: Vec3, b: Vec3, c: Vec3): boolean;
  949. }
  950. }
  951. declare module "collision/AABB" {
  952. import { Vec3 } from "math/Vec3";
  953. import type { Ray } from "collision/Ray";
  954. import type { Transform } from "math/Transform";
  955. import type { Quaternion } from "math/Quaternion";
  956. export class AABB {
  957. lowerBound: Vec3;
  958. upperBound: Vec3;
  959. constructor(options?: {
  960. upperBound?: Vec3;
  961. lowerBound?: Vec3;
  962. });
  963. setFromPoints(points: Vec3[], position?: Vec3, quaternion?: Quaternion, skinSize?: number): AABB;
  964. copy(aabb: AABB): AABB;
  965. clone(): AABB;
  966. extend(aabb: AABB): void;
  967. overlaps(aabb: AABB): boolean;
  968. volume(): number;
  969. contains(aabb: AABB): boolean;
  970. getCorners(a: Vec3, b: Vec3, c: Vec3, d: Vec3, e: Vec3, f: Vec3, g: Vec3, h: Vec3): void;
  971. toLocalFrame(frame: Transform, target: AABB): AABB;
  972. toWorldFrame(frame: Transform, target: AABB): AABB;
  973. overlapsRay(ray: Ray): boolean;
  974. }
  975. }
  976. declare module "objects/Body" {
  977. import { EventTarget } from "utils/EventTarget";
  978. import { Vec3 } from "math/Vec3";
  979. import { Mat3 } from "math/Mat3";
  980. import { Quaternion } from "math/Quaternion";
  981. import { AABB } from "collision/AABB";
  982. import type { Shape } from "shapes/Shape";
  983. import type { Material } from "material/Material";
  984. import type { World } from "world/World";
  985. export const BODY_TYPES: {
  986. readonly DYNAMIC: 1;
  987. readonly STATIC: 2;
  988. readonly KINEMATIC: 4;
  989. };
  990. export type BodyType = typeof BODY_TYPES[keyof typeof BODY_TYPES];
  991. export const BODY_SLEEP_STATES: {
  992. readonly AWAKE: 0;
  993. readonly SLEEPY: 1;
  994. readonly SLEEPING: 2;
  995. };
  996. export type BodySleepState = typeof BODY_SLEEP_STATES[keyof typeof BODY_SLEEP_STATES];
  997. export type BodyOptions = ConstructorParameters<typeof Body>[0];
  998. export class Body extends EventTarget {
  999. static idCounter: number;
  1000. static COLLIDE_EVENT_NAME: string;
  1001. static DYNAMIC: 1;
  1002. static STATIC: 2;
  1003. static KINEMATIC: 4;
  1004. static AWAKE: 0;
  1005. static SLEEPY: 1;
  1006. static SLEEPING: 2;
  1007. static wakeupEvent: {
  1008. type: string;
  1009. };
  1010. static sleepyEvent: {
  1011. type: string;
  1012. };
  1013. static sleepEvent: {
  1014. type: string;
  1015. };
  1016. id: number;
  1017. index: number;
  1018. world: World | null;
  1019. vlambda: Vec3;
  1020. collisionFilterGroup: number;
  1021. collisionFilterMask: number;
  1022. collisionResponse: boolean;
  1023. position: Vec3;
  1024. previousPosition: Vec3;
  1025. interpolatedPosition: Vec3;
  1026. initPosition: Vec3;
  1027. velocity: Vec3;
  1028. initVelocity: Vec3;
  1029. force: Vec3;
  1030. mass: number;
  1031. invMass: number;
  1032. material: Material | null;
  1033. linearDamping: number;
  1034. type: BodyType;
  1035. allowSleep: boolean;
  1036. sleepState: BodySleepState;
  1037. sleepSpeedLimit: number;
  1038. sleepTimeLimit: number;
  1039. timeLastSleepy: number;
  1040. wakeUpAfterNarrowphase: boolean;
  1041. torque: Vec3;
  1042. quaternion: Quaternion;
  1043. initQuaternion: Quaternion;
  1044. previousQuaternion: Quaternion;
  1045. interpolatedQuaternion: Quaternion;
  1046. angularVelocity: Vec3;
  1047. initAngularVelocity: Vec3;
  1048. shapes: Shape[];
  1049. shapeOffsets: Vec3[];
  1050. shapeOrientations: Quaternion[];
  1051. inertia: Vec3;
  1052. invInertia: Vec3;
  1053. invInertiaWorld: Mat3;
  1054. invMassSolve: number;
  1055. invInertiaSolve: Vec3;
  1056. invInertiaWorldSolve: Mat3;
  1057. fixedRotation: boolean;
  1058. angularDamping: number;
  1059. linearFactor: Vec3;
  1060. angularFactor: Vec3;
  1061. aabb: AABB;
  1062. aabbNeedsUpdate: boolean;
  1063. boundingRadius: number;
  1064. wlambda: Vec3;
  1065. isTrigger: boolean;
  1066. constructor(options?: {
  1067. collisionFilterGroup?: number;
  1068. collisionFilterMask?: number;
  1069. collisionResponse?: boolean;
  1070. position?: Vec3;
  1071. velocity?: Vec3;
  1072. mass?: number;
  1073. material?: Material;
  1074. linearDamping?: number;
  1075. type?: BodyType;
  1076. allowSleep?: boolean;
  1077. sleepSpeedLimit?: number;
  1078. sleepTimeLimit?: number;
  1079. quaternion?: Quaternion;
  1080. angularVelocity?: Vec3;
  1081. fixedRotation?: boolean;
  1082. angularDamping?: number;
  1083. linearFactor?: Vec3;
  1084. angularFactor?: Vec3;
  1085. shape?: Shape;
  1086. isTrigger?: boolean;
  1087. });
  1088. wakeUp(): void;
  1089. sleep(): void;
  1090. sleepTick(time: number): void;
  1091. updateSolveMassProperties(): void;
  1092. pointToLocalFrame(worldPoint: Vec3, result?: Vec3): Vec3;
  1093. vectorToLocalFrame(worldVector: Vec3, result?: Vec3): Vec3;
  1094. pointToWorldFrame(localPoint: Vec3, result?: Vec3): Vec3;
  1095. vectorToWorldFrame(localVector: Vec3, result?: Vec3): Vec3;
  1096. addShape(shape: Shape, _offset?: Vec3, _orientation?: Quaternion): Body;
  1097. removeShape(shape: Shape): Body;
  1098. updateBoundingRadius(): void;
  1099. updateAABB(): void;
  1100. updateInertiaWorld(force?: boolean): void;
  1101. applyForce(force: Vec3, relativePoint?: Vec3): void;
  1102. applyLocalForce(localForce: Vec3, localPoint?: Vec3): void;
  1103. applyTorque(torque: Vec3): void;
  1104. applyImpulse(impulse: Vec3, relativePoint?: Vec3): void;
  1105. applyLocalImpulse(localImpulse: Vec3, localPoint?: Vec3): void;
  1106. updateMassProperties(): void;
  1107. getVelocityAtWorldPoint(worldPoint: Vec3, result: Vec3): Vec3;
  1108. integrate(dt: number, quatNormalize: boolean, quatNormalizeFast: boolean): void;
  1109. }
  1110. }
  1111. declare module "collision/ObjectCollisionMatrix" {
  1112. import type { Body } from "objects/Body";
  1113. export class ObjectCollisionMatrix {
  1114. matrix: Record<string, boolean>;
  1115. constructor();
  1116. get(bi: Body, bj: Body): boolean;
  1117. set(bi: Body, bj: Body, value: boolean): void;
  1118. reset(): void;
  1119. setNumObjects(n: number): void;
  1120. }
  1121. }
  1122. declare module "collision/GridBroadphase" {
  1123. import { Broadphase } from "collision/Broadphase";
  1124. import { Vec3 } from "math/Vec3";
  1125. import type { Body } from "objects/Body";
  1126. import type { World } from "world/World";
  1127. export class GridBroadphase extends Broadphase {
  1128. nx: number;
  1129. ny: number;
  1130. nz: number;
  1131. aabbMin: Vec3;
  1132. aabbMax: Vec3;
  1133. bins: Body[][];
  1134. binLengths: number[];
  1135. constructor(aabbMin?: Vec3, aabbMax?: Vec3, nx?: number, ny?: number, nz?: number);
  1136. collisionPairs(world: World, pairs1: Body[], pairs2: Body[]): void;
  1137. }
  1138. }
  1139. declare module "collision/SAPBroadphase" {
  1140. import { Broadphase } from "collision/Broadphase";
  1141. import type { AABB } from "collision/AABB";
  1142. import type { Body } from "objects/Body";
  1143. import type { World } from "world/World";
  1144. export class SAPBroadphase extends Broadphase {
  1145. axisList: Body[];
  1146. world: World | null;
  1147. axisIndex: 0 | 1 | 2;
  1148. private _addBodyHandler;
  1149. private _removeBodyHandler;
  1150. static checkBounds(bi: Body, bj: Body, axisIndex: 0 | 1 | 2): boolean;
  1151. static insertionSortX(a: Body[]): Body[];
  1152. static insertionSortY(a: Body[]): Body[];
  1153. static insertionSortZ(a: Body[]): Body[];
  1154. constructor(world: World);
  1155. setWorld(world: World): void;
  1156. collisionPairs(world: World, p1: Body[], p2: Body[]): void;
  1157. sortList(): void;
  1158. autoDetectAxis(): void;
  1159. aabbQuery(world: World, aabb: AABB, result?: Body[]): Body[];
  1160. }
  1161. }
  1162. declare module "constraints/PointToPointConstraint" {
  1163. import { Constraint } from "constraints/Constraint";
  1164. import { ContactEquation } from "equations/ContactEquation";
  1165. import { Vec3 } from "math/Vec3";
  1166. import type { Body } from "objects/Body";
  1167. export class PointToPointConstraint extends Constraint {
  1168. pivotA: Vec3;
  1169. pivotB: Vec3;
  1170. equationX: ContactEquation;
  1171. equationY: ContactEquation;
  1172. equationZ: ContactEquation;
  1173. constructor(bodyA: Body, pivotA: Vec3 | undefined, bodyB: Body, pivotB?: Vec3, maxForce?: number);
  1174. update(): void;
  1175. }
  1176. }
  1177. declare module "equations/ConeEquation" {
  1178. import { Vec3 } from "math/Vec3";
  1179. import { Equation } from "equations/Equation";
  1180. import type { Body } from "objects/Body";
  1181. export type ConeEquationOptions = ConstructorParameters<typeof ConeEquation>[2];
  1182. export class ConeEquation extends Equation {
  1183. axisA: Vec3;
  1184. axisB: Vec3;
  1185. angle: number;
  1186. constructor(bodyA: Body, bodyB: Body, options?: {
  1187. maxForce?: number;
  1188. axisA?: Vec3;
  1189. axisB?: Vec3;
  1190. angle?: number;
  1191. });
  1192. computeB(h: number): number;
  1193. }
  1194. }
  1195. declare module "equations/RotationalEquation" {
  1196. import { Equation } from "equations/Equation";
  1197. import { Vec3 } from "math/Vec3";
  1198. import type { Body } from "objects/Body";
  1199. export type RotationalEquationOptions = ConstructorParameters<typeof RotationalEquation>[2];
  1200. export class RotationalEquation extends Equation {
  1201. axisA: Vec3;
  1202. axisB: Vec3;
  1203. maxAngle: number;
  1204. constructor(bodyA: Body, bodyB: Body, options?: {
  1205. axisA?: Vec3;
  1206. axisB?: Vec3;
  1207. maxAngle?: number;
  1208. maxForce?: number;
  1209. });
  1210. computeB(h: number): number;
  1211. }
  1212. }
  1213. declare module "constraints/ConeTwistConstraint" {
  1214. import { PointToPointConstraint } from "constraints/PointToPointConstraint";
  1215. import { ConeEquation } from "equations/ConeEquation";
  1216. import { RotationalEquation } from "equations/RotationalEquation";
  1217. import { Vec3 } from "math/Vec3";
  1218. import type { Body } from "objects/Body";
  1219. export type ConeTwistConstraintOptions = ConstructorParameters<typeof ConeTwistConstraint>[2];
  1220. export class ConeTwistConstraint extends PointToPointConstraint {
  1221. axisA: Vec3;
  1222. axisB: Vec3;
  1223. angle: number;
  1224. twistAngle: number;
  1225. coneEquation: ConeEquation;
  1226. twistEquation: RotationalEquation;
  1227. constructor(bodyA: Body, bodyB: Body, options?: {
  1228. pivotA?: Vec3;
  1229. pivotB?: Vec3;
  1230. axisA?: Vec3;
  1231. axisB?: Vec3;
  1232. angle?: number;
  1233. twistAngle?: number;
  1234. maxForce?: number;
  1235. collideConnected?: boolean;
  1236. });
  1237. update(): void;
  1238. }
  1239. }
  1240. declare module "constraints/DistanceConstraint" {
  1241. import { Constraint } from "constraints/Constraint";
  1242. import { ContactEquation } from "equations/ContactEquation";
  1243. import type { Body } from "objects/Body";
  1244. export class DistanceConstraint extends Constraint {
  1245. distance: number;
  1246. distanceEquation: ContactEquation;
  1247. constructor(bodyA: Body, bodyB: Body, distance?: number, maxForce?: number);
  1248. update(): void;
  1249. }
  1250. }
  1251. declare module "equations/RotationalMotorEquation" {
  1252. import { Equation } from "equations/Equation";
  1253. import { Vec3 } from "math/Vec3";
  1254. import type { Body } from "objects/Body";
  1255. export class RotationalMotorEquation extends Equation {
  1256. axisA: Vec3;
  1257. axisB: Vec3;
  1258. targetVelocity: number;
  1259. constructor(bodyA: Body, bodyB: Body, maxForce?: number);
  1260. computeB(h: number): number;
  1261. }
  1262. }
  1263. declare module "constraints/LockConstraint" {
  1264. import { PointToPointConstraint } from "constraints/PointToPointConstraint";
  1265. import { RotationalEquation } from "equations/RotationalEquation";
  1266. import { Vec3 } from "math/Vec3";
  1267. import type { Body } from "objects/Body";
  1268. import type { RotationalMotorEquation } from "equations/RotationalMotorEquation";
  1269. export type LockConstraintOptions = ConstructorParameters<typeof LockConstraint>[2];
  1270. export class LockConstraint extends PointToPointConstraint {
  1271. xA: Vec3;
  1272. xB: Vec3;
  1273. yA: Vec3;
  1274. yB: Vec3;
  1275. zA: Vec3;
  1276. zB: Vec3;
  1277. rotationalEquation1: RotationalEquation;
  1278. rotationalEquation2: RotationalEquation;
  1279. rotationalEquation3: RotationalEquation;
  1280. motorEquation?: RotationalMotorEquation;
  1281. constructor(bodyA: Body, bodyB: Body, options?: {
  1282. maxForce?: number;
  1283. });
  1284. update(): void;
  1285. }
  1286. }
  1287. declare module "constraints/HingeConstraint" {
  1288. import { PointToPointConstraint } from "constraints/PointToPointConstraint";
  1289. import { RotationalEquation } from "equations/RotationalEquation";
  1290. import { RotationalMotorEquation } from "equations/RotationalMotorEquation";
  1291. import { Vec3 } from "math/Vec3";
  1292. import type { Body } from "objects/Body";
  1293. export type HingeConstraintOptions = ConstructorParameters<typeof HingeConstraint>[2];
  1294. export class HingeConstraint extends PointToPointConstraint {
  1295. axisA: Vec3;
  1296. axisB: Vec3;
  1297. rotationalEquation1: RotationalEquation;
  1298. rotationalEquation2: RotationalEquation;
  1299. motorEquation: RotationalMotorEquation;
  1300. constructor(bodyA: Body, bodyB: Body, options?: {
  1301. pivotA?: Vec3;
  1302. pivotB?: Vec3;
  1303. axisA?: Vec3;
  1304. axisB?: Vec3;
  1305. collideConnected?: boolean;
  1306. maxForce?: number;
  1307. });
  1308. enableMotor(): void;
  1309. disableMotor(): void;
  1310. setMotorSpeed(speed: number): void;
  1311. setMotorMaxForce(maxForce: number): void;
  1312. update(): void;
  1313. }
  1314. }
  1315. declare module "objects/Spring" {
  1316. import { Vec3 } from "math/Vec3";
  1317. import type { Body } from "objects/Body";
  1318. export type SpringOptions = ConstructorParameters<typeof Spring>[2];
  1319. export class Spring {
  1320. restLength: number;
  1321. stiffness: number;
  1322. damping: number;
  1323. bodyA: Body;
  1324. bodyB: Body;
  1325. localAnchorA: Vec3;
  1326. localAnchorB: Vec3;
  1327. constructor(bodyA: Body, bodyB: Body, options?: {
  1328. restLength?: number;
  1329. stiffness?: number;
  1330. damping?: number;
  1331. localAnchorA?: Vec3;
  1332. localAnchorB?: Vec3;
  1333. worldAnchorA?: Vec3;
  1334. worldAnchorB?: Vec3;
  1335. });
  1336. setWorldAnchorA(worldAnchorA: Vec3): void;
  1337. setWorldAnchorB(worldAnchorB: Vec3): void;
  1338. getWorldAnchorA(result: Vec3): void;
  1339. getWorldAnchorB(result: Vec3): void;
  1340. applyForce(): void;
  1341. }
  1342. }
  1343. declare module "objects/WheelInfo" {
  1344. import { Vec3 } from "math/Vec3";
  1345. import { Transform } from "math/Transform";
  1346. import { RaycastResult } from "collision/RaycastResult";
  1347. import type { Body } from "objects/Body";
  1348. export type WheelInfoOptions = ConstructorParameters<typeof WheelInfo>[0];
  1349. export type WheelRaycastResult = RaycastResult & Partial<{
  1350. suspensionLength: number;
  1351. directionWorld: Vec3;
  1352. groundObject: number;
  1353. }>;
  1354. export class WheelInfo {
  1355. maxSuspensionTravel: number;
  1356. customSlidingRotationalSpeed: number;
  1357. useCustomSlidingRotationalSpeed: boolean;
  1358. sliding: boolean;
  1359. chassisConnectionPointLocal: Vec3;
  1360. chassisConnectionPointWorld: Vec3;
  1361. directionLocal: Vec3;
  1362. directionWorld: Vec3;
  1363. axleLocal: Vec3;
  1364. axleWorld: Vec3;
  1365. suspensionRestLength: number;
  1366. suspensionMaxLength: number;
  1367. radius: number;
  1368. suspensionStiffness: number;
  1369. dampingCompression: number;
  1370. dampingRelaxation: number;
  1371. frictionSlip: number;
  1372. forwardAcceleration: number;
  1373. sideAcceleration: number;
  1374. steering: number;
  1375. rotation: number;
  1376. deltaRotation: number;
  1377. rollInfluence: number;
  1378. maxSuspensionForce: number;
  1379. engineForce: number;
  1380. brake: number;
  1381. isFrontWheel: boolean;
  1382. clippedInvContactDotSuspension: number;
  1383. suspensionRelativeVelocity: number;
  1384. suspensionForce: number;
  1385. slipInfo: number;
  1386. skidInfo: number;
  1387. suspensionLength: number;
  1388. sideImpulse: number;
  1389. forwardImpulse: number;
  1390. raycastResult: WheelRaycastResult;
  1391. worldTransform: Transform;
  1392. isInContact: boolean;
  1393. constructor(options?: {
  1394. chassisConnectionPointLocal?: Vec3;
  1395. chassisConnectionPointWorld?: Vec3;
  1396. directionLocal?: Vec3;
  1397. directionWorld?: Vec3;
  1398. axleLocal?: Vec3;
  1399. axleWorld?: Vec3;
  1400. suspensionRestLength?: number;
  1401. suspensionMaxLength?: number;
  1402. radius?: number;
  1403. suspensionStiffness?: number;
  1404. dampingCompression?: number;
  1405. dampingRelaxation?: number;
  1406. frictionSlip?: number;
  1407. forwardAcceleration?: number;
  1408. sideAcceleration?: number;
  1409. steering?: number;
  1410. rotation?: number;
  1411. deltaRotation?: number;
  1412. rollInfluence?: number;
  1413. maxSuspensionForce?: number;
  1414. isFrontWheel?: boolean;
  1415. clippedInvContactDotSuspension?: number;
  1416. suspensionRelativeVelocity?: number;
  1417. suspensionForce?: number;
  1418. slipInfo?: number;
  1419. skidInfo?: number;
  1420. suspensionLength?: number;
  1421. maxSuspensionTravel?: number;
  1422. useCustomSlidingRotationalSpeed?: boolean;
  1423. customSlidingRotationalSpeed?: number;
  1424. });
  1425. updateWheel(chassis: Body): void;
  1426. }
  1427. }
  1428. declare module "objects/RaycastVehicle" {
  1429. import type { Body } from "objects/Body";
  1430. import { WheelInfo } from "objects/WheelInfo";
  1431. import type { WheelInfoOptions } from "objects/WheelInfo";
  1432. import type { Transform } from "math/Transform";
  1433. import type { Constraint } from "constraints/Constraint";
  1434. import type { World } from "world/World";
  1435. export type RaycastVehicleOptions = ConstructorParameters<typeof RaycastVehicle>[0];
  1436. export class RaycastVehicle {
  1437. chassisBody: Body;
  1438. wheelInfos: WheelInfo[];
  1439. sliding: boolean;
  1440. world: World | null;
  1441. indexRightAxis: number;
  1442. indexForwardAxis: number;
  1443. indexUpAxis: number;
  1444. constraints: Constraint[];
  1445. preStepCallback: () => void;
  1446. currentVehicleSpeedKmHour: number;
  1447. numWheelsOnGround: number;
  1448. constructor(options: {
  1449. chassisBody: Body;
  1450. indexRightAxis?: number;
  1451. indexForwardAxis?: number;
  1452. indexUpAxis?: number;
  1453. });
  1454. addWheel(options?: WheelInfoOptions): number;
  1455. setSteeringValue(value: number, wheelIndex: number): void;
  1456. applyEngineForce(value: number, wheelIndex: number): void;
  1457. setBrake(brake: number, wheelIndex: number): void;
  1458. addToWorld(world: World): void;
  1459. private getVehicleAxisWorld;
  1460. updateVehicle(timeStep: number): void;
  1461. updateSuspension(deltaTime: number): void;
  1462. removeFromWorld(world: World): void;
  1463. castRay(wheel: WheelInfo): number;
  1464. updateWheelTransformWorld(wheel: WheelInfo): void;
  1465. updateWheelTransform(wheelIndex: number): void;
  1466. getWheelTransformWorld(wheelIndex: number): Transform;
  1467. updateFriction(timeStep: number): void;
  1468. }
  1469. }
  1470. declare module "objects/RigidVehicle" {
  1471. import { Vec3 } from "math/Vec3";
  1472. import { Body } from "objects/Body";
  1473. import { HingeConstraint } from "constraints/HingeConstraint";
  1474. import type { World } from "world/World";
  1475. export type RigidVehicleOptions = ConstructorParameters<typeof RigidVehicle>[0];
  1476. export class RigidVehicle {
  1477. wheelBodies: Body[];
  1478. coordinateSystem: Vec3;
  1479. chassisBody: Body;
  1480. constraints: (HingeConstraint & {
  1481. motorTargetVelocity?: number;
  1482. })[];
  1483. wheelAxes: Vec3[];
  1484. wheelForces: number[];
  1485. constructor(options?: {
  1486. coordinateSystem?: Vec3;
  1487. chassisBody?: Body;
  1488. });
  1489. addWheel(options?: {
  1490. body?: Body;
  1491. position?: Vec3;
  1492. axis?: Vec3;
  1493. direction?: Vec3;
  1494. }): number;
  1495. setSteeringValue(value: number, wheelIndex: number): void;
  1496. setMotorSpeed(value: number, wheelIndex: number): void;
  1497. disableMotor(wheelIndex: number): void;
  1498. setWheelForce(value: number, wheelIndex: number): void;
  1499. applyWheelForce(value: number, wheelIndex: number): void;
  1500. addToWorld(world: World): void;
  1501. private _update;
  1502. removeFromWorld(world: World): void;
  1503. getWheelSpeed(wheelIndex: number): number;
  1504. }
  1505. }
  1506. declare module "objects/SPHSystem" {
  1507. import { Vec3 } from "math/Vec3";
  1508. import type { Body } from "objects/Body";
  1509. export class SPHSystem {
  1510. particles: Body[];
  1511. density: number;
  1512. smoothingRadius: number;
  1513. speedOfSound: number;
  1514. viscosity: number;
  1515. eps: number;
  1516. pressures: number[];
  1517. densities: number[];
  1518. neighbors: Body[][];
  1519. constructor();
  1520. add(particle: Body): void;
  1521. remove(particle: Body): void;
  1522. getNeighbors(particle: Body, neighbors: Body[]): void;
  1523. update(): void;
  1524. w(r: number): number;
  1525. gradw(rVec: Vec3, resultVec: Vec3): void;
  1526. nablaw(r: number): number;
  1527. }
  1528. }
  1529. declare module "solver/SplitSolver" {
  1530. import { Solver } from "solver/Solver";
  1531. import { Body } from "objects/Body";
  1532. import type { Equation } from "equations/Equation";
  1533. import type { World } from "world/World";
  1534. import { GSSolver } from "solver/GSSolver";
  1535. type SplitSolverNode = {
  1536. body: Body | null;
  1537. children: SplitSolverNode[];
  1538. eqs: Equation[];
  1539. visited: boolean;
  1540. };
  1541. export class SplitSolver extends Solver {
  1542. iterations: number;
  1543. tolerance: number;
  1544. subsolver: GSSolver;
  1545. nodes: SplitSolverNode[];
  1546. nodePool: SplitSolverNode[];
  1547. constructor(subsolver: GSSolver);
  1548. createNode(): SplitSolverNode;
  1549. solve(dt: number, world: World): number;
  1550. }
  1551. }
  1552. declare module "cannon-es" {
  1553. export * from "collision/ObjectCollisionMatrix";
  1554. export * from "collision/AABB";
  1555. export * from "collision/ArrayCollisionMatrix";
  1556. export * from "collision/Broadphase";
  1557. export * from "collision/GridBroadphase";
  1558. export * from "collision/NaiveBroadphase";
  1559. export * from "collision/Ray";
  1560. export * from "collision/RaycastResult";
  1561. export * from "collision/SAPBroadphase";
  1562. export * from "constraints/ConeTwistConstraint";
  1563. export * from "constraints/Constraint";
  1564. export * from "constraints/DistanceConstraint";
  1565. export * from "constraints/LockConstraint";
  1566. export * from "constraints/PointToPointConstraint";
  1567. export * from "constraints/HingeConstraint";
  1568. export * from "equations/ContactEquation";
  1569. export * from "equations/Equation";
  1570. export * from "equations/FrictionEquation";
  1571. export * from "equations/RotationalEquation";
  1572. export * from "equations/RotationalMotorEquation";
  1573. export * from "material/ContactMaterial";
  1574. export * from "material/Material";
  1575. export * from "math/Quaternion";
  1576. export * from "math/Mat3";
  1577. export * from "math/Transform";
  1578. export * from "math/Vec3";
  1579. export * from "math/JacobianElement";
  1580. export * from "objects/Body";
  1581. export * from "objects/Spring";
  1582. export * from "objects/RaycastVehicle";
  1583. export * from "objects/WheelInfo";
  1584. export * from "objects/RigidVehicle";
  1585. export * from "objects/SPHSystem";
  1586. export * from "shapes/Box";
  1587. export * from "shapes/ConvexPolyhedron";
  1588. export * from "shapes/Cylinder";
  1589. export * from "shapes/Particle";
  1590. export * from "shapes/Plane";
  1591. export * from "shapes/Shape";
  1592. export * from "shapes/Sphere";
  1593. export * from "shapes/Heightfield";
  1594. export * from "shapes/Trimesh";
  1595. export * from "solver/GSSolver";
  1596. export * from "solver/Solver";
  1597. export * from "solver/SplitSolver";
  1598. export * from "utils/Pool";
  1599. export * from "utils/EventTarget";
  1600. export * from "utils/Vec3Pool";
  1601. export * from "world/Narrowphase";
  1602. export * from "world/World";
  1603. }