io_export_visual.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_visual.py
00018 # Authors: Mikael Arguedas [mikael.arguedas@gmail.com]
00019 #
00020 # This script parses a blender file from Aldebaran robotics, export all the materials of the scene,
00021 # It also export all the meshes to COLLADA files (.dae)
00022 
00023 from __future__ import print_function
00024 import bpy
00025 import os
00026 import sys
00027 
00028 argv = sys.argv
00029 argv = argv[argv.index("--") + 1:]  # get all args after "--"
00030 
00031 # Initialize the blacklist:
00032 # If you don't want to export some meshes, either add their name to this list
00033 # of suffix them with a keyword and add the keyword to this list
00034 blacklist = ["skip"]
00035 
00036 # Get the folder where the meshes will be saved
00037 mesh_dir = argv[0]
00038 name = argv[1]
00039 
00040 # Keep a copy of user selection
00041 bpy.ops.object.select_by_type(type="MESH")
00042 sel_obs = bpy.context.selected_objects[:]
00043 
00044 # Export all the materials from the scene
00045 bpy.ops.ogre.export(filepath=os.path.join(mesh_dir, name + '.scene'),
00046 EX_COPY_SHADER_PROGRAMS=False,
00047 EX_MATERIALS = True,
00048 EX_SEP_MATS=False,
00049 EX_SWAP_AXIS='xyz',
00050 EX_MESH_OVERWRITE=False,
00051 EX_MESH=False,
00052 EX_SELONLY=False,
00053 EX_SCENE=False,
00054 EX_EXPORT_HIDDEN=False,
00055 EX_FORCE_CAMERA=False,
00056 EX_FORCE_LAMPS=False,
00057 EX_ARM_ANIM=False,
00058 EX_SHAPE_ANIM=False,
00059 EX_ARRAY=False,
00060 EX_optimiseAnimations=False)
00061 
00062 # Browse the object list and export all the meshes as COLLADA files(.dae)
00063 for ob in bpy.data.objects:
00064 
00065     skip_mesh = False
00066     for keyword in blacklist:
00067         if ob.name.find(keyword) != -1:
00068             skip_mesh = True
00069     # Skip non-mesh objects or all children meshes we don't want to export
00070     if ob.type != 'MESH' or skip_mesh == True:
00071         continue
00072 
00073     # Clear selection
00074     bpy.ops.object.select_all(action="DESELECT")
00075 
00076     # Select single object
00077     ob.hide = False
00078     ob.select = True
00079 
00080 
00081     # Export single object to COLLADA file (.dae)
00082     bpy.context.scene.collada_export(filepath=os.path.join(mesh_dir, ob.name + ".dae"), selected = True, include_uv_textures=True, include_children=True)
00083 
00084 
00085 # Restore user selection
00086 bpy.ops.object.select_all(action="DESELECT")
00087 for ob in sel_obs:
00088     ob.select = True
00089 bpy.context.scene.objects.active = ob
00090 
00091 print("%s meshes exported." % len(sel_obs))
00092 
00093 bpy.ops.wm.quit_blender()


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