-
Notifications
You must be signed in to change notification settings - Fork 60
/
Freeze.py
69 lines (52 loc) · 2.34 KB
/
Freeze.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import bpy
from . import helper
class BooleanFreezeOperator(bpy.types.Operator):
'''Decimates the object temporarily for viewport performance'''
bl_idname = "boolean.freeze"
bl_label = "Boolean Freeze"
bl_options = {'REGISTER', 'UNDO'}
@classmethod
def poll(cls, context):
return context.active_object is not None and len(bpy.context.selected_objects)==1 and context.active_object.frozen == False
def execute(self, context):
if "Frozen" not in bpy.data.groups:
bpy.data.groups.new("Frozen")
ob = context.active_object
obCopy = helper.objDuplicate(ob)
md = ob.modifiers.new('BoolDecimate', 'DECIMATE')
md.ratio = 0.1
bpy.ops.object.modifier_apply(apply_as='DATA', modifier="BoolDecimate")
ob.hide_render = True
obCopy.select = True
bpy.ops.object.parent_set(type='OBJECT', keep_transform=False)
obCopy.name = "Frozen_"+ob.name
obCopy.hide = True
obCopy.hide_select = True
obCopy.select = False
ob.select = True
bpy.ops.object.group_link(group='Frozen')
ob.frozen = True
return {'FINISHED'}
class BooleanUnfreezeOperator(bpy.types.Operator):
'''Decimates the object temporarily for viewport performance'''
bl_idname = "boolean.unfreeze"
bl_label = "Boolean Unfreeze"
bl_options = {'REGISTER', 'UNDO'}
@classmethod
def poll(cls, context):
return context.active_object is not None and len(bpy.context.selected_objects)==1 and context.active_object.frozen == True
def execute(self, context):
ob = bpy.context.active_object
for sceneObj in bpy.context.scene.objects:
if sceneObj.parent == ob:
frozen = sceneObj
remname = ob.data.name
ob.data = bpy.context.scene.objects['Frozen_'+ob.name].data
bpy.data.scenes[bpy.context.scene.name].objects.unlink(frozen)
bpy.data.objects.remove(frozen)
# remove mesh to prevent memory being cluttered up with hundreds of high-poly objects
bpy.data.meshes.remove(bpy.data.meshes[remname])
ob.hide_render = False
bpy.data.groups['Frozen'].objects.unlink(bpy.context.object)
ob.frozen = False
return {'FINISHED'}