io_export_visual.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_visual.py
18 # Authors: Mikael Arguedas [mikael.arguedas@gmail.com]
19 #
20 # This script parses a blender file from Aldebaran robotics, export all the materials of the scene,
21 # It also export all the meshes to COLLADA files (.dae)
22 
23 from __future__ import print_function
24 import bpy
25 import os
26 import sys
27 
28 argv = sys.argv
29 argv = argv[argv.index("--") + 1:] # get all args after "--"
30 
31 # Initialize the blacklist:
32 # If you don't want to export some meshes, either add their name to this list
33 # of suffix them with a keyword and add the keyword to this list
34 blacklist = ["skip"]
35 
36 # Get the folder where the meshes will be saved
37 mesh_dir = argv[0]
38 name = argv[1]
39 
40 # Keep a copy of user selection
41 bpy.ops.object.select_by_type(type="MESH")
42 sel_obs = bpy.context.selected_objects[:]
43 
44 # Export all the materials from the scene
45 bpy.ops.ogre.export(filepath=os.path.join(mesh_dir, name + '.scene'),
46 EX_COPY_SHADER_PROGRAMS=False,
47 EX_MATERIALS = True,
48 EX_SEP_MATS=False,
49 EX_SWAP_AXIS='xyz',
50 EX_MESH_OVERWRITE=False,
51 EX_MESH=False,
52 EX_SELONLY=False,
53 EX_SCENE=False,
54 EX_EXPORT_HIDDEN=False,
55 EX_FORCE_CAMERA=False,
56 EX_FORCE_LAMPS=False,
57 EX_ARM_ANIM=False,
58 EX_SHAPE_ANIM=False,
59 EX_ARRAY=False,
60 EX_optimiseAnimations=False)
61 
62 # Browse the object list and export all the meshes as COLLADA files(.dae)
63 for ob in bpy.data.objects:
64 
65  skip_mesh = False
66  for keyword in blacklist:
67  if ob.name.find(keyword) != -1:
68  skip_mesh = True
69  # Skip non-mesh objects or all children meshes we don't want to export
70  if ob.type != 'MESH' or skip_mesh == True:
71  continue
72 
73  # Clear selection
74  bpy.ops.object.select_all(action="DESELECT")
75 
76  # Select single object
77  ob.hide = False
78  ob.select = True
79 
80 
81  # Export single object to COLLADA file (.dae)
82  bpy.context.scene.collada_export(filepath=os.path.join(mesh_dir, ob.name + ".dae"), selected = True, include_uv_textures=True, include_children=True)
83 
84 
85 # Restore user selection
86 bpy.ops.object.select_all(action="DESELECT")
87 for ob in sel_obs:
88  ob.select = True
89 bpy.context.scene.objects.active = ob
90 
91 print("%s meshes exported." % len(sel_obs))
92 
93 bpy.ops.wm.quit_blender()


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