Skip to content

Instantly share code, notes, and snippets.

@zeffii
Forked from anonymous/grouped_x3d_import.py
Last active August 29, 2015 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zeffii/9e9f69c0bce986382363 to your computer and use it in GitHub Desktop.
Save zeffii/9e9f69c0bce986382363 to your computer and use it in GitHub Desktop.
# ##### BEGIN GPL LICENSE BLOCK #####
#
# 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 2
# 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.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ##### END GPL LICENSE BLOCK #####
# <pep8-80 compliant>
bl_info = {
"name": "x3d wrapped importer Parents",
"author": "alias",
"version": (0, 0, 1),
"blender": (2, 7, 4),
"category": "Import-Export",
"wiki_url": "",
"tracker_url": ""
}
import bpy
from bpy.types import Operator
from bpy.props import (
BoolProperty,
EnumProperty,
FloatProperty,
StringProperty)
from bpy_extras.io_utils import (
ImportHelper,
orientation_helper_factory,
axis_conversion,
path_reference_mode)
from io_scene_x3d import import_x3d
IOX3DOrientationHelper = orientation_helper_factory(
"IOX3DOrientationHelper",
axis_forward='Z',
axis_up='Y')
class ImportX3DBETA(Operator, ImportHelper, IOX3DOrientationHelper):
"""Import an X3D or VRML2 file"""
bl_idname = "import_scene.x3d_grouped"
bl_label = "Import X3D/VRML2 Grouped"
bl_options = {'PRESET', 'UNDO'}
filename_ext = ".x3d"
filter_glob = StringProperty(default="*.x3d;*.wrl", options={'HIDDEN'})
def parent_new_objects(self, object_names):
objects = bpy.data.objects
MT = objects.new('Empty_Grouper', None)
bpy.context.scene.objects.link(MT)
# parent every new object to MT
for obj in (o for o in objects if o.name in object_names):
obj.parent = MT
def execute(self, context):
keywords = self.as_keywords(ignore=("axis_forward",
"axis_up",
"filter_glob",
))
global_matrix = axis_conversion(from_forward=self.axis_forward,
from_up=self.axis_up,
).to_4x4()
keywords["global_matrix"] = global_matrix
before = {obj.name for obj in bpy.data.objects}
response = import_x3d.load(self, context, **keywords)
if response == {'FINISHED'}:
after = {obj.name for obj in bpy.data.objects}
new_names = after ^ before
self.parent_new_objects(new_names)
return {'FINISHED'}
# Only needed if you want to add into a dynamic menu
def menu_func_import(self, context):
self.layout.operator(ImportX3DBETA.bl_idname, text="Import x3d parented")
def register():
bpy.utils.register_class(ImportX3DBETA)
bpy.types.INFO_MT_file_import.append(menu_func_import)
def unregister():
bpy.types.INFO_MT_file_import.remove(menu_func_import)
bpy.utils.unregister_class(ImportX3DBETA)
if __name__ == "__main__":
register()
# test call
# bpy.ops.import_scene.x3d_grouped('INVOKE_DEFAULT')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment