POV-Ray : Newsgroups : povray.general : mesh in povray3.1/3.5 : Re: mesh in povray3.1/3.5 Server Time
20 Nov 2024 12:41:58 EST (-0500)
  Re: mesh in povray3.1/3.5  
From: ingo
Date: 5 Sep 2001 06:44:26
Message: <Xns9113819AFEC8Cseed7@povray.org>
in news:3B95089F.C85B19CE@gmx.de Ursula wrote:

> I try 3dwin to convert raw-files to pov-meshes, but I do not
> understand the result,

As my answer wasn't clear and there still is need for a piece on mesh2 
for the docs, here is an attempt:

Mesh2

The mesh2 is a representation of a mesh that is much more like the
internal mesh representation than the standard mesh. As a result it
parses faster and it file size is smaller.

<0,0.5,0>___________<1,0.5,0>
       |      /|\   |
       |    /  | \  |
       |  /    |  \ |
       |/      |   \|
       |-------|----|
<0,0,0>   <0.5,0,0>  <1,0,0>
 

We will write the mesh sketched above as a mesh2 object.
The mesh is made of 4 triangles, each with 3 vertices, many of 
these vertices are shared among the triangles. This can be
used to optimise the mesh. First we will do it straight forward.

In mesh2 all the vertices are listed in a list named vertex_vectors{}.
A second list, face_indices{}, tells us how to put together three 
rtices to create one triangle, by pointing to the index number of a 
vertex. All lists in mesh2 are zero based, the number of the first 
vertex is 0. The very first item in a list is the amount of vertices, 
normals or uv_vectors it contains.

Lets go through the mesh above, we do it counter clockwise. The total 
amount of vertices is 12 (4 triangle * 3 vertices)

mesh2 {
   vertex_vectors {
      12,
      ...


Now we can add the coordinates of the vertices of the first triangle:

mesh2 {
   vertex_vectors {
      12, 
      <0,0,0>, <0.5,0,0>, <0.5,0.5,0>
      ..

Next step is to tell the mesh how the triangle should be created:

mesh2 {
   vertex_vectors {
      12, 
      <0,0,0>, <0.5,0,0>, <0.5,0.5,0>
      ...
   }
   face_indices {
      4, 
      <0,1,2> 
      ...

There will be a total of 4 face_indices (4 triangles). The first
point of the first face points to the first vertex_vector (0: <0,0,0>), 
the second to the second (1: <0.5,0,0>), etc...

The complete mesh:

mesh2 {
   vertex_vectors {
      12, 
      <0,0,0>,     <0.5,0,0>, <0.5,0.5,0>
      <0.5,0,0>,   <1,0,0>  , <0.5,0.5,0>
      <1,0,0>,     <1,0.5,0>, <0.5,0.5,0>
      <0.5,0.5,0>, <0,0.5,0>, <0,0,0>
   }
   face_indices {
      4, 
      <0,1,2>
      <3,4,5>
      <6,7,8>
      <9,10,11>
   }
   pigment {rgb 1}
}

As mentioned earlier, many vertices are shared by triangles. We can 
optimise the mesh by removing all duplicate vertices but one. In the 
example this reduces the amount from 12 to 6

mesh2 {
   vertex_vectors {
      6, 
      <0,0,0>,  <0.5,0,0>, <0.5,0.5,0>
      /*as 1*/  <1,0,0>  , /*as 2*/
      /*as 3*/  <1,0.5,0>, /*as 2*/
      /*as 2*/  <0,0.5,0>, /*as 0*/
   }
   ...

Next step is to rebuild the list of face_indices, as they now point 
to indices in the vertex_vector{} list that don't exist anymore.

mesh2 {
   vertex_vectors {
      6, 
      <0,0,0>,  <0.5,0,0>, <0.5,0.5,0>
      /*as 1*/  <1,0,0>  , /*as 2*/
      /*as 3*/  <1,0.5,0>, /*as 2*/
      /*as 2*/  <0,0.5,0>, /*as 0*/
   }
   face_indices {
      4, 
      <0,1,2>
      <1,3,2>
      <3,4,2>
      <2,5,0>
   }
   pigment {rgb 1}
}


In case we want a smooth mesh, the same steps we did also apply to the 
normals in a mesh. For each vertex there is a normal vector listed in 
normal_vectors{}. If the number of normals equals the number of 
vertices then the normal_indices{} list is optional and the indexes 
from the face_indices{} list are used instead.

mesh2 {
   vertex_vectors {
      6, 
      <0,0,0>,  <0.5,0,0>, <0.5,0.5,0>,
       <1,0,0>, <1,0.5,0>, <0,0.5,0>
   }
   normal_vectors {
      6,
      <-1,-1,0>, <0,-1,0>, <0,0,1>
      /*as 1*/   <1,-1,0>, /*as 2*/
      /*as 3*/   <1,1,0>,  /*as 2*/
      /*as 2*/   <-1,1,0>  /*as 0*/
   }
   face_indices {
      4, 
      <0,1,2>
      <1,3,2>
      <3,4,2>
      <2,5,0>
   }
   pigment {rgb 1}
}

When a mesh has a mix of smooth and flat triangles a list of 
normal_indices{} has to be added, where each entry points to what 
vertices a normal should be applied.

mesh2 {
   vertex_vectors {
      6, 
      <0,0,0>,  <0.5,0,0>, <0.5,0.5,0>,
       <1,0,0>, <1,0.5,0>, <0,0.5,0>
   }
   normal_vectors {
      6,
      <-1,-1,0>, <0,-1,0>, <0,0,1>
       <1,-1,0>, <1,1,0>, <-1,1,0> 
   }
   face_indices {
      4, 
      <0,1,2>
      <1,3,2>
      <3,4,2>
      <2,5,0>
   }
   normal_indices {
      2, 
      <1,3,2>
      <3,4,2>
   }
   pigment {rgb 1}
}


Ingo

-- 
Photography: http://members.home.nl/ingoogni/
Pov-Ray    : http://members.home.nl/seed7/


Post a reply to this message

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