diff --git a/bimport.py b/bimport.py index 85cadbe..27cd8b5 100644 --- a/bimport.py +++ b/bimport.py @@ -4,10 +4,11 @@ from bpy.props import ( BoolProperty, EnumProperty, IntProperty, + FloatProperty, CollectionProperty, ) from bpy.types import Operator -from bpy_extras.io_utils import ImportHelper +from bpy_extras.io_utils import ImportHelper, ExportHelper from io_scene_gltf2 import ConvertGLTF2_Base import importlib @@ -15,31 +16,20 @@ import importlib if "Font" in locals(): importlib.reload(Font) else: - pass + from .common import Font if "utils" in locals(): importlib.reload(utils) else: from .common import utils -try: - from io_scene_gltf2.io.imp.gltf2_io_gltf import glTFImporter, ImportError - from io_scene_gltf2.blender.imp.gltf2_blender_gltf import BlenderGlTF - from io_scene_gltf2.blender.imp.gltf2_blender_vnode import VNode, compute_vnodes - from io_scene_gltf2.blender.com.gltf2_blender_extras import set_extras - from io_scene_gltf2.blender.imp.gltf2_blender_node import BlenderNode -except (ModuleNotFoundError, ImportError): - from io_scene_gltf2.io.imp.gltf2_io_gltf import glTFImporter, ImportError - from io_scene_gltf2.blender.imp.blender_gltf import BlenderGlTF - from io_scene_gltf2.blender.imp.vnode import VNode, compute_vnodes - from io_scene_gltf2.blender.com.extras import set_extras - from io_scene_gltf2.blender.imp.node import BlenderNode - # taken from blender_git/blender/scripts/addons/io_scene_gltf2/__init__.py def get_font_faces_in_file(filepath): + from io_scene_gltf2.io.imp.gltf2_io_gltf import glTFImporter, ImportError + try: import_settings = {"import_user_extensions": []} gltf_importer = glTFImporter(filepath, import_settings) @@ -60,7 +50,7 @@ def get_font_faces_in_file(filepath): out.append(node.extras) return out - except ImportError: + except ImportError as e: return None @@ -70,7 +60,7 @@ def get_font_faces_in_file(filepath): class GetFontFacesInFile(Operator, ImportHelper): """Load a glTF 2.0 font and check which faces are in there""" - bl_idname = "abc3d.check_font_gltf" + bl_idname = f"abc3d.check_font_gltf" bl_label = "Check glTF 2.0 Font" bl_options = {"REGISTER", "UNDO"} @@ -87,6 +77,7 @@ class GetFontFacesInFile(Operator, ImportHelper): def check_gltf2(self, context): import os + import sys if self.files: # Multiple file check @@ -109,7 +100,7 @@ class GetFontFacesInFile(Operator, ImportHelper): class ImportGLTF2(Operator, ConvertGLTF2_Base, ImportHelper): """Load a glTF 2.0 font""" - bl_idname = "abc3d.import_font_gltf" + bl_idname = f"abc3d.import_font_gltf" bl_label = "Import glTF 2.0 Font" bl_options = {"REGISTER", "UNDO"} @@ -294,6 +285,11 @@ class ImportGLTF2(Operator, ConvertGLTF2_Base, ImportHelper): def unit_import(self, filename, import_settings): import time + from io_scene_gltf2.io.imp.gltf2_io_gltf import glTFImporter, ImportError + from io_scene_gltf2.blender.imp.gltf2_blender_gltf import BlenderGlTF + from io_scene_gltf2.blender.imp.gltf2_blender_vnode import VNode, compute_vnodes + from io_scene_gltf2.blender.com.gltf2_blender_extras import set_extras + from io_scene_gltf2.blender.imp.gltf2_blender_node import BlenderNode try: gltf = glTFImporter(filename, import_settings) diff --git a/butils.py b/butils.py index 6663a1a..9b696d1 100644 --- a/butils.py +++ b/butils.py @@ -358,7 +358,7 @@ def turn_collection_hierarchy_into_path(obj): def find_font_object(fontcollection, font_name): fonts = find_objects_by_custom_property(fontcollection.objects, "is_font", True) for font in fonts: - if font["font_name"] == font_name and font.parent is None: + if font["font_name"] == font_name and font.parent == None: return font return None @@ -375,7 +375,7 @@ def move_in_fontcollection(obj, fontcollection, allow_duplicates=False): # parent nesting structure # the font object font_obj = find_font_object(fontcollection, obj["font_name"]) - if font_obj is None: + if font_obj == None: font_obj = bpy.data.objects.new(obj["font_name"], None) font_obj.empty_display_type = "PLAIN_AXES" fontcollection.objects.link(font_obj) @@ -386,7 +386,7 @@ def move_in_fontcollection(obj, fontcollection, allow_duplicates=False): # the face object as a child of font object face_obj = find_font_face_object(font_obj, obj["face_name"]) - if face_obj is None: + if face_obj == None: face_obj = bpy.data.objects.new(obj["face_name"], None) face_obj.empty_display_type = "PLAIN_AXES" face_obj["is_face"] = True @@ -678,8 +678,8 @@ def is_metrics_object(o): if f"{utils.prefix()}_type" in o: return o[f"{utils.prefix()}_type"] == "metrics" return ( - re.match(".*_metrics$", o.name) is not None - or re.match(".*_metrics.[\d]{3}$", o.name) is not None + re.match(".*_metrics$", o.name) != None + or re.match(".*_metrics.[\d]{3}$", o.name) != None ) and is_mesh(o) diff --git a/common/Font.py b/common/Font.py index e7a7ac0..bcb7949 100644 --- a/common/Font.py +++ b/common/Font.py @@ -163,7 +163,7 @@ class Font: def register_font(font_name, face_name, glyphs_in_fontfile, filepath): if not fonts.keys().__contains__(font_name): fonts[font_name] = Font({}) - if fonts[font_name].faces.get(face_name) is None: + if fonts[font_name].faces.get(face_name) == None: fonts[font_name].faces[face_name] = FontFace({}) fonts[font_name].faces[face_name].glyphs_in_fontfile = glyphs_in_fontfile else: @@ -193,9 +193,9 @@ def add_glyph(font_name, face_name, glyph_id, glyph_object): if not fonts.keys().__contains__(font_name): fonts[font_name] = Font({}) - if fonts[font_name].faces.get(face_name) is None: + if fonts[font_name].faces.get(face_name) == None: fonts[font_name].faces[face_name] = FontFace({}) - if fonts[font_name].faces[face_name].glyphs.get(glyph_id) is None: + if fonts[font_name].faces[face_name].glyphs.get(glyph_id) == None: fonts[font_name].faces[face_name].glyphs[glyph_id] = [] fonts[font_name].faces[face_name].glyphs.get(glyph_id).append(glyph_object) @@ -224,13 +224,13 @@ def get_glyph(font_name, face_name, glyph_id, alternate=0): return None face = fonts[font_name].faces.get(face_name) - if face is None: + if face == None: # print(f"ABC3D::get_glyph: font({font_name}) face({face_name}) not found") # print(fonts[font_name].faces.keys()) return None glyphs_for_id = face.glyphs.get(glyph_id) - if glyphs_for_id is None or len(glyphs_for_id) <= alternate: + if glyphs_for_id == None or len(glyphs_for_id) <= alternate: # print(f"ABC3D::get_glyph: font({font_name}) face({face_name}) glyph({glyph_id})[{alternate}] not found") if glyph_id not in fonts[font_name].faces[face_name].missing_glyphs: fonts[font_name].faces[face_name].missing_glyphs.append(glyph_id) @@ -243,7 +243,7 @@ def test_glyphs_availability(font_name, face_name, text): # maybe there is NOTHING yet if ( not fonts.keys().__contains__(font_name) - or fonts[font_name].faces.get(face_name) is None + or fonts[font_name].faces.get(face_name) == None ): return "", "", text # , , @@ -286,7 +286,7 @@ MISSING_FACE = 1 def test_availability(font_name, face_name, text): if not fonts.keys().__contains__(font_name): return MISSING_FONT - if fonts[font_name].faces.get(face_name) is None: + if fonts[font_name].faces.get(face_name) == None: return MISSING_FACE loaded, missing, maybe, filepaths = test_glyphs_availability( font_name, face_name, text