custom_shelf initial commit
This commit is contained in:
@@ -0,0 +1,103 @@
|
||||
info = {
|
||||
'icon': 'RECOVER_LAST',
|
||||
'description': 'Duplicate current low as mid',
|
||||
}
|
||||
|
||||
import bpy
|
||||
from pathlib import Path
|
||||
import re
|
||||
# make a proxy through python
|
||||
|
||||
### / unused, just because it's interesting (but relinking break hide statement)
|
||||
## https://blender.stackexchange.com/questions/157562/sorting-collections-alphabetically-in-the-outliner
|
||||
def sort_collection(collection, case = False):
|
||||
|
||||
if collection.children is None: return
|
||||
|
||||
children = sorted (
|
||||
collection.children,
|
||||
key = lambda c: c.name if case else c.name.lower()
|
||||
)
|
||||
|
||||
for child in children:
|
||||
collection.children.unlink(child)
|
||||
collection.children.link(child)
|
||||
sort_collection(child)
|
||||
|
||||
def sort_all_collection():
|
||||
# case_sensitive sort, (default is False)
|
||||
case_sensitive = True
|
||||
|
||||
for scene in bpy.data.scenes:
|
||||
sort_collection(scene.collection, case_sensitive)
|
||||
### unused /
|
||||
|
||||
|
||||
def set_collection(ob, collection, unlink=True) :
|
||||
''' link an object in a collection and create it if necessary, if unlink object is removed from other collections'''
|
||||
scn = bpy.context.scene
|
||||
col = None
|
||||
visible = False
|
||||
linked = False
|
||||
|
||||
# check if collection exist or create it
|
||||
for c in bpy.data.collections :
|
||||
if c.name == collection : col = c
|
||||
if not col : col = bpy.data.collections.new(name=collection)
|
||||
|
||||
# link the collection to the scene's collection if necessary
|
||||
for c in scn.collection.children :
|
||||
if c.name == col.name : visible = True
|
||||
if not visible : scn.collection.children.link(col)
|
||||
|
||||
# check if the object is already in the collection and link it if necessary
|
||||
for o in col.objects :
|
||||
if o == ob : linked = True
|
||||
if not linked : col.objects.link(ob)
|
||||
|
||||
# remove object from scene's collection
|
||||
for o in scn.collection.objects :
|
||||
if o == ob : scn.collection.objects.unlink(ob)
|
||||
|
||||
# if unlink flag we remove the object from other collections
|
||||
if unlink :
|
||||
for c in ob.users_collection :
|
||||
if c.name != collection : c.objects.unlink(ob)
|
||||
return col
|
||||
|
||||
|
||||
# mid = None
|
||||
# low = None
|
||||
# for c in bpy.data.collections:
|
||||
# if re.search(r'vetement.*_mid', c.name, re.I):
|
||||
# mid = c
|
||||
# if re.search(r'vetement.*_low', c.name, re.I):
|
||||
# low = c
|
||||
|
||||
def backup_low_to_mid():
|
||||
low = mid = None
|
||||
for o in bpy.context.scene.objects:
|
||||
if re.search(r'vetements?_mid', o.name, re.I):
|
||||
mid = o
|
||||
if re.search(r'vetements?_low', o.name, re.I):
|
||||
low = o
|
||||
|
||||
if not low:
|
||||
print('ERROR', 'low not found')
|
||||
return
|
||||
|
||||
if not mid and low:
|
||||
#create mid by duplicating low
|
||||
mid = low.copy()
|
||||
mid.name = low.name.replace('_low', '_mid')
|
||||
mid.data = low.data.copy()# also copy data !
|
||||
mid.data.name = low.data.name.replace('_low', '_mid')
|
||||
col = set_collection(mid, mid.name)
|
||||
# hide viewport
|
||||
col.hide_viewport = True
|
||||
|
||||
else:
|
||||
print('ERROR', 'mid already exists')
|
||||
return
|
||||
|
||||
backup_low_to_mid()
|
||||
@@ -0,0 +1,27 @@
|
||||
info = {
|
||||
'icon': 'SYNTAX_OFF',
|
||||
'description': 'rename all lowercase (a bit dangerous, check if any break)',
|
||||
}
|
||||
|
||||
import bpy
|
||||
|
||||
for c in bpy.data.collections:
|
||||
new = c.name.lower()
|
||||
if bpy.data.collections.get(new):
|
||||
print(f'{new} exists!')
|
||||
else:
|
||||
c.name = new
|
||||
|
||||
for o in bpy.data.meshes:
|
||||
new = o.name.lower()
|
||||
if bpy.data.meshes.get(new):
|
||||
print(f'{new} exists!')
|
||||
else:
|
||||
o.name = new
|
||||
|
||||
for o in bpy.data.objects:
|
||||
new = o.name.lower()
|
||||
if bpy.data.objects.get(new):
|
||||
print(f'{new} exists!')
|
||||
else:
|
||||
o.name = new
|
||||
@@ -0,0 +1,90 @@
|
||||
info = {
|
||||
'icon': 'MOD_CLOTH',
|
||||
'description': 'Decimate cloth',
|
||||
}
|
||||
|
||||
import bpy
|
||||
from pathlib import Path
|
||||
import re
|
||||
|
||||
|
||||
def set_panel(panel):
|
||||
'''take a panel name and apply it to properties zone'''
|
||||
for area in bpy.context.screen.areas:
|
||||
if area.type == 'PROPERTIES':
|
||||
for space in area.spaces:
|
||||
if space.type == 'PROPERTIES':
|
||||
space.context = panel
|
||||
return (1)
|
||||
return (0)
|
||||
|
||||
|
||||
def get_panel():
|
||||
'''return active panel name of the properties zone'''
|
||||
for area in bpy.context.screen.areas:
|
||||
if area.type == 'PROPERTIES':
|
||||
for space in area.spaces:
|
||||
if space.type == 'PROPERTIES':
|
||||
return(space.context)
|
||||
return (0)
|
||||
|
||||
def get_override():
|
||||
for window in bpy.context.window_manager.windows:
|
||||
screen = window.screen
|
||||
for area in screen.areas:
|
||||
if area.type == 'PROPERTIES':
|
||||
#for region in area.regions:
|
||||
# if region.type == 'WINDOW':
|
||||
return {'window': window, 'screen': screen, 'area': area}
|
||||
|
||||
|
||||
def simplify_cloth(poly_target):
|
||||
if not get_override():
|
||||
print('ERROR', f'Need a properties windows editor open !')
|
||||
return
|
||||
|
||||
obj = bpy.context.object
|
||||
|
||||
mods = obj.modifiers
|
||||
|
||||
polycount = len(obj.data.polygons)
|
||||
|
||||
if polycount < poly_target:
|
||||
print('ERROR', f'Already lowpoly ({polycount} polygons)')
|
||||
return
|
||||
|
||||
target_ratio = poly_target / polycount
|
||||
print('target_ratio: ', target_ratio)
|
||||
|
||||
sdef = None
|
||||
|
||||
for m in mods:
|
||||
if m.type == 'SURFACE_DEFORM':
|
||||
sdef = m
|
||||
break
|
||||
|
||||
if not sdef:
|
||||
print('ERROR', 'no surface deform found')
|
||||
return
|
||||
|
||||
set_panel('MODIFIER')
|
||||
properties_override = get_override()
|
||||
|
||||
if sdef.is_bound:
|
||||
bpy.ops.object.surfacedeform_bind(properties_override, modifier="SurfaceDeform")
|
||||
|
||||
# create decimate and move to top
|
||||
decim = obj.modifiers.new('Decimate', 'DECIMATE')
|
||||
bpy.ops.object.modifier_move_to_index(modifier="Decimate", index=0)
|
||||
|
||||
# use target ratio
|
||||
decim.ratio = target_ratio
|
||||
# apply
|
||||
bpy.ops.object.modifier_apply(modifier="Decimate")
|
||||
|
||||
# rebind
|
||||
bpy.ops.object.surfacedeform_bind(properties_override, modifier="SurfaceDeform")
|
||||
|
||||
|
||||
|
||||
simplify_cloth(15000)
|
||||
Reference in New Issue
Block a user