support for Chrome

  • Email
  • Sharebar
  • Email
10 replies [Last post]
aplesch
aplesch's picture
Offline
MathematicianScientistTechnologistRegular Blogger
Joined: 05/10/2015

Hi Andy,

it is great to see that you are keeping your VRMATH Logo editor site functional. Since it was mentioned by a user in the x3dom-user group, I took the opportunity to take a look. It works fine in Firefox but newer Chrome does not support certain DOM modification functions anymore which x3dom 1.7 still uses.

I collected a few small fixes which make VRMATH  work with x3dom 1.8.3 which will work well in Chrome:

https://gist.github.com/andreasplesch/7a7f954c6b6d300bde6dacc1ff6b4cb6

One is small update to the x3d css to fit it properly and one is is make convex=true the default which essentially replicates the old behaviour. convex=false has an intricate bug in x3dom exposed by  the dynamic DOM updates of VRMATH but works well in exported finished scenes. convex=true will still work for many concave geometries in the editor.

Perhaps you can consider these fixes, all the best, Andreas

Andy
Andy's picture
Offline
MathematicianTechnologistProfessional Blogger
Joined: 02/10/2010
Applied

Hi Andreas,

Thank you for the fixes. I have applied the css and convex=true and V1.8.3 seems to run in Chrome now. However, glitches can be expected for this sudden upgrade, like the one you found in the gears.

I have not updated any codes since about 2020.. Glad to know if anyone is using VRMath2.

Best,

Andy

aplesch
aplesch's picture
Offline
MathematicianScientistTechnologistRegular Blogger
Joined: 05/10/2015
Mutations

I drlled down and found that heading relies on x3dom and the rotation attribute of the turtle trafo.

With the new Mutation handling something gets out of sync between x3dom, logo and drawing and I could not figure out how to fix that. This is also affects Firefox.

The only solution I found is to switch off MutationObserver support in x3dom-full.js:

x3dom.userAgentFeature = {
    supportsDOMAttrModified: !1,
    supportsMutationObserver: !1
}
 
x3dom still will work by intercepting .setAttribute and .getAttribute calls.
 
That seemed to work well since it is more synchronous.
 
That would be also possible with x3dom 1.7 but x3dom 1.8.3 has a lot of other fixes as well.
 
Cheers, Andreas
aplesch
aplesch's picture
Offline
MathematicianScientistTechnologistRegular Blogger
Joined: 05/10/2015
potentially better fix for heading

In vrm2.js

function pSETHEADING(ori) {
    setRotation(ori);
    _rp._x3domNode.updateField("rotation", ori); //force immediate update
    var m = _x3d.runtime.getCurrentTransform(_rp);
    _rotmat.values = [[m._00, m._01, m._02], [m._10, m._11, m._12], [m._20, m._21, m._22]];
    updateProp()
 
 
The problem is that after setRotation the expectation is that currentTransform gets immediately updated. However, this has to go through the DOM to be observed and the update is triggered a little bit later. So the old currentTransform is returned.
With the fix the update is forced immediately and x3dom-full.js does not have to be modified as shown earlier, eg. supportsMutationObserver can say true.
 
I think this is perhaps the only place where there is such a close link between x3dom and logo. As such I think this may be a better fix.
 
Cheers, Andreas
Andy
Andy's picture
Offline
MathematicianTechnologistProfessional Blogger
Joined: 02/10/2010
Fixed

Amazing! just one line to fix updating heading.  The involute gear codes now run well.

My coding in vrm2.js is very chaotic honestly, at times I could not recall how I did years ago.

Thank you so much for resolving this dom update issue. Potentailly there are similar issues in other parts of vrm2 I think.

Cheers,

Andy :-) 

Andy
Andy's picture
Offline
MathematicianTechnologistProfessional Blogger
Joined: 02/10/2010
Will try later

I have a lot to catch up with current x3dom and will try later today after work.  I did some tests on some existing logo files, mostly works but the sun-earth one caused some issue:

it reported:

VIEWPOINT: has incorrect attribute: centerofrotation
POINTLIGHT: has incorrect attribute: radius

Perhaps this is also the same issue and need to force immediate update.

Andy

aplesch
aplesch's picture
Offline
MathematicianScientistTechnologistRegular Blogger
Joined: 05/10/2015
similar

Yes, this is a similar issue. The attributes for fields are only created by x3dom after the dom node is parsed when the mutation is observed by the browser. That happens a little after parsePara is called, so it does not see it. Ideally, parsePara should not rely on x3dom to check for valid attributes, for example by setting all valid attributes when the element is first created.

But it seems to work pretty well to wait a little and then check:

function parsePara(name, obj, para) {
    for (var i = 0; i < para.length; i++) {
        var colon = para[i].indexOf(":");
        if (colon == -1) {
            appendMsg('<font color="orange">' + name.toUpperCase() + ": </font> has incorrect parameter!", 1);
            return
        }
        var value = para[i].substr(colon + 1).trim();
        if (value == "") {
            appendMsg('<font color="orange">' + name.toUpperCase() + ": </font> has incorrect value: " + value, 1);
            return
        }
        var attr = para[i].substring(0, colon).trim();
        if (obj._x3domNode && obj.hasAttribute(attr)) { //attached _x3domNode means that x3dom has parsed
            obj.setAttribute(attr, value);
            return
        }             
        //wait a little and try again
        setTimeout( function() {
            if (obj._x3domNode && obj.hasAttribute(attr)) {
                obj.setAttribute(attr, value);
            }
            else {
                appendMsg('<font color="orange">' + name.toUpperCase() + ": </font> has incorrect attribute: " + attr, 1);
                //perhaps setAttribute anyways, should not hurt           
            }        
        }, 100 ) // could be longer
    }
}
 
This is not very elegant but forcing the update in addChild() for example is also not too elegant.
 
Andy
Andy's picture
Offline
MathematicianTechnologistProfessional Blogger
Joined: 02/10/2010
Applied and fixed

This one is also applied and fixed in the vrm2ui.min.js.  Big thanks.

Andy :-)

aplesch
aplesch's picture
Offline
MathematicianScientistTechnologistRegular Blogger
Joined: 05/10/2015
Testing

Good to see Chrome now working pretty well. Please let me know if you come across something during testing or if you want me to try something.

aplesch
aplesch's picture
Offline
MathematicianScientistTechnologistRegular Blogger
Joined: 05/10/2015
Logo interpreter

The Logo interpreter in Chrome (I believe through wasm) somehow behaves differently than the same interpreter in Firefox:

 

Chrome:

Firefox:

I believe the Firefox behavior is correct.

I could not quite isolate the issue but probably related to geartooth function below:

 

aplesch
aplesch's picture
Offline
MathematicianScientistTechnologistRegular Blogger
Joined: 05/10/2015
The heading function seems to

The heading function seems to be involved. When I introduce a wait of 60 before recording heading in a variable the result changes:

 

Very puzzling.

END