首页 > 解决方案 > 伪造查看器房间颜色更改不起作用

问题描述

我有一个级别列表,单击每个级别都会显示房间。我想更改每个房间对象的颜色。我尝试使用以下代码片段:

var selSet1 = NOP_VIEWER.getSelection();
NOP_VIEWER.clearSelection();
var color = new THREE.Color( 255 / 255, 0, 0, 1 );
for( let i = 0; i < selSet1.length; i++ ) {
    NOP_VIEWER.setThemingColor( selSet1[i], color );
}


Autodesk.Viewing.Viewer3D.prototype.setColorMaterial = function(objectIds, color){
  if( !(color instanceof THREE.Color) ) throw 'Invalid argument: Color';
    var material = new THREE.MeshPhongMaterial
      ({
        color:      color,
        opacity:    0.8,
        transparent: true
      });
    NOP_VIEWER.impl.matman().addMaterial( 'ColorMaterial-' + new Date().getTime(), material, true );
};

两者都没有工作,你能帮我解决这个问题吗?

标签: autodesk-viewer

解决方案


该函数的第二个参数viewer.setThemingColor只接受THREE.Vector4,这就是它不适合你的原因。您必须将代码更改为这种方式,请在此处查看答案:

var selSet1 = NOP_VIEWER.getSelection();
NOP_VIEWER.clearSelection();
var color = new THREE.Vector4( 255 / 255, 0, 0, 1 );
for( let i = 0; i < selSet1.length; i++ ) {
    NOP_VIEWER.setThemingColor( selSet1[i], color );
}

这是查看器文档:https ://developer.autodesk.com/en/docs/viewer/v2/reference/javascript/viewer3d/

希望能帮助到你。


推荐阅读