diff --git a/radiant/brushmanip.cpp b/radiant/brushmanip.cpp index 1dbc39d2..89be318a 100644 --- a/radiant/brushmanip.cpp +++ b/radiant/brushmanip.cpp @@ -908,6 +908,21 @@ void Scene_BrushGetTexdef_Selected( scene::Graph& graph, TextureProjection& proj Scene_ForEachSelectedBrush_ForEachFace( graph, FaceGetTexdef( projection ) ); } +bool Scene_BrushGetShaderTexdef_Selected( scene::Graph& graph, CopiedString& shader, TextureProjection& projection ){ + BrushInstance *brush = nullptr; + if ( GlobalSelectionSystem().countSelected() == 0 + || !( brush = Instance_getBrush( GlobalSelectionSystem().ultimateSelected() ) ) ) { + Scene_forEachSelectedBrush( [&brush]( BrushInstance& b ){ if( !brush ) brush = &b; } ); + } + if( brush && !brush->getBrush().empty() ){ + Face *face = brush->getBrush().begin()->get(); + shader = face->GetShader(); + face->GetTexdef( projection ); + return true; + } + return false; +} + void Scene_BrushGetTexdef_Component_Selected( scene::Graph& graph, TextureProjection& projection ){ #if 1 if ( !g_SelectedFaceInstances.empty() ) { diff --git a/radiant/brushmanip.h b/radiant/brushmanip.h index 91fbdcbc..222ed58e 100644 --- a/radiant/brushmanip.h +++ b/radiant/brushmanip.h @@ -51,6 +51,7 @@ void Scene_BrushSetTexdef_Component_Selected( scene::Graph& graph, const Texture void Scene_BrushSetTexdef_Selected( scene::Graph& graph, const float* hShift, const float* vShift, const float* hScale, const float* vScale, const float* rotation ); void Scene_BrushSetTexdef_Component_Selected( scene::Graph& graph, const float* hShift, const float* vShift, const float* hScale, const float* vScale, const float* rotation ); void Scene_BrushGetTexdef_Selected( scene::Graph& graph, TextureProjection& projection ); +bool Scene_BrushGetShaderTexdef_Selected( scene::Graph& graph, CopiedString& shader, TextureProjection& projection ); void Scene_BrushGetTexdef_Component_Selected( scene::Graph& graph, TextureProjection& projection ); void Scene_BrushSetFlags_Selected( scene::Graph& graph, const ContentsFlagsValue& flags ); void Scene_BrushSetFlags_Component_Selected( scene::Graph& graph, const ContentsFlagsValue& flags ); diff --git a/radiant/patchmanip.cpp b/radiant/patchmanip.cpp index 87bcfee8..7b577354 100644 --- a/radiant/patchmanip.cpp +++ b/radiant/patchmanip.cpp @@ -1133,6 +1133,20 @@ void Scene_PatchGetTexdef_Selected( scene::Graph& graph, TextureProjection &proj } } +bool Scene_PatchGetShaderTexdef_Selected( scene::Graph& graph, CopiedString& name, TextureProjection &projection ){ + Patch* patch = nullptr; + if ( !( patch = Scene_GetUltimateSelectedVisiblePatch() ) ) + Scene_forEachSelectedPatch( [&patch]( PatchInstance& p ){ if( !patch ) patch = &p.getPatch(); } ); + if( patch ){ + name = patch->GetShader(); + PatchTexdefConstructor c( patch ); + if( c.valid() ) + projection.m_brushprimit_texdef = c.m_bp; + return true; + } + return false; +} + void Patch_SetTexdef( const float* hShift, const float* vShift, const float* hScale, const float* vScale, const float* rotation ){ Scene_forEachVisibleSelectedPatch( [hShift, vShift, hScale, vScale, rotation]( Patch& patch ){ PatchTexdefConstructor c( &patch ); diff --git a/radiant/patchmanip.h b/radiant/patchmanip.h index 39953086..70de3341 100644 --- a/radiant/patchmanip.h +++ b/radiant/patchmanip.h @@ -39,6 +39,7 @@ void Scene_PatchFindReplaceShader( scene::Graph& graph, const char* find, const void Scene_PatchFindReplaceShader_Selected( scene::Graph& graph, const char* find, const char* replace ); void Scene_PatchGetTexdef_Selected( scene::Graph& graph, class TextureProjection &projection ); +bool Scene_PatchGetShaderTexdef_Selected( scene::Graph& graph, CopiedString& name, TextureProjection &projection ); void Patch_SetTexdef( const float* hShift, const float* vShift, const float* hScale, const float* vScale, const float* rotation ); void Scene_PatchCapTexture_Selected( scene::Graph& graph ); diff --git a/radiant/surfacedialog.cpp b/radiant/surfacedialog.cpp index 1419d79c..3f8c2055 100644 --- a/radiant/surfacedialog.cpp +++ b/radiant/surfacedialog.cpp @@ -251,7 +251,7 @@ void SurfaceInspector_SetCurrent_FromSelected(){ CopiedString name; Scene_BrushGetShader_Component_Selected( GlobalSceneGraph(), name ); - if ( string_not_empty( name.c_str() ) ) { + if ( !name.empty() ) { SurfaceInspector_SetSelectedShader( name.c_str() ); } @@ -263,18 +263,12 @@ void SurfaceInspector_SetCurrent_FromSelected(){ { TextureProjection projection; CopiedString name; - Scene_BrushGetShader_Selected( GlobalSceneGraph(), name ); - if ( string_empty( name.c_str() ) ) { - s_patch_mode = true; - Scene_PatchGetShader_Selected( GlobalSceneGraph(), name ); - Scene_PatchGetTexdef_Selected( GlobalSceneGraph(), projection ); - } - else{ - s_patch_mode = false; - Scene_BrushGetTexdef_Selected( GlobalSceneGraph(), projection ); - } + s_patch_mode = false; + if( !Scene_BrushGetShaderTexdef_Selected( GlobalSceneGraph(), name, projection ) ) + if( Scene_PatchGetShaderTexdef_Selected( GlobalSceneGraph(), name, projection ) ) + s_patch_mode = true; SurfaceInspector_SetSelectedTexdef( projection ); - if ( string_not_empty( name.c_str() ) ) { + if ( !name.empty() ) { SurfaceInspector_SetSelectedShader( name.c_str() ); }