简体   繁体   English

添加 Autodesk forge 扩展

[英]Adding a Autodesk forge extension

Hi I'm trying to add a forge extension in my viewer but I don't know what I have missed.您好我正在尝试在我的查看器中添加一个伪造扩展,但我不知道我错过了什么。

I followed this article: https://forge.autodesk.com/blog/loading-external-extensions-forge-viewer我关注了这篇文章: https://forge.autodesk.com/blog/loading-external-extensions-forge-viewer

This is my code:这是我的代码:

 <body>

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


  <script>
      var myViewerDiv = document.getElementById('MyViewerDiv');
      var viewer = new Autodesk.Viewing.Private.GuiViewer3D(myViewerDiv);
      var options = {
          'env' : 'Local',
          'document' : './modelV4/hahahah/4/output.svf',

      };
      Autodesk.Viewing.Initializer(options, function() {
        viewer.start(options.document, options);
      });
      Autodesk.Viewing.theExtensionManager.registerExternalExtension(
  'MyExternal.Extension.Id',
  'http://localhost:3000/js/external.js')
  viewer.addEventListener(
  Autodesk.Viewing.GEOMETRY_LOADED_EVENT, () => {

    viewer.loadExtension('MyExternal.Extension.Id').then(
      function(externalExtension) {

        externalExtension.sayHello('Bob')
      })
  })
  </script>

</body>

and this is my path:这是我的道路:

在此处输入图像描述

With more recent version of Viewer the method described in that article no longer works - you'd need to pass in the extension class/function the directly instead of a link to the extension script:对于更新版本的查看器,该文章中描述的方法不再有效 - 您需要直接传递扩展类/函数而不是指向扩展脚本的链接:

  /**
     * Registers a new extension with the given id.
     *
     * @param {string} extensionId - The string id of the extension.
     * @param {Extension} extension - The Extension-derived class representing the extension.
     * @returns {boolean} - True if the extension was successfully registered.
     * @alias Autodesk.Viewing.ExtensionManager#registerExtension
     */
    function registerExtension(extensionId, extension) {

Follow this tutorial here to get started... 在此处按照本教程开始...

If you'd like to wrap your extension code in another script simply load it with a script tag after the Viewer libraries...:如果您想将扩展代码包装在另一个脚本中,只需在查看器库之后使用脚本标记加载它...:

<script src='https://developer.api.autodesk.com/modelderivative/v2/viewers/viewer3D.min.js'></script>
<script src='path/to/your/extension.js'></script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM