Browse Source

lights are now in pgraph

David Rose 24 years ago
parent
commit
21445c50c2

+ 7 - 10
direct/src/directtools/DirectGeometry.py

@@ -1,6 +1,7 @@
 from PandaModules import *
 from PandaModules import *
 from PandaObject import *
 from PandaObject import *
 import math
 import math
+import UsePgraph
 
 
 X_AXIS = Vec3(1,0,0)
 X_AXIS = Vec3(1,0,0)
 Y_AXIS = Vec3(0,1,0)
 Y_AXIS = Vec3(0,1,0)
@@ -46,12 +47,12 @@ class LineNodePath(NodePath):
 
 
     def reset( self ):
     def reset( self ):
         self.lineSegs.reset()
         self.lineSegs.reset()
-        try:
-            # Old-style graph
-            self.lineNode.clear()
-        except:
+        if UsePgraph.use:
             # New-style graph
             # New-style graph
             self.lineNode.removeAllGeoms()
             self.lineNode.removeAllGeoms()
+        else:
+            # Old-style graph
+            self.lineNode.clear()
 
 
     def isEmpty( self ):
     def isEmpty( self ):
         return self.lineSegs.isEmpty()
         return self.lineSegs.isEmpty()
@@ -215,10 +216,6 @@ def relHpr(nodePath, base, h, p, r):
 # Set direct drawing style for an object
 # Set direct drawing style for an object
 # Never light object or draw in wireframe
 # Never light object or draw in wireframe
 def useDirectRenderStyle(nodePath):
 def useDirectRenderStyle(nodePath):
-    try:
-        # Old-style scene graph
-        nodePath.arc().setTransition(LightTransition.allOff())
-    except:
-        # No new-style equivalent yet.
-        pass
+    if UsePgraph.use:
+        nodePath.node().setAttrib(LightAttrib.makeAllOff())
     nodePath.setRenderModeFilled()
     nodePath.setRenderModeFilled()

+ 23 - 24
direct/src/directtools/DirectLights.py

@@ -1,6 +1,7 @@
 from PandaObject import *
 from PandaObject import *
 from DirectGeometry import *
 from DirectGeometry import *
 from string import lower
 from string import lower
+import UsePgraph
 
 
 class DirectLight(NodePath):
 class DirectLight(NodePath):
     def __init__(self, light, parent):
     def __init__(self, light, parent):
@@ -12,15 +13,15 @@ class DirectLight(NodePath):
 
 
         # Upcast the light object to its node base pointer
         # Upcast the light object to its node base pointer
         if isinstance(light, Spotlight):
         if isinstance(light, Spotlight):
-            node = light.upcastToProjectionNode()
+            node = light.upcastToLensNode()
         else:
         else:
-            node = light.upcastToNamedNode()
+            node = light.upcastToPandaNode()
 
 
         # Attach node to self
         # Attach node to self
-        try:
-            self.assign(parent.attachNewNode(none))
-        except:
-            # New scene graph doesn't have lights yet.
+        if UsePgraph.use:
+            self.assign(parent.attachNewNode(node))
+        else:
+            # Old scene graph no longer has lights.
             pass
             pass
 
 
     def getName(self):
     def getName(self):
@@ -37,8 +38,8 @@ class DirectLights(NodePath):
             parent = direct.group
             parent = direct.group
         # Create a node for the lights
         # Create a node for the lights
         self.assign(parent.attachNewNode('DIRECT Lights'))
         self.assign(parent.attachNewNode('DIRECT Lights'))
-        # Create a light transition 
-        self.lt = LightTransition()
+        # Create a light attrib
+        self.la = LightAttrib.makeAllOff()
         # Create a list of all active lights
         # Create a list of all active lights
         self.lightDict = {}
         self.lightDict = {}
         # Counts of the various types of lights
         # Counts of the various types of lights
@@ -108,37 +109,35 @@ class DirectLights(NodePath):
 
 
     def allOn(self):
     def allOn(self):
         """ Turn on all DIRECT lights """
         """ Turn on all DIRECT lights """
-        try:
-            # Old-style scene graph
-            render.arc().setTransition(self.lt)
-        except:
-            # No new-style equivalent yet.
-            pass
+        if UsePgraph.use:
+            # new-style scene graph
+            render.node().setAttrib(self.la)
         # Make sure there is a default material
         # Make sure there is a default material
         render.setMaterial(Material())
         render.setMaterial(Material())
 
 
     def allOff(self):
     def allOff(self):
         """ Turn off all DIRECT lights """
         """ Turn off all DIRECT lights """
-        try:
-            # Old-style scene graph
-            render.arc().clearTransition(LightTransition.getClassType())
-        except:
-            # No new-style equivalent yet.
-            pass
+        if UsePgraph.use:
+            # new-style scene graph
+            render.node().clearAttrib(LightAttrib.getClassType())
 
 
     def toggle(self):
     def toggle(self):
         """ Toggles light attribute, but doesn't toggle individual lights """
         """ Toggles light attribute, but doesn't toggle individual lights """
-        if render.arc().hasTransition(LightTransition.getClassType()):
+        if render.node().hasAttrib(LightAttrib.getClassType()):
             self.allOff()
             self.allOff()
         else:
         else:
             self.allOn()
             self.allOn()
 
 
     def setOn(self, directLight):
     def setOn(self, directLight):
         """ setOn(directLight) """
         """ setOn(directLight) """
-        self.lt.setOn(directLight.getLight())
-
+        self.la = self.la.addLight(directLight.getLight())
+        if render.node().hasAttrib(LightAttrib.getClassType()):
+            render.node().setAttrib(self.la)
+            
     def setOff(self, directLight):
     def setOff(self, directLight):
         """ setOff(directLight)"""
         """ setOff(directLight)"""
-        self.lt.setOff(directLight.getLight())
+        self.la = self.la.removeLight(directLight.getLight())
+        if render.node().hasAttrib(LightAttrib.getClassType()):
+            render.node().setAttrib(self.la)
 
 
 
 

+ 19 - 26
direct/src/tkpanels/DirectSessionPanel.py

@@ -12,6 +12,7 @@ import Slider
 import VectorWidgets
 import VectorWidgets
 import SceneGraphExplorer
 import SceneGraphExplorer
 from TaskManagerPanel import TaskManagerWidget
 from TaskManagerPanel import TaskManagerWidget
+import UsePgraph
 
 
 """
 """
 Possible to add:
 Possible to add:
@@ -837,10 +838,10 @@ class DirectSessionPanel(AppShell):
 
 
     def setSpecularColor(self, color):
     def setSpecularColor(self, color):
         if self.activeLight:
         if self.activeLight:
-            self.activeLight.getLight().setSpecular(Vec4(color[0]/255.0,
-                                                         color[1]/255.0,
-                                                         color[2]/255.0,
-                                                         color[3]/255.0))
+            self.activeLight.getLight().setSpecularColor(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:
@@ -904,51 +905,43 @@ class DirectSessionPanel(AppShell):
 
 
     def updateLightInfo(self, page = None):
     def updateLightInfo(self, page = None):
         # Set main lighting button
         # Set main lighting button
-        try:
-            # Old scene graph interface
+        if UsePgraph.use:
             self.enableLights.set(
             self.enableLights.set(
-                render.arc().hasTransition(LightTransition.getClassType()))
-        except:
-            # No new scene graph equivalent yet
-            self.enableLights.set(0)
+                render.node().hasAttrib(LightAttrib.getClassType()))
             
             
         # Set light specific info
         # Set light specific info
         if self.activeLight:
         if self.activeLight:
             l = self.activeLight.getLight()
             l = self.activeLight.getLight()
-            self.lightActive.set(direct.lights.lt.isOn(l))
+            self.lightActive.set(direct.lights.la.hasLight(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],
                                  lightColor[2], lightColor[3]], 0)
                                  lightColor[2], lightColor[3]], 0)
             if isinstance(l, DirectionalLight):
             if isinstance(l, DirectionalLight):
-                specularColor = l.getSpecular() * 255.0
+                specularColor = l.getSpecularColor() * 255.0
                 self.dSpecularColor.set([specularColor[0],
                 self.dSpecularColor.set([specularColor[0],
                                          specularColor[1],
                                          specularColor[1],
                                          specularColor[2],
                                          specularColor[2],
                                          specularColor[3]], 0)
                                          specularColor[3]], 0)
             elif isinstance(l, PointLight):
             elif isinstance(l, PointLight):
-                specularColor = l.getSpecular() * 255.0
+                specularColor = l.getSpecularColor() * 255.0
                 self.pSpecularColor.set([specularColor[0],
                 self.pSpecularColor.set([specularColor[0],
                                          specularColor[1],
                                          specularColor[1],
                                          specularColor[2],
                                          specularColor[2],
                                          specularColor[3]], 0)
                                          specularColor[3]], 0)
-                constantAtten = l.getConstantAttenuation()
-                self.pConstantAttenuation.set(constantAtten, 0)
-                linearAtten = l.getLinearAttenuation()
-                self.pLinearAttenuation.set(linearAtten, 0)
-                quadraticAtten = l.getQuadraticAttenuation()
-                self.pQuadraticAttenuation.set(quadraticAtten, 0)
+                att = l.getAttenuation()
+                self.pConstantAttenuation.set(att[0], 0)
+                self.pLinearAttenuation.set(att[1], 0)
+                self.pQuadraticAttenuation.set(att[2], 0)
             elif isinstance(l, Spotlight):
             elif isinstance(l, Spotlight):
-                specularColor = l.getSpecular() * 255.0
+                specularColor = l.getSpecularColor() * 255.0
                 self.sSpecularColor.set([specularColor[0],
                 self.sSpecularColor.set([specularColor[0],
                                          specularColor[1],
                                          specularColor[1],
                                          specularColor[2],
                                          specularColor[2],
                                          specularColor[3]], 0)
                                          specularColor[3]], 0)
-                constantAtten = l.getConstantAttenuation()
-                self.sConstantAttenuation.set(constantAtten, 0)
-                linearAtten = l.getLinearAttenuation()
-                self.sLinearAttenuation.set(linearAtten, 0)
-                quadraticAtten = l.getQuadraticAttenuation()
-                self.sQuadraticAttenuation.set(quadraticAtten, 0)
+                att = l.getAttenuation()
+                self.pConstantAttenuation.set(att[0], 0)
+                self.pLinearAttenuation.set(att[1], 0)
+                self.pQuadraticAttenuation.set(att[2], 0)
 
 
     def updateGridInfo(self):
     def updateGridInfo(self):
         self.enableGrid.set(direct.grid.isEnabled())
         self.enableGrid.set(direct.grid.isEnabled())