diff --git a/.gitignore b/.gitignore index 4fe2d24..a5a208d 100644 --- a/.gitignore +++ b/.gitignore @@ -103,4 +103,8 @@ ENV/ # blender backup files *.blend1 install_plugin_cad.sh -.vscode \ No newline at end of file +.vscode + +# emacs backup files +~* +*# diff --git a/cg/blender/import_fcstd/importer.py b/cg/blender/import_fcstd/importer.py index eade3dc..3d8cae3 100644 --- a/cg/blender/import_fcstd/importer.py +++ b/cg/blender/import_fcstd/importer.py @@ -23,6 +23,7 @@ import bpy from bpy_extras.node_shader_utils import PrincipledBSDFWrapper from import_fcstd.handler import FreeCAD_xml_handler from import_fcstd.materials import set_fem_mat +from import_fcstd.is_object_solid import is_object_solid logger = logging.getLogger(__name__) logging.basicConfig(level=logging.INFO) @@ -123,6 +124,10 @@ def importer(filename, # TODO add parent visibility check continue + if not is_object_solid(obj): + logger.debug('%s is not solid', obj.Label) + continue + verts = [] edges = [] faces = [] diff --git a/cg/blender/import_fcstd/is_object_solid.py b/cg/blender/import_fcstd/is_object_solid.py new file mode 100644 index 0000000..92c5564 --- /dev/null +++ b/cg/blender/import_fcstd/is_object_solid.py @@ -0,0 +1,31 @@ +# -*- coding: utf-8 -*- +# Original code by (C) 2019 yorikvanhavre +# Copyright (C) 2023 Ilia Kurochkin +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +import FreeCAD + + +def is_object_solid(obj): + """If obj is solid return True""" + if not isinstance(obj, FreeCAD.DocumentObject): + return False + + if not hasattr(obj, 'Shape'): + return False + + if not hasattr(obj.Shape, 'Solids'): + return False + + if len(obj.Shape.Solids) == 0: + return False + + return True