Added: #1440 Parser for PolyObject faces

--HG--
branch : build_pipeline_v3
hg/feature/build_pipeline_v3
kaetemi 12 years ago
parent 56fbd0bbb8
commit b6ec41f53d

@ -66,7 +66,7 @@ namespace STORAGE {
#define PMBS_GEOM_BUFFERS_TRI_C_INDEX_CHUNK_ID 0x0942 #define PMBS_GEOM_BUFFERS_TRI_C_INDEX_CHUNK_ID 0x0942
#define PBMS_GEOM_BUFFERS_POLY_A_VERTEX_CHUNK_ID 0x0100 #define PBMS_GEOM_BUFFERS_POLY_A_VERTEX_CHUNK_ID 0x0100
#define PBMS_GEOM_BUFFERS_POLY_A_EDGE_CHUNK_ID 0x010a #define PBMS_GEOM_BUFFERS_POLY_A_EDGE_CHUNK_ID 0x010a
#define PBMS_GEOM_BUFFERS_POLY_A_INDEX_B_CHUNK_ID 0x011a #define PBMS_GEOM_BUFFERS_POLY_A_FACE_CHUNK_ID 0x011a
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
@ -145,6 +145,69 @@ std::string CGeomPolyEdgeInfo::toString() const
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
CGeomPolyFaceInfo::CGeomPolyFaceInfo() : I1(0), Material(0), SmoothingGroups(0)
{
}
void CGeomPolyFaceInfo::serial(NLMISC::IStream &stream)
{
nldebug("go");
stream.serialCont(Vertices);
nldebug("%i vertices", Vertices.size());
uint16 bitfield;
if (!stream.isReading())
{
nldebug("writing");
bitfield = 0x0000;
if (I1) bitfield |= 0x0001;
// bitfield |= 0x0002;
// bitfield |= 0x0004;
if (Material) bitfield |= 0x0008;
if (SmoothingGroups) bitfield |= 0x0010;
if (Triangulation.size()) bitfield |= 0x0020;
// bitfield |= 0x0040;
// bitfield |= 0x0080;
}
stream.serial(bitfield);
nldebug("bitfield 0x%x", (uint32)bitfield);
if (bitfield & 0x0001) { nldebug("i1"); stream.serial(I1); nlassert(I1); bitfield &= ~0x0001; }
else I1 = 0;
if (bitfield & 0x0008) { nldebug("material"); stream.serial(Material); nlassert(Material); bitfield &= ~0x0008; }
else Material = 0;
if (bitfield & 0x0010) { nldebug("smoothing"); stream.serial(SmoothingGroups); nlassert(SmoothingGroups); bitfield &= ~0x0010; }
else SmoothingGroups = 0;
if (bitfield & 0x0020)
{
nldebug("triangles");
if (stream.isReading()) Triangulation.resize(Vertices.size() - 3);
else nlassert(Triangulation.size() == Vertices.size() - 3);
for (std::vector<std::pair<uint32, uint32> >::size_type i = 0; i < Triangulation.size(); ++i)
{
stream.serial(Triangulation[i].first);
nldebug("cut from %i", Triangulation[i].first);
nlassert(Triangulation[i].first < Vertices.size());
stream.serial(Triangulation[i].second);
nldebug("to %i", Triangulation[i].second);
nlassert(Triangulation[i].second < Vertices.size());
}
nlassert(Triangulation.size());
bitfield &= ~0x0020;
}
if (bitfield) nlerror("Remaining bitfield value 0x%x", (uint32)bitfield);
}
std::string CGeomPolyFaceInfo::toString() const
{
std::stringstream ss;
//ss << "0x" << NLMISC::toString("%x", i1) << ", " << a << " " << b;
return ss.str();
}
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
CGeomBuffers::CGeomBuffers() CGeomBuffers::CGeomBuffers()
{ {
@ -200,6 +263,9 @@ IStorageObject *CGeomBuffers::createChunkById(uint16 id, bool container)
case PBMS_GEOM_BUFFERS_POLY_A_EDGE_CHUNK_ID: case PBMS_GEOM_BUFFERS_POLY_A_EDGE_CHUNK_ID:
nlassert(!container); nlassert(!container);
return new CStorageArraySizePre<CGeomPolyEdgeInfo>(); return new CStorageArraySizePre<CGeomPolyEdgeInfo>();
case PBMS_GEOM_BUFFERS_POLY_A_FACE_CHUNK_ID:
nlassert(!container);
return new CStorageArrayDynSize<CGeomPolyFaceInfo>();
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:
nlassert(!container); nlassert(!container);

@ -79,6 +79,26 @@ struct CGeomPolyEdgeInfo
std::string toString() const; std::string toString() const;
}; };
struct CGeomPolyFaceInfo
{
CGeomPolyFaceInfo();
/// Vertex indices in the vertex buffer
std::vector<uint32> Vertices;
// Bitfield (implicitly stored)
/// Unknown 01 00 01 00
uint32 I1;
// Unknown?
// Unknown?
/// Material index in multi-submat
uint16 Material;
/// Bitfield with smoothing groups
uint32 SmoothingGroups;
/// Cuts at local vertex index to local vertex index
std::vector<std::pair<uint32, uint32> > Triangulation;
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

@ -42,6 +42,10 @@
namespace PIPELINE { namespace PIPELINE {
namespace MAX { namespace MAX {
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
/** /**
* \brief CStorageArray * \brief CStorageArray
* \date 2012-08-21 11:33GMT * \date 2012-08-21 11:33GMT
@ -115,6 +119,10 @@ bool CStorageArray<T>::getSize(sint32 &size) const
return true; return true;
} }
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
template <typename T> template <typename T>
class CStorageArraySizePre : public CStorageArray<T> class CStorageArraySizePre : public CStorageArray<T>
{ {
@ -149,9 +157,58 @@ void CStorageArraySizePre<T>::setSize(sint32 size)
template <typename T> template <typename T>
bool CStorageArraySizePre<T>::getSize(sint32 &size) const bool CStorageArraySizePre<T>::getSize(sint32 &size) const
{ {
return CStorageArray<T>::getSize(size) + sizeof(uint32); size = CStorageArray<T>::getSize(size) + sizeof(uint32);
return true;
}
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
/// Same as CStorageArraySizePre but with no sizeof checks.
/// Use when serializing variable sizes in type T.
template <typename T>
class CStorageArrayDynSize : 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 CStorageArrayDynSize<T>::className() const
{
return "StorageArrayDynSize";
} }
template <typename T>
void CStorageArrayDynSize<T>::serial(NLMISC::IStream &stream)
{
uint32 size = this->Value.size();
stream.serial(size);
this->Value.resize(size);
CStorageArray<T>::serial(stream);
}
template <typename T>
void CStorageArrayDynSize<T>::setSize(sint32 size)
{
// Nothing to do here!
}
template <typename T>
bool CStorageArrayDynSize<T>::getSize(sint32 &size) const
{
// Nothing to do here!
return false;
}
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
} /* namespace MAX */ } /* namespace MAX */
} /* namespace PIPELINE */ } /* namespace PIPELINE */

@ -41,10 +41,10 @@ using namespace PIPELINE::MAX::BUILTIN;
using namespace PIPELINE::MAX::BUILTIN::STORAGE; 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";
//static const char *filename = "/home/kaetemi/3dsMax/scenes/test2008.max"; //static const char *filename = "/home/kaetemi/3dsMax/scenes/test2008.max";
//static const char *filename = "/home/kaetemi/3dsMax/scenes/teapot_test_scene.max"; //static const char *filename = "/home/kaetemi/3dsMax/scenes/teapot_test_scene.max";
static const char *filename = "/home/kaetemi/3dsMax/scenes/testplane.max"; //static const char *filename = "/home/kaetemi/3dsMax/scenes/testplane.max";
static const char *streamname = "Scene"; static const char *streamname = "Scene";
void exportObj(const std::string &fileName, const CReferenceMaker *triObject) void exportObj(const std::string &fileName, const CReferenceMaker *triObject)
@ -208,9 +208,9 @@ int main(int argc, char **argv)
//exportObj("tr_hof_civil01_gilet.obj", node->getReference(1)->getReference(1)); // => CDerivedObject::getBase(node->object()) //exportObj("tr_hof_civil01_gilet.obj", node->getReference(1)->getReference(1)); // => CDerivedObject::getBase(node->object())
//INode *node = scene.container()->scene()->rootNode()->find(ucstring("GE_Acc_MikotoBaniere")); nlassert(node); //INode *node = scene.container()->scene()->rootNode()->find(ucstring("GE_Acc_MikotoBaniere")); nlassert(node);
INode *node = scene.container()->scene()->rootNode()->find(ucstring("testplane")); nlassert(node); //INode *node = scene.container()->scene()->rootNode()->find(ucstring("testplane")); nlassert(node);
CReferenceMaker *object = node->getReference(1); //CReferenceMaker *object = node->getReference(1);
object->toString(std::cout); //object->toString(std::cout);
//GE_Acc_MikotoBaniere //GE_Acc_MikotoBaniere

Loading…
Cancel
Save