From b6ec41f53d6766dd6794dbb709a188c3b11d9608 Mon Sep 17 00:00:00 2001 From: kaetemi Date: Sun, 26 Aug 2012 13:52:04 +0200 Subject: [PATCH] Added: #1440 Parser for PolyObject faces --HG-- branch : build_pipeline_v3 --- .../max/builtin/storage/geom_buffers.cpp | 68 ++++++++++++++++++- .../max/builtin/storage/geom_buffers.h | 20 ++++++ code/nel/tools/pipeline/max/storage_array.h | 59 +++++++++++++++- code/nel/tools/pipeline/max_dump/main.cpp | 10 +-- 4 files changed, 150 insertions(+), 7 deletions(-) diff --git a/code/nel/tools/pipeline/max/builtin/storage/geom_buffers.cpp b/code/nel/tools/pipeline/max/builtin/storage/geom_buffers.cpp index cf9e9a0e6..1b7dcb16a 100644 --- a/code/nel/tools/pipeline/max/builtin/storage/geom_buffers.cpp +++ b/code/nel/tools/pipeline/max/builtin/storage/geom_buffers.cpp @@ -66,7 +66,7 @@ namespace STORAGE { #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_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 >::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() { @@ -200,6 +263,9 @@ IStorageObject *CGeomBuffers::createChunkById(uint16 id, bool container) case PBMS_GEOM_BUFFERS_POLY_A_EDGE_CHUNK_ID: nlassert(!container); return new CStorageArraySizePre(); + case PBMS_GEOM_BUFFERS_POLY_A_FACE_CHUNK_ID: + nlassert(!container); + return new CStorageArrayDynSize(); case PMBS_GEOM_BUFFERS_TRI_B_INDEX_CHUNK_ID: case PMBS_GEOM_BUFFERS_TRI_C_INDEX_CHUNK_ID: nlassert(!container); diff --git a/code/nel/tools/pipeline/max/builtin/storage/geom_buffers.h b/code/nel/tools/pipeline/max/builtin/storage/geom_buffers.h index 56c24f1a0..4864f8e7d 100644 --- a/code/nel/tools/pipeline/max/builtin/storage/geom_buffers.h +++ b/code/nel/tools/pipeline/max/builtin/storage/geom_buffers.h @@ -79,6 +79,26 @@ struct CGeomPolyEdgeInfo std::string toString() const; }; +struct CGeomPolyFaceInfo +{ + CGeomPolyFaceInfo(); + /// Vertex indices in the vertex buffer + std::vector 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 > Triangulation; + void serial(NLMISC::IStream &stream); + std::string toString() const; +}; + /** * \brief CGeomBuffers * \date 2012-08-25 07:55GMT diff --git a/code/nel/tools/pipeline/max/storage_array.h b/code/nel/tools/pipeline/max/storage_array.h index ca558c60c..1f72f8213 100644 --- a/code/nel/tools/pipeline/max/storage_array.h +++ b/code/nel/tools/pipeline/max/storage_array.h @@ -42,6 +42,10 @@ namespace PIPELINE { namespace MAX { +//////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////// + /** * \brief CStorageArray * \date 2012-08-21 11:33GMT @@ -115,6 +119,10 @@ bool CStorageArray::getSize(sint32 &size) const return true; } +//////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////// + template class CStorageArraySizePre : public CStorageArray { @@ -149,9 +157,58 @@ void CStorageArraySizePre::setSize(sint32 size) template bool CStorageArraySizePre::getSize(sint32 &size) const { - return CStorageArray::getSize(size) + sizeof(uint32); + size = CStorageArray::getSize(size) + sizeof(uint32); + return true; +} + +//////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////// + +/// Same as CStorageArraySizePre but with no sizeof checks. +/// Use when serializing variable sizes in type T. +template +class CStorageArrayDynSize : public CStorageArray +{ +public: + virtual std::string className() const; + virtual void serial(NLMISC::IStream &stream); + virtual void setSize(sint32 size); + virtual bool getSize(sint32 &size) const; +}; + +template +std::string CStorageArrayDynSize::className() const +{ + return "StorageArrayDynSize"; } +template +void CStorageArrayDynSize::serial(NLMISC::IStream &stream) +{ + uint32 size = this->Value.size(); + stream.serial(size); + this->Value.resize(size); + CStorageArray::serial(stream); +} + +template +void CStorageArrayDynSize::setSize(sint32 size) +{ + // Nothing to do here! +} + +template +bool CStorageArrayDynSize::getSize(sint32 &size) const +{ + // Nothing to do here! + return false; +} + +//////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////// + } /* namespace MAX */ } /* namespace PIPELINE */ diff --git a/code/nel/tools/pipeline/max_dump/main.cpp b/code/nel/tools/pipeline/max_dump/main.cpp index 4067e6fab..d3f353423 100644 --- a/code/nel/tools/pipeline/max_dump/main.cpp +++ b/code/nel/tools/pipeline/max_dump/main.cpp @@ -41,10 +41,10 @@ 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 = "/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/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"; 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()) //INode *node = scene.container()->scene()->rootNode()->find(ucstring("GE_Acc_MikotoBaniere")); nlassert(node); - INode *node = scene.container()->scene()->rootNode()->find(ucstring("testplane")); nlassert(node); - CReferenceMaker *object = node->getReference(1); - object->toString(std::cout); + //INode *node = scene.container()->scene()->rootNode()->find(ucstring("testplane")); nlassert(node); + //CReferenceMaker *object = node->getReference(1); + //object->toString(std::cout); //GE_Acc_MikotoBaniere