Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Randomize renderer color/materials #46

Closed
taiya opened this issue Aug 17, 2020 · 2 comments · Fixed by #51
Closed

Randomize renderer color/materials #46

taiya opened this issue Aug 17, 2020 · 2 comments · Fixed by #51
Assignees
Labels
enhancement New feature or request

Comments

@taiya
Copy link
Collaborator

taiya commented Aug 17, 2020

new_mat = bpy.data.materials.new('Chrome')
new_mat.use_nodes = True
tree = mat.node_tree
[...]
o = bpy.context.object
o.active_material = new_mat

Control color as:

bpy.data.materials["Metal.002"].node_tree.nodes["Principled BSDF"].inputs[0].default_value = (0.749198, 0.297648, 0.249657, 1)

To duplicate materials:
https://blender.stackexchange.com/questions/82768/copy-material-with-python

@taiya taiya added the enhancement New feature or request label Aug 17, 2020
@taiya taiya pinned this issue Aug 17, 2020
@taiya
Copy link
Collaborator Author

taiya commented Aug 17, 2020

Mapping of random colors to materials:

  1. use colorsys
import colorsys
colorsys.hsv_to_rgb(random.random(), .3, .7)
  1. use color_mode in ramp
  CR.color_ramp.color_mode = "HSV"
  CR.color_ramp.elements[0].position = 0.9
  CR.color_ramp.elements[0].color = color_hsv
  CR.color_ramp.elements[1].position = 1
  CR.color_ramp.elements[1].color = (0,0,0,1)

@taiya taiya self-assigned this Aug 17, 2020
@taiya
Copy link
Collaborator Author

taiya commented Aug 17, 2020

Ended up adding a "blender.MeshChromeMaterial" with configurable primary color.

@Qwlouse Qwlouse unpinned this issue Aug 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

Successfully merging a pull request may close this issue.

1 participant