POV-Ray : Newsgroups : povray.binaries.images : isoBox macro : isoBox macro Server Time
5 Nov 2024 08:24:32 EST (-0500)
  isoBox macro  
From: Ross
Date: 17 Nov 2006 15:13:36
Message: <455e17f0@news.povray.org>
In a scene I am working on, I am building it up with just plain primitive
boxes but when I have the layout all done, I'd like to make them isosurfaces
so I can deform them with noise or pigment functions. I couldn't figure out
an easier way than make a macro that takes the same vectors that define the
box, plus some other parameters, resulting in an isosurface.

This may not be usefull for anyone else but me (meaning, it works on the
scale I'm working with, your results may vary... and it's not tested
heavily), but here's the macro and sample output.


// requires the standard f_rounded_box function
#include "functions.inc"

#macro isoBox (vB1, vB2, fRad, vT1, fDeform, fDeformMagnitude, fAccuracy,
fMaxGradient)
// Paramters:
// vB1 = box vector 1
// vB2 = box vector 2
// fRad = radius for f_rounded_box
// vT1 = deformation translate vector (moves the function away from the
origin)
// fDeform = function to deform the box by
// fDeformMagnitude = scale factor for the deformation function
// fAccuracy = isosurface accuracy
// fMaxGradient = isosurface max_gradient

 // X, Y, Z are scales for f_rounded_box
 #local X = abs(vB1.x - vB2.x);
 #local Y = abs(vB1.y - vB2.y);
 #local Z = abs(vB1.z - vB2.z);

 // translate the box so it's back where the
 // box vectors would place it (f_rounded_box
 // places it at the origin it seems)
 #local tX = (vB1.x + vB2.x) / 2;
 #local tY = (vB1.y + vB2.y) / 2;
 #local tZ = (vB1.z + vB2.z) / 2;
 #local vTranslate = <tX, tY, tZ>;

 // amount to translate the deform function by
 #local dX = vT1.x;
 #local dY = vT1.y;
 #local dZ = vT1.z;

 // possibly make this a vector passed as a parameter
 // so that each componant can be applied separatelt.
 // not sure what to call it, but I use it to smooth out
 // the resulting isosurface.
 #local dSmooth = 0.33;

 isosurface {
  function {
    f_rounded_box(x, y, z, fRad, X/2, Y/2, Z/2)-
    fDeform( (x+dX)*dSmooth, (y+dY)*dSmooth,
(z+dZ)*dSmooth).x*fDeformMagnitude
  }

  // this contained_by seems adequate for my needs.
  contained_by { box { -(max(X, Y, Z)-fRad*2), max(X, Y, Z)+fRad*2 } }
  accuracy fAccuracy
  max_gradient fMaxGradient

  translate vTranslate
 }
#end

// example usage:
#declare fnPig2 = function {
 pigment {
  cells
  color_map {
   [0.0 rgb 0.0]
   [0.3 rgb 1.0]
   [0.7 rgb 0.8]
   [0.9 rgb 0.3]
  }
  scale <1, 1, 1> * 0.0085
 }
}

object {
    isoBox(
      <0.085, .085*2, 0.085>,
      <-0.085, 0, -0.085>, 0.005
      <0, 0, 0>,
      fnPig2, 0.01285, 0.001, 4)
 pigment {rgb 0.8}
}


Post a reply to this message


Attachments:
Download 'isobox3.png' (29 KB)

Preview of image 'isobox3.png'
isobox3.png


 

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