diff options
author | Gaia Clary <gaia.clary@machinimatrix.org> | 2018-11-23 17:57:45 +0300 |
---|---|---|
committer | Gaia Clary <gaia.clary@machinimatrix.org> | 2018-11-23 19:08:14 +0300 |
commit | 322cf89a1444c685219ed6b863c9c74d41b5d1d1 (patch) | |
tree | 4145b1ec18a0c5cd4fe344d4e9ed49a0c2d33d0b /source/blender/editors/io | |
parent | 3bf7c846eeb4a728c62100b40463874d83f5b3e0 (diff) |
Partial rewrite of the Collada Module for Blender 2.8
Most important changes are in the Animation exporter and Animation Importer.
There is still some cleaning up to be done. But the Exporter/Importer basically
work within Blender 2.8
Some details:
User Interface:
The interface has been reorganized to look more like the FBX interface.
New options in user interface:
* keep_keyframes:
When sampling the distance between 2 keyframes is defined by
the sampling rate. Furthermore the keyframes defined in the
FCurves are not exported. However when this option is enabled
then also the defined keyframes will be added to the exported fcurves
* keep_smooth_curves:
When sampling we do not use FCurves. So we also have no Curve handles
for smooth exporting. However when this option is enabled, Blender
does its best to recreate the handles for export. This is a very
experimental feature and it is know to break when:
- the exported animated objects have parent inverse matrices
different from the unit matrix
- The exported objects have negative scaling
There may be many other situations when this feature breaks.
This needs to be further tested. It may be removed later or replaced
by something less wonky.
BlenderContext:
is a new class that contains the bridge to Blender. It contains
pointers to the current export/import context plus derived values
of Depsgraph, Scene, Main
Reporting:
I reorganized the output on the Blender Console to become more
informative and more readable
Preservation of Item names:
name attributes are now encoded with XML entities. This makes
sure that i can export/import names exactly defined in the tool.
This affects material names, bone names and object names.
Hierarchy export:
* Object and Bone Hierarchies are now exported correctly
by taking the Blender parent/child hierarchy into account
* Export also not selected intermediate objects
Problem:
When we export an Object Hierarchy, then we must export
all elements of the hierarchy to maintain the transforms. This
is especially important when exporting animated objects, because the
animation curves are exported as relative curves based on the
parent-child hierarchy. If an intermediate animated object is missing
then the exported animation breaks.
Solution:
If the "Selected" Optioon is enabled, then take care
to also export all objects which are not selected and hidden,
but which are parents of selected objects.
Node Based Material Importer (wip):
Added basic support for Materials with diffuse color and
diffuse textures. More properties (opacity, emission) need
changes in the used shader.
Note: Materials are all constructed by using the principled BSDF shader.
Animation Exporter:
* Massive optimization of the Animation Bake tool (Animation Sampler).
Instead of sampling each fcurve separately, i now sample all
exported fcurves simultaneously. So i avoid many (many!)
scene updates during animation export.
* Add support for Continuous Acceleration (Fcurve handles)
This allows us to create smoother FCurves during importing Collada
Animation curves. Possibly this should become an option ionstead of
a fixed import feature.
* Add support for sampling curves (to bake animations)
* The animation sampler now can be used for any animation curve.
Before the sampler only looked at curves which are supported by
Standard Collada 1.4. However the Collada exporter currently
ignores all animation curves which are not covered by the 1.4.1
Collada Standards. There is still some room for improvements
here (work in progres)
Known issues:
* Some exports do currently not work reliably, among those
are the camera animations, material animations and light animations
those animations will be added back next (work in progres)
* Exporting animation curves with keyframes (and tangents)
sometimes results in odd curves (when parent inverse matrix is involved)
This needs to be checked in more depth (probably it can not be solved).
* Export of "all animations in scene" is disabled because the
Collada Importer can not handle this reliably at the
moment (work in progres).
* Support for Animation Clip export
Added one extra level to the exported animations
such that now all scene animations are enclosed:
<Animation name="id_name(ob)_Action">
<Animation>...</Animation>
...
</Animation>
Animation Importer:
* Import of animations for objects with multiple materials
When importing multiple materials for one object,
the imported material animation curves have all been
assigned to the first material in the object.
Error handling (wip):
The Importer was a bit confused as it sometimes ignored fatal
parsing errors and continued to import. I did my best to
unconfuse it, but i believe that this needs to be tested more.
Refactoring:
update : move generation of effect id names into own function
update : adjust importer/exporter for no longer supported HEMI lights
cleanup: Removed no lopnger existing attribute from the exporter presets
cleanup: Removed not needed Context attribute from DocumentExporter
fix : Avoid duplicate deletion of temporary items
cleanup: fixed indentation and white space issues
update : Make BCAnimation class more self contained
cleanup: Renamed classes, updated comments for better reading
cleanup: Moved static class functions to collada_utils
cleanup: Moved typedefs to more intuitive locations
cleanup: indentation and class method declarations
cleanup: Removed no longer needed methods
update : Moved Classes into separate files
cleanup: Added comments
cleanup: take care of name conventions
... : many more small changes, not helpful to list them all
Diffstat (limited to 'source/blender/editors/io')
-rw-r--r-- | source/blender/editors/io/io_collada.c | 251 |
1 files changed, 171 insertions, 80 deletions
diff --git a/source/blender/editors/io/io_collada.c b/source/blender/editors/io/io_collada.c index 554480be72a..abe7ba06cfe 100644 --- a/source/blender/editors/io/io_collada.c +++ b/source/blender/editors/io/io_collada.c @@ -94,10 +94,13 @@ static int wm_collada_export_exec(bContext *C, wmOperator *op) int deform_bones_only; int include_animations; - int sample_animations; + int include_all_actions; int sampling_rate; + int keep_smooth_curves; + int keep_keyframes; int include_material_textures; + int export_animation_type; int use_texture_copies; int active_uv_only; @@ -112,6 +115,7 @@ static int wm_collada_export_exec(bContext *C, wmOperator *op) 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"); @@ -148,8 +152,12 @@ static int wm_collada_export_exec(bContext *C, wmOperator *op) include_shapekeys = RNA_boolean_get(op->ptr, "include_shapekeys"); include_animations = RNA_boolean_get(op->ptr, "include_animations"); - sample_animations = RNA_boolean_get(op->ptr, "sample_animations"); - sampling_rate = (sample_animations) ? RNA_int_get(op->ptr, "sampling_rate") : 0; + 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"); deform_bones_only = RNA_boolean_get(op->ptr, "deform_bones_only"); @@ -172,7 +180,7 @@ static int wm_collada_export_exec(bContext *C, wmOperator *op) /* get editmode results */ ED_object_editmode_load(bmain, CTX_data_edit_object(C)); - Scene *scene = CTX_data_scene(C); + //Scene *scene = CTX_data_scene(C); ExportSettings export_settings; @@ -185,18 +193,36 @@ static int wm_collada_export_exec(bContext *C, wmOperator *op) export_settings.include_armatures = include_armatures != 0; export_settings.include_shapekeys = include_shapekeys != 0; export_settings.deform_bones_only = deform_bones_only != 0; - export_settings.include_animations = include_animations; + export_settings.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.active_uv_only = active_uv_only != 0; - export_settings.include_material_textures = include_material_textures != 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; - export_settings.export_transformation_type = export_transformation_type; + + 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; @@ -207,8 +233,6 @@ static int wm_collada_export_exec(bContext *C, wmOperator *op) export_count = collada_export( C, - CTX_data_depsgraph(C), - scene, &export_settings ); @@ -232,96 +256,134 @@ 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); - uiItemL(row, IFACE_("Export Data Options:"), ICON_MESH_DATA); + uiItemR(row, imfptr, "prop_bc_export_ui_section", UI_ITEM_R_EXPAND, NULL, ICON_NONE); - 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")); + 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, "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_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_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")); + 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); - row = uiLayoutRow(box, false); - uiItemR(row, imfptr, "include_animations", 0, NULL, ICON_NONE); - row = uiLayoutRow(box, false); - if (include_animations) { - uiItemR(row, imfptr, "sample_animations", 0, NULL, ICON_NONE); - row = uiLayoutColumn(box, false); - uiItemR(row, imfptr, "sampling_rate", 0, NULL, ICON_NONE); - uiLayoutSetEnabled(row, RNA_boolean_get(imfptr, "sample_animations")); } + 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); - /* Texture options */ - box = uiLayoutBox(layout); - row = uiLayoutRow(box, false); - uiItemL(row, IFACE_("Texture Options:"), ICON_TEXTURE_DATA); + row = uiLayoutRow(box, false); + uiItemR(row, imfptr, "deform_bones_only", 0, NULL, ICON_NONE); - row = uiLayoutRow(box, false); - uiItemR(row, imfptr, "active_uv_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) { - row = uiLayoutRow(box, false); - uiItemR(row, imfptr, "include_material_textures", 0, NULL, ICON_NONE); + /* ====================== */ + /* Animation Data options */ + /* ====================== */ - row = uiLayoutRow(box, false); - uiItemR(row, imfptr, "use_texture_copies", 1, NULL, ICON_NONE); + row = uiLayoutRow(box, false); + uiItemR(row, imfptr, "include_animations", 0, NULL, ICON_NONE); - /* Armature options */ - box = uiLayoutBox(layout); - row = uiLayoutRow(box, false); - uiItemL(row, IFACE_("Armature Options:"), ICON_ARMATURE_DATA); + row = uiLayoutRow(box, false); + uiItemR(row, imfptr, "export_animation_type_selection", UI_ITEM_R_EXPAND, NULL, ICON_NONE); - row = uiLayoutRow(box, false); - uiItemR(row, imfptr, "deform_bones_only", 0, 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 = uiLayoutRow(box, false); - uiItemR(row, imfptr, "open_sim", 0, NULL, ICON_NONE); + 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)); - /* Collada options: */ - box = uiLayoutBox(layout); - row = uiLayoutRow(box, false); - uiItemL(row, IFACE_("Collada Options:"), ICON_MODIFIER); + row = uiLayoutColumn(box, false); + uiItemR(row, imfptr, "sampling_rate", 0, NULL, ICON_NONE); + uiLayoutSetEnabled(row, sampling && include_animations); - row = uiLayoutRow(box, false); - uiItemR(row, imfptr, "triangulate", 1, NULL, ICON_NONE); - 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 = uiLayoutColumn(box, false); + uiItemR(row, imfptr, "keep_keyframes", 0, NULL, ICON_NONE); + uiLayoutSetEnabled(row, sampling && include_animations); - 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); - row = uiLayoutRow(box, false); - uiItemR(row, imfptr, "sort_by_name", 0, NULL, ICON_NONE); + row = uiLayoutRow(box, false); + uiItemR(row, imfptr, "include_all_actions", 0, NULL, ICON_NONE); + uiLayoutSetEnabled(row, include_animations); - row = uiLayoutRow(box, false); - uiItemR(row, imfptr, "keep_bind_info", 0, NULL, ICON_NONE); + } + 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, "limit_precision", 0, NULL, ICON_NONE); + 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) @@ -357,11 +419,27 @@ void WM_OT_collada_export(wmOperatorType *ot) }; 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} + { 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\n 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"; @@ -379,6 +457,9 @@ void WM_OT_collada_export(wmOperatorType *ot) 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 Organisation"); + RNA_def_boolean(func, "apply_modifiers", 0, "Apply Modifiers", "Apply modifiers to exported mesh (non destructive))"); @@ -404,15 +485,25 @@ void WM_OT_collada_export(wmOperatorType *ot) 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.\nExporting Animations will enforce the decomposition of node transforms\ninto <translation> <rotation> and <scale> components"); - RNA_def_boolean(func, "sample_animations", 0, - "Sample Animations", "Auto-generate keyframes with a frame distance set by 'Sampling Rate'.\nWhen disabled, export only the keyframes defined in the animation f-curves (may be less accurate)"); + RNA_def_boolean(func, "include_all_actions", true, + "Include all Actions", "Export also unassigned actions.\nThis allows you to export entire animation libraries for your charater(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 means: Every frame is keyed", 1, INT_MAX); + RNA_def_boolean(func, "keep_smooth_curves", 0, + "Keep Smooth curves", "Export also the curve handles (if available).\nThis does only work when the inverse parent matrix is the Unity matrix\nOtherwise you may end up with odd results\n"); + + RNA_def_boolean(func, "keep_keyframes", 0, + "Keep Keyframes", "Use existing keyframes as additional sample points.\nThis helps when you want to keep manual tweeks"); RNA_def_boolean(func, "active_uv_only", 0, "Only Selected UV Map", "Export only the selected UV Map"); @@ -497,7 +588,7 @@ static int wm_collada_import_exec(bContext *C, wmOperator *op) return OPERATOR_FINISHED; } else { - BKE_report(op->reports, RPT_ERROR, "Errors found during parsing COLLADA document (see console for details)"); + BKE_report(op->reports, RPT_ERROR, "Parsing errors in Document (see Blender Console)"); return OPERATOR_CANCELLED; } } |