Trying to dynamically show or hide a specific object in the scene

I am trying to dynamically show and hide specific nodes (objects) in my scene using the Shapespark Viewer API by adding a script to body-end.html.

I’ve encountered an issue where the standard API methods for visibility control don’t seem to be available in my setup. Here’s what I’ve found:

  1. Calling WALK.getViewer() returns an object (which my console logs as Pv).
  2. I am successfully using Pv.onSceneReadyToDisplay(callback) to wait for the scene to be ready.
  3. However, this Pv object does not have the hide("node-name") or show("node-name") methods as described in the API documentation (GitHub - shapespark/shapespark-viewer-api: JavaScript API for interacting with the Shapespark 3D scene.). Attempting to call them results in a “is not a function” TypeError.
  4. I can successfully retrieve a node object (logged as Pm in my console) using Pv.findNodesOfType("my-object-name").
  5. However, this retrieved node object (Pm) does not appear to have a direct visible property or any apparent method to control its visibility (e.g., .setVisibility()).

Could you please advise on the correct way to control the visibility (show/hide) of specific named nodes (e.g., “001”, “002”) via JavaScript in this scenario? How can I change the visibility of a node using the Pv object or the node objects retrieved from it?

Any guidance or examples would be greatly appreciated.

Thank you for your assistance.

Hi!

Unfortunately, the hiding of objects is not supported and has not really been supported by the ViewerAPI. You need to use the Switch Object extension to manipulate the visibility of certain objects.

See instructions here:

Thank you for your insight though, we will discuss this internally as a potential extension of our Viewer API in the future.

1 Like