添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I'm trying to set the hsl color for a mesh in THREE.js using a variable to represent the color, so that I can eventually apply a changeable color palette to the faces. For now I'm just trying to get it to work with one color.

I am able to get it to display properly when I directly set the color:

for ( var i = 0; i < geometry.faces.length; i ++ ) {
    var face = geometry.faces[ i ];
    face.color.setHSL(.74, .64, .59);}

But when I try to put the color value into a variable, it gives me a NaN result in the console. example code:

for ( var i = 0; i < geometry.faces.length; i ++ ) {
    var face = geometry.faces[ i ];
    color1 = [0.74, 0.64, 0.59];
    face.color.setHSL(color1);
    console.log(face.color);

I would appreciate any advice!

The setHSL function of Color accepts 3 arguments, you are sending it an array in the second loop you posted. – 2pha May 3, 2018 at 0:05 so I need to break the value into 3 separate variables. Is there a way to pass an array in as separate arguments? – glaemart May 3, 2018 at 0:18

The setHSL function of Color accepts 3 arguments, you are sending it an array in the second loop you posted.
face.color.setHSL(color1[0], color1[1], color1[2]);

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.