Finalizing.

This commit is contained in:
2011-08-16 16:03:37 +00:00
parent 87efb89901
commit f04fb5b6ea
7 changed files with 115 additions and 60 deletions

View File

@@ -61,13 +61,14 @@ void AnimationExporter::exportAnimations(Scene *sce)
bool isMatAnim = false;
if(ob->adt && ob->adt->action)
{
if ( ob->type == OB_ARMATURE )
//transform matrix export for bones are temporarily disabled here.
/*if ( ob->type == OB_ARMATURE )
{
bArmature *arm = (bArmature*)ob->data;
for (Bone *bone = (Bone*)arm->bonebase.first; bone; bone = bone->next)
bake_bone_animation(ob, bone);
}
}*/
fcu = (FCurve*)ob->adt->action->curves.first;
while (fcu) {
transformName = extract_transform_name( fcu->rna_path );
@@ -988,8 +989,7 @@ void AnimationExporter::exportAnimations(Scene *sce)
std::string AnimationExporter::get_light_param_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
// when given rna_path, determine tm_type from it
if (rna_path) {
char *name = extract_transform_name(rna_path);
@@ -1033,6 +1033,57 @@ void AnimationExporter::exportAnimations(Scene *sce)
return std::string("");
}
std::string AnimationExporter::get_camera_param_sid(char *rna_path, int tm_type, const char *axis_name, bool append_axis)
{
std::string tm_name;
// when given rna_path, determine tm_type from it
if (rna_path) {
char *name = extract_transform_name(rna_path);
if (!strcmp(name, "lens"))
tm_type = 0;
else if (!strcmp(name, "ortho_scale"))
tm_type = 1;
else if (!strcmp(name, "clip_end"))
tm_type = 2;
else if (!strcmp(name, "clip_start"))
tm_type = 3;
else
tm_type = -1;
}
switch (tm_type) {
case 0:
tm_name = "xfov";
break;
case 1:
tm_name = "xmag";
break;
case 2:
tm_name = "zfar";
break;
case 3:
tm_name = "znear";
break;
default:
tm_name = "";
break;
}
if (tm_name.size()) {
if (axis_name != "")
return tm_name + "." + std::string(axis_name);
else
return tm_name;
}
return std::string("");
}
// Assign sid of the animated parameter or transform
// for rotation, axis name is always appended and the value of append_axis is ignored
std::string AnimationExporter::get_transform_sid(char *rna_path, int tm_type, const char *axis_name, bool append_axis)
{
@@ -1137,6 +1188,7 @@ void AnimationExporter::exportAnimations(Scene *sce)
return dot ? (dot + 1) : rna_path;
}
//find keyframes of all the objects animations
void AnimationExporter::find_frames(Object *ob, std::vector<float> &fra)
{
FCurve *fcu= (FCurve*)ob->adt->action->curves.first;
@@ -1154,38 +1206,7 @@ void AnimationExporter::exportAnimations(Scene *sce)
std::sort(fra.begin(), fra.end());
}
void AnimationExporter::find_frames(Object *ob, std::vector<float> &fra, const char *prefix, const char *tm_name)
{
FCurve *fcu= (FCurve*)ob->adt->action->curves.first;
for (; fcu; fcu = fcu->next) {
if (prefix && strncmp(prefix, fcu->rna_path, strlen(prefix)))
continue;
char *name = extract_transform_name(fcu->rna_path);
if (!strcmp(name, tm_name)) {
for (unsigned int i = 0; i < fcu->totvert; i++) {
float f = fcu->bezt[i].vec[1][0]; //
if (std::find(fra.begin(), fra.end(), f) == fra.end())
fra.push_back(f);
}
}
}
// keep the keys in ascending order
std::sort(fra.begin(), fra.end());
}
void AnimationExporter::find_rotation_frames(Object *ob, std::vector<float> &fra, const char *prefix, int rotmode)
{
if (rotmode > 0)
find_frames(ob, fra, prefix, "rotation_euler");
else if (rotmode == ROT_MODE_QUAT)
find_frames(ob, fra, prefix, "rotation_quaternion");
/*else if (rotmode == ROT_MODE_AXISANGLE)
;*/
}
// enable fcurves driving a specific bone, disable all the rest
// if bone_name = NULL enable all fcurves
@@ -1218,13 +1239,17 @@ void AnimationExporter::exportAnimations(Scene *sce)
Object *ob = base->object;
FCurve *fcu = 0;
//Check for object transform animations
if(ob->adt && ob->adt->action)
fcu = (FCurve*)ob->adt->action->curves.first;
//Check for Lamp parameter animations
else if( (ob->type == OB_LAMP ) && ((Lamp*)ob ->data)->adt && ((Lamp*)ob ->data)->adt->action )
fcu = (FCurve*)(((Lamp*)ob ->data)->adt->action->curves.first);
//Check for Camera parameter animations
else if( (ob->type == OB_CAMERA ) && ((Camera*)ob ->data)->adt && ((Camera*)ob ->data)->adt->action )
fcu = (FCurve*)(((Camera*)ob ->data)->adt->action->curves.first);
//Check Material Effect parameter animations.
for(int a = 0; a < ob->totcol; a++)
{
Material *ma = give_current_material(ob, a+1);
@@ -1240,3 +1265,36 @@ void AnimationExporter::exportAnimations(Scene *sce)
}
return false;
}
//------------------------------- Not used in the new system.--------------------------------------------------------
void AnimationExporter::find_rotation_frames(Object *ob, std::vector<float> &fra, const char *prefix, int rotmode)
{
if (rotmode > 0)
find_frames(ob, fra, prefix, "rotation_euler");
else if (rotmode == ROT_MODE_QUAT)
find_frames(ob, fra, prefix, "rotation_quaternion");
/*else if (rotmode == ROT_MODE_AXISANGLE)
;*/
}
void AnimationExporter::find_frames(Object *ob, std::vector<float> &fra, const char *prefix, const char *tm_name)
{
FCurve *fcu= (FCurve*)ob->adt->action->curves.first;
for (; fcu; fcu = fcu->next) {
if (prefix && strncmp(prefix, fcu->rna_path, strlen(prefix)))
continue;
char *name = extract_transform_name(fcu->rna_path);
if (!strcmp(name, tm_name)) {
for (unsigned int i = 0; i < fcu->totvert; i++) {
float f = fcu->bezt[i].vec[1][0]; //
if (std::find(fra.begin(), fra.end(), f) == fra.end())
fra.push_back(f);
}
}
}
// keep the keys in ascending order
std::sort(fra.begin(), fra.end());
}

View File

@@ -143,7 +143,7 @@ protected:
// 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_frames(Object *ob, std::vector<float> &fra, const char *prefix, const char *tm_name);
void find_frames(Object *ob, std::vector<float> &fra);

View File

@@ -17,7 +17,7 @@
* 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.
* Contributor(s): Chingiz Dyussenov, Arystanbek Dyussenov, Nathan Letwory, Sukhitha Jayathilake.
*
* ***** END GPL LICENSE BLOCK *****
*/

View File

@@ -17,7 +17,7 @@
* 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.
* Contributor(s): Chingiz Dyussenov, Arystanbek Dyussenov, Nathan Letwory , Sukhitha Jayathilake.
*
* ***** END GPL LICENSE BLOCK *****
*/

View File

@@ -224,7 +224,7 @@ void ArmatureExporter::add_bone_transform(Object *ob_arm, Bone *bone, COLLADASW:
mul_m4_m4m4(mat, pchan->pose_mat, ob_arm->obmat);
}
TransformWriter::add_node_transform(node, mat, NULL);
TransformWriter::add_node_transform(node, mat,NULL );
}
std::string ArmatureExporter::get_controller_id(Object *ob_arm, Object *ob)

View File

@@ -17,7 +17,7 @@
* 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.
* Contributor(s): Chingiz Dyussenov, Arystanbek Dyussenov, Nathan Letwory, Sukhitha jayathilake.
*
* ***** END GPL LICENSE BLOCK *****
*/
@@ -37,6 +37,7 @@
#include "BKE_action.h"
#include "BKE_depsgraph.h"
#include "BKE_object.h"
#include "BKE_armature.h"
#include "BLI_string.h"
#include "ED_armature.h"
@@ -97,28 +98,21 @@ void ArmatureImporter::create_unskinned_bone( COLLADAFW::Node *node, EditBone *p
if (parent) bone->parent = parent;
float ax[3];
float angle = NULL;
float angle = 0;
// get world-space
if (parent){
mul_m4_m4m4(mat, obmat, parent_mat);
bPoseChannel *parchan = get_pose_channel(ob_arm->pose, parent->name);
if ( parchan && pchan)
mul_m4_m4m4(pchan->pose_mat, mat , parchan->pose_mat);
mat4_to_axis_angle(ax,&angle,mat);
bone->roll = angle;
}
else {
copy_m4_m4(mat, obmat);
float invObmat[4][4];
invert_m4_m4(invObmat, ob_arm->obmat);
if(pchan)
mul_m4_m4m4(pchan->pose_mat, mat, invObmat);
mat4_to_axis_angle(ax,&angle,mat);
bone->roll = angle;
}
}
float loc[3], size[3], rot[3][3];
mat4_to_loc_rot_size( loc, rot, size, obmat);
mat3_to_vec_roll(rot, NULL, &angle );
bone->roll=angle;
// set head
copy_v3_v3(bone->head, mat[3]);
@@ -130,10 +124,10 @@ void ArmatureImporter::create_unskinned_bone( COLLADAFW::Node *node, EditBone *p
// set parent tail
if (parent && totchild == 1) {
copy_v3_v3(parent->tail, bone->head);
// not setting BONE_CONNECTED because this would lock child bone location with respect to parent
// bone->flag |= BONE_CONNECTED;
// XXX increase this to prevent "very" small bones?
const float epsilon = 0.000001f;

View File

@@ -410,15 +410,18 @@ void DocumentImporter::write_node (COLLADAFW::Node *node, COLLADAFW::Node *paren
while (geom_done < geom.getCount()) {
ob = mesh_importer.create_mesh_object(node, geom[geom_done], false, uid_material_map,
material_texture_mapping_map);
++geom_done;
if ( ob != NULL )
++geom_done;
}
while (camera_done < camera.getCount()) {
ob = create_camera_object(camera[camera_done], sce);
++camera_done;
if ( ob != NULL )
++camera_done;
}
while (lamp_done < lamp.getCount()) {
ob = create_lamp_object(lamp[lamp_done], sce);
++lamp_done;
if ( ob != NULL )
++lamp_done;
}
while (controller_done < controller.getCount()) {
COLLADAFW::InstanceGeometry *geom = (COLLADAFW::InstanceGeometry*)controller[controller_done];