diff options
author | Campbell Barton <ideasman42@gmail.com> | 2019-04-17 07:17:24 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2019-04-17 07:21:24 +0300 |
commit | e12c08e8d170b7ca40f204a5b0423c23a9fbc2c1 (patch) | |
tree | 8cf3453d12edb177a218ef8009357518ec6cab6a /source/blender/editors/io | |
parent | b3dabc200a4b0399ec6b81f2ff2730d07b44fcaa (diff) |
ClangFormat: apply to source, most of intern
Apply clang format as proposed in T53211.
For details on usage and instructions for migrating branches
without conflicts, see:
https://wiki.blender.org/wiki/Tools/ClangFormat
Diffstat (limited to 'source/blender/editors/io')
-rw-r--r-- | source/blender/editors/io/CMakeLists.txt | 68 | ||||
-rw-r--r-- | source/blender/editors/io/io_alembic.c | 1013 | ||||
-rw-r--r-- | source/blender/editors/io/io_cache.c | 156 | ||||
-rw-r--r-- | source/blender/editors/io/io_collada.c | 1306 | ||||
-rw-r--r-- | source/blender/editors/io/io_ops.c | 16 |
5 files changed, 1394 insertions, 1165 deletions
diff --git a/source/blender/editors/io/CMakeLists.txt b/source/blender/editors/io/CMakeLists.txt index 6e3e111739c..fbbb8621ae6 100644 --- a/source/blender/editors/io/CMakeLists.txt +++ b/source/blender/editors/io/CMakeLists.txt @@ -16,18 +16,18 @@ # ***** END GPL LICENSE BLOCK ***** set(INC - ../include - ../../blenkernel - ../../blenlib - ../../blentranslation - ../../bmesh - ../../depsgraph - ../../makesdna - ../../makesrna - ../../windowmanager - ../../collada - ../../alembic - ../../../../intern/guardedalloc + ../include + ../../blenkernel + ../../blenlib + ../../blentranslation + ../../bmesh + ../../depsgraph + ../../makesdna + ../../makesrna + ../../windowmanager + ../../collada + ../../alembic + ../../../../intern/guardedalloc ) set(INC_SYS @@ -35,42 +35,42 @@ set(INC_SYS ) set(SRC - io_alembic.c - io_cache.c - io_collada.c - io_ops.c + io_alembic.c + io_cache.c + io_collada.c + io_ops.c - io_alembic.h - io_cache.h - io_collada.h - io_ops.h + io_alembic.h + io_cache.h + io_collada.h + io_ops.h ) set(LIB - bf_blenkernel - bf_blenlib + bf_blenkernel + bf_blenlib ) if(WITH_OPENCOLLADA) - list(APPEND LIB - bf_collada - ) - add_definitions(-DWITH_COLLADA) + list(APPEND LIB + bf_collada + ) + add_definitions(-DWITH_COLLADA) endif() if(WITH_ALEMBIC) - list(APPEND LIB - bf_alembic - ) - add_definitions(-DWITH_ALEMBIC) + list(APPEND LIB + bf_alembic + ) + add_definitions(-DWITH_ALEMBIC) - if(WITH_ALEMBIC_HDF5) - add_definitions(-DWITH_ALEMBIC_HDF5) - endif() + if(WITH_ALEMBIC_HDF5) + add_definitions(-DWITH_ALEMBIC_HDF5) + endif() endif() if(WITH_INTERNATIONAL) - add_definitions(-DWITH_INTERNATIONAL) + add_definitions(-DWITH_INTERNATIONAL) endif() blender_add_lib(bf_editor_io "${SRC}" "${INC}" "${INC_SYS}" "${LIB}") diff --git a/source/blender/editors/io/io_alembic.c b/source/blender/editors/io/io_alembic.c index 576d51b7c49..dc8e33c817e 100644 --- a/source/blender/editors/io/io_alembic.c +++ b/source/blender/editors/io/io_alembic.c @@ -24,385 +24,470 @@ #ifdef WITH_ALEMBIC /* needed for directory lookup */ -#ifndef WIN32 -# include <dirent.h> -#else -# include "BLI_winstuff.h" -#endif +# ifndef WIN32 +# include <dirent.h> +# else +# include "BLI_winstuff.h" +# endif -#include <string.h> -#include <errno.h> +# include <string.h> +# include <errno.h> -#include "MEM_guardedalloc.h" +# include "MEM_guardedalloc.h" -#include "DNA_mesh_types.h" -#include "DNA_modifier_types.h" -#include "DNA_object_types.h" -#include "DNA_scene_types.h" -#include "DNA_space_types.h" +# include "DNA_mesh_types.h" +# include "DNA_modifier_types.h" +# include "DNA_object_types.h" +# include "DNA_scene_types.h" +# include "DNA_space_types.h" -#include "BKE_context.h" -#include "BKE_global.h" -#include "BKE_main.h" -#include "BKE_report.h" +# include "BKE_context.h" +# include "BKE_global.h" +# include "BKE_main.h" +# include "BKE_report.h" -#include "BLI_listbase.h" -#include "BLI_math_vector.h" -#include "BLI_path_util.h" -#include "BLI_string.h" -#include "BLI_utildefines.h" +# include "BLI_listbase.h" +# include "BLI_math_vector.h" +# include "BLI_path_util.h" +# include "BLI_string.h" +# include "BLI_utildefines.h" -#include "BLT_translation.h" +# include "BLT_translation.h" -#include "RNA_access.h" -#include "RNA_define.h" -#include "RNA_enum_types.h" +# include "RNA_access.h" +# include "RNA_define.h" +# include "RNA_enum_types.h" -#include "ED_object.h" +# include "ED_object.h" -#include "UI_interface.h" -#include "UI_resources.h" +# include "UI_interface.h" +# include "UI_resources.h" -#include "WM_api.h" -#include "WM_types.h" +# include "WM_api.h" +# include "WM_types.h" -#include "io_alembic.h" +# include "io_alembic.h" -#include "ABC_alembic.h" +# include "ABC_alembic.h" static int wm_alembic_export_invoke(bContext *C, wmOperator *op, const wmEvent *event) { - if (!RNA_struct_property_is_set(op->ptr, "as_background_job")) { - RNA_boolean_set(op->ptr, "as_background_job", true); - } + if (!RNA_struct_property_is_set(op->ptr, "as_background_job")) { + RNA_boolean_set(op->ptr, "as_background_job", true); + } - RNA_boolean_set(op->ptr, "init_scene_frame_range", true); + RNA_boolean_set(op->ptr, "init_scene_frame_range", true); - if (!RNA_struct_property_is_set(op->ptr, "filepath")) { - Main *bmain = CTX_data_main(C); - char filepath[FILE_MAX]; + if (!RNA_struct_property_is_set(op->ptr, "filepath")) { + Main *bmain = CTX_data_main(C); + char filepath[FILE_MAX]; - if (BKE_main_blendfile_path(bmain)[0] == '\0') { - BLI_strncpy(filepath, "untitled", sizeof(filepath)); - } - else { - BLI_strncpy(filepath, BKE_main_blendfile_path(bmain), sizeof(filepath)); - } + if (BKE_main_blendfile_path(bmain)[0] == '\0') { + BLI_strncpy(filepath, "untitled", sizeof(filepath)); + } + else { + BLI_strncpy(filepath, BKE_main_blendfile_path(bmain), sizeof(filepath)); + } - BLI_path_extension_replace(filepath, sizeof(filepath), ".abc"); - RNA_string_set(op->ptr, "filepath", filepath); - } + BLI_path_extension_replace(filepath, sizeof(filepath), ".abc"); + RNA_string_set(op->ptr, "filepath", filepath); + } - WM_event_add_fileselect(C, op); + WM_event_add_fileselect(C, op); - return OPERATOR_RUNNING_MODAL; + return OPERATOR_RUNNING_MODAL; - UNUSED_VARS(event); + UNUSED_VARS(event); } static int wm_alembic_export_exec(bContext *C, wmOperator *op) { - if (!RNA_struct_property_is_set(op->ptr, "filepath")) { - BKE_report(op->reports, RPT_ERROR, "No filename given"); - return OPERATOR_CANCELLED; - } - - char filename[FILE_MAX]; - RNA_string_get(op->ptr, "filepath", filename); - - struct AlembicExportParams params = { - .frame_start = RNA_int_get(op->ptr, "start"), - .frame_end = RNA_int_get(op->ptr, "end"), - - .frame_samples_xform = RNA_int_get(op->ptr, "xsamples"), - .frame_samples_shape = RNA_int_get(op->ptr, "gsamples"), - - .shutter_open = RNA_float_get(op->ptr, "sh_open"), - .shutter_close = RNA_float_get(op->ptr, "sh_close"), - - .selected_only = RNA_boolean_get(op->ptr, "selected"), - .uvs = RNA_boolean_get(op->ptr, "uvs"), - .normals = RNA_boolean_get(op->ptr, "normals"), - .vcolors = RNA_boolean_get(op->ptr, "vcolors"), - .apply_subdiv = RNA_boolean_get(op->ptr, "apply_subdiv"), - .curves_as_mesh = RNA_boolean_get(op->ptr, "curves_as_mesh"), - .flatten_hierarchy = RNA_boolean_get(op->ptr, "flatten"), - .visible_layers_only = RNA_boolean_get(op->ptr, "visible_layers_only"), - .renderable_only = RNA_boolean_get(op->ptr, "renderable_only"), - .face_sets = RNA_boolean_get(op->ptr, "face_sets"), - .use_subdiv_schema = RNA_boolean_get(op->ptr, "subdiv_schema"), - .export_hair = RNA_boolean_get(op->ptr, "export_hair"), - .export_particles = RNA_boolean_get(op->ptr, "export_particles"), - .compression_type = RNA_enum_get(op->ptr, "compression_type"), - .packuv = RNA_boolean_get(op->ptr, "packuv"), - .triangulate = RNA_boolean_get(op->ptr, "triangulate"), - .quad_method = RNA_enum_get(op->ptr, "quad_method"), - .ngon_method = RNA_enum_get(op->ptr, "ngon_method"), - - .global_scale = RNA_float_get(op->ptr, "global_scale"), - }; - - /* Take some defaults from the scene, if not specified explicitly. */ - Scene *scene = CTX_data_scene(C); - if (params.frame_start == INT_MIN) { - params.frame_start = SFRA; - } - if (params.frame_end == INT_MIN) { - params.frame_end = EFRA; - } - - const bool as_background_job = RNA_boolean_get(op->ptr, "as_background_job"); - bool ok = ABC_export(scene, C, filename, ¶ms, as_background_job); - - return as_background_job || ok ? OPERATOR_FINISHED : OPERATOR_CANCELLED; + if (!RNA_struct_property_is_set(op->ptr, "filepath")) { + BKE_report(op->reports, RPT_ERROR, "No filename given"); + return OPERATOR_CANCELLED; + } + + char filename[FILE_MAX]; + RNA_string_get(op->ptr, "filepath", filename); + + struct AlembicExportParams params = { + .frame_start = RNA_int_get(op->ptr, "start"), + .frame_end = RNA_int_get(op->ptr, "end"), + + .frame_samples_xform = RNA_int_get(op->ptr, "xsamples"), + .frame_samples_shape = RNA_int_get(op->ptr, "gsamples"), + + .shutter_open = RNA_float_get(op->ptr, "sh_open"), + .shutter_close = RNA_float_get(op->ptr, "sh_close"), + + .selected_only = RNA_boolean_get(op->ptr, "selected"), + .uvs = RNA_boolean_get(op->ptr, "uvs"), + .normals = RNA_boolean_get(op->ptr, "normals"), + .vcolors = RNA_boolean_get(op->ptr, "vcolors"), + .apply_subdiv = RNA_boolean_get(op->ptr, "apply_subdiv"), + .curves_as_mesh = RNA_boolean_get(op->ptr, "curves_as_mesh"), + .flatten_hierarchy = RNA_boolean_get(op->ptr, "flatten"), + .visible_layers_only = RNA_boolean_get(op->ptr, "visible_layers_only"), + .renderable_only = RNA_boolean_get(op->ptr, "renderable_only"), + .face_sets = RNA_boolean_get(op->ptr, "face_sets"), + .use_subdiv_schema = RNA_boolean_get(op->ptr, "subdiv_schema"), + .export_hair = RNA_boolean_get(op->ptr, "export_hair"), + .export_particles = RNA_boolean_get(op->ptr, "export_particles"), + .compression_type = RNA_enum_get(op->ptr, "compression_type"), + .packuv = RNA_boolean_get(op->ptr, "packuv"), + .triangulate = RNA_boolean_get(op->ptr, "triangulate"), + .quad_method = RNA_enum_get(op->ptr, "quad_method"), + .ngon_method = RNA_enum_get(op->ptr, "ngon_method"), + + .global_scale = RNA_float_get(op->ptr, "global_scale"), + }; + + /* Take some defaults from the scene, if not specified explicitly. */ + Scene *scene = CTX_data_scene(C); + if (params.frame_start == INT_MIN) { + params.frame_start = SFRA; + } + if (params.frame_end == INT_MIN) { + params.frame_end = EFRA; + } + + const bool as_background_job = RNA_boolean_get(op->ptr, "as_background_job"); + bool ok = ABC_export(scene, C, filename, ¶ms, as_background_job); + + return as_background_job || ok ? OPERATOR_FINISHED : OPERATOR_CANCELLED; } static void ui_alembic_export_settings(uiLayout *layout, PointerRNA *imfptr) { - uiLayout *box; - uiLayout *row; - uiLayout *col; + uiLayout *box; + uiLayout *row; + uiLayout *col; -#ifdef WITH_ALEMBIC_HDF5 - box = uiLayoutBox(layout); - row = uiLayoutRow(box, false); - uiItemL(row, IFACE_("Archive Options:"), ICON_NONE); +# ifdef WITH_ALEMBIC_HDF5 + box = uiLayoutBox(layout); + row = uiLayoutRow(box, false); + uiItemL(row, IFACE_("Archive Options:"), ICON_NONE); - row = uiLayoutRow(box, false); - uiItemR(row, imfptr, "compression_type", 0, NULL, ICON_NONE); -#endif + row = uiLayoutRow(box, false); + uiItemR(row, imfptr, "compression_type", 0, NULL, ICON_NONE); +# endif - box = uiLayoutBox(layout); - row = uiLayoutRow(box, false); - uiItemL(row, IFACE_("Manual Transform:"), ICON_NONE); + box = uiLayoutBox(layout); + row = uiLayoutRow(box, false); + uiItemL(row, IFACE_("Manual Transform:"), ICON_NONE); - row = uiLayoutRow(box, false); - uiItemR(row, imfptr, "global_scale", 0, NULL, ICON_NONE); + row = uiLayoutRow(box, false); + uiItemR(row, imfptr, "global_scale", 0, NULL, ICON_NONE); - /* Scene Options */ - box = uiLayoutBox(layout); - row = uiLayoutRow(box, false); - uiItemL(row, IFACE_("Scene Options:"), ICON_SCENE_DATA); + /* Scene Options */ + box = uiLayoutBox(layout); + row = uiLayoutRow(box, false); + uiItemL(row, IFACE_("Scene Options:"), ICON_SCENE_DATA); - row = uiLayoutRow(box, false); - uiItemR(row, imfptr, "start", 0, NULL, ICON_NONE); + row = uiLayoutRow(box, false); + uiItemR(row, imfptr, "start", 0, NULL, ICON_NONE); - row = uiLayoutRow(box, false); - uiItemR(row, imfptr, "end", 0, NULL, ICON_NONE); + row = uiLayoutRow(box, false); + uiItemR(row, imfptr, "end", 0, NULL, ICON_NONE); - row = uiLayoutRow(box, false); - uiItemR(row, imfptr, "xsamples", 0, NULL, ICON_NONE); + row = uiLayoutRow(box, false); + uiItemR(row, imfptr, "xsamples", 0, NULL, ICON_NONE); - row = uiLayoutRow(box, false); - uiItemR(row, imfptr, "gsamples", 0, NULL, ICON_NONE); + row = uiLayoutRow(box, false); + uiItemR(row, imfptr, "gsamples", 0, NULL, ICON_NONE); - row = uiLayoutRow(box, false); - uiItemR(row, imfptr, "sh_open", 0, NULL, ICON_NONE); + row = uiLayoutRow(box, false); + uiItemR(row, imfptr, "sh_open", 0, NULL, ICON_NONE); - row = uiLayoutRow(box, false); - uiItemR(row, imfptr, "sh_close", 0, NULL, ICON_NONE); + row = uiLayoutRow(box, false); + uiItemR(row, imfptr, "sh_close", 0, NULL, ICON_NONE); - row = uiLayoutRow(box, false); - uiItemR(row, imfptr, "selected", 0, NULL, ICON_NONE); + row = uiLayoutRow(box, false); + uiItemR(row, imfptr, "selected", 0, NULL, ICON_NONE); - row = uiLayoutRow(box, false); - uiItemR(row, imfptr, "renderable_only", 0, NULL, ICON_NONE); + row = uiLayoutRow(box, false); + uiItemR(row, imfptr, "renderable_only", 0, NULL, ICON_NONE); - row = uiLayoutRow(box, false); - uiItemR(row, imfptr, "visible_layers_only", 0, NULL, ICON_NONE); + row = uiLayoutRow(box, false); + uiItemR(row, imfptr, "visible_layers_only", 0, NULL, ICON_NONE); - row = uiLayoutRow(box, false); - uiItemR(row, imfptr, "flatten", 0, NULL, ICON_NONE); + row = uiLayoutRow(box, false); + uiItemR(row, imfptr, "flatten", 0, NULL, ICON_NONE); - /* Object Data */ - box = uiLayoutBox(layout); - row = uiLayoutRow(box, false); - uiItemL(row, IFACE_("Object Options:"), ICON_OBJECT_DATA); + /* Object Data */ + box = uiLayoutBox(layout); + row = uiLayoutRow(box, false); + uiItemL(row, IFACE_("Object Options:"), ICON_OBJECT_DATA); - row = uiLayoutRow(box, false); - uiItemR(row, imfptr, "uvs", 0, NULL, ICON_NONE); + row = uiLayoutRow(box, false); + uiItemR(row, imfptr, "uvs", 0, NULL, ICON_NONE); - row = uiLayoutRow(box, false); - uiItemR(row, imfptr, "packuv", 0, NULL, ICON_NONE); - uiLayoutSetEnabled(row, RNA_boolean_get(imfptr, "uvs")); + row = uiLayoutRow(box, false); + uiItemR(row, imfptr, "packuv", 0, NULL, ICON_NONE); + uiLayoutSetEnabled(row, RNA_boolean_get(imfptr, "uvs")); - row = uiLayoutRow(box, false); - uiItemR(row, imfptr, "normals", 0, NULL, ICON_NONE); + row = uiLayoutRow(box, false); + uiItemR(row, imfptr, "normals", 0, NULL, ICON_NONE); - row = uiLayoutRow(box, false); - uiItemR(row, imfptr, "vcolors", 0, NULL, ICON_NONE); + row = uiLayoutRow(box, false); + uiItemR(row, imfptr, "vcolors", 0, NULL, ICON_NONE); - row = uiLayoutRow(box, false); - uiItemR(row, imfptr, "face_sets", 0, NULL, ICON_NONE); + row = uiLayoutRow(box, false); + uiItemR(row, imfptr, "face_sets", 0, NULL, ICON_NONE); - row = uiLayoutRow(box, false); - uiItemR(row, imfptr, "subdiv_schema", 0, NULL, ICON_NONE); + row = uiLayoutRow(box, false); + uiItemR(row, imfptr, "subdiv_schema", 0, NULL, ICON_NONE); - row = uiLayoutRow(box, false); - uiItemR(row, imfptr, "apply_subdiv", 0, NULL, ICON_NONE); + row = uiLayoutRow(box, false); + uiItemR(row, imfptr, "apply_subdiv", 0, NULL, ICON_NONE); - row = uiLayoutRow(box, false); - uiItemR(row, imfptr, "curves_as_mesh", 0, NULL, ICON_NONE); + row = uiLayoutRow(box, false); + uiItemR(row, imfptr, "curves_as_mesh", 0, NULL, ICON_NONE); - row = uiLayoutRow(box, false); - uiItemR(row, imfptr, "triangulate", 0, NULL, ICON_NONE); + row = uiLayoutRow(box, false); + uiItemR(row, imfptr, "triangulate", 0, NULL, ICON_NONE); - const bool triangulate = RNA_boolean_get(imfptr, "triangulate"); + const bool triangulate = RNA_boolean_get(imfptr, "triangulate"); - row = uiLayoutRow(box, false); - uiLayoutSetEnabled(row, triangulate); - uiItemR(row, imfptr, "quad_method", 0, NULL, ICON_NONE); + row = uiLayoutRow(box, false); + uiLayoutSetEnabled(row, triangulate); + uiItemR(row, imfptr, "quad_method", 0, NULL, ICON_NONE); - row = uiLayoutRow(box, false); - uiLayoutSetEnabled(row, triangulate); - uiItemR(row, imfptr, "ngon_method", 0, NULL, ICON_NONE); + row = uiLayoutRow(box, false); + uiLayoutSetEnabled(row, triangulate); + uiItemR(row, imfptr, "ngon_method", 0, NULL, ICON_NONE); - /* Object Data */ - box = uiLayoutBox(layout); - row = uiLayoutRow(box, false); - uiItemL(row, IFACE_("Particle Systems:"), ICON_PARTICLE_DATA); + /* Object Data */ + box = uiLayoutBox(layout); + row = uiLayoutRow(box, false); + uiItemL(row, IFACE_("Particle Systems:"), ICON_PARTICLE_DATA); - col = uiLayoutColumn(box, true); - uiItemR(col, imfptr, "export_hair", 0, NULL, ICON_NONE); - uiItemR(col, imfptr, "export_particles", 0, NULL, ICON_NONE); + col = uiLayoutColumn(box, true); + uiItemR(col, imfptr, "export_hair", 0, NULL, ICON_NONE); + uiItemR(col, imfptr, "export_particles", 0, NULL, ICON_NONE); } static void wm_alembic_export_draw(bContext *C, wmOperator *op) { - PointerRNA ptr; + PointerRNA ptr; - RNA_pointer_create(NULL, op->type->srna, op->properties, &ptr); + RNA_pointer_create(NULL, op->type->srna, op->properties, &ptr); - /* Conveniently set start and end frame to match the scene's frame range. */ - Scene *scene = CTX_data_scene(C); + /* Conveniently set start and end frame to match the scene's frame range. */ + Scene *scene = CTX_data_scene(C); - if (scene != NULL && RNA_boolean_get(&ptr, "init_scene_frame_range")) { - RNA_int_set(&ptr, "start", SFRA); - RNA_int_set(&ptr, "end", EFRA); + if (scene != NULL && RNA_boolean_get(&ptr, "init_scene_frame_range")) { + RNA_int_set(&ptr, "start", SFRA); + RNA_int_set(&ptr, "end", EFRA); - RNA_boolean_set(&ptr, "init_scene_frame_range", false); - } + RNA_boolean_set(&ptr, "init_scene_frame_range", false); + } - ui_alembic_export_settings(op->layout, &ptr); + ui_alembic_export_settings(op->layout, &ptr); } static bool wm_alembic_export_check(bContext *UNUSED(C), wmOperator *op) { - char filepath[FILE_MAX]; - RNA_string_get(op->ptr, "filepath", filepath); + char filepath[FILE_MAX]; + RNA_string_get(op->ptr, "filepath", filepath); - if (!BLI_path_extension_check(filepath, ".abc")) { - BLI_path_extension_ensure(filepath, FILE_MAX, ".abc"); - RNA_string_set(op->ptr, "filepath", filepath); - return true; - } + if (!BLI_path_extension_check(filepath, ".abc")) { + BLI_path_extension_ensure(filepath, FILE_MAX, ".abc"); + RNA_string_set(op->ptr, "filepath", filepath); + return true; + } - return false; + return false; } void WM_OT_alembic_export(wmOperatorType *ot) { - ot->name = "Export Alembic"; - ot->description = "Export current scene in an Alembic archive"; - ot->idname = "WM_OT_alembic_export"; - - ot->invoke = wm_alembic_export_invoke; - ot->exec = wm_alembic_export_exec; - ot->poll = WM_operator_winactive; - ot->ui = wm_alembic_export_draw; - ot->check = wm_alembic_export_check; - - WM_operator_properties_filesel(ot, FILE_TYPE_FOLDER | FILE_TYPE_ALEMBIC, - FILE_BLENDER, FILE_SAVE, WM_FILESEL_FILEPATH, - FILE_DEFAULTDISPLAY, FILE_SORT_ALPHA); - - RNA_def_int(ot->srna, "start", INT_MIN, INT_MIN, INT_MAX, - "Start Frame", - "Start frame of the export, use the default value to " - "take the start frame of the current scene", - INT_MIN, INT_MAX); - - RNA_def_int(ot->srna, "end", INT_MIN, INT_MIN, INT_MAX, - "End Frame", - "End frame of the export, use the default value to " - "take the end frame of the current scene", - INT_MIN, INT_MAX); - - RNA_def_int(ot->srna, "xsamples", 1, 1, 128, - "Transform Samples", "Number of times per frame transformations are sampled", 1, 128); - - RNA_def_int(ot->srna, "gsamples", 1, 1, 128, - "Geometry Samples", "Number of times per frame object data are sampled", 1, 128); - - RNA_def_float(ot->srna, "sh_open", 0.0f, -1.0f, 1.0f, - "Shutter Open", "Time at which the shutter is open", -1.0f, 1.0f); - - RNA_def_float(ot->srna, "sh_close", 1.0f, -1.0f, 1.0f, - "Shutter Close", "Time at which the shutter is closed", -1.0f, 1.0f); - - RNA_def_boolean(ot->srna, "selected", 0, - "Selected Objects Only", "Export only selected objects"); - - RNA_def_boolean(ot->srna, "renderable_only", 1, - "Renderable Objects Only", - "Export only objects marked renderable in the outliner"); - - RNA_def_boolean(ot->srna, "visible_layers_only", 0, - "Visible Layers Only", "Export only objects in visible layers"); - - RNA_def_boolean(ot->srna, "flatten", 0, - "Flatten Hierarchy", - "Do not preserve objects' parent/children relationship"); - - RNA_def_boolean(ot->srna, "uvs", 1, "UVs", "Export UVs"); - - RNA_def_boolean(ot->srna, "packuv", 1, "Pack UV Islands", - "Export UVs with packed island"); - - RNA_def_boolean(ot->srna, "normals", 1, "Normals", "Export normals"); - - RNA_def_boolean(ot->srna, "vcolors", 0, "Vertex Colors", "Export vertex colors"); - - RNA_def_boolean(ot->srna, "face_sets", 0, "Face Sets", "Export per face shading group assignments"); - - RNA_def_boolean(ot->srna, "subdiv_schema", 0, - "Use Subdivision Schema", - "Export meshes using Alembic's subdivision schema"); - - RNA_def_boolean(ot->srna, "apply_subdiv", 0, - "Apply Subsurf", "Export subdivision surfaces as meshes"); - - RNA_def_boolean(ot->srna, "curves_as_mesh", false, - "Curves as Mesh", "Export curves and NURBS surfaces as meshes"); - - RNA_def_enum(ot->srna, "compression_type", rna_enum_abc_compression_items, - ABC_ARCHIVE_OGAWA, "Compression", ""); - - RNA_def_float(ot->srna, "global_scale", 1.0f, 0.0001f, 1000.0f, "Scale", - "Value by which to enlarge or shrink the objects with respect to the world's origin", - 0.0001f, 1000.0f); - - RNA_def_boolean(ot->srna, "triangulate", false, "Triangulate", - "Export Polygons (Quads & NGons) as Triangles"); - - RNA_def_enum(ot->srna, "quad_method", rna_enum_modifier_triangulate_quad_method_items, - MOD_TRIANGULATE_QUAD_SHORTEDGE, "Quad Method", "Method for splitting the quads into triangles"); - - RNA_def_enum(ot->srna, "ngon_method", rna_enum_modifier_triangulate_quad_method_items, - MOD_TRIANGULATE_NGON_BEAUTY, "Polygon Method", "Method for splitting the polygons into triangles"); - - RNA_def_boolean(ot->srna, "export_hair", 1, "Export Hair", "Exports hair particle systems as animated curves"); - RNA_def_boolean(ot->srna, "export_particles", 1, "Export Particles", "Exports non-hair particle systems"); - - RNA_def_boolean(ot->srna, "as_background_job", false, "Run as Background Job", - "Enable this to run the import in the background, disable to block Blender while importing. " - "This option is deprecated; EXECUTE this operator to run in the foreground, and INVOKE it " - "to run as a background job"); - - /* This dummy prop is used to check whether we need to init the start and - * end frame values to that of the scene's, otherwise they are reset at - * every change, draw update. */ - RNA_def_boolean(ot->srna, "init_scene_frame_range", false, "", ""); + ot->name = "Export Alembic"; + ot->description = "Export current scene in an Alembic archive"; + ot->idname = "WM_OT_alembic_export"; + + ot->invoke = wm_alembic_export_invoke; + ot->exec = wm_alembic_export_exec; + ot->poll = WM_operator_winactive; + ot->ui = wm_alembic_export_draw; + ot->check = wm_alembic_export_check; + + WM_operator_properties_filesel(ot, + FILE_TYPE_FOLDER | FILE_TYPE_ALEMBIC, + FILE_BLENDER, + FILE_SAVE, + WM_FILESEL_FILEPATH, + FILE_DEFAULTDISPLAY, + FILE_SORT_ALPHA); + + RNA_def_int(ot->srna, + "start", + INT_MIN, + INT_MIN, + INT_MAX, + "Start Frame", + "Start frame of the export, use the default value to " + "take the start frame of the current scene", + INT_MIN, + INT_MAX); + + RNA_def_int(ot->srna, + "end", + INT_MIN, + INT_MIN, + INT_MAX, + "End Frame", + "End frame of the export, use the default value to " + "take the end frame of the current scene", + INT_MIN, + INT_MAX); + + RNA_def_int(ot->srna, + "xsamples", + 1, + 1, + 128, + "Transform Samples", + "Number of times per frame transformations are sampled", + 1, + 128); + + RNA_def_int(ot->srna, + "gsamples", + 1, + 1, + 128, + "Geometry Samples", + "Number of times per frame object data are sampled", + 1, + 128); + + RNA_def_float(ot->srna, + "sh_open", + 0.0f, + -1.0f, + 1.0f, + "Shutter Open", + "Time at which the shutter is open", + -1.0f, + 1.0f); + + RNA_def_float(ot->srna, + "sh_close", + 1.0f, + -1.0f, + 1.0f, + "Shutter Close", + "Time at which the shutter is closed", + -1.0f, + 1.0f); + + RNA_def_boolean( + ot->srna, "selected", 0, "Selected Objects Only", "Export only selected objects"); + + RNA_def_boolean(ot->srna, + "renderable_only", + 1, + "Renderable Objects Only", + "Export only objects marked renderable in the outliner"); + + RNA_def_boolean(ot->srna, + "visible_layers_only", + 0, + "Visible Layers Only", + "Export only objects in visible layers"); + + RNA_def_boolean(ot->srna, + "flatten", + 0, + "Flatten Hierarchy", + "Do not preserve objects' parent/children relationship"); + + RNA_def_boolean(ot->srna, "uvs", 1, "UVs", "Export UVs"); + + RNA_def_boolean(ot->srna, "packuv", 1, "Pack UV Islands", "Export UVs with packed island"); + + RNA_def_boolean(ot->srna, "normals", 1, "Normals", "Export normals"); + + RNA_def_boolean(ot->srna, "vcolors", 0, "Vertex Colors", "Export vertex colors"); + + RNA_def_boolean( + ot->srna, "face_sets", 0, "Face Sets", "Export per face shading group assignments"); + + RNA_def_boolean(ot->srna, + "subdiv_schema", + 0, + "Use Subdivision Schema", + "Export meshes using Alembic's subdivision schema"); + + RNA_def_boolean( + ot->srna, "apply_subdiv", 0, "Apply Subsurf", "Export subdivision surfaces as meshes"); + + RNA_def_boolean(ot->srna, + "curves_as_mesh", + false, + "Curves as Mesh", + "Export curves and NURBS surfaces as meshes"); + + RNA_def_enum(ot->srna, + "compression_type", + rna_enum_abc_compression_items, + ABC_ARCHIVE_OGAWA, + "Compression", + ""); + + RNA_def_float( + ot->srna, + "global_scale", + 1.0f, + 0.0001f, + 1000.0f, + "Scale", + "Value by which to enlarge or shrink the objects with respect to the world's origin", + 0.0001f, + 1000.0f); + + RNA_def_boolean(ot->srna, + "triangulate", + false, + "Triangulate", + "Export Polygons (Quads & NGons) as Triangles"); + + RNA_def_enum(ot->srna, + "quad_method", + rna_enum_modifier_triangulate_quad_method_items, + MOD_TRIANGULATE_QUAD_SHORTEDGE, + "Quad Method", + "Method for splitting the quads into triangles"); + + RNA_def_enum(ot->srna, + "ngon_method", + rna_enum_modifier_triangulate_quad_method_items, + MOD_TRIANGULATE_NGON_BEAUTY, + "Polygon Method", + "Method for splitting the polygons into triangles"); + + RNA_def_boolean(ot->srna, + "export_hair", + 1, + "Export Hair", + "Exports hair particle systems as animated curves"); + RNA_def_boolean( + ot->srna, "export_particles", 1, "Export Particles", "Exports non-hair particle systems"); + + RNA_def_boolean( + ot->srna, + "as_background_job", + false, + "Run as Background Job", + "Enable this to run the import in the background, disable to block Blender while importing. " + "This option is deprecated; EXECUTE this operator to run in the foreground, and INVOKE it " + "to run as a background job"); + + /* This dummy prop is used to check whether we need to init the start and + * end frame values to that of the scene's, otherwise they are reset at + * every change, draw update. */ + RNA_def_boolean(ot->srna, "init_scene_frame_range", false, "", ""); } /* ************************************************************************** */ @@ -410,210 +495,242 @@ void WM_OT_alembic_export(wmOperatorType *ot) /* TODO(kevin): check on de-duplicating all this with code in image_ops.c */ typedef struct CacheFrame { - struct CacheFrame *next, *prev; - int framenr; + struct CacheFrame *next, *prev; + int framenr; } CacheFrame; static int cmp_frame(const void *a, const void *b) { - const CacheFrame *frame_a = a; - const CacheFrame *frame_b = b; - - if (frame_a->framenr < frame_b->framenr) return -1; - if (frame_a->framenr > frame_b->framenr) return 1; - return 0; + const CacheFrame *frame_a = a; + const CacheFrame *frame_b = b; + + if (frame_a->framenr < frame_b->framenr) + return -1; + if (frame_a->framenr > frame_b->framenr) + return 1; + return 0; } static int get_sequence_len(char *filename, int *ofs) { - int frame; - int numdigit; + int frame; + int numdigit; - if (!BLI_path_frame_get(filename, &frame, &numdigit)) { - return 1; - } + if (!BLI_path_frame_get(filename, &frame, &numdigit)) { + return 1; + } - char path[FILE_MAX]; - BLI_path_abs(filename, BKE_main_blendfile_path_from_global()); - BLI_split_dir_part(filename, path, FILE_MAX); + char path[FILE_MAX]; + BLI_path_abs(filename, BKE_main_blendfile_path_from_global()); + BLI_split_dir_part(filename, path, FILE_MAX); - if (path[0] == '\0') { - /* The filename had no path, so just use the blend file path. */ - BLI_split_dir_part(BKE_main_blendfile_path_from_global(), path, FILE_MAX); - } + if (path[0] == '\0') { + /* The filename had no path, so just use the blend file path. */ + BLI_split_dir_part(BKE_main_blendfile_path_from_global(), path, FILE_MAX); + } - DIR *dir = opendir(path); - if (dir == NULL) { - fprintf(stderr, "Error opening directory '%s': %s\n", - path, errno ? strerror(errno) : "unknown error"); - return -1; - } + DIR *dir = opendir(path); + if (dir == NULL) { + fprintf(stderr, + "Error opening directory '%s': %s\n", + path, + errno ? strerror(errno) : "unknown error"); + return -1; + } - const char *ext = ".abc"; - const char *basename = BLI_path_basename(filename); - const int len = strlen(basename) - (numdigit + strlen(ext)); + const char *ext = ".abc"; + const char *basename = BLI_path_basename(filename); + const int len = strlen(basename) - (numdigit + strlen(ext)); - ListBase frames; - BLI_listbase_clear(&frames); + ListBase frames; + BLI_listbase_clear(&frames); - struct dirent *fname; - while ((fname = readdir(dir)) != NULL) { - /* do we have the right extension? */ - if (!strstr(fname->d_name, ext)) { - continue; - } + struct dirent *fname; + while ((fname = readdir(dir)) != NULL) { + /* do we have the right extension? */ + if (!strstr(fname->d_name, ext)) { + continue; + } - if (!STREQLEN(basename, fname->d_name, len)) { - continue; - } + if (!STREQLEN(basename, fname->d_name, len)) { + continue; + } - CacheFrame *cache_frame = MEM_callocN(sizeof(CacheFrame), "abc_frame"); + CacheFrame *cache_frame = MEM_callocN(sizeof(CacheFrame), "abc_frame"); - BLI_path_frame_get(fname->d_name, &cache_frame->framenr, &numdigit); + BLI_path_frame_get(fname->d_name, &cache_frame->framenr, &numdigit); - BLI_addtail(&frames, cache_frame); - } + BLI_addtail(&frames, cache_frame); + } - closedir(dir); + closedir(dir); - BLI_listbase_sort(&frames, cmp_frame); + BLI_listbase_sort(&frames, cmp_frame); - CacheFrame *cache_frame = frames.first; + CacheFrame *cache_frame = frames.first; - if (cache_frame) { - int frame_curr = cache_frame->framenr; - (*ofs) = frame_curr; + if (cache_frame) { + int frame_curr = cache_frame->framenr; + (*ofs) = frame_curr; - while (cache_frame && (cache_frame->framenr == frame_curr)) { - ++frame_curr; - cache_frame = cache_frame->next; - } + while (cache_frame && (cache_frame->framenr == frame_curr)) { + ++frame_curr; + cache_frame = cache_frame->next; + } - BLI_freelistN(&frames); + BLI_freelistN(&frames); - return frame_curr - (*ofs); - } + return frame_curr - (*ofs); + } - return 1; + return 1; } /* ************************************************************************** */ static void ui_alembic_import_settings(uiLayout *layout, PointerRNA *imfptr) { - uiLayout *box = uiLayoutBox(layout); - uiLayout *row = uiLayoutRow(box, false); - uiItemL(row, IFACE_("Manual Transform:"), ICON_NONE); + uiLayout *box = uiLayoutBox(layout); + uiLayout *row = uiLayoutRow(box, false); + uiItemL(row, IFACE_("Manual Transform:"), ICON_NONE); - row = uiLayoutRow(box, false); - uiItemR(row, imfptr, "scale", 0, NULL, ICON_NONE); + row = uiLayoutRow(box, false); + uiItemR(row, imfptr, "scale", 0, NULL, ICON_NONE); - box = uiLayoutBox(layout); - row = uiLayoutRow(box, false); - uiItemL(row, IFACE_("Options:"), ICON_NONE); + box = uiLayoutBox(layout); + row = uiLayoutRow(box, false); + uiItemL(row, IFACE_("Options:"), ICON_NONE); - row = uiLayoutRow(box, false); - uiItemR(row, imfptr, "set_frame_range", 0, NULL, ICON_NONE); + row = uiLayoutRow(box, false); + uiItemR(row, imfptr, "set_frame_range", 0, NULL, ICON_NONE); - row = uiLayoutRow(box, false); - uiItemR(row, imfptr, "is_sequence", 0, NULL, ICON_NONE); + row = uiLayoutRow(box, false); + uiItemR(row, imfptr, "is_sequence", 0, NULL, ICON_NONE); - row = uiLayoutRow(box, false); - uiItemR(row, imfptr, "validate_meshes", 0, NULL, ICON_NONE); + row = uiLayoutRow(box, false); + uiItemR(row, imfptr, "validate_meshes", 0, NULL, ICON_NONE); } static void wm_alembic_import_draw(bContext *UNUSED(C), wmOperator *op) { - PointerRNA ptr; + PointerRNA ptr; - RNA_pointer_create(NULL, op->type->srna, op->properties, &ptr); - ui_alembic_import_settings(op->layout, &ptr); + RNA_pointer_create(NULL, op->type->srna, op->properties, &ptr); + ui_alembic_import_settings(op->layout, &ptr); } - /* op->invoke, opens fileselect if path property not set, otherwise executes */ static int wm_alembic_import_invoke(bContext *C, wmOperator *op, const wmEvent *event) { - if (!RNA_struct_property_is_set(op->ptr, "as_background_job")) { - RNA_boolean_set(op->ptr, "as_background_job", true); - } - return WM_operator_filesel(C, op, event); + if (!RNA_struct_property_is_set(op->ptr, "as_background_job")) { + RNA_boolean_set(op->ptr, "as_background_job", true); + } + return WM_operator_filesel(C, op, event); } - static int wm_alembic_import_exec(bContext *C, wmOperator *op) { - if (!RNA_struct_property_is_set(op->ptr, "filepath")) { - BKE_report(op->reports, RPT_ERROR, "No filename given"); - return OPERATOR_CANCELLED; - } - - char filename[FILE_MAX]; - RNA_string_get(op->ptr, "filepath", filename); - - const float scale = RNA_float_get(op->ptr, "scale"); - const bool is_sequence = RNA_boolean_get(op->ptr, "is_sequence"); - const bool set_frame_range = RNA_boolean_get(op->ptr, "set_frame_range"); - const bool validate_meshes = RNA_boolean_get(op->ptr, "validate_meshes"); - const bool as_background_job = RNA_boolean_get(op->ptr, "as_background_job"); - - int offset = 0; - int sequence_len = 1; - - if (is_sequence) { - sequence_len = get_sequence_len(filename, &offset); - if (sequence_len < 0) { - BKE_report(op->reports, RPT_ERROR, "Unable to determine ABC sequence length"); - return OPERATOR_CANCELLED; - } - } - - /* Switch out of edit mode to avoid being stuck in it (T54326). */ - Object *obedit = CTX_data_edit_object(C); - if (obedit) { - ED_object_mode_toggle(C, OB_MODE_EDIT); - } - - bool ok = ABC_import(C, filename, scale, is_sequence, set_frame_range, - sequence_len, offset, validate_meshes, - as_background_job); - - return as_background_job || ok ? OPERATOR_FINISHED : OPERATOR_CANCELLED; + if (!RNA_struct_property_is_set(op->ptr, "filepath")) { + BKE_report(op->reports, RPT_ERROR, "No filename given"); + return OPERATOR_CANCELLED; + } + + char filename[FILE_MAX]; + RNA_string_get(op->ptr, "filepath", filename); + + const float scale = RNA_float_get(op->ptr, "scale"); + const bool is_sequence = RNA_boolean_get(op->ptr, "is_sequence"); + const bool set_frame_range = RNA_boolean_get(op->ptr, "set_frame_range"); + const bool validate_meshes = RNA_boolean_get(op->ptr, "validate_meshes"); + const bool as_background_job = RNA_boolean_get(op->ptr, "as_background_job"); + + int offset = 0; + int sequence_len = 1; + + if (is_sequence) { + sequence_len = get_sequence_len(filename, &offset); + if (sequence_len < 0) { + BKE_report(op->reports, RPT_ERROR, "Unable to determine ABC sequence length"); + return OPERATOR_CANCELLED; + } + } + + /* Switch out of edit mode to avoid being stuck in it (T54326). */ + Object *obedit = CTX_data_edit_object(C); + if (obedit) { + ED_object_mode_toggle(C, OB_MODE_EDIT); + } + + bool ok = ABC_import(C, + filename, + scale, + is_sequence, + set_frame_range, + sequence_len, + offset, + validate_meshes, + as_background_job); + + return as_background_job || ok ? OPERATOR_FINISHED : OPERATOR_CANCELLED; } void WM_OT_alembic_import(wmOperatorType *ot) { - ot->name = "Import Alembic"; - ot->description = "Load an Alembic archive"; - ot->idname = "WM_OT_alembic_import"; - - ot->invoke = wm_alembic_import_invoke; - ot->exec = wm_alembic_import_exec; - ot->poll = WM_operator_winactive; - ot->ui = wm_alembic_import_draw; - - WM_operator_properties_filesel(ot, FILE_TYPE_FOLDER | FILE_TYPE_ALEMBIC, - FILE_BLENDER, FILE_SAVE, WM_FILESEL_FILEPATH, - FILE_DEFAULTDISPLAY, FILE_SORT_ALPHA); - - RNA_def_float(ot->srna, "scale", 1.0f, 0.0001f, 1000.0f, "Scale", - "Value by which to enlarge or shrink the objects with respect to the world's origin", - 0.0001f, 1000.0f); - - RNA_def_boolean(ot->srna, "set_frame_range", true, - "Set Frame Range", - "If checked, update scene's start and end frame to match those of the Alembic archive"); - - RNA_def_boolean(ot->srna, "validate_meshes", 0, - "Validate Meshes", "Check imported mesh objects for invalid data (slow)"); - - RNA_def_boolean(ot->srna, "is_sequence", false, "Is Sequence", - "Set to true if the cache is split into separate files"); - - RNA_def_boolean(ot->srna, "as_background_job", false, "Run as Background Job", - "Enable this to run the export in the background, disable to block Blender while exporting. " - "This option is deprecated; EXECUTE this operator to run in the foreground, and INVOKE it " - "to run as a background job"); + ot->name = "Import Alembic"; + ot->description = "Load an Alembic archive"; + ot->idname = "WM_OT_alembic_import"; + + ot->invoke = wm_alembic_import_invoke; + ot->exec = wm_alembic_import_exec; + ot->poll = WM_operator_winactive; + ot->ui = wm_alembic_import_draw; + + WM_operator_properties_filesel(ot, + FILE_TYPE_FOLDER | FILE_TYPE_ALEMBIC, + FILE_BLENDER, + FILE_SAVE, + WM_FILESEL_FILEPATH, + FILE_DEFAULTDISPLAY, + FILE_SORT_ALPHA); + + RNA_def_float( + ot->srna, + "scale", + 1.0f, + 0.0001f, + 1000.0f, + "Scale", + "Value by which to enlarge or shrink the objects with respect to the world's origin", + 0.0001f, + 1000.0f); + + RNA_def_boolean( + ot->srna, + "set_frame_range", + true, + "Set Frame Range", + "If checked, update scene's start and end frame to match those of the Alembic archive"); + + RNA_def_boolean(ot->srna, + "validate_meshes", + 0, + "Validate Meshes", + "Check imported mesh objects for invalid data (slow)"); + + RNA_def_boolean(ot->srna, + "is_sequence", + false, + "Is Sequence", + "Set to true if the cache is split into separate files"); + + RNA_def_boolean( + ot->srna, + "as_background_job", + false, + "Run as Background Job", + "Enable this to run the export in the background, disable to block Blender while exporting. " + "This option is deprecated; EXECUTE this operator to run in the foreground, and INVOKE it " + "to run as a background job"); } #endif diff --git a/source/blender/editors/io/io_cache.c b/source/blender/editors/io/io_cache.c index 300382d3071..6358c2c1370 100644 --- a/source/blender/editors/io/io_cache.c +++ b/source/blender/editors/io/io_cache.c @@ -47,119 +47,123 @@ static void cachefile_init(bContext *C, wmOperator *op) { - PropertyPointerRNA *pprop; + PropertyPointerRNA *pprop; - op->customdata = pprop = MEM_callocN(sizeof(PropertyPointerRNA), "OpenPropertyPointerRNA"); - UI_context_active_but_prop_get_templateID(C, &pprop->ptr, &pprop->prop); + op->customdata = pprop = MEM_callocN(sizeof(PropertyPointerRNA), "OpenPropertyPointerRNA"); + UI_context_active_but_prop_get_templateID(C, &pprop->ptr, &pprop->prop); } static int cachefile_open_invoke(bContext *C, wmOperator *op, const wmEvent *event) { - if (!RNA_struct_property_is_set(op->ptr, "filepath")) { - char filepath[FILE_MAX]; - Main *bmain = CTX_data_main(C); + if (!RNA_struct_property_is_set(op->ptr, "filepath")) { + char filepath[FILE_MAX]; + Main *bmain = CTX_data_main(C); - BLI_strncpy(filepath, BKE_main_blendfile_path(bmain), sizeof(filepath)); - BLI_path_extension_replace(filepath, sizeof(filepath), ".abc"); - RNA_string_set(op->ptr, "filepath", filepath); - } + BLI_strncpy(filepath, BKE_main_blendfile_path(bmain), sizeof(filepath)); + BLI_path_extension_replace(filepath, sizeof(filepath), ".abc"); + RNA_string_set(op->ptr, "filepath", filepath); + } - cachefile_init(C, op); + cachefile_init(C, op); - WM_event_add_fileselect(C, op); + WM_event_add_fileselect(C, op); - return OPERATOR_RUNNING_MODAL; + return OPERATOR_RUNNING_MODAL; - UNUSED_VARS(event); + UNUSED_VARS(event); } static void open_cancel(bContext *UNUSED(C), wmOperator *op) { - MEM_freeN(op->customdata); - op->customdata = NULL; + MEM_freeN(op->customdata); + op->customdata = NULL; } static int cachefile_open_exec(bContext *C, wmOperator *op) { - if (!RNA_struct_property_is_set(op->ptr, "filepath")) { - BKE_report(op->reports, RPT_ERROR, "No filename given"); - return OPERATOR_CANCELLED; - } - - char filename[FILE_MAX]; - RNA_string_get(op->ptr, "filepath", filename); - - Main *bmain = CTX_data_main(C); - - CacheFile *cache_file = BKE_libblock_alloc(bmain, ID_CF, BLI_path_basename(filename), 0); - BLI_strncpy(cache_file->filepath, filename, FILE_MAX); - BKE_cachefile_reload(bmain, cache_file); - - /* Will be set when running invoke, not exec directly. */ - if (op->customdata != NULL) { - /* hook into UI */ - PropertyPointerRNA *pprop = op->customdata; - if (pprop->prop) { - /* When creating new ID blocks, use is already 1, but RNA - * pointer see also increases user, so this compensates it. */ - id_us_min(&cache_file->id); - - PointerRNA idptr; - RNA_id_pointer_create(&cache_file->id, &idptr); - RNA_property_pointer_set(&pprop->ptr, pprop->prop, idptr); - RNA_property_update(C, &pprop->ptr, pprop->prop); - } - - MEM_freeN(op->customdata); - } - - return OPERATOR_FINISHED; + if (!RNA_struct_property_is_set(op->ptr, "filepath")) { + BKE_report(op->reports, RPT_ERROR, "No filename given"); + return OPERATOR_CANCELLED; + } + + char filename[FILE_MAX]; + RNA_string_get(op->ptr, "filepath", filename); + + Main *bmain = CTX_data_main(C); + + CacheFile *cache_file = BKE_libblock_alloc(bmain, ID_CF, BLI_path_basename(filename), 0); + BLI_strncpy(cache_file->filepath, filename, FILE_MAX); + BKE_cachefile_reload(bmain, cache_file); + + /* Will be set when running invoke, not exec directly. */ + if (op->customdata != NULL) { + /* hook into UI */ + PropertyPointerRNA *pprop = op->customdata; + if (pprop->prop) { + /* When creating new ID blocks, use is already 1, but RNA + * pointer see also increases user, so this compensates it. */ + id_us_min(&cache_file->id); + + PointerRNA idptr; + RNA_id_pointer_create(&cache_file->id, &idptr); + RNA_property_pointer_set(&pprop->ptr, pprop->prop, idptr); + RNA_property_update(C, &pprop->ptr, pprop->prop); + } + + MEM_freeN(op->customdata); + } + + return OPERATOR_FINISHED; } void CACHEFILE_OT_open(wmOperatorType *ot) { - ot->name = "Open Cache File"; - ot->description = "Load a cache file"; - ot->idname = "CACHEFILE_OT_open"; - - ot->invoke = cachefile_open_invoke; - ot->exec = cachefile_open_exec; - ot->cancel = open_cancel; - - WM_operator_properties_filesel(ot, FILE_TYPE_ALEMBIC | FILE_TYPE_FOLDER, - FILE_BLENDER, FILE_SAVE, WM_FILESEL_FILEPATH, - FILE_DEFAULTDISPLAY, FILE_SORT_ALPHA); + ot->name = "Open Cache File"; + ot->description = "Load a cache file"; + ot->idname = "CACHEFILE_OT_open"; + + ot->invoke = cachefile_open_invoke; + ot->exec = cachefile_open_exec; + ot->cancel = open_cancel; + + WM_operator_properties_filesel(ot, + FILE_TYPE_ALEMBIC | FILE_TYPE_FOLDER, + FILE_BLENDER, + FILE_SAVE, + WM_FILESEL_FILEPATH, + FILE_DEFAULTDISPLAY, + FILE_SORT_ALPHA); } /* ***************************** Reload Operator **************************** */ static int cachefile_reload_exec(bContext *C, wmOperator *op) { - CacheFile *cache_file = CTX_data_edit_cachefile(C); + CacheFile *cache_file = CTX_data_edit_cachefile(C); - if (!cache_file) { - return OPERATOR_CANCELLED; - } + if (!cache_file) { + return OPERATOR_CANCELLED; + } - Main *bmain = CTX_data_main(C); + Main *bmain = CTX_data_main(C); - BLI_freelistN(&cache_file->object_paths); - BKE_cachefile_reload(bmain, cache_file); + BLI_freelistN(&cache_file->object_paths); + BKE_cachefile_reload(bmain, cache_file); - return OPERATOR_FINISHED; + return OPERATOR_FINISHED; - UNUSED_VARS(op); + UNUSED_VARS(op); } void CACHEFILE_OT_reload(wmOperatorType *ot) { - ot->name = "Refresh Archive"; - ot->description = "Update objects paths list with new data from the archive"; - ot->idname = "CACHEFILE_OT_reload"; + ot->name = "Refresh Archive"; + ot->description = "Update objects paths list with new data from the archive"; + ot->idname = "CACHEFILE_OT_reload"; - /* api callbacks */ - ot->exec = cachefile_reload_exec; + /* api callbacks */ + ot->exec = cachefile_reload_exec; - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } diff --git a/source/blender/editors/io/io_collada.c b/source/blender/editors/io/io_collada.c index 3829821ef2e..6ccdf8628a8 100644 --- a/source/blender/editors/io/io_collada.c +++ b/source/blender/editors/io/io_collada.c @@ -21,673 +21,781 @@ * \ingroup collada */ #ifdef WITH_COLLADA -#include "DNA_space_types.h" +# include "DNA_space_types.h" -#include "BLT_translation.h" +# include "BLT_translation.h" -#include "BLI_blenlib.h" -#include "BLI_utildefines.h" +# include "BLI_blenlib.h" +# include "BLI_utildefines.h" -#include "BKE_context.h" -#include "BKE_global.h" -#include "BKE_main.h" -#include "BKE_object.h" -#include "BKE_report.h" +# include "BKE_context.h" +# include "BKE_global.h" +# include "BKE_main.h" +# include "BKE_object.h" +# include "BKE_report.h" -#include "DEG_depsgraph.h" +# include "DEG_depsgraph.h" -#include "ED_screen.h" -#include "ED_object.h" +# include "ED_screen.h" +# include "ED_object.h" -#include "RNA_access.h" -#include "RNA_define.h" +# include "RNA_access.h" +# include "RNA_define.h" -#include "UI_interface.h" -#include "UI_resources.h" +# include "UI_interface.h" +# include "UI_resources.h" -#include "WM_api.h" -#include "WM_types.h" +# include "WM_api.h" +# include "WM_types.h" -#include "../../collada/collada.h" +# include "../../collada/collada.h" -#include "io_collada.h" +# include "io_collada.h" static int wm_collada_export_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) { - Main *bmain = CTX_data_main(C); + Main *bmain = CTX_data_main(C); - if (!RNA_struct_property_is_set(op->ptr, "filepath")) { - char filepath[FILE_MAX]; - const char *blendfile_path = BKE_main_blendfile_path(bmain); + if (!RNA_struct_property_is_set(op->ptr, "filepath")) { + char filepath[FILE_MAX]; + const char *blendfile_path = BKE_main_blendfile_path(bmain); - if (blendfile_path[0] == '\0') - BLI_strncpy(filepath, "untitled", sizeof(filepath)); - else - BLI_strncpy(filepath, blendfile_path, sizeof(filepath)); + if (blendfile_path[0] == '\0') + BLI_strncpy(filepath, "untitled", sizeof(filepath)); + else + BLI_strncpy(filepath, blendfile_path, sizeof(filepath)); - BLI_path_extension_replace(filepath, sizeof(filepath), ".dae"); - RNA_string_set(op->ptr, "filepath", filepath); - } + BLI_path_extension_replace(filepath, sizeof(filepath), ".dae"); + RNA_string_set(op->ptr, "filepath", filepath); + } - WM_event_add_fileselect(C, op); + WM_event_add_fileselect(C, op); - return OPERATOR_RUNNING_MODAL; + 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; - int include_shapekeys; - int deform_bones_only; - - int include_animations; - int include_all_actions; - int sampling_rate; - int keep_smooth_curves; - int keep_keyframes; - int keep_flat_curves; - - int export_animation_type; - int use_texture_copies; - int active_uv_only; - - int triangulate; - int use_object_instantiation; - int use_blender_profile; - int sort_by_name; - int export_transformation_type; - - int open_sim; - int limit_precision; - int keep_bind_info; - - int export_count; - int sample_animations; - - 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_path_extension_ensure(filepath, sizeof(filepath), ".dae"); - - - /* 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 */ - - /* Options panel */ - apply_modifiers = RNA_boolean_get(op->ptr, "apply_modifiers"); - export_mesh_type = RNA_enum_get(op->ptr, "export_mesh_type_selection"); - 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"); - include_shapekeys = RNA_boolean_get(op->ptr, "include_shapekeys"); - - include_animations = RNA_boolean_get(op->ptr, "include_animations"); - include_all_actions = RNA_boolean_get(op->ptr, "include_all_actions"); - export_animation_type = RNA_enum_get(op->ptr, "export_animation_type_selection"); - sample_animations = (export_animation_type == BC_ANIMATION_EXPORT_SAMPLES); - sampling_rate = (sample_animations) ? RNA_int_get(op->ptr, "sampling_rate") : 0; - keep_smooth_curves = RNA_boolean_get(op->ptr, "keep_smooth_curves"); - keep_keyframes = RNA_boolean_get(op->ptr, "keep_keyframes"); - keep_flat_curves = RNA_boolean_get(op->ptr, "keep_flat_curves"); - - deform_bones_only = RNA_boolean_get(op->ptr, "deform_bones_only"); - - use_texture_copies = RNA_boolean_get(op->ptr, "use_texture_copies"); - active_uv_only = RNA_boolean_get(op->ptr, "active_uv_only"); - - triangulate = RNA_boolean_get(op->ptr, "triangulate"); - use_object_instantiation = RNA_boolean_get(op->ptr, "use_object_instantiation"); - use_blender_profile = RNA_boolean_get(op->ptr, "use_blender_profile"); - sort_by_name = RNA_boolean_get(op->ptr, "sort_by_name"); - export_transformation_type = RNA_enum_get(op->ptr, "export_transformation_type_selection"); - open_sim = RNA_boolean_get(op->ptr, "open_sim"); - - limit_precision = RNA_boolean_get(op->ptr, "limit_precision"); - keep_bind_info = RNA_boolean_get(op->ptr, "keep_bind_info"); - - Main *bmain = CTX_data_main(C); - - /* get editmode results */ - ED_object_editmode_load(bmain, CTX_data_edit_object(C)); - - //Scene *scene = CTX_data_scene(C); - - 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 != 0; - export_settings.include_all_actions = include_all_actions != 0; - export_settings.sampling_rate = sampling_rate; - export_settings.keep_keyframes = keep_keyframes != 0 || sampling_rate < 1; - export_settings.keep_flat_curves = keep_flat_curves != 0; - - export_settings.active_uv_only = active_uv_only != 0; - export_settings.export_animation_type = export_animation_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; - - if (export_animation_type == BC_ANIMATION_EXPORT_SAMPLES) { - export_settings.export_transformation_type = export_transformation_type; - } - else { - // When curves are exported then we can not export as matrix - export_settings.export_transformation_type = BC_TRANSFORMATION_TYPE_TRANSROTLOC; - } - - if (export_settings.export_transformation_type == BC_TRANSFORMATION_TYPE_TRANSROTLOC) { - export_settings.keep_smooth_curves = keep_smooth_curves != 0; - } - else { - // Can not export smooth curves when Matrix export is enabled. - export_settings.keep_smooth_curves = false; - } - - 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; - - export_count = collada_export( - C, - &export_settings - ); - - if (export_count == 0) { - BKE_report(op->reports, RPT_WARNING, "No objects selected -- Created empty export file"); - return OPERATOR_CANCELLED; - } - else if (export_count < 0) { - BKE_report(op->reports, RPT_WARNING, "Error during export (see Console)"); - return OPERATOR_CANCELLED; - } - else { - char buff[100]; - sprintf(buff, "Exported %d Objects", export_count); - BKE_report(op->reports, RPT_INFO, buff); - return OPERATOR_FINISHED; - } + char filepath[FILE_MAX]; + int apply_modifiers; + int export_mesh_type; + int selected; + int include_children; + int include_armatures; + int include_shapekeys; + int deform_bones_only; + + int include_animations; + int include_all_actions; + int sampling_rate; + int keep_smooth_curves; + int keep_keyframes; + int keep_flat_curves; + + int export_animation_type; + int use_texture_copies; + int active_uv_only; + + int triangulate; + int use_object_instantiation; + int use_blender_profile; + int sort_by_name; + int export_transformation_type; + + int open_sim; + int limit_precision; + int keep_bind_info; + + int export_count; + int sample_animations; + + 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_path_extension_ensure(filepath, sizeof(filepath), ".dae"); + + /* 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 */ + + /* Options panel */ + apply_modifiers = RNA_boolean_get(op->ptr, "apply_modifiers"); + export_mesh_type = RNA_enum_get(op->ptr, "export_mesh_type_selection"); + 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"); + include_shapekeys = RNA_boolean_get(op->ptr, "include_shapekeys"); + + include_animations = RNA_boolean_get(op->ptr, "include_animations"); + include_all_actions = RNA_boolean_get(op->ptr, "include_all_actions"); + export_animation_type = RNA_enum_get(op->ptr, "export_animation_type_selection"); + sample_animations = (export_animation_type == BC_ANIMATION_EXPORT_SAMPLES); + sampling_rate = (sample_animations) ? RNA_int_get(op->ptr, "sampling_rate") : 0; + keep_smooth_curves = RNA_boolean_get(op->ptr, "keep_smooth_curves"); + keep_keyframes = RNA_boolean_get(op->ptr, "keep_keyframes"); + keep_flat_curves = RNA_boolean_get(op->ptr, "keep_flat_curves"); + + deform_bones_only = RNA_boolean_get(op->ptr, "deform_bones_only"); + + use_texture_copies = RNA_boolean_get(op->ptr, "use_texture_copies"); + active_uv_only = RNA_boolean_get(op->ptr, "active_uv_only"); + + triangulate = RNA_boolean_get(op->ptr, "triangulate"); + use_object_instantiation = RNA_boolean_get(op->ptr, "use_object_instantiation"); + use_blender_profile = RNA_boolean_get(op->ptr, "use_blender_profile"); + sort_by_name = RNA_boolean_get(op->ptr, "sort_by_name"); + export_transformation_type = RNA_enum_get(op->ptr, "export_transformation_type_selection"); + open_sim = RNA_boolean_get(op->ptr, "open_sim"); + + limit_precision = RNA_boolean_get(op->ptr, "limit_precision"); + keep_bind_info = RNA_boolean_get(op->ptr, "keep_bind_info"); + + Main *bmain = CTX_data_main(C); + + /* get editmode results */ + ED_object_editmode_load(bmain, CTX_data_edit_object(C)); + + //Scene *scene = CTX_data_scene(C); + + 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 != 0; + export_settings.include_all_actions = include_all_actions != 0; + export_settings.sampling_rate = sampling_rate; + export_settings.keep_keyframes = keep_keyframes != 0 || sampling_rate < 1; + export_settings.keep_flat_curves = keep_flat_curves != 0; + + export_settings.active_uv_only = active_uv_only != 0; + export_settings.export_animation_type = export_animation_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; + + if (export_animation_type == BC_ANIMATION_EXPORT_SAMPLES) { + export_settings.export_transformation_type = export_transformation_type; + } + else { + // When curves are exported then we can not export as matrix + export_settings.export_transformation_type = BC_TRANSFORMATION_TYPE_TRANSROTLOC; + } + + if (export_settings.export_transformation_type == BC_TRANSFORMATION_TYPE_TRANSROTLOC) { + export_settings.keep_smooth_curves = keep_smooth_curves != 0; + } + else { + // Can not export smooth curves when Matrix export is enabled. + export_settings.keep_smooth_curves = false; + } + + 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; + + export_count = collada_export(C, &export_settings); + + if (export_count == 0) { + BKE_report(op->reports, RPT_WARNING, "No objects selected -- Created empty export file"); + return OPERATOR_CANCELLED; + } + else if (export_count < 0) { + BKE_report(op->reports, RPT_WARNING, "Error during export (see Console)"); + return OPERATOR_CANCELLED; + } + else { + char buff[100]; + sprintf(buff, "Exported %d Objects", export_count); + BKE_report(op->reports, RPT_INFO, buff); + return OPERATOR_FINISHED; + } } static void uiCollada_exportSettings(uiLayout *layout, PointerRNA *imfptr) { - uiLayout *box, *row, *col, *split; - bool include_animations = RNA_boolean_get(imfptr, "include_animations"); - int ui_section = RNA_enum_get(imfptr, "prop_bc_export_ui_section"); - - BC_export_animation_type animation_type = RNA_enum_get(imfptr, "export_animation_type_selection"); - BC_export_transformation_type transformation_type = RNA_enum_get(imfptr, "export_transformation_type_selection"); - - bool sampling = animation_type == BC_ANIMATION_EXPORT_SAMPLES; - - /* Export Options: */ - box = uiLayoutBox(layout); - - row = uiLayoutRow(box, false); - uiItemR(row, imfptr, "prop_bc_export_ui_section", UI_ITEM_R_EXPAND, NULL, ICON_NONE); - - if (ui_section == BC_UI_SECTION_MAIN) { - /* =================== */ - /* Export Data options */ - /* =================== */ - - row = uiLayoutRow(box, false); - uiItemR(row, imfptr, "selected", 0, NULL, ICON_NONE); - - row = uiLayoutRow(box, false); - uiItemR(row, imfptr, "include_children", 0, NULL, ICON_NONE); - uiLayoutSetEnabled(row, RNA_boolean_get(imfptr, "selected")); - - row = uiLayoutRow(box, false); - uiItemR(row, imfptr, "include_armatures", 0, NULL, ICON_NONE); - uiLayoutSetEnabled(row, RNA_boolean_get(imfptr, "selected")); - - row = uiLayoutRow(box, false); - uiItemR(row, imfptr, "include_shapekeys", 0, NULL, ICON_NONE); - uiLayoutSetEnabled(row, RNA_boolean_get(imfptr, "selected")); - - /* Texture options */ - box = uiLayoutBox(layout); - row = uiLayoutRow(box, false); - uiItemL(row, IFACE_("Texture Options:"), ICON_TEXTURE_DATA); - - row = uiLayoutRow(box, false); - uiItemR(row, imfptr, "active_uv_only", 0, NULL, ICON_NONE); - - row = uiLayoutRow(box, false); - uiItemR(row, imfptr, "use_texture_copies", 1, NULL, ICON_NONE); - - } - else if (ui_section == BC_UI_SECTION_GEOMETRY) { - row = uiLayoutRow(box, false); - uiItemL(row, IFACE_("Export Data Options:"), ICON_MESH_DATA); - - row = uiLayoutRow(box, false); - split = uiLayoutSplit(row, 0.6f, UI_LAYOUT_ALIGN_RIGHT); - col = uiLayoutColumn(split, false); - uiItemR(col, imfptr, "apply_modifiers", 0, NULL, ICON_NONE); - col = uiLayoutColumn(split, false); - uiItemR(col, imfptr, "export_mesh_type_selection", 0, "", ICON_NONE); - uiLayoutSetEnabled(col, RNA_boolean_get(imfptr, "apply_modifiers")); - row = uiLayoutRow(box, false); - uiItemR(row, imfptr, "triangulate", 1, NULL, ICON_NONE); - } - else if (ui_section == BC_UI_SECTION_ARMATURE) { - /* Armature options */ - box = uiLayoutBox(layout); - row = uiLayoutRow(box, false); - uiItemL(row, IFACE_("Armature Options:"), ICON_ARMATURE_DATA); - - row = uiLayoutRow(box, false); - uiItemR(row, imfptr, "deform_bones_only", 0, NULL, ICON_NONE); - - row = uiLayoutRow(box, false); - uiItemR(row, imfptr, "open_sim", 0, NULL, ICON_NONE); - } - else if (ui_section == BC_UI_SECTION_ANIMATION) { - - /* ====================== */ - /* Animation Data options */ - /* ====================== */ - - row = uiLayoutRow(box, false); - uiItemR(row, imfptr, "include_animations", 0, NULL, ICON_NONE); - - - row = uiLayoutRow(box, false); - uiItemR(row, imfptr, "export_animation_type_selection", UI_ITEM_R_EXPAND, NULL, ICON_NONE); - - row = uiLayoutRow(box, false); - split = uiLayoutSplit(row, 0.6f, UI_LAYOUT_ALIGN_RIGHT); - uiItemL(split, IFACE_("Transformation Type"), ICON_NONE); - uiItemR(split, imfptr, "export_transformation_type_selection", 0, "", ICON_NONE); - uiLayoutSetEnabled(row, animation_type == BC_ANIMATION_EXPORT_SAMPLES); - - row = uiLayoutColumn(box, false); - uiItemR(row, imfptr, "keep_smooth_curves", 0, NULL, ICON_NONE); - uiLayoutSetEnabled(row, include_animations && - (transformation_type == BC_TRANSFORMATION_TYPE_TRANSROTLOC || animation_type == BC_ANIMATION_EXPORT_KEYS)); - - row = uiLayoutColumn(box, false); - uiItemR(row, imfptr, "sampling_rate", 0, NULL, ICON_NONE); - uiLayoutSetEnabled(row, sampling && include_animations); - - row = uiLayoutColumn(box, false); - uiItemR(row, imfptr, "keep_keyframes", 0, NULL, ICON_NONE); - uiLayoutSetEnabled(row, sampling && include_animations); - - row = uiLayoutColumn(box, false); - uiItemR(row, imfptr, "keep_flat_curves", 0, NULL, ICON_NONE); - - row = uiLayoutRow(box, false); - uiItemR(row, imfptr, "include_all_actions", 0, NULL, ICON_NONE); - uiLayoutSetEnabled(row, include_animations); - - } - else if (ui_section == BC_UI_SECTION_COLLADA) { - /* Collada options: */ - box = uiLayoutBox(layout); - row = uiLayoutRow(box, false); - uiItemL(row, IFACE_("Collada Options:"), ICON_MODIFIER); - - row = uiLayoutRow(box, false); - uiItemR(row, imfptr, "use_object_instantiation", 1, NULL, ICON_NONE); - row = uiLayoutRow(box, false); - uiItemR(row, imfptr, "use_blender_profile", 1, NULL, ICON_NONE); - - row = uiLayoutRow(box, false); - uiItemR(row, imfptr, "sort_by_name", 0, NULL, ICON_NONE); - - row = uiLayoutRow(box, false); - uiItemR(row, imfptr, "keep_bind_info", 0, NULL, ICON_NONE); - - row = uiLayoutRow(box, false); - uiItemR(row, imfptr, "limit_precision", 0, NULL, ICON_NONE); - } + uiLayout *box, *row, *col, *split; + bool include_animations = RNA_boolean_get(imfptr, "include_animations"); + int ui_section = RNA_enum_get(imfptr, "prop_bc_export_ui_section"); + + BC_export_animation_type animation_type = RNA_enum_get(imfptr, + "export_animation_type_selection"); + BC_export_transformation_type transformation_type = RNA_enum_get( + imfptr, "export_transformation_type_selection"); + + bool sampling = animation_type == BC_ANIMATION_EXPORT_SAMPLES; + + /* Export Options: */ + box = uiLayoutBox(layout); + + row = uiLayoutRow(box, false); + uiItemR(row, imfptr, "prop_bc_export_ui_section", UI_ITEM_R_EXPAND, NULL, ICON_NONE); + + if (ui_section == BC_UI_SECTION_MAIN) { + /* =================== */ + /* Export Data options */ + /* =================== */ + + row = uiLayoutRow(box, false); + uiItemR(row, imfptr, "selected", 0, NULL, ICON_NONE); + + row = uiLayoutRow(box, false); + uiItemR(row, imfptr, "include_children", 0, NULL, ICON_NONE); + uiLayoutSetEnabled(row, RNA_boolean_get(imfptr, "selected")); + + row = uiLayoutRow(box, false); + uiItemR(row, imfptr, "include_armatures", 0, NULL, ICON_NONE); + uiLayoutSetEnabled(row, RNA_boolean_get(imfptr, "selected")); + + row = uiLayoutRow(box, false); + uiItemR(row, imfptr, "include_shapekeys", 0, NULL, ICON_NONE); + uiLayoutSetEnabled(row, RNA_boolean_get(imfptr, "selected")); + + /* Texture options */ + box = uiLayoutBox(layout); + row = uiLayoutRow(box, false); + uiItemL(row, IFACE_("Texture Options:"), ICON_TEXTURE_DATA); + + row = uiLayoutRow(box, false); + uiItemR(row, imfptr, "active_uv_only", 0, NULL, ICON_NONE); + + row = uiLayoutRow(box, false); + uiItemR(row, imfptr, "use_texture_copies", 1, NULL, ICON_NONE); + } + else if (ui_section == BC_UI_SECTION_GEOMETRY) { + row = uiLayoutRow(box, false); + uiItemL(row, IFACE_("Export Data Options:"), ICON_MESH_DATA); + + row = uiLayoutRow(box, false); + split = uiLayoutSplit(row, 0.6f, UI_LAYOUT_ALIGN_RIGHT); + col = uiLayoutColumn(split, false); + uiItemR(col, imfptr, "apply_modifiers", 0, NULL, ICON_NONE); + col = uiLayoutColumn(split, false); + uiItemR(col, imfptr, "export_mesh_type_selection", 0, "", ICON_NONE); + uiLayoutSetEnabled(col, RNA_boolean_get(imfptr, "apply_modifiers")); + row = uiLayoutRow(box, false); + uiItemR(row, imfptr, "triangulate", 1, NULL, ICON_NONE); + } + else if (ui_section == BC_UI_SECTION_ARMATURE) { + /* Armature options */ + box = uiLayoutBox(layout); + row = uiLayoutRow(box, false); + uiItemL(row, IFACE_("Armature Options:"), ICON_ARMATURE_DATA); + + row = uiLayoutRow(box, false); + uiItemR(row, imfptr, "deform_bones_only", 0, NULL, ICON_NONE); + + row = uiLayoutRow(box, false); + uiItemR(row, imfptr, "open_sim", 0, NULL, ICON_NONE); + } + else if (ui_section == BC_UI_SECTION_ANIMATION) { + + /* ====================== */ + /* Animation Data options */ + /* ====================== */ + + row = uiLayoutRow(box, false); + uiItemR(row, imfptr, "include_animations", 0, NULL, ICON_NONE); + + row = uiLayoutRow(box, false); + uiItemR(row, imfptr, "export_animation_type_selection", UI_ITEM_R_EXPAND, NULL, ICON_NONE); + + row = uiLayoutRow(box, false); + split = uiLayoutSplit(row, 0.6f, UI_LAYOUT_ALIGN_RIGHT); + uiItemL(split, IFACE_("Transformation Type"), ICON_NONE); + uiItemR(split, imfptr, "export_transformation_type_selection", 0, "", ICON_NONE); + uiLayoutSetEnabled(row, animation_type == BC_ANIMATION_EXPORT_SAMPLES); + + row = uiLayoutColumn(box, false); + uiItemR(row, imfptr, "keep_smooth_curves", 0, NULL, ICON_NONE); + uiLayoutSetEnabled(row, + include_animations && + (transformation_type == BC_TRANSFORMATION_TYPE_TRANSROTLOC || + animation_type == BC_ANIMATION_EXPORT_KEYS)); + + row = uiLayoutColumn(box, false); + uiItemR(row, imfptr, "sampling_rate", 0, NULL, ICON_NONE); + uiLayoutSetEnabled(row, sampling && include_animations); + + row = uiLayoutColumn(box, false); + uiItemR(row, imfptr, "keep_keyframes", 0, NULL, ICON_NONE); + uiLayoutSetEnabled(row, sampling && include_animations); + + row = uiLayoutColumn(box, false); + uiItemR(row, imfptr, "keep_flat_curves", 0, NULL, ICON_NONE); + + row = uiLayoutRow(box, false); + uiItemR(row, imfptr, "include_all_actions", 0, NULL, ICON_NONE); + uiLayoutSetEnabled(row, include_animations); + } + else if (ui_section == BC_UI_SECTION_COLLADA) { + /* Collada options: */ + box = uiLayoutBox(layout); + row = uiLayoutRow(box, false); + uiItemL(row, IFACE_("Collada Options:"), ICON_MODIFIER); + + row = uiLayoutRow(box, false); + uiItemR(row, imfptr, "use_object_instantiation", 1, NULL, ICON_NONE); + row = uiLayoutRow(box, false); + uiItemR(row, imfptr, "use_blender_profile", 1, NULL, ICON_NONE); + + row = uiLayoutRow(box, false); + uiItemR(row, imfptr, "sort_by_name", 0, NULL, ICON_NONE); + + row = uiLayoutRow(box, false); + uiItemR(row, imfptr, "keep_bind_info", 0, NULL, ICON_NONE); + + row = uiLayoutRow(box, false); + uiItemR(row, imfptr, "limit_precision", 0, NULL, ICON_NONE); + } } static void wm_collada_export_draw(bContext *UNUSED(C), wmOperator *op) { - PointerRNA ptr; + PointerRNA ptr; - RNA_pointer_create(NULL, op->type->srna, op->properties, &ptr); - uiCollada_exportSettings(op->layout, &ptr); + RNA_pointer_create(NULL, op->type->srna, op->properties, &ptr); + uiCollada_exportSettings(op->layout, &ptr); } static bool wm_collada_export_check(bContext *UNUSED(C), wmOperator *op) { - char filepath[FILE_MAX]; - RNA_string_get(op->ptr, "filepath", filepath); + char filepath[FILE_MAX]; + RNA_string_get(op->ptr, "filepath", filepath); - if (!BLI_path_extension_check(filepath, ".dae")) { - BLI_path_extension_ensure(filepath, FILE_MAX, ".dae"); - RNA_string_set(op->ptr, "filepath", filepath); - return true; - } + if (!BLI_path_extension_check(filepath, ".dae")) { + BLI_path_extension_ensure(filepath, FILE_MAX, ".dae"); + RNA_string_set(op->ptr, "filepath", filepath); + return true; + } - return false; + return false; } void WM_OT_collada_export(wmOperatorType *ot) { - struct StructRNA *func = ot->srna; - - static const EnumPropertyItem prop_bc_export_mesh_type[] = { - {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}, - }; - - static const EnumPropertyItem prop_bc_export_transformation_type[] = { - { 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 } - }; - - static const EnumPropertyItem prop_bc_export_animation_type[] = { - { BC_ANIMATION_EXPORT_SAMPLES, "sample", 0, "Samples", "Export Sampled points guided by sampling rate" }, - { BC_ANIMATION_EXPORT_KEYS, "keys", 0, "Curves", "Export Curves (note: guided by curve keys)" }, - { 0, NULL, 0, NULL, NULL } - }; - - static const EnumPropertyItem prop_bc_export_ui_section[] = { - { BC_UI_SECTION_MAIN, "main", 0, "Main", "Data Export Section" }, - { BC_UI_SECTION_GEOMETRY, "geometry", 0, "Geom", "Geometry Export Section" }, - { BC_UI_SECTION_ARMATURE, "armature", 0, "Arm", "Armature Export Section" }, - { BC_UI_SECTION_ANIMATION, "animation", 0, "Anim", "Animation Export Section" }, - { BC_UI_SECTION_COLLADA, "collada", 0, "Extra", "Collada Export Section" }, - { 0, NULL, 0, NULL, NULL } - }; - - - ot->name = "Export COLLADA"; - ot->description = "Save a Collada file"; - ot->idname = "WM_OT_collada_export"; - - ot->invoke = wm_collada_export_invoke; - ot->exec = wm_collada_export_exec; - ot->poll = WM_operator_winactive; - ot->check = wm_collada_export_check; - - ot->flag |= OPTYPE_PRESET; - - ot->ui = wm_collada_export_draw; - - WM_operator_properties_filesel( - ot, FILE_TYPE_FOLDER | FILE_TYPE_COLLADA, FILE_BLENDER, FILE_SAVE, - WM_FILESEL_FILEPATH, FILE_DEFAULTDISPLAY, FILE_SORT_ALPHA); - - RNA_def_enum(func, "prop_bc_export_ui_section", prop_bc_export_ui_section, 0, - "Export Section", "Only for User Interface organization"); - - RNA_def_boolean(func, "apply_modifiers", 0, "Apply Modifiers", - "Apply modifiers to exported mesh (non destructive))"); - - RNA_def_int(func, "export_mesh_type", 0, INT_MIN, INT_MAX, - "Resolution", "Modifier resolution for export", INT_MIN, INT_MAX); - - RNA_def_enum(func, "export_mesh_type_selection", prop_bc_export_mesh_type, 0, - "Resolution", "Modifier resolution for export"); - - RNA_def_boolean(func, "selected", false, "Selection Only", - "Export only selected elements"); - - RNA_def_boolean(func, "include_children", false, "Include Children", - "Export all children of selected objects (even if not selected)"); - - RNA_def_boolean(func, "include_armatures", false, "Include Armatures", - "Export related armatures (even if not selected)"); - - RNA_def_boolean(func, "include_shapekeys", false, "Include Shape Keys", - "Export all Shape Keys from Mesh Objects"); - - RNA_def_boolean(func, "deform_bones_only", false, "Deform Bones only", - "Only export deforming bones with armatures"); - - - - RNA_def_boolean(func, "include_animations", true, "Include Animations", - "Export animations if available (exporting animations will enforce the decomposition of " - "node transforms into <translation> <rotation> and <scale> components)"); - - RNA_def_boolean(func, "include_all_actions", true, "Include all Actions", - "Export also unassigned actions (this allows you to export entire animation libraries for your character(s))"); - - RNA_def_enum(func, "export_animation_type_selection", prop_bc_export_animation_type, 0, "Key Type", - "Type for exported animations (use sample keys or Curve keys)"); - - RNA_def_int(func, "sampling_rate", 1, 1, INT_MAX, "Sampling Rate", - "The distance between 2 keyframes (1 to key every frame)", 1, INT_MAX); - - RNA_def_boolean(func, "keep_smooth_curves", 0, "Keep Smooth curves", - "Export also the curve handles (if available) (this does only work when the inverse parent matrix " - "is the unity matrix, otherwise you may end up with odd results)"); - - RNA_def_boolean( - func, "keep_keyframes", 0, "Keep Keyframes", - "Use existing keyframes as additional sample points (this helps when you want to keep manual tweaks)"); - - RNA_def_boolean( - func, "keep_flat_curves", 0, "All keyed curves", - "Export also curves which have only one key or are totally flat"); - - RNA_def_boolean(func, "active_uv_only", 0, "Only Selected UV Map", - "Export only the selected UV Map"); - - RNA_def_boolean(func, "use_texture_copies", 1, "Copy", - "Copy textures to same folder where the .dae file is exported"); - - - RNA_def_boolean(func, "triangulate", 1, "Triangulate", - "Export Polygons (Quads & NGons) as Triangles"); - - RNA_def_boolean(func, "use_object_instantiation", 1, "Use Object Instances", - "Instantiate multiple Objects from same Data"); - - RNA_def_boolean(func, "use_blender_profile", 1, "Use Blender Profile", - "Export additional Blender specific information (for material, shaders, bones, etc.)"); - - RNA_def_boolean(func, "sort_by_name", 0, "Sort by Object name", - "Sort exported data by Object name"); - - RNA_def_int(func, "export_transformation_type", 0, INT_MIN, INT_MAX, "Transform", - "Transformation type for translation, scale and rotation", INT_MIN, INT_MAX); - - RNA_def_enum(func, "export_transformation_type_selection", prop_bc_export_transformation_type, 0, "Transform", - "Transformation type for translation, scale and rotation"); - - RNA_def_boolean(func, "open_sim", 0, "Export to SL/OpenSim", - "Compatibility mode for SL, OpenSim and other compatible online worlds"); - - RNA_def_boolean(func, "limit_precision", 0, "Limit Precision", - "Reduce the precision of the exported data to 6 digits"); - - RNA_def_boolean(func, "keep_bind_info", 0, "Keep Bind Info", - "Store Bindpose information in custom bone properties for later use during Collada export"); + struct StructRNA *func = ot->srna; + + static const EnumPropertyItem prop_bc_export_mesh_type[] = { + {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}, + }; + + static const EnumPropertyItem prop_bc_export_transformation_type[] = { + {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}}; + + static const EnumPropertyItem prop_bc_export_animation_type[] = { + {BC_ANIMATION_EXPORT_SAMPLES, + "sample", + 0, + "Samples", + "Export Sampled points guided by sampling rate"}, + {BC_ANIMATION_EXPORT_KEYS, + "keys", + 0, + "Curves", + "Export Curves (note: guided by curve keys)"}, + {0, NULL, 0, NULL, NULL}}; + + static const EnumPropertyItem prop_bc_export_ui_section[] = { + {BC_UI_SECTION_MAIN, "main", 0, "Main", "Data Export Section"}, + {BC_UI_SECTION_GEOMETRY, "geometry", 0, "Geom", "Geometry Export Section"}, + {BC_UI_SECTION_ARMATURE, "armature", 0, "Arm", "Armature Export Section"}, + {BC_UI_SECTION_ANIMATION, "animation", 0, "Anim", "Animation Export Section"}, + {BC_UI_SECTION_COLLADA, "collada", 0, "Extra", "Collada Export Section"}, + {0, NULL, 0, NULL, NULL}}; + + ot->name = "Export COLLADA"; + ot->description = "Save a Collada file"; + ot->idname = "WM_OT_collada_export"; + + ot->invoke = wm_collada_export_invoke; + ot->exec = wm_collada_export_exec; + ot->poll = WM_operator_winactive; + ot->check = wm_collada_export_check; + + ot->flag |= OPTYPE_PRESET; + + ot->ui = wm_collada_export_draw; + + WM_operator_properties_filesel(ot, + FILE_TYPE_FOLDER | FILE_TYPE_COLLADA, + FILE_BLENDER, + FILE_SAVE, + WM_FILESEL_FILEPATH, + FILE_DEFAULTDISPLAY, + FILE_SORT_ALPHA); + + RNA_def_enum(func, + "prop_bc_export_ui_section", + prop_bc_export_ui_section, + 0, + "Export Section", + "Only for User Interface organization"); + + RNA_def_boolean(func, + "apply_modifiers", + 0, + "Apply Modifiers", + "Apply modifiers to exported mesh (non destructive))"); + + RNA_def_int(func, + "export_mesh_type", + 0, + INT_MIN, + INT_MAX, + "Resolution", + "Modifier resolution for export", + INT_MIN, + INT_MAX); + + RNA_def_enum(func, + "export_mesh_type_selection", + prop_bc_export_mesh_type, + 0, + "Resolution", + "Modifier resolution for export"); + + RNA_def_boolean(func, "selected", false, "Selection Only", "Export only selected elements"); + + RNA_def_boolean(func, + "include_children", + false, + "Include Children", + "Export all children of selected objects (even if not selected)"); + + RNA_def_boolean(func, + "include_armatures", + false, + "Include Armatures", + "Export related armatures (even if not selected)"); + + RNA_def_boolean(func, + "include_shapekeys", + false, + "Include Shape Keys", + "Export all Shape Keys from Mesh Objects"); + + RNA_def_boolean(func, + "deform_bones_only", + false, + "Deform Bones only", + "Only export deforming bones with armatures"); + + RNA_def_boolean( + func, + "include_animations", + true, + "Include Animations", + "Export animations if available (exporting animations will enforce the decomposition of " + "node transforms into <translation> <rotation> and <scale> components)"); + + RNA_def_boolean(func, + "include_all_actions", + true, + "Include all Actions", + "Export also unassigned actions (this allows you to export entire animation " + "libraries for your character(s))"); + + RNA_def_enum(func, + "export_animation_type_selection", + prop_bc_export_animation_type, + 0, + "Key Type", + "Type for exported animations (use sample keys or Curve keys)"); + + RNA_def_int(func, + "sampling_rate", + 1, + 1, + INT_MAX, + "Sampling Rate", + "The distance between 2 keyframes (1 to key every frame)", + 1, + INT_MAX); + + RNA_def_boolean(func, + "keep_smooth_curves", + 0, + "Keep Smooth curves", + "Export also the curve handles (if available) (this does only work when the " + "inverse parent matrix " + "is the unity matrix, otherwise you may end up with odd results)"); + + RNA_def_boolean(func, + "keep_keyframes", + 0, + "Keep Keyframes", + "Use existing keyframes as additional sample points (this helps when you want " + "to keep manual tweaks)"); + + RNA_def_boolean(func, + "keep_flat_curves", + 0, + "All keyed curves", + "Export also curves which have only one key or are totally flat"); + + RNA_def_boolean( + func, "active_uv_only", 0, "Only Selected UV Map", "Export only the selected UV Map"); + + RNA_def_boolean(func, + "use_texture_copies", + 1, + "Copy", + "Copy textures to same folder where the .dae file is exported"); + + RNA_def_boolean( + func, "triangulate", 1, "Triangulate", "Export Polygons (Quads & NGons) as Triangles"); + + RNA_def_boolean(func, + "use_object_instantiation", + 1, + "Use Object Instances", + "Instantiate multiple Objects from same Data"); + + RNA_def_boolean( + func, + "use_blender_profile", + 1, + "Use Blender Profile", + "Export additional Blender specific information (for material, shaders, bones, etc.)"); + + RNA_def_boolean( + func, "sort_by_name", 0, "Sort by Object name", "Sort exported data by Object name"); + + RNA_def_int(func, + "export_transformation_type", + 0, + INT_MIN, + INT_MAX, + "Transform", + "Transformation type for translation, scale and rotation", + INT_MIN, + INT_MAX); + + RNA_def_enum(func, + "export_transformation_type_selection", + prop_bc_export_transformation_type, + 0, + "Transform", + "Transformation type for translation, scale and rotation"); + + RNA_def_boolean(func, + "open_sim", + 0, + "Export to SL/OpenSim", + "Compatibility mode for SL, OpenSim and other compatible online worlds"); + + RNA_def_boolean(func, + "limit_precision", + 0, + "Limit Precision", + "Reduce the precision of the exported data to 6 digits"); + + RNA_def_boolean( + func, + "keep_bind_info", + 0, + "Keep Bind Info", + "Store Bindpose information in custom bone properties for later use during Collada export"); } - /* function used for WM_OT_save_mainfile too */ static int wm_collada_import_exec(bContext *C, wmOperator *op) { - char filename[FILE_MAX]; - int import_units; - int find_chains; - int auto_connect; - int fix_orientation; - int min_chain_length; - - int keep_bind_info; - ImportSettings import_settings; - - if (!RNA_struct_property_is_set(op->ptr, "filepath")) { - BKE_report(op->reports, RPT_ERROR, "No filename given"); - return OPERATOR_CANCELLED; - } - - /* Options panel */ - import_units = RNA_boolean_get(op->ptr, "import_units"); - find_chains = RNA_boolean_get(op->ptr, "find_chains"); - auto_connect = RNA_boolean_get(op->ptr, "auto_connect"); - fix_orientation = RNA_boolean_get(op->ptr, "fix_orientation"); - - keep_bind_info = RNA_boolean_get(op->ptr, "keep_bind_info"); - - min_chain_length = RNA_int_get(op->ptr, "min_chain_length"); - - RNA_string_get(op->ptr, "filepath", filename); - - 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; - - if (collada_import(C, &import_settings)) { - DEG_id_tag_update(&CTX_data_scene(C)->id, ID_RECALC_BASE_FLAGS); - return OPERATOR_FINISHED; - } - else { - BKE_report(op->reports, RPT_ERROR, "Parsing errors in Document (see Blender Console)"); - return OPERATOR_CANCELLED; - } + char filename[FILE_MAX]; + int import_units; + int find_chains; + int auto_connect; + int fix_orientation; + int min_chain_length; + + int keep_bind_info; + ImportSettings import_settings; + + if (!RNA_struct_property_is_set(op->ptr, "filepath")) { + BKE_report(op->reports, RPT_ERROR, "No filename given"); + return OPERATOR_CANCELLED; + } + + /* Options panel */ + import_units = RNA_boolean_get(op->ptr, "import_units"); + find_chains = RNA_boolean_get(op->ptr, "find_chains"); + auto_connect = RNA_boolean_get(op->ptr, "auto_connect"); + fix_orientation = RNA_boolean_get(op->ptr, "fix_orientation"); + + keep_bind_info = RNA_boolean_get(op->ptr, "keep_bind_info"); + + min_chain_length = RNA_int_get(op->ptr, "min_chain_length"); + + RNA_string_get(op->ptr, "filepath", filename); + + 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; + + if (collada_import(C, &import_settings)) { + DEG_id_tag_update(&CTX_data_scene(C)->id, ID_RECALC_BASE_FLAGS); + return OPERATOR_FINISHED; + } + else { + BKE_report(op->reports, RPT_ERROR, "Parsing errors in Document (see Blender Console)"); + return OPERATOR_CANCELLED; + } } static void uiCollada_importSettings(uiLayout *layout, PointerRNA *imfptr) { - uiLayout *box, *row; + uiLayout *box, *row; - /* Import Options: */ - box = uiLayoutBox(layout); - row = uiLayoutRow(box, false); - uiItemL(row, IFACE_("Import Data Options:"), ICON_MESH_DATA); + /* Import Options: */ + box = uiLayoutBox(layout); + row = uiLayoutRow(box, false); + uiItemL(row, IFACE_("Import Data Options:"), ICON_MESH_DATA); - row = uiLayoutRow(box, false); - uiItemR(row, imfptr, "import_units", 0, NULL, ICON_NONE); + row = uiLayoutRow(box, false); + uiItemR(row, imfptr, "import_units", 0, NULL, ICON_NONE); - box = uiLayoutBox(layout); - row = uiLayoutRow(box, false); - uiItemL(row, IFACE_("Armature Options:"), ICON_MESH_DATA); + box = uiLayoutBox(layout); + row = uiLayoutRow(box, false); + uiItemL(row, IFACE_("Armature Options:"), ICON_MESH_DATA); - row = uiLayoutRow(box, false); - uiItemR(row, imfptr, "fix_orientation", 0, NULL, ICON_NONE); + row = uiLayoutRow(box, false); + uiItemR(row, imfptr, "fix_orientation", 0, NULL, ICON_NONE); - row = uiLayoutRow(box, false); - uiItemR(row, imfptr, "find_chains", 0, NULL, ICON_NONE); + row = uiLayoutRow(box, false); + uiItemR(row, imfptr, "find_chains", 0, NULL, ICON_NONE); - row = uiLayoutRow(box, false); - uiItemR(row, imfptr, "auto_connect", 0, NULL, ICON_NONE); + row = uiLayoutRow(box, false); + uiItemR(row, imfptr, "auto_connect", 0, NULL, ICON_NONE); - row = uiLayoutRow(box, false); - uiItemR(row, imfptr, "min_chain_length", 0, NULL, ICON_NONE); + row = uiLayoutRow(box, false); + uiItemR(row, imfptr, "min_chain_length", 0, NULL, ICON_NONE); - box = uiLayoutBox(layout); - row = uiLayoutRow(box, false); - - row = uiLayoutRow(box, false); - uiItemR(row, imfptr, "keep_bind_info", 0, NULL, ICON_NONE); + box = uiLayoutBox(layout); + row = uiLayoutRow(box, false); + row = uiLayoutRow(box, false); + uiItemR(row, imfptr, "keep_bind_info", 0, NULL, ICON_NONE); } static void wm_collada_import_draw(bContext *UNUSED(C), wmOperator *op) { - PointerRNA ptr; + PointerRNA ptr; - RNA_pointer_create(NULL, op->type->srna, op->properties, &ptr); - uiCollada_importSettings(op->layout, &ptr); + RNA_pointer_create(NULL, op->type->srna, op->properties, &ptr); + uiCollada_importSettings(op->layout, &ptr); } void WM_OT_collada_import(wmOperatorType *ot) { - ot->name = "Import COLLADA"; - ot->description = "Load a Collada file"; - ot->idname = "WM_OT_collada_import"; - - ot->invoke = WM_operator_filesel; - ot->exec = wm_collada_import_exec; - ot->poll = WM_operator_winactive; - - //ot->flag |= OPTYPE_PRESET; - - ot->ui = wm_collada_import_draw; - - WM_operator_properties_filesel( - ot, FILE_TYPE_FOLDER | FILE_TYPE_COLLADA, FILE_BLENDER, FILE_OPENFILE, - WM_FILESEL_FILEPATH, FILE_DEFAULTDISPLAY, FILE_SORT_ALPHA); - - RNA_def_boolean( - ot->srna, - "import_units", 0, "Import Units", - "If disabled match import to Blender's current Unit settings, " - "otherwise use the settings from the Imported scene"); - - RNA_def_boolean( - ot->srna, - "fix_orientation", 0, "Fix Leaf Bones", - "Fix Orientation of Leaf Bones (Collada does only support Joints)"); - - RNA_def_boolean( - ot->srna, - "find_chains", 0, "Find Bone Chains", - "Find best matching Bone Chains and ensure bones in chain are connected"); - - RNA_def_boolean( - ot->srna, - "auto_connect", 0, "Auto Connect", - "Set use_connect for parent bones which have exactly one child bone"); - - 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); - - 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"); - + ot->name = "Import COLLADA"; + ot->description = "Load a Collada file"; + ot->idname = "WM_OT_collada_import"; + + ot->invoke = WM_operator_filesel; + ot->exec = wm_collada_import_exec; + ot->poll = WM_operator_winactive; + + //ot->flag |= OPTYPE_PRESET; + + ot->ui = wm_collada_import_draw; + + WM_operator_properties_filesel(ot, + FILE_TYPE_FOLDER | FILE_TYPE_COLLADA, + FILE_BLENDER, + FILE_OPENFILE, + WM_FILESEL_FILEPATH, + FILE_DEFAULTDISPLAY, + FILE_SORT_ALPHA); + + RNA_def_boolean(ot->srna, + "import_units", + 0, + "Import Units", + "If disabled match import to Blender's current Unit settings, " + "otherwise use the settings from the Imported scene"); + + RNA_def_boolean(ot->srna, + "fix_orientation", + 0, + "Fix Leaf Bones", + "Fix Orientation of Leaf Bones (Collada does only support Joints)"); + + RNA_def_boolean(ot->srna, + "find_chains", + 0, + "Find Bone Chains", + "Find best matching Bone Chains and ensure bones in chain are connected"); + + RNA_def_boolean(ot->srna, + "auto_connect", + 0, + "Auto Connect", + "Set use_connect for parent bones which have exactly one child bone"); + + 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); + + 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"); } #endif diff --git a/source/blender/editors/io/io_ops.c b/source/blender/editors/io/io_ops.c index 93874031ea2..e04fe4a20c0 100644 --- a/source/blender/editors/io/io_ops.c +++ b/source/blender/editors/io/io_ops.c @@ -21,7 +21,7 @@ * \ingroup collada */ -#include "io_ops.h" /* own include */ +#include "io_ops.h" /* own include */ #include "WM_api.h" @@ -38,15 +38,15 @@ void ED_operatortypes_io(void) { #ifdef WITH_COLLADA - /* Collada operators: */ - WM_operatortype_append(WM_OT_collada_export); - WM_operatortype_append(WM_OT_collada_import); + /* Collada operators: */ + WM_operatortype_append(WM_OT_collada_export); + WM_operatortype_append(WM_OT_collada_import); #endif #ifdef WITH_ALEMBIC - WM_operatortype_append(WM_OT_alembic_import); - WM_operatortype_append(WM_OT_alembic_export); + WM_operatortype_append(WM_OT_alembic_import); + WM_operatortype_append(WM_OT_alembic_export); #endif - WM_operatortype_append(CACHEFILE_OT_open); - WM_operatortype_append(CACHEFILE_OT_reload); + WM_operatortype_append(CACHEFILE_OT_open); + WM_operatortype_append(CACHEFILE_OT_reload); } |