[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [32309] trunk/blender/source/blender: Reorganisation of COLLADA import code.
Nathan Letwory
nathan at letworyinteractive.com
Tue Oct 5 02:05:14 CEST 2010
Revision: 32309
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=32309
Author: jesterking
Date: 2010-10-05 02:05:14 +0200 (Tue, 05 Oct 2010)
Log Message:
-----------
Reorganisation of COLLADA import code. Classes have been split into their own files.
No functional changes.
Where necessary extern "C" {} blocks have been added.
Modified Paths:
--------------
trunk/blender/source/blender/blenkernel/BKE_context.h
trunk/blender/source/blender/blenkernel/BKE_depsgraph.h
trunk/blender/source/blender/blenkernel/BKE_fcurve.h
trunk/blender/source/blender/blenkernel/BKE_library.h
trunk/blender/source/blender/blenkernel/BKE_main.h
trunk/blender/source/blender/blenkernel/BKE_scene.h
trunk/blender/source/blender/blenkernel/BKE_texture.h
trunk/blender/source/blender/collada/DocumentExporter.cpp
trunk/blender/source/blender/collada/DocumentExporter.h
trunk/blender/source/blender/collada/DocumentImporter.cpp
trunk/blender/source/blender/collada/DocumentImporter.h
trunk/blender/source/blender/collada/collada.cpp
trunk/blender/source/blender/collada/collada_internal.h
trunk/blender/source/blender/editors/include/ED_armature.h
trunk/blender/source/blender/editors/include/ED_keyframing.h
trunk/blender/source/blender/editors/include/ED_mesh.h
trunk/blender/source/blender/editors/include/ED_object.h
trunk/blender/source/blender/makesdna/DNA_customdata_types.h
trunk/blender/source/blender/makesdna/DNA_texture_types.h
trunk/blender/source/blender/makesdna/DNA_userdef_types.h
trunk/blender/source/blender/makesrna/intern/rna_screen.c
trunk/blender/source/blender/windowmanager/WM_api.h
trunk/blender/source/blender/windowmanager/WM_types.h
Added Paths:
-----------
trunk/blender/source/blender/collada/AnimationImporter.cpp
trunk/blender/source/blender/collada/AnimationImporter.h
trunk/blender/source/blender/collada/ArmatureImporter.cpp
trunk/blender/source/blender/collada/ArmatureImporter.h
trunk/blender/source/blender/collada/MeshImporter.cpp
trunk/blender/source/blender/collada/MeshImporter.h
trunk/blender/source/blender/collada/SkinInfo.cpp
trunk/blender/source/blender/collada/SkinInfo.h
trunk/blender/source/blender/collada/TransformReader.cpp
trunk/blender/source/blender/collada/TransformReader.h
trunk/blender/source/blender/collada/collada_utils.cpp
trunk/blender/source/blender/collada/collada_utils.h
Modified: trunk/blender/source/blender/blenkernel/BKE_context.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_context.h 2010-10-04 23:52:53 UTC (rev 32308)
+++ trunk/blender/source/blender/blenkernel/BKE_context.h 2010-10-05 00:05:14 UTC (rev 32309)
@@ -28,13 +28,13 @@
#ifndef BKE_CONTEXT_H
#define BKE_CONTEXT_H
+#include "DNA_listBase.h"
+#include "RNA_types.h"
+
#ifdef __cplusplus
extern "C" {
#endif
-#include "DNA_listBase.h"
-#include "RNA_types.h"
-
struct ARegion;
struct bScreen;
struct EditMesh;
Modified: trunk/blender/source/blender/blenkernel/BKE_depsgraph.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_depsgraph.h 2010-10-04 23:52:53 UTC (rev 32308)
+++ trunk/blender/source/blender/blenkernel/BKE_depsgraph.h 2010-10-05 00:05:14 UTC (rev 32309)
@@ -28,6 +28,10 @@
#ifndef DEPSGRAPH_API
#define DEPSGRAPH_API
+#ifdef __cplusplus
+extern "C" {
+#endif
+
/*
#define DEPS_DEBUG
*/
@@ -120,5 +124,9 @@
/* callback for editors module to do updates */
void DAG_editors_update_cb(void (*func)(struct Main *bmain, struct ID *id));
+
+#ifdef __cplusplus
+}
+#endif
#endif
Modified: trunk/blender/source/blender/blenkernel/BKE_fcurve.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_fcurve.h 2010-10-04 23:52:53 UTC (rev 32308)
+++ trunk/blender/source/blender/blenkernel/BKE_fcurve.h 2010-10-05 00:05:14 UTC (rev 32309)
@@ -28,6 +28,10 @@
#ifndef BKE_FCURVE_H
#define BKE_FCURVE_H
+#ifdef __cplusplus
+extern "C" {
+#endif
+
struct FCurve;
struct FModifier;
struct ChannelDriver;
@@ -248,4 +252,8 @@
*/
void fcurve_store_samples(struct FCurve *fcu, void *data, int start, int end, FcuSampleFunc sample_cb);
+#ifdef __cplusplus
+}
+#endif
+
#endif /* BKE_FCURVE_H*/
Modified: trunk/blender/source/blender/blenkernel/BKE_library.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_library.h 2010-10-04 23:52:53 UTC (rev 32308)
+++ trunk/blender/source/blender/blenkernel/BKE_library.h 2010-10-05 00:05:14 UTC (rev 32309)
@@ -33,6 +33,10 @@
#ifndef BKE_LIBRARY_TYPES_H
#define BKE_LIBRARY_TYPES_H
+#ifdef __cplusplus
+extern "C" {
+#endif
+
struct ListBase;
struct ID;
struct Main;
@@ -85,4 +89,8 @@
/* use when "" is given to new_id() */
#define ID_FALLBACK_NAME "Untitled"
+#ifdef __cplusplus
+}
#endif
+
+#endif
Modified: trunk/blender/source/blender/blenkernel/BKE_main.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_main.h 2010-10-04 23:52:53 UTC (rev 32308)
+++ trunk/blender/source/blender/blenkernel/BKE_main.h 2010-10-05 00:05:14 UTC (rev 32309)
@@ -40,6 +40,10 @@
#include "DNA_listBase.h"
+#ifdef __cplusplus
+extern "C" {
+#endif
+
struct Library;
typedef struct Main {
@@ -80,5 +84,9 @@
} Main;
+#ifdef __cplusplus
+}
#endif
+#endif
+
Modified: trunk/blender/source/blender/blenkernel/BKE_scene.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_scene.h 2010-10-04 23:52:53 UTC (rev 32308)
+++ trunk/blender/source/blender/blenkernel/BKE_scene.h 2010-10-05 00:05:14 UTC (rev 32309)
@@ -31,6 +31,10 @@
#ifndef BKE_SCENE_H
#define BKE_SCENE_H
+#ifdef __cplusplus
+extern "C" {
+#endif
+
struct AviCodecData;
struct Base;
struct bglMats;
@@ -93,5 +97,9 @@
int get_render_shadow_samples(struct RenderData *r, int samples);
float get_render_aosss_error(struct RenderData *r, float error);
+#ifdef __cplusplus
+}
#endif
+#endif
+
Modified: trunk/blender/source/blender/blenkernel/BKE_texture.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_texture.h 2010-10-04 23:52:53 UTC (rev 32308)
+++ trunk/blender/source/blender/blenkernel/BKE_texture.h 2010-10-05 00:05:14 UTC (rev 32309)
@@ -31,6 +31,10 @@
#ifndef BKE_TEXTURE_H
#define BKE_TEXTURE_H
+#ifdef __cplusplus
+extern "C" {
+#endif
+
struct bNode;
struct Brush;
struct ColorBand;
@@ -112,5 +116,9 @@
int BKE_texture_dependsOnTime(const struct Tex *texture);
+#ifdef __cplusplus
+}
#endif
+#endif
+
Added: trunk/blender/source/blender/collada/AnimationImporter.cpp
===================================================================
--- trunk/blender/source/blender/collada/AnimationImporter.cpp (rev 0)
+++ trunk/blender/source/blender/collada/AnimationImporter.cpp 2010-10-05 00:05:14 UTC (rev 32309)
@@ -0,0 +1,1149 @@
+/**
+ * $Id: DocumentImporter.cpp 32235 2010-10-01 19:46:42Z jesterking $
+ *
+ * ***** 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, Nathan Letwory.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#include "DNA_armature_types.h"
+
+#include "ED_keyframing.h"
+
+#include "BLI_listbase.h"
+#include "BLI_math.h"
+#include "BLI_path_util.h"
+#include "BLI_string.h"
+
+#include "BKE_action.h"
+#include "BKE_armature.h"
+#include "BKE_fcurve.h"
+#include "BKE_object.h"
+
+#include "MEM_guardedalloc.h"
+
+#include "collada_utils.h"
+#include "AnimationImporter.h"
+#include "ArmatureImporter.h"
+
+#include <algorithm>
+
+// use this for retrieving bone names, since these must be unique
+template<class T>
+static const char *bc_get_joint_name(T *node)
+{
+ const std::string& id = node->getOriginalId();
+ return id.size() ? id.c_str() : node->getName().c_str();
+}
+
+FCurve *AnimationImporter::create_fcurve(int array_index, const char *rna_path)
+{
+ FCurve *fcu = (FCurve*)MEM_callocN(sizeof(FCurve), "FCurve");
+
+ fcu->flag = (FCURVE_VISIBLE|FCURVE_AUTO_HANDLES|FCURVE_SELECTED);
+ fcu->rna_path = BLI_strdupn(rna_path, strlen(rna_path));
+ fcu->array_index = array_index;
+ return fcu;
+}
+
+void AnimationImporter::create_bezt(FCurve *fcu, float frame, float output)
+{
+ BezTriple bez;
+ memset(&bez, 0, sizeof(BezTriple));
+ bez.vec[1][0] = frame;
+ bez.vec[1][1] = output;
+ bez.ipo = U.ipo_new; /* use default interpolation mode here... */
+ bez.f1 = bez.f2 = bez.f3 = SELECT;
+ bez.h1 = bez.h2 = HD_AUTO;
+ insert_bezt_fcurve(fcu, &bez, 0);
+ calchandles_fcurve(fcu);
+}
+
+// create one or several fcurves depending on the number of parameters being animated
+void AnimationImporter::animation_to_fcurves(COLLADAFW::AnimationCurve *curve)
+{
+ COLLADAFW::FloatOrDoubleArray& input = curve->getInputValues();
+ COLLADAFW::FloatOrDoubleArray& output = curve->getOutputValues();
+ // COLLADAFW::FloatOrDoubleArray& intan = curve->getInTangentValues();
+ // COLLADAFW::FloatOrDoubleArray& outtan = curve->getOutTangentValues();
+ float fps = (float)FPS;
+ size_t dim = curve->getOutDimension();
+ unsigned int i;
+
+ std::vector<FCurve*>& fcurves = curve_map[curve->getUniqueId()];
+
+ switch (dim) {
+ case 1: // X, Y, Z or angle
+ case 3: // XYZ
+ case 16: // matrix
+ {
+ for (i = 0; i < dim; i++ ) {
+ FCurve *fcu = (FCurve*)MEM_callocN(sizeof(FCurve), "FCurve");
+
+ fcu->flag = (FCURVE_VISIBLE|FCURVE_AUTO_HANDLES|FCURVE_SELECTED);
+ // fcu->rna_path = BLI_strdupn(path, strlen(path));
+ fcu->array_index = 0;
+ //fcu->totvert = curve->getKeyCount();
+
+ // create beztriple for each key
+ for (unsigned int j = 0; j < curve->getKeyCount(); j++) {
+ BezTriple bez;
+ memset(&bez, 0, sizeof(BezTriple));
+
+ // intangent
+ // bez.vec[0][0] = get_float_value(intan, j * 6 + i + i) * fps;
+ // bez.vec[0][1] = get_float_value(intan, j * 6 + i + i + 1);
+
+ // input, output
+ bez.vec[1][0] = bc_get_float_value(input, j) * fps;
+ bez.vec[1][1] = bc_get_float_value(output, j * dim + i);
+
+ // outtangent
+ // bez.vec[2][0] = get_float_value(outtan, j * 6 + i + i) * fps;
+ // bez.vec[2][1] = get_float_value(outtan, j * 6 + i + i + 1);
+
+ bez.ipo = U.ipo_new; /* use default interpolation mode here... */
+ bez.f1 = bez.f2 = bez.f3 = SELECT;
+ bez.h1 = bez.h2 = HD_AUTO;
+ insert_bezt_fcurve(fcu, &bez, 0);
+ }
+
+ calchandles_fcurve(fcu);
+
+ fcurves.push_back(fcu);
+ }
+ }
+ break;
+ default:
+ fprintf(stderr, "Output dimension of %d is not yet supported (animation id = %s)\n", dim, curve->getOriginalId().c_str());
+ }
+
+ for (std::vector<FCurve*>::iterator it = fcurves.begin(); it != fcurves.end(); it++)
+ unused_curves.push_back(*it);
+}
+
+void AnimationImporter::fcurve_deg_to_rad(FCurve *cu)
+{
+ for (unsigned int i = 0; i < cu->totvert; i++) {
+ // TODO convert handles too
+ cu->bezt[i].vec[1][1] *= M_PI / 180.0f;
+ }
+}
+
+void AnimationImporter::add_fcurves_to_object(Object *ob, std::vector<FCurve*>& curves, char *rna_path, int array_index, Animation *animated)
+{
+ bAction *act;
+
+ if (!ob->adt || !ob->adt->action) act = verify_adt_action((ID*)&ob->id, 1);
+ else act = ob->adt->action;
+
+ std::vector<FCurve*>::iterator it;
+ int i;
+
+#if 0
+ char *p = strstr(rna_path, "rotation_euler");
+ bool is_rotation = p && *(p + strlen("rotation_euler")) == '\0';
+
+ // convert degrees to radians for rotation
+ if (is_rotation)
+ fcurve_deg_to_rad(fcu);
+#endif
+
+ for (it = curves.begin(), i = 0; it != curves.end(); it++, i++) {
+ FCurve *fcu = *it;
+ fcu->rna_path = BLI_strdupn(rna_path, strlen(rna_path));
+
+ if (array_index == -1) fcu->array_index = i;
+ else fcu->array_index = array_index;
+
+ if (ob->type == OB_ARMATURE) {
+ bActionGroup *grp = NULL;
+ const char *bone_name = bc_get_joint_name(animated->node);
+
+ if (bone_name) {
+ /* try to find group */
+ grp = action_groups_find_named(act, bone_name);
+
+ /* no matching groups, so add one */
+ if (grp == NULL) {
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list