cannon.d.ts 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210
  1. declare module CANNON {
  2. export interface IAABBOptions {
  3. upperBound?: Vec3;
  4. lowerBound?: Vec3;
  5. }
  6. export class AABB {
  7. lowerBound: Vec3;
  8. upperBound: Vec3;
  9. constructor(options?: IAABBOptions);
  10. clone() : AABB;
  11. setFromPoints(points: Vec3[], position?: Vec3, quaternion?: Quaternion, skinSize?: number): void;
  12. copy(aabb: AABB): void;
  13. extend(aabb: AABB): void;
  14. getCorners( a: Vec3, b: Vec3, c: Vec3, d: Vec3, e: Vec3, f: Vec3, g: Vec3, h: Vec3 ) : void;
  15. overlaps(aabb: AABB): boolean;
  16. toLocalFrame( frame: Transform, target: AABB ) : AABB;
  17. toWorldFrame( frame: Transform, target: AABB ) : AABB;
  18. }
  19. export class ArrayCollisionMatrix {
  20. matrix: Mat3[];
  21. get(i: number, j: number): number;
  22. set(i: number, j: number, value?: number): void;
  23. reset(): void;
  24. setNumObjects(n: number): void;
  25. }
  26. export class Broadphase {
  27. world: World;
  28. useBoundingBoxes: boolean;
  29. dirty: boolean;
  30. collisionPairs(world: World, p1: Body[], p2: Body[]): void;
  31. needBroadphaseCollision(bodyA: Body, bodyB: Body): boolean;
  32. intersectionTest(bodyA: Body, bodyB: Body, pairs1: Body[], pairs2: Body[]): void;
  33. doBoundingSphereBroadphase(bodyA: Body, bodyB: Body, pairs1: Body[], pairs2: Body[]): void;
  34. doBoundingBoxBroadphase(bodyA: Body, bodyB: Body, pairs1: Body[], pairs2: Body[]): void;
  35. makePairsUnique(pairs1: Body[], pairs2: Body[]): void;
  36. setWorld(world: World): void;
  37. boundingSphereCheck(bodyA: Body, bodyB: Body): boolean;
  38. aabbQuery(world: World, aabb: AABB, result: Body[]): Body[];
  39. }
  40. export class GridBroadphase extends Broadphase {
  41. nx: number;
  42. ny: number;
  43. nz: number;
  44. aabbMin: Vec3;
  45. aabbMax: Vec3;
  46. bins: any[];
  47. constructor(aabbMin?: Vec3, aabbMax?: Vec3, nx?: number, ny?: number, nz?: number);
  48. }
  49. export class NaiveBroadphase extends Broadphase {
  50. }
  51. export class ObjectCollisionMatrix {
  52. matrix: number[];
  53. get(i: number, j: number): number;
  54. set(i: number, j: number, value: number): void;
  55. reset(): void;
  56. setNumObjects(n: number): void;
  57. }
  58. export interface IRayIntersectWorldOptions {
  59. mode: number;
  60. result: boolean;
  61. skipBackfaces: boolean;
  62. collisionFilterMask: number;
  63. collisionFilterGroup: number;
  64. from: Vec3;
  65. to: Vec3;
  66. callback: Function;
  67. }
  68. export class Ray {
  69. static CLOSEST: number;
  70. static ANY: number;
  71. static ALL: number;
  72. from: Vec3;
  73. to: Vec3;
  74. precision: number;
  75. checkCollisionResponse: boolean;
  76. callback: Function;
  77. collisionFilterGroup: number;
  78. collisionFilterMask: number;
  79. hasHit: boolean;
  80. mode: number;
  81. result: RaycastResult;
  82. skipBackfaces: boolean;
  83. constructor(from?: Vec3, to?: Vec3);
  84. getAABB(result: RaycastResult): void;
  85. intersectBodies(bodies: Body[], result?: RaycastResult): void;
  86. intersectWorld(world: World, options: any): boolean;
  87. }
  88. export class RaycastResult {
  89. rayFromWorld: Vec3;
  90. rayToWorld: Vec3;
  91. hitNormalWorld: Vec3;
  92. hitPointWorld: Vec3;
  93. hitFaceIndex: number;
  94. hasHit: boolean;
  95. shape: Shape;
  96. body: Body;
  97. distance: number;
  98. abort(): void;
  99. reset(): void;
  100. set(rayFromWorld: Vec3, rayToWorld: Vec3, hitNormalWorld: Vec3, hitPointWorld: Vec3, shape: Shape, body: Body, distance: number): void;
  101. }
  102. export class SAPBroadphase extends Broadphase {
  103. static insertionSortX(a: any[]): any[];
  104. static insertionSortY(a: any[]): any[];
  105. static insertionSortZ(a: any[]): any[];
  106. static checkBounds(bi: Body, bj: Body, axisIndex?: number): boolean;
  107. axisList: any[];
  108. world: World;
  109. axisIndex: number;
  110. constructor(world?: World);
  111. autoDetectAxis(): void;
  112. aabbQuery(world: World, aabb: AABB, result?: Body[]): Body[];
  113. }
  114. export interface IConstraintOptions {
  115. collideConnected?: boolean;
  116. wakeUpBodies?: boolean;
  117. }
  118. export class Constraint {
  119. equations: any[];
  120. bodyA: Body;
  121. bodyB: Body;
  122. id: number;
  123. collideConnected: boolean;
  124. constructor(bodyA: Body, bodyB: Body, options?: IConstraintOptions);
  125. update(): void;
  126. disable(): void;
  127. enable(): void;
  128. }
  129. export class DistanceConstraint extends Constraint {
  130. distance: number;
  131. distanceEquation: ContactEquation;
  132. constructor(bodyA: Body, bodyB: Body, distance?: number, maxForce?: number);
  133. }
  134. export interface IHingeConstraintOptions {
  135. pivotA?: Vec3;
  136. axisA?: Vec3;
  137. pivotB?: Vec3;
  138. axisB?: Vec3;
  139. maxForce?: number;
  140. }
  141. export class HingeConstraint extends Constraint {
  142. axisA: Vec3;
  143. axisB: Vec3;
  144. rotationalEquation1: RotationalEquation;
  145. rotationalEquation2: RotationalEquation;
  146. motorEnabled: boolean;
  147. motorTargetVelocity: number;
  148. motorMinForce: number;
  149. motorMaxForce: number;
  150. motorEquation: RotationalMotorEquation;
  151. constructor(bodyA: Body, bodyB: Body, options?: IHingeConstraintOptions);
  152. enableMotor(): void;
  153. disableMotor(): void;
  154. setMotorMaxForce(maxForce: number): void;
  155. setMotorSpeed(speed: number): void;
  156. }
  157. export class PointToPointConstraint extends Constraint {
  158. equationX: ContactEquation;
  159. equationY: ContactEquation;
  160. equationZ: ContactEquation;
  161. pivotA: Vec3;
  162. pivotB: Vec3;
  163. constructor(bodyA: Body, pivotA: Vec3, bodyB: Body, pivotB: Vec3, maxForce?: number);
  164. }
  165. export class ConeTwistConstraint extends PointToPointConstraint {
  166. coneEquation: ConeEquation;
  167. twistEquation: RotationalEquation;
  168. constructor(bodyA: Body, bodyB: Body, options?: IHingeConstraintOptions);
  169. }
  170. export class LockConstraint extends PointToPointConstraint {
  171. rotationalEquation1: RotationalEquation;
  172. rotationalEquation2: RotationalEquation;
  173. rotationalEquation3: RotationalEquation;
  174. constructor(bodyA: Body, bodyB: Body, maxForce?: number);
  175. }
  176. export class Equation {
  177. id: number;
  178. minForce: number;
  179. maxForce: number;
  180. bi: Body;
  181. bj: Body;
  182. a: number;
  183. b: number;
  184. eps: number;
  185. jacobianElementA: JacobianElement;
  186. jacobianElementB: JacobianElement;
  187. enabled: boolean;
  188. constructor(bi: Body, bj: Body, minForce?: number, maxForce?: number);
  189. setSpookParams(stiffness: number, relaxation: number, timeStep: number): void;
  190. computeB(a: number, b: number, h: number): number;
  191. computeGq(): number;
  192. computeGW(): number;
  193. computeGWlamda(): number;
  194. computeGiMf(): number;
  195. computeGiMGt(): number;
  196. addToWlamda(deltalambda: number): number;
  197. computeC(): number;
  198. computeInvC( eps: number ): number;
  199. }
  200. export class FrictionEquation extends Equation {
  201. constructor(bi: Body, bj: Body, slipForce: number);
  202. }
  203. export interface IRotationalEquationOptions {
  204. axisA?: Vec3;
  205. axisB?: Vec3;
  206. maxForce?: number;
  207. }
  208. export class RotationalEquation extends Equation {
  209. ni: Vec3;
  210. nj: Vec3;
  211. nixnj: Vec3;
  212. njxni: Vec3;
  213. invIi: Mat3;
  214. invIj: Mat3;
  215. relVel: Vec3;
  216. relForce: Vec3;
  217. constructor(bodyA: Body, bodyB: Body, options?: IRotationalEquationOptions);
  218. }
  219. export class RotationalMotorEquation extends Equation {
  220. axisA: Vec3;
  221. axisB: Vec3;
  222. invLi: Mat3;
  223. invIj: Mat3;
  224. targetVelocity: number;
  225. constructor(bodyA: Body, bodyB: Body, maxForce?: number);
  226. }
  227. export interface IConeEquationOptions {
  228. axisA?: Vec3;
  229. axisB?: Vec3;
  230. maxForce?: number;
  231. }
  232. export class ConeEquation extends Equation {
  233. angle: number;
  234. constructor(bodyA: Body, bodyB: Body, options?: IConeEquationOptions);
  235. }
  236. export class ContactEquation extends Equation {
  237. restitution: number;
  238. ri: Vec3;
  239. rj: Vec3;
  240. ni: Vec3;
  241. constructor(bi: Body, bj: Body);
  242. getImpactVelocityAlongNormal(): number;
  243. }
  244. export interface IContactMaterialOptions {
  245. friction?: number;
  246. restitution?: number;
  247. contactEquationStiffness?: number;
  248. contactEquationRelaxation?: number;
  249. frictionEquationStiffness?: number;
  250. frictionEquationRelaxation?: number;
  251. }
  252. export class ContactMaterial {
  253. id: number;
  254. materials: Material[];
  255. friction: number;
  256. restitution: number;
  257. contactEquationStiffness: number;
  258. contactEquationRelaxation: number;
  259. frictionEquationStiffness: number;
  260. frictionEquationRelaxation: number;
  261. constructor(m1: Material, m2: Material, options?: IContactMaterialOptions);
  262. }
  263. export interface IMaterialOptions {
  264. friction?: number;
  265. restitution?: number;
  266. }
  267. export class Material {
  268. name: string;
  269. id: number;
  270. friction:number;
  271. restitution:number;
  272. constructor(options?: string|IMaterialOptions);
  273. }
  274. export class JacobianElement {
  275. spatial: Vec3;
  276. rotational: Vec3;
  277. multiplyElement(element: JacobianElement): number;
  278. multiplyVectors(spacial: Vec3, rotational: Vec3): number;
  279. }
  280. export class Mat3 {
  281. elements: number[];
  282. constructor(elements?: number[]);
  283. identity(): void;
  284. setZero(): void;
  285. setTrace(vec3: Vec3): void;
  286. getTrace(target: Vec3): void;
  287. vmult(v: Vec3, target?: Vec3): Vec3;
  288. smult(s: number): void;
  289. mmult(m: Mat3): Mat3;
  290. scale(v: Vec3, target?: Mat3): Mat3;
  291. solve(b: Vec3, target?: Vec3): Vec3;
  292. e(row: number, column: number, value?: number): number;
  293. copy(source: Mat3): Mat3;
  294. toString(): string;
  295. reverse(target?: Mat3): Mat3;
  296. setRotationFromQuaternion(q: Quaternion): Mat3;
  297. transpose(target?: Mat3): Mat3;
  298. }
  299. export class Trimesh extends Shape {
  300. aabb: AABB;
  301. edges: number[];
  302. indices: number[];
  303. normals: number[];
  304. scale: Vec3;
  305. tree: Octree;
  306. vertices: number[];
  307. static computeNormal(va: Vec3, vb: Vec3, vc: Vec3, target: Vec3): void;
  308. static createTorus(radius?: number, tube?: number, radialSegments?: number, tubularSegments?: number, arc?: number): Trimesh;
  309. constructor(vertices: number[], indices: number[]);
  310. calculateWorldAABB(pos: Vec3, quat: Quaternion, min: Vec3, max: Vec3): void;
  311. computeLocalAABB(aabb: AABB): void;
  312. getEdgeVector(edgeIndex: number, vectorStore: Vec3): void;
  313. getEdgeVertex(edgeIndex: number, firstOrSecond: number, vertexStore: Vec3): void;
  314. getNormal(i: number, target: Vec3): Vec3;
  315. getTrianglesAABB(aabb: AABB, result: number[]): void;
  316. getTriangleVertices(i: number, a: Vec3, b: Vec3, c: Vec3): void;
  317. getVertex(i: number, out: Vec3): Vec3;
  318. getWorldVertex(i: number, pos: Vec3, quat: Quaternion, out: Vec3): Vec3;
  319. setScale(scale: Vec3): void;
  320. updateAABB(): void;
  321. updateEdges(): void;
  322. updateNormals(): void;
  323. updateTree(): void;
  324. }
  325. export class Quaternion {
  326. x: number;
  327. y: number;
  328. z: number;
  329. w: number;
  330. constructor(x?: number, y?: number, z?: number, w?: number);
  331. set(x: number, y: number, z: number, w: number): void;
  332. toString(): string;
  333. toArray(): number[];
  334. setFromAxisAngle(axis: Vec3, angle: number): void;
  335. toAxisAngle(targetAxis?: Vec3): any[];
  336. setFromVectors(u: Vec3, v: Vec3): void;
  337. mult(q: Quaternion, target?: Quaternion): Quaternion;
  338. inverse(target?: Quaternion): Quaternion;
  339. conjugate(target?: Quaternion): Quaternion;
  340. normalize(): void;
  341. normalizeFast(): void;
  342. vmult(v: Vec3, target?: Vec3): Vec3;
  343. copy(source: Quaternion): Quaternion;
  344. toEuler(target: Vec3, order?: string): void;
  345. setFromEuler(x: number, y: number, z: number, order?: string): Quaternion;
  346. clone(): Quaternion;
  347. }
  348. export class Transform {
  349. static pointToLocalFrame(position: Vec3, quaternion: Quaternion, worldPoint: Vec3, result?: Vec3): Vec3;
  350. static pointToWorldFrame(position: Vec3, quaternion: Quaternion, localPoint: Vec3, result?: Vec3): Vec3;
  351. static vectorToWorldFrame(quaternion: Quaternion, localVector: Vec3, result: Vec3): Vec3;
  352. static vectorToLocalFrame(position: Vec3, quaternion: Quaternion, worldVector: Vec3, result?: Vec3): Vec3;
  353. position: Vec3;
  354. quaternion: Quaternion;
  355. pointToLocal(point: Vec3, result: Vec3): Vec3;
  356. pointToWorld(point: Vec3, result: Vec3): Vec3;
  357. }
  358. export class Vec3 {
  359. static ZERO: Vec3;
  360. static UNIT_X: Vec3;
  361. static UNIT_Y: Vec3;
  362. static UNIT_Z: Vec3;
  363. x: number;
  364. y: number;
  365. z: number;
  366. constructor(x?: number, y?: number, z?: number);
  367. cross(v: Vec3, target?: Vec3): Vec3;
  368. set(x: number, y: number, z: number): Vec3;
  369. setZero(): void;
  370. vadd(v: Vec3, target?: Vec3): Vec3;
  371. vsub(v: Vec3, target?: Vec3): Vec3;
  372. crossmat(): Mat3;
  373. normalize(): number;
  374. unit(target?: Vec3): Vec3;
  375. norm(): number;
  376. norm2(): number;
  377. distanceTo(p: Vec3): number;
  378. distanceSquared(p: Vec3): number;
  379. mult(scalar: number, target?: Vec3): Vec3;
  380. scale(scalar: number, target?: Vec3): Vec3;
  381. dot(v: Vec3): number;
  382. isZero(): boolean;
  383. negate(target?: Vec3): Vec3;
  384. tangents(t1: Vec3, t2: Vec3): void;
  385. toString(): string;
  386. toArray(): number[];
  387. copy(source: Vec3): Vec3;
  388. length(): number;
  389. lengthSquared(): number;
  390. lerp(v: Vec3, t: number, target?: Vec3): void;
  391. almostEquals(v: Vec3, precision?: number): boolean;
  392. almostZero(precision?: number): boolean;
  393. isAntiparallelTo(v: Vec3, prescision?: number): boolean;
  394. clone(): Vec3;
  395. }
  396. export interface IBodyOptions {
  397. position?: Vec3;
  398. velocity?: Vec3;
  399. angularVelocity?: Vec3;
  400. quaternion?: Quaternion;
  401. mass?: number;
  402. material?: Material;
  403. type?: number;
  404. linearDamping?: number;
  405. angularDamping?: number;
  406. allowSleep?: boolean;
  407. sleepSpeedLimit?: number;
  408. sleepTimeLimit?: number;
  409. collisionFilterGroup?: number;
  410. collisionFilterMask?: number;
  411. fixedRotation?: boolean;
  412. shape?: Shape;
  413. }
  414. export class Body extends EventTarget {
  415. static DYNAMIC: number;
  416. static STATIC: number;
  417. static KINEMATIC: number;
  418. static AWAKE: number;
  419. static SLEEPY: number;
  420. static SLEEPING: number;
  421. static sleepyEvent: IEvent;
  422. static sleepEvent: IEvent;
  423. id: number;
  424. //miner
  425. layaID:number;
  426. //miner
  427. isTrigger:boolean;
  428. world: World;
  429. preStep: Function;
  430. postStep: Function;
  431. vlambda: Vec3;
  432. collisionFilterGroup: number;
  433. collisionFilterMask: number;
  434. collisionResponse: boolean;
  435. position: Vec3;
  436. previousPosition: Vec3;
  437. initPosition: Vec3;
  438. boundingRadius: number;
  439. velocity: Vec3;
  440. initVelocity: Vec3;
  441. force: Vec3;
  442. mass: number;
  443. invMass: number;
  444. material: Material;
  445. linearDamping: number;
  446. type: number;
  447. allowSleep: boolean;
  448. sleepState: number;
  449. sleepSpeedLimit: number;
  450. sleepTimeLimit: number;
  451. timeLastSleepy: number;
  452. torque: Vec3;
  453. quaternion: Quaternion;
  454. initQuaternion: Quaternion;
  455. angularVelocity: Vec3;
  456. initAngularVelocity: Vec3;
  457. interpolatedPosition: Vec3;
  458. interpolatedQuaternion: Quaternion;
  459. shapes: Shape[];
  460. shapeOffsets: any[];
  461. shapeOrientations: any[];
  462. inertia: Vec3;
  463. invInertia: Vec3;
  464. invInertiaWorld: Mat3;
  465. invMassSolve: number;
  466. invInertiaSolve: Vec3;
  467. invInteriaWorldSolve: Mat3;
  468. fixedRotation: boolean;
  469. angularDamping: number;
  470. aabb: AABB;
  471. aabbNeedsUpdate: boolean;
  472. wlambda: Vec3;
  473. constructor(options?: IBodyOptions);
  474. wakeUp(): void;
  475. sleep(): void;
  476. sleepTick(time: number): void;
  477. pointToLocalFrame(worldPoint: Vec3, result?: Vec3): Vec3;
  478. pointToWorldFrame(localPoint: Vec3, result?: Vec3): Vec3;
  479. vectorToLocalFrame(worldPoint: Vec3, result?: Vec3): Vec3;
  480. vectorToWorldFrame(localVector: Vec3, result?: Vec3): Vec3;
  481. addShape(shape: Shape, offset?: Vec3, orientation?: Vec3): void;
  482. computeAABB(): void;
  483. applyForce(force: Vec3, worldPoint: Vec3): void;
  484. applyImpulse(impulse: Vec3, worldPoint: Vec3): void;
  485. applyLocalForce(force: Vec3, localPoint: Vec3): void;
  486. applyLocalImplse(impulse: Vec3, localPoint: Vec3): void;
  487. updateBoundingRadius(): void;
  488. updateMassProperties(): void;
  489. updateInertiaWorld(force: Vec3): void;
  490. updateSolveMassProperties(): void;
  491. getVelocityAtWorldPoint(worldPoint: Vec3, result: Vec3): Vec3;
  492. }
  493. export interface IWheelInfoOptions {
  494. chassisConnectionPointLocal?: Vec3;
  495. chassisConnectionPointWorld?: Vec3;
  496. directionLocal?: Vec3;
  497. directionWorld?: Vec3;
  498. axleLocal?: Vec3;
  499. axleWorld?: Vec3;
  500. suspensionRestLength?: number;
  501. suspensionMaxLength?: number;
  502. radius?: number;
  503. suspensionStiffness?: number;
  504. dampingCompression?: number;
  505. dampingRelaxation?: number;
  506. frictionSlip?: number;
  507. steering?: number;
  508. rotation?: number;
  509. deltaRotation?: number;
  510. rollInfluence?: number;
  511. maxSuspensionForce?: number;
  512. isFrontWheel?: boolean;
  513. clippedInvContactDotSuspension?: number;
  514. suspensionRelativeVelocity?: number;
  515. suspensionForce?: number;
  516. skidInfo?: number;
  517. suspensionLength?: number;
  518. maxSuspensionTravel?: number;
  519. useCustomSlidingRotationalSpeed?: boolean;
  520. customSlidingRotationalSpeed?: number;
  521. position?: Vec3;
  522. direction?: Vec3;
  523. axis?: Vec3;
  524. body?: Body;
  525. }
  526. export class WheelInfo {
  527. axleLocal: Vec3;
  528. axleWorld: Vec3;
  529. brake: number;
  530. chassisConnectionPointLocal: Vec3;
  531. chassisConnectionPointWorld: Vec3;
  532. clippedInvContactDotSuspension: number;
  533. customSlidingRotationalSpeed: number;
  534. dampingCompression: number;
  535. dampingRelaxation: number;
  536. deltaRotation: number;
  537. directionLocal: Vec3;
  538. directionWorld: Vec3;
  539. engineForce: number;
  540. forwardImpulse: number;
  541. frictionSlip: number;
  542. isFrontWheel: boolean;
  543. isInContact: boolean;
  544. maxSuspensionForce: number;
  545. maxSuspensionTravel: number;
  546. radius: number;
  547. raycastResult: RaycastResult;
  548. rollInfluence: number;
  549. rotation: number;
  550. sideImpulse: number;
  551. skidInfo: number;
  552. sliding: boolean;
  553. steering: number;
  554. suspensionForce: number;
  555. suspensionLength: number;
  556. suspensionMaxLength: number;
  557. suspensionRelativeVelocity: number;
  558. suspensionStiffness: number;
  559. suspensionRestLength: number;
  560. useCustomSlidingRotationalSpeed: boolean;
  561. worldTransform: Transform;
  562. constructor(options?: IWheelInfoOptions);
  563. }
  564. export interface IRaycastVehicleOptions {
  565. chassisBody?: Body;
  566. indexRightAxis?: number;
  567. indexLeftAxis?: number;
  568. indexUpAxis?: number;
  569. }
  570. export class RaycastVehicle {
  571. chassisBody: Body;
  572. wheelInfos: IWheelInfoOptions[];
  573. sliding: boolean;
  574. world: World;
  575. iindexRightAxis: number;
  576. indexForwardAxis: number;
  577. indexUpAxis: number;
  578. constructor(options?: IRaycastVehicleOptions);
  579. addWheel(options?: IWheelInfoOptions): void;
  580. setSteeringValue(value: number, wheelIndex: number): void;
  581. applyEngineForce(value: number, wheelIndex: number): void;
  582. setBrake(brake: number, wheelIndex: number): void;
  583. addToWorld(world: World): void;
  584. getVehicleAxisWorld(axisIndex: number, result: Vec3): Vec3;
  585. updateVehicle(timeStep: number): void;
  586. updateSuspension(deltaTime: number): void;
  587. updateWheelTransform(wheelIndex: number): void;
  588. removeFromWorld(world: World): void;
  589. getWheelTransformWorld(wheelIndex: number): Transform;
  590. }
  591. export interface IRigidVehicleOptions {
  592. chassisBody: Body;
  593. }
  594. export class RigidVehicle {
  595. wheelBodies: Body[];
  596. coordinateSystem: Vec3;
  597. chassisBody: Body;
  598. constraints: Constraint[];
  599. wheelAxes: Vec3[];
  600. wheelForces: Vec3[];
  601. constructor(options?: IRigidVehicleOptions);
  602. addWheel(options?: IWheelInfoOptions): Body;
  603. setSteeringValue(value: number, wheelIndex: number): void;
  604. setMotorSpeed(value: number, wheelIndex: number): void;
  605. disableMotor(wheelIndex: number): void;
  606. setWheelForce(value: number, wheelIndex: number): void;
  607. applyWheelForce(value: number, wheelIndex: number): void;
  608. addToWorld(world: World): void;
  609. removeFromWorld(world: World): void;
  610. getWheelSpeed(wheelIndex: number): number;
  611. }
  612. export class SPHSystem {
  613. particles: Particle[];
  614. density: number;
  615. smoothingRadius: number;
  616. speedOfSound: number;
  617. viscosity: number;
  618. eps: number;
  619. pressures: number[];
  620. densities: number[];
  621. neighbors: number[];
  622. add(particle: Particle): void;
  623. remove(particle: Particle): void;
  624. getNeighbors(particle: Particle, neighbors: Particle[]): void;
  625. update(): void;
  626. w(r: number): number;
  627. gradw(rVec: Vec3, resultVec: Vec3): void;
  628. nablaw(r: number): number;
  629. }
  630. export interface ISpringOptions {
  631. restLength?: number;
  632. stiffness?: number;
  633. damping?: number;
  634. worldAnchorA?: Vec3;
  635. worldAnchorB?: Vec3;
  636. localAnchorA?: Vec3;
  637. localAnchorB?: Vec3;
  638. }
  639. export class Spring {
  640. restLength: number;
  641. stffness: number;
  642. damping: number;
  643. bodyA: Body;
  644. bodyB: Body;
  645. localAnchorA: Vec3;
  646. localAnchorB: Vec3;
  647. constructor(options?: ISpringOptions);
  648. setWorldAnchorA(worldAnchorA: Vec3): void;
  649. setWorldAnchorB(worldAnchorB: Vec3): void;
  650. getWorldAnchorA(result: Vec3): void;
  651. getWorldAnchorB(result: Vec3): void;
  652. applyForce(): void;
  653. }
  654. export class Box extends Shape {
  655. static calculateInertia(halfExtents: Vec3, mass: number, target: Vec3): void;
  656. halfExtents: Vec3;
  657. convexPolyhedronRepresentation: ConvexPolyhedron;
  658. constructor(halfExtents: Vec3);
  659. updateConvexPolyhedronRepresentation(): void;
  660. getSideNormals(sixTargetVectors: boolean, quat?: Quaternion): Vec3[];
  661. forEachWorldCorner(pos: Vec3, quat: Quaternion, callback: Function): void;
  662. }
  663. export class ConvexPolyhedron extends Shape {
  664. static computeNormal(va: Vec3, vb: Vec3, vc: Vec3, target: Vec3): void;
  665. static project(hull: ConvexPolyhedron, axis: Vec3, pos: Vec3, quat: Quaternion, result: number[]): void;
  666. static getFaceNormal(va: Vec3, vb: Vec3, vc: Vec3, target: Vec3): void;
  667. vertices: Vec3[];
  668. worldVertices: Vec3[];
  669. worldVerticesNeedsUpdate: boolean;
  670. faces: number[];
  671. faceNormals: Vec3[];
  672. uniqueEdges: Vec3[];
  673. uniqueAxes: Vec3[];
  674. constructor(points?: Vec3[], faces?: number[]);
  675. computeEdges(): void;
  676. computeNormals(): void;
  677. getFaceNormal(i: number, target: Vec3): Vec3;
  678. clipAgainstHull(posA: Vec3, quatA: Quaternion, hullB: Vec3, quatB: Quaternion, separatingNormal: Vec3, minDist: number, maxDist: number, result: any[]): void;
  679. findSeparatingAxis(hullB: ConvexPolyhedron, posA: Vec3, quatA: Quaternion, posB: Vec3, quatB: Quaternion, target: Vec3, faceListA: any[], faceListB: any[]): boolean;
  680. testSepAxis(axis: Vec3, hullB: ConvexPolyhedron, posA: Vec3, quatA: Quaternion, posB: Vec3, quatB: Quaternion): number;
  681. getPlaneConstantOfFace(face_i: number): number;
  682. clipFaceAgainstHull(separatingNormal: Vec3, posA: Vec3, quatA: Quaternion, worldVertsB1: Vec3[], minDist: number, maxDist: number, result: any[]): void;
  683. clipFaceAgainstPlane(inVertices: Vec3[], outVertices: Vec3[], planeNormal: Vec3, planeConstant: number): Vec3;
  684. computeWorldVertices(position: Vec3, quat: Quaternion): void;
  685. computeLocalAABB(aabbmin: Vec3, aabbmax: Vec3): void;
  686. computeWorldFaceNormals(quat: Quaternion): void;
  687. calculateWorldAABB(pos: Vec3, quat: Quaternion, min: Vec3, max: Vec3): void;
  688. getAveragePointLocal(target: Vec3): Vec3;
  689. transformAllPoints(offset: Vec3, quat: Quaternion): void;
  690. pointIsInside(p: Vec3): boolean;
  691. }
  692. export class Cylinder extends ConvexPolyhedron {
  693. constructor(radiusTop: number, radiusBottom: number, height: number, numSegments: number);
  694. }
  695. export interface IHightfieldOptions {
  696. minValue?: number;
  697. maxValue?: number;
  698. elementSize: number;
  699. }
  700. export class Heightfield extends Shape {
  701. data: number[];
  702. maxValue: number;
  703. minValue: number;
  704. elementSize: number;
  705. cacheEnabled: boolean;
  706. pillarConvex: ConvexPolyhedron;
  707. pillarOffset: Vec3;
  708. type: number;
  709. constructor(data: number[], options?: IHightfieldOptions);
  710. update(): void;
  711. updateMinValue(): void;
  712. updateMaxValue(): void;
  713. setHeightValueAtIndex(xi: number, yi: number, value: number): void;
  714. getRectMinMax(iMinX: number, iMinY: number, iMaxX: number, iMaxY: number, result: any[]): void;
  715. getIndexOfPosition(x: number, y: number, result: any[], clamp: boolean): boolean;
  716. getConvexTrianglePillar(xi: number, yi: number, getUpperTriangle: boolean): void;
  717. }
  718. export class Particle extends Shape {
  719. }
  720. export class Plane extends Shape {
  721. worldNormal: Vec3;
  722. worldNormalNeedsUpdate: boolean;
  723. boundingSphereRadius: number;
  724. computeWorldNormal(quat: Quaternion): void;
  725. calculateWorldAABB(pos: Vec3, quat: Quaternion, min: number, max: number): void;
  726. }
  727. export class Shape {
  728. static types: {
  729. SPHERE: number;
  730. PLANE: number;
  731. BOX: number;
  732. COMPOUND: number;
  733. CONVEXPOLYHEDRON: number;
  734. HEIGHTFIELD: number;
  735. PARTICLE: number;
  736. CYLINDER: number;
  737. }
  738. id: number;
  739. type: number;
  740. boundingSphereRadius: number;
  741. collisionResponse: boolean;
  742. updateBoundingSphereRadius(): number;
  743. volume(): number;
  744. calculateLocalInertia(mass: number, target?: Vec3): Vec3;
  745. }
  746. export class Sphere extends Shape {
  747. radius: number;
  748. constructor(radius: number);
  749. }
  750. export class GSSolver extends Solver {
  751. iterations: number;
  752. tolerance: number;
  753. solve(dy: number, world: World): number;
  754. }
  755. export class Solver {
  756. equations: Equation[];
  757. solve(dy: number, world: World): number;
  758. addEquation(eq: Equation): void;
  759. removeEquation(eq: Equation): void;
  760. removeAllEquations(): void;
  761. }
  762. export class SplitSolver extends Solver {
  763. subsolver: Solver;
  764. constructor(subsolver: Solver);
  765. solve(dy: number, world: World): number;
  766. }
  767. export class EventTarget {
  768. addEventListener(type: string, listener: Function): EventTarget;
  769. hasEventListener(type: string, listener: Function): boolean;
  770. removeEventListener(type: string, listener: Function): EventTarget;
  771. dispatchEvent(event: IEvent): IEvent;
  772. }
  773. export class Pool {
  774. objects: any[];
  775. type: any[];
  776. release(): any;
  777. get(): any;
  778. constructObject(): any;
  779. }
  780. export class TupleDictionary {
  781. data: {
  782. keys: any[];
  783. };
  784. get(i: number, j: number): number;
  785. set(i: number, j: number, value: number): void;
  786. reset(): void;
  787. }
  788. export class Utils {
  789. static defaults(options?: any, defaults?: any): any;
  790. }
  791. export class Vec3Pool extends Pool {
  792. static defaults(options: Object, defaults: Object): Object;
  793. constructObject(): Vec3;
  794. }
  795. export class NarrowPhase {
  796. contactPointPool: Pool[];
  797. enableFrictionReduction: boolean;
  798. v3pool: Vec3Pool;
  799. convexHeightfield(convexShape: Shape, hfShape: Heightfield, convexPos: Vec3, hfPos: Vec3, convexQuat: Quaternion, hfQuat: Quaternion, convexBody: Body, hfBody: Body): void;
  800. convexConvex(si: Shape, sj: Shape, xi: Vec3, xj: Vec3, qi: Quaternion, qj: Quaternion, bi: Body, bj: Body): void;
  801. convexParticle(result: ContactEquation[], si: Shape, sj: Shape, xi: Vec3, xj: Vec3, qi: Quaternion, qj: Quaternion, bi: Body, bj: Body): void;
  802. convexTrimesh( result: ContactEquation[], si: Shape, sj: Shape, xi: Vec3, xj: Vec3, qi: Quaternion, qj: Quaternion, bi: Body, bj: Body): void;
  803. createContactEquation(bi: Body, bj: Body, si: Shape, sj: Shape, rsi: Shape, rsj: Shape): ContactEquation;
  804. getContacts(p1: Body[], p2: Body[], world: World, result: ContactEquation[], oldcontacts: ContactEquation[]): void;
  805. particlePlane( result: ContactEquation[], si: Shape, sj: Shape, xi: Vec3, xj: Vec3, qi: Quaternion, qj: Quaternion, bi: Body, bj: Body): void;
  806. particleSphere(result: ContactEquation[], si: Shape, sj: Shape, xi: Vec3, xj: Vec3, qi: Quaternion, qj: Quaternion, bi: Body, bj: Body): void;
  807. planeBox(result: ContactEquation[], si: Shape, sj: Shape, xi: Vec3, xj: Vec3, qi: Quaternion, qj: Quaternion, bi: Body, bj: Body): void;
  808. planeConvex(si: Shape, sj: Shape, xi: Vec3, xj: Vec3, qi: Quaternion, qj: Quaternion, bi: Body, bj: Body): void;
  809. planeTrimesh(si: Shape, sj: Shape, xi: Vec3, xj: Vec3, qi: Quaternion, qj: Quaternion, bi: Body, bj: Body): void;
  810. sphereBox(si: Shape, sj: Shape, xi: Vec3, xj: Vec3, qi: Quaternion, qj: Quaternion, bi: Body, bj: Body): void;
  811. sphereConvex(si: Shape, sj: Shape, xi: Vec3, xj: Vec3, qi: Quaternion, qj: Quaternion, bi: Body, bj: Body): void;
  812. sphereHeightfield(sphereShape: Shape, hfShape: Heightfield, spherePos: Vec3, hfPos: Vec3, sphereQuat: Quaternion, hfQuat: Quaternion, sphereBody: Body, hfBody: Body): void;
  813. spherePlane( si: Shape, sj: Shape, xi: Vec3, xj: Vec3, qi: Quaternion, qj: Quaternion, bi: Body, bj: Body): void;
  814. sphereSphere(si: Shape, sj: Shape, xi: Vec3, xj: Vec3, qi: Quaternion, qj: Quaternion, bi: Body, bj: Body): void;
  815. sphereTrimesh(sphereShape: Shape, trimeshShape: Shape, spherePos: Vec3, trimeshPos: Vec3, sphereQuat: Quaternion, trimeshQuat: Quaternion, sphereBody: Body, trimeshBody: Body): void;
  816. }
  817. export interface IOctreeOptions {
  818. root: Octree;
  819. aabb: AABB;
  820. }
  821. export class OctreeNode {
  822. aabb: AABB;
  823. children: Octree[];
  824. data: number[];
  825. root: OctreeNode;
  826. }
  827. export class Octree extends OctreeNode {
  828. maxDepth: number;
  829. constructor(aabb: AABB, options: IOctreeOptions);
  830. aabbQuery(aabb: AABB, result: Object[]): Object[];
  831. insert(aabb: AABB, elementData: Object): boolean;
  832. rayQuery(ray: Ray, treeTransform: Transform, result: Object[]): Object[];
  833. removeEmptyNodes(): void;
  834. subdivide(): void;
  835. }
  836. export interface IWorld {
  837. collisisonFilterMask?: number;
  838. collisionFilterGroup?: number;
  839. skipBackfaces?: boolean;
  840. checkCollisionResponse?: boolean;
  841. }
  842. export class World extends EventTarget {
  843. dt: number;
  844. allowSleep: boolean;
  845. contacts: ContactEquation[];
  846. frictionEquations: FrictionEquation[];
  847. quatNormalizeSkip: number;
  848. quatNormalizeFast: boolean;
  849. time: number;
  850. stepnumber: number;
  851. default_dt: number;
  852. nextId: number;
  853. gravity: Vec3;
  854. broadphase: NaiveBroadphase;
  855. bodies: Body[];
  856. //miner
  857. allContacts:ContactEquation[];
  858. callBackBody:Body[];
  859. solver: Solver;
  860. constraints: Constraint[];
  861. narrowPhase: NarrowPhase;
  862. collisionMatrix: ArrayCollisionMatrix;
  863. collisionMatrixPrevious: ArrayCollisionMatrix;
  864. materials: Material[];
  865. contactMaterials: ContactMaterial[];
  866. contactMaterialTable: TupleDictionary;
  867. defaultMaterial: Material;
  868. defaultContactMaterial: ContactMaterial;
  869. doProfiling: boolean;
  870. profile: {
  871. solve: number;
  872. makeContactConstraints: number;
  873. broadphaser: number;
  874. integrate: number;
  875. narrowphase: number;
  876. };
  877. subsystems: any[];
  878. addBodyEvent: IBodyEvent;
  879. removeBodyEvent: IBodyEvent;
  880. addBody(body: Body): void;
  881. addConstraint(c: Constraint): void;
  882. addContactMaterial(cmat: ContactMaterial): void;
  883. addEventListener(type: string, listener: Function): EventTarget;
  884. addMaterial(m: Material): void;
  885. clearForces(): void;
  886. collisionMatrixTick(): void;
  887. getContactMaterial(m1: Material, m2: Material): ContactMaterial;
  888. numObjects(): number;
  889. raycastAll(from: Vec3, to: Vec3, options: IWorld, callback: Function): boolean;
  890. raycastAny(from: Vec3, to: Vec3, options: IWorld, result: RaycastResult): boolean;
  891. raycastClosest(from: Vec3, to: Vec3, options: IWorld, result: RaycastResult): boolean;
  892. rayTest(from: Vec3, to: Vec3, result: RaycastResult): void;
  893. remove(body: Body): void;
  894. removeBody(body: Body): void;
  895. removeConstraint(c: Constraint): void;
  896. removeEventListener(type: string, listener: Function): EventTarget;
  897. step(dy: number, timeSinceLastCalled?: number, maxSubSteps?: number): void;
  898. }
  899. export interface IEvent {
  900. type: string;
  901. }
  902. export interface IBodyEvent extends IEvent {
  903. body: Body;
  904. }
  905. export class Demo {
  906. constructor( options: Object );
  907. addScene( title: string, initfunc: Function ): void;
  908. restartCurrentScene(): void;
  909. }
  910. }