更改Autodesk Forge Viewer隐藏元素的材质 [英] Change material of hidden elements of Autodesk Forge viewer

查看:241
本文介绍了更改Autodesk Forge Viewer隐藏元素的材质的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想更改观看者隐藏的元素的材质(THREE.MeshPhongMaterial).默认的隐藏元素仍然可见,但是我想更改其透明度和颜色.

I would like to change material (THREE.MeshPhongMaterial) of elements which were hidden by the viewer. The default hidden elements are still visible, but I want to change their transparency and color.

这是示例代码.我尝试更改主题颜色和材料,但没有成功:

Here is the example code. I tried to change both theming color and material but no success:

viewer.hideById(dbId);

var color = 0x0000ff; // blue color
viewer.setThemingColor(dbId, color, viewer.model);

var instanceTree = viewer.model.getData().instanceTree;
var fragmentList = viewer.model.getFragmentList();

instanceTree.enumNodeFragments(dbId, function (fragId) {
    fragmentList.setMaterial(fragId, new THREE.MeshPhongMaterial( { opacity: 0.5 } ));
});

viewer.impl.invalidate(true);

但是,更新隐藏元素的材料后,什么都没有改变.如何解决.我希望我的自定义隐藏元素具有不同的颜色和透明度.

However, nothing is changed after updating materials of hidden elements. How to fix that. I want my custom hidden elements with different colors and transparency.

推荐答案

使用Forge Viewer,如果您隐藏对象(如Augusto所述),则似乎该对象将被完全隐藏,您无法设置材质来查看它如你所愿.但是,有一个技巧可以解决您在 http://app.netonapp.com/JavaScript/Three.js/select_inner_objects.html ,您可以选择内部对象,但仍然可以看到外部隐藏"对象.

With Forge Viewer, if you hide an object, as Augusto mentioned, it seems that the object will be completely hidden, you can not set the material to see it as you want. But, there is a trick workaround may help to achieve what you did with Three.js in http://app.netonapp.com/JavaScript/Three.js/select_inner_objects.html, you can select the inside object, and still can see the outside "hidden" object.

我所做的很简单,在"mousedown"事件的回调函数中,我要做的第一件事是将外部对象设置为由API viewer.hideById(dbId)隐藏,然后由您的API查看器选择该对象. impl.renderer().idAtPixel.在这种情况下,它将忽略隐藏的对象而只选择内部对象,并在"SELECTION_CHANGED_EVENT"事件的函数中,添加代码查看器.show(dbid)以显示外部对象

What I did is simple, within the callback function of "mousedown" event, the first thing I did is to set the outside object hidden by API viewer.hideById(dbId), then to select the object by your API viewer.impl.renderer().idAtPixel. In this case, it will ignore the hidden object and just select the inside object. And in the function of "SELECTION_CHANGED_EVENT" event, I added the code viewer.show(dbid) to show the outside object.

通过这种方式,您可以根据需要为外部对象设置材质,外部对象将显示为其他普通对象,但是当您尝试选择对象时,它将仅隐藏一段时间.该解决方案似乎对我有效,但是我没有对其进行彻底的测试,您可以尝试看看是否可行.

By this way, you can set the material as you want for the outside object, the outside object will be shown as other normal objects, but it will be just hidden for a while when you try to select object. The solution seems working on my side, but I did not test it thoroughly, you can try to see if it works.

这篇关于更改Autodesk Forge Viewer隐藏元素的材质的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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