简体   繁体   English

Forge Viewer:Autodesk.BoxSelection 扩展错误

[英]Forge Viewer: Autodesk.BoxSelection extension bug

On the project where I work (React, TS), we use the viewer and added the Box Selection extension for it.在我工作的项目(React、TS)中,我们使用查看器并为其添加了 Box Selection 扩展。

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.轨道模式仍然有效。

At the same time, the button is clicked ( console.log() is fired) and the loadExtension('Autodesk.Box Selection') method works.同时,单击按钮( console.log()被触发)并且loadExtension('Autodesk.Box Selection')方法起作用。

What could be the problem?可能是什么问题呢?

I will give some code snippets我将给出一些代码片段

This is the extension code:这是扩展代码:

 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:接下来,在 Viewer 组件中,我们导入并注册扩展:

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 */
   }

I'm not sure I understand the purpose of your RectangleSelectionExtension .我不确定我是否理解您的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.从代码看来,它只是在工具栏中添加了一个按钮,然后单击该按钮重复加载另一个扩展 ( Autodesk.BoxSelection ),重复激活框选择工具,并将框选择按钮重复添加到工具栏中。 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

// ...

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

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