我使用十六进制值设置几何颜色
RichGeometry.prototype = new THREE.Geometry();
RichGeometry.prototype.constructor = RichGeometry;
function RichGeometry(c) {
c = typeof c !== 'undefined' ? c : 0x00C020; // color
THREE.Geometry.call(this);
this.color = c;
}
但是当我从创建的对象中获取值时,它返回一个 RGB 值,如 16711680。为什么?如何获取十六进制值?
var geometry0 = new RichGeometry(0xff0000);
console.log(geometry0.color);// it returns rgb value like this 16711680
最佳答案
您可以将颜色存储为 THREE.Color
的实例:
function RichGeometry(c) {
c = (typeof c !== 'undefined') ? c : 0x00C020;
THREE.Geometry.call(this);
this.color = new THREE.Color(c);
}
然后您可以使用 THREE.Color
上的方法检索颜色的不同表示形式。对于您的示例,请尝试:
var geometry0 = new RichGeometry(0xff0000);
console.log('0x' + geometry0.color.getHexString());
关于javascript - Threejs 几何颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29829382/