-
-
Notifications
You must be signed in to change notification settings - Fork 340
Support custom physX url #2672
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Support custom physX url #2672
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
d3a2104
feat: support custom physx url
luzhuang f7adcb5
refactor: opt comments
GuoLei1990 b703110
refactor: opt code
GuoLei1990 bba09fc
refactor: opt code
GuoLei1990 08e33bf
feat: update physx downgrade url
luzhuang 0b9e280
refactor: opt code
GuoLei1990 5012224
Merge branch feat/configPhysxUrl of github.com:luzhuang/engine into f…
luzhuang 75896c0
refactor: opt code
GuoLei1990 28da9c2
Merge branch 'feat/configPhysxUrl' of github.com:luzhuang/engine into…
GuoLei1990 4523850
refactor: opt code
GuoLei1990 99de030
refactor: opt code
GuoLei1990 90d5ac3
refactor: opt code
GuoLei1990 dfd7e78
refactor: opt code
8000
GuoLei1990 d80e941
refactor: ot code
GuoLei1990 779d438
Merge branch 'dev/1.5' into feat/configPhysxUrl
GuoLei1990 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
/** | ||
* @title PhysX Custom Url | ||
* @category Physics | ||
*/ | ||
import { | ||
WebGLEngine, | ||
SphereColliderShape, | ||
DynamicCollider, | ||
BoxColliderShape, | ||
Vector3, | ||
MeshRenderer, | ||
PointLight, | ||
PrimitiveMesh, | ||
Camera, | ||
Script, | ||
StaticCollider, | ||
ColliderShape, | ||
PBRMaterial, | ||
AmbientLight, | ||
AssetType, | ||
BlinnPhongMaterial, | ||
Entity, | ||
} from "@galacean/engine"; | ||
import { WireframeManager } from "@galacean/engine-toolkit"; | ||
|
||
import { PhysXPhysics, PhysXRuntimeMode } from "@galacean/engine-physics-physx"; | ||
import { initScreenshot, updateForE2E } from "./.mockForE2E"; | ||
|
||
function addBox(rootEntity: Entity, cubeSize: number, x: number, y: number, z: number, index: number) { | ||
const boxEntity = rootEntity.createChild("BoxEntity"); | ||
boxEntity.transform.setPosition(x, y, z); | ||
boxEntity.transform.setScale(-1, 1, 1); | ||
|
||
const boxMtl = new PBRMaterial(rootEntity.engine); | ||
const boxRenderer = boxEntity.addComponent(MeshRenderer); | ||
boxMtl.baseColor.set(0.6, 0.3, 0.3, 1.0); | ||
boxMtl.roughness = 0.5; | ||
boxMtl.metallic = 0.0; | ||
boxRenderer.mesh = PrimitiveMesh.createCuboid(rootEntity.engine, cubeSize, cubeSize, cubeSize); | ||
boxRenderer.setMaterial(boxMtl); | ||
if (index === 0) { | ||
boxMtl.baseColor.set(1, 0, 0, 1.0); | ||
} else { | ||
boxMtl.baseColor.set(0, 1, 0, 1.0); | ||
} | ||
|
||
const physicsBox = new BoxColliderShape(); | ||
physicsBox.size = new Vector3(cubeSize, cubeSize, cubeSize); | ||
physicsBox.material.staticFriction = 0.1; | ||
physicsBox.material.dynamicFriction = 0.2; | ||
physicsBox.material.bounciness = 1; | ||
physicsBox.isTrigger = true; | ||
|
||
const boxCollider = boxEntity.addComponent(StaticCollider); | ||
boxCollider.addShape(physicsBox); | ||
return boxEntity; | ||
} | ||
|
||
WebGLEngine.create({ canvas: "canvas", physics: new PhysXPhysics(PhysXRuntimeMode.Auto, { | ||
physXUrl: "../physx.release.js" | ||
}) }).then((engine) => { | ||
engine.canvas.resizeByClientSize(); | ||
const scene = engine.sceneManager.activeScene; | ||
const rootEntity = scene.createRootEntity("root"); | ||
|
||
scene.ambientLight.diffuseSolidColor.set(1, 1, 1, 1); | ||
scene.ambientLight.diffuseIntensity = 1.2; | ||
|
||
// init camera | ||
const cameraEntity = rootEntity.createChild("camera"); | ||
const camera = cameraEntity.addComponent(Camera); | ||
cameraEntity.transform.setPosition(-5, 0, 20); | ||
|
||
// init point light | ||
const light = rootEntity.createChild("light"); | ||
light.transform.setPosition(0, 3, 0); | ||
light.addComponent(PointLight); | ||
|
||
// create box test entity | ||
const boxEntity1 = addBox(rootEntity, 2, 0, 0, 0, 0); | ||
const boxEntity2 = addBox(rootEntity, 2, -10, 0, 0, 1); | ||
|
||
// create sphere test entity | ||
const radius = 1.25; | ||
const sphereEntity = rootEntity.createChild("SphereEntity"); | ||
sphereEntity.transform.setPosition(-2, 0, 0); | ||
|
||
const sphereMtl = new PBRMaterial(engine); | ||
const sphereRenderer = sphereEntity.addComponent(MeshRenderer); | ||
sphereMtl.baseColor.set(Math.random(), Math.random(), Math.random(), 1.0); | ||
sphereMtl.metallic = 0.0; | ||
sphereMtl.roughness = 0.5; | ||
sphereRenderer.mesh = PrimitiveMesh.createSphere(engine, radius); | ||
sphereRenderer.setMaterial(sphereMtl); | ||
|
||
const physicsSphere = new SphereColliderShape(); | ||
physicsSphere.radius = radius; | ||
physicsSphere.material.staticFriction = 0.1; | ||
physicsSphere.material.dynamicFriction = 0.2; | ||
physicsSphere.material.bounciness = 1; | ||
|
||
const sphereCollider = sphereEntity.addComponent(DynamicCollider); | ||
sphereCollider.isKinematic = true; | ||
sphereCollider.addShape(physicsSphere); | ||
|
||
rootEntity.addComponent(MeshRenderer); | ||
const wireframe = rootEntity.addComponent(WireframeManager); // debug draw | ||
wireframe.addEntityWireframe(sphereEntity); | ||
wireframe.addEntityWireframe(boxEntity1); | ||
wireframe.addEntityWireframe(boxEntity2); | ||
|
||
class MoveScript extends Script { | ||
pos: number = -5; | ||
vel: number = 0.05; | ||
velSign: number = -1; | ||
|
||
onPhysicsUpdate() { | ||
if (this.pos >= 5) { | ||
this.velSign = -1; | ||
} | ||
if (this.pos <= -15) { | ||
this.velSign = 1; | ||
} | ||
this.pos += this.vel * this.velSign; | ||
this.entity.transform.worldPosition.set(this.pos, 0, 0); | ||
} | ||
} | ||
|
||
// Collision Detection | ||
class CollisionScript extends Script { | ||
onTriggerExit(other: ColliderShape) { | ||
(<BlinnPhongMaterial>sphereRenderer.getMaterial()).baseColor.set(1, 1, 1, 1.0); | ||
} | ||
|
||
onTriggerEnter(other: ColliderShape) { | ||
(sphereRenderer.getMaterial() as BlinnPhongMaterial).baseColor = ( | ||
other.collider.entity.getComponent(MeshRenderer)?.getMaterial() as PBRMaterial | ||
).baseColor; | ||
} | ||
|
||
onTriggerStay(other: ColliderShape) {} | ||
} | ||
|
||
sphereEntity.addComponent(CollisionScript); | ||
sphereEntity.addComponent(MoveScript); | ||
|
||
engine.resourceManager | ||
.load<AmbientLight>({ | ||
type: AssetType.Env, | ||
url: "https://gw.alipayobjects.com/os/bmw-prod/89c54544-1184-45a1-b0f5-c0b17e5c3e68.bin" | ||
}) | ||
.then((ambientLight) => { | ||
scene.ambientLight = ambientLight; | ||
updateForE2E(engine, 95); | ||
initScreenshot(engine, camera); | ||
}); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Inconsistent material types and empty method.
There's a mismatch in material types and an empty method that could be improved.
📝 Committable suggestion
🤖 Prompt for AI Agents