Palette swapping for items

Yang’s recent live stream on building palettes got me thinking about palette swaps for items. I seem to recall seeing something about it in some discussion and/or live stream last year, but perhaps I just dreamed it up.

Anyway, the idea would be to build the .qb files with a particular palette, then allow it to be swapped out at build time by some sort of selector in the workbench menu. It would be in order to reuse models easily, like swapping out banner or bed blanket colors, for example.

Does anyone know if there is some sort of current support for that or something on the horizon?

I’m just getting back into modding after a long hiatus and trying to think of ways to simplify tedious rebuild of several items with explicit palette swaps in Qubicle and multiple sets of .json files.

1 Like

currently all the hair models use palette swapping, and it could probably be applied to any model… but i have no clue how or anything like that, maybe @Drotten could be of more help than me?

Thanks, I’ll take a look there. I was under the impression there were just multiple models with a “one of” randomizer.

well it used to be that way, but the team added palette swapping for hair awhile back :smile:

Yeah, that does look like what I need. I hadn’t dug around in the people since about September, and I was just poking around this week in the furniture and decorations wondering if color selection had been implemented for things like comfy chair.

AS 8BitCrab says, it was first implemented and shown (to us) for the hearthlings hair and skin color. If it can be used for other models though I’m not sure; I haven’t played around with it, and the code for this is located within the engine itself.

Looking more closely at it now, I think it can be done, there are some steps involved though (note that, as I haven’t tried any of this myself, this is pure speculation and should probably be taken with a grain of salt).

First you’d have to define a color map for the type of model which contains the information about which parts of the model that will accept a palette-swap. Consider the hair_color_map.json as an example:

{
   "#FC6EFE" : "stonehearth:hair:hilight",
   "#A438A5" : "stonehearth:hair:midtone",
   "#761B76" : "stonehearth:hair:shadows"
}

It’s simply a collection of uris tied to a color in hex format. Note that the color must match an actual color on the model. The uris will be used later on when doing the palette swap, what uri you choose to use for each color should reflect what the color represents.

Next up would be to define the material maps for the model. These contain the colors that will be swapped into; they’re themselves using the uris defined from the color map. We’ll use hair_black_material_map.json as an example:

{
   "stonehearth:hair:hilight" : {
      "color" : "#2F2C27"
   },
   "stonehearth:hair:midtone" : {
      "color" : "#211F1C"
   },
   "stonehearth:hair:shadows" : {
      "color" : "#0D0D0D"
   }
}

Not that much to this part, it’s just telling the model to change its colors (matched by their respective uri) into the one supplied here.

Now how to implement all this. For this we go to the entity’s json file, add in/modify the render_info component, and add in the color_map and material_maps values. It would look something like so:

   "components": {
      "render_info": {
         "color_map": COLOR_MAP,
         "material_maps": [
            RELEVANT_MATERIAL_MAPS
         ]
      }
   }

Here, COLOR_MAP is referring to the color map json file.
RELEVANT_MATERIAL_MAPS lists all of the material map json files that will be used for this entity. The default behavior is that all of the files listed will be used to swap all colors found, but it can be changed with the usage of one_of which chooses one material map out of those listed. Example (from entities/humans/male/male_1.json):

         "material_maps": [
               "/stonehearth/data/materials/material_maps/skin_white_material_map.json",
               {
                  "type": "one_of",
                  "items": [
                     "/stonehearth/data/materials/material_maps/hair_platinum_material_map.json",
                     "/stonehearth/data/materials/material_maps/hair_blonde_material_map.json",
                     "/stonehearth/data/materials/material_maps/hair_sandy_material_map.json",
                     "/stonehearth/data/materials/material_maps/hair_brown_material_map.json",
                     "/stonehearth/data/materials/material_maps/hair_brown_material_map.json",
                     "/stonehearth/data/materials/material_maps/hair_brown_material_map.json",
                     "/stonehearth/data/materials/material_maps/hair_red_material_map.json",
                     "/stonehearth/data/materials/material_maps/hair_black_material_map.json",
                     "/stonehearth/data/materials/material_maps/hair_black_material_map.json",
                     "/stonehearth/data/materials/material_maps/hair_black_material_map.json"
                  ]
               }
         ]

This will add in skin_white_material_map.json for the skin, and simultaneously choose one of the many hair material maps.


I believe that’s all it takes to be able to add in your own palette swaps for any entity. Though, I should say that doing something like this will choose the palette randomly. If you’d want the player to be able to choose the color from the list, then this is not enough, and I’ve not seen anywhere that makes it possible for us to implement something like that.

1 Like

Thanks much for the detailed response.

I’ve decided to have a go at it. What I am trying to do is define the majority of an object’s details in one folder (ghost, iconic form, etc.) that contains the generically colored qb files, then actually point the manifest to other optional folders that contain files that are mostly mix-ins from the folder with the qb models with just a unique color map added. I think if I’m careful about constructing separate directory trees, adding a new version with a new palette will be fairly easy. The key will be separating out the different “flavors” in the list of recipes that come up when you select a workbench. All items of the same type are going to have generic coloring in the preview png corresponding to the actual qb model file, otherwise if I’m going to swap all the palettes out to make rendered images, I may as well create different models for each “flavor” in the first place. However, once they’re built the object (iconic or normal) will have the selected palette in game.

1 Like

They still have to implement a dye system in the game for items… It would be good to have it, so the weaver can make cloths of different colors easily and also for the other crafters.

Good luck with your attempt, can’t wait to see if it works :smiley:

1 Like

My tests over the weekend looked promising. I was able to create generic models with gray tones in Qubicle, then add the “wrappers” as I described in the previous posts to create red versions of the item in game. I found it was not so satisfying, though, to see the preview image in gray. I may actually make the effort to split out the png into the “wrapper” piece and take the time to color and render them for each “flavor” of my items. The advantage would be that one could still see red vs blue vs green items at a glance in the workbench view, but I would have the ability to easily tweak the coloring of a whole bunch of items in a theme if I decided I thought the palette was too bright or something. That is, change one small json file instead of editing many qb ones (and not get too bent out of shape that the tones of the preview don’t exactly match the constructed items).

2 Likes