Booleans

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Re: Booleans

Postby Bird » Tue Jun 26, 2012 12:43 pm

Julio Jerez wrote:Ha i see, I believe I have all the information I need from part 3 "A Mesh Edit Box"

what I will do is I will write a utility function that will create a VertexList index list mesh just liek is ecplain in part 3, you can use it to build data for you plugin.
It have to be later tonight have to go to work now.

Heh, those tutorials from Ernie Wright were what got me hooked on writing plugins way back then. Ernie was such a great teacher ... too bad he's not still with Newtek.

Thanks for the help with this. It's much appreciated! I'm hoping to have LW doing stuff like this someday using Newton. :)
[url]
http://rayfirestudios.com/index.php?id=18[/url]

-Bird
Bird
 
Posts: 623
Joined: Tue Nov 22, 2011 1:27 am

Re: Booleans

Postby Julio Jerez » Tue Jun 26, 2012 1:20 pm

I believe we can match that. totatlly.

we can also make our own variances.
and I too am hopping thsi will be sooner that you might think.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Booleans

Postby Julio Jerez » Tue Jun 26, 2012 2:53 pm

Ok here we go.
this will make a mesh wih a sible texture. teh etwon mesg also supports per face materai nad more than one UV channel
but for now this I think will do. aftyer you are more familiar you can use it to make more detailed meshes. using matreail and teh secudn UV
I did not test it but I thonk it should work.

Code: Select all
void MakeLightWaveMesh (MeshEditOp* const edit, NewtonMesh* mesh, const char *surfname, const char* const vmapname)
{
   int vertexCount = NewtonMeshGetVertexCount(mesh);
   int vertexStride = NewtonMeshGetVertexStrideInByte(mesh) / sizeof (dFloat64);
   dFloat64* const vertexList = NewtonMeshGetVertexArray(mesh);

   LWPntID* const pt = new LWPntID[vertexCount];
   for (int i = 0; i < vertexCount; i ++) {
      LWDVector pos;
      pos.x = vertexList[i * vertexStride + 0];
      pos.y = vertexList[i * vertexStride + 1];
      pos.z = vertexList[i * vertexStride + 2];
      pt[ i ] = edit->addPoint( edit->state, pos );
   }

   int pointCount = NewtonMeshGetPointCount(mesh);
   int pointStride = NewtonMeshGetPointStrideInByte(mesh) / sizeof (dFloat64);
   dFloat64* const uvList = NewtonMeshGetUV0Array(mesh);
   
   int* const uvMask = new int[pointCount];
   memset (uvMask, 0, sizeof (int) * pointCount);
   for (void* face = NewtonMeshGetFirstFace (mesh); face; face = NewtonMeshGetNextFace (mesh, face)) {
      if (!NewtonMeshIsFaceOpen (mesh, face)) {
         int faceVertexIndices[256];
         int facePointIndices[256];

         int vertexCount = NewtonMeshGetFaceIndexCount (mesh, face);
         NewtonMeshGetFaceIndices (mesh, face, faceVertexIndices);
         LWPntID vt[256];
         for (int j = 0; j < vertexCount; j++ ) {
             vt[j] = pt[faceVertexIndices[j]];
         }
         LWPolID pol = edit->addFace( edit->state, surfname, vertexCount, vt );

         NewtonMeshGetFacePointIndices (mesh, face, facePointIndices);
         for (int j = 0; j < vertexCount; j++ ) {
            int index = facePointIndices[j];
            if (!uvMask[index]) {
               float uv[2];
               uvMask[index] = 1;
               uv[0] = float (uvList[pointStride * index + 0]);
               uv[1] = float (uvList[pointStride * index + 1]);
               edit->pntVPMap( edit->state, pt[faceVertexIndices[j]], pol, LWVMAP_TXUV, vmapname, 2, uv);
            }
         }
      }
   }

   delete[] uvMask;
   delete[] pt;
}
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Booleans

Postby Bird » Tue Jun 26, 2012 10:38 pm

Thanks, that's very helpful. I made a new plugin that uses that code but now there's a new problem. :)

I tested with 2 simple tetrahedron meshes with just one surface and no uv for now. I did a Boolean Difference operation and this time NewtonMeshGetVertexCount(mesh) returns 11 instead of the proper 8. I examined the result mesh in LW Modeler and there are no coincident vertices and the triangles are connected but there are 3 extra vertices from one of the original meshes floating out in space. Image

-Bird
Bird
 
Posts: 623
Joined: Tue Nov 22, 2011 1:27 am

Re: Booleans

Postby Julio Jerez » Tue Jun 26, 2012 11:49 pm

Yes that is correct, ther will be extra vertices. This is because I have noi added teh clean up face.
You were not getting then before becaus eteh function IndexStream remove then implicitly.
That will be clean up tomorrow morning when I add that last edge/vertex intesection function.


can you try a textured mesh to see if thatorks
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Booleans

Postby Bird » Wed Jun 27, 2012 6:35 am

can you try a textured mesh to see if thatork


To do that, I think I need one more piece of information. When I create the Newton mesh from parsing the LW geometry, I assign a surface ID (material index) to each triangle as shown in the "UsingNewtonMeshTool" sdk demo. My Surface class is similar to the DemoSubMesh class in the Newton Demo sdk

Code: Select all
// an user id that can be use to assign a material to the face (in the cube some face has matrial 0,
int * faceMaterialIndex = new int[triCount];
int faceIndex = 0;

const SurfaceList & surfaces = triMesh->getSurfaces();
SurfaceList::const_iterator it = surfaces.begin();
SurfaceList::const_iterator end = surfaces.end();
while ( it != end )
{
   Surface::Ptr surface = *it++;
   int tris = surface->getTriangleCount();
   for( int i = 0; i < tris; i++ )
      faceMaterialIndex[faceIndex++] = surface->id();
}


I need a way to retrieve this material index, so I can find the proper LW surface name for each triangle. Before you showed me this new code, I retrieved the material index like this.

Code: Select all
// extract the surface indices
SurfaceList surfaces;
void* const meshCookie = NewtonMeshBeginHandle (newtonMesh);
for (int handle = NewtonMeshFirstMaterial (newtonMesh, meshCookie); handle != -1; handle = NewtonMeshNextMaterial (newtonMesh, meshCookie, handle))
{
   int surfaceID = NewtonMeshMaterialGetMaterial (newtonMesh, meshCookie, handle);
   int indexCount = NewtonMeshMaterialGetIndexCount (newtonMesh, meshCookie, handle);

   // extract the indices belonging to each different surface
   IBuffer* iBuffer = new IBuffer(indexCount, sizeof(int));
   unsigned *indices = (unsigned*)iBuffer->getData();
   NewtonMeshMaterialGetIndexStream (newtonMesh, meshCookie, handle, (int*)indices);

   // create the new surface
   Surface::Ptr surface = new Surface;
   surface->setIndexBuffer(iBuffer);
   surface->setName( SurfaceMap::instance()->find(surfaceID) );
   surfaces.push_back(surface);
}
NewtonMeshEndHandle (newtonMesh, meshCookie);


Is there a way to find the material index for each face while iterating through the faces in this new code that you showed me?

-Bird
Bird
 
Posts: 623
Joined: Tue Nov 22, 2011 1:27 am

Re: Booleans

Postby Julio Jerez » Wed Jun 27, 2012 8:03 am

it is function NewtonMeshGetFaceMaterial
I added to teh face loop in teh function, I do not knwo how to apply it ti the lighwave sdk, but it sodu be eassy

Code: Select all
void MakeLightWaveMesh (MeshEditOp* const edit, NewtonMesh* mesh, const char *surfname, const char* const vmapname)
{
   int vertexCount = NewtonMeshGetVertexCount(mesh);
   int vertexStride = NewtonMeshGetVertexStrideInByte(mesh) / sizeof (dFloat64);
   dFloat64* const vertexList = NewtonMeshGetVertexArray(mesh);

   LWPntID* const pt = new LWPntID[vertexCount];
   for (int i = 0; i < vertexCount; i ++) {
      LWDVector pos;
      pos.x = vertexList[i * vertexStride + 0];
      pos.y = vertexList[i * vertexStride + 1];
      pos.z = vertexList[i * vertexStride + 2];
      pt[ i ] = edit->addPoint( edit->state, pos );
   }

   int pointCount = NewtonMeshGetPointCount(mesh);
   int pointStride = NewtonMeshGetPointStrideInByte(mesh) / sizeof (dFloat64);
   dFloat64* const uvList = NewtonMeshGetUV0Array(mesh);

   int* const uvMask = new int[pointCount];
   memset (uvMask, 0, sizeof (int) * pointCount);
   for (void* face = NewtonMeshGetFirstFace (mesh); face; face = NewtonMeshGetNextFace (mesh, face)) {
      if (!NewtonMeshIsFaceOpen (mesh, face)) {
         int faceVertexIndices[256];
         int facePointIndices[256];

         int vertexCount = NewtonMeshGetFaceIndexCount (mesh, face);
         NewtonMeshGetFaceIndices (mesh, face, faceVertexIndices);
         LWPntID vt[256];
         for (int j = 0; j < vertexCount; j++ ) {
            vt[j] = pt[faceVertexIndices[j]];
         }
         LWPolID pol = edit->addFace( edit->state, surfname, vertexCount, vt );

         // some where here you nee to use the materil;
         int materialID = NewtonMeshGetFaceMaterial (mesh, face);


         NewtonMeshGetFacePointIndices (mesh, face, facePointIndices);
         for (int j = 0; j < vertexCount; j++ ) {
            int index = facePointIndices[j];
            if (!uvMask[index]) {
               float uv[2];
               uvMask[index] = 1;
               uv[0] = float (uvList[pointStride * index + 0]);
               uv[1] = float (uvList[pointStride * index + 1]);
               edit->pntVPMap( edit->state, pt[faceVertexIndices[j]], pol, LWVMAP_TXUV, vmapname, 2, uv);
            }
         }
      }
   }

   delete[] uvMask;
   delete[] pt;
}


also I completed the clean up of the bollean now, it should remove all T joints, and unsused vertices. Sinc to svn


also if after the call you call the bollean operator you call NewtonMeshPolygonize(mesh);
then you should get a bery clean mesh, but that is optional teh bollean doe no do that.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Booleans

Postby Bird » Wed Jun 27, 2012 8:27 am

also I completed the clean up of the bollean now, it should remove all T joints, and unsused vertices. Sinc to svn

I just tried the new version and it works perfectly!

I'll try to test a textured mesh today. Thanks for the help!

-Bird
Bird
 
Posts: 623
Joined: Tue Nov 22, 2011 1:27 am

Re: Booleans

Postby Julio Jerez » Wed Jun 27, 2012 8:54 am

remember I still has not write the edge vertex clip.
if a mesh edge happen to inteset a vertex eactly on teh oteh mesh teh algorith will fail. those case are rare, but thet happens.
I am writing that function now.
hopefully I get finshi it today or tonight and then is moving to simple voronoi destruction again.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Booleans

Postby Bird » Wed Jun 27, 2012 11:20 am

remember I still has not write the edge vertex clip.
if a mesh edge happen to inteset a vertex eactly on teh oteh mesh teh algorith will fail. those case are rare, but thet happens.
I am writing that function now.
hopefully I get finshi it today or tonight and then is moving to simple voronoi destruction again.


Ok, but today in the latest svn version I am very often hitting this assert on line 1151 of dgMeshEffect5.cpp doing tests that worked fine in previous versions, like a low-res ball intersecting a box
_ASSERTE (vertexMapA.Find(edgeA->m_incidentVertex));

I seem to hit it on anything but the simplest meshes.

-Bird
Bird
 
Posts: 623
Joined: Tue Nov 22, 2011 1:27 am

Re: Booleans

Postby Julio Jerez » Wed Jun 27, 2012 11:33 am

I made changes an the line does no match anymore
can you sync again and tell the line of that the assert happens?

I am working pon teh vertexRay intesection, I am guessing you are getting that part.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Booleans

Postby Bird » Wed Jun 27, 2012 12:21 pm

Julio Jerez wrote:I made changes an the line does no match anymore
can you sync again and tell the line of that the assert happens?

I am working pon teh vertexRay intesection, I am guessing you are getting that part.

It's now on line 1152 of dgMeshEffect5.cpp in the latest svn.

-Bird
Bird
 
Posts: 623
Joined: Tue Nov 22, 2011 1:27 am

Re: Booleans

Postby Bird » Wed Jun 27, 2012 12:39 pm

It's now on line 1152 of dgMeshEffect5.cpp in the latest svn.


I'm actually hitting the asserts at line 1151 and 1152 in the latest svn 2243
Code: Select all
_ASSERTE (vertexMapA.Find(edgeA->m_incidentVertex));
_ASSERTE (vertexMapA.Find(edgeA->m_twin->m_incidentVertex));


and sometimes I hit this one on line 167 of dgMeshEffects1.cpp
Code: Select all
_ASSERTE (node->m_left);


-Bird
Bird
 
Posts: 623
Joined: Tue Nov 22, 2011 1:27 am

Re: Booleans

Postby Julio Jerez » Wed Jun 27, 2012 1:36 pm

that is right, I added and optimization that do no requires that so keep teh clipp edge aoprun, byt it requires to change that function.
I will fix that tonight.
please do no do anything until I check in again.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Booleans

Postby Bird » Mon Jul 02, 2012 6:50 am

Julio Jerez wrote:that is right, I added and optimization that do no requires that so keep teh clipp edge aoprun, byt it requires to change that function.
I will fix that tonight.
please do no do anything until I check in again.

I'm not sure if you're ready for testing yet but I tried anyway with the latest svn 2253 :) I tried a simple test using Boolean Difference on 2 cubes and Newton hangs in an infinite loop in CalculateEdgeVertexIntersetions () in dgMeshEffect5.cpp. The hang occurs in the "while" loop that begins on line 745.

-Bird
Bird
 
Posts: 623
Joined: Tue Nov 22, 2011 1:27 am

PreviousNext

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 10 guests