void TriMesh::Process( uint32_t inStartOffset, uint32_t inEndOffset ) { uint32_t dataLen = inEndOffset - inStartOffset; if (dataLen < 52) { throw DataLengthException( Name(), inStartOffset, inEndOffset, 52 ); } mFaces = FetchUInt32( inStartOffset ); uint32_t numFaceAtts = FetchUInt32( inStartOffset+4 ); mEdges = FetchUInt32( inStartOffset+8 ); uint32_t numEdgeAtts = FetchUInt32( inStartOffset+12 ); mPoints = FetchUInt32( inStartOffset+16 ); uint32_t numPointAtts = FetchUInt32( inStartOffset+20 ); int bytesPointIndex, bytesPerFaceIndex; if (mPoints - 1 <= 0xFE) { bytesPointIndex = 1; } else if (mPoints - 1 <= 0xFFFE) { bytesPointIndex = 2; } else { bytesPointIndex = 4; } if (mFaces - 1 <= 0xFE) { bytesPerFaceIndex = 1; } else if (mFaces - 1 <= 0xFFFE) { bytesPerFaceIndex = 2; } else { bytesPerFaceIndex = 4; } uint32_t trianglesSize = mFaces * 3 * bytesPointIndex; uint32_t edgesSize = mEdges * 2 * (bytesPointIndex + bytesPerFaceIndex); uint32_t pointsSize = mPoints * 12; uint32_t expectedLength = 52 + trianglesSize + edgesSize + pointsSize; if (dataLen != expectedLength) { throw DataLengthException( Name(), inStartOffset, inEndOffset, expectedLength ); } Out() << Indent() << Name() << " (\n" << Indent(1) << mFaces << " " << numFaceAtts << " " << mEdges << " " << numEdgeAtts << " " << mPoints << " " << numPointAtts << "\t" << "# faces faceAtts edges edgeAtts pts ptAtts\n"; WriteTriangles( inStartOffset+24, mFaces, bytesPointIndex ); WriteEdges( inStartOffset+24+trianglesSize, mEdges, bytesPointIndex, bytesPerFaceIndex ); WritePoints( inStartOffset+24+trianglesSize+edgesSize, mPoints ); WriteBoundingBox( inStartOffset+24+trianglesSize+edgesSize+pointsSize ); Out() << Indent() << ")\n"; }
bool CLwoWriter::Write() { OBJ_ASSERT(m_pLwoFile); if(!m_pLwoFile) return false; std::string fileName(m_fileName.string()); // Extract native file path string m_ofs.open(fileName.c_str(), ios::out | ios::binary | std::ios::trunc); MSG_INFO("Writing LWO file : '" << fileName << "'."); if( !m_ofs.is_open() ) { MSG_ERROR("Couldn't write to .LWO file '" << fileName << "'"); return false; } // TODO iterate through layers here: m_curLayer = m_pLwoFile->GetLayerVector()[0]; // first layer // Build the chunk lengths BuildChunkLengths(); // Write the LWO file header WriteHeader(); { // Write TAGS strings WriteTagStrings(); // Write LAYR : Support for only one layer WriteLayer(); // Write PNTS WritePoints(); // Write VMAP | TXUV WriteVertexMapping(); // Write POLS | FACE WritePolygons(); // Write PTAG WritePolygonTagMapping(); // Write VMAD | TXUV WriteDiscVertexMapping(); // Write CLIP WriteImageDefinitions(); // Write SURF WriteSurfaces(); } MSG_DEBUG("Done."); // Close file m_ofs.close(); return true; }