When working with instanced objects, I’d like to assign them random color from a certain range. But maybe I don’t see what’s in front of me anymore or it just got a bit more complicated in my case.
Here’s the idea:
each instance has it’s own color
no “realize instance” node
randomization of color has to be influenced from within geometry nodes
these color adjustments should stay even after making instances real (eg. some darker, some brighter)
Is this possible, with the requirements I stated above? I was thinking about it for a while, but very scarcely worked with materials, so I hanging out dry here…
To explain more in detail why:
I’m creating new maps into a game. By looking at the map metadata file, I realised (pun intended) I could potentially create variety of grass instances via GN, each with their own world location, rotation, color and other attributes for later export via Python. Rather than painting them via dedicated editor on a large scale surface manually, which is a very tedious task.
I also tried to print color sockets, but couldn’t figure out how. I was trying to find an option such as
.outputs[0].colour or .outputs[0].value
but the closet to that was only “default_value”, which is not desirable, as I want to grab those randomized color values. I’ve been looking, but only got what I didn’t need or errors instead.
Could you tell me what am I doing wrong?
import bpy
print("NEW")
# Define the input node name
input_node_name = "VALTORGB"
# Color value to set (R, G, B)
color_value = (0.5, 0.0815209, 0.196314,1)
# Iterate through selected objects
for ob in bpy.context.selected_objects:
# Check if the object has an active material
if ob.active_material:
material = ob.active_material
# Check if the material has a node tree
if material.node_tree:
node_tree = material.node_tree
# Find the specified input node
for node in node_tree.nodes:
if node.type == input_node_name:
print("value is ",node.outputs[0])`
I did the same with the “fur” color, running that from random into a 4 color ramp. Both materials were assigned on the original object/cat head prior to instancing it.
Not sure how that would be tackled as a script, however.
Both solutions are doing what I want to see, but can those individual instances retain their respective colours when made real?
I’d like to made them real, so I can get their color attribute later via Python per each unit individually. But I couldn’t make that to work.
The only alternative that worked for me so far was to use collection with several duplicates, each with a different material. That’s not a very elegant and flexible solution when working with procedural terrain though.
I’m creating new maps into a game. By looking at the map metadata file, I realised (pun intended) I could potentially create variety of grass instances via GN, each with their own world location, rotation, color and other attributes for later export via Python. Rather than painting them via dedicated editor on a large scale surface manually, which is a very tedious task.