framework/cg/blender/export/dae.py

34 lines
1.8 KiB
Python

# -*- coding: utf-8 -*-
"""
DESCRIPTION.
Collada mesh exporter.
Exports all objects in scene.
You can set export path and subdir.
"""
__version__ = "0.1"
import logging
import sys
import bpy
import os
logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.INFO)
def export_dae(path, subdir="dae"):
""" Collada mesh exporter. Exports all objects in scene. """
for ob in bpy.context.scene.objects:
# deselect all but just one object and make it active
bpy.ops.object.select_all(action='DESELECT')
ob.select_set(state=True)
bpy.context.view_layer.objects.active = ob
filename = bpy.context.active_object.name
# export dae
dae_path = os.path.join(path, subdir).replace('\\', '/')
if not os.path.isdir(dae_path):
os.makedirs(dae_path)
outpath = os.path.join(dae_path, filename)
logger.debug('vizual:', outpath)
bpy.ops.wm.collada_export(filepath=outpath, check_existing=False, apply_modifiers=True, export_mesh_type=0, export_mesh_type_selection='view', export_global_forward_selection='Y', export_global_up_selection='Z', apply_global_orientation=False, selected=True, include_children=False, include_armatures=False, include_shapekeys=False, deform_bones_only=False, include_animations=False, include_all_actions=True, export_animation_type_selection='sample', sampling_rate=1, keep_smooth_curves=False, keep_keyframes=False, keep_flat_curves=False, active_uv_only=False, use_texture_copies=True, triangulate=True, use_object_instantiation=True, use_blender_profile=True, sort_by_name=False, export_object_transformation_type=0, export_object_transformation_type_selection='matrix', export_animation_transformation_type=0, export_animation_transformation_type_selection='matrix', open_sim=False, limit_precision=False, keep_bind_info=False)