2 Copyright (C) 1999-2006 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
22 #include "brushmanip.h"
25 #include "gtkutil/widget.h"
26 #include "gtkutil/menu.h"
28 #include "brushnode.h"
30 #include "texwindow.h"
33 #include "mainframe.h"
36 #include "preferences.h"
40 void Brush_ConstructCuboid( Brush& brush, const AABB& bounds, const char* shader, const TextureProjection& projection ){
41 const unsigned char box[3][2] = { { 0, 1 }, { 2, 0 }, { 1, 2 } };
42 Vector3 mins( vector3_subtracted( bounds.origin, bounds.extents ) );
43 Vector3 maxs( vector3_added( bounds.origin, bounds.extents ) );
49 for ( int i = 0; i < 3; ++i )
51 Vector3 planepts1( maxs );
52 Vector3 planepts2( maxs );
53 planepts2[box[i][0]] = mins[box[i][0]];
54 planepts1[box[i][1]] = mins[box[i][1]];
56 brush.addPlane( maxs, planepts1, planepts2, shader, projection );
60 for ( int i = 0; i < 3; ++i )
62 Vector3 planepts1( mins );
63 Vector3 planepts2( mins );
64 planepts1[box[i][0]] = maxs[box[i][0]];
65 planepts2[box[i][1]] = maxs[box[i][1]];
67 brush.addPlane( mins, planepts1, planepts2, shader, projection );
72 inline float max_extent( const Vector3& extents ){
73 return std::max( std::max( extents[0], extents[1] ), extents[2] );
76 inline float max_extent_2d( const Vector3& extents, int axis ){
80 return std::max( extents[1], extents[2] );
82 return std::max( extents[0], extents[2] );
84 return std::max( extents[0], extents[1] );
88 const std::size_t c_brushPrism_minSides = 3;
89 const std::size_t c_brushPrism_maxSides = c_brush_maxFaces - 2;
90 const char* const c_brushPrism_name = "brushPrism";
92 void Brush_ConstructPrism( Brush& brush, const AABB& bounds, std::size_t sides, int axis, const char* shader, const TextureProjection& projection ){
93 if ( sides < c_brushPrism_minSides ) {
94 globalErrorStream() << c_brushPrism_name << ": sides " << Unsigned( sides ) << ": too few sides, minimum is " << Unsigned( c_brushPrism_minSides ) << "\n";
97 if ( sides > c_brushPrism_maxSides ) {
98 globalErrorStream() << c_brushPrism_name << ": sides " << Unsigned( sides ) << ": too many sides, maximum is " << Unsigned( c_brushPrism_maxSides ) << "\n";
103 brush.reserve( sides + 2 );
105 Vector3 mins( vector3_subtracted( bounds.origin, bounds.extents ) );
106 Vector3 maxs( vector3_added( bounds.origin, bounds.extents ) );
108 float radius = max_extent_2d( bounds.extents, axis );
109 const Vector3& mid = bounds.origin;
112 planepts[2][( axis + 1 ) % 3] = mins[( axis + 1 ) % 3];
113 planepts[2][( axis + 2 ) % 3] = mins[( axis + 2 ) % 3];
114 planepts[2][axis] = maxs[axis];
115 planepts[1][( axis + 1 ) % 3] = maxs[( axis + 1 ) % 3];
116 planepts[1][( axis + 2 ) % 3] = mins[( axis + 2 ) % 3];
117 planepts[1][axis] = maxs[axis];
118 planepts[0][( axis + 1 ) % 3] = maxs[( axis + 1 ) % 3];
119 planepts[0][( axis + 2 ) % 3] = maxs[( axis + 2 ) % 3];
120 planepts[0][axis] = maxs[axis];
122 brush.addPlane( planepts[0], planepts[1], planepts[2], shader, projection );
124 planepts[0][( axis + 1 ) % 3] = mins[( axis + 1 ) % 3];
125 planepts[0][( axis + 2 ) % 3] = mins[( axis + 2 ) % 3];
126 planepts[0][axis] = mins[axis];
127 planepts[1][( axis + 1 ) % 3] = maxs[( axis + 1 ) % 3];
128 planepts[1][( axis + 2 ) % 3] = mins[( axis + 2 ) % 3];
129 planepts[1][axis] = mins[axis];
130 planepts[2][( axis + 1 ) % 3] = maxs[( axis + 1 ) % 3];
131 planepts[2][( axis + 2 ) % 3] = maxs[( axis + 2 ) % 3];
132 planepts[2][axis] = mins[axis];
134 brush.addPlane( planepts[0], planepts[1], planepts[2], shader, projection );
136 for ( std::size_t i = 0 ; i < sides ; ++i )
138 double sv = sin( i * 3.14159265 * 2 / sides );
139 double cv = cos( i * 3.14159265 * 2 / sides );
141 planepts[0][( axis + 1 ) % 3] = static_cast<float>( floor( mid[( axis + 1 ) % 3] + radius * cv + 0.5 ) );
142 planepts[0][( axis + 2 ) % 3] = static_cast<float>( floor( mid[( axis + 2 ) % 3] + radius * sv + 0.5 ) );
143 planepts[0][axis] = mins[axis];
145 planepts[1][( axis + 1 ) % 3] = planepts[0][( axis + 1 ) % 3];
146 planepts[1][( axis + 2 ) % 3] = planepts[0][( axis + 2 ) % 3];
147 planepts[1][axis] = maxs[axis];
149 planepts[2][( axis + 1 ) % 3] = static_cast<float>( floor( planepts[0][( axis + 1 ) % 3] - radius * sv + 0.5 ) );
150 planepts[2][( axis + 2 ) % 3] = static_cast<float>( floor( planepts[0][( axis + 2 ) % 3] + radius * cv + 0.5 ) );
151 planepts[2][axis] = maxs[axis];
153 brush.addPlane( planepts[0], planepts[1], planepts[2], shader, projection );
157 const std::size_t c_brushCone_minSides = 3;
158 const std::size_t c_brushCone_maxSides = 32;
159 const char* const c_brushCone_name = "brushCone";
161 void Brush_ConstructCone( Brush& brush, const AABB& bounds, std::size_t sides, const char* shader, const TextureProjection& projection ){
162 if ( sides < c_brushCone_minSides ) {
163 globalErrorStream() << c_brushCone_name << ": sides " << Unsigned( sides ) << ": too few sides, minimum is " << Unsigned( c_brushCone_minSides ) << "\n";
166 if ( sides > c_brushCone_maxSides ) {
167 globalErrorStream() << c_brushCone_name << ": sides " << Unsigned( sides ) << ": too many sides, maximum is " << Unsigned( c_brushCone_maxSides ) << "\n";
172 brush.reserve( sides + 1 );
174 Vector3 mins( vector3_subtracted( bounds.origin, bounds.extents ) );
175 Vector3 maxs( vector3_added( bounds.origin, bounds.extents ) );
177 float radius = max_extent( bounds.extents );
178 const Vector3& mid = bounds.origin;
181 planepts[0][0] = mins[0]; planepts[0][1] = mins[1]; planepts[0][2] = mins[2];
182 planepts[1][0] = maxs[0]; planepts[1][1] = mins[1]; planepts[1][2] = mins[2];
183 planepts[2][0] = maxs[0]; planepts[2][1] = maxs[1]; planepts[2][2] = mins[2];
185 brush.addPlane( planepts[0], planepts[1], planepts[2], shader, projection );
187 for ( std::size_t i = 0 ; i < sides ; ++i )
189 double sv = sin( i * 3.14159265 * 2 / sides );
190 double cv = cos( i * 3.14159265 * 2 / sides );
192 planepts[0][0] = static_cast<float>( floor( mid[0] + radius * cv + 0.5 ) );
193 planepts[0][1] = static_cast<float>( floor( mid[1] + radius * sv + 0.5 ) );
194 planepts[0][2] = mins[2];
196 planepts[1][0] = mid[0];
197 planepts[1][1] = mid[1];
198 planepts[1][2] = maxs[2];
200 planepts[2][0] = static_cast<float>( floor( planepts[0][0] - radius * sv + 0.5 ) );
201 planepts[2][1] = static_cast<float>( floor( planepts[0][1] + radius * cv + 0.5 ) );
202 planepts[2][2] = maxs[2];
204 brush.addPlane( planepts[0], planepts[1], planepts[2], shader, projection );
208 const std::size_t c_brushSphere_minSides = 3;
209 const std::size_t c_brushSphere_maxSides = 31;
210 const char* const c_brushSphere_name = "brushSphere";
212 void Brush_ConstructSphere( Brush& brush, const AABB& bounds, std::size_t sides, const char* shader, const TextureProjection& projection ){
213 if ( sides < c_brushSphere_minSides ) {
214 globalErrorStream() << c_brushSphere_name << ": sides " << Unsigned( sides ) << ": too few sides, minimum is " << Unsigned( c_brushSphere_minSides ) << "\n";
217 if ( sides > c_brushSphere_maxSides ) {
218 globalErrorStream() << c_brushSphere_name << ": sides " << Unsigned( sides ) << ": too many sides, maximum is " << Unsigned( c_brushSphere_maxSides ) << "\n";
223 brush.reserve( sides * sides );
225 float radius = max_extent( bounds.extents );
226 const Vector3& mid = bounds.origin;
229 double dt = 2 * c_pi / sides;
230 double dp = c_pi / sides;
231 for ( std::size_t i = 0; i < sides; i++ )
233 for ( std::size_t j = 0; j < sides - 1; j++ )
236 double p = float(j * dp - c_pi / 2);
238 planepts[0] = vector3_added( mid, vector3_scaled( vector3_for_spherical( t, p ), radius ) );
239 planepts[1] = vector3_added( mid, vector3_scaled( vector3_for_spherical( t, p + dp ), radius ) );
240 planepts[2] = vector3_added( mid, vector3_scaled( vector3_for_spherical( t + dt, p + dp ), radius ) );
242 brush.addPlane( planepts[0], planepts[1], planepts[2], shader, projection );
247 double p = ( sides - 1 ) * dp - c_pi / 2;
248 for ( std::size_t i = 0; i < sides; i++ )
252 planepts[0] = vector3_added( mid, vector3_scaled( vector3_for_spherical( t, p ), radius ) );
253 planepts[1] = vector3_added( mid, vector3_scaled( vector3_for_spherical( t + dt, p + dp ), radius ) );
254 planepts[2] = vector3_added( mid, vector3_scaled( vector3_for_spherical( t + dt, p ), radius ) );
256 brush.addPlane( planepts[0], planepts[1], planepts[2], shader, projection );
261 const std::size_t c_brushRock_minSides = 10;
262 const std::size_t c_brushRock_maxSides = 1000;
263 const char* const c_brushRock_name = "brushRock";
265 void Brush_ConstructRock( Brush& brush, const AABB& bounds, std::size_t sides, const char* shader, const TextureProjection& projection ){
266 if ( sides < c_brushRock_minSides ) {
267 globalErrorStream() << c_brushRock_name << ": sides " << Unsigned( sides ) << ": too few sides, minimum is " << Unsigned( c_brushRock_minSides ) << "\n";
270 if ( sides > c_brushRock_maxSides ) {
271 globalErrorStream() << c_brushRock_name << ": sides " << Unsigned( sides ) << ": too many sides, maximum is " << Unsigned( c_brushRock_maxSides ) << "\n";
276 brush.reserve( sides * sides );
278 float radius = max_extent( bounds.extents );
279 const Vector3& mid = bounds.origin;
282 for ( std::size_t j = 0; j < sides; j++ )
284 planepts[0][0] = rand() - ( RAND_MAX / 2 );
285 planepts[0][1] = rand() - ( RAND_MAX / 2 );
286 planepts[0][2] = rand() - ( RAND_MAX / 2 );
287 vector3_normalise( planepts[0] );
289 // find two vectors that are perpendicular to planepts[0]
290 ComputeAxisBase( planepts[0], planepts[1], planepts[2] );
292 planepts[0] = vector3_added( mid, vector3_scaled( planepts[0], radius ) );
293 planepts[1] = vector3_added( planepts[0], vector3_scaled( planepts[1], radius ) );
294 planepts[2] = vector3_added( planepts[0], vector3_scaled( planepts[2], radius ) );
297 // make sure the orientation is right
298 if ( vector3_dot( vector3_subtracted( planepts[0], mid ), vector3_cross( vector3_subtracted( planepts[1], mid ), vector3_subtracted( planepts[2], mid ) ) ) > 0 ) {
301 planepts[1] = planepts[2];
303 globalOutputStream() << "flip\n";
306 globalOutputStream() << "no flip\n";
310 brush.addPlane( planepts[0], planepts[1], planepts[2], shader, projection );
315 switch ( GlobalXYWnd_getCurrentViewType() )
327 void Brush_ConstructPrefab( Brush& brush, EBrushPrefab type, const AABB& bounds, std::size_t sides, const char* shader, const TextureProjection& projection ){
332 UndoableCommand undo( "brushCuboid" );
334 Brush_ConstructCuboid( brush, bounds, shader, projection );
339 int axis = GetViewAxis();
340 StringOutputStream command;
341 command << c_brushPrism_name << " -sides " << Unsigned( sides ) << " -axis " << axis;
342 UndoableCommand undo( command.c_str() );
344 Brush_ConstructPrism( brush, bounds, sides, axis, shader, projection );
349 StringOutputStream command;
350 command << c_brushCone_name << " -sides " << Unsigned( sides );
351 UndoableCommand undo( command.c_str() );
353 Brush_ConstructCone( brush, bounds, sides, shader, projection );
358 StringOutputStream command;
359 command << c_brushSphere_name << " -sides " << Unsigned( sides );
360 UndoableCommand undo( command.c_str() );
362 Brush_ConstructSphere( brush, bounds, sides, shader, projection );
367 StringOutputStream command;
368 command << c_brushRock_name << " -sides " << Unsigned( sides );
369 UndoableCommand undo( command.c_str() );
371 Brush_ConstructRock( brush, bounds, sides, shader, projection );
378 void ConstructRegionBrushes( scene::Node* brushes[6], const Vector3& region_mins, const Vector3& region_maxs ){
381 Vector3 mins( region_mins[0] - 32, region_mins[1] - 32, region_mins[2] - 32 );
384 for ( std::size_t i = 0; i < 3; i++ )
386 Vector3 maxs( region_maxs[0] + 32, region_maxs[1] + 32, region_maxs[2] + 32 );
387 maxs[i] = region_mins[i];
388 Brush_ConstructCuboid( *Node_getBrush( *brushes[i] ), aabb_for_minmax( mins, maxs ), texdef_name_default(), TextureProjection() );
394 Vector3 maxs( region_maxs[0] + 32, region_maxs[1] + 32, region_maxs[2] + 32 );
397 for ( std::size_t i = 0; i < 3; i++ )
399 Vector3 mins( region_mins[0] - 32, region_mins[1] - 32, region_mins[2] - 32 );
400 mins[i] = region_maxs[i];
401 Brush_ConstructCuboid( *Node_getBrush( *brushes[i + 3] ), aabb_for_minmax( mins, maxs ), texdef_name_default(), TextureProjection() );
409 const TextureProjection& m_projection;
411 FaceSetTexdef( const TextureProjection& projection ) : m_projection( projection ){
413 void operator()( Face& face ) const {
414 face.SetTexdef( m_projection );
418 void Scene_BrushSetTexdef_Selected( scene::Graph& graph, const TextureProjection& projection ){
419 Scene_ForEachSelectedBrush_ForEachFace( graph, FaceSetTexdef( projection ) );
423 void Scene_BrushSetTexdef_Component_Selected( scene::Graph& graph, const TextureProjection& projection ){
424 Scene_ForEachSelectedBrushFace( graph, FaceSetTexdef( projection ) );
431 const ContentsFlagsValue& m_projection;
433 FaceSetFlags( const ContentsFlagsValue& flags ) : m_projection( flags ){
435 void operator()( Face& face ) const {
436 face.SetFlags( m_projection );
440 void Scene_BrushSetFlags_Selected( scene::Graph& graph, const ContentsFlagsValue& flags ){
441 Scene_ForEachSelectedBrush_ForEachFace( graph, FaceSetFlags( flags ) );
445 void Scene_BrushSetFlags_Component_Selected( scene::Graph& graph, const ContentsFlagsValue& flags ){
446 Scene_ForEachSelectedBrushFace( graph, FaceSetFlags( flags ) );
450 class FaceShiftTexdef
454 FaceShiftTexdef( float s, float t ) : m_s( s ), m_t( t ){
456 void operator()( Face& face ) const {
457 face.ShiftTexdef( m_s, m_t );
461 void Scene_BrushShiftTexdef_Selected( scene::Graph& graph, float s, float t ){
462 Scene_ForEachSelectedBrush_ForEachFace( graph, FaceShiftTexdef( s, t ) );
466 void Scene_BrushShiftTexdef_Component_Selected( scene::Graph& graph, float s, float t ){
467 Scene_ForEachSelectedBrushFace( graph, FaceShiftTexdef( s, t ) );
471 class FaceScaleTexdef
475 FaceScaleTexdef( float s, float t ) : m_s( s ), m_t( t ){
477 void operator()( Face& face ) const {
478 face.ScaleTexdef( m_s, m_t );
482 void Scene_BrushScaleTexdef_Selected( scene::Graph& graph, float s, float t ){
483 Scene_ForEachSelectedBrush_ForEachFace( graph, FaceScaleTexdef( s, t ) );
487 void Scene_BrushScaleTexdef_Component_Selected( scene::Graph& graph, float s, float t ){
488 Scene_ForEachSelectedBrushFace( graph, FaceScaleTexdef( s, t ) );
492 class FaceRotateTexdef
496 FaceRotateTexdef( float angle ) : m_angle( angle ){
498 void operator()( Face& face ) const {
499 face.RotateTexdef( m_angle );
503 void Scene_BrushRotateTexdef_Selected( scene::Graph& graph, float angle ){
504 Scene_ForEachSelectedBrush_ForEachFace( graph, FaceRotateTexdef( angle ) );
508 void Scene_BrushRotateTexdef_Component_Selected( scene::Graph& graph, float angle ){
509 Scene_ForEachSelectedBrushFace( graph, FaceRotateTexdef( angle ) );
518 FaceSetShader( const char* name ) : m_name( name ) {}
519 void operator()( Face& face ) const {
520 face.SetShader( m_name );
524 void Scene_BrushSetShader_Selected( scene::Graph& graph, const char* name ){
525 Scene_ForEachSelectedBrush_ForEachFace( graph, FaceSetShader( name ) );
529 void Scene_BrushSetShader_Component_Selected( scene::Graph& graph, const char* name ){
530 Scene_ForEachSelectedBrushFace( graph, FaceSetShader( name ) );
538 FaceSetDetail( bool detail ) : m_detail( detail ){
540 void operator()( Face& face ) const {
541 face.setDetail( m_detail );
545 void Scene_BrushSetDetail_Selected( scene::Graph& graph, bool detail ){
546 Scene_ForEachSelectedBrush_ForEachFace( graph, FaceSetDetail( detail ) );
550 bool Face_FindReplaceShader( Face& face, const char* find, const char* replace ){
551 if ( shader_equal( face.GetShader(), find ) ) {
552 face.SetShader( replace );
558 class FaceFindReplaceShader
561 const char* m_replace;
563 FaceFindReplaceShader( const char* find, const char* replace ) : m_find( find ), m_replace( replace ){
565 void operator()( Face& face ) const {
566 Face_FindReplaceShader( face, m_find, m_replace );
573 const char* m_replace;
575 FaceFindShader( const char* find ) : m_find( find ){
577 void operator()( FaceInstance& faceinst ) const {
578 if ( shader_equal( faceinst.getFace().GetShader(), m_find ) ) {
579 faceinst.setSelected( SelectionSystem::eFace, true );
584 bool DoingSearch( const char *repl ){
585 return ( repl == NULL || ( strcmp( "textures/", repl ) == 0 ) );
588 void Scene_BrushFindReplaceShader( scene::Graph& graph, const char* find, const char* replace ){
589 if ( DoingSearch( replace ) ) {
590 Scene_ForEachBrush_ForEachFaceInstance( graph, FaceFindShader( find ) );
594 Scene_ForEachBrush_ForEachFace( graph, FaceFindReplaceShader( find, replace ) );
598 void Scene_BrushFindReplaceShader_Selected( scene::Graph& graph, const char* find, const char* replace ){
599 if ( DoingSearch( replace ) ) {
600 Scene_ForEachSelectedBrush_ForEachFaceInstance( graph,
601 FaceFindShader( find ) );
605 Scene_ForEachSelectedBrush_ForEachFace( graph,
606 FaceFindReplaceShader( find, replace ) );
610 // TODO: find for components
611 // d1223m: dont even know what they are...
612 void Scene_BrushFindReplaceShader_Component_Selected( scene::Graph& graph, const char* find, const char* replace ){
613 if ( DoingSearch( replace ) ) {
618 Scene_ForEachSelectedBrushFace( graph, FaceFindReplaceShader( find, replace ) );
625 float m_s_repeat, m_t_repeat;
627 FaceFitTexture( float s_repeat, float t_repeat ) : m_s_repeat( s_repeat ), m_t_repeat( t_repeat ){
629 void operator()( Face& face ) const {
630 face.FitTexture( m_s_repeat, m_t_repeat );
634 class FaceFitTextureW
636 float m_s_repeat, m_t_repeat;
638 FaceFitTextureW( float s_repeat, float t_repeat ) : m_s_repeat( s_repeat ), m_t_repeat( t_repeat ){
640 void operator()( Face& face ) const {
641 face.FitTextureW( m_s_repeat, m_t_repeat );
645 class FaceFitTextureH
647 float m_s_repeat, m_t_repeat;
649 FaceFitTextureH( float s_repeat, float t_repeat ) : m_s_repeat( s_repeat ), m_t_repeat( t_repeat ){
651 void operator()( Face& face ) const {
652 face.FitTextureH( m_s_repeat, m_t_repeat );
656 void Scene_BrushFitTexture_Selected( scene::Graph& graph, float s_repeat, float t_repeat ){
657 Scene_ForEachSelectedBrush_ForEachFace( graph, FaceFitTexture( s_repeat, t_repeat ) );
661 void Scene_BrushFitTexture_Component_Selected( scene::Graph& graph, float s_repeat, float t_repeat ){
662 Scene_ForEachSelectedBrushFace( graph, FaceFitTexture( s_repeat, t_repeat ) );
666 void Scene_BrushFitTexture_SelectedW( scene::Graph& graph, float s_repeat, float t_repeat ){
667 Scene_ForEachSelectedBrush_ForEachFace( graph, FaceFitTextureW( s_repeat, t_repeat ) );
671 void Scene_BrushFitTexture_Component_SelectedW( scene::Graph& graph, float s_repeat, float t_repeat ){
672 Scene_ForEachSelectedBrushFace( graph, FaceFitTextureW( s_repeat, t_repeat ) );
676 void Scene_BrushFitTexture_SelectedH( scene::Graph& graph, float s_repeat, float t_repeat ){
677 Scene_ForEachSelectedBrush_ForEachFace( graph, FaceFitTextureH( s_repeat, t_repeat ) );
681 void Scene_BrushFitTexture_Component_SelectedH( scene::Graph& graph, float s_repeat, float t_repeat ){
682 Scene_ForEachSelectedBrushFace( graph, FaceFitTextureH( s_repeat, t_repeat ) );
686 TextureProjection g_defaultTextureProjection;
687 const TextureProjection& TextureTransform_getDefault(){
688 TexDef_Construct_Default( g_defaultTextureProjection );
689 return g_defaultTextureProjection;
692 void Scene_BrushConstructPrefab( scene::Graph& graph, EBrushPrefab type, std::size_t sides, const char* shader ){
693 if ( GlobalSelectionSystem().countSelected() != 0 ) {
694 const scene::Path& path = GlobalSelectionSystem().ultimateSelected().path();
696 Brush* brush = Node_getBrush( path.top() );
698 AABB bounds = brush->localAABB(); // copy bounds because the brush will be modified
699 Brush_ConstructPrefab( *brush, type, bounds, sides, shader, TextureTransform_getDefault() );
705 void Scene_BrushResize_Selected( scene::Graph& graph, const AABB& bounds, const char* shader ){
706 if ( GlobalSelectionSystem().countSelected() != 0 ) {
707 const scene::Path& path = GlobalSelectionSystem().ultimateSelected().path();
709 Brush* brush = Node_getBrush( path.top() );
711 Brush_ConstructCuboid( *brush, bounds, shader, TextureTransform_getDefault() );
717 bool Brush_hasShader( const Brush& brush, const char* name ){
718 for ( Brush::const_iterator i = brush.begin(); i != brush.end(); ++i )
720 if ( shader_equal( ( *i )->GetShader(), name ) ) {
727 class BrushSelectByShaderWalker : public scene::Graph::Walker
731 BrushSelectByShaderWalker( const char* name )
734 bool pre( const scene::Path& path, scene::Instance& instance ) const {
735 if ( path.top().get().visible() ) {
736 Brush* brush = Node_getBrush( path.top() );
737 if ( brush != 0 && Brush_hasShader( *brush, m_name ) ) {
738 Instance_getSelectable( instance )->setSelected( true );
745 void Scene_BrushSelectByShader( scene::Graph& graph, const char* name ){
746 graph.traverse( BrushSelectByShaderWalker( name ) );
749 class FaceSelectByShader
753 FaceSelectByShader( const char* name )
756 void operator()( FaceInstance& face ) const {
757 printf( "checking %s = %s\n", face.getFace().GetShader(), m_name );
758 if ( shader_equal( face.getFace().GetShader(), m_name ) ) {
759 face.setSelected( SelectionSystem::eFace, true );
764 void Scene_BrushSelectByShader_Component( scene::Graph& graph, const char* name ){
765 Scene_ForEachSelectedBrush_ForEachFaceInstance( graph, FaceSelectByShader( name ) );
770 TextureProjection& m_projection;
773 FaceGetTexdef( TextureProjection& projection )
774 : m_projection( projection ), m_done( false ){
776 void operator()( Face& face ) const {
779 face.GetTexdef( m_projection );
785 void Scene_BrushGetTexdef_Selected( scene::Graph& graph, TextureProjection& projection ){
786 Scene_ForEachSelectedBrush_ForEachFace( graph, FaceGetTexdef( projection ) );
789 void Scene_BrushGetTexdef_Component_Selected( scene::Graph& graph, TextureProjection& projection ){
791 if ( !g_SelectedFaceInstances.empty() ) {
792 FaceInstance& faceInstance = g_SelectedFaceInstances.last();
793 faceInstance.getFace().GetTexdef( projection );
796 FaceGetTexdef visitor( projection );
797 Scene_ForEachSelectedBrushFace( graph, visitor );
801 void Scene_BrushGetShaderSize_Component_Selected( scene::Graph& graph, size_t& width, size_t& height ){
802 if ( !g_SelectedFaceInstances.empty() ) {
803 FaceInstance& faceInstance = g_SelectedFaceInstances.last();
804 width = faceInstance.getFace().getShader().width();
805 height = faceInstance.getFace().getShader().height();
812 ContentsFlagsValue& m_flags;
815 FaceGetFlags( ContentsFlagsValue& flags )
816 : m_flags( flags ), m_done( false ){
818 void operator()( Face& face ) const {
821 face.GetFlags( m_flags );
827 void Scene_BrushGetFlags_Selected( scene::Graph& graph, ContentsFlagsValue& flags ){
829 if ( GlobalSelectionSystem().countSelected() != 0 ) {
830 BrushInstance* brush = Instance_getBrush( GlobalSelectionSystem().ultimateSelected() );
832 Brush_forEachFace( *brush, FaceGetFlags( flags ) );
836 Scene_ForEachSelectedBrush_ForEachFace( graph, FaceGetFlags( flags ) );
840 void Scene_BrushGetFlags_Component_Selected( scene::Graph& graph, ContentsFlagsValue& flags ){
842 if ( !g_SelectedFaceInstances.empty() ) {
843 FaceInstance& faceInstance = g_SelectedFaceInstances.last();
844 faceInstance.getFace().GetFlags( flags );
847 Scene_ForEachSelectedBrushFace( graph, FaceGetFlags( flags ) );
854 CopiedString& m_shader;
857 FaceGetShader( CopiedString& shader )
858 : m_shader( shader ), m_done( false ){
860 void operator()( Face& face ) const {
863 m_shader = face.GetShader();
868 void Scene_BrushGetShader_Selected( scene::Graph& graph, CopiedString& shader ){
870 if ( GlobalSelectionSystem().countSelected() != 0 ) {
871 BrushInstance* brush = Instance_getBrush( GlobalSelectionSystem().ultimateSelected() );
873 Brush_forEachFace( *brush, FaceGetShader( shader ) );
877 Scene_ForEachSelectedBrush_ForEachFace( graph, FaceGetShader( shader ) );
881 void Scene_BrushGetShader_Component_Selected( scene::Graph& graph, CopiedString& shader ){
883 if ( !g_SelectedFaceInstances.empty() ) {
884 FaceInstance& faceInstance = g_SelectedFaceInstances.last();
885 shader = faceInstance.getFace().GetShader();
888 FaceGetShader visitor( shader );
889 Scene_ForEachSelectedBrushFace( graph, visitor );
894 class filter_face_shader : public FaceFilter
896 const char* m_shader;
898 filter_face_shader( const char* shader ) : m_shader( shader ){
900 bool filter( const Face& face ) const {
901 return shader_equal( face.GetShader(), m_shader );
905 class filter_face_shader_prefix : public FaceFilter
907 const char* m_prefix;
909 filter_face_shader_prefix( const char* prefix ) : m_prefix( prefix ){
911 bool filter( const Face& face ) const {
912 return shader_equal_n( face.GetShader(), m_prefix, strlen( m_prefix ) );
916 class filter_face_flags : public FaceFilter
920 filter_face_flags( int flags ) : m_flags( flags ){
922 bool filter( const Face& face ) const {
923 return ( face.getShader().shaderFlags() & m_flags ) != 0;
927 class filter_face_contents : public FaceFilter
931 filter_face_contents( int contents ) : m_contents( contents ){
933 bool filter( const Face& face ) const {
934 return ( face.getShader().m_flags.m_contentFlags & m_contents ) != 0;
942 FaceFilter* m_filter;
945 FaceFilterAny( FaceFilter* filter, bool& filtered ) : m_filter( filter ), m_filtered( filtered ){
948 void operator()( Face& face ) const {
949 if ( m_filter->filter( face ) ) {
955 class filter_brush_any_face : public BrushFilter
957 FaceFilter* m_filter;
959 filter_brush_any_face( FaceFilter* filter ) : m_filter( filter ){
961 bool filter( const Brush& brush ) const {
963 Brush_forEachFace( brush, FaceFilterAny( m_filter, filtered ) );
970 FaceFilter* m_filter;
973 FaceFilterAll( FaceFilter* filter, bool& filtered ) : m_filter( filter ), m_filtered( filtered ){
976 void operator()( Face& face ) const {
977 if ( !m_filter->filter( face ) ) {
983 class filter_brush_all_faces : public BrushFilter
985 FaceFilter* m_filter;
987 filter_brush_all_faces( FaceFilter* filter ) : m_filter( filter ){
989 bool filter( const Brush& brush ) const {
991 Brush_forEachFace( brush, FaceFilterAll( m_filter, filtered ) );
997 filter_face_flags g_filter_face_clip( QER_CLIP );
998 filter_brush_all_faces g_filter_brush_clip( &g_filter_face_clip );
1000 filter_face_shader g_filter_face_clip_q2( "textures/clip" );
1001 filter_brush_all_faces g_filter_brush_clip_q2( &g_filter_face_clip_q2 );
1003 filter_face_shader g_filter_face_weapclip( "textures/common/weapclip" );
1004 filter_brush_all_faces g_filter_brush_weapclip( &g_filter_face_weapclip );
1006 filter_face_shader g_filter_face_commonclip( "textures/common/clip" );
1007 filter_brush_all_faces g_filter_brush_commonclip( &g_filter_face_commonclip );
1009 filter_face_shader g_filter_face_fullclip( "textures/common/fullclip" );
1010 filter_brush_all_faces g_filter_brush_fullclip( &g_filter_face_fullclip );
1012 filter_face_shader g_filter_face_botclip( "textures/common/botclip" );
1013 filter_brush_all_faces g_filter_brush_botclip( &g_filter_face_botclip );
1015 filter_face_shader_prefix g_filter_face_caulk( "textures/common/caulk" );
1016 filter_brush_all_faces g_filter_brush_caulk( &g_filter_face_caulk );
1018 filter_face_shader_prefix g_filter_face_caulk_ja( "textures/system/caulk" );
1019 filter_brush_all_faces g_filter_brush_caulk_ja( &g_filter_face_caulk_ja );
1021 filter_face_shader_prefix g_filter_face_liquids( "textures/liquids/" );
1022 filter_brush_any_face g_filter_brush_liquids( &g_filter_face_liquids );
1024 filter_face_shader g_filter_face_hint( "textures/common/hint" );
1025 filter_brush_any_face g_filter_brush_hint( &g_filter_face_hint );
1027 filter_face_shader g_filter_face_hintlocal( "textures/common/hintlocal" );
1028 filter_brush_any_face g_filter_brush_hintlocal( &g_filter_face_hintlocal );
1030 filter_face_shader g_filter_face_hint_q2( "textures/hint" );
1031 filter_brush_any_face g_filter_brush_hint_q2( &g_filter_face_hint_q2 );
1033 filter_face_shader g_filter_face_hint_ja( "textures/system/hint" );
1034 filter_brush_any_face g_filter_brush_hint_ja( &g_filter_face_hint_ja );
1036 filter_face_shader g_filter_face_areaportal( "textures/common/areaportal" );
1037 filter_brush_all_faces g_filter_brush_areaportal( &g_filter_face_areaportal );
1039 filter_face_shader g_filter_face_visportal( "textures/editor/visportal" );
1040 filter_brush_any_face g_filter_brush_visportal( &g_filter_face_visportal );
1042 filter_face_shader g_filter_face_clusterportal( "textures/common/clusterportal" );
1043 filter_brush_all_faces g_filter_brush_clusterportal( &g_filter_face_clusterportal );
1045 filter_face_shader g_filter_face_lightgrid( "textures/common/lightgrid" );
1046 filter_brush_all_faces g_filter_brush_lightgrid( &g_filter_face_lightgrid );
1048 filter_face_flags g_filter_face_translucent( QER_TRANS );
1049 filter_brush_all_faces g_filter_brush_translucent( &g_filter_face_translucent );
1051 filter_face_contents g_filter_face_detail( BRUSH_DETAIL_MASK );
1052 filter_brush_all_faces g_filter_brush_detail( &g_filter_face_detail );
1054 filter_face_shader_prefix g_filter_face_decals( "textures/decals/" );
1055 filter_brush_any_face g_filter_brush_decals( &g_filter_face_decals );
1058 void BrushFilters_construct(){
1059 add_brush_filter( g_filter_brush_clip, EXCLUDE_CLIP );
1060 add_brush_filter( g_filter_brush_clip_q2, EXCLUDE_CLIP );
1061 add_brush_filter( g_filter_brush_weapclip, EXCLUDE_CLIP );
1062 add_brush_filter( g_filter_brush_fullclip, EXCLUDE_CLIP );
1063 add_brush_filter( g_filter_brush_commonclip, EXCLUDE_CLIP );
1064 add_brush_filter( g_filter_brush_botclip, EXCLUDE_BOTCLIP );
1065 add_brush_filter( g_filter_brush_caulk, EXCLUDE_CAULK );
1066 add_brush_filter( g_filter_brush_caulk_ja, EXCLUDE_CAULK );
1067 add_face_filter( g_filter_face_caulk, EXCLUDE_CAULK );
1068 add_face_filter( g_filter_face_caulk_ja, EXCLUDE_CAULK );
1069 add_brush_filter( g_filter_brush_liquids, EXCLUDE_LIQUIDS );
1070 add_brush_filter( g_filter_brush_hint, EXCLUDE_HINTSSKIPS );
1071 add_brush_filter( g_filter_brush_hintlocal, EXCLUDE_HINTSSKIPS );
1072 add_brush_filter( g_filter_brush_hint_q2, EXCLUDE_HINTSSKIPS );
1073 add_brush_filter( g_filter_brush_hint_ja, EXCLUDE_HINTSSKIPS );
1074 add_brush_filter( g_filter_brush_clusterportal, EXCLUDE_CLUSTERPORTALS );
1075 add_brush_filter( g_filter_brush_visportal, EXCLUDE_VISPORTALS );
1076 add_brush_filter( g_filter_brush_areaportal, EXCLUDE_AREAPORTALS );
1077 add_brush_filter( g_filter_brush_translucent, EXCLUDE_TRANSLUCENT );
1078 add_brush_filter( g_filter_brush_detail, EXCLUDE_DETAILS );
1079 add_brush_filter( g_filter_brush_detail, EXCLUDE_STRUCTURAL, true );
1080 add_brush_filter( g_filter_brush_lightgrid, EXCLUDE_LIGHTGRID );
1081 add_brush_filter( g_filter_brush_decals, EXCLUDE_DECALS );
1086 void normalquantisation_draw(){
1088 glBegin( GL_POINTS );
1089 for ( std::size_t i = 0; i <= c_quantise_normal; ++i )
1091 for ( std::size_t j = 0; j <= c_quantise_normal; ++j )
1093 Normal3f vertex( normal3f_normalised( Normal3f(
1094 static_cast<float>( c_quantise_normal - j - i ),
1095 static_cast<float>( i ),
1096 static_cast<float>( j )
1098 VectorScale( normal3f_to_array( vertex ), 64.f, normal3f_to_array( vertex ) );
1099 glVertex3fv( normal3f_to_array( vertex ) );
1100 vertex.x = -vertex.x;
1101 glVertex3fv( normal3f_to_array( vertex ) );
1107 class RenderableNormalQuantisation : public OpenGLRenderable
1110 void render( RenderStateFlags state ) const {
1111 normalquantisation_draw();
1115 const float g_test_quantise_normal = 1.f / static_cast<float>( 1 << 3 );
1117 class TestNormalQuantisation
1119 void check_normal( const Normal3f& normal, const Normal3f& other ){
1120 spherical_t spherical = spherical_from_normal3f( normal );
1121 double longditude = RAD2DEG( spherical.longditude );
1122 double latitude = RAD2DEG( spherical.latitude );
1123 double x = cos( spherical.longditude ) * sin( spherical.latitude );
1124 double y = sin( spherical.longditude ) * sin( spherical.latitude );
1125 double z = cos( spherical.latitude );
1127 ASSERT_MESSAGE( normal3f_dot( normal, other ) > 0.99, "bleh" );
1130 void test_normal( const Normal3f& normal ){
1131 Normal3f test = normal3f_from_spherical( spherical_from_normal3f( normal ) );
1132 check_normal( normal, test );
1134 EOctant octant = normal3f_classify_octant( normal );
1135 Normal3f folded = normal3f_fold_octant( normal, octant );
1136 ESextant sextant = normal3f_classify_sextant( folded );
1137 folded = normal3f_fold_sextant( folded, sextant );
1139 double scale = static_cast<float>( c_quantise_normal ) / ( folded.x + folded.y + folded.z );
1141 double zbits = folded.z * scale;
1142 double ybits = folded.y * scale;
1144 std::size_t zbits_q = static_cast<std::size_t>( zbits );
1145 std::size_t ybits_q = static_cast<std::size_t>( ybits );
1147 ASSERT_MESSAGE( zbits_q <= ( c_quantise_normal / 8 ) * 3, "bleh" );
1148 ASSERT_MESSAGE( ybits_q <= ( c_quantise_normal / 2 ), "bleh" );
1149 ASSERT_MESSAGE( zbits_q + ( ( c_quantise_normal / 2 ) - ybits_q ) <= ( c_quantise_normal / 2 ), "bleh" );
1151 std::size_t y_t = ( zbits_q < ( c_quantise_normal / 4 ) ) ? ybits_q : ( c_quantise_normal / 2 ) - ybits_q;
1152 std::size_t z_t = ( zbits_q < ( c_quantise_normal / 4 ) ) ? zbits_q : ( c_quantise_normal / 2 ) - zbits_q;
1153 std::size_t index = ( c_quantise_normal / 4 ) * y_t + z_t;
1154 ASSERT_MESSAGE( index <= ( c_quantise_normal / 4 ) * ( c_quantise_normal / 2 ), "bleh" );
1156 Normal3f tmp( c_quantise_normal - zbits_q - ybits_q, ybits_q, zbits_q );
1157 tmp = normal3f_normalised( tmp );
1159 Normal3f unfolded = normal3f_unfold_octant( normal3f_unfold_sextant( tmp, sextant ), octant );
1161 check_normal( normal, unfolded );
1163 double dot = normal3f_dot( normal, unfolded );
1164 float length = VectorLength( normal3f_to_array( unfolded ) );
1165 float inv_length = 1 / length;
1167 Normal3f quantised = normal3f_quantised( normal );
1168 check_normal( normal, quantised );
1170 void test2( const Normal3f& normal, const Normal3f& other ){
1171 if ( normal3f_quantised( normal ) != normal3f_quantised( other ) ) {
1176 static Normal3f normalise( float x, float y, float z ){
1177 return normal3f_normalised( Normal3f( x, y, z ) );
1181 return static_cast<float>( rand() - ( RAND_MAX / 2 ) );
1184 Normal3f normal3f_rand(){
1185 return normalise( vec_rand(), vec_rand(), vec_rand() );
1189 TestNormalQuantisation(){
1190 for ( int i = 4096; i > 0; --i )
1191 test_normal( normal3f_rand() );
1193 test_normal( normalise( 1, 0, 0 ) );
1194 test_normal( normalise( 0, 1, 0 ) );
1195 test_normal( normalise( 0, 0, 1 ) );
1196 test_normal( normalise( 1, 1, 0 ) );
1197 test_normal( normalise( 1, 0, 1 ) );
1198 test_normal( normalise( 0, 1, 1 ) );
1200 test_normal( normalise( 10000, 10000, 10000 ) );
1201 test_normal( normalise( 10000, 10000, 10001 ) );
1202 test_normal( normalise( 10000, 10000, 10002 ) );
1203 test_normal( normalise( 10000, 10000, 10010 ) );
1204 test_normal( normalise( 10000, 10000, 10020 ) );
1205 test_normal( normalise( 10000, 10000, 10030 ) );
1206 test_normal( normalise( 10000, 10000, 10100 ) );
1207 test_normal( normalise( 10000, 10000, 10101 ) );
1208 test_normal( normalise( 10000, 10000, 10102 ) );
1209 test_normal( normalise( 10000, 10000, 10200 ) );
1210 test_normal( normalise( 10000, 10000, 10201 ) );
1211 test_normal( normalise( 10000, 10000, 10202 ) );
1212 test_normal( normalise( 10000, 10000, 10203 ) );
1213 test_normal( normalise( 10000, 10000, 10300 ) );
1216 test2( normalise( 10000, 10000, 10000 ), normalise( 10000, 10000, 10001 ) );
1217 test2( normalise( 10000, 10000, 10001 ), normalise( 10000, 10001, 10000 ) );
1221 TestNormalQuantisation g_testNormalQuantisation;
1227 class TestSelectableObserver : public observer_template<const Selectable&>
1230 void notify( const Selectable& arguments ){
1231 bool bleh = arguments.isSelected();
1235 inline void test_bleh(){
1236 TestSelectableObserver test;
1237 ObservableSelectableInstance< SingleObservable< SelectionChangeCallback > > bleh;
1238 bleh.attach( test );
1239 bleh.setSelected( true );
1240 bleh.detach( test );
1251 const TestBleh testbleh;
1256 class TestRefcountedString
1259 TestRefcountedString(){
1262 SmartString string1( "string1" );
1263 SmartString string2( string1 );
1264 SmartString string3( string2 );
1267 // refcounted assignment
1268 SmartString string1( "string1" );
1269 SmartString string2( "string2" );
1274 SmartString string1( "string1" );
1275 SmartString string2( "string2" );
1276 string1 = string2.c_str();
1280 SmartString string1( "string1" );
1284 // self-assignment via another reference
1285 SmartString string1( "string1" );
1286 SmartString string2( string1 );
1292 const TestRefcountedString g_testRefcountedString;
1296 void Select_MakeDetail(){
1297 UndoableCommand undo( "brushSetDetail" );
1298 Scene_BrushSetDetail_Selected( GlobalSceneGraph(), true );
1301 void Select_MakeStructural(){
1302 UndoableCommand undo( "brushClearDetail" );
1303 Scene_BrushSetDetail_Selected( GlobalSceneGraph(), false );
1306 class BrushMakeSided
1308 std::size_t m_count;
1310 BrushMakeSided( std::size_t count )
1314 Scene_BrushConstructPrefab( GlobalSceneGraph(), eBrushPrism, m_count, TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ) );
1316 typedef MemberCaller<BrushMakeSided, &BrushMakeSided::set> SetCaller;
1320 BrushMakeSided g_brushmakesided3( 3 );
1321 BrushMakeSided g_brushmakesided4( 4 );
1322 BrushMakeSided g_brushmakesided5( 5 );
1323 BrushMakeSided g_brushmakesided6( 6 );
1324 BrushMakeSided g_brushmakesided7( 7 );
1325 BrushMakeSided g_brushmakesided8( 8 );
1326 BrushMakeSided g_brushmakesided9( 9 );
1328 inline int axis_for_viewtype( int viewtype ){
1343 EBrushPrefab m_type;
1345 BrushPrefab( EBrushPrefab type )
1349 DoSides( m_type, axis_for_viewtype( GetViewAxis() ) );
1351 typedef MemberCaller<BrushPrefab, &BrushPrefab::set> SetCaller;
1354 BrushPrefab g_brushprism( eBrushPrism );
1355 BrushPrefab g_brushcone( eBrushCone );
1356 BrushPrefab g_brushsphere( eBrushSphere );
1357 BrushPrefab g_brushrock( eBrushRock );
1363 void OnClipMode( bool enable );
1367 void ClipSelected(){
1369 UndoableCommand undo( "clipperClip" );
1374 void SplitSelected(){
1376 UndoableCommand undo( "clipperSplit" );
1386 Callback g_texture_lock_status_changed;
1387 BoolExportCaller g_texdef_movelock_caller( g_brush_texturelock_enabled );
1388 ToggleItem g_texdef_movelock_item( g_texdef_movelock_caller );
1390 void Texdef_ToggleMoveLock(){
1391 g_brush_texturelock_enabled = !g_brush_texturelock_enabled;
1392 g_texdef_movelock_item.update();
1393 g_texture_lock_status_changed();
1400 void Brush_registerCommands(){
1401 GlobalToggles_insert( "TogTexLock", FreeCaller<Texdef_ToggleMoveLock>(), ToggleItem::AddCallbackCaller( g_texdef_movelock_item ), Accelerator( 'T', (GdkModifierType)GDK_SHIFT_MASK ) );
1403 GlobalCommands_insert( "BrushPrism", BrushPrefab::SetCaller( g_brushprism ) );
1404 GlobalCommands_insert( "BrushCone", BrushPrefab::SetCaller( g_brushcone ) );
1405 GlobalCommands_insert( "BrushSphere", BrushPrefab::SetCaller( g_brushsphere ) );
1406 GlobalCommands_insert( "BrushRock", BrushPrefab::SetCaller( g_brushrock ) );
1408 GlobalCommands_insert( "Brush3Sided", BrushMakeSided::SetCaller( g_brushmakesided3 ), Accelerator( '3', (GdkModifierType)GDK_CONTROL_MASK ) );
1409 GlobalCommands_insert( "Brush4Sided", BrushMakeSided::SetCaller( g_brushmakesided4 ), Accelerator( '4', (GdkModifierType)GDK_CONTROL_MASK ) );
1410 GlobalCommands_insert( "Brush5Sided", BrushMakeSided::SetCaller( g_brushmakesided5 ), Accelerator( '5', (GdkModifierType)GDK_CONTROL_MASK ) );
1411 GlobalCommands_insert( "Brush6Sided", BrushMakeSided::SetCaller( g_brushmakesided6 ), Accelerator( '6', (GdkModifierType)GDK_CONTROL_MASK ) );
1412 GlobalCommands_insert( "Brush7Sided", BrushMakeSided::SetCaller( g_brushmakesided7 ), Accelerator( '7', (GdkModifierType)GDK_CONTROL_MASK ) );
1413 GlobalCommands_insert( "Brush8Sided", BrushMakeSided::SetCaller( g_brushmakesided8 ), Accelerator( '8', (GdkModifierType)GDK_CONTROL_MASK ) );
1414 GlobalCommands_insert( "Brush9Sided", BrushMakeSided::SetCaller( g_brushmakesided9 ), Accelerator( '9', (GdkModifierType)GDK_CONTROL_MASK ) );
1416 GlobalCommands_insert( "ClipSelected", FreeCaller<ClipSelected>(), Accelerator( GDK_Return ) );
1417 GlobalCommands_insert( "SplitSelected", FreeCaller<SplitSelected>(), Accelerator( GDK_Return, (GdkModifierType)GDK_SHIFT_MASK ) );
1418 GlobalCommands_insert( "FlipClip", FreeCaller<FlipClipper>(), Accelerator( GDK_Return, (GdkModifierType)GDK_CONTROL_MASK ) );
1420 GlobalCommands_insert( "MakeDetail", FreeCaller<Select_MakeDetail>(), Accelerator( 'D', (GdkModifierType)GDK_MOD1_MASK ) );
1421 GlobalCommands_insert( "MakeStructural", FreeCaller<Select_MakeStructural>(), Accelerator( 'S', (GdkModifierType)GDK_MOD1_MASK ) );
1424 void Brush_constructMenu( GtkMenu* menu ){
1425 create_menu_item_with_mnemonic( menu, "Prism...", "BrushPrism" );
1426 create_menu_item_with_mnemonic( menu, "Cone...", "BrushCone" );
1427 create_menu_item_with_mnemonic( menu, "Sphere...", "BrushSphere" );
1428 create_menu_item_with_mnemonic( menu, "Rock...", "BrushRock" );
1429 menu_separator( menu );
1431 GtkMenu* menu_in_menu = create_sub_menu_with_mnemonic( menu, "CSG" );
1432 if ( g_Layout_enableDetachableMenus.m_value ) {
1433 menu_tearoff( menu_in_menu );
1435 create_menu_item_with_mnemonic( menu_in_menu, "Make _Hollow", "CSGHollow" );
1436 create_menu_item_with_mnemonic( menu_in_menu, "CSG _Subtract", "CSGSubtract" );
1437 create_menu_item_with_mnemonic( menu_in_menu, "CSG _Merge", "CSGMerge" );
1439 menu_separator( menu );
1441 GtkMenu* menu_in_menu = create_sub_menu_with_mnemonic( menu, "Clipper" );
1442 if ( g_Layout_enableDetachableMenus.m_value ) {
1443 menu_tearoff( menu_in_menu );
1446 create_menu_item_with_mnemonic( menu_in_menu, "Clip selection", "ClipSelected" );
1447 create_menu_item_with_mnemonic( menu_in_menu, "Split selection", "SplitSelected" );
1448 create_menu_item_with_mnemonic( menu_in_menu, "Flip Clip orientation", "FlipClip" );
1450 menu_separator( menu );
1451 create_menu_item_with_mnemonic( menu, "Make detail", "MakeDetail" );
1452 create_menu_item_with_mnemonic( menu, "Make structural", "MakeStructural" );
1453 // create_menu_item_with_mnemonic( menu, "Snap selection to _grid", "SnapToGrid" );
1455 create_check_menu_item_with_mnemonic( menu, "Texture Lock", "TogTexLock" );
1456 menu_separator( menu );
1457 create_menu_item_with_mnemonic( menu, "Copy Face Texture", "FaceCopyTexture" );
1458 create_menu_item_with_mnemonic( menu, "Paste Face Texture", "FacePasteTexture" );
1460 command_connect_accelerator( "Brush3Sided" );
1461 command_connect_accelerator( "Brush4Sided" );
1462 command_connect_accelerator( "Brush5Sided" );
1463 command_connect_accelerator( "Brush6Sided" );
1464 command_connect_accelerator( "Brush7Sided" );
1465 command_connect_accelerator( "Brush8Sided" );
1466 command_connect_accelerator( "Brush9Sided" );