43 lines
1.3 KiB
Python
43 lines
1.3 KiB
Python
import bpy
|
||
import os
|
||
import bmesh
|
||
import mathutils
|
||
|
||
# ==== 参数 ====
|
||
input_glb = r"C:/Users/lry/Desktop/digital-embryo/embryo-backend/Data/CS19.glb"
|
||
output_glb = r"C:/Users/lry/Desktop/digital-embryo/embryo-backend/Data/CS19_fixed.glb"
|
||
|
||
# ==== 清空场景 ====
|
||
bpy.ops.object.select_all(action='SELECT')
|
||
bpy.ops.object.delete(use_global=False)
|
||
|
||
# ==== 导入 GLB ====
|
||
print(f"📥 载入 {input_glb}")
|
||
bpy.ops.import_scene.gltf(filepath=input_glb)
|
||
|
||
# ==== 强制应用 matrix_world 到每个顶点 ====
|
||
for obj in [o for o in bpy.context.scene.objects if o.type == 'MESH']:
|
||
bpy.context.view_layer.objects.active = obj
|
||
obj.select_set(True)
|
||
|
||
# 进入编辑模式
|
||
bpy.ops.object.mode_set(mode='EDIT')
|
||
bm = bmesh.from_edit_mesh(obj.data)
|
||
|
||
# 将所有顶点转换到世界坐标
|
||
for v in bm.verts:
|
||
v.co = obj.matrix_world @ v.co
|
||
|
||
bmesh.update_edit_mesh(obj.data)
|
||
bpy.ops.object.mode_set(mode='OBJECT')
|
||
|
||
# 重置 transform(避免重复应用)
|
||
obj.matrix_world = mathutils.Matrix.Identity(4)
|
||
obj.select_set(False)
|
||
|
||
# ==== 导出修复版 GLB ====
|
||
print(f"💾 导出修复版 → {output_glb}")
|
||
bpy.ops.export_scene.gltf(filepath=output_glb, export_format='GLB', export_apply=True)
|
||
|
||
print("✅ 修复完成!")
|