[Bf-blender-cvs] [c437c017e33] collada2.8: Merge branch 'collada' into blender2.8

Gaia Clary noreply at git.blender.org
Tue Nov 6 16:54:53 CET 2018


Commit: c437c017e33f3e76c56744ce9e06a127dbc77323
Author: Gaia Clary
Date:   Thu Oct 25 22:45:40 2018 +0200
Branches: collada2.8
https://developer.blender.org/rBc437c017e33f3e76c56744ce9e06a127dbc77323

Merge branch 'collada' into blender2.8

===================================================================



===================================================================

diff --cc source/blender/collada/AnimationClipExporter.h
index 8a48ca29090,2dbe98ffe31..d76a3fa1380
--- a/source/blender/collada/AnimationClipExporter.h
+++ b/source/blender/collada/AnimationClipExporter.h
@@@ -20,32 -20,31 +20,31 @@@
   * ***** END GPL LICENSE BLOCK *****
   */
  
- /** \file DocumentExporter.h
-  *  \ingroup collada
-  */
- 
- #ifndef __DOCUMENTEXPORTER_H__
- #define __DOCUMENTEXPORTER_H__
- 
- #include "collada.h"
- 
- extern "C" {
- #include "DNA_customdata_types.h"
- 
- }
+ #include <stdlib.h>
+ #include <stdio.h>
+ #include <math.h>
  
- struct Scene;
+ #include "COLLADASWLibraryAnimationClips.h"
  
- class DocumentExporter
- {
-  public:
- 	DocumentExporter(Depsgraph *depsgraph, const ExportSettings *export_settings);
- 	int  exportCurrentScene(bContext *C, Scene *sce);
  
- 	void exportScenes(const char *filename);
+ class AnimationClipExporter:COLLADASW::LibraryAnimationClips {
  private:
 -	EvaluationContext * eval_ctx;
 +	Depsgraph *depsgraph;
+ 	Scene *scene;
+ 	COLLADASW::StreamWriter *sw;
  	const ExportSettings *export_settings;
- };
+ 	std::vector<std::vector<std::string>> anim_meta;
+ 
+ public:
  
- #endif
 -	AnimationClipExporter(EvaluationContext *eval_ctx, COLLADASW::StreamWriter *sw, const ExportSettings *export_settings, std::vector<std::vector<std::string>> anim_meta) :
 -		eval_ctx(eval_ctx),
++	AnimationClipExporter(Depsgraph *depsgraph , COLLADASW::StreamWriter *sw, const ExportSettings *export_settings, std::vector<std::vector<std::string>> anim_meta) :
++		depsgraph(depsgraph),
+ 		COLLADASW::LibraryAnimationClips(sw),
+ 		export_settings(export_settings),
+ 		anim_meta(anim_meta)
+ 	{
+ 		this->sw = sw;
+ 	}
+ 
+ 	void exportAnimationClips(Scene *sce);
 -};
++};
diff --cc source/blender/collada/AnimationExporter.cpp
index ef9611778c9,a5968f9323f..217fb08f014
--- a/source/blender/collada/AnimationExporter.cpp
+++ b/source/blender/collada/AnimationExporter.cpp
@@@ -20,356 -20,198 +20,202 @@@
   * ***** END GPL LICENSE BLOCK *****
   */
  
 +/** \file AnimationExporter.cpp
 + *  \ingroup collada
 + */
 +
  #include "GeometryExporter.h"
  #include "AnimationExporter.h"
+ #include "AnimationClipExporter.h"
+ #include "BCAnimationSampler.h"
  #include "MaterialExporter.h"
+ #include "collada_utils.h"
  
- template<class Functor>
- void forEachObjectInExportSet(Scene *sce, Functor &f, LinkNode *export_set)
- {
- 	LinkNode *node;
- 	for (node = export_set; node; node = node->next) {
- 		Object *ob = (Object *)node->link;
- 		f(ob);
- 	}
- }
+ std::string EMPTY_STRING;
  
- bool AnimationExporter::exportAnimations(Main *bmain, Scene *sce)
+ std::string AnimationExporter::get_axis_name(std::string channel, int id)
  {
- 	bool has_animations = hasAnimations(sce);
- 	m_bmain = bmain;
- 	if (has_animations) {
- 		this->scene = sce;
- 
- 		openLibrary();
+ 	static std::map<std::string, std::vector<std::string>> BC_COLLADA_AXIS_FROM_TYPE = {
+ 		{ "color"         ,{ "R", "G", "B" } },
+ 		{ "specular_color",{ "R", "G", "B" } },
+ 		{ "diffuse_color",{ "R", "G", "B" } },
+ 		{ "alpha",{ "R", "G", "B" } },
+ 		{ "scale",{ "X", "Y", "Z" } },
+ 		{ "location",{ "X", "Y", "Z" } },
+ 		{ "rotation_euler",{ "X", "Y", "Z" } }
+ 	};
  
- 		forEachObjectInExportSet(sce, *this, this->export_settings->export_set);
+ 	std::map<std::string, std::vector<std::string>>::const_iterator it;
+ 	it = BC_COLLADA_AXIS_FROM_TYPE.find(channel);
+ 	if (it == BC_COLLADA_AXIS_FROM_TYPE.end())
+ 		return "";
  
- 		closeLibrary();
- 	}
- 	return has_animations;
+ 	const std::vector<std::string> &subchannel = it->second;
+ 	if (id >= subchannel.size())
+ 		return "";
+ 	return subchannel[id];
  }
  
- bool AnimationExporter::is_flat_line(std::vector<float> &values, int channel_count)
+ bool AnimationExporter::open_animation_container(bool has_container, Object *ob)
  {
- 	for (int i = 0; i < values.size(); i += channel_count) {
- 		for (int j = 0; j < channel_count; j++) {
- 			if (!bc_in_range(values[j], values[i+j], 0.000001))
- 				return false;
- 		}
+ 	if (!has_container) {
+ 		char anim_id[200];
+ 		sprintf(anim_id, "action_container-%s", translate_id(id_name(ob)).c_str());
+ 		openAnimation(anim_id, id_name(ob));
  	}
  	return true;
  }
- /*
-  * This function creates a complete LINEAR Collada <Animation> Entry with all needed
-  * <source>, <sampler>, and <channel> entries.
-  * This is is used for creating sampled Transformation Animations for either:
-  *
-  *		1-axis animation:
-  *		    times contains the time points in seconds from within the timeline
-  *			values contains the data (list of single floats)
-  *			channel_count = 1
-  *			axis_name = ['X' | 'Y' | 'Z']
-  *			is_rot indicates if the animation is a rotation
-  *
-  *		3-axis animation:
-  *			times contains the time points in seconds from within the timeline
-  *			values contains the data (list of floats where each 3 entries are one vector)
-  *			channel_count = 3
-  *			axis_name = "" (actually not used)
-  *			is_rot = false (see xxx below)
-  *
-  *	xxx: I tried to create a 3 axis rotation animation
-  *		 like for translation or scale. But i could not
-  *		 figure out how to setup the channel for this case.
-  *		 So for now rotations are exported as 3 separate 1-axis collada animations
-  *		 See export_sampled_animation() further down.
-  */
- void AnimationExporter::create_sampled_animation(int channel_count,
- 	std::vector<float> &times,
- 	std::vector<float> &values,
- 	std::string ob_name,
- 	std::string label,
- 	std::string axis_name,
- 	bool is_rot)
- {
- 	char anim_id[200];
- 
- 	if (is_flat_line(values, channel_count))
- 		return;
- 
- 	BLI_snprintf(anim_id, sizeof(anim_id), "%s_%s_%s", (char *)translate_id(ob_name).c_str(), label.c_str(), axis_name.c_str());
- 
- 	openAnimation(anim_id, COLLADABU::Utils::EMPTY_STRING);
- 
- 	/* create input source */
- 	std::string input_id = create_source_from_vector(COLLADASW::InputSemantic::INPUT, times, false, anim_id, "");
- 
- 	/* create output source */
- 	std::string output_id;
- 	if (channel_count == 1)
- 		output_id = create_source_from_array(COLLADASW::InputSemantic::OUTPUT, &values[0], values.size(), is_rot, anim_id, axis_name.c_str());
- 	else if (channel_count == 3)
- 		output_id = create_xyz_source(&values[0], times.size(), anim_id);
- 	else if (channel_count == 16)
- 		output_id = create_4x4_source(times, values, anim_id);
- 
- 	std::string sampler_id = std::string(anim_id) + SAMPLER_ID_SUFFIX;
- 	COLLADASW::LibraryAnimations::Sampler sampler(sw, sampler_id);
- 	std::string empty;
- 	sampler.addInput(COLLADASW::InputSemantic::INPUT, COLLADABU::URI(empty, input_id));
- 	sampler.addInput(COLLADASW::InputSemantic::OUTPUT, COLLADABU::URI(empty, output_id));
- 
- 	/* TODO create in/out tangents source (LINEAR) */
- 	std::string interpolation_id = fake_interpolation_source(times.size(), anim_id, "");
- 
- 	/* Create Sampler */
- 	sampler.addInput(COLLADASW::InputSemantic::INTERPOLATION, COLLADABU::URI(empty, interpolation_id));
- 	addSampler(sampler);
- 
- 	/* Create channel */
- 	std::string target = translate_id(ob_name) + "/" + label + axis_name + ((is_rot) ? ".ANGLE" : "");
- 	addChannel(COLLADABU::URI(empty, sampler_id), target);
- 
- 	closeAnimation();
- 
- }
  
- /*
-  * Export all animation FCurves of an Object.
-  *
-  * Note: This uses the keyframes as sample points,
-  * and exports "baked keyframes" while keeping the tangent information
-  * of the FCurves intact. This works for simple cases, but breaks
-  * especially when negative scales are involved in the animation.
-  *
-  * If it is necessary to conserve the Animation precisely then
-  * use export_sampled_animation_set() instead.
-  */
- void AnimationExporter::export_keyframed_animation_set(Object *ob)
+ void AnimationExporter::openAnimationWithClip(std::string action_id, std::string action_name)
  {
- 	FCurve *fcu = (FCurve *)ob->adt->action->curves.first;
- 	if (!fcu) {
- 		return; /* object has no animation */
- 	}
- 
- 	if (this->export_settings->export_transformation_type == BC_TRANSFORMATION_TYPE_MATRIX) {
+ 	std::vector<std::string> anim_meta_entry;
+ 	anim_meta_entry.push_back(translate_id(action_id));
+ 	anim_meta_entry.push_back(action_name);
+ 	anim_meta.push_back(anim_meta_entry);
  
- 		std::vector<float> ctimes;
- 		find_keyframes(ob, ctimes);
- 		if (ctimes.size() > 0)
- 			export_sampled_matrix_animation(ob, ctimes);
- 	}
- 	else {
- 		char *transformName;
- 		while (fcu) {
- 			//for armature animations as objects
- 			if (ob->type == OB_ARMATURE)
- 				transformName = fcu->rna_path;
- 			else
- 				transformName = extract_transform_name(fcu->rna_path);
- 
- 			if (
- 				STREQ(transformName, "location") ||
- 				STREQ(transformName, "scale") ||
- 				(STREQ(transformName, "rotation_euler") && ob->rotmode == ROT_MODE_EUL) ||
- 				STREQ(transformName, "rotation_quaternion"))
- 			{
- 				create_keyframed_animation(ob, fcu, transformName, false);
- 			}
- 			fcu = fcu->next;
- 		}
- 	}
+ 	openAnimation(translate_id(action_id), action_name);
  }
  
- /*
-  * Export the sampled animation of an Object.
-  *
-  * Note: This steps over all animation frames (step size is given in export_settings.sample_size)
-  * and then evaluates the transformation,
-  * and exports "baked samples" This works always, however currently the interpolation type is set
-  * to LINEAR for now. (maybe later this can be changed to BEZIER)
-  *
-  * Note: If it is necessary to keep the FCurves intact, then use export_keyframed_animation_set() instead.
-  * However be aware that exporting keyframed animation may modify the animation slightly.
-  * Also keyframed animation exports tend to break when negative scales are involved.
-  */
- void AnimationExporter::export_sampled_animation_set(Object *ob)
+ void AnimationExporter::close_animation_container(bool has_container)
  {
- 	std::vector<float>ctimes;
- 	find_sampleframes(ob, ctimes);
- 	if (ctimes.size() > 0) {
- 		if (this->export_settings->export_transformation_type == BC_TRANSFORMATION_TYPE_MATRIX)
- 			export_sampled_matrix_animation(ob, ctimes);
- 		else
- 			export_sampled_transrotloc_animation(ob, ctimes);
- 	}
+ 	if (has_container)
+ 		closeAnimation();
  }
  
- void AnimationExporter::ex

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list