consider only renderable gp for crop export

0.6.8
main
Pullusb 2021-11-12 17:02:19 +01:00
parent da86da59ce
commit 266079410a
2 changed files with 30 additions and 8 deletions

View File

@ -17,7 +17,7 @@ Activate / deactivate all masks using MA layers
0.6.8 0.6.8
- feat: New multi-scene viewlayer inspection button - feat: New multi-scene viewlayer inspection button
- fix: revert back export json crop to use GP names when available - fix: revert back export json crop to use GP names when available with better check
0.6.7 0.6.7

36
fn.py
View File

@ -786,6 +786,23 @@ def get_bbox_3d(ob):
bbox_coords = ob.bound_box bbox_coords = ob.bound_box
return [ob.matrix_world @ Vector(b) for b in bbox_coords] return [ob.matrix_world @ Vector(b) for b in bbox_coords]
def is_render_included(o, scn):
'''return True if object is in at least one non-excluded collection
in all passed scene viewlayer
'''
if o.hide_render:
return False
for vl in scn.view_layers:
all_cols = get_collection_childs_recursive(vl.layer_collection)
for c in all_cols:
print(c.name)
if o in c.collection.objects[:]:
if not c.exclude:
return True
return False
def get_crop_pixel_coord(scn): def get_crop_pixel_coord(scn):
# width height probably not needed. might need # width height probably not needed. might need
px_width = (scn.render.border_max_x - scn.render.border_min_x) * scn.render.resolution_x px_width = (scn.render.border_max_x - scn.render.border_min_x) * scn.render.resolution_x
@ -828,8 +845,8 @@ def export_crop_to_json():
## Only scn name (meaning only one name to refer if multiple GP) ## Only scn name (meaning only one name to refer if multiple GP)
# coord_dic[scn.name] = scn_border # coord_dic[scn.name] = scn_border
## use name of first found GP : ## use name of first found visible GP (scene name if no visible GP)
gps = [o for o in scn.objects if o.type == 'GPENCIL'] gps = [o for o in scn.objects if o.type == 'GPENCIL' if is_render_included(o, scn)] # o.visible_get() < only work on active window
if gps: if gps:
for ob in gps: for ob in gps:
coord_dic[ob.name] = scn_border coord_dic[ob.name] = scn_border
@ -1026,18 +1043,24 @@ def set_box_from_selected_objects(scn=None, cam=None, export_json=False):
_bbox_px = set_border_region_from_coord(coords, margin=30, scn=scn, export_json=export_json) _bbox_px = set_border_region_from_coord(coords, margin=30, scn=scn, export_json=export_json)
def get_collection_childs_recursive(col, cols=[]): def get_collection_childs_recursive(col, cols=[], include_root=True):
'''return a list of all the sub-collections in passed col''' '''return a list of all the sub-collections in passed col'''
# force start from fresh list (otherwise same cols list is used at next call)
cols = cols or []
for sub in col.children: for sub in col.children:
if sub not in cols: if sub not in cols:
cols.append(sub) cols.append(sub)
if len(sub.children): if len(sub.children):
cols = get_collection_childs_recursive(sub, cols) cols = get_collection_childs_recursive(sub, cols)
if include_root and col not in cols: # add root col
cols.append(col)
return cols return cols
def unlink_objects_from_scene(oblist, scn): def unlink_objects_from_scene(oblist, scn):
all_col = [scn.collection] all_col = get_collection_childs_recursive(scn.collection)
all_col += get_collection_childs_recursive(scn.collection)
for col in all_col: for col in all_col:
for ob in reversed(col.objects): for ob in reversed(col.objects):
if ob in oblist: if ob in oblist:
@ -1075,8 +1098,7 @@ def split_object_to_scene():
# new.render.filepath = f'/tmp/' # new.render.filepath = f'/tmp/'
## unlink unwanted objects from collection ## unlink unwanted objects from collection
all_col = [new.collection] all_col = get_collection_childs_recursive(new.collection)
all_col += get_collection_childs_recursive(new.collection)
for col in all_col: for col in all_col:
for sob in reversed(col.objects): for sob in reversed(col.objects):
if sob.type in ('CAMERA', 'LIGHT'): if sob.type in ('CAMERA', 'LIGHT'):