instantreality forum
news: Welcome to the instantreality forums!
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
April 24, 2018, 01:18:50 pm


Login with username, password and session length


Pages: [1]
  Print  
Author Topic: Exporting Nodes  (Read 1605 times)
FA55
Newbie
*
Posts: 3


View Profile
« on: January 17, 2013, 02:15:52 pm »

Hi,
sorry to get on everyones nerves again.
Is there a possibility to get an XML or vrml-string representation of a whole group object with children and fields? I'm trying to export parts of the scene to an x3d file, but it seems i only can get an xml-representation of the actual node, but without children or fields, so in this case of an empty group node. Is there some nice way to do this i missed or do i have to walk the scenegraph and parse all the data?

Just noticed some other stuff and getting very frustrated with the ecma-scripting of instant. Either i'm too stupid, which i don't want to rule out or there are some bugs:
I'm trying to get all the children of a node:
The  X3D-File looks like this:

<Scene>
    <Group DEF='SaveGroup'>
        <Transform translation='1 1 -10'> 
                <Shape DEF='S1'>
                  <Box DEF='Box1' size= '1 1 1'/>
                  <Appearance>
                        <Material DEF='mat1' diffuseColor='0.5 0.5 0.5'/>
                  </Appearance>
                </Shape>
             <Transform translation='1 2 -10'>
                <Shape DEF='S2'>
                  <Box DEF='Box2' size= '2 2 2'/>
                  <Appearance>
                        <Material DEF='mat2' diffuseColor='0.7 0.5 0.8'/>
                  </Appearance>
                </Shape>
             </Transform>
        </Transform>
        <TouchSensor DEF='ts'/>
    </Group>

    <Script DEF='FileExporter' url=' "scripts/FileExporter.js" ' mustEvaluate='true' directOutput='true'>
        <field accessType='inputOnly' name='isActive' type='SFBool'/>
    </Script>
    <ROUTE fromNode="ts" fromField="isActive" toNode="FileExporter" toField="isActive"/>
  </Scene>

Now i have a FileExporter.js that prints out the nodeStrings to console if i click the group:

function isActive(value){
    if (value == true){
        print("active");
        var node = Browser.currentScene.getNamedNode("SaveGroup");
        var c1=node.getChildren();
        Browser.println(c1.length);
        Browser.println(c1[0].toXMLString());
        Browser.println(c1[1].toXMLString());

the console output is:
active
0
<Transform/>
<TouchSensor DEF='ts'/>

Why is the length of c1 "0" if it has 2 children, which i can both access?
Tested on V2.2 and latest daily build.

If i change the code from "c1=node.getChildren();" to "c1=node.children;" i get the correct length of "2", but now if  i parse a Shape Node, i don't get the geometry and appearance as array elements, because they are not listed under the children-field "children", but under their own fields, which brings me back to getChildren(), but i can't iterate over the result because i get length=0 even if there are existing elements. Seems parsing the Scenegraph and getting all the elements will be next to impossible.

Sorry for the ranting, but very frustrated at the moment. If its my fault, please excuse this thread and i would be incredibly thankful if you could tell me where the mistakes are or show me more efficient ways of doing things, especially exporting nodes with content from IR to file.

Best regards
« Last Edit: January 17, 2013, 03:25:52 pm by FA55 » Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by SMF 1.1.15 | SMF © 2011, Simple Machines