io_export_ogre.py
Go to the documentation of this file.
1 #! /usr/bin/env python
2 
3 # Copyright (C) 2014 Aldebaran
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 #
17 # io_export_ogre.py
18 # Authors: Mikael Arguedas [mikael.arguedas@gmail.com]
19 
20 # This script import one by one each collada file in a folder,
21 # Merge them when necessary and export them as .mesh files (OGRE)
22 # This is an Aldebaran specific scripts which won't work on blender files of other companies
23 
24 from __future__ import print_function
25 import bpy
26 import os
27 import sys
28 
29 argv = sys.argv
30 argv = argv[argv.index("--") + 1:] # get all args after "--"
31 
32 mesh_dir = argv[0]
33 output_dir = argv[1]
34 print("Exporting ogre meshes to <%s>." % output_dir)
35 
36 scene = bpy.context.scene
37 
38 # Delete all existing objects in the blender file
39 for ob in scene.objects:
40  ob.select = True
41 bpy.ops.object.delete()
42 
43 # List the collada files present in the mesh_dir folder
44 file_list = sorted(os.listdir(mesh_dir))
45 for file in file_list:
46  if file.endswith('.dae') == True :
47  # Import the collada meshes one by one
48  bpy.ops.wm.collada_import(filepath= os.path.join(mesh_dir , file))
49  # Select all the objects and set the parent object as the active one
50  for ob in scene.objects:
51  if ob.type == 'MESH':
52  ob.select = True
53  if ob.name.find("_skip") ==-1:
54  bpy.context.scene.objects.active = ob
55  else:
56  ob.select = False
57  # Merge the selected meshes
58  bpy.ops.object.join()
59  for ob in scene.objects:
60  ob.name = file
61  # Export the mesh as a .mesh file (OGRE)
62  bpy.ops.ogre.export(filepath=os.path.join(output_dir, file) + ".scene",
63  EX_COPY_SHADER_PROGRAMS=False,
64  EX_MATERIALS = False,
65  EX_SWAP_AXIS='xyz',
66  EX_MESH=True,
67  EX_MESH_OVERWRITE=True,
68  EX_SCENE=False,
69  EX_EXPORT_HIDDEN=False,
70  EX_FORCE_CAMERA=False,
71  EX_FORCE_LAMPS=False,
72  EX_ARM_ANIM=False,
73  EX_SHAPE_ANIM=False,
74  EX_ARRAY=False,
75  EX_optimiseAnimations=False)
76  # Delete all the objects
77  bpy.ops.object.select_all(action="SELECT")
78  bpy.ops.object.delete()
79  print ("\n\n removed all objects")
80  for ob in scene.objects:
81  print(ob.name)
82  print ("\n\n")
83  # Remove all the materials
84  for material in bpy.data.materials:
85  bpy.data.materials[material.name].user_clear()
86  bpy.data.materials.remove(material)
87 
88 bpy.ops.wm.quit_blender()
89 
90 


naoqi_tools
Author(s): Mikael Arguedas
autogenerated on Thu Jul 16 2020 03:18:36