diff --git a/direct/src/directtools/DirectGeometry.py b/direct/src/directtools/DirectGeometry.py index 0d0130171c..bb8d206010 100644 --- a/direct/src/directtools/DirectGeometry.py +++ b/direct/src/directtools/DirectGeometry.py @@ -1,6 +1,7 @@ from PandaModules import * from PandaObject import * import math +import UsePgraph X_AXIS = Vec3(1,0,0) Y_AXIS = Vec3(0,1,0) @@ -46,12 +47,12 @@ class LineNodePath(NodePath): def reset( self ): self.lineSegs.reset() - try: - # Old-style graph - self.lineNode.clear() - except: + if UsePgraph.use: # New-style graph self.lineNode.removeAllGeoms() + else: + # Old-style graph + self.lineNode.clear() def isEmpty( self ): return self.lineSegs.isEmpty() @@ -215,10 +216,6 @@ def relHpr(nodePath, base, h, p, r): # Set direct drawing style for an object # Never light object or draw in wireframe 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() diff --git a/direct/src/directtools/DirectLights.py b/direct/src/directtools/DirectLights.py index cc00608bf3..539c15b837 100644 --- a/direct/src/directtools/DirectLights.py +++ b/direct/src/directtools/DirectLights.py @@ -1,6 +1,7 @@ from PandaObject import * from DirectGeometry import * from string import lower +import UsePgraph class DirectLight(NodePath): def __init__(self, light, parent): @@ -12,15 +13,15 @@ class DirectLight(NodePath): # Upcast the light object to its node base pointer if isinstance(light, Spotlight): - node = light.upcastToProjectionNode() + node = light.upcastToLensNode() else: - node = light.upcastToNamedNode() + node = light.upcastToPandaNode() # 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 def getName(self): @@ -37,8 +38,8 @@ class DirectLights(NodePath): parent = direct.group # Create a node for the 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 self.lightDict = {} # Counts of the various types of lights @@ -108,37 +109,35 @@ class DirectLights(NodePath): def allOn(self): """ 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 render.setMaterial(Material()) def allOff(self): """ 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): """ Toggles light attribute, but doesn't toggle individual lights """ - if render.arc().hasTransition(LightTransition.getClassType()): + if render.node().hasAttrib(LightAttrib.getClassType()): self.allOff() else: self.allOn() def setOn(self, 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): """ 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) diff --git a/direct/src/tkpanels/DirectSessionPanel.py b/direct/src/tkpanels/DirectSessionPanel.py index 2cd9860081..9f2baf114a 100644 --- a/direct/src/tkpanels/DirectSessionPanel.py +++ b/direct/src/tkpanels/DirectSessionPanel.py @@ -12,6 +12,7 @@ import Slider import VectorWidgets import SceneGraphExplorer from TaskManagerPanel import TaskManagerWidget +import UsePgraph """ Possible to add: @@ -837,10 +838,10 @@ class DirectSessionPanel(AppShell): def setSpecularColor(self, color): 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): if self.activeLight: @@ -904,51 +905,43 @@ class DirectSessionPanel(AppShell): def updateLightInfo(self, page = None): # Set main lighting button - try: - # Old scene graph interface + if UsePgraph.use: 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 if self.activeLight: 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 self.lightColor.set([lightColor[0], lightColor[1], lightColor[2], lightColor[3]], 0) if isinstance(l, DirectionalLight): - specularColor = l.getSpecular() * 255.0 + specularColor = l.getSpecularColor() * 255.0 self.dSpecularColor.set([specularColor[0], specularColor[1], specularColor[2], specularColor[3]], 0) elif isinstance(l, PointLight): - specularColor = l.getSpecular() * 255.0 + specularColor = l.getSpecularColor() * 255.0 self.pSpecularColor.set([specularColor[0], specularColor[1], specularColor[2], 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): - specularColor = l.getSpecular() * 255.0 + specularColor = l.getSpecularColor() * 255.0 self.sSpecularColor.set([specularColor[0], specularColor[1], specularColor[2], 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): self.enableGrid.set(direct.grid.isEnabled())