7 Tooltip: 'Vector Rendering Method Export Script'
12 from Blender import Scene, Object, Lamp, Camera
14 from Blender.Window import *
20 renderDir = scena.getRenderdir()
22 # distance from camera Z'
23 def Distance(PX,PY,PZ):
25 dist = sqrt(PX*PX+PY*PY+PZ*PZ)
32 def RotatePoint(PX,PY,PZ,AngleX,AngleY,AngleZ):
36 NewY = (PY * cos(AngleX))-(PZ * sin(AngleX))
37 NewZ = (PZ * cos(AngleX))+(PY * sin(AngleX))
41 NewZ = (PZ * cos(AngleY))-(PX * sin(AngleY))
42 NewX = (PX * cos(AngleY))+(PZ * sin(AngleY))
46 NewX = (PX * cos(AngleZ))-(PY * sin(AngleZ))
47 NewY = (PY * cos(AngleZ))+(PX * sin(AngleZ))
53 def flatern(vertx, verty, vertz):
55 cam = Camera.get() # Get the cameras in scene
56 Lens = cam[0].getLens() # The First Blender camera lens
58 camTyp = cam[0].getType()
60 msize = scena.getWinSize()
61 xres = msize[0] # X res for output
62 yres = msize[1] # Y res for output
70 fov = atan(ratio * 16.0 / Lens) # Get fov stuff
71 dist = xres/2*tan(fov) # Calculate dist from pinhole camera to image plane
72 #----------------------------
73 # calculate x'=dist*x/z & y'=dist*x/z
74 #----------------------------
75 screenxy[0]=int(xres/2+4*x*dist/z)
76 screenxy[1]=int(yres/2+4*y*dist/z)
81 for i in range(0, ob[0]+1):
89 scena = Scene.GetCurrent()
93 lice = [3,tacka,tacka,tacka,tacka]
95 msize = scena.getWinSize()
97 file=open("d:\proba.svg","w")
99 file.write("<svg width=\"" + `msize[0]` + "\" height=\"" + `msize[1]` + "\"\n")
100 file.write("xmlns=\"http://www.w3.org/2000/svg\" version=\"1.2\" streamable=\"true\">\n")
101 #file.write("<pageSet>\n")
103 Objects = Blender.Object.Get()
104 NUMobjects = len(Objects)
106 startFrm = scena.startFrame()
107 endFrm = scena.endFrame()
108 camera = scena.getCurrentCamera() # Get the current camera
110 for f in range(startFrm, endFrm+1):
111 #scena.currentFrame(f)
112 Blender.Set('curframe', f)
114 DrawProgressBar (f/(endFrm+1-startFrm),"Rendering ..." + str(scena.currentFrame()))
116 print "Frame: ", f, "\n"
117 if startFrm <> endFrm: file.write("<g id=\"Frame" + str(f) + "\" style=\"visibility:hidden\">\n")
118 for o in range(NUMobjects):
120 if Objects[o].getType() == "Mesh":
122 obj = Objects[o] # Get the first selected object
123 objname = obj.name # The object name
126 OBJmesh = obj.getData() # Get the mesh data for the object
127 numfaces=len(OBJmesh.faces) # The number of faces in the object
128 numEachVert=len(OBJmesh.faces[0]) # The number of verts in each face
131 # Get the Material Colors
133 # MATinfo = OBJmesh.getMaterials()
135 # if len(MATinfo) > 0:
136 # RGB=MATinfo[0].rgbCol
140 # color=`R`+"."+`G`+"."+`B`
143 # color="100.100.100"
149 for face in range(numfaces):
150 numvert = len(OBJmesh.faces[face])
151 objekat.append(numvert)
156 a.append(OBJmesh.faces[face][0][0])
157 a.append(OBJmesh.faces[face][0][1])
158 a.append(OBJmesh.faces[face][0][2])
159 a = RotatePoint(a[0], a[1], a[2], obj.RotX, obj.RotY, obj.RotZ)
160 a[0] += obj.LocX - camera.LocX
161 a[1] += obj.LocY - camera.LocY
162 a[2] += obj.LocZ - camera.LocZ
164 b.append(OBJmesh.faces[face][1][0])
165 b.append(OBJmesh.faces[face][1][1])
166 b.append(OBJmesh.faces[face][1][2])
167 b = RotatePoint(b[0], b[1], b[2], obj.RotX, obj.RotY, obj.RotZ)
168 b[0] += obj.LocX - camera.LocX
169 b[1] += obj.LocY - camera.LocY
170 b[2] += obj.LocZ - camera.LocZ
172 c.append(OBJmesh.faces[face][numvert-1][0])
173 c.append(OBJmesh.faces[face][numvert-1][1])
174 c.append(OBJmesh.faces[face][numvert-1][2])
175 c = RotatePoint(c[0], c[1], c[2], obj.RotX, obj.RotY, obj.RotZ)
176 c[0] += obj.LocX - camera.LocX
177 c[1] += obj.LocY - camera.LocY
178 c[2] += obj.LocZ - camera.LocZ
181 norm[0] = (b[1] - a[1])*(c[2] - a[2]) - (c[1] - a[1])*(b[2] - a[2])
182 norm[1] = -((b[0] - a[0])*(c[2] - a[2]) - (c[0] - a[0])*(b[2] - a[2]))
183 norm[2] = (b[0] - a[0])*(c[1] - a[1]) - (c[0] - a[0])*(b[1] - a[1])
185 d = norm[0]*a[0] + norm[1]*a[1] + norm[2]*a[2]
188 file.write("<polygon points=\"")
189 for vert in range(numvert):
195 if vert != 0: file.write(", ")
197 vertxyz.append(OBJmesh.faces[face][vert][0])
198 vertxyz.append(OBJmesh.faces[face][vert][1])
199 vertxyz.append(OBJmesh.faces[face][vert][2])
203 vertxyz = RotatePoint(vertxyz[0], vertxyz[1], vertxyz[2], obj.RotX, obj.RotY, obj.RotZ)
205 vertxyz[0] += obj.LocX - camera.LocX
206 vertxyz[1] += obj.LocY - camera.LocY
207 vertxyz[2] += obj.LocZ - camera.LocZ
211 vertxyz = RotatePoint(vertxyz[0], vertxyz[1], vertxyz[2], -camera.RotX, -camera.RotY, -camera.RotZ)
213 objekat.append(Distance(vertxyz[0], vertxyz[1], vertxyz[2]))
214 # dist = Distance(vertxyz[0], vertxyz[1], vertxyz[2])
215 xy = flatern(vertxyz[0], vertxyz[1], vertxyz[2])
220 # add/sorting in Z' direction
221 #Dodaj(px,py,Distance(vertxyz[0], vertxyz[1], vertxyz[2]))
222 file.write(`px` + ", " + `py`)
223 # svetla = Blender.Lamp.Get()
228 vektori = (norm[0]*svetlo[0]+norm[1]*svetlo[1]+norm[2]*svetlo[2])
229 vduzine = fabs(sqrt(pow(norm[0],2)+pow(norm[1],2)+pow(norm[2],2))*sqrt(pow(svetlo[0],2)+pow(svetlo[1],2)+pow(svetlo[2],2)))
230 intensity = floor(ambient + 255 * acos(vektori/vduzine))
231 print vektori/vduzine
232 if intensity < 0: intensity = 0
233 file.write("\"\n style=\"fill:rgb("+str(intensity)+","+str(intensity)+","+str(intensity)+");stroke:rgb(0,0,0);stroke-width:1\"/>\n")
234 if startFrm <> endFrm:
235 file.write("<animate attributeName=\"visibility\" begin=\""+str(f*0.08)+"s\" dur=\"0.08s\" fill=\"remove\" to=\"visible\">\n")
236 file.write("</animate>\n")
243 DrawProgressBar (1.0,"Finished.")