[Bf-blender-cvs] [322cf89a144] blender2.8: Partial rewrite of the Collada Module for Blender 2.8

Gaia Clary noreply at git.blender.org
Fri Nov 23 17:08:27 CET 2018


Commit: 322cf89a1444c685219ed6b863c9c74d41b5d1d1
Author: Gaia Clary
Date:   Fri Nov 23 15:57:45 2018 +0100
Branches: blender2.8
https://developer.blender.org/rB322cf89a1444c685219ed6b863c9c74d41b5d1d1

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

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

M	release/scripts/presets/operator/wm.collada_export/sl_plus_open_sim_rigged.py
A	source/blender/collada/AnimationClipExporter.cpp
A	source/blender/collada/AnimationClipExporter.h
A	source/blender/collada/AnimationCurveCache.cpp
A	source/blender/collada/AnimationCurveCache.h
M	source/blender/collada/AnimationExporter.cpp
M	source/blender/collada/AnimationExporter.h
M	source/blender/collada/AnimationImporter.cpp
M	source/blender/collada/AnimationImporter.h
M	source/blender/collada/ArmatureExporter.cpp
M	source/blender/collada/ArmatureExporter.h
A	source/blender/collada/BCAnimationCurve.cpp
A	source/blender/collada/BCAnimationCurve.h
A	source/blender/collada/BCAnimationSampler.cpp
A	source/blender/collada/BCAnimationSampler.h
A	source/blender/collada/BCSampleData.cpp
A	source/blender/collada/BCSampleData.h
A	source/blender/collada/BlenderContext.cpp
A	source/blender/collada/BlenderContext.h
M	source/blender/collada/CMakeLists.txt
M	source/blender/collada/ControllerExporter.cpp
M	source/blender/collada/ControllerExporter.h
M	source/blender/collada/DocumentExporter.cpp
M	source/blender/collada/DocumentExporter.h
M	source/blender/collada/DocumentImporter.cpp
M	source/blender/collada/DocumentImporter.h
M	source/blender/collada/EffectExporter.cpp
M	source/blender/collada/EffectExporter.h
M	source/blender/collada/ErrorHandler.cpp
M	source/blender/collada/ExportSettings.h
M	source/blender/collada/GeometryExporter.cpp
M	source/blender/collada/GeometryExporter.h
M	source/blender/collada/ImageExporter.cpp
M	source/blender/collada/ImageExporter.h
M	source/blender/collada/LightExporter.cpp
M	source/blender/collada/MaterialExporter.cpp
M	source/blender/collada/MaterialExporter.h
A	source/blender/collada/Materials.cpp
A	source/blender/collada/Materials.h
M	source/blender/collada/MeshImporter.cpp
M	source/blender/collada/SceneExporter.cpp
M	source/blender/collada/SceneExporter.h
M	source/blender/collada/SkinInfo.cpp
M	source/blender/collada/TransformReader.cpp
M	source/blender/collada/collada.cpp
M	source/blender/collada/collada.h
M	source/blender/collada/collada_internal.cpp
M	source/blender/collada/collada_internal.h
M	source/blender/collada/collada_utils.cpp
M	source/blender/collada/collada_utils.h
M	source/blender/editors/io/io_collada.c

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

diff --git a/release/scripts/presets/operator/wm.collada_export/sl_plus_open_sim_rigged.py b/release/scripts/presets/operator/wm.collada_export/sl_plus_open_sim_rigged.py
index 7825a4d0f32..311d71c4557 100644
--- a/release/scripts/presets/operator/wm.collada_export/sl_plus_open_sim_rigged.py
+++ b/release/scripts/presets/operator/wm.collada_export/sl_plus_open_sim_rigged.py
@@ -10,7 +10,6 @@ op.include_armatures = True
 op.include_shapekeys = False
 op.deform_bones_only = True
 op.active_uv_only = True
-op.include_uv_textures = True
 op.use_texture_copies = True
 op.triangulate = True
 op.use_object_instantiation = False
diff --git a/source/blender/collada/AnimationClipExporter.cpp b/source/blender/collada/AnimationClipExporter.cpp
new file mode 100644
index 00000000000..a2c4b388b7e
--- /dev/null
+++ b/source/blender/collada/AnimationClipExporter.cpp
@@ -0,0 +1,55 @@
+/*
+* ***** BEGIN GPL LICENSE BLOCK *****
+*
+* This program is free software; you can redistribute it and/or
+* modify it under the terms of the GNU General Public License
+* as published by the Free Software Foundation; either version 2
+* of the License, or (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program; if not, write to the Free Software Foundation,
+* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+*
+* Contributor(s): Chingiz Dyussenov, Arystanbek Dyussenov, Jan Diederich, Tod Liverseed.
+*
+* ***** END GPL LICENSE BLOCK *****
+*/
+
+#include "GeometryExporter.h"
+#include "AnimationClipExporter.h"
+#include "MaterialExporter.h"
+
+void AnimationClipExporter::exportAnimationClips(Scene *sce)
+{
+	openLibrary();
+	std::map<std::string, COLLADASW::ColladaAnimationClip *> clips;
+
+	std::vector<std::vector<std::string>>::iterator anim_meta_entry;
+	for (anim_meta_entry = anim_meta.begin(); anim_meta_entry != anim_meta.end(); ++anim_meta_entry) {
+		std::vector<std::string> entry = *anim_meta_entry;
+		std::string action_id = entry[0];
+		std::string action_name = entry[1];
+
+		std::map<std::string, COLLADASW::ColladaAnimationClip *>::iterator it = clips.find(action_name);
+		if (it == clips.end())
+		{
+			COLLADASW::ColladaAnimationClip *clip = new COLLADASW::ColladaAnimationClip(action_name);
+			clips[action_name] = clip;
+		}
+		COLLADASW::ColladaAnimationClip *clip = clips[action_name];
+		clip->setInstancedAnimation(action_id);
+	}
+
+	std::map<std::string, COLLADASW::ColladaAnimationClip *>::iterator clips_it;
+	for (clips_it = clips.begin(); clips_it != clips.end(); clips_it++) {
+		COLLADASW::ColladaAnimationClip *clip = (COLLADASW::ColladaAnimationClip *)clips_it->second;
+		addAnimationClip(*clip);
+	}
+
+	closeLibrary();
+}
diff --git a/source/blender/collada/DocumentExporter.h b/source/blender/collada/AnimationClipExporter.h
similarity index 55%
copy from source/blender/collada/DocumentExporter.h
copy to source/blender/collada/AnimationClipExporter.h
index 8a48ca29090..d76a3fa1380 100644
--- a/source/blender/collada/DocumentExporter.h
+++ b/source/blender/collada/AnimationClipExporter.h
@@ -15,37 +15,36 @@
  * along with this program; if not, write to the Free Software Foundation,
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  *
- * Contributor(s): Chingiz Dyussenov, Arystanbek Dyussenov.
+ * Contributor(s): Chingiz Dyussenov, Arystanbek Dyussenov, Jan Diederich, Tod Liverseed.
  *
  * ***** 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:
 	Depsgraph *depsgraph;
+	Scene *scene;
+	COLLADASW::StreamWriter *sw;
 	const ExportSettings *export_settings;
-};
+	std::vector<std::vector<std::string>> anim_meta;
+
+public:
 
-#endif
+	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 --git a/source/blender/collada/AnimationCurveCache.cpp b/source/blender/collada/AnimationCurveCache.cpp
new file mode 100644
index 00000000000..3ad921baffe
--- /dev/null
+++ b/source/blender/collada/AnimationCurveCache.cpp
@@ -0,0 +1,391 @@
+/*
+* ***** BEGIN GPL LICENSE BLOCK *****
+*
+* This program is free software; you can redistribute it and/or
+* modify it under the terms of the GNU General Public License
+* as published by the Free Software Foundation; either version 2
+* of the License, or (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program; if not, write to the Free Software Foundation,
+* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+*
+* Contributor(s): Chingiz Dyussenov, Arystanbek Dyussenov, Jan Diederich, Tod Liverseed.
+*
+* ***** END GPL LICENSE BLOCK *****
+*/
+
+#include "AnimationCurveCache.h"
+
+extern "C" {
+#include "BKE_action.h"
+#include "BLI_listbase.h"
+}
+
+AnimationCurveCache::AnimationCurveCache(bContext *C):
+	mContext(C)
+{
+}
+
+AnimationCurveCache::~AnimationCurveCache()
+{
+	clear_cache();
+}
+
+void AnimationCurveCache::clear_cache()
+{
+
+}
+
+void AnimationCurveCache::clear_cache(Object *ob)
+{
+
+}
+
+void AnimationCurveCache::create_curves(Object *ob)
+{
+
+}
+
+void AnimationCurveCache::addObject(Object *ob)
+{
+	cached_objects.push_back(ob);
+}
+
+bool AnimationCurveCache::bone_matrix_local_get(Object *ob, Bone *bone, float(&mat)[4][4], bool for_opensim)
+{
+
+	/* Ok, lets be super cautious and check if the bone exists */
+	bPose *pose = ob->pose;
+	bPoseChannel *pchan = BKE_pose_channel_find_name(pose, bone->name);
+	if (!pchan) {
+		return false;
+	}
+
+	bAction *action = bc_getSceneObjectAction(ob);
+	bPoseChannel *parchan = pchan->parent;
+	enable_fcurves(action, bone->name);
+	float ipar[4][4];
+
+	if (bone->parent) {
+		invert_m4_m4(ipar, parchan->pose_mat);
+		mul_m4_m4m4(mat, ipar, pchan->pose_mat);
+	}
+	else
+		copy_m4_m4(mat, pchan->pose_mat);
+
+	/* OPEN_SIM_COMPATIBILITY
+	* AFAIK animation to second life is via BVH, but no
+	* reason to not have the collada-animation be correct
+	*/
+	if (for_opensim) {
+		float temp[4][4];
+		copy_m4_m4(temp, bone->arm_mat);
+		temp[3][0] = temp[3][1] = temp[3][2] = 0.0f;
+		invert_m4(temp);
+
+		mul_m4_m4m4(mat, mat, temp);
+
+		if (bone->parent) {
+			copy_m4_m4(temp, bone->parent->arm_mat);
+			temp[3][0] = temp[3][1] = temp[3][2] = 0.0f;
+
+			mul_m4_m4m4(mat, temp, mat);
+		}
+	}
+
+	return true;
+}
+
+void AnimationCurveCache::sampleMain(Scene *scene, BC_export_transformation_type atm_type, bool for_opensim)
+{
+	std::map<int, std::vector<SamplePoint>>::iterator frame;
+	for (frame = sample_frames.begin(); frame != sample_frames.end(); frame++) {
+		int frame_index = frame->first;
+		std::vector<SamplePoint> sample_points = frame->second;
+
+		bc_update_scene(mContext, scene, frame_index);
+
+		for (int spi = 0; spi < sample_points.size(); spi++) {
+			SamplePoint &point = sample_points[spi];
+			Object *ob = point.get_object();
+			float mat[4][4];
+
+			if (ob->type == OB_ARMATURE) {
+				/* For Armatures we need to check if this maybe is a pose sample point*/
+				Bone *bone = point.get_bone();
+				if (bone) {
+					if (bone_matrix_local_get(ob, bone, mat, for_opensim)) {
+						point.set_matrix(mat);
+					}
+					continue;
+				}
+			}
+
+			/* When this SamplePoint is not for a Bone, 
+			 * then we just store the Object local matrix here
+			 */
+
+			BKE_object_matrix_local_get(ob, mat);
+			point.set_matrix(mat);
+
+		}
+	}
+}
+
+/*
+* enable fcurves driving a specific bone, disable all the rest
+* if bone_name = NULL enable all fcurves
+*/
+void AnimationCurveCache::enable_fcurves(bAction *act, char *bone_name)
+{
+	FCurve *fcu;
+	char prefix[200];
+
+	if (bone_name)
+		BLI_snprintf(prefix, sizeof(prefix), "pose.bones[\"%s\"]", bone_name);
+
+	for (fcu = (FCurve *)act->curves.first; fcu; fcu = fcu->next) {
+		if (bone_name) {
+			if (STREQLEN(fcu->rna_path, prefix, strlen(prefix)))
+				fcu->flag &= ~FCURVE_DISABLED;
+			else
+				fcu->flag |= FCURVE_DISABLED;
+		}
+		else {
+			fcu->flag &= ~FCURVE_DISABLED;
+		}
+	}
+}
+/*
+* Sample the scene at frames where object fcurves
+* have defined keys.
+*/
+void AnimationCurveCache::sampleScene(Scene *scene, BC_export_transformation_type atm_type, bool for_opensim, bool keyframe_at_end)
+{
+	create_sample_frames_from_keyframes();
+	sampleMain(scene, atm_type, for_opensim);
+}
+
+void AnimationCurveCache::sampleScene(Scene *scene, BC_export_transformation_type atm_type, int sampling_rate, bool for_opensim, bool keyframe_at_end)
+{
+	create_sample_frames_generated(scene->r.sfra, scene->r.efra, sampling_rate, keyframe_at_end);
+	sampleMain(scene, atm_type, for_opensim);
+}
+
+std::vector<FCurve *> *AnimationCurveCache::getSampledCurves(Object *ob)
+{
+	std::map<Object *, std::vector<FCurve *>>::iterator fcurves;
+	fcurves = cached_curves.find(ob);
+	return (fcurves == cached_curves.end()) ? NULL : &fcurves->second;
+}
+


@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list