Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # float_lerp as defined above.
- 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):
- ops.object.empty_add(type='PLAIN_AXES', location=loc)
- sampler = context.object
- sampler.name = name
- inv_count_ln = 1.0 / (count - 1)
- inv_count_rd = 1.0 / count
- radius = count * 0.35
- for i in range(0, count, 1):
- # Enter edit mode upon creation.
- ops.mesh.primitive_uv_sphere_add(size=swatch_size, segments=segments, ring_count=ring_count, enter_editmode=True)
- # Set UV coordinates.
- ops.uv.sphere_project(direction='ALIGN_TO_OBJECT')
- # Toggle back to object mode.
- ops.object.editmode_toggle()
- # Use smooth shading.
- ops.object.shade_smooth()
- # Set name and parent.
- obj = context.object
- obj.name = obj.data.name = '{0:0>3d}.Sample'.format(i)
- obj.parent = sampler
- # Set location.
- i_percent_rd = i * inv_count_rd
- theta = TWOPI * i_percent_rd
- obj.location = (cos(theta) * radius, sin(theta) * radius, 0.0)
- # Create materials.
- 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})
- # Cache references.
- node_tree = mat.node_tree
- nodes = node_tree.nodes
- # Set color.
- i_percent_ln = i * inv_count_ln
- 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})
- node_tree.links.new(nodes['Principled BSDF'].inputs['Base Color'], comb_hsv.outputs['Color'])
- # Append new material to sample.
- obj.data.materials.append(mat)
- return sampler
- create_sampler()
Add Comment
Please, Sign In to add comment