import Blender import os import sys import socket from threading import Thread from Blender import * from Blender.Scene import Render from Blender import Draw from Blender.BGL import * from Blender import Registry from Blender import Text from Blender import Texture,Image,Material from math import * #Enter your executable location here executable = 'f:\\Processing\\sketchBoard\\applet\\sketchBoard.jar' #Enter your java path here javaPath = 'c:\\Program Files\\Java\\jre1.6.0\\bin\\java.exe' #lets escape any spaces that may be in the executable path qexecutable = "\""+ executable + "\"" print ("paths:") print executable print javaPath #this angers me in ways I cannot explain. I cannot find a way to spawn a process #and get a pipe to it in both windows and linux. So i'm using sockets. def makePlane(w,h,m,a): asp = float(h)/float(w) width = size.val height = size.val*asp coords = [[0,0,0],[0,0,height],[width,0,height],[width,0,0]] faces = [[3,2,1,0]] me = Mesh.New('myMesh') me.verts.extend(coords) me.faces.extend(faces) diffTex = Texture.New('diff') diffTex.setType('Image') img = Image.Load(m) diffTex.image = img aTex = Texture.New('alph') aTex.setType('Image') imga = Image.Load(a) aTex.image = imga mat = Material.New('billboard') mtextures = mat.getTextures() mat.setTexture(0,diffTex,Texture.TexCo.UV,) mat.setTexture(1,aTex,Texture.TexCo.UV,Texture.MapTo.ALPHA) mat.spec = 0; mat.ref = .95; mat.alpha = 0.0; mat.mode |= Material.Modes.ZTRANSP me.materials += [mat] for f in me.faces: f.image = img; ob = Object.New('Mesh','myObj') ob.link(me) sc = Scene.GetCurrent() sc.link(ob) def render(): print 'Render called' bob = os.spawnv(os.P_NOWAIT,javaPath,[' -jar ' + qexecutable , "--Blender"] ) s = socket.socket(socket.AF_INET,socket.SOCK_STREAM) s.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1) s.bind(('localhost',50007)) s.listen(1) try: exit = False while exit == False: conn,addr = s.accept() data = conn.recv(1024) if data == 'quit': exit = True else: tokens = data.rsplit(',') if tokens[0] == 'plane': makePlane(tokens[1],tokens[2],tokens[3], tokens[4]) conn.close() s.close() except: print 'Quitting' size = Draw.Create(2) def draw(): global size BGL.glClearColor(1.0, 1.0, 1.0, 0.0) BGL.glClear(GL_COLOR_BUFFER_BIT) leftMargin = 10; bottomMargin = 15; columnWidth = 170; buttonWidth = columnWidth - leftMargin; columnHeight = 35; buttonHeight = columnHeight - bottomMargin; if os.path.exists(executable): Draw.Button('Exit', 2, leftMargin, 5, buttonWidth, buttonHeight, '') Draw.Button('Sketch!', 1, leftMargin+columnWidth,5, buttonWidth, buttonHeight, '') size = Draw.Slider('Size', 12, leftMargin , 2*columnHeight, buttonWidth, buttonHeight, size.val, 1, 20, 1,'') else: BGL.glColor3f(0.15,0.15,0.15) BGL.glRasterPos2i(leftMargin,50) Draw.Text("Could not locate the sketch executable. Enter its location into the script header.") Draw.Button('Exit', 2, leftMargin, 5, buttonWidth, buttonHeight, '') def bevent(evt): if evt == 2: #ExitButton #kill the server thread Draw.Exit() elif evt == 1: #Button2 render() else: Blender.Redraw() Draw.Register(draw, event, bevent)