Parsing vrml into a tree
Mike C. Fletcher
mcfletch at rogers.com
Sat Dec 8 18:04:55 EST 2001
Hmm, there really isn't a built-in mechanism for getting "a plain tree"
of the type you describe. What you get from mcf.vrml is a directed
graph of Node objects (that is, nodes can exist in multiple places
within the tree):
>>> from mcf.vrml import loader
>>> sg = loader.load( r'Z:\worlds\temple\temple.wrl' )
Gives you the graph, which you can walk through fairly easily. The root
node handed back is a sceneGraph Node (or None if the load failed), it's
most interesting attribute is "children", which is the collection of
root nodes in the graph.
>>> sg.children
[<Viewpoint('Camera01'): ['orientation', 'fieldOfView', 'position',
'description']>, <PointLight('Omni01'): ['location', 'radius',
'intensity', 'on', 'color']>, <PointLight('Omni02'): ['location',
'radius', 'intensity', 'on', 'color']>, <NavigationInfo(''):
['headlight']>, <Transform('Dome'): ['translation', 'children']>,
<Transform('BathsTemple'): ['translation', 'children']>,
<Transform('MushroomTemple'): ['translation', 'children']>]
For each node described there, you can walk through dealing with
whatever attributes you need:
>>> sg.children[-1].children[0]
<TimeSensor('MushroomTemple-TIMER'): ['loop', 'cycleInterval']>
>>> sg.children[-1].children[0].loop = 1
If you really wanted to, you could pull out the attributes from the node
objects:
>>> sg.children[-1].children[0].attributeDictionary
{'loop': 1, 'cycleInterval': 3.3330000000000002}
And could then figure out how you want the other information (node type,
DEF name, etceteras) stored in your simple tree.
Hope that helps,
Mike
Joonas Paalasmaa wrote:
> How can I parse vrml into a plain
> tree (dictionary or list) with mcf.vrml?
>
--
_______________________________________
Mike C. Fletcher
http://members.rogers.com/mcfletch/
More information about the Python-list
mailing list