如何在Autodesk Forge Viewer中更改选择颜色?

时间:2019-02-25 21:22:20

标签: autodesk-forge autodesk-viewer

在Forge Viewer v3中,我们设置了所选内容的颜色,如下所示:

onRequestClick(e) {
  const THREE_RED_COLOR = new THREE.Color(1, 0, 0);
  NOP_VIEWER.impl.setSelectionColor(THREE_RED_COLOR);
  NOP_VIEWER.select($(e.target).parent().find(`th`).data(`attributes`));
}

在v6中,此代码仍然按预期选择查看器对象,但是选择颜色保持默认的蓝色,并且没有按预期更改为红色。 现在是否通过其他方法完成此更改?还有其他我想念的东西吗?

3 个答案:

答案 0 :(得分:1)

尝试使用查看器viewer.clearSelection(); viewer.set2dSelectionColor(red)

其中viewer=NOP_VIEWER; red = new THREE.Color(1,0,0)

可以解决吗?

答案 1 :(得分:0)

当我尝试使用Viewer v6.4.2时,您的代码工作正常:

viewer.impl.setSelectionColor(new THREE.Color(1, 0, 0));
viewer.addEventListener(Autodesk.Viewing.GEOMETRY_LOADED_EVENT,()=>viewer.select(1))

查看实际情况here

您可能想在浏览器控制台中再次尝试相关代码,以找出问题所在。

编辑

如果您查看源代码,它会明确指出它仅适用于3D模型:

/**
     * Changes the color of the selection for 3D models.
     * 
     * @example
     *  viewer.setSelectionColor(new THREE.Color(0xFF0000)); // red color
     * @param {THREE.Color} color
     * 
     * @alias Autodesk.Viewing.Viewer3D#setSelectionColor
     */
    Viewer3D.prototype.setSelectionColor = function(color, selectionType) {
        this.impl.setSelectionColor(color, selectionType);
    };

还将向Engineering记录功能请求,以将该功能也移植到2D模型中。

答案 2 :(得分:0)

我确认它不适用于2D文件。 这是我的尝试的屏幕截图。

我在2个圆上调用了get Selection。确认观众参与其中,并且我能够检测到其他选择。

然后,当我调用setSelectionColor函数时,什么也没发生。

enter image description here