Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
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:]
00030
00031 mesh_dir = argv[0]
00032
00033 RATIO = float(argv[1])
00034
00035 THRESHOLD = int(argv[2])
00036
00037 output_dir = argv[3]
00038 print("Exporting collision meshes to <%s>." % mesh_dir)
00039
00040 scene = bpy.context.scene
00041
00042 for ob in scene.objects:
00043 ob.select = True
00044
00045 bpy.ops.object.delete()
00046
00047 file_list = sorted(os.listdir(mesh_dir))
00048 for file in file_list:
00049
00050 if file.endswith('.dae') == True:
00051 print(str(mesh_dir + '/' + file))
00052 bpy.ops.wm.collada_import(filepath= os.path.join(mesh_dir , file))
00053
00054 if(len(bpy.context.scene.objects[0].data.vertices) > THRESHOLD):
00055 bpy.ops.object.modifier_add(type='DECIMATE')
00056 mod = bpy.context.scene.objects.active.modifiers[0]
00057 mod.ratio = RATIO
00058
00059
00060 bpy.ops.object.modifier_apply(apply_as='DATA')
00061 else:
00062 print (" does not have enough vertices for DECIMATION")
00063
00064 bpy.ops.export_mesh.stl(filepath=os.path.join(output_dir,
00065 file[0:file.find('.dae')]
00066 + "_" + "{:.2f}".format(RATIO)+ ".stl"))
00067
00068 bpy.ops.object.delete()
00069
00070 bpy.ops.wm.quit_blender()