2 Copyright (C) 1999-2007 id Software, Inc. and contributors.
3 For a list of contributors, see the accompanying CONTRIBUTORS file.
5 This file is part of GtkRadiant.
7 GtkRadiant is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 GtkRadiant is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GtkRadiant; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28 CPtrArray g_SelectedFaces;
29 CPtrArray g_SelectedFaceBrushes;
30 CPtrArray& g_ptrSelectedFaces = g_SelectedFaces;
31 CPtrArray& g_ptrSelectedFaceBrushes = g_SelectedFaceBrushes;
38 #define DIST_START 999999
39 trace_t Test_Ray (vec3_t origin, vec3_t dir, int flags)
46 memset (&t, 0, sizeof(t));
52 brush_t *pToSelect = (selected_brushes.next != &selected_brushes) ? selected_brushes.next : NULL;
55 // go through active brushes and accumulate all "hit" brushes
56 for (brush = active_brushes.next ; brush != &active_brushes ; brush=brush->next)
58 //if ( (flags & SF_ENTITIES_FIRST) && brush->owner == world_entity)
64 if (!g_PrefsDlg.m_bSelectCurves && brush->patchBrush)
67 if (!g_PrefsDlg.m_bSelectModels && (brush->owner->eclass->nShowFlags & ECLASS_MISCMODEL))
70 //if (!g_bShowPatchBounds && brush->patchBrush)
73 face = Brush_Ray (origin, dir, brush, &dist, flags);
79 int nSize = array.GetSize();
83 for (int i = 0; i < nSize; i++)
85 brush_t *b = reinterpret_cast<brush_t*>(array.GetAt(i));
86 // did we hit the last one selected yet ?
89 // yes we want to select the next one in the list
90 int n = (i > 0) ? i-1 : nSize-1;
91 pToSelect = reinterpret_cast<brush_t*>(array.GetAt(n));
97 pToSelect = reinterpret_cast<brush_t*>(array.GetAt(0));
101 face = Brush_Ray (origin, dir, pToSelect, &dist, flags);
110 if (! (flags & SF_SELECTED_ONLY) )
112 for (brush = active_brushes.next ; brush != &active_brushes ; brush=brush->next)
114 if ( (flags & SF_ENTITIES_FIRST) && (brush->owner == world_entity || !brush->owner->eclass->fixedsize))
117 if (brush->bFiltered)
120 if (!g_PrefsDlg.m_bSelectCurves && brush->patchBrush)
123 if (!g_PrefsDlg.m_bSelectModels && (brush->owner->eclass->nShowFlags & ECLASS_MISCMODEL))
126 //if (!g_bShowPatchBounds && brush->patchBrush)
129 face = Brush_Ray (origin, dir, brush, &dist, flags);
130 if (face && dist > 0 && dist < t.dist)
141 for (brush = selected_brushes.next ; brush != &selected_brushes ; brush=brush->next)
143 if ( (flags & SF_ENTITIES_FIRST) && (brush->owner == world_entity || !brush->owner->eclass->fixedsize))
146 if (brush->bFiltered)
149 if (!g_PrefsDlg.m_bSelectCurves && brush->patchBrush)
152 if (!g_PrefsDlg.m_bSelectModels && (brush->owner->eclass->nShowFlags & ECLASS_MISCMODEL))
155 face = Brush_Ray (origin, dir, brush, &dist, flags);
156 if (dist > 0 && dist < t.dist)
165 // if entites first, but didn't find any, check regular
167 if ( (flags & SF_ENTITIES_FIRST) && t.brush == NULL)
168 return Test_Ray (origin, dir, flags & ~SF_ENTITIES_FIRST);
181 void Select_Brush (brush_t *brush, bool bComplete, bool bStatus)
186 g_ptrSelectedFaces.RemoveAll();
187 g_ptrSelectedFaceBrushes.RemoveAll();
188 if (g_qeglobals.d_select_count < 2)
189 g_qeglobals.d_select_order[g_qeglobals.d_select_count] = brush;
190 g_qeglobals.d_select_count++;
195 // select complete entity on first click
196 if (e != world_entity && bComplete == true)
198 for (b=selected_brushes.next ; b != &selected_brushes ; b=b->next)
201 for (b=e->brushes.onext ; b != &e->brushes ; b=b->onext)
203 if( b == brush ) // make sure we add the actual selected brush last, mainly for cycle select
205 Brush_RemoveFromList (b);
206 Brush_AddToList (b, &selected_brushes);
208 Brush_RemoveFromList (brush);
209 Brush_AddToList (brush, &selected_brushes);
214 Brush_RemoveFromList (brush);
215 Brush_AddToList (brush, &selected_brushes);
216 UpdatePatchInspector();
221 UpdateEntitySel(brush->owner->eclass);
224 UpdateSurfaceDialog();
229 vec3_t vMin, vMax, vSize;
230 Select_GetBounds (vMin, vMax);
231 VectorSubtract(vMax, vMin, vSize);
233 strStatus.Format("Selection X:: %.1f Y:: %.1f Z:: %.1f", vSize[0], vSize[1], vSize[2]);
234 g_pParentWnd->SetStatusText(2, strStatus);
240 Select_FaceInSelectedBrushes
243 bool Select_FaceInSelectedBrushes( face_t *face )
248 for(brush = selected_brushes.next; brush != &selected_brushes; brush = brush->next)
250 for(tface = brush->brush_faces; tface; tface = tface->next)
266 If the origin is inside a brush, that brush will be ignored.
269 void Select_Ray (vec3_t origin, vec3_t dir, int flags)
274 static trace_t lastTrace = {
281 t = Test_Ray (origin, dir, flags);
285 if (flags & SF_SINGLEFACE)
287 if( flags & SF_DRAG )
289 if ( t.brush == lastTrace.brush && t.face == lastTrace.face )
294 if(Select_FaceInSelectedBrushes(t.face))
296 // Deselect the brush
297 Brush_RemoveFromList (t.brush);
298 Brush_AddToList (t.brush, &active_brushes);
299 UpdatePatchInspector();
301 // Select all of the brush's faces except the one we are pointing at
302 for( tface = t.brush->brush_faces; tface; tface = tface->next )
304 if( tface == t.face )
308 // NOTE: keep the size check in the loop, we remove stuff inside
309 for (int i = 0; i < g_SelectedFaces.GetSize(); i++)
311 if (tface == reinterpret_cast<face_t*>(g_SelectedFaces.GetAt(i)))
317 g_SelectedFaces.Add(tface);
318 g_SelectedFaceBrushes.Add(t.brush);
321 g_qeglobals.d_select_mode = sel_facets_off;
326 // NOTE: keep the size check in the loop, we remove stuff inside
327 for (int i = 0; i < g_SelectedFaces.GetSize(); i++)
329 if (t.face == reinterpret_cast<face_t*>(g_SelectedFaces.GetAt(i)))
332 if( flags & SF_DRAG_ON )
335 g_qeglobals.d_select_mode = sel_facets_off;
336 // need to remove i'th entry
337 g_SelectedFaces.RemoveAt(i, 1);
338 g_SelectedFaceBrushes.RemoveAt(i, 1);
342 if (bOk && !(flags & SF_DRAG_OFF))
344 g_SelectedFaces.Add(t.face);
345 g_SelectedFaceBrushes.Add(t.brush);
346 g_qeglobals.d_select_mode = sel_facets_on;
349 UpdateSurfaceDialog();
350 Sys_UpdateWindows (W_ALL);
351 //g_qeglobals.d_select_mode = sel_brush;
352 // Texture_SetTexture requires a brushprimit_texdef fitted to the default width=2 height=2 texture
353 brushprimit_texdef_t brushprimit_texdef;
354 ConvertTexMatWithQTexture ( &t.face->brushprimit_texdef, t.face->d_texture, &brushprimit_texdef, NULL );
355 Texture_SetTexture ( &t.face->texdef, &brushprimit_texdef, false, NULL, false );
359 // move the brush to the other list
362 if( flags & SF_DRAG_ON )
365 g_qeglobals.d_select_mode = sel_brush_off;
366 Brush_RemoveFromList (t.brush);
367 Brush_AddToList (t.brush, &active_brushes);
369 UpdatePatchInspector();
373 if( flags & SF_DRAG_OFF )
376 g_qeglobals.d_select_mode = sel_brush_on;
377 Select_Brush (t.brush, g_PrefsDlg.m_nCamDragMultiSelect == 1 ? Sys_AltDown () : !Sys_AltDown ());
379 UpdateSurfaceDialog();
380 Sys_UpdateWindows (W_ALL);
384 void Select_Delete (void)
389 g_ptrSelectedFaces.RemoveAll();
390 g_ptrSelectedFaceBrushes.RemoveAll();
392 g_qeglobals.d_select_mode = sel_brush;
394 g_qeglobals.d_select_count = 0;
395 g_qeglobals.d_num_move_points = 0;
396 while (selected_brushes.next != &selected_brushes)
398 brush = selected_brushes.next;
399 if (brush->patchBrush)
401 Patch_Delete(brush->pPatch);
405 // remove if no brushes
406 if (e != world_entity && e->brushes.onext == &e->brushes)
410 Sys_MarkMapModified ();
411 UpdateSurfaceDialog();
412 Sys_UpdateWindows (W_ALL);
415 // update the workzone to a given brush
416 void UpdateWorkzone_ForBrush( brush_t* b )
418 VectorCopy( b->mins, g_qeglobals.d_work_min );
419 VectorCopy( b->maxs, g_qeglobals.d_work_max );
422 // will update the workzone to the given brush
423 // g_pParentWnd->ActiveXY()->GetViewType()
424 // cf VIEWTYPE defintion: enum VIEWTYPE {YZ, XZ, XY};
425 // we fit our work zone to the last brush on the list (b)
426 int nViewType = g_pParentWnd->ActiveXY()->GetViewType();
427 int nDim1 = (nViewType == YZ) ? 1 : 0;
428 int nDim2 = (nViewType == XY) ? 1 : 2;
429 g_qeglobals.d_work_min[nDim1] = b->mins[nDim1];
430 g_qeglobals.d_work_max[nDim1] = b->maxs[nDim1];
431 g_qeglobals.d_work_min[nDim2] = b->mins[nDim2];
432 g_qeglobals.d_work_max[nDim2] = b->maxs[nDim2];
436 // here to filter new brushes once unselected
437 extern void PerformFiltering();
439 void Select_Deselect (bool bDeselectFaces)
445 g_pParentWnd->ActiveXY()->UndoClear();
447 g_qeglobals.d_workcount++;
448 g_qeglobals.d_select_count = 0;
449 g_qeglobals.d_num_move_points = 0;
450 b = selected_brushes.next;
452 if (b == &selected_brushes)
456 g_ptrSelectedFaces.RemoveAll();
457 g_ptrSelectedFaceBrushes.RemoveAll();
460 UpdateSurfaceDialog();
461 Sys_UpdateWindows (W_ALL);
467 g_ptrSelectedFaces.RemoveAll();
468 g_ptrSelectedFaceBrushes.RemoveAll();
471 g_qeglobals.d_select_mode = sel_brush;
473 UpdateWorkzone_ForBrush(b);
475 selected_brushes.next->prev = &active_brushes;
476 selected_brushes.prev->next = active_brushes.next;
477 active_brushes.next->prev = selected_brushes.prev;
478 active_brushes.next = selected_brushes.next;
479 selected_brushes.prev = selected_brushes.next = &selected_brushes;
481 // filter newly created stuff once it's unselected
483 UpdateSurfaceDialog();
484 Sys_UpdateWindows (W_ALL);
492 /*! Moves the currently selected brush/patch
493 \param delta How far to move the selection (x,y,z)
494 \param bSnap If the move should snap to grid points
496 void Select_Move (vec3_t delta, bool bSnap)
500 // actually move the selected brushes
501 for (b = selected_brushes.next ; b != &selected_brushes ; b=b->next)
502 Brush_Move (b, delta, bSnap);
505 Select_GetBounds (vMin, vMax);
507 strStatus.Format("Origin X:: %.1f Y:: %.1f Z:: %.1f", vMin[0], vMax[1], vMax[2]);
508 g_pParentWnd->SetStatusText(2, strStatus);
510 //Sys_UpdateWindows (W_ALL);
518 /*! Moves the currently selected brush/patch vertices
519 \param delta How far to move the vertices (x,y,z)
520 \param bSnap If the move should snap to grid points
522 void Select_NudgePoint(vec3_t delta, qboolean bSnap)
524 if (g_qeglobals.d_select_mode == sel_vertex)
526 // move selected verts
529 qboolean success = true;
530 for (b = selected_brushes.next; b != &selected_brushes; b = b->next)
532 success &= (qboolean)Brush_MoveVertex(b, g_qeglobals.d_move_points[0], delta, end, bSnap);
535 VectorCopy(end, g_qeglobals.d_move_points[0]);
537 else if (g_qeglobals.d_select_mode == sel_curvepoint)
539 // move selected patch control points
540 Patch_UpdateSelected(delta);
548 Creates an exact duplicate of the selection in place, then moves
549 the selected brushes off of their old positions
552 void Select_Clone (void)
554 g_bScreenUpdates = false;
555 g_pParentWnd->Copy();
557 g_pParentWnd->Paste();
558 g_pParentWnd->NudgeSelection(2, g_qeglobals.d_gridsize);
559 g_pParentWnd->NudgeSelection(3, g_qeglobals.d_gridsize);
561 Undo_EndBrushList(&selected_brushes);
563 g_bScreenUpdates = true;
564 Sys_UpdateWindows(W_ALL);
572 Timo : bFitScale to compute scale on the plane and counteract plane / axial plane snapping
573 Timo : brush primitive texturing
574 the brushprimit_texdef given must be understood as a qtexture_t width=2 height=2 ( HiRes )
575 Timo : texture plugin, added an IPluginTexdef* parameter
576 must be casted to an IPluginTexdef!
577 if not NULL, get ->Copy() of it into each face or brush ( and remember to hook )
578 if NULL, means we have no information, ask for a default
579 TTimo - shader code cleanup
580 added IShader* parameter
583 void WINAPI Select_SetTexture2 (IShader* pShader, texdef_t *texdef, brushprimit_texdef_t *brushprimit_texdef, bool bFitScale, void* pPlugTexdef )
586 int nCount = g_ptrSelectedFaces.GetSize();
589 Undo_Start("set face textures");
590 ASSERT(g_ptrSelectedFaces.GetSize() == g_ptrSelectedFaceBrushes.GetSize());
591 for (int i = 0; i < nCount; i++)
593 face_t *selFace = reinterpret_cast<face_t*>(g_ptrSelectedFaces.GetAt(i));
594 brush_t *selBrush = reinterpret_cast<brush_t*>(g_ptrSelectedFaceBrushes.GetAt(i));
595 Undo_AddBrush(selBrush);
596 //++timo TODO: propagate the IShader* ..
597 SetFaceTexdef (selFace, texdef, brushprimit_texdef, bFitScale, static_cast<IPluginTexdef *>(pPlugTexdef) );
598 Brush_Build(selBrush, bFitScale);
599 Undo_EndBrush(selBrush);
603 else if (selected_brushes.next != &selected_brushes)
605 Undo_Start("set brush textures");
606 for (b=selected_brushes.next ; b != &selected_brushes ; b=b->next)
607 if (!b->owner->eclass->fixedsize)
610 Brush_SetTexture2 (b, pShader, texdef, brushprimit_texdef, bFitScale, static_cast<IPluginTexdef *>(pPlugTexdef) );
615 Sys_UpdateWindows (W_ALL);
622 Timo : bFitScale to compute scale on the plane and counteract plane / axial plane snapping
623 Timo : brush primitive texturing
624 the brushprimit_texdef given must be understood as a qtexture_t width=2 height=2 ( HiRes )
625 Timo : texture plugin, added an IPluginTexdef* parameter
626 must be casted to an IPluginTexdef!
627 if not NULL, get ->Copy() of it into each face or brush ( and remember to hook )
628 if NULL, means we have no information, ask for a default
631 void WINAPI Select_SetTexture (texdef_t *texdef, brushprimit_texdef_t *brushprimit_texdef, bool bFitScale, void* pPlugTexdef )
635 static int count = 0;
642 Sys_Printf("count: %d\n", count);
644 Sys_Printf("break!\n");
647 int nCount = g_ptrSelectedFaces.GetSize();
650 Undo_Start("set face textures");
651 assert(g_ptrSelectedFaces.GetSize() == g_ptrSelectedFaceBrushes.GetSize());
652 for (int i = 0; i < nCount; i++)
654 face_t *selFace = reinterpret_cast<face_t*>(g_ptrSelectedFaces.GetAt(i));
655 brush_t *selBrush = reinterpret_cast<brush_t*>(g_ptrSelectedFaceBrushes.GetAt(i));
656 Undo_AddBrush(selBrush);
657 SetFaceTexdef (selFace, texdef, brushprimit_texdef, bFitScale, static_cast<IPluginTexdef *>(pPlugTexdef) );
658 Brush_Build(selBrush, bFitScale);
659 Undo_EndBrush(selBrush);
663 else if (selected_brushes.next != &selected_brushes)
665 Undo_Start("set brush textures");
666 for (b=selected_brushes.next ; b != &selected_brushes ; b=b->next)
667 if (!b->owner->eclass->fixedsize)
670 Brush_SetTexture (b, texdef, brushprimit_texdef, bFitScale, static_cast<IPluginTexdef *>(pPlugTexdef) );
675 //++timo FIXME: not necessary in every cases, write a message defering / move one level up
676 Sys_UpdateWindows (W_ALL);
681 ================================================================
685 ================================================================
688 void Select_GetBounds (vec3_t mins, vec3_t maxs)
693 for (i=0 ; i<3 ; i++)
699 for (b=selected_brushes.next ; b != &selected_brushes ; b=b->next)
701 if (b->owner->eclass->fixedsize)
703 for (i=0 ; i<3 ; i++)
705 if (b->owner->origin[i] < mins[i])
706 mins[i] = b->owner->origin[i];
707 if (b->owner->origin[i] > maxs[i])
708 maxs[i] = b->owner->origin[i];
713 for (i=0 ; i<3 ; i++)
715 if (b->mins[i] < mins[i])
716 mins[i] = b->mins[i];
717 if (b->maxs[i] > maxs[i])
718 maxs[i] = b->maxs[i];
724 void Select_GetTrueMid (vec3_t mid)
727 Select_GetBounds (mins, maxs);
729 for (int i=0 ; i<3 ; i++)
730 mid[i] = (mins[i] + ((maxs[i] - mins[i]) / 2));
733 void Select_GetMid (vec3_t mid)
738 if (g_PrefsDlg.m_bNoClamp)
740 Select_GetTrueMid(mid);
744 Select_GetBounds (mins, maxs);
746 for (i=0 ; i<3 ; i++)
747 mid[i] = g_qeglobals.d_gridsize*floor ( ( (mins[i] + maxs[i])*0.5 )/g_qeglobals.d_gridsize );
750 vec3_t select_origin;
751 vec3_t select_matrix[3];
752 qboolean select_fliporder;
754 // FIXME: bApplyBPrimit is supposed to be temporary
755 // TODO: manage Brush_Build calls, too many of them with the texture processing
756 // FIXME: the undo doesn't seem to work correctly on texturing and flip/rotate operations?? this is not supposed to be related to the texture locking code, so what is happening?
757 // FIXME: ApplyMatrix works on flipping operation, b0rks on Rotations (so does the "regular" rotation code??)
758 // FIXME: what is getting called in free rotation mode? that used to work right?
759 void Select_ApplyMatrix (bool bSnap, bool bRotation, int nAxis, float fDeg)//, qboolean bApplyBPrimit)
764 vec3_t temp, tmporigin;
766 for (b=selected_brushes.next ; b != &selected_brushes ; b=b->next)
768 if(b->owner->eclass->fixedsize)
770 VectorCopy (b->owner->origin, tmporigin);
771 // transform the origin point
772 VectorSubtract (b->owner->origin, select_origin, temp);
773 for (j=0 ; j<3 ; j++)
774 b->owner->origin[j] = DotProduct(temp, select_matrix[j]) + select_origin[j];
776 // update the origin key
778 sprintf (text, "%i %i %i",
779 (int)b->owner->origin[0], (int)b->owner->origin[1], (int)b->owner->origin[2]);
780 SetKeyValue(b->owner, "origin", text);
782 /*\todo remove brush-based bounding box for fixedsize entities */
783 VectorSubtract (b->owner->origin, tmporigin, temp);
784 for (f=b->brush_faces ; f ; f=f->next)
786 // move fixedsize bbox to new origin
787 for (i=0 ; i<3 ; i++)
788 VectorAdd (f->planepts[i], temp, f->planepts[i]);
790 Brush_Build(b, bSnap,true,false,false); // don't filter
793 else if (b->patchBrush)
795 if (!bRotation && !((g_qeglobals.d_select_mode == sel_curvepoint && g_qeglobals.d_num_move_points != 0) || g_bPatchBendMode))
796 // invert patch if this is a mirroring operation, unless points are selected or bendmode is active
797 patchInvert(b->pPatch);
798 // NOTE: does not clamp points to integers
799 Patch_ApplyMatrix(b->pPatch, select_origin, select_matrix, false);
803 for (f=b->brush_faces ; f ; f=f->next)
805 // FIXME: only in BP mode!
806 // if we are using Brush Primitives texturing, we need to compute the texture matrix after the geometric transformation
807 // (with the default texturing you don't need to compute anything for flipping and mirroring operations)
808 // if (bApplyBPrimit) {
809 // ApplyMatrix_BrushPrimit (f, select_matrix, select_origin, select_fliporder);
811 for (i=0 ; i<3 ; i++)
813 VectorSubtract (f->planepts[i], select_origin, temp);
814 for (j=0 ; j<3 ; j++)
815 f->planepts[i][j] = DotProduct(temp, select_matrix[j]) + select_origin[j];
817 if (select_fliporder)
819 VectorCopy (f->planepts[0], temp);
820 VectorCopy (f->planepts[2], f->planepts[0]);
821 VectorCopy (temp, f->planepts[2]);
824 Brush_Build(b, bSnap,true,false,false); // don't filter
829 void ProjectOnPlane(vec3_t& normal,float dist,vec3_t& ez, vec3_t& p)
831 if (fabs(ez[0]) == 1)
832 p[0] = (dist - normal[1] * p[1] - normal[2] * p[2]) / normal[0];
833 else if (fabs(ez[1]) == 1)
834 p[1] = (dist - normal[0] * p[0] - normal[2] * p[2]) / normal[1];
836 p[2] = (dist - normal[0] * p[0] - normal[1] * p[1]) / normal[2];
839 void Back(vec3_t& dir, vec3_t& p)
841 if (fabs(dir[0]) == 1)
843 else if (fabs(dir[1]) == 1)
850 // using scale[0] and scale[1]
851 void ComputeScale(vec3_t& rex, vec3_t& rey, vec3_t& p, face_t* f)
853 float px = DotProduct(rex, p);
854 float py = DotProduct(rey, p);
855 px *= f->texdef.scale[0];
856 py *= f->texdef.scale[1];
858 VectorCopy(rex, aux);
859 VectorScale(aux, px, aux);
861 VectorCopy(rey, aux);
862 VectorScale(aux, py, aux);
863 VectorAdd(p, aux, p);
866 void ComputeAbsolute(face_t* f, vec3_t& p1, vec3_t& p2, vec3_t& p3)
868 vec3_t ex,ey,ez; // local axis base
871 if (g_qeglobals.m_bBrushPrimitMode)
872 Sys_Printf("Warning : illegal call of ComputeAbsolute in brush primitive mode\n");
875 // compute first local axis base
876 TextureAxisFromPlane(&f->plane, ex, ey);
877 CrossProduct(ex, ey, ez);
881 VectorScale(aux, -f->texdef.shift[0], aux);
884 VectorScale(aux, -f->texdef.shift[1], aux);
885 VectorAdd(p1, aux, p1);
887 VectorAdd(p2, ex, p2);
889 VectorAdd(p3, ey, p3);
891 VectorScale(aux, -f->texdef.rotate, aux);
892 VectorRotate(p1, aux, p1);
893 VectorRotate(p2, aux, p2);
894 VectorRotate(p3, aux, p3);
895 // computing rotated local axis base
898 VectorRotate(rex, aux, rex);
900 VectorRotate(rey, aux, rey);
902 ComputeScale(rex,rey,p1,f);
903 ComputeScale(rex,rey,p2,f);
904 ComputeScale(rex,rey,p3,f);
906 // project on normal plane
908 // assumes plane normal is normalized
909 ProjectOnPlane(f->plane.normal,f->plane.dist,ez,p1);
910 ProjectOnPlane(f->plane.normal,f->plane.dist,ez,p2);
911 ProjectOnPlane(f->plane.normal,f->plane.dist,ez,p3);
915 void AbsoluteToLocal(plane_t normal2, face_t* f, vec3_t& p1, vec3_t& p2, vec3_t& p3)
920 if (g_qeglobals.m_bBrushPrimitMode)
921 Sys_Printf("Warning : illegal call of AbsoluteToLocal in brush primitive mode\n");
924 // computing new local axis base
925 TextureAxisFromPlane(&normal2, ex, ey);
926 CrossProduct(ex, ey, ez);
928 // projecting back on (ex,ey)
936 VectorSubtract(aux, p1,aux);
938 float x = DotProduct(aux,ex);
939 float y = DotProduct(aux,ey);
940 f->texdef.rotate = 180 * atan2(y,x) / Q_PI;
943 // computing rotated local axis base
945 VectorScale(aux, f->texdef.rotate, aux);
947 VectorRotate(rex, aux, rex);
949 VectorRotate(rey, aux, rey);
953 VectorSubtract(aux, p1, aux);
954 f->texdef.scale[0] = DotProduct(aux, rex);
956 VectorSubtract(aux, p1, aux);
957 f->texdef.scale[1] = DotProduct(aux, rey);
961 x = DotProduct(rex,p1);
962 y = DotProduct(rey,p1);
963 x /= f->texdef.scale[0];
964 y /= f->texdef.scale[1];
967 VectorScale(p1, x, p1);
968 VectorCopy(rey, aux);
969 VectorScale(aux, y, aux);
970 VectorAdd(p1, aux, p1);
972 VectorScale(aux, -f->texdef.rotate, aux);
973 VectorRotate(p1, aux, p1);
974 f->texdef.shift[0] = -DotProduct(p1, ex);
975 f->texdef.shift[1] = -DotProduct(p1, ey);
977 // stored rot is good considering local axis base
978 // change it if necessary
979 f->texdef.rotate = -f->texdef.rotate;
981 Clamp(f->texdef.shift[0], f->d_texture->width);
982 Clamp(f->texdef.shift[1], f->d_texture->height);
983 Clamp(f->texdef.rotate, 360);
987 void RotateFaceTexture(face_t* f, int nAxis, float fDeg)
989 vec3_t p1,p2,p3, rota;
990 p1[0] = p1[1] = p1[2] = 0;
993 VectorCopy(p1, rota);
994 ComputeAbsolute(f, p1, p2, p3);
997 VectorRotateOrigin (p1, rota, select_origin, p1);
998 VectorRotateOrigin (p2, rota, select_origin, p2);
999 VectorRotateOrigin (p3, rota, select_origin, p3);
1003 vNormal[0] = f->plane.normal[0];
1004 vNormal[1] = f->plane.normal[1];
1005 vNormal[2] = f->plane.normal[2];
1006 VectorRotate(vNormal, rota, vNormal);
1007 normal2.normal[0] = vNormal[0];
1008 normal2.normal[1] = vNormal[1];
1009 normal2.normal[2] = vNormal[2];
1010 AbsoluteToLocal(normal2, f, p1, p2 ,p3);
1014 void RotateTextures(int nAxis, float fDeg, vec3_t vOrigin)
1016 for (brush_t* b=selected_brushes.next ; b != &selected_brushes ; b=b->next)
1018 for (face_t* f=b->brush_faces ; f ; f=f->next)
1020 if (g_qeglobals.m_bBrushPrimitMode)
1021 RotateFaceTexture_BrushPrimit (f, nAxis, fDeg, vOrigin);
1023 RotateFaceTexture (f, nAxis, fDeg);
1025 Brush_Build(b, false,true,false,false); // don't filter
1029 void Select_ApplyMatrix_BrushPrimit()
1032 if (!g_qeglobals.m_bBrushPrimitMode) {
1033 Sys_FPrintf(SYS_ERR,"ERROR: Select_ApplyMatrix_BrushPrimit called in non-BP mode\n");
1036 for (brush_t* b=selected_brushes.next ; b != &selected_brushes ; b=b->next)
1038 for (face_t* f=b->brush_faces ; f ; f=f->next)
1040 ApplyMatrix_BrushPrimit (f, select_matrix, select_origin);
1045 void Select_FlipAxis (int axis)
1049 Select_GetMid (select_origin);
1050 for (i=0 ; i<3 ; i++)
1052 VectorCopy (vec3_origin, select_matrix[i]);
1053 select_matrix[i][i] = 1;
1055 select_matrix[axis][axis] = -1;
1056 select_fliporder = true;
1059 if (g_PrefsDlg.m_bRotateLock) {
1060 // axis flipping inverts space orientation, we have to use a general texture locking algorithm instead of the RotateFaceTexture
1061 if (g_qeglobals.m_bBrushPrimitMode) {
1062 Select_ApplyMatrix_BrushPrimit();
1066 // there's never been flip locking for non BP mode, this would be tricky to write and there's not much interest for it with the coming of BP format
1067 // what could be done is converting regular to BP, locking, then back to regular :)
1068 Sys_FPrintf(SYS_WRN, "WARNING: regular texturing doesn't have texture lock on flipping operations\n");
1071 // geometric transformation
1072 Select_ApplyMatrix (true, false, 0, 0);
1073 Sys_UpdateWindows (W_ALL);
1077 void Select_Scale(float x, float y, float z)
1079 Select_GetMid (select_origin);
1080 for (brush_t* b=selected_brushes.next ; b != &selected_brushes ; b=b->next)
1082 // ignore fixedsize entities
1083 if(b->owner->eclass->fixedsize) continue;
1084 for (face_t* f=b->brush_faces ; f ; f=f->next)
1086 for (int i=0 ; i<3 ; i++)
1088 f->planepts[i][0] -= select_origin[0];
1089 f->planepts[i][1] -= select_origin[1];
1090 f->planepts[i][2] -= select_origin[2];
1091 f->planepts[i][0] *= x;
1092 f->planepts[i][1] *= y;
1093 f->planepts[i][2] *= z;
1095 f->planepts[i][0] += select_origin[0];
1096 f->planepts[i][1] += select_origin[1];
1097 f->planepts[i][2] += select_origin[2];
1100 Brush_Build(b, false,true,false,false); // don't filter
1107 Patch_Scale(b->pPatch, select_origin, v);
1112 void Select_RotateAxis (int axis, float deg, bool bPaint, bool bMouse)
1124 VectorCopy(g_pParentWnd->ActiveXY()->RotateOrigin(), select_origin);
1128 Select_GetMid (select_origin);
1135 VectorSet(rotation, 0, 0, 360 - deg);
1136 for(brush_t *b = selected_brushes.next; b != &selected_brushes; b = b->next)
1137 if(b->owner->model.pEdit)
1138 b->owner->model.pEdit->Rotate(select_origin, rotation);
1142 select_fliporder = false;
1144 // the "90" degrees algorithm is mostly used on axis rotate as a speedup and possibly avoiding rounding errors as much as possible
1145 // previous implementation was doing an indirect-oriented rotation over the plane whereas the general algo below was doing a direct-oriented rotation
1146 // this was confusing the texture locking algorithms, fixed it to be direct-oriented (side consequence is that the axis rotate toolbar button rotates the other way now)
1147 // NOTE: previous algo was using vec3_origin in the matrix computation..
1148 // I don't see what an origin does in linear transformations (3x3 matrixes always relate to a (0,0,0) origin)
1149 // in Radiant it's initialized as (0,0,0) and never set to another value
1150 // so I got rid of it when it's not used for initialisation tasks (and even if it's not (0,0,0) it should not matter
1158 c = cos(deg * Q_PI / 180.0);
1159 s = sin(deg * Q_PI / 180.0);
1162 for (i=0 ; i<3 ; i++)
1164 VectorCopy (vec3_origin, select_matrix[i]);
1165 select_matrix[i][i] = 1;
1171 select_matrix[1][1] = c;
1172 select_matrix[1][2] = s;
1173 select_matrix[2][1] = -s;
1174 select_matrix[2][2] = c;
1177 select_matrix[0][0] = c;
1178 select_matrix[0][2] = s;
1179 select_matrix[2][0] = -s;
1180 select_matrix[2][2] = c;
1183 select_matrix[0][0] = c;
1184 select_matrix[0][1] = s;
1185 select_matrix[1][0] = -s;
1186 select_matrix[1][1] = c;
1192 if (g_PrefsDlg.m_bRotateLock)
1194 // Terrible hack, reversing input rotation angle to correct
1195 // texture rotation direction for X and Z axes.
1196 // RotateTextures needs to be changed to fix this properly?
1198 RotateTextures(axis, deg, select_origin);
1200 RotateTextures(axis, deg * -1, select_origin);
1202 // geometric transformation
1203 Select_ApplyMatrix(!bMouse, true, axis, deg);//, false);
1206 Sys_UpdateWindows (W_ALL);
1210 ================================================================
1214 ================================================================
1217 void Select_RealCompleteTall(vec3_t mins, vec3_t maxs)
1221 int nDim1 = (g_pParentWnd->ActiveXY()->GetViewType() == YZ) ? 1 : 0;
1222 int nDim2 = (g_pParentWnd->ActiveXY()->GetViewType() == XY) ? 1 : 2;
1224 g_qeglobals.d_select_mode = sel_brush;
1226 for (b=active_brushes.next ; b != &active_brushes ; b=next)
1233 if ( (b->maxs[nDim1] > maxs[nDim1] || b->mins[nDim1] < mins[nDim1])
1234 || (b->maxs[nDim2] > maxs[nDim2] || b->mins[nDim2] < mins[nDim2]) )
1237 Brush_RemoveFromList (b);
1238 Brush_AddToList (b, &selected_brushes);
1242 void Select_CompleteTall (void)
1246 if (!QE_SingleBrush ())
1249 Undo_Start ("select complete tall");
1250 Undo_AddBrushList (&selected_brushes);
1253 VectorCopy (selected_brushes.next->mins, mins);
1254 VectorCopy (selected_brushes.next->maxs, maxs);
1257 Select_RealCompleteTall(mins, maxs);
1258 Sys_UpdateWindows (W_ALL);
1261 void Select_PartialTall (void)
1266 if (!QE_SingleBrush ())
1269 Undo_Start ("select complete tall");
1270 Undo_AddBrushList (&selected_brushes);
1273 g_qeglobals.d_select_mode = sel_brush;
1275 VectorCopy (selected_brushes.next->mins, mins);
1276 VectorCopy (selected_brushes.next->maxs, maxs);
1279 int nDim1 = (g_pParentWnd->ActiveXY()->GetViewType() == YZ) ? 1 : 0;
1280 int nDim2 = (g_pParentWnd->ActiveXY()->GetViewType() == XY) ? 1 : 2;
1282 for (b=active_brushes.next ; b != &active_brushes ; b=next)
1289 if ( (b->mins[nDim1] > maxs[nDim1] || b->maxs[nDim1] < mins[nDim1])
1290 || (b->mins[nDim2] > maxs[nDim2] || b->maxs[nDim2] < mins[nDim2]) )
1294 Brush_RemoveFromList (b);
1295 Brush_AddToList (b, &selected_brushes);
1298 Sys_UpdateWindows (W_ALL);
1301 void Select_Touching (void)
1307 if (!QE_SingleBrush ())
1310 g_qeglobals.d_select_mode = sel_brush;
1312 VectorCopy (selected_brushes.next->mins, mins);
1313 VectorCopy (selected_brushes.next->maxs, maxs);
1315 for (b=active_brushes.next ; b != &active_brushes ; b=next)
1322 for (i=0 ; i<3 ; i++)
1323 if (b->mins[i] > maxs[i]+1 || b->maxs[i] < mins[i]-1)
1328 Brush_RemoveFromList (b);
1329 Brush_AddToList (b, &selected_brushes);
1333 Sys_UpdateWindows (W_ALL);
1336 void Select_Inside (void)
1342 if (!QE_SingleBrush ())
1345 Undo_Start ("select inside");
1346 Undo_AddBrushList (&selected_brushes);
1349 g_qeglobals.d_select_mode = sel_brush;
1351 VectorCopy (selected_brushes.next->mins, mins);
1352 VectorCopy (selected_brushes.next->maxs, maxs);
1355 for (b=active_brushes.next ; b != &active_brushes ; b=next)
1362 for (i=0 ; i<3 ; i++)
1363 if (b->maxs[i] > maxs[i] || b->mins[i] < mins[i])
1367 Brush_RemoveFromList (b);
1368 Brush_AddToList (b, &selected_brushes);
1372 Sys_UpdateWindows (W_ALL);
1375 void Select_Ungroup(void)
1377 int numselectedgroups;
1381 numselectedgroups = 0;
1382 for (sb = selected_brushes.next; sb != &selected_brushes; sb = sb->next)
1386 if (e == world_entity || e->eclass->fixedsize)
1391 for (b = e->brushes.onext; b != &e->brushes; b = e->brushes.onext)
1393 Entity_UnlinkBrush (b);
1394 Entity_LinkBrush (world_entity, b);
1397 numselectedgroups++;
1400 if (numselectedgroups <= 0)
1402 Sys_Printf("No grouped entities selected.\n");
1405 Sys_Printf("Ungrouped %d entit%s.\n", numselectedgroups, (numselectedgroups == 1)?"y":"ies");
1406 Sys_UpdateWindows (W_ALL);
1410 group selected brushes into specified entity
1411 if an entity is empty afterwards, destroy it
1413 void Select_GroupEntity(entity_t* group)
1418 if(group->eclass->fixedsize)
1420 Sys_FPrintf (SYS_ERR, "Select_GroupEntity: can't group anything to a fixedsize entity\n");
1424 for (b = selected_brushes.next; b != &selected_brushes; b = b->next)
1426 if(b->owner->eclass->fixedsize) continue;
1428 Entity_UnlinkBrush(b);
1429 Entity_LinkBrush(group, b);
1430 if(e != world_entity && e->brushes.onext == &e->brushes)
1439 merge all selected entities together into the first one selected
1440 NOTE: makes use of order of selected_brushes list
1441 can be used to move world brushes in an entity, or to merge several ents together
1442 NOTE: didn't devise a strategy on the epairs, we merge into the first entity and use those
1444 void Select_MergeEntity()
1448 for (b = selected_brushes.next; b != &selected_brushes; b = b->next)
1450 if(!b->owner->eclass->fixedsize)
1459 Select_GroupEntity(e);
1462 for(b = e->brushes.onext; b != &e->brushes; b=b->onext)
1464 //Brush_RemoveFromList (b);
1465 //Brush_AddToList(b, &active_brushes);
1468 Sys_Printf ("Merged %d brushes into %s entity\n", count, ValueForKey (e, "classname"));
1473 ====================
1475 ====================
1477 void Select_Seperate( void ) {
1478 Select_GroupEntity( world_entity );
1482 ====================
1483 Select_MakeStructural
1484 ====================
1486 void Select_MakeStructural (void)
1491 for (b=selected_brushes.next ; b != &selected_brushes ; b=b->next)
1493 for (f=b->brush_faces ; f ; f=f->next)
1494 f->texdef.contents &= ~CONTENTS_DETAIL;
1495 b->bFiltered = FilterBrush(b);
1498 Sys_UpdateWindows (W_ALL);
1501 void Select_MakeDetail (void)
1506 for (b=selected_brushes.next ; b != &selected_brushes ; b=b->next)
1508 for (f=b->brush_faces ; f ; f=f->next)
1509 f->texdef.contents |= CONTENTS_DETAIL;
1510 b->bFiltered = FilterBrush(b);
1513 Sys_UpdateWindows (W_ALL);
1516 // brush primitive texture adjustments, use the camera view to map adjustments
1517 // ShiftTextureRelative_BrushPrimit ( s , t ) will shift relative to the texture
1518 void ShiftTextureRelative_Camera(face_t *f, int x, int y)
1521 vec_t XY[2]; // the values we are going to send for translation
1522 vec_t sgn[2]; // +1 or -1
1526 // get the two relative texture axes for the current texturing
1527 BrushPrimit_GetRelativeAxes(f, vecS, vecT);
1529 // center point of the face, project it on the camera space
1533 for (i=0; i<f->face_winding->numpoints; i++)
1535 VectorAdd(C,f->face_winding->points[i],C);
1537 VectorScale(C,1.0/f->face_winding->numpoints,C);
1539 pCam = g_pParentWnd->GetCamWnd();
1540 pCam->MatchViewAxes(C, vecS, axis[0], sgn[0]);
1541 pCam->MatchViewAxes(C, vecT, axis[1], sgn[1]);
1543 // this happens when the two directions can't be mapped on two different directions on the screen
1544 // then the move will occur against a single axis
1545 // (i.e. the user is not positioned well enough to send understandable shift commands)
1546 // NOTE: in most cases this warning is not very relevant because the user would use one of the two axes
1547 // for which the solution is easy (the other one being unknown)
1548 // so this warning could be removed
1549 if (axis[0] == axis[1])
1550 Sys_FPrintf(SYS_WRN, "Warning: degenerate in ShiftTextureRelative_Camera\n");
1552 // compute the X Y geometric increments
1553 // those geometric increments will be applied along the texture axes (the ones we computed above)
1558 // moving right/left
1559 XY[axis[0]] += sgn[0]*x;
1563 XY[axis[1]] += sgn[1]*y;
1565 // we worked out a move along vecS vecT, and we now it's geometric amplitude
1567 ShiftTextureRelative_BrushPrimit(f, XY[0], XY[1]);
1570 void Select_ShiftTexture(int x, int y)
1575 int nFaceCount = g_ptrSelectedFaces.GetSize();
1577 if(selected_brushes.next == &selected_brushes && nFaceCount == 0)
1580 for (b=selected_brushes.next ; b != &selected_brushes ; b=b->next)
1582 for (f=b->brush_faces ; f ; f=f->next)
1584 if (g_qeglobals.m_bBrushPrimitMode)
1586 ShiftTextureRelative_Camera( f, x, y );
1590 f->texdef.shift[0] += x;
1591 f->texdef.shift[1] += y;
1594 Brush_Build(b,true,true,false,false); // don't filter
1597 Patch_ShiftTexture(b->pPatch, x, y);
1603 for (int i = 0; i < nFaceCount; i++)
1605 face_t *selFace = reinterpret_cast<face_t*>(g_ptrSelectedFaces.GetAt(i));
1606 brush_t *selBrush = reinterpret_cast<brush_t*>(g_ptrSelectedFaceBrushes.GetAt(i));
1607 if (g_qeglobals.m_bBrushPrimitMode)
1609 ShiftTextureRelative_Camera( selFace, x, y );
1613 selFace->texdef.shift[0] += x;
1614 selFace->texdef.shift[1] += y;
1616 Brush_Build(selBrush,true,true,false,false); // don't filter
1620 Sys_UpdateWindows (W_CAMERA);
1623 // setting float as input
1624 void Select_ScaleTexture(float x, float y)
1629 int nFaceCount = g_ptrSelectedFaces.GetSize();
1631 if(selected_brushes.next == &selected_brushes && nFaceCount == 0)
1636 for (b=selected_brushes.next ; b != &selected_brushes ; b=b->next)
1638 for (f=b->brush_faces ; f ; f=f->next)
1640 if (g_qeglobals.m_bBrushPrimitMode)
1642 // apply same scale as the spinner button of the surface inspector
1646 brushprimit_texdef_t bp;
1647 // compute normalized texture matrix
1648 ConvertTexMatWithQTexture( &f->brushprimit_texdef, f->d_texture, &bp, NULL );
1649 // compute fake shift scale rot
1650 TexMatToFakeTexCoords( bp.coords, shift, &rotate, scale );
1652 scale[0]+=static_cast<float>(x)*0.1;
1653 scale[1]+=static_cast<float>(y)*0.1;
1654 // compute new normalized texture matrix
1655 FakeTexCoordsToTexMat( shift, rotate, scale, bp.coords );
1656 // apply to face texture matrix
1657 ConvertTexMatWithQTexture( &bp, NULL, &f->brushprimit_texdef, f->d_texture );
1661 f->texdef.scale[0] += x;
1662 f->texdef.scale[1] += y;
1665 Brush_Build(b,true,true,false,false); // don't filter
1668 Patch_ScaleTexture(b->pPatch, x, y);
1674 for (int i = 0; i < nFaceCount; i++)
1676 face_t *selFace = reinterpret_cast<face_t*>(g_ptrSelectedFaces.GetAt(i));
1677 brush_t *selBrush = reinterpret_cast<brush_t*>(g_ptrSelectedFaceBrushes.GetAt(i));
1678 if (g_qeglobals.m_bBrushPrimitMode)
1683 brushprimit_texdef_t bp;
1684 ConvertTexMatWithQTexture( &selFace->brushprimit_texdef, selFace->d_texture, &bp, NULL );
1685 TexMatToFakeTexCoords( bp.coords, shift, &rotate, scale );
1686 scale[0]+=static_cast<float>(x)*0.1;
1687 scale[1]+=static_cast<float>(y)*0.1;
1688 FakeTexCoordsToTexMat( shift, rotate, scale, bp.coords );
1689 ConvertTexMatWithQTexture( &bp, NULL, &selFace->brushprimit_texdef, selFace->d_texture );
1693 selFace->texdef.scale[0] += x;
1694 selFace->texdef.scale[1] += y;
1696 Brush_Build(selBrush,true,true,false,false); // don't filter
1700 Sys_UpdateWindows (W_CAMERA);
1703 void Select_RotateTexture(int amt)
1708 int nFaceCount = g_ptrSelectedFaces.GetSize();
1710 if(selected_brushes.next == &selected_brushes && nFaceCount == 0)
1715 for (b=selected_brushes.next ; b != &selected_brushes ; b=b->next)
1717 for (f=b->brush_faces ; f ; f=f->next)
1719 if (g_qeglobals.m_bBrushPrimitMode)
1721 // apply same scale as the spinner button of the surface inspector
1725 brushprimit_texdef_t bp;
1726 // compute normalized texture matrix
1727 ConvertTexMatWithQTexture( &f->brushprimit_texdef, f->d_texture, &bp, NULL );
1728 // compute fake shift scale rot
1729 TexMatToFakeTexCoords( bp.coords, shift, &rotate, scale );
1732 // compute new normalized texture matrix
1733 FakeTexCoordsToTexMat( shift, rotate, scale, bp.coords );
1734 // apply to face texture matrix
1735 ConvertTexMatWithQTexture( &bp, NULL, &f->brushprimit_texdef, f->d_texture );
1739 f->texdef.rotate += amt;
1740 f->texdef.rotate = static_cast<int>(f->texdef.rotate) % 360;
1743 Brush_Build(b,true,true,false,false); // don't filter
1746 //Patch_RotateTexture(b->nPatchID, amt);
1747 Patch_RotateTexture(b->pPatch, amt);
1753 for (int i = 0; i < nFaceCount; i++)
1755 face_t *selFace = reinterpret_cast<face_t*>(g_ptrSelectedFaces.GetAt(i));
1756 brush_t *selBrush = reinterpret_cast<brush_t*>(g_ptrSelectedFaceBrushes.GetAt(i));
1757 if (g_qeglobals.m_bBrushPrimitMode)
1762 brushprimit_texdef_t bp;
1763 ConvertTexMatWithQTexture( &selFace->brushprimit_texdef, selFace->d_texture, &bp, NULL );
1764 TexMatToFakeTexCoords( bp.coords, shift, &rotate, scale );
1766 FakeTexCoordsToTexMat( shift, rotate, scale, bp.coords );
1767 ConvertTexMatWithQTexture( &bp, NULL, &selFace->brushprimit_texdef, selFace->d_texture );
1771 selFace->texdef.rotate += amt;
1772 selFace->texdef.rotate = static_cast<int>(selFace->texdef.rotate) % 360;
1774 Brush_Build(selBrush,true,true,false,false); // don't filter
1778 Sys_UpdateWindows (W_CAMERA);
1781 // TTimo modified to handle shader architecture:
1782 // expects shader names at input, comparison relies on shader names .. texture names no longer relevant
1783 void FindReplaceTextures(const char* pFind, const char* pReplace, bool bSelected, bool bForce, bool bSelectMatchingFaces)
1785 if (strchr(pFind, ' ') || strchr(pReplace, ' '))
1787 Sys_FPrintf(SYS_WRN, "FindReplaceTextures: '%s' or '%s' have spaces, aborted\n", pFind, pReplace);
1791 brush_t* pList = (bSelected) ? &selected_brushes : &active_brushes;
1795 //++timo BP mode: replacing a texture in BP mode is not that easy, you need to recompute the texture matrix
1796 // if the size of the replacing texture differs, otherwise you get wrong scaling
1797 if (g_qeglobals.m_bBrushPrimitMode)
1798 Sys_Printf("TODO: finalize find/replace code for brush primitives");
1801 for (brush_t* pBrush = pList->next ; pBrush != pList; pBrush = pBrush->next)
1803 if (!bSelectMatchingFaces && pBrush->patchBrush)
1805 Patch_FindReplaceTexture(pBrush, pFind, pReplace, bForce);
1808 bool found = false; //spog
1809 for (face_t* pFace = pBrush->brush_faces; pFace; pFace = pFace->next)
1811 if(bForce || strcmpi(pFace->pShader->getName(), pFind) == 0)
1813 if (!bSelectMatchingFaces) {
1814 pFace->pShader->DecRef();
1815 pFace->pShader = QERApp_Shader_ForName( pReplace );
1816 pFace->pShader->IncRef();
1817 pFace->d_texture = pFace->pShader->getTexture();
1818 pFace->texdef.SetName(pReplace);
1820 } else if (bSelectMatchingFaces) {
1826 if (found) // spog - speed increase, only build brushes that changed
1827 Brush_Build(pBrush);
1831 if (bSelectMatchingFaces) {
1835 int nSize = mFaces.GetSize();
1836 for (int i = 0; i < nSize; i++) {
1837 g_SelectedFaces.Add(reinterpret_cast<face_t *>(mFaces.GetAt(i)));
1841 Sys_UpdateWindows (W_CAMERA);
1844 void Select_AllOfType()
1848 // if no brush selected, we will select based on texture
1849 // the first selected face's texture if any, or the current texture
1850 // if a brush is selected, we will select entities (first non-worldspawn owner in selected brushes)
1851 if (selected_brushes.next == &selected_brushes)
1855 if (g_ptrSelectedFaces.GetSize() == 0)
1857 strName = g_qeglobals.d_texturewin.texdef.GetName();
1861 face_t *selFace = reinterpret_cast<face_t*>(g_ptrSelectedFaces.GetAt(0));
1862 strName = selFace->texdef.GetName();
1865 Sys_Printf("Selecting all brushes with the texture %s\n", strName.GetBuffer());
1868 for (b=active_brushes.next ; b != &active_brushes ; b=next)
1877 if (strcmpi(strName, b->pPatch->pShader->getName()) == 0)
1879 Brush_RemoveFromList (b);
1880 Brush_AddToList (b, &selected_brushes);
1885 for (face_t* pFace = b->brush_faces; pFace; pFace = pFace->next)
1887 if (strcmpi(strName, pFace->texdef.GetName()) == 0)
1889 Brush_RemoveFromList (b);
1890 Brush_AddToList (b, &selected_brushes);
1895 Sys_UpdateWindows(W_ALL);
1900 b = selected_brushes.next;
1905 if (e != world_entity)
1907 CString strName = e->eclass->name;
1908 CString strKey, strVal;
1909 bool bCriteria = GetSelectAllCriteria(strKey, strVal);
1910 Sys_Printf("Selecting all %s entities\n", strName.GetBuffer());
1913 for (b=active_brushes.next ; b != &active_brushes ; b=next)
1923 if (strcmpi(e->eclass->name, strName) == 0)
1927 CString str = ValueForKey (e, strKey);
1928 if (str.CompareNoCase(strVal) != 0) {
1933 Brush_RemoveFromList (b);
1934 Brush_AddToList (b, &selected_brushes);
1941 Sys_UpdateWindows (W_ALL);
1945 void Select_Reselect()
1947 Select_Brush(selected_brushes.next);
1948 Sys_UpdateWindows (W_ALL);
1952 void Select_FitTexture(int nHeight, int nWidth)
1956 int nFaceCount = g_ptrSelectedFaces.GetSize();
1958 if(selected_brushes.next == &selected_brushes && nFaceCount == 0)
1961 for (b=selected_brushes.next ; b != &selected_brushes ; b=b->next)
1963 Brush_FitTexture(b, nHeight, nWidth);
1964 Brush_Build(b,true,true,false,false); // don't filter
1969 for (int i = 0; i < nFaceCount; i++)
1971 face_t *selFace = reinterpret_cast<face_t*>(g_ptrSelectedFaces.GetAt(i));
1972 brush_t *selBrush = reinterpret_cast<brush_t*>(g_ptrSelectedFaceBrushes.GetAt(i));
1973 Face_FitTexture(selFace, nHeight, nWidth);
1974 Brush_Build(selBrush,true,true,false,false); // don't filter
1978 Sys_UpdateWindows (W_CAMERA);
1983 for (brush_t* b=selected_brushes.next ; b && b != &selected_brushes ; b=b->next)
1985 b->hiddenBrush = true;
1986 b->bFiltered = true;
1988 Sys_UpdateWindows (W_ALL);
1991 void Select_ShowAllHidden()
1994 for (b=selected_brushes.next ; b && b != &selected_brushes ; b=b->next)
1998 b->hiddenBrush = false;
1999 b->bFiltered = FilterBrush(b);
2002 for (b=active_brushes.next ; b && b != &active_brushes ; b=b->next)
2006 b->hiddenBrush = false;
2007 b->bFiltered = FilterBrush(b);
2010 Sys_UpdateWindows (W_ALL);
2019 void Select_Invert(void)
2021 brush_t *next, *prev, *b;
2023 Sys_Printf("inverting selection...\n");
2025 next = active_brushes.next;
2026 prev = active_brushes.prev;
2027 if (selected_brushes.next != &selected_brushes)
2029 active_brushes.next = selected_brushes.next;
2030 active_brushes.prev = selected_brushes.prev;
2031 active_brushes.next->prev = &active_brushes;
2032 active_brushes.prev->next = &active_brushes;
2036 active_brushes.next = &active_brushes;
2037 active_brushes.prev = &active_brushes;
2039 if (next != &active_brushes)
2041 selected_brushes.next = next;
2042 selected_brushes.prev = prev;
2043 selected_brushes.next->prev = &selected_brushes;
2044 selected_brushes.prev->next = &selected_brushes;
2048 selected_brushes.next = &selected_brushes;
2049 selected_brushes.prev = &selected_brushes;
2052 // now check if any hidden brush is selected
2053 for (b = selected_brushes.next; b != &selected_brushes; )
2056 b->pPatch->bSelected = true;
2062 Brush_RemoveFromList (pb);
2063 Brush_AddToList (pb, &active_brushes);
2069 for (b = active_brushes.next; b != &active_brushes; b = b->next)
2073 b->pPatch->bSelected = false;
2077 // since invert selection only works at the brush level,
2078 // set g_qeglobals.d_select_mode accordingly
2079 g_qeglobals.d_select_mode = sel_brush;
2081 // since invert selection only works at the brush level,
2082 // set g_qeglobals.d_select_mode accordingly
2083 g_qeglobals.d_select_mode = sel_brush;
2085 Sys_UpdateWindows(W_ALL);
2087 Sys_Printf("done.\n");
2090 #ifdef ENABLE_GROUPS
2096 void Select_Name(const char *pName)
2098 if (g_qeglobals.m_bBrushPrimitMode)
2100 for (brush_t* b=selected_brushes.next ; b && b != &selected_brushes ; b=b->next)
2102 Brush_SetEpair(b, "Name", pName);
2110 add selected brushes to a group, update the tree
2113 void Select_AddToGroup(const char *pName)
2115 if (g_qeglobals.m_bBrushPrimitMode)
2117 for (brush_t* b=selected_brushes.next ; b && b != &selected_brushes ; b=b->next)
2119 Brush_SetEpair(b, "group", pName);
2120 Group_AddToProperGroup(b);