forked from rdb/blender-egg-importer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
__init__.py
executable file
·108 lines (83 loc) · 3.21 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
bl_info = {
"name": "Import Panda3D .egg models",
"author": "rdb",
"version": (2, 3),
"blender": (2, 80, 0),
"location": "File > Import > Panda3D (.egg)",
"description": "",
"warning": "",
"category": "Import-Export",
}
import bpy
if bpy.app.version < (2, 80):
bl_info["blender"] = (2, 74, 0) # Needed for normals_split_custom_set
if "loaded" in locals():
import imp
imp.reload(eggparser)
imp.reload(importer)
else:
from . import eggparser
from . import importer
loaded = True
import os.path
import bpy.types
from bpy import props
from bpy_extras.io_utils import ImportHelper
class IMPORT_OT_egg(bpy.types.Operator, ImportHelper):
"""Import .egg Operator"""
bl_idname = "import_scene.egg"
bl_label = "Import .egg"
bl_description = "Import a Panda3D .egg file"
bl_options = {'REGISTER', 'UNDO'}
filename_ext = ".egg"
filter_glob = props.StringProperty(default="*.egg;*.egg.pz;*.egg.gz", options={'HIDDEN'})
directory = props.StringProperty(name="Directory", options={'HIDDEN'})
files = props.CollectionProperty(type=bpy.types.OperatorFileListElement, options={'HIDDEN'})
load_external = props.BoolProperty(name="Load external references", description="Loads other .egg files referenced by this file as separate scenes, and instantiates them using DupliGroups.")
auto_bind = props.BoolProperty(name="Auto bind", default=True, description="Automatically tries to bind actions to armatures.")
def execute(self, context):
context = importer.EggContext()
context.info = lambda msg: self.report({'INFO'}, context.prefix_message(msg))
context.warn = lambda msg: self.report({'WARNING'}, context.prefix_message(msg))
context.error = lambda msg: self.report({'ERROR'}, context.prefix_message(msg))
context.search_dir = self.directory
roots = []
for file in self.files:
path = os.path.join(self.directory, file.name)
root = context.read_file(path)
roots.append(root)
for root in roots:
root.build_tree(context)
context.assign_vertex_groups()
if self.load_external:
context.load_external_references()
if self.auto_bind:
context.auto_bind()
context.final_report()
return {'FINISHED'}
def invoke(self, context, event):
wm = context.window_manager
wm.fileselect_add(self)
return {'RUNNING_MODAL'}
def draw(self, context):
layout = self.layout
row = layout.row()
row.prop(self, "load_external")
row = layout.row()
row.prop(self, "auto_bind")
def menu_func(self, context):
self.layout.operator(IMPORT_OT_egg.bl_idname, text="Panda3D (.egg)")
def register():
bpy.utils.register_class(IMPORT_OT_egg)
if bpy.app.version >= (2, 80):
bpy.types.TOPBAR_MT_file_import.append(menu_func)
else:
bpy.types.INFO_MT_file_import.append(menu_func)
def unregister():
if bpy.app.version >= (2, 80):
bpy.types.TOPBAR_MT_file_import.remove(menu_func)
else:
bpy.types.INFO_MT_file_import.remove(menu_func)
bpy.utils.unregister_class(IMPORT_OT_egg)
if __name__ == "__main__":
register()