<div dir="ltr">Here's more useful code for converting Script to script:<div><br></div><div><a href="https://github.com/coderextreme/X3DJSONLD/blob/51da0f0213084ab6511a22d8b0caf6a4fb957de8/src/main/node/Script.js#L671">https://github.com/coderextreme/X3DJSONLD/blob/51da0f0213084ab6511a22d8b0caf6a4fb957de8/src/main/node/Script.js#L671</a><br></div><div><br></div><div>John</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, Jun 6, 2020 at 1:44 PM John Carlson <<a href="mailto:yottzumm@gmail.com">yottzumm@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">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, ...<div><br></div><div>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.</div><div><br></div><div>You may find this function (rename to x3dom of course) very useful! (requires JQuery for now)</div><div><br></div><div>X3DJSON.nodeUtil = function(selector, node, field, value) {<br> if (typeof selector === 'undefined') {<br> selector = '';<br> } else {<br> selector = selector+' ';<br> }<br> selector = selector+"[DEF='"+node+"']";<br> var element = document.querySelector(selector);<br> if (element === null) {<br> console.error('unDEFed node', node, selector);<br> } else if (arguments.length > 3) {<br> /*<br> if (value && typeof value.toString === 'function') {<br> value = value.toString();<br> }<br> $(selector).attr(field, value);<br> // console.log('set', node, '.', field, '=', value);<br> */<br> try {<br> if (typeof element.setFieldValue === 'function')<br> {<br> element.setFieldValue(field, value);<br> } else {<br> element.setAttribute(field, value);<br> }<br> } catch (e) {<br> console.log(e);<br> }<br> return element;<br> } else if (arguments.length > 2) {<br> if (typeof element.getFieldValue === 'function') {<br> value = element.getFieldValue(field);<br> } else {<br> value = element.getAttribute(field);<br> }<br> /*<br> if (element &&<br> element._x3domNode &&<br> element._x3domNode._vf &&<br> element._x3domNode._vf[field] &&<br> element._x3domNode._vf[field].setValueByStr) {<br> value = element._x3domNode._vf[field].setValueByStr(value);<br> }<br> */<br> // console.log('get', node, '.', field,'=',value);<br> return value;<br> } else if (arguments.length > 0) {<br> return $(selector)[0];<br> } else {<br> return;<br> }<br>};<br></div><div><br></div><div>John</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, Jun 6, 2020 at 1:06 PM Don Brutzman <<a href="mailto:brutzman@nps.edu" target="_blank">brutzman@nps.edu</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">[possible Web3D 2020 participant gift: skateboard bumperstickers that say "X3D Prototypes Are Not A Crime"]<br>
<br>
8)<br>
<br>
On 6/5/2020 12:45 PM, Andreas Plesch wrote:<br>
> Indeed,<br>
> <br>
> <a href="https://savage.nps.edu/Savage/Tools/Animation/DoubleClickTouchSensorPrototypeIndex.html" rel="noreferrer" target="_blank">https://savage.nps.edu/Savage/Tools/Animation/DoubleClickTouchSensorPrototypeIndex.html</a><br>
> <br>
> shows that pattern of allowing metadata for a ProtoInstance. Perhaps<br>
> the exposed metadata field should be populated in the example<br>
> ProtoInstance as well.<br>
<br>
Sounds good, thank you. Excerpt follows, checked in and validated.<br>
<br>
<ProtoDeclare appinfo='DoubleClickTouchSensor functionality activates when user double clicks (or double selects) within maxDelayInterval' name='DoubleClickTouchSensor'><br>
<ProtoInterface><br>
<field accessType='inputOutput' appinfo='describe the purpose of this sensor' name='description' type='SFString'/><br>
<field accessType='initializeOnly' appinfo='seconds' name='maxDelayInterval' type='SFTime' value='0.5'/><br>
<field accessType='inputOutput' name='enabled' type='SFBool' value='true'/><br>
<field accessType='outputOnly' name='isActive' type='SFBool'/><br>
<field accessType='outputOnly' name='isOver' type='SFBool'/><br>
<field accessType='outputOnly' appinfo='seconds' name='touchTime' type='SFTime'/><br>
<field accessType='outputOnly' name='hitPoint_changed' type='SFVec3f'/><br>
<field accessType='outputOnly' name='hitNormal_changed' type='SFVec3f'/><br>
<field accessType='outputOnly' name='hitTexCoord_changed' type='SFVec2f'/><br>
<field accessType='initializeOnly' name='metadata' type='SFNode' appinfo='can contain one of Metadata nodes'><br>
<!-- initialization node (if any) goes here --><br>
</field><br>
<field accessType='initializeOnly' name='traceEnabled' type='SFBool' value='false'/><br>
</ProtoInterface><br>
...<br>
<br>
<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" "<a href="https://savage.nps.edu/Savage/Tools/Animation/DoubleClickTouchSensorPrototype.x3d#DoubleClickTouchSensor" rel="noreferrer" target="_blank">https://savage.nps.edu/Savage/Tools/Animation/DoubleClickTouchSensorPrototype.x3d#DoubleClickTouchSensor</a>" "DoubleClickTouchSensorPrototype.wrl#DoubleClickTouchSensor" "../../../Savage/Tools/Animation/DoubleClickTouchSensorPrototype.wrl#DoubleClickTouchSensor" "<a href="https://savage.nps.edu/Savage/Tools/Animation/DoubleClickTouchSensorPrototype.wrl#DoubleClickTouchSensor" rel="noreferrer" target="_blank">https://savage.nps.edu/Savage/Tools/Animation/DoubleClickTouchSensorPrototype.wrl#DoubleClickTouchSensor</a>"'><br>
<field accessType='inputOutput' appinfo='describe the purpose of this sensor' name='description' type='SFString'/><br>
<field accessType='initializeOnly' appinfo='seconds' name='maxDelayInterval' type='SFTime'/><br>
<field accessType='inputOutput' name='enabled' type='SFBool'/><br>
<field accessType='outputOnly' name='isActive' type='SFBool'/><br>
<field accessType='outputOnly' name='isOver' type='SFBool'/><br>
<field accessType='outputOnly' appinfo='seconds' name='touchTime' type='SFTime'/><br>
<field accessType='outputOnly' name='hitPoint_changed' type='SFVec3f'/><br>
<field accessType='outputOnly' name='hitNormal_changed' type='SFVec3f'/><br>
<field accessType='outputOnly' name='hitTexCoord_changed' type='SFVec2f'/><br>
<field accessType='initializeOnly' name='metadata' type='SFNode' appinfo='can contain one of Metadata nodes'><br>
<!-- initialization node (if any) goes here --><br>
</field><br>
<field accessType='initializeOnly' name='traceEnabled' type='SFBool'/><br>
</ExternProtoDeclare><br>
...<br>
<br>
<ProtoInstance DEF='TouchSensorActive' name='DoubleClickTouchSensor'><br>
<fieldValue name='description' value='double click to initiate time delay and color change'/><br>
<fieldValue name='traceEnabled' value='true'/><br>
<fieldValue name='metadata'><br>
<MetadataString name="exampleTerm" value='"exampleValue"'/><br>
</fieldValue><br>
</ProtoInstance><br>
<br>
This design pattern seemed too specialized to add to X3D Tooltips, but I have added an entry with links to<br>
<br>
* X3D Scene Authoring Hints, Inline Scenes and Prototype Templates<br>
<a href="https://www.web3d.org/x3d/content/examples/X3dSceneAuthoringHints.html#Inlines" rel="noreferrer" target="_blank">https://www.web3d.org/x3d/content/examples/X3dSceneAuthoringHints.html#Inlines</a><br>
<br>
"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."<br>
<br>
> Authors should consider ProtoInstance as a node in the scenegraph.<br>
> Does that indicate that the spec. also should consider ProtoInstance<br>
> more formally as a node, rather than a statement ? The SAI efforts, I<br>
> think, already do that. It would be a node which is dynamically<br>
> defined as it derives its definition from the named Protodeclaration.<br>
> So instead of treating it as something to be replaced/expanded, it<br>
> would be stay in the scenegraph and reference the Protodeclaration.<br>
<br>
From a 'specification parlance' perspective, ProtoDeclare ExternProtoDeclare ProtoInstance (PROTO EXTERNPROTO [someName] ) are statements.<br>
<br>
From a practical perspective, an instantiated ProtoInstance is a node (or node subtree) in the scene graph.<br>
<br>
In X3DJSAIL some creativity was needed, class ProtoInstanceObject indrectly implements X3DChildNode (and thus X3DNode) with the following signature:<br>
<br>
public class ProtoInstanceObject extends X3DConcreteNode implements ProtoInstance<br>
<br>
* <a href="https://www.web3d.org/specifications/java/javadoc/org/web3d/x3d/jsail/Core/ProtoInstanceObject.html" rel="noreferrer" target="_blank">https://www.web3d.org/specifications/java/javadoc/org/web3d/x3d/jsail/Core/ProtoInstanceObject.html</a><br>
<br>
The specification prose seems pretty thorough about all these ins & outs... no doubt you've seen it.<br>
<br>
* X3D Architecture, 4.4.4 Prototype semantics<br>
<a href="https://www.web3d.org/documents/specifications/19775-1/V3.3/Part01/concepts.html#PrototypeSemantics" rel="noreferrer" target="_blank">https://www.web3d.org/documents/specifications/19775-1/V3.3/Part01/concepts.html#PrototypeSemantics</a><br>
<br>
For anybody, questions or potential spec clarifications are always welcome.<br>
<br>
> To be honest, I am a bit worried that if Proto's should become<br>
> available for x3dom, there will be unnecessary management of<br>
> expectations, mostly with regards to scripting. So strategically, it<br>
> will be best to first figure out if it is possible to reproduce<br>
> scripted prototype behaviours with dom scripts, and only then release<br>
> more widely.<br>
> <br>
> -Andreas<br>
<br>
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.<br>
<br>
Looking ahead in that direction...<br>
<br>
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).<br>
<br>
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.<br>
<br>
We're having fun now... Thanks Andreas!<br>
<br>
> On Fri, Jun 5, 2020 at 9:54 AM Don Brutzman <<a href="mailto:brutzman@nps.edu" target="_blank">brutzman@nps.edu</a>> wrote:<br>
>><br>
>> Great question about metadata in a protoinstance... i believe that your deduction is correct and that we have some examples. here are some:<br>
<br>
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)<br>
<br>
>> [1] X3D Example Archives: Savage, Tools, Animation, Flying Text Prototype<br>
>> <a href="https://savage.nps.edu/Savage/Tools/Animation/FlyingTextPrototypeIndex.html" rel="noreferrer" target="_blank">https://savage.nps.edu/Savage/Tools/Animation/FlyingTextPrototypeIndex.html</a><br>
>><br>
>> [2] X3D Example Archives: Savage, Tools, Animation, Flying Text Example<br>
>> <a href="https://savage.nps.edu/Savage/Tools/Animation/FlyingTextExampleIndex.html" rel="noreferrer" target="_blank">https://savage.nps.edu/Savage/Tools/Animation/FlyingTextExampleIndex.html</a><br>
>><br>
>> <field name='metadata' type='SFNode' accessType='initializeOnly'/><br>
>><br>
>> [3] X3D Example Archives: Savage, Tools, Animation, Double Click Touch Sensor Prototype<br>
>> <a href="https://savage.nps.edu/Savage/Tools/Animation/DoubleClickTouchSensorPrototypeIndex.html" rel="noreferrer" target="_blank">https://savage.nps.edu/Savage/Tools/Animation/DoubleClickTouchSensorPrototypeIndex.html</a><br>
>><br>
>> <field name='metadata' type='SFNode' accessType='initializeOnly'><br>
>> <!-- initialization node (if any) goes here --><br>
>> </field><br>
>><br>
>> [4] X3D Example Archives: Savage, Tools, Animation, Double Click Touch Sensor Example<br>
>> <a href="https://savage.nps.edu/Savage/Tools/Animation/DoubleClickTouchSensorExampleIndex.html" rel="noreferrer" target="_blank">https://savage.nps.edu/Savage/Tools/Animation/DoubleClickTouchSensorExampleIndex.html</a><br>
>><br>
>> Authors should definitely consider a ProtoInstance as a node in the scene graph.<br>
>><br>
>> 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.<br>
>><br>
>> 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.<br>
>><br>
>> Prototypes are a fundamental part of the "X" in X3D. Onward we go...<br>
>><br>
>> On 6/4/2020 3:36 PM, Andreas Plesch wrote:<br>
>>> I realized that the way to add metadata to a protoinstance is expose a<br>
>>> metadata field in the protodeclaration. I think that answers my<br>
>>> question.<br>
>>><br>
>>> -Andreas<br>
>>><br>
>>> On Thu, Jun 4, 2020 at 3:31 PM Andreas Plesch <<a href="mailto:andreasplesch@gmail.com" target="_blank">andreasplesch@gmail.com</a>> wrote:<br>
>>>><br>
>>>> I think a ProtoInstance currently cannot have its own, instance<br>
>>>> specific metadata node since it is a statement rather than a node.<br>
>>>><br>
>>>> Is that correct ?<br>
>>>><br>
>>>> If so, it does not seem to be much of an issue since there does not<br>
>>>> seem to be much demand for it. But everything else can have associated<br>
>>>> metadata, so should a ProtoInstance not have this ability as well ?<br>
>>>><br>
>>>> -Andreas<br>
<br>
all the best, Don<br>
-- <br>
Don Brutzman Naval Postgraduate School, Code USW/Br <a href="mailto:brutzman@nps.edu" target="_blank">brutzman@nps.edu</a><br>
Watkins 270, MOVES Institute, Monterey CA 93943-5000 USA +1.831.656.2149<br>
X3D graphics, virtual worlds, navy robotics <a href="http://faculty.nps.edu/brutzman" rel="noreferrer" target="_blank">http://faculty.nps.edu/brutzman</a><br>
<br>
_______________________________________________<br>
x3d-public mailing list<br>
<a href="mailto:x3d-public@web3d.org" target="_blank">x3d-public@web3d.org</a><br>
<a href="http://web3d.org/mailman/listinfo/x3d-public_web3d.org" rel="noreferrer" target="_blank">http://web3d.org/mailman/listinfo/x3d-public_web3d.org</a><br>
</blockquote></div>
</blockquote></div>