Forge Viewer:Autodesk.BoxSelection 扩展错误 [英] Forge Viewer: Autodesk.BoxSelection extension bug

查看:33
本文介绍了Forge Viewer:Autodesk.BoxSelection 扩展错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我工作的项目(React、TS)中,我们使用查看器并为其添加了框选择扩展.

On the project where I work (React, TS), we use the viewer and added the Box Selection extension for it.

第一次使用工具栏中的按钮激活它时,扩展工作,元素被突出显示.然后您可以切换到另一种模式,例如轨道模式.之后,当您单击激活框选择扩展"的按钮时,该扩展将不再起作用.轨道模式仍然有效.

The first time you activate it with a button in the toolbar, the extension works, the elements are highlighted. Then you can switch to another mode, for example, the orbit mode. And after that, when you click on the button that activates the "box Selection extension", the extension no longer works. The orbit mode remains working.

同时,按钮被点击(console.log() 被触发)并且 loadExtension('Autodesk.Box Selection') 方法起作用.

At the same time, the button is clicked (console.log() is fired) and the loadExtension('Autodesk.Box Selection') method works.

可能是什么问题?

我会给出一些代码片段

这是扩展代码:

export default function RectangleSelectionExtension(
  this,
  viewer,
  options,
) {
  window.Autodesk.Viewing.Extension.call(this, viewer, options);
}
RectangleSelectionExtension.prototype = (
  Object.create(window.Autodesk.Viewing.Extension.prototype)
);

RectangleSelectionExtension.prototype.constructor = RectangleSelectionExtension;
RectangleSelectionExtension.prototype.load = () => true;
RectangleSelectionExtension.prototype.unload = () => true;
RectangleSelectionExtension.prototype.onToolbarCreated = function onToolbarCreated() {
  this.group = this.viewer.toolbar.getControl('allExtensionsToolbar');
  if (!this.group) {
    this.group = new window.Autodesk.Viewing.UI.ControlGroup('allExtensionsToolbar');
    this.viewer.toolbar.addControl(this.group);
  }
  // Add a new button to the toolbar group
  this.button = new window.Autodesk.Viewing.UI.Button('RectangleSelectionExtension');
  this.button.onClick = async () => {
    const boxSelectionExtension = await this.viewer.loadExtension('Autodesk.BoxSelection');
    this.viewer.toolController.activateTool(boxSelectionExtension.boxSelectionTool.getName());
    boxSelectionExtension.addToolbarButton(this.viewer);
  };
  this.button.setToolTip('Select within a rectangle area');
  this.button.addClass('RectangleSelectionExtension');
  this.group.addControl(this.button);
};
window.Autodesk.Viewing.theExtensionManager.registerExtension('BoxSelection', RectangleSelectionExtension);

接下来,在查看器组件中,我们导入并注册扩展:

Next, in the Viewer component, we import and register the extension:

window.Autodesk.Viewing.theExtensionManager.registerExtension('RectangleSelectionExtension', RectangleSelectionExtension);

这就是我们初始化查看器的方式:

And this is how we initialize the viewer:

  window.Autodesk.Viewing.Initializer(options, () => {
    const container = document.getElementById('forgeViewer');
    if (container) {
      viewer = new window.Autodesk.Viewing.GuiViewer3D(
        container,
        {
          token,
          extensions: [
            /* ...some extensions */
            'RectangleSelectionExtension',
          ],
        },
      );
      const startedCode = viewer.start();
      if (startedCode > 0) {
        return;
      }
      /* ...some eventListeners */
   }

推荐答案

我不确定我是否理解您的 RectangleSelectionExtension 的用途.从代码看它只是在工具栏中添加了一个按钮,然后单击该按钮重复加载另一个扩展程序(Autodesk.BoxSelection),重复激活框选择工具,并重复添加框选择按钮到工具栏.这似乎不对.

I'm not sure I understand the purpose of your RectangleSelectionExtension. From the code it looks like it just adds a button in the toolbar, and clicking that button repeatedly loads another extension (Autodesk.BoxSelection), repeatedly activates the box selection tool, and repeatedly adds the box selection button to the toolbar. That doesn't seem right.

如果您只是对框选择感兴趣,您可以像这样加载它(并将其包含在工具栏中):

If you're simply interested in the box selection, you can load it (and include it in the toolbar) like so:

// ...

viewer = new window.Autodesk.Viewing.GuiViewer3D(
    container,
    {
        token,
        extensions: [
            /* ...some extensions */
            'Autodesk.BoxSelection',
        ]
    }
);

// and later ...

const boxSelectionExt = viewer.getExtension('Autodesk.BoxSelection');
boxSelectionExt.addToolbarButton(true); // Add the button to the toolbar
boxSelectionExt.addToolbarButton(false); // Remove the button from the toolbar

// ...

这篇关于Forge Viewer:Autodesk.BoxSelection 扩展错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆