You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Multi-backend subcontracting design of physical system
API Design
UML:
Colliders:
/** * Basic class of rigid body collider. */exportabstractclassColliderextendsComponent{/** The shape of the Collider. */getshapes(): Readonly<ColliderShape[]>{}/** * Add a collider shape. * @param shape - The collider shape. */addShape(shape: ColliderShape): void{}/** * Remove a collider shape. * @param shape - The collider shape. */removeShape(shape: ColliderShape): void{}/** * Clear all shape collection. */clearShapes(): void{}}/** * A static rigid body collider component that will not move when colliding with a dynamic rigid body collider. * @remarks Mostly used for object which always stays at the same place and never moves around. */exportclassStaticColliderextendsCollider{}/** * A dynamic rigid body collider component. */exportclassDynamicColliderextendsCollider{/** The linear velocity vector of the RigidBody measured in world unit per second. */linearVelocity: number;/** The angular velocity vector of the RigidBody measured in radians per second. */angularVelocity: number;/** The linear damping of the RigidBody. */linearDamping: number;/** The angular damping of the RigidBody. */angularDamping: number;/** The mass of the RigidBody. */mass: number;/** Controls whether physics affects the RigidBody. */isKinematic: boolean;/** apply a force to the DynamicCollider. */applyForce(force: Vector3): void{}/** apply a torque to the DynamicCollider. */applyTorque(torque: Vector3): void{}}
Shapes:
/** * Basic class of collider shape. */exportabstractclassColliderShape{/** The position of this ColliderShape. */position: Vector3;/** Whether the ColliderShape is a trigger. */isTrigger: boolean;/** The physic material of this ColliderShape. */material: PhysicsMaterial;}/** * Box-shaped collider shape. */exportclassBoxColliderShapeextendsColliderShape{/** The size of this BoxColliderShape. */size: Vector3;}/** * Sphere-shaped collider shape. */exportclassSphereColliderShapeextendsColliderShape{/** The radius of this SphereColliderShape. */radius: number;}/** * Plane-shaped collider shape. */exportclassPlaneColliderShapeextendsColliderShape{/** The rotation of this PlaneColliderShape. */rotation: Vector3;}/** * Capsule-shaped collider shape. */exportclassCapsuleColliderShapeextendsColliderShape{/** The radius of this CapsuleColliderShape. */radius: number;/** The height of this CapsuleColliderShape. */height: number;/** The up axis of this CapsuleColliderShape. */upAxis: ColliderShapeUpAxis;}
Script Call back:
exportclassScriptextendsComponent{
............../** * Called when the collision enter. * @param other - Other ColliderShape */onTriggerEnter(other: ColliderShape): void{}/** * Called when the collision stay. * @remarks onTriggerStay is called every frame while the collision stay. * @param other - Other ColliderShape */onTriggerStay(other: ColliderShape): void{}/** * Called when the collision exit. * @param other - Other ColliderShape */onTriggerExit(other: ColliderShape): void{}
..............}
PhysicsManager:
exportclassPhysicsManager{/** * Casts a ray through the Scene and returns the first hit. * @param ray - The ray * @returns Returns true if the ray intersects with a Collider, otherwise false. */raycast(ray: Ray): Boolean;/** * Casts a ray through the Scene and returns the first hit. * @param ray - The ray * @param outHitResult - If true is returned, outHitResult will contain more detailed collision information * @returns Returns true if the ray intersects with a Collider, otherwise false. */raycast(ray: Ray,outHitResult: HitResult): Boolean;/** * Casts a ray through the Scene and returns the first hit. * @param ray - The ray * @param distance - The max distance the ray should check * @returns Returns true if the ray intersects with a Collider, otherwise false. */raycast(ray: Ray,distance: number): Boolean;/** * Casts a ray through the Scene and returns the first hit. * @param ray - The ray * @param distance - The max distance the ray should check * @param outHitResult - If true is returned, outHitResult will contain more detailed collision information * @returns Returns true if the ray intersects with a Collider, otherwise false. */raycast(ray: Ray,distance: number,outHitResult: HitResult): Boolean;/** * Casts a ray through the Scene and returns the first hit. * @param ray - The ray * @param distance - The max distance the ray should check * @param layerMask - Layer mask that is used to selectively ignore Colliders when casting * @returns Returns true if the ray intersects with a Collider, otherwise false. */raycast(ray: Ray,distance: number,layerMask: Layer): Boolean;/** * Casts a ray through the Scene and returns the first hit. * @param ray - The ray * @param distance - The max distance the ray should check * @param layerMask - Layer mask that is used to selectively ignore Colliders when casting * @param outHitResult - If true is returned, outHitResult will contain more detailed collision information * @returns Returns true if the ray intersects with a Collider, otherwise false. */raycast(ray: Ray,distance: number,layerMask: Layer,outHitResult: HitResult): Boolean;
Auxiliary Class:
/** * The up axis of the collider shape. */exportenumColliderShapeUpAxis{/** Up axis is X. */X,/** Up axis is Y. */Y,/** Up axis is Z. */Z}/** * Describe how to handle with collisions between colliders. */exportclassPhysicsMaterial{/** The bounciness of collider surface. */bounciness: number;/** The friction coefficient used when already moving. */dynamicFriction: number;/** The friction coefficient used when an object is lying on a surface. */staticFriction: number;/** The friction bounce mode.*/bounceCombine: PhysicsMaterialCombineMode;/** The friction combine mode. */frictionCombine: PhysicsMaterialCombineMode;}/** * Describes how physics materials of the colliders are combined. */exportenumPhysicsMaterialCombineMode{/** Averages the friction/bounce of the two colliding materials. */Average,/** Uses the smaller friction/bounce of the two colliding materials. */Minimum,/** Uses the larger friction/bounce of the two colliding materials. */Maximum,/** Multiplies the friction/bounce of the two colliding materials. */Multiply}/** * Structure used to get information back from a raycast or a sweep. */exportclassHitResult{/** The collider shape that was hit. */colliderShape: ColliderShape=null;/** The distance from the origin to the hit point. */distance: number=0;/** The hit point of the collider that was hit in world space. */point: Vector3=newVector3();/** The hit normal of the collider that was hit in world space. */normal: Vector3=newVector3();}
This is the design of physical system.
Multi-backend subcontracting design of physical system
API Design
UML:
Colliders:
Shapes:
Script Call back:
PhysicsManager:
Auxiliary Class:
Physics engine interface:
Design Source Code
https://github.com/GuoLei1990/engine/tree/design/physics
User API Design:
packages/core/src/physics
Physics engine interface Design:
packages/design/src/physics
Physics engine implement sample:
packages/physics-physX
andpackages/physics-lite
The text was updated successfully, but these errors were encountered: