Booleans

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Re: Booleans

Postby Julio Jerez » Mon Jul 02, 2012 9:54 am

yes I noticed that yesterday, I am debuging it.
doe it happen every time for you?


I am adding a unttility funtion to save NewtonMesh in OFF format so that I can save inetmediate phase of teh prossess to see where teh Bug Happens.
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 10:09 am

Julio Jerez wrote:yes I noticed that yesterday, I am debuging it.
doe it happen every time for you?


Yes it happens every time with cubes or other more complex meshes. However, if I use 2 tetrahedron meshes, then there's no problem.

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

Re: Booleans

Postby Bird » Mon Jul 02, 2012 10:25 am

can you try a textured mesh to see if thatorks

I tried with 2 tetrahedrons and it's not working correctly yet ... although I wouldn't be surprised if this was a problem on my side as finding the uv values per polygon per vertex is surprisingly difficult in LW.

In the video you can see that the boolean intersect looks ok but the boolean difference messes up the uv values
http://www.hurleyworks.com/media/flash/BooleanUV/BooleanUV.html

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

Re: Booleans

Postby Julio Jerez » Mon Jul 02, 2012 10:33 am

I do not thonk it is a bug in your side, not yet.

I just impemenet eh code, and this si no a trivial piece of code. It nee to be debugget.

Ther are tow problems. teh first oen in the infiniot loop when cliiping edge/edge and edge/vertex
the secund in the flood fill to detrmine what face is in what side.

These are hard to debug because o fteh vilume of the data, for that I am adding a debug tool to teh NewtonMesh so that I can see what is going on during teh inetmeduate phase of the hlagorithm,
It jsu nee to e debugged.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Booleans

Postby Julio Jerez » Mon Jul 02, 2012 10:46 am

does lightwave have plugin for loading OFF files. If is does, here is an example of what I am doing to debu the code..

Iam and doing teh voronoid destruction, because it si a way to make lot and lot of boolean intersection.
I am using as Box and soem random vetercess , and most o fteh boolen are fine ecpet for one.

nwo after added teh code I am saving the intemadian values and these are the tow meshes that teh bollem intersection funtion falke to make

box
    OFF
    8 6 0
    0.250000 -0.250000 0.250000
    0.250000 -0.250000 -0.250000
    -0.250000 -0.250000 0.250000
    -0.250000 -0.250000 -0.250000
    -0.250000 0.250000 0.250000
    0.250000 0.250000 0.250000
    0.250000 0.250000 -0.250000
    -0.250000 0.250000 -0.250000
    4 0 1 6 5
    4 0 2 3 1
    4 0 5 4 2
    4 1 3 7 6
    4 2 4 7 3
    4 4 5 6 7

voronoi generated convex
    OFF
    10 16 0
    2.543240 -0.093750 2.480740
    -0.031250 -3.254637 -1.580443
    -0.062500 -0.093750 0.031250
    -1.106966 -3.258398 -1.044466
    2.933710 -2.007890 -0.957070
    -0.062500 -0.125000 0.000000
    -1.611693 -0.093750 3.129637
    0.093750 -0.093750 0.031250
    -0.031250 -0.156250 -0.031250
    0.156250 -0.156250 -0.031250
    3 0 2 6
    3 0 3 4
    3 0 4 7
    3 0 6 3
    3 0 7 2
    3 1 3 8
    3 1 4 3
    3 1 8 4
    3 2 3 6
    3 2 5 3
    3 2 7 5
    3 3 5 8
    3 4 8 9
    3 4 9 7
    3 5 7 8
    3 7 9 8

what Is good abpu tehi snew funtion is that it is very veryu eassy to provide feed back
you onel; need to call function
void NewtonMeshSaveOFF(const NewtonMesh* const mesh, const char* const filename)
NewtonMesh* NewtonMeshLoadOFF(const NewtonWorld* const newtonWorld, const char* const filename)

to save and load NetwonMesh without going over to much code complexity

Like I said if lightwave can load OFF files, see if you can load thsoe two mesh I save.
mean while I am debuging these bugs.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Booleans

Postby Julio Jerez » Mon Jul 02, 2012 10:55 am

these are teh same tow meshe aft eteh boolean interstion are executed

Box
    OFF
    23 33 0
    0.250000 -0.250000 0.250000
    0.250000 -0.250000 -0.250000
    -0.250000 -0.250000 0.250000
    -0.250000 -0.250000 -0.250000
    -0.250000 0.250000 0.250000
    0.250000 0.250000 0.250000
    0.250000 0.250000 -0.250000
    -0.250000 0.250000 -0.250000
    0.250000 -0.250000 -0.078125
    -0.250000 -0.250000 0.250000
    0.250000 -0.093750 0.250000
    0.184158 -0.093750 0.250000
    0.250000 -0.093750 0.187500
    -0.031250 -0.250000 -0.078125
    -0.113565 -0.250000 -0.022870
    -0.171875 -0.093750 0.250000
    -0.104167 -0.250000 -0.041667
    -0.065044 -0.250000 -0.061228
    0.250000 -0.200160 -0.025319
    0.250000 -0.218750 -0.062500
    -0.250000 -0.250000 0.250000
    -0.250000 -0.250000 0.250000
    0.128362 -0.250000 -0.078125
    3 0 8 12
    3 0 9 13
    3 0 10 11
    3 0 11 9
    3 0 12 10
    4 0 13 22 8
    4 1 3 7 6
    3 1 6 12
    4 1 8 22 13
    3 1 12 18
    3 1 13 3
    3 1 18 19
    3 1 19 8
    3 2 3 14
    4 2 4 7 3
    4 2 9 11 20
    4 2 14 13 21
    3 2 15 4
    4 2 20 11 15
    4 2 21 13 9
    3 3 13 16
    3 3 16 14
    4 4 5 6 7
    3 4 11 5
    3 4 15 11
    3 5 10 12
    3 5 11 10
    3 5 12 6
    3 8 18 12
    3 8 19 18
    3 13 14 17
    3 13 17 16
    3 14 16 17

convex
    OFF
    25 28 0
    1.318495 -0.093750 1.255995
    -0.031250 -1.705443 -0.805847
    -0.062500 -0.093750 0.031250
    -0.584733 -1.691699 -0.522233
    1.544980 -1.082070 -0.494160
    -0.062500 -0.125000 0.000000
    -0.837097 -0.093750 1.580443
    0.093750 -0.093750 0.031250
    -0.031250 -0.156250 -0.031250
    0.156250 -0.156250 -0.031250
    0.250000 -0.250000 -0.078125
    -0.250000 -0.250000 0.250000
    0.250000 -0.093750 0.250000
    0.184158 -0.093750 0.250000
    0.250000 -0.093750 0.187500
    -0.031250 -0.250000 -0.078125
    -0.113565 -0.250000 -0.022870
    -0.171875 -0.093750 0.250000
    -0.104167 -0.250000 -0.041667
    -0.065044 -0.250000 -0.061228
    0.250000 -0.200160 -0.025319
    0.250000 -0.218750 -0.062500
    -0.250000 -0.250000 0.250000
    -0.250000 -0.250000 0.250000
    0.128362 -0.250000 -0.078125
    3 0 3 4
    5 0 4 20 7 14
    3 0 6 3
    4 0 12 2 13
    5 0 13 2 17 6
    4 0 14 7 12
    5 1 3 19 8 15
    3 1 4 3
    5 1 15 8 24 4
    5 2 5 18 3 16
    3 2 7 5
    3 2 11 22
    3 2 12 7
    3 2 16 23
    3 2 22 17
    3 2 23 11
    3 3 6 11
    3 3 11 23
    5 3 18 5 8 19
    3 3 23 16
    4 4 10 9 21
    5 4 21 9 7 20
    4 4 24 8 10
    3 5 7 8
    3 6 17 22
    3 6 22 11
    3 7 9 8
    3 8 9 10


now I can load them in a modeler and see if the point match, or if teh is any anomally.
later I will add a face color so that I can see what when on afte teh partions partition, I thonk this will allow me to debug the whole feature more quickly.
But now I am late for work.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Booleans

Postby Julio Jerez » Mon Jul 02, 2012 11:01 am

looking at the tow meshes it looks liek the is a special case it seems tha a coren of the Box touches a face i\on teh convex, and it may be that teh algorith doe no how to handle that.
This is somethong I have to write.


can you save the to meshe that make the algorithn go into an infinite loop? maybe that is a different Bug and I can debug that first.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Booleans

Postby Julio Jerez » Mon Jul 02, 2012 11:06 am

Bird wrote:although I wouldn't be surprised if this was a problem on my side as finding the uv values per polygon per vertex is surprisingly difficult in LW.
-Bird


why? I though it was well defined. It is in fact very much like teh Netwon Mesh work. althogh It seem the Newton Mesh is a little more flexible for some things
I like abput lightwave is that is use channel whiel I use flat vertex.
I was considering to chneg teh flat format to channet as well, but that will be when I am adding shader and oteh things. for nwo a falt vertex with two UV seem sufficient.

but I do not think the lighwave format is any particular more difficult that other formats.
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 11:23 am

Julio Jerez wrote:looking at the tow meshes it looks liek the is a special case it seems tha a coren of the Box touches a face i\on teh convex, and it may be that teh algorith doe no how to handle that.
This is somethong I have to write.


can you save the to meshe that make the algorithn go into an infinite loop? maybe that is a different Bug and I can debug that first.


The infinite loop problem disappeared in the new versions you published this morning, sorry I don't know exactly which version it was. The version latest svn 2260 will not compile cleanly.
Bird
 
Posts: 623
Joined: Tue Nov 22, 2011 1:27 am

Re: Booleans

Postby Julio Jerez » Mon Jul 02, 2012 11:34 am

the infinite loop may have desapered however that is no guarateee that it will no happens again.

The problem is that I impelmnet teh algorith using naive arithmnetic using tolreance, however that will certally fail at some point.
It iwll work in must case but it will fail in others.

after I have the alforithm all debuget, I have to remap all arithemetic operations with the SmallDetrminat Class, that class that producet robust arithemetic with tracking of errors rouding errors.
the reason I do not do it the first time is that mapping all operations to vector and matrix makes the code hard to debug, therefore I only do it on clean and debuged code.
That is the code I use for some of the hard and very numerical error prompt function in the dcore library, stuff like 3d and 4d convex hulls, convex partition, delanay triangulation, and few other stuff.
after I add that, then it will be perfect in all cases, for now we can leave wit the occational errors.
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 11:47 am

why? I though it was well defined. It is in fact very much like teh Netwon Mesh work. althogh It seem the Newton Mesh is a little more flexible for some things
I like abput lightwave is that is use channel whiel I use flat vertex.
I was considering to chneg teh flat format to channet as well, but that will be when I am adding shader and oteh things. for nwo a falt vertex with two UV seem sufficient.

It's easy to find the uv data for each vertex in a mesh but it's not straight forward(AFAIK) to know which polygon has the uv applied unless it's a LW discontinuous uv.

My project really needs to support the other LW vertex map types like Weight(scalar), Morph(x,y,z), and Color( r,g,b and r,g,b,a ). Do you think you will be able to support those in Newton now or will it have to wait until you switch to channels if you decide to?

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

Re: Booleans

Postby Bird » Mon Jul 02, 2012 11:51 am

does lightwave have plugin for loading OFF files. If is does, here is an example of what I am doing to debu the code..


I couldn't find one. It looks like such a simple format maybe a hack together a quick OFF import/export tool.

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

Re: Booleans

Postby Julio Jerez » Mon Jul 02, 2012 11:54 am

that is what I was saying before, That some tiem I will replace teh flat vertex attibute in teh NewtonMesh to channel.

when I support channel base attribute that it does no matter all vert funtionality cna be supperted.

basically a channe is a lien of infromation.
say a mesh has one UV, and vetex collor, vertex weights, vete normal, bealreal normal, user define chaneel dat for shader, you name anythong will be supported.

I will need that when I move to the soft body, and also for skin meshes. also I will add a full Nurb to the dMesh so ther we will also nee user defined channel data, for the rational part of the Nurbs.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Booleans

Postby Julio Jerez » Mon Jul 02, 2012 11:57 am

Bird wrote:I couldn't find one. It looks like such a simple format maybe a hack together a quick OFF import/export tool.-Bird


yes that will be very useful for debugging. there is OFF public domain code floating around, but it is dreadfull, I just added my own. you can use as a getting start point
Code: Select all
dgMeshEffect::dgMeshEffect(dgMemoryAllocator* const allocator, const char* const fileName)
   :dgPolyhedra (allocator)
{
   class ParceOFF
   {
      public:
      enum Token
      {
         m_off,   
         m_value,
         m_end,
      };

      ParceOFF (FILE* const file)
         :m_file (file)
      {
      }

      Token GetToken(char* const buffer) const
      {
         while (!feof (m_file)) {
            fscanf (m_file, "%s", buffer);
            if (buffer[0] == '#') {
               SkipLine();
            } else {
               if (!stricmp (buffer, "OFF")) {
                  return m_off;
               }
               return m_value;
            }
         }
         return m_end;
      }

      void SkipLine() const
      {
         char tmp[1024];
         fgets (tmp, sizeof (tmp), m_file);
      }

      dgInt32 GetInteger() const
      {
         char buffer[1024];
         Token token = GetToken(buffer);
         _ASSERTE (token == m_value);
         return atoi (buffer);   
      }

      dgFloat64 GetFloat() const
      {
         char buffer[1024];
         Token token = GetToken(buffer);
         _ASSERTE (token == m_value);
         return atof (buffer);   
      }

      FILE* m_file;
   };

   Init();
   FILE* const file = fopen (fileName, "rb");
   if (file) {
      ParceOFF parcel (file);

      dgInt32 vertexCount = 0;
      dgInt32 faceCount = 0;
      dgInt32 edgeCount = 0;

      char buffer[1024];
      bool stillData = true;
      while (stillData) {
         ParceOFF::Token token = parcel.GetToken(buffer);
         switch (token)
         {
            case ParceOFF::m_off:
            {
               vertexCount = parcel.GetInteger();
               faceCount = parcel.GetInteger();
               edgeCount = parcel.GetInteger();
               parcel.SkipLine();

               dgVertexAtribute attribute;
               memset (&attribute, 0, sizeof (dgVertexAtribute));
               attribute.m_normal_y = 1.0f;
               AddAtribute(attribute);
               for (dgInt32 i = 0; i < vertexCount; i ++) {
                  dgBigVector point;
                  point.m_x = parcel.GetFloat();
                  point.m_y = parcel.GetFloat();
                  point.m_z = parcel.GetFloat();
                  point.m_w = 0.0;
                  parcel.SkipLine();
                  AddVertex(point);
               }

               BeginFace();
               for (dgInt32 i = 0; i < faceCount; i ++) {
                  dgInt32 face[256];
                  dgInt32 faceVertexCount = parcel.GetInteger();
                  for (dgInt32 j = 0; j < faceVertexCount; j ++) {
                     face[j] = parcel.GetInteger();
                  }
                  parcel.SkipLine();
                  AddFace(faceVertexCount, face);
               }
               EndFace();
               stillData = false;
               break;
            }
               
            default:;
         }
      }

      fclose (file);
   }
}
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Booleans

Postby pHySiQuE » Mon Jul 02, 2012 1:00 pm

If you can calculate one binormal and tangent plane for the face, it's easy to calculate new texcoords for any new vertex on that face.
pHySiQuE
 
Posts: 608
Joined: Fri Sep 02, 2011 9:54 pm

PreviousNext

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 21 guests

cron