safe gltf with fontcollection objects
This commit is contained in:
parent
7534699fb5
commit
a99215df54
1 changed files with 57 additions and 2 deletions
59
__init__.py
59
__init__.py
|
@ -328,14 +328,69 @@ class FONT3D_OT_SaveFontToFile(bpy.types.Operator):
|
|||
font3d_data = scene.font3d_data
|
||||
font3d = scene.font3d
|
||||
|
||||
selected_font = font3d_data.available_fonts[font3d_data.active_font_index]
|
||||
fontcollection = bpy.data.collections.get("Font3D")
|
||||
|
||||
print(selected_font.font_name)
|
||||
# needed to restore current state later
|
||||
fontcollection_was_linked = False
|
||||
previous_objects = []
|
||||
fontcollection_objects = []
|
||||
|
||||
# hide fontcollection
|
||||
if fontcollection is None:
|
||||
self.report({'INFO'}, f"{bl_info['name']}: There is no collection")
|
||||
return {'CANCELLED'}
|
||||
elif scene.collection.children.find(fontcollection.name) > 0:
|
||||
scene.collection.children.unlink(fontcollection)
|
||||
fontcollection_was_linked = True
|
||||
|
||||
# collect and hide previous objects
|
||||
for o in scene.objects:
|
||||
previous_objects.append(o)
|
||||
scene.collection.objects.unlink(o)
|
||||
|
||||
# show fontcollection
|
||||
# if scene.collection.children.find(fontcollection.name) < 0:
|
||||
# scene.collection.children.link(fontcollection)
|
||||
# link fontcollection
|
||||
for o in fontcollection.objects:
|
||||
fontcollection_objects.append(o)
|
||||
fontcollection.objects.unlink(o)
|
||||
scene.collection.objects.link(o)
|
||||
|
||||
# get save data
|
||||
selected_font = font3d_data.available_fonts[font3d_data.active_font_index]
|
||||
|
||||
if selected_font == "":
|
||||
butils.ShowMessageBox("Warning", 'ERROR', "no font selected")
|
||||
return {'CANCELLED'}
|
||||
|
||||
print(selected_font.font_name)
|
||||
# save as gltf
|
||||
bpy.ops.export_scene.gltf(
|
||||
filepath="/home/jrkb/Downloads/toast/maker.gltf",
|
||||
check_existing=False,
|
||||
export_format='GLTF_SEPARATE',
|
||||
export_extras=True,
|
||||
export_hierarchy_full_collections=True,
|
||||
use_active_collection_with_nested=True,
|
||||
)
|
||||
|
||||
# restore from previous state
|
||||
def restore():
|
||||
for o in scene.objects:
|
||||
scene.collection.objects.unlink(o)
|
||||
|
||||
for o in previous_objects:
|
||||
scene.collection.objects.link(o)
|
||||
|
||||
for o in fontcollection_objects:
|
||||
fontcollection.objects.link(o)
|
||||
|
||||
if fontcollection_was_linked:
|
||||
scene.collection.children.link(fontcollection)
|
||||
|
||||
bpy.app.timers.register(restore, first_interval=5)
|
||||
|
||||
return {'FINISHED'}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue