Freestyle: Use of the Fill Range by Selection operator in the mesh edit mode.
This revision extends the functionality of the "Fill Range by Selection" button in the "Distance from Camera/Object" modifiers so that only selected mesh vertices in the edit mode are taken into account (instead of considering all vertices when in the object mode) to compute the min & max distances from the reference. This will give users much finer control on the range values.
This commit is contained in:
parent
bc4aeefe82
commit
4e1025376e
|
@ -75,6 +75,32 @@ class SCENE_OT_freestyle_fill_range_by_selection(bpy.types.Operator):
|
|||
else:
|
||||
self.report({'ERROR'}, "Unexpected modifier type: " + m.type)
|
||||
return {'CANCELLED'}
|
||||
# Find selected vertices in editmesh
|
||||
ob = bpy.context.active_object
|
||||
if ob.type == 'MESH' and ob.mode == 'EDIT' and ob.name != ref.name:
|
||||
bpy.ops.object.mode_set(mode='OBJECT')
|
||||
selected_verts = [v for v in bpy.context.active_object.data.vertices if v.select]
|
||||
bpy.ops.object.mode_set(mode='EDIT')
|
||||
# Compute the min/max distance from the reference to mesh vertices
|
||||
min_dist = sys.float_info.max
|
||||
max_dist = -min_dist
|
||||
if m.type == 'DISTANCE_FROM_CAMERA':
|
||||
ob_to_cam = matrix_to_camera * ob.matrix_world
|
||||
for vert in selected_verts:
|
||||
# dist in the camera space
|
||||
dist = (ob_to_cam * vert.co).length
|
||||
min_dist = min(dist, min_dist)
|
||||
max_dist = max(dist, max_dist)
|
||||
elif m.type == 'DISTANCE_FROM_OBJECT':
|
||||
for vert in selected_verts:
|
||||
# dist in the world space
|
||||
dist = (ob.matrix_world * vert.co - target_location).length
|
||||
min_dist = min(dist, min_dist)
|
||||
max_dist = max(dist, max_dist)
|
||||
# Fill the Range Min/Max entries with the computed distances
|
||||
m.range_min = min_dist
|
||||
m.range_max = max_dist
|
||||
return {'FINISHED'}
|
||||
# Find selected mesh objects
|
||||
selection = [ob for ob in scene.objects if ob.select and ob.type == 'MESH' and ob.name != ref.name]
|
||||
if selection:
|
||||
|
|
Loading…
Reference in New Issue