#if !defined PTEX_IMPORTER #define PTEX_IMPORTER //**************************************************************************/ // Copyright (c) 2011, 2012 Autodesk, Inc. // All rights reserved. // // Use of this software is subject to the terms of the Autodesk license // agreement provided at the time of installation or download, or which // otherwise accompanies this software in either electronic or hard copy form. // //**************************************************************************/ // DESCRIPTION: PTEX texture importer // CREATED: January 2011 //**************************************************************************/ #if defined(JAMBUILD) #include <Mudbox/mudbox.h> #include <UVlessPainting/UVMeshGrid.h> #include <UVlessPainting/UVGeneratorInterface.h> #include <EdgeBleeding/EdgeBleeding.h> #else #include "../../include/Mudbox/mudbox.h" #include "../../include/UVlessPainting/UVGeneratorInterface.h" #include "../../include/EdgeBleeding/EdgeBleeding.h" #endif #include "ptex/Ptexture.h" using namespace mudbox; //------------------------------------------------------------------------------ // We will refuse to import ptex files with polys larger than MAX_EDGE_COUNT // Don't make this too large -- staticly sized arrays on the stack will // be sized based on this. It should be more than 5, definitely less than 500. // It is very possible that other parts of Mudbox will break when presented with // a 100 edge poly -- I've never tried it.... #define MAX_EDGE_COUNT 100 //------------------------------------------------------------------------------ // Cross reference our face ids with the ptex face ids. // Each ptex face will create 1 or more Mudbox faces. // The map is indexed by PTex parent Face ID, and for each of those, will give the // start MudboxFaceID and the number of triangles the PTexFace // has been tessellated into. It also gives the Ptex subface index for the first // subface. // The Mudbox FaceIDs for those faces will // be m_MBFaceID, m_MBFaceID+1, ... m_MBFaceID+m_NumTessellatedFaces-1 class FaceMapEntry { // there is one of these for each PTex Face / n-gon poly. public: int m_NumTessellatedFaces; // How many Mudbox triangles has this been tessellated into. int m_NumEdges; // how many edges in the poly. int m_MBFaceID; // Index of the first triangle in the Mudbox Mesh (or of the quad if its an all quad mesh). int m_PTexSubfaceID; // indes of the first ptex subface where the texture data can be read from the ptex file FaceMapEntry() : m_NumTessellatedFaces(0), m_NumEdges(0), m_MBFaceID(0), m_PTexSubfaceID(0) {}; }; //------------------------------------------------------------------------------ class PtexImporter : public Importer { public: Q_DECLARE_TR_FUNCTIONS(PtexImporter); DECLARE_CLASS; // Make sure everything is initialized, if only to ensure determinism. PtexImporter() : m_allQuads(false), m_iFaceCount(0), m_iSubFaceCount(0), m_maxFaceSize(0), m_minFaceSize(0), m_iTotalTesselatedFaceCount(0), m_FaceMap(0), m_ReverseFaceMap(0) { memset(m_hist, 0, MAX_EDGE_COUNT * sizeof(int)); } // Returns the file extension and description of the supported file by the plugin. QVector<FileExtension> SupportedExtensions( void ) const { QVector<FileExtension> ret; ret.push_back(FileExtension(NTR("ptx"), tr("Ptex File"), FileExtension::flagNoTextureCoordinates)); return ret; }; // Import a file, main function of the class. virtual void Import( const QString &sFileName, Scene::LoadData &cData ); // This function creates a mesh from the metadata in a ptex file. If there is no mesh // metadata in the ptex file, it will return NULL. Mesh *CreateMeshFromPtex( const QString &sFileName, bool makeMesh = true, bool silent = false ); // If there is no mesh data in the ptex file, you can call this to build the cross reference // tables to go from ptex ids to mudbox and back. void BuildMapsFromBaseMesh(Mesh *pMesh); bool m_allQuads; // true if the ptex file is all quads int m_iFaceCount; // count of ptex polys (quads, tris and ngons each count as 1) int m_iSubFaceCount; // in this many quad faces (tris and ngons subdivided into quad subfaces) int m_maxFaceSize; // min and max edge count for the ptex faces int m_minFaceSize; int m_iTotalTesselatedFaceCount; // how many triangles are we making in total for the mudbox mesh FaceMapEntry *m_FaceMap; // map of ptex faces to mudbox faces and ptex subfaces int *m_ReverseFaceMap; // map from Mudbox faceID to ptex face (not subface) id // to get the subface, take the result of this map and index into the FaceMap int m_hist[MAX_EDGE_COUNT]; // a histogram of PTex poly edge counts }; //------------------------------------------------------------------------------ #endif