lib.wx.phys3D.d.ts 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  1. /*! *****************************************************************************
  2. Copyright (c) 2024 Tencent, Inc. All rights reserved.
  3. Permission is hereby granted, free of charge, to any person obtaining a copy of
  4. this software and associated documentation files (the "Software"), to deal in
  5. the Software without restriction, including without limitation the rights to
  6. use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
  7. of the Software, and to permit persons to whom the Software is furnished to do
  8. so, subject to the following conditions:
  9. The above copyright notice and this permission notice shall be included in all
  10. copies or substantial portions of the Software.
  11. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  17. SOFTWARE.
  18. ***************************************************************************** */
  19. declare namespace phys3D {
  20. // pvd调试配置
  21. export interface PhysicsDebugConfig {
  22. isNetwork: boolean // 采用网络的方式
  23. ip?: string // 如果isNetwork为true,调试信息会通过tcp转发的方式转发到打开了pvd调试软件的电脑,需要注意的是,防火墙要对pvd打开
  24. port?: 5425 // pvd默认接口
  25. timeout?: 1000 // 默认耗时
  26. path?: string // 如果isNetwork为false,调试信息会通过写本地文件的方式落地,文件名建议为xxx.pxd2,导入pvd调试即可
  27. }
  28. export enum QueryTriggerInteraction {
  29. UseGlobal = 0,
  30. Ignore = 1,
  31. Collide = 2
  32. }
  33. export class PhysSystem {
  34. constructor(config?: PhysicsDebugConfig)
  35. gravity: RawVec3f
  36. bounceThreshold: number
  37. defaultMaxAngularSpeed: number
  38. defaultSolverIterations: number
  39. defaultSolverVelocityIterations: number
  40. sleepThreshold: number
  41. defaultContactOffset: number
  42. destroyScene: () => void
  43. createScene: () => number
  44. Simulate: (step: number) => void
  45. SyncFromTransforms: (() => void) | undefined // added in 2021.06
  46. SetCollisionMask: (mask: ArrayBuffer) => void
  47. Raycast: (
  48. origin: RawVec3f,
  49. unitDir: RawVec3f,
  50. distance: number,
  51. hit: RaycastHit,
  52. layerMask?: number,
  53. queryTriggerInteraction?: QueryTriggerInteraction
  54. ) => boolean
  55. RaycastAll: (
  56. origin: RawVec3f,
  57. unitDir: RawVec3f,
  58. distance: number,
  59. layerMask?: number,
  60. queryTriggerInteraction?: QueryTriggerInteraction
  61. ) => RaycastHit[]
  62. CapsuleCast(
  63. p1: RawVec3f,
  64. p2: RawVec3f,
  65. radius: number,
  66. direction: RawVec3f,
  67. hit: RaycastHit,
  68. maxDistance: number,
  69. layerMask?: number,
  70. queryTriggerInteraction?: QueryTriggerInteraction
  71. ): void
  72. CapsuleCastAll: (
  73. p1: RawVec3f,
  74. p2: RawVec3f,
  75. radius: number,
  76. direction: RawVec3f,
  77. maxDistance: number,
  78. layerMask?: number,
  79. queryTriggerInteraction?: QueryTriggerInteraction
  80. ) => RaycastHit[]
  81. BoxCast(
  82. center: RawVec3f,
  83. halfExt: RawVec3f,
  84. direction: RawVec3f,
  85. hit: RaycastHit,
  86. orientation: RawQuaternion,
  87. maxDistance: number,
  88. layerMask?: number,
  89. queryTriggerInteraction?: QueryTriggerInteraction
  90. ): void
  91. BoxCastAll: (
  92. center: RawVec3f,
  93. halfExt: RawVec3f,
  94. direction: RawVec3f,
  95. orientation: RawQuaternion,
  96. maxDistance: number,
  97. layerMask?: number,
  98. queryTriggerInteraction?: QueryTriggerInteraction
  99. ) => RaycastHit[]
  100. OverlapBox: (
  101. center: RawVec3f,
  102. halfExt: RawVec3f,
  103. orientation: RawQuaternion,
  104. layermask?: number,
  105. queryTriggerInteraction?: QueryTriggerInteraction
  106. ) => Collider[]
  107. OverlapCapsule: (
  108. p1: RawVec3f,
  109. p2: RawVec3f,
  110. radius: number,
  111. layermask?: number,
  112. queryTriggerInteraction?: QueryTriggerInteraction
  113. ) => Collider[]
  114. }
  115. export class Rigidbody {
  116. constructor(system: PhysSystem)
  117. enabled?: boolean // since 2021.06
  118. position: RawVec3f
  119. rotation: RawQuaternion
  120. AttachToEntity: (pollObj: any, id: number) => void
  121. Remove(): void
  122. Detach(): void
  123. IsAttached(): boolean
  124. }
  125. export enum CollisionDetectionMode {
  126. Discrete = 0,
  127. Continuous = 1,
  128. ContinuousDynamic = 2,
  129. ContinuousSpeculative = 3
  130. }
  131. export enum RigidbodyConstraints {
  132. None = 0,
  133. FreezePositionX = 1 << 0,
  134. FreezePositionY = 1 << 1,
  135. FreezePositionZ = 1 << 2,
  136. FreezeRotationX = 1 << 3,
  137. FreezeRotationY = 1 << 4,
  138. FreezeRotationZ = 1 << 5,
  139. FreezePosition = FreezePositionX | FreezePositionY | FreezePositionZ,
  140. FreezeRotation = FreezeRotationX | FreezeRotationY | FreezeRotationZ,
  141. FreezeAll = FreezePosition | FreezeRotation
  142. }
  143. export enum ForceMode {
  144. kForceModeForce = 0,
  145. kForceModeImpulse = 1 << 0,
  146. kForceModeVelocityChange = 1 << 1,
  147. kForceModeAcceleration = 1 << 2
  148. }
  149. export enum CombineMode {
  150. eAverage = 0,
  151. eMin,
  152. eMultiply,
  153. eMax
  154. }
  155. export enum CookingFlag {
  156. None = 0,
  157. CookForFasterSimulation = 1 << 0,
  158. EnableMeshCleaning = 1 << 1,
  159. WeldColocatedVertices = 1 << 2
  160. }
  161. export enum CollisionFlags {
  162. None = 0,
  163. Sides = 1 << 0,
  164. Above = 1 << 1,
  165. Below = 1 << 2
  166. }
  167. export class RawVec3f {
  168. constructor()
  169. constructor(x: number, y: number, z: number)
  170. x: number
  171. y: number
  172. z: number
  173. }
  174. export class RawQuaternion {
  175. constructor()
  176. constructor(x: number, y: number, z: number, w: number)
  177. x: number
  178. y: number
  179. z: number
  180. w: number
  181. }
  182. export class Collider {
  183. attachedRigidbody: Rigidbody
  184. bounds: Bounds
  185. name: string
  186. contactOffset: number
  187. enabled: boolean
  188. isTrigger: boolean
  189. scale: RawVec3f
  190. material?: Material
  191. sharedMateiral?: Material
  192. ClosestPoint: (raw: RawVec3f) => RawVec3f
  193. ClosestPointOnBounds: (raw: RawVec3f) => RawVec3f
  194. onCollisionEnter?: (collision: Collision) => void
  195. onCollisionExit?: (collision: Collision) => void
  196. onCollisionStay?: (collision: Collision) => void
  197. onTriggerEnter?: (collision: Collision) => void
  198. onTriggerExit?: (collision: Collision) => void
  199. onTriggerStay?: (collision: Collision) => void
  200. dettachRigidbody?: () => void
  201. userData?: unknown
  202. layer: number
  203. }
  204. export class BoxCollider extends Collider {
  205. constructor(system: PhysSystem, center: RawVec3f, size: RawVec3f)
  206. center: RawVec3f
  207. size: RawVec3f
  208. }
  209. export class SphereCollider extends Collider {
  210. constructor(system: PhysSystem, center: RawVec3f, radius: number)
  211. center: RawVec3f
  212. radius: number
  213. }
  214. export class CapsuleCollider extends Collider {
  215. constructor(
  216. system: PhysSystem,
  217. center: RawVec3f,
  218. height: number,
  219. radius: number
  220. )
  221. center: RawVec3f
  222. height: number
  223. radius: number
  224. }
  225. export class MeshCollider extends Collider {
  226. constructor(
  227. system: PhysSystem,
  228. convex: boolean,
  229. cookingOptions: number,
  230. sharedMesh: PhysMesh
  231. )
  232. cookingOptions: number
  233. sharedMesh: PhysMesh | null
  234. convex: boolean
  235. }
  236. export class CharacterController extends Collider {
  237. constructor(system: PhysSystem)
  238. position: RawVec3f
  239. center: RawVec3f
  240. collisionFlags: CollisionFlags
  241. detectCollisions: boolean
  242. enableOverlapRecovery: boolean
  243. height: number
  244. isGrounded: boolean
  245. minMoveDistance: number
  246. radius: number
  247. skinWidth: number
  248. slopeLimit: number
  249. stepOffset: number
  250. velocity: RawVec3f
  251. Move: (movement: RawVec3f) => CollisionFlags
  252. SimpleMove: (speed: RawVec3f) => boolean
  253. AttachToEntity: (pollObj: any, id: number) => void
  254. OnControllerColliderHit?: (hit: ControllerColliderHit) => void
  255. }
  256. export interface ContactPoint {
  257. normal: RawVec3f
  258. this_collider: Collider
  259. other_collider: Collider
  260. point: RawVec3f
  261. separation: number
  262. }
  263. export interface Collision {
  264. collider: Collider
  265. contacts: ContactPoint[]
  266. impulse: RawVec3f
  267. relative_velocity: RawVec3f
  268. }
  269. export interface ControllerColliderHit {
  270. collider: Collider
  271. controller: CharacterController
  272. moveDirection: RawVec3f
  273. normal: RawVec3f
  274. moveLength: number
  275. point: RawVec3f
  276. }
  277. export class Bounds {
  278. constructor(center: RawVec3f, size: RawVec3f)
  279. center: RawVec3f
  280. extents: RawVec3f
  281. max: RawVec3f
  282. min: RawVec3f
  283. size: RawVec3f
  284. ClosestPoint: (point: RawVec3f) => RawVec3f
  285. Contains: (point: RawVec3f) => boolean
  286. Expand: (amount: number) => void
  287. Intersects: (bounds: Bounds) => boolean
  288. SetMinMax: (min: RawVec3f, max: RawVec3f) => void
  289. SqrDistance: (point: RawVec3f) => number
  290. }
  291. export class Material {
  292. constructor(system: PhysSystem)
  293. dynamicFriction: number
  294. staticFriction: number
  295. bounciness: number
  296. frictionCombine: CombineMode
  297. bounceCombine: CombineMode
  298. id: number
  299. }
  300. export class DynamicRigidbody extends Rigidbody {
  301. mass: number
  302. angularDamping: number
  303. angularVelocity: RawVec3f
  304. centerOfMass: RawVec3f
  305. collisionDetectionMode: CollisionDetectionMode
  306. constraints: number
  307. detectCollisions: boolean
  308. linearDamping: number
  309. freezeRotation: boolean
  310. inertiaTensor: number
  311. // inertiaTensorRotation
  312. // interpolation
  313. isKinematic: boolean
  314. maxAngularVelocity: number
  315. maxDepenetrationVelocity: number
  316. sleepThreshold: number
  317. solverIterations: number
  318. solverVelocityIterations: number
  319. useGravity: boolean
  320. velocity: RawVec3f
  321. userData?: unknown
  322. GetWorldCenterOfMass: () => RawVec3f
  323. AddForce: (force: RawVec3f, mode: ForceMode) => void
  324. AddTorque: (torque: RawVec3f, mode: ForceMode) => void
  325. IsSleeping: () => boolean
  326. Sleep: () => void
  327. WakeUp: () => void
  328. AddExplosionForce: (
  329. explosionForce: number,
  330. explosionPosition: RawVec3f,
  331. explosionRadius: number,
  332. upwardsModifier: number,
  333. mode: ForceMode
  334. ) => void
  335. AddForceAtPosition: (
  336. force: RawVec3f,
  337. position: RawVec3f,
  338. mode: ForceMode
  339. ) => void
  340. AddRelativeForce: (force: RawVec3f, mode: ForceMode) => void
  341. AddRelativeTorque: (torque: RawVec3f, mode: ForceMode) => void
  342. ClosestPointOnBounds: (position: RawVec3f) => RawVec3f
  343. GetPointVelocity: (worldPoint: RawVec3f) => RawVec3f
  344. GetRelativePointVelocity: (relativePoint: RawVec3f) => RawVec3f
  345. MovePosition: (position: RawVec3f) => void
  346. MoveRotation: (rotation: RawQuaternion) => void
  347. ResetCenterOfMass: () => void
  348. ResetInertiaTensor: () => void
  349. SetDensity: (density: number) => void
  350. // SweepTest: () => void;
  351. // SweepTestAll: () => void;
  352. }
  353. export class PhysMesh {
  354. constructor(system: PhysSystem)
  355. // set vertices
  356. SetVertices: (buffer: Float32Array, count: number) => void
  357. // set indices
  358. SetTriangles: (
  359. buffer: Uint16Array | Uint32Array,
  360. count: number,
  361. useUint16: boolean
  362. ) => void
  363. }
  364. export class RaycastHit {
  365. constructor()
  366. collider: Collider
  367. distance: number
  368. normal: RawVec3f
  369. point: RawVec3f
  370. rigidbody: Rigidbody
  371. }
  372. }