|
Package parasol ::
Module POV_Basics
|
|
1
2
5 if len(args) == 1:
6 self.v = args[0]
7 else:
8 self.v = args
10 return "<%s>"%(", ".join([str(x)for x in self.v]))
12 return "Vector(%s)"%self.v
14 return Vector( [r*other for r in self.v] )
16 return Vector( [r*other for r in self.v] )
17
19 - def __init__(self, pos=[0,0,-10], lookat=[0,0,0], ang=None, sky=None ):
20 self.pos = Vector( pos )
21 self.lookat = Vector( lookat )
22 self.sky = sky
23 self.angle = ang
24
26 self.lookat = Vector( lookatL )
27
28 - def setPos(self, posL=[10,10,-20]):
30
31 - def setSky(self, skyL=[0,1,0]):
33
36
38 sL = ['camera {location %s'%(str(self.pos))]
39
40 if self.sky:
41 sL.append('sky %s'% (str(self.sky)) )
42
43 if self.angle:
44 sL.append('angle %g'% self.angle )
45
46 sL.append('look_at %s}'% (str(self.lookat)) )
47 return ' '.join(sL)
48
50 - def __init__(self, colorName="Aquamarine", rgb=None, transmit=0.0, filter=0.0):
51 self.colorName = colorName
52 self.rgb = None
53 if rgb:
54 self.setRGB( rgb )
55
56 self.transmit = transmit
57 self.filter = filter
58
59 - def setRGB(self, rgbL=[0,1,0]):
60 self.rgb = Vector( rgbL )
61 self.colorName = None
62
64 self.colorName = colorName
65 self.rgb = None
66
68 if self.rgb:
69 return 'rgb %s'% (str(self.rgb)) + ' transmit %g filter %g '%(self.transmit, self.filter)
70 else:
71 return 'color %s'% (str(self.colorName)) + ' transmit %g filter %g '%(self.transmit, self.filter)
72
74 - def __init__(self, pos=[10,10,-50], colorName='White', shadowless=1 ):
75 self.pos = Vector( pos )
76 self.color = Color(colorName)
77 self.shadowless = shadowless
78
79 - def setRGB(self, rgbL=[0,1,0]):
81
84
86 sL = ['light_source { %s '%(str(self.pos))]
87
88 sL.append(str(self.color))
89
90 if self.shadowless:
91 sL.append('shadowless')
92
93 return ' '.join(sL) + '}'
94
95 -class Texture(object):
96 - def __init__(self, ambient=0.5, colorName="Aquamarine", rgb=None, name=None,
97 imageMapFile='',imageMapType=0, bumpSize=0.01, transmit=0.0, filter=0.0,
98 reflection=0.1):
99 self.ambient = ambient
100 self.color = Color(colorName, transmit=transmit, filter=filter)
101
102 self.reflection = reflection
103 self.name = name
104 self.rgb = None
105 self.bumpSize = bumpSize
106 if rgb:
107 self.setRGB( rgb )
108
109 self.setImageMap( imageMapFile,imageMapType)
110
111 - def setImageMap(self, file='', type=0):
112
113 self.imageMapFile = file
114 self.imageMapType = type
115 try:
116 sp = file.split('.')
117 self.imageMapFileFormat = sp[-1].lower()
118 except:
119 self.imageMapFileFormat = 'gif'
120
121 - def setRGB(self, rgbL=[0,1,0]):
122 self.color.setRGB( rgbL )
123
124 - def setColor(self, colorName="White"):
125 self.color.setColor( colorName )
126
128 if self.name:
129 sL = [' texture { %s \n'%self.name]
130 if self.ambient >= 0.0:
131 sL.append(' finish {\n')
132 sL.append(' ambient %g phong 0.8 phong_size 60 reflection %g\n'%(self.ambient,self.reflection))
133 sL.append(' }\n')
134
135
136 else:
137 sL = [' texture { \n']
138 if self.ambient >= 0.0:
139 sL.append(' finish {\n')
140 sL.append(' ambient %g phong 0.8 phong_size 60 reflection %g\n'%(self.ambient,self.reflection))
141 sL.append(' }\n')
142 sL.append(' pigment {\n')
143
144 if len(self.imageMapFile)>0:
145 sL.append(' image_map { %s "%s"\n'%(self.imageMapFileFormat, self.imageMapFile))
146 sL.append(' map_type %i}\n'%self.imageMapType )
147 else:
148 sL.append(' %s\n'% (str(self.color)) )
149
150 sL.append(' }\n')
151
152 if self.bumpSize != None:
153 sL.append(' normal{ bumps %g }\n'%self.bumpSize)
154 sL.append(' }')
155 return ' '.join(sL)
156
157 myMacros='''
158 global_settings {max_trace_level 7}
159
160 #macro ObjCenter(Object)
161 #local Mn = min_extent(Object);
162 #local Mx = max_extent(Object);
163
164 #local result = (Mx - Mn)/2 + Mn;
165 result
166 #end
167 #macro LocationForAngleD(Object, myAngleD, myMargin)
168 // myAngleD is full angle of view
169 // myMargin is a multiplier on the distance (normal = 1.1, ortho views need 1.5)
170 // camera is moved away from Object along negative z axis by distance d
171 #local Mn = min_extent(Object);
172 #local Mx = max_extent(Object);
173
174 #local sOvrd = tan( myAngleD*pi/180.0/2.0 );
175 #local Ds = (Mx - Mn)/2;
176 #local objC = (Mx - Mn)/2 + Mn;
177
178 // make maxDist in y direction (i.e. assume screen aspect ratio of 4/3
179 //#local maxDist = sqrt(Ds.x*Ds.x + Ds.y*Ds.y + Ds.z*Ds.z) * 4.0/3.0;
180 //#local d = maxDist/sOvrd;
181
182 // project object bounding box onto the z axis
183 #local zoffset = Mn.z;
184 #local Proj = VProject_Plane(Ds, <0,0,1> );
185 #local d = myMargin * ( max(Proj.x/sOvrd, Proj.y*4.0/sOvrd/3.0) ) - zoffset;
186
187 #local result = (<objC.x, objC.y, objC.z-d>);
188 result
189 #end
190 #macro LocationForLight1(Object, camLoc, N)
191 // myMargin is a multiplier on the distance (normal = 1.1, ortho views need 1.5)
192 // camera is moved away from Object along negative z axis by distance d
193 #local Mn = min_extent(Object);
194 #local Mx = max_extent(Object);
195
196 #local Ds = (Mx - Mn)/2;
197 #local maxDist = sqrt(Ds.x*Ds.x + Ds.y*Ds.y + Ds.z*Ds.z) ;
198 #local objC = (Mx - Mn)/2 + Mn;
199 #local objMid = (camLoc + objC) / 2.0;
200
201 #if (N=1)
202 #local result = (<camLoc.x-maxDist, camLoc.y-maxDist, camLoc.z-maxDist>);
203 #end
204 #if (N=2)
205 #local result = (<objMid.x-maxDist*20, objMid.y+maxDist*50.0, objMid.z-maxDist*20>);
206 #end
207 #if (N=3)
208 #local result = (<objMid.x+maxDist, objMid.y-maxDist, objMid.z+maxDist*20>);
209 #end
210 result
211 #end
212
213 '''
214
215 if __name__ == '__main__':
216
217 print Vector([1,2,3])
218