|
|
Mick Hazelgrove wrote:
> Hi
>
> > Can you please give an example on how to call your macro or/and
> > explain the parameters. Then it will be easier to debug your code.
>
> OK here's the full version. I was trying to save space. Pic in p.b.a.
> ...
I have now had a look at your code. And I'm not quite sure what you're after.
But you could try to replace this:
#local EPt=vaxis_rotate(<NM.x,NM.y+(segLength*SF)*Dim,NM.z>,RVec,RotX);
with this:
#local EPt =
vaxis_rotate(<NM.x, NM.y + segLength*SF, NM.z>*Dim, RVec, RotX);
I have also tried to optimize your code a little bit. See code below.
(I tried to pass the file-handle as a parameter parameter from the
MakeBlade macro to the MakePatch macro, but this did not
seem to work. Does anyone have any ideas about this ?)
Btw.:
Are there any reasons for why you're applying the texture in the
MakeBlade macro and not in the MakePatch macro or in the
final object statement ?
Regards,
Tor Olav
--
mailto:tor### [at] hotmailcom
http://www.crosswinds.net/~tok/tokrays.html
// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
#version 3.1;
#include "colors.inc"
#include "textures.inc"
global_settings { ambient_light 1.5 }
// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
// Macros that do not use a file
#macro MakeBlade1(XRot, YRot, SegmLength, NoSegs,
XPos, ZPos, SF, Dim, BladeW, FoldDepth, BladeTexture)
#local pO1 = SF*vrotate(XPos*x + BladeW*x, YRot*y);
#local pOM = SF*vrotate(XPos*x + FoldDepth*z, YRot*y);
#local pO2 = SF*vrotate(XPos*x - BladeW*x, YRot*y);
#local vRot = vnormalize(pO1 - pO2);
#local vGr = SF*SegmLength*y;
#local Cnt = 0;
#while (Cnt < NoSegs)
#local pN1 = Dim*vaxis_rotate(pO1 + vGr, vRot, XRot);
#local pNM = Dim*vaxis_rotate(pOM + vGr, vRot, XRot);
#local pN2 = Dim*vaxis_rotate(pO2 + vGr, vRot, XRot);
triangle { pOM, pO1, pN1 texture { BladeTexture } }
triangle { pOM, pNM, pN1 texture { BladeTexture } }
triangle { pOM, pO2, pN2 texture { BladeTexture } }
triangle { pOM, pNM, pN2 texture { BladeTexture } }
#local pO1 = pN1;
#local pOM = pNM;
#local pO2 = pN2;
#local Cnt = Cnt + 1;
#end // while
#local pEM = Dim*vaxis_rotate(pNM + vGr, vRot, XRot);
triangle { pOM, pO1, pEM texture { BladeTexture } }
triangle { pOM, pO2, pEM texture { BladeTexture } }
#end // macro MakeBlade1
#macro MakePatch1(XnBlades, ZnBlades, Spacing,
NoSegs, SegmLength, XRot,
Dim, BladeW, FoldDepth, Seed, GrassTexture)
#local RdN = seed(Seed);
#local XCnt = -ZnBlades;
#while(XCnt < XnBlades)
#local ZCnt = -XnBlades;
#while (ZCnt < ZnBlades)
#local XRot = XRot + rand(RdN)/10;
#local YRot = rand(RdN)*360;
#local SF = rand(RdN);
MakeBlade1(XRot, YRot,
SegmLength, NoSegs,
XCnt*Spacing, ZCnt*Spacing,
SF, Dim, BladeW, FoldDepth,
GrassTexture)
#local ZCnt = ZCnt + 1;
#end // while
#local XCnt = XCnt + 1;
#end // while
#end // macro MakePatch1
// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
// Macros that do use a file
#macro MakeBlade2(XRot, YRot, SegmLength, NoSegs,
XPos, ZPos, SF, Dim, BladeW, FoldDepth)
#local pO1 = SF*vrotate(XPos*x + BladeW*x, YRot*y);
#local pOM = SF*vrotate(XPos*x + FoldDepth*z, YRot*y);
#local pO2 = SF*vrotate(XPos*x - BladeW*x, YRot*y);
#local vRot = vnormalize(pO1 - pO2);
#local vGr = SF*SegmLength*y;
#local Str1 = " triangle { "
#local Str2 = "texture { GrassTex } }\n"
#local Cnt = 0;
#while (Cnt < NoSegs)
#local pN1 = Dim*vaxis_rotate(pO1 + vGr, vRot, XRot);
#local pNM = Dim*vaxis_rotate(pOM + vGr, vRot, XRot);
#local pN2 = Dim*vaxis_rotate(pO2 + vGr, vRot, XRot);
#write (FileHandle, Str1, pOM, ", ", pO1, ", ", pN1, Str2)
#write (FileHandle, Str1, pOM, ", ", pNM, ", ", pN1, Str2)
#write (FileHandle, Str1, pOM, ", ", pO2, ", ", pN2, Str2)
#write (FileHandle, Str1, pOM, ", ", pNM, ", ", pN2, Str2)
#local pO1 = pN1;
#local pOM = pNM;
#local pO2 = pN2;
#local Cnt = Cnt + 1;
#end // while
#local pEM = Dim*vaxis_rotate(pNM + vGr, vRot, XRot);
#write (FileHandle, Str1, pOM, ", ", pO1, ", ", pEM, Str2)
#write (FileHandle, Str1, pOM, ", ", pO2, ", ", pEM, Str2)
#end // macro MakeBlade2
#macro MakePatch2(XnBlades, ZnBlades, Spacing,
NoSegs, SegmLength, XRot,
Dim, BladeW, FoldDepth, Seed, FileName)
#fopen FileHandle FileName write
#write (FileHandle, "mesh {\n")
#local RdN = seed(Seed);
#local XCnt = -ZnBlades;
#while (XCnt < XnBlades)
#local ZCnt = -XnBlades;
#while (ZCnt < ZnBlades)
#local XRot = XRot + rand(RdN)/10;
#local YRot = rand(RdN)*360;
#local SF = rand(RdN);
MakeBlade2(XRot, YRot,
SegmLength, NoSegs,
XCnt*Spacing, ZCnt*Spacing,
SF, Dim, BladeW, FoldDepth)
#local ZCnt = ZCnt + 1;
#end // while
#local XCnt = XCnt + 1;
#end // while
#write (FileHandle, "}\n")
#fclose FileHandle
#end // macro MakePatch2
// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
// Do it without a file
#declare YellowGrass =
mesh {
MakePatch1(
3, // Horizontal(X) number of blades in Patch
5, // Horizontal(Z) number of blades in Patch
3, // Spacing between blades, default 3
10, // Number of segments in blade
3, // Length of blade segment
5, // Rotation of Blade in degrees, default 2
0.9125 // Amount by which blade gets thinner towards end
0.7, // Blade start width
0.75, // Depth of fold
217, // Random seed
texture { pigment { color Yellow } }
)
}
// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
// Do it with a file
#declare GrassTex =
texture {
normal {
bozo 0.01
scale <0.1, 5.0, 0.1>
scallop_wave
}
pigment { color Green }
finish {
specular 1
roughness 0.01
}
}
#declare GrassFileName = "GMF.inc"
MakePatch2(
3, // Horizontal(X) number of blades in Patch
5, // Horizontal(Z) number of blades in Patch
3, // Spacing between blades,default 3
10, // Number of segments in blade
3, // Length of blade segment
5, // Rotation of Blade in degrees, default 2
0.9125 // Amount by which blade gets thinner towards end
0.7, // Blade start width
0.75, // Depth of fold
1549, // Random seed
GrassFileName
)
#declare GreenGrass =
object {
#include GrassFileName
scale <3, 4, 3>/4
}
// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
// Put it all together
object { YellowGrass translate 10*x }
object { GreenGrass translate -12*x }
plane { y, 0 pigment { Tan } }
sky_sphere {
pigment {
gradient y
color_map {
[ 0 color Blue*0.6 ]
[ 1 color White ]
}
}
}
light_source { 30*<-1, 1, -1> color White }
camera {
location <0, 1, -10>*5
direction 3/2*z
right 4/3*x
look_at <0, 5, 0>
}
// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
Post a reply to this message
|
|