forked from ross-g/io_pdx_mesh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
__init__.py
146 lines (123 loc) · 4.67 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
"""
IO PDX Mesh Python module.
Supports Maya 2018 and up, supports Blender 2.83 and up.
author : ross-g
"""
from __future__ import unicode_literals
import sys
import json
import inspect
import logging
import zipfile
import traceback
import os.path as path
from imp import reload
from collections import OrderedDict
from .settings import PDXsettings
# vendored package imports
from .external.appdirs import user_data_dir # user settings directory
bl_info = {
"author": "ross-g",
"name": "IO PDX Mesh",
"description": "Import/Export Paradox asset files for the Clausewitz game engine.",
"location": "3D View > Toolbox",
"category": "Import-Export",
"support": "COMMUNITY",
"blender": (2, 93, 0),
"maya": (2018),
"version": (0, 9),
"warning": "this add-on is beta",
"project_name": "io_pdx_mesh",
"project_url": "https://github.com/ross-g/io_pdx_mesh",
"doc_url": "https://github.com/ross-g/io_pdx_mesh/wiki",
"tracker_url": "https://github.com/ross-g/io_pdx_mesh/issues",
"forum_url": "https://forum.paradoxplaza.com/forum/index.php?forums/clausewitz-maya-exporter-modding-tool.935/",
}
""" ====================================================================================================================
Setup.
========================================================================================================================
"""
# setup module logging
log_name = "io_pdx"
log_format = "[%(name)s] %(levelname)s: %(message)s"
log_lvl = logging.INFO
# setup module preferences
config_path = path.join(user_data_dir(bl_info["project_name"], False), "settings.json")
IO_PDX_SETTINGS = PDXsettings(config_path)
# setup engine/export settings
root_path = path.abspath(path.dirname(inspect.getfile(inspect.currentframe())))
export_settings = path.join(root_path, "clausewitz.json")
ENGINE_SETTINGS = {}
try:
if ".zip" in export_settings:
zipped = export_settings.split(".zip")[0] + ".zip"
with zipfile.ZipFile(zipped, "r") as z:
f = z.open("io_pdx_mesh/clausewitz.json")
ENGINE_SETTINGS = json.loads(f.read(), object_pairs_hook=OrderedDict)
else:
with open(export_settings, "rt") as f:
ENGINE_SETTINGS = json.load(f, object_pairs_hook=OrderedDict)
except Exception as err:
print(err)
msg = (
"CRITICAL ERROR! Your 'clausewitz.json' settings file has errors and is unreadable."
"Some functions of the tool will not work without these settings."
)
raise RuntimeError(msg)
""" ====================================================================================================================
Startup.
========================================================================================================================
"""
IO_PDX_LOG, running_from, version = None, None, None
environment = sys.executable.lower()
# check if running from Blender
try:
import bpy # noqa
running_from, version = bpy.app.binary_path.lower(), bpy.app.version
except ImportError:
pass
else:
logging.basicConfig(level=log_lvl, format=log_format)
IO_PDX_LOG = logging.getLogger(log_name)
if version < bl_info["blender"]:
IO_PDX_LOG.warning("UNSUPPORTED VERSION! Update to Blender {0}".format(bl_info["blender"]))
bl_info["unsupported_version"] = True
try:
# register the Blender addon
from .pdx_blender import register, unregister # noqa
except Exception as e:
traceback.print_exc()
raise e
# or running from Maya
try:
import maya.cmds # noqa
running_from, version = sys.executable.lower(), int(maya.cmds.about(version=True))
except ImportError:
pass
else:
IO_PDX_LOG = logging.getLogger(log_name)
IO_PDX_LOG.setLevel(log_lvl)
IO_PDX_LOG.propagate = False
IO_PDX_LOG.handlers = []
console = logging.StreamHandler(sys.stdout)
console.setFormatter(logging.Formatter(log_format))
IO_PDX_LOG.addHandler(console)
if version < bl_info["maya"]:
IO_PDX_LOG.warning("UNSUPPORTED VERSION! Update to Maya {0}".format(bl_info["maya"]))
bl_info["unsupported_version"] = True
try:
# launch the Maya UI
from .pdx_maya import maya_ui
reload(maya_ui)
maya_ui.main()
except Exception as e:
traceback.print_exc()
raise e
if running_from is not None:
IO_PDX_LOG.info("Running from {0} ({1})".format(running_from, version))
IO_PDX_LOG.info(root_path)
# otherwise, we don't support running with UI setup
else:
logging.basicConfig(level=logging.DEBUG, format=log_format)
IO_PDX_LOG = logging.getLogger(log_name)
IO_PDX_LOG.warning('Running without UI from environment "{0}"'.format(sys.executable))