You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用SceneBuilder添加的模型临时隐藏对象无效果的技术咨询

问题分析与解决办法

你当前的思路走偏了,不要通过修改材质的visible属性来隐藏模型对象——这不是Viewer里隐藏对象的正确方式,而且Three.js材质的visible属性在Viewer的渲染逻辑中可能被覆盖,导致设置后没效果。

给你两个可行的处理方案:

方案1:直接操作对象的可见性(推荐)

直接定位到要隐藏的模型对象,修改它自身的visible属性,这是最直接可靠的方式:

// 替换成你要隐藏的对象ID
const targetObj = this.customModel.findObject(targetObjectId);
if (targetObj) {
  targetObj.visible = false;
  this.customModel.sceneUpdated();
  this.viewer.impl.invalidate(true, true, true);
}

方案2:如果一定要通过材质控制(不推荐)

如果你坚持要通过材质实现,需要注意两个关键点:

  1. 不能用扩展运算符...克隆材质,Three.js材质包含大量内部属性,必须用clone()方法才能完整复制:
const existingMaterial = this.customModel.findMaterial(id);
const newMaterial = existingMaterial.clone();
newMaterial.visible = false;
// 额外开启透明并设置透明度为0,避免残留渲染
newMaterial.transparent = true;
newMaterial.opacity = 0;

const res = this.customModel.changeMaterial(existingMaterial, newMaterial);
this.customModel.sceneUpdated();
this.viewer.impl.invalidate(true, true, true);
  1. 这种方式依然可能因为Viewer的材质缓存、渲染优先级等问题失效,所以优先推荐方案1。

另外提个小细节:你代码里的exstingMaterial拼写错误,正确应为existingMaterial,虽然不影响运行,但规范拼写能避免后续排查问题时的干扰。

内容的提问来源于stack exchange,提问作者Takahiro Matsumoto

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.01 07:26:00