[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [22455] branches/soc-2009-chingachgook/ source/blender/collada: Importer:
Chingiz Dyussenov
chingiz.ds at gmail.com
Fri Aug 14 19:12:04 CEST 2009
Revision: 22455
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=22455
Author: chingachgook
Date: 2009-08-14 19:12:04 +0200 (Fri, 14 Aug 2009)
Log Message:
-----------
Importer:
* Converts euler rotation to quaternion for bone animation.
Modified Paths:
--------------
branches/soc-2009-chingachgook/source/blender/collada/DocumentExporter.cpp
branches/soc-2009-chingachgook/source/blender/collada/DocumentImporter.cpp
Modified: branches/soc-2009-chingachgook/source/blender/collada/DocumentExporter.cpp
===================================================================
--- branches/soc-2009-chingachgook/source/blender/collada/DocumentExporter.cpp 2009-08-14 16:25:59 UTC (rev 22454)
+++ branches/soc-2009-chingachgook/source/blender/collada/DocumentExporter.cpp 2009-08-14 17:12:04 UTC (rev 22455)
@@ -280,7 +280,7 @@
std::string geom_id = get_geometry_id(ob);
// openMesh(geoId, geoName, meshId)
- openMesh(geom_id, "", "");
+ openMesh(geom_id);
// writes <source> for vertex coords
createVertsSource(geom_id, me);
@@ -1129,7 +1129,7 @@
void exportScene(Scene *sce) {
// <library_visual_scenes> <visual_scene>
- openVisualScene(id_name(sce), "");
+ openVisualScene(id_name(sce));
// write <node>s
//forEachMeshObjectInScene(sce, *this);
@@ -1307,7 +1307,7 @@
}
if (find(mImages.begin(), mImages.end(), name) == mImages.end()) {
- COLLADASW::Image img(COLLADABU::URI(COLLADABU::URI::nativePathToUri(rel)), name, "");
+ COLLADASW::Image img(COLLADABU::URI(COLLADABU::URI::nativePathToUri(rel)), name);
img.add(mSW);
mImages.push_back(name);
@@ -1351,7 +1351,7 @@
else if (ma->spec_shader == MA_SPEC_PHONG) {
ep.setShaderType(COLLADASW::EffectProfile::PHONG);
// shininess
- // XXX not sure about this
+ // XXX not sure, stolen this from previous Collada plugin
ep.setShininess(ma->har / 4);
}
else {
@@ -1370,6 +1370,7 @@
// emission
COLLADASW::ColorOrTexture cot = getcol(0.0f, 0.0f, 0.0f, 1.0f);
ep.setEmission(cot);
+ ep.setTransparent(cot);
// diffuse
cot = getcol(ma->r, ma->g, ma->b, 1.0f);
ep.setDiffuse(cot);
@@ -1478,6 +1479,9 @@
if (t->mapto & MAP_REF) {
ep.setReflective(createTexture(ima, uvname, sampler));
}
+ if (t->mapto & MAP_ALPHA) {
+ ep.setTransparent(createTexture(ima, uvname, sampler));
+ }
}
// performs the actual writing
ep.addProfileElements();
@@ -1622,11 +1626,11 @@
addLight(cla);
}
// spot
- // XXX add other params later
else if (la->type == LA_SPOT) {
COLLADASW::SpotLight cla(mSW, la_id, la_name, e);
cla.setColor(col);
cla.setFallOffAngle(la->spotsize);
+ cla.setFallOffExponent(la->spotblend);
cla.setLinearAttenuation(la->att1);
cla.setQuadraticAttenuation(la->att2);
addLight(cla);
Modified: branches/soc-2009-chingachgook/source/blender/collada/DocumentImporter.cpp
===================================================================
--- branches/soc-2009-chingachgook/source/blender/collada/DocumentImporter.cpp 2009-08-14 16:25:59 UTC (rev 22454)
+++ branches/soc-2009-chingachgook/source/blender/collada/DocumentImporter.cpp 2009-08-14 17:12:04 UTC (rev 22455)
@@ -50,6 +50,7 @@
#include "BKE_depsgraph.h"
#include "BLI_util.h"
#include "BKE_displist.h"
+#include "BLI_arithb.h"
}
#include "BKE_armature.h"
#include "BKE_mesh.h"
@@ -160,13 +161,6 @@
typedef std::map<COLLADAFW::TextureMapId, std::vector<MTex*> > TexIndexTextureArrayMap;
-// this is only for ArmatureImporter to "see" MeshImporter::get_object_by_geom_uid
-class MeshImporterBase
-{
-public:
- virtual Object *get_object_by_geom_uid(const COLLADAFW::UniqueId& geom_uid) = 0;
-};
-
class TransformReader : public TransformBase
{
protected:
@@ -255,6 +249,20 @@
}
};
+// only for ArmatureImporter to "see" MeshImporter::get_object_by_geom_uid
+class MeshImporterBase
+{
+public:
+ virtual Object *get_object_by_geom_uid(const COLLADAFW::UniqueId& geom_uid) = 0;
+};
+
+// ditto as above
+class AnimationImporterBase
+{
+public:
+ virtual void change_eul_to_quat(Object *ob, bAction *act) = 0;
+};
+
class ArmatureImporter : private TransformReader
{
private:
@@ -291,6 +299,11 @@
std::map<COLLADAFW::UniqueId, COLLADAFW::Node*> joint_by_uid; // contains all joints
std::vector<COLLADAFW::Node*> root_joints;
+ std::vector<Object*> armature_objects;
+
+ MeshImporterBase *mesh_importer;
+ AnimationImporterBase *anim_importer;
+
// This is used to store data passed in write_controller_data.
// Arrays from COLLADAFW::SkinControllerData lose ownership, so do this class members
// so that arrays don't get freed until we free them explicitly.
@@ -395,7 +408,7 @@
}
// called from write_controller
- void create_armature(const COLLADAFW::SkinController* co, Scene *scene)
+ Object *create_armature(const COLLADAFW::SkinController* co, Scene *scene)
{
ob_arm = add_object(scene, OB_ARMATURE);
@@ -412,6 +425,8 @@
// now we'll be able to get inv bind matrix from joint id
// joint_id_to_joint_index_map[joint_ids[i]] = i;
}
+
+ return ob_arm;
}
bool get_joint_inv_bind_matrix(float inv_bind_mat[][4], COLLADAFW::Node *node)
@@ -528,8 +543,6 @@
};
std::map<COLLADAFW::UniqueId, SkinInfo> skin_by_data_uid; // data UID = skin controller data UID
- MeshImporterBase *mesh_importer;
-
#if 0
JointData *get_joint_data(COLLADAFW::Node *node)
{
@@ -809,8 +822,8 @@
public:
- ArmatureImporter(UnitConverter *conv, MeshImporterBase *imp, Scene *sce) :
- TransformReader(conv), scene(sce), empty(NULL), mesh_importer(imp) {}
+ ArmatureImporter(UnitConverter *conv, MeshImporterBase *mesh, AnimationImporterBase *anim, Scene *sce) :
+ TransformReader(conv), scene(sce), empty(NULL), mesh_importer(mesh), anim_importer(anim) {}
~ArmatureImporter()
{
@@ -936,7 +949,9 @@
return true;
}
- skin_by_data_uid[data_uid].create_armature(co, scene);
+ Object *ob_arm = skin_by_data_uid[data_uid].create_armature(co, scene);
+
+ armature_objects.push_back(ob_arm);
}
// morph controller
else {
@@ -972,6 +987,17 @@
{
BLI_snprintf(joint_path, count, "pose.pose_channels[\"%s\"]", get_joint_name(node));
}
+
+ void fix_animation()
+ {
+ /* Change Euler rotation to Quaternion for bone animation */
+ std::vector<Object*>::iterator it;
+ for (it = armature_objects.begin(); it != armature_objects.end(); it++) {
+ Object *ob = *it;
+ if (!ob || !ob->adt || !ob->adt->action) continue;
+ anim_importer->change_eul_to_quat(ob, ob->adt->action);
+ }
+ }
};
class MeshImporter : public MeshImporterBase
@@ -1506,7 +1532,7 @@
if (texindex_texarray_map.find(texture_index) == texindex_texarray_map.end()) {
fprintf(stderr, "Cannot find texture array by texture index.\n");
- return NULL;
+ return color_texture;
}
std::vector<MTex*> textures = texindex_texarray_map[texture_index];
@@ -1555,15 +1581,14 @@
*color_texture);
}
- // if material has color texture
- if (*color_texture && strlen((*color_texture)->uvname)) {
- // set tface
- if (strcmp(layername, (*color_texture)->uvname) != 0) {
-
- texture_face = (MTFace*)CustomData_get_layer_named(&me->fdata, CD_MTFACE,
- (*color_texture)->uvname);
- strcpy(layername, (*color_texture)->uvname);
- }
+ // set texture face
+ if (*color_texture &&
+ strlen((*color_texture)->uvname) &&
+ strcmp(layername, (*color_texture)->uvname) != 0) {
+
+ texture_face = (MTFace*)CustomData_get_layer_named(&me->fdata, CD_MTFACE,
+ (*color_texture)->uvname);
+ strcpy(layername, (*color_texture)->uvname);
}
MaterialIdPrimitiveArrayMap& mat_prim_map = geom_uid_mat_mapping_map[*geom_uid];
@@ -1582,7 +1607,7 @@
while (i++ < prim.totface) {
prim.mface->mat_nr = mat_index;
prim.mface++;
- // bind image to tface
+ // bind texture images to faces
if (texture_face && (*color_texture)) {
texture_face->mode = TF_TEX;
texture_face->tpage = (Image*)(*color_texture)->tex->ima;
@@ -1694,14 +1719,14 @@
read_faces(mesh, me, new_tris);
- //mesh_calc_normals(me->mvert, me->totvert, me->mface, me->totface, NULL);
+ mesh_calc_normals(me->mvert, me->totvert, me->mface, me->totface, NULL);
return true;
}
};
-class AnimationImporter : private TransformReader
+class AnimationImporter : private TransformReader, public AnimationImporterBase
{
private:
@@ -1710,6 +1735,30 @@
std::map<COLLADAFW::UniqueId, std::vector<FCurve*> > uid_fcurve_map;
std::map<COLLADAFW::UniqueId, TransformReader::Animation> uid_animated_map;
+ std::map<bActionGroup*, std::vector<FCurve*> > fcurves_actionGroup_map;
+
+ FCurve *create_fcurve(int array_index, 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 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);
+ calchandles_fcurve(fcu);
+ }
void make_fcurves_from_animation(COLLADAFW::AnimationCurve *curve,
COLLADAFW::FloatOrDoubleArray& input,
@@ -1728,7 +1777,7 @@
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 (i = 0; i < curve->getKeyCount(); i++) {
@@ -1761,7 +1810,7 @@
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 (int j = 0; j < curve->getKeyCount(); j++) {
@@ -1789,33 +1838,31 @@
}
}
- void add_fcurves_to_object(Object *ob, std::vector<FCurve*>& curves, char *rna_path, int array_index)
+ void add_fcurves_to_object(Object *ob, std::vector<FCurve*>& curves, char *rna_path, int array_index, Animation *animated)
{
ID *id = &ob->id;
bAction *act;
+ bActionGroup *grp = NULL;
+
+ if (!ob->adt || !ob->adt->action) act = verify_adt_action(id, 1);
+ else act = verify_adt_action(id, 0);
- if (!ob->adt || !ob->adt->action)
- act = verify_adt_action(id, 1);
- else
- act = verify_adt_action(id, 0);
-
if (!ob->adt || !ob->adt->action) {
fprintf(stderr, "Cannot create anim data or action for this object. \n");
return;
}
-
+
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list