📄 utloader.cpp
字号:
// **************************************************************************************
// Copyright (c) 2000-2005 Zalsoft Inc
// www.zalsoft.com
// sales@zalsoft.com
// You are licensed to use this file on a single computer only.
// **************************************************************************************
#include "stdafx.h"
#include "stdio.h"
#include "baselib.h"
#include "basecont.h"
#include "UTLoader.h"
#define ASAMBLE_COMBINERS(c3_,c2_,c1_,nt_) MAKELONG(MAKEWORD(nt_, c1_),MAKEWORD(c2_,c2_))
//---------------------------------------------------------------------------------------
// polygon flags
#define POLY_INVISIBLE 1 //1
#define POLY_MASKED 2 //10
#define POLY_TRANSLUCENT 4 //100
#define POLY_NOTSOLID 8 //1000
#define POLY_ENVIRONMENT 16 //10000
#define POLY_FORCEVIEWZONE 16 //10000
#define POLY_SEMISOLID 32 //100000
#define POLY_MODULATED 64 //1000000
#define POLY_FAKEBACKDROP 128 //10000000
#define POLY_TWOSIDED 256 //100000000
#define POLY_AUTOUPAN 512 //1000000000
#define POLY_AUTOVPAN 1024 //10000000000
#define POLY_NOSMOOTH 2048 //100000000000
#define POLY_BIGWAVY 4096 //1000000000000
#define POLY_SPECIALPOLY 4096 //1000000000000
#define POLY_SMALLWAVY 8192 //10000000000000
#define POLY_FLAT 16384 //1000000000000000
#define POLY_LOWSHADOWDETAIL 32768 //10000000000000000
#define POLY_NOMERGE 65536 //100000000000000000
#define POLY_CLOUDWAVY 131072 //1000000000000000000
#define POLY_DIRTYSHADOWS 262144 //10000000000000000000
#define POLY_BRIGHTCORNERS 524288 //100000000000000000000
#define POLY_SPECIALLIT 1048576 //10000000000000000000000
#define POLY_GOURAUD 2097152 //100000000000000000000000
#define POLY_NOBOUNDREJECTION 2097152 //100000000000000000000000
#define POLY_UNLIT 4194304 //1000000000000000000000000
#define POLY_HIGHSHADOWDETAIL 8388608 //10000000000000000000000000
#define POLY_PORTAL 67108864 //100000000000000000000000000
#define POLY_MIRRORED 134217728 //1000000000000000000000000000
#define POLY_NOOCCLUDE (POLY_MASKED | POLY_TRANSLUCENT | POLY_INVISIBLE | POLY_MODULATED)
#define POLY_NOSHADOWS (POLY_UNLIT | POLY_INVISIBLE | POLY_ENVIRONMENT | POLY_FAKEBACKDROP)
//---------------------------------------------------------------------------------------
static struct
{
int utflag;
int geticflag;
}__flagMap[]={
{POLY_INVISIBLE ,FACE_TRANSPARENT},
{POLY_MASKED ,FACE_BLACKMASK},
{POLY_TRANSLUCENT ,0},
{POLY_NOTSOLID ,FACE_NOCOLLIDE},
{POLY_ENVIRONMENT ,0},
{POLY_FORCEVIEWZONE ,0},
{POLY_SEMISOLID ,0},
{POLY_MODULATED ,0},
{POLY_FAKEBACKDROP ,0},
{POLY_TWOSIDED ,FACE_SHOWBACK},
{POLY_AUTOUPAN ,0},
{POLY_AUTOVPAN ,0},
{POLY_NOSMOOTH ,0},
{POLY_BIGWAVY ,FACE_TA_WAVY},
{POLY_SPECIALPOLY ,0},
{POLY_SMALLWAVY ,FACE_TA_WAVY},
{POLY_FLAT ,0},
{POLY_LOWSHADOWDETAIL ,0},
{POLY_NOMERGE ,0},
{POLY_CLOUDWAVY ,FACE_TA_WAVY},
{POLY_DIRTYSHADOWS ,0},
{POLY_BRIGHTCORNERS ,0},
{POLY_SPECIALLIT ,FACE_FULLBRIGHT},
{POLY_GOURAUD ,FACE_GSHADE},
{POLY_NOBOUNDREJECTION,0},
{POLY_UNLIT ,FACE_NOLIGTMAP},
{POLY_HIGHSHADOWDETAIL,0 },
{POLY_PORTAL ,FACE_TRANSPARENT },
{POLY_MIRRORED ,FACE_MIRROR },
};
//------------------------------------------------------------------------------------------------
INLN char* StripChar(char* psz, char ch)
{
char* ps = psz;
char* pd = psz;
while(*ps){
if(*ps==ch)
{ ps++;continue;}
*pd++=*ps++;
}
*pd=0;
return psz;
}
//------------------------------------------------------------------------------------------------
long UTLoader::ExportFile(IGeticEditor* pe, char*,char* bsFileName, const Plg_Scene* pBrush)
{
_pe = pe;
return -1;
}
//------------------------------------------------------------------------------------------------
long UTLoader::GetMenuStringAndType(char* bsFileName, DWORD* type)
{
//large enough
_tcscpy(bsFileName,"UT Files,t3d");
*type = PLUG_IMPORTER;
return 0;
}
//------------------------------------------------------------------------------------------------
struct UtPoly
{
vvector<Vtx> _vxes;
DWORD _flags;
DWORD _origFlags;
int _texIdx;
V3 texax[2]; // texture axis (use them to save q and ut map file)
UV texPan; // shift on u and v (use them to save q and ut map file)
UV texScale;
};
//------------------------------------------------------------------------------------------------
struct UtModel
{
DWORD _flags;
vvector<UtPoly> _polys;
string _name;
};
//------------------------------------------------------------------------------------------------
struct UrScene
{
vvector<UtModel> _models;
vvector<string> _texnames;
// adds a unique tex and returns the index into this array
int AddTex(const char* n){
vvector<string>::iterator fi = find(_texnames.begin(), _texnames.end(), n);
if(fi != _texnames.end())
return fi-_texnames.begin();
_texnames<<n;
return _texnames.size()-1;
}
};
//------------------------------------------------------------------------------------------------
void UTLoader::CalcTexCoord(UrScene& s, UtPoly& p)
{
// get tex coord
int szX = 256, szY = 256; // dummy texture bmp size
if(_pe)
{
if(p._texIdx < s._texnames.size())
{
Plg_Texture dummyTex;
string& texname = s._texnames[p._texIdx];
::strcpy(dummyTex.filename, texname.c_str());
dummyTex.flags = 0; // want the dimensions only
if(NO_ERROR == _pe->GetTextureInfo(&dummyTex))
{
szX = dummyTex.dims[0];
szY = dummyTex.dims[1];
}
}
}
// texture origin
V3 texO = -(p.texPan.u * p.texax[0]) / p.texax[0].len();
texO -= (p.texPan.v * p.texax[1]) / p.texax[1].len();
V3 S = p.texax[0] / szX; // xbitmap
V3 T = p.texax[1] / szY; //ybitmap
REAL scaleS = S.len();
REAL scaleT = T.len();
S /= scaleS;
T /= scaleT;
for(int i=0; i < p._vxes.size() ;i++)
{
V3& v = p._vxes[i]._xyz;
UV& t = p._vxes[i]._uv[0];
V3 diffX = p._vxes[i]._xyz - texO;
t.u = Vdp(diffX , (S)) * scaleS;
t.v = Vdp(diffX , (T)) * scaleT;
}
//U = ((vertex - origin) dot textureU + panU)/texW
//V = ((vertex - origin) dot textureV + panV)/texH
}
//------------------------------------------------------------------------------------------------
BOOL UTLoader::HandlePolygon(UrScene& s, UtPoly& p, FILE* f, V3& location, V3& rotation)
{
char line[512];
V3 origin;
V3 normal;
V3 texV;
V3 texU;
UV pan;
V3 corners[12];
char* premain;
int vxidx = 0;
while(1)
{
::fgets(line,512,f);
if(feof(f))
break;
StripChar(line,' ');
StripChar(line,'\t');
if(strlen(line) < 8)
continue;
if(!strncmp(line, "EndPolygon",10))
break;
if(!strncmp(line, "Origin", 6))
{
premain = line + 6;
sscanf(premain,"%f,%f,%f",&origin.x,&origin.z,&origin.y);
continue;
}
if(!strncmp(line, "Normal", 6))
{
premain = line + 6;
sscanf(premain,"%f,%f,%f",&normal.x,&normal.z,&normal.y);
continue;
}
if(!strncmp(line, "Pan", 3))
{
// pan"U=0V=20"
premain = line + 3;
char local[32];
strcpy(local,premain);
char* ps = strtok(local,"V");
pan.u = atoi(ps+2);
ps = strtok(0,"V");
pan.v = atoi(ps+1);
continue;
}
if(!strncmp(line, "TextureU", 8))
{
premain = line + 8;
sscanf(premain,"%f,%f,%f",&texU.x,&texU.z,&texU.y);
texU.y=-texU.y;
}
if(!strncmp(line, "TextureV", 8))
{
premain = line + 8;
sscanf(premain,"%f,%f,%f",&texV.x,&texV.z,&texV.y);
texV.y=-texV.y;
}
if(!strncmp(line, "Vertex", 6))
{
premain = line + 6;
sscanf(premain,"%f,%f,%f",&corners[vxidx].x,
&corners[vxidx].z,
&corners[vxidx].y);
// corners[vxidx].z=-corners[vxidx].z;
++vxidx;
}
}
if(vxidx < 3)
return FALSE;
// M4 we are digging here......
M4 mt = MTranslate(-location.x, location.z, location.y);
//mt *= MRadRotate(rotation.x, rotation.z, rotation.y);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -