Skip to content

colors.push(new THREE.Color(colorToHex(color))) cannot accept colour in string hex format #3

@mrmikearmstrong

Description

@mrmikearmstrong

THREE.Color cannot accept args in the form of HEX strings e.g #FF0000

Solution:
Modify colorToHex to return in the form of int

      function colorToHex(color) {
        if (color.substr(0, 1) === '0x') {
          return color;
        }
        var digits = /(.*?)rgb\((\d+),(\d+),(\d+)\)/.exec(color);

        var red = parseInt(digits[2]);
        var green = parseInt(digits[3]);
        var blue = parseInt(digits[4]);

        var rgb = blue | (green << 8) | (red << 16);
        var z = digits[1] + '0x' + rgb.toString(16);
		
		var colorValue = parseInt(z.replace("#","0x"), 16 );
		return colorValue;
      }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions