mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-04 19:08:55 -04:00
lights are now in pgraph
This commit is contained in:
parent
4e6dd4a6bf
commit
21445c50c2
@ -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:
|
if UsePgraph.use:
|
||||||
# Old-style graph
|
|
||||||
self.lineNode.clear()
|
|
||||||
except:
|
|
||||||
# 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:
|
if UsePgraph.use:
|
||||||
# Old-style scene graph
|
nodePath.node().setAttrib(LightAttrib.makeAllOff())
|
||||||
nodePath.arc().setTransition(LightTransition.allOff())
|
|
||||||
except:
|
|
||||||
# No new-style equivalent yet.
|
|
||||||
pass
|
|
||||||
nodePath.setRenderModeFilled()
|
nodePath.setRenderModeFilled()
|
||||||
|
@ -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:
|
if UsePgraph.use:
|
||||||
self.assign(parent.attachNewNode(none))
|
self.assign(parent.attachNewNode(node))
|
||||||
except:
|
else:
|
||||||
# New scene graph doesn't have lights yet.
|
# 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
|
# Create a light attrib
|
||||||
self.lt = LightTransition()
|
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:
|
if UsePgraph.use:
|
||||||
# Old-style scene graph
|
# new-style scene graph
|
||||||
render.arc().setTransition(self.lt)
|
render.node().setAttrib(self.la)
|
||||||
except:
|
|
||||||
# No new-style equivalent yet.
|
|
||||||
pass
|
|
||||||
# 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:
|
if UsePgraph.use:
|
||||||
# Old-style scene graph
|
# new-style scene graph
|
||||||
render.arc().clearTransition(LightTransition.getClassType())
|
render.node().clearAttrib(LightAttrib.getClassType())
|
||||||
except:
|
|
||||||
# No new-style equivalent yet.
|
|
||||||
pass
|
|
||||||
|
|
||||||
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)
|
||||||
|
|
||||||
|
|
||||||
|
@ -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,7 +838,7 @@ 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,
|
self.activeLight.getLight().setSpecularColor(Vec4(color[0]/255.0,
|
||||||
color[1]/255.0,
|
color[1]/255.0,
|
||||||
color[2]/255.0,
|
color[2]/255.0,
|
||||||
color[3]/255.0))
|
color[3]/255.0))
|
||||||
@ -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:
|
if UsePgraph.use:
|
||||||
# Old scene graph interface
|
|
||||||
self.enableLights.set(
|
self.enableLights.set(
|
||||||
render.arc().hasTransition(LightTransition.getClassType()))
|
render.node().hasAttrib(LightAttrib.getClassType()))
|
||||||
except:
|
|
||||||
# No new scene graph equivalent yet
|
|
||||||
self.enableLights.set(0)
|
|
||||||
|
|
||||||
# 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()
|
att = l.getAttenuation()
|
||||||
self.pConstantAttenuation.set(constantAtten, 0)
|
self.pConstantAttenuation.set(att[0], 0)
|
||||||
linearAtten = l.getLinearAttenuation()
|
self.pLinearAttenuation.set(att[1], 0)
|
||||||
self.pLinearAttenuation.set(linearAtten, 0)
|
self.pQuadraticAttenuation.set(att[2], 0)
|
||||||
quadraticAtten = l.getQuadraticAttenuation()
|
|
||||||
self.pQuadraticAttenuation.set(quadraticAtten, 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()
|
att = l.getAttenuation()
|
||||||
self.sConstantAttenuation.set(constantAtten, 0)
|
self.pConstantAttenuation.set(att[0], 0)
|
||||||
linearAtten = l.getLinearAttenuation()
|
self.pLinearAttenuation.set(att[1], 0)
|
||||||
self.sLinearAttenuation.set(linearAtten, 0)
|
self.pQuadraticAttenuation.set(att[2], 0)
|
||||||
quadraticAtten = l.getQuadraticAttenuation()
|
|
||||||
self.sQuadraticAttenuation.set(quadraticAtten, 0)
|
|
||||||
|
|
||||||
def updateGridInfo(self):
|
def updateGridInfo(self):
|
||||||
self.enableGrid.set(direct.grid.isEnabled())
|
self.enableGrid.set(direct.grid.isEnabled())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user