ambiera home ambiera home

Ambiera Forum

Discussions, Help and Support.

Create a new account, Search, or Login:
Name:  Password:
Ambiera Forum > CopperLicht
Mesh-Mesh collisions?
Author Text

Mike
Guest
Quote
2014-07-17 17:18:58

I'm trying to develop a simple demo in CL. Part of the functionality expected from it is adding meshes to the scene - that I can do, but I've ran into a difficulty with collisions between the inserted nodes (not a full-blown physics system, all I need is that the nodes stop each other's mvement..

The basic scene, with two cube nodes on a plane, was created in CopperCube. Those two objects can be moved and collide with each other when moved.
Moved nodes collide with the pre-placed ones, but not with the ones added during the demo's operation.
What am I missing or doing wrong?
Here's the code I'm using to add a new node to the scene and add the collision response animator to it:
	MySceneNode = function(engine)
{
var node=new CL3D.MeshSceneNode();
node.setMesh(mesh1);
node.DoesCollision=true;
node.CollidesWithWorld=true;
scene.getRootSceneNode().addChild(node)
node.Pos.X=-10;
node.Pos.Z=-10;
node.refreshCollision();
return node
}

CL3D.SceneNode.prototype.refreshCollision = function () {
var o = this.getAnimatorOfType('collisionresponse');
this.recalculateBoundingBox();
var r = this.Box.getExtent().multiplyWithScal(0.5);
if (o!=null)
{
this.addAnimator(new CL3D.AnimatorCollisionResponse(r, o.getGravity(), new CL3D.Vect3d(0,0,0), o.getWorld()));
this.removeAnimator(o);
}
else
this.addAnimator(new CL3D.AnimatorCollisionResponse(r, new CL3D.Vect3d(0,-10,0), new CL3D.Vect3d(0,0,0), scene.getCollisionGeometry()));
return null
};
CL3D.SceneNode.prototype.recalculateBoundingBox = function () {
this.Box=new CL3D.Box3d();
this.Box.reset(0, 0, 0);
var v=Array();
var m=this.getMesh().MeshBuffers;
if (this.getMesh().MeshBuffers.length + this.Children.length > 0)
{
for (var i=0; i<m.length; i=i+1)
{
m[i].recalculateBoundingBox();
v.push(m[i].Box.MinEdge);
v.push(m[i].Box.MaxEdge);
}
if (this.Children){
for (var i=0; i<this.Children.length; ++i){
this.Children[i].recalculateBoundingBox();
v.push(this.Children[i].getTransformedBoundingBox().MinEdge);
v.push(this.Children[i].getTransformedBoundingBox().MaxEdge);
}
}
this.Box.MinEdge = v[0];
this.Box.MaxEdge = v[1];
for (var i=2; i<v.length; ++i)
{
this.Box.addInternalPointByVector(v[i]);
}
}
};



niko
Moderator
Quote
2014-07-18 05:25:36

This isn't supported, since this would need complex physics calculations between the objects - that's what a physics engine does. What you could do is to add a child object like a cube to each object, so that each object cannot move through each other, and this might work, but not perfectly.

For stuff like that you'd need a real physics engine, and there is a reason they are so complicated and need a lot of CPU power.


Mike
Guest
Quote
2014-07-18 15:33:15

I don't need perfect collisions, nor any physics simulation - if the objects were prevented from clipping each other's bounding box, it would be sufficient.

The pre-placed cubes were showing the desired behavior, and the nodes added at run time (with same mesh) did not, what I was trying to understand was what caused the difference.

Found it now: the collision world was set for the new nodes, but it was not reset when nodes were added, deleted or had their meshes changed. This mostly solves the problem (needs to be called after each of the above events):
CL3D.CopperLicht.prototype.resetCollisionWorld(){
this.getScene().CollisionWorld = this.getScene().createCollisionGeometry(true);
this.setCollisionWorldForAllSceneNodes(this.getScene().getRootSceneNode(), this.getScene().CollisionWorld);
};

To fix the glitch with nodes retaining their old collision after setting new mesh, setMesh() has to be changed a bit:
CL3D.MeshSceneNode.prototype.setMesh = function (a) {
this.OwnedMesh = a;
if (a && a.GetPolyCount() > 100) {
this.Selector = new CL3D.OctTreeTriangleSelector(c.OwnedMesh, c)
} else {
this.Selector = new CL3D.MeshTriangleSelector(a, this)
}
};



Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "?nternational" (you are not logged in)


Text:

 

  

Forum Codes


Feature Code
Link [url] www.example.com [/url]
Bold [b]bold text[/b]
Image [img]http://www.example.com/image.jpg[/img]
Quote [quote]quoted text[/quote]
Code [code]source code[/code]

Emoticons


   





Software: Ambiera Light Forum. © 2008-2019 Nikolaus Gebhardt, Ambiera e.U.