... I " /> ... I " /> ... I "/>

SFNode field in Proto

28 views Asked by At

I've got these DEFs in my X3D file:

    <ImageTexture DEF="texture1" URL="some/image1.png" />
    ...
    <ImageTexture DEF="texture2" URL="some/image2.png" />

I wish to USE these in my ProtoInstances so that I don't have to create a texture node for each (with the corresponding http request for each), by referencing them by name in one of the proto fiels. Something like this:

    <ProtoDeclare name="myProto">
        <ProtoInterface>
            <field name="texture" type="SFString" accessType="initializeOnly" />
        </ProtoInterface>
        <ProtoBody>
            ...
            <!-- obviously this doesn't work, but you get the idea: -->
            <ImageTexture USE="${texture}" />
            ...
        </ProtoBody>
    </ProtoDeclare>
    
    ...

    <ProtoInstance name="myProto">
        <FieldValue name="texture" value="texture1" />
    </ProtoInstance>

I have tried with IS within the proto set to the one already defined, but it doesn't work for me:

    <ProtoDeclare name="myProto">
        <ProtoInterface>
            <field name="texture" type="SFNode" accessType="initializeOnly" />
        </ProtoInterface>
        <ProtoBody>
            ...
            <Appearance>
                <IS><connect nodeField="texture" protoField="texture"/></IS>
            </Appearance>
            ...
        </ProtoBody>
    </ProtoDeclare>
    
    ...

    <ProtoInstance name="myProto">
        <FieldValue name="texture">
            <ImageTexture USE="texture1" />
        </FieldValue>
    </ProtoInstance>

I have also tried with a Script, but cannot find a way to make the link.

Any ideas are very welcome. Thanks!

1

There are 1 answers

0
h3f3st0 On

The IS solution does work. My problem was a different one. The url of my textures was not properly written. Texture url is a MFString, so I had to enclose the value in additional single quotes, like this:

<ImageTexture DEF="texture1" URL='"some/image1.png"' />
...
<ImageTexture DEF="texture2" URL='"some/image2.png"' />

Note that at least in my case, with X_ITE as the browser, using quotes the other way round (double quotes around single quotes) did not work.