def loadImage(self, filename, label=None): if label: handle = PyUnseen.createTexture(filename) self.images[label] = handle else: handle = PyUnseen.createTexture(filename) self.images[filename] = handle
def loadImage(self, filename, label = None): if label: handle = PyUnseen.createTexture(filename) self.images[label] = handle else: handle = PyUnseen.createTexture(filename) self.images[filename] = handle
def run(): done = 1 frame = 0 t = time.time() import testopt opts = testopt.parseCommandLine(800, 600, "dx") pyui.init(*opts) # w = pyui.widgets.ViewWindow(10, 10, 400, 300) # w.pack() terrainDetails = CreateTestTerrainDetails() terrain = PyUnseen.createTerrainRegion(terrainDetails) # will take dictionary of stuff rootWorld = PyUnseen.getRootWorld() PyUnseen.addToWorld(rootWorld, terrain) # just like any other object cameraPos = (-10, 6, -10) cameraDir = (45, -45, 0) view1 = PyUnseen.createView(rootWorld) # will also take zMin, zMax? PyUnseen.setCameraParameters(view1, cameraPos, cameraDir) rootView = PyUnseen.getRootView() PyUnseen.setCameraParameters(rootView, cameraPos, cameraDir) while done: pyui.draw() done = pyui.update() print "done" pyui.quit()
def gotEvent(event, wParam, lParam): global keydown, keystate, debugEnabled if event in mouseMsgs: x = lParam & 0xffff y = lParam >> 16 #print "Mouse Event: %d (%d,%d)" % (event, x, y) mods = pyui.locals.MOD_NONE if event in [ WM_LBUTTONDOWN, WM_LBUTTONUP, WM_RBUTTONDOWN, WM_RBUTTONUP, WM_MOUSEMOVE ]: if keystate[VK_SHIFT]: mods |= pyui.locals.MOD_SHIFT if keystate[VK_CONTROL]: mods |= pyui.locals.MOD_CONTROL if keystate[VK_MENU]: mods |= pyui.locals.MOD_ALT if getDesktop(): getDesktop().postUserEvent(event, x, y, wParam, mods) return # mods for key events if event in [WM_CHAR, WM_KEYDOWN, WM_KEYUP]: mods = pyui.locals.MOD_NONE if keystate[VK_SHIFT]: mods |= pyui.locals.MOD_SHIFT if keystate[VK_CONTROL]: mods |= pyui.locals.MOD_CONTROL if keystate[VK_MENU]: mods |= pyui.locals.MOD_ALT # This is the handler for character keys. if event == WM_CHAR: getDesktop().postUserEvent(pyui.locals.CHAR, 0, 0, chr(wParam), mods) return if event == WM_KEYDOWN: if debugEnabled and (DEBUG_KEY == wParam): PyUnseen.debug(0) return global keydown, keystate keystate[wParam] += 1 getDesktop().postUserEvent(pyui.locals.KEYDOWN, 0, 0, wParam, mods) return if event == WM_KEYUP: global keydown, keystate keystate[wParam] = 0 getDesktop().postUserEvent(pyui.locals.KEYUP, 0, 0, wParam, mods) return # special event handlers if event == WM_CLOSE: getDesktop().postUserEvent(pyui.locals.QUIT, 0, 0, 0) return
def draw(self, windows): """run the python widgets drawing code. This calls describeWindow on any windows that have changed. The actual drawing is done within PyUnseen.render. """ for w in windows: w.drawWindow(self) PyUnseen.render() PyUnseen.messagepump() self.mustFill = 0 self.dirtyRects = []
def gotEvent(event, wParam, lParam): global keydown, keystate, debugEnabled if event in mouseMsgs: x = lParam & 0xffff y = lParam >> 16 #print "Mouse Event: %d (%d,%d)" % (event, x, y) mods = pyui.locals.MOD_NONE if event in [WM_LBUTTONDOWN, WM_LBUTTONUP, WM_RBUTTONDOWN, WM_RBUTTONUP, WM_MOUSEMOVE]: if keystate[VK_SHIFT]: mods |= pyui.locals.MOD_SHIFT if keystate[VK_CONTROL]: mods |= pyui.locals.MOD_CONTROL if keystate[VK_MENU]: mods |= pyui.locals.MOD_ALT if getDesktop(): getDesktop().postUserEvent(event, x, y, wParam, mods) return # mods for key events if event in [WM_CHAR, WM_KEYDOWN, WM_KEYUP]: mods = pyui.locals.MOD_NONE if keystate[VK_SHIFT]: mods |= pyui.locals.MOD_SHIFT if keystate[VK_CONTROL]: mods |= pyui.locals.MOD_CONTROL if keystate[VK_MENU]: mods |= pyui.locals.MOD_ALT # This is the handler for character keys. if event == WM_CHAR: getDesktop().postUserEvent(pyui.locals.CHAR, 0, 0, chr(wParam), mods) return if event == WM_KEYDOWN: if debugEnabled and (DEBUG_KEY == wParam): PyUnseen.debug(0) return global keydown, keystate keystate[wParam] += 1 getDesktop().postUserEvent(pyui.locals.KEYDOWN, 0, 0, wParam, mods) return if event == WM_KEYUP: global keydown, keystate keystate[wParam] = 0 getDesktop().postUserEvent(pyui.locals.KEYUP, 0, 0, wParam, mods) return # special event handlers if event == WM_CLOSE: getDesktop().postUserEvent(pyui.locals.QUIT, 0, 0, 0) return
def __init__(self, w, h, fullscreen, title="Unseen"): Renderer3DBase.__init__(self, w, h, fullscreen) PyUnseen.initialize(w, h, gotEvent, messageMap, title) self.font1 = PyUnseen.createFont("Arial", 9, 0) self.fixedFont = PyUnseen.createFont("Courier", 7, 0) self.populateConstants() # store the actual height and width surface created (might be less than requested) #(getDesktop().width, getDesktop().height) = PyUnseen.getDesktopSize() (w, pyui.locals.TEXT_HEIGHT) = self.getTextSize(" ") self.images = {} self.cache = {} # tracks all objects by Handle. useful for debugging
def __init__(self, w, h, fullscreen, title="Unseen"): Renderer3DBase.__init__(self, w, h, fullscreen) PyUnseen.initialize(w, h, gotEvent, messageMap, title ) self.font1 = PyUnseen.createFont( "Arial", 9, 0 ) self.fixedFont = PyUnseen.createFont( "Courier", 7, 0 ) self.populateConstants() # store the actual height and width surface created (might be less than requested) #(getDesktop().width, getDesktop().height) = PyUnseen.getDesktopSize() (w, pyui.locals.TEXT_HEIGHT) = self.getTextSize(" ") self.images = {} self.cache = {} # tracks all objects by Handle. useful for debugging
def getTextSize(self, text, font = None): if font == 'fixed': font = self.fixedFont elif not font: font = self.font1 return PyUnseen.getTextSize(font, text)
def createView(self, world): """Create a view object and return the handle to it. Width and height ignored by PyUnseen """ handle = PyUnseen.createView(world) self.cache[handle] = "view" return handle
def rotateObjectTo(self, objectHandle, orientation, turnRate, onCompleted=None): return PyUnseen.rotateObjectTo(objectHandle, orientation, turnRate, onCompleted)
def getTextSize(self, text, font=None): if font == 'fixed': font = self.fixedFont elif not font: font = self.font1 return PyUnseen.getTextSize(font, text)
def quit(self): print "PyUnseen Quitting." PyUnseen.destroyFont(self.font1) PyUnseen.destroyFont(self.fixedFont) for filename in self.images.keys(): handle = self.images[filename] PyUnseen.destroyTexture(handle) self.dumpCache() PyUnseen.cleanup()
def attachObject(self, objectHandle, toObjectHandle, connectionPointName="", toConnectionPointName=""): return PyUnseen.attachObject(objectHandle, toObjectHandle, connectionPointName, toConnectionPointName)
def moveObject(self, objectHandle, delta, moveRate, turnRate=0, onCompleted=None): return PyUnseen.moveObject(objectHandle, delta, moveRate, turnRate, onCompleted)
def moveObjectTo(self, objectHandle, location, moveRate, turnRate=0, onCompleted=None): return PyUnseen.moveObjectTo(objectHandle, location, moveRate, turnRate, onCompleted)
def setObjectAnimation(self, objectHandle, animation, onCompleted=None, blendTime=0.0, loop=1): return PyUnseen.setObjectAnimation(objectHandle, animation, onCompleted, blendTime, loop)
def describeWindow(self, handle, drawList): if not handle: return #print "Describing window (%d): %s" % (handle, drawList) #print "Describing window ", handle #for d in drawList: # print d return PyUnseen.describeWindow(handle, drawList)
def addGeometryPiece(self, node, iType, info, offset, ypr, effect="", effectParams={}): return PyUnseen.addGeometryPiece(node, iType, info, offset, ypr, effect, effectParams)
def playMusic(self, waveFileName, completionCallback = None): return PyUnseen.playMusic(waveFileName, completionCallback)
def stopSound(self, waveFileName): return PyUnseen.stopSound(waveFileName)
def destroyFont(self, fontHandle): del self.cache[fontHandle] return PyUnseen.destroyFont(fontHandle)
def getObjectNode(self, objectHandle, nodeName, iLOD): return PyUnseen.getObjectNode(objectHandle, nodeName, iLOD)
def getObjectProjectedPos(self, objectHandle, viewHandle): return PyUnseen.getObjectProjectedPos(objectHandle, viewHandle)
def loadMusic(self, waveFileName): return PyUnseen.loadMusic(waveFileName)
def addGeometryNode(self, objectHandle, bone=0): return PyUnseen.addGeometryNode(objectHandle, bone)
def getNodeEffect(self, node, num): return PyUnseen.getNodeEffect(node, num)
def createEmptyBody(self, xyz=(0.0, 0.0, 0.0), label="emptyBody"): handle = PyUnseen.createEmptyBody(xyz) self.cache[handle] = label return handle
def setWindowEffect(self, windowHandle, effectName): return PyUnseen.setWindowViewEffect(windowHandle, effectName)
def toggleDebugInfo(self): return PyUnseen.togglePerfInfo()
def setEffectParameters(self, effect, parms): return PyUnseen.setEffectParameters(effect, parms)
def playMusic(self, waveFileName, completionCallback=None): return PyUnseen.playMusic(waveFileName, completionCallback)
def detachController(self, objectHandle, controllerHandle): return PyUnseen.detachController(objectHandle, controllerHandle)
def loadSound(self, waveFileName): return PyUnseen.loadSound(waveFileName)
def getNodeProjectedPos(self, nodeHandle, viewHandle): return PyUnseen.getNodeProjectedPos(nodeHandle, viewHandle)
def createFont(self, fontName, size, flag): handle = PyUnseen.createFont(fontName, size, flag) self.cache[handle] = "font %s %s" % ( fontName, size) return handle
def getScreenSize(self): return PyUnseen.getScreenSize()
def createFont(self, fontName, size, flag): handle = PyUnseen.createFont(fontName, size, flag) self.cache[handle] = "font %s %s" % (fontName, size) return handle
def stopMusic(self, waveFileName): return PyUnseen.stopMusic(waveFileName)
def createEmptyBody(self, xyz=(0.0,0.0,0.0), label="emptyBody"): handle= PyUnseen.createEmptyBody(xyz) self.cache[handle] = label return handle
def attachController(self, objectHandle, controllerType, boneName): return PyUnseen.attachController(objectHandle, controllerType, boneName)
def addGeometryPiece(self, node, iType, info, offset, ypr, effect = "", effectParams = {}): return PyUnseen.addGeometryPiece(node, iType, info, offset, ypr, effect, effectParams)
def setController(self, controllerHandle, **parms): return PyUnseen.setController(controllerHandle, parms)