Created
November 19, 2015 16:09
-
-
Save zeffii/eaceeedf762daf8fb2c3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import bpy | |
mode_set = bpy.ops.object.mode_set | |
def clone(): | |
ob = bpy.context.active_object | |
mode_set(mode='OBJECT') | |
clone_mesh = ob.data.copy() | |
clone_mesh.name = ob.name + '_clone' | |
clone_mesh.use_fake_user = True | |
mode_set(mode='EDIT') | |
def restore(): | |
ob = bpy.context.active_object | |
mode_set(mode='OBJECT') | |
clone_mesh = bpy.data.meshes.get(ob.name + '_clone') | |
clone_verts = clone_mesh.vertices | |
for v in ob.data.vertices: | |
if v.select: | |
v.co = clone_verts[v.index].co | |
mode_set(mode='EDIT') | |
def changed(): | |
ob = bpy.context.active_object | |
bpy.ops.mesh.select_all(action='DESELECT') | |
mode_set(mode='OBJECT') | |
clone_mesh = bpy.data.meshes.get(ob.name + '_clone') | |
clone_verts = clone_mesh.vertices | |
for v in ob.data.vertices: | |
if (v.co - clone_verts[v.index].co).length > 0.0001: | |
v.select = True | |
mode_set(mode='EDIT') | |
class ClonedRestoreOps(bpy.types.Operator): | |
bl_idname = "object.cloned_restore_op" | |
bl_label = "Short Name" | |
fn_name = bpy.props.StringProperty(default='') | |
def execute(self, context): | |
exec(self.fn_name + '()') | |
return {'FINISHED'} | |
class ClonedRestore(bpy.types.Panel): | |
"""Creates a Panel in the Object properties window""" | |
bl_label = "Clone Restore Panel" | |
bl_idname = "OBJECT_PT_clone_restore" | |
bl_space_type = 'VIEW_3D' | |
bl_region_type = 'TOOLS' | |
def draw(self, context): | |
layout = self.layout | |
obj = context.object | |
col = layout.column() | |
operators = 'clone', 'restore', 'changed' | |
for op in operators: | |
ob = context.active_object | |
if op == 'clone' and ob and (ob.name + '_clone' in bpy.data.meshes): | |
col.label('cloned as: ' + ob.name + '_clone') | |
else: | |
col.operator("object.cloned_restore_op", text=op).fn_name = op | |
def register(): | |
bpy.utils.register_module(__name__) | |
def unregister(): | |
bpy.utils.unregister_module(__name__) | |
if __name__ == "__main__": | |
register() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment