-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy path__init__.py
421 lines (338 loc) · 14.8 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
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
import bpy
import bpy.utils.previews
import bpy_types
from bpy.props import *
from bpy.app.handlers import persistent
import os
ADDON_ROOT_PATH = os.path.dirname(__file__)
bl_info = {
"name" : "Blendermania",
"author" : "skyslide22, juice & schadocalex",
"description" : "Makes creating objects for Trackmania more easy and fun!",
"blender" : (4, 0, 0),
"version" : (4, 2, 2),
"location" : "View3D",
"warning" : "",
"category" : "Generic",
}
from .utils.Constants import *
from .utils.Descriptions import *
from .utils.Dotnet import *
from .utils.Functions import *
from .utils.ItemsExport import *
from .utils.ItemsIcon import *
from .utils.ItemsImport import *
from .utils.ItemsUVs import *
from .utils.Materials import *
from .utils.Models import *
from .utils.NadeoImporter import *
from .utils.NadeoXML import *
from .utils.BlenderObjects import *
from .utils.Server import run_server
from .properties.Functions import *
from .properties.ConvertingItemsProperties import *
from .properties.GeneratedProperties import *
from .properties.ItemXMLTemplatesProperties import *
from .properties.LinkedMaterialsProperties import *
from .properties.MapObjectProperties import *
from .properties.PannelsPropertyGroup import *
from .properties.PivotsProperties import *
from .operators.OT_Map_Manipulate import *
from .operators.OT_NinjaRipper import *
from .operators.OT_Settings import *
from .operators.OT_Items_Export import *
from .operators.OT_Materials import *
from .operators.OT_Items_XML import *
from .operators.OT_Items_Icon import *
from .operators.OT_Items_Manipulate import *
from .operators.OT_UV_Manipulate import *
from .operators.OT_Assets_Library import *
from .operators.OT_Items_Templates import *
from .operators.OT_WikiLink import *
from .operators.OT_Textures import *
from .operators.OT_Imports import *
from .operators.OT_VisibilitySelection import *
from .panels.PT_Map_Manipulate import *
from .panels.PT_Imports import *
from .panels.PT_Settings import *
from .panels.PT_Items_Export import *
from .panels.PT_Materials import *
from .panels.PT_Items_XML import *
from .panels.PT_Items_UVMaps import *
from .panels.PT_Items_Icon import *
from .panels.PT_Items_Manipulate import *
from .panels.PT_UV_Manipulate import *
from .panels.PT_Textures import *
from .panels.PT_VisibilitySelection import *
from .panels.PT_EditorTrails import *
from .NICE.nice import NICE_register, NICE_unregister
# owner of the object eventlistener
object_eventlistner_owner = object()
# register order matters for UI panel ordering
classes = (
# props (not panel)
MapObjectProperties,
PannelsPropertyGroup,
GeneratedProperties,
PivotsProperties,
ConvertingItemsProperties,
LinkedMaterialsProperties,
ItemXMLTemplate,
InvalidMaterial,
FailedConvertObject,
FailedConvertCollection,
FailedConverts,
# settings
TM_PT_Settings,
TM_PT_Settings_BlenderRelated,
TM_PT_Settings_NadeoImporter,
TM_PT_Settings_Performance,
TM_OT_Settings_AutoFindNadeoIni,
TM_OT_Settings_InstallNadeoImporter,
TM_OT_Settings_InstallGameTextures,
TM_OT_Settings_InstallGameAssetsLIbrary,
TM_OT_Settings_InstallBlendermaniaDotnet,
TM_OT_Settings_UpdateAddon,
TM_OT_Settings_UpdateAddonResetSettings,
TM_OT_Settings_UpdateAddonCheckForNewRelease,
TM_OT_Settings_OpenUrl,
TM_OT_Settings_OpenFolder,
TM_OT_Settings_DebugAll,
TM_OT_Settings_OpenConvertReport,
TM_PT_Settings_Experimentals,
# object manipulation
TM_PT_ObjectManipulations,
TM_PT_Items_CollectionManipulation,
TM_PT_Items_ObjectManipulation,
TM_OT_Items_ObjectManipulationAddSocketItem,
TM_OT_Items_ObjectManipulationAddTriggerItem,
TM_OT_Items_ObjectManipulationToggleIgnore,
TM_OT_Items_ObjectManipulationToggleItem,
TM_OT_Items_ObjectManipulationToggleIconOnly,
TM_OT_Items_CollectionManipulationToggleIgnore,
TM_OT_Items_ObjectManipulationToggleNotvisible,
TM_OT_Items_ObjectManipulationToggleNotcollidable,
TM_OT_Items_ObjectManipulationToggleSocket,
TM_OT_Items_ObjectManipulationToggleTrigger,
TM_OT_Items_ObjectManipulationToggleLod0,
TM_OT_Items_ObjectManipulationToggleLod1,
TM_OT_Items_ObjectManipulationToggleDoublesided,
TM_OT_Items_ObjectManipulationToggleOrigin,
TM_OT_Items_ObjectManipulationTogglePivot,
TM_OT_Items_ObjectManipulationChangeCollectionScale,
TM_OT_Items_SetItemXMLTemplateOfCollection,
TM_OT_Items_ToggleLightType,
TM_OT_Items_ToggleNightOnly,
TM_OT_Items_RenameObject,
TM_OT_Items_EditUVMap,
TM_OT_Items_ShowUVMap,
TM_OT_Items_CollectionManipulationToggleNICE,
TM_OT_Items_ObjectManipulationToggleGate,
# object visibility and selection controls
TM_PT_VisibilitySelection,
TM_OT_VisibilitySelection_Toggle,
# uv manipulation
TM_PT_UVManipulations,
TM_OT_Items_UVManipulationsFollowActiveQuadsForFaceLoop,
# export
TM_PT_Items_Export,
TM_OT_Items_Export_ExportAndOrConvert,
TM_OT_Items_Export_CloseConvertSubPanel,
TM_OT_Items_Export_ExportAndOrConverFailedOnes,
# xml,
TM_PT_Items_MeshXML,
TM_PT_Items_ItemXML,
TM_OT_Items_ItemXML_AddPivot,
TM_OT_Items_ItemXML_RemovePivot,
TM_OT_Items_ItemXML_SaveItemPlacementTemplate,
TM_OT_Items_ItemXML_RemoveItemPlacementTemplate,
# icons,
TM_PT_Items_Icon,
TM_OT_Items_Icon_Test,
# uvs
TM_PT_Items_UVmaps_LightMap,
TM_PT_Items_UVmaps_BaseMaterial_CubeProject,
# materials
TM_PT_Materials,
TM_OT_Materials_Create,
TM_OT_Materials_Update,
TM_OT_Materials_Create_Asset_Lib,
TM_OT_Materials_ClearBaseMaterial,
TM_OT_Materials_RevertCustomColor,
TM_OT_Materials_CloseInvalidPanel,
# textures
TM_PT_Textures,
TM_PT_Textures_Install,
TM_OT_Textures_ToggleModwork,
TM_OT_Textures_UpdateTextureSource,
# ninja
TM_OT_Ninja17Install,
TM_OT_Ninja20Install,
# imports
TM_OT_ImportItem,
TM_PT_Imports,
# templates
OT_ItemsCarsTemplates,
OT_ItemsEnviTemplates,
OT_MediaTrackerClipTriggerTemplates,
# map
OT_UICollectionToMap,
OT_UIValidateMapCollection,
PT_UIMapManipulation,
PT_UIMapExport,
PT_UIMapObjectsManipulation,
OT_UICreateUpdateMapItemBlock,
OT_UIImportMediatrackerClips,
OT_UIExportMediatrackerClips,
PT_UIMediatrackerClips,
OT_UIChangeMediatrackerTriggerClipName,
OT_UIRefreshMediatrackerTriggerClipNamesFromMap,
OT_UISelectMediatrackerTriggersByName,
PT_UIMapHelpers,
# editor trails
TM_PT_UIEditorTrails,
# util
OT_UIWikiLink,
TM_OT_Settings_OpenMessageBox,
# experimental/dangerous
TM_PT_DangerousManualManipulations,
)
# register classes
def register():
for cls in classes:
bpy.utils.register_class(cls)
bpy.types.Scene.tm_props = PointerProperty( type=PannelsPropertyGroup)
bpy.types.Scene.tm_props_pivots = CollectionProperty(type=PivotsProperties)
bpy.types.Scene.tm_props_generated = CollectionProperty(type=GeneratedProperties)
bpy.types.Scene.tm_props_convertingItems = CollectionProperty(type=ConvertingItemsProperties)
bpy.types.Scene.tm_props_linkedMaterials = CollectionProperty(type=LinkedMaterialsProperties)
bpy.types.Scene.tm_props_invalidMaterials = CollectionProperty(type=InvalidMaterial)
bpy.types.Scene.tm_props_failed_converts = PointerProperty(type=FailedConverts)
# bpy.types.Scene.tm_props_itemxml_templates= CollectionProperty(type=ItemXMLTemplatesProperties)
bpy.types.Scene.tm_props_itemxml_templates_ui = EnumProperty(items=get_itemxml_template_names_enum)
bpy.types.Scene.tm_props_itemxml_templates = CollectionProperty(type=ItemXMLTemplate)
bpy.types.DATA_PT_EEVEE_light.append(draw_nightonly_option)
bpy.types.Light.night_only = BoolProperty(default=False)
bpy.types.VIEW3D_MT_add.prepend(OT_MediaTrackerClipTriggerTemplates.add_menu_item)
bpy.types.VIEW3D_MT_add.prepend(OT_ItemsCarsTemplates.add_menu_item)
bpy.types.VIEW3D_MT_add.prepend(OT_ItemsEnviTemplates.add_menu_item)
# object extra props
bpy.types.Object.tm_map_object_kind = StringProperty(name="Item (soon Block)", default="Item")
bpy.types.Object.tm_map_object_path = StringProperty(name="Name/Path of Item or Block", default="")
bpy.types.Object.tm_map_object_animphaseoffset = EnumProperty(name="Animation Phase Offset", items=get_animphaseoffset_values())
bpy.types.Object.tm_map_object_difficultycolor = EnumProperty(name="Difficulty Color", items=get_difficultycolor_values())
bpy.types.Object.tm_map_object_lightmapquality = EnumProperty(name="Lightmap Quality", items=get_lightmapquality_values())
bpy.types.Object.tm_map_clip_name = StringProperty(name="Name of mediatracker clip", default="")
bpy.types.Object.tm_force_grid_helper = BoolProperty(default=False)
bpy.types.Object.tm_forced_grid_helper_step_x = FloatProperty(default=0.0)
bpy.types.Object.tm_forced_grid_helper_step_y = FloatProperty(default=0.0)
bpy.types.Object.tm_forced_grid_helper_step_z = FloatProperty(default=0.0)
# collections
bpy.types.Collection.tm_itemxml_template = StringProperty(name="Item XML Template", default="")
# material extra props
bpy.types.Material.gameType = EnumProperty( name="Game", default=0, items=getGameTypes())
bpy.types.Material.baseTexture = StringProperty( name="BaseTexture", default="")
bpy.types.Material.link = StringProperty( name="Link", default="")
bpy.types.Material.physicsId = StringProperty( name="PhysicsId", default="")
bpy.types.Material.usePhysicsId = BoolProperty( name="Use PhysicsId", default=False)
bpy.types.Material.gameplayId = StringProperty( name="GameplayId", default="")
bpy.types.Material.useGameplayId = BoolProperty( name="Use GameplayId", default=False)
bpy.types.Material.model = EnumProperty( name="Model", default="TDSN", items=getMaterialModelTypes())
bpy.types.Material.environment = EnumProperty( name="Collection", default="Stadium", items=getMaterialCollectionTypes())#Material."collection" not allowed
# the size should be 4 (for BSDF) but to keep backward compability we have to keep it with size=3 (we convert it later in the code)
bpy.types.Material.surfaceColor = FloatVectorProperty( name='Surface Color ', subtype='COLOR', min=0, max=1, step=1000, default=(0.0,0.319,0.855))
# object listeners
from .utils.MapObjects import listen_object_move
try:
bpy.app.handlers.depsgraph_update_post.remove(listen_object_move)
except:
pass
bpy.app.handlers.depsgraph_update_post.append(listen_object_move)
bpy.types.Object.location_before = FloatVectorProperty(name="old pos", subtype="TRANSLATION")
NICE_register()
# delete classes
def unregister():
for cls in reversed(classes):
bpy.utils.unregister_class(cls)
del bpy.types.Scene.tm_props
del bpy.types.Scene.tm_props_generated
del bpy.types.Scene.tm_props_pivots
del bpy.types.Scene.tm_props_convertingItems
del bpy.types.Scene.tm_props_linkedMaterials
del bpy.types.Scene.tm_props_itemxml_templates_ui
del bpy.types.Scene.tm_props_itemxml_templates
# del bpy.types.Scene.tm_props_itemxml_templates
del bpy.types.Object.location_before
bpy.types.DATA_PT_EEVEE_light.remove(draw_nightonly_option)
bpy.types.VIEW3D_MT_add.remove(OT_ItemsCarsTemplates.add_menu_item)
bpy.types.VIEW3D_MT_add.remove(OT_ItemsEnviTemplates.add_menu_item)
bpy.types.VIEW3D_MT_add.remove(OT_MediaTrackerClipTriggerTemplates.add_menu_item)
# icons
for pcoll in preview_collections.values():
bpy.utils.previews.remove(pcoll)
preview_collections.clear()
from .utils.MapObjects import listen_object_move
try:
bpy.app.handlers.depsgraph_update_post.remove(listen_object_move)
except:
pass
NICE_unregister()
@persistent
def on_save(what, idontknow) -> None: # on quit?
"""run on blender save"""
saveDefaultSettingsJSON()
# TODO runs 10 times on new blend file ??
@persistent
def on_startup(dummy) -> None:
"""run on blender startup, load blend file & reload current file"""
# can be opened on save
try:
bpy.ops.view3d.tm_closeconvertsubpanel()
bpy.ops.view3d.tm_resetaddonupdatesettings()
tm_props = get_global_props()
tm_props.CB_DL_ProgressRunning = False
tm_props.NU_DL_Progress = 0
tm_props.ST_DL_ProgressErrors = ""
tm_props.CB_DL_ProgressShow = False
# so grid_subdivisions is editable
bpy.context.scene.unit_settings.system = 'NONE'
except AttributeError as error:
debug(error)
pass # fails on first startup when open_mainfile used
loadDefaultSettingsJSON()
@in_new_thread
def checkUpdate():
AddonUpdate.check_for_new_release()
checkUpdate()
# external addons
installUvPackerAddon()
# remove possible error text
is_nadeoimporter_installed()
update_installed_nadeoimporter_version_ui()
# modwork
check_modwork_folders_enabled()
from .utils.MapObjects import delete_map_grid_helper_and_cleanup
delete_map_grid_helper_and_cleanup()
# this mat is auto created by blender, remove due appearance in mat list
stroke_mat = bpy.data.materials.get("Dots Stroke", None)
if stroke_mat is not None:
bpy.data.materials.remove(stroke_mat)
# clear before add to avoid multi register
bpy.msgbus.clear_by_owner(object_eventlistner_owner)
# eventlistner when a object gets selected
try:
bpy.msgbus.subscribe_rna(
key=(bpy.types.LayerObjects, 'active'),
owner=object_eventlistner_owner,
args=(),
notify=on_select_obj
)
except RuntimeError:
pass # first try always fails
# RuntimeError: subscribe_rna, missing bl_rna attribute from 'Scene' instance (may not be registered)
try:
run_server()
except:
print("server died hm..")
bpy.app.handlers.load_post.append(on_startup)
bpy.app.handlers.save_post.append(on_save)