blender/release/scripts/op/mesh.py

186 lines
5.3 KiB
Python
Raw Normal View History

# ##### BEGIN GPL LICENSE BLOCK #####
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
2010-02-12 13:34:04 +00:00
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ##### END GPL LICENSE BLOCK #####
2010-01-31 14:46:28 +00:00
# <pep8 compliant>
import bpy
2010-01-31 14:46:28 +00:00
class MeshSelectInteriorFaces(bpy.types.Operator):
'''Select faces where all edges have more then 2 face users.'''
2009-12-13 22:48:11 +00:00
bl_idname = "mesh.faces_select_interior"
bl_label = "Select Interior Faces"
bl_options = {'REGISTER', 'UNDO'}
@classmethod
def poll(cls, context):
ob = context.active_object
return (ob and ob.type == 'MESH')
def execute(self, context):
ob = context.active_object
bpy.ops.mesh.selection_type(type='FACE')
is_editmode = (ob.mode == 'EDIT')
if is_editmode:
bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
mesh = ob.data
face_list = [face for face in mesh.faces]
face_edge_keys = [face.edge_keys for face in face_list]
edge_face_count = mesh.edge_face_count_dict
def test_interior(index):
for key in face_edge_keys[index]:
if edge_face_count[key] < 3:
return False
return True
for index, face in enumerate(face_list):
if(test_interior(index)):
Apply first pass of edits to rna values from rna_booleans.txt. These are not animated and are best not change names like this too late in the release. ActionGroup.selected -> select: boolean Action Group is selected BezierSplinePoint.hidden -> hide: boolean Visibility status BezierSplinePoint.selected_control_point -> select_control_point: boolean Control point selection status BezierSplinePoint.selected_handle1 -> select_left_handle: boolean Handle 1 selection status BezierSplinePoint.selected_handle2 -> select_right_handle: boolean Handle 2 selection status Bone.restrict_select -> hide_select: boolean Bone is able to be selected Bone.selected -> select: boolean CurveMapPoint.selected -> select: boolean Selection state of the curve point EditBone.restrict_select -> hide_select: boolean Bone is able to be selected EditBone.selected -> select: boolean EditBone.selected_head -> select_head: boolean EditBone.selected_tail -> select_tail: boolean EditBone.locked -> lock: boolean Bone is not able to be transformed when in Edit Mode EditBone.hidden -> hide: boolean Bone is not visible when in Edit Mode NEGATE * FCurve.disabled -> enabled: boolean F-Curve could not be evaluated in past, so should be skipped when evaluating FCurve.locked -> lock: boolean F-Curve's settings cannot be edited FCurve.muted -> mute: boolean F-Curve is not evaluated FCurve.selected -> select: boolean F-Curve is selected for editing NEGATE * FCurve.visible -> hide: boolean F-Curve and its keyframes are shown in the Graph Editor graphs FCurveSample.selected -> select: boolean Selection status GPencilFrame.selected -> select: boolean Frame is selected for editing in the DopeSheet GPencilLayer.locked -> lock: boolean Protect layer from further editing and/or frame changes GPencilLayer.selected -> select: boolean Layer is selected for editing in the DopeSheet Keyframe.selected -> select: boolean Control point selection status Keyframe.selected_handle1 -> select_left_handle: boolean Handle 1 selection status Keyframe.selected_handle2 -> select_right_handle: boolean Handle 2 selection status MeshEdge.selected -> select: boolean MeshEdge.hidden -> hide: boolean MeshFace.hidden -> hide: boolean MeshFace.selected -> select: boolean MeshVertex.hidden -> hide: boolean MeshVertex.selected -> select: boolean MotionPathVert.selected -> select: boolean Path point is selected for editing NlaStrip.selected -> select: boolean NLA Strip is selected NlaTrack.locked -> lock: boolean NLA Track is locked NlaTrack.muted -> mute: boolean NLA Track is not evaluated NlaTrack.selected -> select: boolean NLA Track is selected Object.restrict_render -> hide_render: boolean Restrict renderability Object.restrict_select -> hide_select: boolean Restrict selection in the viewport Object.restrict_view -> hide: boolean Restrict visibility in the viewport Object.selected -> select: boolean Object selection state ObjectBase.selected -> select: boolean Object base selection state PoseBone.selected -> select: boolean Sequence.right_handle_selected -> select_right_handle: boolean Sequence.selected -> select: boolean SplinePoint.selected -> select_control_point: boolean Selection status TimelineMarker.selected -> select: boolean Marker selection state Sequence.left_handle_selected -> select_left_handle: boolean ActionGroup.locked -> lock: boolean Action Group is locked Bone.hidden -> hide: boolean Bone is not visible when it is not in Edit Mode (i.e. in Object or Pose Modes) SplinePoint.hidden -> hide: boolean Visibility status FModifier.muted -> mute: boolean F-Curve Modifier will not be evaluated note: rebaned uv_select to select_uv
2010-07-15 16:56:04 +00:00
face.select = True
else:
Apply first pass of edits to rna values from rna_booleans.txt. These are not animated and are best not change names like this too late in the release. ActionGroup.selected -> select: boolean Action Group is selected BezierSplinePoint.hidden -> hide: boolean Visibility status BezierSplinePoint.selected_control_point -> select_control_point: boolean Control point selection status BezierSplinePoint.selected_handle1 -> select_left_handle: boolean Handle 1 selection status BezierSplinePoint.selected_handle2 -> select_right_handle: boolean Handle 2 selection status Bone.restrict_select -> hide_select: boolean Bone is able to be selected Bone.selected -> select: boolean CurveMapPoint.selected -> select: boolean Selection state of the curve point EditBone.restrict_select -> hide_select: boolean Bone is able to be selected EditBone.selected -> select: boolean EditBone.selected_head -> select_head: boolean EditBone.selected_tail -> select_tail: boolean EditBone.locked -> lock: boolean Bone is not able to be transformed when in Edit Mode EditBone.hidden -> hide: boolean Bone is not visible when in Edit Mode NEGATE * FCurve.disabled -> enabled: boolean F-Curve could not be evaluated in past, so should be skipped when evaluating FCurve.locked -> lock: boolean F-Curve's settings cannot be edited FCurve.muted -> mute: boolean F-Curve is not evaluated FCurve.selected -> select: boolean F-Curve is selected for editing NEGATE * FCurve.visible -> hide: boolean F-Curve and its keyframes are shown in the Graph Editor graphs FCurveSample.selected -> select: boolean Selection status GPencilFrame.selected -> select: boolean Frame is selected for editing in the DopeSheet GPencilLayer.locked -> lock: boolean Protect layer from further editing and/or frame changes GPencilLayer.selected -> select: boolean Layer is selected for editing in the DopeSheet Keyframe.selected -> select: boolean Control point selection status Keyframe.selected_handle1 -> select_left_handle: boolean Handle 1 selection status Keyframe.selected_handle2 -> select_right_handle: boolean Handle 2 selection status MeshEdge.selected -> select: boolean MeshEdge.hidden -> hide: boolean MeshFace.hidden -> hide: boolean MeshFace.selected -> select: boolean MeshVertex.hidden -> hide: boolean MeshVertex.selected -> select: boolean MotionPathVert.selected -> select: boolean Path point is selected for editing NlaStrip.selected -> select: boolean NLA Strip is selected NlaTrack.locked -> lock: boolean NLA Track is locked NlaTrack.muted -> mute: boolean NLA Track is not evaluated NlaTrack.selected -> select: boolean NLA Track is selected Object.restrict_render -> hide_render: boolean Restrict renderability Object.restrict_select -> hide_select: boolean Restrict selection in the viewport Object.restrict_view -> hide: boolean Restrict visibility in the viewport Object.selected -> select: boolean Object selection state ObjectBase.selected -> select: boolean Object base selection state PoseBone.selected -> select: boolean Sequence.right_handle_selected -> select_right_handle: boolean Sequence.selected -> select: boolean SplinePoint.selected -> select_control_point: boolean Selection status TimelineMarker.selected -> select: boolean Marker selection state Sequence.left_handle_selected -> select_left_handle: boolean ActionGroup.locked -> lock: boolean Action Group is locked Bone.hidden -> hide: boolean Bone is not visible when it is not in Edit Mode (i.e. in Object or Pose Modes) SplinePoint.hidden -> hide: boolean Visibility status FModifier.muted -> mute: boolean F-Curve Modifier will not be evaluated note: rebaned uv_select to select_uv
2010-07-15 16:56:04 +00:00
face.select = False
if is_editmode:
bpy.ops.object.mode_set(mode='EDIT', toggle=False)
return {'FINISHED'}
2009-12-13 22:48:11 +00:00
class MeshMirrorUV(bpy.types.Operator):
'''Copy mirror UV coordinates on the X axis based on a mirrored mesh'''
bl_idname = "mesh.faces_miror_uv"
bl_label = "Copy Mirrored UV coords"
bl_options = {'REGISTER', 'UNDO'}
2010-01-31 14:46:28 +00:00
@classmethod
def poll(cls, context):
ob = context.active_object
return (ob and ob.type == 'MESH')
2010-01-31 14:46:28 +00:00
def execute(self, context):
DIR = 1 # TODO, make an option
2010-01-31 14:46:28 +00:00
from mathutils import Vector
2010-01-31 14:46:28 +00:00
ob = context.active_object
is_editmode = (ob.mode == 'EDIT')
if is_editmode:
bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
mesh = ob.data
2010-01-31 14:46:28 +00:00
# mirror lookups
mirror_gt = {}
mirror_lt = {}
2010-08-18 03:42:26 +00:00
vcos = [v.co.to_tuple(5) for v in mesh.vertices]
for i, co in enumerate(vcos):
if co[0] > 0.0:
mirror_gt[co] = i
elif co[0] < 0.0:
mirror_lt[co] = i
else:
mirror_gt[co] = i
mirror_lt[co] = i
2010-08-18 03:42:26 +00:00
#for i, v in enumerate(mesh.vertices):
vmap = {}
for mirror_a, mirror_b in (mirror_gt, mirror_lt), (mirror_lt, mirror_gt):
for co, i in mirror_a.items():
nco = (-co[0], co[1], co[2])
j = mirror_b.get(nco)
if j is not None:
vmap[i] = j
2010-01-31 14:46:28 +00:00
active_uv_layer = None
for lay in mesh.uv_textures:
if lay.active:
active_uv_layer = lay.data
break
fuvs = [(uv.uv1, uv.uv2, uv.uv3, uv.uv4) for uv in active_uv_layer]
fuvs_cpy = [(uv[0].copy(), uv[1].copy(), uv[2].copy(), uv[3].copy()) for uv in fuvs]
2010-01-31 14:46:28 +00:00
# as a list
faces = mesh.faces[:]
2010-01-31 14:46:28 +00:00
Apply first pass of edits to rna values from rna_booleans.txt. These are not animated and are best not change names like this too late in the release. ActionGroup.selected -> select: boolean Action Group is selected BezierSplinePoint.hidden -> hide: boolean Visibility status BezierSplinePoint.selected_control_point -> select_control_point: boolean Control point selection status BezierSplinePoint.selected_handle1 -> select_left_handle: boolean Handle 1 selection status BezierSplinePoint.selected_handle2 -> select_right_handle: boolean Handle 2 selection status Bone.restrict_select -> hide_select: boolean Bone is able to be selected Bone.selected -> select: boolean CurveMapPoint.selected -> select: boolean Selection state of the curve point EditBone.restrict_select -> hide_select: boolean Bone is able to be selected EditBone.selected -> select: boolean EditBone.selected_head -> select_head: boolean EditBone.selected_tail -> select_tail: boolean EditBone.locked -> lock: boolean Bone is not able to be transformed when in Edit Mode EditBone.hidden -> hide: boolean Bone is not visible when in Edit Mode NEGATE * FCurve.disabled -> enabled: boolean F-Curve could not be evaluated in past, so should be skipped when evaluating FCurve.locked -> lock: boolean F-Curve's settings cannot be edited FCurve.muted -> mute: boolean F-Curve is not evaluated FCurve.selected -> select: boolean F-Curve is selected for editing NEGATE * FCurve.visible -> hide: boolean F-Curve and its keyframes are shown in the Graph Editor graphs FCurveSample.selected -> select: boolean Selection status GPencilFrame.selected -> select: boolean Frame is selected for editing in the DopeSheet GPencilLayer.locked -> lock: boolean Protect layer from further editing and/or frame changes GPencilLayer.selected -> select: boolean Layer is selected for editing in the DopeSheet Keyframe.selected -> select: boolean Control point selection status Keyframe.selected_handle1 -> select_left_handle: boolean Handle 1 selection status Keyframe.selected_handle2 -> select_right_handle: boolean Handle 2 selection status MeshEdge.selected -> select: boolean MeshEdge.hidden -> hide: boolean MeshFace.hidden -> hide: boolean MeshFace.selected -> select: boolean MeshVertex.hidden -> hide: boolean MeshVertex.selected -> select: boolean MotionPathVert.selected -> select: boolean Path point is selected for editing NlaStrip.selected -> select: boolean NLA Strip is selected NlaTrack.locked -> lock: boolean NLA Track is locked NlaTrack.muted -> mute: boolean NLA Track is not evaluated NlaTrack.selected -> select: boolean NLA Track is selected Object.restrict_render -> hide_render: boolean Restrict renderability Object.restrict_select -> hide_select: boolean Restrict selection in the viewport Object.restrict_view -> hide: boolean Restrict visibility in the viewport Object.selected -> select: boolean Object selection state ObjectBase.selected -> select: boolean Object base selection state PoseBone.selected -> select: boolean Sequence.right_handle_selected -> select_right_handle: boolean Sequence.selected -> select: boolean SplinePoint.selected -> select_control_point: boolean Selection status TimelineMarker.selected -> select: boolean Marker selection state Sequence.left_handle_selected -> select_left_handle: boolean ActionGroup.locked -> lock: boolean Action Group is locked Bone.hidden -> hide: boolean Bone is not visible when it is not in Edit Mode (i.e. in Object or Pose Modes) SplinePoint.hidden -> hide: boolean Visibility status FModifier.muted -> mute: boolean F-Curve Modifier will not be evaluated note: rebaned uv_select to select_uv
2010-07-15 16:56:04 +00:00
fuvsel = [(False not in uv.select_uv) for uv in active_uv_layer]
fcents = [f.center for f in faces]
2010-01-31 14:46:28 +00:00
# find mirror faces
mirror_fm = {}
for i, f in enumerate(faces):
2010-08-18 03:42:26 +00:00
verts = f.vertices[:]
verts.sort()
verts = tuple(verts)
mirror_fm[verts] = i
2010-01-31 14:46:28 +00:00
fmap = {}
for i, f in enumerate(faces):
2010-08-18 03:42:26 +00:00
verts = [vmap.get(j) for j in f.vertices]
if None not in verts:
verts.sort()
j = mirror_fm.get(tuple(verts))
if j is not None:
fmap[i] = j
2010-01-31 14:46:28 +00:00
done = [False] * len(faces)
for i, j in fmap.items():
2010-01-31 14:46:28 +00:00
if not fuvsel[i] or not fuvsel[j]:
continue
elif DIR == 0 and fcents[i][0] < 0.0:
continue
elif DIR == 1 and fcents[i][0] > 0.0:
continue
# copy UVs
2010-01-31 14:46:28 +00:00
uv1 = fuvs[i]
uv2 = fuvs_cpy[j]
# get the correct rotation
2010-08-18 03:42:26 +00:00
v1 = faces[j].vertices[:]
v2 = [vmap[k] for k in faces[i].vertices[:]]
2010-01-31 14:46:28 +00:00
for k in range(len(uv1)):
k_map = v1.index(v2[k])
2010-01-31 14:46:28 +00:00
uv1[k].x = - (uv2[k_map].x - 0.5) + 0.5
uv1[k].y = uv2[k_map].y
2010-01-31 14:46:28 +00:00
if is_editmode:
bpy.ops.object.mode_set(mode='EDIT', toggle=False)
return {'FINISHED'}
def register():
pass
def unregister():
pass
if __name__ == "__main__":
register()