POV-Ray : Newsgroups : povray.unofficial.patches : Tesselation and mesh data extraction patches Server Time
1 Nov 2024 11:13:40 EDT (-0400)
  Tesselation and mesh data extraction patches (Message 1 to 10 of 32)  
Goto Latest 10 Messages Next 10 Messages >>>
From: Warp
Subject: Tesselation and mesh data extraction patches
Date: 13 Dec 2000 15:35:13
Message: <3a37dd81@news.povray.org>
I have been playing with the two patches mentioned in the subject.

  I'll describe my ideas and I hope to get some suggestions about the syntax,
improvement ideas and so on.


  - The mesh data extraction patch
    ==============================

  This is an independent patch which can be used with any mesh. Although
it's useful in itself, it makes the tesselation patch to make sense
(the tesselation patch without this patch would be pretty useless).

  The idea is that you could get individual values (vertices, triangles,
normals...) from a mesh object.
  This can be used to, for example, export a mesh to an ascii file format
(such as PCM or other more popular mesh formats), use macros on the mesh
(such as the SSS or the PCM macros) and so on.

  Right now I have done these functions:

  * get_triangle_count(MESH)
      Returns the number of triangles in the mesh

  * get_vertex_count(MESH)
      Returns the number of vertices in the mesh

  * get_normal_count(MESH)
      Returns the number of normal vectors in the mesh

  * get_vertex(MESH, INDEX)
      Returns the vertex vector that corresponds to the given index
      value (starting from 0)

  * get_normal(MESH, INDEX)
      As get_vertex, but returns a normal vector

  * get_vertex_indices(MESH, INDEX)
      Returns a vector containing index values to vertices for the triangle
      number INDEX (starting from 0). This can be used to read the three
      vertices of the triangle calling get_vertex() with each vector component

  * get_normal_indices(MESH, INDEX)
      The same as get_vertex_indices(), but returns indices to the normal
      vectors of the triangle number INDEX

  * is_smooth_triangle(MESH, INDEX)
      Tells whether the triangle number INDEX is smooth or not (not yet
      implemented).

  As you can see, there are lots of functions.

  My first idea was to put everything into arrays so that you could just
do all that with one function, like for example:

  get_mesh_data(MESH, VERTICES, NORMALS, TRIANGLES)

(with the three last parameters being undefined identifiers).
  You could then get the count values by reading the size of the arrays and
the data would be inside the arrays.
  (Another option would be to create three functions, each one returning
one array.)

  This latter option certainly sounds better than having 8 functions to get
the triangle data.
  However, it has one drawback: It takes a lot of memory to create those
arrays. Studying the povray source I have deduced that the arrays would
take more than twice the memory than the mesh itself (which would mean
that it takes more than three times the memory required for the mesh
itself to be able to handle the mesh and the arrays).

  But I can add this kind of function as an option. It's not like it was
mutually exclusive with the 8 first functions. Both could exist.

  Here is an example macro that writes a mesh to PCM format:

#macro ExportToPCM(Mesh, FileName)
  #fopen OutFile FileName write
  #local vrt_cnt = get_vertex_count(Mesh);
  #local nrm_cnt = get_normal_count(Mesh);
  #write(OutFile, "\"PCM1\",\n", vrt_cnt+nrm_cnt, ",\n")
  #local VInd = 0;
  #while(VInd < vrt_cnt)
    #local V = get_vertex(Mesh, VInd);
    #write(OutFile, V.x, ",", V.y, ",", V.z, ",")
    #local VInd = VInd+1;
  #end
  #local NInd = 0;
  #while(NInd < nrm_cnt)
    #local N = get_normal(Mesh, NInd);
    #write(OutFile, N.x, ",", N.y, ",", N.z, ",")
    #local NInd = NInd+1;
  #end
  #local tr_cnt = get_triangle_count(Mesh);
  #write(OutFile, "\n0,", tr_cnt, ",\n")
  #local TInd = 0;
  #while(TInd < tr_cnt)
    #local Ind1 = get_vertex_indices(Mesh, TInd);
    #local Ind2 = vrt_cnt + get_normal_indices(Mesh, TInd);
    #write(OutFile,
      Ind1.x, ",", Ind2.x, ",",
      Ind1.y, ",", Ind2.y, ",",
      Ind1.z, ",", Ind2.z, ",")
    #local TInd = TInd+1;
  #end
  #fclose OutFile
#end


  - The tesselation patch
    =====================

  The tesselation patch defines a function called tesselate() which can
be used to convert any object with a finite bounding box into a triangle
mesh. The syntax is the following:

  tesselate(OBJECT, RESOLUTION, SMOOTH, BBOX_OFFSET)

  The two last parameters are optional.
  The function returns a regular mesh object.

  The parameters have to following meaning:

  OBJECT: Any object with a finite bounding box.

  RESOLUTION: An integer value which must be greater than 0 and which
    affects the accuracy of the tesselation. A larger value gives a higher
    accuracy.

  SMOOTH: Boolean value which tells the function whether it should calculate
    flat or smooth triangles. If smooth triangles are calculated, the normal
    vectors are taken from the object itself. The default value is false.

  BBOX_OFFSET: If this value is different from 0, then the dimensions taken
    from the bounding box are enlarged by this amount. Only very small
    values should be used if any (like 0.0001). The default value is 0.
      This operation is necessary to tesselate objects like box { -1,1 }.
    However, this is not usually necessary and using a value different
    from 0 can cause inaccuracies with some objects (if an edge of the
    object touches the bounding box).

  To do: To study whether it's possible to use some supersampling algorithm
to calculate more triangles at sharp edges of the object.
  Currently the tesselation is not very good with sharp edges.

-- 
main(i,_){for(_?--i,main(i+2,"FhhQHFIJD|FQTITFN]zRFHhhTBFHhhTBFysdB"[i]
):_;i&&_>1;printf("%s",_-70?_&1?"[]":" ":(_=0,"\n")),_/=2);} /*- Warp -*/


Post a reply to this message

From: Chris Huff
Subject: Re: Tesselation and mesh data extraction patches
Date: 13 Dec 2000 16:45:58
Message: <chrishuff-679ACB.16465513122000@news.povray.org>
In article <3a37dd81@news.povray.org>, Warp <war### [at] tagpovrayorg> 
wrote:

>   - The mesh data extraction patch
>     ==============================

This definitely looks useful!


>   - The tesselation patch
>     =====================

This reminds me of something I have been thinking of but don't know 
enough about meshes to do...extending the mesh object so you can put 
other objects in it and have them be automatically tesselated. There 
would also be various mesh processes that could do things like remove 
internal triangles, auto-smooth normals, remove redundant triangles, 
replace groups of tiny triangles with larger ones, apply a warp to the 
points to displace the mesh(I actually tried this one, I never got it to 
work), and various subdivision features...these would be in a 
"process_mesh" block and would be done in the order they are found.
The syntax would be something like this:

mesh {
    ...triangles and/or smooth triangles...
    OBJECT {OBJECT_STUFF TESSELATION_OPTIONS}
    process_mesh {
        warp {WARP}
        smooth SMOOTH_METHOD
        strip_interior_triangles
        subdivide {...}
        round_edges {...}
        ...
    }
}

TESSELATION_OPTIONS would vary from object to object, but would contain 
things like method, uv resolution, a target triangle area, whatever...as 
well as commands for how to add the tesselated object to the mesh: union 
would just add the triangles, merge would strip the interior triangles, 
etc...it could also contain mesh processing commands applied to the mesh 
generated from that object, before it is added into the main mesh.
An example would be:

mesh {
    sphere {<-1, 0, 0>, 1
        method 1, 4// 0=usual sin/cos tesselation, 1=subdividing 
polyhedron with depth as second parameter, something like a geodesic 
sphere
    }
    sphere {< 2, 0, 0>, 2
        method 1, 4
        merge// tell it to automatically remove interior triangles and 
produce the proper "seams"
        process_mesh {
            warp {turbulence 0.3}
        }
    }
    process_mesh {
        smooth SMOOTH_METHOD
    }
}

This could be very useful for manipulating meshes by hand...I had 
visualized it as using an approximation of objects which it couldn't 
tesselate directly, the bounding box of a julia_fractal for instance, 
but your tesselation algorithm would be a much better choice for this.

-- 
Christopher James Huff
Personal: chr### [at] maccom, http://homepage.mac.com/chrishuff/
TAG: chr### [at] tagpovrayorg, http://tag.povray.org/

<><


Post a reply to this message

From: Tony[B]
Subject: Re: Tesselation and mesh data extraction patches
Date: 13 Dec 2000 21:21:35
Message: <3a382eaf@news.povray.org>
Whoa... you did it*. Way to go! Our dreams are a reality! Now we can make
POV benefit from those nice video cards, and stuff. Can you make a patch for
reading directly from 3DS and other file formats directly? :)


* "it" being "the tesselation of POV objects".


Post a reply to this message

From: Warp
Subject: Re: Tesselation and mesh data extraction patches
Date: 14 Dec 2000 08:25:54
Message: <3a38ca62@news.povray.org>
Would this alternative syntax be better?

tesselate
{ MyObject
  accuracy INTEGER
  [smooth]
  [inside_vector VECTOR]
}

-- 
main(i,_){for(_?--i,main(i+2,"FhhQHFIJD|FQTITFN]zRFHhhTBFHhhTBFysdB"[i]
):_;i&&_>1;printf("%s",_-70?_&1?"[]":" ":(_=0,"\n")),_/=2);} /*- Warp -*/


Post a reply to this message

From: Warp
Subject: Modified syntax (Was: Tesselation and mesh data extraction patches)
Date: 14 Dec 2000 09:35:54
Message: <3a38daca@news.povray.org>
I modified the syntax of the tesselation to be more versatile and more
homogeneous with the syntax of other povray objects.

tesselate
{ OBJECT
  [accuracy INTEGER]
  [smooth]
  [inside_vector VECTOR]
  [distance FLOAT]

  OBJECT_MODIFIERS
}

  I reused old keywords in MegaPov so that I wouldn't have to create new
ones.
  The hardest keyword to find was for the bounding-box offset value. I thought
that 'distance' could be the best one for that.

  I still have to work a bit about the meaning of the accuracy value.
  Any suggestions?

-- 
main(i,_){for(_?--i,main(i+2,"FhhQHFIJD|FQTITFN]zRFHhhTBFHhhTBFysdB"[i]
):_;i&&_>1;printf("%s",_-70?_&1?"[]":" ":(_=0,"\n")),_/=2);} /*- Warp -*/


Post a reply to this message

From: Ron Parker
Subject: Re: Modified syntax (Was: Tesselation and mesh data extraction patches)
Date: 14 Dec 2000 10:08:50
Message: <slrn93hok7.2uh.ron.parker@fwi.com>
On 14 Dec 2000 09:35:54 -0500, Warp wrote:
>  I reused old keywords in MegaPov so that I wouldn't have to create new
>ones.
>  The hardest keyword to find was for the bounding-box offset value. I thought
>that 'distance' could be the best one for that.

Isn't "offset" a keyword in MegaPOV anymore?

-- 
Ron Parker   http://www2.fwi.com/~parkerr/traces.html
My opinions.  Mine.  Not anyone else's.


Post a reply to this message

From: Warp
Subject: Re: Modified syntax
Date: 14 Dec 2000 10:11:10
Message: <3a38e30e@news.povray.org>
Warp <war### [at] tagpovrayorg> wrote:
:   [accuracy INTEGER]

  I have decided to change that to:

    [accuracy VECTOR]

  This way the user can specify the accuracy in each axis.
  Of course specifying a single value will have the same effect as before
(because it's converted to a vector with the three components being that
value).

-- 
main(i,_){for(_?--i,main(i+2,"FhhQHFIJD|FQTITFN]zRFHhhTBFHhhTBFysdB"[i]
):_;i&&_>1;printf("%s",_-70?_&1?"[]":" ":(_=0,"\n")),_/=2);} /*- Warp -*/


Post a reply to this message

From: Warp
Subject: Re: Modified syntax
Date: 14 Dec 2000 10:13:46
Message: <3a38e3aa@news.povray.org>
Ron Parker <ron### [at] povrayorg> wrote:
: Isn't "offset" a keyword in MegaPOV anymore?

  Oh... You are right. I changed it to "offset" :)

-- 
main(i,_){for(_?--i,main(i+2,"FhhQHFIJD|FQTITFN]zRFHhhTBFHhhTBFysdB"[i]
):_;i&&_>1;printf("%s",_-70?_&1?"[]":" ":(_=0,"\n")),_/=2);} /*- Warp -*/


Post a reply to this message

From: Tony[B]
Subject: Re: Modified syntax
Date: 14 Dec 2000 10:23:22
Message: <3a38e5ea@news.povray.org>
Sounds fine now. Just one question: What's "inside_vector"?


Post a reply to this message

From: Warp
Subject: Re: Modified syntax
Date: 14 Dec 2000 11:40:12
Message: <3a38f7eb@news.povray.org>
Tony[B] <ben### [at] panamac-comnet> wrote:
: Sounds fine now. Just one question: What's "inside_vector"?

  See the section 5.3 (Solid Triangle mesh) of the MegaPov documentation.

-- 
main(i,_){for(_?--i,main(i+2,"FhhQHFIJD|FQTITFN]zRFHhhTBFHhhTBFysdB"[i]
):_;i&&_>1;printf("%s",_-70?_&1?"[]":" ":(_=0,"\n")),_/=2);} /*- Warp -*/


Post a reply to this message

Goto Latest 10 Messages Next 10 Messages >>>

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