📄 utloader.cpp
字号:
//mt *= MRadRotate(rotation.x, rotation.z, rotation.y);
p.texax[0] = texU;
p.texax[1] = texV;
p.texPan = pan;
for(int j=0; j < vxidx; j++)
{
Vtx v;
v._xyz = corners[vxidx-j-1];
mt.v3transform(v._xyz);
p._vxes << v;
}
p._vxes.reverse();
Plane p2;
p2.CalcNormal(p._vxes[0]._xyz,p._vxes[1]._xyz,p._vxes[2]._xyz);
normal.norm();
if(IsZero(Vdp(p2._n, normal)), 0.0001)// poly has to be reversed
{
p._vxes.reverse();
}
return TRUE;
}
//---------------------------------------------------------------------------------------
void UTLoader::HandleBrush(FILE* f, UrScene& s, V3& location, V3 rotation, BOOL csgadd)
{
char line[512];
map<string, UtModel> models;
char* pszp;
string item = "def";
while(1)
{
fgets(line,512,f);
if(::strstr(line,"End Brush") ||
::strstr(line,"End PolyList"))
break;
if(feof(f))
break;
if(pszp = ::strstr(line,"Begin Polygon"))
{
UtPoly p;
DWORD uflgs = 0;
string texture;
DWORD flags = 0;
int link = 0;
char locline[512] ;
::strcpy(locline, pszp+13);
char* pline = locline;
char* ptok = " ";
char* pword;
while(pword = strtok(pline, ptok))
{
pline = 0;
if(!strncmp(pword,"Item",4))
{
item = pword+5;
}
else if(!strncmp(pword,"Texture",7))
{
texture = pword+8;
}
else if(!strncmp(pword,"Flags",5))
{
uflgs = ::atoi(pword+6);
for(int i=0; i < sizeof(__flagMap)/sizeof(__flagMap[0]); i++)
{
if(256 & uflgs)
TRACEX("");
if(__flagMap[i].utflag & uflgs)
{
flags|=__flagMap[i].geticflag;
}
}
}
else if(!strncmp(pword,"Link",4))
{
link = ::atoi(pword+5);
}
}
if(HandlePolygon(s, p, f, location, rotation))
{
if(texture.length())
p._texIdx = s.AddTex(texture.c_str());
else
p._texIdx = -1;
p._flags = flags;
p._origFlags = uflgs;
CalcTexCoord(s,p);
if(!(p._flags & FACE_TRANSPARENT))
{
// dont put them by brush name couse they dont define convex regions
models["a"]._name = item;
models["a"]._flags = csgadd ? BRSH_SOLID|BRSH_DISABLED : BRSH_CUT;
models["a"]._polys << p;
}
}
}
}
for(map<string, UtModel>::iterator b = models.begin();
b != models.end() ; b++)
{
s._models.push_back(b->second);
}
}
//---------------------------------------------------------------------------------------
long UTLoader::ImportFile(IGeticEditor* pe, char*,char* bsFileName, Plg_Scene** pScene)
{
_pe = pe;
FILE* f= _tfopen(bsFileName,"rb");
if(0 == f)
return 0;
char line[512];
BOOL csgadd=1;
UrScene s;
V3 location;
V3 rotation;
char* paftereq;
while(!feof(f))
{
fgets(line,512,f);
char* ps=0;
if(ps=strstr(line,"Class=Brush"))
{
location.reset();
rotation.reset();
}
else
if(ps=strstr(line,"CsgOper"))
{
char* pop = ps+strlen("CsgOper")+1;
if(!strncmp(pop, "CSG_Add",7))
csgadd=1;
else
csgadd=1;
}
else
if(strstr(line,"Location"))
{
paftereq = strstr(line,"X=");
if(paftereq)
{
paftereq+=2;
sscanf(paftereq,"%f",&location.x);
}
paftereq = strstr(line,"Y=");
if(paftereq)
{
paftereq+=2;
sscanf(paftereq,"%f",&location.y);
}
paftereq = strstr(line,"Z=");
if(paftereq)
{
paftereq+=2;
sscanf(paftereq,"%f",&location.z);
}
//(X=-1280.000000,Y=1280.000000,Z=384.000000)
}
else
if(strstr(line,"Rotation"))
{
// Rotation=(Yaw=16384)
paftereq = strstr(line,"Yaw=");
if(paftereq)
{
paftereq+=4;
sscanf(paftereq,"%f",&rotation.y);
rotation.y = G2R(rotation.y / 182.04);
}
paftereq = strstr(line,"Pitch=");
if(paftereq)
{
paftereq+=6;
sscanf(paftereq,"%f",&rotation.x);
rotation.x = G2R(rotation.x / 182.04);
}
paftereq = strstr(line,"Roll=");
if(paftereq)
{
paftereq+=5;
sscanf(paftereq,"%f",&rotation.z);
rotation.z = G2R(rotation.z / 182.04);
}
}
if(strstr(line,"Begin Brush") || strstr(line,"Begin PolyList"))
{
HandleBrush(f,s,location,rotation,csgadd);
}
if(feof(f))
break;
}
fclose(f);
// place collected scene in out param
*pScene = new Plg_Scene;
::memset(*pScene, 0, sizeof(Plg_Scene));
(*pScene)->flags = 0; // CALC_TEXCOORD1;
(*pScene)->nBrushes = s._models.size();
(*pScene)->pBrushes = new Plg_Brush[s._models.size()];
(*pScene)->nTextures = s._texnames.size();
(*pScene)->pTextures = new Plg_Texture[(*pScene)->nTextures];
for(int t=0; t< s._texnames.size(); t++)
{
::strcpy((*pScene)->pTextures[t].filename, s._texnames[t].c_str());
(*pScene)->pTextures[t].target = 0;
}
for(int i=0;i<s._models.size();i++)
{
UtModel& model = s._models[i];
(*pScene)->pBrushes[i].nPolys = model._polys.size();
(*pScene)->pBrushes[i].pPolys = new Plg_Poly[model._polys.size()];
(*pScene)->pBrushes[i].flags = model._flags;
if(model._name.length())
strcpy((*pScene)->pBrushes[i].name, model._name.c_str());
else
(*pScene)->pBrushes[i].name[0]=0;
for(int j=0;j<model._polys.size();j++)
{
UtPoly& poly = model._polys[j];
(*pScene)->pBrushes[i].pPolys[j].texIdx[0] = poly._texIdx;
(*pScene)->pBrushes[i].pPolys[j].texIdx[1] = -1;
(*pScene)->pBrushes[i].pPolys[j].texIdx[2] = -1;
(*pScene)->pBrushes[i].pPolys[j].texIdx[3] = -1;
(*pScene)->pBrushes[i].pPolys[j].combine = ASAMBLE_COMBINERS(0,1,0,0); //one texture no combiners
(*pScene)->pBrushes[i].pPolys[j].texapply[0] = 0;
(*pScene)->pBrushes[i].pPolys[j].texapply[1] = 0;
(*pScene)->pBrushes[i].pPolys[j].texapply[2] = 0;
(*pScene)->pBrushes[i].pPolys[j].user = poly._origFlags;
(*pScene)->pBrushes[i].pPolys[j].flags = poly._flags;
(*pScene)->pBrushes[i].pPolys[j].nvXes = poly._vxes.size();
(*pScene)->pBrushes[i].pPolys[j].vXes = new Vtx[poly._vxes.size()];
// global color
(*pScene)->pBrushes[i].pPolys[j].color = CLR(255,255,255);
int allv =poly._vxes.size()-1;
for(int k=0;k<poly._vxes.size();k++)
{
(*pScene)->pBrushes[i].pPolys[j].vXes[k] = poly._vxes[allv-k];
}
}
}
return 0;
}
//---------------------------------------------------------------------------------------
long UTLoader::ReleaseScene(Plg_Scene* pScene)
{
RELEASE_SCENE(pScene);// has to be on this heap
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -