【问题标题】:How do you change selection color in the autodesk forge viewer?如何在 Autodesk Forge 查看器中更改选择颜色?
【发布时间】:2019-07-19 08:50:50
【问题描述】:

在 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 中,此代码仍按预期选择查看器对象,但选择颜色保持默认蓝色,不会按预期更改为红色。 现在这个改变是通过不同的方法完成的吗?我还有什么遗漏的吗?

【问题讨论】:

    标签: autodesk-forge autodesk-viewer


    【解决方案1】:

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

    在哪里viewer=NOP_VIEWER; red = new THREE.Color(1,0,0)

    这样能解决吗?

    【讨论】:

    • 嗨 Michale,有没有办法将 Alpha 通道传递给选择颜色?
    【解决方案2】:

    当我尝试使用 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 模型。

    【讨论】:

    • 您的示例使用的是 3D 查看器,这段代码使用 2D 查看器是否有所不同? (抱歉,忘记在我原来的帖子中提到这是 2D)另外,我使用控制台记录了该函数,它看起来接受了 2 个参数,而不是 1 ƒ (e,t){var n=new O.Color(e);n.multiplyScalar(.5);var i=function(t){t.color.set(e),t.emissive.set(n)};i(this.selectionMaterialBase),i(this.selectionMaterialTop),this.selectionMaterialBase.variants&&thi…
    【解决方案3】:

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

    我在 2 个圆圈上调用了 get Selection。确认观看者参与其中并且我能够检测到不同的选择。

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

    【讨论】:

    • 对于2d sheet,设置选择颜色的方法是:NOP_VIEWER.set2dSelectionColor(new THREE.Color(1,1,1))
    猜你喜欢
    • 2020-10-27
    • 2018-11-01
    • 2023-03-06
    • 2021-11-12
    • 1970-01-01
    • 2020-09-24
    • 2021-04-26
    • 2021-09-19
    • 2020-07-05
    相关资源
    最近更新 更多