//--------------------------------------------------------------------------- //------------------------ ObjectToDF3Example.pov --------------------------- //--------------------------------------------------------------------------- global_settings { assumed_gamma 1.0000 ambient_light srgb <1.0000,1.0000,1.0000> } #declare Swamp = srgbft <0.0000,0.1059,0.1098,0.0000,0.0000>; background { color Swamp } #declare Camera00 = camera { perspective location <2.5000,2.5000,-2.5010> sky <0.0000,1.0000,0.0000> angle 35.0000 right x*(image_width/image_height) look_at <0.5000,0.5000,0.5000> } #declare White = srgbft <1.0000,1.0000,1.0000,0.0000,0.0000>; #declare Light00 = light_source { <50.0000,150.0000,50.0000>, White } #declare Red = srgbft <1.0000,0.0000,0.0000,0.0000,0.0000>; #declare CylinderX = cylinder { <0.0000,0.0000,0.0000>, <1.0000,0.0000,0.0000>, 0.0100 pigment { color Red } } #declare Green = srgbft <0.0000,1.0000,0.0000,0.0000,0.0000>; #declare CylinderY = cylinder { <0.0000,0.0000,0.0000>, <0.0000,1.0000,0.0000>, 0.0100 pigment { color Green } } #declare Blue = srgbft <0.0000,0.0000,1.0000,0.0000,0.0000>; #declare CylinderZ = cylinder { <0.0000,0.0000,0.0000>, <0.0000,0.0000,1.0000>, 0.0100 pigment { color Blue } } #declare BoxRed = box { <0.1500,0.4500,0.1500>,<0.2500,0.5500,0.2500> pigment { color Red } } #declare BoxGreen = box { <0.3500,0.4500,0.3500>,<0.4500,0.5500,0.4500> pigment { color Green } } #declare BoxBlue = box { <0.5500,0.4500,0.5500>,<0.6500,0.5500,0.6500> pigment { color Blue } } #include "arrays.inc" #macro MacroSetVoxelsToColorByUnitObject (Obj_,Ary_,RangeX_,RangeY_,RangeZ_,MapIndex_) //---------------------------------------------------------------------------------- //- The loop through all vertices method here is not fast, but it seems to work OK. //--- // Notes on DF3 files in general no matter how used. Perhaps someday I'll have the // time to put together a tutorial with images. Perhaps others know them, but I // found each the hard way & perhaps one or more explain why folks sometimes // struggle with DF3 files. // // 1) Today we have 3 DF3 density file interpolation techniques 0,1 and 2. // 0=NO_INTERPOLATION, 1=TRILINEAR_INTERPOLATION and 2=TRICUBIC_INTERPOLATION. // - The 0 interpolation type is voxel centered. // - The 1 & 2 types are vertice centered, shifting everything lower 1/2 vozel. // - If mixing the two types this is sometimes important to understand, // especially with smaller DF3 files where the shift is relatively more // substantial. Functions in isosurfaces or patterns can re-align. // 2) Interpolation type 2 rings / wobbles when there are any surface protrusions // or say a plane of one value with a larger or smaller value inserted in that // plane. If using type 2 for anything you want to be numerically stable, use // multiple single value coincident DF3 files. I tend not to use option 2. // a) If the ring goes below 0 or above 1 it gets clamped at 0 or 1. // // 3) Keep your DF3 data away from the array edges for interpolation types 1 & 2. // - Both techniques implement edge wrapping / handling which mangle things // neart the DF3 edges. // - I'm now adding a buffer of 5 voxels around meaningful inner values. // #local IdxZ = 0; #while (IdxZ < RangeZ_) #local IdxY = 0; #while (IdxY < RangeY_) #local IdxX = 0; #while (IdxX < RangeX_) #local ValX = IdxX/RangeX_; #local ValY = IdxY/RangeY_; #local ValZ = IdxZ/RangeZ_; #if (inside(Obj_,)) #declare Ary_[IdxX][IdxY][IdxZ] = MapIndex_; #else #ifndef (Ary_[IdxX][IdxY][IdxZ]) #declare Ary_[IdxX][IdxY][IdxZ] = 0; #end #end #local IdxX = IdxX + 1; #end #local IdxY = IdxY + 1; #end #local IdxZ = IdxZ + 1; #end #end #macro MacroSetDefinedVoxelsToOneStrength (Ary_,RangeX_,RangeY_,RangeZ_,Strength_) #local IdxZ = 0; #while (IdxZ < RangeZ_) #local IdxY = 0; #while (IdxY < RangeY_) #local IdxX = 0; #while (IdxX < RangeX_) #local ValX = IdxX/RangeX_; #local ValY = IdxY/RangeY_; #local ValZ = IdxZ/RangeZ_; #if (Ary_[IdxX][IdxY][IdxZ]>0) #declare Ary_[IdxX][IdxY][IdxZ] = Strength_; #end #local IdxX = IdxX + 1; #end #local IdxY = IdxY + 1; #end #local IdxZ = IdxZ + 1; #end #end #macro MacroCreateDF3FilePairs (ColorDF3_,ShapeDF3_,RangeX_,RangeY_,RangeZ_) #declare TmpAray = array[VarRangeX][VarRangeY][VarRangeZ] //---------------------------------------------------------------------------------- //- The df3 map value for a particular color ( 0.0 to 1.0 ) -------------------+ //- The df3 3D sizes ----------------------------------+-------+-------+ | //- Objects def colors for df3 map ---+ | | | | // | | | | | MacroSetVoxelsToColorByUnitObject(BoxRed, TmpAray,RangeX_,RangeY_,RangeZ_,0.2500) MacroSetVoxelsToColorByUnitObject(BoxGreen,TmpAray,RangeX_,RangeY_,RangeZ_,0.5000) MacroSetVoxelsToColorByUnitObject(BoxBlue, TmpAray,RangeX_,RangeY_,RangeZ_,0.7500) //---- Repeat above lines for as many colors as you have in the map. Last color //---- shape wins if color objects collide. Use Merge multi-csg object. ARRAYS_WriteDF3(TmpAray,ColorDF3_,8) //---------------------------------------------------------------------------------- //- Create the shape df3 at one constant value if using shape * color pattern approach. MacroSetDefinedVoxelsToOneStrength(TmpAray,RangeX_,RangeY_,RangeZ_,0.9000) ARRAYS_WriteDF3(TmpAray,ShapeDF3_,8) //---------------------------------------------------------------------------------- #undef TmpAray #end #declare VarRangeX = 110; #declare VarRangeY = 110; #declare VarRangeZ = 110; MacroCreateDF3FilePairs("color.df3","shape.df3",VarRangeX,VarRangeY,VarRangeZ) //------ Top level scene items ------ camera { Camera00 } light_source { Light00 } object { CylinderX } object { CylinderY } object { CylinderZ } object { BoxRed } object { BoxGreen } object { BoxBlue }