-
Notifications
You must be signed in to change notification settings - Fork 26
/
__init__.py
604 lines (496 loc) · 15.4 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
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
############################################################################
# BsMax, 3D apps inteface simulator and tools pack for Blender
# Copyright (C) 2021 Naser Merati (Nevil)
#
# 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 3 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, see <https://www.gnu.org/licenses/>.
############################################################################
# 2024/07/21
import bpy
import sys
import os
from bpy.types import AddonPreferences, Operator
from bpy.props import EnumProperty, BoolProperty, FloatProperty
from time import sleep
from _thread import start_new_thread
from bpy.utils import register_class, unregister_class
bl_info = {
'name': "BsMax",
'description': "BsMax UI simulations and Tool pack (Blender 3.6LTS ~ 4.2LTS)",
'author': "Naser Merati (Nevil)",
'version': (0, 1, 3, 20241225),
'blender': (3, 6, 0), # Minimum Version
'location': "Almost Everywhere in Blender",
'doc_url': 'https://github.com/NevilArt/BsMax/wiki',
'tracker_url': 'https://github.com/NevilArt/BsMax/issues',
'category': "Interface"
}
# TODO switch prefrence saving data to jason
# Add public classes, variables and functions path if not in list.
path = os.path.dirname(os.path.realpath(__file__))
if path not in sys.path:
sys.path.append(path)
from .bsmax.math import isfloat
from .bsmax import register_bsmax, unregister_bsmax
from .keymaps import register_keymaps, unregister_keymaps
from .menu import register_menu, unregister_menu
from .primitive import register_primitives, unregister_primitives
from .startup import register_startup, unregister_startup
from .tools import register_tools, unregister_tools
# import templates
addons = bpy.context.preferences.addons
wiki = 'https://github.com/NevilArt/BsMax/wiki/'
iniFileName = bpy.utils.user_resource('SCRIPTS') + '\\addons\\BsMax.ini'
# Addon preferences
def update_preferences(cls, _, action):
global addons
preferences = addons[__name__].preferences
""" Quick Selection """
if cls.mode == 'QUICK' and action == 'APLICATION':
if cls.aplication != 'CUSTOM':
cls.navigation = cls.aplication
cls.keymaps = cls.aplication
cls.navigation_3d = cls.aplication
cls.navigation_2d = cls.aplication
cls.viowport = cls.aplication
cls.sculpt = cls.aplication
cls.uv_editor = cls.aplication
cls.node_editor = cls.aplication
cls.graph_editor = cls.aplication
cls.clip_editor = cls.aplication
cls.video_sequencer = cls.aplication
cls.text_editor = cls.aplication
cls.file_browser = cls.aplication
cls.floatmenus = cls.aplication
if cls.aplication == '3DSMAX':
cls.side_panel='3DSMAX'
else:
cls.side_panel='NONE'
""" Simple Selection """
if cls.mode == 'SIMPLE':
if action == 'NAVIGATION':
if cls.navigation != 'CUSTOM':
cls.navigation_3d = cls.navigation
cls.navigation_2d = cls.navigation
return
elif action in {'KEYMAPS', 'TRANSFORM'}:
if cls.keymaps != 'CUSTOM':
cls.viowport = cls.keymaps
cls.sculpt = cls.keymaps
cls.uv_editor = cls.keymaps
cls.node_editor = cls.keymaps
cls.graph_editor = cls.keymaps
cls.clip_editor = cls.keymaps
cls.video_sequencer = cls.keymaps
cls.text_editor = cls.keymaps
cls.file_browser = cls.keymaps
return
""" Custom Selection """
if action in {
'NAVIGATION_3D', 'NAVIGATION_2D','VIEWPORT',
'SCULPT', 'UV_EDITOR', 'NODE_EDITOR', 'TEXT_EDITOR',
'GRAPH_EDITOR','CLIP_EDITOR', 'VIDEO_SEQUENCER',
'FILE_BROWSER', 'FLOATMENUS', 'VIEW_UNDO'
}:
register_keymaps(preferences)
if action == 'PANEL':
pass
def row_prop(cls, col, name, page):
global wiki
row = col.row()
row.prop(cls, name)
srow = row.row()
srow.scale_x = 1
srow.operator('wm.url_open', icon='HELP').url= wiki + page
def draw_simple_panel(cls, layout):
row = layout.row()
col = row.column()
col.label(text="Select packages parts separately")
row_prop(cls, col, 'navigation', 'Navigation')
row_prop(cls, col, 'keymaps', 'Keymaps-' + cls.keymaps)
row_prop(cls, col, 'floatmenus', 'floatmenus-' + cls.floatmenus)
#TODO update wiki page
row_prop(cls, col, 'side_panel', 'SidePanel-' + cls.floatmenus)
col.label(
text="Note: Sometimes need to restart Blender to addon work properly"
)
def draw_custom_panel(cls, layout):
row = layout.row()
col = row.column()
col.label(text="Select packages parts customly")
row_prop(cls, col, 'navigation_3d', 'navigation_3d-' + cls.navigation_3d)
row_prop(cls, col, 'navigation_2d', 'navigation_2d-' + cls.navigation_2d)
row_prop(cls, col, 'viowport', 'viowport-' + cls.viowport)
row_prop(cls, col, 'sculpt', 'sculpt-' + cls.sculpt)
row_prop(cls, col, 'uv_editor','uv_editor-' + cls.uv_editor)
row_prop(cls, col, 'node_editor', 'node_editor-' + cls.node_editor)
row_prop(cls, col, 'text_editor', 'text_editor-' + cls.text_editor)
row_prop(cls, col, 'graph_editor', 'graph_editor-' + cls.graph_editor)
row_prop(cls, col, 'clip_editor', 'clip_editor-' + cls.clip_editor)
row_prop(cls,
col, 'video_sequencer', 'video_sequencer-' + cls.video_sequencer
)
row_prop(cls, col, 'file_browser', 'file_browser-' + cls.file_browser)
row_prop(cls, col, 'floatmenus', 'floatmenus-' + cls.floatmenus)
row_prop(cls, col, 'side_panel', 'SidePanel-' + cls.floatmenus)
col.label(
text="Note: Sometimes need to restart Blender to addon work properly"
)
def draw_option_panel(cls, layout):
box = layout.box()
row = box.row()
row.prop(cls, 'view_undo')
row.prop(cls, 'menu_scale')
row = box.row()
row.prop(cls, 'blender_transform_type')
row.prop(cls, 'nevil_stuff')
row = box.row()
row.prop(cls, 'geonode_pirimitve')
row.prop(cls, 'affect_theme')
row = box.row()
row.prop(cls, 'experimental')
def save_preferences(preferences):
global iniFileName
string = ''
for prop in preferences.bl_rna.properties:
if not prop.is_readonly:
key = prop.identifier
if key != 'bl_idname':
val = str(getattr(preferences, key))
string += key + '=' + val + os.linesep
ini = open(iniFileName, 'w')
ini.write(string)
ini.close()
def load_preferences(preferences):
global iniFileName
if not os.path.exists(iniFileName):
return
string = open(iniFileName).read()
props = string.splitlines()
for prop in props:
key = prop.split('=')
if len(key) != 2:
continue
if isfloat(key[1]):
value = float(key[1])
elif key[1] in {'True', 'False'}:
value = key[1] == 'True'
else:
value = key[1].upper()
if hasattr(preferences, key[0]):
current_value = getattr(preferences, key[0])
if value != current_value:
setattr(preferences, key[0], value)
class BsMax_AddonPreferences(AddonPreferences):
bl_idname = __name__
mode: EnumProperty(
items=[
(
'SIMPLE',
"Simple",
"Select Package by main parts",
'MESH_UVSPHERE', 2
),
(
'CUSTOM',
"Custom",
"Select Package part by part",
'MESH_ICOSPHERE', 3
)
],
default='SIMPLE',
update= lambda self, ctx: update_preferences(self, ctx, 'aplication'),
description="select a package"
) # type: ignore
apps = [
(
'3DSMAX',
"3DsMax",
"Try to simulate 3DsMax HotKeys and Menus"
),
(
'MAYA',
"Maya",
"Try to simulate Maya HotKeys"
),
(
'NONE',
"Blender (Default)",
"Do not makes any changes on Keymaps"
),
(
'BLENDER',
"Blender (Adapted)",
"Some Keymaps change to work with Bsmax"
)
]
custom = [('CUSTOM', "Custom", "")]
menus = [
(
'3DSMAX',
"3DsMax (Quad Menu)",
"Simulate 3DsMax Quad menu"
),
( 'PIEMAX',
"3DsMax (Pie Menu) (Under Construction)",
"Simulate 3DsMax Quad menu as Pie Menu"
),
(
'MAYA',
"Maya (Not ready yet)",
""
),
(
'BLENDER',
"Blender (Default)",
"Do not make any changes."
)
]
panels = [
('3DSMAX', "3DsMax (Command Panel)", ""),
('NONE', "None", "")
]
""" Quick select mode """
aplication: EnumProperty(
name="Aplication",
items=apps+custom,
default='BLENDER',
update= lambda self, ctx: update_preferences(self, ctx, 'APLICATION'),
description="select a package"
) # type: ignore
""" Simple select mode """
navigation: EnumProperty(
name="Navigation",
items=apps+custom,
default='BLENDER',
update= lambda self, ctx: update_preferences(self, ctx, 'NAVIGATION'),
description="select overide navigation mode"
) # type: ignore
keymaps: EnumProperty(
name="Keymap",
items=apps+custom,
default='BLENDER',
update= lambda self, ctx: update_preferences(self, ctx, 'KEYMAPS'),
description="Overide Full Keymap"
) # type: ignore
floatmenus: EnumProperty(
name="Float Menu",
items=menus,
default='BLENDER',
update= lambda self, ctx: update_preferences(self, ctx, 'FLOATMENUS'),
description="Float menus type"
) # type: ignore
side_panel: EnumProperty(
name="Side Panel",
items=panels,
default='NONE',
update= lambda self, ctx: update_preferences(self, ctx, 'PANEL'),
description="panel in right side of target software"
) # type: ignore
""" Custom select mode """
navigation_3d: EnumProperty(
name="Navigation 3D",
items=apps,
default='BLENDER',
update= lambda self, ctx: update_preferences(
self, ctx, 'NAVIGATION_3D'
),
description="Overide navigation on 3D View"
) # type: ignore
navigation_2d: EnumProperty(
name="Navigation 2D",
items=apps,
default='BLENDER',
update= lambda self, ctx: update_preferences(
self, ctx, 'NAVIGATION_2D'
),
description="Overide navigation in 2D Views"
) # type: ignore
viowport: EnumProperty(
name="View 3D",
items=apps,
default='BLENDER',
update= lambda self, ctx: update_preferences(self, ctx, 'VIEWPORT'),
description="Overide keymaps in 3D view"
) # type: ignore
sculpt: EnumProperty(
name="Sculpt / Paint",
items=apps,
default='BLENDER',
update= lambda self, ctx: update_preferences(self, ctx, 'SCULPT'),
description="Overide keymaps in sculpt and paint mode"
) # type: ignore
uv_editor: EnumProperty(
name="UV Editor",
items=apps,
default='BLENDER',
update= lambda self, ctx: update_preferences(self, ctx, 'UV_EDITOR'),
description="Overide keymaps in UV editor"
) # type: ignore
node_editor: EnumProperty(
name="Node Editor",
items=apps,
default='BLENDER',
update= lambda self, ctx: update_preferences(self, ctx, 'NODE_EDITOR'),
description="Overide keymaps in Node editors"
) # type: ignore
graph_editor: EnumProperty(
name="Graph Editor",
items=apps,
default='BLENDER',
update= lambda self, ctx: update_preferences(
self, ctx, 'GRAPH_EDITOR'
),
description="Overide keymaps in Time ediotrs"
) # type: ignore
clip_editor: EnumProperty(
name="Clip Editor",
items=apps,
default='BLENDER',
update= lambda self, ctx: update_preferences(self, ctx, 'CLIP_EDITOR'),
description="Overide keymaps in Clip editor"
) # type: ignore
video_sequencer: EnumProperty(
name="Video Sequencer",
items=apps + [('Premiere', "Premiere", "")],
default='BLENDER',
update= lambda self, ctx: update_preferences(
self, ctx, 'VIDEO_SEQUENCER'
),
description="Overide keymaps in Video sequencer"
) # type: ignore
text_editor: EnumProperty(
name="Text Editor",
items=apps,
default='BLENDER',
update= lambda self, ctx: update_preferences(
self, ctx, 'TEXT_EDITOR'
),
description="Overide keymaps in text editor"
) # type: ignore
file_browser: EnumProperty(
name="File Browser",
items=apps,
default='BLENDER',
update= lambda self, ctx: update_preferences(
self, ctx, 'FILE_BROWSER'
),
description="Overide keymaps in File Browser"
) # type: ignore
""" Global options """
options: BoolProperty(default=False) # type: ignore
view_undo: BoolProperty(
name="View Undo",
default=False,
update= lambda self, ctx: update_preferences(self, ctx, 'VIEW_UNDO'),
description="undo the only view angle"
) # type: ignore
menu_scale: FloatProperty(
name="Float Menu Scale", min=1, max=3,
description=""
) # type: ignore
menu_auto_scale: BoolProperty(
name="Auto",
default=False,
description="Link float menu size to thema scale value"
) # type: ignore
blender_transform_type: BoolProperty(
name="Blender Transform Type",
default=False,
update= lambda self, ctx: update_preferences(self, ctx, 'TRANSFORM'),
description="Make 'W E R' work as 'G R S', Need to restart to See effect"
) # type: ignore
nevil_stuff: BoolProperty(
name="Developer Exteras",
default=False,
description="This tools may not usefull for theres, just keep it off"
) # type: ignore
affect_theme: BoolProperty(
name="Affect Theme",
default=True,
description="Let addon change some part of theme"
) # type: ignore
experimental: BoolProperty(
name="Experimental",
default=False,
description="Enable unfinished tools too"
) # type: ignore
geonode_pirimitve: BoolProperty(
name="GeoNode primitive",
default=False,
description="Convert Primitives to geometry node modfier"
) # type: ignore
def draw(self, _):
layout = self.layout
box = layout.box()
row = box.row(align=True)
row.prop(self, 'mode', expand=True)
if self.mode == 'SIMPLE':
draw_simple_panel(self, box)
elif self.mode == 'CUSTOM':
draw_custom_panel(self, box)
box = layout.box()
row = box.row()
icon = 'DOWNARROW_HLT' if self.options else 'RIGHTARROW'
row.prop(self, 'options', text="Options", icon=icon)
row.operator(
'bsmax.save_preferences',
text="Save Preferences Setting",
icon='FILE_TICK'
)
if self.options:
draw_option_panel(self, box)
if self.menu_scale < 1:
self.menu_scale = 1
class BsMax_OT_Save_Preferences(Operator):
bl_idname = 'bsmax.save_preferences'
bl_label = "Save BsMax Preferences"
bl_options = {'REGISTER', 'INTERNAL'}
def execute(self, _):
global addons
save_preferences(addons[__name__].preferences)
return{'FINISHED'}
def register_delay(preferences):
sleep(0.2)
register_keymaps(preferences)
register_startup(preferences)
classes = {
BsMax_OT_Save_Preferences,
BsMax_AddonPreferences
}
def register():
global classes, addons
for cls in classes:
register_class(cls)
preferences = addons[__name__].preferences
load_preferences(preferences)
register_bsmax()
register_primitives(preferences)
register_tools(preferences)
register_menu(preferences)
# templates.register()
start_new_thread(register_delay, tuple([preferences]))
def unregister():
global classes, addons
save_preferences(addons[__name__].preferences)
unregister_keymaps()
unregister_menu()
unregister_tools()
unregister_primitives()
unregister_startup()
unregister_bsmax()
for cls in classes:
unregister_class(cls)
# templates.unregister()
if path in sys.path:
sys.path.remove(path)