From: Nikola Radovanovic Date: Fri, 23 Jan 2004 10:34:07 +0000 (+0100) Subject: Initial commit X-Git-Tag: vrm-0.1 X-Git-Url: https://git.ao2.it/vrm.git/commitdiff_plain/refs/tags/vrm-0.1 Initial commit Original first version by Nikola Radovanovic. Signed-off-by: Antonio Ospite --- 93ab13c89413991d1b26e747c5e953b61bf530ed diff --git a/vrm.py b/vrm.py new file mode 100644 index 0000000..380a65b --- /dev/null +++ b/vrm.py @@ -0,0 +1,244 @@ +#!BPY + +""" +Name: 'VRM' +Blender: 228 +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" + + renderDir = scena.getRenderdir() + +# distance from camera Z' +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 = [] + # Rotate X + NewY = (PY * cos(AngleX))-(PZ * sin(AngleX)) + NewZ = (PZ * cos(AngleX))+(PY * sin(AngleX)) + # Rotate Y + PZ = NewZ + PY = NewY + NewZ = (PZ * cos(AngleY))-(PX * sin(AngleY)) + NewX = (PX * cos(AngleY))+(PZ * sin(AngleY)) + PX = NewX + PZ = NewZ + # Rotate Z + NewX = (PX * cos(AngleZ))-(PY * sin(AngleZ)) + NewY = (PY * cos(AngleZ))+(PX * sin(AngleZ)) + NewPoint.append(NewX) + NewPoint.append(NewY) + NewPoint.append(NewZ) + return NewPoint + +def flatern(vertx, verty, vertz): + + cam = Camera.get() # Get the cameras in scene + Lens = cam[0].getLens() # The First Blender camera lens + + camTyp = cam[0].getType() + + msize = scena.getWinSize() + xres = msize[0] # X res for output + yres = msize[1] # Y res for output + ratio = xres/yres + + 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) + 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() + +tacka = [0,0,0] +lice = [3,tacka,tacka,tacka,tacka] + +msize = scena.getWinSize() + +file=open("d:\proba.svg","w") + +file.write("\n") +#file.write("\n") + +Objects = Blender.Object.Get() +NUMobjects = len(Objects) + +startFrm = scena.startFrame() +endFrm = scena.endFrame() +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) +file.write("") +file.close() +DrawProgressBar (1.0,"Finished.") +print "Finished\n"