[x3d-public] metadata for ProtoInstance

John Carlson yottzumm at gmail.com
Sat Jun 6 12:24:53 PDT 2020


Here's more useful code for converting Script to script:

https://github.com/coderextreme/X3DJSONLD/blob/51da0f0213084ab6511a22d8b0caf6a4fb957de8/src/main/node/Script.js#L671

John

On Sat, Jun 6, 2020 at 1:44 PM John Carlson <yottzumm at gmail.com> wrote:

> I think the primary things one can do is create a new tag, <x3dscript> is
> okay with me.  I believe we should solve ROUTE between proto and script
> first-- just implement very basic scripts, set and value_changed, ...
>
> Note that when I went exploring in this direction, I discovered HTML DOM
> scripting could not contain fields?  I was trying to create a script node
> of some kind.  Thus when I was implementing scripts, I had to provide DOM
> functions for set and get.
>
> You may find this function (rename to x3dom of course) very useful!
> (requires JQuery for now)
>
> X3DJSON.nodeUtil = function(selector, node, field, value) {
>                 if (typeof selector === 'undefined') {
>                         selector = '';
>                 } else {
>                         selector = selector+' ';
>                 }
>                 selector = selector+"[DEF='"+node+"']";
>                 var element = document.querySelector(selector);
>                 if (element === null) {
>                         console.error('unDEFed node', node, selector);
>                 } else if (arguments.length > 3) {
>                         /*
>                         if (value && typeof value.toString === 'function')
> {
>                                 value = value.toString();
>                         }
>                         $(selector).attr(field, value);
>                         // console.log('set', node, '.', field, '=',
> value);
>                         */
>                         try {
>                                 if (typeof element.setFieldValue ===
> 'function')
>  {
>                                         element.setFieldValue(field,
> value);
>                                 } else {
>                                         element.setAttribute(field, value);
>                                 }
>                         } catch (e) {
>                                 console.log(e);
>                         }
>                         return element;
>                 } else if (arguments.length > 2) {
>                         if (typeof element.getFieldValue === 'function') {
>                                 value = element.getFieldValue(field);
>                         } else {
>                                 value = element.getAttribute(field);
>                         }
>                         /*
>                         if (element &&
>                                 element._x3domNode &&
>                                 element._x3domNode._vf &&
>                                 element._x3domNode._vf[field] &&
>
> element._x3domNode._vf[field].setValueByStr) {
>                                 value =
> element._x3domNode._vf[field].setValueByStr(value);
>                         }
>                         */
>                         // console.log('get', node, '.', field,'=',value);
>                         return value;
>                 } else if (arguments.length > 0) {
>                         return $(selector)[0];
>                 } else {
>                         return;
>                 }
> };
>
> John
>
> On Sat, Jun 6, 2020 at 1:06 PM Don Brutzman <brutzman at nps.edu> wrote:
>
>> [possible Web3D 2020 participant gift: skateboard bumperstickers that say
>> "X3D Prototypes Are Not A Crime"]
>>
>> 8)
>>
>> On 6/5/2020 12:45 PM, Andreas Plesch wrote:
>> > Indeed,
>> >
>> >
>> https://savage.nps.edu/Savage/Tools/Animation/DoubleClickTouchSensorPrototypeIndex.html
>> >
>> > shows that pattern of allowing metadata for a ProtoInstance. Perhaps
>> > the exposed metadata field should be populated in the example
>> > ProtoInstance as well.
>>
>> Sounds good, thank you.  Excerpt follows, checked in and validated.
>>
>>      <ProtoDeclare appinfo='DoubleClickTouchSensor functionality
>> activates when user double clicks (or double selects) within
>> maxDelayInterval' name='DoubleClickTouchSensor'>
>>        <ProtoInterface>
>>          <field accessType='inputOutput' appinfo='describe the purpose of
>> this sensor' name='description' type='SFString'/>
>>          <field accessType='initializeOnly' appinfo='seconds'
>> name='maxDelayInterval' type='SFTime' value='0.5'/>
>>          <field accessType='inputOutput' name='enabled' type='SFBool'
>> value='true'/>
>>          <field accessType='outputOnly' name='isActive' type='SFBool'/>
>>          <field accessType='outputOnly' name='isOver' type='SFBool'/>
>>          <field accessType='outputOnly' appinfo='seconds'
>> name='touchTime' type='SFTime'/>
>>          <field accessType='outputOnly' name='hitPoint_changed'
>> type='SFVec3f'/>
>>          <field accessType='outputOnly' name='hitNormal_changed'
>> type='SFVec3f'/>
>>          <field accessType='outputOnly' name='hitTexCoord_changed'
>> type='SFVec2f'/>
>>          <field accessType='initializeOnly' name='metadata' type='SFNode'
>> appinfo='can contain one of Metadata nodes'>
>>            <!-- initialization node (if any) goes here -->
>>          </field>
>>          <field accessType='initializeOnly' name='traceEnabled'
>> type='SFBool' value='false'/>
>>        </ProtoInterface>
>> ...
>>
>>      <ExternProtoDeclare appinfo='DoubleClickTouchSensor functionality
>> activates when user double clicks (or double selects) within
>> maxDelayInterval' name='DoubleClickTouchSensor'
>> url='"DoubleClickTouchSensorPrototype.x3d#DoubleClickTouchSensor"
>> "../../../Savage/Tools/Animation/DoubleClickTouchSensorPrototype.x3d#DoubleClickTouchSensor"
>> "
>> https://savage.nps.edu/Savage/Tools/Animation/DoubleClickTouchSensorPrototype.x3d#DoubleClickTouchSensor"
>> "DoubleClickTouchSensorPrototype.wrl#DoubleClickTouchSensor"
>> "../../../Savage/Tools/Animation/DoubleClickTouchSensorPrototype.wrl#DoubleClickTouchSensor"
>> "
>> https://savage.nps.edu/Savage/Tools/Animation/DoubleClickTouchSensorPrototype.wrl#DoubleClickTouchSensor
>> "'>
>>        <field accessType='inputOutput' appinfo='describe the purpose of
>> this sensor' name='description' type='SFString'/>
>>        <field accessType='initializeOnly' appinfo='seconds'
>> name='maxDelayInterval' type='SFTime'/>
>>        <field accessType='inputOutput' name='enabled' type='SFBool'/>
>>        <field accessType='outputOnly' name='isActive' type='SFBool'/>
>>        <field accessType='outputOnly' name='isOver' type='SFBool'/>
>>        <field accessType='outputOnly' appinfo='seconds' name='touchTime'
>> type='SFTime'/>
>>        <field accessType='outputOnly' name='hitPoint_changed'
>> type='SFVec3f'/>
>>        <field accessType='outputOnly' name='hitNormal_changed'
>> type='SFVec3f'/>
>>        <field accessType='outputOnly' name='hitTexCoord_changed'
>> type='SFVec2f'/>
>>        <field accessType='initializeOnly' name='metadata' type='SFNode'
>> appinfo='can contain one of Metadata nodes'>
>>            <!-- initialization node (if any) goes here -->
>>        </field>
>>        <field accessType='initializeOnly' name='traceEnabled'
>> type='SFBool'/>
>>      </ExternProtoDeclare>
>> ...
>>
>>        <ProtoInstance DEF='TouchSensorActive'
>> name='DoubleClickTouchSensor'>
>>          <fieldValue name='description' value='double click to initiate
>> time delay and color change'/>
>>          <fieldValue name='traceEnabled' value='true'/>
>>          <fieldValue name='metadata'>
>>              <MetadataString name="exampleTerm" value='"exampleValue"'/>
>>          </fieldValue>
>>        </ProtoInstance>
>>
>> This design pattern seemed too specialized to add to X3D Tooltips, but I
>> have added an entry with links to
>>
>> * X3D Scene Authoring Hints, Inline Scenes and Prototype Templates
>>
>> https://www.web3d.org/x3d/content/examples/X3dSceneAuthoringHints.html#Inlines
>>
>> "If an author wants a ProtoInstance node to contain metadata like other
>> X3D nodes, then first add a metadata field to the defining ProtoDeclere.
>> For an example, see DoubleClickTouchSensorPrototype and
>> DoubleClickTouchSensorExample."
>>
>> > Authors should consider ProtoInstance as a node in the scenegraph.
>> > Does that indicate that the spec. also should consider ProtoInstance
>> > more formally as a node, rather than a statement ? The SAI efforts, I
>> > think, already do that. It would be a node which is dynamically
>> > defined as it derives its definition from the named Protodeclaration.
>> > So instead of treating it as something to be replaced/expanded, it
>> > would be stay in the scenegraph and reference the Protodeclaration.
>>
>>  From a 'specification parlance' perspective, ProtoDeclare
>> ExternProtoDeclare ProtoInstance (PROTO EXTERNPROTO [someName] ) are
>> statements.
>>
>>  From a practical perspective, an instantiated ProtoInstance is a node
>> (or node subtree) in the scene graph.
>>
>> In X3DJSAIL some creativity was needed, class ProtoInstanceObject
>> indrectly implements X3DChildNode (and thus X3DNode) with the following
>> signature:
>>
>>         public class ProtoInstanceObject extends X3DConcreteNode
>> implements ProtoInstance
>>
>> *
>> https://www.web3d.org/specifications/java/javadoc/org/web3d/x3d/jsail/Core/ProtoInstanceObject.html
>>
>> The specification prose seems pretty thorough about all these ins &
>> outs... no doubt you've seen it.
>>
>> * X3D Architecture, 4.4.4 Prototype semantics
>>
>> https://www.web3d.org/documents/specifications/19775-1/V3.3/Part01/concepts.html#PrototypeSemantics
>>
>> For anybody, questions or potential spec clarifications are always
>> welcome.
>>
>> > To be honest, I am a bit worried that if Proto's should become
>> > available for x3dom, there will be unnecessary management of
>> > expectations, mostly with regards to scripting. So strategically, it
>> > will be best to first figure out if it is possible to reproduce
>> > scripted prototype behaviours with dom scripts, and only then release
>> > more widely.
>> >
>> > -Andreas
>>
>> Understood, please implement/rollout as you think best.  Each will be a
>> major advance for X3DOM.  Suggest getting prototypes out without scripting
>> is a good incremental achievement; acknowledged that many prototype
>> declarations include scripting for advanced capabilities.
>>
>> Looking ahead in that direction...
>>
>> I've always thought that a <Script> within a <Scene> within a root <X3D>
>> ought to be pretty easy to distinguish from a HTML Script.  However I
>> haven't actually tried to do that in any DOM programming.  MIght be an
>> issue if the page is some kinda tag soup (which HTML allows, I think).
>>
>> If you want to experiment with <X3dScript> as a synonym, that might be an
>> interesting experiment.  If it seems necessary then we could write that up
>> in the forthcoming X3D4 section for X3D-HTML.  Similarly we might consider
>> implications of using <X3DCanvas> (as X_ITE does) when scene graph is
>> external to the HTML page.
>>
>> We're having fun now... Thanks Andreas!
>>
>> > On Fri, Jun 5, 2020 at 9:54 AM Don Brutzman <brutzman at nps.edu> wrote:
>> >>
>> >> Great question about metadata in a protoinstance... i believe that
>> your deduction is correct and that we have some examples.  here are some:
>>
>> p.s. it took me a heckuva lot longer (weeks maybe) than the few hours you
>> apparently needed to figure that one out - very impressive!!  8)
>>
>> >> [1] X3D Example Archives: Savage, Tools, Animation, Flying Text
>> Prototype
>> >>
>> https://savage.nps.edu/Savage/Tools/Animation/FlyingTextPrototypeIndex.html
>> >>
>> >> [2] X3D Example Archives: Savage, Tools, Animation, Flying Text Example
>> >>
>> https://savage.nps.edu/Savage/Tools/Animation/FlyingTextExampleIndex.html
>> >>
>> >> <field name='metadata' type='SFNode' accessType='initializeOnly'/>
>> >>
>> >> [3] X3D Example Archives: Savage, Tools, Animation, Double Click Touch
>> Sensor Prototype
>> >>
>> https://savage.nps.edu/Savage/Tools/Animation/DoubleClickTouchSensorPrototypeIndex.html
>> >>
>> >> <field name='metadata' type='SFNode' accessType='initializeOnly'>
>> >>       <!-- initialization node (if any) goes here -->
>> >> </field>
>> >>
>> >> [4] X3D Example Archives: Savage, Tools, Animation, Double Click Touch
>> Sensor Example
>> >>
>> https://savage.nps.edu/Savage/Tools/Animation/DoubleClickTouchSensorExampleIndex.html
>> >>
>> >> Authors should definitely consider a ProtoInstance as a node in the
>> scene graph.
>> >>
>> >> btw i fixed a small error in x3d.py for serializing out typed values
>> found in field/fieldValue declarations, wrapping str() around the value
>> being written out.  planning to deploy an x3d.py at the end of the weekend,
>> hopefully.
>> >>
>> >> Finally, i expend demand for ProtoInstance to shoot way up as people
>> understand it and as X3DOM matches support found in other key
>> implementations (InstantReality, X_ITE, Xj3D, others).  Will be happy for
>> the community to check compliance all around, especially if you and John
>> Carlson et al. are successful in finally bringing it to X3DOM some day.
>> >>
>> >> Prototypes are a fundamental part of the "X" in X3D.  Onward we go...
>> >>
>> >> On 6/4/2020 3:36 PM, Andreas Plesch wrote:
>> >>> I realized that the way to add metadata to a protoinstance is expose a
>> >>> metadata field in the protodeclaration. I think that answers my
>> >>> question.
>> >>>
>> >>> -Andreas
>> >>>
>> >>> On Thu, Jun 4, 2020 at 3:31 PM Andreas Plesch <
>> andreasplesch at gmail.com> wrote:
>> >>>>
>> >>>> I think a ProtoInstance currently cannot have its own, instance
>> >>>> specific metadata node since it is a statement rather than a node.
>> >>>>
>> >>>> Is that correct ?
>> >>>>
>> >>>> If so, it does not seem to be much of an issue since there does not
>> >>>> seem to be much demand for it. But everything else can have
>> associated
>> >>>> metadata, so should a ProtoInstance not have this ability as well ?
>> >>>>
>> >>>> -Andreas
>>
>> all the best, Don
>> --
>> Don Brutzman  Naval Postgraduate School, Code USW/Br
>> brutzman at nps.edu
>> Watkins 270,  MOVES Institute, Monterey CA 93943-5000 USA
>>  +1.831.656.2149
>> X3D graphics, virtual worlds, navy robotics
>> http://faculty.nps.edu/brutzman
>>
>> _______________________________________________
>> x3d-public mailing list
>> x3d-public at web3d.org
>> http://web3d.org/mailman/listinfo/x3d-public_web3d.org
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://web3d.org/pipermail/x3d-public_web3d.org/attachments/20200606/9ac55b71/attachment-0001.html>


More information about the x3d-public mailing list