mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-04 02:42:49 -04:00
*** empty log message ***
This commit is contained in:
parent
e2393582ba
commit
11b70c31f2
@ -2,6 +2,23 @@ from PandaObject import *
|
||||
from DirectGeometry import *
|
||||
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):
|
||||
def __init__(self, parent = None):
|
||||
# Initialize the superclass
|
||||
@ -14,73 +31,72 @@ class DirectLights(NodePath):
|
||||
# Create a light attribute
|
||||
self.la = LightAttribute()
|
||||
# Create a list of all active lights
|
||||
self.lightList = []
|
||||
self.nodePathList = []
|
||||
self.nameList = []
|
||||
self.lightDict = {}
|
||||
# Counts of the various types of lights
|
||||
self.ambientCount = 0
|
||||
self.directionalCount = 0
|
||||
self.pointCount = 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):
|
||||
return len(self.lightList)
|
||||
return len(self.lightDict)
|
||||
|
||||
def getLightNodePath(self, index):
|
||||
return self.nodePathList[index]
|
||||
def delete(self, light):
|
||||
del self.lightDict[light.getName()]
|
||||
self.setOff(light)
|
||||
light.removeNode()
|
||||
|
||||
def getLightName(self, index):
|
||||
return self.nameList[index]
|
||||
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):
|
||||
type = type.lower()
|
||||
if type == 'ambient':
|
||||
self.ambientCount += 1
|
||||
light = AmbientLight('ambient_' + `self.ambientCount`)
|
||||
light = AmbientLight('ambient-' + `self.ambientCount`)
|
||||
light.setColor(VBase4(.3,.3,.3,1))
|
||||
elif type == 'directional':
|
||||
self.directionalCount += 1
|
||||
light = DirectionalLight('directional_' + `self.directionalCount`)
|
||||
light = DirectionalLight('directional-' + `self.directionalCount`)
|
||||
light.setColor(VBase4(1))
|
||||
elif type == 'point':
|
||||
self.pointCount += 1
|
||||
light = PointLight('point_' + `self.pointCount`)
|
||||
light = PointLight('point-' + `self.pointCount`)
|
||||
light.setColor(VBase4(1))
|
||||
elif type == 'spot':
|
||||
self.spotCount += 1
|
||||
light = Spotlight('spot_' + `self.spotCount`)
|
||||
light = Spotlight('spot-' + `self.spotCount`)
|
||||
light.setColor(VBase4(1))
|
||||
else:
|
||||
print 'Invalid light type'
|
||||
return None
|
||||
# Add the new light
|
||||
self.addLight(light)
|
||||
directLight = DirectLight(light,self)
|
||||
self.lightDict[directLight.getName()] = directLight
|
||||
# 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 light
|
||||
return directLight
|
||||
|
||||
def createDefaultLights(self):
|
||||
self.create('ambient')
|
||||
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):
|
||||
""" Turn on all DIRECT lights """
|
||||
base.initialState.setAttribute(LightTransition.getClassType(),
|
||||
@ -97,16 +113,12 @@ class DirectLights(NodePath):
|
||||
else:
|
||||
self.allOn()
|
||||
|
||||
def setOnNum(self, index):
|
||||
self.setOn(self.lightList[index])
|
||||
def setOn(self, directLight):
|
||||
""" setOn(directLight) """
|
||||
self.la.setOn(directLight.getLight().upcastToLight())
|
||||
|
||||
def setOffNum(self, index):
|
||||
self.setOff(self.lightList[index])
|
||||
|
||||
def setOn(self, light):
|
||||
self.la.setOn(light.upcastToLight())
|
||||
|
||||
def setOff(self, light):
|
||||
self.la.setOff(light.upcastToLight())
|
||||
def setOff(self, directLight):
|
||||
""" setOff(directLight)"""
|
||||
self.la.setOff(directLight.getLight().upcastToLight())
|
||||
|
||||
|
||||
|
@ -256,7 +256,7 @@ class DirectBoundingBox:
|
||||
|
||||
def computeBounds(self):
|
||||
self.bounds = self.nodePath.getBounds()
|
||||
if self.bounds.isEmpty():
|
||||
if self.bounds.isEmpty() or self.bounds.isInfinite():
|
||||
self.center = Point3(0)
|
||||
self.radius = 1.0
|
||||
else:
|
||||
|
@ -23,9 +23,14 @@ class LerpInterval(Interval):
|
||||
if (event == IVAL_INIT):
|
||||
self.lerp = Lerp.Lerp(self.functorFunc(), self.duration,
|
||||
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):
|
||||
"""__getBlend(self, string)
|
||||
|
@ -39,7 +39,7 @@ class DirectSessionPanel(AppShell):
|
||||
|
||||
# Active light
|
||||
if len(direct.lights) > 0:
|
||||
name = direct.lights[0].getName()
|
||||
name = direct.lights.getNameList()[0]
|
||||
self.lightMenu.selectitem(name)
|
||||
self.selectLightNamed(name)
|
||||
else:
|
||||
@ -318,7 +318,7 @@ class DirectSessionPanel(AppShell):
|
||||
mainSwitchFrame.pack(fill = X, expand = 0)
|
||||
|
||||
# Widget to select a light to configure
|
||||
nameList = direct.lights.nameList
|
||||
nameList = direct.lights.getNameList()
|
||||
lightMenuFrame = Frame(lightFrame)
|
||||
|
||||
self.lightMenu = Pmw.ComboBox(
|
||||
@ -769,47 +769,47 @@ class DirectSessionPanel(AppShell):
|
||||
|
||||
# Lights #
|
||||
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:
|
||||
self.activeLight = direct.lights.create(name)
|
||||
# Do we have a valid light at this point?
|
||||
if self.activeLight:
|
||||
if isinstance(self.activeLight, AmbientLight):
|
||||
light = self.activeLight.getLight()
|
||||
if isinstance(light, AmbientLight):
|
||||
self.lightNotebook.selectpage('Ambient')
|
||||
elif isinstance(self.activeLight, DirectionalLight):
|
||||
elif isinstance(light, DirectionalLight):
|
||||
self.lightNotebook.selectpage('Directional')
|
||||
elif isinstance(self.activeLight, PointLight):
|
||||
elif isinstance(light, PointLight):
|
||||
self.lightNotebook.selectpage('Point')
|
||||
elif isinstance(self.activeLight, Spotlight):
|
||||
elif isinstance(light, Spotlight):
|
||||
self.lightNotebook.selectpage('Spot')
|
||||
else:
|
||||
# Restore valid data
|
||||
listbox = self.lightMenu.component('scrolledlist')
|
||||
listbox.setlist(direct.lights.nameList)
|
||||
listbox.setlist(direct.lights.getNameList())
|
||||
if len(direct.lights) > 0:
|
||||
self.lightMenu.selectitem(direct.lights[0].getName())
|
||||
self.lightMenu.selectitem(direct.lights.getNameList()[0])
|
||||
# Make sure info is current
|
||||
self.updateLightInfo()
|
||||
|
||||
def addAmbient(self):
|
||||
direct.lights.create('ambient')
|
||||
return direct.lights.create('ambient')
|
||||
|
||||
def addDirectional(self):
|
||||
direct.lights.create('directional')
|
||||
return direct.lights.create('directional')
|
||||
|
||||
def addPoint(self):
|
||||
direct.lights.create('point')
|
||||
return direct.lights.create('point')
|
||||
|
||||
def addSpot(self):
|
||||
direct.lights.create('spot')
|
||||
|
||||
return direct.lights.create('spot')
|
||||
|
||||
def addLight(self, light):
|
||||
# Make list reflect current list of lights
|
||||
listbox = self.lightMenu.component('scrolledlist')
|
||||
listbox.setlist(direct.lights.nameList)
|
||||
listbox.setlist(direct.lights.getNameList())
|
||||
# Select the newly added light
|
||||
self.lightMenu.selectitem(light.getName())
|
||||
# And show corresponding page
|
||||
@ -830,33 +830,33 @@ class DirectSessionPanel(AppShell):
|
||||
|
||||
def setLightColor(self, color):
|
||||
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):
|
||||
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):
|
||||
if self.activeLight:
|
||||
self.activeLight.setConstantAttenuation(value)
|
||||
self.activeLight.getLight().setConstantAttenuation(value)
|
||||
|
||||
def setLinearAttenuation(self, value):
|
||||
if self.activeLight:
|
||||
self.activeLight.setLinearAttenuation(value)
|
||||
self.activeLight.getLight().setLinearAttenuation(value)
|
||||
|
||||
def setQuadraticAttenuation(self, value):
|
||||
if self.activeLight:
|
||||
self.activeLight.setQuadraticAttenuation(value)
|
||||
self.activeLight.getLight().setQuadraticAttenuation(value)
|
||||
|
||||
def setExponent(self, value):
|
||||
if self.activeLight:
|
||||
self.activeLight.setExponent(value)
|
||||
self.activeLight.getLight().setExponent(value)
|
||||
|
||||
## GRID CONTROLS ##
|
||||
def toggleGrid(self):
|
||||
@ -908,7 +908,7 @@ class DirectSessionPanel(AppShell):
|
||||
base.initialState.hasAttribute(LightTransition.getClassType()))
|
||||
# Set light specific info
|
||||
if self.activeLight:
|
||||
l = self.activeLight
|
||||
l = self.activeLight.getLight()
|
||||
self.lightActive.set(direct.lights.la.isOn(l))
|
||||
lightColor = l.getColor() * 255.0
|
||||
self.lightColor.set([lightColor[0], lightColor[1],
|
||||
@ -983,5 +983,7 @@ class DirectSessionPanel(AppShell):
|
||||
|
||||
def onDestroy(self, event):
|
||||
# Remove hooks
|
||||
print 'here'
|
||||
for event, method in self.actionEvents:
|
||||
self.ignore(event)
|
||||
print 'there'
|
||||
|
@ -105,8 +105,7 @@ class SceneGraphExplorerItem(TreeItem):
|
||||
pass
|
||||
|
||||
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):
|
||||
return self.nodePath.getNumChildren() != 0
|
||||
|
@ -121,6 +121,7 @@ class TreeNode:
|
||||
|
||||
def popupMenuCommand(self):
|
||||
self.item.MenuCommand(self.menuList[self.menuVar.get()])
|
||||
self.parent.update()
|
||||
|
||||
def expand(self, event=None):
|
||||
if not self.item.IsExpandable():
|
||||
|
Loading…
x
Reference in New Issue
Block a user