Applied soc-2017-normal-tools

This commit is contained in:
Rohan Rathi
2018-05-25 22:24:24 +05:30
parent a709e8d6bb
commit 5d2d36b068
40 changed files with 2997 additions and 82 deletions

View File

@@ -56,6 +56,7 @@ KM_HIERARCHY = [
('Particle', 'EMPTY', 'WINDOW', []),
('Knife Tool Modal Map', 'EMPTY', 'WINDOW', []),
('Custom Normals Modal Map', 'EMPTY', 'WINDOW', []),
('Paint Stroke Modal', 'EMPTY', 'WINDOW', []),
('Paint Curve', 'EMPTY', 'WINDOW', []),

View File

@@ -203,57 +203,7 @@ class MeshSelectPrev(Operator):
return {'FINISHED'}
# XXX This is hackish (going forth and back from Object mode...), to be redone once we have proper support of
# custom normals in BMesh/edit mode.
class MehsSetNormalsFromFaces(Operator):
"""Set the custom vertex normals from the selected faces ones"""
bl_idname = "mesh.set_normals_from_faces"
bl_label = "Set Normals From Faces"
bl_options = {'REGISTER', 'UNDO'}
@classmethod
def poll(cls, context):
return (context.mode == 'EDIT_MESH' and context.edit_object.data.polygons)
def execute(self, context):
import mathutils
bpy.ops.object.mode_set(mode='OBJECT')
obj = context.active_object
me = obj.data
v2nors = {}
for p in me.polygons:
if not p.select:
continue
for lidx, vidx in zip(p.loop_indices, p.vertices):
assert(me.loops[lidx].vertex_index == vidx)
v2nors.setdefault(vidx, []).append(p.normal)
for nors in v2nors.values():
nors[:] = [sum(nors, mathutils.Vector((0, 0, 0))).normalized()]
if not me.has_custom_normals:
me.create_normals_split()
me.calc_normals_split()
normals = []
for l in me.loops:
nor = v2nors.get(l.vertex_index, [None])[0]
if nor is None:
nor = l.normal
normals.append(nor.to_tuple())
me.normals_split_custom_set(normals)
me.free_normals_split()
bpy.ops.object.mode_set(mode='EDIT')
return {'FINISHED'}
classes = (
MehsSetNormalsFromFaces,
MeshMirrorUV,
MeshSelectNext,
MeshSelectPrev,

View File

@@ -1557,6 +1557,22 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
if md.rest_source == 'BIND':
layout.operator("object.correctivesmooth_bind", text="Unbind" if is_bind else "Bind")
def WEIGHTED_NORMAL(self, layout, ob, md):
layout.label("Weighting Mode:")
split = layout.split(align=True)
col = split.column(align=True)
col.prop(md, "mode", text="")
col.prop(md, "weight", text="Weight")
col.prop(md, "keep_sharp")
col = split.column(align=True)
row = col.row(align=True)
row.prop_search(md, "vertex_group", ob, "vertex_groups", text="")
row.active = bool(md.vertex_group)
row.prop(md, "invert_vertex_group", text="", icon='ARROW_LEFTRIGHT')
col.prop(md, "thresh", text="Threshold")
col.prop(md, "face_influence")
classes = (
DATA_PT_modifiers,

View File

@@ -2777,6 +2777,30 @@ class VIEW3D_MT_edit_mesh_normals(Menu):
layout.operator("mesh.flip_normals")
layout.operator("mesh.set_normals_from_faces", text="Set From Faces")
layout.operator("transform.rotate_normal", text="Rotate Normal")
layout.operator("mesh.point_normals", text="Point normals to target")
layout.operator("mesh.merge_normals", text="Merge")
layout.operator("mesh.split_normals", text="Split")
layout.operator("mesh.average_normals", text="Average Normals")
layout.label(text="Normal Vector")
layout.operator("mesh.normals_tools", text="Copy").mode = 'COPY'
layout.operator("mesh.normals_tools", text="Paste").mode = 'PASTE'
layout.operator("mesh.normals_tools", text="Multiply").mode = 'MULTIPLY'
layout.operator("mesh.normals_tools", text="Add").mode = 'ADD'
layout.operator("mesh.normals_tools", text="Reset").mode = 'RESET'
layout.operator("mesh.smoothen_normals", text="Smoothen")
layout.label(text="Face Strength")
layout.operator("mesh.mod_weighted_strength", text="Face select", icon = "FACESEL").set = False
layout.operator("mesh.mod_weighted_strength", text="Set Strength", icon = "ZOOMIN").set = True
class VIEW3D_MT_edit_mesh_shading(Menu):
bl_label = "Shading"

View File

@@ -1297,6 +1297,26 @@ class VIEW3D_PT_tools_particlemode(View3DPanel, Panel):
sub.prop(pe, "fade_frames", slider=True)
class VIEW3D_PT_tools_normal(View3DPanel, Panel):
bl_category = ""
bl_context = ".mesh_edit"
bl_label = "Normal Tools"
def draw(self, context):
layout = self.layout
toolsettings = context.tool_settings
col = layout.column(align=True)
col.label(text="Normal Vector")
col.prop(toolsettings, "normal_vector", text="")
layout.separator()
layout.label(text="Face Strength")
layout.prop(toolsettings, "face_strength", text="")
col = layout.column(align=True)
# Grease Pencil drawing tools
class VIEW3D_PT_tools_grease_pencil_draw(GreasePencilDrawingToolsPanel, Panel):
bl_space_type = 'VIEW_3D'
@@ -1361,6 +1381,7 @@ classes = (
VIEW3D_PT_tools_grease_pencil_sculpt,
VIEW3D_PT_tools_grease_pencil_brush,
VIEW3D_PT_tools_grease_pencil_brushcurves,
VIEW3D_PT_tools_normal,
)
if __name__ == "__main__": # only for live edit.