[x3d-public] ECMAScript
Michalis Kamburelis
michalis.kambi at gmail.com
Mon Aug 7 06:39:29 PDT 2023
Indeed, view3dscene / Castle Game Engine is missing ECMAScript.
It is on the roadmap, and certainly possible to do. We could use
Duktape like FreeWRL; or other JS engines -- whatever is lightweight
to execute and easy to maintain.
But admittedly implementing JS scripting is not high priority in our
case. Reason: most of CGE users do programming "outside" of X3D, using
Castle Game Engine API to manipulate scenes (and X3D nodes too). This
API is available from Pascal, we think about extending to other
languages (Python) in the future too. In most cases, people want to
treat model formats like X3D or glTF (or anything else) as just
carriers of information between 3D authoring tool and CGE. So
executing scripts within the models is not a commonly needed feature.
As a solution for now: We support CastleScript, a really simple (very
simple, much more limited than JS) language for simple things. See
https://castle-engine.io/castle_script.php . It can express the
operation you do in your samples :) And in X3D "Script" node, you can
specify a few alternatives, so you could have both ecmascript and
castlescript versions for cross-browser support. If you want to
pursue this option, the "OrientationData" node would look like this:
-----------
#X3D V3.2 utf8
PROFILE Interchange
DEF OrientationData Script {
outputOnly MFString orientation
inputOnly SFRotation printOrientation
initializeOnly SFString sep ", "
url [
"ecmascript:
function printOrientation (value,ts) {
var x = Math.round(value.x*100)/100;
var y = Math.round(value.y*100)/100;
var z = Math.round(value.z*100)/100;
var angle = Math.round(value.angle*100)/100;
orientation = new MFString ( x + sep + y + sep + z + sep + angle );
}
"
"castlescript:
function foo(value,ts)
{ Note that we have to hardcode sep value (comma) below, due to
CastleScript limitations. }
orientation :=
string(round(vector_get(value, 0) * 100) / 100) + ',' +
string(round(vector_get(value, 1) * 100) / 100) + ',' +
string(round(vector_get(value, 2) * 100) / 100) + ',' +
string(round(vector_get(value, 3) * 100) / 100) + ','
"
]
}
-----------
Regards,
Michalis
niedz., 6 sie 2023 o 22:31 Joseph D Williams <joedwil at earthlink.net> napisał(a):
>
>
>
> Hi, view3dscene, missing ECMAScript.
>
> Near implementation?
>
> All I need is some basic stuff. :
>
>
>
> DEF PositionData Script {
>
> outputOnly MFString position
>
> inputOnly SFVec3f printPosition
>
> initializeOnly SFString sep ", "
>
> url "ecmascript:
>
> function printPosition (value,ts) {
>
> var x = Math.round(value.x*100)/100; // simple 2 decimal digits
>
> var y = Math.round(value.y*100)/100;
>
> var z = Math.round(value.z*100)/100;
>
> position = new MFString ( x + sep + y + sep + z );
>
> }
>
> "
>
> }
>
>
>
> DEF OrientationData Script {
>
> outputOnly MFString orientation
>
> inputOnly SFRotation printOrientation
>
> initializeOnly SFString sep ", "
>
> url "ecmascript:
>
> function printOrientation (value,ts) {
>
> var x = Math.round(value.x*100)/100;
>
> var y = Math.round(value.y*100)/100;
>
> var z = Math.round(value.z*100)/100;
>
> var angle = Math.round(value.angle*100)/100;
>
> orientation = new MFString ( x + sep + y + sep + z + sep + angle );
>
> }
>
> "
>
> }
>
>
>
> Thanks,
>
> Joe
>
> _______________________________________________
> x3d-public mailing list
> x3d-public at web3d.org
> http://web3d.org/mailman/listinfo/x3d-public_web3d.org
More information about the x3d-public
mailing list