Changed: #1440 Use more specific structures

--HG--
branch : build_pipeline_v3
hg/feature/build_pipeline_v3
kaetemi 12 years ago
parent 6e8e6ab86a
commit a8a6be68d5

@ -29,9 +29,11 @@
#include "geom_buffers.h" #include "geom_buffers.h"
// STL includes // STL includes
#include <sstream>
// NeL includes // NeL includes
// #include <nel/misc/debug.h> // #include <nel/misc/debug.h>
#include <nel/misc/vector.h>
// Project includes // Project includes
#include "../../storage_array.h" #include "../../storage_array.h"
@ -71,6 +73,26 @@ namespace STORAGE {
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
void CGeomTriIndexInfo::serial(NLMISC::IStream &stream)
{
stream.serial(a);
stream.serial(b);
stream.serial(c);
stream.serial(i1);
stream.serial(i2);
}
std::string CGeomTriIndexInfo::toString() const
{
std::stringstream ss;
ss << a << ", " << b << ", " << c << ", " << i1 << ", " << i2;
return ss.str();
}
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
CGeomBuffers::CGeomBuffers() CGeomBuffers::CGeomBuffers()
{ {
@ -115,19 +137,23 @@ IStorageObject *CGeomBuffers::createChunkById(uint16 id, bool container)
{ {
switch (id) switch (id)
{ {
case PMBS_GEOM_BUFFERS_TRI_A_VERTEX_CHUNK_ID:
case PMBS_GEOM_BUFFERS_TRI_B_VERTEX_CHUNK_ID: case PMBS_GEOM_BUFFERS_TRI_B_VERTEX_CHUNK_ID:
case PMBS_GEOM_BUFFERS_TRI_C_VERTEX_CHUNK_ID: case PMBS_GEOM_BUFFERS_TRI_C_VERTEX_CHUNK_ID:
case PBMS_GEOM_BUFFERS_POLY_A_VERTEX_CHUNK_ID: case PBMS_GEOM_BUFFERS_POLY_A_VERTEX_CHUNK_ID:
nlassert(!container); nlassert(!container);
return new CStorageArray<float>(); return new CStorageArray<float>();
case PMBS_GEOM_BUFFERS_TRI_A_INDEX_CHUNK_ID:
case PMBS_GEOM_BUFFERS_TRI_B_INDEX_CHUNK_ID: case PMBS_GEOM_BUFFERS_TRI_B_INDEX_CHUNK_ID:
case PMBS_GEOM_BUFFERS_TRI_C_INDEX_CHUNK_ID: case PMBS_GEOM_BUFFERS_TRI_C_INDEX_CHUNK_ID:
case PBMS_GEOM_BUFFERS_POLY_A_INDEX_A_CHUNK_ID: case PBMS_GEOM_BUFFERS_POLY_A_INDEX_A_CHUNK_ID:
case PBMS_GEOM_BUFFERS_POLY_A_INDEX_B_CHUNK_ID: case PBMS_GEOM_BUFFERS_POLY_A_INDEX_B_CHUNK_ID:
nlassert(!container); nlassert(!container);
return new CStorageArray<uint32>(); return new CStorageArray<uint32>();
case PMBS_GEOM_BUFFERS_TRI_A_INDEX_CHUNK_ID:
nlassert(!container);
return new CStorageArraySizePre<CGeomTriIndexInfo>();
case PMBS_GEOM_BUFFERS_TRI_A_VERTEX_CHUNK_ID:
nlassert(!container);
return new CStorageArraySizePre<NLMISC::CVector>();
} }
return CStorageContainer::createChunkById(id, container); return CStorageContainer::createChunkById(id, container);
} }

@ -41,6 +41,17 @@ namespace MAX {
namespace BUILTIN { namespace BUILTIN {
namespace STORAGE { namespace STORAGE {
struct CGeomTriIndexInfo
{
uint32 a;
uint32 b;
uint32 c;
uint32 i1;
uint32 i2;
void serial(NLMISC::IStream &stream);
std::string toString() const;
};
/** /**
* \brief CGeomBuffers * \brief CGeomBuffers
* \date 2012-08-25 07:55GMT * \date 2012-08-25 07:55GMT

@ -88,16 +88,16 @@ void CStorageArray<T>::serial(NLMISC::IStream &stream)
template <typename T> template <typename T>
void CStorageArray<T>::toString(std::ostream &ostream, const std::string &pad) const void CStorageArray<T>::toString(std::ostream &ostream, const std::string &pad) const
{ {
ostream << "(" << className() << ") { "; // << s << " } "; ostream << "(" << className() << ") [" << Value.size() << "] { "; // << s << " } ";
uint i = 0; uint i = 0;
for (typename TTypeArray::const_iterator it = Value.begin(), end = Value.end(); it != end; ++it) for (typename TTypeArray::const_iterator it = Value.begin(), end = Value.end(); it != end; ++it)
{ {
std::string s = NLMISC::toString(*it); std::string s = NLMISC::toString(*it);
//ostream << "\n" << pad << i << ": " << s; //ostream << "\n" << pad << i << ": " << s;
ostream << s << ", "; ostream << "{ " << s << " } ";
++i; ++i;
} }
ostream << " } "; ostream << "} ";
} }
template <typename T> template <typename T>
@ -115,6 +115,43 @@ bool CStorageArray<T>::getSize(sint32 &size) const
return true; return true;
} }
template <typename T>
class CStorageArraySizePre : public CStorageArray<T>
{
public:
virtual std::string className() const;
virtual void serial(NLMISC::IStream &stream);
virtual void setSize(sint32 size);
virtual bool getSize(sint32 &size) const;
};
template <typename T>
std::string CStorageArraySizePre<T>::className() const
{
return "StorageArraySizePre";
}
template <typename T>
void CStorageArraySizePre<T>::serial(NLMISC::IStream &stream)
{
uint32 size = this->Value.size();
stream.serial(size);
nlassert(this->Value.size() == size);
CStorageArray<T>::serial(stream);
}
template <typename T>
void CStorageArraySizePre<T>::setSize(sint32 size)
{
CStorageArray<T>::setSize(size - sizeof(uint32));
}
template <typename T>
bool CStorageArraySizePre<T>::getSize(sint32 &size) const
{
return CStorageArray<T>::getSize(size) + sizeof(uint32);
}
} /* namespace MAX */ } /* namespace MAX */
} /* namespace PIPELINE */ } /* namespace PIPELINE */

@ -18,6 +18,7 @@
#include <utility> #include <utility>
#include <nel/misc/file.h> #include <nel/misc/file.h>
#include <nel/misc/vector.h>
#include "../max/storage_stream.h" #include "../max/storage_stream.h"
#include "../max/storage_object.h" #include "../max/storage_object.h"
@ -30,12 +31,14 @@
// Testing // Testing
#include "../max/builtin/storage/app_data.h" #include "../max/builtin/storage/app_data.h"
#include "../max/builtin/storage/geom_buffers.h"
#include "../max/builtin/builtin.h" #include "../max/builtin/builtin.h"
#include "../max/builtin/scene_impl.h" #include "../max/builtin/scene_impl.h"
#include "../max/builtin/i_node.h" #include "../max/builtin/i_node.h"
using namespace PIPELINE::MAX; using namespace PIPELINE::MAX;
using namespace PIPELINE::MAX::BUILTIN; using namespace PIPELINE::MAX::BUILTIN;
using namespace PIPELINE::MAX::BUILTIN::STORAGE;
static const char *filename = "/srv/work/database/interfaces/anims_max/cp_fy_hof_species.max"; static const char *filename = "/srv/work/database/interfaces/anims_max/cp_fy_hof_species.max";
//static const char *filename = "/home/kaetemi/source/minimax/GE_Acc_MikotoBaniere.max"; //static const char *filename = "/home/kaetemi/source/minimax/GE_Acc_MikotoBaniere.max";
@ -49,14 +52,14 @@ void exportObj(const std::string &fileName, const CReferenceMaker *triObject)
IStorageObject *bufferBlock = triObject->findStorageObject(0x08fe); IStorageObject *bufferBlock = triObject->findStorageObject(0x08fe);
nlassert(bufferBlock->isContainer()); nlassert(bufferBlock->isContainer());
CStorageContainer *buffers = static_cast<CStorageContainer *>(bufferBlock); CStorageContainer *buffers = static_cast<CStorageContainer *>(bufferBlock);
CStorageArray<float> *vertexBuffer = static_cast<CStorageArray<float> *>(buffers->findStorageObject(0x0914)); CStorageArraySizePre<NLMISC::CVector> *vertexBuffer = static_cast<CStorageArraySizePre<NLMISC::CVector> *>(buffers->findStorageObject(0x0914));
CStorageArray<uint32> *indexBuffer = static_cast<CStorageArray<uint32> *>(buffers->findStorageObject(0x0912)); CStorageArraySizePre<CGeomTriIndexInfo> *indexBuffer = static_cast<CStorageArraySizePre<CGeomTriIndexInfo> *>(buffers->findStorageObject(0x0912));
std::ofstream ofs(fileName.c_str()); std::ofstream ofs(fileName.c_str());
for (uint i = 1; i < vertexBuffer->Value.size() - 1; i += 3) for (uint i = 0; i < vertexBuffer->Value.size(); ++i)
ofs << "v " << vertexBuffer->Value[i] << " " << vertexBuffer->Value[i + 1] << " " << vertexBuffer->Value[i + 2] << "\n"; ofs << "v " << vertexBuffer->Value[i].x << " " << vertexBuffer->Value[i].y << " " << vertexBuffer->Value[i].z << "\n";
for (uint i = 1; i < indexBuffer->Value.size() - 1; i += 5) for (uint i = 0; i < indexBuffer->Value.size(); ++i)
ofs << "f " << (indexBuffer->Value[i] + 1) << " " << (indexBuffer->Value[i + 1] + 1) << " " << (indexBuffer->Value[i + 2] + 1) << "\n"; ofs << "f " << (indexBuffer->Value[i].a) << " " << (indexBuffer->Value[i].b) << " " << (indexBuffer->Value[i].c) << "\n";
} }
// int __stdcall WinMain(void *, void *, void *, int) // int __stdcall WinMain(void *, void *, void *, int)

Loading…
Cancel
Save