Does anyone know how to access the impostor physics of a model imported from Blender3D with physical properties?
The export format is .babylon
I am using this code, but it doesn’t work.
You can see it in playground
https://www.babylonjs-playground.com/#UV4X1G#19
Summary of the problem
var suelo: BABYLON.PhysicsImpostor = <unknown>scene.getNodeByName("suelo") as BABYLON.PhysicsImpostor;
if(suelo)//If the soil exists
{
console.log(suelo.mass);//NO WORK
mostrarColisiones.showImpostor(suelo);//NO WORK
suelo.onCollideEvent = (collider, collidedWith) =>{
console.log("algo colisiono con el suelo")//NO WORK
if(BABYLON.Tags.GetTags(collidedWith) === "cuboTags")//NO WORK
{
console.log("el cubo colisiono");//NO WORK
}
};
}
I believe the GLTF 2.0 format supports physics as well (or at least there was a discussion about it some months ago), have you tried it?
No, but now I try it and I tell you, another problem I am having is that if I use an empty object for parent, the physicsImpostor are miscalculated, it is positioned and they scale anywhere
I did several tests with official Blender 2.82 glTF2 and unfortunately it doesn’t export the physical properties like the babylon plugin does.
However, I observe that if I want to see the impostor of a model with physics imported from Blender3D, I cannot do it either.
var showCollision: BABYLON.Debug.PhysicsViewer = new BABYLON.Debug.PhysicsViewer(scene);
showCollision.showImpostor(soil);
The .babylon exporter exports the collision shape, physicsImposter in BJS, when doing rigid body. The load also enables physics for the scene, I believe. If you wish something to stop when it hits something else, you also need to set to check collisions.
I do not know much about physics, but you are doing that. Your pg seems to drop the block, stopping on the ground.
I do not see anywhere you can look up imposters through the scene. Also, the mesh seems to have no idea that it has an imposter. Wild guess is so that one of many physics systems could be used, and a physics system is optional.
Maybe try to see if you can look it up with the physics engine. It surely must have the list of them.
You know I was able to find the physical bodies, but I can’t interact with them, I would also like to know how to access the node from that physical body
var impostores:BABYLON.PhysicsImpostor[] = physicsEngine.getImpostors();
console.log(impostores.length);
BABYLON.Tags.AddTagsTo(impostores[1],"cuboTags");
////////////////////NO WORK//////////////////////////////////
if(impostores[0] != null)
{
impostores[0].onCollideEvent = (collider, collidedWith) => { //NO WORK
console.log("algo colisiono con el suelo")//NO WORK
if (BABYLON.Tags.GetTags(collidedWith) === "cuboTags")//NO WORK
{
console.log("el cubo colisiono");//NO WORK
}
};
}
This way it works, but I have to place the object that is going to collide.
var impostores:BABYLON.PhysicsImpostor[] = physicsEngine.getImpostors();
console.log(impostores.length);
BABYLON.Tags.AddTagsTo(impostores[1],"cuboTags");
console.log(impostores[1]);
////////////////////WORK BUT....//////////////////////////////////
impostores[0].registerOnPhysicsCollide(impostores[1],
function(collider: BABYLON.PhysicsImpostor,collidedAgainst: BABYLON.PhysicsImpostor)
{
if (BABYLON.Tags.GetTags(collidedAgainst) === "cuboTags")//WORK
{
console.log("el cubo colisiono");//WORK
}
});
The first parameter can be an array, therefore I have solved the collision detection problem using groups.
const physicsEngine:BABYLON.IPhysicsEngine = scene.getPhysicsEngine()
var impostores:BABYLON.PhysicsImpostor[] = physicsEngine.getImpostors();
console.log(impostores.length);
BABYLON.Tags.AddTagsTo(impostores[1],"cuboTags");
console.log(impostores[1]);
////////////////////WORK!!!!!.//////////////////////////////////
impostores[0].registerOnPhysicsCollide(impostores,
function(collider: BABYLON.PhysicsImpostor,collidedAgainst: BABYLON.PhysicsImpostor)
{
if (BABYLON.Tags.GetTags(collidedAgainst) === "cuboTags")//WORK
{
console.log("el cubo colisiono");//WORK
}
});
Now I have another problem, which would be to know to which mesh or node that impostor physics belongs, but I think that with this I have 80% of the most complicated part solved, now I can import Blender3D models with Physics to look for the collisions and create interactions with groups .
The detail will be to know to which mesh or node each body belongs.
I had a lot of trouble looking for the tag in the physical body. To fix it I import the tagged mesh from Blender3D (the babylon plugin brings this option), then in an arrangement I look for all the child colliders that have that tag and add the physical body. I put the physics to the parent node but of non-impostor type. In the end I add the tag to the parent node, not to the children and this way I can detect the collisions.
In this post the topic of multiple colliders to 1 object is explained.
“An Important Topic Always place the father impostor after the children and add the label to the father.”
https://playground.babylonjs.com/#66PS52#85
I leave a code example with my solution.
var Columnasfisicas: BABYLON.Mesh[] = scene.getMeshesByTags("obstaculo") as BABYLON.Mesh[];//busco todos los objetos que tienen la etiqueta obstaculo son hijos de un nodo vacio que maneja las columnas fíśicas
Columnasfisicas.forEach(i => { //recorro todos esos objetos ycreo un impostores físicos automaticamente
i.physicsImpostor = new BABYLON.PhysicsImpostor(i, BABYLON.PhysicsImpostor.BoxImpostor, { mass: 0 }, scene);//creo impostores físicos,la masa se va sumando
i.visibility = 0;
});
//An Important Topic Always place the impostor on the father after the children.
var columnasPrincipales: BABYLON.Mesh[] = scene.getMeshesByTags("columnasPrincipal") as BABYLON.Mesh[];//busco el nodo padre que contiene a esas columnas
columnasPrincipales.forEach(i => { //recorro todos esos objetos ycreo un impostores físicos automaticamente
i.physicsImpostor = new BABYLON.PhysicsImpostor(i, BABYLON.PhysicsImpostor.NoImpostor, { mass: 0 }, scene);//creo el impostor físico al padre es importante que este último y que no tenga cuerpo ya que los cuerpos son manejados por los hijos
BABYLON.Tags.AddTagsTo(i.physicsImpostor, "obstaculo")//agrego la etiqueta
i.visibility = 0;
});