[x3d-public] nested proto?

Andreas Plesch andreasplesch at gmail.com
Sat Jul 4 19:22:16 PDT 2020


Hi Joe,

I added the kaleidoscope example to

https://andreasplesch.github.io/x3dom/test/functional/proto/inline.html

It seems to work fine.

There is all kinds of nesting. For example, a harder to implement case
is when a ProtoInstance inside a ProtoBody has an IS connection.

I was also thinking about recursive nesting which is not legal but
would seem to lend itself to define recursive graphics like a Hilbert
curve.

But how would it be possible to stop the recursing into deeper levels,
in declarative x3d without scripting ?

I think the switch statement could do one part. Just give the Proto a
whichChoice field which depends on recursion depth. whichChoice=0
would be the final, actually drawn atomic piece, =1 the composite,
self referential piece.

There still needs to be logic, to increment/decrement a recursion
depth counter to call the nested Proto, and to truncate to 1.

Instead of truncation one could just list say 10 identical
whichChoices, with DEF/USE, a bit ugly but typical declarative style.

Perhaps for decrementing it would work to have a ScalarInterpolator
with key='0, 1' keyvalue='-0.1, 0.9' which is fed back its own
valueChanged. Then an IntegerSequencer could transform that to a
whichChoice. Perhaps it also could do the truncation.

A sketch:
ProtoDeclare name='recursive'
ProtoInterface
  SFVec3f fracDepthIn
  SFNode baseShape
ProtoBody
  Switch DEF='gfx' whichChoice='-1'
    Group DEF='firstChoice'
      baseShape
    Group DEF='secondChoice'
       transform sometransform
         protoinstance DEF='deeper' name='recursive'
           IS nodeField='baseShape' protoField='baseShape'
       transform othertransform
         protoinstance USE='deeper'
  ScalarInterpolator DEF='decreaser' key='0 1' keyValue'-0.2 0.8'
  ROUTE from this.fracDepthIn to decreaser.set_fraction
  ROUTE from decreaser.value_changed to deeper.fracDepthIn
  IntegerSequencer DEF='chooser' key='0 0.2 0.4 0.6 0.8 1.0'
keyValue='0 1 1 1 1 1'
  ROUTE from this.fracDepthIn to chooser.set_fraction
  ROUTE from chooser.value_changed to gfx.whichChoice
  somehow trigger fracDepthIn output event, perhaps with TimeSensor/Interpolator
    IS nodeField=soemField protoField=fracDepthIn

Not quite there yet.








> Date: Sat, 4 Jul 2020 15:40:41 -0700
> From: Joseph D Williams <joedwil at earthlink.net>
> To: X3D Graphics public mailing list <x3d-public at web3d.org>
> Subject: [x3d-public] nested proto?
> Message-ID: <E1jrqpr-00045a-TG at elasmtp-galgo.atl.sa.earthlink.net>
> Content-Type: text/plain; charset="utf-8"
>
>
> I saw a comment about using protos and I must bring this example that show clearly a very useful nesting style gained using this complete ability. Pick your own texture down in the LittleGeode node.
>
> <?xml version="1.0" encoding="UTF-8"?>
> <!DOCTYPE X3D PUBLIC "ISO//Web3D//DTD X3D 3.0//EN" "http://www.web3d.org/specifications/x3d-3.0.dtd">
> <X3D profile='Immersive' >
> <head>
> <meta name='edited' content='joe 1/15/2006'/>
> </head>
> <Scene>
> <WorldInfo
> title='kaleidoscope'
> info='"converted to xml 20061012 last 20100103. mostly from an old wrl originally built by the master of this stuff"'/>
>
> <ProtoDeclare name='Geode'>
> <ProtoInterface>
>   <field name='children' accessType='inputOutput' type='MFNode'/>
> </ProtoInterface>
> <ProtoBody>
>   <Group>
>    <Transform DEF='PartGeode_0'>
>     <IS><connect nodeField='children' protoField='children'/></IS>
>    </Transform>
>    <Transform DEF='PartGeode_1' rotation='0 1.618 1 1.257'>
>     <IS><connect nodeField='children' protoField='children'/></IS>
>    </Transform>
>    <Transform DEF='PartGeode_2' rotation='0 1.618 1 -1.257'>
>      <IS><connect nodeField='children' protoField='children'/></IS>
>    </Transform>
>    <Transform DEF='PartGeode_3' rotation='0 1.618 1 2.513'>
>     <IS><connect nodeField='children' protoField='children'/></IS>
>    </Transform>
>    <Transform DEF='PartGeode_4' rotation='0 1.618 1 -2.513'>
>     <IS><connect nodeField='children' protoField='children'/></IS>
>    </Transform>
>    <Transform DEF='PartGeode_5' rotation='0 1.618 -1 1.257'>
>     <IS><connect nodeField='children' protoField='children'/></IS>
>    </Transform>
>    <Transform DEF='PartGeode_6' rotation='0 1.618 -1 -1.257'>
>     <IS><connect nodeField='children' protoField='children'/></IS>
>    </Transform>
>    <Transform DEF='PartGeode_7' rotation='0 1.618 -1 2.513'>
>     <IS><connect nodeField='children' protoField='children'/></IS>
>    </Transform>
>    <Transform DEF='PartGeode_8' rotation='0 1.618 -1 -2.513'>
>     <IS><connect nodeField='children' protoField='children'/></IS>
>    </Transform>
>    <Transform DEF='PartGeode_9' rotation='1.618 1 0 1.257'>
>     <IS><connect nodeField='children' protoField='children'/></IS>
>    </Transform>
>    <Transform DEF='PartGeode_10' rotation='1.618 1 0 -1.257'>
>     <IS><connect nodeField='children' protoField='children'/></IS>
>    </Transform>
>    <Transform DEF='PartGeode_11' rotation='1.618 1 0 2.513'>
>     <IS><connect nodeField='children' protoField='children'/></IS>
>    </Transform>
>    <Transform DEF='PartGeode_12' rotation='1.618 1 0 -2.513'>
>     <IS><connect nodeField='children' protoField='children'/></IS>
>    </Transform>
>    <Transform DEF='PartGeode_13' rotation='1.618 -1 0 1.257'>
>     <IS><connect nodeField='children' protoField='children'/></IS>
>    </Transform>
>    <Transform DEF='PartGeode_14' rotation='1.618 -1 0 -1.257'>
>     <IS><connect nodeField='children' protoField='children'/></IS>
>    </Transform>
>    <Transform DEF='PartGeode_15' rotation='1.618 -1 0 2.513'>
>     <IS><connect nodeField='children' protoField='children'/></IS>
>    </Transform>
>    <Transform DEF='PartGeode_16' rotation='1.618 -1 0 -2.513'>
>     <IS><connect nodeField='children' protoField='children'/></IS>
>    </Transform>
>    <Transform DEF='PartGeode_17' rotation='1 0 1.618 1.257'>
>     <IS><connect nodeField='children' protoField='children'/></IS>
>    </Transform>
>    <Transform DEF='PartGeode_18' rotation='1 0 1.618 -1.257'>
>     <IS><connect nodeField='children' protoField='children'/></IS>
>    </Transform>
>    <Transform DEF='PartGeode_19' rotation='1 0 1.618 2.513'>
>     <IS><connect nodeField='children' protoField='children'/></IS>
>    </Transform>
>    <Transform DEF='PartGeode_20' rotation='1 0 1.618 -2.513'>
>     <IS><connect nodeField='children' protoField='children'/></IS>
>    </Transform>
>    <Transform DEF='PartGeode_21' rotation='-1 0 1.618 1.257'>
>     <IS><connect nodeField='children' protoField='children'/></IS>
>    </Transform>
>    <Transform DEF='PartGeode_22' rotation='-1 0 1.618 -1.257'>
>     <IS><connect nodeField='children' protoField='children'/></IS>
>    </Transform>
>    <Transform DEF='PartGeode_23' rotation='-1 0 1.618 2.513'>
>     <IS><connect nodeField='children' protoField='children'/></IS>
>    </Transform>
>    <Transform DEF='PartGeode_24' rotation='-1 0 1.618 -2.513'>
>     <IS><connect nodeField='children' protoField='children'/></IS>
>    </Transform>
>    <Transform DEF='PartGeode_25' rotation='.618 1.618 0 2.094'>
>     <IS><connect nodeField='children' protoField='children'/></IS>
>    </Transform>
>    <Transform DEF='PartGeode_26' rotation='.618 1.618 0 -2.094'>
>     <IS><connect nodeField='children' protoField='children'/></IS>
>    </Transform>
>    <Transform DEF='PartGeode_27' rotation='-.618 1.618 0 2.094'>
>     <IS><connect nodeField='children' protoField='children'/></IS>
>    </Transform>
>    <Transform DEF='PartGeode_28' rotation='-.618 1.618 0 -2.094'>
>     <IS><connect nodeField='children' protoField='children'/></IS>
>    </Transform>
>    <Transform DEF='PartGeode_29' rotation='1.618 0 .618 2.094'>
>     <IS><connect nodeField='children' protoField='children'/></IS>
>    </Transform>
>    <Transform DEF='PartGeode_30' rotation='1.618 0 .618 -2.094'>
>     <IS><connect nodeField='children' protoField='children'/></IS>
>    </Transform>
>    <Transform DEF='PartGeode_31' rotation='1.618 0 -.618 2.094'>
>     <IS><connect nodeField='children' protoField='children'/></IS>
>    </Transform>
>    <Transform DEF='PartGeode_32' rotation='1.618 0 -.618 -2.094'>
>     <IS><connect nodeField='children' protoField='children'/></IS>
>    </Transform>
>    <Transform DEF='PartGeode_33' rotation='0 .618 1.618 2.094'>
>     <IS><connect nodeField='children' protoField='children'/></IS>
>    </Transform>
>    <Transform DEF='PartGeode_34' rotation='0 .618 1.618 -2.094'>
>     <IS><connect nodeField='children' protoField='children'/></IS>
>    </Transform>
>    <Transform DEF='PartGeode_35' rotation='0 -.618 1.618 2.094'>
>     <IS><connect nodeField='children' protoField='children'/></IS>
>    </Transform>
>    <Transform DEF='PartGeode_36' rotation='0 -.618 1.618 -2.094'>
>     <IS><connect nodeField='children' protoField='children'/></IS>
>    </Transform>
>    <Transform DEF='PartGeode_37' rotation='1 1 1 2.094'>
>     <IS><connect nodeField='children' protoField='children'/></IS>
>    </Transform>
>    <Transform DEF='PartGeode_38' rotation='1 1 1 -2.094'>
>     <IS><connect nodeField='children' protoField='children'/></IS>
>    </Transform>
>    <Transform DEF='PartGeode_39' rotation='1 -1 1 2.094'>
>     <IS><connect nodeField='children' protoField='children'/></IS>
>    </Transform>
>    <Transform DEF='PartGeode_40' rotation='1 -1 1 -2.094'>
>     <IS><connect nodeField='children' protoField='children'/></IS>
>    </Transform>
>    <Transform DEF='PartGeode_41' rotation='-1 -1 1 2.094'>
>     <IS><connect nodeField='children' protoField='children'/></IS>
>    </Transform>
>    <Transform DEF='PartGeode_42' rotation='-1 -1 1 -2.094'>
>     <IS><connect nodeField='children' protoField='children'/></IS>
>    </Transform>
>    <Transform DEF='PartGeode_43' rotation='-1 1 1 2.094'>
>     <IS><connect nodeField='children' protoField='children'/></IS>
>    </Transform>
>    <Transform DEF='PartGeode_44' rotation='-1 1 1 -2.094'>
>     <IS><connect nodeField='children' protoField='children'/></IS>
>    </Transform>
>    <Transform DEF='PartGeode_45' rotation='1 0 0 3.142'>
>     <IS><connect nodeField='children' protoField='children'/></IS>
>    </Transform>
>    <Transform DEF='PartGeode_46' rotation='0 1 0 3.142'>
>     <IS><connect nodeField='children' protoField='children'/></IS>
>    </Transform>
>    <Transform DEF='PartGeode_47' rotation='0 0 1 3.142'>
>     <IS><connect nodeField='children' protoField='children'/></IS>
>    </Transform>
>    <Transform DEF='PartGeode_48' rotation='1 1.618 2.618 3.142'>
>     <IS><connect nodeField='children' protoField='children'/></IS>
>    </Transform>
>    <Transform DEF='PartGeode_49' rotation='-1 1.618 2.618 3.142'>
>     <IS><connect nodeField='children' protoField='children'/></IS>
>    </Transform>
>    <Transform DEF='PartGeode_50' rotation='1 -1.618 2.618 3.142'>
>     <IS><connect nodeField='children' protoField='children'/></IS>
>    </Transform>
>    <Transform DEF='PartGeode_51' rotation='-1 -1.618 2.618 3.142'>
>     <IS><connect nodeField='children' protoField='children'/></IS>
>    </Transform>
>    <Transform DEF='PartGeode_52' rotation='2.618 1 1.618 3.142'>
>     <IS><connect nodeField='children' protoField='children'/></IS>
>    </Transform>
>    <Transform DEF='PartGeode_53' rotation='2.618 -1 1.618 3.142'>
>     <IS><connect nodeField='children' protoField='children'/></IS>
>    </Transform>
>    <Transform DEF='PartGeode_54' rotation='2.618 1 -1.618 3.142'>
>     <IS><connect nodeField='children' protoField='children'/></IS>
>    </Transform>
>    <Transform DEF='PartGeode_55' rotation='2.618 -1 -1.618 3.142'>
>     <IS><connect nodeField='children' protoField='children'/></IS>
>    </Transform>
>    <Transform DEF='PartGeode_56' rotation='1.618 2.618 1 3.142'>
>     <IS><connect nodeField='children' protoField='children'/></IS>
>    </Transform>
>    <Transform DEF='PartGeode_57' rotation='1.618 2.618 -1 3.142'>
>     <IS><connect nodeField='children' protoField='children'/></IS>
>    </Transform>
>    <Transform DEF='PartGeode_58' rotation='-1.618 2.618 1 3.142'>
>     <IS><connect nodeField='children' protoField='children'/></IS>
>    </Transform>
>    <Transform DEF='PartGeode_59' rotation='-1.618 2.618 -1 3.142'>
>     <IS><connect nodeField='children' protoField='children'/></IS>
>    </Transform>
>   </Group>
> </ProtoBody>
> </ProtoDeclare>
>
> <ProtoDeclare name='Triangle'>
> <ProtoInterface/>
> <ProtoBody>
>  <Group>
>    <Transform DEF='LittleGeode'>
>     <Shape>
>      <Appearance>
>       <ImageTexture url='"buddapalmstrike.png"'/>
>       <TextureTransform DEF='TextureTransform0' center='0 1'/>
>      </Appearance>
>      <IndexedFaceSet solid='false' creaseAngle='0.524'
>       coordIndex='
>         0 1 2 -1
>         0 2 3 -1'
>       texCoordIndex='
>         0 1 2 -1
>         0 2 1 -1'>
>       <Coordinate DEF='COORD0'
>        point='
>         0 1 0
>         0 0.85065 0.52573
>         0.35682 0.93417 0
>         0 0.85065 -0.52573'/>
>       <TextureCoordinate DEF='TEX_COORD0'
>        point='
>         0 0
>         1 0
>         0 1'/>
>      </IndexedFaceSet>
>     </Shape>
>    </Transform>
>     <Transform DEF='BigGeode' scale='100.3 100.3 100.3'>
>       <Shape USE='LittleGeode' />
>    </Transform>
>   </Group>
>
>   <TimeSensor DEF='TS_TextRot' cycleInterval='133.0' loop='true'/>
>   <ScalarInterpolator DEF='TextRotInterp'
>    key='0 0.25 0.5 0.75 1'
>    keyValue='0 1.57 3.14 4.71 6.28'/>
>   <ROUTE fromNode='TS_TextRot' fromField='fraction_changed' toNode='TextRotInterp' toField='set_fraction'/>
>   <ROUTE fromNode='TextRotInterp' fromField='value_changed' toNode='TextureTransform0' toField='set_rotation'/>
>
> </ProtoBody>
> </ProtoDeclare>
>
> <Group DEF='3Dkscope'>
> <NavigationInfo avatarSize='.25 1.6 .75' visibilityLimit='0'
>   speed='1' headlight='false' type='"FLY" "ANY"'/>
>
> <ProtoInstance containerField='children' name='Geode'>
>   <fieldValue name='children'>
>    <ProtoInstance DEF='PartGeode' name='Triangle'/>
>   </fieldValue>
> </ProtoInstance>
>
> <Transform DEF='Camera_yaw'>
>   <Viewpoint DEF='Camera_pitch' description='Moving Camera1'
>    jump='false' fieldOfView='0.785'
>    position='0 0 10' orientation='0 0 1 0'/>
> </Transform>
>
> <TimeSensor DEF='TS_Camera_yaw' cycleInterval='60.000' loop='true' startTime='-1.000'/>
> <OrientationInterpolator DEF='OI_Camera_yaw'
>   key=' 0 .25 .5 .75 1'
>   keyValue='
>   0 1 0 0
>   0 1 0 1.57
>   0 1 0 3.14
>   0 1 0 4.71
>   0 1 0 6.28'/>
>
> <TimeSensor DEF='TS_Camera_pos' cycleInterval='55.000' loop='true' startTime='-1.000'/>
> <PositionInterpolator DEF='PI_Camera_pos'
>   key='0 .35 .5 .65 1'
>   keyValue='
>   0 0 90
>   0 1 45
>   0 2 6
>   0 1 45
>   0 0 90'/>
>
> <TimeSensor DEF='TS_Camera_pitch' cycleInterval='125.000' loop='true' startTime='-1.000'/>
> <OrientationInterpolator DEF='OI_Camera_pitch'
>   key='0 .25 .5 .75 1'
>   keyValue='
>   1 0 0 0
>   1 0 0 1.57
>   1 0 0 3.14
>   1 0 0 4.71
>   1 0 0 6.28'/>
>
> <Viewpoint description='Close View'
>   jump='true' fieldOfView='0.785' position='0 0 4' orientation='0 1 0 .525'/>
> <Viewpoint description='Close View 2'
>   jump='true' fieldOfView='0.785'
>   position='0 0 4' orientation='0 0 1 0'/>
> <Transform DEF='Camera_yaw1'>
>   <Viewpoint DEF='Camera_pitch0' description='Orbiting Camera'
>    jump='false' fieldOfView='0.785' position='0 0 5' orientation='0 0 1 0'/>
> </Transform>
>
> <TimeSensor DEF='TS_Camera_yaw1' cycleInterval='23.000' loop='true' startTime='-1.000'/>
> <OrientationInterpolator DEF='OI_Camera_yaw1'
>   key='0 .25 .5 .75 1'
>   keyValue='
>   0 1 0 0
>   0 1 0 1.57
>   0 1 0 3.14
>   0 1 0 4.71
>   0 1 0 6.28'/>
>
> <Viewpoint description='Far View' jump='true'
>   fieldOfView='0.785' position='0 0 100' orientation='0 0 1 0'/>
> <Viewpoint description='Outside View'
>   jump='true' fieldOfView='0.785' position='0 0 125' orientation='0 1 0 0'/>
> </Group>
>
>
> <TimeSensor DEF='vizx_init' cycleInterval='0.100' loop='true'/>
> <ROUTE fromNode='vizx_init' fromField='cycleTime' toNode='TS_Camera_yaw' toField='startTime'/>
> <ROUTE fromNode='vizx_init' fromField='cycleTime' toNode='TS_Camera_pos' toField='startTime'/>
> <ROUTE fromNode='vizx_init' fromField='cycleTime' toNode='TS_Camera_pitch' toField='startTime'/>
> <ROUTE fromNode='vizx_init' fromField='cycleTime' toNode='TS_Camera_yaw1' toField='startTime'/>
> <ROUTE fromNode='vizx_init' fromField='cycleTime' toNode='vizx_init' toField='stopTime'/>
>
> <ROUTE fromNode='TS_Camera_pitch' fromField='fraction_changed' toNode='OI_Camera_pitch' toField='set_fraction'/>
> <ROUTE fromNode='OI_Camera_pitch' fromField='value_changed' toNode='Camera_pitch' toField='set_orientation'/>
> <ROUTE fromNode='TS_Camera_pos' fromField='fraction_changed' toNode='PI_Camera_pos' toField='set_fraction'/>
> <ROUTE fromNode='PI_Camera_pos' fromField='value_changed' toNode='Camera_pitch' toField='set_position'/>
> <ROUTE fromNode='TS_Camera_yaw' fromField='fraction_changed' toNode='OI_Camera_yaw' toField='set_fraction'/>
> <ROUTE fromNode='OI_Camera_yaw' fromField='value_changed' toNode='Camera_yaw' toField='set_rotation'/>
> <ROUTE fromNode='TS_Camera_yaw1' fromField='fraction_changed' toNode='OI_Camera_yaw1' toField='set_fraction'/>
> <ROUTE fromNode='OI_Camera_yaw1' fromField='value_changed' toNode='Camera_yaw1' toField='set_rotation'/>
>
> </Scene>
> </X3D>
>
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: <http://web3d.org/pipermail/x3d-public_web3d.org/attachments/20200704/6cfb0351/attachment.html>
>
> ------------------------------
>
> Subject: Digest Footer
>
> _______________________________________________
> x3d-public mailing list
> x3d-public at web3d.org
> http://web3d.org/mailman/listinfo/x3d-public_web3d.org
>
>
> ------------------------------
>
> End of x3d-public Digest, Vol 136, Issue 11
> *******************************************



--
Andreas Plesch
Waltham, MA 02453



More information about the x3d-public mailing list