Tool for convert FreeCAD sub-assemblies to URDF-world according to config

This commit is contained in:
brothermechanic 2023-10-10 16:32:29 +00:00 committed by Igor Brylyov
parent 03bc34539c
commit 184ac7df88
12 changed files with 327 additions and 119 deletions

View file

@ -1,34 +1,64 @@
# -*- coding: utf-8 -*-
"""
# Copyright (C) 2023 Ilia Kurochkin <brothermechanic@gmail.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
'''
DESCRIPTION.
Collada mesh exporter.
Exports all objects in scene.
You can set export path and subdir.
"""
__version__ = "0.1"
'''
__version__ = "0.2"
import logging
import sys
import bpy
import os
logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.INFO)
from blender.export import export_decorator
def export_dae(path, subdir=""):
""" 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)
@export_decorator
def export_dae(**kwargs):
outpath = ('{}.dae'.format(kwargs['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)
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)
return outpath