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

Commit

Permalink
op
Browse files Browse the repository at this point in the history
  • Loading branch information
NicoMico authored and NicoMico committed Nov 8, 2024
1 parent b531d47 commit 9aa2156
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
2 changes: 1 addition & 1 deletion blender/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"name": "DBMT-Blender-Plugin",
"description": "DBMT的Blender插件 目前只支持3.6LTS版本",
"blender": (3, 6, 0),
"version": (1, 0, 1, 5),
"version": (1, 0, 1, 6),
"location": "View3D",
"category": "Generic"
}
Expand Down
7 changes: 7 additions & 0 deletions blender/unity/migoto_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,13 @@ def export_3dmigoto(operator, context, vb_path, ib_path, fmt_path):
# Write format reference file
write_fmt_file(open(fmt_path, 'w'), vb, ib)

# Flush every time export
bpy.context.view_layer.update()

# Force flush make good user experience.
bpy.ops.wm.redraw_timer(type='DRAW_WIN_SWAP', iterations=1)



class Export3DMigoto(bpy.types.Operator, ExportHelper):
"""Export a mesh for re-injection into a game with 3DMigoto"""
Expand Down
29 changes: 20 additions & 9 deletions blender/unity/migoto_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,25 +243,30 @@ def create_material_with_texture(obj, mesh_name:str, directory:str):


def import_3dmigoto_raw_buffers(operator, context, fmt_path:str, vb_path:str, ib_path:str, flip_texcoord_v=True, **kwargs):
vb = VertexBuffer(open(fmt_path, 'r'))
vb.parse_vb_bin(open(vb_path, 'rb'))

ib = IndexBuffer(open(fmt_path, 'r'))
ib.parse_ib_bin(open(ib_path, 'rb'))


# get import prefix
mesh_name = os.path.basename(fmt_path)
if mesh_name.endswith(".fmt"):
mesh_name = mesh_name[0:len(mesh_name) - 4]

# 创建mesh和Object对象,用于后续填充
# create mesh and obj
mesh = bpy.data.meshes.new(mesh_name)
obj = bpy.data.objects.new(mesh.name, mesh)

# 设置坐标系
# TODO every game need different coordinate.
obj.matrix_world = axis_conversion(from_forward='-Z', from_up='Y').to_4x4()

# check if .ib .vb file is empty, skip empty import.
if os.path.getsize(vb_path) == 0 or os.path.getsize(ib_path) == 0:
return obj

# create vb and ib class and read data.
vb = VertexBuffer(open(fmt_path, 'r'))
vb.parse_vb_bin(open(vb_path, 'rb'))

ib = IndexBuffer(open(fmt_path, 'r'))
ib.parse_ib_bin(open(ib_path, 'rb'))

# Attach the vertex buffer layout to the object for later exporting. Can't
# seem to retrieve this if attached to the mesh - to_mesh() doesn't copy it:
obj['3DMigoto:VBLayout'] = vb.layout.serialise()
Expand All @@ -270,6 +275,7 @@ def import_3dmigoto_raw_buffers(operator, context, fmt_path:str, vb_path:str, ib
obj['3DMigoto:IBFormat'] = ib.format
obj['3DMigoto:FirstIndex'] = ib.first

# post process for import data.
import_faces_from_ib(mesh, ib)

(blend_indices, blend_weights, texcoords, vertex_layers, use_normals) = import_vertices(mesh, vb)
Expand Down Expand Up @@ -297,7 +303,6 @@ def import_3dmigoto_raw_buffers(operator, context, fmt_path:str, vb_path:str, ib
obj['3DMigoto:OriginalVertexNumber'] = len(mesh.vertices)
obj['3DMigoto:OriginalIndicesNumber'] = len(mesh.loops)


# Set auto_smooth 89° for unity game's perfect shadow.
obj.data.use_auto_smooth = True
# TODO Blender 4.1 remove auto_smooth_angle function.
Expand All @@ -311,6 +316,12 @@ def import_3dmigoto_raw_buffers(operator, context, fmt_path:str, vb_path:str, ib
obj.rotation_euler[1] = 0.0 # Y轴
obj.rotation_euler[2] = 0.0 # Z轴

# Flush every time export
bpy.context.view_layer.update()

# Force flush make good user experience.
bpy.ops.wm.redraw_timer(type='DRAW_WIN_SWAP', iterations=1)

return obj


Expand Down

0 comments on commit 9aa2156

Please sign in to comment.