[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [37488] branches/soc-2011-pepper/source/ blender/collada: New Animation Import system.
Sukhitha Jayathilake
pr.jayathilake at gmail.com
Tue Jun 14 22:42:01 CEST 2011
Revision: 37488
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=37488
Author: phabtar
Date: 2011-06-14 20:42:01 +0000 (Tue, 14 Jun 2011)
Log Message:
-----------
New Animation Import system. Only Mesh object animation import support implemented for now.
Modified Paths:
--------------
branches/soc-2011-pepper/source/blender/collada/AnimationExporter.cpp
branches/soc-2011-pepper/source/blender/collada/AnimationExporter.h
branches/soc-2011-pepper/source/blender/collada/AnimationImporter.cpp
branches/soc-2011-pepper/source/blender/collada/AnimationImporter.h
branches/soc-2011-pepper/source/blender/collada/DocumentImporter.cpp
Modified: branches/soc-2011-pepper/source/blender/collada/AnimationExporter.cpp
===================================================================
--- branches/soc-2011-pepper/source/blender/collada/AnimationExporter.cpp 2011-06-14 19:11:01 UTC (rev 37487)
+++ branches/soc-2011-pepper/source/blender/collada/AnimationExporter.cpp 2011-06-14 20:42:01 UTC (rev 37488)
@@ -57,7 +57,8 @@
if (!ob->adt || !ob->adt->action) return; //this is already checked in hasAnimations()
FCurve *fcu = (FCurve*)ob->adt->action->curves.first;
char * transformName = extract_transform_name( fcu->rna_path );
-
+
+
//if (ob->type == OB_ARMATURE) {
// if (!ob->data) return;
// bArmature *arm = (bArmature*)ob->data;
@@ -74,17 +75,46 @@
//else {
while (fcu) {
transformName = extract_transform_name( fcu->rna_path );
- printf("fcu -> rna _path : %s \n transformName : %s\n", fcu->rna_path, transformName);
+
if ((!strcmp(transformName, "location") || !strcmp(transformName, "scale")) ||
(!strcmp(transformName, "rotation_euler") && ob->rotmode == ROT_MODE_EUL)||
(!strcmp(transformName, "rotation_quaternion")))
- dae_animation(ob ,fcu,/* id_name(ob),*/ transformName);
+ dae_animation(ob ,fcu, transformName );
fcu = fcu->next;
}
//}
}
+ /*float * AnimationExporter::get_eul_source_for_quat(Object *ob )
+ {
+ FCurve *fcu = (FCurve*)ob->adt->action->curves.first;
+ const int keys = fcu->totvert;
+ float quat[keys][4];
+ float eul[keys][3];
+ while(fcu)
+ {
+ transformName = extract_transform_name( fcu->rna_path );
+
+ if( !strcmp(transformName, "rotation_quaternion") )
+ {
+ for ( int i = 0 ; i < fcu->totvert ; i+=)
+ {
+ quat[i][fcu->array_index] = fcu->bezt[i].vec[1][1];
+ }
+ }
+
+ fcu = fcu->next;
+ }
+
+ for ( int i = 0 ; i < fcu->totvert ; i+=)
+ {
+ quat_to_eul(eul[i],quat[i]);
+ }
+
+ return eul;
+
+ }*/
std::string AnimationExporter::getObjectBoneName( Object* ob,const FCurve* fcu )
{
//hard-way to derive the bone name from rna_path. Must find more compact method
@@ -99,16 +129,18 @@
return id_name(ob);
}
- void AnimationExporter::dae_animation(Object* ob, FCurve *fcu/*, std::string ob_name*/ , char* transformName)
+ void AnimationExporter::dae_animation(Object* ob, FCurve *fcu/*, std::string ob_name*/ , char* transformName )
{
- printf("in dae animation\n");
+
const char *axis_name = NULL;
char anim_id[200];
bool has_tangents = false;
+ bool quatRotation = false;
if ( !strcmp(transformName, "rotation_quaternion") )
{
- const char *axis_names[] = {"W", "X", "Y", "Z"};
+ //quatRotation = true;
+ const char *axis_names[] = {"", "X", "Y", "Z"};
if (fcu->array_index < 4)
axis_name = axis_names[fcu->array_index];
}
@@ -118,8 +150,6 @@
const char *axis_names[] = {"X", "Y", "Z"};
if (fcu->array_index < 3)
axis_name = axis_names[fcu->array_index];
-
-
}
std::string ob_name = std::string("null");
if (ob->type == OB_ARMATURE)
@@ -377,7 +407,7 @@
float AnimationExporter::convert_angle(float angle)
{
- return COLLADABU::Math::Utils::radToDegF(angle);
+ return COLLADABU::Math::Utils::degToRadF(angle);
}
std::string AnimationExporter::get_semantic_suffix(COLLADASW::InputSemantic::Semantics semantic)
@@ -414,7 +444,7 @@
if (axis) {
param.push_back(axis);
}
- else { //assumes if axis isn't specified all axi are added
+ else { //assumes if axis isn't specified all axises are added
param.push_back("X");
param.push_back("Y");
param.push_back("Z");
@@ -440,12 +470,12 @@
break;
case COLLADASW::InputSemantic::OUTPUT:
*length = 1;
- if (rotation) {
+ /*if (rotation) {
values[0] = convert_angle(bezt->vec[1][1]);
}
- else {
+ else {*/
values[0] = bezt->vec[1][1];
- }
+ //}
break;
case COLLADASW::InputSemantic::IN_TANGENT:
@@ -454,12 +484,13 @@
if (bezt->ipo != BEZT_IPO_BEZ) {
// We're in a mixed interpolation scenario, set zero as it's irrelevant but value might contain unused data
values[0] = 0;
- values[1] = 0;
- } else if (rotation) {
+ values[1] = 0;
+ }
+ /* else if (rotation) {
values[1] = convert_angle(bezt->vec[0][1]);
- } else {
+ } else {*/
values[1] = bezt->vec[0][1];
- }
+ //}
break;
case COLLADASW::InputSemantic::OUT_TANGENT:
@@ -469,11 +500,12 @@
// We're in a mixed interpolation scenario, set zero as it's irrelevant but value might contain unused data
values[0] = 0;
values[1] = 0;
- } else if (rotation) {
+ }
+ /* else if (rotation) {
values[1] = convert_angle(bezt->vec[2][1]);
- } else {
+ } else {*/
values[1] = bezt->vec[2][1];
- }
+ //}
break;
break;
default:
@@ -516,9 +548,8 @@
for (unsigned int i = 0; i < fcu->totvert; i++) {
float values[3]; // be careful!
int length = 0;
-
get_source_values(&fcu->bezt[i], semantic, is_rotation, values, &length);
- for (int j = 0; j < length; j++)
+ for (int j = 0; j < length; j++)
source.appendValues(values[j]);
}
@@ -526,6 +557,7 @@
return source_id;
}
+
//Currently called only to get OUTPUT source values ( if rotation and hence the axis is also specified )
std::string AnimationExporter::create_source_from_array(COLLADASW::InputSemantic::Semantics semantic, float *v, int tot, bool is_rot, const std::string& anim_id, const char *axis_name)
{
@@ -676,7 +708,7 @@
std::string AnimationExporter::get_transform_sid(char *rna_path, int tm_type, const char *axis_name, bool append_axis)
{
std::string tm_name;
-
+ bool is_rotation =false;
// when given rna_path, determine tm_type from it
if (rna_path) {
char *name = extract_transform_name(rna_path);
@@ -695,9 +727,10 @@
switch (tm_type) {
case 0:
- return std::string("rotation_euler.") + std::string(axis_name) + ".ANGLE";
case 1:
- return std::string("rotation_quaternion.") + std::string(axis_name) + ".ANGLE";
+ tm_name = "rotation";
+ is_rotation = true;
+ break;
case 2:
tm_name = "scale";
break;
@@ -710,8 +743,8 @@
}
if (tm_name.size()) {
- if (append_axis)
- return tm_name + std::string(".") + std::string(axis_name);
+ if (is_rotation)
+ return tm_name + std::string(axis_name);
else
return tm_name;
}
Modified: branches/soc-2011-pepper/source/blender/collada/AnimationExporter.h
===================================================================
--- branches/soc-2011-pepper/source/blender/collada/AnimationExporter.h 2011-06-14 19:11:01 UTC (rev 37487)
+++ branches/soc-2011-pepper/source/blender/collada/AnimationExporter.h 2011-06-14 20:42:01 UTC (rev 37488)
@@ -111,7 +111,11 @@
COLLADASW::InputSemantic::Semantics semantic, bool is_rot, const char *axis);
void get_source_values(BezTriple *bezt, COLLADASW::InputSemantic::Semantics semantic, bool rotation, float *values, int *length);
+
+ /*float * get_eul_source_for_quat(Object *ob );*/
+ /*std::string create_source_from_array(COLLADASW::InputSemantic::Semantics semantic, float *v, int tot, const std::string& anim_id, int array_index);*/
+
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_array(COLLADASW::InputSemantic::Semantics semantic, float *v, int tot, bool is_rot, const std::string& anim_id, const char *axis_name);
Modified: branches/soc-2011-pepper/source/blender/collada/AnimationImporter.cpp
===================================================================
--- branches/soc-2011-pepper/source/blender/collada/AnimationImporter.cpp 2011-06-14 19:11:01 UTC (rev 37487)
+++ branches/soc-2011-pepper/source/blender/collada/AnimationImporter.cpp 2011-06-14 20:42:01 UTC (rev 37488)
@@ -89,12 +89,15 @@
{
COLLADAFW::FloatOrDoubleArray& input = curve->getInputValues();
COLLADAFW::FloatOrDoubleArray& output = curve->getOutputValues();
- // COLLADAFW::FloatOrDoubleArray& intan = curve->getInTangentValues();
- // COLLADAFW::FloatOrDoubleArray& outtan = curve->getOutTangentValues();
+
+ if( curve->getInterpolationType() == COLLADAFW::AnimationCurve::INTERPOLATION_BEZIER ) {
+ 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) {
@@ -108,28 +111,42 @@
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();
+ 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... */
+ if( curve->getInterpolationType() == COLLADAFW::AnimationCurve::INTERPOLATION_BEZIER )
+ {
+ COLLADAFW::FloatOrDoubleArray& intan = curve->getInTangentValues();
+ COLLADAFW::FloatOrDoubleArray& outtan = curve->getOutTangentValues();
+
+ // intangent
+ bez.vec[0][0] = bc_get_float_value(intan, (j * 2 * dim ) + (2 * i)) * fps;
+ bez.vec[0][1] = bc_get_float_value(intan, (j * 2 * dim )+ (2 * i) + 1);
+
+ // outtangent
+ bez.vec[2][0] = bc_get_float_value(outtan, (j * 2 * dim ) + (2 * i)) * fps;
+ bez.vec[2][1] = bc_get_float_value(outtan, (j * 2 * dim )+ (2 * i) + 1);
+ bez.ipo = BEZT_IPO_BEZ;
+ //bez.h1 = bez.h2 = HD_AUTO;
+ }
+ else
+ {
+ bez.h1 = bez.h2 = HD_AUTO;
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list