FaceAttribute and raycast

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

FaceAttribute and raycast

Postby Leadwerks » Tue Jun 16, 2009 5:00 pm

Can the raycast retrieve the face attribute from NewtonTreeCollisionAddFace()? I set the face attribute to the triangle index, so this would allow me to retrieve which triangle was picked.
User avatar
Leadwerks
 
Posts: 569
Joined: Fri Oct 27, 2006 2:54 pm

Re: FaceAttribute and raycast

Postby Julio Jerez » Tue Jun 16, 2009 5:58 pm

this is the prototype of the raycast call back

Code: Select all
static dFloat RayCast (const NewtonBody* body, const dFloat* normal, int collisionID, void* userData, dFloat intersetParam)

collisionID is the terrain ID of the face you passed.
if you set an ordinal number to each face, and you set optimization off, the you can use collisionID, as the index into the face list, in your own mesh.
just make sure the shape is a collision TREE by calling CollsionGetInfo.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: FaceAttribute and raycast

Postby Leadwerks » Wed Jun 17, 2009 11:19 am

Thanks.
User avatar
Leadwerks
 
Posts: 569
Joined: Fri Oct 27, 2006 2:54 pm

Re: FaceAttribute and raycast

Postby JernejL » Wed Jun 17, 2009 1:23 pm

Julio: i know this may be a important limit of newton engine internals, but is it really impossible to have a trimesh that has multiple materials? similar with a compound collision - this would really solve a lot of material issues, right now i have to split all my trimeshes for each material type and re-combine them in game world space as separate bodies at same locations.
Help improving the Newton Game Dynamics WIKI
User avatar
JernejL
 
Posts: 1587
Joined: Mon Dec 06, 2004 2:00 pm
Location: Slovenia

Re: FaceAttribute and raycast

Postby Julio Jerez » Wed Jun 17, 2009 2:18 pm

The collision shape has an ID per face. you can put whatever you want on teh ID.
if you want to make a Collision tree, or a Terrain, you need to implement a Material call back that handle different shape ID.
Say for example you have a mesh for you level, and you want to identify floor and wall,
Then what you do is you make a Level/other material callback.
In the callback you implement a switch case for each material ID in the level.

You can do that for all multi shape collisions: Terrain, collision trees, and compound collision.
Collision tree is the more common multi shape collisions which have the capacity to store a uniq id per face.

I realize I removed an implementation of this functionality in the SDK demos, but I will add one tonight.
There was one in 1.53

Basically you do not need to implement multiplex bodies just so that you can have different material, you can do that with just one body and collision tree using the collision ID in the call back.

Thank for point that out, I think many people do not realize that. But the functionality is there.
I will post the code here tonight and also add it to the SDK.

Maybe I will add a sound to play on different faces.
Will that help?
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: FaceAttribute and raycast

Postby JernejL » Wed Jun 17, 2009 6:05 pm

But then i have to manually calculate the material collision responses, it's not as easy as just setting up material pairs, i still havent figured out a good consistient way how to do this.
Help improving the Newton Game Dynamics WIKI
User avatar
JernejL
 
Posts: 1587
Joined: Mon Dec 06, 2004 2:00 pm
Location: Slovenia

Re: FaceAttribute and raycast

Postby Leadwerks » Wed Jun 17, 2009 6:16 pm

I don't think it is a good design approach to have multiple materials per tree. Rendering is done with batches of like triangles, and I think physics should be treated the same way, as it is now.
User avatar
Leadwerks
 
Posts: 569
Joined: Fri Oct 27, 2006 2:54 pm

Re: FaceAttribute and raycast

Postby Julio Jerez » Wed Jun 17, 2009 7:18 pm

Actually Delfi’s idea is not bad. But it is a big change in the engine.
The problem is that materials are assigned to Bodies not to Collision shape.
When to bodies collide you get one function call for the material pair.
And it is the client responsibility to scan each of the contacts for collision respond.
Because there is only one call for all contacts, it is possible that a body have a contact in one material and a contact on another material.
So it is difficult to determine how to make the call.
If this was 1.53 were we made one call per contact, thne that could be very eassy to assign the Material to the collision shape, and not to Bodies.
Maybe there is a compromised solution, but I have to revisit the engine to see if it is possible.

I like the idea of moving the material ID to the shape, and not to the body, because it make more sense, that a collision shape is made of a material type the a body is made of a material.
Let me make the demo and see what I can come up with. Because I do no thonk it si that hard Delfi.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: FaceAttribute and raycast

Postby Julio Jerez » Wed Jun 17, 2009 7:26 pm

Oh I think I got it. And it is quite simple.
Let me get home to check the engine, but if I am correct this is very simple and do no requires any engine changes, but and it is will handle collision shapes, faces and everything else in a generic way.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: FaceAttribute and raycast

Postby JernejL » Sat Jun 20, 2009 7:45 pm

would this still work with old way where bodies were assigned materials and not collisions? i assume a lot of old code may be out there that depends on assigning material to bodies, so both ways should still work.
Help improving the Newton Game Dynamics WIKI
User avatar
JernejL
 
Posts: 1587
Joined: Mon Dec 06, 2004 2:00 pm
Location: Slovenia

Re: FaceAttribute and raycast

Postby Julio Jerez » Sat Jun 20, 2009 8:53 pm

yes, it will.
I am not changeng anything, I will only and a demo with a level collsion and few bodes with different materials.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 2 guests

cron