gpt4 book ai didi

javascript - 三人组 : assign different colors to each vertex in a geometry

转载 作者:行者123 更新时间:2023-12-03 01:31:11 27 4
gpt4 key购买 nike

我想通过 Three.js 中的 IdMapping 进行挑选

由于性能问题,我只有一个巨大的几何图形,计算如下:

for (var i = 0; i < numberOfVertices; i += 9) {
p1 = new THREE.Vector3(graphData.triangles.vertices[i+0], graphData.triangles.vertices[i+1], graphData.triangles.vertices[i+2]);
p2 = new THREE.Vector3(graphData.triangles.vertices[i+3], graphData.triangles.vertices[i+4], graphData.triangles.vertices[i+5]);
p3 = new THREE.Vector3(graphData.triangles.vertices[i+6], graphData.triangles.vertices[i+7], graphData.triangles.vertices[i+8]);
geometry.vertices.push(new THREE.Vertex( p1.clone() ));
geometry.vertices.push(new THREE.Vertex( p2.clone() ));
geometry.vertices.push(new THREE.Vertex( p3.clone() ));
geometry.faces.push( new THREE.Face3( i/3, i/3+1, i/3+2 ) );

// i want to do something like this:
geometry.colors.push(new THREE.Color(0xFF0000));
geometry.colors.push(new THREE.Color(0xFF0000));
geometry.colors.push(new THREE.Color(0xFF0000));
}

geometry.computeFaceNormals();
var material = new THREE.MeshBasicMaterial({});

var triangles = new THREE.Mesh( geometry, material );
scene.add(triangles);

如何为几何体中的每个顶点指定不同的颜色?

最佳答案

它必须是geometry.vertexColors而不是geometry.colors(为每个顶点推送一个颜色)。

Material :

material = new THREE.MeshBasicMaterial({ vertexColors: THREE.VertexColors });

关于javascript - 三人组 : assign different colors to each vertex in a geometry,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10330342/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com