我使用 THREE.Shape 创建了一个简单的圆圈并将其着色为绿色。
但是我希望更改颜色,使其从绿色(中间)变为红色(边框)。
我一直在看 this 中的一个例子网站,但我不明白如何为我的项目实现类似的方式。
创建圆圈的代码:
var arcShape = new THREE.Shape();
arcShape.absarc(100, 100, circleRadius, 0, Math.PI * 2, false);
var geometry = new THREE.ShapeGeometry(arcShape);
var material = new THREE.MeshBasicMaterial({ color: 0x00ff11, overdraw: 0.5, side: THREE.DoubleSide });
var mesh = new THREE.Mesh(geometry, material);
mesh.position = CirclePosition;
mesh.rotation.set(Algorithms.ConvertDegreesToRadians(-90), 0, 0);
最佳答案
另一种方法是使用顶点颜色
var colorRed = new THREE.Color (0.9, 0.0, 0.0);
var colorGreen = new THREE.Color (0.0, 0.9, 0.0);
material = new THREE.MeshBasicMaterial({ vertexColors: THREE.VertexColors});
geometry = new THREE.CircleGeometry(100, 10, 0, 3);
var nmax = geometry.faces.length;
for (var n=0; n<nmax; n++) {
geometry.faces[n].vertexColors[0] = colorRed;
geometry.faces[n].vertexColors[1] = colorRed;
geometry.faces[n].vertexColors[2] = colorGreen;
}
关于javascript - 三、形状从绿色到红色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23422189/