Batch export/Conversion Models Using Blender

Source: Internet
Author: User

The blender API of version 2.4 is very different from the API of Version 2.5 or later. Here we only provide ideas and the export solution of version 2.4.

First, provide a script called by blender to convert the mesh file of ogre.

import Blenderimport bpyimport sysimport os,globsys.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_fbxdef 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("--", ""))


The second script is called in the Windows command line. It is used to start the blender for conversion.

import glob,sys,osDUMMY_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");

This script traverses all. Mesh files in the folder and then converts them.

The core content is the same as the code "blender-B project file-P script file-Parameters"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.