【问题标题】:How to dynamically change vertex colors in Three JS如何在三个 JS 中动态更改顶点颜色
【发布时间】:2021-08-01 22:01:08
【问题描述】:

我正在通过 STL 加载器添加模型元素,并且可以在那里设置顶点颜色。稍后我还需要更改此颜色,并且我正在尝试通过以下代码进行更改。不幸的是颜色没有改变。有人知道怎么改吗?

let geometry = this.scene.getObjectByName("myFile.stl").geometry   
const color = new THREE.Color(0xFF0000);  
// @ts-ignore 
for(let idx = 0; idx < geometry.attributes.color.count; idx++) 
{ 
    // @ts-ignore 
    geometry.getAttribute("color").setXYZ( idx, color.r, color.g, color.b ) 
}

【问题讨论】:

    标签: typescript three.js


    【解决方案1】:

    更改值后,您必须将缓冲区属性的needsUpdate 标志设置为true。试试看:

    let geometry = this.scene.getObjectByName("myFile.stl").geometry; 
    const color = new THREE.Color(0xFF0000);  
    const colorAttribute = geometry.getAttribute("color");
    for(let idx = 0; idx < colorAttribute.count; idx++) 
    { 
        // @ts-ignore 
        colorAttribute.setXYZ( idx, color.r, color.g, color.b ) 
    }
    colorAttribute.needsUpdate = true;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-07-31
      • 1970-01-01
      • 2017-10-07
      • 2021-10-11
      • 1970-01-01
      • 2018-01-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多