POV-Ray : Newsgroups : povray.text.scene-files : Planet mesh generator Server Time
1 Nov 2024 15:25:30 EDT (-0400)
  Planet mesh generator (Message 1 to 1 of 1)  
From: Chris Huff
Subject: Planet mesh generator
Date: 31 Dec 1999 12:22:52
Message: <chrishuff_99-38BA11.12234731121999@news.povray.org>
// Persistence of Vision Ray Tracer Scene Description File
// File: MeshPlanet.pov
// Author: Chris Huff
// Desc: A macro for creating planets. This scene uses
// an iteration which is far too small, and the resolution
// of the mesh is pretty coarse, but it demonstrates the
// basic use of the macro.
// Warning: this may take quite a while to parse.
// I will modify it to output the mesh to an include file,
// which will parse much faster. I might even make a C++
// version, which will run much faster than the POV-Ray
// version, although I would only provide an executable for
// Macintosh machines. Users of other OS's would have to
// compile it for themselves.
//  
//*******************************************
#include "colors.inc"
#version 3.1;
//-------------------------------------------

global_settings {
   assumed_gamma 1.8
}

camera {
   location <-3, 5, -8>
   angle 35
   look_at < 0, 0, 0>
}


//*******************************************
#declare T_White = texture {pigment {color White}}
#declare T_Red   = texture {pigment {color Red}}
#declare T_Green = texture {pigment {color Green}}
#declare T_Blue  = texture {pigment {color Blue}}
#declare T_Blue2  = texture {pigment {color rgbf < 0.5, 0.5, 1, 1>}}
//*******************************************
#macro MeshBall(Pos, Rad, xRes, yRes)
   mesh {
   #local J=0;
   #while(J<yRes)
      #local K=0;
      #while(K<xRes)
         #local ptA = vrotate(y*Rad, < J*(180/yRes),     K*(360/xRes), 
0>);
         #local ptB = vrotate(y*Rad, < (J+1)*(180/yRes), K*(360/xRes), 
0>);
         #local ptC = vrotate(y*Rad, < J*(180/yRes),     
(K+1)*(360/xRes), 0>);
         #local ptD = vrotate(y*Rad, < (J+1)*(180/yRes), 
(K+1)*(360/xRes), 0>);
         triangle {ptA, ptB, ptC}
         triangle {ptD, ptB, ptC}
         #local K=K+1;
      #end
      #local J=J+1;
   #end
   translate Pos
#end

#macro ModifyPt(Pt, Scale, I, Seed)
   #local RS1 = seed(Seed);
   #local Result = (Pt);
   #local M=0;
   #while(M<I)
      #local tempPt = vrotate(Pt, < rand(RS1)*360, rand(RS1)*360, 
rand(RS1)*360>);
      #local tempPt = tempPt + < rand(RS1), rand(RS1), rand(RS1)>;
      #if(tempPt.y>0)
         #local Result = Result + vnormalize(Pt)*Scale*(rand(RS1)*2 - 1);
//       #local Result = Result*(1 + Scale*(rand(RS1)*2 - 1));
      #end
      #local M=M+1;
   #end
   (Result)
#end

#macro MeshPlanet(Pos, Rad, xRes, yRes, Seed, Scale, Iterations)
   mesh {
   #local J=0;
   #while(J<yRes)
      #local K=0;
      #while(K<xRes)
         #local ptA = vrotate(y*Rad, <     J*(180/yRes),     
K*(360/xRes), 0>);
         #local ptB = vrotate(y*Rad, < (J+1)*(180/yRes),     
K*(360/xRes), 0>);
         #local ptC = vrotate(y*Rad, <     J*(180/yRes), 
(K+1)*(360/xRes), 0>);
         #local ptD = vrotate(y*Rad, < (J+1)*(180/yRes), 
(K+1)*(360/xRes), 0>);
         
         #local ptA = ModifyPt(ptA, Scale, Iterations, Seed);
         #local ptB = ModifyPt(ptB, Scale, Iterations, Seed);
         #local ptC = ModifyPt(ptC, Scale, Iterations, Seed);
         #local ptD = ModifyPt(ptD, Scale, Iterations, Seed);
         
         #if(vlength(ptA - ptC) > 0.001)
         triangle {ptA, ptB, ptC
//          texture {T_Blue}
         }
         #end
         #if(vlength(ptB - ptD) > 0.001)
         triangle {ptD, ptB, ptC
//          texture {T_Green}
         }
         #end
         #local K=K+1;
      #end
      #local J=J+1;
   #end
   translate Pos
#end

sphere {< 0, 0, 0>, 0.99
   texture {T_Blue2} 
}
//MeshBall(< 0, 0, 0 >, 1, 50, 7)
//MeshPlanet(< 0, 0, 0 >, 1, 200, 100, 456123, 0.005, 150)
MeshPlanet(< 0, 0, 0>, 1, 100, 50, 456123, 0.005, 20)
   texture {T_White}
// rotate x*180
}
//*******************************************

light_source {<-20, 45,-50> color White}

//-------------------------------------------

-- 
Chris Huff
e-mail: chr### [at] yahoocom
Web page: http://chrishuff.dhs.org/


Post a reply to this message

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