简体   繁体   中英

how can we change text color in blender with using of python

mat_red = bpy.data.materials.new("Text")
mat_red.diffuse_color = (0.85, 0.8, 1,1)
mesh = bpy.context.object.data
mesh.materials.append(mat_red)

not changing the color of text.

While you are adding a material to the object, the material will only be used if no other material already exists on the object. You can check the length of the material list to see if you want to append a new material or replace the existing material with your new one.

mat_red = bpy.data.materials.new("Text")
mat_red.diffuse_color = (0.85, 0.8, 1.1)
mesh = bpy.context.object.data

if len(mesh.materials) == 0:
    mesh.materials.append(mat_red)
else:
    mesh.materials[0] = mat_red

You could check the length first and adjust the existing material, then only create a new one when needed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM