NewtonBodySetCollisionScale issue

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

NewtonBodySetCollisionScale issue

Postby Spek » Sat Apr 30, 2016 6:52 am

Any idea why my player -just a capsule with an up constraint joint- falls through the floor as soon as I change the scale with
NewtonBodySetCollisionScale( body, 1, height, 1 );

This function is called continously, no problem. But as soon as the "height" is something different than 1, collision-detection with the scene stops working.

I'd like to use scaling to make a "crouch" pose for my player. So the height gradually goes down to 0.5 for example, when hitting the crouch button.


Using Newton 3. Not sure which version, but not the latest (downloaded it somewhere early 2015). Switching to a newer version is a bit more tricky as I'm using Delphi, so I wanted to ask first before taking that route.
Spek
 
Posts: 66
Joined: Sat Oct 04, 2008 8:54 am

Re: NewtonBodySetCollisionScale issue

Postby Spek » Sat Apr 30, 2016 7:18 am

Little extra detail; when I set the scale back to "1" after downscaling it first, collisions work again.
Spek
 
Posts: 66
Joined: Sat Oct 04, 2008 8:54 am

Re: NewtonBodySetCollisionScale issue

Postby Julio Jerez » Sat Apr 30, 2016 8:39 am

That should never happens, scale should always works.
there where some changes to the low level collision system for 3.14
maybe some was left out.
can you recreate that bug in the sandbox demos for me to debug, just change any of the demos.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: NewtonBodySetCollisionScale issue

Postby Spek » Sat Apr 30, 2016 1:26 pm

Just tried it by adjusting the "BasicPlayerController" demo in a very recent download of Newton. Besides the demo crashing a bit randomly (it already did before the adjustments, and also in older versions of Newton), the collisions kept working - so no scaling issues here. All I do really is decreasing the Y-scale over time when going into crouch.


I think that something else is going wrong in my (Newton related) code prior to that, but its hard to tell what.

Now interestingly, it does not fall through other bodies which are usually Convex Compounds, except the scenery, which is a "CollisionTree". Or actually, a whole bunch of bodies, added with "NewtonSceneCollisionAddSubCollision".

Although it seemed to work so far, I always found my code here suspicious, as I'm not really sure I'm adding / removing "chunks" to this CollisionTree properly (note its a roaming world, so stuff appears and dissapears all the time).

Could a wrong setup (or destruction) of the CollisionTree cause this, or perhaps trigger a memory bug of some sort?
Spek
 
Posts: 66
Joined: Sat Oct 04, 2008 8:54 am

Re: NewtonBodySetCollisionScale issue

Postby Julio Jerez » Sat Apr 30, 2016 2:32 pm

The thing is that is I do I will probable do it right and will not recreate the problem.

try make the change by editing the demo. the is a simple player demo that move on a collision tree mesh
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: NewtonBodySetCollisionScale issue

Postby Spek » Sun May 01, 2016 5:16 am

It's a bit hard to test, as the demo's keep crashing sort of randomly, throwing an assertion in a vector or math operation. Anyhow:
- Default floor - demo works, but crashes at some point
- No floor - demo works, players falls deep down, then the demo crashes at some point
- My quad floor - demo crashes after 1 second, before hitting the floor

It doesn't like the testFloor CollisionTree I made for sure, though it crashes in all circumstances anyway, so it might be coincidence. Anyhow, code below. Added a function to create the test floor, replaced parts of the original floor construction code.


Back in my own program, I noticed:
- It works when inserting Boxes into the SceneCollision, instead of Trees. I can downscale objects now.
- It doesn't work with trees
- It neither works with the simplified floormesh (as I tried in the Newton demo)

Now I thought, maybe the mesh itself is a problem? The standard demo floor is a 6-quad box (right?).
In my case, floors or walls are just triangles without volume. A floor or wall could be
a flat quad (made of 2 tris). Basically I just re-use the visual mesh for Newton. And that visual mesh could be anything really.

I must say that I always had trouble with stuff falling through the world sometimes, in older versions of Newton (1,2). So maybe the root of the problem lays in the trees, or the way how I construct them.


Code: Select all
// Make a 2-triangle flat test floor
NewtonCollision* testCreateFlatFloor(DemoEntityManager* const scene)
{
   NewtonCollision* tree = NewtonCreateTreeCollision(scene->GetNewton(), 0);
   NewtonTreeCollisionBeginBuild(tree);

   dFloat face[3][3];
   face[0][0] = +50; face[0][1] = 0; face[0][2] = -50;
   face[1][0] = -50; face[1][1] = 0; face[1][2] = -50;
   face[2][0] = -50; face[2][1] = 0; face[2][2] = +50;
   NewtonTreeCollisionAddFace(tree, 3, &face[0][0], 36, 0);

   face[0][0] = +50; face[0][1] = 0; face[0][2] = -50;
   face[1][0] = -50; face[1][1] = 0; face[1][2] = +50;
   face[2][0] = +50; face[2][1] = 0; face[2][2] = +50;
   NewtonTreeCollisionAddFace(tree, 3, &face[0][0], 36, 0);

   NewtonTreeCollisionEndBuild( tree, 0);

   return tree;
} // testCreateFlatFloor


static void LoadFloor(DemoEntityManager* const scene, NewtonCollision* const sceneCollision)
{
   NewtonWorld* const world = scene->GetNewton();

   // add a flat plane
   dMatrix matrix(dGetIdentityMatrix());
   DemoEntityManager::dListNode* const floorNode = LoadScene(scene, "flatPlane.ngd", matrix);

   DemoEntity* const entity = floorNode->GetInfo();
   DemoMesh* const mesh = (DemoMesh*)entity->GetMesh();
   dAssert (mesh->IsType(DemoMesh::GetRttiType()));

   // Replace original code with testFloor

/*   NewtonCollision* const tree = NewtonCreateTreeCollision(world, 0);
   NewtonTreeCollisionBeginBuild(tree);

   dFloat* const vertex = mesh->m_vertex;
   for (DemoMesh::dListNode* node = mesh->GetFirst(); node; node = node->GetNext()){
      DemoSubMesh* const subMesh = &node->GetInfo();
      unsigned int* const indices = subMesh->m_indexes;
      int trianglesCount = subMesh->m_indexCount;
      for (int i = 0; i < trianglesCount; i += 3) {

         dFloat face[3][3];
         for (int j = 0; j < 3; j ++) {
            int index = indices[i + j] * 3;
            face[j][0] = vertex[index + 0];
            face[j][1] = vertex[index + 1];
            face[j][2] = vertex[index + 2];
         }
//         index = indices[i + 1] * 3;
//         face[1] = dVector (vertex[index + 0], vertex[index + 1], vertex[index + 2]);

//         index = indices[i + 2] * 3;
//         face[2] = dVector (vertex[index + 0], vertex[index + 1], vertex[index + 2]);

         int matID = 0;
         //matID = matID == 2 ? 1 : 2 ;
         NewtonTreeCollisionAddFace(tree, 3, &face[0][0], 3 * sizeof (dFloat), matID);
      }
   }
   NewtonTreeCollisionEndBuild (tree, 1);
*/
   NewtonCollision* const tree = testCreateFlatFloor(scene);

   // add the collision tree to the collision scene
   void* const proxy = NewtonSceneCollisionAddSubCollision (sceneCollision, tree);

   // destroy the original tree collision
   NewtonDestroyCollision (tree);


   // set the parameter on the added collision share
   matrix = entity->GetCurrentMatrix();
   NewtonCollision* const collisionTree = NewtonSceneCollisionGetCollisionFromNode (sceneCollision, proxy);

   NewtonSceneCollisionSetSubCollisionMatrix (sceneCollision, proxy, &matrix[0][0]);   
   NewtonCollisionSetUserData(collisionTree, entity);

   // set the application level callback, for debug display
   #ifdef USE_STATIC_MESHES_DEBUG_COLLISION
   NewtonStaticCollisionSetDebugCallback (collisionTree, ShowMeshCollidingFaces);
   #endif   
}
Spek
 
Posts: 66
Joined: Sat Oct 04, 2008 8:54 am

Re: NewtonBodySetCollisionScale issue

Postby Julio Jerez » Sun May 01, 2016 7:58 am

Spek wrote:It's a bit hard to test, as the demo's keep crashing sort of randomly, throwing an assertion in a vector or math operation. Anyhow:
- Default floor - demo works, but crashes at some point
- No floor - demo works, players falls deep down, then the demo crashes at some point
- My quad floor - demo crashes after 1 second, before hitting the floor

Do no assume that the engine should crash, and accept it as normal, is not normal.
some is wrong either in newton side or the way you are setting parameters.

The demo should no crash under any circumstances, unless some input data is too extreme.
not there should ne be object falling trough the floor ever. Tell me what I do in the demo to make that happen. I have test more than a second and I do not see how to make it. and let us start form there.


is that c++ script what do add to the demo to make it crash, where do I put that?
I pasted in both player demos and the both do no complex.

I assume it is in id file AdvancedPlayerController.cpp
both when added there I get error.

so them exactly were to put and what to comet out. Because my guess is that you comment pout something and the demo expect that to be there.

also I thing is better you try the Basic Player controller with only put a player in the scene.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: NewtonBodySetCollisionScale issue

Postby Julio Jerez » Sun May 01, 2016 8:23 am

ok I see why you function crashes, you are passing the size of the entire array as vertex size, the function expect that size of a Vertex in the array.

Code: Select all
// Make a 2-triangle flat test floor
NewtonCollision* testCreateFlatFloor(DemoEntityManager* const scene)
{
   NewtonCollision* tree = NewtonCreateTreeCollision(scene->GetNewton(), 0);
   NewtonTreeCollisionBeginBuild(tree);

   dFloat face[3][3];
   face[0][0] = +50; face[0][1] = 0; face[0][2] = -50;
   face[1][0] = -50; face[1][1] = 0; face[1][2] = -50;
   face[2][0] = -50; face[2][1] = 0; face[2][2] = +50;
// !!he bug is here 36 is the number of bites in the array, vertex size of 3 * sizeof (dFloat) = 12
//NewtonTreeCollisionAddFace(tree, 3, &face[0][0], 36, 0);
   NewtonTreeCollisionAddFace(tree, 3, &face[0][0], 3 * sizeof (dFloat), 0);
...
...
} // testCreateFlatFloor


I pasted the script in the advanced player demo and I check in the code, so that you can continue from there adding the scaling bug problem.
Please sync and see if this work for you now. and see if you have similar problem in you original code.

when you test the demo, enable show collision wire frame, so that you can see the limit of the collision mesh, is small than the visual and the player will go over the edge, you may want to make the floor larger.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: NewtonBodySetCollisionScale issue

Postby Spek » Sun May 01, 2016 10:11 am

I'll download a clean copy of Newton first, maybe I screwed up something elsewhere in the Sandbox project, another time, as demo's keep crashing for no apparent reason. I also noticed the graphics being glitchy; I think the debug-draw is rendering solid meshes (instead of wireframes?) over the textured polygons. I bet that isn't supposed to happen either.
Spek
 
Posts: 66
Joined: Sat Oct 04, 2008 8:54 am

Re: NewtonBodySetCollisionScale issue

Postby Julio Jerez » Sun May 01, 2016 11:58 am

what copy are you downloading? all you nee to do is sync to github.
I check the demo will run the player demo with your changes.

I should work with not error, and no graphic glitches. It should near perfect in every way.

There are two debug display options in the menu, one that render solid meshes, and one that draw wire frame line, my guess is that you selected the solid shaped.
chose show wire frame.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: NewtonBodySetCollisionScale issue

Postby Spek » Sun May 01, 2016 3:17 pm

Not really familiar with Github, I just clicked the "Download ZIP" button on the root page. Well, after a re-download the glitchy graphics & crashes are gone. And as you tried, no problem either with the testfloor or scaling the player body down. So far so good. Or actually not good as I still couldn't reproduce the problem :)


Just to be sure, I also updated the Newton.dll in my own project (grabbed the one from the Github download, placed in /ModelEditor/). But no luck with the same test floor - and with a proper Stride bytecount. Solid boxes (NewtonCreateBox) on the other hand do work.


If there aren't any clear "do-not-do-X" related to Scaling, Trees or CollisionScene's, I'm afraid its a chain reaction of earlier bugs (on my side). I remember having very unpredictable behavior in the past, because one of the header declarations didn't stroke with the actual DLL function notation.

I'll just update to the latest Newton and walk through all my steps. When trying to run now with the latest DLL (assuming the /ModelEditor/ DLL inside the Github package is recent) and Stucuk's Pascal headers, it crashes, so something is smelling fishy anyway.
Spek
 
Posts: 66
Joined: Sat Oct 04, 2008 8:54 am

Re: NewtonBodySetCollisionScale issue

Postby Sweenie » Sun May 01, 2016 3:50 pm

I think the Newton.dll in the ModelEditor folder is at least 8 months old.

I you are unsure how to build a new dll I can do it for you.

[EDIT]

Try this(contains both 32 & 64-bit)

http://www.svenberra.net/NewtonBinaries.zip
Sweenie
 
Posts: 503
Joined: Mon Jan 24, 2005 7:59 am
Location: Sweden

Re: NewtonBodySetCollisionScale issue

Postby Julio Jerez » Sun May 01, 2016 4:10 pm

Is this Pascal wrapper? lot of thing has changes
do not use the dll in the model editor just compile the project you got with the download zip.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: NewtonBodySetCollisionScale issue

Postby Spek » Mon May 02, 2016 1:17 pm

That may also explain some of the weird quirks :)

I was already comparing all the C++ Newton.h declarations with the one I have, somewhere halfway now. One little doubt I had (and I think its also declared wrong in Stucuk's Pascal headers), is the "dLong" type. This is a 64bit (signed) integer, right?


Thanks Sweenie! I have VS2013, but wasn't sure how to build the DLL's.
I'll let you guys know what the results are when I'm done upgrading.
Spek
 
Posts: 66
Joined: Sat Oct 04, 2008 8:54 am

Re: NewtonBodySetCollisionScale issue

Postby Spek » Mon May 02, 2016 6:39 pm

All right. No more falling through floors when downscaling :) Used recent binaries Sweenie gave & updated the whole Delphi header file.


But of course programming wouldn't be programming if another problem didn't occur; upVector. It worked fine before, but now it makes my player spin as if he was possessed. Or other times it doesn't go wild, but neither does the constraint keep my player up. Not calling "NewtonConstraintCreateUpVector" avoids the wild spinning, but obviously the player falls down like a drunken sailor now.

For the info, the player is just a capsule ( "NewtonCreateCapsule" ), not a Newton Player. Maybe it's just another bug from my side, or is there something different with the upVector nowadays?
Spek
 
Posts: 66
Joined: Sat Oct 04, 2008 8:54 am

Next

Return to General Discussion

Who is online

Users browsing this forum: Julio Jerez and 5 guests