From 709296ebf30c59b00ffb30fd71edaf8944a8aebf Mon Sep 17 00:00:00 2001 From: yangfengzzz Date: Mon, 7 Mar 2022 16:51:11 +0800 Subject: [PATCH 1/9] feat: non-trigger script and dynamic collider --- packages/core/src/Script.ts | 19 + packages/core/src/physics/DynamicCollider.ts | 272 +++++++++++++- packages/core/src/physics/PhysicsManager.ts | 60 ++- .../design/src/physics/IDynamicCollider.ts | 120 +++++- .../physics-lite/src/LiteDynamicCollider.ts | 133 ++++++- .../physics-physx/src/PhysXDynamicCollider.ts | 347 +++--------------- .../physics-physx/src/PhysXPhysicsManager.ts | 18 +- 7 files changed, 631 insertions(+), 338 deletions(-) diff --git a/packages/core/src/Script.ts b/packages/core/src/Script.ts index 277d7ab0ac..ab5eadd3b9 100644 --- a/packages/core/src/Script.ts +++ b/packages/core/src/Script.ts @@ -86,6 +86,25 @@ export class Script extends Component { */ onTriggerStay(other: ColliderShape): void {} + /** + * Called when the collision enter. + * @param other ColliderShape + */ + onContactEnter(other: ColliderShape): void {} + + /** + * Called when the collision stay. + * @remarks onTriggerStay is called every frame while the collision stay. + * @param other ColliderShape + */ + onContactExit(other: ColliderShape): void {} + + /** + * Called when the collision exit. + * @param other ColliderShape + */ + onContactStay(other: ColliderShape): void {} + /** * Called when the pointer is down while over the ColliderShape. */ diff --git a/packages/core/src/physics/DynamicCollider.ts b/packages/core/src/physics/DynamicCollider.ts index 13ecbd8970..03eec1d17a 100644 --- a/packages/core/src/physics/DynamicCollider.ts +++ b/packages/core/src/physics/DynamicCollider.ts @@ -2,24 +2,215 @@ import { IDynamicCollider } from "@oasis-engine/design"; import { Entity } from "../Entity"; import { Collider } from "./Collider"; import { PhysicsManager } from "./PhysicsManager"; -import { Vector3 } from "@oasis-engine/math"; +import { Vector3, Quaternion } from "@oasis-engine/math"; /** * A dynamic collider can act with self-defined movement or physical force. */ export class DynamicCollider extends Collider { - /** The linear velocity vector of the dynamic collider measured in world unit per second. */ - linearVelocity: Vector3; - /** The angular velocity vector of the dynamic collider measured in radians per second. */ - angularVelocity: Vector3; - /** The linear damping of the dynamic collider. */ - linearDamping: number; - /** The angular damping of the dynamic collider. */ - angularDamping: number; - /** The mass of the dynamic collider. */ - mass: number; - /** Controls whether physics affects the dynamic collider. */ - isKinematic: boolean; + private _linearDamping: number = 0; + private _angularDamping: number = 0; + private _linearVelocity = new Vector3(); + private _angularVelocity = new Vector3(); + private _mass: number = 0; + private _centerOfMass = new Vector3(); + private _inertiaTensor = new Vector3(); + private _maxAngularVelocity: number = 0; + private _maxDepenetrationVelocity: number = 0; + private _sleepThreshold: number = 0; + private _solverIterations: number = 0; + private _isKinematic: boolean = false; + private _freezeRotation: boolean = false; + private _constraints: number = 0; + private _collisionDetectionMode: CollisionDetectionMode = CollisionDetectionMode.Discrete; + + /** + * The linear damping of the dynamic collider. + */ + get linearDamping(): number { + return this._linearDamping; + } + + set linearDamping(newValue: number) { + this._linearDamping = newValue; + (this._nativeCollider).setLinearDamping(newValue); + } + + /** + * The angular damping of the dynamic collider. + */ + get angularDamping(): number { + return this._angularDamping; + } + + set angularDamping(newValue: number) { + this._angularDamping = newValue; + (this._nativeCollider).setAngularDamping(newValue); + } + + /** + * The linear velocity vector of the dynamic collider measured in world unit per second. + */ + get linearVelocity(): Vector3 { + return this._linearVelocity; + } + + set linearVelocity(newValue: Vector3) { + if (this._linearVelocity !== newValue) { + newValue.cloneTo(this._linearVelocity); + } + (this._nativeCollider).setLinearVelocity(this._linearVelocity); + } + + /** + * The angular velocity vector of the dynamic collider measured in radians per second. + */ + get angularVelocity(): Vector3 { + return this._angularVelocity; + } + + set angularVelocity(newValue: Vector3) { + if (this._angularVelocity !== newValue) { + newValue.cloneTo(this._angularVelocity); + } + (this._nativeCollider).setAngularVelocity(this._angularVelocity); + } + + /** + * The mass of the dynamic collider. + */ + get mass(): number { + return this._mass; + } + + set mass(newValue: number) { + this._mass = newValue; + (this._nativeCollider).setMass(newValue); + } + + /** + * The center of mass relative to the transform's origin. + */ + get centerOfMass(): Vector3 { + return this._centerOfMass; + } + + set centerOfMass(newValue: Vector3) { + if (this._centerOfMass !== newValue) { + newValue.cloneTo(this._centerOfMass); + } + (this._nativeCollider).setCenterOfMass(this._centerOfMass); + } + + /** + * The diagonal inertia tensor of mass relative to the center of mass. + */ + get inertiaTensor(): Vector3 { + return this._inertiaTensor; + } + + set inertiaTensor(newValue: Vector3) { + if (this._inertiaTensor !== newValue) { + newValue.cloneTo(this._inertiaTensor); + } + (this._nativeCollider).setInertiaTensor(this._inertiaTensor); + } + + /** + * The maximum angular velocity of the collider measured in radians per second. (Default 7) range { 0, infinity }. + */ + get maxAngularVelocity(): number { + return this._maxAngularVelocity; + } + + set maxAngularVelocity(newValue: number) { + this._maxAngularVelocity = newValue; + (this._nativeCollider).setMaxAngularVelocity(newValue); + } + + /** + * Maximum velocity of a collider when moving out of penetrating state. + */ + get maxDepenetrationVelocity(): number { + return this._maxDepenetrationVelocity; + } + + set maxDepenetrationVelocity(newValue: number) { + this._maxDepenetrationVelocity = newValue; + (this._nativeCollider).setMaxDepenetrationVelocity(newValue); + } + + /** + * The mass-normalized energy threshold, below which objects start going to sleep. + */ + get sleepThreshold(): number { + return this._sleepThreshold; + } + + set sleepThreshold(newValue: number) { + this._sleepThreshold = newValue; + (this._nativeCollider).setSleepThreshold(newValue); + } + + /** + * The solverIterations determines how accurately collider joints and collision contacts are resolved. + */ + get solverIterations(): number { + return this._solverIterations; + } + + set solverIterations(newValue: number) { + this._solverIterations = newValue; + (this._nativeCollider).setSolverIterations(newValue); + } + + /** + * Controls whether physics affects the dynamic collider. + */ + get isKinematic(): boolean { + return this._isKinematic; + } + + set isKinematic(newValue: boolean) { + this._isKinematic = newValue; + (this._nativeCollider).setIsKinematic(newValue); + } + + /** + * Controls whether physics will change the rotation of the object. + */ + get freezeRotation(): boolean { + return this._freezeRotation; + } + + set freezeRotation(newValue: boolean) { + this._freezeRotation = newValue; + (this._nativeCollider).setFreezeRotation(newValue); + } + + /** + * The particular rigid dynamic lock flag. + */ + get constraints(): number { + return this._constraints; + } + + set constraints(newValue: number) { + this._constraints = newValue; + (this._nativeCollider).setConstraints(newValue); + } + + /** + * The colliders' collision detection mode. + */ + get collisionDetectionMode(): CollisionDetectionMode { + return this._collisionDetectionMode; + } + + set collisionDetectionMode(newValue: CollisionDetectionMode) { + this._collisionDetectionMode = newValue; + (this._nativeCollider).setCollisionDetectionMode(newValue); + } constructor(entity: Entity) { super(entity); @@ -46,6 +237,29 @@ export class DynamicCollider extends Collider { (this._nativeCollider).addTorque(torque); } + /** + * Moves kinematically controlled dynamic actors through the game world. + * @param position The desired position for the kinematic actor + * @param rotation The desired rotation for the kinematic actor + */ + setKinematicTarget(position: Vector3, rotation: Quaternion) { + (this._nativeCollider).setKinematicTarget(position, rotation); + } + + /** + * Forces a collider to sleep at least one frame. + */ + putToSleep() { + (this._nativeCollider).putToSleep(); + } + + /** + * Forces a collider to wake up. + */ + wakeUp() { + (this._nativeCollider).wakeUp(); + } + /** * @override * @internal @@ -59,3 +273,35 @@ export class DynamicCollider extends Collider { this._updateFlag.flag = false; } } + +/** + * The collision detection mode constants. + */ +export enum CollisionDetectionMode { + /// Continuous collision detection is off for this dynamic collider. + Discrete, + /// Continuous collision detection is on for colliding with static mesh geometry. + Continuous, + /// Continuous collision detection is on for colliding with static and dynamic geometry. + ContinuousDynamic, + /// Speculative continuous collision detection is on for static and dynamic geometries + ContinuousSpeculative +} + +/** + * Use these flags to constrain motion of dynamic collider. + */ +export enum DynamicColliderConstraints { + /** Freeze motion along the X-axis. */ + FreezePositionX = 1, + /** Freeze motion along the Y-axis. */ + FreezePositionY = 2, + /** Freeze motion along the Z-axis. */ + FreezePositionZ = 4, + /** Freeze rotation along the X-axis. */ + FreezeRotationX = 8, + /** Freeze rotation along the Y-axis. */ + FreezeRotationY = 16, + /** Freeze rotation along the Z-axis. */ + FreezeRotationZ = 32 +} diff --git a/packages/core/src/physics/PhysicsManager.ts b/packages/core/src/physics/PhysicsManager.ts index a328a0f702..af8e196b9b 100644 --- a/packages/core/src/physics/PhysicsManager.ts +++ b/packages/core/src/physics/PhysicsManager.ts @@ -1,5 +1,5 @@ import { HitResult } from "./HitResult"; -import { Ray } from "@oasis-engine/math"; +import { Ray, Vector3 } from "@oasis-engine/math"; import { IPhysics, IPhysicsManager } from "@oasis-engine/design"; import { Collider } from "./Collider"; import { Layer } from "../Layer"; @@ -12,11 +12,51 @@ export class PhysicsManager { /** @internal */ static _nativePhysics: IPhysics; + private _gravity: Vector3 = new Vector3(); private _nativePhysicsManager: IPhysicsManager; private _physicalObjectsMap: Record = {}; - private _onContactEnter = (obj1: number, obj2: number) => {}; - private _onContactExit = (obj1: number, obj2: number) => {}; - private _onContactStay = (obj1: number, obj2: number) => {}; + private _onContactEnter = (obj1: number, obj2: number) => { + const shape1 = this._physicalObjectsMap[obj1]; + const shape2 = this._physicalObjectsMap[obj2]; + + let scripts = shape1.collider.entity._scripts; + for (let i = 0, len = scripts.length; i < len; i++) { + scripts.get(i).onContactEnter(shape2); + } + + scripts = shape2.collider.entity._scripts; + for (let i = 0, len = scripts.length; i < len; i++) { + scripts.get(i).onContactEnter(shape1); + } + }; + private _onContactExit = (obj1: number, obj2: number) => { + const shape1 = this._physicalObjectsMap[obj1]; + const shape2 = this._physicalObjectsMap[obj2]; + + let scripts = shape1.collider.entity._scripts; + for (let i = 0, len = scripts.length; i < len; i++) { + scripts.get(i).onContactExit(shape2); + } + + scripts = shape2.collider.entity._scripts; + for (let i = 0, len = scripts.length; i < len; i++) { + scripts.get(i).onContactExit(shape1); + } + }; + private _onContactStay = (obj1: number, obj2: number) => { + const shape1 = this._physicalObjectsMap[obj1]; + const shape2 = this._physicalObjectsMap[obj2]; + + let scripts = shape1.collider.entity._scripts; + for (let i = 0, len = scripts.length; i < len; i++) { + scripts.get(i).onContactStay(shape2); + } + + scripts = shape2.collider.entity._scripts; + for (let i = 0, len = scripts.length; i < len; i++) { + scripts.get(i).onContactStay(shape1); + } + }; private _onTriggerEnter = (obj1: number, obj2: number) => { const shape1 = this._physicalObjectsMap[obj1]; const shape2 = this._physicalObjectsMap[obj2]; @@ -62,6 +102,18 @@ export class PhysicsManager { } }; + get gravity(): Vector3 { + return this._gravity; + } + + set gravity(g: Vector3) { + const gravity = this._gravity; + if (this._gravity !== g) { + g.cloneTo(gravity); + } + this._nativePhysicsManager.setGravity(gravity); + } + constructor() { this._nativePhysicsManager = PhysicsManager._nativePhysics.createPhysicsManager( this._onContactEnter, diff --git a/packages/design/src/physics/IDynamicCollider.ts b/packages/design/src/physics/IDynamicCollider.ts index 86c5fbd9f7..4a1325fff2 100644 --- a/packages/design/src/physics/IDynamicCollider.ts +++ b/packages/design/src/physics/IDynamicCollider.ts @@ -1,22 +1,99 @@ -import { Vector3 } from "@oasis-engine/math"; +import { Quaternion, Vector3 } from "@oasis-engine/math"; import { ICollider } from "./ICollider"; /** * Interface of physics dynamic collider. */ export interface IDynamicCollider extends ICollider { - /** The linear velocity vector of the dynamic collider measured in world unit per second. */ - linearVelocity: Vector3; - /** The angular velocity vector of the dynamic collider measured in radians per second. */ - angularVelocity: Vector3; - /** The linear damping of the dynamic collider. */ - linearDamping: number; - /** The angular damping of the dynamic collider. */ - angularDamping: number; - /** The mass of the dynamic collider. */ - mass: number; - /** Controls whether physics affects the dynamic collider. */ - isKinematic: boolean; + /** + * Sets the linear damping coefficient. + * @param value Linear damping coefficient. + */ + setLinearDamping(value: number): void; + + /** + * Sets the angular damping coefficient. + * @param value Angular damping coefficient. + */ + setAngularDamping(value: number): void; + + /** + * Sets the linear velocity of the actor. + * @param value New linear velocity of actor. + */ + setLinearVelocity(value: Vector3): void; + + /** + * Sets the angular velocity of the actor. + * @param value New angular velocity of actor. + */ + setAngularVelocity(value: Vector3): void; + + /** + * Sets the mass of a dynamic actor. + * @param value New mass value for the actor. + */ + setMass(value: number): void; + + /** + * Sets the pose of the center of mass relative to the actor. + * @param value Mass frame offset transform relative to the actor frame. + */ + setCenterOfMass(value: Vector3): void; + + /** + * Sets the inertia tensor, using a parameter specified in mass space coordinates. + * @param value New mass space inertia tensor for the actor. + */ + setInertiaTensor(value: Vector3): void; + + /** + * Set the maximum angular velocity permitted for this actor. + * @param value Max allowable angular velocity for actor. + */ + setMaxAngularVelocity(value: number): void; + + /** + * Sets the maximum depenetration velocity permitted to be introduced by the solver. + * @param value The maximum velocity to de-penetrate + */ + setMaxDepenetrationVelocity(value: number): void; + + /** + * Sets the mass-normalized kinetic energy threshold below which an actor may go to sleep. + * @param value Energy below which an actor may go to sleep. + */ + setSleepThreshold(value: number): void; + + /** + * Sets the solver iteration counts for the body. + * @param value Number of position iterations the solver should perform for this body. + */ + setSolverIterations(value: number): void; + + /** + * Sets the colliders' collision detection mode. + * @param value rigid body flag + */ + setCollisionDetectionMode(value: number): void; + + /** + * Controls whether physics affects the dynamic collider. + * @param value is or not + */ + setIsKinematic(value: boolean): void; + + /** + * Controls whether physics will change the rotation of the object. + * @param value is or not + */ + setFreezeRotation(value: boolean): void; + + /** + * Raises or clears a particular rigid dynamic lock flag. + * @param flags the flag to raise(set) or clear. + */ + setConstraints(flags: number): void; /** * Apply a force to the dynamic collider. @@ -29,4 +106,21 @@ export interface IDynamicCollider extends ICollider { * @param torque - The force make the collider rotate */ addTorque(torque: Vector3): void; + + /** + * Moves kinematically controlled dynamic actors through the game world. + * @param position The desired position for the kinematic actor + * @param rotation The desired rotation for the kinematic actor + */ + setKinematicTarget(position: Vector3, rotation: Quaternion): void; + + /** + * Forces a collider to sleep at least one frame. + */ + putToSleep(): void; + + /** + * Forces a collider to wake up. + */ + wakeUp(): void; } diff --git a/packages/physics-lite/src/LiteDynamicCollider.ts b/packages/physics-lite/src/LiteDynamicCollider.ts index 787171ef1c..462dd47e70 100644 --- a/packages/physics-lite/src/LiteDynamicCollider.ts +++ b/packages/physics-lite/src/LiteDynamicCollider.ts @@ -6,13 +6,6 @@ import { Quaternion, Vector3 } from "oasis-engine"; * A dynamic collider can act with self-defined movement or physical force */ export class LiteDynamicCollider extends LiteCollider implements IDynamicCollider { - angularDamping: number; - angularVelocity: Vector3; - isKinematic: boolean; - linearDamping: number; - linearVelocity: Vector3; - mass: number; - /** * Initialize dynamic actor. * @param position - The global position @@ -37,4 +30,130 @@ export class LiteDynamicCollider extends LiteCollider implements IDynamicCollide addTorque(torque: Vector3): void { throw "Physics-lite don't support addTorque. Use Physics-PhysX instead!"; } + + /** + * {@inheritDoc IDynamicCollider.setKinematicTarget } + */ + setKinematicTarget(position: Vector3, rotation: Quaternion): void { + throw "Physics-lite don't support setKinematicTarget. Use Physics-PhysX instead!"; + } + + /** + * {@inheritDoc IDynamicCollider.putToSleep } + */ + putToSleep(): void { + throw "Physics-lite don't support putToSleep. Use Physics-PhysX instead!"; + } + + /** + * {@inheritDoc IDynamicCollider.setAngularDamping } + */ + setAngularDamping(value: number): void { + throw "Physics-lite don't support setAngularDamping. Use Physics-PhysX instead!"; + } + + /** + * {@inheritDoc IDynamicCollider.setAngularVelocity } + */ + setAngularVelocity(value: Vector3): void { + throw "Physics-lite don't support setAngularVelocity. Use Physics-PhysX instead!"; + } + + /** + * {@inheritDoc IDynamicCollider.setCenterOfMass } + */ + setCenterOfMass(value: Vector3): void { + throw "Physics-lite don't support setCenterOfMass. Use Physics-PhysX instead!"; + } + + /** + * {@inheritDoc IDynamicCollider.setCollisionDetectionMode } + */ + setCollisionDetectionMode(value: number): void { + throw "Physics-lite don't support setCollisionDetectionMode. Use Physics-PhysX instead!"; + } + + /** + * {@inheritDoc IDynamicCollider.setFreezeRotation } + */ + setFreezeRotation(value: boolean): void { + throw "Physics-lite don't support setFreezeRotation. Use Physics-PhysX instead!"; + } + + /** + * {@inheritDoc IDynamicCollider.setConstraints } + */ + setConstraints(flags: number): void { + throw "Physics-lite don't support setConstraints. Use Physics-PhysX instead!"; + } + + /** + * {@inheritDoc IDynamicCollider.setInertiaTensor } + */ + setInertiaTensor(value: Vector3): void { + throw "Physics-lite don't support setInertiaTensor. Use Physics-PhysX instead!"; + } + + /** + * {@inheritDoc IDynamicCollider.setIsKinematic } + */ + setIsKinematic(value: boolean): void { + throw "Physics-lite don't support setIsKinematic. Use Physics-PhysX instead!"; + } + + /** + * {@inheritDoc IDynamicCollider.setLinearDamping } + */ + setLinearDamping(value: number): void { + throw "Physics-lite don't support setLinearDamping. Use Physics-PhysX instead!"; + } + + /** + * {@inheritDoc IDynamicCollider.setLinearVelocity } + */ + setLinearVelocity(value: Vector3): void { + throw "Physics-lite don't support setLinearVelocity. Use Physics-PhysX instead!"; + } + + /** + * {@inheritDoc IDynamicCollider.setMass } + */ + setMass(value: number): void { + throw "Physics-lite don't support setMass. Use Physics-PhysX instead!"; + } + + /** + * {@inheritDoc IDynamicCollider.setMaxAngularVelocity } + */ + setMaxAngularVelocity(value: number): void { + throw "Physics-lite don't support setMaxAngularVelocity. Use Physics-PhysX instead!"; + } + + /** + * {@inheritDoc IDynamicCollider.setMaxDepenetrationVelocity } + */ + setMaxDepenetrationVelocity(value: number): void { + throw "Physics-lite don't support setMaxDepenetrationVelocity. Use Physics-PhysX instead!"; + } + + /** + * {@inheritDoc IDynamicCollider.setSleepThreshold } + */ + setSleepThreshold(value: number): void { + throw "Physics-lite don't support setSleepThreshold. Use Physics-PhysX instead!"; + } + + /** + * {@inheritDoc IDynamicCollider.setSolverIterations } + */ + setSolverIterations(value: number): void { + throw "Physics-lite don't support setSolverIterations. Use Physics-PhysX instead!"; + } + + /** + * {@inheritDoc IDynamicCollider.wakeUp } + */ + wakeUp(): void { + throw "Physics-lite don't support wakeUp. Use Physics-PhysX instead!"; + } } diff --git a/packages/physics-physx/src/PhysXDynamicCollider.ts b/packages/physics-physx/src/PhysXDynamicCollider.ts index 2522e229d5..de993cc3a1 100644 --- a/packages/physics-physx/src/PhysXDynamicCollider.ts +++ b/packages/physics-physx/src/PhysXDynamicCollider.ts @@ -3,7 +3,9 @@ import { Quaternion, Vector3 } from "oasis-engine"; import { IDynamicCollider } from "@oasis-engine/design"; import { PhysXCollider } from "./PhysXCollider"; -/** The collision detection mode constants used for PhysXDynamicCollider.collisionDetectionMode. */ +/** + * The collision detection mode constants used for PhysXDynamicCollider.collisionDetectionMode. + * */ export enum CollisionDetectionMode { /** Continuous collision detection is off for this dynamic collider. */ Discrete, @@ -15,214 +17,97 @@ export enum CollisionDetectionMode { ContinuousSpeculative } -/** Use these flags to constrain motion of dynamic collider. */ -export enum DynamicColliderConstraints { - /** Freeze motion along the X-axis. */ - FreezePositionX, - /** Freeze motion along the Y-axis. */ - FreezePositionY, - /** Freeze motion along the Z-axis. */ - FreezePositionZ, - /** Freeze rotation along the X-axis. */ - FreezeRotationX, - /** Freeze rotation along the Y-axis. */ - FreezeRotationY, - /** Freeze rotation along the Z-axis. */ - FreezeRotationZ, - /** Freeze motion along all axes. */ - FreezePosition, - /** Freeze rotation along all axes. */ - FreezeRotation, - /** Freeze rotation and motion along all axes. */ - FreezeAll -} - /** * A dynamic collider can act with self-defined movement or physical force */ export class PhysXDynamicCollider extends PhysXCollider implements IDynamicCollider { - /** The linear damping of the dynamic collider. */ - private _drag: number; - /** The angular damping of the dynamic collider. */ - private _angularDrag: number; - /** The linear velocity vector of the dynamic collider measured in world unit per second. */ - private _velocity: Vector3; - /** The angular velocity vector of the dynamic collider measured in radians per second. */ - private _angularVelocity: Vector3; - /** The mass of the dynamic collider. */ - private _mass: number; - private _centerOfMass: Vector3; - private _inertiaTensor: Vector3; - - private _maxAngularVelocity: number; - private _maxDepenetrationVelocity: number; - - private _sleepThreshold: number; - private _solverIterations: number; - - private _collisionDetectionMode: CollisionDetectionMode; - /** Controls whether physics affects the dynamic collider. */ - private _isKinematic: boolean; - - private _constraints: DynamicColliderConstraints; - private _freezeRotation: boolean; + constructor(position: Vector3, rotation: Quaternion) { + super(); + const transform = this._transform(position, rotation); + this._pxActor = PhysXPhysics._pxPhysics.createRigidDynamic(transform); + } /** - * The drag of the object. + * {@inheritDoc IDynamicCollider.setLinearDamping } */ - get linearDamping(): number { - return this._drag; - } - - set linearDamping(value: number) { - this._drag = value; + setLinearDamping(value: number): void { this._pxActor.setLinearDamping(value); } /** - * The angular drag of the object. + * {@inheritDoc IDynamicCollider.setAngularDamping } */ - get angularDamping(): number { - return this._angularDrag; - } - - set angularDamping(value: number) { - this._angularDrag = value; + setAngularDamping(value: number): void { this._pxActor.setAngularDamping(value); } /** - * The velocity vector of the collider. It represents the rate of change of collider position. + * {@inheritDoc IDynamicCollider.setLinearVelocity } */ - get linearVelocity(): Vector3 { - return this._velocity; - } - - set linearVelocity(value: Vector3) { - this._velocity = value; - const vel = { x: value.x, y: value.y, z: value.z }; - this._pxActor.setLinearVelocity(vel, true); + setLinearVelocity(value: Vector3): void { + this._pxActor.setLinearVelocity({ x: value.x, y: value.y, z: value.z }, true); } /** - * The angular velocity vector of the collider measured in radians per second. + * {@inheritDoc IDynamicCollider.setAngularVelocity } */ - get angularVelocity(): Vector3 { - return this._angularVelocity; - } - - set angularVelocity(value: Vector3) { - this._angularVelocity = value; + setAngularVelocity(value: Vector3): void { this._pxActor.setAngularVelocity({ x: value.x, y: value.y, z: value.z }, true); } /** - * The mass of the collider. + * {@inheritDoc IDynamicCollider.setMass } */ - get mass(): number { - return this._mass; - } - - set mass(value: number) { - this._mass = value; + setMass(value: number): void { this._pxActor.setMass(value); } /** - * The center of mass relative to the transform's origin. + * {@inheritDoc IDynamicCollider.setCenterOfMass } */ - get centerOfMass(): Vector3 { - return this._centerOfMass; - } - - set centerOfMass(value: Vector3) { - this._centerOfMass = value; - const transform = { - translation: { - x: value.x, - y: value.y, - z: value.z - }, - rotation: { - w: 1, - x: 0, - y: 0, - z: 0 - } - }; - this._pxActor.setCMassLocalPose(transform); + setCenterOfMass(position: Vector3): void { + this._pxActor.setCMassLocalPose(position); } /** - * The diagonal inertia tensor of mass relative to the center of mass. + * {@inheritDoc IDynamicCollider.setInertiaTensor } */ - get inertiaTensor(): Vector3 { - return this._inertiaTensor; - } - - set inertiaTensor(value: Vector3) { - this._inertiaTensor = value; - this._pxActor.setMassSpaceInertiaTensor({ x: value.x, y: value.y, z: value.z }); + setInertiaTensor(value: Vector3): void { + this._pxActor.setMassSpaceInertiaTensor(value); } /** - * The maximum angular velocity of the collider measured in radians per second. (Default 7) range { 0, infinity }. + * {@inheritDoc IDynamicCollider.setMaxAngularVelocity } */ - get maxAngularVelocity(): number { - return this._maxAngularVelocity; - } - - set maxAngularVelocity(value: number) { - this._maxAngularVelocity = value; + setMaxAngularVelocity(value: number): void { this._pxActor.setMaxAngularVelocity(value); } /** - * Maximum velocity of a collider when moving out of penetrating state. + * {@inheritDoc IDynamicCollider.setMaxDepenetrationVelocity } */ - get maxDepenetrationVelocity(): number { - return this._maxDepenetrationVelocity; - } - - set maxDepenetrationVelocity(value: number) { - this._maxDepenetrationVelocity = value; + setMaxDepenetrationVelocity(value: number): void { this._pxActor.setMaxDepenetrationVelocity(value); } /** - * The mass-normalized energy threshold, below which objects start going to sleep. + * {@inheritDoc IDynamicCollider.setSleepThreshold } */ - get sleepThreshold(): number { - return this._sleepThreshold; - } - - set sleepThreshold(value: number) { - this._sleepThreshold = value; + setSleepThreshold(value: number): void { this._pxActor.setSleepThreshold(value); } /** - * The solverIterations determines how accurately collider joints and collision contacts are resolved. - * Overrides Physics.defaultSolverIterations. Must be positive. + * {@inheritDoc IDynamicCollider.setSolverIterations } */ - get solverIterations(): number { - return this._solverIterations; - } - - set solverIterations(value: number) { - this._solverIterations = value; + setSolverIterations(value: number): void { this._pxActor.setSolverIterationCounts(value, 1); } /** - * The colliders' collision detection mode. + * {@inheritDoc IDynamicCollider.setCollisionDetectionMode } */ - get collisionDetectionMode(): CollisionDetectionMode { - return this._collisionDetectionMode; - } - - set collisionDetectionMode(value: CollisionDetectionMode) { - this._collisionDetectionMode = value; + setCollisionDetectionMode(value: number): void { switch (value) { case CollisionDetectionMode.Continuous: this._pxActor.setRigidBodyFlag(PhysXPhysics._physX.PxRigidBodyFlag.eENABLE_CCD, true); @@ -242,14 +127,9 @@ export class PhysXDynamicCollider extends PhysXCollider implements IDynamicColli } /** - * Controls whether physics affects the collider. + * {@inheritDoc IDynamicCollider.setIsKinematic } */ - get isKinematic(): boolean { - return this._isKinematic; - } - - set isKinematic(value: boolean) { - this._isKinematic = value; + setIsKinematic(value: boolean): void { if (value) { this._pxActor.setRigidBodyFlag(PhysXPhysics._physX.PxRigidBodyFlag.eKINEMATIC, true); } else { @@ -258,77 +138,17 @@ export class PhysXDynamicCollider extends PhysXCollider implements IDynamicColli } /** - * Controls which degrees of freedom are allowed for the simulation of this collider. + * {@inheritDoc IDynamicCollider.setFreezeRotation } */ - get constraints(): DynamicColliderConstraints { - return this._constraints; + setFreezeRotation(value: boolean): void { + this._pxActor.setFreezeRotation(value); } /** - * Controls whether physics will change the rotation of the object. + * {@inheritDoc IDynamicCollider.setConstraints } */ - get freezeRotation(): boolean { - return this._freezeRotation; - } - - set freezeRotation(value: boolean) { - this._freezeRotation = value; - this.setConstraints(DynamicColliderConstraints.FreezeRotation, value); - } - - constructor(position: Vector3, rotation: Quaternion) { - super(); - const transform = this._transform(position, rotation); - this._pxActor = PhysXPhysics._pxPhysics.createRigidDynamic(transform); - } - - /** - * Set constraint flags - * @param flag Collider Constraint - * @param value true or false - */ - setConstraints(flag: DynamicColliderConstraints, value: boolean) { - if (value) this._constraints = this._constraints | flag; - else this._constraints = this._constraints & ~flag; - - switch (flag) { - case DynamicColliderConstraints.FreezePositionX: - this._pxActor.setRigidDynamicLockFlag(PhysXPhysics._physX.PxRigidDynamicLockFlag.eLOCK_LINEAR_X, value); - break; - case DynamicColliderConstraints.FreezePositionY: - this._pxActor.setRigidDynamicLockFlag(PhysXPhysics._physX.PxRigidDynamicLockFlag.eLOCK_LINEAR_Y, value); - break; - case DynamicColliderConstraints.FreezePositionZ: - this._pxActor.setRigidDynamicLockFlag(PhysXPhysics._physX.PxRigidDynamicLockFlag.eLOCK_LINEAR_Y, value); - break; - case DynamicColliderConstraints.FreezeRotationX: - this._pxActor.setRigidDynamicLockFlag(PhysXPhysics._physX.PxRigidDynamicLockFlag.eLOCK_ANGULAR_X, value); - break; - case DynamicColliderConstraints.FreezeRotationY: - this._pxActor.setRigidDynamicLockFlag(PhysXPhysics._physX.PxRigidDynamicLockFlag.eLOCK_ANGULAR_Y, value); - break; - case DynamicColliderConstraints.FreezeRotationZ: - this._pxActor.setRigidDynamicLockFlag(PhysXPhysics._physX.PxRigidDynamicLockFlag.eLOCK_ANGULAR_Z, value); - break; - case DynamicColliderConstraints.FreezeAll: - this._pxActor.setRigidDynamicLockFlag(PhysXPhysics._physX.PxRigidDynamicLockFlag.eLOCK_LINEAR_X, value); - this._pxActor.setRigidDynamicLockFlag(PhysXPhysics._physX.PxRigidDynamicLockFlag.eLOCK_LINEAR_Y, value); - this._pxActor.setRigidDynamicLockFlag(PhysXPhysics._physX.PxRigidDynamicLockFlag.eLOCK_LINEAR_Y, value); - this._pxActor.setRigidDynamicLockFlag(PhysXPhysics._physX.PxRigidDynamicLockFlag.eLOCK_ANGULAR_X, value); - this._pxActor.setRigidDynamicLockFlag(PhysXPhysics._physX.PxRigidDynamicLockFlag.eLOCK_ANGULAR_Y, value); - this._pxActor.setRigidDynamicLockFlag(PhysXPhysics._physX.PxRigidDynamicLockFlag.eLOCK_ANGULAR_Z, value); - break; - case DynamicColliderConstraints.FreezePosition: - this._pxActor.setRigidDynamicLockFlag(PhysXPhysics._physX.PxRigidDynamicLockFlag.eLOCK_LINEAR_X, value); - this._pxActor.setRigidDynamicLockFlag(PhysXPhysics._physX.PxRigidDynamicLockFlag.eLOCK_LINEAR_Y, value); - this._pxActor.setRigidDynamicLockFlag(PhysXPhysics._physX.PxRigidDynamicLockFlag.eLOCK_LINEAR_Y, value); - break; - case DynamicColliderConstraints.FreezeRotation: - this._pxActor.setRigidDynamicLockFlag(PhysXPhysics._physX.PxRigidDynamicLockFlag.eLOCK_ANGULAR_X, value); - this._pxActor.setRigidDynamicLockFlag(PhysXPhysics._physX.PxRigidDynamicLockFlag.eLOCK_ANGULAR_Y, value); - this._pxActor.setRigidDynamicLockFlag(PhysXPhysics._physX.PxRigidDynamicLockFlag.eLOCK_ANGULAR_Z, value); - break; - } + setConstraints(flags: number): void { + this._pxActor.setRigidDynamicLockFlags(flags); } /** @@ -346,90 +166,21 @@ export class PhysXDynamicCollider extends PhysXCollider implements IDynamicColli } /** - * Applies force at position. As a result this will apply a torque and force on the object. - * @param force Force vector in world coordinates. - * @param pos Position in world coordinates. - */ - addForceAtPosition(force: Vector3, pos: Vector3) { - this._pxActor.addForceAtPos({ x: force.x, y: force.y, z: force.z }, { x: pos.x, y: pos.y, z: pos.z }); - } - - /** - * The velocity of the collider at the point worldPoint in global space. - * @param pos The point in global space. - */ - getPointVelocity(pos: Vector3): Vector3 { - const vel = this._pxActor.getVelocityAtPos({ x: pos.x, y: pos.y, z: pos.z }); - return new Vector3(vel.x, vel.y, vel.z); - } - - /** - * The velocity relative to the collider at the point relativePoint. - * @param pos The relative point - */ - getRelativePointVelocity(pos: Vector3): Vector3 { - const vel = this._pxActor.getLocalVelocityAtLocalPos({ x: pos.x, y: pos.y, z: pos.z }); - return new Vector3(vel.x, vel.y, vel.z); - } - - /** - * Moves the kinematic collider towards position. - * @param value Provides the new position for the collider object. - */ - MovePosition(value: Vector3) { - const transform = { - translation: { - x: value.x, - y: value.y, - z: value.z - }, - rotation: { - w: 1, - x: 0, - y: 0, - z: 0 - } - }; - this._pxActor.setKinematicTarget(transform); - } - - /** - * Rotates the collider to rotation. - * @param value The new rotation for the collider. - */ - MoveRotation(value: Quaternion) { - const transform = { - translation: { - x: 0, - y: 0, - z: 0 - }, - rotation: { - w: value.w, - x: value.x, - y: value.y, - z: value.z - } - }; - this._pxActor.setKinematicTarget(transform); - } - - /** - * Is the collider sleeping? + * {@inheritDoc IDynamicCollider.setKinematicTarget } */ - isSleeping(): boolean { - return this._pxActor.isSleeping(); + setKinematicTarget(position: Vector3, rotation: Quaternion): void { + this._pxActor.setKinematicTarget(position, rotation); } /** - * Forces a collider to sleep at least one frame. + * {@inheritDoc IDynamicCollider.putToSleep } */ - sleep() { + putToSleep(): void { return this._pxActor.putToSleep(); } /** - * Forces a collider to wake up. + * {@inheritDoc IDynamicCollider.wakeUp } */ wakeUp() { return this._pxActor.wakeUp(); diff --git a/packages/physics-physx/src/PhysXPhysicsManager.ts b/packages/physics-physx/src/PhysXPhysicsManager.ts index 81110a3474..c392731913 100644 --- a/packages/physics-physx/src/PhysXPhysicsManager.ts +++ b/packages/physics-physx/src/PhysXPhysicsManager.ts @@ -51,9 +51,21 @@ export class PhysXPhysicsManager implements IPhysicsManager { this._onTriggerStay = onTriggerStay; const triggerCallback = { - onContactBegin: (obj1, obj2) => {}, - onContactEnd: (obj1, obj2) => {}, - onContactPersist: (obj1, obj2) => {}, + onContactBegin: (obj1, obj2) => { + const index1 = obj1.getQueryFilterData().word0; + const index2 = obj2.getQueryFilterData().word0; + this._onContactEnter(index1, index2); + }, + onContactEnd: (obj1, obj2) => { + const index1 = obj1.getQueryFilterData().word0; + const index2 = obj2.getQueryFilterData().word0; + this._onContactExit(index1, index2); + }, + onContactPersist: (obj1, obj2) => { + const index1 = obj1.getQueryFilterData().word0; + const index2 = obj2.getQueryFilterData().word0; + this._onContactStay(index1, index2); + }, onTriggerBegin: (obj1, obj2) => { const index1 = obj1.getQueryFilterData().word0; const index2 = obj2.getQueryFilterData().word0; From d6671774ddb67a6059526d3dcb27504a76af6dd6 Mon Sep 17 00:00:00 2001 From: yangfengzzz Date: Tue, 8 Mar 2022 16:56:26 +0800 Subject: [PATCH 2/9] fix: opt code in CR --- packages/core/src/Script.ts | 6 ++--- packages/core/src/physics/DynamicCollider.ts | 26 ++++++++++--------- packages/core/src/physics/PhysicsManager.ts | 12 ++++----- .../design/src/physics/IDynamicCollider.ts | 2 +- .../physics-lite/src/LiteDynamicCollider.ts | 4 +-- .../physics-physx/src/PhysXDynamicCollider.ts | 6 ++--- 6 files changed, 29 insertions(+), 27 deletions(-) diff --git a/packages/core/src/Script.ts b/packages/core/src/Script.ts index ab5eadd3b9..6dea0296d5 100644 --- a/packages/core/src/Script.ts +++ b/packages/core/src/Script.ts @@ -90,20 +90,20 @@ export class Script extends Component { * Called when the collision enter. * @param other ColliderShape */ - onContactEnter(other: ColliderShape): void {} + onCollisionEnter(other: ColliderShape): void {} /** * Called when the collision stay. * @remarks onTriggerStay is called every frame while the collision stay. * @param other ColliderShape */ - onContactExit(other: ColliderShape): void {} + onCollisionExit(other: ColliderShape): void {} /** * Called when the collision exit. * @param other ColliderShape */ - onContactStay(other: ColliderShape): void {} + onCollisionStay(other: ColliderShape): void {} /** * Called when the pointer is down while over the ColliderShape. diff --git a/packages/core/src/physics/DynamicCollider.ts b/packages/core/src/physics/DynamicCollider.ts index 03eec1d17a..83787d5074 100644 --- a/packages/core/src/physics/DynamicCollider.ts +++ b/packages/core/src/physics/DynamicCollider.ts @@ -21,7 +21,7 @@ export class DynamicCollider extends Collider { private _solverIterations: number = 0; private _isKinematic: boolean = false; private _freezeRotation: boolean = false; - private _constraints: number = 0; + private _constraints: DynamicColliderConstraints = 0; private _collisionDetectionMode: CollisionDetectionMode = CollisionDetectionMode.Discrete; /** @@ -191,11 +191,11 @@ export class DynamicCollider extends Collider { /** * The particular rigid dynamic lock flag. */ - get constraints(): number { + get constraints(): DynamicColliderConstraints { return this._constraints; } - set constraints(newValue: number) { + set constraints(newValue: DynamicColliderConstraints) { this._constraints = newValue; (this._nativeCollider).setConstraints(newValue); } @@ -242,21 +242,21 @@ export class DynamicCollider extends Collider { * @param position The desired position for the kinematic actor * @param rotation The desired rotation for the kinematic actor */ - setKinematicTarget(position: Vector3, rotation: Quaternion) { + setKinematicTarget(position: Vector3, rotation: Quaternion): void { (this._nativeCollider).setKinematicTarget(position, rotation); } /** * Forces a collider to sleep at least one frame. */ - putToSleep() { - (this._nativeCollider).putToSleep(); + sleep(): void { + (this._nativeCollider).sleep(); } /** * Forces a collider to wake up. */ - wakeUp() { + wakeUp(): void { (this._nativeCollider).wakeUp(); } @@ -264,7 +264,7 @@ export class DynamicCollider extends Collider { * @override * @internal */ - _onLateUpdate() { + _onLateUpdate(): void { const { transform } = this.entity; const { worldPosition, worldRotationQuaternion } = transform; this._nativeCollider.getWorldTransform(worldPosition, worldRotationQuaternion); @@ -278,13 +278,13 @@ export class DynamicCollider extends Collider { * The collision detection mode constants. */ export enum CollisionDetectionMode { - /// Continuous collision detection is off for this dynamic collider. + /** Continuous collision detection is off for this dynamic collider. */ Discrete, - /// Continuous collision detection is on for colliding with static mesh geometry. + /** Continuous collision detection is on for colliding with static mesh geometry. */ Continuous, - /// Continuous collision detection is on for colliding with static and dynamic geometry. + /** Continuous collision detection is on for colliding with static and dynamic geometry. */ ContinuousDynamic, - /// Speculative continuous collision detection is on for static and dynamic geometries + /** Speculative continuous collision detection is on for static and dynamic geometries */ ContinuousSpeculative } @@ -292,6 +292,8 @@ export enum CollisionDetectionMode { * Use these flags to constrain motion of dynamic collider. */ export enum DynamicColliderConstraints { + /** Not Freeze. */ + None = 0, /** Freeze motion along the X-axis. */ FreezePositionX = 1, /** Freeze motion along the Y-axis. */ diff --git a/packages/core/src/physics/PhysicsManager.ts b/packages/core/src/physics/PhysicsManager.ts index af8e196b9b..e52fed8a23 100644 --- a/packages/core/src/physics/PhysicsManager.ts +++ b/packages/core/src/physics/PhysicsManager.ts @@ -21,12 +21,12 @@ export class PhysicsManager { let scripts = shape1.collider.entity._scripts; for (let i = 0, len = scripts.length; i < len; i++) { - scripts.get(i).onContactEnter(shape2); + scripts.get(i).onCollisionEnter(shape2); } scripts = shape2.collider.entity._scripts; for (let i = 0, len = scripts.length; i < len; i++) { - scripts.get(i).onContactEnter(shape1); + scripts.get(i).onCollisionEnter(shape1); } }; private _onContactExit = (obj1: number, obj2: number) => { @@ -35,12 +35,12 @@ export class PhysicsManager { let scripts = shape1.collider.entity._scripts; for (let i = 0, len = scripts.length; i < len; i++) { - scripts.get(i).onContactExit(shape2); + scripts.get(i).onCollisionExit(shape2); } scripts = shape2.collider.entity._scripts; for (let i = 0, len = scripts.length; i < len; i++) { - scripts.get(i).onContactExit(shape1); + scripts.get(i).onCollisionExit(shape1); } }; private _onContactStay = (obj1: number, obj2: number) => { @@ -49,12 +49,12 @@ export class PhysicsManager { let scripts = shape1.collider.entity._scripts; for (let i = 0, len = scripts.length; i < len; i++) { - scripts.get(i).onContactStay(shape2); + scripts.get(i).onCollisionStay(shape2); } scripts = shape2.collider.entity._scripts; for (let i = 0, len = scripts.length; i < len; i++) { - scripts.get(i).onContactStay(shape1); + scripts.get(i).onCollisionStay(shape1); } }; private _onTriggerEnter = (obj1: number, obj2: number) => { diff --git a/packages/design/src/physics/IDynamicCollider.ts b/packages/design/src/physics/IDynamicCollider.ts index 4a1325fff2..16b1502b23 100644 --- a/packages/design/src/physics/IDynamicCollider.ts +++ b/packages/design/src/physics/IDynamicCollider.ts @@ -117,7 +117,7 @@ export interface IDynamicCollider extends ICollider { /** * Forces a collider to sleep at least one frame. */ - putToSleep(): void; + sleep(): void; /** * Forces a collider to wake up. diff --git a/packages/physics-lite/src/LiteDynamicCollider.ts b/packages/physics-lite/src/LiteDynamicCollider.ts index 462dd47e70..5b6747af02 100644 --- a/packages/physics-lite/src/LiteDynamicCollider.ts +++ b/packages/physics-lite/src/LiteDynamicCollider.ts @@ -39,9 +39,9 @@ export class LiteDynamicCollider extends LiteCollider implements IDynamicCollide } /** - * {@inheritDoc IDynamicCollider.putToSleep } + * {@inheritDoc IDynamicCollider.sleep } */ - putToSleep(): void { + sleep(): void { throw "Physics-lite don't support putToSleep. Use Physics-PhysX instead!"; } diff --git a/packages/physics-physx/src/PhysXDynamicCollider.ts b/packages/physics-physx/src/PhysXDynamicCollider.ts index de993cc3a1..fc4b354b3f 100644 --- a/packages/physics-physx/src/PhysXDynamicCollider.ts +++ b/packages/physics-physx/src/PhysXDynamicCollider.ts @@ -173,16 +173,16 @@ export class PhysXDynamicCollider extends PhysXCollider implements IDynamicColli } /** - * {@inheritDoc IDynamicCollider.putToSleep } + * {@inheritDoc IDynamicCollider.sleep } */ - putToSleep(): void { + sleep(): void { return this._pxActor.putToSleep(); } /** * {@inheritDoc IDynamicCollider.wakeUp } */ - wakeUp() { + wakeUp(): void { return this._pxActor.wakeUp(); } } From 8979cf79a15a81638cfdd27393f4a9b5c60b8096 Mon Sep 17 00:00:00 2001 From: yangfengzzz Date: Wed, 9 Mar 2022 16:23:21 +0800 Subject: [PATCH 3/9] fix: opt code in CR --- packages/core/src/physics/DynamicCollider.ts | 114 +++++++++--------- packages/core/src/physics/PhysicsManager.ts | 6 +- .../design/src/physics/IDynamicCollider.ts | 10 +- .../physics-lite/src/LiteDynamicCollider.ts | 13 +- .../physics-physx/src/PhysXDynamicCollider.ts | 28 +++-- 5 files changed, 84 insertions(+), 87 deletions(-) diff --git a/packages/core/src/physics/DynamicCollider.ts b/packages/core/src/physics/DynamicCollider.ts index 83787d5074..dc6e1837a1 100644 --- a/packages/core/src/physics/DynamicCollider.ts +++ b/packages/core/src/physics/DynamicCollider.ts @@ -31,9 +31,9 @@ export class DynamicCollider extends Collider { return this._linearDamping; } - set linearDamping(newValue: number) { - this._linearDamping = newValue; - (this._nativeCollider).setLinearDamping(newValue); + set linearDamping(value: number) { + this._linearDamping = value; + (this._nativeCollider).setLinearDamping(value); } /** @@ -43,9 +43,9 @@ export class DynamicCollider extends Collider { return this._angularDamping; } - set angularDamping(newValue: number) { - this._angularDamping = newValue; - (this._nativeCollider).setAngularDamping(newValue); + set angularDamping(value: number) { + this._angularDamping = value; + (this._nativeCollider).setAngularDamping(value); } /** @@ -55,9 +55,9 @@ export class DynamicCollider extends Collider { return this._linearVelocity; } - set linearVelocity(newValue: Vector3) { - if (this._linearVelocity !== newValue) { - newValue.cloneTo(this._linearVelocity); + set linearVelocity(value: Vector3) { + if (this._linearVelocity !== value) { + value.cloneTo(this._linearVelocity); } (this._nativeCollider).setLinearVelocity(this._linearVelocity); } @@ -69,9 +69,9 @@ export class DynamicCollider extends Collider { return this._angularVelocity; } - set angularVelocity(newValue: Vector3) { - if (this._angularVelocity !== newValue) { - newValue.cloneTo(this._angularVelocity); + set angularVelocity(value: Vector3) { + if (this._angularVelocity !== value) { + value.cloneTo(this._angularVelocity); } (this._nativeCollider).setAngularVelocity(this._angularVelocity); } @@ -83,9 +83,9 @@ export class DynamicCollider extends Collider { return this._mass; } - set mass(newValue: number) { - this._mass = newValue; - (this._nativeCollider).setMass(newValue); + set mass(value: number) { + this._mass = value; + (this._nativeCollider).setMass(value); } /** @@ -95,9 +95,9 @@ export class DynamicCollider extends Collider { return this._centerOfMass; } - set centerOfMass(newValue: Vector3) { - if (this._centerOfMass !== newValue) { - newValue.cloneTo(this._centerOfMass); + set centerOfMass(value: Vector3) { + if (this._centerOfMass !== value) { + value.cloneTo(this._centerOfMass); } (this._nativeCollider).setCenterOfMass(this._centerOfMass); } @@ -109,9 +109,9 @@ export class DynamicCollider extends Collider { return this._inertiaTensor; } - set inertiaTensor(newValue: Vector3) { - if (this._inertiaTensor !== newValue) { - newValue.cloneTo(this._inertiaTensor); + set inertiaTensor(value: Vector3) { + if (this._inertiaTensor !== value) { + value.cloneTo(this._inertiaTensor); } (this._nativeCollider).setInertiaTensor(this._inertiaTensor); } @@ -123,9 +123,9 @@ export class DynamicCollider extends Collider { return this._maxAngularVelocity; } - set maxAngularVelocity(newValue: number) { - this._maxAngularVelocity = newValue; - (this._nativeCollider).setMaxAngularVelocity(newValue); + set maxAngularVelocity(value: number) { + this._maxAngularVelocity = value; + (this._nativeCollider).setMaxAngularVelocity(value); } /** @@ -135,9 +135,9 @@ export class DynamicCollider extends Collider { return this._maxDepenetrationVelocity; } - set maxDepenetrationVelocity(newValue: number) { - this._maxDepenetrationVelocity = newValue; - (this._nativeCollider).setMaxDepenetrationVelocity(newValue); + set maxDepenetrationVelocity(value: number) { + this._maxDepenetrationVelocity = value; + (this._nativeCollider).setMaxDepenetrationVelocity(value); } /** @@ -147,9 +147,9 @@ export class DynamicCollider extends Collider { return this._sleepThreshold; } - set sleepThreshold(newValue: number) { - this._sleepThreshold = newValue; - (this._nativeCollider).setSleepThreshold(newValue); + set sleepThreshold(value: number) { + this._sleepThreshold = value; + (this._nativeCollider).setSleepThreshold(value); } /** @@ -159,9 +159,9 @@ export class DynamicCollider extends Collider { return this._solverIterations; } - set solverIterations(newValue: number) { - this._solverIterations = newValue; - (this._nativeCollider).setSolverIterations(newValue); + set solverIterations(value: number) { + this._solverIterations = value; + (this._nativeCollider).setSolverIterations(value); } /** @@ -171,21 +171,9 @@ export class DynamicCollider extends Collider { return this._isKinematic; } - set isKinematic(newValue: boolean) { - this._isKinematic = newValue; - (this._nativeCollider).setIsKinematic(newValue); - } - - /** - * Controls whether physics will change the rotation of the object. - */ - get freezeRotation(): boolean { - return this._freezeRotation; - } - - set freezeRotation(newValue: boolean) { - this._freezeRotation = newValue; - (this._nativeCollider).setFreezeRotation(newValue); + set isKinematic(value: boolean) { + this._isKinematic = value; + (this._nativeCollider).setIsKinematic(value); } /** @@ -195,9 +183,9 @@ export class DynamicCollider extends Collider { return this._constraints; } - set constraints(newValue: DynamicColliderConstraints) { - this._constraints = newValue; - (this._nativeCollider).setConstraints(newValue); + set constraints(value: DynamicColliderConstraints) { + this._constraints = value; + (this._nativeCollider).setConstraints(value); } /** @@ -207,9 +195,9 @@ export class DynamicCollider extends Collider { return this._collisionDetectionMode; } - set collisionDetectionMode(newValue: CollisionDetectionMode) { - this._collisionDetectionMode = newValue; - (this._nativeCollider).setCollisionDetectionMode(newValue); + set collisionDetectionMode(value: CollisionDetectionMode) { + this._collisionDetectionMode = value; + (this._nativeCollider).setCollisionDetectionMode(value); } constructor(entity: Entity) { @@ -237,13 +225,27 @@ export class DynamicCollider extends Collider { (this._nativeCollider).addTorque(torque); } + /** + * Moves kinematically controlled dynamic actors through the game world. + * @param position The desired position for the kinematic actor + */ + move(position: Vector3): void; + + /** + * Moves kinematically controlled dynamic actors through the game world. + * @param rotation The desired rotation for the kinematic actor + */ + move(rotation: Quaternion): void; + /** * Moves kinematically controlled dynamic actors through the game world. * @param position The desired position for the kinematic actor * @param rotation The desired rotation for the kinematic actor */ - setKinematicTarget(position: Vector3, rotation: Quaternion): void { - (this._nativeCollider).setKinematicTarget(position, rotation); + move(position: Vector3, rotation: Quaternion): void; + + move(positionOrRotation: Vector3 | Quaternion, rotation?: Quaternion): void { + (this._nativeCollider).move(positionOrRotation, rotation); } /** diff --git a/packages/core/src/physics/PhysicsManager.ts b/packages/core/src/physics/PhysicsManager.ts index e52fed8a23..9f4e811e37 100644 --- a/packages/core/src/physics/PhysicsManager.ts +++ b/packages/core/src/physics/PhysicsManager.ts @@ -106,10 +106,10 @@ export class PhysicsManager { return this._gravity; } - set gravity(g: Vector3) { + set gravity(value: Vector3) { const gravity = this._gravity; - if (this._gravity !== g) { - g.cloneTo(gravity); + if (this._gravity !== value) { + value.cloneTo(gravity); } this._nativePhysicsManager.setGravity(gravity); } diff --git a/packages/design/src/physics/IDynamicCollider.ts b/packages/design/src/physics/IDynamicCollider.ts index 16b1502b23..b1274294b4 100644 --- a/packages/design/src/physics/IDynamicCollider.ts +++ b/packages/design/src/physics/IDynamicCollider.ts @@ -83,12 +83,6 @@ export interface IDynamicCollider extends ICollider { */ setIsKinematic(value: boolean): void; - /** - * Controls whether physics will change the rotation of the object. - * @param value is or not - */ - setFreezeRotation(value: boolean): void; - /** * Raises or clears a particular rigid dynamic lock flag. * @param flags the flag to raise(set) or clear. @@ -109,10 +103,10 @@ export interface IDynamicCollider extends ICollider { /** * Moves kinematically controlled dynamic actors through the game world. - * @param position The desired position for the kinematic actor + * @param positionOrRotation The desired position or rotation for the kinematic actor * @param rotation The desired rotation for the kinematic actor */ - setKinematicTarget(position: Vector3, rotation: Quaternion): void; + move(positionOrRotation: Vector3 | Quaternion, rotation?: Quaternion): void; /** * Forces a collider to sleep at least one frame. diff --git a/packages/physics-lite/src/LiteDynamicCollider.ts b/packages/physics-lite/src/LiteDynamicCollider.ts index 5b6747af02..cb5701a613 100644 --- a/packages/physics-lite/src/LiteDynamicCollider.ts +++ b/packages/physics-lite/src/LiteDynamicCollider.ts @@ -32,10 +32,10 @@ export class LiteDynamicCollider extends LiteCollider implements IDynamicCollide } /** - * {@inheritDoc IDynamicCollider.setKinematicTarget } + * {@inheritDoc IDynamicCollider.move } */ - setKinematicTarget(position: Vector3, rotation: Quaternion): void { - throw "Physics-lite don't support setKinematicTarget. Use Physics-PhysX instead!"; + move(positionOrRotation: Vector3 | Quaternion, rotation?: Quaternion): void { + throw "Physics-lite don't support move. Use Physics-PhysX instead!"; } /** @@ -73,13 +73,6 @@ export class LiteDynamicCollider extends LiteCollider implements IDynamicCollide throw "Physics-lite don't support setCollisionDetectionMode. Use Physics-PhysX instead!"; } - /** - * {@inheritDoc IDynamicCollider.setFreezeRotation } - */ - setFreezeRotation(value: boolean): void { - throw "Physics-lite don't support setFreezeRotation. Use Physics-PhysX instead!"; - } - /** * {@inheritDoc IDynamicCollider.setConstraints } */ diff --git a/packages/physics-physx/src/PhysXDynamicCollider.ts b/packages/physics-physx/src/PhysXDynamicCollider.ts index fc4b354b3f..05b6d1bb15 100644 --- a/packages/physics-physx/src/PhysXDynamicCollider.ts +++ b/packages/physics-physx/src/PhysXDynamicCollider.ts @@ -21,6 +21,9 @@ export enum CollisionDetectionMode { * A dynamic collider can act with self-defined movement or physical force */ export class PhysXDynamicCollider extends PhysXCollider implements IDynamicCollider { + private static _tempTranslation = new Vector3(); + private static _tempRotation = new Quaternion(); + constructor(position: Vector3, rotation: Quaternion) { super(); const transform = this._transform(position, rotation); @@ -137,13 +140,6 @@ export class PhysXDynamicCollider extends PhysXCollider implements IDynamicColli } } - /** - * {@inheritDoc IDynamicCollider.setFreezeRotation } - */ - setFreezeRotation(value: boolean): void { - this._pxActor.setFreezeRotation(value); - } - /** * {@inheritDoc IDynamicCollider.setConstraints } */ @@ -166,10 +162,22 @@ export class PhysXDynamicCollider extends PhysXCollider implements IDynamicColli } /** - * {@inheritDoc IDynamicCollider.setKinematicTarget } + * {@inheritDoc IDynamicCollider.move } */ - setKinematicTarget(position: Vector3, rotation: Quaternion): void { - this._pxActor.setKinematicTarget(position, rotation); + move(positionOrRotation: Vector3 | Quaternion, rotation?: Quaternion): void { + if (rotation) { + this._pxActor.setKinematicTarget(positionOrRotation, rotation); + return; + } + + const tempTranslation = PhysXDynamicCollider._tempTranslation; + const tempRotation = PhysXDynamicCollider._tempRotation; + this.getWorldTransform(tempTranslation, tempRotation); + if (positionOrRotation instanceof Vector3) { + this._pxActor.setKinematicTarget(positionOrRotation, tempRotation); + } else { + this._pxActor.setKinematicTarget(tempTranslation, positionOrRotation); + } } /** From 85a7e40a2a7673310075e593c0f37e5ad9768040 Mon Sep 17 00:00:00 2001 From: yangfengzzz Date: Thu, 10 Mar 2022 10:35:05 +0800 Subject: [PATCH 4/9] fix: opt code in CR --- packages/core/src/physics/PhysicsManager.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core/src/physics/PhysicsManager.ts b/packages/core/src/physics/PhysicsManager.ts index 9f4e811e37..24ad3c963a 100644 --- a/packages/core/src/physics/PhysicsManager.ts +++ b/packages/core/src/physics/PhysicsManager.ts @@ -108,7 +108,7 @@ export class PhysicsManager { set gravity(value: Vector3) { const gravity = this._gravity; - if (this._gravity !== value) { + if (gravity !== value) { value.cloneTo(gravity); } this._nativePhysicsManager.setGravity(gravity); From 11f4c095146d10701ef25ee8ed6c93228bf88b47 Mon Sep 17 00:00:00 2001 From: yangfengzzz Date: Wed, 16 Mar 2022 16:27:53 +0800 Subject: [PATCH 5/9] fix: scale bug --- packages/core/src/physics/index.ts | 2 +- packages/physics-physx/src/PhysXPhysicsManager.ts | 8 ++++++-- packages/physics-physx/src/shape/PhysXBoxColliderShape.ts | 6 +++--- .../physics-physx/src/shape/PhysXCapsuleColliderShape.ts | 7 ++++--- packages/physics-physx/src/shape/PhysXColliderShape.ts | 6 +++--- .../physics-physx/src/shape/PhysXPlaneColliderShape.ts | 7 ++++--- .../physics-physx/src/shape/PhysXSphereColliderShape.ts | 5 +++-- 7 files changed, 24 insertions(+), 17 deletions(-) diff --git a/packages/core/src/physics/index.ts b/packages/core/src/physics/index.ts index 42f10a8b36..66ca44f015 100644 --- a/packages/core/src/physics/index.ts +++ b/packages/core/src/physics/index.ts @@ -12,4 +12,4 @@ export { CapsuleColliderShape } from "./shape/CapsuleColliderShape"; export { Collider } from "./Collider"; export { StaticCollider } from "./StaticCollider"; -export { DynamicCollider } from "./DynamicCollider"; +export { DynamicCollider, CollisionDetectionMode, DynamicColliderConstraints } from "./DynamicCollider"; diff --git a/packages/physics-physx/src/PhysXPhysicsManager.ts b/packages/physics-physx/src/PhysXPhysicsManager.ts index c392731913..374d83e178 100644 --- a/packages/physics-physx/src/PhysXPhysicsManager.ts +++ b/packages/physics-physx/src/PhysXPhysicsManager.ts @@ -138,7 +138,11 @@ export class PhysXPhysicsManager implements IPhysicsManager { * {@inheritDoc IPhysicsManager.update } */ update(elapsedTime: number): void { - this._simulate(elapsedTime); + const step = Math.max(1, Math.floor(elapsedTime * 60)); + for (let i = 0; i < step; i++) { + this._simulate(1 / 60); + } + this._fetchResults(); this._fireEvent(); } @@ -195,7 +199,7 @@ export class PhysXPhysicsManager implements IPhysicsManager { private _fireEvent(): void { const { _eventPool: eventPool, _currentEvents: currentEvents } = this; - for (let i = 0, n = currentEvents.length; i < n; ) { + for (let i = 0, n = currentEvents.length; i < n;) { const event = currentEvents.get(i); if (event.state == TriggerEventState.Enter) { this._onTriggerEnter(event.index1, event.index2); diff --git a/packages/physics-physx/src/shape/PhysXBoxColliderShape.ts b/packages/physics-physx/src/shape/PhysXBoxColliderShape.ts index 08b430e622..608622cfd8 100644 --- a/packages/physics-physx/src/shape/PhysXBoxColliderShape.ts +++ b/packages/physics-physx/src/shape/PhysXBoxColliderShape.ts @@ -28,7 +28,7 @@ export class PhysXBoxColliderShape extends PhysXColliderShape implements IBoxCol this._halfSize.z * this._scale.z ); this._allocShape(material); - this._setLocalPose(this._scale); + this._setLocalPose(); this.setUniqueID(uniqueID); } @@ -46,9 +46,9 @@ export class PhysXBoxColliderShape extends PhysXColliderShape implements IBoxCol * {@inheritDoc IColliderShape.setWorldScale } */ setWorldScale(scale: Vector3): void { - this._setLocalPose(this._scale); - scale.cloneTo(this._scale); + this._setLocalPose(); + Vector3.multiply(this._halfSize, this._scale, PhysXBoxColliderShape._tempHalfExtents); this._pxGeometry.halfExtents = PhysXBoxColliderShape._tempHalfExtents; this._pxShape.setGeometry(this._pxGeometry); diff --git a/packages/physics-physx/src/shape/PhysXCapsuleColliderShape.ts b/packages/physics-physx/src/shape/PhysXCapsuleColliderShape.ts index 46fbce4e49..36598a11f2 100644 --- a/packages/physics-physx/src/shape/PhysXCapsuleColliderShape.ts +++ b/packages/physics-physx/src/shape/PhysXCapsuleColliderShape.ts @@ -27,7 +27,7 @@ export class PhysXCapsuleColliderShape extends PhysXColliderShape implements ICa this._pxGeometry = new PhysXPhysics._physX.PxCapsuleGeometry(this._radius, this._halfHeight); this._allocShape(material); - this._setLocalPose(this._scale); + this._setLocalPose(); this.setUniqueID(uniqueID); } @@ -85,14 +85,15 @@ export class PhysXCapsuleColliderShape extends PhysXColliderShape implements ICa this._rotation.setValue(0, PhysXColliderShape.halfSqrt, 0, PhysXColliderShape.halfSqrt); break; } - this._setLocalPose(this._scale); + this._setLocalPose(); } /** * {@inheritDoc IColliderShape.setWorldScale } */ setWorldScale(scale: Vector3): void { - this._setLocalPose(this._scale); + scale.cloneTo(this._scale); + this._setLocalPose(); switch (this._upAxis) { case ColliderShapeUpAxis.X: diff --git a/packages/physics-physx/src/shape/PhysXColliderShape.ts b/packages/physics-physx/src/shape/PhysXColliderShape.ts index 0ae06697e6..8ba57cafd8 100644 --- a/packages/physics-physx/src/shape/PhysXColliderShape.ts +++ b/packages/physics-physx/src/shape/PhysXColliderShape.ts @@ -45,7 +45,7 @@ export abstract class PhysXColliderShape implements IColliderShape { if (value !== this._position) { value.cloneTo(this._position); } - this._setLocalPose(this._scale); + this._setLocalPose(); } /** @@ -94,9 +94,9 @@ export abstract class PhysXColliderShape implements IColliderShape { this._pxShape.setFlags(new PhysXPhysics._physX.PxShapeFlags(this._shapeFlags)); } - protected _setLocalPose(scale: Vector3): void { + protected _setLocalPose(): void { const transform = PhysXColliderShape.transform; - Vector3.multiply(this._position, scale, transform.translation); + Vector3.multiply(this._position, this._scale, transform.translation); transform.rotation = this._rotation; this._pxShape.setLocalPose(PhysXColliderShape.transform); } diff --git a/packages/physics-physx/src/shape/PhysXPlaneColliderShape.ts b/packages/physics-physx/src/shape/PhysXPlaneColliderShape.ts index 5c78fba4a3..2cef1000fd 100644 --- a/packages/physics-physx/src/shape/PhysXPlaneColliderShape.ts +++ b/packages/physics-physx/src/shape/PhysXPlaneColliderShape.ts @@ -19,7 +19,7 @@ export class PhysXPlaneColliderShape extends PhysXColliderShape implements IPlan this._pxGeometry = new PhysXPhysics._physX.PxPlaneGeometry(); this._allocShape(material); - this._setLocalPose(this._scale); + this._setLocalPose(); this.setUniqueID(uniqueID); } @@ -30,13 +30,14 @@ export class PhysXPlaneColliderShape extends PhysXColliderShape implements IPlan Quaternion.rotationYawPitchRoll(value.x, value.y, value.z, this._rotation); Quaternion.rotateZ(this._rotation, Math.PI * 0.5, this._rotation); this._rotation.normalize(); - this._setLocalPose(this._scale); + this._setLocalPose(); } /** * {@inheritDoc IColliderShape.setWorldScale } */ setWorldScale(scale: Vector3): void { - this._setLocalPose(this._scale); + scale.cloneTo(this._scale); + this._setLocalPose(); } } diff --git a/packages/physics-physx/src/shape/PhysXSphereColliderShape.ts b/packages/physics-physx/src/shape/PhysXSphereColliderShape.ts index 28df217123..91b3ace091 100644 --- a/packages/physics-physx/src/shape/PhysXSphereColliderShape.ts +++ b/packages/physics-physx/src/shape/PhysXSphereColliderShape.ts @@ -24,7 +24,7 @@ export class PhysXSphereColliderShape extends PhysXColliderShape implements ISph this._pxGeometry = new PhysXPhysics._physX.PxSphereGeometry(this._radius * this._maxScale); this._allocShape(material); - this._setLocalPose(this._scale); + this._setLocalPose(); this.setUniqueID(uniqueID); } @@ -41,7 +41,8 @@ export class PhysXSphereColliderShape extends PhysXColliderShape implements ISph * {@inheritDoc IColliderShape.setWorldScale } */ setWorldScale(scale: Vector3): void { - this._setLocalPose(this._scale); + scale.cloneTo(this._scale); + this._setLocalPose(); this._maxScale = Math.max(scale.x, Math.max(scale.x, scale.y)); this._pxGeometry.radius = this._radius * this._maxScale; From aac512cc53316bbf2f576e02f4c76f469b38b8cd Mon Sep 17 00:00:00 2001 From: yangfengzzz Date: Wed, 16 Mar 2022 16:50:06 +0800 Subject: [PATCH 6/9] feat: fix-time physics update --- packages/core/src/physics/PhysicsManager.ts | 10 ++++++++++ .../design/src/physics/IPhysicsManager.ts | 6 ++++++ .../physics-lite/src/LitePhysicsManager.ts | 7 +++++++ .../physics-physx/src/PhysXPhysicsManager.ts | 19 +++++++++++++++++-- 4 files changed, 40 insertions(+), 2 deletions(-) diff --git a/packages/core/src/physics/PhysicsManager.ts b/packages/core/src/physics/PhysicsManager.ts index 24ad3c963a..84061524db 100644 --- a/packages/core/src/physics/PhysicsManager.ts +++ b/packages/core/src/physics/PhysicsManager.ts @@ -12,6 +12,7 @@ export class PhysicsManager { /** @internal */ static _nativePhysics: IPhysics; + private _frequency: number = 60; private _gravity: Vector3 = new Vector3(); private _nativePhysicsManager: IPhysicsManager; private _physicalObjectsMap: Record = {}; @@ -227,6 +228,15 @@ export class PhysicsManager { } } + get frequency() { + return this._frequency; + } + + set frequency(value: number) { + this._frequency = value; + this._nativePhysicsManager.setFrequency(value); + } + /** * Call on every frame to update pose of objects. * @internal diff --git a/packages/design/src/physics/IPhysicsManager.ts b/packages/design/src/physics/IPhysicsManager.ts index 64f0efde85..a4dca993d9 100644 --- a/packages/design/src/physics/IPhysicsManager.ts +++ b/packages/design/src/physics/IPhysicsManager.ts @@ -42,6 +42,12 @@ export interface IPhysicsManager { */ update(elapsedTime: number): void; + /** + * The times of update in one second. + * @param freq - Frequency. + */ + setFrequency(freq: number): void; + /** * Casts a ray through the Scene and returns the first hit. * @param ray - The ray diff --git a/packages/physics-lite/src/LitePhysicsManager.ts b/packages/physics-lite/src/LitePhysicsManager.ts index bc23dfdd0b..3732078d46 100644 --- a/packages/physics-lite/src/LitePhysicsManager.ts +++ b/packages/physics-lite/src/LitePhysicsManager.ts @@ -85,6 +85,13 @@ export class LitePhysicsManager implements IPhysicsManager { } } + /** + * {@inheritDoc IPhysicsManager.setFrequency } + */ + setFrequency(freq: number): void { + throw "Physics-lite don't support setFrequency. Use Physics-PhysX instead!"; + } + /** * {@inheritDoc IPhysicsManager.update } */ diff --git a/packages/physics-physx/src/PhysXPhysicsManager.ts b/packages/physics-physx/src/PhysXPhysicsManager.ts index 374d83e178..90b874e4d8 100644 --- a/packages/physics-physx/src/PhysXPhysicsManager.ts +++ b/packages/physics-physx/src/PhysXPhysicsManager.ts @@ -23,6 +23,9 @@ export class PhysXPhysicsManager implements IPhysicsManager { } private _pxScene: any; + private _restTime: number = 0; + private _frequency: number = 60; + private _singleStepTime: number = 1.0 / 60.0; private readonly _onContactEnter?: (obj1: number, obj2: number) => void; private readonly _onContactExit?: (obj1: number, obj2: number) => void; @@ -134,13 +137,25 @@ export class PhysXPhysicsManager implements IPhysicsManager { this._pxScene.removeActor(collider._pxActor, true); } + /** + * {@inheritDoc IPhysicsManager.setFrequency } + */ + setFrequency(freq: number): void { + this._frequency = Math.floor(freq); + this._singleStepTime = 1 / Math.floor(freq); + } + /** * {@inheritDoc IPhysicsManager.update } */ update(elapsedTime: number): void { - const step = Math.max(1, Math.floor(elapsedTime * 60)); + const { _frequency: frequency, _singleStepTime: singleStepTime, _restTime: restTime } = this; + + const simulateTime = elapsedTime + restTime; + const step = Math.floor(simulateTime * frequency); + this._restTime = simulateTime - step * singleStepTime; for (let i = 0; i < step; i++) { - this._simulate(1 / 60); + this._simulate(singleStepTime); } this._fetchResults(); From f81b2f923d077cbcbbf0b6891e2e62b1a73ab7a5 Mon Sep 17 00:00:00 2001 From: yangfengzzz Date: Mon, 21 Mar 2022 15:12:31 +0800 Subject: [PATCH 7/9] feat: physics fix-time update --- packages/core/src/ComponentsManager.ts | 24 +++++++- packages/core/src/Engine.ts | 2 +- packages/core/src/Script.ts | 26 ++++++-- packages/core/src/physics/DynamicCollider.ts | 9 ++- packages/core/src/physics/PhysicsManager.ts | 60 +++++++++++++++---- .../design/src/physics/IDynamicCollider.ts | 32 +++++----- .../design/src/physics/IPhysicsManager.ts | 6 -- .../physics-lite/src/LitePhysicsManager.ts | 9 +-- .../physics-physx/src/PhysXPhysicsManager.ts | 23 +------ 9 files changed, 115 insertions(+), 76 deletions(-) diff --git a/packages/core/src/ComponentsManager.ts b/packages/core/src/ComponentsManager.ts index 6e37ffa600..0ba5abccb8 100644 --- a/packages/core/src/ComponentsManager.ts +++ b/packages/core/src/ComponentsManager.ts @@ -6,7 +6,7 @@ import { Script } from "./Script"; import { ShaderMacroCollection } from "./shader/ShaderMacroCollection"; import { RenderContext } from "./RenderPipeline/RenderContext"; import { Vector3 } from "@oasis-engine/math"; -import { Collider } from "./physics/Collider"; +import { Collider } from "./physics"; /** * The manager of the components. @@ -19,6 +19,7 @@ export class ComponentsManager { private _onStartScripts: DisorderedArray