Compare commits
11 commits
13b5a4dd88
...
7b4e65cbb7
Author | SHA1 | Date | |
---|---|---|---|
7b4e65cbb7 | |||
4113343e79 | |||
e21ecaef0a | |||
9c77139dcd | |||
5bd78a3fc1 | |||
1e54a10341 | |||
23624ea1eb | |||
42c4a33801 | |||
35d864b9b8 | |||
a2c4ba60f2 | |||
7e2eeeeec1 |
3 changed files with 30 additions and 26 deletions
32
bimport.py
32
bimport.py
|
@ -4,11 +4,10 @@ from bpy.props import (
|
|||
BoolProperty,
|
||||
EnumProperty,
|
||||
IntProperty,
|
||||
FloatProperty,
|
||||
CollectionProperty,
|
||||
)
|
||||
from bpy.types import Operator
|
||||
from bpy_extras.io_utils import ImportHelper, ExportHelper
|
||||
from bpy_extras.io_utils import ImportHelper
|
||||
from io_scene_gltf2 import ConvertGLTF2_Base
|
||||
import importlib
|
||||
|
||||
|
@ -16,20 +15,31 @@ import importlib
|
|||
if "Font" in locals():
|
||||
importlib.reload(Font)
|
||||
else:
|
||||
from .common import Font
|
||||
pass
|
||||
|
||||
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)
|
||||
|
@ -50,7 +60,7 @@ def get_font_faces_in_file(filepath):
|
|||
out.append(node.extras)
|
||||
return out
|
||||
|
||||
except ImportError as e:
|
||||
except ImportError:
|
||||
return None
|
||||
|
||||
|
||||
|
@ -60,7 +70,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 = f"abc3d.check_font_gltf"
|
||||
bl_idname = "abc3d.check_font_gltf"
|
||||
bl_label = "Check glTF 2.0 Font"
|
||||
bl_options = {"REGISTER", "UNDO"}
|
||||
|
||||
|
@ -77,7 +87,6 @@ class GetFontFacesInFile(Operator, ImportHelper):
|
|||
|
||||
def check_gltf2(self, context):
|
||||
import os
|
||||
import sys
|
||||
|
||||
if self.files:
|
||||
# Multiple file check
|
||||
|
@ -100,7 +109,7 @@ class GetFontFacesInFile(Operator, ImportHelper):
|
|||
class ImportGLTF2(Operator, ConvertGLTF2_Base, ImportHelper):
|
||||
"""Load a glTF 2.0 font"""
|
||||
|
||||
bl_idname = f"abc3d.import_font_gltf"
|
||||
bl_idname = "abc3d.import_font_gltf"
|
||||
bl_label = "Import glTF 2.0 Font"
|
||||
bl_options = {"REGISTER", "UNDO"}
|
||||
|
||||
|
@ -285,11 +294,6 @@ 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)
|
||||
|
|
10
butils.py
10
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 == None:
|
||||
if font["font_name"] == font_name and font.parent is 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 == None:
|
||||
if font_obj is 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 == None:
|
||||
if face_obj is 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) != None
|
||||
or re.match(".*_metrics.[\d]{3}$", o.name) != None
|
||||
re.match(".*_metrics$", o.name) is not None
|
||||
or re.match(".*_metrics.[\d]{3}$", o.name) is not None
|
||||
) and is_mesh(o)
|
||||
|
||||
|
||||
|
|
|
@ -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) == None:
|
||||
if fonts[font_name].faces.get(face_name) is 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) == None:
|
||||
if fonts[font_name].faces.get(face_name) is None:
|
||||
fonts[font_name].faces[face_name] = FontFace({})
|
||||
if fonts[font_name].faces[face_name].glyphs.get(glyph_id) == None:
|
||||
if fonts[font_name].faces[face_name].glyphs.get(glyph_id) is 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 == None:
|
||||
if face is 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 == None or len(glyphs_for_id) <= alternate:
|
||||
if glyphs_for_id is 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) == None
|
||||
or fonts[font_name].faces.get(face_name) is None
|
||||
):
|
||||
return "", "", text # <loaded>, <missing>, <maybe>
|
||||
|
||||
|
@ -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) == None:
|
||||
if fonts[font_name].faces.get(face_name) is None:
|
||||
return MISSING_FACE
|
||||
loaded, missing, maybe, filepaths = test_glyphs_availability(
|
||||
font_name, face_name, text
|
||||
|
|
Loading…
Add table
Reference in a new issue