Back to the Shapespark home page

Gettings the views in a scene

Is it possible to get all views available in a scene?

The root cause is this:
Whenever you switch to a view that hides a node, all child nodes will be hidden or shown as well instead.
I’m building a configurator using the and node.hide() functions. I hide all non chosen options.
Because switching views will update the visibility of all children, all the non chosen options are shown again whenever the root node is shown.

I work around this by hiding all the non chosen options after onViewSwitchDone. However I need to know if they should be hidden depending on the view or not (there doesn’t seem to be an node.isVisible() function or variable)
There is the node.hideInViews array though which allows me to check manually if it should be visible.
Yet another issue is that it uses the ID’s while onViewSwitchDone passes the name of the current view.

Is there a way the get the views in the scene?
Or is there another way to deal with this apart from hard coding?

I do see that I could parse the scene.json for that data. Can I access that file when it’s uploaded? (seems like I can’t).
My final solution would be to write a script to retrieve the view data from the json before we upload and store it on my own server.

The ideal fix would be in shapespark itself:
Whenever you show or hide a node that is linked to a view, only update that node’s visibility and skip rendering the children if the parent node is invisible.

In the Shapespark editor Objects tab, Custom hide in views, Custom lightmap resolution, Custom collisions setting apply to a node and all its children nodes, unless a child provides own settings.
So perhaps a solution in your case would be to always set Custom hide in views for all children nodes that you would like to control by API to an empty list? This way view switching won’t affect these nodes visibility.

From my experience it is difficult to reliably control visibility if you have two independent mechanisms for changing it: views menu and API. If possible in your use case, clearly dividing objects into two groups: one with visibility controlled by the view menu only and one with visibility controlled by API only should make things simpler.

If this doesn’t address the problem, could you explain what kind of visibility changes the view menu is responsible for in your scene?

In the Shapespark editor Objects tab, Custom hide in views , Custom lightmap resolution , Custom collisions setting apply to a node and all its children nodes, unless a child provides own settings.

That’s good information to have, thanks Jan.
Can it be that is not the case when you show or hide using the API and you instead force update all the children regardless?
When I show a node using the API, a child node that has a custom view is also shown, even though looking at the custom hide in view list it should be hidden.

The per-view visibility is applied only when switch to view finishes, if you then modify the visibility using the API, the modifications do not take into account which view was recently activated and which nodes should stay hidden in this view.

Anyway, nodes represent a scene tree, and this is why the operations on nodes propagate to the whole sub-tree. Perhaps more suitable for your case would be working with meshes, node.mesh.visible = false will just hide a single mesh, without propagating to meshes attached to children nodes.

After trying some things the solution I settled on was keeping a map with my viewNames and their respective Id’s. Then checking the node.hideInViews and depending on that calling or node.hide() on the swappable options.

You can mark this as resolved.
Thanks for the help. :slight_smile: