|
|
Christopher James Huff wrote:
> I don't know if you meant this, but that last paragraph implies that a
> mesh box would be unuseable in CSG. If he uses inside_vector, it will be
> useable for CSG operations.
Works quite well actually :)
-----------------------------------------------------------
// Macro for creating a basic box object using triangles
#macro Box_Mesh(Vec1,Vec2)
#if (Vec1.x=Vec2.x | Vec1.y=Vec2.y | Vec1.z=Vec2.z)
#debug "\n MeshBox detected identical vector values.\n" #end
#local P1=<Vec1.x, Vec1.y, Vec1.z>;
#local P2=<Vec2.x, Vec1.y, Vec1.z>;
#local P3=<Vec2.x, Vec1.y, Vec2.z>;
#local P4=<Vec1.x, Vec1.y, Vec2.z>;
#local P5=<Vec1.x, Vec2.y, Vec1.z>;
#local P6=<Vec2.x, Vec2.y, Vec1.z>;
#local P7=<Vec2.x, Vec2.y, Vec2.z>;
#local P8=<Vec1.x, Vec2.y, Vec2.z>;
mesh {
triangle { P5, P1, P2 texture {T1} }
triangle { P5, P6, P2 texture {T1} }
triangle { P6, P2, P3 texture {T2} }
triangle { P6, P7, P3 texture {T2} }
triangle { P7, P3, P4 texture {T3} }
triangle { P7, P8, P4 texture {T3} }
triangle { P8, P4, P1 texture {T4} }
triangle { P8, P5, P1 texture {T4} }
triangle { P8, P5, P6 texture {T5} }
triangle { P8, P7, P6 texture {T5} }
triangle { P4, P1, P2 texture {T6} }
triangle { P4, P3, P2 texture {T6} }
inside_vector <0, 0, 1>
}
#end
default { finish { ambient .4 diffuse .6 } }
#declare T1 = texture { pigment { rgb<1,0,0> }}
#declare T2 = texture { pigment { rgb<0,1,0> }}
#declare T3 = texture { pigment { rgb<0,0,1> }}
#declare T4 = texture { pigment { rgb<1,1,0> }}
#declare T5 = texture { pigment { rgb<1,0,1> }}
#declare T6 = texture { pigment { rgb<0,1,1> }}
// Usage
camera{location<-4,4,-4> look_at 0}
light_source{<-5,5,-5>rgb 1}
difference
{
Box_Mesh ( <-1,-1,-1>, <1,1,1> )
cylinder { z*-1.1, z*1.1, .75 pigment { rgb 1 }}
}
--
Ken Tyler
Post a reply to this message
|
|
|
|
Rafal 'Raf256' Maj <raf### [at] raf256com> wrote:
> so finaly - with method is the fastest ?
> maybe some union/merge/intersection of planes ?
I made a test with boxes made of planes, polygons and a mesh (with
differently colored sides) and compared their rendering speed
(-w800 -h600 +a0.1) by randomly placing 500 of them in the scene.
The render times were:
Planes: 75 s
Polygons: 80 s
Mesh: 63 s
Seems like the mesh wins.
This is the scene:
// 1: Planes
// 2: Polygons
// 3: Mesh
#declare BoxType = 1;
#declare Amount = 500;
#macro FixCorners(Corner1, Corner2)
#local X1 = Corner1.x; #local X2 = Corner2.x;
#local Y1 = Corner1.y; #local Y2 = Corner2.y;
#local Z1 = Corner1.z; #local Z2 = Corner2.z;
#if(X1 > X2) #local tmp = X1; #local X1 = X2; #local X2 = tmp; #end
#if(Y1 > Y2) #local tmp = Y1; #local Y1 = Y2; #local Y2 = tmp; #end
#if(Z1 > Z2) #local tmp = Z1; #local Z1 = Z2; #local Z2 = tmp; #end
#local Corner1 = <X1, Y1, Z1>;
#local Corner2 = <X2, Y2, Z2>;
#end
#macro PlaneBox(Corner1, Corner2, T1, T2, T3, T4, T5, T6)
#local C1 = Corner1+<0,0,0>;
#local C2 = Corner2+<0,0,0>;
FixCorners(C1, C2)
intersection
{
plane { -x, -C1.x texture { T1 } }
plane { x, C2.x texture { T2 } }
plane { -y, -C1.y texture { T3 } }
plane { y, C2.y texture { T4 } }
plane { -z, -C1.z texture { T5 } }
plane { z, C2.z texture { T6 } }
bounded_by { box { C1, C2 } }
}
#end
#macro PolygonBox(Corner1, Corner2, T1, T2, T3, T4, T5, T6)
#local C1 = Corner1+<0,0,0>;
#local C2 = Corner2+<0,0,0>;
FixCorners(C1, C2)
union
{
polygon
{ 5, C1, <C1.x, C1.y, C2.z>, <C1.x, C2.y, C2.z>, <C1.x, C2.y, C1.z>, C1
texture { T1 }
}
polygon
{ 5, C2, <C2.x, C2.y, C1.z>, <C2.x, C1.y, C1.z>, <C2.x, C1.y, C2.z>, C2
texture { T2 }
}
polygon
{ 5, C1, <C2.x, C1.y, C1.z>, <C2.x, C1.y, C2.z>, <C1.x, C1.y, C2.z>, C1
texture { T3 }
}
polygon
{ 5, C2, <C1.x, C2.y, C2.z>, <C1.x, C2.x, C1.z>, <C2.x, C2.y, C1.z>, C2
texture { T4 }
}
polygon
{ 5, C1, <C2.x, C1.y, C1.z>, <C2.x, C2.y, C1.z>, <C1.x, C2.y, C1.z>, C1
texture { T5 }
}
polygon
{ 5, C2, <C1.x, C2.y, C2.z>, <C1.x, C1.y, C2.z>, <C2.x, C1.y, C2.z>, C2
texture { T6 }
}
}
#end
#macro MeshBox(Corner1, Corner2, T1, T2, T3, T4, T5, T6)
#local C1 = Corner1+<0,0,0>;
#local C2 = Corner2+<0,0,0>;
FixCorners(C1, C2)
mesh2
{
vertex_vectors
{ 8,
C1, <C2.x, C1.y, C1.z>, <C2.x, C1.y, C2.z>, <C1.x, C1.y, C2.z>,
<C1.x, C2.x, C1.z>, <C2.x, C2.y, C1.z>, C2, <C1.x, C2.y, C2.z>
}
texture_list
{ 6,
texture { T1 }, texture { T2 }, texture { T3 },
texture { T4 }, texture { T5 }, texture { T6 }
}
face_indices
{ 6*2,
<0, 3, 7>, 0, <0, 7, 4>, 0,
<1, 5, 6>, 1, <1, 6, 2>, 1,
<0, 1, 2>, 2, <0, 2, 3>, 2,
<4, 7, 6>, 3, <4, 6, 5>, 3,
<0, 4, 5>, 4, <0, 5, 1>, 4,
<3, 2, 6>, 5, <3, 6, 7>, 5
}
}
#end
camera { location <4,10,-20>*2 look_at 0 angle 35 }
light_source { <100,200,-150>, 1 }
#declare T = array[6]
{
pigment { rgb 1 },
pigment { rgb x },
pigment { rgb y },
pigment { rgb z },
pigment { rgb x+y },
pigment { rgb y+z },
}
#declare Box =
#switch(BoxType)
#case(1)
PlaneBox(-1, 1, T[0], T[1], T[2], T[3], T[4], T[5])
#break
#case(2)
PolygonBox(-1, 1, T[0], T[1], T[2], T[3], T[4], T[5])
#break
#case(3)
MeshBox(-1, 1, T[0], T[1], T[2], T[3], T[4], T[5])
#break
#end
#declare S = seed(1);
#declare Ind = 0;
#while(Ind < Amount)
object
{ Box
rotate <rand(S)*360, rand(S)*360, rand(S)*360>
translate (<rand(S),.5,rand(S)>-.5)*50
}
#declare Ind = Ind+1;
#end
--
#macro N(D)#if(D>99)cylinder{M()#local D=div(D,104);M().5,2pigment{rgb M()}}
N(D)#end#end#macro M()<mod(D,13)-6mod(div(D,13)8)-3,10>#end blob{
N(11117333955)N(4254934330)N(3900569407)N(7382340)N(3358)N(970)}// - Warp -
Post a reply to this message
|
|