Viewer-1.2.0 mouse events not working


(Shaderbytes) #1

Hey all so if i use

src=“https://static.sketchfab.com/api/sketchfab-viewer-1.1.0.js

Mouse events work in the viewer, but if i use

src=“https://static.sketchfab.com/api/sketchfab-viewer-1.2.0.js

Mouse events do not work…

any ideas…?

ps ( i cant paste the full script tag in here or the forum deletes those lines all together )


(Paul Sketch) #2

Seems to works on https://sketchfab.com/developers/viewer/startstop ?
(check console for event)

Any reproducible bug page we can check ?


(Shaderbytes) #3

ok here is my testing platform of a tool i built that is part of a much larger project, This is fully working using 1.1.0 as the src for the viewer.

https://www.shaderbytes.co.za/clients/richard_rawlings/takoa/patch_demo/index.html

If you click on “toggle patches display” and then select a patch you will see it works.

If i change only the src value of the viewer script tag in the head of the html then clicking the patches does nothing.

I put a log in the console to make sure the function is being called to add the listener and it is, it just doesnt work. There are console logs in the relevant callbacks and they are never triggered , there is also no error in the console related to this, so it is a mystery.

In my utility, it triggers a callback when all the relevant info has being fetched and built , at this point im adding the listener.

i will send you a pm with a link to all the files in a zip , the current working version. You can then test it yourself by only changing this one script tag src value and see it stops working.


(Paul Sketch) #4

Thanks, there’s indeed a bug on mouse event coordinates on 1.2.

Maybe sketchfab-utility will need some 1.2 (and now 1.2.1) changes:

  • Click can return null (so that you can do “unselect”) see Viewer API Change Log)
  • The mesh is no more optimized, so no geometry nor material merge. That may change how you do the node/parent instance id matching (Uv channels keep switching )
  • for click I would use the ‘slow’ but more precise picking

Thanks again for the quick report and reproducible case !


(Shaderbytes) #5

ok let me try get everything stright for updating :

I already discovered i need to use “merge_materials”: 0,“graph_optimizer”: 0 for the utility to work, i was just passing these in in the constructor but there is a defaults object “clientInitObject” within the utility itself ( the constructor argument object is merged with this one ) which was currently empty so i just added these to that object now as it has to be set for the tool to work.

the utility was updated recently and now builds the internals from calling “getSceneGraph”. All the objects are sorted into objects matching their types but thye also each have a parent property and store a reference to their parent. I abstract adding listeners so that i can do some additional logic when a click event happens. So when a mouse event occurs i firstly get the node of the event object instanceID returned from sketchfab, then i simply transverse the parent structure till the first “Group” node and first node of type “MatrixTransform” is found. These references are then added to the event object.

this.onClick = function (e) {
      
        var node = classScope.getNodeObject(e.instanceID);
		var parentGroup = node.parent;
		if(parentGroup !== null && parentGroup !== undefined){
			while(parentGroup.type !== classScope.nodeTypeGroup ){
				parentGroup = parentGroup.parent;
		
			}
		}

		var parentMatrixTransform = node.parent;
		if(parentMatrixTransform !== null && parentMatrixTransform !== undefined){
			while(parentMatrixTransform.type !== classScope.nodeTypeMatrixtransform ){
				parentMatrixTransform = parentMatrixTransform.parent;
		
			}
		}

        e.node = node;
		e.parentGroup = parentGroup;
		e.parentMatrixTransform = parentMatrixTransform;
        for (var i = 0; i < classScope.eventListeners.click.length; i++) {
            classScope.eventListeners.click[i](e);
        }
    };

This works well let me know if you see anything that can be a problem… I obviously need to think about the null thing now… so will the event object argument be null then?

for the slow thing it is not documented any where but from you code example above can i presume it should be like this :

classScope.api.addEventListener("click", classScope.onClick,{ pick: 'slow' });

I dont know how this is related to the untility , this is a bug when uploading .blend files with multiple uv sets , i have encountered this bug over and over again even since that post.

This is not a problem to the utility and i have a optional argument when calling to update a material eg :

classScope.updateMaterial(classScope.sict.materialName, classScope.sketchfabAPIUtility.AlbedoPBR,{"texCoordUnit":1});

classScope.updateMaterial(classScope.sict.materialName, classScope.sketchfabAPIUtility.Opacity,{"internalFormat":"ALPHA","texCoordUnit":1,"type":"alphaBlend"});

So i can just change the texCoordUnit value to get around this bug. The huge problem is that many materials have textures set in the editor and when the uv is switched those textures all map incorrectly and I have to manually change every material, ~30 to fix it. and it switches a lot - sometimes every time i upload. In a day of editing and testing i can update a model several times and this switching is causing me 20-30 minutes of unneeded work each time.

anyway thank for the info , i will get to updating the utility where needed , i want to be as compliant to the latest viewer code as can be :wink:


(Paul Sketch) #6

sorry I was unclear: the link is just about the comment on the graph_optimizer/material_merge thing. in 1.2, no more merge, so you might get more nodes than 1.2


(Paul Sketch) #7

so will the event object argument be null then

you get the event but with the position,instanceid null.

for the slow thing it is not documented any where

ouch indeed. thanks for pointing that, will fix.
yes ‘slow’ it is.

classScope.getNodeObject(e.instanceID);

From you code and the 1.2, I did sometimes get an array of object sometimes, thus rest of the code fails afterwards


(Shaderbytes) #8

ok i will double check this logic again , i know arrays where created for same name objects , but i didnt think it was happening for instanceID , those are supposed to all be unique , will get back to you ( do you perhaps have a model link i can use to test this on ? ) just the model id is fine if you have one