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/collada/AnimationExporter.h | |
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/collada/AnimationExporter.h')
-rw-r--r-- | source/blender/collada/AnimationExporter.h | 201 |
1 files changed, 129 insertions, 72 deletions
diff --git a/source/blender/collada/AnimationExporter.h b/source/blender/collada/AnimationExporter.h index f5e96dbd813..a5d3780af63 100644 --- a/source/blender/collada/AnimationExporter.h +++ b/source/blender/collada/AnimationExporter.h @@ -20,13 +20,15 @@ * ***** END GPL LICENSE BLOCK ***** */ -/** \file AnimationExporter.h - * \ingroup collada - */ +#ifndef __BC_ANIMATION_EXPORTER_H__ +#define __BC_ANIMATION_EXPORTER_H__ #include <stdlib.h> #include <stdio.h> #include <math.h> + +#include "BCAnimationCurve.h" + extern "C" { #include "DNA_scene_types.h" @@ -74,35 +76,40 @@ extern "C" #include "COLLADASWBaseInputElement.h" #include "EffectExporter.h" - +#include "BCAnimationSampler.h" #include "collada_internal.h" #include "IK_solver.h" #include <vector> +#include <map> #include <algorithm> // std::find struct Depsgraph; +typedef enum BC_animation_source_type { + BC_SOURCE_TYPE_VALUE, + BC_SOURCE_TYPE_ANGLE, + BC_SOURCE_TYPE_TIMEFRAME +} BC_animation_source_type; + class AnimationExporter: COLLADASW::LibraryAnimations { private: - Main *m_bmain; - Scene *scene; - Depsgraph *depsgraph; + BlenderContext &blender_context; COLLADASW::StreamWriter *sw; public: - AnimationExporter(Depsgraph *depsgraph, COLLADASW::StreamWriter *sw, const ExportSettings *export_settings): + AnimationExporter(BlenderContext &blender_context, COLLADASW::StreamWriter *sw, const ExportSettings *export_settings): + blender_context(blender_context), COLLADASW::LibraryAnimations(sw), - depsgraph(depsgraph), export_settings(export_settings) { this->sw = sw; } - bool exportAnimations(Main *bmain, Scene *sce); + bool exportAnimations(); // called for each exported object void operator() (Object *ob); @@ -110,7 +117,6 @@ public: protected: const ExportSettings *export_settings; - void export_object_constraint_animation(Object *ob); void export_morph_animation(Object *ob); @@ -121,8 +127,6 @@ protected: void sample_and_write_bone_animation(Object *ob_arm, Bone *bone, int transform_type); - bool is_bone_deform_group(Bone * bone); - void sample_and_write_bone_animation_matrix(Object *ob_arm, Bone *bone); void sample_animation(float *v, std::vector<float> &frames, int type, Bone *bone, Object *ob_arm, bPoseChannel *pChan); @@ -141,70 +145,123 @@ protected: float convert_angle(float angle); + std::vector<std::vector<std::string>> anim_meta; + + /* Main entry point into Animation export (called for each exported object) */ + void exportAnimation(Object *ob, BCAnimationSampler &sampler); + + /* export animation as separate trans/rot/scale curves */ + void export_curve_animation_set( + Object *ob, + BCAnimationSampler &sampler, + bool export_tm_curves); + + /* export one single curve */ + void export_curve_animation( + Object *ob, + BCAnimationCurve &curve); + + /* export animation as matrix data */ + void export_matrix_animation( + Object *ob, + BCAnimationSampler &sampler); + + /* step through the bone hierarchy */ + void export_bone_animations_recursive( + Object *ob_arm, + Bone *bone, + BCAnimationSampler &sampler); + + /* Export for one bone */ + void export_bone_animation( + Object *ob, + Bone *bone, + BCFrames &frames, + BCMatrixSampleMap &outmats); + + /* call to the low level collada exporter */ + void export_collada_curve_animation( + std::string id, + std::string name, + std::string target, + std::string axis, + BCAnimationCurve &curve); + + /* call to the low level collada exporter */ + void export_collada_matrix_animation( + std::string id, + std::string name, + std::string target, + BCFrames &frames, + BCMatrixSampleMap &outmats); + + BCAnimationCurve *get_modified_export_curve(Object *ob, BCAnimationCurve &curve, BCAnimationCurveMap &curves); + + /* Helper functions */ + void openAnimationWithClip(std::string id, std::string name); + bool open_animation_container(bool has_container, Object *ob); + void close_animation_container(bool has_container); + + /* Input and Output sources (single valued) */ + std::string collada_source_from_values( + BC_animation_source_type tm_channel, + COLLADASW::InputSemantic::Semantics semantic, + std::vector<float> &values, + const std::string& anim_id, + const std::string axis_name); + + /* Output sources (matrix data) */ + std::string collada_source_from_values( + BCMatrixSampleMap &samples, + const std::string& anim_id); + + /* Interpolation sources */ + std::string collada_linear_interpolation_source( + int tot, + const std::string& anim_id); + + /* source ID = animation_name + semantic_suffix */ + std::string get_semantic_suffix(COLLADASW::InputSemantic::Semantics semantic); void add_source_parameters(COLLADASW::SourceBase::ParameterNameList& param, - COLLADASW::InputSemantic::Semantics semantic, bool is_rot, const char *axis, bool transform); - - void get_source_values(BezTriple *bezt, COLLADASW::InputSemantic::Semantics semantic, bool is_angle, float *values, int *length); - - float* get_eul_source_for_quat(Object *ob ); - - bool is_flat_line(std::vector<float> &values, int channel_count); - void export_keyframed_animation_set(Object *ob); - void create_keyframed_animation(Object *ob, FCurve *fcu, char *transformName, bool is_param, Material *ma = NULL); - void export_sampled_animation_set(Object *ob); - void export_sampled_transrotloc_animation(Object *ob, std::vector<float> &ctimes); - void export_sampled_matrix_animation(Object *ob, std::vector<float> &ctimes); - void create_sampled_animation(int channel_count, std::vector<float> ×, std::vector<float> &values, std::string, std::string label, std::string axis_name, bool is_rot); - - void evaluate_anim_with_constraints(Object *ob, float ctime); - - std::string create_source_from_fcurve(COLLADASW::InputSemantic::Semantics semantic, FCurve *fcu, const std::string& anim_id, const char *axis_name); - std::string create_source_from_fcurve(COLLADASW::InputSemantic::Semantics semantic, FCurve *fcu, const std::string& anim_id, const char *axis_name, Object *ob); - - std::string create_lens_source_from_fcurve(Camera *cam, COLLADASW::InputSemantic::Semantics semantic, FCurve *fcu, const std::string& anim_id); - - std::string create_source_from_array(COLLADASW::InputSemantic::Semantics semantic, float *v, int tot, bool is_rot, const std::string& anim_id, const char *axis_name); + COLLADASW::InputSemantic::Semantics semantic, + bool is_rot, + const std::string axis, + bool transform); + + int get_point_in_curve(BCBezTriple &bezt, COLLADASW::InputSemantic::Semantics semantic, bool is_angle, float *values); + int get_point_in_curve(const BCAnimationCurve &curve, float sample_frame, COLLADASW::InputSemantic::Semantics semantic, bool is_angle, float *values); + + std::string collada_tangent_from_curve( + COLLADASW::InputSemantic::Semantics semantic, + BCAnimationCurve &curve, + const std::string& anim_id, + const std::string axis_name); + + std::string collada_interpolation_source(const BCAnimationCurve &curve, const std::string& anim_id, std::string axis_name, bool *has_tangents); + + std::string get_axis_name(std::string channel, int id); + const std::string get_collada_name(std::string channel_target) const; + std::string get_collada_sid(const BCAnimationCurve &curve, const std::string axis_name); + + /* ===================================== */ + /* Currently unused or not (yet?) needed */ + /* ===================================== */ - std::string create_source_from_vector(COLLADASW::InputSemantic::Semantics semantic, std::vector<float> &fra, bool is_rot, const std::string& anim_id, const char *axis_name); - - std::string create_xyz_source(float *v, int tot, const std::string& anim_id); - std::string create_4x4_source(std::vector<float> ×, std::vector<float> &values, const std::string& anim_id); - std::string create_4x4_source(std::vector<float> &frames, Object * ob_arm, Bone *bone, const std::string& anim_id); - - std::string create_interpolation_source(FCurve *fcu, const std::string& anim_id, const char *axis_name, bool *has_tangents); - - std::string fake_interpolation_source(int tot, const std::string& anim_id, const char *axis_name); - - // for rotation, axis name is always appended and the value of append_axis is ignored - std::string get_transform_sid(char *rna_path, int tm_type, const char *axis_name, bool append_axis); - std::string get_light_param_sid(char *rna_path, int tm_type, const char *axis_name, bool append_axis); - std::string get_camera_param_sid(char *rna_path, int tm_type, const char *axis_name, bool append_axis); - - void find_keyframes(Object *ob, std::vector<float> &fra, const char *prefix, const char *tm_name); - void find_keyframes(Object *ob, std::vector<float> &fra); - void find_sampleframes(Object *ob, std::vector<float> &fra); - - - void make_anim_frames_from_targets(Object *ob, std::vector<float> &frames ); - - void find_rotation_frames(Object *ob, std::vector<float> &fra, const char *prefix, int rotmode); - - // enable fcurves driving a specific bone, disable all the rest - // if bone_name = NULL enable all fcurves - void enable_fcurves(bAction *act, char *bone_name); - - bool hasAnimations(Scene *sce); - - char *extract_transform_name(char *rna_path); - - std::string getObjectBoneName(Object *ob, const FCurve * fcu); - std::string getAnimationPathId(const FCurve *fcu); - - void getBakedPoseData(Object *obarm, int startFrame, int endFrame, bool ActionBake, bool ActionBakeFirstFrame); + bool is_bone_deform_group(Bone * bone); - bool validateConstraints(bConstraint *con); +#if 0 + BC_animation_transform_type _get_transform_type(const std::string path); + void get_eul_source_for_quat(std::vector<float> &cache, Object *ob); +#endif +#ifdef WITH_MORPH_ANIMATION + void export_morph_animation( + Object *ob, + BCAnimationSampler &sampler); +#endif }; + +#endif |