A place to discuss everything related to Newton Dynamics.
Moderators: Sascha Willems, walaber
by Markus » Thu Apr 14, 2011 3:25 pm
Hi,
for the domino simulation I'm programming I encountered the problem that the domino pieces will not stay upright on surfaces with a little slope. I'm loading the scene from a 3ds file into a TreeCollision and tried to place the pieces on a small ramp, but they start falling even at a small angle.
So I figured one could use NewtonMeshDifference to clip the domino pieces against the scene collision in order to adjust the bottom face to the underlying surface (See attachment for a picture).
I tried using the clip functions with a small test program:
- Code: Select all
tmp = identity;
tmp1 = translate(0.0f, 2.5f, 0.0f);
NewtonCollision* collision1 = NewtonCreateBox(g_world, 5.0, 5.0, 5.0, 0, tmp[0]);
NewtonCollision* collision2 = NewtonCreateBox(g_world, 5.0, 5.0, 5.0, 0, tmp1[0]);
NewtonMesh* mesh1 = NewtonMeshCreateFromCollision(collision1);
NewtonMesh* mesh2 = NewtonMeshCreateFromCollision(collision2);
NewtonMesh* mesh3 = NewtonMeshCreate(g_world);
NewtonMesh* mesh4 = NewtonMeshCreate(g_world);
NewtonMeshClip(mesh1, mesh2, tmp[0], &mesh3, &mesh4);
// mesh3 and mesh4 are NULL
The result i get is that both mesh3 and mesh4 are NULL. Using NewtonMeshDifference, NewtonMeshIntersection and NewtonMeshUnion leads to the same result. I looked into the code and realized that all clip functions use
void dgMeshEffect::TransformMesh (const dgMatrix& matrix) which consists of "_ASSERTE (0);" Is this the problem or am I doing anything wrong? I could not find any documentation to these functions anyway...
Maybe there even is an idea much more simple for achieving the same thing?
- Attachments
-

- clip.png (2.4 KiB) Viewed 2348 times
-
Markus
-
- Posts: 52
- Joined: Sat Mar 19, 2011 6:31 am
by Julio Jerez » Thu Apr 14, 2011 4:11 pm
you are doing it correct, There was a bug in the mesh difference that I fixed this morning, (I guess it is a case of serendipity)
basically the function will return bogus value if the input manes have coplanar faces, it is fixed now and check in. I discovered when I was making the Compound collision demo.
If you are sync to SVN just update and it should the test should work.
-
Julio Jerez
- Moderator

-
- Posts: 12426
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by Julio Jerez » Thu Apr 14, 2011 4:18 pm
looking at the function I do not think will work, try this
- Code: Select all
matrix tmp = identity;
NewtonCollision* collision1 = NewtonCreateBox(g_world, 5.0, 5.0, 5.0, 0, tmp[0]);
NewtonCollision* collision2 = NewtonCreateBox(g_world, 5.0, 5.0, 5.0, 0, tmp[0]);
NewtonMesh* mesh1 = NewtonMeshCreateFromCollision(collision1);
NewtonMesh* mesh2 = NewtonMeshCreateFromCollision(collision2);
matrix tmp1 = translate(0.0f, 2.5f, 0.0f);
NewtonMesh* const mesh3 = NewtonMeshDifference (mesh1, mesh2, & tmp1[0]);
// do not forget delete the meshes, of you will leave big memory leaks behind
-
Julio Jerez
- Moderator

-
- Posts: 12426
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by Julio Jerez » Thu Apr 14, 2011 5:24 pm
Ha one more thing, if you are going to clip the dominos against the floor for better,
do not make a collision mesh of the terrain, and clip against the terrain, that will make the boolean very slow if the mesh have lots of faces.
I think it will be better to get the faces underneah the domino and make a temp NewtonMesh and then clip gainst that smaller mesh.
you can use the full mesh and get it to work, but if it is slow you can try that as an optimization phase.
-
Julio Jerez
- Moderator

-
- Posts: 12426
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by Markus » Fri Apr 15, 2011 7:15 am
Thanks Julio, it seems to be working great in my small test program!
I have one other issue, though: When clipping the white box (domino) against the red box (floor), I will end up with the blue collision, created with NewtonCreateConvexHullFromMesh(g_world, mesh3, 0.0f, 0);, where mesh3 is the result of the difference operation. This is obvious, because it is a convex collision. What would I need to do in order to get the yellow collision? Is there a way to do that in Newton?
- Attachments
-

- diff.png (8.23 KiB) Viewed 2329 times
-
Markus
-
- Posts: 52
- Joined: Sat Mar 19, 2011 6:31 am
by Julio Jerez » Fri Apr 15, 2011 7:24 am
to get the yellow collision ther is a another set of function.
firt clip boolean the mesh until you get teh shape you want
the you make a comve decompaosition using the function NewtonMeshTetrahedralization
then you call NewtonCreateCompoundCollisionFromMesh, and it will and make an optimal compound collision
whowever NewtonMeshTetrahedralization and NewtonCreateCompoundCollisionFromMesh are no workimng yet, I am make that demo and I am hopping to have ready by this week end.
-
Julio Jerez
- Moderator

-
- Posts: 12426
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by Markus » Fri Apr 15, 2011 2:03 pm
That would be great, thanks. It is working nicely with a convex shape even on surfaces with a large angle (see picture).
I will be testing it with these function after you have implemented them. I'm looking forward to it.
- Attachments
-

- diffclip.jpg (56.1 KiB) Viewed 2315 times
-
Markus
-
- Posts: 52
- Joined: Sat Mar 19, 2011 6:31 am
Return to General Discussion
Who is online
Users browsing this forum: No registered users and 0 guests