Guest User

Untitled

a guest
May 27th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. # float_lerp as defined above.
  2.  
  3. def create_sampler(data=bpy.data, context=bpy.context, ops=bpy.ops, scene=bpy.context.scene, loc=(0.0, 0.0, 0.0), name='Sampler', count=20, swatch_size=1.0, segments=48, ring_count=24, frame_start=bpy.context.scene.frame_start, frame_end=bpy.context.scene.frame_end):
  4. ops.object.empty_add(type='PLAIN_AXES', location=loc)
  5. sampler = context.object
  6. sampler.name = name
  7.  
  8. inv_count_ln = 1.0 / (count - 1)
  9. inv_count_rd = 1.0 / count
  10. radius = count * 0.35
  11.  
  12. for i in range(0, count, 1):
  13.  
  14. # Enter edit mode upon creation.
  15. ops.mesh.primitive_uv_sphere_add(size=swatch_size, segments=segments, ring_count=ring_count, enter_editmode=True)
  16.  
  17. # Set UV coordinates.
  18. ops.uv.sphere_project(direction='ALIGN_TO_OBJECT')
  19.  
  20. # Toggle back to object mode.
  21. ops.object.editmode_toggle()
  22.  
  23. # Use smooth shading.
  24. ops.object.shade_smooth()
  25.  
  26. # Set name and parent.
  27. obj = context.object
  28. obj.name = obj.data.name = '{0:0>3d}.Sample'.format(i)
  29. obj.parent = sampler
  30.  
  31. # Set location.
  32. i_percent_rd = i * inv_count_rd
  33. theta = TWOPI * i_percent_rd
  34. obj.location = (cos(theta) * radius, sin(theta) * radius, 0.0)
  35.  
  36. # Create materials.
  37. mat = init_pbr_mat(obj=obj, name=obj.name, metallic={frame_start: 0.0, frame_end: 0.5}, specular={0: 0.2}, roughness={frame_start: 0.01, frame_end: 0.333}, sheen={0: 0.2}, clearcoat={0: 0.99}, clearcoat_roughness={0: 0.01})
  38.  
  39. # Cache references.
  40. node_tree = mat.node_tree
  41. nodes = node_tree.nodes
  42.  
  43. # Set color.
  44. i_percent_ln = i * inv_count_ln
  45. comb_hsv = append_comb_hsv(nodes=nodes, scene=scene, h={0: float_lerp(1.0, 0.5, i_percent_ln)}, s={0: 1.0}, v={frame_start: 1.0, frame_end: 0.02})
  46. node_tree.links.new(nodes['Principled BSDF'].inputs['Base Color'], comb_hsv.outputs['Color'])
  47.  
  48. # Append new material to sample.
  49. obj.data.materials.append(mat)
  50.  
  51. return sampler
  52.  
  53. create_sampler()
Add Comment
Please, Sign In to add comment