[x3d-public] ECMAScript 6 X3D API

John Carlson yottzumm at gmail.com
Tue Nov 9 16:03:49 PST 2021


I tried under Safari on iOS.  I guess sound is turned off there.

Looks like the example below, which includes similar code to the 
standards example, further below, works OK on Kubuntu 21.10., Firefox.  
YMMV.

I have iOS, iPadOS, Linux, and maybe others here, if you want me to try 
a different combination.  I don't really want to mess with sound drivers 
on a virtual machine though.

I think the best thing to do to get X3D scripting working on the web is 
to use X_ITE.  I've been advocating it over X3DOM for a long time now.  
You'll have to have an inclusive HTML or XHTML page to get it to work, I 
don't know how to get an external X_ITE to work with an .x3d 
file--AFAIK, it works with HTML, then X3D, JSON and VRML web addresses 
embedded in attributes.   X3DJSONLD has many examples. in src/main/html 
getting this kind of thing working.

If you want to get X3DOM Scripting working, with the understanding that 
at least Protos are working, that's not really my baliwick.  I might 
advise stuff, like stick with simple ECMAScript scripts at first.

My code for scripting only works for JSON and had a very strange, 
non-standard event model.  Here it is:

https://github.com/coderextreme/X3DJSONLD/blob/master/src/main/node/Script.js

I believe one enters the code with loadScripts().  Note that the script 
code doesn't work with a DOM tree, just with parsed JSON.

One should probably focus on getting existing Scripts working, instead 
of totally rewriting the JavaScript as I have done.  I've relied on DOM 
to get any routing working.  I did develop a strawman JS object event 
router, if anyone is interested.

Note; with X3DOM, routes including script fields do not work, AFAIK.   
Getting the routing working between script fields and routes should be 
first priority.  A field element is not a legal script element child in 
HTML, AFAIK.  That's where you need to address the W3C, or do your own 
event routing.

I'm not saying it's impossible.  I just have larger fish to fry, like 
getting Ajv8 working in the browser add dealing with JSON schema issues.

If someone wants to help fix up @geoSystem in the JSON schema, so that 
Java schema validation will not be broken, that would be cool.

I believe that Andreas Plesch was able to add an attribute to the Script 
so that it would not be parsed as HTML JavaScript.  That's been posted 
to this list, but may need to be revisited.  X_ITE avoids it by not 
putting Scripts in the HTML page (but there are extensions).

John

On 11/9/21 13:03, John Carlson wrote:
> For example, take a look at this:
>
> https://coderextreme.net/X3DJSONLD/src/main/html/x_itejoe.html
>
> No sound…any idea why?
>
> John
>
> On Tue, Nov 9, 2021 at 11:42 AM John Carlson <yottzumm at gmail.com> wrote:
>
>     Joe, if you have not done so already,  save off the html below,
>     save in a folder with click.wav.   If the html is in index.html,
>     and you have previously saved off the standard example as
>     JoeExample.x3d in the same folder then there should be click.wav,
>     index.html and JoeExample.x3d in the same folder.   Open
>     index.html in the browser.
>
>     I think that’s the best way to get the example to work.   I’m not
>     even sure what the x3d is supposed to do by reading it.   Do you
>     need to attach the TouchSensor to a shape?  Idk
>
>     On Sun, Oct 31, 2021 at 11:14 PM John Carlson <yottzumm at gmail.com>
>     wrote:
>
>         Try this:
>
>         <!DOCTYPE html>
>         <html>
>         <html>
>          <head>
>           <meta charset="utf-8"/>
>         <link rel="stylesheet" type="text/css"
>         href="https://create3000.github.io/code/x_ite/latest/dist/x_ite.css"
>         <https://create3000.github.io/code/x_ite/latest/dist/x_ite.css>/>
>         <script type="text/javascript"
>         src="https://create3000.github.io/code/x_ite/latest/dist/x_ite.min.js"
>         <https://create3000.github.io/code/x_ite/latest/dist/x_ite.min.js>></scrip
>         t>
>         <script type="text/javascript"
>         src="https://raw.githack.com/andreasplesch/x_ite_dom/master/release/x_ite_dom.
>         1.3.js"></script>
>           <style>
>         X3DCanvas {
>           width: 300px;
>           height:150px;
>         }
>
>         body {
>                margin:0px;
>                padding:0px;
>         }
>           </style>
>           </head>
>          <body>
>            <X3DCanvas cache='false' url='"JoeExample.x3d"'>
>                   <p>Your browser may not support all features
>         required by X_ITE!</p>
>                   <Scene>
>                   </Scene>
>            </X3DCanvas>
>          </body>
>         </html>
>
>         On 10/31/21 18:55, Joseph D Williams wrote:
>>
>>         Looks like great stuff if I as a simple user of the x3d
>>         ecmascript SAI ever needed to know about it in order to
>>         create and use x3d Script node.
>>
>>         All I want to know is will this example work.
>>
>>         ISO/IEC 19775-2 Index page (web3d.org)
>>         <https://www.web3d.org/documents/specifications/19775-2/V3.3/index.html>
>>
>>         https://www.web3d.org/documents/specifications/19775-2/V3.3/index.html
>>
>>         ISO/IEC 19777-1 Edition 2 -- X3D ECMAScript binding
>>         (web3d.org)
>>         <https://www.web3d.org/documents/specifications/19777-1/V3.3/index.html>
>>
>>         https://www.web3d.org/documents/specifications/19777-1/V3.3/index.html
>>
>>         ISO/IEC 19776-1:2015 — X3D XML encoding — Index (web3d.org)
>>         <https://www.web3d.org/documents/specifications/19776-1/V3.3/index.html>
>>
>>         https://www.web3d.org/documents/specifications/19776-1/V3.3/Part01/examples.html#ScriptingExample
>>
>>         Here is the example:
>>
>>         *<?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"
>>         <http://www.web3d.org/specifications/x3d-3.0.dtd>>*
>>         **
>>         *<X3D version='3.0' profile='Immersive'>*
>>         *  <head>*
>>         *    <meta name='filename' content='Scripting.x3d'/>*
>>         *  </head>*
>>         *  <Scene>*
>>         *    <Script DEF='OpenVault'>*
>>         *      <field name='openVault' type='SFTime' *
>>         *             accessType='inputOnly'/>*
>>         *      <field name='combinationEntered' type='SFBool' *
>>         *             accessType='inputOnly'/>*
>>         *      <field name='vaultUnlocked' type='SFTime' *
>>         *             accessType='outputOnly'/>*
>>         *      <field name='unlocked' type='SFBool' value='false' *
>>         *             accessType='initializeOnly' />*
>>         *      <![CDATA[*
>>         *      ecmascript:*
>>         *      function combinationEntered (value) {*
>>         *        unlocked = value;*
>>         *      }*
>>         *      function openVault(value) {*
>>         *      if (unlocked) vaultUnlocked = value;*
>>         *      }*
>>         *      ]]>*
>>         *    </Script>*
>>         *    <Shape>*
>>         *      <Appearance>*
>>         *        <Material diffuseColor='1 0 0'/>*
>>         *      </Appearance>*
>>         *      <Sphere/>*
>>         *    </Shape>*
>>         *    <Sound maxBack='1000' maxFront='1000' minBack='1000'
>>         minFront='1000'>*
>>         *      <AudioClip DEF='Click' stopTime='1' *
>>         *        description='clicking sound' url='"click.wav"'/>*
>>         *   </Sound>*
>>         *    <TouchSensor DEF='TS'/>*
>>         *    <ROUTE fromNode='TS' fromField='isOver' *
>>         *           toNode='OpenVault' toField='combinationEntered'/>*
>>         *    <ROUTE fromNode='TS' fromField='touchTime' *
>>         *           toNode='OpenVault' toField='openVault'/>*
>>         *    <ROUTE fromNode='OpenVault' fromField='vaultUnlocked' *
>>         *           toNode='Click' toField='startTime'/>*
>>         *  </Scene>*
>>         *</X3D>*
>>         **
>>         Click here  <https://www.web3d.org/documents/specifications/19776-1/V3.3/Part01/Examples/Scripting.x3d> to view this example in a 3D scene window.
>>         If already ok for some tools please tell me:
>>         How can we best be sure that when that ‘Click here’ in the
>>         spec or in this note gets made, that it works as described
>>         using any competent html Dom webGL ecmascript browser, not in
>>         a sandbox (at least show the geometry and retrieve that
>>         .wav), free to interact with the rest of our WWW.
>>         Thanks for all,
>>         Joe **
>>
>>         *From: *John Carlson <mailto:yottzumm at gmail.com>
>>         *Sent: *Sunday, October 31, 2021 1:16 PM
>>         *To: *x3d-public at web3d.org
>>         *Subject: *[x3d-public] ECMAScript 6 X3D API
>>
>>         More work done on es6x3d:
>>
>>         https://GitHub.com/coderextreme/es6x3d
>>         <https://GitHub.com/coderextreme/es6x3d>
>>
>>         Changes for MFString, and other MF work.
>>
>>         Still lots of work to do, including possible export to three.js
>>
>>         John
>>
>>         _______________________________________________
>>
>>         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/20211109/ff2940cc/attachment-0001.html>


More information about the x3d-public mailing list