2
$\begingroup$

Do you have any idea to recreate the node setup below, but in such a way that instead of a True/False switch you get a Float input from 0 to 1? I'm asking because I would like to create an animation that will allow you to smoothly change materials in all objects in a given collection. Thx.

enter image description here


I'm looking for a solution that will allow me to animate the gradual appearance and disappearance of an entire collection of objects at once. I received from the client a model of a rather complicated device, where individual objects are assigned dozens of different materials, and the whole machine contains a lot of such parts. My task will be to show the process of assembling the machine in such a way that each part appears and falls into place.Animating the properties of each separate material in each separate part would be a nightmare.

On RCS I found an interesting solution that allows you to animate the disappearance of an object along with all its materials.

adrian2 7mo

in material, add "Object info node" and connect "Alpha" socket to materials Alpha.

Now in Object Properties find Viewport Display. In there you'll find "Color". Alpha value of this color is now attached to Object Info node.

If you animate this alpha value, all materials attached to this object will change it's opacity. And it works per object. So when you have this material on multiple objects, Object Info node will read Alpha value only of object you animated.

On the other hand, a similar solution, but based on entire collections, would be the most optimal and effective, but I haven't found one yet.

$\endgroup$
4
  • $\begingroup$ Geometry nodes is not the right tool for this. If you want to work with materials, you should probably work with materials and material nodes. $\endgroup$ Jun 21, 2023 at 7:09
  • $\begingroup$ Hi @Zyzio, Materials are assigned per-face, and a face can only have one material at a time. You could build a tree which switches faces instantly, by some progressive selection. What you can blend smoothly, is any parameter (or parameters) of a single material you like.. color, roughness, anything .. or your material might be a mix between two or more shaders, and you could control the mix. Could you give a specific example of what you want? As Martynas says, GN might be the wrong tool. $\endgroup$
    – Robin Betts
    Jun 21, 2023 at 7:15
  • $\begingroup$ If you have a lot of objects, it's possible to use Python to insert a node group into every material just before material output so you can animate properties from inside one node group for many materials. If this is something that might work for you, I could explain in more detail, and provide a script. $\endgroup$ Jun 21, 2023 at 7:21
  • 1
    $\begingroup$ This sounds like a job for the compositor: partly because you wouldn't want objects to become transparent to their own backfaces, while they disappear? Perhaps you could confirm/reject that. If so, look up some examples of Cryptomatte $\endgroup$
    – Robin Betts
    Jun 21, 2023 at 8:30

1 Answer 1

4
$\begingroup$

Here is a script that you can run in the text editor after replacing variables node_group_to_insert and collections with the name of a pre-made node group with at least one input and output and a list of collection names:

import bpy
from mathutils import Vector


node_group_to_insert = "MixToPinkDiffuse" #Name of the group(string). First input and first output will be used
collections =[ "a", "b" ] #List collection names


grp = bpy.data.node_groups[node_group_to_insert]

# Let's make materials unique in collections
for c in collections:
    for o in bpy.data.collections[c].objects:
        for slot in o.material_slots:
            try:  #in case slot has no material
                name = c+"_"+slot.material.name
                if name in bpy.data.materials:
                    slot.material = bpy.data.materials[name]
                else:
                    slot.material = slot.material.copy()
                    slot.material.name = name
            except:
                pass

# Insert the group copies
for c in collections:
    col_grp = grp.copy()
    col_grp.name = "Fade " + c
    for o in bpy.data.collections[c].objects:
        for m in o.data.materials:
            nodes = m.node_tree.nodes
            links = m.node_tree.links
            for n in nodes:
                if n.type != 'OUTPUT_MATERIAL':
                    continue
                inserted = nodes.new("ShaderNodeGroup")
                inserted.node_tree = col_grp
                inserted.location = n.location - Vector((80,-150))
                links_list = list(links) 
                for l in links_list:
                    if l.to_node != n:
                        continue
                    from_socket = l.from_socket
                    to_socket = l.to_socket
                    links.remove(l)
                    links.new(from_socket,inserted.inputs[0])
                    links.new(inserted.outputs[0], to_socket)

It will insert copies of the node group renamed by collection just before material output nodes so you can animate whatever properties inside one group to affect all materials of objects in the collection. Objects can have same material and be in different collections, so it needs to make materials unique for this. This might introduce problems if you later need to edit the materials... Also same object can be in multiple collections - in that case this might not work well.

After running the script you should have groups for every collection, that you can animate:

enter image description here

$\endgroup$
1
  • $\begingroup$ Thank you, I will try to implement this solution. $\endgroup$
    – Zyzio
    Jun 21, 2023 at 10:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .