Trying to add custom mesh to offline viewer

I try to add a custom sphereMesh to a offline viewer. I saw this can be done with the online version of the viewer. But I get an uncaught TypeError: Cannot read property 'Add' of undefined if I try this in my viewer.

<div id="MyViewerDiv"></div>

    <script>
           var myViewerDiv = document.getElementById('MyViewerDiv');
            var viewer = new Autodesk.Viewing.Private.GuiViewer3D(myViewerDiv);
      var options = {
          'env' : 'Local',
         'document' : './_3D_ 197440/_3D_.svf'
      };
    
      Autodesk.Viewing.Initializer(options, function() {
        viewer.start(options.document, options);
      });

     var geom = new THREE.SphereGeometry(1000, 8, 8);
     var material = new THREE.MeshBasicMaterial({ color: 0xff0000 });
     var sphereMesh = new THREE.Mesh(geom, material);
    
     sphereMesh.position.set(0, 0, 0);
     viewer.impl.scene.add(sphereMesh);
 
    </script>

Answers:

Answer

There is no difference between online and offline viewer, when it comes to ways of adding custom geometry. In your case you have a situation similar to "race condition", where you try to use a resource while it is initializing: sometimes the init process finishes first => success, sometimes it finishes later => get errors.

To solve the problem, there are 2 approaches:

  1. Add your code into an extension and load extension as mentioned in documentation (the recommended one). Example: https://apprentice3d.github.io/SD226781-Samples/02.html
  2. Move your custom mesh code into the body of the document loading callback function. Example: Check the source of https://s3.amazonaws.com/sample-collection/GiroWatch_Latest.html

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.