[x3d-public] More on X3D script to X3DOM scripting...conversionprogram beginning. Help is welcome.

John Carlson yottzumm at gmail.com
Sun Dec 20 16:21:03 PST 2015


What happens when you make it an array instead of an array of arrays?

Thanks,

Sent from Mail for Windows 10


From: Clement IGONET
Sent: Sunday, December 20, 2015 4:49 PM
To: John Carlson
Cc: X3D Graphics public mailing list; x3dom mlist
Subject: Re: [x3d-public] More on X3D script to X3DOM scripting...conversionprogram beginning. Help is welcome.

geometry crossSection is missing testing with X3Djson of my own:

{
    "X3D": {
        "@profile": "Immersive",
        "@version": 3.3,
        "@xsd:noNamespaceSchemaLocation":
"http://www.web3d.org/specifications/x3d-3.3.xsd",
        "Scene": {
            "-children": [{
                    "Transform": {
                        "@translation": [0, 20, 0],
                        "-children": [{
                                "Group": {
                                    "@class": "buildingPart",
                                    "-children": [{
                                            "Shape": {
                                                "-appearance": [{
                                                        "Appearance": {
                                                            "-material": [{

"Material": {

 "@diffuseColor": [null, null, null],

 "@transparency": 0.6
                                                                    }
                                                                }]
                                                        }
                                                    }],
                                                "-geometry": [{
                                                        "Extrusion": {
                                                            "@convex": false,

"@creaseAngle": 0.785,

"@crossSection": [[-39.94663841462567, -39.472313797352705],
[-26.98130996805282, -33.99040391371091], [-24.13471984587026,
-37.8377483755381], [0.5505538701044541, -27.385425271266268],
[-2.2960362520781055, -23.538080809439077], [3.5528168882482545,
-21.058433944731174], [24.424104619198804, -12.21843727668515],
[30.10616537155961, -9.816626861538039], [33.00835295692408,
-13.752927264140247], [57.671387687309995, -3.3117236526628173],
[54.791439085954146, 0.6023377651406799], [68.37945912269265,
6.351115472687708], [41.848349624970105, 42.33379373503747],
[28.28256857382039, 36.59613552028483], [25.22470809249468,
40.74370628361037], [0.561673362108766, 30.30250267213294],
[3.58617536742154, 26.199409879194917], [-2.2293192968918842,
23.73088250728141], [-23.078368042253633, 14.913124824824184],
[-28.81602625779635, 12.477955931293877], [-31.907245218295344,
16.67000466579701], [-56.614757918278684, 6.206562067940691],
[-53.501299972190886, 1.992274348638849], [-66.47774791234822,
-3.500755027797344], [-39.94663841462567, -39.472313797352705]],
                                                            "@solid": false,
                                                            "@endCap": false,
                                                            "@spine":
[0, 0, 0, 0, 55, 0]
                                                        }
                                                    }]
                                            }
(...)

And after converting to xml X3D with X3DJSONLD:

<!DOCTYPE X3D PUBLIC "ISO//Web3D//DTD X3D 3.3//EN"
"http://www.web3d.org/specifications/x3d-3.3.dtd"><X3D><Scene>
  <X3D profile='Immersive' version='3.3'
xsd:noNamespaceSchemaLocation='http://www.web3d.org/specifications/x3d-3.3.xsd'>
    <Scene>
         <Transform translation='0 20 0'>
              <Group class='buildingPart'>
                   <Shape>
                        <Appearance>
                             <Material diffuseColor='' transparency='0.6'>
                             </Material>
                        </Appearance>
                        <Extrusion convex='false' creaseAngle='0.785'
crossSection='' solid='false' endCap='false' spine='0 0 0 0 55 0'>
                        </Extrusion>
                   </Shape>
(...)

On Sat, Dec 19, 2015 at 6:26 AM, John Carlson <yottzumm at gmail.com> wrote:
> Start of a Script Expander for X3D JSON — X3D -> X3DOM scripting.  I have no
> clue how initialization, shutdown or event processing will work.
>
> This code is currently a MESS.  This is not an example of how I like to
> present myself and I present it here in order to stimulate someone else to
> help with X3D bits I have little knowledge of.  I will continue working on
> this, but some guidance would be welcome.
>
> John
>
> https://github.com/coderextreme/X3DJSONLD/blob/master/Script.js
>
>
> // X3D JSON Script Expander
>
> var content = '';
> // read content into buffer
> process.stdin.resume();
> process.stdin.on('data', function(buf) { content += buf.toString(); });
>
> function Package(package, name) {
> this.initializers = [];
> this.getters = {};
> this.setters = {};
> this.values = {};
> this.types = {};
> this.packages = {};
> if (typeof package === 'undefined' || package.name === "") {
> if (typeof name === 'undefined') {
> this.name = "";
> } else {
> this.name = name;
> }
> } else {
> if (typeof name === 'undefined') {
> this.name = package.name;
> } else {
> this.name = package.name+'.'+name;
> }
> package.packages[name] = this;
> }
> // initialize children packages
> // add package to parent so you can find the package without full path
> }
>
> Package.prototype.find = function (name) {
> if (typeof this.packages[name] === 'undefined') {
> // there is no package, so global package
> return new Package(undefined, name);
> } else {
> return this.packages[name];
> }
> }
>
>
> function processPrototypes(object, clazz, package) {
> var p;
> if (typeof object === "object") {
> for (p in object) {
> var name = object[p]["@name"];
> if (typeof name === 'undefined') {
> name = object[p]["@DEF"];
> }
> if (p.toLowerCase() === 'script') {
> var script = new Package(package, name);
> processPrototypes(object[p], clazz, script);
> } else if (p.toLowerCase() === 'route') {
> processRoutes(object[p], clazz, package);
> } else if (p.toLowerCase() === 'field' && object['@language'] !== 'GLSL') {
> processFields(object[p], package);
> clazz.push('var ' +  package.name +  ' = function(' +
> package.initializers.join(', ') + ') {');
> clazz.push('var that = this;');
> clazz.push('this.setters = {};');
> clazz.push('this.getters = {};');
> for (var v in package.values) {
> if (package.types[v].indexOf("MF") === 0) {
> clazz.push('var that.' + v + ' = ['+ package.values[v] + '];');
> } else {
> clazz.push('var that.' + v + ' = '+ package.values[v] + ';');
> }
> }
> for (var v in package.getters) {
> clazz.push('this.getters.' + v +  ' = function () { return that.' +  v +  ';
> };');
> }
> processSource(object['#sourceText'], clazz, package);
> clazz.push('}');
> processPrototypes(object[p], clazz, package);
> } else if (p.toLowerCase() === '@use') {
> var name = object["@USE"];
> object["@USE"] = name;
> // object[p] is not an object
> } else if (p.toLowerCase() === '@def') {
> var name = object["@DEF"];
> object["@DEF"] = name;
> // object[p] is not an object
> } else {
> processPrototypes(object[p], clazz, package);
> }
> }
> }
> }
>
> function processRoutes(routes, clazz, package) {
> clazz.push("this.runRoute = function() {");
> var r;
> for (r in routes) {
> var route = routes[r];
> var fromNode = route["@fromNode"];
> var fromField = route["@fromField"];
> var toNode = route["@toNode"];
> var toField = route["@toField"];
> clazz.push(package.name+'.this.'+toNode+'.setters.'+toField+'('+package.name+'.this.'+fromNode+'.getters.'+fromField+'());');
> }
> clazz.push("};");
> }
>
> function processFields(fields, package) {
> var f;
> for (f in fields) {
> var object = fields[f];
> var name = object["@name"];
> package.types[name] = object["@type"];
> switch(object['@accessType']) {
> case 'initializeOnly':
> // these should be in order, so it's an array
> package.initializers.push(name);
> package.values[name] = object["@value"];
> break;
> case 'inputOutput':
> // setters should be looked up by name
> package.setters[name] = object;
> package.getters[name] = object;
> package.values[name] = object["@value"];
> break;
> case 'inputOnly':
> // setters should be looked up by name
> package.setters[name] = object;
> package.values[name] = object["@value"];
> break;
> case 'outputOnly':
> break;
> package.getters[name] = object;
> default:
> break;
> }
> }
> }
>
> function processSource(lines, clazz, package) {
> if (typeof lines !== 'undefined') {
> var functions = lines.join("\n").split("function");
> var f;
> for (var f = 1; f < functions.length; f++) {  // skip ecmascript:
> var func = functions[f];
> var sp = func.indexOf('(');
> var name = func.substr(0, sp).trim();
> var funcvar = 'this.' + name;  //  a non setter function
> if (typeof package.setters[name] !== 'undefined') {
> funcvar = 'this.setters.' + name; // a setter function
> }
> clazz.push(funcvar + ' = function ' + func.substr(sp));
> }
> }
> }
>
> process.stdin.on('end', function() {
> var object = JSON.parse(content);
> var clazz = [];
> processPrototypes(object, clazz, new Package());
> console.log(clazz.join('\n'));
> //console.log(JSON.stringify(object, null, 2));
> });
>
>
> _______________________________________________
> 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/20151220/d4c03c71/attachment-0001.html>


More information about the x3d-public mailing list