|
From: Charles L. <cn...@us...> - 2009-04-21 05:06:35
|
Update of /cvsroot/hgengine/Mercury/Util/ModelOptimizer In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv16703 Modified Files: ModelContainer.h main.cpp Added Files: Makefile smoother.cpp Removed Files: compile.sh Log Message: update and add smoother ---------------------------------------------------------------------- Index: ModelContainer.h =================================================================== RCS file: /cvsroot/hgengine/Mercury/Util/ModelOptimizer/ModelContainer.h,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** ModelContainer.h 29 Sep 2008 20:59:23 -0000 1.6 --- ModelContainer.h 21 Apr 2009 05:06:23 -0000 1.7 *************** *** 12,15 **** --- 12,28 ---- struct Vert { + bool operator < ( const Vert & rhs ) const + { + if( pPosition.z != rhs.pPosition.z ) + return pPosition.z < rhs.pPosition.z; + if( pPosition.y != rhs.pPosition.y ) + return pPosition.y < rhs.pPosition.y; + if( pPosition.x != rhs.pPosition.x ) + return pPosition.x < rhs.pPosition.x; + if( uv[0] != rhs.uv[0] ) + return uv[0] < uv[0]; + return uv[1] < uv[1]; + } + float uv[2]; MercuryPoint pNormal; --- NEW FILE: Makefile --- all : optimizer smoother CXXFLAGS:=-g -I../../src optimizer : ModelContainer.o main.o StripAndFanner.o ../../src/MercuryMath.o ../../src/MercuryMatrix.o ../../src/MercuryTypes.o g++ -o $@ $^ $(CXXFLAGS) smoother : ModelContainer.o smoother.o StripAndFanner.o ../../src/MercuryMath.o ../../src/MercuryMatrix.o ../../src/MercuryTypes.o g++ -o $@ $^ $(CXXFLAGS) clean : rm -f *.o *~ optimizer smoother --- NEW FILE: smoother.cpp --- #include "ModelContainer.h" #include "StripAndFanner.h" #include <vector> #include <map> using namespace std; #define MINIMUM_WEIGHT 0.001 #define MINIMUM_TO_CREATE_STATIC_MESH 16 #define MINIMUM_TO_CREATE_BONE_MESH 9 //Model optimizer by Charles Lohr. /* The purpose of this application is to take an existing model, in hgmdl format and then figure out the best way to minimize the noncached faces and verticies. There's a bit of stuff left to do: 1: Allow creation of static meshes. Currently, it only uncaches bones. 2: Allow destruction of entire meshes, once they're empty. 3: Pay attention to materials more closely. */ struct IntegerPair { IntegerPair() { A = -1; B = -1; } IntegerPair( int a, int b ) { A = a; B = b; } int A; int B; bool operator == ( const IntegerPair & rhs ) { return (rhs.A == A)&&(rhs.B == B ); } }; int main( int argc, char ** argv ) { Model c; unsigned i,j,k,l; int iTotalVerts = 0; int iTotalFaces = 0; int iTotalAssignments = 0; if ( argc != 3 ) { printf( "Usage: smoother <infile> <outfile>\n" ); return -1; } printf( "Loading Model.\n" ); c.LoadModel( argv[1] ); for( i = 0; i < c.vBones.size(); i++ ) iTotalAssignments += c.vBones[i].vAssignments.size(); printf( "Model Loaded.\n" ); printf( " Animations: %d\n", c.vAnimations.size() ); for( i = 0; i < c.vAnimations.size(); i++ ) printf( " %02d: %s %f\n", i, c.vAnimations[i].sName.c_str(), c.vAnimations[i].fDuration ); printf( " Bones: %d\n", c.vBones.size() ); printf( " Assignments:%d\n", iTotalAssignments ); printf( " Materials: %d\n", c.vMaterials.size() ); printf( " Meshes: %d\n", c.vMeshes.size() ); for( i = 0; i < c.vMeshes.size(); i++ ) { printf( " %03d: [%d] [%d] [%d] [%d] [%d]\n", i, c.vMeshes[i].vTriangles.size(), c.vMeshes[i].vVerticies.size(), c.vMeshes[i].bCache, c.vMeshes[i].iMaterialNumber, c.vMeshes[i].iBoneAttached ); iTotalVerts += c.vMeshes[i].vVerticies.size(); iTotalFaces += c.vMeshes[i].vTriangles.size(); } printf( " Faces: %d\n", iTotalFaces ); printf( " Verts: %d\n", iTotalVerts ); for( i = 0; i < c.vMeshes.size(); i++ ) { vector< int > m_vAllMap; map< Vert, int > m_mAllVerts; vector< Vert > m_vNewVerts; m_mAllVerts.clear(); Mesh & m = c.vMeshes[i]; m_vAllMap.resize( m.vVerticies.size() ); int curVert = 0; for( int j = 0; j < m.vVerticies.size(); j++ ) { Vert v = m.vVerticies[j]; if( m_mAllVerts.find( v ) == m_mAllVerts.end() ) { m_mAllVerts[v] = curVert; m_vAllMap[j] = curVert; m_vNewVerts.push_back( v ); curVert++; } else { m_vAllMap[j] = m_mAllVerts[v]; } } //Now we have a map of all condensed vertices. //Update all bones who use this vertex. for( int j = 0; j < c.vBones.size(); j++ ) { Bone & b = c.vBones[j]; //Skip meshes that are exclusive if( b.iAssociatedMesh != -1 ) continue; vector< BoneAssignment > vNewAssignments; map< int, int > mHitAssignment; for( int k = 0; k < b.vAssignments.size(); k++ ) { BoneAssignment & ba = b.vAssignments[k]; //If it's not in our mesh, keep looking. if( ba.iMesh != i ) { vNewAssignments.push_back( ba ); continue; } //Already hit. if( mHitAssignment[ba.iVertex] != 0 ) continue; ba.iVertex = m_vAllMap[ba.iVertex]; vNewAssignments.push_back( ba ); } b.vAssignments = vNewAssignments; } //Update my triangles for( int j = 0; j < m.vTriangles.size(); j++ ) { Triangle & t = m.vTriangles[j]; for( int k = 0; k < 3; k++ ) { t.iFace[k] = m_vAllMap[t.iFace[k]]; } } printf( " %02d: %d -> %d\n", i, m.vVerticies.size(), m_vNewVerts.size() ); //Update the output vertices. m.vVerticies = m_vNewVerts; } printf( "Saving Model.\n" ); c.SaveModel( argv[2] ); printf( "Model Saved. Exiting.\n" ); return 0; } /* * (c) 2006 Charles Lohr * All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, and/or sell copies of the Software, and to permit persons to * whom the Software is furnished to do so, provided that the above * copyright notice(s) and this permission notice appear in all copies of * the Software and that both the above copyright notice(s) and this * permission notice appear in supporting documentation. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF * THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS * INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT * OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR * PERFORMANCE OF THIS SOFTWARE. */ --- compile.sh DELETED --- Index: main.cpp =================================================================== RCS file: /cvsroot/hgengine/Mercury/Util/ModelOptimizer/main.cpp,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** main.cpp 21 Apr 2009 03:41:23 -0000 1.11 --- main.cpp 21 Apr 2009 05:06:23 -0000 1.12 *************** *** 52,61 **** c.LoadModel( argv[1] ); - // StripAndFanner F; - // F.AttachToMesh( &c.vMeshes[0], 0 ); - // F.Go(); - - // return 0; - for( i = 0; i < c.vBones.size(); i++ ) --- 52,55 ---- |