Forge观看者房间的颜色更改无法正常工作

时间:2018-06-25 09:48:30

标签: autodesk-viewer

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

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 );
};

两个都没有用,请您帮我一下。

1 个答案:

答案 0 :(得分:0)

函数viewer.setThemingColor的第二个参数仅接受THREE.Vector4,这就是为什么它对您不起作用的原因。您必须将代码更改为这种方式,然后检查答案here

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 );
}

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

希望有帮助。