gpt4 book ai didi

javascript - Threejs 几何颜色

转载 作者:行者123 更新时间:2023-12-03 10:17:00 28 4
gpt4 key购买 nike

我使用十六进制值设置几何颜色

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/

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