Procházet zdrojové kódy

*** empty log message ***

Mark Mine před 25 roky
rodič
revize
11b70c31f2

+ 56 - 44
direct/src/directtools/DirectLights.py

@@ -2,6 +2,23 @@ from PandaObject import *
 from DirectGeometry import *
 from DirectGeometry import *
 from string import lower
 from string import lower
 
 
+class DirectLight(NodePath):
+    def __init__(self, light, parent):
+        # Initialize the superclass
+        NodePath.__init__(self)
+        # Record light and name
+        self.light = light
+        self.name = light.getName()
+        # Attach node to self
+        if isinstance(light, Spotlight):
+            self.assign(parent.attachNewNode(light.upcastToProjectionNode()))
+        else:
+            self.assign(parent.attachNewNode(light.upcastToNamedNode()))
+    def getName(self):
+        return self.name
+    def getLight(self):
+        return self.light
+
 class DirectLights(NodePath):
 class DirectLights(NodePath):
     def __init__(self, parent = None):
     def __init__(self, parent = None):
         # Initialize the superclass
         # Initialize the superclass
@@ -14,73 +31,72 @@ class DirectLights(NodePath):
         # Create a light attribute 
         # Create a light attribute 
         self.la = LightAttribute()
         self.la = LightAttribute()
         # Create a list of all active lights
         # Create a list of all active lights
-        self.lightList = []
-        self.nodePathList = []
-        self.nameList = []
+        self.lightDict = {}
         # Counts of the various types of lights
         # Counts of the various types of lights
         self.ambientCount = 0
         self.ambientCount = 0
         self.directionalCount = 0
         self.directionalCount = 0
         self.pointCount = 0
         self.pointCount = 0
         self.spotCount = 0
         self.spotCount = 0
 
 
-    def __getitem__(self, index):
-        return self.lightList[index]
+    def __getitem__(self, name):
+        return self.lightDict.get(name, None)
 
 
     def __len__(self):
     def __len__(self):
-        return len(self.lightList)
-
-    def getLightNodePath(self, index):
-        return self.nodePathList[index]
-
-    def getLightName(self, index):
-        return self.nameList[index]
-
+        return len(self.lightDict)
+
+    def delete(self, light):
+        del self.lightDict[light.getName()]
+        self.setOff(light)
+        light.removeNode()
+
+    def deleteAll(self):
+        for light in self.asList():
+            self.delete(light)
+
+    def asList(self):
+        return map(lambda n, s=self: s[n], self.getNameList())
+
+    def getNameList(self):
+        # Return a sorted list of all lights in the light dict
+        nameList = map(lambda x: x.getName(), self.lightDict.values())
+        nameList.sort()
+        return nameList
+    
     def create(self, type):
     def create(self, type):
         type = type.lower()
         type = type.lower()
         if type == 'ambient':
         if type == 'ambient':
             self.ambientCount += 1
             self.ambientCount += 1
-            light = AmbientLight('ambient_' + `self.ambientCount`)
+            light = AmbientLight('ambient-' + `self.ambientCount`)
             light.setColor(VBase4(.3,.3,.3,1))
             light.setColor(VBase4(.3,.3,.3,1))
         elif type == 'directional':
         elif type == 'directional':
             self.directionalCount += 1
             self.directionalCount += 1
-            light = DirectionalLight('directional_' + `self.directionalCount`)
+            light = DirectionalLight('directional-' + `self.directionalCount`)
             light.setColor(VBase4(1))
             light.setColor(VBase4(1))
         elif type == 'point':
         elif type == 'point':
             self.pointCount += 1
             self.pointCount += 1
-            light = PointLight('point_' + `self.pointCount`)
+            light = PointLight('point-' + `self.pointCount`)
             light.setColor(VBase4(1))
             light.setColor(VBase4(1))
         elif type == 'spot':
         elif type == 'spot':
             self.spotCount += 1
             self.spotCount += 1
-            light = Spotlight('spot_' + `self.spotCount`)
+            light = Spotlight('spot-' + `self.spotCount`)
             light.setColor(VBase4(1))
             light.setColor(VBase4(1))
         else:
         else:
             print 'Invalid light type'
             print 'Invalid light type'
             return None
             return None
         # Add the new light
         # Add the new light
-        self.addLight(light)
+        directLight = DirectLight(light,self)
+        self.lightDict[directLight.getName()] = directLight
         # Turn it on as a default
         # Turn it on as a default
-        self.setOn(light)
+        self.setOn(directLight)
+        # Send an event to all watching objects
+        messenger.send('DirectLights_addLight', [directLight])
         # Return the new light
         # Return the new light
-        return light
+        return directLight
 
 
     def createDefaultLights(self):
     def createDefaultLights(self):
         self.create('ambient')
         self.create('ambient')
         self.create('directional')
         self.create('directional')
 
 
-    def addLight(self, light):
-        # Attach node to self
-        if isinstance(light, Spotlight):
-            nodePath = self.attachNewNode(light.upcastToProjectionNode())
-        else:
-            nodePath = self.attachNewNode(light.upcastToNamedNode())
-        name = light.getName()
-        # Store it in the lists
-        self.lightList.append(light)
-        self.nodePathList.append(nodePath)
-        self.nameList.append(name)
-        # Send an event to all watching objects
-        messenger.send('DirectLights_addLight', [light])
-
     def allOn(self):
     def allOn(self):
         """ Turn on all DIRECT lights """
         """ Turn on all DIRECT lights """
         base.initialState.setAttribute(LightTransition.getClassType(),
         base.initialState.setAttribute(LightTransition.getClassType(),
@@ -97,16 +113,12 @@ class DirectLights(NodePath):
         else:
         else:
             self.allOn()
             self.allOn()
 
 
-    def setOnNum(self, index):
-        self.setOn(self.lightList[index])
-
-    def setOffNum(self, index):
-        self.setOff(self.lightList[index])
-
-    def setOn(self, light):
-        self.la.setOn(light.upcastToLight())
+    def setOn(self, directLight):
+        """ setOn(directLight) """
+        self.la.setOn(directLight.getLight().upcastToLight())
 
 
-    def setOff(self, light):
-        self.la.setOff(light.upcastToLight())
+    def setOff(self, directLight):
+        """ setOff(directLight)"""
+        self.la.setOff(directLight.getLight().upcastToLight())
 
 
 
 

+ 1 - 1
direct/src/directtools/DirectSelection.py

@@ -256,7 +256,7 @@ class DirectBoundingBox:
 
 
     def computeBounds(self):
     def computeBounds(self):
         self.bounds = self.nodePath.getBounds()
         self.bounds = self.nodePath.getBounds()
-        if self.bounds.isEmpty():
+        if self.bounds.isEmpty() or self.bounds.isInfinite():
             self.center = Point3(0)
             self.center = Point3(0)
             self.radius = 1.0
             self.radius = 1.0
         else:
         else:

+ 8 - 3
direct/src/interval/LerpInterval.py

@@ -23,9 +23,14 @@ class LerpInterval(Interval):
 	if (event == IVAL_INIT):
 	if (event == IVAL_INIT):
 	    self.lerp = Lerp.Lerp(self.functorFunc(), self.duration, 
 	    self.lerp = Lerp.Lerp(self.functorFunc(), self.duration, 
                                   self.blendType)
                                   self.blendType)
-        # Evaluate the lerp if its been created
-        if self.lerp:
-            self.lerp.setT(t)
+        # Make sure lerp exists
+        try:
+            self.lerp
+        except AttributeError:
+	    self.lerp = Lerp.Lerp(self.functorFunc(), self.duration, 
+                                  self.blendType)
+        # Evaluate the lerp
+        self.lerp.setT(t)
 
 
     def getBlend(self, blendType):
     def getBlend(self, blendType):
         """__getBlend(self, string)
         """__getBlend(self, string)

+ 34 - 32
direct/src/tkpanels/DirectSessionPanel.py

@@ -39,7 +39,7 @@ class DirectSessionPanel(AppShell):
         
         
         # Active light
         # Active light
         if len(direct.lights) > 0:
         if len(direct.lights) > 0:
-            name = direct.lights[0].getName()
+            name = direct.lights.getNameList()[0]
             self.lightMenu.selectitem(name)
             self.lightMenu.selectitem(name)
             self.selectLightNamed(name)
             self.selectLightNamed(name)
         else:
         else:
@@ -318,7 +318,7 @@ class DirectSessionPanel(AppShell):
         mainSwitchFrame.pack(fill = X, expand = 0)
         mainSwitchFrame.pack(fill = X, expand = 0)
         
         
         # Widget to select a light to configure
         # Widget to select a light to configure
-        nameList = direct.lights.nameList
+        nameList = direct.lights.getNameList()
         lightMenuFrame = Frame(lightFrame)
         lightMenuFrame = Frame(lightFrame)
         
         
         self.lightMenu = Pmw.ComboBox(
         self.lightMenu = Pmw.ComboBox(
@@ -769,47 +769,47 @@ class DirectSessionPanel(AppShell):
             
             
     # Lights #
     # Lights #
     def selectLightNamed(self, name):
     def selectLightNamed(self, name):
-        self.activeLight = None
-        for light in direct.lights:
-            if name == light.getName():
-                self.activeLight = light
-                break
+        # See if light exists
+        self.activeLight = direct.lights[name]
+        # If not...create new one
         if self.activeLight == None:
         if self.activeLight == None:
             self.activeLight = direct.lights.create(name)
             self.activeLight = direct.lights.create(name)
+        # Do we have a valid light at this point?
         if self.activeLight:
         if self.activeLight:
-            if isinstance(self.activeLight, AmbientLight):
+            light = self.activeLight.getLight()
+            if isinstance(light, AmbientLight):
                 self.lightNotebook.selectpage('Ambient')
                 self.lightNotebook.selectpage('Ambient')
-            elif isinstance(self.activeLight, DirectionalLight):
+            elif isinstance(light, DirectionalLight):
                 self.lightNotebook.selectpage('Directional')
                 self.lightNotebook.selectpage('Directional')
-            elif isinstance(self.activeLight, PointLight):
+            elif isinstance(light, PointLight):
                 self.lightNotebook.selectpage('Point')
                 self.lightNotebook.selectpage('Point')
-            elif isinstance(self.activeLight, Spotlight):
+            elif isinstance(light, Spotlight):
                 self.lightNotebook.selectpage('Spot')
                 self.lightNotebook.selectpage('Spot')
         else:
         else:
             # Restore valid data
             # Restore valid data
             listbox = self.lightMenu.component('scrolledlist')
             listbox = self.lightMenu.component('scrolledlist')
-            listbox.setlist(direct.lights.nameList)
+            listbox.setlist(direct.lights.getNameList())
             if len(direct.lights) > 0:
             if len(direct.lights) > 0:
-                self.lightMenu.selectitem(direct.lights[0].getName())
+                self.lightMenu.selectitem(direct.lights.getNameList()[0])
         # Make sure info is current
         # Make sure info is current
         self.updateLightInfo()
         self.updateLightInfo()
 
 
     def addAmbient(self):
     def addAmbient(self):
-        direct.lights.create('ambient')
+        return direct.lights.create('ambient')
 
 
     def addDirectional(self):
     def addDirectional(self):
-        direct.lights.create('directional')
+        return direct.lights.create('directional')
 
 
     def addPoint(self):
     def addPoint(self):
-        direct.lights.create('point')
+        return direct.lights.create('point')
 
 
     def addSpot(self):
     def addSpot(self):
-        direct.lights.create('spot')
-
+        return direct.lights.create('spot')
+        
     def addLight(self, light):
     def addLight(self, light):
         # Make list reflect current list of lights
         # Make list reflect current list of lights
         listbox = self.lightMenu.component('scrolledlist')
         listbox = self.lightMenu.component('scrolledlist')
-        listbox.setlist(direct.lights.nameList)
+        listbox.setlist(direct.lights.getNameList())
         # Select the newly added light
         # Select the newly added light
         self.lightMenu.selectitem(light.getName())
         self.lightMenu.selectitem(light.getName())
         # And show corresponding page
         # And show corresponding page
@@ -830,33 +830,33 @@ class DirectSessionPanel(AppShell):
 
 
     def setLightColor(self, color):
     def setLightColor(self, color):
         if self.activeLight:
         if self.activeLight:
-            self.activeLight.setColor(Vec4(color[0]/255.0,
-                                           color[1]/255.0,
-                                           color[2]/255.0,
-                                           color[3]/255.0))
+            self.activeLight.getLight().setColor(Vec4(color[0]/255.0,
+                                                      color[1]/255.0,
+                                                      color[2]/255.0,
+                                                      color[3]/255.0))
 
 
     def setSpecularColor(self, color):
     def setSpecularColor(self, color):
         if self.activeLight:
         if self.activeLight:
-            self.activeLight.setSpecular(Vec4(color[0]/255.0,
-                                              color[1]/255.0,
-                                              color[2]/255.0,
-                                              color[3]/255.0))
+            self.activeLight.getLight().setSpecular(Vec4(color[0]/255.0,
+                                                         color[1]/255.0,
+                                                         color[2]/255.0,
+                                                         color[3]/255.0))
 
 
     def setConstantAttenuation(self, value):
     def setConstantAttenuation(self, value):
         if self.activeLight:
         if self.activeLight:
-            self.activeLight.setConstantAttenuation(value)
+            self.activeLight.getLight().setConstantAttenuation(value)
 
 
     def setLinearAttenuation(self, value):
     def setLinearAttenuation(self, value):
         if self.activeLight:
         if self.activeLight:
-            self.activeLight.setLinearAttenuation(value)
+            self.activeLight.getLight().setLinearAttenuation(value)
             
             
     def setQuadraticAttenuation(self, value):
     def setQuadraticAttenuation(self, value):
         if self.activeLight:
         if self.activeLight:
-            self.activeLight.setQuadraticAttenuation(value)
+            self.activeLight.getLight().setQuadraticAttenuation(value)
 
 
     def setExponent(self, value):
     def setExponent(self, value):
         if self.activeLight:
         if self.activeLight:
-            self.activeLight.setExponent(value)
+            self.activeLight.getLight().setExponent(value)
 
 
     ## GRID CONTROLS ##
     ## GRID CONTROLS ##
     def toggleGrid(self):
     def toggleGrid(self):
@@ -908,7 +908,7 @@ class DirectSessionPanel(AppShell):
             base.initialState.hasAttribute(LightTransition.getClassType()))
             base.initialState.hasAttribute(LightTransition.getClassType()))
         # Set light specific info
         # Set light specific info
         if self.activeLight:
         if self.activeLight:
-            l = self.activeLight
+            l = self.activeLight.getLight()
             self.lightActive.set(direct.lights.la.isOn(l))
             self.lightActive.set(direct.lights.la.isOn(l))
             lightColor = l.getColor() * 255.0
             lightColor = l.getColor() * 255.0
             self.lightColor.set([lightColor[0], lightColor[1],
             self.lightColor.set([lightColor[0], lightColor[1],
@@ -983,5 +983,7 @@ class DirectSessionPanel(AppShell):
         
         
     def onDestroy(self, event):
     def onDestroy(self, event):
         # Remove hooks
         # Remove hooks
+        print 'here'
         for event, method in self.actionEvents:
         for event, method in self.actionEvents:
             self.ignore(event)
             self.ignore(event)
+        print 'there'

+ 1 - 2
direct/src/tkwidgets/SceneGraphExplorer.py

@@ -105,8 +105,7 @@ class SceneGraphExplorerItem(TreeItem):
             pass
             pass
 
 
     def GetIconName(self):
     def GetIconName(self):
-        if not self.IsExpandable():
-            return "sphere2" # XXX wish there was a "file" icon
+        return "sphere2" # XXX wish there was a "file" icon
 
 
     def IsExpandable(self):
     def IsExpandable(self):
         return self.nodePath.getNumChildren() != 0
         return self.nodePath.getNumChildren() != 0

+ 1 - 0
direct/src/tkwidgets/Tree.py

@@ -121,6 +121,7 @@ class TreeNode:
 
 
     def popupMenuCommand(self):
     def popupMenuCommand(self):
         self.item.MenuCommand(self.menuList[self.menuVar.get()])
         self.item.MenuCommand(self.menuList[self.menuVar.get()])
+        self.parent.update()
 
 
     def expand(self, event=None):
     def expand(self, event=None):
         if not self.item.IsExpandable():
         if not self.item.IsExpandable():