Toggle visibility of assets

What would be the equivalent code for the ShapeDiver Viewer v3 to list assets, and toggle their visibility?
For v2 the code is as follows:

const toggleDimensions = function (api, val) {

  // look for dimension objects:

  var assets = api.scene.get(null, "CommPlugin_1").data

  let assetsScenePaths = [];

  for (let i = 0; i < assets.length; i++) {
    if (assets[i].name.includes("DIM - ")) {
      assetsScenePaths.push(assets[i].scenePath);
    }
  };

  if (val == "hide") {
    // HIDE DIMENSIONS
    api.scene.toggleGeometry([], assetsScenePaths);
  }

  if (val == "show") {
    // SHOW DIMENSIONS
    api.scene.toggleGeometry(assetsScenePaths, []);
  }

}

Thanks!

Hello @post8

sure thing, I created an example for you where I create this behavior with one output. It should be relatively straightforward to adjust your code accordingly.

Cheers, Michael

Hi Michael,

Thanks, that surely got me in the right direction.
One issue: I’m also showing/hiding ‘dimension’ assets which have html-text linked to them.
With the previous viewer they would also disappear when I toggled them off, but now they won’t.

I found out that it’s the “tag2d” outputs that need to be toggled, but setting ‘visible’ to false won’t cut it there.
The code snippet I’ve been trying:

  session.getOutputByFormat("tag2d").forEach((item) => {
    if (!!item?.name.includes("DIM - ")) {
      if (typeof item?.node?.visible === "boolean")
        item.node.visible = false
          // setting this to false won't hide the text-items
    }
  })

Thanks!

Hello @post8
thank you for letting me know about this, there definitely seems to be something going on. I’ll get back to you with a solution!
Cheers, Michael

1 Like

Hello @post8,

this issue has been resolve with viewer version 2.5.0. Here is an example: visibility - html anchors - CodeSandbox

Cheers, Michael

That’s great, thanks!

I did find this flickering behaviour of the dimensions. Maybe you have a clue why this is?

We are aware of this issue and have it filed in our backlog. When Michael comes back he can give you a better estimation of when this fix can be released.

Thanks!
Another thing I’ve noticed is that when the geometry is updated (by updating a parameter), the dimension assets become visible again.
(I’m currently keeping those assets invisible with an always running interval, which is far from optimal.)

Hello @post8,

regarding your first issue, this happens due to an issue with the visibility check that we currently use. A planned restructuring for that is in our pipeline, but this might take a bit longer. As a workaround for now, you can look into creating more space for the dimensions tag, by creating a wider gap between the lines. That should help with the flickering.

For you second issue, how are you currently applying the visibility?
In this example we are using the updateCallback function to re-apply the visiblity of an object. I think this might already solve your problem.

Cheers, Michael

Hi Micheal, any progress with this? Or can you think of any alternatives methods?

We don’t have a proper way of showing dimensions at the moment, which is becoming an issue.

Hello @shwdehaan,

your message had a great timing. This issue has already been fixed and will be in our next release which will probably happen next week. I’ll message you here once it is publicly available.

Cheers, Michael

1 Like

Hello @shwdehaan

this issues should be resolved now on our platform and viewer version 2.9.1, please give it a try.

Cheers, Michael

1 Like

Hi Michael,

I gave it a try today and I stumbled upon the following issue. When updating parameters, the previous values are not being removed as can be seen in the following sandbox:

Kind regards,
Rudin

Hello @post8

thank you for the notice about this. This will be fixed asap. I’ll notify you once it is done.

Cheers, Michael

Hello @post8

this issue has been resolved in version 2.9.2. Sorry about the inconvinience!

Cheers, Michael

1 Like

Hi Michael,

Thanks for the update!

One thing I have noticed is that when I hide the dimension assets (“glb” and “tag2d”) by setting “visible” to false, they become visible again whenever I update the model parameters. This behaviour seems different from what I remember as the default.

Am I correct, or could it be related to a configuration in the ShapeDiver model?

Kind regards,
Rudin

Hello @post8,

when a customization is done, the tree nodes are replaced and you need to re-apply the visible property. Here is an example on how to do that.

Cheers, Michael