lo-th / phy Goto Github PK
View Code? Open in Web Editor NEWPhysics for three. Game engine
Home Page: https://lo-th.github.io/phy/
License: MIT License
Physics for three. Game engine
Home Page: https://lo-th.github.io/phy/
License: MIT License
(physx) Adding a contact between a vehicle and a body is never triggered.
However, the worker does detect the contact - it only doesn't find the name of the object so it doesnt call the callback.
In the supplied screenshot - when the worker receives the "addVehicle" - it just lacks:
case "vehicle":
C.set(A.vehicleActor.ptr, A.name);
then later on, Q is found correctly as the vehicle and the callback reaches phy.
Hey,
I love your work on phy and would like to donate 50eur, but I am not comfortable to share my private address (which is required by paypal).
Don't you have github sponsors?
Thanks
Yannick
Hi there!
Been playing a little trying to understand how breakables work and have some questions about the intended use case.
I saw that when breaking the object by slicing its geometry (which sits as a children[0] of the Basic3D container) - then discards the parent Basic3D object and sets the children as the parent.
This has a nuber of implications, as the children is not a Basic3D:
1 - object will be at 0,0,0 - ish (as the children pos & quat are the decal - and the real worldpos & quat were in the discarded quats
2 - collisions are then (broken/unstable) - what happens with the collision shape, volume, etc... ?
3 - several places where this body is indexed will rty to call stuff from the basic3d object causing crashes
4 - also - in the case of instances it will fail right away because there is no mesh as chilren of the (fake) instance Basic3d.
Soooo --- As the functionality looks really cool - i wonder how it should be used ? ?
thanks in advance !!!
Hello !
So i have been fiddling with Hero so he can now board platforms and move alongside them -- the development was nearly finished I just added a couple things here and there. Do you think it is a good solution ?
https://gist.github.com/nebular/81025fdb25ed6cc7b563437948ad3989
https://www.youtube.com/watch?v=8hva2y7IyWo
also im trying to fix the jump and always come up with everything screwed up! Why is it so difficult to add the impulse vertical :( can you share some advice about that ?
thanx in advance!
Please provide some reference to any API documentation
Like how to play pause animation and physics
get/set the mas velocity on runtime and other available properties of bodies
enable disable physics in runtime
change materials in runtime
thanks for reading...
Can you please provide a sample implementation
Is there an example template project that demonstrates importing phy and using it in another project?
Using rollup or vite
DeepMind bought the company behind MuJoCo a while ago and open sourced it. It's a very robust engine with a huge ecosystem around it. It's a general-purpose engine, but it's particularly well-suited to bringing embodied agents that are trained via reinforcement learning into games, since most software for training RL agents uses MuJoCo as the physics engine. The idea is that you train with Python, and then you can deploy on the web with no "domain gap" problem.
Despite being more robust / 'scientifically accurate' than game-oriented physics engines, it is still fast/efficient. Here's an existing wasm port:
I'm not sure how hard this would be to add to Phy, but if it's feasible then that would be very exciting!
Some more links to check out:
Since Jolt now has soft body support, it'd be neat if Phy had support too:
There are some caveats to the current implementation though - e.g. soft bodies can only collide with rigid bodies (not other soft bodies, and I'm guessing soft body self-collision is not supported either, but just a guess).
Maybe with all the caveats listed in the linked comment it is too early to add to Phy, but I guess it might be handy to have this tracking issue for it anyway.
If I run npm run build
I get [!] Error: Could not resolve './_physx/engine.js' from src/Physx.js
because the /src/_physx
directory is not in the repo. Is there a way to get that code? Thanks.
It appears that commit 8c495fb broke the robot PhysX example.
Thank you for the awesome library!! ๐
While its true that is incorrect to issue ```phy.change({name:"solid1", wake:true}) - the worker throws an unhandled exception and dies.
I fixed it in physx.module just adding a check (A.wake && I.wakeUp && i.wakeUp())
```if (I.isBone || (A.sleep && (I.putToSleep(), g = !1), A.wake && I.wakeUp && I.wakeUp() ...````
I ran into this problem when trying to deploy to github pages, which puts everything in a subdirectory with the name of your project ie:
https://ubernaut.github.io/simple-template/
you should be able to pass in a relative path (like './') so compact would be resolved at:
https://ubernaut.github.io/simple-template/compact
instead, it will insist on trying to find it here:
https://ubernaut.github.io/compact/
this doesn't work, phy will fail to find the physics hex files in compact if they aren't at the root of your url's path:
phy.init({
type: "physx",
worker: true,
compact: true,
scene: scene,
renderer: renderer,
callback: physicsReady,
path: './'
});
workaround:
You can pass in an explicit path and it does correctly prefix the dependencies so set an env variable in your package script for the path you want to use. like this (start is for local dev where it can run at root, and build is for gh pages):
"scripts": {
"test": "",
"start": "export stpath='./'; parcel --https index.html",
"build": "export stpath='/simple-template/'; parcel build index.html --public-url /simple-template/"
},
then reference the variable in the init
phy.init({
type: "physx",
worker: true,
compact: true,
scene: scene,
renderer: renderer,
callback: physicsReady,
path: process.env.stpath
});
let mP
onComplete = () => {
mP = phy.add({ name:'movingPlatform', type:'box', pos:[0,0,0], size:[10,1,10], restitution:0, friction:0.5, kinematic:true})
phy.add({type: 'box', material:'chrome', size: [1,1,1], pos: [0, 1.1, 0] })
}
update = () => {
phy.change( { name:mP.name, pos:[mP.position.x, mP.position.y, mP.position.z+0.1], wake:true } )
}
box1 isn't effected by the movement of the platform underneath it when using Physx.
Create some objects that make use of InstancedMesh
let test = []
for(let i=0; i < 100; i++) {
test.push(phy.add( { type: 'cylinder', size:[1,1], instance:'someObj', mesh:aMesh, pos:[0,i,0]} ))
}
Then remove some.
setTimeout( () => {
for(let i=0; i < 100; i+=2) {
phy.remove(test[i].name)
}
}, 2000)
The mesh of the removed objects remains in view.
I've also seen an issue where the remaining instances then flicker in and out of view.
So if you add a joint with "debug" turned off
When removing this joint, phy.remove(joint.name)
--- the routine in Motor will do nothing, as phy.byName() returns null - however the joint is kept alive in the worker.
This causes many nasty bugs - for example
if you remove any object part of the joint, the worker (physx at least) will later crash on stepItems (when attempting to call getGlobalPose() on the existing joints, but their objects do not exist.
if joints belong to instancemeshes and instances are removed, joints are kept alive and sometimes point to the wrong instance, resulting in funny joints between incorrect objects in the scene
After that crash, worker must be restarted.
My temp fix:
// RLP: SEND ALWAYS TO MOTOR to remove non-exising joints
static remove(name, direct = false, physicsType = "joint") {
if (name.constructor === Array) return Motor.removes(name, direct);
let b = Motor.byName(name);
if (b) {
// remove on three side
if (b.extraRemove) b.extraRemove();
ITEM_LIBRARY[b.type].clear(b);
}
const objectType = b ? b.type : physicsType;
// remove on physics side
if (objectType) root.post({ m: "remove", o: { name: name, type: objectType } }, null, direct);
}
So when removing joints, I call remove(jointName, false, "joint") - or remove(jointName, false) as physicsType is set to joint. It's not the most elegant but it works well.
hello,
Do you plan to add the softBody demos?
just like virtual clothes
First of all, thats a really really great project.
I'd like to ask if you could provide the code for Havok terrain?
I would be incredibly grateful.
Hello,
Could you add https://schteppe.github.io/cannon.js/ to the test on https://lo-th.github.io/phy/?
Hey,
do you have any plans to add this two physics?
Hello! I would like advice about how to use this phy physics engine in Freeciv 3D, which uses Three.js.
How can I use this physics engine, and what in the game client would benefit from a physics engine? Thank you!
I am making a web app using ThreeJS and React
It's very similar with the museum example of phy
I implemented almost of functionalities using Phy
However I encountered in issue to load custom museum model
phy.load(
'dices.glb',
onComplete
)
phy.load(
['dices.glb', 'yo.jpg'],
onComplete
)
This code are wrotten at the Phy engine guide
https://lo-th.github.io/phy/docs/index.html#manual/phy-load
But this code doesn't works in my project
I will share my main code:
const loadModels = () => {
const models = ["./assets/models/musee.glb"];
phy.load([...models], onCompleteLoadModels);
};
const onCompleteLoadModels = () => {}
This code occured errors at the crhome console like the following:
index.tsx:86 SyntaxError: Unexpected token '<', "<!doctype "... is not valid JSON
at JSON.parse (<anonymous>)
at GLTFLoader.parse (Phy.module.js:17994:17)
at Object.onLoad (Phy.module.js:17889:11)
at three.module.js:44245:38
If I remove the above code, all works well
In one word, if I use simple model like box, the project works well
But if I gonna load new model, it occur error
It's a urgent project, so I would be happy anyone let me know how to overcome this issue
Best regards
The lib uses a custom build directly from Bullet 3.1.7 last version?
Could you share the build script and code adaptations needed?
Awesome lib and demo visuals btw!
https://lo-th.github.io/phy/docs/scenes/engines.html#PHYSX
ysx.module.js:1 Failed to load resource: the server responded with a status of 404 ()
Phy.module.js:26368 Uncaught (in promise) TypeError: Failed to fetch dynamically imported module: https://lo-th.github.io/phy/docs/scenes/build/Physx.module.js
I was hoping to make a chain (out of hundreds of linked torus shaped objects), but that isn't a convex hull. Does this project support full mesh-based collisions? It looks like it does with the gear demo, but that may have been some creative modelling of multiple convex shapes glued together.
Thanks! This project looks amazing!
Could you add a simple example to how to add a gdb model to the scene ?
Hello, your work is amazing. But I was wondering how to use it for example on the server, is it very linked with ThreeJS, maybe have a headless option? So we can use it both on the client and on the server.
can you please give me some advice or submit a new demo?
Cool project! Just tried out the demo and noticed that the ragdolls fall apart when using the Havok engine.
(Also, random question: Are soft bodies supported with Havok or PhysX?)
What design patterns were used?
phy.add({ type:'contact', b1:obj1.name, b2:'obj2.name, callback: someCallback })
In Havok someCallback is called for all collisions involving obj1, not just those involving obj2 but arg.hit is always false.
Phsyx works as expected
Rapier, seems to always have arg.hit == true
Also, including all details of the contact in the collision callback argument is probably needed in most real world uses - body1, body2, position, velocity etc
Hi there Lo.th!
I will send a separate message detailing how much I love you and what an endless collection of awesomeness this repository is. Im learning so much.
I only use PHYSX engine (that has the native vehicle) - so maybe the bug does not apply to other ones.
There is something with the vehicle wheels that make them sink in kinematic platforms and lose traction. I have compiled a short video showing the issue, shall you find the time to take a look and share some advice.
https://www.youtube.com/watch?v=RubbU1yXCKc
Thanks for your awesome work.
In the documentation the example show worker : false
by default
Shoudnt it be true
by default / in the doc example for the performance ?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.