POV-Ray : Newsgroups : povray.general : Reading mesh2 data from file Server Time
29 Mar 2024 05:41:58 EDT (-0400)
  Reading mesh2 data from file (Message 1 to 10 of 11)  
Goto Latest 10 Messages Next 1 Messages >>>
From: Kima
Subject: Reading mesh2 data from file
Date: 3 Jul 2021 02:00:01
Message: <web.60dffc3036463e86e75ac487d427f3e5@news.povray.org>
Since a mesh is made of thousands or millions of triangles, it is tidy to keep
the data in separate files and include them in the .pov file whenever necessary.
I mean something like

#declare Vertices = read from vertices.txt;
#declare Faces = read from faces.txt;

mesh2 {
   vertex_vectors {
      N_vertices,
      Vertices
   }
   face_indices {
      N_faces,
      Faces
   }
}


fopen directive of POV-Ray reads the file into variables,
#read (FILE_HANDLE_IDENTIFIER,MyString,MyFloat,MyVect)

I don't know if it works as vertices and faces are thousands/millions of
vectors.


Post a reply to this message

From: jr
Subject: Re: Reading mesh2 data from file
Date: 3 Jul 2021 02:35:00
Message: <web.60e004a3c54a2bf05e0fed26cde94f1@news.povray.org>
hi,

"Kima" <nomail@nomail> wrote:
> Since a mesh is made of thousands or millions of triangles, it is tidy to keep
> the data in separate files and include them in the .pov file whenever necessary.
> I mean something like
>
> #declare Vertices = read from vertices.txt;
> #declare Faces = read from faces.txt;
> ...
> fopen directive of POV-Ray reads the file into variables,
> #read (FILE_HANDLE_IDENTIFIER,MyString,MyFloat,MyVect)
>
> I don't know if it works as vertices and faces are thousands/millions of
> vectors.

storing vertex and face coords/points in separate files etc should/would work.
however, have you considered only doing "the work" once?  that is, create an
..inc file from your '*.txt' files instead and simply use that from then on?
have attached an example.


regards, jr.


Post a reply to this message


Attachments:
Download 'cube2_mesh.inc.txt' (1 KB)

From: clipka
Subject: Re: Reading mesh2 data from file
Date: 3 Jul 2021 02:57:09
Message: <60e00a45$1@news.povray.org>
Am 03.07.2021 um 07:57 schrieb Kima:
> Since a mesh is made of thousands or millions of triangles, it is tidy to keep
> the data in separate files and include them in the .pov file whenever necessary.

If you really want to keep the vertices in a different file than the 
faces, what you could do is use:

     mesh2 {
       vertex_vectors {
         #include "vertices.inc"
       }
       face_indices {
         #include "faces.inc"
       }
     }

making sure to store the vertices and faces, respectively, in the format 
expected by POV-Ray, and putting the number of entries at the top of 
each file.

Meshes tend to take a long time to parse, simply due to the sheer number 
of data points, and every overhead you add to the parsing of that data - 
every single processing step - will only make matters worse. Far, far worse.


That said, I would argue however that it is neater to have all the data 
for one mesh in one file. It is customary to put the entire `mesh2` into 
a single include file, preceded by a `#declare`, like so:

     #declare MyThingumajig = mesh2 {
       ...
     }

In your main scene file, you then use:

     #include "my_thingumajig.inc"
     object { MyThingumajig }


(As an exception, if you are rendering an animation of a mesh that 
changes shape, it might make sense to place vertex and normal vectors in 
one file and the face indices and uv vectors in another, to avoid 
duplicating data, as typically you'll want different vertex and normal 
vectors for each frame but the same face indices and uv vectors for all 
frames.)


Post a reply to this message

From: Kima
Subject: Re: Reading mesh2 data from file
Date: 3 Jul 2021 16:10:00
Message: <web.60e0c2f4c54a2bf0e75ac487d427f3e5@news.povray.org>
"jr" <cre### [at] gmailcom> wrote:
> hi,
>
> "Kima" <nomail@nomail> wrote:
> > Since a mesh is made of thousands or millions of triangles, it is tidy to keep
> > the data in separate files and include them in the .pov file whenever necessary.
> > I mean something like
> >
> > #declare Vertices = read from vertices.txt;
> > #declare Faces = read from faces.txt;
> > ...
> > fopen directive of POV-Ray reads the file into variables,
> > #read (FILE_HANDLE_IDENTIFIER,MyString,MyFloat,MyVect)
> >
> > I don't know if it works as vertices and faces are thousands/millions of
> > vectors.
>
> storing vertex and face coords/points in separate files etc should/would work.
> however, have you considered only doing "the work" once?  that is, create an
> ..inc file from your '*.txt' files instead and simply use that from then on?
> have attached an example.
>
>
> regards, jr.

I admit it is odd. I create the vertices and faces by a script in C. I save the
vertex and face vectors within loops directly into files by fprintf. Then, I get
the numbers at the end of the loops. AT  this stage, I cannot append the numbers
at the beginning of the vectors saved into files.

Therefore, my output is two files and the corresponding numbers.


Post a reply to this message

From: Kima
Subject: Re: Reading mesh2 data from file
Date: 3 Jul 2021 16:10:00
Message: <web.60e0c335c54a2bf0e75ac487d427f3e5@news.povray.org>
clipka <ano### [at] anonymousorg> wrote:
> Am 03.07.2021 um 07:57 schrieb Kima:
> > Since a mesh is made of thousands or millions of triangles, it is tidy to keep
> > the data in separate files and include them in the .pov file whenever necessary.
>
> If you really want to keep the vertices in a different file than the
> faces, what you could do is use:
>
>      mesh2 {
>        vertex_vectors {
>          #include "vertices.inc"
>        }
>        face_indices {
>          #include "faces.inc"
>        }
>      }
>
> making sure to store the vertices and faces, respectively, in the format
> expected by POV-Ray, and putting the number of entries at the top of
> each file.
>
> Meshes tend to take a long time to parse, simply due to the sheer number
> of data points, and every overhead you add to the parsing of that data -
> every single processing step - will only make matters worse. Far, far worse.
>
>
> That said, I would argue however that it is neater to have all the data
> for one mesh in one file. It is customary to put the entire `mesh2` into
> a single include file, preceded by a `#declare`, like so:
>
>      #declare MyThingumajig = mesh2 {
>        ...
>      }
>
> In your main scene file, you then use:
>
>      #include "my_thingumajig.inc"
>      object { MyThingumajig }
>
>
> (As an exception, if you are rendering an animation of a mesh that
> changes shape, it might make sense to place vertex and normal vectors in
> one file and the face indices and uv vectors in another, to avoid
> duplicating data, as typically you'll want different vertex and normal
> vectors for each frame but the same face indices and uv vectors for all
> frames.)

#include "vertices.inc" trick works like a charm. So silly of me that forgot
#include can do the job. I agree we should minimise any unnecessary process, but
I think reading two files (perhaps three, adding normals) is not a significant
overhead.


Post a reply to this message

From: clipka
Subject: Re: Reading mesh2 data from file
Date: 3 Jul 2021 20:23:10
Message: <60e0ff6e$1@news.povray.org>
Am 03.07.2021 um 22:06 schrieb Kima:

> #include "vertices.inc" trick works like a charm. So silly of me that forgot
> #include can do the job. I agree we should minimise any unnecessary process, but
> I think reading two files (perhaps three, adding normals) is not a significant
> overhead.

Given the constraints of your process to create the data, it seems like 
a reasonable approach. Given typical mesh sizes, the overheard of 
opening two additional files (or even up to four, with normals and UV 
vectors) should indeed be benign compared to the overhead of actually 
parsing the data.


Post a reply to this message

From: ingo
Subject: Re: Reading mesh2 data from file
Date: 4 Jul 2021 03:27:19
Message: <XnsAD5D602EDC952seed7@news.povray.org>
You have a look at meshmaker.inc in the \include folder. When mesh are 
generated all different parts, vertices, normals, uv-vectors are kept in 
different arrays. The there is a separate macro to assemble all data to a 
mesh. There are also macro's to write and read mesh data as an include 
file.
You can write the seperate data to a file and use the BuildWriteMesh2 to 
build the actual mesh2

Ingo

-- 
https://ingoogni.nl


Post a reply to this message

From: ingo
Subject: Re: Reading mesh2 data from file
Date: 4 Jul 2021 03:55:41
Message: <XnsAD5D64FFC2275seed7@news.povray.org>
in news:XnsAD5D602EDC952seed7@news.povray.org ingo wrote:

> There are also macro's to write and read mesh data as an include 
> file.

Should have added, if you use the macros you can write the mesh to an 
*.arr file. Then the data is written as separate arrays for vertex, normal 
etc. You can also write to *.obj files, but not read them with POV-Ray.

-- 
https://ingoogni.nl


Post a reply to this message

From: jr
Subject: Re: Reading mesh2 data from file
Date: 4 Jul 2021 05:25:00
Message: <web.60e17d41c54a2bf05e0fed26cde94f1@news.povray.org>
hi,

"Kima" <nomail@nomail> wrote:
> ...
> > > I mean something like
> > > ...

> > storing vertex and face coords/points in separate files etc should/would work.
> > however, have you considered only doing "the work" once?  that is, create an
> > ..inc file from your '*.txt' files instead and simply use that from then on?
> > have attached an example.
> >
> >
> > regards, jr.

> I admit it is odd. I create the vertices and faces by a script in C. I save the
> vertex and face vectors within loops directly into files by fprintf. Then, I get
> the numbers at the end of the loops. AT  this stage, I cannot append the numbers
> at the beginning of the vectors saved into files.
>
> Therefore, my output is two files and the corresponding numbers.

odd, yes. :-)  I gather that the "script in C" is your own, so what I do not
understand is, why not keep everything in RAM until all calculations are done,
and do the "fprintf()"s after?  (my own effort too is in C, make use of it if
you wish
<https://news.povray.org/povray.text.scene-files/message/%3Cweb.5e2ec3f92af4d0a48c662f470%40news.povray.org%3E/#%3Cweb.
5e2ec3f92af4d0a48c662f470%40news.povray.org%3E>)


regards, jr.


Post a reply to this message

From: Kima
Subject: Re: Reading mesh2 data from file
Date: 5 Jul 2021 03:50:00
Message: <web.60e2b882c54a2bf0e75ac487d427f3e5@news.povray.org>
"jr" <cre### [at] gmailcom> wrote:

> odd, yes. :-)  I gather that the "script in C" is your own, so what I do not
> understand is, why not keep everything in RAM until all calculations are done,
> and do the "fprintf()"s after?  (my own effort too is in C, make use of it if
> you wish
>
<https://news.povray.org/povray.text.scene-files/message/%3Cweb.5e2ec3f92af4d0a48c662f470%40news.povray.org%3E/#%3Cwe
b.
> 5e2ec3f92af4d0a48c662f470%40news.povray.org%3E>)
>
>
> regards, jr.

Thanks for sharing your script. It's quite sophisticated. Mine is messy :)

For two reasons, I directly use fprintf():

1. The mesh may get large, and surely I will have stack overflow. Thus, I have
to allocate the memory dynamically to keep all the data in memory. The memory
footprint is trivial for the modern machines, but I considered to be safer to
directly write them to the files.

2. When saving the data in raw forms (vectors), I can easily create other mesh
formats from the separate files. It is unlikely, as I only use POV-Ray, but it's
not a bad idea to keep the system flexible for future expansion.


Post a reply to this message

Goto Latest 10 Messages Next 1 Messages >>>

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