POV-Ray : Newsgroups : povray.general : mesh to mesh2 conversion Server Time
7 Nov 2024 04:54:08 EST (-0500)
  mesh to mesh2 conversion (Message 1 to 9 of 9)  
From: TinCanMan
Subject: mesh to mesh2 conversion
Date: 23 Apr 2002 10:12:54
Message: <3cc56be6$1@news.povray.org>
1) Does anyone have a program to convert mesh1 to mesh2?
2) Is it worth it to do this conversion (i.e., I have an 8Mb mesh1 object)

I ask this because I was going to attempt to make a converter for myself but
if there exists one already, then I don't need to.

-tgq


Post a reply to this message

From: Warp
Subject: Re: mesh to mesh2 conversion
Date: 23 Apr 2002 11:39:55
Message: <3cc5804b@news.povray.org>
TinCanMan <Tin### [at] hotmailcom> wrote:
> 2) Is it worth it to do this conversion (i.e., I have an 8Mb mesh1 object)

  The advantage of having a mesh2 is a smaller file size and probably a
faster parsing. It does not affect render time or memory usage in any way.

  (Ok, that's not technically true. When parsing a mesh, POV-Ray uses some
temporary data structures which take some memory. However, I think that it
frees these when the parsing of the mesh is done and thus in the rendering
step there is not extra memory needed.)

-- 
#macro N(D)#if(D>99)cylinder{M()#local D=div(D,104);M().5,2pigment{rgb M()}}
N(D)#end#end#macro M()<mod(D,13)-6mod(div(D,13)8)-3,10>#end blob{
N(11117333955)N(4254934330)N(3900569407)N(7382340)N(3358)N(970)}//  - Warp -


Post a reply to this message

From: Ian Shumsky
Subject: Re: mesh to mesh2 conversion
Date: 23 Apr 2002 15:23:35
Message: <3cc5b4b7@news.povray.org>
Hi,

Here is some sample C code I wrote a two years ago - IIRC you pass the file
name containing (a single) mesh on the command line and it writes a mesh2
object to stdout. I think it will need a little work to convert to the
latest mesh2 format, but it could be a good starting point.

If it works for you, let me know! Also, if you have any questions, I'll trya
nd answer them.

Cheers,
Ian.

http://www.outerarm.demon.co.uk/graphics/graphics.html
(About time for a spring clean)




#include <stdio.h>
#include <stdlib.h>

typedef struct _vertex
{
 char x[64];
 char y[64];
 char z[64];
} vertex;

vertex vlist[10000];
int vindex = 0;

main (int argc, char* argv[])
{
 FILE *in_file;
 FILE *out_file;
 char c;
 char string_x[64];
 char string_y[64];
 char string_z[64];
 double x,y,z;
 int i;
 int no_tri;
 vertex temp_vertex;
 int vcount;

 //
 // Open input and output files.
 //

 in_file = fopen (argv[1], "r");

 if (in_file == NULL)
 {
  printf ("ERROR: Unable to open file '%s'\n", argv[1]);
  return -1;
 }

 //
 // Scan input file for vertex vectors and store, removing duplicates.
 // Vertex vectors are in the form <x, y, z>
 //

 no_tri = 0;

 while ((c = getc(in_file)) != EOF)
 {
  if (c == '<')
  {
   //
   // We have found a vertex, so extract the 'x' part.
   //

   i = 0;

   while ((c = getc (in_file)) != ',')
   {
    string_x[i] = c;
    i++;
   }

   string_x[i] = '\0';

   //
   // Now get the 'y' part.
   //

   i = 0;

   while ((c = getc (in_file)) != ',')
   {
    string_y[i] = c;
    i++;
   }

   string_y[i] = '\0';

   //
   // Now get the 'z' part.
   //

   i = 0;

   while ((c = getc (in_file)) != '>')
   {
    string_z[i] = c;
    i++;
   }

   string_z[i] = '\0';

   //
   // increase the count of the number of triangles we have found.
   //

   no_tri++;

   //
   // We now have the x, y and z of the vertex. Convert to a vertex
   // type and check that it is not already in the vertex array. If
   // it is not, add it to the end.
   //

   strcpy (temp_vertex.x, string_x);
   strcpy (temp_vertex.y, string_y);
   strcpy (temp_vertex.z, string_z);

   if (vmatch (temp_vertex) < 0)
   {
    strcpy (vlist[vindex].x, temp_vertex.x);
    strcpy (vlist[vindex].y, temp_vertex.y);
    strcpy (vlist[vindex].z, temp_vertex.z);
    vindex++;
   }
  }

 }

 //
 // Close the input file.
 //

 close (in_file);

 //
 // Write out vertex vectors.
 //

 printf ("mesh2\n");
 printf ("{\n");
 printf ("\tvertex_vectors\n");
 printf ("\t{\n");
 printf ("\t\t%d\n", vindex);

 for (i = 0; i < vindex; i++)
 {
  printf ("\t\t<%s,%s,%s>\n", vlist[i].x, vlist[i].y, vlist[i].z);
 }

 printf ("\t}\n");

 printf ("\tface_indices\n");
 printf ("\t{\n");
 printf ("\t\t%d\n", no_tri / 3);

 //
 // Open input and output files.
 //

 in_file = fopen (argv[1], "r");

 if (in_file == NULL)
 {
  printf ("ERROR: Unable to open file input.txt\n");
  return -1;
 }

 //
 // Scan input file for triangles, find index in vertex list and write
 // out.
 //

 vcount = 0;

 while ((c = getc(in_file)) != EOF)
 {
  if (c == '<')
  {
   //
   // We have found a vertex, so extract the 'x' part.
   //

   i = 0;

   while ((c = getc (in_file)) != ',')
   {
    string_x[i] = c;
    i++;
   }

   string_x[i] = '\0';

   //
   // Now get the 'y' part.
   //

   i = 0;

   while ((c = getc (in_file)) != ',')
   {
    string_y[i] = c;
    i++;
   }

   string_y[i] = '\0';

   //
   // Now get the 'z' part.
   //

   i = 0;

   while ((c = getc (in_file)) != '>')
   {
    string_z[i] = c;
    i++;
   }

   string_z[i] = '\0';

   //
   // We now have the x, y and z of the vertex. Convert to a vertex
   // type and get its index from the array.
   //

   strcpy (temp_vertex.x, string_x);
   strcpy (temp_vertex.y, string_y);
   strcpy (temp_vertex.z, string_z);

   i = vmatch (temp_vertex);

   if (vcount == 0)
   {
    printf ("\t\t<");
   }

   printf ("%d", i);

   vcount++;

   if ((vcount == 1) || (vcount == 2))
   {
    printf (",");
   }
   else
   {
    printf (">\n");
   }

   if (vcount == 3)
   {
    vcount = 0;
   }
  }
 }

 printf ("\t}\n");
 printf ("}\n");

 //
 // Close the files.
 //

 close (in_file);
}

int vmatch (vertex temp_vertex)
{
 int i;

 for (i = 0; i < vindex; i++)
 {
  if ((strcmp (vlist[i].x, temp_vertex.x) == 0) &&
   (strcmp (vlist[i].y, temp_vertex.y) == 0) &&
   (strcmp (vlist[i].z, temp_vertex.z) == 0))
  {
   return i;
  }
 }

 return -1;
}


Post a reply to this message

From: Mike Williams
Subject: Re: mesh to mesh2 conversion
Date: 23 Apr 2002 15:30:53
Message: <3YBGrBAF7ax8EwHH@econym.demon.co.uk>
Wasn't it Warp who wrote:
>TinCanMan <Tin### [at] hotmailcom> wrote:
>> 2) Is it worth it to do this conversion (i.e., I have an 8Mb mesh1 object)
>
>  The advantage of having a mesh2 is a smaller file size and probably a
>faster parsing. It does not affect render time or memory usage in any way.
>
>  (Ok, that's not technically true. When parsing a mesh, POV-Ray uses some
>temporary data structures which take some memory. However, I think that it
>frees these when the parsing of the mesh is done and thus in the rendering
>step there is not extra memory needed.)

It just so happens that the scene I'm currently working on has a fairly
large mesh in it that I can make available in either format. I did a
quick test, and the stats are:-

    Format  Filesize  Parse  Render  Total  Peak
                      Time   Time    Time   Memory

    mesh1   11740 Kb  13s    77s     90s    14.36 Mb

    mesh2    4622 Kb   6s    64s     70s    11.36 Mb


In this particular case, the difference in render time is probably
caused by the fact that there has to be a separate mesh1 object each
time there's a change in texture. In this case there were 144 meshes
(there are only 18 textures, but they change back and forth many times).

Manually hacking the meshes to produce a single mesh1 object and a mesh2
object with the same single simple texture the stats are:-

    Format  Filesize  Parse  Render  Total  Peak
                      Time   Time    Time   Memory

    mesh1   12769 Kb  25s    29s     54s    28.94 Mb

    mesh2    4745 Kb   6s    27s     33s    11.42 Mb

-- 
Mike Williams
Gentleman of Leisure


Post a reply to this message

From: Warp
Subject: Re: mesh to mesh2 conversion
Date: 23 Apr 2002 15:41:57
Message: <3cc5b904@news.povray.org>
Ian Shumsky <ian### [at] outerarmdemoncouk> wrote:
>  char x[64];
>  char y[64];
>  char z[64];

> vertex vlist[10000];

  Buffer overflow warning lights just exploded. ;)

  (This also limits the number of vertices to 10000. Why? In practical meshes
there can be hundreds of thousands of vertex points.)

> int vmatch (vertex temp_vertex)
> {
>  int i;

>  for (i = 0; i < vindex; i++)
>  {
>   if ((strcmp (vlist[i].x, temp_vertex.x) == 0) &&
>    (strcmp (vlist[i].y, temp_vertex.y) == 0) &&
>    (strcmp (vlist[i].z, temp_vertex.z) == 0))
>   {
>    return i;
>   }
>  }

>  return -1;
> }

  No offence, but that's one of the slowest way of doing it.

-- 
#macro M(A,N,D,L)plane{-z,-9pigment{mandel L*9translate N color_map{[0rgb x]
[1rgb 9]}scale<D,D*3D>*1e3}rotate y*A*8}#end M(-3<1.206434.28623>70,7)M(
-1<.7438.1795>1,20)M(1<.77595.13699>30,20)M(3<.75923.07145>80,99)// - Warp -


Post a reply to this message

From: Ian Shumsky
Subject: Re: mesh to mesh2 conversion
Date: 23 Apr 2002 15:59:23
Message: <3cc5bd1b@news.povray.org>
Hi Warp,

Yeah, it is a crap piece of code, but it did the job I needed when I wrote
it. I had some small meshes (Gilles' grass mesh and some random generated
stone shapes) which needed converting and about 10 minutes of spare time,
hence the lack of memory management, doubles, linked lists, binary trees,
etc.

Any self-respecting mesh to mesh2 converter should be able to (efficiently)
handle a large mesh object as well as supporting all the new mesh2
functionality.

Now only if RL didn't get in the way I'd be able to get it sorted by the
morning...

Cheers,
Ian.

http://www.outerarm.demon.co.uk/graphics/graphics.html


Warp <war### [at] tagpovrayorg> wrote in message news:3cc5b904@news.povray.org...
> Ian Shumsky <ian### [at] outerarmdemoncouk> wrote:
> >  char x[64];
> >  char y[64];
> >  char z[64];
>
> > vertex vlist[10000];
>
>   Buffer overflow warning lights just exploded. ;)
>
>   (This also limits the number of vertices to 10000. Why? In practical
meshes
> there can be hundreds of thousands of vertex points.)
>
> > int vmatch (vertex temp_vertex)
> > {
> >  int i;
>
> >  for (i = 0; i < vindex; i++)
> >  {
> >   if ((strcmp (vlist[i].x, temp_vertex.x) == 0) &&
> >    (strcmp (vlist[i].y, temp_vertex.y) == 0) &&
> >    (strcmp (vlist[i].z, temp_vertex.z) == 0))
> >   {
> >    return i;
> >   }
> >  }
>
> >  return -1;
> > }
>
>   No offence, but that's one of the slowest way of doing it.
>
> --
> #macro M(A,N,D,L)plane{-z,-9pigment{mandel L*9translate N color_map{[0rgb
x]
> [1rgb 9]}scale<D,D*3D>*1e3}rotate y*A*8}#end M(-3<1.206434.28623>70,7)M(
> -1<.7438.1795>1,20)M(1<.77595.13699>30,20)M(3<.75923.07145>80,99)// -
Warp -


Post a reply to this message

From: TinCanMan
Subject: Re: mesh to mesh2 conversion
Date: 23 Apr 2002 16:57:25
Message: <3cc5cab5$1@news.povray.org>
> Here is some sample C code I wrote a two years ago - IIRC you pass the
file
> name containing (a single) mesh on the command line and it writes a mesh2


Thanks.  I'll have a look at it.  I have to put visual stuio back on machine
first.  Unfortunately I have never programmed in C yet, only visual basic,
but I can pick up the gist.

-tgq


Post a reply to this message

From: Ian Shumsky
Subject: Re: mesh to mesh2 conversion
Date: 23 Apr 2002 18:42:23
Message: <3cc5e34f@news.povray.org>
Hi,

As Warp has pointed out, the code as it is won't convert your mesh - the
array of mesh points is way too small and the vertices match checking would
take an awfully long time as implemented... But it could act as a start.

Cheers,
Ian.

TinCanMan <Tin### [at] hotmailcom> wrote in message
news:3cc5cab5$1@news.povray.org...
> > Here is some sample C code I wrote a two years ago - IIRC you pass the
> file
> > name containing (a single) mesh on the command line and it writes a
mesh2
>
>
> Thanks.  I'll have a look at it.  I have to put visual stuio back on
machine
> first.  Unfortunately I have never programmed in C yet, only visual basic,
> but I can pick up the gist.
>
> -tgq
>
>


Post a reply to this message

From: Warp
Subject: Re: mesh to mesh2 conversion
Date: 23 Apr 2002 21:01:58
Message: <3cc60405@news.povray.org>
My triangle mesh compressor has an experimental mesh2 exporting option
(I haven't updated it to 3.5, but I think it should work just fine).
  And it should be extremely fast... ;)

  Btw, it's at http://geocities.com/ccolefax/pcm.html

-- 
#macro N(D)#if(D>99)cylinder{M()#local D=div(D,104);M().5,2pigment{rgb M()}}
N(D)#end#end#macro M()<mod(D,13)-6mod(div(D,13)8)-3,10>#end blob{
N(11117333955)N(4254934330)N(3900569407)N(7382340)N(3358)N(970)}//  - Warp -


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.