Mesh build problem

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Mesh build problem

Postby Forthehorde » Sun Dec 29, 2013 6:24 am

My mesh build process always fails here:
dgAssert ((normal % normal) > dgFloat32 (1.0e-10f));

Function: dgInt32 dgPolygonSoupDatabaseBuilder::FilterFace (dgInt32 count, dgInt32* const pool)

Normal: {m_x=3.2726675271987915e-006 m_y=2.1652085706591606e-006 m_z=8.3241611719131470e-006 ...}

The mesh works perfect in PhysX but I cannot get it to work here.

Full code of mesh build process for reference:

Code: Select all
void AABBoxRasterizerScalar::BuildCollision(CPUTAssetSet **pAssetSet,
                           UINT numAssetSets,
                           UINT idx)
{
   NewtonCollision * SceneData = NewtonCreateTreeCollision(GlobalWorld, 0);
   NewtonTreeCollisionBeginBuild(SceneData);

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//SAVE COOKED DATA TO DISK
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

   for(UINT assetId = 0, modelId = 0; assetId < numAssetSets; ++assetId)
   {
      for(UINT nodeId = 0; nodeId < pAssetSet[assetId]->GetAssetCount(); ++nodeId)
      {
         CPUTRenderNode* pRenderNode = 0;
         CPUTResult result = pAssetSet[assetId]->GetAssetByIndex(nodeId, &pRenderNode);
         ASSERT((CPUT_SUCCESS == result), _L ("Failed getting asset by index"));
         CPUTModelDX11 * model = (CPUTModelDX11*)pRenderNode;
         if(pRenderNode->IsModel() && model)
         {
            for(int meshId = 0; meshId < model->GetMeshCount(); ++meshId)
            {
               auto Mesh = model->GetMesh(meshId);
               if(Mesh && Mesh->mpRawVertices)
               {
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//FOR EACH MESH IN THE NODE
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

                  std::vector<float>NewVertices;
                  for(unsigned int i = 0; i < Mesh->mRawVertexCount; ++i)
                  {
                     float4 Vert4(Mesh->mpRawVertices[i].pos, 1.0f);
                     Vert4 = Vert4 * (*model->GetWorldMatrix()); //Test other way too
                     //Vert4 = (*model->GetWorldMatrix()) * Vert4;

                     NewVertices.push_back(Vert4.x);
                     NewVertices.push_back(Vert4.y);
                     NewVertices.push_back(Vert4.z);
                  }

                  if(Mesh->mIndexCount % 3 != 0)
                  {
                     int a = 0;
                  }

                  for(unsigned int i = 0; i < Mesh->mIndexCount; i += 3)
                  {
                     float3 Face[3];
                     unsigned int Index = Mesh->mpRawIndices[i + 0] * 3;

                     Face[0] = float3(NewVertices[Index + 0], NewVertices[Index + 1], NewVertices[Index + 2]);

                     Index = Mesh->mpRawIndices[i + 1] * 3;
                     Face[1] = float3(NewVertices[Index + 0], NewVertices[Index + 1], NewVertices[Index + 2]);

                     Index = Mesh->mpRawIndices[i + 2] * 3;
                     Face[2] = float3(NewVertices[Index + 0], NewVertices[Index + 1], NewVertices[Index + 2]);

                     NewtonTreeCollisionAddFace(SceneData, 3, &Face[0].x, sizeof(float3), 0);

                  }

                  

                  //PxTriangleMeshDesc meshDesc;
                  //meshDesc.points.count           = Mesh->mRawVertexCount;
                  //meshDesc.points.stride          = sizeof(float3);
                  //meshDesc.points.data            = &NewVertices[0].x;

                  //meshDesc.triangles.count        = Mesh->mIndexCount / 3; //Indices - 2 for strip.
                  //meshDesc.triangles.stride       = 3 * sizeof(unsigned int);
                  //meshDesc.triangles.data         = &Mesh->mpRawIndices[0];

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//FOR EACH MESH IN THE NODE END
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
               }
            }
         }

         ++modelId;         
         pRenderNode->Release();
      }
   }

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//FINALIZE AND SERIALIZE MESH
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

   NewtonTreeCollisionEndBuild(SceneData, 1);

   //void * const proxy = NewtonSceneCollisionAddSubCollision(m_sceneCollision, SceneData);
   //NewtonDestroyCollision(SceneData);

   int a = 0;
}
User avatar
Forthehorde
 
Posts: 26
Joined: Sun Dec 29, 2013 6:17 am

Re: Mesh build problem

Postby Forthehorde » Sun Dec 29, 2013 8:05 am

Ok I realised that NewtonMesh is latest and best thing so I used it and no more problems, however after serializing the data and trying to open with nme.exe it crashes.
User avatar
Forthehorde
 
Posts: 26
Joined: Sun Dec 29, 2013 6:17 am

Re: Mesh build problem

Postby Julio Jerez » Sun Dec 29, 2013 11:20 am

how you serialized the mesh?


Serialization is not a file formal. you determine the format,
if you want to open the mesh in mne, you can saveit as a .off whi is a file format wit specification.

also the first code should no crash, the assert if only telling you that the mesh has degenerated faces.
if you continues or you build in release it will not warn you.

however mesh with degenerated face lead to bad physics behavior, The dNetwonMesh does not fail because it repair the mesh by combing generated faces with adjacent faces.
and finally yes using dNewtonMesh is better than building collision tree directly, but that utill does more work top get a higher quality mesh
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 0 guests

cron