Scaling A Compound Collision Body

Report any bugs here and we'll post fixes

Moderators: Sascha Willems, Thomas

Scaling A Compound Collision Body

Postby Bird » Tue Jul 23, 2013 1:31 pm

I can't get scaling to work properly on an NewtonCollision object that was created using NewtonMeshApproximateConvexDecomposition() and NewtonCreateCompoundCollisionFromMesh()

Here's a little video that shows what I'm getting. The first time the cow is scaled, it's using a ConvexHull shape and it works fine. But if I switch to using the ConvexAproximation you can see that Newton is not seeing the new scale

http://hurleyworks.com/media/flash/NewtonCompoundScale/NewtonCompoundScale.html

Is there something special we have to do to scale compound shapes?

Here's the code I'm using to scale the body before running the simulation:

Code: Select all
bool NewtonScene::updateBodyProperties (const BodyID & bodyID)
{   TRACE("NewtonScene::updateBodyProperties")

   PhysicsBodies::iterator it = bodies_.find(bodyID);
   if ( it != bodies_.end() )
   {
      PhysicsBody::Ptr pBody = it->second;
      if( pBody && pBody->component )
      {
         const NewtonBody * const newtonBody = (NewtonBody*)pBody->component->userData;
         if( !newtonBody ) return false;

         NewtonCollision * collision = NewtonBodyGetCollision(newtonBody);
         if( !collision ) return false;

         if( pBody->bodyDesc.bodyState & BodyState::ScaleChanged )
         {
            NewtonCollisionSetScale(collision, pBody->bodyDesc.scale[0], pBody->bodyDesc.scale[1], pBody->bodyDesc.scale[2] );
            pBody->bodyDesc.bodyState ^= BodyState::ScaleChanged;
         }

         dVector origin;
         dVector inertia;
         dFloat mass = pBody->bodyDesc.mass;
         NewtonConvexCollisionCalculateInertialMatrix (collision, &inertia[0], &origin[0]);   
         dFloat Ixx = mass * inertia[0];
         dFloat Iyy = mass * inertia[1];
         dFloat Izz = mass * inertia[2];

         NewtonBodySetMassMatrix (newtonBody, mass, Ixx, Iyy, Izz);
      }
   }
   return true;
}


-Bird
http://hurleyworks.com
Bird
 
Posts: 623
Joined: Tue Nov 22, 2011 1:27 am

Re: Scaling A Compound Collision Body

Postby Julio Jerez » Tue Jul 23, 2013 2:34 pm

Oh yes, that's not going to work.
I will add extend scale function to compound, I will do tonight

One of teh change in core 300, wa sthat I remove teh old hierchiocal metor to apply general scaling, and I use
a local scale.

tteh problem wi that is teh hiegchical shapes liek comppudn and scenm collision do no inherit the scale.
to do that I have to go down the collsion shape calculation the scale matrix, and setting the equivalient orthornalized and scale matrix to each children.
not big deal, I will do that tonight.

after that, it will jsut be teh same generic inteface that is exposed to scale all other shapes, no special coding.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Scaling A Compound Collision Body

Postby Bird » Tue Jul 23, 2013 5:55 pm

Great! Thanks for the quick fix.

I've have a couple of meshes that are causing Newton to crash during the call to NewtonMeshApproximateConvexDecomposition(). What's the best way to get you the meshes these days?

-Bird
http://hurleyworks.com
Bird
 
Posts: 623
Joined: Tue Nov 22, 2011 1:27 am

Re: Scaling A Compound Collision Body

Postby Julio Jerez » Tue Jul 23, 2013 6:16 pm

Since I am going to work on that, I wll also use teh oprotunoty to add teh serializtion to eh NewtonMesh.
That way you can give then to me as newton mesh.

I say this because sometime going for format to format a but can not be reproduce, just because the mesh topology changes.
if we have serialization of the mesh then tha file will be exactly the same.

so the plan is this.
I will fix the scale problem and also add teh serization, ten you can send me the problematic mesh as NetwonSerialized meshses.
anotheing thing that serilzia mesh cna provide is a way for me to distribute file with me samples, and no having to wioor about license.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Scaling A Compound Collision Body

Postby Bird » Tue Jul 23, 2013 6:29 pm

Julio Jerez wrote:can you provide me with those meshes so that I can try?


What's the best way to do that? I can't use NewtonSerializeToFile() because Newton crashes before I can create the NewtonCollision for the mesh. I can successfully create a NewtonMesh from the geometry data. Is there a way I can export that NewtonMEsh to an .ngd file?

-Bird
Bird
 
Posts: 623
Joined: Tue Nov 22, 2011 1:27 am

Re: Scaling A Compound Collision Body

Postby Julio Jerez » Tue Jul 23, 2013 6:51 pm

wait until I check in the serilazation of NetwonMesh tonight.
I wil post a sample code and you cna just save those files.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Scaling A Compound Collision Body

Postby Julio Jerez » Wed Jul 24, 2013 11:19 am

Ok if you call NewtonCollisionSetScale on a compound collsion it will properly scale the collision

there is one difference, since in newton 300 the scale is local, instead of global.
if you apply local scale to a hierarchical structure lie a compound collision you will get some different that what you expect.

basically it will scale each shape locally which will be wrong.

this is a trade off I have to made when moving form core 200 and lower, to core 300.
before the scale was and transform modifier, that do a proper polar matrix decomposition on each frame, but that is too slow for real time if we want scale to be part of collision.
Local scale do no require matrix decomposition, however is doe no apply to children.

to apply the scale to a compound collision I nee to do what was done in core 200, basically I apply the scale globally, but fo rthat I nee to propagate the matrices to each child shape,
but since child shape no longer have a matrix, the only way to do that is by baking the matrix into the shape. whi mean the shape have to be converted to a convex hull.

so what happen is that the scale is baked into the shape, and you will read back as 1, 1, 1.

please try see if it works for you.

I also wrote the NetwonMesh serialize,

NewtonMeshCreateFromSerialization (const NewtonWorld* const newtonWorld, NewtonDeserializeCallback deserializeFunction, void* const serializeHandle);
void NewtonMeshSerialize (const NewtonMesh* const mesh, NewtonSerializeCallback serializeFunction, void* const serializeHandle);

I have not write any demo yest, but it is used the same way that serialization is use for collisions.
see if you undertand it, if not I will post a demo later.

I have not tested but I believe it should works fine.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Scaling A Compound Collision Body

Postby Julio Jerez » Wed Jul 24, 2013 1:39 pm

Oh I am sorry, I forget to check in the compound scaling code last night, I just synced from work and it is not chek in.
I will do it tonioght when I get home.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Scaling A Compound Collision Body

Postby Bird » Wed Jul 24, 2013 7:11 pm

No worries. I'll test it out when you've got it checked in.

I tried NewtonMeshSerialize but I can't get it to work cause there's still an assert(0) in dgMeshEffect::Serialize(). Here's the code I've used which I took from the
NewtonColliionsSerialize in the ToolBox->LevelPrimitive.cpp. Is that the correct?

Thanks,

-Bird

Code: Select all
static const char* MAGIC_NUMBER = "serialize data";
void SerializeFile (void* serializeHandle, const void* buffer, int size)
{
   _ASSERTE ((size % 4) == 0);
   fwrite (buffer, size, 1, (FILE*) serializeHandle);
}

void NewtonMeshOps::serializeMesh( const NewtonMesh * const mesh, const std::string & fullpath )
{   TRACE("NewtonMeshOps::serialzieBody")

   FILE* file;
   file = fopen (fullpath.c_str(), "wb");
   SerializeFile (file, MAGIC_NUMBER, int (strlen (MAGIC_NUMBER) + 2));
   NewtonMeshSerialize  (mesh, SerializeFile, file);
   fclose (file);
}
Bird
 
Posts: 623
Joined: Tue Nov 22, 2011 1:27 am

Re: Scaling A Compound Collision Body

Postby Julio Jerez » Thu Jul 25, 2013 9:25 am

Ah, yes I forget to remove that.
It is checked in now, I also put in the scaling on compound.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Scaling A Compound Collision Body

Postby Bird » Thu Jul 25, 2013 10:39 am

Hi Julio,

Thanks for the quick attention!

I'm finding that scaling the CompoundCollisions only works if they are scaled before adding to the engine.. If I try to update CompoundCollisions scale by calling NewtonCollisionSetScale() while they're in the engine I get lots of penetration errors. But if I load a fresh scene with the new scale already applied then it works fine.

Also I'm hitting debug asserts while scaling a CompoundCollision up or down. Usually the error is in dgVec.h line 813 Expression: ret.m_f[0] == dgFloor(m_f[0]

Also I tried serializing a mesh with NewtonMeshSerialize but it won't load into the DemoSandbox.exe. DemoSandbox just hangs while it's trying to load it.

-Bird
Bird
 
Posts: 623
Joined: Tue Nov 22, 2011 1:27 am

Re: Scaling A Compound Collision Body

Postby Julio Jerez » Thu Jul 25, 2013 11:15 am

Bird wrote:Hi Julio,
Also I'm hitting debug asserts while scaling a CompoundCollision up or down. Usually the error is in dgVec.h line 813 Expression: ret.m_f[0] == dgFloor(m_f[0]
-Bird

that's a very big bug can you show me the trace stack of where that error come form?
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Scaling A Compound Collision Body

Postby Bird » Thu Jul 25, 2013 11:53 am

Julio Jerez wrote:
Bird wrote:Hi Julio,
Also I'm hitting debug asserts while scaling a CompoundCollision up or down. Usually the error is in dgVec.h line 813 Expression: ret.m_f[0] == dgFloor(m_f[0]
-Bird

that's a very big bug can you show me the trace stack of where that error come form?


Here' it is after scaling the mesh up;

-Bird

AdvancedPlacement083_64d.dll!dgVector::Floor() Line 814 + 0x47 bytes C++
AdvancedPlacement083_64d.dll!dgBroadPhase::dgNode::SetAABB(const dgVector & minBox, const dgVector & maxBox) Line 126 + 0x12 bytes C++
AdvancedPlacement083_64d.dll!dgBroadPhase::UpdateBodyBroadphase(dgBody * const body, int threadIndex) Line 1082 C++
AdvancedPlacement083_64d.dll!dgBody::UpdateCollisionMatrix(float timestep, int threadIndex) Line 216 C++
AdvancedPlacement083_64d.dll!dgBody::SetMatrix(const dgMatrix & matrix) Line 183 C++
AdvancedPlacement083_64d.dll!dgBody::SetMatrixIgnoreSleep(const dgMatrix & matrix) Line 189 C++
AdvancedPlacement083_64d.dll!dgDynamicBody::SetMatrixIgnoreSleep(const dgMatrix & matrix) Line 125 C++
AdvancedPlacement083_64d.dll!NewtonBodySetMatrix(const NewtonBody * const bodyPtr, const float * const matrixPtr) Line 4870 C++
AdvancedPlacement083_64d.dll!IPhysics::NewtonScene::setBodyPose(const unsigned __int64 & bodyID) Line 347 + 0x29 bytes C++
AdvancedPlacement083_64d.dll!IPhysics::PhysicsModel::setBodyPose(const unsigned __int64 & bodyID) Line 178 C++
AdvancedPlacement083_64d.dll!EventHandler::onMotionUpdateComplete(void * const & itemID, const std::basic_string<char,std::char_traits<char>,std::allocator<char> > & itemName, const double & newTime) Line 221 C++
AdvancedPlacement083_64d.dll!MasterHandler::onMasterEvent(void * __formal, const st_LWMasterAccess * access) Line 289 + 0x35 bytes C++
AdvancedPlacement083_64d.dll!LWKit::Statics::onMasterEvent<MasterHandler>(void * inst, const st_LWMasterAccess * access) Line 60 C++
Bird
 
Posts: 623
Joined: Tue Nov 22, 2011 1:27 am

Re: Scaling A Compound Collision Body

Postby Bird » Thu Jul 25, 2013 11:56 am

Sometimes I get a different crash when scaling down:

AdvancedPlacement083_64d.dll!dgCollisionInstance::GetChildShape() Line 186 + 0x5 bytes C++
AdvancedPlacement083_64d.dll!dgCollisionCompound::ApplyScale(const dgVector & scale) Line 913 + 0xd bytes C++
AdvancedPlacement083_64d.dll!dgCollisionInstance::SetScale(const dgVector & scale) Line 373 C++
AdvancedPlacement083_64d.dll!NewtonCollisionSetScale(const NewtonCollision * const collision, float scaleX, float scaleY, float scaleZ) Line 4138 C++
AdvancedPlacement083_64d.dll!IPhysics::NewtonScene::updateBodyProperties(const unsigned __int64 & bodyID) Line 378 C++
AdvancedPlacement083_64d.dll!IPhysics::PhysicsModel::updateBodyProperties(const unsigned __int64 & bodyID) Line 193 + 0x23 bytes C++
AdvancedPlacement083_64d.dll!EventHandler::onMotionUpdateComplete(void * const & itemID, const std::basic_string<char,std::char_traits<char>,std::allocator<char> > & itemName, const double & newTime) Line 216 C++
AdvancedPlacement083_64d.dll!MasterHandler::onMasterEvent(void * __formal, const st_LWMasterAccess * access) Line 289 + 0x35 bytes C++
AdvancedPlacement083_64d.dll!LWKit::Statics::onMasterEvent<MasterHandler>(void * inst, const st_LWMasterAccess * access) Line 60 C++


-Bird
Bird
 
Posts: 623
Joined: Tue Nov 22, 2011 1:27 am

Re: Scaling A Compound Collision Body

Postby Julio Jerez » Thu Jul 25, 2013 1:12 pm

Ok It seem there is a degenerated number on being produce whne the mesh collision is scaled.
We can check if thsi si a ilecal number by using float expection

I place a float execption trap to capture undeflow and overfloat whne teh scale is applied, let us see i fteh bug is genertaed there.
Sync to SNV and build in debug mode let us see if the expection happen. when the number goes bad.

and for make teh bodies react when you move them.
there is a way to do that with material call back, but first let us fix these two bugs.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Next

Return to Bugs and Fixes

Who is online

Users browsing this forum: No registered users and 1 guest

cron