UNPKG

@osobh/reactar

Version:

AR Library for React Native and Expo

105 lines (104 loc) 2.67 kB
export interface AmmoInstance { btDefaultCollisionConfiguration: any; btCollisionDispatcher: any; btDbvtBroadphase: any; btSequentialImpulseConstraintSolver: any; btDiscreteDynamicsWorld: any; btTransform: any; btVector3: any; btQuaternion: any; btDefaultMotionState: any; btBoxShape: any; btRigidBodyConstructionInfo: any; btRigidBody: any; btTypedConstraint: any; btHingeConstraint: any; btConeTwistConstraint: any; btPoint2PointConstraint: any; destroy: (obj: any) => void; } declare global { const Ammo: AmmoInstance; } import { Vector3, Quaternion } from 'three'; import { EventEmitter } from 'events'; export interface PhysicsObject { id: string; body: AmmoInstance['btRigidBody']; mass: number; position: Vector3; rotation: Quaternion; scale: Vector3; } export interface PhysicsProperties { mass?: number; friction?: number; restitution?: number; linearDamping?: number; angularDamping?: number; isKinematic?: boolean; } export declare class PhysicsManager extends EventEmitter { private physicsWorld; private collisionConfiguration; private dispatcher; private broadphase; private solver; private objects; private isInitialized; private gravity; private timeStep; constructor(); /** * Initializes the physics engine */ initialize(): Promise<boolean>; /** * Creates a physics object and adds it to the physics world */ createObject(id: string, position: Vector3, rotation: Quaternion, scale: Vector3, properties?: PhysicsProperties): void; /** * Updates the physics simulation */ update(deltaTime?: number): void; /** * Applies a force to an object */ applyForce(id: string, force: Vector3, point?: Vector3): void; /** * Sets the gravity of the physics world */ setGravity(gravity: Vector3): void; /** * Creates a box collision shape */ private createBoxShape; /** * Removes an object from the physics world */ removeObject(id: string): void; /** * Cleans up physics resources */ /** * Creates a rigid body with specified position, rotation and mass */ createRigidBody(position: { x: number; y: number; z: number; }, rotation: { x: number; y: number; z: number; w: number; }, mass: number): any; /** * Gets the physics world instance */ getWorld(): AmmoInstance['btDiscreteDynamicsWorld']; /** * Cleans up physics resources */ cleanup(): void; }