Scenegraph
From DreamsteepWiki
THE GRAPH
class data_graph():
nodes =[]
##
def listnodes(self):
#print self.nodes
for node in self.nodes:
print node.name
##
def add(self,node):
#check node health
self.nodes.append(node)
##
def setattribute(self,node,attr,data):
found=0
for foonode in self.nodes:
if foonode.name == node:
#print 'NODE FOUND'
#print node
foonode.ATTRS = data
print foonode.ATTRS
found=1
if found==0:
print 'ERROR NOT FOUND '
##
def getattribute(self,node,attr):
found = 0
has = node.hasattrib(attr)
print has
#if found==0:
# print 'ERROR NOT FOUND '
THE NODE
"""
2D LAYER or 3D SCENEGRAPH , BOTH ACTUALLY
attempt to make a graph and node data tree system with 2 inputs per node
attempt to genericaly define a scenegraph , or composite
"""
class node_base (object):
#USE OVERLOADING TO DEAL WITH MULTIPLE TYPES
ATTRS =[]
VALUES =[] #table for attr values , indexed the same NEED TYPE str, long ...etc
#SHAPES =[] maya specific derive later instead
#isconnected inputone etc
name = ''
inputone = ''
inputtwo = ''
output = ''
##..##..##..##
posx = 0
posy = 0
posz = 0
rotx = 0
roty = 0
rotz = 0
##..##..##..##
def __init__(self,nam):
self.name = nam
##
def addattrib (self,attrname):
self.ATTRS.append(attrname)
##
def listattrib (self):
print self.ATTRS#DEBUG
return self.ATTRS
def hasattrib (self,attrname):
has = 0
for attr in self.ATTRS:
#print 'DEBUG '
#print attr
if attr ==attrname:
has =1
def listinputs(self,one,two):
out = []
out.append(self.inputone)
out.append(self.inputtwo)
print out #debug
return out
def setinputs(self,one,two):
self.inputone = one
#set isconnected
self.inputone = two
#set isconnected
def setoutput(self,one,two):
self.inputone = one
self.inputone = two
#translations are optional
def xform(self,fbt):
self.posx = fbt[0]
self.posx = fbt[1]
self.posx = fbt[2]
def rotate(self,fbt):
self.rotx = fbt[0]
self.roty = fbt[1]
self.rotz = fbt[2]
HOW TO USE IT
#MAKE A GRAPH
scenegraph = data_graph()
#MAKE 3 NODES AND ADD TO GRAPH
node1 = node_base('a')
node2 = node_base('b')
node3 = node_base('c')
scenegraph.add(node1)
scenegraph.add(node2)
scenegraph.add(node3)
#list all nodes
#scenegraph.listnodes()
#add an attribute to a node
node2.addattrib('sparky')
node2.addattrib('buttplug')
#list all node attributes
#node2.listattrib()
#get attributes from a node
#scenegraph.getattribute(node2,'sparky')

