[Solved]Player controller seems ignore tree collision.

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Re: Player controller seems ignore tree collision.

Postby Neo » Sun May 19, 2013 12:41 pm

Yeah,absolutely.
And manualy use vertices(float array)to create tree collision.
Here's the construction code, just ignore my comments, there's too much comment to modify:
Code: Select all
NewtonBody* mapManager::createTreeCollisionFromMesh(NewtonWorld *nWorld, irr::scene::IMeshSceneNode *irr_meshNode,s32 shapeID)
{
   scene::IMesh *irr_mesh=irr_meshNode->getMesh();
   NewtonCollision *collision_map=NewtonCreateTreeCollision(nWorld,0);

   NewtonTreeCollisionBeginBuild(collision_map);

   u32 nMeshBuffer=0;//meshBuffer总数
   u32 vertice_index[3]={0,0,0};//顶点索引
   scene::IMeshBuffer *mesh_buffer=NULL;
   f32 vertex_array[9];//save 3 points

   for (nMeshBuffer=0;nMeshBuffer<irr_mesh->getMeshBufferCount();nMeshBuffer++)
   {
      mesh_buffer=irr_mesh->getMeshBuffer(nMeshBuffer);
      switch(mesh_buffer->getVertexType())//判断向量类型(阴影图有些特殊向量要忽略)
      {
         //取得顶点和索引指针
      case video::EVT_STANDARD:
         {
            video::S3DVertex *vertices=(video::S3DVertex*)mesh_buffer->getVertices();
            u16*indices=mesh_buffer->getIndices();

            //填充碰撞模型
            for (u32 i=0;i<mesh_buffer->getIndexCount();i+=3)
            {
               //一次取三个点
               for(u32 j=0;j<3;j++)vertice_index[j]=indices[i+j];
               
               //第一个顶点
               vertex_array[0]=vertices[vertice_index[0]].Pos.X;
               vertex_array[1]=vertices[vertice_index[0]].Pos.Y;
               vertex_array[2]=vertices[vertice_index[0]].Pos.Z;
               //第二个顶点
               vertex_array[3]=vertices[vertice_index[1]].Pos.X;
               vertex_array[4]=vertices[vertice_index[1]].Pos.Y;
               vertex_array[5]=vertices[vertice_index[1]].Pos.Z;
               //第三个顶点
               vertex_array[6]=vertices[vertice_index[2]].Pos.X;
               vertex_array[7]=vertices[vertice_index[2]].Pos.Y;
               vertex_array[8]=vertices[vertice_index[2]].Pos.Z;
               

               //向碰撞模型中加入新的面
               NewtonTreeCollisionAddFace(collision_map,//要增加面的模型
                                    3,//一个面的顶点数
                                    &vertex_array[0],//储存顶点的数组
                                    3*sizeof(f32),//每个顶点的大小
                                    shapeID+nMeshBuffer);//面的ID
            }
            break;
         }
      case video::EVT_2TCOORDS:
         {
            video::S3DVertex2TCoords* vertices = (video::S3DVertex2TCoords*)mesh_buffer->getVertices();
            u16*indices=mesh_buffer->getIndices();

            //填充碰撞模型
            for (u32 i=0;i<mesh_buffer->getIndexCount();i+=3)
            {
               //一次取三个点
               for(u32 j=0;j<3;j++)vertice_index[j]=indices[i+j];

               //第一个顶点
               vertex_array[0]=vertices[vertice_index[0]].Pos.X;
               vertex_array[1]=vertices[vertice_index[0]].Pos.Y;
               vertex_array[2]=vertices[vertice_index[0]].Pos.Z;
               //第二个顶点
               vertex_array[3]=vertices[vertice_index[1]].Pos.X;
               vertex_array[4]=vertices[vertice_index[1]].Pos.Y;
               vertex_array[5]=vertices[vertice_index[1]].Pos.Z;
               //第三个顶点
               vertex_array[6]=vertices[vertice_index[2]].Pos.X;
               vertex_array[7]=vertices[vertice_index[2]].Pos.Y;
               vertex_array[8]=vertices[vertice_index[2]].Pos.Z;


               //向碰撞模型中加入新的面
               NewtonTreeCollisionAddFace(collision_map,//要增加面的模型
                  3,//一个面的顶点数
                  &vertex_array[0],//储存顶点的数组
                  3*sizeof(f32),//每个顶点的大小
                  shapeID+nMeshBuffer);//面的ID
            }
         }
         break;
      case video::EVT_TANGENTS:
         {
            video::S3DVertexTangents* vertices = (video::S3DVertexTangents*)mesh_buffer->getVertices();
            u16*indices=mesh_buffer->getIndices();

            //填充碰撞模型
            for (u32 i=0;i<mesh_buffer->getIndexCount();i+=3)
            {
               //一次取三个点
               for(u32 j=0;j<3;j++)vertice_index[j]=indices[i+j];

               //第一个顶点
               vertex_array[0]=vertices[vertice_index[0]].Pos.X;
               vertex_array[1]=vertices[vertice_index[0]].Pos.Y;
               vertex_array[2]=vertices[vertice_index[0]].Pos.Z;
               //第二个顶点
               vertex_array[3]=vertices[vertice_index[1]].Pos.X;
               vertex_array[4]=vertices[vertice_index[1]].Pos.Y;
               vertex_array[5]=vertices[vertice_index[1]].Pos.Z;
               //第三个顶点
               vertex_array[6]=vertices[vertice_index[2]].Pos.X;
               vertex_array[7]=vertices[vertice_index[2]].Pos.Y;
               vertex_array[8]=vertices[vertice_index[2]].Pos.Z;


               //向碰撞模型中加入新的面
               NewtonTreeCollisionAddFace(collision_map,//要增加面的模型
                  3,//一个面的顶点数
                  &vertex_array[0],//储存顶点的数组
                  3*sizeof(f32),//每个顶点的大小
                  shapeID+nMeshBuffer);//面的ID
            }
         }
         break;
      default:
         return 0;
      }
   }

   NewtonTreeCollisionEndBuild(collision_map,1);
   NewtonBody* mapMesh;
   //get position and rotation
   matrix4 matrix;
   vector3df scale=irr_meshNode->getScale()*IrrToNewton;
   matrix.makeIdentity();
   vector3df pos=irr_meshNode->getPosition()*IrrToNewton;
   vector3df rot=irr_meshNode->getRotation();
   matrix.setTranslation(pos);
   matrix.setRotationDegrees(rot);
   NewtonCollisionSetScale(collision_map,scale.X,scale.Y,scale.Z);
   //create newtonbody
   mapMesh=NewtonCreateBody(nWorld,collision_map,&matrix.pointer()[0]);
   
   NewtonBodySetMaterialGroupID(mapMesh,floorM);

   NewtonDestroyCollision(collision_map);
   
   return mapMesh;
}
Neo
 
Posts: 127
Joined: Fri May 11, 2012 12:29 pm
Location: China,Sichuan

Re: Player controller seems ignore tree collision.

Postby Julio Jerez » Sun May 19, 2013 12:58 pm

Ok, first let us do one more thing, before you I modify that code.

SynC to SVN, and ;let me know if the bug is still happening, I think I know what made the player fail,

Then I post the change to your function to make that problem go away.
Julio Jerez
Moderator
Moderator
 
Posts: 12478
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Player controller seems ignore tree collision.

Postby Neo » Sun May 19, 2013 1:17 pm

Updated and recompled, and player still falling..
Neo
 
Posts: 127
Joined: Fri May 11, 2012 12:29 pm
Location: China,Sichuan

Re: Player controller seems ignore tree collision.

Postby Julio Jerez » Sun May 19, 2013 1:21 pm

that doe no make sense, you said that I was working before.

has you implemented do you have debug display?
is so are you sure the collision mesh are in the same location that the visual mesh says?
can you post a picture that shows the collision mesh to see what is going on?
Julio Jerez
Moderator
Moderator
 
Posts: 12478
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Player controller seems ignore tree collision.

Postby Neo » Sun May 19, 2013 1:42 pm

I do't have debug display, but I can export a serialize file of current scene when I press tab button, then import it into sandbox.
The new sandbox somehow cannot import serialized file, so now i use the old one to see what happend..
Image
beside is a rigid body, it stay there without falling. Next frame the player fall straight through the floor while the rigid body next to it is still there.
I let the sand box show the collision mesh, but I dont know why the tree collision (you see, the terrain and the house)doesn't show collision wireframe.(But the collision between collision tree and rigid body still happens)
Neo
 
Posts: 127
Joined: Fri May 11, 2012 12:29 pm
Location: China,Sichuan

Re: Player controller seems ignore tree collision.

Postby Julio Jerez » Sun May 19, 2013 1:57 pm

yet I have no added serialization to the new SDK yet.
how you loaded the mesh in the demos SandBox in the first place? I can probably do the same

Is there a way you can provide me with the lever mesh you are using?
I can place in the SDK an have a see what is wrong.

Maybe if you give me a copy of the serialized mesh that I can use for testing.
Julio Jerez
Moderator
Moderator
 
Posts: 12478
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Player controller seems ignore tree collision.

Postby Neo » Sun May 19, 2013 2:09 pm

Here, the level mesh, without texture. To make it easy to observe you can choose any texture you like:
https://dl.dropboxusercontent.com/u/91496491/terrain01.obj
Neo
 
Posts: 127
Joined: Fri May 11, 2012 12:29 pm
Location: China,Sichuan

Re: Player controller seems ignore tree collision.

Postby Julio Jerez » Sun May 19, 2013 2:25 pm

Ok I go the obj mesh, but that will required lot of work.

What I mean is that if you send me the serialized scene, because I can load the and have the visual mesh with the correct scale and the collision right scale.
Serialization still work is just that I have no implemented the menu option in the sanb bod demo.

Maybe if you let me add that serialization to the menu and you try to load the serialized word before you send it to me, at least we know it loads, would the be better for you.
Julio Jerez
Moderator
Moderator
 
Posts: 12478
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Player controller seems ignore tree collision.

Postby Neo » Sun May 19, 2013 2:36 pm

Ok, here's the serialize file, but, as you know, the joint won't save into serialize file, so those hinge joints(tanks) are just individual
rigid body in the scene..
https://dl.dropboxusercontent.com/u/91496491/test.bin
Thx
Neo
 
Posts: 127
Joined: Fri May 11, 2012 12:29 pm
Location: China,Sichuan

Re: Player controller seems ignore tree collision.

Postby Julio Jerez » Sun May 19, 2013 2:47 pm

I am no sure what is that I seeing wrong, I just hack the basic player controller demo so that it can load that file

this is the hack

Code: Select all
void BasicPlayerController (DemoEntityManager* const scene)
{
   // load the sky box
   scene->CreateSkyBox();

   //CreateLevelMesh (scene, "flatPlane.ngd", true);
   //CreateLevelMesh (scene, "playground.ngd", true);
   //CreateLevelMesh (scene, "castle.ngd", true);
   //CreateLevelMesh (scene, "sponza.ngd", true);
//   CreateLevelMesh (scene, "sibenik.ngd", true);

char xxx[256];
GetWorkingFileName ("test.bin", xxx);
FILE* const file = fopen (xxx, "rb");
dMatrix camMatrix(GetIdentityMatrix());
NewtonDeserializeBodyArray(scene->GetNewton(), DemoEntityManager::BodyDeserialization, DemoEntityManager::DeserializeFile, file);
fclose (file);


and the player runs fine. can you do that in your side and see if we are getting the same result?
Julio Jerez
Moderator
Moderator
 
Posts: 12478
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Player controller seems ignore tree collision.

Postby Julio Jerez » Sun May 19, 2013 2:53 pm

Oh I see when I start to walk aroung I do find place where the player do no fin a floor, it is as if there are missing faces in the mesh.

Ok let us do this.
-first I nee to add the serialization meny so tha we do no have to hack stuff.
-I will add an option when we can see the collsion mesh as solid geometry because in wire frame is difficult to see if the face is missing or not

them we will know where the real bug is. I believe it is because some faces are missing form the level.
the have to be tomorrow thought I have to go out now.
Julio Jerez
Moderator
Moderator
 
Posts: 12478
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Player controller seems ignore tree collision.

Postby Julio Jerez » Sun May 19, 2013 4:58 pm

Ok I added the serialization menu, please sync to svn and see if you can load you serilized level from your game.
It load as a world with a mesh and all teh dynamics bodies, teh playe will be a kenamic body that will be invisible by do no worrie aboout that.

to load in the game you can do just change the Basic Player controller to simple load that serilized level lie this


Code: Select all
   //CreateLevelMesh (scene, "flatPlane.ngd", true);
   //CreateLevelMesh (scene, "playground.ngd", true);
   //CreateLevelMesh (scene, "castle.ngd", true);
   //CreateLevelMesh (scene, "sponza.ngd", true);
//   CreateLevelMesh (scene, "sibenik.ngd", true);

// hack to load a serialized lever an test the player controller in teh snadBoxDemo
GetWorkingFileName ("MySerializedWorld.bin", xxx);
FILE* const file = fopen (xxx, "rb");
dMatrix camMatrix(GetIdentityMatrix());
NewtonDeserializeBodyArray(scene->GetNewton(), DemoEntityManager::BodyDeserialization, DemoEntityManager::DeserializeFile, file);
fclose (file);

the if that works, please send me the serialized world so that I can debug the bug.

Mean while I am adding the mode to just see the faces that teh playe ins interating with.
Julio Jerez
Moderator
Moderator
 
Posts: 12478
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Player controller seems ignore tree collision.

Postby Neo » Mon May 20, 2013 10:18 am

Sorry for late reply...I sync to svn just now, but cannot see the serialize menu in sandbox..
Dis you just change the code and I have to recompile the sandbox myself?
Neo
 
Posts: 127
Joined: Fri May 11, 2012 12:29 pm
Location: China,Sichuan

Re: Player controller seems ignore tree collision.

Postby Julio Jerez » Mon May 20, 2013 10:43 am

I may no check in the executable, I nee to be more careful with the check ins, I run out of space in google and I and already at 33% of the quota

you may have sync you need to rebuild the code if did no checked in binaries.
Julio Jerez
Moderator
Moderator
 
Posts: 12478
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Player controller seems ignore tree collision.

Postby Neo » Mon May 20, 2013 10:58 am

I have encounter a compiler error while trying to rebuild the sandbox:
“type_traits”: No such file or directory
What happend?
Neo
 
Posts: 127
Joined: Fri May 11, 2012 12:29 pm
Location: China,Sichuan

PreviousNext

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 3 guests