io_export_ogre.py
Go to the documentation of this file.
00001 #! /usr/bin/env python
00002 
00003 # Copyright (C) 2014 Aldebaran
00004 #
00005 # Licensed under the Apache License, Version 2.0 (the "License");
00006 # you may not use this file except in compliance with the License.
00007 # You may obtain a copy of the License at
00008 #
00009 # http://www.apache.org/licenses/LICENSE-2.0
00010 #
00011 # Unless required by applicable law or agreed to in writing, software
00012 # distributed under the License is distributed on an "AS IS" BASIS,
00013 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014 # See the License for the specific language governing permissions and
00015 # limitations under the License.
00016 #
00017 # io_export_ogre.py
00018 # Authors: Mikael Arguedas [mikael.arguedas@gmail.com]
00019 
00020 # This script import one by one each collada file in a folder,
00021 # Merge them when necessary and export them as .mesh files (OGRE)
00022 # This is an Aldebaran specific scripts which won't work on blender files of other companies
00023 
00024 from __future__ import print_function
00025 import bpy
00026 import os
00027 import sys
00028 
00029 argv = sys.argv
00030 argv = argv[argv.index("--") + 1:]  # get all args after "--"
00031 
00032 mesh_dir = argv[0]
00033 output_dir = argv[1]
00034 print("Exporting ogre meshes to <%s>." % output_dir)
00035 
00036 scene = bpy.context.scene
00037 
00038 # Delete all existing objects in the blender file
00039 for ob in scene.objects:
00040      ob.select = True
00041 bpy.ops.object.delete()
00042 
00043 # List the collada files present in the mesh_dir folder
00044 file_list = sorted(os.listdir(mesh_dir))
00045 for file in file_list:
00046     if file.endswith('.dae') == True :
00047         # Import the collada meshes one by one
00048         bpy.ops.wm.collada_import(filepath= os.path.join(mesh_dir , file))
00049         # Select all the objects and set the parent object as the active one
00050         for ob in scene.objects:
00051             if ob.type == 'MESH':
00052                 ob.select = True
00053                 if ob.name.find("_skip") ==-1:
00054                     bpy.context.scene.objects.active = ob
00055             else:
00056                 ob.select = False
00057         # Merge the selected meshes
00058         bpy.ops.object.join()
00059         for ob in scene.objects:
00060             ob.name = file
00061         # Export the mesh as a .mesh file (OGRE)
00062         bpy.ops.ogre.export(filepath=os.path.join(output_dir, file) + ".scene",
00063         EX_COPY_SHADER_PROGRAMS=False,
00064         EX_MATERIALS = False,
00065         EX_SWAP_AXIS='xyz',
00066         EX_MESH=True,
00067         EX_MESH_OVERWRITE=True,
00068         EX_SCENE=False,
00069         EX_EXPORT_HIDDEN=False,
00070         EX_FORCE_CAMERA=False,
00071         EX_FORCE_LAMPS=False,
00072         EX_ARM_ANIM=False,
00073         EX_SHAPE_ANIM=False,
00074         EX_ARRAY=False,
00075         EX_optimiseAnimations=False)
00076         # Delete all the objects
00077         bpy.ops.object.select_all(action="SELECT")
00078         bpy.ops.object.delete()
00079         print ("\n\n removed all objects")
00080         for ob in scene.objects:
00081             print(ob.name)
00082         print ("\n\n")
00083         # Remove all the materials
00084         for material in bpy.data.materials:
00085             bpy.data.materials[material.name].user_clear()
00086             bpy.data.materials.remove(material)
00087 
00088 bpy.ops.wm.quit_blender()
00089 
00090 


naoqi_tools
Author(s): Mikael Arguedas
autogenerated on Sat Jun 8 2019 20:30:21