# Mesh Collider?

## Recommended Posts

Is it possible to make mash collision physics calculation only around some radius around mesh?

For example If we have ball with radius 1 unit and some big mesh with 1 milion vertices.

I would like that mesh collision will calculate only collision around radius 5 unit around current ball position. Object with mesh-collision will be rotate at run-time (So if we don't have static-collider object_with_mesh_impostor/collider)

Is possible to add this functions? Can be this funcions accelerate collision calculation?

Greetings
Ian

##### Share on other sites

Hey @ian

Are you mentioning camera collision or physics simulation?

For physics simulation it is easy as all meshes use impostors: So in this case, just set some box/sphere impostors and there is no problem

For camera collision: Camera impostor is an ellipsoid and it is evaluated against bounding sphere, so what you are mentioning is already in place

##### Share on other sites

Simulation. For example I have some mesh and if I use mesh impostor with sphere I have problem if mesh have a lot vertices. Problem is that ball fall over somewhere.

Second example I put 470 box impostors around mesh and use sphere with 470 box impostors. This simulation works reliable/better (ball does not fall over box impostors) But here is physics performance problem (works slower but reliable).

This simulation works so that mesh and box colliders are always rotating!

I would like to know if it will be possible to add mesh impostor on mesh and add some radius around current ball position. So that only mesh's vertices/faces which are inside radius should be calculate physics collision between ball and vertices/faces of mesh around radius

I hope you understand.

Greetings

Ian

##### Share on other sites

Maybe I am asking stupid question?

I don't know exactly how mesh collision works sphere again mesh?
There is probably sphere's radius. And mesh's faces/vertices??? Which mesh's faces/vertices are needed  for calculation physics collision between sphere(SphereImpostor) and mesh(MeshImpostor) ???

##### Share on other sites

So you are talking about physics.

Which engine are you using? Oimo or Cannon?

Cannon

##### Share on other sites

Ok. regarding your question you can still think about using mesh intersections and turn on impostors only when there is a mesh intersection (which is done at bounding box level):

For isntance use actions with BABYLON.ActionManager.OnIntersectionEnterTrigger to add impostor and use BABYLON.ActionManager.OnIntersectionExitTrigger to remove it

##### Share on other sites

aha - thank you for your suggestion

##### Share on other sites

• 3 weeks later...

@RaananW
I prepared two playground (simple and complex(with WSAD rotation)

Deltakosh as you suggest. I put first on loading all Cube... meshes/boxes in colliders array. Than I sey for each colliders as parent of perplexus mesh.
Than I add on each box-mesh-collider (from colliders array) OnIntersectionEnterTrigger and OnIntersectionExitTrigger.
Here I add physicsImpostor.BoxImpostor on each box IF playball and specific box OnIntersectionEnterTrigger happend.
And I remove physicsImpostor.BoxImpostor from specific box in colliders object if OnIntersectionExitTrigger happend.
(F12 console shows ok ..)

BUT playball mesh/sphere fall through. Am I missing anything? Or Am I doing anything incorrect? Any help?

I add also console.log you can see that playBall mesh/sphere fall over

simple example
http://www.babylonjs-playground.com/#1U2VMI#0

``````...
if ( newMesheI.id.substring(0, 4) == "Cube") {
colliders.push( newMesheI );

}
....
....

for (var a=0; a<colliders.length; a++) {
colliders[a].parent = perplexus;
colliders[a].rotationQuaternion = new BABYLON.Quaternion();
colliders[a].isVisible = true;
} // end for set up all colliders

for (var a=0; a<colliders.length; a++) {
colliders[a].actionManager = new BABYLON.ActionManager(scene);
colliders[a].actionManager.registerAction(
new BABYLON.ExecuteCodeAction(
{ trigger: BABYLON.ActionManager.OnIntersectionEnterTrigger, parameter: { mesh:playBall, usePreciseIntersection: true}  },
function(evt) {
console.log("onIntersectioneEnterTrigger BEGIN");
console.log("Object ID - intersection = "+evt.source.id);
console.log("Object ID - begin physicsImpostor = "+evt.source.physicsImpostor);
evt.source.checkCollisions = true;
if ( evt.source.physicsImpostor == undefined ) {
evt.source.physicsImpostor = new BABYLON.PhysicsImpostor( evt.source, BABYLON.PhysicsImpostor.BoxImpostor, { mass : 0, friction : 1, restitution : 0 }, scene);
console.log("Object ID - end physicsImpostor = "+evt.source.physicsImpostor);
console.log("onIntersectioneEnterTrigger END");
}
})
);

colliders[a].actionManager.registerAction(
new BABYLON.ExecuteCodeAction(
{ trigger: BABYLON.ActionManager.OnIntersectionExitTrigger, parameter: { mesh:playBall, usePreciseIntersection: true}  },
function(evt) {
console.log("onIntersectionExitTriger BEGIN");
console.log("Object ID - intersection = "+evt.source.id);
console.log("Object ID - begin physicsImpostor = "+evt.source.physicsImpostor);
evt.source.checkCollisions = false;
if ( evt.source.physicsImpostor != undefined ) {
evt.source.physicsImpostor = undefined;
}
})
);
} // end set up enter end exit triggers/listeners on all Cube boxes (adding impostor and removeing impostors)
``````

complex example (this playground has more code camera is focusing on ball and you can rotate model with WSAD but ball fall over....)
http://www.babylonjs-playground.com/#VZM8J#0

Greetings,

Ian

Hello

##### Share on other sites

``````if ( newMesheI.id.substring(0, 4) == "Cube") {
colliders.push( newMesheI );
newMesheI.physicsImpostor = new BABYLON.PhysicsImpostor( newMesheI, BABYLON.PhysicsImpostor.BoxImpostor, { mass : 0, friction : 1, restitution : 0 }, scene);
}``````

As I can see you add physicsImpostor at the beginning. (If you do same on my complex example. you will see that BoxImpostor(physics) are static and are not moving.

No I would like that BoxImpostors are moving. I don't want static BoxImpostors.

1.alternative
Or I want to activate only those BoxImpostors which are enter-intersection with playBall and deactivate those BoxImpostors exit-which are intersection.

2.alternative
Or If we imagine PlayBall with radius 1. and Virtual_PlayBall->(as child of PlayBall) with radius 5.

If we calculate intersection-faces of Perplexus with Virtual_PlayBall at each frame/physics_steep. I would like that physics-collision will work/calculate only between PlayBall and intersection-faces of Perplexus.

....................

Maybe I am asking stupid question. What I would like to achieve is that collision between perplexus and playball will calculate only around some virtual-sphere(this virtual-sphere is child of playBall) area ( or specific example around radius 5 around virtual-sphere).
I want that perplexus can have "unlimited/lot of" number of vetices. If I understand correct if we have for example to big perplexus model the mesh collision is not reliable any more.

Is possible to custom MeshImpostor/Mesh_collision. To add some parameter(virtual_sphere_area) and that collision between ball and mesh will calculate only intersection faces of mesh and virtual_sphere_area and playball.

##### Share on other sites

Rannan is possible to enable/disable box physics colliders at runtime(render or physics time)?

Is possible to rotate phsycs box colliders/impostors and enable only those which happen enter-intersection between ball/sphere and boxes(which are intended for box impostors/colliders).

or

If we initialize all cubes as box impostors and if cubes are child of perplexus. Does box impostors rotate/move if we rotate perplexus or are those box impostors static?

Is possible to achieve anything like that???

Rannan what is your opinion to achieve that and what do you think about performance impact?

##### Share on other sites

we are trying to do some example with parent-child box colliders. I'll report if this will work.

greetings
Ian

##### Share on other sites

I'll see with raanan to see if he has time

##### Share on other sites

Hi @ian,

there is the option to make a collider "sleep" and "wakeUp" (both functions are implemented on the physics collider), which stops the physics engine from applying forces on the box. Is this what you are looking for?

##### Share on other sites

RannanW, I and my friend solve this problem.
Now colliders(box-impostors) are as child of model. Model and colliders are rotating as expected!
So physics works as charm (perfect). I have 470 box colliders and everythink work fine (reliable working physics collision): And performance are fine too.
Soon I'll show when I finsih upgrade of game (almost finish I am trying also to make custom camera aligment... - alternative).

RannaW thank you for your post (Il save it) Maybe someday I'll try something like that sleep and wakUp..

greetings
Ian

##### Share on other sites

On 4/5/2017 at 0:30 AM, RaananW said:

Hi @ian,

there is the option to make a collider "sleep" and "wakeUp" (both functions are implemented on the physics collider), which stops the physics engine from applying forces on the box. Is this what you are looking for?

@RaananW
RaananW is there any playground showcase for learning to see how works sleep and wakeUp ?

Greetings
Ian

##### Share on other sites

there should be one, right?  I will try making one this evening, after fixing the extend size bug

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.