Browse Source

Added RGBA attribute to object data structure

Gyedo Jeon 16 years ago
parent
commit
b60fa8ff04

+ 1 - 0
direct/src/leveleditor/ObjectGlobals.py

@@ -9,6 +9,7 @@ OBJ_DEF = 2
 OBJ_MODEL = 3
 OBJ_ANIM = 4
 OBJ_PROP = 5
+OBJ_RGBA = 6
 
 # supported UI types
 PROP_UI_ENTRY = '_PropUIEntry'

+ 16 - 9
direct/src/leveleditor/ObjectMgr.py

@@ -130,7 +130,7 @@ class ObjectMgr:
                 properties[key] = objDef.properties[key][OG.PROP_DEFAULT]
 
             # insert obj data to main repository
-            self.objects[uid] = [uid, newobj, objDef, model, anim, properties]
+            self.objects[uid] = [uid, newobj, objDef, model, anim, properties, (1,1,1,1)]
             self.npIndex[NodePath(newobj)] = uid
 
             if self.editor:
@@ -150,7 +150,7 @@ class ObjectMgr:
         return self.objects.get(uid)
 
     def findObjectByNodePath(self, nodePath):
-        uid = self.npIndex.get(nodePath)
+        uid = self.npIndex.get(NodePath(nodePath))
         if uid is None:
             return None
         else:
@@ -265,12 +265,19 @@ class ObjectMgr:
         np.setSy(float(self.editor.ui.objectPropertyUI.propSY.getValue()))
         np.setSz(float(self.editor.ui.objectPropertyUI.propSZ.getValue()))        
         
-    def updateObjectColor(self, r, g, b, a):
-        if self.currNodePath is None:
-            return
+    def updateObjectColor(self, r, g, b, a, np=None):
+        if np is None:
+            np = self.currNodePath
 
-        np = self.currNodePath
-        np.setColorScale(r, g, b, a)
+        obj = self.findObjectByNodePath(np)
+        if not obj:
+            return
+        obj[OG.OBJ_RGBA] = (r,g,b,a)
+        for child in np.getChildren():
+            if not child.hasTag('OBJRoot') and\
+               child.getName() != 'bboxines':
+                child.setTransparency(1)
+                child.setColorScale(r, g, b, a)
 
     def updateObjectModel(self, model, obj, fSelectObject=True):
         """ replace object's model """
@@ -463,6 +470,7 @@ class ObjectMgr:
                     objDef = obj[OG.OBJ_DEF]
                     objModel = obj[OG.OBJ_MODEL]
                     objProp = obj[OG.OBJ_PROP]
+                    objRGBA = obj[OG.OBJ_RGBA]
 
                     if parentId:
                         parentStr = "objects['%s']"%parentId
@@ -477,8 +485,7 @@ class ObjectMgr:
                     self.saveData.append("    objects['%s'].setPos(%s)"%(uid, np.getPos()))
                     self.saveData.append("    objects['%s'].setHpr(%s)"%(uid, np.getHpr()))
                     self.saveData.append("    objects['%s'].setScale(%s)"%(uid, np.getScale()))
-                    self.saveData.append("    objects['%s'].setTransparency(1)"%uid)
-                    self.saveData.append("    objects['%s'].setColorScale(%s)"%(uid, np.getColorScale()))
+                    self.saveData.append("    objectMgr.updateObjectColor(%f, %f, %f, %f, objects['%s'])"%(objRGBA[0], objRGBA[1], objRGBA[2], objRGBA[3], uid))
                     self.saveData.append("    objectMgr.updateObjectProperties(objects['%s'], %s)"%(uid,objProp))
                     
                 self.traverse(child, uid)

+ 2 - 1
direct/src/leveleditor/SceneGraphUI.py

@@ -243,7 +243,8 @@ class SceneGraphUI(wx.Panel):
         itemId = self.tree.GetItemPyData(event.GetItem())
         if itemId:
             obj = self.editor.objectMgr.findObjectById(itemId);
-            base.direct.select(obj[OG.OBJ_NP])
+            if obj:
+                base.direct.select(obj[OG.OBJ_NP])
 
     def onBeginDrag(self, event):
         item = event.GetItem()

+ 72 - 79
direct/src/leveleditor/testData.py

@@ -1,79 +1,72 @@
-from pandac.PandaModules import *
-
-if hasattr(base, 'le'):
-    objectMgr = base.le.objectMgr
-    ui = base.le.ui
-    ui.sceneGraphUI.reset()
-
-else:
-    objectMgr = base.objectMgr
-# temporary place holder for nodepath
-objects = {}
-
-objects['1252538687.73gjeon'] = objectMgr.addNewObject('Smiley', '1252538687.73gjeon', 'models/smiley.egg', None)
-if objects['1252538687.73gjeon']:
-    objects['1252538687.73gjeon'].setPos(Point3(8.66381, 0, 7.13246))
-    objects['1252538687.73gjeon'].setHpr(VBase3(-180, 0, 0))
-    objects['1252538687.73gjeon'].setScale(VBase3(1, 1, 1))
-    objects['1252538687.73gjeon'].setTransparency(1)
-    objects['1252538687.73gjeon'].setColorScale(VBase4(1, 1, 1, 1))
-    objectMgr.updateObjectProperties(objects['1252538687.73gjeon'], {'123': 1, 'Abc': 'a', 'Number': 1, 'Happy': True})
-
-objects['1252538690.2gjeon'] = objectMgr.addNewObject('H Double Smiley', '1252538690.2gjeon', None, objects['1252538687.73gjeon'])
-if objects['1252538690.2gjeon']:
-    objects['1252538690.2gjeon'].setPos(Point3(0, 0, 2.12046))
-    objects['1252538690.2gjeon'].setHpr(VBase3(0, 0, 0))
-    objects['1252538690.2gjeon'].setScale(VBase3(1, 1, 1))
-    objects['1252538690.2gjeon'].setTransparency(1)
-    objects['1252538690.2gjeon'].setColorScale(VBase4(1, 1, 1, 1))
-    objectMgr.updateObjectProperties(objects['1252538690.2gjeon'], {'Distance': 2.0, 'Abc': 'a'})
-
-objects['1252539696.69gjeon'] = objectMgr.addNewObject('H Double Smiley', '1252539696.69gjeon', None, objects['1252538687.73gjeon'])
-if objects['1252539696.69gjeon']:
-    objects['1252539696.69gjeon'].setPos(Point3(-9.53674e-006, 0, 0))
-    objects['1252539696.69gjeon'].setHpr(VBase3(0, 0, 0))
-    objects['1252539696.69gjeon'].setScale(VBase3(1, 1, 1))
-    objects['1252539696.69gjeon'].setTransparency(1)
-    objects['1252539696.69gjeon'].setColorScale(VBase4(1, 1, 1, 1))
-    objectMgr.updateObjectProperties(objects['1252539696.69gjeon'], {'Distance': 2.0, 'Abc': 'a'})
-
-objects['1252539897.22gjeon'] = objectMgr.addNewObject('H Double Smiley', '1252539897.22gjeon', None, objects['1252538687.73gjeon'])
-if objects['1252539897.22gjeon']:
-    objects['1252539897.22gjeon'].setPos(Point3(0.06987, 0, -2.12046))
-    objects['1252539897.22gjeon'].setHpr(VBase3(0, 0, 0))
-    objects['1252539897.22gjeon'].setScale(VBase3(1, 1, 1))
-    objects['1252539897.22gjeon'].setTransparency(1)
-    objects['1252539897.22gjeon'].setColorScale(VBase4(1, 1, 1, 1))
-    objectMgr.updateObjectProperties(objects['1252539897.22gjeon'], {'Distance': 2.0, 'Abc': 'a'})
-
-objects['1252538689.13gjeon'] = objectMgr.addNewObject('V Double Smiley', '1252538689.13gjeon', None, objects['1252538687.73gjeon'])
-if objects['1252538689.13gjeon']:
-    objects['1252538689.13gjeon'].setPos(Point3(6.07152, 0, -0.863791))
-    objects['1252538689.13gjeon'].setHpr(VBase3(0, 0, 0))
-    objects['1252538689.13gjeon'].setScale(VBase3(1, 1, 1))
-    objects['1252538689.13gjeon'].setTransparency(1)
-    objects['1252538689.13gjeon'].setColorScale(VBase4(1, 1, 1, 1))
-    objectMgr.updateObjectProperties(objects['1252538689.13gjeon'], {'Distance': 1.0, 'Abc': 'a'})
-
-objects['1252539974.19gjeon'] = objectMgr.addNewObject('Smiley', '1252539974.19gjeon', 'models/frowney.egg', objects['1252538689.13gjeon'])
-if objects['1252539974.19gjeon']:
-    objects['1252539974.19gjeon'].setPos(Point3(0.06987, 0, 3.09209))
-    objects['1252539974.19gjeon'].setHpr(VBase3(0, 0, 0))
-    objects['1252539974.19gjeon'].setScale(VBase3(1, 1, 1))
-    objects['1252539974.19gjeon'].setTransparency(1)
-    objects['1252539974.19gjeon'].setColorScale(VBase4(1, 1, 1, 1))
-    objectMgr.updateObjectProperties(objects['1252539974.19gjeon'], {'123': 1, 'Abc': 'a', 'Number': 1, 'Happy': True})
-
-objects['1252623762.9gjeon'] = objectMgr.addNewObject('Panda', '1252623762.9gjeon', None, None)
-if objects['1252623762.9gjeon']:
-    objects['1252623762.9gjeon'].setPos(Point3(0, 0, 0))
-    objects['1252623762.9gjeon'].setHpr(VBase3(172.8, 0, 0))
-    objects['1252623762.9gjeon'].setScale(VBase3(0.005, 0.005, 0.005))
-    objects['1252623762.9gjeon'].setTransparency(1)
-    objects['1252623762.9gjeon'].setColorScale(VBase4(1, 0, 0, 0.57))
-    objectMgr.updateObjectProperties(objects['1252623762.9gjeon'], {})
-
-if hasattr(base, 'le'):
-    ui.layerEditorUI.reset()
-    ui.layerEditorUI.addLayerEntry('Layer1', 1 )
-    ui.layerEditorUI.addLayerData(1, '1252538687.73gjeon')
+from pandac.PandaModules import *
+
+if hasattr(base, 'le'):
+    objectMgr = base.le.objectMgr
+    ui = base.le.ui
+    ui.sceneGraphUI.reset()
+
+else:
+    objectMgr = base.objectMgr
+# temporary place holder for nodepath
+objects = {}
+
+objects['1252538687.73gjeon'] = objectMgr.addNewObject('Smiley', '1252538687.73gjeon', 'models/smiley.egg', None)
+if objects['1252538687.73gjeon']:
+    objects['1252538687.73gjeon'].setPos(Point3(8.66381, 0, 7.13246))
+    objects['1252538687.73gjeon'].setHpr(VBase3(-180, 0, 0))
+    objects['1252538687.73gjeon'].setScale(VBase3(1, 1, 1))
+    objectMgr.updateObjectColor(1.000000, 1.000000, 1.000000, 1.000000, objects['1252538687.73gjeon'])
+    objectMgr.updateObjectProperties(objects['1252538687.73gjeon'], {'123': 1, 'Abc': 'a', 'Number': 1, 'Happy': True})
+
+objects['1252538690.2gjeon'] = objectMgr.addNewObject('H Double Smiley', '1252538690.2gjeon', None, objects['1252538687.73gjeon'])
+if objects['1252538690.2gjeon']:
+    objects['1252538690.2gjeon'].setPos(Point3(0, 0, 2.12046))
+    objects['1252538690.2gjeon'].setHpr(VBase3(0, 0, 0))
+    objects['1252538690.2gjeon'].setScale(VBase3(1, 1, 1))
+    objectMgr.updateObjectColor(1.000000, 1.000000, 1.000000, 1.000000, objects['1252538690.2gjeon'])
+    objectMgr.updateObjectProperties(objects['1252538690.2gjeon'], {'Distance': 2.0, 'Abc': 'a'})
+
+objects['1252539696.69gjeon'] = objectMgr.addNewObject('H Double Smiley', '1252539696.69gjeon', None, objects['1252538687.73gjeon'])
+if objects['1252539696.69gjeon']:
+    objects['1252539696.69gjeon'].setPos(Point3(-9.53674e-006, 0, 0))
+    objects['1252539696.69gjeon'].setHpr(VBase3(0, 0, 0))
+    objects['1252539696.69gjeon'].setScale(VBase3(1, 1, 1))
+    objectMgr.updateObjectColor(1.000000, 1.000000, 1.000000, 1.000000, objects['1252539696.69gjeon'])
+    objectMgr.updateObjectProperties(objects['1252539696.69gjeon'], {'Distance': 2.0, 'Abc': 'a'})
+
+objects['1252539897.22gjeon'] = objectMgr.addNewObject('H Double Smiley', '1252539897.22gjeon', None, objects['1252538687.73gjeon'])
+if objects['1252539897.22gjeon']:
+    objects['1252539897.22gjeon'].setPos(Point3(0.06987, 0, -2.12046))
+    objects['1252539897.22gjeon'].setHpr(VBase3(0, 0, 0))
+    objects['1252539897.22gjeon'].setScale(VBase3(1, 1, 1))
+    objectMgr.updateObjectColor(1.000000, 1.000000, 1.000000, 1.000000, objects['1252539897.22gjeon'])
+    objectMgr.updateObjectProperties(objects['1252539897.22gjeon'], {'Distance': 2.0, 'Abc': 'a'})
+
+objects['1252538689.13gjeon'] = objectMgr.addNewObject('V Double Smiley', '1252538689.13gjeon', None, objects['1252538687.73gjeon'])
+if objects['1252538689.13gjeon']:
+    objects['1252538689.13gjeon'].setPos(Point3(6.07152, 0, -0.863791))
+    objects['1252538689.13gjeon'].setHpr(VBase3(0, 0, 0))
+    objects['1252538689.13gjeon'].setScale(VBase3(1, 1, 1))
+    objectMgr.updateObjectColor(1.000000, 1.000000, 1.000000, 1.000000, objects['1252538689.13gjeon'])
+    objectMgr.updateObjectProperties(objects['1252538689.13gjeon'], {'Distance': 1.0, 'Abc': 'a'})
+
+objects['1252539974.19gjeon'] = objectMgr.addNewObject('Smiley', '1252539974.19gjeon', 'models/frowney.egg', objects['1252538689.13gjeon'])
+if objects['1252539974.19gjeon']:
+    objects['1252539974.19gjeon'].setPos(Point3(0.06987, 0, 3.09209))
+    objects['1252539974.19gjeon'].setHpr(VBase3(0, 0, 0))
+    objects['1252539974.19gjeon'].setScale(VBase3(1, 1, 1))
+    objectMgr.updateObjectColor(1.000000, 1.000000, 1.000000, 1.000000, objects['1252539974.19gjeon'])
+    objectMgr.updateObjectProperties(objects['1252539974.19gjeon'], {'123': 1, 'Abc': 'a', 'Number': 1, 'Happy': True})
+
+objects['1252623762.9gjeon'] = objectMgr.addNewObject('Panda', '1252623762.9gjeon', None, None)
+if objects['1252623762.9gjeon']:
+    objects['1252623762.9gjeon'].setPos(Point3(0, 0, 0))
+    objects['1252623762.9gjeon'].setHpr(VBase3(172.8, 0, 0))
+    objects['1252623762.9gjeon'].setScale(VBase3(0.005, 0.005, 0.005))
+    objectMgr.updateObjectColor(1.000000, 0.000000, 0.000000, 0.517647, objects['1252623762.9gjeon'])
+    objectMgr.updateObjectProperties(objects['1252623762.9gjeon'], {})
+
+if hasattr(base, 'le'):
+    ui.layerEditorUI.reset()
+    ui.layerEditorUI.addLayerEntry('Layer1', 1 )
+    ui.layerEditorUI.addLayerData(1, '1252538687.73gjeon')