0

I add an item to the viewer with the following function:

 createText(params) {
    const textGeometry = new TextGeometry(params.text,
          Object.assign({}, {
            font: new Font(FontJson),
            params
          }));
    const geometry = new THREE.BufferGeometry;

    geometry.fromGeometry(textGeometry);

    const material = this.createColorMaterial(
          params.color);

    const text = new THREE.Mesh(
          geometry, material);
    text.scale.set(params.scale, params.scale, params.scale);

    text.position.set(
          params.position.x,
          params.position.y,
          10);




    this.intersectMeshes.push(text);
    this.viewer.impl.scene.add(text);

    this.viewer.impl.sceneUpdated(true);

    return text;
  }

Later, I try to remove this item I have added with viewer.impl.scene.remove() passing in the object I want to be removed. The problem with this is that it 1) does not remove the object 2) does not give me an error. I even add viewer.impl.sceneUpdated(true) afterwards. Am I doing this wrong? Or is there a special way you have to do this with the viewer?

Sam Curry
  • 445
  • 2
  • 11

1 Answers1

0

This definitely works fine on my side, so you must be doing something wrong ...

viewer.impl.scene.remove(mesh)
viewer.impl.sceneUpdated(true)

You can take a look at my particle demo, which definitely adds/remove a lot of custom meshes from the scene. Relevant code is there.

Felipe
  • 4,325
  • 1
  • 14
  • 19
  • I'm finding a lot of stuff is under `viewer.impl` - is this documented anywhere? – Lewy Blue Oct 30 '19 at 23:57
  • It's not, digging the unminified code would be your best option (replace version number for future releases): https://developer.api.autodesk.com/modelderivative/v2/viewers/7.5.0/viewer3D.js. Alternatively take a look at the articles from the blog: https://forge.autodesk.com/blog – Felipe Oct 31 '19 at 07:06
  • Way ahead of you :D Seems like `viewer.impl` is used in nearly every blog post and SO answer though so it's kind of strange there are no docs. Figured I must have missed them somewhere. – Lewy Blue Oct 31 '19 at 07:47
  • 1
    The reason is the "public" API is extremely limited, so as soon as you looking for a bit more advanced customization like transforms, inserting three.js meshes and so on... you very quickly have to rely on the `viewer.impl` methods. The underlying reason for that is that adsk viewer dev team didn't think that other devs will be willing to do more than loading a single model and view it, so all the useful stuff is undocumented and is likely a hack. – Felipe Oct 31 '19 at 09:56