Skip to content
This repository was archived by the owner on Dec 9, 2024. It is now read-only.

Commit 09a676f

Browse files
NicoMicoNicoMico
authored andcommitted
op
1 parent bd0eff0 commit 09a676f

File tree

5 files changed

+106
-27
lines changed

5 files changed

+106
-27
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77

88
有无法解决的问题可以联系我或者提交issue。
99

10+
DBMT的Blender插件就在DBMT解压缩后文件夹下的Plugins目录下,以blender开头V10XX结尾,V后面是版本号。
11+
尽量不要使用正在开发中的代码,避免无法适配。
12+
1013
# 开发环境
1114
- Windows11
1215
- Visual Studio Code

blender/__init__.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"name": "DBMT-Blender-Plugin",
2121
"description": "DBMT的Blender插件 目前只支持3.6LTS版本",
2222
"blender": (3, 6, 0),
23-
"version": (1, 0, 1, 8),
23+
"version": (1, 0, 1, 9),
2424
"location": "View3D",
2525
"category": "Generic"
2626
}
@@ -64,7 +64,11 @@
6464
SplitMeshByCommonVertexGroup,
6565

6666
# MMD类型动画Mod支持
67-
MMDModIniGenerator
67+
MMDModIniGenerator,
68+
69+
# Collection's right click menu item.
70+
DBMT_MarkCollection_Switch,
71+
DBMT_MarkCollection_Toggle
6872
)
6973

7074

@@ -84,6 +88,8 @@ def register():
8488
# 右键菜单
8589
bpy.types.VIEW3D_MT_object_context_menu.append(menu_func_migoto_right_click)
8690

91+
bpy.types.OUTLINER_MT_collection.append(menu_dbmt_mark_collection_switch)
92+
8793
# 在Blender退出前保存选择的MMT的路径
8894
bpy.app.handlers.depsgraph_update_post.append(save_mmt_path)
8995

@@ -99,6 +105,9 @@ def unregister():
99105
# 退出时移除右键菜单
100106
bpy.types.VIEW3D_MT_object_context_menu.remove(menu_func_migoto_right_click)
101107

108+
109+
bpy.types.OUTLINER_MT_collection.remove(menu_dbmt_mark_collection_switch)
110+
102111
# 退出注册时删除MMT的MMD变量
103112
del bpy.types.Scene.mmt_mmd_animation_mod_start_frame
104113
del bpy.types.Scene.mmt_mmd_animation_mod_end_frame

blender/rightclick_menu/mesh_operator.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,3 +137,37 @@ def draw(self, context):
137137
# 定义菜单项的注册函数
138138
def menu_func_migoto_right_click(self, context):
139139
self.layout.menu(MigotoRightClickMenu.bl_idname)
140+
141+
142+
143+
# --------------------------
144+
# Right click menu for collection.
145+
class DBMT_MarkCollection_Switch(bpy.types.Operator):
146+
# bl_idname必须小写,中间可以下划线分割,不然报错无法加载
147+
bl_idname = "object.mark_collection_switch"
148+
bl_label = "Mark Collection Switch"
149+
bl_options = {'UNDO'}
150+
151+
def execute(self, context):
152+
# 示例:打印当前选中的集合名称
153+
if context.collection:
154+
context.collection.color_tag = "COLOR_03"
155+
return {'FINISHED'}
156+
157+
class DBMT_MarkCollection_Toggle(bpy.types.Operator):
158+
# bl_idname必须小写,中间可以下划线分割,不然报错无法加载
159+
bl_idname = "object.mark_collection_toggle"
160+
bl_label = "Mark Collection Toggle"
161+
bl_options = {'UNDO'}
162+
163+
def execute(self, context):
164+
# 示例:打印当前选中的集合名称
165+
if context.collection:
166+
context.collection.color_tag = "COLOR_04"
167+
return {'FINISHED'}
168+
169+
170+
def menu_dbmt_mark_collection_switch(self, context):
171+
self.layout.separator()
172+
self.layout.operator(DBMT_MarkCollection_Switch.bl_idname, text="分支:标记为按键开关类型")
173+
self.layout.operator(DBMT_MarkCollection_Toggle.bl_idname, text="分支:标记为按键切换类型")

blender/unity/migoto_export.py

Lines changed: 42 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -369,43 +369,62 @@ def execute(self, context):
369369
if len(selected_collection.children) == 0:
370370
self.report({'ERROR'},"当前选中集合不是一个标准的分支模型集合,请检查您是否以分支集合方式导入了模型。")
371371
return {'FINISHED'}
372+
372373
# 构建一个export.json,记录当前集合所有object层级关系
373-
# part_name_collection_list 装当前集合下所有的集合名称
374-
# 然后是一个键值对,键是集合名称,值是一个列表,装了集合中所有mesh名称,隐藏的mesh不计入在内。
375374
export_json = {}
376-
for child_collection in selected_collection.children:
377-
378-
export_part_name = child_collection.name
375+
for part_collection in selected_collection.children:
376+
# 从集合名称中获取导出后部位的名称,如果有.001这种自动添加的后缀则去除掉
377+
export_part_name = part_collection.name
379378
if "." in export_part_name:
380379
export_part_name = export_part_name[0:len(export_part_name) - 4]
381380

382-
collection_obj_name_list = []
383-
for obj in child_collection.objects:
384-
# 判断对象是否为网格对象,并且不是隐藏状态
385-
if obj.type == 'MESH' and obj.hide_get() == False:
386-
collection_obj_name_list.append("export-" + obj.data.name)
387-
export_json[export_part_name] = collection_obj_name_list
381+
part_collection_json = {}
382+
for model_collection in part_collection.children:
383+
# 声明一个model_collection对象
384+
model_collection_json = {}
385+
386+
# 先根据颜色确定是什么类型的集合 03是开关 04是分支
387+
model_collection_type = "default"
388+
if model_collection.color_tag == "COLOR_03":
389+
model_collection_type = "switch"
390+
elif model_collection.color_tag == "COLOR_04":
391+
model_collection_type = "toggle"
392+
model_collection_json["type"] = model_collection_type
393+
394+
# 集合中的模型列表
395+
model_collection_obj_name_list = []
396+
for obj in model_collection.objects:
397+
# 判断对象是否为网格对象,并且不是隐藏状态
398+
if obj.type == 'MESH' and obj.hide_get() == False:
399+
model_collection_obj_name_list.append("export-" + obj.data.name)
400+
model_collection_json["model"] = model_collection_obj_name_list
401+
402+
# 集合的名称后面用作注释标记到ini文件中
403+
part_collection_json[model_collection.name] = model_collection_json
404+
405+
export_json[export_part_name] = part_collection_json
388406

389407
# 将字典转换为 JSON 格式的字符串
390408
json_string = json.dumps(export_json, ensure_ascii=False, indent=4)
391-
392409
# 将 JSON 字符串写入文件
393410
with open(output_folder_path + draw_ib + "\\" + 'export.json', 'w', encoding='utf-8') as f:
394411
f.write(json_string)
395412

396413
# 随后直接导出所有模型
397414
export_time = 0
398-
for child_collection in selected_collection.children:
399-
for obj in child_collection.objects:
400-
# 判断对象是否为网格对象
401-
if obj.type == 'MESH' and obj.hide_get() == False:
402-
export_time = export_time + 1
403-
bpy.context.view_layer.objects.active = obj
404-
vb_path = output_folder_path + draw_ib + "\\" + "export-" + obj.data.name + ".vb"
405-
ib_path = os.path.splitext(vb_path)[0] + '.ib'
406-
fmt_path = os.path.splitext(vb_path)[0] + '.fmt'
407-
408-
export_3dmigoto(self, context, vb_path, ib_path, fmt_path)
415+
for child_part_collection in selected_collection.children:
416+
for model_collection in child_part_collection.children:
417+
for obj in model_collection.objects:
418+
# 判断对象是否为网格对象
419+
if obj.type == 'MESH' and obj.hide_get() == False:
420+
bpy.context.view_layer.objects.active = obj
421+
vb_path = output_folder_path + draw_ib + "\\" + "export-" + obj.data.name + ".vb"
422+
ib_path = os.path.splitext(vb_path)[0] + '.ib'
423+
fmt_path = os.path.splitext(vb_path)[0] + '.fmt'
424+
425+
export_3dmigoto(self, context, vb_path, ib_path, fmt_path)
426+
427+
export_time = export_time + 1
409428

410429
if export_time == 0:
411430
self.report({'ERROR'}, "导出失败!请选择一个集合后再点一键导出!")

blender/unity/migoto_import.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -493,13 +493,23 @@ def execute(self, context):
493493

494494
# create a new collection.
495495
collection = bpy.data.collections.new(folder_draw_ib_name)
496+
collection.color_tag = "COLOR_07" #红色
496497

497498
# link to scene.collection.
498499
bpy.context.scene.collection.children.link(collection)
499500

501+
part_count = 1
500502
for prefix in import_prefix_list:
503+
component_name = "Component " + str(part_count)
501504
# Create a child collection for every part in a single drawib.
502-
child_collection = bpy.data.collections.new(prefix)
505+
child_collection = bpy.data.collections.new(component_name)
506+
child_collection.color_tag = "COLOR_05" #蓝色
507+
child_collection.tag = True
508+
509+
510+
defualt_collection = bpy.data.collections.new("default")
511+
defualt_collection.color_tag = "COLOR_04" #绿色
512+
defualt_collection.tag = False
503513

504514
# combine and verify if path exists.
505515
vb_bin_path = import_folder_path + "\\" + prefix + '.vb'
@@ -522,17 +532,21 @@ def execute(self, context):
522532
if fmt_path is not None:
523533
obj_result = import_3dmigoto_raw_buffers(self, context, fmt_path=fmt_path, vb_path=vb_bin_path,
524534
ib_path=ib_bin_path, **migoto_raw_import_options)
525-
child_collection.objects.link(obj_result)
535+
defualt_collection.objects.link(obj_result)
526536

527537
else:
528538
self.report({'ERROR'}, "Can't find .fmt file!")
529539

540+
child_collection.children.link(defualt_collection)
541+
530542
# bind to parent collection
531543
collection.children.link(child_collection)
532544

533545

534546
except Fatal as e:
535547
self.report({'ERROR'}, str(e))
548+
549+
part_count = part_count + 1
536550
# Select all objects under collection.
537551
select_collection_objects(collection)
538552

0 commit comments

Comments
 (0)