This repository has been archived by the owner on Nov 28, 2019. It is now read-only.
forked from OGRECave/blender2ogre
-
Notifications
You must be signed in to change notification settings - Fork 1
/
config.py
205 lines (178 loc) · 8.11 KB
/
config.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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
import bpy, os, sys, logging, pickle, mathutils
from pprint import pprint
from bpy.props import *
AXIS_MODES = [
('xyz', 'xyz', 'no swapping'),
('xz-y', 'xz-y', 'ogre standard'),
('-xzy', '-xzy', 'non standard'),
]
CONFIG_PATH = bpy.utils.user_resource('CONFIG', path='scripts', create=True)
CONFIG_FILENAME = 'io_ogre.pickle'
CONFIG_FILEPATH = os.path.join(CONFIG_PATH, CONFIG_FILENAME)
_CONFIG_DEFAULTS_ALL = {
'MESH' : True,
'SCENE' : True,
'COPY_SHADER_PROGRAMS' : True,
'MAX_TEXTURE_SIZE' : 4096,
'SWAP_AXIS' : 'xyz', # ogre standard is 'xz-y', but swapping is currently broken
'SEP_MATS' : True,
'SELONLY' : True,
'EXPORT_HIDDEN' : True,
'FORCE_CAMERA' : True,
'FORCE_LAMPS' : True,
'MESH_OVERWRITE' : True,
'ONLY_DEFORMABLE_BONES' : False,
'ONLY_KEYFRAMED_BONES' : False,
'OGRE_INHERIT_SCALE' : False,
'FORCE_IMAGE_FORMAT' : 'NONE',
'TOUCH_TEXTURES' : True,
'ARM_ANIM' : True,
'SHAPE_ANIM' : True,
'ARRAY' : True,
'MATERIALS' : True,
'DDS_MIPS' : True,
'TRIM_BONE_WEIGHTS' : 0.01,
'TUNDRA_STREAMING' : True,
'lodLevels' : 0,
'lodDistance' : 300,
'lodPercent' : 40,
'nuextremityPoints' : 0,
'generateEdgeLists' : False,
'generateTangents' : True, # this is now safe - ignored if mesh is missing UVs
'tangentSemantic' : 'tangent', # used to default to "uvw" but that doesn't seem to work with anything and breaks shaders
'tangentUseParity' : 4,
'tangentSplitMirrored' : False,
'tangentSplitRotated' : False,
'reorganiseBuffers' : True,
'optimiseAnimations' : True,
'interface_toggle': False,
}
_CONFIG_TAGS_ = 'OGRETOOLS_XML_CONVERTER OGRETOOLS_MESH_MAGICK TUNDRA_ROOT OGRE_MESHY IMAGE_MAGICK_CONVERT NVCOMPRESS NVIDIATOOLS_EXE USER_MATERIALS SHADER_PROGRAMS TUNDRA_STREAMING'.split()
''' todo: Change pretty much all of these windows ones. Make a smarter way of detecting
Ogre tools and Tundra from various default folders. Also consider making a installer that
ships Ogre cmd line tools to ease the setup steps for end users. '''
_CONFIG_DEFAULTS_WINDOWS = {
'OGRETOOLS_XML_CONVERTER' : 'C:\\OgreCommandLineTools\\OgreXmlConverter.exe',
'OGRETOOLS_MESH_MAGICK' : 'C:\\OgreCommandLineTools\\MeshMagick.exe',
'TUNDRA_ROOT' : 'C:\\Tundra2',
'OGRE_MESHY' : 'C:\\OgreMeshy\\Ogre Meshy.exe',
'IMAGE_MAGICK_CONVERT' : 'C:\\Program Files\\ImageMagick\\convert.exe',
'NVIDIATOOLS_EXE' : 'C:\\Program Files\\NVIDIA Corporation\\DDS Utilities\\nvdxt.exe',
'USER_MATERIALS' : 'C:\\Tundra2\\media\\materials',
'SHADER_PROGRAMS' : 'C:\\Tundra2\\media\\materials\\programs',
'NVCOMPRESS' : 'C:\\nvcompress.exe'
}
_CONFIG_DEFAULTS_UNIX = {
# do not use absolute paths like /usr/bin/exe_name. some distris install to /usr/local/bin ...
# just trust the env PATH variable
'IMAGE_MAGICK_CONVERT' : 'convert',
'NVCOMPRESS' : 'nvcompress',
'OGRETOOLS_XML_CONVERTER' : 'OgreXMLConverter',
'OGRETOOLS_MESH_MAGICK' : '/usr/local/bin/MeshMagick',
'TUNDRA_ROOT' : '~/Tundra2',
'OGRE_MESHY' : '~/OgreMeshy/Ogre Meshy.exe',
'NVIDIATOOLS_EXE' : '~/.wine/drive_c/Program Files/NVIDIA Corporation/DDS Utilities',
'USER_MATERIALS' : '~/Tundra2/media/materials',
'SHADER_PROGRAMS' : '~/Tundra2/media/materials/programs',
#'USER_MATERIALS' : '~/ogre_src_v1-7-3/Samples/Media/materials',
#'SHADER_PROGRAMS' : '~/ogre_src_v1-7-3/Samples/Media/materials/programs',
}
# Unix: Replace ~ with absolute home dir path
if sys.platform.startswith('linux') or sys.platform.startswith('darwin') or sys.platform.startswith('freebsd'):
for tag in _CONFIG_DEFAULTS_UNIX:
path = _CONFIG_DEFAULTS_UNIX[ tag ]
if path.startswith('~'):
_CONFIG_DEFAULTS_UNIX[ tag ] = os.path.expanduser( path )
elif tag.startswith('OGRETOOLS') and not os.path.isfile( path ):
_CONFIG_DEFAULTS_UNIX[ tag ] = os.path.join( '/usr/bin', os.path.split( path )[-1] )
del tag
del path
## PUBLIC API continues
def load_config():
config_dict = {}
if os.path.isfile( CONFIG_FILEPATH ):
try:
with open( CONFIG_FILEPATH, 'rb' ) as f:
config_dict = pickle.load( f )
except:
print('[ERROR]: Can not read config from %s' %CONFIG_FILEPATH)
for tag in _CONFIG_DEFAULTS_ALL:
if tag not in config_dict:
config_dict[ tag ] = _CONFIG_DEFAULTS_ALL[ tag ]
for tag in _CONFIG_TAGS_:
if tag not in config_dict:
if sys.platform.startswith('win'):
config_dict[ tag ] = _CONFIG_DEFAULTS_WINDOWS[ tag ]
elif sys.platform.startswith('linux') or sys.platform.startswith('darwin') or sys.platform.startswith('freebsd'):
config_dict[ tag ] = _CONFIG_DEFAULTS_UNIX[ tag ]
else:
print( 'ERROR: unknown platform' )
assert 0
try:
if sys.platform.startswith('win'):
import winreg
# Find the blender2ogre install path from windows registry
registry_key = winreg.OpenKey(winreg.HKEY_CLASSES_ROOT, r'Software\blender2ogre', 0, winreg.KEY_READ)
exe_install_dir = winreg.QueryValueEx(registry_key, "Path")[0]
if exe_install_dir != "":
# OgreXmlConverter
if os.path.isfile(exe_install_dir + "OgreXmlConverter.exe"):
print ("Using OgreXmlConverter from install path:", exe_install_dir + "OgreXmlConverter.exe")
config_dict['OGRETOOLS_XML_CONVERTER'] = exe_install_dir + "OgreXmlConverter.exe"
# Run auto updater as silent. Notifies user if there is a new version out.
# This will not show any UI if there are no update and will go to network
# only once per 2 days so it wont be spending much resources either.
# todo: Move this to a more appropriate place than load_config()
if os.path.isfile(exe_install_dir + "check-for-updates.exe"):
subprocess.Popen([exe_install_dir + "check-for-updates.exe", "/silent"])
except Exception as e:
print("Exception while reading windows registry:", e)
# Setup temp hidden RNA to expose the file paths
for tag in _CONFIG_TAGS_:
default = config_dict[ tag ]
#func = eval( 'lambda self,con: config_dict.update( {"%s" : self.%s} )' %(tag,tag) )
func = lambda self,con: config_dict.update( {tag : getattr(self,tag,default)} )
if type(default) is bool:
prop = BoolProperty( name=tag,
description='updates bool setting',
default=default,
options={'SKIP_SAVE'},
update=func)
else:
prop = StringProperty( name=tag,
description='updates path setting',
maxlen=128,
default=default,
options={'SKIP_SAVE'},
update=func)
setattr( bpy.types.WindowManager, tag, prop )
return config_dict
CONFIG = load_config()
def get(name, default=None):
global CONFIG
if name in CONFIG:
return CONFIG[name]
return default
def update(**kwargs):
for k,v in kwargs.items():
if k not in _CONFIG_DEFAULTS_ALL:
print("trying to set CONFIG['%s']=%s, but is not a known config setting" % (k,v))
CONFIG[k] = v
save_config()
def save_config():
global CONFIG
#for key in CONFIG: print( '%s = %s' %(key, CONFIG[key]) )
if os.path.isdir( CONFIG_PATH ):
try:
with open( CONFIG_FILEPATH, 'wb' ) as f:
pickle.dump( CONFIG, f, -1 )
except:
print('[ERROR]: Can not write to %s' %CONFIG_FILEPATH)
else:
print('[ERROR:] Config directory does not exist %s' %CONFIG_PATH)
def update_from_addon_preference(context):
addon_preferences = context.user_preferences.addons["io_ogre"].preferences
for key in _CONFIG_TAGS_:
addon_pref_value = getattr(addon_preferences,key,None)
if addon_pref_value is not None:
CONFIG[key] = addon_pref_value