2.4版本號的Blender API和2.5以上版本號的API有非常大的不同,這里僅僅是提供了思路和2.4版本號的導出方案。
先提供一個腳本,這個是由Blender調用的。用於轉換Ogre的Mesh文件的腳本
import Blender import bpy import sys import os,glob sys.path.append(r"D:\Program Files\blender-2.49b-windows\.blender\scripts\torchlight"); sys.path.append(r"D:\Program Files\blender-2.49b-windows\.blender\scripts"); import importTL,export_fbx def ImportMesh(file): print file; scn = bpy.data.scenes.active #Scene.Unlink(scn); importTL.ImportOgre(file); output = file.replace(".mesh", ".fbx"); output = output.replace(".MESH", ".fbx"); export_fbx.fbx_default_setting(); export_fbx.fbx_write(output); return True; ImportMesh(sys.argv[5].replace("--", ""))
import glob,sys,os DUMMY_BLEND = r"E:\MyProj\unity3d\arpg36\ARPG\Tool\auto_convert_mesh\dummy.blend" CONVERT_SCRIPT = r"E:\MyProj\unity3d\arpg36\ARPG\Tool\auto_convert_mesh\convert_mesh.py" def convert_path(path): for root, dirs, files in os.walk(path): for dir in dirs: strDir = os.path.join(root, dir); #print(strDir); for file in files: file = file.lower(); strFile = os.path.join(root, file); #print(strFile); if strFile.find(".mesh") != -1: os.system("Blender -b {0} -P {1} --{2}".format(DUMMY_BLEND, CONVERT_SCRIPT, strFile)); for root, dirs, files in os.walk(path): for file in files: file = file.lower(); if file.find(".mesh") != -1 or file.find(".skeleton") != -1 or file.find(".xml") != -1 or file.find(".material") != -1 or file.find(".animation") != -1 or file.find(".adm") != -1: strFile = os.path.join(root, file); os.remove(strFile); convert_path(r"E:\MyProj\unity3d\arpg36\ARPG\Assets\Model\Media\Level");
此腳本遍歷目錄下的全部.mesh文件。然后進行轉換。
最核心的內容就一樣代碼 "Blender -b 項目文件 -P 腳本文件 --參數"