简体   繁体   English

在 Autodesk.Viewing.Viewer3D 中显示上下文菜单

[英]Show context menu in Autodesk.Viewing.Viewer3D

I am trying to show a context menu using Autodesk.Viewing.Viewer3D (Headless Viewer).我正在尝试使用 Autodesk.Viewing.Viewer3D(无头查看器)显示上下文菜单。

I can get the context menu to show up easily when using Autodesk.Viewing.Private.GuiViewer3D as my viewer type but i don't want to use this viewer type as it has a toolbar and i don't want it to appear for this viewer.使用 Autodesk.Viewing.Private.GuiViewer3D 作为查看器类型时,我可以轻松显示上下文菜单,但我不想使用此查看器类型,因为它有一个工具栏,我不希望它为此出现观众。 I can't use the css approach suggested here as I also want the toolbar in a different viewer in the same application.我不能使用此处建议的 css 方法,因为我还希望在同一应用程序中使用不同查看器中的工具栏。

My attempt to initialise a context menu using Autodesk.Viewing.Viewer3D (Headless Viewer) look like the following:我尝试使用 Autodesk.Viewing.Viewer3D(无头查看器)初始化上下文菜单如下所示:

var contextMenu = new Autodesk.Viewing.UI.ObjectContextMenu(viewer);
        viewer.setContextMenu(contextMenu);
        viewer.registerContextMenuCallback('CustomContextMenuItems', function (menu, status) {
            if (status.hasSelected) {
                if(menu === null){menu=[];}
                while (menu.length > 0) {
                    menu.pop();
                }

                menu.push({
                    title: 'Do Something',
                    target: function () {
                        console.log("Doing something")
                    }
                });

            } 
        });

The context menu is intended to be used with GuiViewer3D .上下文菜单旨在与GuiViewer3D一起使用。 It's most likely relying on some of its HTML or CSS setup, which is why it's causing issues with Viewer3D .它很可能依赖于它的一些 HTML 或 CSS 设置,这就是它导致Viewer3D问题的原因。 If you need this level of customization of the GUI, I'd suggest to implement a separate, simple context menu instead of bending the built-in one.如果您需要这种级别的 GUI 自定义,我建议您实现一个单独的、简单的上下文菜单,而不是弯曲内置的菜单。

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

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