Advertisement
Guest User

Blender mesh.hide_backface JP

a guest
Jul 21st, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.10 KB | None | 0 0
  1. import bmesh, math, mathutils
  2. class hide_backface(bpy.types.Operator):
  3.     bl_idname = _common.get_ops_idname('mesh', 'hide_backface')
  4.     bl_label = "裏側を隠す"
  5.     bl_options = {'REGISTER', 'UNDO'}
  6.    
  7.     show_radian = bpy.props.FloatProperty(name="表示角度", default=math.radians(110), min=0, max=math.radians(180), soft_min=0, soft_max=math.radians(180), step=500, precision=0, subtype='ANGLE', unit='ROTATION')
  8.    
  9.     @classmethod
  10.     def poll(cls, context):
  11.         try:
  12.             ob = context.active_object
  13.             if ob.mode != 'EDIT' or ob.type != 'MESH': return False
  14.         except: return False
  15.         return True
  16.    
  17.     def execute(self, context):
  18.         ob, me = context.active_object, context.active_object.data
  19.         bm = bmesh.from_edit_mesh(me)
  20.        
  21.         view_rotation = context.region_data.view_rotation.copy()
  22.         up_axis = mathutils.Vector((0, 0, 1))
  23.        
  24.         for vert in bm.verts:
  25.             normal_rotation = up_axis.rotation_difference(ob.matrix_world * vert.normal)
  26.             diff_rotation = view_rotation.rotation_difference(normal_rotation)
  27.             vert.hide_set(self.show_radian < diff_rotation.angle)
  28.        
  29.         bmesh.update_edit_mesh(me)
  30.         return {'FINISHED'}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement