POV-Ray : Newsgroups : povray.advanced-users : Creating meshes with trace Server Time
23 Nov 2024 12:43:46 EST (-0500)
  Creating meshes with trace (Message 1 to 9 of 9)  
From: Bald Eagle
Subject: Creating meshes with trace
Date: 11 Nov 2016 12:10:01
Message: <web.5825fa6a1a595b28b488d9aa0@news.povray.org>
I haven't looked into the exact way meshes are generated from POV files, like
the chess set, but I had an idea and decided to try my hand at "scanning" some
simple primitives and using that to create a mesh.

It seems to work fines for some things - and others --- notsomuch.

I considered using a spherical trace shell rather than the cylindrical one I'm
using now - maybe when I get some time.


The interesting thing that I have a hard time explaining - is why the top of the
Cylinder object has a "cap" (tiny rounding errors?), and why there's an inner
"core" that seems to be wide at the ends an narrow to nonexistent near the
center.
The Sphere also has the same strange "core".

The cylindrical scanning is kinda craptastic for making the Box, and the two
Cross objects _really_ get butchered.


----------------------------------------------------------------------------


#version 3.7;
global_settings {
 assumed_gamma 1.0
 ambient_light color rgb <1, 1, 1>
}
#include "colors.inc"
#include "math.inc"
#include "transforms.inc"


#declare Camera_Front = camera {
                            location  <2, 5, -30.0>
      //location  <0.0, 12, -10.0>
                            right    x*image_width/image_height
      sky y
                            look_at   <2, 5, 0>}


//####################
camera {Camera_Front}
//####################


light_source{ <50, 50, -100>  color rgb <1, 1, 1>}    // White top

// Create an infinite sphere around scene and allow any pigment on it
sky_sphere{ pigment { gradient <0,1,0>
                      color_map { [0.00 rgb <0.6, 0.7, 1.0>]
                                  [0.35 rgb <0.0, 0.1, 0.8>]
                                  [0.65 rgb <0.0, 0.1, 0.8>]
                                  [1.00 rgb <0.6, 0.7, 1.0>]
                                }
                      scale 2
                    } // end of pigment
          } //end of skysphere -------------------------------------


#declare Cylinder = cylinder {<0, 0, 0>, <0, 10, 0> 2 pigment {Red} }
#declare Sphere = sphere {<0, 0, 0>, 2 pigment {Red} }
#declare Box = box {-1, 1 pigment {Red} }
#declare Cross = union {
 cylinder {<0, 0, 0>, <0, 10, 0> 1 pigment {Red} }
 cylinder {<-5, 5, 0>, <5, 5, 0> 1 pigment {Red} }
}
#declare Cross2 = union {
 cylinder {<0, 0, 0>, <0, 10, 0> 1 pigment {Red} }
 cylinder {<-5, 5, 0>, <5, 5, 0> 1 pigment {Red} }
 cylinder {<0, 5, -5>, <0, 5, 5> 1 pigment {Red} }
}
#declare Torus = torus {3, 0.5 pigment {Red} rotate x*0}

#declare Object = object {Sphere}

object {Object}

// Scan object with a loop of traces

#declare Min = min_extent (Object);
#declare Max = max_extent (Object);

#declare TraceRadius = max (Min.x, Max.x, Min.z, Max.z) * 2;
#declare Step = 0.125;
#declare Arcs = 72;
#declare TraceNormal = <0, 0, 0>;

#declare Degrees = 360/Arcs;
#declare OddShift = Degrees/2;
#declare Levels = (Max.y-Min.y)/Step;
#debug concat( " Levels = ", str(Levels, 3, 1), "\n")

#declare TraceMeshArray = array [Levels+1][Arcs+1];
#declare ArrayY = 0;
#declare ArrayX = 0;


#for (Y, Min.y, Max.y, Step)
 #if (odd(ArrayY))
  #declare Shift = OddShift;
 #else
  #declare Shift = 0;
 #end

 #for (Theta, 0, 360, Degrees)
  #declare MyTransform = transform { rotate  y*(Theta+Shift) };
  #declare TracePoint = vtransform (<TraceRadius, Y, 0>, MyTransform);
  #declare TraceMeshArray[ArrayY][ArrayX] = trace(Object, <0, Y, 0>, TracePoint,
TraceNormal);
  //#debug concat( " Y = ", str(ArrayY, 3, 1),  "     X = ", str(ArrayX, 3, 1),
"     TraceNormal = ", vstr(3, TraceNormal, ", ", 3, 0), "\n")
  cylinder {TracePoint, <0, Y, 0> 0.005 pigment {Blue} }
  #declare TraceNormal = <0, 0, 0>;
  #declare ArrayX = ArrayX+1;
 #end
#declare ArrayX = 0;  // reset X
#declare ArrayY = ArrayY+1;
#end

#declare Move = (Max.x*2)+4;

// plot mesh vertices
#declare ArrayY = 0;
#declare ArrayX = 0;
#declare SphereRadius = 0.01;
#for (Y, Min.y, Max.y, Step)
 #for (Theta, 0, 360, Degrees)
  sphere {TraceMeshArray[ArrayY][ArrayX], SphereRadius pigment {Black} translate
x*Move}
  #declare ArrayX = ArrayX+1;
 #end
#declare ArrayX = 0;  // reset X
#declare ArrayY = ArrayY+1;
#end

// draw mesh edges
#declare SphereRadius = 0.025;
#declare ArrayY = 0;
#declare ArrayX = 0;
#declare SphereRadius = 0.0125;
#for (Y, Min.y, Max.y, Step)
 #for (Theta, 0, 360, Degrees)
  //horizontal edges
  #if (ArrayX >= 1)
   //#debug concat( "TraceMeshArray[ArrayY][ArrayX] = ", vstr(3,
TraceMeshArray[ArrayY][ArrayX], ", ", 3, 3), "
TraceMeshArray[ArrayY][ArrayX-1] = ", vstr(3, TraceMeshArray[ArrayY][ArrayX-1],
", ", 3, 3),"\n")
   cylinder {TraceMeshArray[ArrayY][ArrayX],
TraceMeshArray[ArrayY][ArrayX-1]+0.001, SphereRadius pigment {Green} translate
x*Move}
  #end

  // diagonal edges
  #if (Y > Min.y)
   cylinder {TraceMeshArray[ArrayY][ArrayX], TraceMeshArray[ArrayY-1][ArrayX],
SphereRadius pigment {Green} translate x*Move}
   #if (odd(ArrayY))
    #if (ArrayX < Arcs)
     cylinder {TraceMeshArray[ArrayY][ArrayX],
TraceMeshArray[ArrayY-1][ArrayX+1], SphereRadius pigment {Green} translate
x*Move}
    #else
     cylinder {TraceMeshArray[ArrayY][ArrayX], TraceMeshArray[ArrayY-1][0],
SphereRadius pigment {Green} translate x*Move}
    #end
   #else
    #if (ArrayX > 0)
     cylinder {TraceMeshArray[ArrayY][ArrayX],
TraceMeshArray[ArrayY-1][ArrayX-1], SphereRadius pigment {Green} translate
x*Move}
    #else
     cylinder {TraceMeshArray[ArrayY][ArrayX], TraceMeshArray[ArrayY-1][0],
SphereRadius pigment {Green} translate x*Move}
    #end
   #end
  #end

  #declare ArrayX = ArrayX+1;
 #end
#declare ArrayX = 0;  // reset X
#declare ArrayY = ArrayY+1;
#end


Post a reply to this message

From: INVALID ADDRESS
Subject: Re: Creating meshes with trace
Date: 15 Nov 2016 19:30:10
Message: <1127382658.500948152.716357.gdsHYPHENentropyAThotmaolDOTcom@news.povray.org>
This is a very cool idea, I had long ago wondered about mesh-casting but
had insufficient experience and time to try to cook an algorithm up.

Have you tried it with many connected blobs of varying size? What kind of
shapes cause issues? Is your primary issue in the trace shell?

I wonder if using a two step trace shell construction would work; step one
trace your upscaled target object from all sides to get a list of vectors,
step two use those vectors as trace origins to get a fitted shell.

I only looked at and considered this for a few seconds so I might be
speaking nonsense above...

If it works for blobs I might be able to use that to speed up and improve
the outcome of the snow/ice/corrosion macros I made a long time ago. I need
to go back to those and improve them, a lot.

Im going to play with this...

Ian

Bald Eagle <cre### [at] netscapenet> wrote:
> 
> I haven't looked into the exact way meshes are generated from POV files, like
> the chess set, but I had an idea and decided to try my hand at "scanning" some
> simple primitives and using that to create a mesh.
> 
> It seems to work fines for some things - and others --- notsomuch.
> 
> I considered using a spherical trace shell rather than the cylindrical one I'm
> using now - maybe when I get some time.
> 
> 
> The interesting thing that I have a hard time explaining - is why the top of the
> Cylinder object has a "cap" (tiny rounding errors?), and why there's an inner
> "core" that seems to be wide at the ends an narrow to nonexistent near the
> center.
> The Sphere also has the same strange "core".
> 
> The cylindrical scanning is kinda craptastic for making the Box, and the two
> Cross objects _really_ get butchered.
> 
> 
> ----------------------------------------------------------------------------
> 
> 
> #version 3.7;
> global_settings {
>  assumed_gamma 1.0
>  ambient_light color rgb <1, 1, 1>
> }
> #include "colors.inc"
> #include "math.inc"
> #include "transforms.inc"
> 
> 
> #declare Camera_Front = camera {
>                             location  <2, 5, -30.0>
>       //location  <0.0, 12, -10.0>
>                             right    x*image_width/image_height
>       sky y
>                             look_at   <2, 5, 0>}
> 
> 
> //####################
> camera {Camera_Front}
> //####################
> 
> 
> light_source{ <50, 50, -100>  color rgb <1, 1, 1>}    // White top
> 
> // Create an infinite sphere around scene and allow any pigment on it
> sky_sphere{ pigment { gradient <0,1,0>
>                       color_map { [0.00 rgb <0.6, 0.7, 1.0>]
>                                   [0.35 rgb <0.0, 0.1, 0.8>]
>                                   [0.65 rgb <0.0, 0.1, 0.8>]
>                                   [1.00 rgb <0.6, 0.7, 1.0>]
>                                 }
>                       scale 2
>                     } // end of pigment
>           } //end of skysphere -------------------------------------
> 
> 
> #declare Cylinder = cylinder {<0, 0, 0>, <0, 10, 0> 2 pigment {Red} }
> #declare Sphere = sphere {<0, 0, 0>, 2 pigment {Red} }
> #declare Box = box {-1, 1 pigment {Red} }
> #declare Cross = union {
>  cylinder {<0, 0, 0>, <0, 10, 0> 1 pigment {Red} }
>  cylinder {<-5, 5, 0>, <5, 5, 0> 1 pigment {Red} }
> }
> #declare Cross2 = union {
>  cylinder {<0, 0, 0>, <0, 10, 0> 1 pigment {Red} }
>  cylinder {<-5, 5, 0>, <5, 5, 0> 1 pigment {Red} }
>  cylinder {<0, 5, -5>, <0, 5, 5> 1 pigment {Red} }
> }
> #declare Torus = torus {3, 0.5 pigment {Red} rotate x*0}
> 
> #declare Object = object {Sphere}
> 
> object {Object}
> 
> // Scan object with a loop of traces
> 
> #declare Min = min_extent (Object);
> #declare Max = max_extent (Object);
> 
> #declare TraceRadius = max (Min.x, Max.x, Min.z, Max.z) * 2;
> #declare Step = 0.125;
> #declare Arcs = 72;
> #declare TraceNormal = <0, 0, 0>;
> 
> #declare Degrees = 360/Arcs;
> #declare OddShift = Degrees/2;
> #declare Levels = (Max.y-Min.y)/Step;
> #debug concat( " Levels = ", str(Levels, 3, 1), "\n")
> 
> #declare TraceMeshArray = array [Levels+1][Arcs+1];
> #declare ArrayY = 0;
> #declare ArrayX = 0;
> 
> 
> #for (Y, Min.y, Max.y, Step)
>  #if (odd(ArrayY))
>   #declare Shift = OddShift;
>  #else
>   #declare Shift = 0;
>  #end
> 
>  #for (Theta, 0, 360, Degrees)
>   #declare MyTransform = transform { rotate  y*(Theta+Shift) };
>   #declare TracePoint = vtransform (<TraceRadius, Y, 0>, MyTransform);
>   #declare TraceMeshArray[ArrayY][ArrayX] = trace(Object, <0, Y, 0>, TracePoint,
> TraceNormal);
>   //#debug concat( " Y = ", str(ArrayY, 3, 1),  "     X = ", str(ArrayX, 3, 1),
> "     TraceNormal = ", vstr(3, TraceNormal, ", ", 3, 0), "\n")
>   cylinder {TracePoint, <0, Y, 0> 0.005 pigment {Blue} }
>   #declare TraceNormal = <0, 0, 0>;
>   #declare ArrayX = ArrayX+1;
>  #end
> #declare ArrayX = 0;  // reset X
> #declare ArrayY = ArrayY+1;
> #end
> 
> #declare Move = (Max.x*2)+4;
> 
> // plot mesh vertices
> #declare ArrayY = 0;
> #declare ArrayX = 0;
> #declare SphereRadius = 0.01;
> #for (Y, Min.y, Max.y, Step)
>  #for (Theta, 0, 360, Degrees)
>   sphere {TraceMeshArray[ArrayY][ArrayX], SphereRadius pigment {Black} translate
> x*Move}
>   #declare ArrayX = ArrayX+1;
>  #end
> #declare ArrayX = 0;  // reset X
> #declare ArrayY = ArrayY+1;
> #end
> 
> // draw mesh edges
> #declare SphereRadius = 0.025;
> #declare ArrayY = 0;
> #declare ArrayX = 0;
> #declare SphereRadius = 0.0125;
> #for (Y, Min.y, Max.y, Step)
>  #for (Theta, 0, 360, Degrees)
>   //horizontal edges
>   #if (ArrayX >= 1)
>    //#debug concat( "TraceMeshArray[ArrayY][ArrayX] = ", vstr(3,
> TraceMeshArray[ArrayY][ArrayX], ", ", 3, 3), "
> TraceMeshArray[ArrayY][ArrayX-1] = ", vstr(3, TraceMeshArray[ArrayY][ArrayX-1],
> ", ", 3, 3),"\n")
>    cylinder {TraceMeshArray[ArrayY][ArrayX],
> TraceMeshArray[ArrayY][ArrayX-1]+0.001, SphereRadius pigment {Green} translate
> x*Move}
>   #end
> 
>   // diagonal edges
>   #if (Y > Min.y)
>    cylinder {TraceMeshArray[ArrayY][ArrayX], TraceMeshArray[ArrayY-1][ArrayX],
> SphereRadius pigment {Green} translate x*Move}
>    #if (odd(ArrayY))
>     #if (ArrayX < Arcs)
>      cylinder {TraceMeshArray[ArrayY][ArrayX],
> TraceMeshArray[ArrayY-1][ArrayX+1], SphereRadius pigment {Green} translate
> x*Move}
>     #else
>      cylinder {TraceMeshArray[ArrayY][ArrayX], TraceMeshArray[ArrayY-1][0],
> SphereRadius pigment {Green} translate x*Move}
>     #end
>    #else
>     #if (ArrayX > 0)
>      cylinder {TraceMeshArray[ArrayY][ArrayX],
> TraceMeshArray[ArrayY-1][ArrayX-1], SphereRadius pigment {Green} translate
> x*Move}
>     #else
>      cylinder {TraceMeshArray[ArrayY][ArrayX], TraceMeshArray[ArrayY-1][0],
> SphereRadius pigment {Green} translate x*Move}
>     #end
>    #end
>   #end
> 
>   #declare ArrayX = ArrayX+1;
>  #end
> #declare ArrayX = 0;  // reset X
> #declare ArrayY = ArrayY+1;
> #end
> 
> 
>


Post a reply to this message

From: Bald Eagle
Subject: Re: Creating meshes with trace
Date: 16 Nov 2016 07:55:01
Message: <web.582c569aaea87895b488d9aa0@news.povray.org>
[GDS|Entropy] <gdsHYPHENentropyAThotmaolDOTcom> wrote:
> This is a very cool idea, I had long ago wondered about mesh-casting but
> had insufficient experience and time to try to cook an algorithm up.

I've wondered about it from time to time, and I just had one of those moments
where a way to start just came to me.

> Have you tried it with many connected blobs of varying size? What kind of
> shapes cause issues? Is your primary issue in the trace shell?

Blobs as the object being scanned?   Nope, I'll try that.


> I wonder if using a two step trace shell construction would work; step one
> trace your upscaled target object from all sides to get a list of vectors,
> step two use those vectors as trace origins to get a fitted shell.

That's a brilliant idea - I was wondering how to get into convex areas and other
shielded places where there might be something obstructing the trace.
I'm not at all sure how to piece together those separate trace levels smoothly.
I still have some troubles with getting the arrays right, and avoiding
degenerate cylinders/triangles.

Perhaps a 6-step scan from the faces of a cube would yield good results.

I've also wondered about "slicing" an object, and somehow scanning the
perimeter(s) of the slices, so that even hollow objects could be fully
converted.

Thanks for your interest - I'm still constantly learning new things and skills.


Post a reply to this message

From: Bill Pragnell
Subject: Re: Creating meshes with trace
Date: 16 Nov 2016 09:40:01
Message: <web.582c6eeaaea878955b7d07940@news.povray.org>
"Bald Eagle" <cre### [at] netscapenet> wrote:
> [GDS|Entropy] <gdsHYPHENentropyAThotmaolDOTcom> wrote:
> > I wonder if using a two step trace shell construction would work; step one
> > trace your upscaled target object from all sides to get a list of vectors,
> > step two use those vectors as trace origins to get a fitted shell.
>
> That's a brilliant idea - I was wondering how to get into convex areas and other
> shielded places where there might be something obstructing the trace.

I wrote some mesh generation and deformation macros some years ago that took
exactly this approach - search for 'meshrelief' in the object library on this
site, or get it here (ancient site, sorry, but it still works):
http://www.infradead.org/~wmp/macro_meshrelief.html

I found that although secondary target object did help spread out the mesh
samples to get a more even triangulation, it didn't really make much difference
for awkward objects. You might find the source interesting to adapt to your own
purposes...

Bill


Post a reply to this message

From: Mike Horvath
Subject: Re: Creating meshes with trace
Date: 16 Nov 2016 11:32:03
Message: <582c8a03@news.povray.org>
What are you going to do with the meshes once they're made? Save them to 
disk?

Mike


Post a reply to this message

From: INVALID ADDRESS
Subject: Re: Creating meshes with trace
Date: 16 Nov 2016 18:34:04
Message: <1796714765.501031424.410476.gdsHYPHENentropyAThotmaolDOTcom@news.povray.org>
Bald Eagle <cre### [at] netscapenet> wrote:
> 
> Blobs as the object being scanned?   Nope, I'll try that.
> 

Cool; let me know how that goes. I will try it too.

> That's a brilliant idea - I was wondering how to get into convex areas and other
> shielded places where there might be something obstructing the trace.
> I'm not at all sure how to piece together those separate trace levels smoothly.
> I still have some troubles with getting the arrays right, and avoiding
> degenerate cylinders/triangles.

I do some scanning in my snow/ice/corrosion/moss macro posted in one of the
source forums; that is my end use for whatever we can come up with.

I think I will pause my work on the rectangle packing algorithm and see
what I can come up with for the trace scan. If that can be sufficiently
generic and made a macro, it can be a good core for MANY macros which could
do very cool things.

It might even be a solved problem; Pov has been around for a while and many
smart folks have had their hands on it, I would bet someone else has
wondered exactly the same thing as we.

> Perhaps a 6-step scan from the faces of a cube would yield good results.
> 

I don't recall how I handled it in my macros, but I didn't have coverage
issues. I was coating objects with blobs and so used torii, superquads,
trees and etc as test objects.

I will take a look in a bit.

> I've also wondered about "slicing" an object, and somehow scanning the
> perimeter(s) of the slices, so that even hollow objects could be fully
> converted.

Yes that will be complex, but I think the first place to start simply to
get a good foundation before going all out would be an object constructed
of 3 torii, each oriented on a separate axis but with a common origin.

Something like a hollow box with a window in the side is going to be a
bear, but a switch to designate a hollow object and input of a vector
specifying the center of its cavity would allow you to use two separate
algorithms.

The algorithm for the interior could simply be the inverse of the one used
for the outside, as in operating on a scaled down version of the object
with the normal inverted.

> Thanks for your interest - I'm still constantly learning new things and skills.
> 

Thats why we are all here. :)


Post a reply to this message

From: INVALID ADDRESS
Subject: Re: Creating meshes with trace
Date: 16 Nov 2016 18:36:26
Message: <1617494888.501032112.655460.gdsHYPHENentropyAThotmaolDOTcom@news.povray.org>
Bill Pragnell <bil### [at] hotmailcom> wrote:

> I wrote some mesh generation and deformation macros some years ago that took
> exactly this approach - search for 'meshrelief' in the object library on this
> site, or get it here (ancient site, sorry, but it still works):
> http://www.infradead.org/~wmp/macro_meshrelief.html
> 
> I found that although secondary target object did help spread out the mesh
> samples to get a more even triangulation, it didn't really make much difference
> for awkward objects. You might find the source interesting to adapt to your own
> purposes...
> 

Oh awesome!
I just knew we couldn't have been the only ones to have thought of this!
Thanks!!

This will advance efforts greatly.

Ian


Post a reply to this message

From: Bald Eagle
Subject: Re: Creating meshes with trace
Date: 21 Nov 2016 12:35:00
Message: <web.58332f5eaea87895c437ac910@news.povray.org>
"Bill Pragnell" <bil### [at] hotmailcom> wrote:

> I wrote some mesh generation and deformation macros some years ago that took
> exactly this approach - search for 'meshrelief' in the object library on this
> site, or get it here (ancient site, sorry, but it still works):
> http://www.infradead.org/~wmp/macro_meshrelief.html


> You might find the source interesting to adapt to your own
> purposes...

I remember reading about this project here and there over the years - I
instantly recognized that render of deformed meshes.

I'm sure the next time I get a chance, I'll find analyzing your method very
instructive and helpful - thanks!


Post a reply to this message

From: Bald Eagle
Subject: Re: Creating meshes with trace
Date: 21 Nov 2016 12:40:00
Message: <web.5833310baea87895c437ac910@news.povray.org>
Mike Horvath <mik### [at] gmailcom> wrote:
> What are you going to do with the meshes once they're made? Save them to
> disk?
>
> Mike

I think at the moment, I'm just experimenting with mesh generation and ways to
create matrices of points from items defined in SDL.

I would imagine that if further experiments result in useful data sets, then
sure - they could be saved to disk for use in future scenes, etc.


Post a reply to this message

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