forked from bartvdbraak/blender
Added a button to the UI of "Distance from Object" color/alpha/thickness
modifiers to fill the Range Min/Max entries by the min/max distance between selected mesh objects and the target object.
This commit is contained in:
parent
33bb1ed53e
commit
7eb10d1538
@ -22,7 +22,7 @@ from bpy.props import (EnumProperty, StringProperty)
|
||||
|
||||
|
||||
class SCENE_OT_freestyle_fill_range_by_selection(bpy.types.Operator):
|
||||
'''Fill the Range Min/Max entries by the min/max distance between selected mesh objects and the active camera.'''
|
||||
'''Fill the Range Min/Max entries by the min/max distance between selected mesh objects and the source object (either a user-specified object or the active camera).'''
|
||||
bl_idname = "scene.freestyle_fill_range_by_selection"
|
||||
bl_label = "Fill Range by Selection"
|
||||
|
||||
@ -43,17 +43,26 @@ class SCENE_OT_freestyle_fill_range_by_selection(bpy.types.Operator):
|
||||
m = linestyle.alpha_modifiers[self.name]
|
||||
else:
|
||||
m = linestyle.thickness_modifiers[self.name]
|
||||
# Find the active camera
|
||||
camera = context.scene.camera
|
||||
# Find the source object
|
||||
if m.type == 'DISTANCE_FROM_CAMERA':
|
||||
source = context.scene.camera
|
||||
elif m.type == 'DISTANCE_FROM_OBJECT':
|
||||
if m.target is None:
|
||||
self.report({'ERROR'}, "Target object not specified")
|
||||
return {'CANCELLED'}
|
||||
source = m.target
|
||||
else:
|
||||
self.report({'ERROR'}, "Unexpected modifier type: " + m.type)
|
||||
return {'CANCELLED'}
|
||||
# Find selected mesh objects
|
||||
selection = [ob for ob in context.scene.objects if ob.select and ob.type == 'MESH']
|
||||
selection = [ob for ob in context.scene.objects if ob.select and ob.type == 'MESH' and ob.name != source.name]
|
||||
if len(selection) > 0:
|
||||
# Compute the min/max distance between selected mesh objects and the camera
|
||||
# Compute the min/max distance between selected mesh objects and the source
|
||||
min_dist = float('inf')
|
||||
max_dist = -min_dist
|
||||
for ob in selection:
|
||||
for vert in ob.data.vertices:
|
||||
dist = (ob.matrix_world * vert.co - camera.location).length
|
||||
dist = (ob.matrix_world * vert.co - source.location).length
|
||||
min_dist = min(dist, min_dist)
|
||||
max_dist = max(dist, max_dist)
|
||||
# Fill the Range Min/Max entries with the computed distances
|
||||
|
@ -364,6 +364,9 @@ class RENDER_PT_freestyle_linestyle(RenderButtonsPanel, Panel):
|
||||
elif modifier.type == "DISTANCE_FROM_OBJECT":
|
||||
box.prop(modifier, "target")
|
||||
self.draw_modifier_color_ramp_common(box, modifier, True)
|
||||
prop = box.operator("scene.freestyle_fill_range_by_selection")
|
||||
prop.type = 'COLOR'
|
||||
prop.name = modifier.name
|
||||
|
||||
elif modifier.type == "DISTANCE_FROM_CAMERA":
|
||||
self.draw_modifier_color_ramp_common(box, modifier, True)
|
||||
@ -400,6 +403,9 @@ class RENDER_PT_freestyle_linestyle(RenderButtonsPanel, Panel):
|
||||
elif modifier.type == "DISTANCE_FROM_OBJECT":
|
||||
box.prop(modifier, "target")
|
||||
self.draw_modifier_curve_common(box, modifier, True, False)
|
||||
prop = box.operator("scene.freestyle_fill_range_by_selection")
|
||||
prop.type = 'ALPHA'
|
||||
prop.name = modifier.name
|
||||
|
||||
elif modifier.type == "DISTANCE_FROM_CAMERA":
|
||||
self.draw_modifier_curve_common(box, modifier, True, False)
|
||||
@ -426,6 +432,9 @@ class RENDER_PT_freestyle_linestyle(RenderButtonsPanel, Panel):
|
||||
elif modifier.type == "DISTANCE_FROM_OBJECT":
|
||||
box.prop(modifier, "target")
|
||||
self.draw_modifier_curve_common(box, modifier, True, True)
|
||||
prop = box.operator("scene.freestyle_fill_range_by_selection")
|
||||
prop.type = 'THICKNESS'
|
||||
prop.name = modifier.name
|
||||
|
||||
elif modifier.type == "DISTANCE_FROM_CAMERA":
|
||||
self.draw_modifier_curve_common(box, modifier, True, True)
|
||||
|
Loading…
Reference in New Issue
Block a user