pmesh.cpp
来自「quake3工具源码。包括生成bsp文件」· C++ 代码 · 共 2,635 行 · 第 1/5 页
CPP
2,635 行
float yc = (b->maxs[1] + b->mins[1]) * 0.5;
for ( i = 0 ; i < p->width ; i ++)
{
p->ctrl[i][2].xyz[0] = xc;
p->ctrl[i][2].xyz[1] = yc;
}
}
/*
if (bEndcap || bBevel)
{
if (bInverted)
{
for ( i = 0 ; i < p->height ; i ++)
{
if (bBevel)
{
VectorCopy(p->ctrl[7][i], p->ctrl[0][i]);
VectorCopy(p->ctrl[7][i], p->ctrl[8][i]);
VectorCopy(p->ctrl[3][i], p->ctrl[2][i]);
VectorCopy(p->ctrl[5][i], p->ctrl[1][i]);
VectorCopy(p->ctrl[5][i], p->ctrl[4][i]);
VectorCopy(p->ctrl[5][i], p->ctrl[6][i]);
}
else
{
VectorCopy(p->ctrl[4][i], p->ctrl[8][i]);
VectorCopy(p->ctrl[1][i], p->ctrl[0][i]);
VectorCopy(p->ctrl[1][i], p->ctrl[10][i]);
VectorCopy(p->ctrl[3][i], p->ctrl[2][i]);
VectorCopy(p->ctrl[5][i], p->ctrl[4][i]);
VectorCopy(p->ctrl[7][i], p->ctrl[6][i]);
VectorCopy(p->ctrl[5][i], p->ctrl[7][i]);
VectorCopy(p->ctrl[3][i], p->ctrl[9][i]);
}
}
}
else
{
for ( i = 0 ; i < p->height ; i ++)
{
VectorCopy(p->ctrl[1][i], p->ctrl[2][i]);
VectorCopy(p->ctrl[7][i], p->ctrl[6][i]);
if (bBevel)
{
VectorCopy(p->ctrl[5][i], p->ctrl[4][i]);
}
}
}
}
*/
b = AddBrushForPatch(p);
#if 1
Select_Delete();
Select_Brush(b);
#else
if (!bCone)
{
Select_Delete();
Select_Brush(b);
GenerateEndCaps(b, bBevel, bEndcap, bInverted);
eclass_t *pecNew = Eclass_ForName("func_group", false);
if (pecNew)
{
Entity_Create(pecNew);
}
}
else
{
Select_Delete();
Select_Brush(b);
}
#endif
}
/*
==================
Patch_GenericMesh
==================
*/
brush_t* Patch_GenericMesh(int nWidth, int nHeight, int nOrientation, bool bDeleteSource, bool bOverride)
{
int i,j;
if (nHeight < 3 || nHeight > 15 || nWidth < 3 || nWidth > 15)
{
Sys_Printf("Invalid patch width or height.\n");
return NULL;
}
if (! bOverride && !QE_SingleBrush())
{
Sys_Printf("Cannot generate a patch from multiple selections.\n");
return NULL;
}
patchMesh_t* p = MakeNewPatch();
p->d_texture = Texture_ForName(g_qeglobals.d_texturewin.texdef.name);
p->width = nWidth;
p->height = nHeight;
p->type = PATCH_GENERIC;
int nFirst = 0;
int nSecond = 1;
if (nOrientation == 0)
{
nFirst = 1;
nSecond = 2;
}
else if (nOrientation == 1)
{
nSecond = 2;
}
brush_t *b = selected_brushes.next;
int xStep = b->mins[nFirst];
float xAdj = abs((b->maxs[nFirst] - b->mins[nFirst]) / (nWidth - 1));
float yAdj = abs((b->maxs[nSecond] - b->mins[nSecond]) / (nHeight - 1));
for (i = 0; i < nWidth; i++)
{
int yStep = b->mins[nSecond];
for (j = 0; j < nHeight; j++)
{
p->ctrl[i][j].xyz[nFirst] = xStep;
p->ctrl[i][j].xyz[nSecond] = yStep;
p->ctrl[i][j].xyz[nOrientation] = 0;
yStep += yAdj;
}
xStep += xAdj;
}
Patch_Naturalize(p);
b = AddBrushForPatch(p);
if (bDeleteSource)
{
Select_Delete();
Select_Brush(b);
}
return b;
//g_qeglobals.d_select_mode = sel_curvepoint;
}
/*
==================
PointInMoveList
==================
*/
int PointInMoveList(float *pf)
{
for (int i = 0; i < g_qeglobals.d_num_move_points; i++)
{
if (pf == &g_qeglobals.d_move_points[i][0])
return i;
}
return -1;
}
/*
==================
PointValueInMoveList
==================
*/
int PointValueInMoveList(vec3_t v)
{
for (int i = 0; i < g_qeglobals.d_num_move_points; i++)
{
if (VectorCompare(v, g_qeglobals.d_move_points[i]))
return i;
}
return -1;
}
/*
==================
RemovePointFromMoveList
==================
*/
void RemovePointFromMoveList(vec3_t v)
{
int n;
while ( (n = PointValueInMoveList(v)) >= 0)
{
for (int i = n; i < g_qeglobals.d_num_move_points-1; i++)
{
g_qeglobals.d_move_points[i] = g_qeglobals.d_move_points[i+1];
}
g_qeglobals.d_num_move_points--;
}
}
/*
==================
ColumnSelected
==================
*/
bool ColumnSelected(patchMesh_t* p, int nCol)
{
for (int i = 0; i < p->height; i++)
{
if (PointInMoveList(p->ctrl[nCol][i].xyz) == -1)
return false;
}
return true;
}
/*
==================
AddPoint
==================
*/
void AddPoint(patchMesh_t* p, vec3_t v, bool bWeldOrDrill = true)
{
int nDim1 = (g_pParentWnd->ActiveXY()->GetViewType() == YZ) ? 1 : 0;
int nDim2 = (g_pParentWnd->ActiveXY()->GetViewType() == XY) ? 1 : 2;
g_qeglobals.d_move_points[g_qeglobals.d_num_move_points++] = v;
if ((g_bPatchWeld || g_bPatchDrillDown) && bWeldOrDrill)
{
for ( int i = 0 ; i < p->width ; i++ )
{
for ( int j = 0 ; j < p->height ; j++ )
{
if (g_bPatchWeld)
{
if ( VectorCompare(v, p->ctrl[i][j].xyz)
&& PointInMoveList(p->ctrl[i][j].xyz) == -1)
{
g_qeglobals.d_move_points[g_qeglobals.d_num_move_points++] = p->ctrl[i][j].xyz;
continue;
}
}
if (g_bPatchDrillDown && g_nPatchClickedView != W_CAMERA)
{
if ( (fabs(v[nDim1] - p->ctrl[i][j].xyz[nDim1]) <= EQUAL_EPSILON)
&&(fabs(v[nDim2] - p->ctrl[i][j].xyz[nDim2]) <= EQUAL_EPSILON))
{
if (PointInMoveList(p->ctrl[i][j].xyz) == -1)
{
g_qeglobals.d_move_points[g_qeglobals.d_num_move_points++] = p->ctrl[i][j].xyz;
continue;
}
}
#if 0
int l = 0;
for ( int k = 0; k < 2; k++ )
{
if (fabs(v[k] - p->ctrl[i][j].xyz[k]) > EQUAL_EPSILON)
continue;
l++;
}
if (l >= 2 && PointInMoveList(p->ctrl[i][j].xyz) == -1)
{
g_qeglobals.d_move_points[g_qeglobals.d_num_move_points++] = p->ctrl[i][j].xyz;
continue;
}
#endif
}
}
}
}
#if 0
if (g_qeglobals.d_num_move_points == 1)
{
// single point selected
// FIXME: the two loops can probably be reduced to one
for ( int i = 0 ; i < p->width ; i++ )
{
for ( int j = 0 ; j < p->height ; j++ )
{
int n = PointInMoveList(v);
if (n >= 0)
{
if (((i & 0x01) && (j & 0x01)) == 0)
{
// put any sibling fixed points
// into the inverse list
int p1, p2, p3, p4;
p1 = i + 2;
p2 = i - 2;
p3 = j + 2;
p4 = j - 2;
if (p1 < p->width)
{
}
if (p2 >= 0)
{
}
if (p3 < p->height)
{
}
if (p4 >= 0)
{
}
}
}
}
}
}
#endif
}
/*
==================
SelectRow
==================
*/
void SelectRow(patchMesh_t* p, int nRow, bool bMulti)
{
if (!bMulti)
g_qeglobals.d_num_move_points = 0;
for (int i = 0; i < p->width; i++)
{
AddPoint(p, p->ctrl[i][nRow].xyz, false);
}
//Sys_Printf("Selected Row %d\n", nRow);
}
/*
==================
SelectColumn
==================
*/
void SelectColumn(patchMesh_t* p, int nCol, bool bMulti)
{
if (!bMulti)
g_qeglobals.d_num_move_points = 0;
for (int i = 0; i < p->height; i++)
{
AddPoint(p, p->ctrl[nCol][i].xyz, false);
}
//Sys_Printf("Selected Col %d\n", nCol);
}
/*
==================
AddPatchMovePoint
==================
*/
void AddPatchMovePoint(vec3_t v, bool bMulti, bool bFull)
{
if (!g_bSameView && !bMulti && !bFull)
{
g_bSameView = true;
return;
}
for (brush_t *pb = selected_brushes.next ; pb != &selected_brushes ; pb = pb->next)
{
if (pb->patchBrush)
{
patchMesh_t* p = pb->pPatch;
for ( int i = 0 ; i < p->width ; i++ )
{
for ( int j = 0 ; j < p->height ; j++ )
{
if (VectorCompare(v, p->ctrl[i][j].xyz))
{
if (PointInMoveList(p->ctrl[i][j].xyz) == -1)
{
if (bFull) // if we want the full row/col this is on
{
SelectColumn(p, i, bMulti);
}
else
{
if (!bMulti)
g_qeglobals.d_num_move_points = 0;
AddPoint(p, p->ctrl[i][j].xyz);
//Sys_Printf("Selected col:row %d:%d\n", i, j);
}
//--if (!bMulti)
return;
}
else
{
if (bFull)
{
if (ColumnSelected(p, i))
{
SelectRow(p, j, bMulti);
}
else
{
SelectColumn(p, i, bMulti);
}
return;
}
if (g_bSameView)
{
RemovePointFromMoveList(v);
return;
}
}
}
}
}
}
}
}
/*
==================
Patch_UpdateSelected
==================
*/
void Patch_UpdateSelected(vec3_t vMove)
{
int i, j;
for (i=0 ; i < g_qeglobals.d_num_move_points ; i++)
{
VectorAdd (g_qeglobals.d_move_points[i], vMove, g_qeglobals.d_move_points[i]);
if (g_qeglobals.d_num_move_points == 1)
{
}
}
//--patchMesh_t* p = &patchMeshes[g_nSelectedPatch];
for (brush_t *pb = selected_brushes.next ; pb != &selected_brushes ; pb = pb->next)
{
if (pb->patchBrush)
{
patchMesh_t* p = pb->pPatch;
g_qeglobals.d_numpoints = 0;
for (i = 0 ; i < p->width ; i++ )
{
for ( j = 0 ; j < p->height ; j++ )
{
VectorCopy (p->ctrl[i][j].xyz, g_qeglobals.d_points[g_qeglobals.d_numpoints]);
if (g_qeglobals.d_numpoints < MAX_POINTS-1)
{
g_qeglobals.d_numpoints++;
}
}
}
vec3_t vMin, vMax;
Patch_CalcBounds(p, vMin, vMax);
Brush_RebuildBrush(p->pSymbiot, vMin, vMax);
}
}
//Brush_Free(p->pSymbiot);
//Select_Brush(AddBrushForPatch(g_nSelectedPatch));
}
/*
===============
SampleSinglePatch
===============
*/
void SampleSinglePatch (float ctrl[3][3][5], float u, float v, float out[5]) {
float vCtrl[3][5];
int vPoint;
int axis;
// find the control points for the v coordinate
for (vPoint = 0 ; vPoint < 3 ; vPoint++)
{
for (axis = 0 ; axis < 5 ; axis++)
{
float a, b, c;
float qA, qB, qC;
a = ctrl[0][vPoint][axis];
b = ctrl[1][vPoint][axis];
c = ctrl[2][vPoint][axis];
qA = a - 2 * b + c;
qB = 2 * b - 2 * a;
qC = a;
vCtrl[vPoint][axis] = qA * u * u + qB * u + qC;
}
}
// interpolate the v value
for (axis = 0 ; axis < 5 ; axis++)
{
float a, b, c;
float qA, qB, qC;
a = vCtrl[0][axis];
b = vCtrl[1][axis];
c = vCtrl[2][axis];
qA = a - 2 * b + c;
qB = 2 * b - 2 * a;
qC = a;
out[axis] = qA * v * v + qB * v + qC;
}
}
/*
===================
DrawSinglePatch
===================
*/
void DrawSinglePatch (float ctrl[3][3][5], bool bPoints)
{
int i, j;
float u, v;
float verts[CBLOCK_SUBDIVISIONS+1][CBLOCK_SUBDIVISIONS+1][5];
for (i = 0 ; i <= CBLOCK_SUBDIVISIONS ; i++)
{
for (j = 0 ; j <= CBLOCK_SUBDIVISIONS ; j++)
{
u = (float)i / CBLOCK_SUBDIVISIONS;
v = (float)j / CBLOCK_SUBDIVISIONS;
SampleSinglePatch (ctrl, u, v, verts[i][j]);
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?