2 # this is the Entity class
4 from PyOSG
import osg
, osgUtil
, osgDB
7 print "Entity class...more documentation to come"
11 def __init__(self
, engine
, specs
):
15 if specs
.has_key('script') and specs
['script'] != []:
17 self
.script
= engine
.readZipfile(specs
['script'])
20 print "Entity.__init__(): Couldn't find/exec script"
22 assert specs
.has_key('contents')
23 self
.name
= specs
['contents']
27 self
.transform
= osg
.PositionAttitudeTransform()
29 if specs
.has_key('model') and specs
['model'] != '':
31 self
.model
= self
.engine
.readNodeFile(specs
['model'])
33 # print "Entity.__init__(): Error loading node file"
37 self
.transform
.addChild(self
.model
)
38 self
.engine
.root
.addChild(self
.transform
)
40 if specs
.has_key('pos'):
42 specs_pos
= eval(specs
['pos'])
43 pos
= osg
.Vec3d(specs_pos
[0],
46 self
.transform
.setPosition(pos
)
48 if specs
.has_key('rot'):
49 specs_rot
= eval(specs
['rot'])
50 rot
= osg
.Quat(specs_rot
[0], specs_rot
[1],
52 self
.transform
.setAttitude(rot
)
54 def draw(self
, engine
):
58 def event(self
, event
, data
):
60 if self
.functions
.has_key(event
):
62 self
.functions
[event
](self
, data
)
64 # print "Entity.event(): Error running event callback"
68 if __name__
== '__main__': main()