How to "color code" 3D models for different teams like in RTS?

Godot Version

4.3

Question

In RTS games, all objects will belong to a team. Each team has its own color. This means there should be a base 3D model and in the game, the game should color these models on the desired parts with respect to the team’s color.

My question is normally in Godot, how do we “color” for these parts on the 3D models? I am using Blender for the 3D models.

I believe the Models/Meshes should have a material applied to them with a specific surface color.
You can change and adjust the surface color via code by accessing the property (it is usually called albedo_color)
In usual cases, a model has a mesh with multiple surfaces that are numbered. The structure may differ a bit based on mesh objects and character models.


I would set const variable for your teams first, then apply the albedo_color appropriately.

const TEAM_COLOR : Dictionary = {
    "blue" = Color.BLUE,
    "red" = Color.RED

func _set_team_color(color: String) -> void:
    mesh.surface_0.material.albedo_color = TEAM_COLOR[color]
    mesh.surface_1.material.albedo_color = TEAM_COLOR[color]
    mesh.surface_2.material.albedo_color = TEAM_COLOR[color]

of course this is all pseudo code, it’s best to export and import the models first and see how and where the color is configured in the model.

2 Likes

I would look into shaders.

Here is an example of a shader that does this for canvas items (2D)

You should be able to make a similar shader for 3D

1 Like

Hi @nutlike4693, between albedo color above and using shader , do you know which one has better performance?

Certainly the standard materials with albedo is better for performance.

2 Likes

I am not familiar with performance, but the other way seems easier.

And, unless you are having performance issues, easier to do is probably better.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.