Skip to content

Commit

Permalink
Merge branch 'main' into dev/1.1
Browse files Browse the repository at this point in the history
* main:
  Add physic unit test timeout (#1717)
  "v1.0.0-beta.20"
  Fix `PhysicManager`  fixedTimeStep less than 0 bug (#1715)
  Fix physx unit test (#1714)
  Fix a series of physical system problems (#1712)
  Fix avoid destroyed material error (#1705)
  "v1.0.0-beta.19"

# Conflicts:
#	packages/core/package.json
#	packages/core/src/physics/PhysicsScene.ts
#	packages/design/package.json
#	packages/draco/package.json
#	packages/galacean/package.json
#	packages/loader/package.json
#	packages/math/package.json
#	packages/physics-lite/package.json
#	packages/physics-lite/src/LitePhysicsManager.ts
#	packages/physics-physx/package.json
#	packages/physics-physx/src/PhysXPhysics.ts
#	packages/rhi-webgl/package.json
#	tests/package.json
  • Loading branch information
GuoLei1990 committed Aug 30, 2023
2 parents 971a450 + 2312080 commit d6f97f7
Show file tree
Hide file tree
Showing 14 changed files with 378 additions and 48 deletions.
19 changes: 14 additions & 5 deletions packages/core/src/physics/PhysicsScene.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ICharacterController, ICollider, IPhysics, IPhysicsScene } from "@galacean/engine-design";
import { Ray, Vector3 } from "@galacean/engine-math";
import { MathUtil, Ray, Vector3 } from "@galacean/engine-math";
import { DisorderedArray } from "../DisorderedArray";
import { Layer } from "../Layer";
import { Scene } from "../Scene";
Expand All @@ -20,6 +20,7 @@ export class PhysicsScene {

private _scene: Scene;
private _restTime: number = 0;
private _fixedTimeStep: number = 1 / 60;

private _colliders: DisorderedArray<Collider> = new DisorderedArray();

Expand Down Expand Up @@ -155,9 +156,6 @@ export class PhysicsScene {
}
};

/** The fixed time step in seconds at which physics are performed. */
fixedTimeStep: number = 1 / 60;

/**
* The gravity of physics scene.
*/
Expand All @@ -172,6 +170,17 @@ export class PhysicsScene {
}
}

/**
* The fixed time step in seconds at which physics are performed.
*/
get fixedTimeStep(): number {
return this._fixedTimeStep;
}

set fixedTimeStep(value: number) {
this._fixedTimeStep = Math.max(value, MathUtil.zeroTolerance);
}

constructor(scene: Scene) {
this._scene = scene;

Expand Down Expand Up @@ -302,7 +311,7 @@ export class PhysicsScene {
* @internal
*/
_update(deltaTime: number): void {
const { fixedTimeStep, _nativePhysicsScene: nativePhysicsManager } = this;
const { _fixedTimeStep: fixedTimeStep, _nativePhysicsScene: nativePhysicsManager } = this;
const componentsManager = this._scene._componentsManager;

const simulateTime = this._restTime + deltaTime;
Expand Down
2 changes: 1 addition & 1 deletion packages/physics-lite/src/shape/LiteSphereColliderShape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class LiteSphereColliderShape extends LiteColliderShape implements ISpher
* {@inheritDoc IColliderShape.setWorldScale }
*/
setWorldScale(scale: Vector3): void {
this._maxScale = Math.max(scale.x, Math.max(scale.x, scale.y));
this._maxScale = Math.max(scale.x, scale.y, scale.z);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/physics-physx/libs/physx.release.js

Large diffs are not rendered by default.

64 changes: 32 additions & 32 deletions packages/physics-physx/libs/physx.release.js.js

Large diffs are not rendered by default.

Binary file modified packages/physics-physx/libs/physx.release.js.mem
Binary file not shown.
Binary file added packages/physics-physx/libs/physx.release.wasm
Binary file not shown.
2 changes: 1 addition & 1 deletion packages/physics-physx/src/PhysXCharacterController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,6 @@ export class PhysXCharacterController implements ICharacterController {
*/
_setLocalPosition(position: Vector3, scale: Vector3): void {
Vector3.multiply(position, scale, this._scaledOffset);
this.setWorldPosition(this._position);
this.setWorldPosition(position);
}
}
8 changes: 3 additions & 5 deletions packages/physics-physx/src/PhysXPhysics.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Quaternion, Vector3 } from "@galacean/engine";
import { Quaternion, Vector3, version } from "@galacean/engine";
import {
IBoxColliderShape,
ICapsuleColliderShape,
Expand Down Expand Up @@ -89,11 +89,9 @@ export class PhysXPhysics implements IPhysics {
}

if (runtimeMode == PhysXRuntimeMode.JavaScript) {
script.src =
"https://gw.alipayobjects.com/os/lib/oasis-engine/physics-physx/1.0.0-alpha.4/libs/physx.release.js.js";
script.src = `https://gw.alipayobjects.com/os/lib/galacean/engine-physics-physx/${version}/libs/physx.release.js.js`;
} else if (runtimeMode == PhysXRuntimeMode.WebAssembly) {
script.src =
"https://gw.alipayobjects.com/os/lib/oasis-engine/physics-physx/1.0.0-alpha.4/libs/physx.release.js";
script.src = `https://gw.alipayobjects.com/os/lib/galacean/engine-physics-physx/${version}/libs/physx.release.js`;
}
});

Expand Down
2 changes: 1 addition & 1 deletion packages/physics-physx/src/shape/PhysXColliderShape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export abstract class PhysXColliderShape implements IColliderShape {
}
const controllers = this._controllers;
for (let i = 0, n = controllers.length; i < n; i++) {
controllers.get(i)._pxController.setLocalPosition(this._position, this._scale);
controllers.get(i)._setLocalPosition(this._position, this._scale);
}

this._setLocalPose();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class PhysXSphereColliderShape extends PhysXColliderShape implements ISph
override setWorldScale(scale: Vector3): void {
super.setWorldScale(scale);

this._maxScale = Math.max(scale.x, Math.max(scale.x, scale.y));
this._maxScale = Math.max(scale.x, scale.y, scale.z);
this._pxGeometry.radius = this._radius * this._maxScale;
this._pxShape.setGeometry(this._pxGeometry);
}
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
"@galacean/engine-math": "workspace:*",
"@galacean/engine-rhi-webgl": "workspace:*",
"@galacean/engine-physics-lite": "workspace:*",
"@galacean/engine-shader-lab": "workspace:*"
"@galacean/engine-shader-lab": "workspace:*",
"@galacean/engine-physics-physx": "workspace:*"

}
}
40 changes: 40 additions & 0 deletions tests/src/core/physics/CharacterController.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { Entity, CapsuleColliderShape, CharacterController } from "@galacean/engine-core";
import { Ray, Vector3 } from "@galacean/engine-math";
import { PhysXPhysics } from "@galacean/engine-physics-physx";
import { WebGLEngine } from "@galacean/engine-rhi-webgl";
import { expect } from "chai";

describe("physics collider test", function () {
this.timeout(5000);

let engine: WebGLEngine;
let rootEntity: Entity;
let controllerEntity: Entity;

before(async () => {
engine = await WebGLEngine.create({ canvas: document.createElement("canvas"), physics: new PhysXPhysics() });
const scene = engine.sceneManager.activeScene;
rootEntity = scene.createRootEntity("root");

engine.run();
});

beforeEach(() => {
rootEntity.clearChildren();

controllerEntity = rootEntity.createChild("controller");
});

it("Set Position", async () => {
const physicsCapsule = new CapsuleColliderShape();
physicsCapsule.radius = 0.15;
physicsCapsule.height = 0.2;
const characterController = controllerEntity.addComponent(CharacterController);
characterController.addShape(physicsCapsule);

physicsCapsule.position = new Vector3(5, 3, 3);
expect(physicsCapsule.position.x).to.equal(5);
expect(physicsCapsule.position.y).to.equal(3);
expect(physicsCapsule.position.z).to.equal(3);
});
});
Loading

0 comments on commit d6f97f7

Please sign in to comment.