x3d import and export nodes from inline url

2019-09-04 09:05发布

问题:

I need to get access to nodes from an inline x3d file in a parent x3d file. For example, say we have a room model as an x3d file. We populate this room with several chairs. We use the inline url to populate room.x3d with several chair.x3d files. We've got something like this inside the room.x3d file to place chairs:

<Transform DEF = 'Chair'
        translation = '0 0 0'
        scale = '1 1 1'
        rotation='-0.600546 0.600546 90 0'>
        <Inline DEF ='chr' url = 'Chair.x3d' />
    </Transform>

Now, I need to get access to a few nodes within Chair.x3d to manipulate the scene. I have read about IMPORT and EXPORT and how they are used to get nodes from an inline url, however I have not found a good working example yet. I've looked at this:

http://www.web3d.org/x3d/content/examples/Basic/development/_pages/page27.html

But it does not seem to work.

I've also read this:

http://www.web3d.org/files/specifications/19775-1/V3.2/Part01/components/networking.html

But the syntax is VRML as opposed to x3d.

If anyone could give me a quick example of how to use IMPORT and EXPORT and how to route the nodes from the inline url so I can send it events, etc. it would be greatly appreciated. Let me know if I'm not being clear enough.

回答1:

This works for me: Source FILE of X3D object ( a brown cylinder):

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE X3D PUBLIC "ISO//Web3D//DTD X3D 3.0//EN" .stuff..>
<X3D profile='Interchange' version='3.0'
    xmlns:xsd='http://www.w3.org/2001/XMLSchema-instance' ..stuff..>
<Scene>
<Transform DEF='XFER_OBJECT'>
    <Shape> 
        <Cylinder radius='1' height='1'/> 
        <Appearance> 
            <Material diffuseColor='.9 .3 .3'/> 
        </Appearance>
    </Shape> 
</Transform>
<Export localDEF='XFER_OBJECT' as='Cyl'/>
</Scene>
</X3D>

and the url/import code in my xhtml file:

<Transform translation='2 0 0' >
    <Inline DEF='objectBrnCyl' url='"test33.x3d"' />
</Transform>
<IMPORT InlineDEF='objectBrnCyl' exportDEF='Cyl' as='brnCyl'/>

Haven't finished case testing the commands yet -- the documentation is a little spooky.