From: Antonio Ospite Date: Thu, 23 Mar 2006 14:47:08 +0000 (+0100) Subject: Fix and reindent th main loop X-Git-Tag: vrm-0.2 X-Git-Url: https://git.ao2.it/vrm.git/commitdiff_plain/cb334b8afdb1d2133db56e1c5f22e0d5b999f42a Fix and reindent th main loop Signed-off-by: Antonio Ospite --- diff --git a/vrm.py b/vrm.py index bbff105..726c83d 100755 --- a/vrm.py +++ b/vrm.py @@ -7,19 +7,12 @@ Group: 'Export' Tooltip: 'Vector Rendering Method Export Script' """ - import Blender from Blender import Scene, Object, Lamp, Camera from math import * from Blender.Window import * from Blender.Scene import Render - -def init(): - - print "Init\n" - renderDir = context.getRenderPath() - # distance from camera Z' def Distance(PX,PY,PZ): @@ -27,10 +20,6 @@ def Distance(PX,PY,PZ): dist = sqrt(PX*PX+PY*PY+PZ*PZ) return dist -def Dodaj(x,y,z): - - print "" - def RotatePoint(PX,PY,PZ,AngleX,AngleY,AngleZ): NewPoint = [] @@ -52,6 +41,16 @@ def RotatePoint(PX,PY,PZ,AngleX,AngleY,AngleZ): NewPoint.append(NewZ) return NewPoint +def vetmatmult(v, M): + + v2 = [0, 0, 0, 0] + + for i in range(0, 3): + for j in range(0, 3): + v2[i] += (v[i]*M[i][j]) + + return v2 + def flatern(vertx, verty, vertz): cam = Camera.get() # Get the cameras in scene @@ -64,25 +63,22 @@ def flatern(vertx, verty, vertz): yres = msize[1] # Y res for output ratio = xres/yres + fov = atan(ratio * 16.0 / Lens) # Get fov stuff + + dist = xres/2*tan(fov) # Calculate dist from pinhole camera to image plane + screenxy=[0,0] x=-vertx y=verty z=vertz - fov = atan(ratio * 16.0 / Lens) # Get fov stuff - dist = xres/2*tan(fov) # Calculate dist from pinhole camera to image plane -#---------------------------- -# calculate x'=dist*x/z & y'=dist*x/z -#---------------------------- - screenxy[0]=int(xres/2+4*x*dist/z) - screenxy[1]=int(yres/2+4*y*dist/z) + #---------------------------- + # calculate x'=dist*x/z & y'=dist*x/z + #---------------------------- + screenxy[0]=int(xres/2.0+4*x*dist/z) + screenxy[1]=int(yres/2.0+4*y*dist/z) return screenxy -def writesvg(ob): - - for i in range(0, ob[0]+1): - print ob[i], "\n" - print "WriteSVG\n" ######## # Main # @@ -90,21 +86,15 @@ def writesvg(ob): scena = Scene.GetCurrent() context = scena.getRenderingContext() - -#print dir(context) - -init() - -tacka = [0,0,0] -lice = [3,tacka,tacka,tacka,tacka] +renderDir = context.getRenderPath() msize = (context.imageSizeX(), context.imageSizeY()) -print msize file=open("proba.svg","w") +file.write("\n") file.write("\n") +file.write("\txmlns=\"http://www.w3.org/2000/svg\" version=\"1.2\" streamable=\"true\">\n") #file.write("\n") Objects = Blender.Object.Get() @@ -113,138 +103,144 @@ NUMobjects = len(Objects) startFrm = context.startFrame() endFrm = startFrm #endFrm = context.endFrame() +frames = range(startFrm, endFrm+1) + +# are we rendering an animation ? +animation = (len(frames) > 1) + camera = scena.getCurrentCamera() # Get the current camera -for f in range(startFrm, endFrm+1): - #scena.currentFrame(f) - Blender.Set('curframe', f) - - DrawProgressBar (f/(endFrm+1-startFrm),"Rendering ..." + str(context.currentFrame())) - - print "Frame: ", f, "\n" - if startFrm <> endFrm: file.write("\n") - for o in range(NUMobjects): - - if Objects[o].getType() == "Mesh": - - obj = Objects[o] # Get the first selected object - objname = obj.name # The object name - - - OBJmesh = obj.getData() # Get the mesh data for the object - numfaces=len(OBJmesh.faces) # The number of faces in the object - numEachVert=len(OBJmesh.faces[0]) # The number of verts in each face - - #------------ - # Get the Material Colors - #------------ -# MATinfo = OBJmesh.getMaterials() -# -# if len(MATinfo) > 0: -# RGB=MATinfo[0].rgbCol -# R=int(RGB[0]*255) -# G=int(RGB[1]*255) -# B=int(RGB[2]*255) -# color=`R`+"."+`G`+"."+`B` -# print color -# else: -# color="100.100.100" - - objekat = [] - - objekat.append(0) - - for face in range(numfaces): - numvert = len(OBJmesh.faces[face]) - objekat.append(numvert) - objekat[0] += 1 - -# backface cutting - a = [] - a.append(OBJmesh.faces[face][0][0]) - a.append(OBJmesh.faces[face][0][1]) - a.append(OBJmesh.faces[face][0][2]) - a = RotatePoint(a[0], a[1], a[2], obj.RotX, obj.RotY, obj.RotZ) - a[0] += obj.LocX - camera.LocX - a[1] += obj.LocY - camera.LocY - a[2] += obj.LocZ - camera.LocZ - b = [] - b.append(OBJmesh.faces[face][1][0]) - b.append(OBJmesh.faces[face][1][1]) - b.append(OBJmesh.faces[face][1][2]) - b = RotatePoint(b[0], b[1], b[2], obj.RotX, obj.RotY, obj.RotZ) - b[0] += obj.LocX - camera.LocX - b[1] += obj.LocY - camera.LocY - b[2] += obj.LocZ - camera.LocZ - c = [] - c.append(OBJmesh.faces[face][numvert-1][0]) - c.append(OBJmesh.faces[face][numvert-1][1]) - c.append(OBJmesh.faces[face][numvert-1][2]) - c = RotatePoint(c[0], c[1], c[2], obj.RotX, obj.RotY, obj.RotZ) - c[0] += obj.LocX - camera.LocX - c[1] += obj.LocY - camera.LocY - c[2] += obj.LocZ - camera.LocZ - - norm = [0,0,0] - norm[0] = (b[1] - a[1])*(c[2] - a[2]) - (c[1] - a[1])*(b[2] - a[2]) - norm[1] = -((b[0] - a[0])*(c[2] - a[2]) - (c[0] - a[0])*(b[2] - a[2])) - norm[2] = (b[0] - a[0])*(c[1] - a[1]) - (c[0] - a[0])*(b[1] - a[1]) - - d = norm[0]*a[0] + norm[1]*a[1] + norm[2]*a[2] - - if d < 0: - file.write("\n") - if startFrm <> endFrm: - file.write("\n") - file.write("\n") - file.write("\n") - -#flatern() -#writesvg(objekat) +for f in frames: + context.currentFrame(f) + Blender.Set('curframe', f) + + DrawProgressBar (f/len(frames),"Rendering ..." + str(f)) + + print "Frame: ", f, "\n" + if animation : + file.write("\n") + + for o in Objects: + + if o.getType() == "Mesh": + + obj = o # Get the first selected object + objname = obj.name # The object name + + + OBJmesh = obj.getData() # Get the mesh data for the object + meshfaces = OBJmesh.faces # The number of faces in the object + + #------------ + # Get the Material Colors + #------------ + + #MATinfo = OBJmesh.getMaterials() + # + #if len(MATinfo) > 0: + # RGB=MATinfo[0].rgbCol + # R=int(RGB[0]*255) + # G=int(RGB[1]*255) + # B=int(RGB[2]*255) + # color=`R`+"."+`G`+"."+`B` + # print color + #else: + # color="100.100.100" + + + for face in range(0, len(meshfaces)): + numvert = len(OBJmesh.faces[face]) + + #if (isVisible(face)): + # print "face visible" + + # backface culling + a = [] + a.append(OBJmesh.faces[face][0][0]) + a.append(OBJmesh.faces[face][0][1]) + a.append(OBJmesh.faces[face][0][2]) + a = RotatePoint(a[0], a[1], a[2], obj.RotX, obj.RotY, obj.RotZ) + a[0] += obj.LocX - camera.LocX + a[1] += obj.LocY - camera.LocY + a[2] += obj.LocZ - camera.LocZ + b = [] + b.append(OBJmesh.faces[face][1][0]) + b.append(OBJmesh.faces[face][1][1]) + b.append(OBJmesh.faces[face][1][2]) + b = RotatePoint(b[0], b[1], b[2], obj.RotX, obj.RotY, obj.RotZ) + b[0] += obj.LocX - camera.LocX + b[1] += obj.LocY - camera.LocY + b[2] += obj.LocZ - camera.LocZ + c = [] + c.append(OBJmesh.faces[face][numvert-1][0]) + c.append(OBJmesh.faces[face][numvert-1][1]) + c.append(OBJmesh.faces[face][numvert-1][2]) + c = RotatePoint(c[0], c[1], c[2], obj.RotX, obj.RotY, obj.RotZ) + c[0] += obj.LocX - camera.LocX + c[1] += obj.LocY - camera.LocY + c[2] += obj.LocZ - camera.LocZ + + norm = [0,0,0] + norm[0] = (b[1] - a[1])*(c[2] - a[2]) - (c[1] - a[1])*(b[2] - a[2]) + norm[1] = -((b[0] - a[0])*(c[2] - a[2]) - (c[0] - a[0])*(b[2] - a[2])) + norm[2] = (b[0] - a[0])*(c[1] - a[1]) - (c[0] - a[0])*(b[1] - a[1]) + + d = norm[0]*a[0] + norm[1]*a[1] + norm[2]*a[2] + + # if the face is visible flatten it on the "picture plane" + if d < 0: + file.write("\n") + if animation: + file.write("\n") + file.write("\n") + file.write("\n") + file.write("") file.close() -print file DrawProgressBar (1.0,"Finished.") print "Finished\n"