[x3d-public] loading DOM VRML Script. Cobweb enhancement?

Andreas Plesch andreasplesch at gmail.com
Sun Dec 4 12:31:38 PST 2016


Hi John,

I looked at the
http://www.web3d.org/x3d/content/examples/Basic/ScriptConformance/TouchSensorIsOverEventECMAScript.json
example.

The problem is that X3DJSONLD turns the script node into a DOM node with
correct field node children but the script text is contained in raw text
nodes:

<field>
<field>
#text "<![CDATA["
#text "ecmascript:function isOver(val) {     if (val == true)     {
diffuseColor_changed = new SFColor(1,0,0);     }     else     {
diffuseColor_changed = new SFColor(0,0,1);    }}"
#text "]]>"

The script text should be contained in the nodeValue/textContent of a
CDATASection :

<field>
<field>
CDATASection nodeValue=textContent="ecmascript:function isOver(val) {
if (val == true)     {         diffuseColor_changed = new
SFColor(1,0,0);     }     else     {         diffuseColor_changed = new
SFColor(0,0,1);    }}"

https://developer.mozilla.org/en-US/docs/Web/API/Document/createCDATASection

However, createCDATASection only works with xhtml.

I am sneaking a CDATASection into a html document using DOMParser in xml
mode here:

https://github.com/andreasplesch/cobweb_dom/blob/master/cobweb/cobweb_dom.js#L34

I think DOMParser.parseFromString("<![CDATA[ scripttext using > and < ]]>",
'application/xml'); should return a document with a single cdatasection
node which then can be appended to the script node.

https://github.com/coderextreme/X3DJSONLD/blob/master/X3DJSONLD.js#L224

looks like the function where an actual CDATASection node needs to be
created instead of raw text nodes.

Hope this helps,

Andreas

On Sun, Dec 4, 2016 at 1:42 PM, Andreas Plesch <andreasplesch at gmail.com>
wrote:

> Hi John,
>
> X3dom is designed to work with the XML encoding or a dom. So for x3dom it
> would be necessary to first create a DOM from the json. It will be
> difficult to get around that.
>
> Cobweb has parsers which parse XML or vrml into a scene graph. So it
> should be possible to make a parser for json, probably following what the
> XML parser does. But the easier path would be also to create a DOM from the
> json first.
>
> How do you envision you or others would use json encoded x3d content to
> add value to a project ? Easier manipulation as a js object ? Easier
> programmatic content creation ? As an exchange/transmission format, a bit
> similar to gltf ?
>
>
> http://www.web3d.org/x3d/content/examples/Basic/ScriptConformance/
>
> has good examples to test scripting. For example,
>
> http://www.web3d.org/x3d/content/examples/Basic/ScriptConformance/
> TouchSensorIsOverEventECMAScriptIndex.html
>
> http://www.web3d.org/x3d/content/examples/Basic/ScriptConformance/
> TouchSensorIsOverEventECMAScript.json
>
> I may give this example a try with the json loader and cobweb.
>
> -Andreas
>
> On Dec 4, 2016 1:49 AM, "John Carlson" <yottzumm at gmail.com> wrote:
>
>> Perhaps it's time for me to dig into Cobweb and X3DOM to see how they can
>> be extended to support JSON?  If it's through DOM, which is fine by me, I
>> would have to look and see how the various encodings are loaded after DOM
>> is loaded.
>>
>> On Dec 4, 2016 1:40 AM, "John Carlson" <yottzumm at gmail.com> wrote:
>>
>>> Again, the X3D JSON Loader is a proof of concept patch until we get full
>>> JSON support in Cobweb and X3DOM, if desired.
>>>
>>> On Dec 4, 2016 1:24 AM, "John Carlson" <yottzumm at gmail.com> wrote:
>>>
>>>> Because I may not have the full x3d examples downloaded.   And I do
>>>> want to test to see if JSON inclusion works.
>>>>
>>>> On Dec 2, 2016 3:04 PM, "Andreas Plesch" <andreasplesch at gmail.com>
>>>> wrote:
>>>>
>>>>> Hi John,
>>>>>
>>>>> I tried a bit to load gears.json with X3DJSONLD:
>>>>>
>>>>> https://raw.githubusercontent.com/andreasplesch/X3DJSONLD/ma
>>>>> ster/AP_minimal_JSLD.html
>>>>>
>>>>> But even before any script parsing/loading, there is a problem
>>>>> with the ExternProtoDeclare node in gears.json. It has a url field to
>>>>> Rotor.x3d which is replaced by the json loader with Rotor.json before being
>>>>> handed off to cobweb with importDocument(). Cobweb does not know what to do
>>>>> with the Rotor.json file and gives up.
>>>>>
>>>>> Why modify the url field value ? If the scene author wants to use a
>>>>> .json encoded scene, she will put it in  the url field just like a .wrl
>>>>> encoded scene.
>>>>>
>>>>> On another note, I agree that eval() cannot be avoided if script
>>>>> should be supported. cobweb itself also uses eval() (after some setup and
>>>>> massaging) to run the x3d script.
>>>>>
>>>>> type="application/x-vrmlscript" is necessary because without it the
>>>>> web browser will try to run the script "as is" as soon as it gets appended
>>>>> to the page DOM. When cobweb gets a chance to check for the type attribute,
>>>>> it is already too late. So it cannot use the attribute to prevent it from
>>>>> running. It can only not reject it which is what it does.
>>>>>
>>>>> -Andreas
>>>>>
>>>>>
>>>>> On Thu, Dec 1, 2016 at 1:02 AM, <yottzumm at gmail.com> wrote:
>>>>>
>>>>>> It appears that Cobweb is fouled up with DOM loading of scripts, even
>>>>>> with the additional name value pair.  See gears.x3d/gears.json and load DOM
>>>>>> through importDocument.  And independent test would help.  I am not sure
>>>>>> which of my X3DCanvases gets loaded first and I am using absolute indexing,
>>>>>> so it could be the XML loaded one that is failing.  Basically, we need a
>>>>>> good way to load scripts coming in through JSON I think, and the only real
>>>>>> way I know how to do it is eval or cobweb with JSON to XML conversion and
>>>>>> VRMLscript.  If Cobweb could use the VRMLscript from JSON or DOM, that
>>>>>> might be ideal.
>>>>>>
>>>>>>
>>>>>>
>>>>>> This is with cobweb 2.4.
>>>>>>
>>>>>>
>>>>>>
>>>>>> John
>>>>>>
>>>>>>
>>>>>>
>>>>>> Sent from Mail <https://go.microsoft.com/fwlink/?LinkId=550986> for
>>>>>> Windows 10
>>>>>>
>>>>>>
>>>>>>
>>>>>> *From: *yottzumm at gmail.com
>>>>>> *Sent: *Thursday, December 1, 2016 12:32 AM
>>>>>> *To: *Andreas Plesch <andreasplesch at gmail.com>; Don Brutzman
>>>>>> <brutzman at nps.edu>; Roy Walmsley <roy.walmsley at ntlworld.com>
>>>>>> *Subject: *FW: loading X3D DOM. Latest Cobweb techniques?
>>>>>>
>>>>>>
>>>>>>
>>>>>> Would it be possible to get a name/value of
>>>>>>
>>>>>>
>>>>>>
>>>>>> "@type" : "application/x-vrmlscript"
>>>>>>
>>>>>>
>>>>>>
>>>>>> On the Script tag in X3D JSON?  I will do some testing here first to
>>>>>> see if it will help.
>>>>>>
>>>>>>
>>>>>>
>>>>>> John
>>>>>>
>>>>>>
>>>>>>
>>>>>> *From: *yottzumm at gmail.com
>>>>>> *Sent: *Thursday, December 1, 2016 12:24 AM
>>>>>> *To: *Andreas Plesch <andreasplesch at gmail.com>
>>>>>> *Subject: *RE: loading X3D DOM. Latest Cobweb techniques?
>>>>>>
>>>>>>
>>>>>>
>>>>>> One thing I noticed once I got both DOM and XML views loaded, was
>>>>>> that I think the DOM VRML script tag was disabled, but the XML one worked.
>>>>>> Was there some attribute to add to the Script tag to make it work?  Can I
>>>>>> add it in both XML and DOM?  Thanks, John  I will start email search.
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> Andreas Plesch
>>>>> 39 Barbara Rd.
>>>>> Waltham, MA 02453
>>>>>
>>>>


-- 
Andreas Plesch
39 Barbara Rd.
Waltham, MA 02453
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://web3d.org/pipermail/x3d-public_web3d.org/attachments/20161204/5991245c/attachment.html>


More information about the x3d-public mailing list