Asset Json Configuration

Hi,
we have created a material asset which take basecolor as input attribute.
in Catalogue item we are passing the json with hexcode and it works fine
{“BaseColor”:"#640E0F"}.

How we can pass the same with RGB?

I have tried this but didn’t work
{“BaseColor”:“176,18,31”}
{“BaseColor”:"[176,18,31]"}

You can specify each segment of the color:

{BaseColor: {r: 176, g: 18, b: 31}}

You can also write code to convert RGB to hex if you can only get RGB.

function componentToHex(c) {
  var hex = c.toString(16);
  return hex.length == 1 ? "0" + hex : hex;
}

function rgbToHex(r, g, b) {
  return "#" + componentToHex(r) + componentToHex(g) + componentToHex(b);
}

rgbToHex(176,18,31) // "#b0121f"

Thanks Will. I tried updating the json confoguratin in Catalogue items but it didn;t work. I tried the follwoing

{“BaseColor”: “{r: 176, g: 18, b: 31}”}
and

{“BaseColor”: {“r: 176, g: 18, b: 31”}}

For clarification, you are attempting to set the configuration of the asset in your embed with the API, correct?

Please notice the differences in the objects below, the first example will not work when calling setConfiguration but the second one will. I believe the issue lies in your use of quotation marks - the first example will create a string inside of the object rather than being a proper object.

{“BaseColor”: "{r: 176, g: 18, b: 31}"} - incorrect
{BaseColor: {r: 176, g: 18, b: 31}} - correct

Hello Will,
I am trying to setup the configuration in the catlogue item,
We have created a Material with Color as Attribute.
now we have to create multiple catalogue items for the different colors. I am able to do so if I pass the configuration in Hex code. But the client has given RGB code. so need to code sample, I am using the following for Hex Code and its working fine.
{“BaseColor”:"#547A54"}

Hi @Prashant I’m not sure I understand, I apologize. Are you having trouble converting colors from RGB as provided by your client to Hex? Or would you like to set the colors with RGB colors on the platform?

I am not having issues converting color from RGB to Hex.
i am not sure how to set color on platform with RGB colors.

  1. We have created a Generic Material which has baseColor as attribute.
    https://preview.threekit.com/o/rimadesio/assets/596166d6-0a7a-498d-b668-c6d621ba97f7
  2. We are creating multiple Catalogue items by setting the “Asset Json Configuration”. I am passing {“BaseColor”:"#3a4352"} in the Asset Json Configuration and it works fine. I was passing Hex code so far. Now i need to set the color by passing RGB value in “Asset Json Configuration”.
    https://preview.threekit.com/o/rimadesio/items/aec10fea-51eb-4d99-b8bb-1993e86ee177
    image

So i need help in the syntax to pass the RGB color in Asset JSON configuration to create multiple colors[catalouge item] using same material.

I cloned the material you linked to test, you can find it here.

On the Asset JSON Configuration you will have to divide each RGB value by 255 before entering it in the form, the JSON syntax like this works:
{"BaseColor": {"r": 0.48235294117,"g": 0.12156862745, "b": 0.12156862745}}

RGB are 8 bit each. The range for each individual color is 0-255. The combination range is 256x256x256. By dividing by 255, the 0-255 range can be described with a 0.0-1.0 range where 0.0 means 0 (0x00) and 1.0 means 255 (0xFF).

I hope this helps!

thanks Will… it is working fine.

1 Like