7 Tooltip: 'Vector Rendering Method Export Script'
12 from Blender import Scene, Object, Lamp, Camera
14 from Blender.Window import *
15 from Blender.Scene import Render
21 renderDir = context.getRenderPath()
24 # distance from camera Z'
25 def Distance(PX,PY,PZ):
27 dist = sqrt(PX*PX+PY*PY+PZ*PZ)
34 def RotatePoint(PX,PY,PZ,AngleX,AngleY,AngleZ):
38 NewY = (PY * cos(AngleX))-(PZ * sin(AngleX))
39 NewZ = (PZ * cos(AngleX))+(PY * sin(AngleX))
43 NewZ = (PZ * cos(AngleY))-(PX * sin(AngleY))
44 NewX = (PX * cos(AngleY))+(PZ * sin(AngleY))
48 NewX = (PX * cos(AngleZ))-(PY * sin(AngleZ))
49 NewY = (PY * cos(AngleZ))+(PX * sin(AngleZ))
55 def flatern(vertx, verty, vertz):
57 cam = Camera.get() # Get the cameras in scene
58 Lens = cam[0].getLens() # The First Blender camera lens
60 camTyp = cam[0].getType()
62 msize = (context.imageSizeX(), context.imageSizeY())
63 xres = msize[0] # X res for output
64 yres = msize[1] # Y res for output
72 fov = atan(ratio * 16.0 / Lens) # Get fov stuff
73 dist = xres/2*tan(fov) # Calculate dist from pinhole camera to image plane
74 #----------------------------
75 # calculate x'=dist*x/z & y'=dist*x/z
76 #----------------------------
77 screenxy[0]=int(xres/2+4*x*dist/z)
78 screenxy[1]=int(yres/2+4*y*dist/z)
83 for i in range(0, ob[0]+1):
91 scena = Scene.GetCurrent()
92 context = scena.getRenderingContext()
99 lice = [3,tacka,tacka,tacka,tacka]
101 msize = (context.imageSizeX(), context.imageSizeY())
104 file=open("proba.svg","w")
106 file.write("<svg width=\"" + `msize[0]` + "\" height=\"" + `msize[1]` + "\"\n")
107 file.write("xmlns=\"http://www.w3.org/2000/svg\" version=\"1.2\" streamable=\"true\">\n")
108 #file.write("<pageSet>\n")
110 Objects = Blender.Object.Get()
111 NUMobjects = len(Objects)
113 startFrm = context.startFrame()
115 #endFrm = context.endFrame()
116 camera = scena.getCurrentCamera() # Get the current camera
118 for f in range(startFrm, endFrm+1):
119 #scena.currentFrame(f)
120 Blender.Set('curframe', f)
122 DrawProgressBar (f/(endFrm+1-startFrm),"Rendering ..." + str(context.currentFrame()))
124 print "Frame: ", f, "\n"
125 if startFrm <> endFrm: file.write("<g id=\"Frame" + str(f) + "\" style=\"visibility:hidden\">\n")
126 for o in range(NUMobjects):
128 if Objects[o].getType() == "Mesh":
130 obj = Objects[o] # Get the first selected object
131 objname = obj.name # The object name
134 OBJmesh = obj.getData() # Get the mesh data for the object
135 numfaces=len(OBJmesh.faces) # The number of faces in the object
136 numEachVert=len(OBJmesh.faces[0]) # The number of verts in each face
139 # Get the Material Colors
141 # MATinfo = OBJmesh.getMaterials()
143 # if len(MATinfo) > 0:
144 # RGB=MATinfo[0].rgbCol
148 # color=`R`+"."+`G`+"."+`B`
151 # color="100.100.100"
157 for face in range(numfaces):
158 numvert = len(OBJmesh.faces[face])
159 objekat.append(numvert)
164 a.append(OBJmesh.faces[face][0][0])
165 a.append(OBJmesh.faces[face][0][1])
166 a.append(OBJmesh.faces[face][0][2])
167 a = RotatePoint(a[0], a[1], a[2], obj.RotX, obj.RotY, obj.RotZ)
168 a[0] += obj.LocX - camera.LocX
169 a[1] += obj.LocY - camera.LocY
170 a[2] += obj.LocZ - camera.LocZ
172 b.append(OBJmesh.faces[face][1][0])
173 b.append(OBJmesh.faces[face][1][1])
174 b.append(OBJmesh.faces[face][1][2])
175 b = RotatePoint(b[0], b[1], b[2], obj.RotX, obj.RotY, obj.RotZ)
176 b[0] += obj.LocX - camera.LocX
177 b[1] += obj.LocY - camera.LocY
178 b[2] += obj.LocZ - camera.LocZ
180 c.append(OBJmesh.faces[face][numvert-1][0])
181 c.append(OBJmesh.faces[face][numvert-1][1])
182 c.append(OBJmesh.faces[face][numvert-1][2])
183 c = RotatePoint(c[0], c[1], c[2], obj.RotX, obj.RotY, obj.RotZ)
184 c[0] += obj.LocX - camera.LocX
185 c[1] += obj.LocY - camera.LocY
186 c[2] += obj.LocZ - camera.LocZ
189 norm[0] = (b[1] - a[1])*(c[2] - a[2]) - (c[1] - a[1])*(b[2] - a[2])
190 norm[1] = -((b[0] - a[0])*(c[2] - a[2]) - (c[0] - a[0])*(b[2] - a[2]))
191 norm[2] = (b[0] - a[0])*(c[1] - a[1]) - (c[0] - a[0])*(b[1] - a[1])
193 d = norm[0]*a[0] + norm[1]*a[1] + norm[2]*a[2]
196 file.write("<polygon points=\"")
197 for vert in range(numvert):
203 if vert != 0: file.write(", ")
205 vertxyz.append(OBJmesh.faces[face][vert][0])
206 vertxyz.append(OBJmesh.faces[face][vert][1])
207 vertxyz.append(OBJmesh.faces[face][vert][2])
211 vertxyz = RotatePoint(vertxyz[0], vertxyz[1], vertxyz[2], obj.RotX, obj.RotY, obj.RotZ)
213 vertxyz[0] += obj.LocX - camera.LocX
214 vertxyz[1] += obj.LocY - camera.LocY
215 vertxyz[2] += obj.LocZ - camera.LocZ
219 vertxyz = RotatePoint(vertxyz[0], vertxyz[1], vertxyz[2], -camera.RotX, -camera.RotY, -camera.RotZ)
221 objekat.append(Distance(vertxyz[0], vertxyz[1], vertxyz[2]))
222 # dist = Distance(vertxyz[0], vertxyz[1], vertxyz[2])
223 xy = flatern(vertxyz[0], vertxyz[1], vertxyz[2])
228 # add/sorting in Z' direction
229 #Dodaj(px,py,Distance(vertxyz[0], vertxyz[1], vertxyz[2]))
230 file.write(`px` + ", " + `py`)
233 vektori = (norm[0]*svetlo[0]+norm[1]*svetlo[1]+norm[2]*svetlo[2])
234 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)))
235 intensity = floor(ambient + 255 * acos(vektori/vduzine))
236 print vektori/vduzine
237 if intensity < 0: intensity = 0
238 file.write("\"\n style=\"fill:rgb("+str(intensity)+","+str(intensity)+","+str(intensity)+");stroke:rgb(0,0,0);stroke-width:1\"/>\n")
239 if startFrm <> endFrm:
240 file.write("<animate attributeName=\"visibility\" begin=\""+str(f*0.08)+"s\" dur=\"0.08s\" fill=\"remove\" to=\"visible\">\n")
241 file.write("</animate>\n")
249 DrawProgressBar (1.0,"Finished.")