POV-Ray : Newsgroups : povray.advanced-users : Creating meshes with trace : Creating meshes with trace Server Time
5 May 2024 23:43:09 EDT (-0400)
  Creating meshes with trace  
From: Bald Eagle
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

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