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