def Create_Tab(X1,Y1,X2,Y2,Title,Buttons): # X1,Y1 = Top Left X2,Y2 = Bottom Right """ Create a bordered tab/frame/box with the given top left corner (X1,Y1) and bottom right corner (X2, Y2) with the given Title and Buttons. """ TITLE_HEIGHT = 15 INDENT = 6 BUTTON_GAP = 4 BGL.glColor3f(0.75, 0.75, 0.75) BGL.glRecti(X1,Y1,X2,Y2) Draw_Border(X1,Y1,X2,Y2); BGL.glColor3f(0.0,0.0,0.0) BGL.glRasterPos2d(X1+INDENT,Y1 - TITLE_HEIGHT) Draw.Text(Title) BUTTON_HEIGHT = 18 Button_X = X1 + INDENT Button_Y = Y1 - TITLE_HEIGHT - BUTTON_HEIGHT - 8 if (Buttons != 0): key= Buttons.keys() BUTTON_WIDTH = (X2 - (X1 + INDENT + BUTTON_GAP + INDENT)) / len(key) for k in key: Buttons[k][0]= Draw.Toggle(k,Buttons[k][1],Button_X,Button_Y, BUTTON_WIDTH,BUTTON_HEIGHT,Buttons[k][0].val,Buttons[k][2]) Button_X += BUTTON_WIDTH + BUTTON_GAP
def changeA(): global a a += .2 # print 'step',a if a > 6: Draw.Exit() time.sleep(0.1) Draw.Redraw(1)
def main(): scn = Scene.GetCurrent() ob = scn.objects.active if not ob or ob.type != 'Mesh': Draw.PupMenu('Error, no active mesh object, aborting.') return me = ob.getData(mesh=1) act_group = me.activeGroup PREF_NAME = Draw.Create(act_group + '_copy') PREF_SEL_ONLY = Draw.Create(0) pup_block= [\ ('', PREF_NAME, 0, 31, 'Name of group copy.'),\ ('Only Selected', PREF_SEL_ONLY, 'Only include selected faces in the new grop.'),\ ] if not Draw.PupBlock('New Name...', pup_block): return PREF_NAME = PREF_NAME.val PREF_SEL_ONLY = PREF_SEL_ONLY.val copy_act_vgroup(me, PREF_NAME, PREF_SEL_ONLY) try: me.activeGroup = PREF_NAME except: pass
def button_event(evt): global config_data if (evt == BROWSE_HOME_CLICKED): default_path = "C:\\" if (Blender.sys.exists(config_data["home"])): default_path = config_data["home"] Window.FileSelector(SetHomeDir, "Nebula Home", default_path) if (evt == BROWSE_PROJ_CLICKED): default_path = "C:\\" if (Blender.sys.exists(config_data["home"])): default_path = config_data["proj"] Window.FileSelector(SetProjDir, "Project Dir", default_path) if (evt == ASSIGN_DIR_CHANGED): for data in config_data: if (data != "home" and data != "texture_dir" and data != "proj"): config_data[data] = dir_assigns[data].val if (evt == OK_CLICKED): SaveConfig() result = Draw.PupMenu("Saved%t|Do you want to exit?") if (result != -1): Draw.Exit() return if (evt == CANCEL_CLICKED): result = Draw.PupMenu("Exit%t|Exit and Discard Changes?") if (result != -1): Draw.Exit() return
def read_ui(filename): global guiTable, IMPORT_VC, IMPORT_UV guiTable = {'VC': 1, 'UV': 1} for s in Window.GetScreenInfo(): Window.QHandle(s['id']) IMPORT_VC = Draw.Create(guiTable['VC']) IMPORT_UV = Draw.Create(guiTable['UV']) # Get USER Options pup_block = [ ('Import Options'), ('Vertex Color', IMPORT_VC, 'Import Vertex Colors if exist'), ('UV', IMPORT_UV, 'Import UV if exist'), ] if not Draw.PupBlock('Import...', pup_block): return Window.WaitCursor(1) guiTable['VC'] = IMPORT_VC.val guiTable['UV'] = IMPORT_UV.val read_main(filename) Window.WaitCursor(0)
def dodialog(newname): global newimage, newsize, offsets, rows, cols try: newimage = Image.Load(newname) newsize = newimage.getSize() except: Draw.PupMenu("Can't read image %s" % newname) return if newsize[0] == oldsize[0] and newsize[1] == oldsize[1]: # same size, just replace doapply(0, 0) return elif newsize[0] < oldsize[0] or newsize[1] < oldsize[1]: Draw.PupMenu("The new image must be larger than the old image") return else: if newsize[0] % oldsize[0] == 0: xoffs = range(0, newsize[0], oldsize[0]) else: xoffs = [0, newsize[0] - oldsize[0]] if newsize[1] % oldsize[1] == 0: yoffs = range(newsize[1] - oldsize[1], -oldsize[1], -oldsize[1]) else: yoffs = [newsize[1] - oldsize[1], 0] for i in yoffs: for j in xoffs: offsets.append((j, i)) cols = len(xoffs) rows = len(yoffs) Draw.Register(gui, event, bevent)
def event(evt, val): # input events global SCREEN, START_SCREEN, SCRIPT_SCREEN global SCROLL_DOWN, FMODE if not val: return if evt == Draw.ESCKEY: if SCREEN == START_SCREEN or FMODE: Draw.Exit() else: SCREEN = START_SCREEN SCROLL_DOWN = 0 Draw.Redraw() return elif evt == Draw.QKEY: Draw.Exit() return elif evt in [Draw.DOWNARROWKEY, Draw.WHEELDOWNMOUSE ] and SCREEN == SCRIPT_SCREEN: SCROLL_DOWN += 1 fit_scroll() Draw.Redraw() return elif evt in [Draw.UPARROWKEY, Draw.WHEELUPMOUSE ] and SCREEN == SCRIPT_SCREEN: SCROLL_DOWN -= 1 fit_scroll() Draw.Redraw() return elif evt == Draw.SKEY: if SCREEN == SCRIPT_SCREEN and SCRIPT_INFO: load_script_text(SCRIPT_INFO.script) return
def main(): ret = Draw.PupMenu( 'Clean Selected Objects Ipos%t|Object IPO%x1|Object Action%x2|%l|All IPOs (be careful!)%x3' ) sce = bpy.data.scenes.active ipos = [] if ret == 3: ipos.extend(list(bpy.data.ipos)) else: for ob in sce.objects.context: if ret == 1: ipo = ob.ipo if ipo: ipos.append(ipo) elif ret == 2: action = ob.action if action: ipos.extend([ ipo for ipo in action.getAllChannelIpos().values() if ipo ]) if not ipos: Draw.PupMenu('Error%t|No ipos found') else: total_removed, total = clean_ipos(ipos) Draw.PupMenu('Done!%t|Removed ' + str(total_removed) + ' of ' + str(total) + ' points') Window.RedrawAll()
def bevent(evt): global EVENT_NOEVENT, EVENT_DRAW, EVENT_EXIT if (evt == EVENT_EXIT): Draw.Exit() elif (evt == EVENT_DRAW): Draw.Redraw() elif (evt == EVENT_EXPORT): sce = bpy.data.scenes.active if (export_all == 1): print "oh ja" # get a list of mesh objects obs = [ob for ob in sce.objects if ob.type == 'Mesh'] # export all object names for ob in obs: me = Mesh.New() me.getFromObject(ob, 0) print(me.name) export_to_as(ob) Draw.PupMenu("Export Successful") else: export_to_as(sce.objects.active) Draw.PupMenu("Export Successful") elif (evt == EVENT_BROWSEFILE): Window.FileSelector(FileSelected, "Export .as", expFileName) Draw.Redraw(1)
def x3d_export_ui(filename): if not filename.endswith(extension): filename += extension #if _safeOverwrite and sys.exists(filename): # result = Draw.PupMenu("File Already Exists, Overwrite?%t|Yes%x1|No%x0") #if(result != 1): # return # Get user options EXPORT_APPLY_MODIFIERS = Draw.Create(1) EXPORT_TRI = Draw.Create(0) EXPORT_GZIP = Draw.Create(filename.lower().endswith('.x3dz')) # Get USER Options pup_block = [\ ('Apply Modifiers', EXPORT_APPLY_MODIFIERS, 'Use transformed mesh data from each object.'),\ ('Triangulate', EXPORT_TRI, 'Triangulate quads.'),\ ('Compress', EXPORT_GZIP, 'GZip the resulting file, requires a full python install'),\ ] if not Draw.PupBlock('Export...', pup_block): return Blender.Window.EditMode(0) Blender.Window.WaitCursor(1) x3d_export(filename,\ EXPORT_APPLY_MODIFIERS = EXPORT_APPLY_MODIFIERS.val,\ EXPORT_TRI = EXPORT_TRI.val,\ EXPORT_GZIP = EXPORT_GZIP.val\ ) Blender.Window.WaitCursor(0)
def event(evt, val): global vertical, mousex, mousey, anchor, offset if evt == Draw.ESCKEY and not val: if anchor: anchor = None else: Draw.Exit() # exit when user releases ESC elif evt == Draw.MOUSEX: mousex = val if anchor: offset = (max(0, anchor[0] - mousex), offset[1]) Draw.Redraw() elif evt == Draw.MOUSEY: mousey = val if anchor: offset = (offset[0], min(0, anchor[1] - mousey)) Draw.Redraw() elif evt == Draw.MIDDLEMOUSE and val: anchor = (mousex + offset[0], mousey + offset[1]) elif evt == Draw.MIDDLEMOUSE and not val: anchor = None elif anchor: pass # suppress other activity while panning elif evt == Draw.RIGHTMOUSE and val: r = Draw.PupMenu('Panel Alignment%t|Horizontal|Vertical') if r == 1: vertical = False elif r == 2: vertical = True else: return Draw.Redraw()
def export(self, scene): theObjects = scene.objects print "Starting OBJ export to " + self.filename if not checkFile(self.filename): return Blender.Window.WaitCursor(1) Window.DrawProgressBar(0, "Examining textures") self.texture = getTexture(self, theObjects, self.iscsl, 7) if self.regions: (pwidth, pheight) = PanelRegionHandler().panelimage().size for img, (n, x1, y1, width, height) in self.regions.iteritems(): self.regions[img] = (float(x1) / pwidth, float(y1) / pheight, float(width) / pwidth, float(height) / pheight) #clock=time.clock() # Processor time self.file = open(self.filename, "w") self.writeHeader() self.writeObjects(theObjects) checkLayers(self, theObjects) self.file.close() Window.DrawProgressBar(1, "Finished") #print "%s CPU time" % (time.clock()-clock) print "Finished - exported %s primitives\n" % self.nprim if self.log: r = Draw.PupMenu(("Exported %s primitives%%t|" % self.nprim) + '|'.join([a[0] for a in self.log])) if r > 0: raise ExportError(None, self.log[r - 1][1]) else: Draw.PupMenu("Exported %s primitives%%t|OK" % self.nprim)
def drawGUI(): """ Create and draw the GUI. """ HEIGHT = 382 CONTROL_WIDTH = 400 BGL.glClearColor(0.6, 0.6, 0.6, 1.0) BGL.glClear(BGL.GL_COLOR_BUFFER_BIT) BGL.glColor3f(0.75, 0.75, 0.75) BGL.glRecti(3,45,CONTROL_WIDTH,3) stitchOffset = 22 HEIGHT += stitchOffset * num_motions_button.val Display_Title_Bar(HEIGHT,25, CONTROL_WIDTH) Display_File_Bar(HEIGHT - 25, 71 + stitchOffset * num_motions_button.val, CONTROL_WIDTH) Display_Mesh_Bar(HEIGHT - 96 - stitchOffset * num_motions_button.val, 48, CONTROL_WIDTH) Display_Camera_Bar(HEIGHT - 144 - stitchOffset * num_motions_button.val, 112, CONTROL_WIDTH) Display_Render_Bar(HEIGHT - 256 - stitchOffset * num_motions_button.val, 48, CONTROL_WIDTH) Display_Output_Bar(HEIGHT - 304 - stitchOffset * num_motions_button.val, 48, CONTROL_WIDTH) Draw.PushButton('Load simulation', SimulationButton, 9, 8, (CONTROL_WIDTH / 2) - 9, 18, 'Load simulation') if hasLoaded: Draw.PushButton('Render scene', RenderButton, (CONTROL_WIDTH / 2) + 3, 8, (CONTROL_WIDTH / 2) - 9, 18, 'Render scene')
def button_event(evt): global persist_server, mesh_format, window_width, window_height, fullscreen, renderpath, filename, group, aa if (evt == CANCEL_CLICKED): SavePrefs() Draw.Exit() return if (evt == PERSIST_SERVER_CHANGED): persist_server = mnu_persist_servers.val if (evt == MESH_FORMAT_CHANGED): mesh_format = mnu_mesh_formats.val if (evt == WIDTH_CHANGED): window_width = mnu_width.val if (evt == HEIGHT_CHANGED): window_height = mnu_height.val if (evt == FULLSCREEN_CHANGED): fullscreen = 1 - fullscreen if (evt == AA_CHANGED): aa = mnu_aa.val if (evt == FILENAME_CHANGED): filename = mnu_filename.val if (evt == GROUP_CHANGED): file2 = n2.lookup("/sys/servers/file2") path = "" is_valid = True if (mnu_group.val): path = file2.manglepath("gfxlib:") + "/" + mnu_group.val else: path = file2.manglepath("gfxlib:") if (not Blender.sys.exists(path)): is_valid = False path = "" if (mnu_group.val): path = file2.manglepath("meshes:") + "/" + mnu_group.val else: path = file2.manglepath("meshes:") if (not Blender.sys.exists(path)): is_valid = False if (is_valid): group = mnu_group.val else: err = "The directory ' %s ' must exist in both gfxlib and meshes folders" % mnu_group.val Draw.PupMenu("Invalid Group%t|" + err) Draw.Redraw(1) if (evt == RENDERPATH_CHANGED): renderpath = mnu_renderpath.val if (evt == OK_CLICKED): SavePrefs() DoExport()
def changeA(): global a a[0] += 2 a[1] += 1 # print 'step',a if a[1] > 100: Draw.Exit() time.sleep(0.1) Draw.Redraw(1)
def button_event(evt): # gui button events global SCREEN, START_SCREEN, SCRIPT_SCREEN global BEVT_LINK, BEVT_EMAIL, BEVT_GMENU, BUT_GMENU, SCRIPT_INFO global SCROLL_DOWN, FMODE if evt >= 100: # group menus for i in range(len(BUT_GMENU)): if evt == BEVT_GMENU[i]: group = AllGroups[i] index = BUT_GMENU[i].val - 1 if index < 0: return # user didn't pick a menu entry script = group.get_scripts()[BUT_GMENU[i].val - 1] if parse_help_info(script): SCREEN = SCRIPT_SCREEN BEVT_LINK = range(20, len(SCRIPT_INFO.d['__url__']) + 20) BEVT_EMAIL = range(50, len(SCRIPT_INFO.d['__email__']) + 50) Draw.Redraw() else: res = Draw.PupMenu( "No help available%t|View Source|Cancel") if res == 1: load_script_text(script) elif evt >= 20: if not WEBBROWSER: Draw.PupMenu( 'Missing standard Python module%t|You need module "webbrowser" to access the web' ) return if evt >= 50: # script screen email buttons email = SCRIPT_INFO.d['__email__'][evt - 50][1] webbrowser.open("mailto:%s" % email) else: # >= 20: script screen link buttons link = SCRIPT_INFO.d['__url__'][evt - 20][1] webbrowser.open(link) elif evt == BEVT_VIEWSOURCE: if SCREEN == SCRIPT_SCREEN: load_script_text(SCRIPT_INFO.script) elif evt == BEVT_EXIT: Draw.Exit() return elif evt == BEVT_BACK: if SCREEN == SCRIPT_SCREEN and not FMODE: SCREEN = START_SCREEN SCRIPT_INFO = None SCROLL_DOWN = 0 Draw.Redraw() elif evt == BEVT_EXEC: # Execute script exec_line = '' if SCRIPT_INFO.script.userdir: exec_line = bsys.join(Blender.Get('uscriptsdir'), SCRIPT_INFO.script.fname) else: exec_line = bsys.join(Blender.Get('scriptsdir'), SCRIPT_INFO.script.fname) Blender.Run(exec_line)
def getparents(): global lookup, hierarchy, firstlevel, has_sim, armature, bones, theobject if Window.EditMode(): objects = [Scene.GetCurrent().objects.active] else: objects = Object.GetSelected() for theobject in objects: parent = theobject.parent if not parent or parent.getType() != 'Armature': Draw.PupMenu('Object "%s" is not a child of a bone.' % theobject.name) return None bonename = theobject.getParentBoneName() if not bonename: Draw.PupMenu( 'Object "%s" is the child of an armature. It should be the child of a bone.' % theobject.name) return None thisbones = parent.getData().bones if bonename in thisbones.keys(): bone = thisbones[bonename] else: Draw.PupMenu('Object "%s" has a deleted bone as its parent.' % theobject.name) return None if armature and (parent != armature or bone != bones[0]): Draw.PupMenu( 'You have selected multiple objects with different parents.') return None else: armature = parent bones = [bone] if not bones: return bone = bones[0] while bone.parent: bones.append(bone.parent) bone = bone.parent try: has_sim = False (lookup, hierarchy) = getDatarefs() firstlevel = [] for key in lookup: if lookup[key]: (path, n) = lookup[key] ref = path.split('/') if not ref[0] in firstlevel: firstlevel.append(ref[0]) if len(firstlevel) == 1: firstlevel = hierarchy['sim'].keys() has_sim = True firstlevel.sort(lambda x, y: -cmp(x.lower(), y.lower())) except IOError, e: Draw.PupMenu(str(e)) return None
def Display_Render_Bar(Y_POS, CONTROL_HEIGHT, CONTROL_WIDTH): """ Create the Render setup box.""" Create_Tab(3, Y_POS, CONTROL_WIDTH, Y_POS - CONTROL_HEIGHT, "Render setup", 0) global original_fps_button original_fps_button = Draw.Number("Original FPS:", origFpsButton, 9, (Y_POS - 41), (CONTROL_WIDTH / 2) - 9, 18, original_fps_button.val, 1, 120, 'Orignal FPS of the motion imported') global output_fps_button output_fps_button = Draw.Number("Output FPS:", outputFpsButton, ((CONTROL_WIDTH / 2) + 3), (Y_POS - 41), (CONTROL_WIDTH / 2) - 9, 18, output_fps_button.val, 1, 120, 'The desired output FPS of the motion')
def main(): scn = bpy.data.scenes.active ob_sel = list(scn.objects.context) PREF_KEEP_ASPECT = False # Error Checking if len(ob_sel) < 2: Draw.PupMenu("Error%t|Select 2 mesh objects") return me_ob = scn.objects.active if not me_ob: Draw.PupMenu("Error%t|No active mesh selected.") try: ob_sel.remove(me_ob) except: pass if me_ob.type != 'Mesh': Draw.PupMenu( "Error%t|Active Object must be a mesh to write billboard images too" ) return me_data = me_ob.getData(mesh=1) for f in me_data.faces: if len(f) != 4: Draw.PupMenu("Error%t|Active mesh must have only quads") return # Get user input block = [\ 'Image Pixel Size',\ ("Packed Size: ", PREF_RES, 128, 2048, "Pixel width and height to render the billboard to"),\ ("Tile Size: ", PREF_TILE_RES, 64, 1024, "Pixel width and height for each tile to render to"),\ 'Render Settings',\ ("Pack Final", PREF_IMG_PACK , "Pack the image for each face into images into a single image"),\ ("Oversampling", PREF_AA , "Higher quality woth extra sampling"),\ ("Alpha Clipping", PREF_ALPHA , "Render empty areas as transparent"),\ ("Cam ZOffset: ", PREF_Z_OFFSET, 0.1, 100, "Distance to place the camera away from the quad when rendering")\ ] if not Draw.PupBlock("Billboard Render", block): return # Set globals GLOBALS['ob_sel'] = ob_sel GLOBALS['me_ob'] = me_ob GLOBALS['me_data'] = me_data Blender.Window.FileSelector(save_billboard, 'SAVE BILLBOARD', Blender.sys.makename(ext='.png'))
def buttonEventHandler(button): """ Event handler for button presses. @param button: Button ID. """ global G G.havebupclik = False if button == BUTTON_QUIT: removeCustomScriptLink() writeDataToRegistry() Draw.Exit() Window.RedrawAll() elif button == BUTTON_LOAD: G.havebupclik = True Window.ImageSelector(loadImage) elif button == BUTTON_ZOOM: x, y, w, h = getWinRect() setZoom((w / 2, h / 2), G.buttons.zoom.val) elif button == BUTTON_FULLOPT: G.fullopt = G.buttons.fullopt.val elif button == BUTTON_COPLANAR: G.coplanar = G.buttons.coplanar.val elif button == BUTTON_OFSX: G.ofsx = G.buttons.ofsx.val elif button == BUTTON_OFSY: G.ofsy = G.buttons.ofsy.val elif button == BUTTON_OFSZ: G.ofsz = G.buttons.ofsz.val elif button == BUTTON_ADD: G.mode = MODE_ADD Draw.Redraw(1) elif button == BUTTON_DELETE: def delmap(x): del G.coordmap[x.getName()] x.select(False) map(delmap, G.selection) Window.RedrawAll() elif button == BUTTON_CALIBRATE: Window.WaitCursor(True) G.last_camera = G.selection[0] calibrate()
def Display_Mesh_Bar(Y_POS, CONTROL_HEIGHT, CONTROL_WIDTH): """ Create the mesh setup box. """ Create_Tab(3, Y_POS, CONTROL_WIDTH, Y_POS - CONTROL_HEIGHT, "Mesh setup", 0) menuItems = "Mesh %t|Male %x1|Female %x2" global MESH_menu MESH_menu = Draw.Menu(menuItems, MESHMENU, 9, (Y_POS - 41), 130, 18, MESH_menu.val, 'Select mesh (.obj)') global OUTERJOINTS_toggle OUTERJOINTS_toggle = Draw.Toggle('Ignore outer joints', OUTERJOINTSBUTTON, ((CONTROL_WIDTH / 2) + 3), (Y_POS - 41), (CONTROL_WIDTH / 2) - 9, 18, OUTERJOINTS_toggle.val, 'Ignores the outer joints of the animation (fingers and toes)')
def event(evt, val): # эта функция обрабатывает прерывания от клавиатуры и мыши global mystr if evt == Draw.ESCKEY: Draw.Exit() # выход из скрипта return if val==0 and evt ==Draw.LEFTMOUSE: coor=Blender.Window.GetMouseCoords() print coor mystr =str(coor[0])+" "+str(coor[1]) Draw.Redraw(1)
def changeA(): global a global vect global t a +=1 vect = (1-t)*Vector(6,8,2)+t*Vector(-4,6,1) t+=0.001 if a>1000: Draw.Exit() time.sleep(0.001) Draw.Redraw(1)
def event(evt, val): # эта функция обрабатывает прерывания от клавиатуры и мыши if evt == Draw.ESCKEY: Draw.Exit() # выход из скрипта return global mystring#, mymsg if Draw.AKEY <= evt <= Draw.ZKEY: if val==0: #чтобы буква не печаталась два раза mystring += chr(evt) # это срабатывает при нажатие на символьную клавишу. chr(evt) преобразует символ клавиши в соответствующий символ Draw.Redraw(1)
def CheckSelection(): selob = Object.GetSelected() if not selob: Draw.PupMenu("Warning%t|Please make a selection.") elif ob and selob[0].name == ob.name: Draw.PupMenu("Warning%t|Object already selected.") else: return selob[0] return None
def render(self): try: Draw.Number(self.label, self.event, self.x, self.y, self.width, self.height, self.value, self.min, self.max, self.tooltip, self.update_value, self.range, self.precision) except: # needed for backwards compatibility (no range and precision in 2.48a) Draw.Number(self.label, self.event, self.x, self.y, self.width, self.height, self.value, self.min, self.max, self.tooltip, self.update_value)
def gui(self): # the function to draw the screen BGL.glClearColor(0, 0, 0.5, 1) BGL.glClear(BGL.GL_COLOR_BUFFER_BIT) BGL.glColor3f(1, 1, 1) BGL.glRasterPos2i(20, 200) Draw.Text("Select the object to export:", "normal") self.objMenu = Draw.Menu(self.sObjSelection, 1, 20, 170, 200, 20, self.objSel, "Select the animated object.") BGL.glRasterPos2i(20, 150) Draw.Text("Select the armature to export:", "normal") self.armMenu = Draw.Menu(self.sArmSelection, 2, 20, 120, 200, 20, self.armSel, "Select the matching armature.") BGL.glRasterPos2i(20, 100) Draw.Text("Select the root bone of the armature:", "normal") self.boneMenu = Draw.Menu(self.sBoneSelection, 3, 20, 70, 200, 20, self.boneSel, "Select the Root Bone of the armature.") Draw.PushButton("Export", 4, 250, 150, 50, 20, "Export File") Draw.PushButton("Cancel", 5, 250, 110, 50, 20, "Cancel") BGL.glRasterPos2i(72, 16) string = "Selections: " + ("%s" % self.objSel) + " / " + ( "%s" % self.armSel) + " / " + ("%s" % self.boneSel) Draw.Text(string, "small")
def drawdataref(datarefs, indices, eventbase, boneno, x, y): dataref = datarefs[boneno] valid = True mbutton = Draw.Menu('sim/%t|' + '/...|'.join(firstlevel) + '/...', DONTCARE + eventbase, x + 4, y, CONTROLSIZE, CONTROLSIZE, -1, 'Pick the dataref from a list', datarefmenucallback) bbutton = Draw.String( '', DATAREF_B + eventbase, x + 4 + CONTROLSIZE, y, PANELWIDTH - 2 * PANELINDENT - CONTROLSIZE, CONTROLSIZE, dataref, 100, 'Full name of the dataref used to animate this object') ibutton = None tbutton = None ref = dataref.split('/') if len(ref) <= 1 or ref[0] == 'sim': if len(ref) == 1 and ref[0] in lookup and not lookup[ref[0]]: BGL.glRasterPos2d(x + 4, y - 21) Draw.Text('This dataref name is ambiguous') valid = False else: try: thing = hierarchy for i in range(len(ref)): thing = thing[ref[i]] n = thing + 0 # check is a leaf - ie numeric if not n: BGL.glRasterPos2d(x + 4, y - 21) Draw.Text("This dataref can't be used for animation") valid = False elif n == 1: indices[boneno] = None else: if indices[boneno] == None or indices[boneno] >= n: indices[boneno] = 0 Draw.Label("Part number:", x, y - 26, 120, CONTROLSIZE) ibutton = Draw.Number('', INDICES_B + eventbase, x + 108, y - 26, 50, CONTROLSIZE, indices[boneno], 0, n - 1, 'The part number / array index') except: BGL.glRasterPos2d(x + 4, y - 21) Draw.Text("This is not a valid dataref") valid = False else: if indices[boneno] != None: val = 1 else: val = 0 tbutton = Draw.Toggle('Part number', INDICES_T + eventbase, x + 4, y - 26, 104, CONTROLSIZE, val, 'Whether this is an array dataref') if val: ibutton = Draw.Number('', INDICES_B + eventbase, x + 108, y - 26, 50, CONTROLSIZE, indices[boneno], 0, 729, 'The part number / array index') return (valid, mbutton, bbutton, ibutton, tbutton)
def draw_gui(): global EVENT_ALL, EVENT_SEL global EVENT_NOR, EVENT_COL, EVENT_CAM, EVENT_LIG global EVENT_EXP, EVENT_QUI button_width = 222 button_height = 20 def draw_rect(x, y, width, height): glBegin(GL_LINE_LOOP) glVertex2i(x, y) glVertex2i(x + width, y) glVertex2i(x + width, y - height) glVertex2i(x, y - height) glEnd() Blender.BGL.glClearColor(34.0 / 255.0, 85.0 / 255.0, 136.0 / 255.0, 1.0) Blender.BGL.glClear(Blender.BGL.GL_COLOR_BUFFER_BIT) glColor3f(170.0 / 255.0, 255.0 / 255.0, 255.0 / 255.0) draw_rect(20, 330, 262, 310) draw_rect(22, 328, 258, 306) glColor3f(255.0 / 255.0, 238.0 / 255.0, 0.0 / 255.0) glRasterPos2i(70, 300) Draw.Text("Blitz3D Exporter 2.07", 'large') Blender.Draw.Toggle("All Objects", EVENT_ALL, 40, 13 * button_height, button_width, button_height, flag_stack[0], "Export All Scene Objects") Blender.Draw.Toggle("Selected Only", EVENT_SEL, 40, 12 * button_height, button_width, button_height, flag_stack[1], "Export Only Selected Objects") Blender.Draw.Toggle("Normals", EVENT_NOR, 40, 10 * button_height, button_width, button_height, flag_stack[2], "Export Vertex Normals") Blender.Draw.Toggle("Vertex Colors", EVENT_COL, 40, 9 * button_height, button_width, button_height, flag_stack[3], "Export Vertex Colors") Blender.Draw.Toggle("Cameras", EVENT_CAM, 40, 8 * button_height, button_width, button_height, flag_stack[4], "Export Cameras") Blender.Draw.Toggle("Lights", EVENT_LIG, 40, 7 * button_height, button_width, button_height, flag_stack[5], "Export Lights") Blender.Draw.Button("Export", EVENT_EXP, 40, 5 * button_height, button_width, button_height, "Export to B3D") Blender.Draw.Button("Quit", EVENT_QUI, 40, 4 * button_height, button_width, button_height, "Quit this script") glRasterPos2i(36, 55) Draw.Text("Copyright 2009 Diego Parisi", 'small') glRasterPos2i(105, 37) Draw.Text("www.diegoparisi.com", 'small')
def save_file(file_contents, class_name): try: f = open(fileButton.val + "" + class_name + ".as", 'w') f.write(file_contents) f.close() print "Export Successful: " + class_name + ".as" except: Draw.PupMenu("Export failed | Check the console for more info") raise # throw the exception Draw.Exit()