0
$\begingroup$

OK so I have a scenario whereby my colleagues are creating an image and overwriting a texture, they can then open a blender file and hit render to get an image showing off the design. However I need them to be able to change certain colours of materials without ever having to know anything about node setups. They are comfortable with design software but 3D etc is beyond them.

I am looking to create a separate scene that will act as a simple GUI for them, whereby they can change certain colours of materials with colour picker boxes etc.

I'm comfortable with scripting in other languages and feel I could get on with Python but is there a way of doing something like this without much scripting? I see the option to 'add custom properties' on an object (probably not what I'm looking for but it gives you an idea)

Hope that all makes sense.

Tom

$\endgroup$
1
$\begingroup$

You can display any existing property in any place you want. This means you can show properties of nodes, like the diffuse color or mix factor, in your own panel.

Example:

import bpy
from bpy.types import Panel

class ExamplePanel(Panel):
    bl_label = "Example Panel"
    bl_space_type = 'PROPERTIES'
    bl_region_type = 'WINDOW'
    bl_context = "render"

    def draw(self, context):
        layout = self.layout

        obj = context.active_object
        if not obj:
            layout.label("Select an object")
            return

        mat = obj.active_material
        if not mat:
            layout.label("Create a material")
            return

        nodes = mat.node_tree.nodes
        # Note: you will have to edit these node names to use the ones in your setup
        diffuse_1 = nodes["Diffuse BSDF"]
        diffuse_2 = nodes["Diffuse BSDF.001"]
        mix = nodes["Mix Shader"]

        layout.prop(diffuse_1.inputs["Color"], "default_value",
                    text="Color of first diffuse node")
        layout.prop(diffuse_2.inputs["Color"], "default_value",
                    text="Color of second diffuse node")
        layout.prop(mix.inputs["Fac"], "default_value",
                    text="Factor of mix node")


if __name__ == "__main__":  # only for live edit.
    from bpy.utils import register_class
    register_class(ExamplePanel)

To find the names of your nodes, open the right side panel in the node editor (shortcut N) and select the node:

enter image description here

Here you can see the new panel on the right, and the node editor on the bottom.

enter image description here

$\endgroup$
  • $\begingroup$ That is fantastic, thank you, I will start looking at scripting it. $\endgroup$ – Tom Jelfs Oct 27 '18 at 12:10
  • $\begingroup$ Actually I have just noticed that this relies on the user selecting the object, can these properties change a material on an object that is not active. I'd like them to be able to change the colours, hit render and see the result. $\endgroup$ – Tom Jelfs Oct 27 '18 at 12:32
  • $\begingroup$ You can access objects via bpy.data.objects. So just write obj = bpy.data.objects["your_objects_name"]. $\endgroup$ – B.Y.O.B. Oct 28 '18 at 11:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.