Added export objects hierarchy.

This commit is contained in:
Chingiz Dyussenov
2009-07-10 06:55:05 +00:00
parent b91492c683
commit edf5200fa1
2 changed files with 106 additions and 11 deletions

View File

@@ -7,6 +7,9 @@
#include "DNA_texture_types.h"
#include "DNA_camera_types.h"
#include "DNA_lamp_types.h"
#include "DNA_anim_types.h"
#include "DNA_action_types.h"
#include "DNA_curve_types.h"
extern "C"
{
@@ -30,6 +33,7 @@ extern "C"
#include <COLLADASWInputList.h>
#include <COLLADASWPrimitves.h>
#include <COLLADASWVertices.h>
#include <COLLADASWLibraryAnimations.h>
#include <COLLADASWLibraryImages.h>
#include <COLLADASWLibraryEffects.h>
#include <COLLADASWImage.h>
@@ -59,6 +63,8 @@ extern "C"
// This function assumes that quat is normalized.
// The following document was used as reference:
// http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/index.htm
void QuatToAxisAngle(float *q, float *axis, float *angle)
{
// quat to axis angle
@@ -109,12 +115,28 @@ std::string id_name(void *id)
// void operator()(Object* ob)
template<class Functor>
void forEachMeshObjectInScene(Scene *sce, Functor &f)
{
Base *base= (Base*) sce->base.first;
while(base) {
Object *ob = base->object;
if (ob->type == OB_MESH && ob->data) {
f(ob);
}
base= base->next;
}
}
template<class Functor>
void forEachObjectWithAnimationInScene(Scene *sce, Functor &f)
{
Base *base= (Base*) sce->base.first;
while(base) {
Object *ob = base->object;
if (ob->type == OB_MESH && ob->data) {
if (ob->adt && ob->data) {
f(ob);
}
base= base->next;
@@ -531,10 +553,11 @@ public:
openVisualScene(id_name(sce), "");
// write <node>s
forEachMeshObjectInScene(sce, *this);
forEachCameraObjectInScene(sce, *this);
forEachLampObjectInScene(sce, *this);
//forEachMeshObjectInScene(sce, *this);
//forEachCameraObjectInScene(sce, *this);
//forEachLampObjectInScene(sce, *this);
exportHierarchy(sce);
// </visual_scene> </library_visual_scenes>
closeVisualScene();
@@ -542,7 +565,9 @@ public:
}
// called for each object
void operator()(Object *ob) {
//void operator()(Object *ob) {
void writeNodes(Object *ob, Scene *sce) {
COLLADASW::Node node(mSW);
std::string ob_name(id_name(ob));
node.start();
@@ -603,9 +628,37 @@ public:
instLa.add();
}
// write node for child object
Base *b = (Base*) sce->base.first;
while(b) {
Object *cob = b->object;
if ((cob->type == OB_MESH || cob->type == OB_CAMERA || cob->type == OB_LAMP) && cob->parent == ob) {
// write node...
writeNodes(cob, sce);
}
b = b->next;
}
node.end();
}
void exportHierarchy(Scene *sce)
{
Base *base= (Base*) sce->base.first;
while(base) {
Object *ob = base->object;
if ((ob->type == OB_MESH || ob->type == OB_CAMERA || ob->type == OB_LAMP) && !ob->parent) {
// write nodes....
writeNodes(ob, sce);
}
base= base->next;
}
}
};
class ImagesExporter: COLLADASW::LibraryImages
@@ -959,6 +1012,46 @@ public:
}
};
class AnimationsExporter: COLLADASW::LibraryAnimations
{
public:
AnimationsExporter(COLLADASW::StreamWriter *sw): COLLADASW::LibraryAnimations(sw) {}
void exportAnimation(Scene *sce)
{
openLibrary();
forEachObjectWithAnimationInScene(sce, *this);
closeLibrary();
}
void operator() (Object *ob)
{
AnimData *adt = ob->adt;
NlaTrack *nlt;
NlaStrip *strip;
FCurve *fcu;
// iterate over all nla tracks
for (nlt = (NlaTrack*)adt->nla_tracks.first; nlt; nlt = nlt->next) {
// iterate over all nla strips of current nla track
for (strip = (NlaStrip*)nlt->strips.first; strip; strip = strip->next) {
bAction *act = strip->act;
// iterate over all fcurves of current nla strip's action
for (fcu = (FCurve*)act->curves.first; fcu; fcu = fcu->next) {
// write <animation> for each fcurve
// each fcurve represents one axis of loc/rot/scale
// through fcurve I can take intangents and outtangents
// but how do I get objects loc/rot/scale data at specific time
}
}
}
}
};
void DocumentExporter::exportCurrentScene(Scene *sce, const char* filename)
{
COLLADABU::NativeString native_filename =

View File

@@ -144,7 +144,8 @@ private:
{
//int uv_coords_index = mVData->getInputInfosArray()[uv_set_index]->getCount() * uv_set_index + uv_index * 2;
int uv_coords_index = uv_index * 2;
// int uv_coords_index = mVData->getLength(uv_set_index) * uv_set_index + uv_index * 2;
//int uv_coords_index = mVData->getLength(uv_set_index) * uv_set_index + uv_index * 2;
switch(mVData->getType()) {
case COLLADAFW::MeshVertexData::DATA_TYPE_FLOAT:
{
@@ -164,8 +165,6 @@ private:
break;
}
}
//uv[0] = mVData;
//uv[1] = ...;
}
};
@@ -429,13 +428,16 @@ public:
0
};
if (quad) uv_indices[3] = index_list.getIndex(index + 3);
//if (quad) uv_indices[3] = index_list.getIndex(index + 3);
uvs.getUV(uv_set_index, uv_indices[0], mtface->uv[0]);
uvs.getUV(uv_set_index, uv_indices[1], mtface->uv[1]);
uvs.getUV(uv_set_index, uv_indices[2], mtface->uv[2]);
if (quad) uvs.getUV(uv_set_index, uv_indices[3], mtface->uv[3]);
if (quad) {
uv_indices[3] = index_list.getIndex(index + 3);
uvs.getUV(uv_set_index, uv_indices[3], mtface->uv[3]);
}
}
/** When this method is called, the writer must write the geometry.