select.cpp
来自「quake3工具源码。包括生成bsp文件」· C++ 代码 · 共 1,712 行 · 第 1/3 页
CPP
1,712 行
=============
Select_Ungroup
Turn the currently selected entity back into normal brushes
=============
*/
void Select_Ungroup(void)
{
int numselectedgroups;
entity_t *e;
brush_t *b, *sb;
numselectedgroups = 0;
for (sb = selected_brushes.next; sb != &selected_brushes; sb = sb->next)
{
e = sb->owner;
if (!e || e == world_entity || e->eclass->fixedsize)
{
continue;
}
for (b = e->brushes.onext; b != &e->brushes; b = e->brushes.onext)
{
//Brush_RemoveFromList (b);
//Brush_AddToList (b, &active_brushes);
Entity_UnlinkBrush (b);
Entity_LinkBrush (world_entity, b);
Brush_Build( b );
b->owner = world_entity;
}
Entity_Free (e);
numselectedgroups++;
}
if (numselectedgroups <= 0)
{
Sys_Printf("No grouped entities selected.\n");
return;
}
Sys_Printf("Ungrouped %d entit%s.\n", numselectedgroups, (numselectedgroups == 1)?"y":"ies");
Sys_UpdateWindows (W_ALL);
}
/*
====================
Select_MakeStructural
====================
*/
void Select_MakeStructural (void)
{
brush_t *b;
face_t *f;
for (b=selected_brushes.next ; b != &selected_brushes ; b=b->next)
for (f=b->brush_faces ; f ; f=f->next)
f->texdef.contents &= ~CONTENTS_DETAIL;
Select_Deselect ();
Sys_UpdateWindows (W_ALL);
}
void Select_MakeDetail (void)
{
brush_t *b;
face_t *f;
for (b=selected_brushes.next ; b != &selected_brushes ; b=b->next)
for (f=b->brush_faces ; f ; f=f->next)
f->texdef.contents |= CONTENTS_DETAIL;
Select_Deselect ();
Sys_UpdateWindows (W_ALL);
}
void Select_ShiftTexture(int x, int y)
{
brush_t *b;
face_t *f;
int nFaceCount = g_ptrSelectedFaces.GetSize();
if(selected_brushes.next == &selected_brushes && nFaceCount == 0)
return;
for (b=selected_brushes.next ; b != &selected_brushes ; b=b->next)
{
for (f=b->brush_faces ; f ; f=f->next)
{
if (g_qeglobals.m_bBrushPrimitMode)
{
// use face normal to compute a true translation
Select_ShiftTexture_BrushPrimit( f, x, y );
}
else
{
f->texdef.shift[0] += x;
f->texdef.shift[1] += y;
}
}
Brush_Build(b);
if (b->patchBrush)
{
//Patch_ShiftTexture(b->nPatchID, x, y);
Patch_ShiftTexture(b->pPatch, x, y);
}
}
if (nFaceCount > 0)
{
for (int i = 0; i < nFaceCount; i++)
{
face_t *selFace = reinterpret_cast<face_t*>(g_ptrSelectedFaces.GetAt(i));
brush_t *selBrush = reinterpret_cast<brush_t*>(g_ptrSelectedFaceBrushes.GetAt(i));
if (g_qeglobals.m_bBrushPrimitMode)
{
// use face normal to compute a true translation
// Select_ShiftTexture_BrushPrimit( selected_face, x, y );
// use camera view to compute texture shift
g_pParentWnd->GetCamera()->ShiftTexture_BrushPrimit( selFace, x, y );
}
else
{
selFace->texdef.shift[0] += x;
selFace->texdef.shift[1] += y;
}
Brush_Build(selBrush);
}
}
Sys_UpdateWindows (W_CAMERA);
}
void Select_ScaleTexture(int x, int y)
{
brush_t *b;
face_t *f;
int nFaceCount = g_ptrSelectedFaces.GetSize();
if(selected_brushes.next == &selected_brushes && nFaceCount == 0)
{
return;
}
for (b=selected_brushes.next ; b != &selected_brushes ; b=b->next)
{
for (f=b->brush_faces ; f ; f=f->next)
{
if (g_qeglobals.m_bBrushPrimitMode)
{
// apply same scale as the spinner button of the surface inspector
float shift[2];
float rotate;
float scale[2];
brushprimit_texdef_t bp;
// compute normalized texture matrix
ConvertTexMatWithQTexture( &f->brushprimit_texdef, f->d_texture, &bp, NULL );
// compute fake shift scale rot
TexMatToFakeTexCoords( bp.coords, shift, &rotate, scale );
// update
scale[0]+=static_cast<float>(x)*0.1;
scale[1]+=static_cast<float>(y)*0.1;
// compute new normalized texture matrix
FakeTexCoordsToTexMat( shift, rotate, scale, bp.coords );
// apply to face texture matrix
ConvertTexMatWithQTexture( &bp, NULL, &f->brushprimit_texdef, f->d_texture );
}
else
{
f->texdef.scale[0] += x;
f->texdef.scale[1] += y;
}
}
Brush_Build(b);
if (b->patchBrush)
{
Patch_ScaleTexture(b->pPatch, x, y);
}
}
if (nFaceCount > 0)
{
for (int i = 0; i < nFaceCount; i++)
{
face_t *selFace = reinterpret_cast<face_t*>(g_ptrSelectedFaces.GetAt(i));
brush_t *selBrush = reinterpret_cast<brush_t*>(g_ptrSelectedFaceBrushes.GetAt(i));
if (g_qeglobals.m_bBrushPrimitMode)
{
float shift[2];
float rotate;
float scale[2];
brushprimit_texdef_t bp;
ConvertTexMatWithQTexture( &selFace->brushprimit_texdef, selFace->d_texture, &bp, NULL );
TexMatToFakeTexCoords( bp.coords, shift, &rotate, scale );
scale[0]+=static_cast<float>(x)*0.1;
scale[1]+=static_cast<float>(y)*0.1;
FakeTexCoordsToTexMat( shift, rotate, scale, bp.coords );
ConvertTexMatWithQTexture( &bp, NULL, &selFace->brushprimit_texdef, selFace->d_texture );
}
else
{
selFace->texdef.scale[0] += x;
selFace->texdef.scale[1] += y;
}
Brush_Build(selBrush);
}
}
Sys_UpdateWindows (W_CAMERA);
}
void Select_RotateTexture(int amt)
{
brush_t *b;
face_t *f;
int nFaceCount = g_ptrSelectedFaces.GetSize();
if(selected_brushes.next == &selected_brushes && nFaceCount == 0)
{
return;
}
for (b=selected_brushes.next ; b != &selected_brushes ; b=b->next)
{
for (f=b->brush_faces ; f ; f=f->next)
{
if (g_qeglobals.m_bBrushPrimitMode)
{
// apply same scale as the spinner button of the surface inspector
float shift[2];
float rotate;
float scale[2];
brushprimit_texdef_t bp;
// compute normalized texture matrix
ConvertTexMatWithQTexture( &f->brushprimit_texdef, f->d_texture, &bp, NULL );
// compute fake shift scale rot
TexMatToFakeTexCoords( bp.coords, shift, &rotate, scale );
// update
rotate += amt;
// compute new normalized texture matrix
FakeTexCoordsToTexMat( shift, rotate, scale, bp.coords );
// apply to face texture matrix
ConvertTexMatWithQTexture( &bp, NULL, &f->brushprimit_texdef, f->d_texture );
}
else
{
f->texdef.rotate += amt;
f->texdef.rotate = static_cast<int>(f->texdef.rotate) % 360;
}
}
Brush_Build(b);
if (b->patchBrush)
{
//Patch_RotateTexture(b->nPatchID, amt);
Patch_RotateTexture(b->pPatch, amt);
}
}
if (nFaceCount > 0)
{
for (int i = 0; i < nFaceCount; i++)
{
face_t *selFace = reinterpret_cast<face_t*>(g_ptrSelectedFaces.GetAt(i));
brush_t *selBrush = reinterpret_cast<brush_t*>(g_ptrSelectedFaceBrushes.GetAt(i));
if (g_qeglobals.m_bBrushPrimitMode)
{
float shift[2];
float rotate;
float scale[2];
brushprimit_texdef_t bp;
ConvertTexMatWithQTexture( &selFace->brushprimit_texdef, selFace->d_texture, &bp, NULL );
TexMatToFakeTexCoords( bp.coords, shift, &rotate, scale );
rotate += amt;
FakeTexCoordsToTexMat( shift, rotate, scale, bp.coords );
ConvertTexMatWithQTexture( &bp, NULL, &selFace->brushprimit_texdef, selFace->d_texture );
}
else
{
selFace->texdef.rotate += amt;
selFace->texdef.rotate = static_cast<int>(selFace->texdef.rotate) % 360;
}
Brush_Build(selBrush);
}
}
Sys_UpdateWindows (W_CAMERA);
}
void FindReplaceTextures(const char* pFind, const char* pReplace, bool bSelected, bool bForce)
{
brush_t* pList = (bSelected) ? &selected_brushes : &active_brushes;
if (!bSelected)
Select_Deselect();
for (brush_t* pBrush = pList->next ; pBrush != pList; pBrush = pBrush->next)
{
if (pBrush->patchBrush)
{
Patch_FindReplaceTexture(pBrush, pFind, pReplace, bForce);
}
for (face_t* pFace = pBrush->brush_faces; pFace; pFace = pFace->next)
{
if(bForce || strcmpi(pFace->texdef.name, pFind) == 0)
{
pFace->d_texture = Texture_ForName(pReplace);
//strcpy(pFace->texdef.name, pReplace);
pFace->texdef.SetName(pReplace);
}
}
Brush_Build(pBrush);
}
Sys_UpdateWindows (W_CAMERA);
}
void Select_AllOfType()
{
brush_t *b, *next;
entity_t *e;
if ( (selected_brushes.next == &selected_brushes)
|| (selected_brushes.next->next != &selected_brushes) )
{
CString strName;
if (g_ptrSelectedFaces.GetSize() == 0)
{
strName = g_qeglobals.d_texturewin.texdef.name;
}
else
{
face_t *selFace = reinterpret_cast<face_t*>(g_ptrSelectedFaces.GetAt(0));
strName = selFace->texdef.name;
}
Select_Deselect();
for (b=active_brushes.next ; b != &active_brushes ; b=next)
{
next = b->next;
if (FilterBrush (b))
continue;
if (b->patchBrush)
{
if (strcmpi(strName, b->pPatch->d_texture->name) == 0)
{
Brush_RemoveFromList (b);
Brush_AddToList (b, &selected_brushes);
}
}
else
{
for (face_t* pFace = b->brush_faces; pFace; pFace = pFace->next)
{
if (strcmpi(strName, pFace->texdef.name) == 0)
{
Brush_RemoveFromList (b);
Brush_AddToList (b, &selected_brushes);
}
}
}
}
Sys_UpdateWindows(W_ALL);
return;
}
b = selected_brushes.next;
e = b->owner;
if (e != NULL)
{
if (e != world_entity)
{
CString strName = e->eclass->name;
CString strKey, strVal;
bool bCriteria = GetSelectAllCriteria(strKey, strVal);
Sys_Printf("Selecting all %s(s)\n", strName);
Select_Deselect();
for (b=active_brushes.next ; b != &active_brushes ; b=next)
{
next = b->next;
if (FilterBrush (b))
continue;
e = b->owner;
if (e != NULL)
{
if (strcmpi(e->eclass->name, strName) == 0)
{
bool doIt = true;
if (bCriteria) {
CString str = ValueForKey (e, strKey);
if (str.CompareNoCase(strVal) != 0) {
doIt = false;
}
}
if (doIt) {
Brush_RemoveFromList (b);
Brush_AddToList (b, &selected_brushes);
}
}
}
}
}
}
Sys_UpdateWindows (W_ALL);
}
void Select_Reselect()
{
CPtrArray holdArray;
for (brush_t* b=selected_brushes.next ; b && b != &selected_brushes ; b=b->next)
{
holdArray.Add(reinterpret_cast<void*>(b));
}
int n = holdArray.GetSize();
while (n-- > 0)
{
b = reinterpret_cast<brush_t*>(holdArray.GetAt(n));
Select_Brush(b);
}
Sys_UpdateWindows (W_ALL);
}
void Select_FitTexture(int nHeight, int nWidth)
{
brush_t *b;
int nFaceCount = g_ptrSelectedFaces.GetSize();
if(selected_brushes.next == &selected_brushes && nFaceCount == 0)
return;
for (b=selected_brushes.next ; b != &selected_brushes ; b=b->next)
{
Brush_FitTexture(b, nHeight, nWidth);
Brush_Build(b);
}
if (nFaceCount > 0)
{
for (int i = 0; i < nFaceCount; i++)
{
face_t *selFace = reinterpret_cast<face_t*>(g_ptrSelectedFaces.GetAt(i));
brush_t *selBrush = reinterpret_cast<brush_t*>(g_ptrSelectedFaceBrushes.GetAt(i));
Face_FitTexture(selFace, nHeight, nWidth);
Brush_Build(selBrush);
}
}
Sys_UpdateWindows (W_CAMERA);
}
void Select_AxialTexture()
{
}
void Select_Hide()
{
for (brush_t* b=selected_brushes.next ; b && b != &selected_brushes ; b=b->next)
{
b->hiddenBrush = true;
}
Sys_UpdateWindows (W_ALL);
}
void Select_ShowAllHidden()
{
brush_t* b;
for (b=selected_brushes.next ; b && b != &selected_brushes ; b=b->next)
{
b->hiddenBrush = false;
}
for (b=active_brushes.next ; b && b != &active_brushes ; b=b->next)
{
b->hiddenBrush = false;
}
Sys_UpdateWindows (W_ALL);
}
/*
============
Select_Invert
============
*/
void Select_Invert(void)
{
brush_t *next, *prev;
Sys_Printf("inverting selection...\n");
next = active_brushes.next;
prev = active_brushes.prev;
if (selected_brushes.next != &selected_brushes)
{
active_brushes.next = selected_brushes.next;
active_brushes.prev = selected_brushes.prev;
active_brushes.next->prev = &active_brushes;
active_brushes.prev->next = &active_brushes;
}
else
{
active_brushes.next = &active_brushes;
active_brushes.prev = &active_brushes;
}
if (next != &active_brushes)
{
selected_brushes.next = next;
selected_brushes.prev = prev;
selected_brushes.next->prev = &selected_brushes;
selected_brushes.prev->next = &selected_brushes;
}
else
{
selected_brushes.next = &selected_brushes;
selected_brushes.prev = &selected_brushes;
}
Sys_UpdateWindows(W_ALL);
Sys_Printf("done.\n");
}
/*
===========
Select_Name
===========
*/
void Select_Name(const char *pName)
{
if (g_qeglobals.m_bBrushPrimitMode)
{
for (brush_t* b=selected_brushes.next ; b && b != &selected_brushes ; b=b->next)
{
Brush_SetEpair(b, "Name", pName);
}
}
}
/*
=================
Select_AddToGroup
add selected brushes to a group, update the tree
=================
*/
void Select_AddToGroup(const char *pName)
{
if (g_qeglobals.m_bBrushPrimitMode)
{
for (brush_t* b=selected_brushes.next ; b && b != &selected_brushes ; b=b->next)
{
Brush_SetEpair(b, "group", pName);
Group_AddToProperGroup(b);
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?