Difference between revisions of "Reference:Mesh"

From POV-Wiki
Jump to navigation Jump to search
m (1 revision: underscore link repair)
m (3.7.1 updates)
Line 12: Line 12:
 
{{#indexentry:keyword, triangle}}  
 
{{#indexentry:keyword, triangle}}  
 
{{#indexentry:smooth_triangle, mesh}}
 
{{#indexentry:smooth_triangle, mesh}}
{{#indexentry:keyword, smooth_triangle}}  
+
{{#indexentry:keyword, smooth_triangle}}
 +
{{#indexentry:mesh, wavefront}}
 +
{{#indexentry:wavefront, mesh}}
 +
{{#indexentry:mesh, obj}}
 +
{{#indexentry:obj, mesh}}  
 
<p>The <code>mesh</code> object can be used to efficiently store large
 
<p>The <code>mesh</code> object can be used to efficiently store large
 
numbers of triangles. Its syntax is:</p>
 
numbers of triangles. Its syntax is:</p>
Line 20: Line 24:
 
     MESH_TRIANGLE...
 
     MESH_TRIANGLE...
 
     [MESH_MODIFIER...]
 
     [MESH_MODIFIER...]
 +
    } |
 +
  mesh {
 +
    obj FILENAME
 +
    [OBJ_TEXTURE_LIST]
 +
    [inside_vector VECTOR]
 
     }
 
     }
 +
 
MESH_TRIANGLE:
 
MESH_TRIANGLE:
 
   triangle {
 
   triangle {
Line 27: Line 37:
 
     [MESH_TEXTURE]
 
     [MESH_TEXTURE]
 
     } |
 
     } |
 
 
   smooth_triangle {
 
   smooth_triangle {
 
     &lt;Corner_1&gt;, &lt;Normal_1&gt;,
 
     &lt;Corner_1&gt;, &lt;Normal_1&gt;,
Line 35: Line 44:
 
     [MESH_TEXTURE]
 
     [MESH_TEXTURE]
 
     }
 
     }
 +
 +
MESH_MODIFIER:
 +
  inside_vector &lt;direction&gt; | hierarchy [ Boolean ] |
 +
  OBJECT_MODIFIER
 +
 +
OBJ_TEXTURE_LIST:
 +
  texture_list {
 +
    [OBJ_TEXTURE_LIST_ITEM]
 +
    }
 +
 +
OBJ_TEXTURE_LIST_ITEM:
 +
  STRING texture { TEXTURE } | STRING material { TEXTURE } | prefix STRING | suffix STRING
 +
 
MESH_TEXTURE:
 
MESH_TEXTURE:
 
   texture { TEXTURE_IDENTIFIER }
 
   texture { TEXTURE_IDENTIFIER }
Line 40: Line 62:
 
     TEXTURE_IDENTIFIER TEXTURE_IDENTIFIER TEXTURE_IDENTIFIER
 
     TEXTURE_IDENTIFIER TEXTURE_IDENTIFIER TEXTURE_IDENTIFIER
 
     }
 
     }
 
MESH_MODIFIER:
 
  inside_vector &lt;direction&gt; | hierarchy [ Boolean ] |
 
  OBJECT_MODIFIER
 
 
</pre>
 
</pre>
  
Line 52: Line 70:
 
</pre>
 
</pre>
  
<p>Any number of <code>triangle</code> and/or <code>smooth_triangle</code>
+
<p>Any number of <code>triangle</code> and/or <code>smooth_triangle</code> statements can be used and each of those triangles can be individually textured by assigning a texture identifier to it. The texture has to be declared before the mesh is parsed. It is not possible to use texture definitions inside the triangle or smooth triangle statements. This is a restriction that is necessary for an efficient storage of the assigned textures. See [[Reference:Triangle Texture Interpolation|Triangle and Smooth Triangle]] for more information on triangles.</p>
statements can be used and each of those triangles can be individually
+
<p>The <code>mesh</code> object can support <code>uv_mapping</code>. For this, per triangle the keyword <code>uv_vectors</code> has to be given, together with three 2D uv-vectors. Each vector specifies a location in the xy-plane from which the texture has to be mapped to the matching points of the triangle. Also see the section [[Reference:UV Mapping|:uv_mapping|uv_mapping]].</p>
textured by assigning a texture identifier to it. The texture has to be
 
declared before the mesh is parsed. It is not possible to use texture
 
definitions inside the triangle or smooth triangle statements. This is a
 
restriction that is necessary for an efficient storage of the assigned
 
textures. See [[Reference:Triangle Texture Interpolation|Triangle and Smooth Triangle]] for more information on triangles.</p>
 
<p>The <code>mesh</code> object can support <code>uv_mapping</code>. For this, per triangle the keyword
 
<code>uv_vectors</code> has to be given, together with three 2D uv-vectors. Each vector specifies a location
 
in the xy-plane from which the texture has to be mapped to the matching points of the triangle.
 
Also see the section [[Reference:UV Mapping|:uv_mapping|uv_mapping]].</p>
 
  
 
{{#indexentry:hierarchy, mesh}}
 
{{#indexentry:hierarchy, mesh}}
 
{{#indexentry:keyword, hierarchy}}
 
{{#indexentry:keyword, hierarchy}}
<p>The mesh's components are internally bounded by a bounding box hierarchy
+
<p>The mesh's components are internally bounded by a bounding box hierarchy to speed up intersection testing. The bounding hierarchy can be turned off with the <code>hierarchy off</code> keyword. This should only be done if memory is short or the mesh consists of only a few triangles. The default is <code>hierarchy on</code>.</p>
to speed up intersection testing. The bounding hierarchy can be turned off
 
with the <code>hierarchy off</code> keyword. This should only be done if
 
memory is short or the mesh consists of only a few triangles. The default is
 
<code>hierarchy on</code>.</p>
 
  
<p>Copies of a mesh object refer to the same triangle data and thus consume
+
<p>Copies of a mesh object refer to the same triangle data and thus consume very little memory. You can easily trace a hundred copies of a 10000 triangle mesh without running out of memory (assuming the first mesh fits into memory). The mesh object has two advantages over a union of triangles: it needs less memory and it is transformed faster. The memory requirements are reduced by efficiently storing the triangles vertices and normals. The parsing time for transformed meshes is reduced because only the mesh object has to be transformed and not every single triangle as it is necessary for unions.</p>
very little memory. You can easily trace a hundred copies of a 10000 triangle
 
mesh without running out of memory (assuming the first mesh fits into
 
memory). The mesh object has two advantages over a union of triangles: it
 
needs less memory and it is transformed faster. The memory requirements are
 
reduced by efficiently storing the triangles vertices and normals. The
 
parsing time for transformed meshes is reduced because only the mesh object
 
has to be transformed and not every single triangle as it is necessary for
 
unions.</p>
 
  
<p>The mesh object can currently only include triangle and smooth triangle
 
components. That restriction may change, allowing polygonal components, at
 
some point in the future.</p>
 
 
{{#indexentry:inside_vector}}
 
{{#indexentry:inside_vector}}
 
{{#indexentry:solid triangle mesh}}
 
{{#indexentry:solid triangle mesh}}
Line 95: Line 89:
 
</pre>
 
</pre>
 
<p>This change does not have any effect on unions of triangles, these will still be always hollow.</p>
 
<p>This change does not have any effect on unions of triangles, these will still be always hollow.</p>
 +
{{#indexentry:mesh, wavefront}}
 +
{{#indexentry:wavefront, mesh}}
 +
{{#indexentry:mesh, obj}}
 +
{{#indexentry:obj, mesh}}
 +
==Wavefront Import==
 +
<p>{{New}} to version 3.7.1 support has been added to allow importing Wavefront (OBJ) files.</p>
 +
<p>Wavefront (OBJ) import provides rudimentary support for non-triangular polygons, but currently just blindly cuts up such polygons into triangles, relying on the polygons to be nicely planar and convex. This may also affect the apparent curvature of such polygons.</p>
 +
<p>At present, associated .mtl files will <em>not</em> be evaluated instead, textures must be defined using one of the following means:</p>
 +
<ol>
 +
  <li>in the <code>texture_list</code> as a list of the individual material names as used in the .obj file and the respective texture definition to use</li>
 +
  <li>before the <code>mesh</code> keyword, by defining texture variables with corresponding names. For some ease of use, a <code>prefix</code> and <code>suffix</code> can be defined that will be added to the material name as used in the .obj file</li>
 +
</ol>
 +
<p>For additional ease of use materials can be used instead of textures, however, in that case only the texture is taken from the material. The <code>interior_texture</code> and interior are ignored.</p>
 +
<p>In the following example:</p>
 +
<pre>
 +
#declare MyTexture = texture { ... }
 +
#declare MyMaterial = material { ... }
 +
 +
mesh {
 +
  obj "MyMesh.obj"
 +
  texture_list {
 +
    "Foo" texture { MyTexture }
 +
    "Bar" material { MyMaterial }
 +
    prefix "Tx"
 +
    suffix "_"
 +
  }
 +
  inside_vector y
 +
}
 +
</pre>
 +
<p>Will map the material name &quot;Foo&quot; in the .obj file to <em>MyTexture</em> and the material name &quot;Bar&quot; to <em>MyMaterial</em> while any other name e.g. <em>Fnord</em> or <em>Uqbar</em> would be mapped to <em>TxFnord_</em> and <em>TxUqbar_</em> respectively.</p>

Revision as of 19:52, 14 September 2016

The mesh object can be used to efficiently store large numbers of triangles. Its syntax is:

MESH:
  mesh {
    MESH_TRIANGLE...
    [MESH_MODIFIER...]
    } |
  mesh {
    obj FILENAME
    [OBJ_TEXTURE_LIST]
    [inside_vector VECTOR]
    }

MESH_TRIANGLE:
  triangle {
    <Corner_1>, <Corner_2>, <Corner_3>
    [uv_vectors <uv_Corner_1>, <uv_Corner_2>, <uv_Corner_3>]
    [MESH_TEXTURE]
    } |
  smooth_triangle {
    <Corner_1>, <Normal_1>,
    <Corner_2>, <Normal_2>,
    <Corner_3>, <Normal_3>
    [uv_vectors <uv_Corner_1>, <uv_Corner_2>, <uv_Corner_3>]
    [MESH_TEXTURE]
    }

MESH_MODIFIER:
  inside_vector <direction> | hierarchy [ Boolean ] |
  OBJECT_MODIFIER

OBJ_TEXTURE_LIST:
  texture_list {
    [OBJ_TEXTURE_LIST_ITEM]
    }

OBJ_TEXTURE_LIST_ITEM:
  STRING texture { TEXTURE } | STRING material { TEXTURE } | prefix STRING | suffix STRING

MESH_TEXTURE:
  texture { TEXTURE_IDENTIFIER }
  texture_list {
    TEXTURE_IDENTIFIER TEXTURE_IDENTIFIER TEXTURE_IDENTIFIER
    }

Mesh default values:

hierarchy : on

Any number of triangle and/or smooth_triangle statements can be used and each of those triangles can be individually textured by assigning a texture identifier to it. The texture has to be declared before the mesh is parsed. It is not possible to use texture definitions inside the triangle or smooth triangle statements. This is a restriction that is necessary for an efficient storage of the assigned textures. See Triangle and Smooth Triangle for more information on triangles.

The mesh object can support uv_mapping. For this, per triangle the keyword uv_vectors has to be given, together with three 2D uv-vectors. Each vector specifies a location in the xy-plane from which the texture has to be mapped to the matching points of the triangle. Also see the section uv_mapping.

The mesh's components are internally bounded by a bounding box hierarchy to speed up intersection testing. The bounding hierarchy can be turned off with the hierarchy off keyword. This should only be done if memory is short or the mesh consists of only a few triangles. The default is hierarchy on.

Copies of a mesh object refer to the same triangle data and thus consume very little memory. You can easily trace a hundred copies of a 10000 triangle mesh without running out of memory (assuming the first mesh fits into memory). The mesh object has two advantages over a union of triangles: it needs less memory and it is transformed faster. The memory requirements are reduced by efficiently storing the triangles vertices and normals. The parsing time for transformed meshes is reduced because only the mesh object has to be transformed and not every single triangle as it is necessary for unions.

Solid Mesh

The triangle mesh objects mesh (and mesh2) can be used in CSG objects such as difference and intersect. Adding the inside_vector they do have a defined inside. This will only work for well-behaved meshes, which are completely closed volumes. If meshes have any holes in them, this might work, but the results are not guaranteed.

To determine if a point is inside a triangle mesh, POV-Ray shoots a ray from the point in some arbitrary direction. If this vector intersects an odd number of triangles, the point is inside the mesh. If it intersects an even number of triangles, the point is outside of the mesh. You can specify the direction of this vector. For example, to use +z as the direction, you would add the following line to the triangle mesh description (following all other mesh data, but before the object modifiers).

inside_vector <0, 0, 1>

This change does not have any effect on unions of triangles, these will still be always hollow.

Wavefront Import

New to version 3.7.1 support has been added to allow importing Wavefront (OBJ) files.

Wavefront (OBJ) import provides rudimentary support for non-triangular polygons, but currently just blindly cuts up such polygons into triangles, relying on the polygons to be nicely planar and convex. This may also affect the apparent curvature of such polygons.

At present, associated .mtl files will not be evaluated instead, textures must be defined using one of the following means:

  1. in the texture_list as a list of the individual material names as used in the .obj file and the respective texture definition to use
  2. before the mesh keyword, by defining texture variables with corresponding names. For some ease of use, a prefix and suffix can be defined that will be added to the material name as used in the .obj file

For additional ease of use materials can be used instead of textures, however, in that case only the texture is taken from the material. The interior_texture and interior are ignored.

In the following example:

#declare MyTexture = texture { ... }
#declare MyMaterial = material { ... }

mesh {
  obj "MyMesh.obj"
  texture_list {
    "Foo" texture { MyTexture }
    "Bar" material { MyMaterial }
    prefix "Tx"
    suffix "_"
  }
  inside_vector y
}

Will map the material name "Foo" in the .obj file to MyTexture and the material name "Bar" to MyMaterial while any other name e.g. Fnord or Uqbar would be mapped to TxFnord_ and TxUqbar_ respectively.