├── .gitignore ├── screenshot.png ├── template.lua ├── desktop.ini ├── README.md ├── gameobjects ├── __init__.py ├── Point.py ├── Plane.py ├── Sphere.py ├── SphereAberration.py ├── Box.py ├── BoxAberration.py └── SpherePortal.py ├── gameobject.py ├── camera.py ├── scripteditor.py ├── scene.py ├── gui.py ├── util.py ├── setup.py └── editor.py /.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | dist/ 3 | Renderer/ 4 | 5 | *.pyc 6 | *.bat -------------------------------------------------------------------------------- /screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rameshvarun/Azathoth/HEAD/screenshot.png -------------------------------------------------------------------------------- /template.lua: -------------------------------------------------------------------------------- 1 | function preBuildShader() 2 | end 3 | 4 | function load() 5 | end 6 | 7 | function update(dt) 8 | end -------------------------------------------------------------------------------- /desktop.ini: -------------------------------------------------------------------------------- 1 | [.ShellClassInfo] 2 | IconFile=C:\Users\Varun Ramesh\AppData\Roaming\Dropbox\bin\Dropbox.exe 3 | IconIndex=-2301 4 | InfoTip=A securely backed up place to put your important files. 5 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Azathoth 2 | ======== 3 | 4 | ![](./screenshot.png) 5 | 6 | A level editor for non-euclidean worlds. Designed to be used with a real-time raytracer that I am developing. 7 | 8 | Dependencies 9 | ------------ 10 | Make sure that you don't mix and match 64-bit and 32-bit versions of the dependencies and the python interpreter. 11 | 12 | * Pygame - http://www.pygame.org/ 13 | * PyOpenGL - http://pyopengl.sourceforge.net/ 14 | * wxPython - http://wxpython.org/ 15 | * wxPropGrid - http://wxpropgrid.sourceforge.net/cgi-bin/index 16 | -------------------------------------------------------------------------------- /gameobjects/__init__.py: -------------------------------------------------------------------------------- 1 | import pkgutil 2 | 3 | types = {} 4 | 5 | add = {} 6 | 7 | import inspect 8 | 9 | def get_user_attributes(cls): 10 | boring = dir(type('dummy', (object,), {})) 11 | return [item 12 | for item in inspect.getmembers(cls) 13 | if item[0] not in boring] 14 | 15 | for loader, name, ispkg in pkgutil.walk_packages(__path__): 16 | module = __import__( "gameobjects." + name ) 17 | object_class = eval( name + "." + name ) 18 | 19 | types[name] = object_class 20 | 21 | print "Loaded GameObject type ", name -------------------------------------------------------------------------------- /gameobject.py: -------------------------------------------------------------------------------- 1 | 2 | 3 | import gui 4 | import scene 5 | 6 | class GameObject: 7 | def __init__(self): 8 | self.selected = False 9 | 10 | self.uniform = False 11 | self.edit = False 12 | 13 | self.pg = None 14 | 15 | self.cast = False 16 | self.recieve = False 17 | 18 | self.transparent = False 19 | 20 | if self.name == None: 21 | self.name = scene.uniqueName( self.type ) 22 | 23 | scene.objects[self.name] = self #Add back to scene 24 | 25 | #Add to gui tree 26 | self.treeitem = gui.tree_ctrl.AppendItem(gui.treeroot, self.name) 27 | gui.tree_ctrl.ExpandAll() 28 | 29 | print "Added " + self.type + " - " + self.name -------------------------------------------------------------------------------- /camera.py: -------------------------------------------------------------------------------- 1 | from math import * 2 | 3 | from OpenGL.GL import * 4 | from OpenGL.GLU import * 5 | 6 | import pygame 7 | from pygame.locals import * 8 | 9 | class Camera: 10 | def __init__(self): 11 | self.speed = 1 12 | self.theta = 1.24 13 | self.phi = 0.75 14 | 15 | self.old = False 16 | self.downX = 0 17 | self.downY = 0 18 | 19 | self.oldTheta = 0 20 | self.oldPhi = 0 21 | 22 | self.lookX = 0 23 | self.lookY = 0 24 | self.lookZ = 0 25 | 26 | 27 | self.x = 0 28 | self.y = 0 29 | self.z = 0 30 | 31 | self.ro = [0,0,0] 32 | self.rd = [0,0,0] 33 | 34 | def render(self): 35 | gluLookAt(self.x, self.y, self.z, self.x + self.lookX, self.y + self.lookY, self.z + self.lookZ, 0, 1, 0) 36 | 37 | 38 | glDisable(GL_LIGHTING) 39 | glBegin(GL_LINES) 40 | 41 | glColor3f(0,255,0) 42 | glVertex3f(self.ro[0], self.ro[1], self.ro[2]) 43 | glVertex3f(self.ro[0] + self.rd[0]*50, self.ro[1]+self.rd[1]*50, self.ro[2]+self.rd[2]*50) 44 | 45 | glEnd() 46 | 47 | glEnable(GL_LIGHTING) 48 | def update(self, dt): 49 | keys = pygame.key.get_pressed() 50 | 51 | if pygame.mouse.get_pressed()[2] == True and self.old == False: 52 | self.downX = pygame.mouse.get_pos()[0] 53 | self.downY = pygame.mouse.get_pos()[1] 54 | 55 | self.oldTheta = self.theta 56 | self.oldPhi = self.phi 57 | 58 | self.old = pygame.mouse.get_pressed()[2] 59 | 60 | 61 | 62 | if pygame.mouse.get_pressed()[2]: 63 | self.currX = pygame.mouse.get_pos()[0] 64 | self.currY = pygame.mouse.get_pos()[1] 65 | 66 | self.theta = self.oldTheta + float(self.currY - self.downY)/100 67 | self.phi = self.oldPhi + float(self.currX - self.downX)/100 68 | 69 | if self.theta < 0.5: 70 | self.theta = 0.5 71 | if self.theta > 3.14: 72 | self.theta = 3.14 73 | 74 | if keys[K_w]: 75 | self.x += sin(self.theta)*cos(self.phi)*self.speed 76 | self.y += cos(self.theta)*self.speed 77 | self.z += sin(self.theta)*sin(self.phi)*self.speed 78 | if keys[K_s]: 79 | self.x -= sin(self.theta)*cos(self.phi)*self.speed 80 | self.y -= cos(self.theta)*self.speed 81 | self.z -= sin(self.theta)*sin(self.phi)*self.speed 82 | if keys[K_d]: 83 | self.x += sin(self.theta)*cos(self.phi + 3.14/2)*self.speed 84 | self.z += sin(self.theta)*sin(self.phi + 3.14/2)*self.speed 85 | if keys[K_a]: 86 | self.x -= sin(self.theta)*cos(self.phi + 3.14/2)*self.speed 87 | self.z -= sin(self.theta)*sin(self.phi + 3.14/2)*self.speed 88 | if keys[K_e]: 89 | self.y += self.speed 90 | if keys[K_q]: 91 | self.y -= self.speed 92 | 93 | self.lookX = sin(self.theta)*cos(self.phi) 94 | self.lookY = cos(self.theta) 95 | self.lookZ = sin(self.theta)*sin(self.phi) 96 | 97 | cam = Camera() -------------------------------------------------------------------------------- /scripteditor.py: -------------------------------------------------------------------------------- 1 | import wx 2 | 3 | from wx.stc import * 4 | 5 | def GetText(): 6 | global script_ctrl 7 | return script_ctrl.GetText() 8 | 9 | def SetText(text): 10 | global script_ctrl 11 | 12 | text = text.replace("\n\n", "\n") 13 | 14 | script_ctrl.SetText(text) 15 | 16 | def initialize(): 17 | global script_ctrl 18 | 19 | luakeywords = "and break do else elseif end for function if local nil not or repeat return then until while" 20 | 21 | #Create script editor 22 | scriptedit = wx.Frame(None, wx.ID_ANY, "Script Editor", (10,10), (500,550)) 23 | 24 | script_ctrl = StyledTextCtrl(scriptedit, -1) 25 | 26 | script_ctrl.SetLexer(STC_LEX_LUA) 27 | 28 | script_ctrl.SetKeyWords(0, luakeywords) 29 | 30 | scriptedit.Show(True) 31 | 32 | #Load script template 33 | SetText( open("template.lua").read() ) 34 | 35 | #From Yellow Brain Styling Example 36 | #http://www.yellowbrain.com/stc/styling.html#example 37 | 38 | faces = { 'times': 'Courier New', 39 | 'mono' : 'Courier New', 40 | 'helv' : 'Courier New', 41 | 'other': 'Courier New', 42 | 'size' : 12, 43 | 'size2': 10, 44 | } 45 | 46 | # Global default styles for all languages 47 | script_ctrl.StyleSetSpec(STC_STYLE_DEFAULT, "face:%(helv)s,size:%(size)d" % faces) 48 | script_ctrl.StyleSetSpec(STC_STYLE_LINENUMBER, "back:#C0C0C0,face:%(helv)s,size:%(size2)d" % faces) 49 | script_ctrl.StyleSetSpec(STC_STYLE_CONTROLCHAR, "face:%(other)s" % faces) 50 | script_ctrl.StyleSetSpec(STC_STYLE_BRACELIGHT, "fore:#FFFFFF,back:#0000FF,bold") 51 | script_ctrl.StyleSetSpec(STC_STYLE_BRACEBAD, "fore:#000000,back:#FF0000,bold") 52 | 53 | # Python styles 54 | # White space 55 | script_ctrl.StyleSetSpec(STC_LUA_DEFAULT, "fore:#808080,face:%(helv)s,size:%(size)d" % faces) 56 | 57 | # Comment 58 | script_ctrl.StyleSetSpec(STC_LUA_COMMENTLINE, "fore:#007F00,face:%(other)s,size:%(size)d" % faces) 59 | 60 | # Number 61 | script_ctrl.StyleSetSpec(STC_LUA_NUMBER, "fore:#007F7F,size:%(size)d" % faces) 62 | 63 | # String 64 | script_ctrl.StyleSetSpec(STC_LUA_STRING, "fore:#7F007F,italic,face:%(times)s,size:%(size)d" % faces) 65 | 66 | # Single quoted string 67 | script_ctrl.StyleSetSpec(STC_LUA_CHARACTER, "fore:#7F007F,italic,face:%(times)s,size:%(size)d" % faces) 68 | 69 | # Keyword 70 | script_ctrl.StyleSetSpec(STC_LUA_WORD, "fore:#00007F,bold,size:%(size)d" % faces) 71 | 72 | # Triple quotes 73 | script_ctrl.StyleSetSpec(STC_LUA_LITERALSTRING, "fore:#7F0000,size:%(size)d" % faces) 74 | 75 | # Operators 76 | script_ctrl.StyleSetSpec(STC_LUA_OPERATOR, "bold,size:%(size)d" % faces) 77 | 78 | # Identifiers 79 | script_ctrl.StyleSetSpec(STC_LUA_IDENTIFIER, "fore:#808080,face:%(helv)s,size:%(size)d" % faces) 80 | 81 | # Comment-blocks 82 | script_ctrl.StyleSetSpec(STC_LUA_COMMENTDOC, "fore:#7F7F7F,size:%(size)d" % faces) 83 | 84 | # Comment-blocks 85 | script_ctrl.StyleSetSpec(STC_LUA_COMMENT, "fore:#7F7F7F,size:%(size)d" % faces) 86 | 87 | # End of line where string is not closed 88 | script_ctrl.StyleSetSpec(STC_LUA_STRINGEOL, "fore:#000000,face:%(mono)s,back:#E0C0E0,eol,size:%(size)d" % faces) -------------------------------------------------------------------------------- /gameobjects/Point.py: -------------------------------------------------------------------------------- 1 | from OpenGL.GL import * 2 | from OpenGL.GLU import * 3 | 4 | from util import * 5 | 6 | import gui 7 | import scene 8 | 9 | import wx #import wxWidgets 10 | import wx.propgrid as wxpg 11 | 12 | from gameobject import GameObject 13 | 14 | class Point ( GameObject ): 15 | def __init__(self, name = None, x = 1, y = 1, z = 1): 16 | self.name = name 17 | self.x = x 18 | self.y = y 19 | self.z = z 20 | 21 | self.type = "Point" 22 | 23 | self.pointselection = -1 24 | 25 | self.r = 1 26 | 27 | GameObject.__init__(self) 28 | 29 | @staticmethod 30 | def create(event): 31 | Point() 32 | 33 | @staticmethod 34 | def load(element): 35 | name = element.getAttribute("name") 36 | 37 | newobject = Point(name, float( element.getAttribute("x")) , float(element.getAttribute("y")) , float(element.getAttribute("z")) ) 38 | 39 | newobject.uniform = (element.getAttribute("uniform") == "True") 40 | 41 | return newobject 42 | 43 | def duplicate(self, newname): 44 | newsphere = Point(newname, self.x, self.y, self.z) 45 | 46 | newsphere.uniform = self.uniform 47 | 48 | return newsphere 49 | 50 | def center(self): 51 | return [self.x, self.y, self.z] 52 | 53 | def move(self, x, y, z): 54 | self.x += x 55 | self.y += y 56 | self.z += z 57 | 58 | if self.pg != None: 59 | self.pg.GetPropertyByName("Position.X").SetValue(self.x) 60 | self.pg.GetPropertyByName("Position.Y").SetValue(self.y) 61 | self.pg.GetPropertyByName("Position.Z").SetValue(self.z) 62 | 63 | def collide(self, ro, rd): 64 | return iSphere(self.x, self.y, self.z, self.r, ro, rd) 65 | 66 | #This has no edit mode 67 | def click(self, pos): 68 | pass 69 | 70 | def draw(self): 71 | glDisable(GL_LIGHTING) 72 | 73 | glLineWidth(2) 74 | 75 | glBegin(GL_LINES) 76 | 77 | #Y axis 78 | if self.selected: 79 | glColor3f(0,1,0) 80 | else: 81 | glColor3f(1, 1, 1) 82 | 83 | glVertex3f(self.x, self.y - self.r, self.z) 84 | glVertex3f(self.x, self.y + self.r, self.z) 85 | 86 | #Z axis 87 | glVertex3f(self.x, self.y, self.z - self.r) 88 | glVertex3f(self.x, self.y, self.z + self.r) 89 | 90 | #X axis 91 | glVertex3f(self.x - self.r, self.y, self.z) 92 | glVertex3f(self.x + self.r, self.y, self.z) 93 | 94 | glEnd() 95 | 96 | glLineWidth(1) 97 | 98 | glEnable(GL_LIGHTING) 99 | 100 | drawText3d((self.x, self.y + self.r, self.z), self.name, 32) 101 | 102 | def PropertyChange(self, event): 103 | p = event.GetProperty() 104 | if p: 105 | print p.GetName() + " changed." 106 | 107 | #General Properties 108 | if p.GetName() == "Object Name": 109 | del scene.objects[self.name] 110 | self.name = p.GetValue() 111 | scene.objects[self.name] = self 112 | gui.tree_ctrl.SetItemText(self.treeitem, self.name) 113 | if p.GetName() == "Uniform": 114 | self.uniform = p.GetValue() 115 | 116 | if p.GetName() == "Position.X": 117 | self.x = p.GetValue() 118 | if p.GetName() == "Position.Y": 119 | self.y = p.GetValue() 120 | if p.GetName() == "Position.Z": 121 | self.z = p.GetValue() 122 | 123 | def populatepropgrid(self, pg): 124 | #Geometry Properties 125 | pg.Append( wxpg.PropertyCategory("Geometry") ) 126 | 127 | normalID = pg.Append( wxpg.StringProperty("Position", value="") ) 128 | pg.AppendIn (normalID, wxpg.FloatProperty("X", value=self.x) ) 129 | pg.AppendIn (normalID, wxpg.FloatProperty("Y", value=self.y) ) 130 | pg.AppendIn (normalID, wxpg.FloatProperty("Z", value=self.z) ) 131 | 132 | def write(self, object): 133 | object.setAttribute("x", str(self.x) ) 134 | object.setAttribute("y", str(self.y) ) 135 | object.setAttribute("z", str(self.z) ) -------------------------------------------------------------------------------- /scene.py: -------------------------------------------------------------------------------- 1 | from OpenGL.GL import * 2 | from OpenGL.GLU import * 3 | 4 | from xml.dom.minidom import getDOMImplementation 5 | from xml.dom.minidom import parse 6 | 7 | import subprocess 8 | 9 | import os 10 | 11 | import gui 12 | import scripteditor 13 | 14 | import gameobjects 15 | 16 | import wx 17 | 18 | from util import * 19 | 20 | from camera import * 21 | 22 | def initialize(): 23 | global objects 24 | global currentfile 25 | 26 | #Dictionary of all objects in scene 27 | objects = {} 28 | 29 | #The current file that the editor is working on 30 | currentfile = "empty" 31 | 32 | #A helper function for generating a unique name that is not currently being used for an object in the scene 33 | def uniqueName(stub): 34 | counter = 1 35 | while (stub + str(counter)) in objects: 36 | counter += 1 37 | 38 | return (stub + str(counter)) 39 | 40 | #Clear the entire scene 41 | def clearScene(): 42 | #Clear both the GUI tree and the objects list 43 | gui.tree_ctrl.DeleteAllItems() 44 | objects.clear() 45 | 46 | #Re-add the root element of the scene tree 47 | gui.treeroot = gui.tree_ctrl.AddRoot('Scene') 48 | gui.tree_ctrl.ExpandAll() 49 | 50 | #Clear script 51 | scripteditor.SetText( "" ) 52 | 53 | def newFile(event): 54 | global currentfile 55 | currentfile = "empty" 56 | 57 | clearScene() 58 | 59 | def getText(n): 60 | rc = [] 61 | for node in n.childNodes: 62 | if node.nodeType == node.TEXT_NODE: 63 | rc.append(node.data) 64 | return ''.join(rc) 65 | 66 | #Function that loads a scene from a file 67 | def openFile(event): 68 | global currentfile 69 | 70 | clearScene() #Clear current scene first 71 | 72 | openFileDialog = wx.FileDialog(gui.frame, "Open a scene file", "", "","XML file (*.xml)|*.xml", wx.FD_OPEN | wx.FD_FILE_MUST_EXIST) 73 | 74 | if openFileDialog.ShowModal() == wx.ID_CANCEL: 75 | return 76 | 77 | currentfile = openFileDialog.GetPath() 78 | 79 | doc = parse(currentfile) 80 | 81 | 82 | 83 | #For every xml element with tag 84 | for camObj in doc.getElementsByTagName("Camera"): 85 | cam.phi = float(camObj.getAttribute("phi")) 86 | cam.theta = float(camObj.getAttribute("theta")) 87 | 88 | cam.speed = float(camObj.getAttribute("speed")) 89 | 90 | cam.x = float(camObj.getAttribute("x")) 91 | cam.y = float(camObj.getAttribute("y")) 92 | cam.z = float(camObj.getAttribute("z")) 93 | 94 | #Load in all the object types 95 | for class_name in gameobjects.types.keys(): 96 | for object_element in doc.getElementsByTagName( class_name ): 97 | gameobjects.types[class_name].load(object_element) 98 | 99 | for script in doc.getElementsByTagName("script"): 100 | scripteditor.SetText( getText(script) ) 101 | 102 | def writeXML(filename): 103 | 104 | file = None 105 | 106 | doc = getDOMImplementation().createDocument(None, "scene", None) 107 | 108 | camera = doc.createElement("Camera") 109 | camera.setAttribute("x", str(cam.x) ) 110 | camera.setAttribute("y", str(cam.y) ) 111 | camera.setAttribute("z", str(cam.z) ) 112 | 113 | camera.setAttribute("theta", str(cam.theta) ) 114 | camera.setAttribute("phi", str(cam.phi) ) 115 | camera.setAttribute("speed", str(cam.speed) ) 116 | 117 | doc.documentElement.appendChild(camera) 118 | 119 | for obj in objects.values(): 120 | object = doc.createElement(obj.type) 121 | 122 | object.setAttribute("name", obj.name) 123 | 124 | object.setAttribute("uniform", str(obj.uniform) ) 125 | 126 | obj.write(object) 127 | 128 | object.setAttribute("selected", str(obj.selected) ) 129 | 130 | doc.documentElement.appendChild(object) 131 | 132 | script = doc.createElement("script") 133 | script.appendChild( doc.createTextNode( scripteditor.GetText() ) ) 134 | doc.documentElement.appendChild(script) 135 | 136 | file = open(filename, "w") 137 | file.write( doc.toprettyxml() ) 138 | file.close() 139 | 140 | def saveFile(event): 141 | global currentfile 142 | 143 | if currentfile == "empty": 144 | saveFileDialog = wx.FileDialog(gui.frame, "Save a scene file", "", "","XML file (*.xml)|*.xml", wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT) 145 | 146 | if saveFileDialog.ShowModal() == wx.ID_CANCEL: 147 | return 148 | 149 | currentfile = saveFileDialog.GetPath() 150 | 151 | writeXML(currentfile) 152 | 153 | #Triggered by menu button, runs current scene in game engine 154 | def runTest(event): 155 | writeXML("Renderer\\test.xml") #Save file 156 | 157 | subprocess.Popen("Renderer\\NonEuclid.exe", cwd="Renderer\\") #Start game process -------------------------------------------------------------------------------- /gui.py: -------------------------------------------------------------------------------- 1 | #File that handles all GUI-Related stuff 2 | import threading, os, sys, time 3 | import wx #import wxWidgets 4 | import wx.stc 5 | import wx.propgrid as wxpg 6 | import scene 7 | 8 | import scripteditor 9 | 10 | import gameobjects 11 | 12 | #Callback for exiting application 13 | def closeFile(event): 14 | os._exit(0) 15 | 16 | def initialize(): 17 | global app, evtloop, frame, editframe, currentselection, tree_ctrl, treeroot 18 | 19 | app = wx.App(False) 20 | 21 | 22 | evtloop = wx.EventLoop() 23 | old = wx.EventLoop.GetActive() 24 | wx.EventLoop.SetActive(evtloop) 25 | 26 | 27 | #Create main window 28 | frame = wx.Frame(None, wx.ID_ANY, "Non-Euclidean Level Editor", (10,10), (250,550)) 29 | frame.Show(True) 30 | 31 | filemenu = wx.Menu() 32 | addmenu = wx.Menu() 33 | runmenu = wx.Menu() 34 | 35 | frame.CreateStatusBar() 36 | 37 | frame.Bind(wx.EVT_CLOSE, closeFile) 38 | 39 | scripteditor.initialize() 40 | 41 | menuBar = wx.MenuBar() 42 | menuBar.Append(filemenu,"&File") 43 | menuBar.Append(addmenu,"&Add") 44 | menuBar.Append(runmenu,"&Run") 45 | frame.SetMenuBar(menuBar) 46 | 47 | #Create all of the actions under the file menu 48 | new = filemenu.Append(wx.ID_NEW, "&New","Create a new scene.") 49 | open = filemenu.Append(wx.ID_OPEN, "&Open","Open an existing scene file.") 50 | save = filemenu.Append(wx.ID_SAVE, "&Save","Save the current scene file.") 51 | close = filemenu.Append(wx.ID_EXIT, "&Exit","Exit the editor.") 52 | 53 | #Bind a function to every action under the file menu 54 | frame.Bind(wx.EVT_MENU, scene.newFile, new) 55 | frame.Bind(wx.EVT_MENU, scene.openFile, open) 56 | frame.Bind(wx.EVT_MENU, scene.saveFile, save) 57 | frame.Bind(wx.EVT_MENU, closeFile, close) 58 | 59 | #Create all of the menu items under the Add menu 60 | 61 | for key, value in gameobjects.types.items(): 62 | addmenu_item = addmenu.Append(wx.ID_ANY, "&" + key,"Create a new " + key + ".") 63 | 64 | frame.Bind(wx.EVT_MENU, value.create, addmenu_item) 65 | 66 | #Create/Bind a function to the runTest item 67 | runtest = runmenu.Append(wx.ID_ANY, "&Run Test","Run a test of the map within the actual game engine.") 68 | frame.Bind(wx.EVT_MENU, scene.runTest, runtest) 69 | 70 | 71 | #Create the tree view 72 | tree_ctrl = wx.TreeCtrl(frame, -1, style=wx.TR_DEFAULT_STYLE | wx.TR_FULL_ROW_HIGHLIGHT | wx.TR_EDIT_LABELS | wx.TR_MULTIPLE) 73 | treeroot = tree_ctrl.AddRoot('Scene') 74 | tree_ctrl.ExpandAll() 75 | 76 | #Create the edit window 77 | editframe = wx.Frame( None, -1, "Properties Window", (1280,10), (350,550) ) 78 | 79 | editframe.panel = PropertyGridPanel(editframe) 80 | 81 | editframe.Show() 82 | editframe.Bind(wx.EVT_CLOSE, closeFile) 83 | 84 | currentselection = None 85 | editframe.panel.delete.Hide() 86 | 87 | frame.Bind(wx.EVT_TREE_SEL_CHANGED, updateSelection, tree_ctrl) 88 | 89 | class PropertyGridPanel(wx.Panel): 90 | def __init__(self, parent): 91 | wx.Panel.__init__(self, parent, -1, style=wx.WANTS_CHARS) 92 | topsizer = wx.BoxSizer(wx.VERTICAL) 93 | self.pg = pg = wxpg.PropertyGrid(self, style=wxpg.PG_SPLITTER_AUTO_CENTER|wxpg.PG_TOOLBAR) 94 | 95 | pg.SetExtraStyle(wxpg.PG_EX_HELP_AS_TOOLTIPS | wxpg.PG_EX_MULTIPLE_SELECTION) 96 | topsizer.Add(pg,1,wx.EXPAND) 97 | rowsizer = wx.BoxSizer(wx.HORIZONTAL) 98 | self.delete = wx.Button(self,-1,"Delete Object") 99 | 100 | rowsizer.Add(self.delete,1) 101 | 102 | topsizer.Add(rowsizer,0,wx.EXPAND) 103 | self.SetSizer(topsizer) 104 | topsizer.SetSizeHints(self) 105 | 106 | def updateSelection(event): 107 | for obj in scene.objects.values(): 108 | if tree_ctrl.IsSelected(obj.treeitem): 109 | obj.selected = True 110 | else: 111 | obj.selected = False 112 | 113 | def update(): 114 | global currentselection 115 | 116 | while evtloop.Pending(): 117 | evtloop.Dispatch() 118 | 119 | #time.sleep(0.10) 120 | app.ProcessIdle() 121 | 122 | newselection = None 123 | for obj in scene.objects.values(): 124 | if obj.selected: 125 | newselection = obj 126 | break 127 | 128 | if currentselection != newselection: 129 | if currentselection != None: 130 | currentselection.pg = None 131 | 132 | currentselection = newselection 133 | 134 | editframe.panel.pg.Clear() 135 | 136 | if currentselection == None: 137 | editframe.SetTitle("Properties Window") 138 | editframe.panel.delete.Hide() 139 | else: 140 | currentselection.pg = editframe.panel.pg 141 | 142 | currentselection.pg.Bind( wxpg.EVT_PG_CHANGED, currentselection.PropertyChange ) 143 | 144 | editframe.SetTitle("Properties of " + currentselection.name) 145 | editframe.panel.delete.Show() 146 | 147 | pg = editframe.panel.pg 148 | 149 | pg.Append( wxpg.PropertyCategory("General") ) 150 | pg.Append( wxpg.StringProperty("Object Name", value=currentselection.name) ) 151 | pg.Append( wxpg.BoolProperty("Uniform",value=currentselection.uniform) ) 152 | pg.SetPropertyAttribute("Uniform", "UseCheckbox", True) 153 | 154 | currentselection.populatepropgrid(pg) -------------------------------------------------------------------------------- /util.py: -------------------------------------------------------------------------------- 1 | import math 2 | from OpenGL.GL import * 3 | from OpenGL.GLU import * 4 | 5 | import pygame 6 | 7 | #Turns a vector of either length 3 or 2 into a string 8 | def formatString(v): 9 | if len(v) == 3: 10 | return str(v[0]) + ", " + str(v[1]) + ", " + str(v[2]) 11 | if len(v) == 2: 12 | return str(v[0]) + ", " + str(v[1]) 13 | 14 | #Turns a list of strings into a list of floats 15 | def toFloats(val): 16 | returnval = [] 17 | 18 | for s in val: 19 | returnval.append( float(s) ) 20 | 21 | return returnval 22 | 23 | #Cross-product of two Vectors 24 | def cross(v1, v2): 25 | c1 = v1[1]*v2[2] - v1[2]*v2[1] 26 | c2 = v1[2]*v2[0] - v1[0]*v2[2] 27 | c3 = v1[0]*v2[1] - v1[1]*v2[0] 28 | 29 | return [c1, c2, c3] 30 | 31 | #Normalize a vector 32 | def norm(v): 33 | mag = math.sqrt( v[0]*v[0] + v[1]*v[1] + v[2]*v[2] ) 34 | return [v[0] / mag, v[1] / mag, v[2] / mag] 35 | 36 | #Calculate the dot-product of two vectors 37 | def dot(v1, v2): 38 | if len(v1) == 3 and len(v2) == 3: 39 | return v1[0]*v2[0] + v1[1]*v2[1] + v1[2]*v2[2] 40 | if len(v1) == 2 and len(v2) == 2: 41 | return v1[0]*v2[0] + v1[1]*v2[1] 42 | 43 | #Given a ray and a box, return the intersection point 44 | #ro -- Ray Origin 45 | #rd -- Ray Direction 46 | #min -- Lower corner of box 47 | #max -- Upper corner of box 48 | def iBox(min, max, ro, rd): 49 | if min[0] < ro[0] and min[1] < ro[1] and min[2] < ro[2]: 50 | if max[0] > ro[0] and max[1] > ro[1] and max[2] > ro[2]: 51 | return False, 0 52 | 53 | tmin = ( min[0] - ro[0] ) / rd[0] 54 | tmax = ( max[0] - ro[0] ) / rd[0] 55 | 56 | if tmin > tmax: 57 | temp = tmin 58 | tmin = tmax 59 | tmax = temp 60 | 61 | tymin = ( min[1] - ro[1] ) / rd[1] 62 | tymax = ( max[1] - ro[1] ) / rd[1] 63 | 64 | if tymin > tymax: 65 | temp = tymin 66 | tymin = tymax 67 | tymax = temp 68 | 69 | if (tmin > tymax) or (tymin > tmax) : 70 | return False, 0 71 | 72 | if (tymin > tmin): 73 | tmin = tymin 74 | if (tymax < tmax): 75 | tmax = tymax 76 | 77 | tzmin = ( min[2] - ro[2] ) / rd[2] 78 | tzmax = ( max[2] - ro[2] ) / rd[2] 79 | 80 | if(tzmin > tzmax): 81 | temp = tzmin 82 | tzmin = tzmax 83 | tzmax = temp 84 | 85 | if ((tmin > tzmax) or (tzmin > tmax)): 86 | return False, 0 87 | 88 | if (tzmin > tmin): 89 | tmin = tzmin 90 | if (tzmax < tmax): 91 | tmax = tzmax 92 | 93 | if ( tmax < 0.0 ): 94 | return False, 0 95 | 96 | t = tmin 97 | 98 | return True, t 99 | 100 | #Draws text in the 3D world 101 | def drawText3d(position, textString, size): 102 | font = pygame.font.Font (None, size) 103 | textSurface = font.render(textString, True, (255,255,255,255), (0,0,0,255)) 104 | textData = pygame.image.tostring(textSurface, "RGBA", True) 105 | glRasterPos3d(*position) 106 | glDrawPixels(textSurface.get_width(), textSurface.get_height(), GL_RGBA, GL_UNSIGNED_BYTE, textData) 107 | 108 | #Draws text based off of a 2D screen position 109 | def drawText2d(position, textString, size): 110 | font = pygame.font.Font (None, size) 111 | textSurface = font.render(textString, True, (255,255,255,255), (0,0,0,255)) 112 | textData = pygame.image.tostring(textSurface, "RGBA", True) 113 | glWindowPos2d(*position) 114 | glDrawPixels(textSurface.get_width(), textSurface.get_height(), GL_RGBA, GL_UNSIGNED_BYTE, textData) 115 | 116 | #Intersect a ray with a plane 117 | #(x, y, z) = normal of plane 118 | #w = distance along normal 119 | #These values follow the plane equation: n*pos = w 120 | #ro - Ray origin 121 | #rd - Ray direction 122 | def iPlane(x, y, z, w, ro, rd): 123 | t = -(dot( [x, y, z] ,ro) + w)/dot( [x, y, z] ,rd) 124 | 125 | if t > 0.0: 126 | return True, t 127 | else: 128 | return False, 0 129 | 130 | #Intersect a ray with a sphere 131 | #(x, y, z) = center of sphere 132 | #r = radius of sphere 133 | #ro - Ray origin 134 | #rd - Ray direction 135 | def iSphere(x, y, z, r, ro, rd): 136 | d = [ ro[0] - x, ro[1] - y, ro[2] - z ]; 137 | b = dot(rd, d) 138 | c = dot(d, d) - r*r 139 | 140 | t = b*b - c 141 | if t > 0.0: 142 | t = - b - math.sqrt(t) 143 | return True, t 144 | 145 | return False, 0 146 | #Add two vectors 147 | def add(v1, v2): 148 | return [ v1[0] + v2[0] , v1[1] + v2[1], v1[2] + v2[2] ] 149 | 150 | #Subtract v2 from v1 151 | def subtract(v1, v2): 152 | return [ v1[0] - v2[0] , v1[1] - v2[1], v1[2] - v2[2] ] 153 | 154 | #Distance betweem two points 155 | def dist(v1, v2): 156 | if len(v1) == 3 and len(v2) == 3: 157 | return math.sqrt( math.pow(v2[0] - v1[0], 2) + math.pow(v2[1] - v1[1], 2) + math.pow(v2[2] - v1[2], 2)) 158 | if len(v1) == 2 and len(v2) == 2: 159 | return math.sqrt( math.pow(v2[0] - v1[0], 2) + math.pow(v2[1] - v1[1], 2) ) 160 | 161 | #Multiply a vetor by a scalar 162 | def mult(scalar, v): 163 | return [ scalar*v[0], scalar*v[1], scalar*v[2] ] 164 | 165 | #Call to draw a 166 | def movetool(x, y, z, scale): 167 | glLineWidth(10) #Make lines very thick 168 | 169 | glDisable(GL_DEPTH_TEST) 170 | 171 | 172 | glDisable(GL_LIGHTING) 173 | glBegin(GL_LINES) 174 | 175 | #Y axis 176 | glColor3f(0,255,0) 177 | glVertex3f(x, y, z) 178 | glColor3f(0,255,0) 179 | glVertex3f(x, y + scale, z) 180 | 181 | #Z axis 182 | glColor3f(0,0,255) 183 | glVertex3f(x, y, z) 184 | glColor3f(0,0,255) 185 | glVertex3f(x, y, z + scale) 186 | 187 | #X axis 188 | glColor3f(255,0,0) 189 | glVertex3f(x, y, z) 190 | glColor3f(255,0,0) 191 | glVertex3f(x + scale, y, z) 192 | 193 | glEnd() 194 | 195 | glEnable(GL_LIGHTING) 196 | 197 | glLineWidth(1) #Return lines to their normal size 198 | 199 | glEnable(GL_DEPTH_TEST) -------------------------------------------------------------------------------- /gameobjects/Plane.py: -------------------------------------------------------------------------------- 1 | from OpenGL.GL import * 2 | from OpenGL.GLU import * 3 | 4 | from util import * 5 | 6 | import gui 7 | import scene 8 | 9 | import wx #import wxWidgets 10 | import wx.propgrid as wxpg 11 | 12 | from gameobject import GameObject 13 | 14 | class Plane ( GameObject ): 15 | def __init__(self, name = None, x = 0, y = 1, z = 0, c = 0): 16 | self.type = "Plane" 17 | 18 | self.name = name 19 | 20 | n = norm( [x, y, z] ) 21 | 22 | self.x = n[0] 23 | self.y = n[1] 24 | self.z = n[2] 25 | self.c = -c 26 | 27 | self.reflectivity = 0.0 28 | 29 | self.extension = 1000 30 | 31 | GameObject.__init__(self) 32 | 33 | @staticmethod 34 | def create(event): 35 | Plane() 36 | 37 | @staticmethod 38 | def load(element): 39 | newobject = Plane(element.getAttribute("name"), float(element.getAttribute("x")) , float(element.getAttribute("y")) , float(element.getAttribute("z")) , float(element.getAttribute("c")) ) 40 | 41 | newobject.selected = (element.getAttribute("selected") == "True") 42 | 43 | newobject.uniform = (element.getAttribute("uniform") == "True") 44 | newobject.reflectivity = float(element.getAttribute("reflectivity")) 45 | newobject.recieve = (element.getAttribute("recieve") == "True") 46 | 47 | return newobject 48 | 49 | def duplicate(self, newname): 50 | newplane = Plane(newname, self.x, self.y, self.z, -self.c) 51 | 52 | newplane.reflectivity = self.reflectivity 53 | newplane.uniform = self.uniform 54 | newplane.recieve = self.recieve 55 | 56 | return newplane 57 | 58 | def center(self): 59 | return (self.x * self.c, self.y * self.c, self.z * self.c) 60 | def move(self, x, y, z): 61 | pass 62 | def collide(self, ro, rd): 63 | return iPlane(self.x, self.y, self.z, -self.c, ro, rd) 64 | def uniformChanged(self, event): 65 | print event.widget.variable.get() 66 | def draw(self): 67 | glEnable(GL_LIGHTING) 68 | glDisable(GL_CULL_FACE) 69 | 70 | glMaterialfv(GL_FRONT, GL_DIFFUSE, (1.0, 1.0, 1.0, 1.0)) 71 | 72 | glBegin(GL_QUADS) 73 | 74 | glNormal3f( self.x, self.y, self.z) 75 | 76 | origin = (self.x * self.c, self.y * self.c, self.z * self.c) 77 | 78 | v1 = norm( cross( ( self.x, self.y, self.z), ( self.x + 1, self.y, self.z) ) ) 79 | 80 | v2 = norm( cross( ( self.x, self.y, self.z), v1) ) 81 | 82 | 83 | glVertex3f( origin[0] - self.extension*v1[0] - self.extension*v2[0], origin[1] - self.extension*v1[1] - self.extension*v2[1], origin[2] - self.extension*v1[2] - self.extension*v2[2]) 84 | 85 | glVertex3f( origin[0] - self.extension*v1[0] + self.extension*v2[0], origin[1] - self.extension*v1[1] + self.extension*v2[1], origin[2] - self.extension*v1[2] + self.extension*v2[2] ) 86 | 87 | glVertex3f( origin[0] + self.extension*v1[0] + self.extension*v2[0], origin[1] + self.extension*v1[1] + self.extension*v2[1], origin[2] + self.extension*v1[2] + self.extension*v2[2] ) 88 | 89 | glVertex3f( origin[0] + self.extension*v1[0] - self.extension*v2[0], origin[1] + self.extension*v1[1] - self.extension*v2[1], origin[2] + self.extension*v1[2] - self.extension*v2[2] ) 90 | 91 | glEnd() 92 | 93 | glEnable(GL_CULL_FACE) 94 | 95 | glDisable(GL_LIGHTING) 96 | 97 | glLineWidth(2) 98 | 99 | glBegin(GL_LINES) 100 | 101 | if self.edit: 102 | glColor3f(1, 0.62745, 0.176470) 103 | elif self.selected: 104 | glColor3f(0,1,0) 105 | else: 106 | glColor3f(1, 1, 1) 107 | 108 | glVertex3f(origin[0], origin[1], origin[2] ) 109 | glVertex3f( origin[0] + 10*self.x, origin[1] + 10*self.y, origin[2] + 10*self.z) 110 | 111 | 112 | glVertex3f(origin[0], origin[1], origin[2] ) 113 | glVertex3f( origin[0] + 10*v1[0], origin[1] + 10*v1[1], origin[2] + 10*v1[2]) 114 | 115 | glVertex3f(origin[0], origin[1], origin[2] ) 116 | glVertex3f( origin[0] + 10*v2[0], origin[1] + 10*v2[1], origin[2] + 10*v2[2]) 117 | 118 | glEnd() 119 | 120 | glLineWidth(1) 121 | 122 | glEnable(GL_LIGHTING) 123 | 124 | def PropertyChange(self, event): 125 | p = event.GetProperty() 126 | if p: 127 | print p.GetName() + " changed." 128 | 129 | #General Properties 130 | if p.GetName() == "Object Name": 131 | del scene.objects[self.name] 132 | self.name = p.GetValue() 133 | scene.objects[self.name] = self 134 | gui.tree_ctrl.SetItemText(self.treeitem, self.name) 135 | if p.GetName() == "Uniform": 136 | self.uniform = p.GetValue() 137 | 138 | #Geometry Properties 139 | if p.GetName() == "C": 140 | self.c = -p.GetValue() 141 | 142 | if p.GetName() == "Normal": 143 | 144 | n = norm( [self.pg.GetPropertyByName("Normal.X").GetValue(), 145 | self.pg.GetPropertyByName("Normal.Y").GetValue(), 146 | self.pg.GetPropertyByName("Normal.Z").GetValue()] ) 147 | 148 | self.x = n[0] 149 | self.y = n[1] 150 | self.z = n[2] 151 | 152 | #Material Properties 153 | if p.GetName() == "Reflectivity": 154 | self.reflectivity = p.GetValue() 155 | if p.GetName() == "Recieve Shadows": 156 | self.recieve = p.GetValue() 157 | def populatepropgrid(self, pg): 158 | #Geometry Properties 159 | pg.Append( wxpg.PropertyCategory("Geometry") ) 160 | 161 | normalID = pg.Append( wxpg.StringProperty("Normal", value="") ) 162 | pg.AppendIn (normalID, wxpg.FloatProperty("X", value=self.x) ) 163 | pg.AppendIn (normalID, wxpg.FloatProperty("Y", value=self.y) ) 164 | pg.AppendIn (normalID, wxpg.FloatProperty("Z", value=self.z) ) 165 | 166 | pg.Append( wxpg.FloatProperty("C", value=self.c) ) 167 | 168 | 169 | pg.Append( wxpg.PropertyCategory("Material") ) 170 | 171 | pg.Append( wxpg.FloatProperty("Reflectivity", value=self.reflectivity) ) 172 | 173 | pg.Append( wxpg.BoolProperty("Recieve Shadows",value=self.recieve) ) 174 | pg.SetPropertyAttribute("Recieve Shadows", "UseCheckbox", True) 175 | def write(self, object): 176 | object.setAttribute("x", str(self.x) ) 177 | object.setAttribute("y", str(self.y) ) 178 | object.setAttribute("z", str(self.z) ) 179 | object.setAttribute("c", str(-self.c) ) 180 | 181 | object.setAttribute("reflectivity", str(self.reflectivity) ) 182 | object.setAttribute("recieve", str(self.recieve) ) -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | # ======================================================# 2 | # File automagically generated by GUI2Exe version 0.3 3 | # Andrea Gavana, 01 April 2007 4 | # ======================================================# 5 | 6 | # Let's start with some default (for me) imports... 7 | 8 | from distutils.core import setup 9 | import py2exe 10 | import glob 11 | import os 12 | import zlib 13 | import shutil 14 | import sys 15 | import zipfile 16 | 17 | #hack which fixes the pygame mixer and pygame font 18 | origIsSystemDLL = py2exe.build_exe.isSystemDLL # save the orginal before we edit it 19 | def isSystemDLL(pathname): 20 | # checks if the freetype and ogg dll files are being included 21 | if os.path.basename(pathname).lower() in ("libfreetype-6.dll", "libogg-0.dll","sdl_ttf.dll"): # "sdl_ttf.dll" added by arit. 22 | return 0 23 | return origIsSystemDLL(pathname) # return the orginal function 24 | py2exe.build_exe.isSystemDLL = isSystemDLL # override the default function with this one 25 | 26 | 27 | # Remove the build folder 28 | shutil.rmtree("build", ignore_errors=True) 29 | 30 | # do the same for dist folder 31 | shutil.rmtree("dist", ignore_errors=True) 32 | 33 | MANIFEST_TEMPLATE = """ 34 | 35 | 36 | 42 | %(prog)s 43 | 44 | 45 | 46 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 61 | 62 | 63 | 64 | 65 | 66 | 74 | 75 | 76 | 77 | """ 78 | 79 | class Target(object): 80 | """ A simple class that holds information on our executable file. """ 81 | def __init__(self, **kw): 82 | """ Default class constructor. Update as you need. """ 83 | self.__dict__.update(kw) 84 | 85 | 86 | # Ok, let's explain why I am doing that. 87 | # Often, data_files, excludes and dll_excludes (but also resources) 88 | # can be very long list of things, and this will clutter too much 89 | # the setup call at the end of this file. So, I put all the big lists 90 | # here and I wrap them using the textwrap module. 91 | 92 | data_files = [] 93 | 94 | includes = [] 95 | excludes = ['_gtkagg', '_tkagg', 'bsddb', 'curses', 'email', 'pywin.debugger', 96 | 'pywin.debugger.dbgcon', 'pywin.dialogs', 'tcl', 97 | 'Tkconstants', 'Tkinter'] 98 | packages = [] 99 | dll_excludes = ['libgdk-win32-2.0-0.dll', 'libgobject-2.0-0.dll', 'tcl84.dll', 100 | 'tk84.dll', 101 | 'MSVCP90.dll', 'mswsock.dll', 'powrprof.dll'] 102 | icon_resources = [] 103 | bitmap_resources = [] 104 | other_resources = [] 105 | other_resources = [(24, 1, MANIFEST_TEMPLATE % dict(prog="Non-Euclidean Level Editor"))] 106 | 107 | 108 | # This is a place where the user custom code may go. You can do almost 109 | # whatever you want, even modify the data_files, includes and friends 110 | # here as long as they have the same variable name that the setup call 111 | # below is expecting. 112 | 113 | 114 | # 115 | # The following will copy the MSVC run time dll's 116 | # (msvcm90.dll, msvcp90.dll and msvcr90.dll) and 117 | # the Microsoft.VC90.CRT.manifest which I keep in the 118 | # "Py26MSdlls" folder to the dist folder 119 | # 120 | # depending on wx widgets you use, you might need to add 121 | # gdiplus.dll to the above collection 122 | 123 | py26MSdll = glob.glob(r"c:\Dev\Py26MSdlls-9.0.21022.8\msvc\*.*") 124 | 125 | # install the MSVC 9 runtime dll's into the application folder 126 | data_files += [("", py26MSdll),] 127 | 128 | # I found on some systems one has to put them into sub-folders. 129 | ##data_files += [("Microsoft.VC90.CRT", py26MSdll), 130 | ## ("lib\Microsoft.VC90.CRT", py26MSdll)] 131 | 132 | 133 | 134 | # Ok, now we are going to build our target class. 135 | # I chose this building strategy as it works perfectly for me :-D 136 | 137 | 138 | GUI2Exe_Target_1 = Target( 139 | # what to build 140 | script = "editor.py", 141 | icon_resources = icon_resources, 142 | bitmap_resources = bitmap_resources, 143 | other_resources = other_resources, 144 | dest_base = "editor", 145 | version = "0.1", 146 | company_name = "Varun Ramesh", 147 | copyright = "Copyright 2013 Varun Ramesh", 148 | name = "Non-Euclidean Level Editor" 149 | ) 150 | 151 | 152 | 153 | # That's serious now: we have all (or almost all) the options py2exe 154 | # supports. I put them all even if some of them are usually defaulted 155 | # and not used. Some of them I didn't even know about. 156 | 157 | setup( 158 | 159 | data_files = data_files, 160 | 161 | options = {"py2exe": {"compressed": 2, 162 | "optimize": 2, 163 | "includes": includes, 164 | "excludes": excludes, 165 | "packages": packages, 166 | "dll_excludes": dll_excludes, 167 | "bundle_files": 3, 168 | "dist_dir": "dist", 169 | "xref": False, 170 | "skip_archive": False, 171 | "ascii": False, 172 | "custom_boot_script": '', 173 | } 174 | }, 175 | 176 | zipfile = "lib/library.zip", 177 | console = [], 178 | windows = [GUI2Exe_Target_1] 179 | ) 180 | 181 | # This is a place where any post-compile code may go. 182 | # You can add as much code as you want, which can be used, for example, 183 | # to clean up your folders or to do some particular post-compilation 184 | # actions. 185 | 186 | # And we are done. That's a setup script :-D 187 | 188 | 189 | def recursive_zip(zipf, directory, folder=None): 190 | print "Searching " + directory 191 | list = os.listdir(directory) 192 | for file in list: 193 | if os.path.isfile(os.path.join(directory, file)) and (folder + "/" + file) not in zipf.namelist(): 194 | zipf.write(os.path.join(directory, file), folder + "/" + file) 195 | print file + " written to " + folder + "/" + file 196 | elif os.path.isdir(os.path.join(directory, file)): 197 | recursive_zip(zipf, os.path.join(directory, file), folder + "/" + file) 198 | 199 | font = os.path.join(os.path.dirname(sys.executable), 'lib', 'site-packages', 'pygame', 'freesansbold.ttf') 200 | zip = zipfile.ZipFile('dist/lib/library.zip', 'a') 201 | zip.write(font, 'pygame/freesansbold.ttf') 202 | 203 | print 'pygame/freesansbold.ttf Copied' 204 | 205 | opengl = os.path.join(os.path.dirname(sys.executable), 'lib', 'site-packages', 'OpenGL') 206 | recursive_zip(zip, opengl, "OpenGL") 207 | 208 | shutil.copytree("Renderer", "dist/Renderer") -------------------------------------------------------------------------------- /gameobjects/Sphere.py: -------------------------------------------------------------------------------- 1 | from OpenGL.GL import * 2 | from OpenGL.GLU import * 3 | 4 | from util import * 5 | 6 | import gui 7 | import scene 8 | 9 | import wx #import wxWidgets 10 | import wx.propgrid as wxpg 11 | 12 | from gameobject import GameObject 13 | 14 | class Sphere ( GameObject ): 15 | def __init__(self, name = None, x = 1, y = 1, z = 1, r = 1): 16 | self.name = name 17 | self.x = x 18 | self.y = y 19 | self.z = z 20 | 21 | self.r = r 22 | 23 | self.reflectivity = 0.0 24 | 25 | self.type = "Sphere" 26 | 27 | self.pointselection = -1 28 | 29 | GameObject.__init__(self) 30 | 31 | @staticmethod 32 | def load(element): 33 | name = element.getAttribute("name") 34 | 35 | newobject = Sphere(name, float( element.getAttribute("x")) , float(element.getAttribute("y")) , float(element.getAttribute("z")) , float(element.getAttribute("r")) ) 36 | newobject.selected = ( element.getAttribute("selected") == "True") 37 | 38 | newobject.uniform = ( element.getAttribute("uniform") == "True") 39 | 40 | newobject.reflectivity = float( element.getAttribute("reflectivity")) 41 | newobject.recieve = ( element.getAttribute("recieve") == "True") 42 | newobject.cast = ( element.getAttribute("cast") == "True") 43 | 44 | return newobject 45 | 46 | @staticmethod 47 | def create(event): 48 | Sphere() 49 | 50 | def duplicate(self, newname): 51 | newsphere = Sphere(newname, self.x, self.y, self.z, self.r) 52 | 53 | newsphere.uniform = self.uniform 54 | newsphere.recieve = self.recieve 55 | newsphere.cast = self.cast 56 | 57 | newsphere.reflectivity = self.reflectivity 58 | 59 | return newsphere 60 | def center(self): 61 | return [self.x, self.y, self.z] 62 | def move(self, x, y, z): 63 | if self.edit: 64 | if self.pointselection == 1: 65 | self.x += x 66 | self.y += y 67 | self.z += z 68 | if self.pointselection == 2: 69 | self.r += x 70 | else: 71 | self.x += x 72 | self.y += y 73 | self.z += z 74 | 75 | if self.pg != None: 76 | self.pg.GetPropertyByName("Center.X").SetValue(self.x) 77 | self.pg.GetPropertyByName("Center.Y").SetValue(self.y) 78 | self.pg.GetPropertyByName("Center.Z").SetValue(self.z) 79 | 80 | self.pg.GetPropertyByName("Radius").SetValue(self.r) 81 | 82 | def collide(self, ro, rd): 83 | return iSphere(self.x, self.y, self.z, self.r, ro, rd) 84 | def click(self, pos): 85 | SELECTIONDIST = 20 86 | 87 | self.pointselection = -1 88 | 89 | modelViewMatrix = glGetDouble( GL_MODELVIEW_MATRIX ) 90 | projectionMatrix = glGetDouble( GL_PROJECTION_MATRIX ) 91 | viewport = glGetInteger(GL_VIEWPORT) 92 | 93 | dotpos = gluProject(self.x , self.y, self.z, modelViewMatrix, projectionMatrix, viewport) 94 | if dist( [dotpos[0], dotpos[1]], [pos[0], 720 - pos[1]] ) < SELECTIONDIST: 95 | self.pointselection = 1 96 | 97 | dotpos = gluProject(self.x + self.r, self.y, self.z, modelViewMatrix, projectionMatrix, viewport) 98 | if dist( [dotpos[0], dotpos[1]], [pos[0], 720 - pos[1]] ) < SELECTIONDIST: 99 | self.pointselection = 2 100 | def draw(self): 101 | glEnable(GL_LIGHTING) 102 | 103 | glMaterialfv(GL_FRONT, GL_DIFFUSE, (1.0, 1.0, 1.0, 1.0)) 104 | 105 | 106 | 107 | glPushMatrix() 108 | glTranslatef(self.x, self.y, self.z) 109 | q = gluNewQuadric() 110 | gluSphere( q, self.r, 10, 10 ) 111 | glPopMatrix() 112 | 113 | glDisable(GL_LIGHTING) 114 | 115 | glLineWidth(2) 116 | 117 | glBegin(GL_LINES) 118 | 119 | self.min = [self.x - self.r,self.y - self.r,self.z - self.r] 120 | self.max = [self.x + self.r,self.y + self.r,self.z + self.r] 121 | 122 | if self.edit: 123 | glColor3f(1, 0.62745, 0.176470) 124 | elif self.selected: 125 | glColor3f(0,1,0) 126 | else: 127 | glColor3f(1, 1, 1) 128 | 129 | glVertex3f(self.min[0], self.min[1], self.min[2]) 130 | glVertex3f(self.max[0], self.min[1], self.min[2]) 131 | 132 | glVertex3f(self.min[0], self.min[1], self.min[2]) 133 | glVertex3f(self.min[0], self.max[1], self.min[2]) 134 | 135 | glVertex3f(self.min[0], self.min[1], self.min[2]) 136 | glVertex3f(self.min[0], self.min[1], self.max[2]) 137 | 138 | glVertex3f(self.max[0], self.max[1], self.max[2]) 139 | glVertex3f(self.min[0], self.max[1], self.max[2]) 140 | 141 | glVertex3f(self.max[0], self.max[1], self.max[2]) 142 | glVertex3f(self.max[0], self.min[1], self.max[2]) 143 | 144 | glVertex3f(self.max[0], self.max[1], self.max[2]) 145 | glVertex3f(self.max[0], self.max[1], self.min[2]) 146 | 147 | glVertex3f(self.min[0], self.max[1], self.max[2]) 148 | glVertex3f(self.min[0], self.max[1], self.min[2]) 149 | 150 | glVertex3f(self.max[0], self.max[1], self.min[2]) 151 | glVertex3f(self.min[0], self.max[1], self.min[2]) 152 | 153 | 154 | glVertex3f(self.min[0], self.max[1], self.max[2]) 155 | glVertex3f(self.min[0], self.min[1], self.max[2]) 156 | 157 | glVertex3f(self.max[0], self.max[1], self.min[2]) 158 | glVertex3f(self.max[0], self.min[1], self.min[2]) 159 | 160 | glVertex3f(self.max[0], self.min[1], self.min[2]) 161 | glVertex3f(self.max[0], self.min[1], self.max[2]) 162 | 163 | glVertex3f(self.min[0], self.min[1], self.max[2]) 164 | glVertex3f(self.max[0], self.min[1], self.max[2]) 165 | 166 | glEnd() 167 | 168 | glLineWidth(1) 169 | 170 | if self.edit: 171 | glDisable(GL_DEPTH_TEST) 172 | 173 | glPointSize (10) 174 | glBegin(GL_POINTS) 175 | 176 | if self.pointselection == 1: 177 | glColor3f(0, 1, 0) 178 | else: 179 | glColor3f(1, 1, 1) 180 | glVertex3f(self.x, self.y, self.z) 181 | 182 | if self.pointselection == 2: 183 | glColor3f(0, 1, 0) 184 | else: 185 | glColor3f(1, 1, 1) 186 | 187 | glVertex3f(self.x + self.r, self.y, self.z) 188 | 189 | glEnd() 190 | glPointSize (1) 191 | 192 | if self.pointselection == 1: 193 | movetool(self.x, self.y, self.z, 5) 194 | if self.pointselection == 2: 195 | movetool(self.x + self.r, self.y, self.z, 5) 196 | 197 | glEnable(GL_DEPTH_TEST) 198 | 199 | glEnable(GL_LIGHTING) 200 | def PropertyChange(self, event): 201 | p = event.GetProperty() 202 | if p: 203 | print p.GetName() + " changed." 204 | 205 | #General Properties 206 | if p.GetName() == "Object Name": 207 | del scene.objects[self.name] 208 | self.name = p.GetValue() 209 | scene.objects[self.name] = self 210 | gui.tree_ctrl.SetItemText(self.treeitem, self.name) 211 | if p.GetName() == "Uniform": 212 | self.uniform = p.GetValue() 213 | 214 | if p.GetName() == "Center.X": 215 | self.x = p.GetValue() 216 | if p.GetName() == "Center.Y": 217 | self.y = p.GetValue() 218 | if p.GetName() == "Center.Z": 219 | self.z = p.GetValue() 220 | 221 | if p.GetName() == "Radius": 222 | self.r = p.GetValue() 223 | 224 | #Material Properties 225 | if p.GetName() == "Reflectivity": 226 | self.reflectivity = p.GetValue() 227 | if p.GetName() == "Cast Shadows": 228 | self.cast = p.GetValue() 229 | if p.GetName() == "Recieve Shadows": 230 | self.recieve = p.GetValue() 231 | def populatepropgrid(self, pg): 232 | #Geometry Properties 233 | pg.Append( wxpg.PropertyCategory("Geometry") ) 234 | 235 | normalID = pg.Append( wxpg.StringProperty("Center", value="") ) 236 | pg.AppendIn (normalID, wxpg.FloatProperty("X", value=self.x) ) 237 | pg.AppendIn (normalID, wxpg.FloatProperty("Y", value=self.y) ) 238 | pg.AppendIn (normalID, wxpg.FloatProperty("Z", value=self.z) ) 239 | 240 | pg.Append( wxpg.FloatProperty("Radius", value=self.r) ) 241 | 242 | #Material Properties 243 | pg.Append( wxpg.PropertyCategory("Material") ) 244 | pg.Append( wxpg.FloatProperty("Reflectivity", value=self.reflectivity) ) 245 | 246 | pg.Append( wxpg.BoolProperty("Cast Shadows",value=self.cast) ) 247 | pg.SetPropertyAttribute("Cast Shadows", "UseCheckbox", True) 248 | 249 | pg.Append( wxpg.BoolProperty("Recieve Shadows",value=self.recieve) ) 250 | pg.SetPropertyAttribute("Recieve Shadows", "UseCheckbox", True) 251 | 252 | def write(self, object): 253 | object.setAttribute("x", str(self.x) ) 254 | object.setAttribute("y", str(self.y) ) 255 | object.setAttribute("z", str(self.z) ) 256 | object.setAttribute("r", str(self.r) ) 257 | 258 | object.setAttribute("reflectivity", str(self.reflectivity) ) 259 | object.setAttribute("recieve", str(self.recieve) ) 260 | object.setAttribute("cast", str(self.cast) ) -------------------------------------------------------------------------------- /gameobjects/SphereAberration.py: -------------------------------------------------------------------------------- 1 | from OpenGL.GL import * 2 | from OpenGL.GLU import * 3 | 4 | from util import * 5 | 6 | import gui 7 | import scene 8 | 9 | import wx #import wxWidgets 10 | import wx.propgrid as wxpg 11 | 12 | from gameobject import GameObject 13 | 14 | class SphereAberration ( GameObject ): 15 | def __init__(self, name = None, x = 1, y = 1, z = 1, r = 1): 16 | self.name = name 17 | self.x = x 18 | self.y = y 19 | self.z = z 20 | 21 | self.r = r 22 | 23 | self.reflectivity = 0.0 24 | 25 | self.type = "SphereAberration" 26 | 27 | self.scale = [1.0, 1.0, 1.0] 28 | 29 | self.pointselection = -1 30 | 31 | GameObject.__init__(self) 32 | 33 | @staticmethod 34 | def create(event): 35 | SphereAberration() 36 | 37 | @staticmethod 38 | def load(element): 39 | name = element.getAttribute("name") 40 | 41 | newobject = SphereAberration(name, float(element.getAttribute("x")) , float(element.getAttribute("y")) , float(element.getAttribute("z")) , float(element.getAttribute("r")) ) 42 | newobject.selected = (element.getAttribute("selected") == "True") 43 | 44 | newobject.uniform = (element.getAttribute("uniform") == "True") 45 | 46 | newobject.reflectivity = float(element.getAttribute("reflectivity")) 47 | newobject.recieve = (element.getAttribute("recieve") == "True") 48 | newobject.cast = (element.getAttribute("cast") == "True") 49 | 50 | newobject.scale = toFloats( element.getAttribute("scale").split(",") ) 51 | 52 | return newobject 53 | 54 | def duplicate(self, newname): 55 | newsphere = SphereAberration(newname, self.x, self.y, self.z, self.r) 56 | 57 | newsphere.uniform = self.uniform 58 | newsphere.recieve = self.recieve 59 | newsphere.cast = self.cast 60 | 61 | newsphere.reflectivity = self.reflectivity 62 | 63 | newsphere.scale = list( self.scale ) 64 | 65 | return newsphere 66 | def center(self): 67 | return [self.x, self.y, self.z] 68 | def move(self, x, y, z): 69 | if self.edit: 70 | if self.pointselection == 1: 71 | self.x += x 72 | self.y += y 73 | self.z += z 74 | if self.pointselection == 2: 75 | self.r += x 76 | else: 77 | self.x += x 78 | self.y += y 79 | self.z += z 80 | 81 | if self.pg != None: 82 | self.pg.GetPropertyByName("Center.X").SetValue(self.x) 83 | self.pg.GetPropertyByName("Center.Y").SetValue(self.y) 84 | self.pg.GetPropertyByName("Center.Z").SetValue(self.z) 85 | 86 | self.pg.GetPropertyByName("Radius").SetValue(self.r) 87 | 88 | def collide(self, ro, rd): 89 | return iSphere(self.x, self.y, self.z, self.r, ro, rd) 90 | def click(self, pos): 91 | SELECTIONDIST = 20 92 | 93 | self.pointselection = -1 94 | 95 | modelViewMatrix = glGetDouble( GL_MODELVIEW_MATRIX ) 96 | projectionMatrix = glGetDouble( GL_PROJECTION_MATRIX ) 97 | viewport = glGetInteger(GL_VIEWPORT) 98 | 99 | dotpos = gluProject(self.x , self.y, self.z, modelViewMatrix, projectionMatrix, viewport) 100 | if dist( [dotpos[0], dotpos[1]], [pos[0], 720 - pos[1]] ) < SELECTIONDIST: 101 | self.pointselection = 1 102 | 103 | dotpos = gluProject(self.x + self.r, self.y, self.z, modelViewMatrix, projectionMatrix, viewport) 104 | if dist( [dotpos[0], dotpos[1]], [pos[0], 720 - pos[1]] ) < SELECTIONDIST: 105 | self.pointselection = 2 106 | def draw(self): 107 | glEnable(GL_LIGHTING) 108 | 109 | glMaterialfv(GL_FRONT, GL_DIFFUSE, (1.0, 1.0, 1.0, 0.5)) 110 | 111 | 112 | 113 | glPushMatrix() 114 | glTranslatef(self.x, self.y, self.z) 115 | q = gluNewQuadric() 116 | gluSphere( q, self.r, 10, 10 ) 117 | glPopMatrix() 118 | 119 | glDisable(GL_LIGHTING) 120 | 121 | glLineWidth(2) 122 | 123 | glBegin(GL_LINES) 124 | 125 | self.min = [self.x - self.r,self.y - self.r,self.z - self.r] 126 | self.max = [self.x + self.r,self.y + self.r,self.z + self.r] 127 | 128 | if self.edit: 129 | glColor3f(1, 0.62745, 0.176470) 130 | elif self.selected: 131 | glColor3f(0,1,0) 132 | else: 133 | glColor3f(1, 1, 1) 134 | 135 | glVertex3f(self.min[0], self.min[1], self.min[2]) 136 | glVertex3f(self.max[0], self.min[1], self.min[2]) 137 | 138 | glVertex3f(self.min[0], self.min[1], self.min[2]) 139 | glVertex3f(self.min[0], self.max[1], self.min[2]) 140 | 141 | glVertex3f(self.min[0], self.min[1], self.min[2]) 142 | glVertex3f(self.min[0], self.min[1], self.max[2]) 143 | 144 | glVertex3f(self.max[0], self.max[1], self.max[2]) 145 | glVertex3f(self.min[0], self.max[1], self.max[2]) 146 | 147 | glVertex3f(self.max[0], self.max[1], self.max[2]) 148 | glVertex3f(self.max[0], self.min[1], self.max[2]) 149 | 150 | glVertex3f(self.max[0], self.max[1], self.max[2]) 151 | glVertex3f(self.max[0], self.max[1], self.min[2]) 152 | 153 | glVertex3f(self.min[0], self.max[1], self.max[2]) 154 | glVertex3f(self.min[0], self.max[1], self.min[2]) 155 | 156 | glVertex3f(self.max[0], self.max[1], self.min[2]) 157 | glVertex3f(self.min[0], self.max[1], self.min[2]) 158 | 159 | 160 | glVertex3f(self.min[0], self.max[1], self.max[2]) 161 | glVertex3f(self.min[0], self.min[1], self.max[2]) 162 | 163 | glVertex3f(self.max[0], self.max[1], self.min[2]) 164 | glVertex3f(self.max[0], self.min[1], self.min[2]) 165 | 166 | glVertex3f(self.max[0], self.min[1], self.min[2]) 167 | glVertex3f(self.max[0], self.min[1], self.max[2]) 168 | 169 | glVertex3f(self.min[0], self.min[1], self.max[2]) 170 | glVertex3f(self.max[0], self.min[1], self.max[2]) 171 | 172 | glEnd() 173 | 174 | glLineWidth(1) 175 | 176 | if self.edit: 177 | glDisable(GL_DEPTH_TEST) 178 | 179 | glPointSize (10) 180 | glBegin(GL_POINTS) 181 | 182 | if self.pointselection == 1: 183 | glColor3f(0, 1, 0) 184 | else: 185 | glColor3f(1, 1, 1) 186 | glVertex3f(self.x, self.y, self.z) 187 | 188 | if self.pointselection == 2: 189 | glColor3f(0, 1, 0) 190 | else: 191 | glColor3f(1, 1, 1) 192 | 193 | glVertex3f(self.x + self.r, self.y, self.z) 194 | 195 | glEnd() 196 | glPointSize (1) 197 | 198 | if self.pointselection == 1: 199 | movetool(self.x, self.y, self.z, 5) 200 | if self.pointselection == 2: 201 | movetool(self.x + self.r, self.y, self.z, 5) 202 | 203 | glEnable(GL_DEPTH_TEST) 204 | 205 | glEnable(GL_LIGHTING) 206 | def PropertyChange(self, event): 207 | p = event.GetProperty() 208 | if p: 209 | print p.GetName() + " changed." 210 | 211 | #General Properties 212 | if p.GetName() == "Object Name": 213 | del scene.objects[self.name] 214 | self.name = p.GetValue() 215 | scene.objects[self.name] = self 216 | gui.tree_ctrl.SetItemText(self.treeitem, self.name) 217 | if p.GetName() == "Uniform": 218 | self.uniform = p.GetValue() 219 | 220 | #Aberration Properties 221 | if p.GetName() == "Scale.X": 222 | self.scale[0] = p.GetValue() 223 | if p.GetName() == "Scale.Y": 224 | self.scale[1] = p.GetValue() 225 | if p.GetName() == "Scale.Z": 226 | self.scale[2] = p.GetValue() 227 | 228 | #Geometry Properties 229 | if p.GetName() == "Center.X": 230 | self.x = p.GetValue() 231 | if p.GetName() == "Center.Y": 232 | self.y = p.GetValue() 233 | if p.GetName() == "Center.Z": 234 | self.z = p.GetValue() 235 | 236 | if p.GetName() == "Radius": 237 | self.r = p.GetValue() 238 | 239 | #Material Properties 240 | if p.GetName() == "Reflectivity": 241 | self.reflectivity = p.GetValue() 242 | if p.GetName() == "Cast Shadows": 243 | self.cast = p.GetValue() 244 | if p.GetName() == "Recieve Shadows": 245 | self.recieve = p.GetValue() 246 | def populatepropgrid(self, pg): 247 | #Geometry Properties 248 | pg.Append( wxpg.PropertyCategory("Geometry") ) 249 | 250 | normalID = pg.Append( wxpg.StringProperty("Center", value="") ) 251 | pg.AppendIn (normalID, wxpg.FloatProperty("X", value=self.x) ) 252 | pg.AppendIn (normalID, wxpg.FloatProperty("Y", value=self.y) ) 253 | pg.AppendIn (normalID, wxpg.FloatProperty("Z", value=self.z) ) 254 | 255 | pg.Append( wxpg.FloatProperty("Radius", value=self.r) ) 256 | 257 | #Aberration Properties 258 | pg.Append( wxpg.PropertyCategory("Aberration") ) 259 | abID = pg.Append( wxpg.StringProperty("Scale", value="") ) 260 | pg.AppendIn (abID, wxpg.FloatProperty("X", value=self.scale[0]) ) 261 | pg.AppendIn (abID, wxpg.FloatProperty("Y", value=self.scale[1]) ) 262 | pg.AppendIn (abID, wxpg.FloatProperty("Z", value=self.scale[2]) ) 263 | 264 | #Material Properties 265 | pg.Append( wxpg.PropertyCategory("Material") ) 266 | pg.Append( wxpg.FloatProperty("Reflectivity", value=self.reflectivity) ) 267 | 268 | pg.Append( wxpg.BoolProperty("Cast Shadows",value=self.cast) ) 269 | pg.SetPropertyAttribute("Cast Shadows", "UseCheckbox", True) 270 | 271 | pg.Append( wxpg.BoolProperty("Recieve Shadows",value=self.recieve) ) 272 | pg.SetPropertyAttribute("Recieve Shadows", "UseCheckbox", True) 273 | def write(self, object): 274 | object.setAttribute("x", str(self.x) ) 275 | object.setAttribute("y", str(self.y) ) 276 | object.setAttribute("z", str(self.z) ) 277 | object.setAttribute("r", str(self.r) ) 278 | 279 | object.setAttribute("reflectivity", str(self.reflectivity) ) 280 | object.setAttribute("recieve", str(self.recieve) ) 281 | object.setAttribute("cast", str(self.cast) ) 282 | 283 | object.setAttribute("scale", formatString(self.scale) ) -------------------------------------------------------------------------------- /gameobjects/Box.py: -------------------------------------------------------------------------------- 1 | from OpenGL.GL import * 2 | from OpenGL.GLU import * 3 | 4 | from util import * 5 | 6 | import gui 7 | import scene 8 | 9 | import wx #import wxWidgets 10 | import wx.propgrid as wxpg 11 | 12 | from gameobject import GameObject 13 | 14 | class Box ( GameObject ): 15 | def __init__(self, name = None, min = [0,0,0], max = [5,5,5]): 16 | self.name = name 17 | 18 | self.min = min 19 | self.max = max 20 | 21 | self.type = "Box" 22 | 23 | self.pointselection = -1 24 | 25 | GameObject.__init__(self) 26 | 27 | @staticmethod 28 | def create(event): 29 | Box() 30 | 31 | @staticmethod 32 | def load(element): 33 | name = element.getAttribute("name") 34 | min = element.getAttribute("min").split(",") 35 | max = element.getAttribute("max").split(",") 36 | 37 | newobject = Box(name, toFloats(min), toFloats(max) ) 38 | newobject.selected = (element.getAttribute("selected") == "True") 39 | 40 | newobject.uniform = (element.getAttribute("uniform") == "True") 41 | 42 | newobject.cast = (element.getAttribute("cast") == "True") 43 | newobject.recieve = (element.getAttribute("recieve") == "True") 44 | 45 | return newobject 46 | 47 | def duplicate(self, newname): 48 | newbox = Box(newname, [self.min[0], self.min[1], self.min[2]], [self.max[0], self.max[1], self.max[2]]) 49 | 50 | newbox.uniform = self.uniform 51 | newbox.recieve = self.recieve 52 | newbox.cast = self.cast 53 | 54 | return newbox 55 | def center(self): 56 | return mult( 0.5, add(self.min, self.max) ) 57 | def move(self, x, y, z): 58 | if self.edit: 59 | if self.pointselection == 1: 60 | self.min[0] += x 61 | self.min[1] += y 62 | self.min[2] += z 63 | if self.pointselection == 2: 64 | self.max[0] += x 65 | self.max[1] += y 66 | self.max[2] += z 67 | else: 68 | self.min[0] += x 69 | self.max[0] += x 70 | 71 | self.min[1] += y 72 | self.max[1] += y 73 | 74 | self.min[2] += z 75 | self.max[2] += z 76 | 77 | if self.pg != None: 78 | self.pg.GetPropertyByName("Minimum.X").SetValue(self.min[0]) 79 | self.pg.GetPropertyByName("Minimum.Y").SetValue(self.min[1]) 80 | self.pg.GetPropertyByName("Minimum.Z").SetValue(self.min[2]) 81 | 82 | self.pg.GetPropertyByName("Maximum.X").SetValue(self.max[0]) 83 | self.pg.GetPropertyByName("Maximum.Y").SetValue(self.max[1]) 84 | self.pg.GetPropertyByName("Maximum.Z").SetValue(self.max[2]) 85 | def collide(self, ro, rd): 86 | return iBox(self.min, self.max, ro, rd) 87 | def click(self, pos): 88 | SELECTIONDIST = 30 89 | 90 | self.pointselection = -1 91 | 92 | modelViewMatrix = glGetDouble( GL_MODELVIEW_MATRIX ) 93 | projectionMatrix = glGetDouble( GL_PROJECTION_MATRIX ) 94 | viewport = glGetInteger(GL_VIEWPORT) 95 | 96 | dotpos = gluProject(self.min[0], self.min[1], self.min[2], modelViewMatrix, projectionMatrix, viewport) 97 | if dist( [dotpos[0], dotpos[1]], [pos[0], 720 - pos[1]] ) < SELECTIONDIST: 98 | self.pointselection = 1 99 | 100 | dotpos = gluProject(self.max[0], self.max[1], self.max[2], modelViewMatrix, projectionMatrix, viewport) 101 | if dist( [dotpos[0], dotpos[1]], [pos[0], 720 - pos[1]] ) < SELECTIONDIST: 102 | self.pointselection = 2 103 | def draw(self): 104 | glEnable(GL_LIGHTING) 105 | 106 | glMaterialfv(GL_FRONT, GL_DIFFUSE, (1.0, 1.0, 1.0, 1.0)) 107 | 108 | glBegin(GL_QUADS) 109 | 110 | #Front Face 111 | glNormal3f( 0.0, 0.0, 1.0) 112 | glVertex3f( self.min[0], self.min[1], self.max[2] ) 113 | glVertex3f( self.max[0], self.min[1], self.max[2] ) 114 | glVertex3f( self.max[0], self.max[1], self.max[2] ) 115 | glVertex3f( self.min[0], self.max[1], self.max[2] ) 116 | 117 | #Back Face 118 | glNormal3f( 0.0, 0.0,-1.0) 119 | glVertex3f( self.min[0], self.min[1], self.min[2] ) 120 | glVertex3f( self.min[0], self.max[1], self.min[2] ) 121 | glVertex3f( self.max[0], self.max[1], self.min[2] ) 122 | glVertex3f( self.max[0], self.min[1], self.min[2] ) 123 | 124 | #Top Face 125 | glNormal3f( 0.0, 1.0, 0.0) 126 | glVertex3f( self.min[0], self.max[1], self.min[2] ) 127 | glVertex3f( self.min[0], self.max[1], self.max[2] ) 128 | glVertex3f( self.max[0], self.max[1], self.max[2] ) 129 | glVertex3f( self.max[0], self.max[1], self.min[2] ) 130 | 131 | #Bottom Face 132 | glNormal3f( 0.0,-1.0, 0.0) 133 | glVertex3f( self.min[0], self.min[1], self.min[2] ) 134 | glVertex3f( self.max[0], self.min[1], self.min[2] ) 135 | glVertex3f( self.max[0], self.min[1], self.max[2] ) 136 | glVertex3f( self.min[0], self.min[1], self.max[2] ) 137 | 138 | #Right Face 139 | glNormal3f( 1.0, 0.0, 0.0) 140 | glVertex3f( self.max[0], self.min[1], self.min[2] ) 141 | glVertex3f( self.max[0], self.max[1], self.min[2] ) 142 | glVertex3f( self.max[0], self.max[1], self.max[2] ) 143 | glVertex3f( self.max[0], self.min[1], self.max[2] ) 144 | 145 | #Left Face 146 | glNormal3f(-1.0, 0.0, 0.0) 147 | glVertex3f( self.min[0], self.min[1], self.min[2] ) 148 | glVertex3f( self.min[0], self.min[1], self.max[2] ) 149 | glVertex3f( self.min[0], self.max[1], self.max[2] ) 150 | glVertex3f( self.min[0], self.max[1], self.min[2] ) 151 | 152 | glEnd() 153 | 154 | glDisable(GL_LIGHTING) 155 | 156 | glLineWidth(2) 157 | 158 | if self.edit: 159 | glDisable(GL_DEPTH_TEST) 160 | 161 | glBegin(GL_LINES) 162 | 163 | if self.edit: 164 | glColor3f(1, 0.62745, 0.176470) 165 | elif self.selected: 166 | glColor3f(0,1,0) 167 | else: 168 | glColor3f(1, 1, 1) 169 | 170 | glVertex3f(self.min[0], self.min[1], self.min[2]) 171 | glVertex3f(self.max[0], self.min[1], self.min[2]) 172 | 173 | glVertex3f(self.min[0], self.min[1], self.min[2]) 174 | glVertex3f(self.min[0], self.max[1], self.min[2]) 175 | 176 | glVertex3f(self.min[0], self.min[1], self.min[2]) 177 | glVertex3f(self.min[0], self.min[1], self.max[2]) 178 | 179 | glVertex3f(self.max[0], self.max[1], self.max[2]) 180 | glVertex3f(self.min[0], self.max[1], self.max[2]) 181 | 182 | glVertex3f(self.max[0], self.max[1], self.max[2]) 183 | glVertex3f(self.max[0], self.min[1], self.max[2]) 184 | 185 | glVertex3f(self.max[0], self.max[1], self.max[2]) 186 | glVertex3f(self.max[0], self.max[1], self.min[2]) 187 | 188 | glVertex3f(self.min[0], self.max[1], self.max[2]) 189 | glVertex3f(self.min[0], self.max[1], self.min[2]) 190 | 191 | glVertex3f(self.max[0], self.max[1], self.min[2]) 192 | glVertex3f(self.min[0], self.max[1], self.min[2]) 193 | 194 | 195 | glVertex3f(self.min[0], self.max[1], self.max[2]) 196 | glVertex3f(self.min[0], self.min[1], self.max[2]) 197 | 198 | glVertex3f(self.max[0], self.max[1], self.min[2]) 199 | glVertex3f(self.max[0], self.min[1], self.min[2]) 200 | 201 | glVertex3f(self.max[0], self.min[1], self.min[2]) 202 | glVertex3f(self.max[0], self.min[1], self.max[2]) 203 | 204 | glVertex3f(self.min[0], self.min[1], self.max[2]) 205 | glVertex3f(self.max[0], self.min[1], self.max[2]) 206 | 207 | glEnd() 208 | 209 | glLineWidth(1) 210 | 211 | if self.edit: 212 | glPointSize (10) 213 | glBegin(GL_POINTS) 214 | 215 | if self.pointselection == 1: 216 | glColor3f(0, 1, 0) 217 | else: 218 | glColor3f(1, 1, 1) 219 | glVertex3f(self.min[0], self.min[1], self.min[2]) 220 | 221 | if self.pointselection == 2: 222 | glColor3f(0, 1, 0) 223 | else: 224 | glColor3f(1, 1, 1) 225 | 226 | glVertex3f(self.max[0], self.max[1], self.max[2]) 227 | 228 | glEnd() 229 | glPointSize (1) 230 | 231 | if self.pointselection == 1: 232 | movetool(self.min[0], self.min[1], self.min[2], 5) 233 | if self.pointselection == 2: 234 | movetool(self.max[0], self.max[1], self.max[2], 5) 235 | 236 | glEnable(GL_LIGHTING) 237 | 238 | glEnable(GL_DEPTH_TEST) 239 | def PropertyChange(self, event): 240 | p = event.GetProperty() 241 | if p: 242 | print p.GetName() + " changed." 243 | 244 | #General Properties 245 | if p.GetName() == "Object Name": 246 | del scene.objects[self.name] 247 | self.name = p.GetValue() 248 | scene.objects[self.name] = self 249 | gui.tree_ctrl.SetItemText(self.treeitem, self.name) 250 | if p.GetName() == "Uniform": 251 | self.uniform = p.GetValue() 252 | 253 | if p.GetName() == "Minimum.X": 254 | self.min[0] = p.GetValue() 255 | if p.GetName() == "Minimum.Y": 256 | self.min[1] = p.GetValue() 257 | if p.GetName() == "Minimum.Z": 258 | self.min[2] = p.GetValue() 259 | 260 | if p.GetName() == "Maximum.X": 261 | self.max[0] = p.GetValue() 262 | if p.GetName() == "Maximum.Y": 263 | self.max[1] = p.GetValue() 264 | if p.GetName() == "Maximum.Z": 265 | self.max[2] = p.GetValue() 266 | 267 | if p.GetName() == "Cast Shadows": 268 | self.cast = p.GetValue() 269 | if p.GetName() == "Recieve Shadows": 270 | self.recieve = p.GetValue() 271 | def populatepropgrid(self, pg): 272 | #Geometry Properties 273 | pg.Append( wxpg.PropertyCategory("Geometry") ) 274 | 275 | minID = pg.Append( wxpg.StringProperty("Minimum", value="") ) 276 | pg.AppendIn (minID, wxpg.FloatProperty("X", value=self.min[0]) ) 277 | pg.AppendIn (minID, wxpg.FloatProperty("Y", value=self.min[1]) ) 278 | pg.AppendIn (minID, wxpg.FloatProperty("Z", value=self.min[2]) ) 279 | 280 | maxID = pg.Append( wxpg.StringProperty("Maximum", value="") ) 281 | pg.AppendIn (maxID, wxpg.FloatProperty("X", value=self.max[0]) ) 282 | pg.AppendIn (maxID, wxpg.FloatProperty("Y", value=self.max[1]) ) 283 | pg.AppendIn (maxID, wxpg.FloatProperty("Z", value=self.max[2]) ) 284 | 285 | #Material Properties 286 | pg.Append( wxpg.PropertyCategory("Material") ) 287 | 288 | pg.Append( wxpg.BoolProperty("Cast Shadows",value=self.cast) ) 289 | pg.SetPropertyAttribute("Cast Shadows", "UseCheckbox", True) 290 | 291 | def write(self, object): 292 | object.setAttribute("min", formatString(self.min) ) 293 | object.setAttribute("max", formatString(self.max) ) 294 | 295 | object.setAttribute("recieve", str(self.recieve) ) 296 | object.setAttribute("cast", str(self.cast) ) -------------------------------------------------------------------------------- /editor.py: -------------------------------------------------------------------------------- 1 | #These lines below have to do with the exporting to an exe process 2 | from ctypes import util 3 | try: 4 | from OpenGL.platform import win32 5 | except AttributeError: 6 | pass 7 | #import pygame._view 8 | 9 | from math import * 10 | 11 | from OpenGL.GL import * 12 | from OpenGL.GLU import * 13 | 14 | import pygame 15 | from pygame.locals import * 16 | 17 | from camera import * 18 | 19 | import gameobjects 20 | 21 | import gui 22 | 23 | import threading 24 | 25 | from util import * 26 | 27 | import scene 28 | 29 | import os 30 | 31 | 32 | 33 | DEFAULTSCREENSIZE = (1280,720) 34 | 35 | #Properties of the Light 36 | LightAmbient = ( 0.0, 0.0, 0.0, 1.0 ) 37 | LightDiffuse = ( 0.8, 0.8, 0.8, 1.0 ) 38 | LightSpecular = ( 0.2, 0.2, 0.2, 1.0) 39 | LightPosition = ( 1.0, 1.0, 1.0, 0.0 ) 40 | 41 | #Called automatically when the screen has been resized 42 | def resize(size): 43 | width = size[0] 44 | height = size[1] 45 | 46 | glViewport(0, 0, width, height) 47 | glMatrixMode(GL_PROJECTION) 48 | glLoadIdentity() 49 | gluPerspective(60.0, float(width)/height, .1, 1000.) 50 | glMatrixMode(GL_MODELVIEW) 51 | glLoadIdentity() 52 | 53 | #Draws an axis (used in the center) 54 | def axes(): 55 | glDisable(GL_LIGHTING) 56 | glBegin(GL_LINES) 57 | 58 | #Y axis 59 | glColor3f(0,255,0) 60 | glVertex3f(0,0,0) 61 | glColor3f(0,255,0) 62 | glVertex3f(0,10,0) 63 | 64 | #Z axis 65 | glColor3f(0,0,255) 66 | glVertex3f(0,0,0) 67 | glColor3f(0,0,255) 68 | glVertex3f(0,0,10) 69 | 70 | #X axis 71 | glColor3f(255,0,0) 72 | glVertex3f(0,0,0) 73 | glColor3f(255,0,0) 74 | glVertex3f(10,0,0) 75 | 76 | glEnd() 77 | 78 | drawText3d((0,10, 0), "y", 32) 79 | drawText3d((10,0, 0), "x", 32) 80 | drawText3d((0,0, 10), "z", 32) 81 | 82 | glEnable(GL_LIGHTING) 83 | 84 | 85 | 86 | def main(): 87 | 88 | pygame.init() #Startup pygame 89 | 90 | font = pygame.font.Font (None, 10) #Create the font object that will be used to draw things 91 | 92 | screen = pygame.display.set_mode(DEFAULTSCREENSIZE, HWSURFACE|OPENGL|DOUBLEBUF) 93 | 94 | resize(DEFAULTSCREENSIZE) 95 | 96 | glEnable(GL_DEPTH_TEST) 97 | 98 | glShadeModel(GL_SMOOTH) #Smooth shading 99 | 100 | #Create one main light 101 | glLightfv(GL_LIGHT1, GL_DIFFUSE, LightDiffuse) 102 | glLightfv(GL_LIGHT1, GL_POSITION,LightPosition) 103 | glEnable(GL_LIGHT1) 104 | 105 | glEnable(GL_LIGHTING) #Enable lighting 106 | 107 | glClearColor(0, 0, 0, 0.0) 108 | glEnable (GL_BLEND); 109 | glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 110 | 111 | glEnable(GL_CULL_FACE); 112 | 113 | clock = pygame.time.Clock() #Clock object for calculating a dt 114 | 115 | running = True #When this is set to false, the main loop will no longer repeat 116 | 117 | mousedown = [0, 0] #What position was the mouse at when the left click is first pressed 118 | mousecolor = None #What color was under the mouse when the left click is first pressed 119 | 120 | 121 | center = [0,0,0] #Value for storing the center of the current selection of objects (Averages the individual center of the objects in the selection) 122 | #This is important because it is where the move tool is drawn 123 | 124 | #Quick set of utilities for handling the edit mode 125 | def isEdit(): #Are we in edit mode? Basically checks to see if any object has its edit value set to True 126 | for obj in scene.objects.values(): 127 | if obj.edit: 128 | return True 129 | return False 130 | def getEdit(): #What object is currently being edited 131 | for obj in scene.objects.values(): 132 | if obj.edit: 133 | return obj 134 | return None 135 | def endEdit(): #End edit mode - basically set every single objects edit value to false 136 | for obj in scene.objects.values(): 137 | obj.edit = False 138 | 139 | #Main loop 140 | while running: 141 | gui.update() #Update gui system - handle event polling 142 | 143 | #Process all pygame events 144 | for event in pygame.event.get(): 145 | keys = pygame.key.get_pressed() 146 | 147 | #Quitting 148 | if event.type == QUIT: 149 | running = False 150 | 151 | if event.type == KEYUP: 152 | if event.key == K_ESCAPE: 153 | running = False 154 | 155 | #Handle deleting of objects from scene 156 | if event.key == K_DELETE and not isEdit(): #Can't delete objects in edit mode 157 | for obj in scene.objects.values(): 158 | if obj.selected: 159 | gui.tree_ctrl.Delete(obj.treeitem) 160 | del scene.objects[obj.name] 161 | 162 | #Hitting space duplicates the current selection 163 | if event.key == K_SPACE and not isEdit(): #Can't duplicate objects in edit mode 164 | for obj in scene.objects.values(): 165 | if obj.selected: 166 | newobj = obj.duplicate( None ) 167 | 168 | #The e key enables edit mode 169 | if event.key == K_e: 170 | if isEdit(): 171 | endEdit() 172 | else: 173 | for obj in scene.objects.values(): 174 | if obj.selected: 175 | obj.edit = True 176 | break 177 | print getEdit() 178 | 179 | if event.type == MOUSEBUTTONDOWN: 180 | if event.button == 4: 181 | cam.speed *= 1.1 182 | if event.button == 5: 183 | cam.speed *= 0.9 184 | if event.button == 1: 185 | mousedown = event.pos 186 | 187 | data = glReadPixels( 0,0, DEFAULTSCREENSIZE[0], DEFAULTSCREENSIZE[1], GL_RGB, GL_UNSIGNED_BYTE) 188 | surface = pygame.image.fromstring(str(buffer(data)), DEFAULTSCREENSIZE, 'RGB', True) 189 | mousecolor = surface.get_at( (event.pos[0], event.pos[1]) ) 190 | if event.type == MOUSEMOTION: 191 | relx = -event.rel[0]*0.002*dist( center, [cam.x, cam.y, cam.z] ) 192 | rely = event.rel[1]*0.002*dist( center, [cam.x, cam.y, cam.z] ) 193 | 194 | modelViewMatrix = glGetDouble( GL_MODELVIEW_MATRIX ) 195 | projectionMatrix = glGetDouble( GL_PROJECTION_MATRIX ) 196 | viewport = glGetInteger(GL_VIEWPORT) 197 | 198 | if event.buttons[0]: 199 | if dist(mousedown, event.pos) > 5: 200 | if mousecolor == (0,255,0,255): 201 | v = subtract( gluProject(center[0], center[1], center[2], modelViewMatrix, projectionMatrix, viewport), gluProject(center[0], center[1] + 10, center[2], modelViewMatrix, projectionMatrix, viewport) ) 202 | v = norm(v) 203 | 204 | move = dot( [ v[0], v[1] ], [relx, rely] ) 205 | for obj in scene.objects.values(): 206 | if obj.selected == True: 207 | obj.move( 0, move, 0 ) 208 | 209 | if mousecolor == (255,0,0,255): 210 | v = subtract( gluProject(center[0], center[1], center[2], modelViewMatrix, projectionMatrix, viewport), gluProject(center[0] + 10, center[1], center[2], modelViewMatrix, projectionMatrix, viewport) ) 211 | v = norm(v) 212 | 213 | move = dot( [ v[0], v[1] ], [relx, rely] ) 214 | for obj in scene.objects.values(): 215 | if obj.selected == True: 216 | obj.move( move, 0, 0 ) 217 | if mousecolor == (0,0,255,255): 218 | v = subtract( gluProject(center[0], center[1], center[2], modelViewMatrix, projectionMatrix, viewport), gluProject(center[0], center[1], center[2] + 10, modelViewMatrix, projectionMatrix, viewport) ) 219 | v = norm(v) 220 | 221 | move = dot( [ v[0], v[1] ], [relx, rely] ) 222 | for obj in scene.objects.values(): 223 | if obj.selected == True: 224 | obj.move(0, 0, move) 225 | if event.type == MOUSEBUTTONUP: 226 | if event.button == 1: 227 | if dist(mousedown, event.pos) < 5: 228 | if not isEdit(): #You cant select other objects in edit mode 229 | if keys[K_LSHIFT]: 230 | pass 231 | else: 232 | for obj in scene.objects.values(): 233 | obj.selected = False 234 | gui.tree_ctrl.UnselectAll() 235 | 236 | modelViewMatrix = glGetDouble( GL_MODELVIEW_MATRIX ) 237 | projectionMatrix = glGetDouble( GL_PROJECTION_MATRIX ) 238 | viewport = glGetInteger(GL_VIEWPORT) 239 | 240 | ro = gluUnProject( event.pos[0] , DEFAULTSCREENSIZE[1] - event.pos[1], 0.0, modelViewMatrix, projectionMatrix, viewport ) 241 | re = gluUnProject( event.pos[0] , DEFAULTSCREENSIZE[1] - event.pos[1], 1.0, modelViewMatrix, projectionMatrix, viewport ) 242 | rd = norm( [re[0] - ro[0], re[1] - ro[1], re[2] - ro[2] ] ) 243 | 244 | cam.ro = ro 245 | cam.rd = rd 246 | 247 | selected = None 248 | 249 | tm = 10000.0 250 | t = tm 251 | for obj in scene.objects.values(): 252 | result, t = obj.collide(ro, rd) 253 | if result and t < tm: 254 | tm = t 255 | selected = obj 256 | 257 | if selected != None: 258 | selected.selected = not selected.selected 259 | gui.tree_ctrl.ToggleItemSelection(selected.treeitem) 260 | 261 | selection = "" 262 | for obj in scene.objects.values(): 263 | if obj.selected == True: 264 | selection += obj.name 265 | selection += " " 266 | else: 267 | getEdit().click(event.pos) 268 | 269 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) 270 | 271 | time_passed = clock.tick() 272 | dt = time_passed / 1000.0 273 | 274 | cam.update(dt) 275 | 276 | keys = pygame.key.get_pressed() 277 | 278 | 279 | glMatrixMode(GL_MODELVIEW) 280 | glLoadIdentity() 281 | cam.render() 282 | 283 | axes() 284 | 285 | selection = [] 286 | center = [0, 0, 0] 287 | for obj in scene.objects.values(): 288 | if obj != getEdit() and obj.transparent == False: 289 | obj.draw() 290 | 291 | if obj.selected == True: 292 | selection.append(obj) 293 | 294 | for obj in scene.objects.values(): 295 | if obj != getEdit() and obj.transparent == True: 296 | obj.draw() 297 | 298 | #Make sure that the current object being edited is drawn last 299 | if isEdit(): 300 | getEdit().draw() 301 | 302 | for obj in selection: 303 | center = add( center, obj.center() ) 304 | 305 | 306 | if len(selection) > 0: 307 | center = mult( 1/float(len(selection)) , center) 308 | 309 | distance = dist( center, [cam.x, cam.y, cam.z] ) 310 | 311 | if not isEdit(): #Don't draw move tool in edit mode 312 | movetool(center[0] , center[1], center[2], distance*0.3) 313 | 314 | 315 | drawText2d ( (0,720-25), "Camera Speed = " + str(cam.speed) , 30) 316 | 317 | 318 | pygame.display.flip() 319 | 320 | pygame.quit() 321 | 322 | gui.initialize() 323 | scene.initialize() 324 | 325 | 326 | main() #Start the main code block 327 | os._exit(0) #Once that loop is done, for both threads to close -------------------------------------------------------------------------------- /gameobjects/BoxAberration.py: -------------------------------------------------------------------------------- 1 | from OpenGL.GL import * 2 | from OpenGL.GLU import * 3 | 4 | from util import * 5 | 6 | import gui 7 | import scene 8 | 9 | import wx #import wxWidgets 10 | import wx.propgrid as wxpg 11 | 12 | from gameobject import GameObject 13 | 14 | class BoxAberration ( GameObject ): 15 | def __init__(self, name = None, min = [0,0,0], max = [5,5,5]): 16 | self.name = name 17 | self.min = min 18 | self.max = max 19 | 20 | self.type = "BoxAberration" 21 | 22 | 23 | self.scale = [1.0, 1.0, 1.0] 24 | 25 | self.pointselection = -1 26 | 27 | GameObject.__init__(self) 28 | 29 | self.transparent = True 30 | 31 | @staticmethod 32 | def create(event): 33 | BoxAberration() 34 | 35 | @staticmethod 36 | def load(element): 37 | name = element.getAttribute("name") 38 | min = element.getAttribute("min").split(",") 39 | max = element.getAttribute("max").split(",") 40 | 41 | newobject = BoxAberration(name, toFloats(min), toFloats(max) ) 42 | newobject.selected = (element.getAttribute("selected") == "True") 43 | 44 | newobject.uniform = (element.getAttribute("uniform") == "True") 45 | 46 | newobject.cast = (element.getAttribute("cast") == "True") 47 | newobject.recieve = (element.getAttribute("recieve") == "True") 48 | 49 | newobject.scale = toFloats( element.getAttribute("scale").split(",") ) 50 | 51 | return newobject 52 | 53 | def duplicate(self, newname): 54 | newbox = BoxAberration(newname, [self.min[0], self.min[1], self.min[2]], [self.max[0], self.max[1], self.max[2]]) 55 | 56 | newbox.scale = list( self.scale ) 57 | newbox.uniform = self.uniform 58 | newbox.recieve = self.recieve 59 | newbox.cast = self.cast 60 | 61 | return newbox 62 | def center(self): 63 | return mult( 0.5, add(self.min, self.max) ) 64 | def move(self, x, y, z): 65 | if self.edit: 66 | if self.pointselection == 1: 67 | self.min[0] += x 68 | self.min[1] += y 69 | self.min[2] += z 70 | if self.pointselection == 2: 71 | self.max[0] += x 72 | self.max[1] += y 73 | self.max[2] += z 74 | else: 75 | self.min[0] += x 76 | self.max[0] += x 77 | 78 | self.min[1] += y 79 | self.max[1] += y 80 | 81 | self.min[2] += z 82 | self.max[2] += z 83 | 84 | if self.pg != None: 85 | self.pg.GetPropertyByName("Minimum.X").SetValue(self.min[0]) 86 | self.pg.GetPropertyByName("Minimum.Y").SetValue(self.min[1]) 87 | self.pg.GetPropertyByName("Minimum.Z").SetValue(self.min[2]) 88 | 89 | self.pg.GetPropertyByName("Maximum.X").SetValue(self.max[0]) 90 | self.pg.GetPropertyByName("Maximum.Y").SetValue(self.max[1]) 91 | self.pg.GetPropertyByName("Maximum.Z").SetValue(self.max[2]) 92 | def collide(self, ro, rd): 93 | return iBox(self.min, self.max, ro, rd) 94 | def click(self, pos): 95 | SELECTIONDIST = 30 96 | 97 | self.pointselection = -1 98 | 99 | modelViewMatrix = glGetDouble( GL_MODELVIEW_MATRIX ) 100 | projectionMatrix = glGetDouble( GL_PROJECTION_MATRIX ) 101 | viewport = glGetInteger(GL_VIEWPORT) 102 | 103 | dotpos = gluProject(self.min[0], self.min[1], self.min[2], modelViewMatrix, projectionMatrix, viewport) 104 | if dist( [dotpos[0], dotpos[1]], [pos[0], 720 - pos[1]] ) < SELECTIONDIST: 105 | self.pointselection = 1 106 | 107 | dotpos = gluProject(self.max[0], self.max[1], self.max[2], modelViewMatrix, projectionMatrix, viewport) 108 | if dist( [dotpos[0], dotpos[1]], [pos[0], 720 - pos[1]] ) < SELECTIONDIST: 109 | self.pointselection = 2 110 | def draw(self): 111 | 112 | 113 | glEnable(GL_LIGHTING) 114 | 115 | glMaterialfv(GL_FRONT, GL_DIFFUSE, (1.0, 1.0, 1.0, 0.5)) 116 | 117 | glBegin(GL_QUADS) 118 | 119 | #Front Face 120 | glNormal3f( 0.0, 0.0, 1.0) 121 | glVertex3f( self.min[0], self.min[1], self.max[2] ) 122 | glVertex3f( self.max[0], self.min[1], self.max[2] ) 123 | glVertex3f( self.max[0], self.max[1], self.max[2] ) 124 | glVertex3f( self.min[0], self.max[1], self.max[2] ) 125 | 126 | #Back Face 127 | glNormal3f( 0.0, 0.0,-1.0) 128 | glVertex3f( self.min[0], self.min[1], self.min[2] ) 129 | glVertex3f( self.min[0], self.max[1], self.min[2] ) 130 | glVertex3f( self.max[0], self.max[1], self.min[2] ) 131 | glVertex3f( self.max[0], self.min[1], self.min[2] ) 132 | 133 | #Top Face 134 | glNormal3f( 0.0, 1.0, 0.0) 135 | glVertex3f( self.min[0], self.max[1], self.min[2] ) 136 | glVertex3f( self.min[0], self.max[1], self.max[2] ) 137 | glVertex3f( self.max[0], self.max[1], self.max[2] ) 138 | glVertex3f( self.max[0], self.max[1], self.min[2] ) 139 | 140 | #Bottom Face 141 | glNormal3f( 0.0,-1.0, 0.0) 142 | glVertex3f( self.min[0], self.min[1], self.min[2] ) 143 | glVertex3f( self.max[0], self.min[1], self.min[2] ) 144 | glVertex3f( self.max[0], self.min[1], self.max[2] ) 145 | glVertex3f( self.min[0], self.min[1], self.max[2] ) 146 | 147 | #Right Face 148 | glNormal3f( 1.0, 0.0, 0.0) 149 | glVertex3f( self.max[0], self.min[1], self.min[2] ) 150 | glVertex3f( self.max[0], self.max[1], self.min[2] ) 151 | glVertex3f( self.max[0], self.max[1], self.max[2] ) 152 | glVertex3f( self.max[0], self.min[1], self.max[2] ) 153 | 154 | #Left Face 155 | glNormal3f(-1.0, 0.0, 0.0) 156 | glVertex3f( self.min[0], self.min[1], self.min[2] ) 157 | glVertex3f( self.min[0], self.min[1], self.max[2] ) 158 | glVertex3f( self.min[0], self.max[1], self.max[2] ) 159 | glVertex3f( self.min[0], self.max[1], self.min[2] ) 160 | 161 | glEnd() 162 | 163 | glDisable(GL_LIGHTING) 164 | 165 | glLineWidth(2) 166 | 167 | 168 | if self.edit: 169 | glDisable(GL_DEPTH_TEST) 170 | 171 | 172 | glBegin(GL_LINES) 173 | 174 | if self.edit: 175 | glColor3f(1, 0.62745, 0.176470) 176 | elif self.selected: 177 | glColor3f(0,1,0) 178 | else: 179 | glColor3f(1, 1, 1) 180 | 181 | glVertex3f(self.min[0], self.min[1], self.min[2]) 182 | glVertex3f(self.max[0], self.min[1], self.min[2]) 183 | 184 | glVertex3f(self.min[0], self.min[1], self.min[2]) 185 | glVertex3f(self.min[0], self.max[1], self.min[2]) 186 | 187 | glVertex3f(self.min[0], self.min[1], self.min[2]) 188 | glVertex3f(self.min[0], self.min[1], self.max[2]) 189 | 190 | glVertex3f(self.max[0], self.max[1], self.max[2]) 191 | glVertex3f(self.min[0], self.max[1], self.max[2]) 192 | 193 | glVertex3f(self.max[0], self.max[1], self.max[2]) 194 | glVertex3f(self.max[0], self.min[1], self.max[2]) 195 | 196 | glVertex3f(self.max[0], self.max[1], self.max[2]) 197 | glVertex3f(self.max[0], self.max[1], self.min[2]) 198 | 199 | glVertex3f(self.min[0], self.max[1], self.max[2]) 200 | glVertex3f(self.min[0], self.max[1], self.min[2]) 201 | 202 | glVertex3f(self.max[0], self.max[1], self.min[2]) 203 | glVertex3f(self.min[0], self.max[1], self.min[2]) 204 | 205 | 206 | glVertex3f(self.min[0], self.max[1], self.max[2]) 207 | glVertex3f(self.min[0], self.min[1], self.max[2]) 208 | 209 | glVertex3f(self.max[0], self.max[1], self.min[2]) 210 | glVertex3f(self.max[0], self.min[1], self.min[2]) 211 | 212 | glVertex3f(self.max[0], self.min[1], self.min[2]) 213 | glVertex3f(self.max[0], self.min[1], self.max[2]) 214 | 215 | glVertex3f(self.min[0], self.min[1], self.max[2]) 216 | glVertex3f(self.max[0], self.min[1], self.max[2]) 217 | 218 | glEnd() 219 | 220 | 221 | glLineWidth(1) 222 | 223 | if self.edit: 224 | glPointSize (10) 225 | glBegin(GL_POINTS) 226 | 227 | if self.pointselection == 1: 228 | glColor3f(0, 1, 0) 229 | else: 230 | glColor3f(1, 1, 1) 231 | glVertex3f(self.min[0], self.min[1], self.min[2]) 232 | 233 | if self.pointselection == 2: 234 | glColor3f(0, 1, 0) 235 | else: 236 | glColor3f(1, 1, 1) 237 | 238 | glVertex3f(self.max[0], self.max[1], self.max[2]) 239 | 240 | glEnd() 241 | glPointSize (1) 242 | 243 | if self.pointselection == 1: 244 | movetool(self.min[0], self.min[1], self.min[2], 5) 245 | if self.pointselection == 2: 246 | movetool(self.max[0], self.max[1], self.max[2], 5) 247 | 248 | glEnable(GL_LIGHTING) 249 | 250 | glEnable(GL_DEPTH_TEST) 251 | 252 | def PropertyChange(self, event): 253 | p = event.GetProperty() 254 | if p: 255 | print p.GetName() + " changed." 256 | 257 | #General Properties 258 | if p.GetName() == "Object Name": 259 | del scene.objects[self.name] 260 | self.name = p.GetValue() 261 | scene.objects[self.name] = self 262 | gui.tree_ctrl.SetItemText(self.treeitem, self.name) 263 | if p.GetName() == "Uniform": 264 | self.uniform = p.GetValue() 265 | 266 | if p.GetName() == "Minimum.X": 267 | self.min[0] = p.GetValue() 268 | if p.GetName() == "Minimum.Y": 269 | self.min[1] = p.GetValue() 270 | if p.GetName() == "Minimum.Z": 271 | self.min[2] = p.GetValue() 272 | 273 | if p.GetName() == "Maximum.X": 274 | self.max[0] = p.GetValue() 275 | if p.GetName() == "Maximum.Y": 276 | self.max[1] = p.GetValue() 277 | if p.GetName() == "Maximum.Z": 278 | self.max[2] = p.GetValue() 279 | 280 | if p.GetName() == "Scale.X": 281 | self.scale[0] = p.GetValue() 282 | if p.GetName() == "Scale.Y": 283 | self.scale[1] = p.GetValue() 284 | if p.GetName() == "Scale.Z": 285 | self.scale[2] = p.GetValue() 286 | 287 | if p.GetName() == "Cast Shadows": 288 | self.cast = p.GetValue() 289 | if p.GetName() == "Recieve Shadows": 290 | self.recieve = p.GetValue() 291 | def populatepropgrid(self, pg): 292 | #Geometry Properties 293 | pg.Append( wxpg.PropertyCategory("Geometry") ) 294 | 295 | minID = pg.Append( wxpg.StringProperty("Minimum", value="") ) 296 | pg.AppendIn (minID, wxpg.FloatProperty("X", value=self.min[0]) ) 297 | pg.AppendIn (minID, wxpg.FloatProperty("Y", value=self.min[1]) ) 298 | pg.AppendIn (minID, wxpg.FloatProperty("Z", value=self.min[2]) ) 299 | 300 | maxID = pg.Append( wxpg.StringProperty("Maximum", value="") ) 301 | pg.AppendIn (maxID, wxpg.FloatProperty("X", value=self.max[0]) ) 302 | pg.AppendIn (maxID, wxpg.FloatProperty("Y", value=self.max[1]) ) 303 | pg.AppendIn (maxID, wxpg.FloatProperty("Z", value=self.max[2]) ) 304 | 305 | #Aberration Properties 306 | pg.Append( wxpg.PropertyCategory("Aberration") ) 307 | abID = pg.Append( wxpg.StringProperty("Scale", value="") ) 308 | pg.AppendIn (abID, wxpg.FloatProperty("X", value=self.scale[0]) ) 309 | pg.AppendIn (abID, wxpg.FloatProperty("Y", value=self.scale[1]) ) 310 | pg.AppendIn (abID, wxpg.FloatProperty("Z", value=self.scale[2]) ) 311 | 312 | #Material Properties 313 | pg.Append( wxpg.PropertyCategory("Material") ) 314 | 315 | pg.Append( wxpg.BoolProperty("Cast Shadows",value=self.cast) ) 316 | pg.SetPropertyAttribute("Cast Shadows", "UseCheckbox", True) 317 | 318 | pg.Append( wxpg.BoolProperty("Recieve Shadows",value=self.recieve) ) 319 | pg.SetPropertyAttribute("Recieve Shadows", "UseCheckbox", True) 320 | def write(self, object): 321 | object.setAttribute("min", formatString(self.min) ) 322 | object.setAttribute("max", formatString(self.max) ) 323 | 324 | object.setAttribute("recieve", str(self.recieve) ) 325 | object.setAttribute("cast", str(self.cast) ) 326 | 327 | object.setAttribute("scale", formatString(self.scale) ) -------------------------------------------------------------------------------- /gameobjects/SpherePortal.py: -------------------------------------------------------------------------------- 1 | from OpenGL.GL import * 2 | from OpenGL.GLU import * 3 | 4 | from util import * 5 | 6 | import gui 7 | import scene 8 | 9 | import wx #import wxWidgets 10 | import wx.propgrid as wxpg 11 | 12 | from gameobject import GameObject 13 | 14 | class SpherePortal ( GameObject ): 15 | def __init__(self, name = None, x = 1, y = 1, z = 1, r = 1): 16 | self.name = name 17 | self.x = x 18 | self.y = y 19 | self.z = z 20 | 21 | 22 | self.x2 = x+r*4 23 | self.y2 = y 24 | self.z2 = z 25 | 26 | self.r = r 27 | 28 | self.reflectivity = 0.0 29 | 30 | self.type = "SpherePortal" 31 | 32 | self.pointselection = -1 33 | 34 | GameObject.__init__(self) 35 | 36 | @staticmethod 37 | def create(event): 38 | SpherePortal() 39 | 40 | @staticmethod 41 | def load(element): 42 | name = element.getAttribute("name") 43 | 44 | newobject = SpherePortal(name, float( element.getAttribute("x")) , float(element.getAttribute("y")) , float(element.getAttribute("z")) , float(element.getAttribute("r")) ) 45 | 46 | newobject.x2 = float(element.getAttribute("x2")) 47 | newobject.y2 = float(element.getAttribute("y2")) 48 | newobject.z2 = float(element.getAttribute("z2")) 49 | 50 | newobject.selected = (element.getAttribute("selected") == "True") 51 | 52 | newobject.uniform = (element.getAttribute("uniform") == "True") 53 | 54 | newobject.reflectivity = float(element.getAttribute("reflectivity")) 55 | newobject.recieve = (element.getAttribute("recieve") == "True") 56 | newobject.cast = (element.getAttribute("cast") == "True") 57 | 58 | return newobject 59 | 60 | def duplicate(self, newname): 61 | newsphere = SpherePortal(newname, self.x, self.y, self.z, self.r) 62 | 63 | newsphere.uniform = self.uniform 64 | newsphere.recieve = self.recieve 65 | newsphere.cast = self.cast 66 | 67 | newsphere.x2 = self.x2 68 | newsphere.y2 = self.y2 69 | newsphere.z2 = self.z2 70 | 71 | newsphere.reflectivity = self.reflectivity 72 | 73 | return newsphere 74 | def center(self): 75 | return [self.x, self.y, self.z] 76 | def move(self, x, y, z): 77 | if self.edit: 78 | if self.pointselection == 1: 79 | self.x += x 80 | self.y += y 81 | self.z += z 82 | if self.pointselection == 2: 83 | self.r += x 84 | if self.pointselection == 3: 85 | self.x2 += x 86 | self.y2 += y 87 | self.z2 += z 88 | if self.pointselection == 4: 89 | self.r += x 90 | else: 91 | self.x += x 92 | self.y += y 93 | self.z += z 94 | 95 | self.x2 += x 96 | self.y2 += y 97 | self.z2 += z 98 | 99 | if self.pg != None: 100 | self.pg.GetPropertyByName("Center.X").SetValue(self.x) 101 | self.pg.GetPropertyByName("Center.Y").SetValue(self.y) 102 | self.pg.GetPropertyByName("Center.Z").SetValue(self.z) 103 | 104 | self.pg.GetPropertyByName("Center2.X").SetValue(self.x2) 105 | self.pg.GetPropertyByName("Center2.Y").SetValue(self.y2) 106 | self.pg.GetPropertyByName("Center2.Z").SetValue(self.z2) 107 | 108 | self.pg.GetPropertyByName("Radius").SetValue(self.r) 109 | 110 | def collide(self, ro, rd): 111 | result1 = iSphere(self.x, self.y, self.z, self.r, ro, rd) 112 | result2 = iSphere(self.x2, self.y2, self.z2, self.r, ro, rd) 113 | 114 | if result1[0]: 115 | return result1 116 | else: 117 | return result2 118 | def click(self, pos): 119 | SELECTIONDIST = 20 120 | 121 | self.pointselection = -1 122 | 123 | modelViewMatrix = glGetDouble( GL_MODELVIEW_MATRIX ) 124 | projectionMatrix = glGetDouble( GL_PROJECTION_MATRIX ) 125 | viewport = glGetInteger(GL_VIEWPORT) 126 | 127 | dotpos = gluProject(self.x , self.y, self.z, modelViewMatrix, projectionMatrix, viewport) 128 | if dist( [dotpos[0], dotpos[1]], [pos[0], 720 - pos[1]] ) < SELECTIONDIST: 129 | self.pointselection = 1 130 | 131 | dotpos = gluProject(self.x + self.r, self.y, self.z, modelViewMatrix, projectionMatrix, viewport) 132 | if dist( [dotpos[0], dotpos[1]], [pos[0], 720 - pos[1]] ) < SELECTIONDIST: 133 | self.pointselection = 2 134 | 135 | dotpos = gluProject(self.x2 , self.y2, self.z2, modelViewMatrix, projectionMatrix, viewport) 136 | if dist( [dotpos[0], dotpos[1]], [pos[0], 720 - pos[1]] ) < SELECTIONDIST: 137 | self.pointselection = 3 138 | 139 | dotpos = gluProject(self.x2 + self.r, self.y2, self.z2, modelViewMatrix, projectionMatrix, viewport) 140 | if dist( [dotpos[0], dotpos[1]], [pos[0], 720 - pos[1]] ) < SELECTIONDIST: 141 | self.pointselection = 4 142 | def draw(self): 143 | glEnable(GL_LIGHTING) 144 | 145 | glMaterialfv(GL_FRONT, GL_DIFFUSE, (0.0, 0.0, 1.0, 1.0)) 146 | 147 | 148 | 149 | glPushMatrix() 150 | glTranslatef(self.x, self.y, self.z) 151 | q = gluNewQuadric() 152 | gluSphere( q, self.r, 10, 10 ) 153 | glPopMatrix() 154 | 155 | glPushMatrix() 156 | glTranslatef(self.x2, self.y2, self.z2) 157 | q = gluNewQuadric() 158 | gluSphere( q, self.r, 10, 10 ) 159 | glPopMatrix() 160 | 161 | glDisable(GL_LIGHTING) 162 | 163 | glLineWidth(2) 164 | 165 | glBegin(GL_LINES) 166 | 167 | #Set bounding box color 168 | if self.edit: 169 | glColor3f(1, 0.62745, 0.176470) 170 | elif self.selected: 171 | glColor3f(0,1,0) 172 | else: 173 | glColor3f(1, 1, 1) 174 | 175 | #Draw box around first sphere 176 | self.min = [self.x - self.r,self.y - self.r,self.z - self.r] 177 | self.max = [self.x + self.r,self.y + self.r,self.z + self.r] 178 | 179 | glVertex3f(self.min[0], self.min[1], self.min[2]) 180 | glVertex3f(self.max[0], self.min[1], self.min[2]) 181 | 182 | glVertex3f(self.min[0], self.min[1], self.min[2]) 183 | glVertex3f(self.min[0], self.max[1], self.min[2]) 184 | 185 | glVertex3f(self.min[0], self.min[1], self.min[2]) 186 | glVertex3f(self.min[0], self.min[1], self.max[2]) 187 | 188 | glVertex3f(self.max[0], self.max[1], self.max[2]) 189 | glVertex3f(self.min[0], self.max[1], self.max[2]) 190 | 191 | glVertex3f(self.max[0], self.max[1], self.max[2]) 192 | glVertex3f(self.max[0], self.min[1], self.max[2]) 193 | 194 | glVertex3f(self.max[0], self.max[1], self.max[2]) 195 | glVertex3f(self.max[0], self.max[1], self.min[2]) 196 | 197 | glVertex3f(self.min[0], self.max[1], self.max[2]) 198 | glVertex3f(self.min[0], self.max[1], self.min[2]) 199 | 200 | glVertex3f(self.max[0], self.max[1], self.min[2]) 201 | glVertex3f(self.min[0], self.max[1], self.min[2]) 202 | 203 | 204 | glVertex3f(self.min[0], self.max[1], self.max[2]) 205 | glVertex3f(self.min[0], self.min[1], self.max[2]) 206 | 207 | glVertex3f(self.max[0], self.max[1], self.min[2]) 208 | glVertex3f(self.max[0], self.min[1], self.min[2]) 209 | 210 | glVertex3f(self.max[0], self.min[1], self.min[2]) 211 | glVertex3f(self.max[0], self.min[1], self.max[2]) 212 | 213 | glVertex3f(self.min[0], self.min[1], self.max[2]) 214 | glVertex3f(self.max[0], self.min[1], self.max[2]) 215 | 216 | #Draw box around second sphere 217 | self.min = [self.x2 - self.r,self.y2 - self.r,self.z2 - self.r] 218 | self.max = [self.x2 + self.r,self.y2 + self.r,self.z2 + self.r] 219 | 220 | glVertex3f(self.min[0], self.min[1], self.min[2]) 221 | glVertex3f(self.max[0], self.min[1], self.min[2]) 222 | 223 | glVertex3f(self.min[0], self.min[1], self.min[2]) 224 | glVertex3f(self.min[0], self.max[1], self.min[2]) 225 | 226 | glVertex3f(self.min[0], self.min[1], self.min[2]) 227 | glVertex3f(self.min[0], self.min[1], self.max[2]) 228 | 229 | glVertex3f(self.max[0], self.max[1], self.max[2]) 230 | glVertex3f(self.min[0], self.max[1], self.max[2]) 231 | 232 | glVertex3f(self.max[0], self.max[1], self.max[2]) 233 | glVertex3f(self.max[0], self.min[1], self.max[2]) 234 | 235 | glVertex3f(self.max[0], self.max[1], self.max[2]) 236 | glVertex3f(self.max[0], self.max[1], self.min[2]) 237 | 238 | glVertex3f(self.min[0], self.max[1], self.max[2]) 239 | glVertex3f(self.min[0], self.max[1], self.min[2]) 240 | 241 | glVertex3f(self.max[0], self.max[1], self.min[2]) 242 | glVertex3f(self.min[0], self.max[1], self.min[2]) 243 | 244 | 245 | glVertex3f(self.min[0], self.max[1], self.max[2]) 246 | glVertex3f(self.min[0], self.min[1], self.max[2]) 247 | 248 | glVertex3f(self.max[0], self.max[1], self.min[2]) 249 | glVertex3f(self.max[0], self.min[1], self.min[2]) 250 | 251 | glVertex3f(self.max[0], self.min[1], self.min[2]) 252 | glVertex3f(self.max[0], self.min[1], self.max[2]) 253 | 254 | glVertex3f(self.min[0], self.min[1], self.max[2]) 255 | glVertex3f(self.max[0], self.min[1], self.max[2]) 256 | 257 | glEnd() 258 | 259 | glLineWidth(1) 260 | 261 | if self.edit: 262 | glDisable(GL_DEPTH_TEST) 263 | 264 | glPointSize (10) 265 | glBegin(GL_POINTS) 266 | 267 | if self.pointselection == 1: 268 | glColor3f(0, 1, 0) 269 | else: 270 | glColor3f(1, 1, 1) 271 | glVertex3f(self.x, self.y, self.z) 272 | 273 | if self.pointselection == 2: 274 | glColor3f(0, 1, 0) 275 | else: 276 | glColor3f(1, 1, 1) 277 | 278 | glVertex3f(self.x + self.r, self.y, self.z) 279 | 280 | if self.pointselection == 3: 281 | glColor3f(0, 1, 0) 282 | else: 283 | glColor3f(1, 1, 1) 284 | glVertex3f(self.x2, self.y2, self.z2) 285 | 286 | if self.pointselection == 4: 287 | glColor3f(0, 1, 0) 288 | else: 289 | glColor3f(1, 1, 1) 290 | glVertex3f(self.x2 + self.r, self.y2, self.z2) 291 | 292 | glEnd() 293 | glPointSize (1) 294 | 295 | if self.pointselection == 1: 296 | movetool(self.x, self.y, self.z, 5) 297 | if self.pointselection == 2: 298 | movetool(self.x + self.r, self.y, self.z, 5) 299 | if self.pointselection == 3: 300 | movetool(self.x2, self.y2, self.z2, 5) 301 | if self.pointselection == 4: 302 | movetool(self.x2 + self.r, self.y2, self.z2, 5) 303 | 304 | glEnable(GL_DEPTH_TEST) 305 | 306 | glEnable(GL_LIGHTING) 307 | def PropertyChange(self, event): 308 | p = event.GetProperty() 309 | if p: 310 | print p.GetName() + " changed." 311 | 312 | #General Properties 313 | if p.GetName() == "Object Name": 314 | del scene.objects[self.name] 315 | self.name = p.GetValue() 316 | scene.objects[self.name] = self 317 | gui.tree_ctrl.SetItemText(self.treeitem, self.name) 318 | if p.GetName() == "Uniform": 319 | self.uniform = p.GetValue() 320 | 321 | if p.GetName() == "Center.X": 322 | self.x = p.GetValue() 323 | if p.GetName() == "Center.Y": 324 | self.y = p.GetValue() 325 | if p.GetName() == "Center.Z": 326 | self.z = p.GetValue() 327 | 328 | if p.GetName() == "Center2.X": 329 | self.x2 = p.GetValue() 330 | if p.GetName() == "Center2.Y": 331 | self.y2 = p.GetValue() 332 | if p.GetName() == "Center2.Z": 333 | self.z2 = p.GetValue() 334 | 335 | if p.GetName() == "Radius": 336 | self.r = p.GetValue() 337 | 338 | #Material Properties 339 | if p.GetName() == "Reflectivity": 340 | self.reflectivity = p.GetValue() 341 | if p.GetName() == "Cast Shadows": 342 | self.cast = p.GetValue() 343 | if p.GetName() == "Recieve Shadows": 344 | self.recieve = p.GetValue() 345 | def populatepropgrid(self, pg): 346 | #Geometry Properties 347 | pg.Append( wxpg.PropertyCategory("Geometry") ) 348 | 349 | normalID = pg.Append( wxpg.StringProperty("Center", value="") ) 350 | pg.AppendIn (normalID, wxpg.FloatProperty("X", value=self.x) ) 351 | pg.AppendIn (normalID, wxpg.FloatProperty("Y", value=self.y) ) 352 | pg.AppendIn (normalID, wxpg.FloatProperty("Z", value=self.z) ) 353 | 354 | normalID2 = pg.Append( wxpg.StringProperty("Center2", value="") ) 355 | pg.AppendIn (normalID2, wxpg.FloatProperty("X", value=self.x2) ) 356 | pg.AppendIn (normalID2, wxpg.FloatProperty("Y", value=self.y2) ) 357 | pg.AppendIn (normalID2, wxpg.FloatProperty("Z", value=self.z2) ) 358 | 359 | pg.Append( wxpg.FloatProperty("Radius", value=self.r) ) 360 | 361 | #Material Properties 362 | pg.Append( wxpg.PropertyCategory("Material") ) 363 | pg.Append( wxpg.FloatProperty("Reflectivity", value=self.reflectivity) ) 364 | 365 | pg.Append( wxpg.BoolProperty("Cast Shadows",value=self.cast) ) 366 | pg.SetPropertyAttribute("Cast Shadows", "UseCheckbox", True) 367 | 368 | pg.Append( wxpg.BoolProperty("Recieve Shadows",value=self.recieve) ) 369 | pg.SetPropertyAttribute("Recieve Shadows", "UseCheckbox", True) 370 | 371 | def write(self, object): 372 | object.setAttribute("x", str(self.x) ) 373 | object.setAttribute("y", str(self.y) ) 374 | object.setAttribute("z", str(self.z) ) 375 | 376 | object.setAttribute("x2", str(self.x2) ) 377 | object.setAttribute("y2", str(self.y2) ) 378 | object.setAttribute("z2", str(self.z2) ) 379 | 380 | object.setAttribute("r", str(self.r) ) 381 | 382 | object.setAttribute("reflectivity", str(self.reflectivity) ) 383 | object.setAttribute("recieve", str(self.recieve) ) 384 | object.setAttribute("cast", str(self.cast) ) --------------------------------------------------------------------------------