Get object visibility

(Klaasnienhuis) #1

I'm doing some development with the viewer API and I wonder if there's a way to get the visibility of an object. I'd like to know which objects are hidden and which aren't.

(Stephomi) #2

With the getNodeMap or getSceneGraph function, you should have a nodeMask entry on each nodes.
0 means hidden, something else will be visible.

(Klaasnienhuis) #3

Thanks @stephomi,
by the way, how does the graph work? I don't seem to get any results when I call the getSceneGraph function on a model. Probably I'm doing something wrong...

(Klaasnienhuis) #4

hm, I'm actually not seeing this. All my objects (matrixTransform, Group and Geometry) have a nodemask of -1, no exception. Even though some objects have been hidden.

(Stephomi) #5

A bug on our side, we always return the initial scene graph, I'll try to fix that.

(Stephomi) #6

(I'll only fix the nodeMask attribute, but fyi the localMatrix and worldMatrix for the transform won't be updated. In that case the api function getMatrix should be used instead)

(Shaderbytes) #7

not sure how ideal such a fix is. At least with it returning the initial state the results are constant to a point in the life cycle of the viewer. If you make partial changes only to the node mask this makes the results a mixed bag of life cycle data, some initial and some updated. If nothing else is changed other than the mask it is redundant to call to get the full scene graph just to read one property off of it. It should either always be all initial or all updated.. otherwise it is just a hack. No clear logic for other developers to pick up and work with when first starting to use the API.

Maybe an additional function could be created to just get the individual node mask value for an object?

I personally didnt run into this issue because I didnt assume the graph was ever updated, I only call for the data once, expecting the initial values , and wrote my own variable for visibility onto each object on setup. I handle tracking the state of visibility myself. Same for matrix operations , I simply overwrite the values on my local copy of the graph at the same time as calling to update anything matrix transform related in the API.

ps there is an error in the documentation for getSceneGraph :

getSceneGraph( callback )
This function provides the scene graph. The callback will be passed ( graph ).

It incorrectly shows the return function as only receiving one argument , the graph, where in fact it is two arguments ( like getNodeMap) the first argument being the possible error result. It should be :

The callback will be passed (err, graph ).

(Klaasnienhuis) #8

Thanks, that works!

As for the lifecycle, I assume that getting info on an object through the API reflects the current state of that object, whichever method I use. But I agree that having the states mixed can be quite confusing.

(Stephomi) #9

getNodeMask(instanceID, callback) added with (err, nodeMask).