Problem with static mesh collision in core 300

Report any bugs here and we'll post fixes

Moderators: Sascha Willems, Thomas

Re: Problem with static mesh collision in core 300

Postby Julio Jerez » Wed Dec 07, 2011 8:50 am

Bird wrote:I'd like to remove nodes from a CompoundCollision during NewtonMaterialSetCollisionCallback. Is it possible to know on which node the contact occurred when the Collision type is CompoundCollision?


that is not a good idea, removeing object from a callcback will use the memory manager, and will lead to a guarantee crash. In newton teh memory manage is a pool base, and use free list to allocate report chunf of regualr size.
the memory mamegr is not thread safe by design, because doij that will bring teh ebnegien to a groudn hold on spin locks.
The mamory manage is use extesivally in eh engien to simply teh coding, and ti will required a lot of work, almost a New engine to make it posible to remove and add object form call back.


teh other issues with compound is that a compound may be colliding with more that one body, and it si possible that the part you removed is already saved on anothe contact pair, if remove then later that conat will be prossesing and dead pointer. solve that will also reqired lao of refering counting and will also bring the angine to a cloll.

you will have to place those part into a temporaty list and then remove then when the call back exits.

if you are going to write to memory you can use these funtion if you are using the engine with microthreads

void NewtonWorldCriticalSectionLock (const NewtonWorld* const newtonWorld);
// write to memory
void NewtonWorldCriticalSectionUnlock (const NewtonWorld* const newtonWorld);

or you can use teh thread id, to write per thread to local data, and you do no need to use critacal sections.

sorry about that but that is a very big task for the engien design now.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Problem with static mesh collision in core 300

Postby Bird » Wed Dec 07, 2011 11:22 am

you will have to place those part into a temporaty list and then remove then when the call back exits.

Sorry, I wasn't clear. I just want to find out which nodes had contact so I can remove them from the CollisionCompound and re-add the nodes as separate bodies when it's safe to do so. With other engines, I do save to a temporary list just like you've suggested, and only remove/add them just before the next call to physics->update().

During the callback, the joint bodies and collisions are the CollisionCompound, correct?. Is there a way to find out which node in the compound has contact so I can remove it from the compound when it's safe to do so?

-Bird

Code: Select all
void Newton3Engine::genericContactProcess (const NewtonJoint * joint,
                                           dFloat timestep,
                                           int threadIndex)
{   

   NewtonBody* const body0 = NewtonJointGetBody0(joint); 
   NewtonBody* const body1 = NewtonJointGetBody1(joint);
   NewtonCollision* const colliison0 = NewtonBodyGetCollision (body0);   // How to get Node from this Compound
   NewtonCollision* const colliison1 = NewtonBodyGetCollision (body1);
}
Bird
 
Posts: 623
Joined: Tue Nov 22, 2011 1:27 am

Re: Problem with static mesh collision in core 300

Postby Julio Jerez » Wed Dec 07, 2011 4:23 pm

Bird wrote:
you will have to place those part into a temporaty list and then remove then when the call back exits.

Sorry, I wasn't clear. I just want to find out which nodes had contact so I can remove them from the CollisionCompound and re-add the nodes as separate bodies when it's safe to do so. With other engines, I do save to a temporary list just like you've suggested, and only remove/add them just before the next call to physics->update().when }[/code]


the compound has a per shape callback, also in the genric call back you can iterate ove thr contact and get the collsion from teh body.

I will post a sample code tonight to show. all of teh information is abialable.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Problem with static mesh collision in core 300

Postby Julio Jerez » Thu Dec 08, 2011 12:14 pm

Ok I check in the demo that allow you to get the sub collision shape when a compound collides
It is in demo Compounds collision.
There are two function, one the is hooked to the material callback and I assume that's the one that repost zero reaction forces.
This is because the first collision and any other impulse collision is not calculated at that time, only resting force are valid there.

IO also wrote another function that you can call after the Newton Update, and that one call the same call back, but this time the force are updated and you can read them.
In Newton the narrow phase collision manager has a contact cache that if a contact moves from the previous position, then the at that point was an impulsive force and should not be considered as first guess for the solver,
so the cache it set the force to zero, this is why you always read zero there, if you have a resting body the force with valid on the call back after the body is at rest.
However if you read then after the Newton Update then you will read force the engien use to preven the body to interpenetrate.

these are the functions
Code: Select all
static void GetCollidongSubShape(const NewtonJoint* const contactJoint, NewtonBody* const body)
{
   NewtonCollisionInfoRecord collisionInfo;

   NewtonCollision* const collision = NewtonBodyGetCollision(body);
   NewtonCollisionGetInfo (collision, &collisionInfo);


   int count = 0;
   NewtonCollision* collidingSubShapeArrar[32];

   // see if this is a compound collision or any other collision with sub collision shapes 
   if (collisionInfo.m_collisionType == SERIALIZE_ID_COMPOUND) {

      // to get the torque we need the center of gravity in global space
      dVector origin;
      dMatrix bodyMatrix;
      NewtonBodyGetMatrix(body, &bodyMatrix[0][0]);
      NewtonBodyGetCentreOfMass(body, &origin[0]);
      origin = bodyMatrix.TransformVector(origin);

      for (void* contact = NewtonContactJointGetFirstContact (contactJoint); contact; contact = NewtonContactJointGetNextContact (contactJoint, contact)) {
         // get the material of this contact,
         // this part contain all contact information, the sub colliding shape,
         NewtonMaterial* const material = NewtonContactGetMaterial (contact);
         NewtonCollision* const subShape = NewtonMaterialGetBodyCollidingShape (material, body);
         int i = count - 1;
         for (; i >= 0; i --) {
            if (collidingSubShapeArrar[i] == subShape) {
               break;
            }
         }
         if (i < 0) {
            collidingSubShapeArrar[count] = subShape;
            count ++;
            _ASSERTE (count < (sizeof (collidingSubShapeArrar) / sizeof (collidingSubShapeArrar[0])));

            // you can also get the forces here, however when tho function is call form a contact material
            // we can only get resting forces, impulsive forces can not be read here since they has no being calculated yet.
            // whoever if this function function is call after the NetwonUpdate they the application can read the contact force, that was applied to each contact point
            dVector force;
            dVector posit;
            dVector normal;
            NewtonMaterialGetContactForce (material, body, &force[0]);
            NewtonMaterialGetContactPositionAndNormal (material, body, &posit[0], &normal[0]);
            // the torque on this contact is
            dVector torque ((origin - posit) * force);

            // do what ever you want wit this 


         }
      }
   }

   // here we should have an array of all colling sub shapes
   if (count) {
      // do what you need with this sub shape list
   }
}



static void GettingTheCollidonSubShapeAfteNetwonUpdate (NewtonWorld* const world)
{
   for (NewtonBody* body = NewtonWorldGetFirstBody(world); body; body = NewtonWorldGetNextBody(world, body)) {
      for (NewtonJoint* contactJoint = NewtonBodyGetFirstContactJoint(body); contactJoint; contactJoint = NewtonBodyGetNextContactJoint(body, contactJoint)) {
         // this call should report the correct reaction forces in each call
         GetCollidongSubShape(contactJoint, body);
      }
   }
}

static void GettingTheCollidonSubShapeFromMaterialCallback (const NewtonJoint* const contactJoint, dFloat timestep, int threadIndex)
{
   NewtonBody* const body0 = NewtonJointGetBody0(contactJoint);
   GetCollidongSubShape(contactJoint, body0);

   NewtonBody* const body1 = NewtonJointGetBody1(contactJoint);
   GetCollidongSubShape(contactJoint, body1);
}


These are the detail that separate Newton form other engines.

I still has no added the GetForceFeedBack at et solve calculation, to the contact material,
This is an important feature that is already in 2.00 but only for Bilateral joints, and it is for especial joints.

This give the application the force, velocity and everything on a joint when eh are calculated but before they are apply to the body.
This allow for making Player controller, and I will add to finish the vehicle controller, this is why I need to on the contact Material.
This feature allow the possibility to make Player controller that ac as if they were kinematic, but the react with the world physically.
Again a powerful feature that Separate Newton from all other engine.
If I can only work on this full time...?
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Problem with static mesh collision in core 300

Postby Bird » Thu Jan 05, 2012 9:04 pm

I'm seeing collision problems in core_300 when using NewtonTreeCollision to create static meshes. Here's a simple example http://www.hurleyworks.com/media/flash/ ... hProb.html

The container mesh is made using with NewtonCreateTreeCollision and has 0 mass. I tried linking my project to core_200 and it worked as expected so I think this is a core_300 problem. If you need the objects just let me know but I think it should be easy to reproduce using any objects.


I'd like to bring this up again as we went off on a tangent last time.:) I'm trying to release a new beta of my project and this is a show stopper for me. Were you ever able to reproduce it?

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

Re: Problem with static mesh collision in core 300

Postby Julio Jerez » Fri Jan 06, 2012 8:25 am

oh yes. Now that the engine is more stable, can you save the sane and give me the ngd file for that scene?

I had made lots of fixes. but it is possible that bug is still there.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Problem with static mesh collision in core 300

Postby Bird » Fri Jan 06, 2012 9:57 pm

Julio Jerez wrote:oh yes. Now that the engine is more stable, can you save the sane and give me the ngd file for that scene?

I had made lots of fixes. but it is possible that bug is still there.

I tried in svn 1336 and it's still there. I'm not sure how to save the .ngd file anymore. Here's where you last talked about the api for saving the scene to .ngd http://newtondynamics.com/forum/viewtopic.php?f=12&t=6989&start=15#p48514 and looking at the latest NewtonDemo class I don't think you've found the time to put in the changes yet.

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

Re: Problem with static mesh collision in core 300

Postby Julio Jerez » Sat Jan 07, 2012 10:34 am

I asume you have a world in you exposter.
all you have to do is this, to add a pice of code like this

Code: Select all
class MakeViualMesh: public dScene::dSceneExportCallback
{
   public:
   MakeViualMesh (NewtonWorld* const world)
      :m_world (world)
   {
   }

   NewtonMesh* CreateVisualMesh (NewtonBody* const body, char* const name, int maxNameSize) const
   {
      // here the use should take the user data from the body create newtonMesh form it and return that back
      NewtonCollision* collision = NewtonBodyGetCollision(body);
      NewtonMesh* const mesh = NewtonMeshCreateFromCollision(collision);

      sprintf (name, "visual Mesh");
      return mesh;
   }

   NewtonWorld* m_world;
};

void ExportScene (NewtonWorld* const world, const char* const fileName)
{
   MakeViualMesh context (world);
   dScene testScene (world);
   testScene.NewtonWorldToScene (world, &context);
   testScene.Serialize (fileName);
}



then calling scene expost will save the work to an .ngn file
then you can even open the SDK demo a load the file in the viewr and seeit work. The will be good to make sure is work before you send it to me.
you are right, I have not implemented the on save menu command yet, but for me it will be to add a call to ExportScene.
I Will added in next check in.

But before that I will add a mode new type to the file format so that I can have links to mesh assets, that way insteha of each fiel be self contatned, they can call other files
to lod the asset, and resus the asset.
Thsi allow for a separtion betwee physsics and Graphics, anc can even sop[poprt call to oteh file formal.
say for example you use you own epecial graphics format, but you wna to add physics, you cna explrt teh Netwon world and teh mesk is simply a name to a mej file.
the on lod teh contact will be call to get teh asset and there the application can simple pass the relevat data to hook the physics body and collision.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Problem with static mesh collision in core 300

Postby Bird » Sat Jan 07, 2012 12:47 pm

then calling scene expost will save the work to an .ngn file
then you can even open the SDK demo a load the file in the viewr and seeit work. The will be good to make sure is work before you send it to me.

There's no errors if I load the exported .ngd file into the SDK demo viewer. But in my project it's still failing badly.

One thing I'm still not sure of is how to get the NewtonMesh * from MakeVisualMesh::CreateVisualMesh(). You said:
you need to build it from the userData of the rigid body which I asume Is your visual mesh.

Can you please show me how to do that using the SDK::DemoMesh or DemoEntity.

Sorry to be such a pain!

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

Re: Problem with static mesh collision in core 300

Postby Julio Jerez » Sat Jan 07, 2012 12:51 pm

I am confused.
are you saying that you exported and NGD file from your plugin, and whne you load it in the SDK viewer fremawork, it is working correctly?
let us clarify that first.


you do not have to work with demo Mesh or demo entity, those are not part of the SDK. those are for me to make soem mockup of what a end application use for graphics.
I try to be very explicit in separating then.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Problem with static mesh collision in core 300

Postby Bird » Sat Jan 07, 2012 12:59 pm

I am confused.
are you saying that you exported and NGD file from your plugin, and whne you load it in the SDK viewer fremawork, it is working correctly?
let us clarify that first.

Yes. That's what's happening.

But I'm confused about how to obtain the NewtonMesh * from MakeVisualMesh::CreateVisualMesh(). I'm using

Code: Select all
NewtonCollision* collision = NewtonBodyGetCollision(body);
      NewtonMesh* const mesh = NewtonMeshCreateFromCollision(collision);


And you told me before that's not the proper way and I'm not sure what the right way is.

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

Re: Problem with static mesh collision in core 300

Postby Julio Jerez » Sat Jan 07, 2012 1:30 pm

Bird wrote:
I am confused.
But I'm confused about how to obtain the NewtonMesh * from MakeVisualMesh::CreateVisualMesh(). I'm using
Code: Select all
NewtonCollision* collision = NewtonBodyGetCollision(body);
      NewtonMesh* const mesh = NewtonMeshCreateFromCollision(collision);


And you told me before that's not the proper way and I'm not sure what the right way is.
-Bird


that is correct, I beleive I said, if you want to save a visual mesh, the than is not correct because that is just default context fallback to display the collision shape as a visual mesh.
I beleive that the contex call back will bring lots of confusion, I will add the new sSceneGemetryAssets.
Basically this will be a Geometry Node will contatin a string name tah point to an asset. simila to what a texture node is now.

In the call back the use can either open another NGD file and load the mesh or open any file load the mesh a make a NewtonMesh and return that.
this will efectivally allow fo the dScene to be link with other file formats. right now the file is an all or nothing and many application may wna to have their own graphics file format.
for example in you plugin you cna simple save the name of the file mesh file, and the in teh call back you can load simply fidn teh mesh in the scene alo mak eteh NewtonMesh an return that back.
That is how I am planning to do it in my own Max plugin.

thsi can allow peopel to inject physics to a scen the was already made, by simply writing the name of teh mashe in teh NGH file and manipula teh mesh in opteh editors.
but the other editors can use their own graphics formats, or even place holders.


anyway if the save file can be load in the SDK, then there most be some bug in the plug in.
are you using optimization when you build teh collision tree? turn tha of an let of see what happens?
also turn SIMD off too.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Problem with static mesh collision in core 300

Postby Bird » Sat Jan 07, 2012 1:51 pm

anyway if the save file can be load in the SDK, then there most be some bug in the plug in.
are you using optimization when you build teh collision tree? turn tha of an let of see what happens?
also turn SIMD off too.

Bingo! Looks like SIMD is the problem. If I set NewtonSetPlatformArchitecture (world_, 0), then it works ok whether collision tree optimization is off or on. But if set NewtonSetPlatformArchitecture( world_, 3 ) then the bad things happen again. I hope that doesn't mean I have to disable SIMD because there seems to be a nice performance gain when it's on.

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

Re: Problem with static mesh collision in core 300

Postby Julio Jerez » Sat Jan 07, 2012 2:39 pm

Yes that was waht I though, I forget to say That for core 300, teh simd path will no be supported 100%

Instead I will implement move OpenCL.
Intel, Nvidia, AMD, and all other hardwere vendeo are soporting openCL.
there will be some simd because ter is code that si not prarical to write in OpelCL, CUDA or Direct Compute
but that is simple generic code. The heavy dutty vetorization will be delegate to OpenCL compiler.

when I stared copre 300 openCL was terrible, because it was only supote by Video card makers, but now that it run on CPU and GPU it seem the natyual choice.
Hand tweaking Simd code is too time consuming, and you get better perforemace at the expence of non cross platform spagetti code, and lot of effor.

what I will do is that I will hack the code so that people using the Simd path, will be redirected it to x87 path unti I start the OpenCL conversion.


Bird wrote:I hope that doesn't mean I have to disable SIMD because there seems to be a nice performance gain when it's on.
-Bird

Temporallity yes, however say you have an intell core with AVX instrutions, teh simd path is no uning AVX, in fact it is usin SSE that is pention three compatible.

Even in the pention 4 already have instrution like horizontal add, and more advance intruction that I can not use because of compatibility.
the simd code usin Dot prpdin, SPermute, horizatl add, and oteh specil intrution is even faster than teh current simd.
having all those permuation of insturtion set make teh simd support unsustainable.

it is true that hande coded simd is fate that openCL, but when you you cna say teh same for hand code assemble vs C++ .
once we get the OpenCL path, going the performance will even go faster that it is now with current Simd.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Problem with static mesh collision in core 300

Postby Bird » Sat Jan 07, 2012 4:23 pm

Sounds like a good way to go. Thanks for the help tracking down what was going on!

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

PreviousNext

Return to Bugs and Fixes

Who is online

Users browsing this forum: No registered users and 3 guests

cron