import { IBoxColliderShape , ICapsuleColliderShape , IDynamicCollider , IPhysics , IPhysicsManager , IPhysicsMaterial , IPlaneColliderShape , ISphereColliderShape , IStaticCollider } from "@oasis-engine/design" ; import { PhysXPhysicsMaterial } from "./PhysXPhysicsMaterial" ; import { PhysXPhysicsManager } from "./PhysXPhysicsManager" ; import { PhysXBoxColliderShape } from "./shape/PhysXBoxColliderShape" ; import { PhysXSphereColliderShape } from "./shape/PhysXSphereColliderShape" ; import { PhysXCapsuleColliderShape } from "./shape/PhysXCapsuleColliderShape" ; import { PhysXDynamicCollider } from "./PhysXDynamicCollider" ; import { PhysXStaticCollider } from "./PhysXStaticCollider" ; import { StaticInterfaceImplement } from "./StaticInterfaceImplement" ; import { Quaternion , Vector3 } from "oasis-engine" ; import { PhysXPlaneColliderShape } from "./shape/PhysXPlaneColliderShape" ; import { PhysXRuntimeMode } from "./enum/PhysXRuntimeMode" ; /**
 * PhysX object creation.
 */ @ StaticInterfaceImplement < IPhysics > ( ) export class PhysXPhysics { internal static _physX : any ; internal static _pxPhysics : any ; param runtimeMode returns public static init ( runtimeMode = PhysXRuntimeMode . Auto ) { const scriptPromise = new Promise ( ( resolve ) => { const script = document . createElement ( "script" ) ; document . body . appendChild ( script ) ; script . async = true ; script . onload = resolve ; const supported = ( ( ) => { try { if ( typeof WebAssembly === "object" && typeof WebAssembly . instantiate === "function" ) { const module = new WebAssembly . Module ( Uint8Array . of ( 0x0 , 0x61 , 0x73 , 0x6d , 0x01 , 0x00 , 0x00 , 0x00 ) ) ; if ( module instanceof WebAssembly . Module ) return new WebAssembly . Instance ( module ) instanceof WebAssembly . Instance ; } } catch ( e ) { } return false ; } ) ( ) ; if ( runtimeMode == PhysXRuntimeMode . Auto ) { if ( supported ) { runtimeMode = PhysXRuntimeMode . WebAssembly ; } else { runtimeMode = PhysXRuntimeMode . JavaScript ; } } if ( runtimeMode == PhysXRuntimeMode . JavaScript ) { script . src = "https://gw.alipayobjects.com/os/lib/oasis-engine/physics-physx/0.6.0-alpha.1/dist/physx.release.js" ; } else if ( runtimeMode == PhysXRuntimeMode . WebAssembly ) { script . src = "https://gw.alipayobjects.com/os/lib/oasis-engine/physics-physx/0.6.0-alpha.1/dist/physx.release.js" ; } } ) ; return new Promise ( ( resolve ) => { scriptPromise . then ( ( ) => { ( < any > window ) . PHYSX ( ) . then ( ( PHYSX ) => { PhysXPhysics . _init ( PHYSX ) ; PhysXPhysicsManager . _init ( ) ; console . log ( "PhysX loaded." ) ; resolve ( ) ; } ) ; } ) ; } ) ; } /**
     * {@inheritDoc IPhysics.createPhysicsManager }
     */ static createPhysicsManager ( onContactBegin ? , onContactEnd ? , onContactStay ? , onTriggerBegin ? , onTriggerEnd ? , onTriggerStay ? ) { return new PhysXPhysicsManager ( onContactBegin , onContactEnd , onContactStay , onTriggerBegin , onTriggerEnd , onTriggerStay ) ; } /**
     * {@inheritDoc IPhysics.createStaticCollider }
     */ static createStaticCollider ( position , rotation ) { return new PhysXStaticCollider ( position , rotation ) ; } /**
     * {@inheritDoc IPhysics.createDynamicCollider }
     */ static createDynamicCollider ( position , rotation ) { return new PhysXDynamicCollider ( position , rotation ) ; } /**
     * {@inheritDoc IPhysics.createPhysicsMaterial }
     */ static createPhysicsMaterial ( staticFriction , dynamicFriction , bounciness , frictionCombine , bounceCombine ) { return new PhysXPhysicsMaterial ( staticFriction , dynamicFriction , bounciness , frictionCombine , bounceCombine ) ; } /**
     * {@inheritDoc IPhysics.createBoxColliderShape }
     */ static createBoxColliderShape ( uniqueID , size , material ) { return new PhysXBoxColliderShape ( uniqueID , size , material ) ; } /**
     * {@inheritDoc IPhysics.createSphereColliderShape }
     */ static createSphereColliderShape ( uniqueID , radius , material ) { return new PhysXSphereColliderShape ( uniqueID , radius , material ) ; } /**
     * {@inheritDoc IPhysics.createPlaneColliderShape }
     */ static createPlaneColliderShape ( uniqueID , material ) { return new PhysXPlaneColliderShape ( uniqueID , material ) ; } /**
     * {@inheritDoc IPhysics.createCapsuleColliderShape }
     */ static createCapsuleColliderShape ( uniqueID , radius , height , material ) { return new PhysXCapsuleColliderShape ( uniqueID , radius , height , material ) ; } private static _init ( PHYSX ) { PhysXPhysics . _physX = PHYSX ; const version = PhysXPhysics . _physX . PX_PHYSICS_VERSION ; const defaultErrorCallback = new PhysXPhysics . _physX . PxDefaultErrorCallback ( ) ; const allocator = new PhysXPhysics . _physX . PxDefaultAllocator ( ) ; const foundation = PhysXPhysics . _physX . PxCreateFoundation ( version , allocator , defaultErrorCallback ) ; this . _pxPhysics = PhysXPhysics . _physX . PxCreatePhysics ( version , foundation , new PhysXPhysics . _physX . PxTolerancesScale ( ) , false , null ) ; PhysXPhysics . _physX . PxInitExtensions ( this . _pxPhysics , null ) ; } }