Sketchfab Forum

Need help with viewer api and api utility

viewer-api
api

(Pierre Savoie) #1

I'm not so good at programming but I hope this is relatively simple.
I am trying to Show/Hide my Box002 but only if Box001 is visible.
Same for for Box003, it will show only when Box001 is hidden and Cylinder001 toggled visible.

My big issue is with my "if", I don't know how to detect whether Box001 is visible or not.
What am I doing wrong here?
Here's the model ID : b90043a5a2c2469a8bf48391c5e9ad59

sketchfabAPIUtility.setNodeVisibility("Cylinder001", false);
sketchfabAPIUtility.setNodeVisibility("Box002", false);
sketchfabAPIUtility.setNodeVisibility("Box003", false);

$("#variation_7").on("click", function (event) {

       sketchfabAPIUtility.toggleNodeVisibility("Box001");
       sketchfabAPIUtility.toggleNodeVisibility("Cylinder001");

        });

$("#variation_8").on("click", function (event) {

if(("Box001").is(":visible")){

            sketchfabAPIUtility.toggleNodeVisibility("Box002");
			} else {
            sketchfabAPIUtility.toggleNodeVisibility("Box003");
			}
        });

#2

@shaderbytes do you have a getNodeVisibility function or something?


(Shaderbytes) #3

I dont have a direct function but i do store the current state in a property on the object named "isVisible" There is a function that will return a node by name called "getNodeObject" so you could do this :

if(sketchfabAPIUtility.getNodeObject("yourNodeName").isVisible){
...
}

(Pierre Savoie) #4

It worked!
Thank you Shaderbytes and James for the quick response.