Collision Against Uniform Grid (Voxel) Without Creating Mesh

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Re: Collision Against Uniform Grid (Voxel) Without Creating

Postby Layla » Wed Oct 02, 2013 5:34 pm

Yeah I'm scaling the shape I get back from the body using NewtonBodyGetCollision. The strange thing is that with no scaling the physics simulation is still pretty fast even with massive bodies colliding against the scene. It just grinds the application to a halt if I scale after the body is made. I could just scale before the body is created which works perfect but I want the option to scale bodies at runtime. Very odd.
Layla
 
Posts: 54
Joined: Sat Sep 28, 2013 11:56 am

Re: Collision Against Uniform Grid (Voxel) Without Creating

Postby Julio Jerez » Wed Oct 02, 2013 6:22 pm

If anything it should be the non scale one that is slow.

usually I can check a serialized copy, but you say that is does not happen when you do that.
do you have a test that I can try? if you do you need to link ti to the newton DLL, so that I can attach the debugger.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Collision Against Uniform Grid (Voxel) Without Creating

Postby Layla » Wed Oct 02, 2013 6:30 pm

I would but I can't distribute it yet. I'll try and replicate it in the demo sandbox. If it helps, the problem doesn't happen if I use the convex collision on its own, it's just when I put it inside a compound.
Layla
 
Posts: 54
Joined: Sat Sep 28, 2013 11:56 am

Re: Collision Against Uniform Grid (Voxel) Without Creating

Postby Julio Jerez » Wed Oct 02, 2013 6:35 pm

you are scaling the collision shape directly,
try this: NewtonBodySetCollisionScale (const NewtonBody* const body, dFloat scaleX, dFloat scaleY, dFloat scaleZ);

I do not know if it will make a difference, by when you scale a shape, the represeation of the shape on teh braphase does not know about that
the body scale make sure that the broaphase is updated appropriatle.

The broaphase in newton use an static procces to reduce the entropy of the mesh, it is possible tha the scale it triggering a full broaphase update each frame, that will be bad if you have too many objects
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Collision Against Uniform Grid (Voxel) Without Creating

Postby Julio Jerez » Wed Oct 02, 2013 6:36 pm

ha if you can recreate the situation on the demes that will be much better.
you can hack anyone

do you mean, the compound has only one shape? and you are apply an uniform scale?
that seems very wierd behavior, because teh compound collsion are resule with the same function that is use for single collisions.

maybe there is a bug in the compund vs compound with scale on them, bu I had test with compound of up to 400 convexes and I did not see any difference
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Collision Against Uniform Grid (Voxel) Without Creating

Postby Layla » Wed Oct 02, 2013 6:38 pm

Yep I've also tried scaling the body of the compound, the exact same thing happens. Sorry I can't be of anymore help, I'm trying to recreate it in the demo sandbox, it's just taking me a while because I'm not used to the code base.
Layla
 
Posts: 54
Joined: Sat Sep 28, 2013 11:56 am

Re: Collision Against Uniform Grid (Voxel) Without Creating

Postby Layla » Wed Oct 02, 2013 6:48 pm

With the model I'm testing, the compound only has 1 convex collision shape. I apply a uniform scale of 0.05 in XYZ to the compound. If you want to try and replicate it, load in a very large point cloud into a convex collision, put the convex in a compound, put the compound in a body and scale the body to 0.05. Have a bunch collide against a scene collision.
Layla
 
Posts: 54
Joined: Sat Sep 28, 2013 11:56 am

Re: Collision Against Uniform Grid (Voxel) Without Creating

Postby Julio Jerez » Wed Oct 02, 2013 7:08 pm

That can not be the cause of the error,
if you pass a max point count to the convex hull generaror then convex hull generator is independ of the point cloud size,
it does not matter if you have a million point of 100 point it iwll make the same convex.

beside the fact ta is work when the convex is a single collision, rules out that the point cloud size is the reason of the problem.

can you send me a copy of the model you are using?
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Collision Against Uniform Grid (Voxel) Without Creating

Postby Layla » Wed Oct 02, 2013 7:22 pm

https://dl.dropboxusercontent.com/u/99765/oildrum.obj

this is the model. It's very low poly, it's just that it has a big scale.

Best way to replicate it would be to make a scene collision of boxes, just a floor of 128x128 of them.

Pass that model into a NewtonCreateConvexHull.
Add it to a compound with NewtonCompoundCollisionAddSubCollision.
Create a body with the compound.
Scale the body or compound shape by 0.05.

That's all I'm doing. Dropping a few of them should slow the application right down.

And I just noticed it's not even specific to that model, I can create a convex manually from 8 points, so a 50 unit sized box, and the same problem happens.

It even happens when I put a box collision inside a compound. So I've narrowed it down to a scaled compound colliding against a scene collision with many elements.

Code: Select all
   NewtonCollision* compoundCollision = NewtonCreateCompoundCollision(world, 0);
   NewtonCompoundCollisionBeginAddRemove(compoundCollision);

   NewtonCollision* boxCollision = NewtonCreateBox(world, 50, 50, 50, 0, NULL);
   NewtonCompoundCollisionAddSubCollision(compoundCollision, boxCollision);
   NewtonDestroyCollision(boxCollision);

   NewtonCompoundCollisionEndAddRemove(compoundCollision);

   NewtonBody* compoundBody = NewtonCreateDynamicBody(world, compoundCollision);
   NewtonDestroyCollision(compoundCollision);
   
   // scale after creating body slows everything down. Without the scale it runs fine even though the body is huge
   NewtonCollisionSetScale(NewtonBodyGetCollision(compoundBody), 0.05f, 0.05f, 0.05f);
Layla
 
Posts: 54
Joined: Sat Sep 28, 2013 11:56 am

Re: Collision Against Uniform Grid (Voxel) Without Creating

Postby Layla » Wed Oct 02, 2013 11:08 pm

I managed to get around it by removing all child shapes from the compound, making copies of them, scaling them and adding them back to the compound. Obviously I shouldn't need to but it fixes my problem. Maybe it will help find the problem but I can only guess until I manage to replicate it outside my project.

Code: Select all
   NewtonCompoundCollisionBeginAddRemove(compoundCollision);

   std::vector<NewtonCollision*> childCollisions;

   for (void* collisionNode = NewtonCompoundCollisionGetFirstNode(compoundCollision); collisionNode;)
   {
      void* nextCollisionNode = NewtonCompoundCollisionGetNextNode(compoundCollision, collisionNode);

      // copy collision
      NewtonCollision* convexCollision = NewtonCompoundCollisionGetCollisionFromNode(compoundCollision, collisionNode);
      convexCollision = NewtonCollisionCreateInstance(convexCollision);

      // save it
      childCollisions.push_back(convexCollision);

      // remove collision
      NewtonCompoundCollisionRemoveSubCollision(compoundCollision, collisionNode);

      collisionNode = nextCollisionNode;
   }

   for (size_t i = 0; i < childCollisions.size(); ++i)
   {
      NewtonCollision* convexCollision = childCollisions[i];

      // scale and add collision
      NewtonCollisionSetScale(convexCollision, scale.x, scale.y, scale.z);
      NewtonCompoundCollisionAddSubCollision(compoundCollision, convexCollision);

      NewtonDestroyCollision(convexCollision);
   }

   NewtonCompoundCollisionEndAddRemove(compoundCollision);
Layla
 
Posts: 54
Joined: Sat Sep 28, 2013 11:56 am

Re: Collision Against Uniform Grid (Voxel) Without Creating

Postby Julio Jerez » Thu Oct 03, 2013 4:40 am

I try to pasted that code on the demo Primitive collision, but for what I can see that demo does no compile,

..\applications\demosSandbox\sdkDemos\demos\ConvexCast.cpp

Code: Select all
void MakeSingleCompound(DemoEntityManager* const scene)
{
   NewtonWorld* const world = scene->GetNewton();

   NewtonCollision* compoundCollision = NewtonCreateCompoundCollision(world, 0);
   NewtonCompoundCollisionBeginAddRemove(compoundCollision);

   NewtonCollision* boxCollision = NewtonCreateBox(world, 50, 50, 50, 0, NULL);
   NewtonCompoundCollisionAddSubCollision(compoundCollision, boxCollision);
   NewtonDestroyCollision(boxCollision);

   dMatrix matrix(GetIdentityMatrix());
   matrix.m_posit.m_y = 10.0f;

   NewtonCompoundCollisionEndAddRemove(compoundCollision);
   NewtonBody* compoundBody = NewtonCreateDynamicBody(world, compoundCollision, &matrix[0][0]);
   NewtonDestroyCollision(compoundCollision);

   // scale after creating body slows everything down. Without the scale it runs fine even though the body is huge
   NewtonCollisionSetScale(NewtonBodyGetCollision(compoundBody), 0.05f, 0.05f, 0.05f);


// adding some visualization
DemoMesh* mesh = new DemoMesh("geometry", NewtonBodyGetCollision(compoundBody), "smilli.tga", "smilli.tga", "smilli.tga");
DemoEntity* const entity = new DemoEntity(matrix, NULL);
entity->SetMesh(mesh);
mesh->Release();
NewtonBodySetUserData(compoundBody, entity);
scene->Append(entity);

}


1> "..\..\sdkDemos\demos\PrimitiveCollision.cpp"
1>PrimitiveCollision.cpp
1>..\..\sdkDemos\demos\PrimitiveCollision.cpp(114) : error C2660: 'NewtonCreateDynamicBody' : function does not take 2 arguments
1>ConvexCast.cpp


but even if it did compiled you are not setting the mass, so that body will be static. you have to tell me exactly how you did it so that I can reproduce.

I modified the code so that it passes a transformation matrix, and also added a visual representation,
the compound is place on top up a big floor made of 100 x 100 compound spheres, (it can be change to any shape) but it does now fall because the box on top is also static,
if you sync to svn you will get and you see demo: ..\applications\demosSandbox\sdkDemos\demos\ConvexCast.cpp

can you add the part how you set the mass, it has to set it exactly how you did, or else the bug may not happens
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Collision Against Uniform Grid (Voxel) Without Creating

Postby Layla » Thu Oct 03, 2013 10:52 am

I set the mass with just a call to NewtonBodySetMassProperties. I'm baffled that it doesn't recreate the slow downs I get. I've compared the two and they're the same situation.

Maybe it will be best to leave it until I can recreate it. I can scale by taking everything out of the compound and putting them back in so that will do for now until I figure out what I'm doing wrong.
Layla
 
Posts: 54
Joined: Sat Sep 28, 2013 11:56 am

Re: Collision Against Uniform Grid (Voxel) Without Creating

Postby Julio Jerez » Thu Oct 03, 2013 11:24 am

Layla wrote:Maybe it will be best to leave it until I can recreate it. I can scale by taking everything out of the compound and putting them back in

that does no look like it would make any difference at all, how did you arrive to the solution?

anyway if that does it for you it is ok, maybe the bug will show up later, on different circumstances.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Collision Against Uniform Grid (Voxel) Without Creating

Postby Layla » Thu Oct 03, 2013 11:29 am

It was just something I tried and it worked. If I just iterate through the compound and scale each child, the slow down is still there so I figured I'd make a copy of the child collision, remove it from the compound, set the scale and then add it back in. This works fine. I don't know why that would fix it.
Layla
 
Posts: 54
Joined: Sat Sep 28, 2013 11:56 am

Re: Collision Against Uniform Grid (Voxel) Without Creating

Postby Julio Jerez » Thu Oct 03, 2013 1:37 pm

there is one thing I can still test. You said that the compound is falling ona scene collision, is that right?
In the demo the box is falling on another compound I will make that demo modification and see what happens.
maybe there bug is why scene collision and not with compounds.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

PreviousNext

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 3 guests