Changing BaseColor property with Metadata Query

I was following the Template Assets guide to automate the materials and I also wanted to make the BaseColor property of the Template Material change in the similar way as other texture maps in the Advanced Setup section. I have a list of 50~ HEX coded colors that are used in 20~ material families that have DiffuseMaps in gray scale and are then multiplied with the BaseColor property and I was wondering if it would be possible to automate that, since while setting up Rules in the Logic of the Template Material, I saw that it was possible to set the BaseColor property to Metadata Query, here’s the screen:
image

In short, I am looking for a way to automate the BaseColor property without the use of the intermediary Proxy Material, as shown in the Basic Setup section of the guide.

Hi Jakub,
That’s likely a bug in the UI, because the result of the asset query (metadata query) is always an asset, NOT a color.

What you want to do can be achieved in several different ways. A simple way would be to create a color-type attribute on the catalog items, and populate it with the hex codes you already have. If you’re using a script to generate the catalog items that would be even easier than manually adding the values. That attribute can then be added to the material template as well, so that the value from the parent catalog item will propagate.
Inside the material template you can then simply assign it to the base color using the set property action.

Another way to handle this would be to store the color hex codes inside a data table spreadsheet. Unfortunately, our spreadsheet import does not allow us to convert hex codes to color attributes in the data tables. You can import that column as a string. Inside the template material you can then use data table query to read the hex codes into a local string attribute, then convert it with a custom script to a local color attribute. You can then again assign it to the base color using the set property action.
This is obviously a more complicated setup, but it does offer the ease of use of spreadsheets. The metadata fields on the items can be used to match the hex codes in the spreadsheet. The documentation includes the details on how to use the datatable query as well, and we can provide the code snippet to convert the string hex code to a color attribute in a custom code action if you’d like to go that route.

Hi Andrei,
Thanks for your reply.

The second method is precisely one of the approaches I was experimenting with, but I got stuck at the hex to color conversion. I would greatly appreciate it if you could share the mentioned code snippet for the hex to color attribute conversion.

Here’s the code snippet, written to work with an attribute HexCode of type String, and an attribute MyColor of type color.

const hex2rgb = (hex) => {

    // Remove the '#' symbol if it's present
    hex = hex.startsWith('#') ? hex.slice(1) : hex;

    const r = parseInt(hex.slice(0, 2), 16)/255;
    const g = parseInt(hex.slice(2, 4), 16)/255;
    const b = parseInt(hex.slice(4, 6), 16)/255;

    console.log(`RGB values: r=${r}, g=${g}, b=${b}`); 
    return { r, g, b };

}

api.configurator.setConfiguration ({
	'MyColor': hex2rgb(api.configuration["HexCode"])
});

Note: this function is designed to work only with the full hex code written with the 6 characters #ffffff instead of #fff.

Thank you for providing the code! I’ve tested it, and everything is working perfectly. I appreciate your assistance!

I also have a question about the following excerpt from the Template Assets Metadata Management section:

The metadata on Catalog Items would ideally be generated during the data import process, when using spreadsheets to create the catalog items.

Could you provide guidance on how to achieve this? Is it possible to do it similarly to creating Data Tables with .CSV spreadsheets, or does it only work with .JSON files since that’s the file format downloaded when exporting items? The phrase “using spreadsheets to generate catalog items” suggests that it is indeed possible. However, when I attempted it, nothing seemed to happen. It’s unclear whether this is because it’s not possible with .CSV files, if I didn’t set up the spreadsheet correctly, or if there’s another issue entirely.

Generating entirety of the catalogue items with pre-assigned metadata values through a spreadsheet would be a significant time saver.

Unfortunately we do not have that functionality available in the platform UI yet. This can be accomplished using a custom web application. We normally write these custom web apps that make use of our REST APIs to generate the catalog data from an imported Data Table.

I do plan to create a general app for this at some point next year, but we do hope to add this functionality into the platform eventually. If you need this done right now, you would need to build your own custom web app.

Here’s the link to our REST APIs that can be used for this purpose:
https://developer.threekit.com/reference/available-apis

We will soon also post a guide there on how to write custom web apps for ThreeKit projects. We do offer the option to deploy the app for you, and would provide you with a GitHub repo if you make the request through ThreeKit Support.

I will reword that Guide doc to avoid this confusion. Thank you for the heads-up :).