Materials

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Materials

Postby thedmd » Fri Oct 30, 2009 6:33 pm

Hello Julio,

Is there any way to get an NewtonMaterial* for given pair of ID's? I didn't fount nothing suitable. : /
Maybe something similar to code below can be introduced?
Code: Select all
NewtonWorld* NewtonWorldGetMaterial(const NewtonWorld* world, int id0, int id1);


From my point of view it will be very good if I can get an instance of material form id pair just directly after creating one or more new groups. This operation will make material managment a lot easier for managed code.

Are there any chances for such routine?
thedmd
 

Re: Materials

Postby JernejL » Sat Oct 31, 2009 8:34 am

thedmd wrote:Hello Julio,

Is there any way to get an NewtonMaterial* for given pair of ID's? I didn't fount nothing suitable. : /
Maybe something similar to code below can be introduced?
Code: Select all
NewtonWorld* NewtonWorldGetMaterial(const NewtonWorld* world, int id0, int id1);


From my point of view it will be very good if I can get an instance of material form id pair just directly after creating one or more new groups. This operation will make material managment a lot easier for managed code.

Are there any chances for such routine?


What are these.. "pair of ids" you talk about? what do the IDs reprisent in your logic?

Maybe NewtonBodyGetMaterialGroupID is what you are looking for? you can call it for 2 bodies.. and then you are able to retrieve or set material parameters..
Help improving the Newton Game Dynamics WIKI
User avatar
JernejL
 
Posts: 1587
Joined: Mon Dec 06, 2004 2:00 pm
Location: Slovenia

Re: Materials

Postby thedmd » Sat Oct 31, 2009 11:58 am

Delfi wrote:What are these.. "pair of ids" you talk about? what do the IDs reprisent in your logic?

As far as I know NewtonMaterial is defined for a unique pair of two group ID's. I'm trying to follow Newton as much as possible.

Delfi wrote:Maybe NewtonBodyGetMaterialGroupID is what you are looking for? you can call it for 2 bodies.. and then you are able to retrieve or set material parameters..

Yes, but to do that I need to have two Bodies.

I will describe by problem a little more deep. I want do provide managed version of function:
Code: Select all
void NewtonMaterialSetCollisionCallback (const NewtonWorld* newtonWorld, int id0, int id1, void* userData, NewtonOnAABBOverlap aabbOverlap, NewtonContactsProcess process);

Which in managed code looks in that way:
Code: Select all
void SetMaterialCollisionCallback(World world, int id0, int id1, object userData, AABBOverlapCallback overlapCallback, ProcessContactsCallback processCallback);

On my side I need to store userData object and two delegates overlapCallback and processCallback. Ok, this can be done without much trouble. I just have to cache those values. Then we got two similar functions:
Code: Select all
void* NewtonMaterialGetUserData (const NewtonWorld* newtonWorld, int id0, int id1);
void *NewtonMaterialGetMaterialPairUserData (const NewtonMaterial* material);

In managed code:
Code: Select all
object GetMaterialUserData(World world, int id0, int id1);
object GetMaterialUserData(Material material);

Both of them need to return same userData value that has been set in SetMaterialCollisionCallback(). But in last case I'm unable to identify from which ID's this material was created and which managed object I have to return.

So I think there are two ways to solve this problem:
  • add a function which give NewtonMaterial from ID's
  • add a function which allow to get ID's from which NewtonMaterial is build

After some considerations I think this last one will be a better solition, becouse only some additional data will be exposed. And this may not be the case for first one.

There is also a possibility that I miss something important, but still I'm trying to do not.
thedmd
 

Re: Materials

Postby JernejL » Sat Oct 31, 2009 8:14 pm

thedmd wrote:
Delfi wrote:What are these.. "pair of ids" you talk about? what do the IDs reprisent in your logic?

As far as I know NewtonMaterial is defined for a unique pair of two group ID's. I'm trying to follow Newton as much as possible.


You still haven't explained what these group ids are that you speak about..

also: material is defined for a SINGLE BODY (or per collision), one body can have only one material (except i think in cases of a compound mesh), and one material (and therefore set interactions) can be shared between many bodies.

Material interaction is set between two of these materials (for example: NewtonMaterialSetDefaultFriction).

Newton is different in this regard, that you don't just give a body a material with specific friction, elasticity etc.. but you give those attributes to a material PAIR of two materials, and set the interaction of this material with all others by yourself.

thedmd wrote:
Delfi wrote:Maybe NewtonBodyGetMaterialGroupID is what you are looking for? you can call it for 2 bodies.. and then you are able to retrieve or set material parameters..

Yes, but to do that I need to have two Bodies.


No, see above, a body only has 1 material, you got the material logic wrong. all what you need is.. reverse calls for those NewtonMaterialSetDefaultFriction, NewtonMaterialSetDefaultElasticity etc.. values (but you could just as well just cache those ) to get the material parameters for the material pairs.
Help improving the Newton Game Dynamics WIKI
User avatar
JernejL
 
Posts: 1587
Joined: Mon Dec 06, 2004 2:00 pm
Location: Slovenia

Re: Materials

Postby Julio Jerez » Sat Oct 31, 2009 8:56 pm

you can iterate over the Materials using these functions,
NewtonMaterial* NewtonWorldGetFirstMaterial (const NewtonWorld* world);
NewtonMaterial* NewtonWorldGetNextMaterial (const NewtonWorld* world, const NewtonMaterial* material);
and from the Materials you can get the information you need, isn't that suficient?

like Delfi say we keep calling Material, but they are not really Material they are Material pairs that define relation between two Material who are asigned to two bodies by an ID.

Bear in mind that Material Iterations are just Template to define creation properties for a contact Joint.
in a collision you do not get a pointer to the template Material you created, instead an Instance of the template is created that links two bodies uniquetly while they are conected by the contact.
therefore it is a big mistake to get a pointer to a Material in a callback and save it because they will be destroyed when the Bodies move aparts from each other, and you will be left with an orphan pointer, or worse
the same Material will be reasigned to a new pair of colliding bodies by the memory manager.

Basically Materials are intitalization parameters for Contact Joints, and ContactJoint are normal Joints that sepcify how to solve unilateral constraint by the solver.
those joint are managed (created and destroyed by the Collision system)

The Material iterators gives you the pointer to the Templates material.
The Contact Joints Iterators gives a pointer to the Instance of that Material.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Materials

Postby thedmd » Sun Nov 01, 2009 3:48 am

Now I see. So by pair of ID's I can define template behaviour for two groups. Then when a contact occure an ContactJoint is created and instance of NewtonMaterial is assigned to it and then passed to callback function(s). Thank you for explanation. I think I will put those thoughts on WIKI when I finish.

All my mistake comes from thought that NewtonMaterial returned by iterator in time of collision are same. Which is not true.

Thanks for detailed explanation. I should read more carefully in future.

Delfi wrote:You still haven't explained what these group ids are that you speak about..

Group ID is just a Material ID. I'm trying to follow Newton naming:
Code: Select all
int NewtonMaterialCreateGroupID(const NewtonWorld* newtonWorld);

So Delfi, don't let me to confuse you. : )
thedmd
 

Re: Materials

Postby JernejL » Sun Nov 01, 2009 6:47 am

thedmd wrote:
Delfi wrote:You still haven't explained what these group ids are that you speak about..

Group ID is just a Material ID. I'm trying to follow Newton naming:
Code: Select all
int NewtonMaterialCreateGroupID(const NewtonWorld* newtonWorld);

So Delfi, don't let me to confuse you. : )


Oh yea, that's rather confusing, but it actually does define a "group - ID".. a single id for a whole group of relations to other materials for interactions, so althru the name sounds very wrong it actually means the right thing :D
Help improving the Newton Game Dynamics WIKI
User avatar
JernejL
 
Posts: 1587
Joined: Mon Dec 06, 2004 2:00 pm
Location: Slovenia

Re: Materials

Postby thedmd » Sun Nov 01, 2009 7:02 am

Delfi wrote:Oh yea, that's rather confusing, but it actually does define a "group - ID".. a single id for a whole group of relations to other materials for interactions, so althru the name sounds very wrong it actually means the right thing :D

Yeap! "Group ID" is just an identifier of the group not group of identifiers. Which I mean from the very beginning but maybe typed wrong. : )

I think I have almost whole picture about Newton API. Very thanks for help.
thedmd
 

Re: Materials

Postby Julio Jerez » Sun Nov 01, 2009 8:19 am

There one new feature for 2.00
You can ignore the Materials and use the Collision ID instead.
you can Let the Default-Default ID for all bodies and in teh Callback you can use the Collision Shape ID for handling your own Material system on the Application side.
This is possible because in 2.0 because collision IDs are part of the cache signature of the collison shape, so when you identical shape the are only different in the ID, they will get different Cache entries.
This allow for make a unified collision system tah can dealt with shapes with mutipels IDs, like compound, terrains, and collision tree in teh same callback and with one system.

Writting the Material system one the application side gives the application more control and you do not have to write some many callback,

See tutorial Advanced Custom Material System in the wiki 200 series.
I implemented a Material system using collision shapes, that is very similar to the one use internally in Newton and it is open source.

you can even use both systems simultanuely, sence the the system base on ID will use just one Materail Pairs, and only boies with thos ID will answer tha callback.
I like this user side Materail method because it is more flexible
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Materials

Postby thedmd » Sun Nov 01, 2009 11:10 am

I wonder what those ID's in collision was for. Now I know. : )

It is great idea to manage materials by myself, but there is the other side of the same coin. I'm trying to provide 1-1 Newton API for managed languages, so I also must expose materials.

Writting an Material System using Collision ID is a solution, but then I need to mimic Newton behaviour. There is a much more possibility that I introduce some fresh bugs. So this is not ideal, but have a potential.

I'm prefer to keep close to the metal and let Newton do his job. Wrapper should be as thin as possible.

I will keep in mind this possibility of writing customized material system. Also I will check mentioned toutorial.
thedmd
 

Re: Materials

Postby JernejL » Sun Nov 01, 2009 6:50 pm

Since you are going to cache the set values using NewtonMaterialSetDefaultSoftness.. (my guess) as there's no GET calls, this will come in handy for filling defaults:

default material values:
Softness 0.1
Elasticity 0.4
staticFriction 0.9
dynamicFriction 0.5
Help improving the Newton Game Dynamics WIKI
User avatar
JernejL
 
Posts: 1587
Joined: Mon Dec 06, 2004 2:00 pm
Location: Slovenia

Re: Materials

Postby thedmd » Sun Nov 01, 2009 8:26 pm

Thanks Delfi. You're guessing well. : )
I will use those values.
thedmd
 


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 2 guests

cron