Sujoy
Sujoy

Reputation: 69

How to batch export Unity3d prefab files to FBX format?

I have Unity3d project where in the assests folder I have 1000 prefab files. I want to convert them to fbix format or meshobj format. Is there any program that can bulk convert prefab to fbix?

Upvotes: 1

Views: 9225

Answers (1)

Sujoy
Sujoy

Reputation: 69

The solution that I found is a bit lengthy. I needed to convert prefab files to fbx format and then used blender to convert fbx files into wavefrontObj. To convert prefab files to fbx file format I used a Unity Package called FBX Exporter. The installation guide that I followed is from here.

After converting the files into fbx format I used blender to convert the files into obj format. I only needed the mesh files, so I excluded materials.To batch convert fbx files to wavefrontObj files I wrote the following script.

import bpy
import glob

fbx_file_folder = "input_folder/*.fbx"

mylist = [f for f in glob.glob(fbx_file_folder)]

for input_file in mylist:
    output_file = input_file.split(".")[0]
    output_file  = output_file + ".obj"
    print(output_file)
    bpy.ops.wm.read_factory_settings(use_empty=True)
    bpy.ops.import_scene.fbx(filepath=input_file)
    bpy.ops.export_scene.obj(filepath=output_file,use_materials=False,check_existing=True)

To run the script, save the files as convertFBXtoOBJ.py and in terminal run the following command once blender is installed.

blender --python convertFBXtoOBJ.py

To get information about the API that I have used for the script, Blender PyDocs will be a great help.

Upvotes: 1

Related Questions