Restructure repository to include all source folders
Move git root from Client/ to src/ to track all source code: - Client: Game client source (moved to Client/Client/) - Server: Game server source - GameTools: Development tools - CryptoSource: Encryption utilities - database: Database scripts - Script: Game scripts - rylCoder_16.02.2008_src: Legacy coder tools - GMFont, Game: Additional resources 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
196
GameTools/WORLDCREATOR/OptimizeMesh.cpp
Normal file
196
GameTools/WORLDCREATOR/OptimizeMesh.cpp
Normal file
@@ -0,0 +1,196 @@
|
||||
// OptimizeMesh.cpp: implementation of the COptimizeMesh class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "worldcreator.h"
|
||||
#include "OptimizeMesh.h"
|
||||
#include "Vertex.h"
|
||||
|
||||
|
||||
#ifdef _DEBUG
|
||||
#undef THIS_FILE
|
||||
static char THIS_FILE[]=__FILE__;
|
||||
#define new DEBUG_NEW
|
||||
#endif
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Construction/Destruction
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
COptimizeMesh::COptimizeMesh()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
COptimizeMesh::~COptimizeMesh()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void COptimizeMesh::Load(char *strFilename,int mode)
|
||||
{
|
||||
FILE *fp=fopen(strFilename,"rb");
|
||||
|
||||
int nObject,nMat,TextureSize;
|
||||
fread(&nObject,sizeof(int),1,fp);
|
||||
fread(&nMat,sizeof(int),1,fp);
|
||||
fread(&TextureSize,sizeof(int),1,fp);
|
||||
|
||||
|
||||
char *strTextureName;
|
||||
List<char *> TextureNameList;
|
||||
|
||||
for(int i=0;i<nMat;i++)
|
||||
{
|
||||
strTextureName=new char[256];
|
||||
fread(strTextureName,sizeof(char)*256,1,fp);
|
||||
TextureNameList.Add(strTextureName);
|
||||
/*
|
||||
if(strcmp(strTextureName,"")==0)
|
||||
continue;
|
||||
*/
|
||||
}
|
||||
|
||||
char strObjectName[256];
|
||||
int MatRef,cVertex,cIndices;
|
||||
MultiVertex *pVertexData;
|
||||
WORD *pIndicesData;
|
||||
|
||||
List<MultiVertex*> VertexList;
|
||||
List<WORD*> IndexList;
|
||||
List<int> nVertexList;
|
||||
List<int> nIndexList;
|
||||
List<long> MatRefList;
|
||||
|
||||
for(i=0;i<nObject;i++)
|
||||
{
|
||||
fread(strObjectName,sizeof(char)*256,1,fp);
|
||||
fread(&MatRef,sizeof(long),1,fp);
|
||||
MatRefList.Add(MatRef);
|
||||
fread(&cVertex,sizeof(long),1,fp);
|
||||
fread(&cIndices,sizeof(int),1,fp);
|
||||
nVertexList.Add(cVertex);
|
||||
nIndexList.Add(cIndices);
|
||||
pVertexData=new MultiVertex[cVertex];
|
||||
pIndicesData=new WORD[cIndices*3];
|
||||
fread(pVertexData,sizeof(MultiVertex)*cVertex,1,fp);
|
||||
fread(pIndicesData,sizeof(WORD)*cIndices*3,1,fp);
|
||||
VertexList.Add(pVertexData);
|
||||
IndexList.Add(pIndicesData);
|
||||
}
|
||||
fclose(fp);
|
||||
|
||||
|
||||
const float fEll=0.0001f;
|
||||
|
||||
for(i=0;i<nIndexList.num;i++)
|
||||
{
|
||||
MultiVertex *pOPVertexData=new MultiVertex[nVertexList[i]];
|
||||
MultiVertex *pOldVertex=VertexList[i];
|
||||
WORD *pOPIndicesData=new WORD[nIndexList[i]*3];
|
||||
|
||||
int cNowAdd=0;
|
||||
for(int cIndices=0;cIndices<nIndexList[i]*3;cIndices++)
|
||||
{
|
||||
MultiVertex CompareVertex=pOldVertex[IndexList[i][cIndices]];
|
||||
bool isAlready=false;
|
||||
for(int cVertex=0;cVertex<cNowAdd;cVertex++)
|
||||
{
|
||||
if(mode==0)
|
||||
{
|
||||
if( fabs( CompareVertex.v.x - pOPVertexData[cVertex].v.x ) <= fEll &&
|
||||
fabs( CompareVertex.v.y - pOPVertexData[cVertex].v.y ) <= fEll &&
|
||||
fabs( CompareVertex.v.z - pOPVertexData[cVertex].v.z ) <= fEll &&
|
||||
fabs( CompareVertex.tu - pOPVertexData[cVertex].tu ) <= fEll &&
|
||||
fabs( CompareVertex.tv - pOPVertexData[cVertex].tv ) <= fEll)
|
||||
{
|
||||
isAlready=true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if( fabs( CompareVertex.v.x - pOPVertexData[cVertex].v.x ) <= fEll &&
|
||||
fabs( CompareVertex.v.y - pOPVertexData[cVertex].v.y ) <= fEll &&
|
||||
fabs( CompareVertex.v.z - pOPVertexData[cVertex].v.z ) <= fEll &&
|
||||
fabs( CompareVertex.tu - pOPVertexData[cVertex].tu ) <= fEll &&
|
||||
fabs( CompareVertex.tv - pOPVertexData[cVertex].tv ) <= fEll &&
|
||||
fabs( CompareVertex.tu1 - pOPVertexData[cVertex].tu1) <= fEll &&
|
||||
fabs( CompareVertex.tv1 - pOPVertexData[cVertex].tv1) <= fEll)
|
||||
{
|
||||
isAlready=true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(isAlready)
|
||||
{
|
||||
pOPIndicesData[cIndices]=cVertex;
|
||||
}
|
||||
else
|
||||
{
|
||||
pOPVertexData[cVertex]=CompareVertex;
|
||||
pOPIndicesData[cIndices]=cVertex;
|
||||
cNowAdd++;
|
||||
}
|
||||
}
|
||||
nVertexList[i]=cNowAdd;
|
||||
delete [] VertexList[i];
|
||||
VertexList[i]=new MultiVertex[cNowAdd];
|
||||
memcpy(VertexList[i],pOPVertexData,sizeof(MultiVertex)*cNowAdd);
|
||||
memcpy(IndexList[i],pOPIndicesData,sizeof(WORD)*nIndexList[i]*3);
|
||||
|
||||
delete [] pOPVertexData;
|
||||
delete [] pOPIndicesData;
|
||||
}
|
||||
|
||||
fp=fopen(strFilename,"wb");
|
||||
|
||||
fwrite(&nObject,sizeof(int),1,fp);
|
||||
fwrite(&nMat,sizeof(int),1,fp);
|
||||
fwrite(&TextureSize,sizeof(int),1,fp);
|
||||
|
||||
for(i=0;i<nMat;i++)
|
||||
{
|
||||
fwrite(TextureNameList[i],sizeof(char)*256,1,fp);
|
||||
delete [] TextureNameList[i];
|
||||
}
|
||||
strcpy(strObjectName,"");
|
||||
|
||||
for(i=0;i<nObject;i++)
|
||||
{
|
||||
fwrite(strObjectName,sizeof(char)*256,1,fp);
|
||||
fwrite(&MatRefList[i],sizeof(long),1,fp);
|
||||
fwrite(&nVertexList[i],sizeof(long),1,fp);
|
||||
fwrite(&nIndexList[i],sizeof(int),1,fp);
|
||||
|
||||
fwrite(VertexList[i],sizeof(MultiVertex)*nVertexList[i],1,fp);
|
||||
fwrite(IndexList[i],sizeof(WORD)*nIndexList[i]*3,1,fp);
|
||||
|
||||
delete [] VertexList[i];
|
||||
delete [] IndexList[i];
|
||||
}
|
||||
fclose(fp);
|
||||
|
||||
/*
|
||||
for(i=0;i<nObject;i++)
|
||||
{
|
||||
fread(strObjectName,sizeof(char)*256,1,fp);
|
||||
fread(&MatRef,sizeof(long),1,fp);
|
||||
fread(&cVertex,sizeof(long),1,fp);
|
||||
fread(&cIndices,sizeof(int),1,fp);
|
||||
nVertexList.Add(cVertex);
|
||||
nIndexList.Add(cIndices);
|
||||
pVertexData=new MultiVertex[cVertex];
|
||||
pIndicesData=new WORD[cIndices*3];
|
||||
fread(pVertexData,sizeof(MultiVertex)*cVertex,1,fp);
|
||||
fread(pIndicesData,sizeof(WORD)*cIndices*3,1,fp);
|
||||
VertexList.Add(pVertexData);
|
||||
IndexList.Add(pIndicesData);
|
||||
}
|
||||
fclose(fp);
|
||||
|
||||
*/
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user