2012-06-17 23:13:39 +00:00
/*
* * * * * * BEGIN GPL LICENSE BLOCK * * * * *
*
* 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 2
* 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 .
*
* You should have received a copy of the GNU General Public License
* along with this program ; if not , write to the Free Software Foundation ,
* Inc . , 51 Franklin Street , Fifth Floor , Boston , MA 02110 - 1301 , USA .
*
* The Original Code is Copyright ( C ) 2008 Blender Foundation .
* All rights reserved .
*
*
* Contributor ( s ) : Blender Foundation
*
* * * * * * END GPL LICENSE BLOCK * * * * *
*/
2012-06-27 18:29:47 +00:00
/** \file blender/editors/io/io_collada.c
2012-06-17 23:13:39 +00:00
* \ ingroup collada
*/
2012-06-18 00:27:30 +00:00
# ifdef WITH_COLLADA
2012-06-17 23:13:39 +00:00
# include "DNA_scene_types.h"
2015-08-16 17:32:01 +10:00
# include "BLT_translation.h"
2012-06-17 23:13:39 +00:00
# include "BLI_blenlib.h"
# include "BLI_utildefines.h"
# include "BKE_context.h"
2018-02-26 16:49:06 +01:00
# include "BKE_depsgraph.h"
2012-06-17 23:13:39 +00:00
# include "BKE_global.h"
# include "BKE_main.h"
# include "BKE_report.h"
2018-02-28 15:59:49 +01:00
# include "BKE_object.h"
2012-06-17 23:13:39 +00:00
# include "ED_screen.h"
# include "ED_object.h"
# include "RNA_access.h"
# include "RNA_define.h"
# include "UI_interface.h"
# include "UI_resources.h"
# include "WM_api.h"
# include "WM_types.h"
# include "../../collada/collada.h"
2012-09-18 07:03:23 +00:00
# include "io_collada.h"
2013-03-13 09:03:46 +00:00
static int wm_collada_export_invoke ( bContext * C , wmOperator * op , const wmEvent * UNUSED ( event ) )
2012-06-17 23:13:39 +00:00
{
if ( ! RNA_struct_property_is_set ( op - > ptr , " filepath " ) ) {
char filepath [ FILE_MAX ] ;
if ( G . main - > name [ 0 ] = = 0 )
BLI_strncpy ( filepath , " untitled " , sizeof ( filepath ) ) ;
else
BLI_strncpy ( filepath , G . main - > name , sizeof ( filepath ) ) ;
BLI_replace_extension ( filepath , sizeof ( filepath ) , " .dae " ) ;
RNA_string_set ( op - > ptr , " filepath " , filepath ) ;
}
WM_event_add_fileselect ( C , op ) ;
return OPERATOR_RUNNING_MODAL ;
}
/* function used for WM_OT_save_mainfile too */
static int wm_collada_export_exec ( bContext * C , wmOperator * op )
{
char filepath [ FILE_MAX ] ;
int apply_modifiers ;
int export_mesh_type ;
int selected ;
int include_children ;
int include_armatures ;
2013-01-21 13:45:49 +00:00
int include_shapekeys ;
2012-06-17 23:13:39 +00:00
int deform_bones_only ;
2018-02-26 16:34:45 +01:00
int include_animations ;
int sample_animations ;
2018-02-24 13:11:30 +01:00
int sampling_rate ;
2012-06-22 16:16:58 +00:00
2017-06-24 22:09:08 +02:00
int export_texture_type ;
2012-06-22 16:16:58 +00:00
int use_texture_copies ;
int active_uv_only ;
2013-03-02 15:58:13 +00:00
int triangulate ;
2012-06-17 23:13:39 +00:00
int use_object_instantiation ;
2016-05-26 17:40:56 +02:00
int use_blender_profile ;
2012-06-17 23:13:39 +00:00
int sort_by_name ;
2013-03-06 23:21:52 +00:00
int export_transformation_type ;
2017-03-23 00:07:05 +01:00
2014-09-30 14:22:20 +02:00
int open_sim ;
2017-04-03 10:48:00 +02:00
int limit_precision ;
2017-03-23 00:07:05 +01:00
int keep_bind_info ;
2014-09-30 14:22:20 +02:00
int export_count ;
2012-06-17 23:13:39 +00:00
if ( ! RNA_struct_property_is_set ( op - > ptr , " filepath " ) ) {
BKE_report ( op - > reports , RPT_ERROR , " No filename given " ) ;
return OPERATOR_CANCELLED ;
}
RNA_string_get ( op - > ptr , " filepath " , filepath ) ;
BLI_ensure_extension ( filepath , sizeof ( filepath ) , " .dae " ) ;
2013-08-24 09:51:05 +00:00
/* Avoid File write exceptions in Collada */
if ( ! BLI_exists ( filepath ) ) {
BLI_make_existing_file ( filepath ) ;
if ( ! BLI_file_touch ( filepath ) ) {
BKE_report ( op - > reports , RPT_ERROR , " Can't create export file " ) ;
fprintf ( stdout , " Collada export: Can not create: %s \n " , filepath ) ;
return OPERATOR_CANCELLED ;
}
}
else if ( ! BLI_file_is_writable ( filepath ) ) {
BKE_report ( op - > reports , RPT_ERROR , " Can't overwrite export file " ) ;
fprintf ( stdout , " Collada export: Can not modify: %s \n " , filepath ) ;
return OPERATOR_CANCELLED ;
}
/* Now the exporter can create and write the export file */
2012-06-17 23:13:39 +00:00
/* Options panel */
apply_modifiers = RNA_boolean_get ( op - > ptr , " apply_modifiers " ) ;
2012-06-22 16:16:58 +00:00
export_mesh_type = RNA_enum_get ( op - > ptr , " export_mesh_type_selection " ) ;
2012-06-17 23:13:39 +00:00
selected = RNA_boolean_get ( op - > ptr , " selected " ) ;
include_children = RNA_boolean_get ( op - > ptr , " include_children " ) ;
include_armatures = RNA_boolean_get ( op - > ptr , " include_armatures " ) ;
2013-01-21 13:45:49 +00:00
include_shapekeys = RNA_boolean_get ( op - > ptr , " include_shapekeys " ) ;
2018-02-26 16:34:45 +01:00
include_animations = RNA_boolean_get ( op - > ptr , " include_animations " ) ;
sample_animations = RNA_boolean_get ( op - > ptr , " sample_animations " ) ;
2018-04-06 10:47:39 +02:00
sampling_rate = ( sample_animations ) ? RNA_int_get ( op - > ptr , " sampling_rate " ) : 0 ;
2018-02-26 16:34:45 +01:00
2012-06-17 23:13:39 +00:00
deform_bones_only = RNA_boolean_get ( op - > ptr , " deform_bones_only " ) ;
2012-06-22 16:16:58 +00:00
2017-06-24 22:09:08 +02:00
export_texture_type = RNA_enum_get ( op - > ptr , " export_texture_type_selection " ) ;
2012-06-22 16:16:58 +00:00
use_texture_copies = RNA_boolean_get ( op - > ptr , " use_texture_copies " ) ;
active_uv_only = RNA_boolean_get ( op - > ptr , " active_uv_only " ) ;
2013-03-06 23:21:52 +00:00
triangulate = RNA_boolean_get ( op - > ptr , " triangulate " ) ;
use_object_instantiation = RNA_boolean_get ( op - > ptr , " use_object_instantiation " ) ;
2016-05-26 17:40:56 +02:00
use_blender_profile = RNA_boolean_get ( op - > ptr , " use_blender_profile " ) ;
2013-03-06 23:21:52 +00:00
sort_by_name = RNA_boolean_get ( op - > ptr , " sort_by_name " ) ;
export_transformation_type = RNA_enum_get ( op - > ptr , " export_transformation_type_selection " ) ;
2013-10-03 14:24:54 +00:00
open_sim = RNA_boolean_get ( op - > ptr , " open_sim " ) ;
2012-06-17 23:13:39 +00:00
2017-04-03 10:48:00 +02:00
limit_precision = RNA_boolean_get ( op - > ptr , " limit_precision " ) ;
2017-03-23 00:07:05 +01:00
keep_bind_info = RNA_boolean_get ( op - > ptr , " keep_bind_info " ) ;
2018-06-01 17:08:38 +02:00
Main * bmain = CTX_data_main ( C ) ;
2012-06-17 23:13:39 +00:00
/* get editmode results */
2018-06-01 17:08:38 +02:00
ED_object_editmode_load ( bmain , CTX_data_edit_object ( C ) ) ;
2012-06-17 23:13:39 +00:00
2018-06-01 17:08:38 +02:00
EvaluationContext * eval_ctx = bmain - > eval_ctx ;
2018-02-26 16:49:06 +01:00
Scene * scene = CTX_data_scene ( C ) ;
2018-02-28 15:59:49 +01:00
ExportSettings export_settings ;
export_settings . filepath = filepath ;
export_settings . apply_modifiers = apply_modifiers ! = 0 ;
export_settings . export_mesh_type = export_mesh_type ;
export_settings . selected = selected ! = 0 ;
export_settings . include_children = include_children ! = 0 ;
export_settings . include_armatures = include_armatures ! = 0 ;
export_settings . include_shapekeys = include_shapekeys ! = 0 ;
export_settings . deform_bones_only = deform_bones_only ! = 0 ;
export_settings . include_animations = include_animations ;
export_settings . sampling_rate = sampling_rate ;
export_settings . active_uv_only = active_uv_only ! = 0 ;
export_settings . export_texture_type = export_texture_type ;
export_settings . use_texture_copies = use_texture_copies ! = 0 ;
export_settings . triangulate = triangulate ! = 0 ;
export_settings . use_object_instantiation = use_object_instantiation ! = 0 ;
export_settings . use_blender_profile = use_blender_profile ! = 0 ;
export_settings . sort_by_name = sort_by_name ! = 0 ;
export_settings . export_transformation_type = export_transformation_type ;
export_settings . open_sim = open_sim ! = 0 ;
export_settings . limit_precision = limit_precision ! = 0 ;
export_settings . keep_bind_info = keep_bind_info ! = 0 ;
int includeFilter = OB_REL_NONE ;
if ( export_settings . include_armatures ) includeFilter | = OB_REL_MOD_ARMATURE ;
if ( export_settings . include_children ) includeFilter | = OB_REL_CHILDREN_RECURSIVE ;
2013-08-24 09:51:05 +00:00
2018-02-26 16:49:06 +01:00
export_count = collada_export ( eval_ctx ,
scene ,
2018-02-28 15:59:49 +01:00
& export_settings
2017-03-23 00:07:05 +01:00
) ;
2014-09-30 12:21:53 +01:00
2014-10-03 08:09:00 +02:00
if ( export_count = = 0 ) {
2016-07-19 16:33:57 +02:00
BKE_report ( op - > reports , RPT_WARNING , " No objects selected -- Created empty export file " ) ;
2012-06-17 23:13:39 +00:00
return OPERATOR_CANCELLED ;
2014-10-03 08:09:00 +02:00
}
2016-02-20 21:42:12 +01:00
else if ( export_count < 0 ) {
BKE_report ( op - > reports , RPT_WARNING , " Error during export (see Console) " ) ;
return OPERATOR_CANCELLED ;
}
2014-09-30 12:21:53 +01:00
else {
char buff [ 100 ] ;
sprintf ( buff , " Exported %d Objects " , export_count ) ;
BKE_report ( op - > reports , RPT_INFO , buff ) ;
return OPERATOR_FINISHED ;
2012-06-17 23:13:39 +00:00
}
}
2012-09-18 15:13:45 +00:00
static void uiCollada_exportSettings ( uiLayout * layout , PointerRNA * imfptr )
2012-06-17 23:13:39 +00:00
{
2012-06-22 16:16:58 +00:00
uiLayout * box , * row , * col , * split ;
2018-02-26 16:34:45 +01:00
bool include_animations = RNA_boolean_get ( imfptr , " include_animations " ) ;
2012-06-17 23:13:39 +00:00
/* Export Options: */
box = uiLayoutBox ( layout ) ;
2014-04-01 11:34:00 +11:00
row = uiLayoutRow ( box , false ) ;
2012-06-17 23:13:39 +00:00
uiItemL ( row , IFACE_ ( " Export Data Options: " ) , ICON_MESH_DATA ) ;
2014-04-01 11:34:00 +11:00
row = uiLayoutRow ( box , false ) ;
2012-06-22 16:16:58 +00:00
split = uiLayoutSplit ( row , 0.6f , UI_LAYOUT_ALIGN_RIGHT ) ;
2014-04-01 11:34:00 +11:00
col = uiLayoutColumn ( split , false ) ;
2012-06-22 16:16:58 +00:00
uiItemR ( col , imfptr , " apply_modifiers " , 0 , NULL , ICON_NONE ) ;
2014-04-01 11:34:00 +11:00
col = uiLayoutColumn ( split , false ) ;
2012-06-22 16:16:58 +00:00
uiItemR ( col , imfptr , " export_mesh_type_selection " , 0 , " " , ICON_NONE ) ;
uiLayoutSetEnabled ( col , RNA_boolean_get ( imfptr , " apply_modifiers " ) ) ;
2012-06-17 23:13:39 +00:00
2014-04-01 11:34:00 +11:00
row = uiLayoutRow ( box , false ) ;
2012-06-17 23:13:39 +00:00
uiItemR ( row , imfptr , " selected " , 0 , NULL , ICON_NONE ) ;
2014-04-01 11:34:00 +11:00
row = uiLayoutRow ( box , false ) ;
2012-06-22 16:16:58 +00:00
uiItemR ( row , imfptr , " include_children " , 0 , NULL , ICON_NONE ) ;
2012-06-17 23:13:39 +00:00
uiLayoutSetEnabled ( row , RNA_boolean_get ( imfptr , " selected " ) ) ;
2014-04-01 11:34:00 +11:00
row = uiLayoutRow ( box , false ) ;
2012-06-22 16:16:58 +00:00
uiItemR ( row , imfptr , " include_armatures " , 0 , NULL , ICON_NONE ) ;
2012-06-17 23:13:39 +00:00
uiLayoutSetEnabled ( row , RNA_boolean_get ( imfptr , " selected " ) ) ;
2014-04-01 11:34:00 +11:00
row = uiLayoutRow ( box , false ) ;
2013-01-21 13:45:49 +00:00
uiItemR ( row , imfptr , " include_shapekeys " , 0 , NULL , ICON_NONE ) ;
uiLayoutSetEnabled ( row , RNA_boolean_get ( imfptr , " selected " ) ) ;
2018-02-24 13:11:30 +01:00
row = uiLayoutRow ( box , false ) ;
2018-02-26 16:34:45 +01:00
uiItemR ( row , imfptr , " include_animations " , 0 , NULL , ICON_NONE ) ;
row = uiLayoutRow ( box , false ) ;
if ( include_animations ) {
uiItemR ( row , imfptr , " sample_animations " , 0 , NULL , ICON_NONE ) ;
row = uiLayoutColumn ( box , false ) ;
uiItemR ( row , imfptr , " sampling_rate " , 0 , NULL , ICON_NONE ) ;
uiLayoutSetEnabled ( row , RNA_boolean_get ( imfptr , " sample_animations " ) ) ;
}
2018-02-24 13:11:30 +01:00
2012-07-07 22:51:57 +00:00
/* Texture options */
2012-06-22 16:16:58 +00:00
box = uiLayoutBox ( layout ) ;
2014-04-01 11:34:00 +11:00
row = uiLayoutRow ( box , false ) ;
2012-06-22 16:16:58 +00:00
uiItemL ( row , IFACE_ ( " Texture Options: " ) , ICON_TEXTURE_DATA ) ;
2014-04-01 11:34:00 +11:00
row = uiLayoutRow ( box , false ) ;
2012-06-22 16:16:58 +00:00
uiItemR ( row , imfptr , " active_uv_only " , 0 , NULL , ICON_NONE ) ;
2014-04-01 11:34:00 +11:00
row = uiLayoutRow ( box , false ) ;
2017-06-24 22:09:08 +02:00
uiItemR ( row , imfptr , " export_texture_type_selection " , 0 , " " , ICON_NONE ) ;
2012-06-23 22:03:31 +00:00
2014-04-01 11:34:00 +11:00
row = uiLayoutRow ( box , false ) ;
2012-06-22 16:16:58 +00:00
uiItemR ( row , imfptr , " use_texture_copies " , 1 , NULL , ICON_NONE ) ;
2012-06-17 23:13:39 +00:00
2012-07-07 22:51:57 +00:00
/* Armature options */
2012-06-17 23:13:39 +00:00
box = uiLayoutBox ( layout ) ;
2014-04-01 11:34:00 +11:00
row = uiLayoutRow ( box , false ) ;
2012-06-17 23:13:39 +00:00
uiItemL ( row , IFACE_ ( " Armature Options: " ) , ICON_ARMATURE_DATA ) ;
2014-04-01 11:34:00 +11:00
row = uiLayoutRow ( box , false ) ;
2012-06-17 23:13:39 +00:00
uiItemR ( row , imfptr , " deform_bones_only " , 0 , NULL , ICON_NONE ) ;
2018-02-24 13:11:30 +01:00
2014-04-01 11:34:00 +11:00
row = uiLayoutRow ( box , false ) ;
2013-10-03 14:24:54 +00:00
uiItemR ( row , imfptr , " open_sim " , 0 , NULL , ICON_NONE ) ;
2012-06-17 23:13:39 +00:00
/* Collada options: */
box = uiLayoutBox ( layout ) ;
2014-04-01 11:34:00 +11:00
row = uiLayoutRow ( box , false ) ;
2012-06-17 23:13:39 +00:00
uiItemL ( row , IFACE_ ( " Collada Options: " ) , ICON_MODIFIER ) ;
2014-04-01 11:34:00 +11:00
row = uiLayoutRow ( box , false ) ;
2017-03-12 20:31:34 +01:00
uiItemR ( row , imfptr , " triangulate " , 1 , NULL , ICON_NONE ) ;
2014-04-01 11:34:00 +11:00
row = uiLayoutRow ( box , false ) ;
2017-03-12 20:31:34 +01:00
uiItemR ( row , imfptr , " use_object_instantiation " , 1 , NULL , ICON_NONE ) ;
2016-05-26 17:40:56 +02:00
row = uiLayoutRow ( box , false ) ;
2017-03-12 20:31:34 +01:00
uiItemR ( row , imfptr , " use_blender_profile " , 1 , NULL , ICON_NONE ) ;
2013-03-06 23:21:52 +00:00
2014-04-01 11:34:00 +11:00
row = uiLayoutRow ( box , false ) ;
2013-03-06 23:21:52 +00:00
split = uiLayoutSplit ( row , 0.6f , UI_LAYOUT_ALIGN_RIGHT ) ;
2014-08-05 13:36:35 +10:00
uiItemL ( split , IFACE_ ( " Transformation Type " ) , ICON_NONE ) ;
2013-03-06 23:21:52 +00:00
uiItemR ( split , imfptr , " export_transformation_type_selection " , 0 , " " , ICON_NONE ) ;
2014-04-01 11:34:00 +11:00
row = uiLayoutRow ( box , false ) ;
2012-06-17 23:13:39 +00:00
uiItemR ( row , imfptr , " sort_by_name " , 0 , NULL , ICON_NONE ) ;
2017-04-03 10:48:00 +02:00
2017-03-23 00:07:05 +01:00
row = uiLayoutRow ( box , false ) ;
uiItemR ( row , imfptr , " keep_bind_info " , 0 , NULL , ICON_NONE ) ;
2012-06-17 23:13:39 +00:00
2017-04-03 10:48:00 +02:00
row = uiLayoutRow ( box , false ) ;
uiItemR ( row , imfptr , " limit_precision " , 0 , NULL , ICON_NONE ) ;
2012-06-17 23:13:39 +00:00
}
static void wm_collada_export_draw ( bContext * UNUSED ( C ) , wmOperator * op )
{
PointerRNA ptr ;
RNA_pointer_create ( NULL , op - > type - > srna , op - > properties , & ptr ) ;
uiCollada_exportSettings ( op - > layout , & ptr ) ;
}
2016-08-19 04:42:12 +02:00
static bool wm_collada_export_check ( bContext * UNUSED ( C ) , wmOperator * op )
{
char filepath [ FILE_MAX ] ;
RNA_string_get ( op - > ptr , " filepath " , filepath ) ;
if ( ! BLI_testextensie ( filepath , " .dae " ) ) {
BLI_ensure_extension ( filepath , FILE_MAX , " .dae " ) ;
RNA_string_set ( op - > ptr , " filepath " , filepath ) ;
return true ;
}
return false ;
}
2012-06-17 23:13:39 +00:00
void WM_OT_collada_export ( wmOperatorType * ot )
{
2017-03-12 20:31:34 +01:00
struct StructRNA * func = ot - > srna ;
2017-10-18 15:07:26 +11:00
static const EnumPropertyItem prop_bc_export_mesh_type [ ] = {
2012-06-17 23:13:39 +00:00
{ BC_MESH_TYPE_VIEW , " view " , 0 , " View " , " Apply modifier's view settings " } ,
{ BC_MESH_TYPE_RENDER , " render " , 0 , " Render " , " Apply modifier's render settings " } ,
{ 0 , NULL , 0 , NULL , NULL }
} ;
2017-10-18 15:07:26 +11:00
static const EnumPropertyItem prop_bc_export_transformation_type [ ] = {
2017-06-24 22:09:08 +02:00
{ BC_TRANSFORMATION_TYPE_MATRIX , " matrix " , 0 , " Matrix " , " Use <matrix> to specify transformations " } ,
{ BC_TRANSFORMATION_TYPE_TRANSROTLOC , " transrotloc " , 0 , " TransRotLoc " , " Use <translate>, <rotate>, <scale> to specify transformations " } ,
{ 0 , NULL , 0 , NULL , NULL }
} ;
2017-10-18 15:07:26 +11:00
static const EnumPropertyItem prop_bc_export_texture_type [ ] = {
2017-06-25 22:06:04 +02:00
{ BC_TEXTURE_TYPE_MAT , " mat " , 0 , " Materials " , " Export Materials " } ,
{ BC_TEXTURE_TYPE_UV , " uv " , 0 , " UV Textures " , " Export UV Textures (Face textures) as materials " } ,
2017-06-24 22:09:08 +02:00
{ 0 , NULL , 0 , NULL , NULL }
2013-03-06 23:21:52 +00:00
} ;
2012-06-17 23:13:39 +00:00
ot - > name = " Export COLLADA " ;
ot - > description = " Save a Collada file " ;
ot - > idname = " WM_OT_collada_export " ;
2012-09-18 07:03:23 +00:00
2012-06-17 23:13:39 +00:00
ot - > invoke = wm_collada_export_invoke ;
ot - > exec = wm_collada_export_exec ;
ot - > poll = WM_operator_winactive ;
2016-08-19 04:42:12 +02:00
ot - > check = wm_collada_export_check ;
2012-06-17 23:13:39 +00:00
ot - > flag | = OPTYPE_PRESET ;
ot - > ui = wm_collada_export_draw ;
2012-09-18 07:03:23 +00:00
2016-02-07 22:56:20 +11:00
WM_operator_properties_filesel (
ot , FILE_TYPE_FOLDER | FILE_TYPE_COLLADA , FILE_BLENDER , FILE_SAVE ,
WM_FILESEL_FILEPATH , FILE_DEFAULTDISPLAY , FILE_SORT_ALPHA ) ;
2012-06-17 23:13:39 +00:00
2017-03-12 20:31:34 +01:00
RNA_def_boolean ( func ,
2012-06-22 16:16:58 +00:00
" apply_modifiers " , 0 , " Apply Modifiers " ,
" Apply modifiers to exported mesh (non destructive)) " ) ;
2012-06-17 23:13:39 +00:00
2017-03-12 20:31:34 +01:00
RNA_def_int ( func , " export_mesh_type " , 0 , INT_MIN , INT_MAX ,
2012-06-17 23:13:39 +00:00
" Resolution " , " Modifier resolution for export " , INT_MIN , INT_MAX ) ;
2017-03-12 20:31:34 +01:00
RNA_def_enum ( func , " export_mesh_type_selection " , prop_bc_export_mesh_type , 0 ,
2012-06-17 23:13:39 +00:00
" Resolution " , " Modifier resolution for export " ) ;
2018-02-27 16:52:51 +01:00
RNA_def_boolean ( func , " selected " , false , " Selection Only " ,
2012-06-17 23:13:39 +00:00
" Export only selected elements " ) ;
2018-02-27 16:52:51 +01:00
RNA_def_boolean ( func , " include_children " , false , " Include Children " ,
2012-06-17 23:13:39 +00:00
" Export all children of selected objects (even if not selected) " ) ;
2018-02-27 16:52:51 +01:00
RNA_def_boolean ( func , " include_armatures " , false , " Include Armatures " ,
2012-06-17 23:13:39 +00:00
" Export related armatures (even if not selected) " ) ;
2018-02-27 16:51:52 +01:00
RNA_def_boolean ( func , " include_shapekeys " , false , " Include Shape Keys " ,
2013-01-21 13:45:49 +00:00
" Export all Shape Keys from Mesh Objects " ) ;
2018-02-27 16:52:51 +01:00
RNA_def_boolean ( func , " deform_bones_only " , false , " Deform Bones only " ,
2018-02-24 13:11:30 +01:00
" Only export deforming bones with armatures " ) ;
2018-02-27 16:48:41 +01:00
RNA_def_boolean ( func , " include_animations " , true ,
2018-02-26 16:34:45 +01:00
" Include Animations " , " Export Animations if available. \n Exporting Animations will enforce the decomposition of node transforms \n into <translation> <rotation> and <scale> components " ) ;
RNA_def_boolean ( func , " sample_animations " , 0 ,
" Sample Animations " , " Auto-generate keyframes with a frame distance set by 'Sampling Rate'. \n When disabled, export only the keyframes defined in the animation f-curves (may be less accurate) " ) ;
RNA_def_int ( func , " sampling_rate " , 1 , 1 , INT_MAX ,
" Sampling Rate " , " The distance between 2 keyframes. 1 means: Every frame is keyed " , 1 , INT_MAX ) ;
2012-06-17 23:13:39 +00:00
2017-03-12 20:31:34 +01:00
RNA_def_boolean ( func , " active_uv_only " , 0 , " Only Selected UV Map " ,
2015-03-03 23:42:17 +01:00
" Export only the selected UV Map " ) ;
2012-06-22 16:16:58 +00:00
2017-03-12 20:31:34 +01:00
RNA_def_boolean ( func , " use_texture_copies " , 1 , " Copy " ,
2012-06-22 16:16:58 +00:00
" Copy textures to same folder where the .dae file is exported " ) ;
2017-03-12 20:31:34 +01:00
RNA_def_boolean ( func , " triangulate " , 1 , " Triangulate " ,
2013-03-02 15:58:13 +00:00
" Export Polygons (Quads & NGons) as Triangles " ) ;
2013-02-27 13:53:43 +00:00
2017-03-12 20:31:34 +01:00
RNA_def_boolean ( func , " use_object_instantiation " , 1 , " Use Object Instances " ,
2016-05-26 17:40:56 +02:00
" Instantiate multiple Objects from same Data " ) ;
2017-03-12 20:31:34 +01:00
RNA_def_boolean ( func , " use_blender_profile " , 1 , " Use Blender Profile " ,
2016-05-26 17:40:56 +02:00
" Export additional Blender specific information (for material, shaders, bones, etc.) " ) ;
2012-06-17 23:13:39 +00:00
2017-03-12 20:31:34 +01:00
RNA_def_boolean ( func , " sort_by_name " , 0 , " Sort by Object name " ,
2012-06-17 23:13:39 +00:00
" Sort exported data by Object name " ) ;
2017-06-24 22:09:08 +02:00
2017-03-12 20:31:34 +01:00
RNA_def_int ( func , " export_transformation_type " , 0 , INT_MIN , INT_MAX ,
2017-06-24 22:09:08 +02:00
" Transform " , " Transformation type for translation, scale and rotation " , INT_MIN , INT_MAX ) ;
2013-03-06 23:21:52 +00:00
2017-03-12 20:31:34 +01:00
RNA_def_enum ( func , " export_transformation_type_selection " , prop_bc_export_transformation_type , 0 ,
2017-06-24 22:09:08 +02:00
" Transform " , " Transformation type for translation, scale and rotation " ) ;
RNA_def_int ( func , " export_texture_type " , 0 , INT_MIN , INT_MAX ,
" Texture Type " , " Type for exported Textures (UV or MAT) " , INT_MIN , INT_MAX ) ;
RNA_def_enum ( func , " export_texture_type_selection " , prop_bc_export_texture_type , 0 ,
" Texture Type " , " Type for exported Textures (UV or MAT) " ) ;
2013-03-06 23:21:52 +00:00
2017-03-12 20:31:34 +01:00
RNA_def_boolean ( func , " open_sim " , 0 , " Export to SL/OpenSim " ,
2014-10-02 08:54:59 +02:00
" Compatibility mode for SL, OpenSim and other compatible online worlds " ) ;
2017-03-23 00:07:05 +01:00
2017-04-03 10:48:00 +02:00
RNA_def_boolean ( func , " limit_precision " , 0 ,
" Limit Precision " , " Reduce the precision of the exported data to 6 digits " ) ;
2017-03-23 00:07:05 +01:00
RNA_def_boolean ( func , " keep_bind_info " , 0 ,
" Keep Bind Info " , " Store Bindpose information in custom bone properties for later use during Collada export " ) ;
2012-06-17 23:13:39 +00:00
}
/* function used for WM_OT_save_mainfile too */
static int wm_collada_import_exec ( bContext * C , wmOperator * op )
{
char filename [ FILE_MAX ] ;
2013-02-09 16:19:30 +00:00
int import_units ;
2014-11-29 13:24:26 +01:00
int find_chains ;
2016-06-03 18:26:12 +02:00
int auto_connect ;
2014-12-01 20:31:42 +01:00
int fix_orientation ;
2017-03-23 00:07:05 +01:00
int min_chain_length ;
int keep_bind_info ;
2018-02-28 15:59:49 +01:00
ImportSettings import_settings ;
2012-09-18 07:03:23 +00:00
2012-06-17 23:13:39 +00:00
if ( ! RNA_struct_property_is_set ( op - > ptr , " filepath " ) ) {
BKE_report ( op - > reports , RPT_ERROR , " No filename given " ) ;
return OPERATOR_CANCELLED ;
}
2013-02-09 16:19:30 +00:00
/* Options panel */
2014-11-29 13:24:26 +01:00
import_units = RNA_boolean_get ( op - > ptr , " import_units " ) ;
find_chains = RNA_boolean_get ( op - > ptr , " find_chains " ) ;
2016-06-03 18:26:12 +02:00
auto_connect = RNA_boolean_get ( op - > ptr , " auto_connect " ) ;
2014-12-01 20:31:42 +01:00
fix_orientation = RNA_boolean_get ( op - > ptr , " fix_orientation " ) ;
2017-03-23 00:07:05 +01:00
keep_bind_info = RNA_boolean_get ( op - > ptr , " keep_bind_info " ) ;
2014-11-29 13:24:26 +01:00
min_chain_length = RNA_int_get ( op - > ptr , " min_chain_length " ) ;
2012-09-18 07:03:23 +00:00
2013-02-09 16:19:30 +00:00
RNA_string_get ( op - > ptr , " filepath " , filename ) ;
2018-02-28 15:59:49 +01:00
import_settings . filepath = filename ;
import_settings . import_units = import_units ! = 0 ;
import_settings . auto_connect = auto_connect ! = 0 ;
import_settings . find_chains = find_chains ! = 0 ;
import_settings . fix_orientation = fix_orientation ! = 0 ;
import_settings . min_chain_length = min_chain_length ;
import_settings . keep_bind_info = keep_bind_info ! = 0 ;
2018-04-06 10:47:39 +02:00
if ( collada_import ( C , & import_settings ) ) {
2013-02-10 17:06:05 +00:00
return OPERATOR_FINISHED ;
2013-02-09 16:19:30 +00:00
}
else {
2013-02-10 22:14:56 +00:00
BKE_report ( op - > reports , RPT_ERROR , " Errors found during parsing COLLADA document (see console for details) " ) ;
2013-02-10 17:06:05 +00:00
return OPERATOR_CANCELLED ;
2013-02-09 16:19:30 +00:00
}
}
static void uiCollada_importSettings ( uiLayout * layout , PointerRNA * imfptr )
{
uiLayout * box , * row ;
/* Import Options: */
box = uiLayoutBox ( layout ) ;
2014-04-01 11:34:00 +11:00
row = uiLayoutRow ( box , false ) ;
2013-02-09 16:19:30 +00:00
uiItemL ( row , IFACE_ ( " Import Data Options: " ) , ICON_MESH_DATA ) ;
2012-09-18 07:03:23 +00:00
2014-04-01 11:34:00 +11:00
row = uiLayoutRow ( box , false ) ;
2013-02-09 16:19:30 +00:00
uiItemR ( row , imfptr , " import_units " , 0 , NULL , ICON_NONE ) ;
2014-11-29 13:24:26 +01:00
box = uiLayoutBox ( layout ) ;
row = uiLayoutRow ( box , false ) ;
uiItemL ( row , IFACE_ ( " Armature Options: " ) , ICON_MESH_DATA ) ;
2014-12-01 20:31:42 +01:00
row = uiLayoutRow ( box , false ) ;
uiItemR ( row , imfptr , " fix_orientation " , 0 , NULL , ICON_NONE ) ;
2014-11-29 13:24:26 +01:00
row = uiLayoutRow ( box , false ) ;
uiItemR ( row , imfptr , " find_chains " , 0 , NULL , ICON_NONE ) ;
2016-06-03 18:26:12 +02:00
row = uiLayoutRow ( box , false ) ;
uiItemR ( row , imfptr , " auto_connect " , 0 , NULL , ICON_NONE ) ;
2014-11-29 13:24:26 +01:00
row = uiLayoutRow ( box , false ) ;
uiItemR ( row , imfptr , " min_chain_length " , 0 , NULL , ICON_NONE ) ;
2017-03-23 00:07:05 +01:00
box = uiLayoutBox ( layout ) ;
row = uiLayoutRow ( box , false ) ;
row = uiLayoutRow ( box , false ) ;
uiItemR ( row , imfptr , " keep_bind_info " , 0 , NULL , ICON_NONE ) ;
2013-02-09 16:19:30 +00:00
}
static void wm_collada_import_draw ( bContext * UNUSED ( C ) , wmOperator * op )
{
PointerRNA ptr ;
RNA_pointer_create ( NULL , op - > type - > srna , op - > properties , & ptr ) ;
uiCollada_importSettings ( op - > layout , & ptr ) ;
2012-06-17 23:13:39 +00:00
}
void WM_OT_collada_import ( wmOperatorType * ot )
{
ot - > name = " Import COLLADA " ;
ot - > description = " Load a Collada file " ;
ot - > idname = " WM_OT_collada_import " ;
2012-09-18 07:03:23 +00:00
2012-06-17 23:13:39 +00:00
ot - > invoke = WM_operator_filesel ;
ot - > exec = wm_collada_import_exec ;
ot - > poll = WM_operator_winactive ;
2012-09-18 07:03:23 +00:00
2013-02-09 16:19:30 +00:00
//ot->flag |= OPTYPE_PRESET;
ot - > ui = wm_collada_import_draw ;
2016-02-07 22:56:20 +11:00
WM_operator_properties_filesel (
ot , FILE_TYPE_FOLDER | FILE_TYPE_COLLADA , FILE_BLENDER , FILE_OPENFILE ,
WM_FILESEL_FILEPATH , FILE_DEFAULTDISPLAY , FILE_SORT_ALPHA ) ;
2013-02-09 16:19:30 +00:00
2013-02-10 22:14:56 +00:00
RNA_def_boolean ( ot - > srna ,
2014-11-29 13:24:26 +01:00
" import_units " , 0 , " Import Units " ,
" If disabled match import to Blender's current Unit settings, "
" otherwise use the settings from the Imported scene " ) ;
2014-12-01 20:31:42 +01:00
RNA_def_boolean ( ot - > srna ,
" fix_orientation " , 0 , " Fix Leaf Bones " ,
" Fix Orientation of Leaf Bones (Collada does only support Joints) " ) ;
2014-11-29 13:24:26 +01:00
RNA_def_boolean ( ot - > srna ,
" find_chains " , 0 , " Find Bone Chains " ,
" Find best matching Bone Chains and ensure bones in chain are connected " ) ;
2016-06-03 18:26:12 +02:00
RNA_def_boolean ( ot - > srna ,
" auto_connect " , 0 , " Auto Connect " ,
2016-06-14 00:16:39 +02:00
" Set use_connect for parent bones which have exactly one child bone " ) ;
2016-06-03 18:26:12 +02:00
2014-11-29 13:24:26 +01:00
RNA_def_int ( ot - > srna ,
" min_chain_length " ,
0 ,
0 ,
INT_MAX ,
" Minimum Chain Length " ,
" When searching Bone Chains disregard chains of length below this value " ,
0 ,
INT_MAX ) ;
2013-02-09 16:19:30 +00:00
2017-03-23 00:07:05 +01:00
RNA_def_boolean ( ot - > srna ,
" keep_bind_info " , 0 , " Keep Bind Info " ,
" Store Bindpose information in custom bone properties for later use during Collada export " ) ;
2012-06-18 00:27:30 +00:00
}
2012-06-18 01:17:50 +00:00
# endif