I wanted to add a color field to my Blender addon panel, with which I can adjust the color input of a Principled Volume node. But i´m struggling, how I can insert such a color field there and synchronize it with the color field of the Principled Volume. Does anybody know how to do that? I would appreciate every help!
-
use FloatVectorProperty – Karan Mar 31 '24 at 05:24
1 Answers
check this out:
import bpy
def hndl_draw(self, context):
row = self.layout.row()
row.prop(context.object.data, "myColor")
def get_color(self):
return bpy.data.materials["Material.001"].node_tree.nodes["Principled Volume"].inputs[0].default_value
def set_color(self, value):
bpy.data.materials["Material.001"].node_tree.nodes["Principled Volume"].inputs[0].default_value = value
return
def register():
bpy.types.Armature.myColor = bpy.props.FloatVectorProperty(
get=get_color,
set=set_color,
name = "myColor",
subtype = "COLOR",
size = 4,
min = 0.0,
max = 1.0,
default = (0.75,0.0,0.8,1.0)
)
bpy.types.DATA_PT_display.append(hndl_draw)
def unregister():
bpy.types.DATA_PT_display.remove(hndl_draw)
del bpy.types.Armature.myColor
if name == "main":
register()
Note1: i used the solution from here: Color as Custom Property?
Note2: i changed it a bit
Note3: you need a material called "Material.001" with a principled volume in it with exact the name i used, and an armature
result:
hope that helps.
- 59,454
- 6
- 30
- 84
-
1Many thanks Chris, i came to a quite similar solution yesterday and it works! – VICUBE Animation Mar 31 '24 at 11:32
