|
![](/i/fill.gif) |
Hi everybody!!
At lunch time today I made this little macro that may help to better bound
some objects. The macro is embeded in a sample scene. Perhaps it can be of
some convenience ...
Regards
Bruno
// Persistence of Vision Ray Tracer Scene Description File
// File: bbox.pov
// Vers: 3.5
// Desc: bbox macro sample scene
// Date: March 2007
// Auth: Bruno Cabasson
//
#version 3.5;
#include "colors.inc"
#include "functions.inc"
global_settings {
assumed_gamma 1.0
}
// ----------------------------------------
camera {
location <0.0, 2, -4.0>
direction 1.5*z
right x*image_width/image_height
look_at <0.0, 0.5, 0.0>
}
sky_sphere {
pigment {
gradient y
color_map {
[0.0 rgb <0.6,0.7,1.0>]
[0.7 rgb <0.0,0.1,0.8>]
}
}
}
light_source {
<0, 0, 0> // light's position (translated below)
color rgb <1, 1, 1> // light's color
translate <-30, 30, -30>*100
}
//
----------------------------------------------------------------------------
// bbox(_object, _corner_type, _corner_color, _edge_color, _face_color,
_draw_faces)
//
// Purpose: Draw the bounding box of an object. May help tuning bounded_by{}
for objects
// and for contained_by{} for isosurfaces.
//
// Parameters:
//
// _object: a #declared object you want to draw the bounding_box of
// _corner_type: shape og the corners: BBOX_CORNER_TYPE_SPHERE |
BBOX_CORNER_TYPE_SQUARE | BBOX_CORNER_TYPE_DIAMOND
// _corner_color: the color of the corners of the bounding box, normally
without transmit
// _corner_color: the color of the corners of the bounding box, normally
without transmit
// _edge_color: the color of the edges of the bounding box, normally without
transmit
// _face_color: the color of the faces of the bounding box, normally with
transmit
// _draw_faces: true if the faces are to be drawn, false otherwise
//
// Usage: For the object(s) under tuning, perform like the following
//
// Instead of: object {myThing transform {myTransform}} // myThing was
#decalre'd earlier
//
// Write : union
// {
// object {myThing}
// bbox(MyThing, BBOX_CORNER_TYPE_DIAMOND, Red, Green, color
Blue transmit 0.7, true)
// transform {myTransform}
// }
//
#declare BBOX_CORNER_TYPE_SPHERE = 0;
#declare BBOX_CORNER_TYPE_SQUARE = 1;
#declare BBOX_CORNER_TYPE_DIAMOND = 2;
#macro bbox(_object, _corner_type, _corner_color, _edge_color, _face_color,
_draw_faces)
#local _ret = union
{
#local _min = min_extent(_object);
#local _max = max_extent(_object);
#local _v = _max - _min;
#local _vx = _v.x;
#local _vy = _v.y;
#local _vz = _v.z;
#local _p = array[8];
#local _p[0] = _min;
#local _p[1] = _min + <_vx, 0, 0>;
#local _p[2] = _min + <_vx, 0, _vz>;
#local _p[3] = _min + <0, 0, _vz>;
#local _p[4] = _min + <0, _vy, 0>;
#local _p[5] = _min + <_vx, _vy, 0>;
#local _p[6] = _max;
#local _p[7] = _min + <0, _vy, _vz>;
// 8 corners
#local _d1 = max(max(_vx, _vy), max(_vy, _vz))/40;
#switch (_corner_type)
#case (BBOX_CORNER_TYPE_SPHERE)
#local _base_corner = sphere {0, _d1}
#break
#case (BBOX_CORNER_TYPE_SQUARE)
#local _base_corner = box {-_d1, _d1}
#break
#case (BBOX_CORNER_TYPE_DIAMOND)
#local _base_corner = isosurface {function
{abs(x)+abs(y)+abs(z) - _d1} max_gradient 4 contained_by {box{-1.05*_d1,
1.05*_d1}} scale sqrt(2)}
#break
#else
#local _base_corner = isosurface {function
{abs(x)+abs(y)+abs(z) - _d1} max_gradient 4 contained_by {box{-1.05*_d1,
1.05*_d1}} scale sqrt(2)}
#break
#end
#local i=0;
#while (i<dimension_size(_p, 1))
object {_base_corner pigment {color _corner_color} translate
_p[i]}
#local i=i+1;
#end
// 12 edges
#local _d2 = _d1/3;
cylinder {_p[0], _p[1], _d2 pigment{color _edge_color}}
cylinder {_p[1], _p[2], _d2 pigment{color _edge_color}}
cylinder {_p[2], _p[3], _d2 pigment{color _edge_color}}
cylinder {_p[3], _p[0], _d2 pigment{color _edge_color}}
cylinder {_p[4], _p[5], _d2 pigment{color _edge_color}}
cylinder {_p[5], _p[6], _d2 pigment{color _edge_color}}
cylinder {_p[6], _p[7], _d2 pigment{color _edge_color}}
cylinder {_p[7], _p[4], _d2 pigment{color _edge_color}}
cylinder {_p[0], _p[4], _d2 pigment{color _edge_color}}
cylinder {_p[1], _p[5], _d2 pigment{color _edge_color}}
cylinder {_p[2], _p[6], _d2 pigment{color _edge_color}}
cylinder {_p[3], _p[7], _d2 pigment{color _edge_color}}
// 6 faces
#if (_draw_faces)
polygon {4, _p[0], _p[1], _p[2], _p[3] pigment {color
_face_color}}
polygon {4, _p[4], _p[5], _p[6], _p[7] pigment {color
_face_color}}
polygon {4, _p[0], _p[1], _p[5], _p[4] pigment {color
_face_color}}
polygon {4, _p[1], _p[2], _p[6], _p[5] pigment {color
_face_color}}
polygon {4, _p[1], _p[2], _p[6], _p[5] pigment {color
_face_color}}
polygon {4, _p[3], _p[0], _p[4], _p[7] pigment {color
_face_color}}
#end
no_shadow
}
_ret // returned value is object{}-able
#end
//
----------------------------------------------------------------------------
plane {
y, -1
pigment { color rgb <0.7,0.5,0.3> }
}
#declare O_Sphere = sphere {
0.0, 1
texture {
pigment {
radial
frequency 8
color_map {
[0.00 color rgb <1.0,0.4,0.2> ]
[0.33 color rgb <0.2,0.4,1.0> ]
[0.66 color rgb <0.4,1.0,0.2> ]
[1.00 color rgb <1.0,0.4,0.2> ]
}
}
finish{
specular 0.6
}
}
rotate 45*x + 30*y
}
#declare O_Box = box {
-1, 1
texture {
pigment {
agate
color_map {
[0.00 color rgb <1.0,0.4,0.2> ]
[0.33 color rgb <0.2,0.4,1.0> ]
[0.66 color rgb <0.4,1.0,0.2> ]
[1.00 color rgb <1.0,0.4,0.2> ]
}
}
finish{
specular 0.6
}
}
scale 0.5
rotate 45*x + 30*y
}
// CSG
#declare O_SphereBox_union = union
{
object {O_Box translate -0.4*x}
object {O_Sphere translate 0.4*x}
//bounded_by {box{-1,1}} // improper manual bounding, let it be
automatic.
}
#declare O_SphereBox_difference = difference
{
object {O_Box translate -0.4*x}
object {O_Sphere translate 0.4*x}
}
#declare O_SphereBox_intersection = intersection
{
object {O_Box translate -0.4*x}
object {O_Sphere translate 0.4*x}
}
// Isosurface
#declare O_IsoBox = isosurface
{
#local _dims = <1,1/2,1/3>;
#local _dx = _dims.x;
#local _dy = _dims.y;
#local _dz = _dims.z;
function {f_rounded_box(x,y,z, 0.01, _dx/2, _dy/2, _dz/2) -
0.3*f_noise3d(x*3,y*3,z*3)}
max_gradient 2
contained_by {box{-2*_dims/2, 2*_dims/2}}
pigment {wrinkles scale 0.1}
scale 0.5
}
// Good automatic bounding
union
{
object {O_SphereBox_union}
bbox(O_SphereBox_union, BBOX_CORNER_TYPE_DIAMOND, Red, Green, color Red
transmit 0.8, true)
translate 5*z+y/2-2*x
}
// Improvable automatic bounding (too large, not well centered)
union
{
object {O_SphereBox_difference}
bbox(O_SphereBox_difference, BBOX_CORNER_TYPE_SQUARE, Red, Green, color
Green transmit 0.8, true)
translate 5*z+y/2+3*x
}
// Good automatic bounding
union
{
object {O_SphereBox_intersection}
bbox(O_SphereBox_intersection, BBOX_CORNER_TYPE_DIAMOND, Red, Green,
color Blue transmit 0.8, true)
translate z+y/2+x/2
}
// Improvable bounding (too large in x, too small in z)
union
{
object {O_IsoBox}
bbox(O_IsoBox, BBOX_CORNER_TYPE_SPHERE, Red, Green, color Yellow
transmit 0.8, true)
translate -z+y/2-0.7*x
}
Post a reply to this message
Attachments:
Download 'bbox.png' (200 KB)
Preview of image 'bbox.png'
![bbox.png](/povray.binaries.images/attachment/%3Cweb.46091dfb8c694744f5fba6ef0%40news.povray.org%3E/bbox.png?ttop=443866&toff=3900&preview=1)
|
![](/i/fill.gif) |