Tutorial: 如何改变模型构件的显示状态?

如何改变模型构件的显示状态?

待模型添加完成以后,可以通过调用API使构件的显示状态发生变化。

// 添加待显示的模型或图纸
viewer3D.addView(viewToken);

// 待模型添加完成以后,监听ViewAdded事件
viewer3D.addEventListener(Glodon.Bimface.Viewer.Viewer3DEvent.ViewAdded, function(){

    // 手动render
    viewer3D.render();

    // *******************
    // 举例:在下文中编写改变模型构件显示状态的代码,其中"x1"、"x2"表示构件的ObjectId
    // *******************

    // 显示构件
    viewer3D.showComponents(["x1", "x2"]);

    // 隐藏构件
    viewer3D.hideComponents(["x1", "x2"]);

    // 显示所有构件
    viewer3D.showAllComponents();

    // 改变构件的颜色
    var redColor = new Glodon.Web.Graphics.Color(255, 0, 0, 1);
    viewer3D.overrideComponentsColorById(["x1", "x2"], redColor);

    // 恢复构件原来的颜色
    viewer3D.restoreComponentsColorById(["x1", "x2"]);

    // 设置构件半透明
    viewer3D.setComponentsOpacity(["x1", "x2"], Glodon.Bimface.Viewer.OpacityOption.Translucent);

    // 取消构件半透明
    viewer3D.setComponentsOpacity(["x1", "x2"], Glodon.Bimface.Viewer.OpacityOption.Opaque);

    // 设置构件加入选择集,加入后,构件高亮
    viewer3D.setSelectedComponentsById(["x1", "x2"]);

    // 继续添加构件到选择集
    viewer3D.addSelectedComponentsById(["x3", "x4"]);

    // 把构件从选择集中移除
    viewer3D.removeSelectedId(["x1", "x2", "x3", "x4"]);

    // 隔离构件,其他全部隐藏、半透明
    viewer3D.isolateComponentsById(["x1", "x2"], Glodon.Bimface.Viewer.IsolateOption.HideOthers);
    viewer3D.isolateComponentsById(["x1", "x2"], Glodon.Bimface.Viewer.IsolateOption.MakeOthersTranslucent);

    // 根据筛选条件隔离构件,下面是隔离出categoryId=-2001340,且levelName=F01的构件
    var conditions = {"categoryId":-2001340, "levelName":"F01"};
    viewer3D.isolateComponentsByObjectData(conditions, Glodon.Bimface.Viewer.IsolateOption.HideOthers);
});