X-Git-Url: https://git.ao2.it/vrm.git/blobdiff_plain/93ab13c89413991d1b26e747c5e953b61bf530ed..cb334b8afdb1d2133db56e1c5f22e0d5b999f42a:/vrm.py diff --git a/vrm.py b/vrm.py old mode 100644 new mode 100755 index 380a65b..726c83d --- a/vrm.py +++ b/vrm.py @@ -2,22 +2,17 @@ """ Name: 'VRM' -Blender: 228 +Blender: 237 Group: 'Export' Tooltip: 'Vector Rendering Method Export Script' """ - import Blender from Blender import Scene, Object, Lamp, Camera from math import * from Blender.Window import * - -def init(): - - print "Init\n" +from Blender.Scene import Render - renderDir = scena.getRenderdir() # distance from camera Z' def Distance(PX,PY,PZ): @@ -25,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 = [] @@ -50,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 @@ -57,187 +58,188 @@ def flatern(vertx, verty, vertz): camTyp = cam[0].getType() - msize = scena.getWinSize() + msize = (context.imageSizeX(), context.imageSizeY()) xres = msize[0] # X res for output 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 # ######## scena = Scene.GetCurrent() -init() +context = scena.getRenderingContext() +renderDir = context.getRenderPath() -tacka = [0,0,0] -lice = [3,tacka,tacka,tacka,tacka] +msize = (context.imageSizeX(), context.imageSizeY()) -msize = scena.getWinSize() - -file=open("d:\proba.svg","w") +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() NUMobjects = len(Objects) -startFrm = scena.startFrame() -endFrm = scena.endFrame() +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(scena.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() DrawProgressBar (1.0,"Finished.")