diff --git a/include/ishaders.h b/include/ishaders.h index fc837f28d2..19233cc32a 100644 --- a/include/ishaders.h +++ b/include/ishaders.h @@ -236,6 +236,9 @@ class Material /// Surface Type (wood, stone, surfType15, ...) virtual SurfaceType getSurfaceType() const = 0; + // Set the surface type of this material + virtual void setSurfaceType(SurfaceType type) = 0; + /// Get the deform type of this material virtual DeformType getDeformType() const = 0; diff --git a/libs/materials/ParseLib.h b/libs/materials/ParseLib.h index c373266f2c..5678b7b0bf 100644 --- a/libs/materials/ParseLib.h +++ b/libs/materials/ParseLib.h @@ -39,6 +39,19 @@ inline std::string getStringForSurfaceType(Material::SurfaceType type) return std::string(); } +inline Material::SurfaceType getSurfaceTypeForString(const std::string& surfaceTypeString) +{ + for (const auto& pair : SurfaceTypeMapping) + { + if (surfaceTypeString == pair.first) + { + return pair.second; + } + } + + return Material::SURFTYPE_DEFAULT; +} + constexpr std::pair PredefinedSortValues[] { { "subview", Material::SORT_SUBVIEW }, diff --git a/radiant/ui/materials/MaterialEditor.cpp b/radiant/ui/materials/MaterialEditor.cpp index 1d01075823..d44236e30d 100644 --- a/radiant/ui/materials/MaterialEditor.cpp +++ b/radiant/ui/materials/MaterialEditor.cpp @@ -155,6 +155,8 @@ void MaterialEditor::setupMaterialProperties() typeDropdown->AppendString(pair.first); } + typeDropdown->Bind(wxEVT_CHOICE, &MaterialEditor::_onMaterialTypeChoice, this); + auto* sortDropdown = getControl("MaterialSortValue"); sortDropdown->AppendString(""); // empty string for undefined @@ -1084,4 +1086,12 @@ void MaterialEditor::updateStageControls() } } +void MaterialEditor::_onMaterialTypeChoice(wxCommandEvent& ev) +{ + if (!_material) return; + + auto selectedString = getControl("MaterialType")->GetStringSelection(); + _material->setSurfaceType(shaders::getSurfaceTypeForString(selectedString.ToStdString())); +} + } diff --git a/radiant/ui/materials/MaterialEditor.h b/radiant/ui/materials/MaterialEditor.h index 2d1e4d3489..5e5ff59bfc 100644 --- a/radiant/ui/materials/MaterialEditor.h +++ b/radiant/ui/materials/MaterialEditor.h @@ -92,6 +92,7 @@ class MaterialEditor : void _onTreeViewSelectionChanged(wxDataViewEvent& ev); void _onStageListSelectionChanged(wxDataViewEvent& ev); + void _onMaterialTypeChoice(wxCommandEvent& ev); // Shortcut template diff --git a/radiantcore/shaders/CShader.cpp b/radiantcore/shaders/CShader.cpp index ae0ab9d9c2..055be800ff 100644 --- a/radiantcore/shaders/CShader.cpp +++ b/radiantcore/shaders/CShader.cpp @@ -185,6 +185,12 @@ Material::SurfaceType CShader::getSurfaceType() const return _template->getSurfaceType(); } +void CShader::setSurfaceType(SurfaceType type) +{ + ensureTemplateCopy(); + _template->setSurfaceType(type); +} + Material::DeformType CShader::getDeformType() const { return _template->getDeformType(); diff --git a/radiantcore/shaders/CShader.h b/radiantcore/shaders/CShader.h index 4eb8c7b21b..ffa1039fc8 100644 --- a/radiantcore/shaders/CShader.h +++ b/radiantcore/shaders/CShader.h @@ -72,6 +72,7 @@ class CShader final : ClampType getClampType() const override; int getSurfaceFlags() const override; SurfaceType getSurfaceType() const override; + void setSurfaceType(SurfaceType type) override; DeformType getDeformType() const override; IShaderExpressionPtr getDeformExpression(std::size_t index) override; std::string getDeformDeclName() override; diff --git a/radiantcore/shaders/ShaderTemplate.h b/radiantcore/shaders/ShaderTemplate.h index cd88867e53..72cb5bebc6 100644 --- a/radiantcore/shaders/ShaderTemplate.h +++ b/radiantcore/shaders/ShaderTemplate.h @@ -207,6 +207,12 @@ class ShaderTemplate final return _surfaceType; } + void setSurfaceType(Material::SurfaceType type) + { + if (!_parsed) parseDefinition(); + _surfaceType = type; + } + Material::DeformType getDeformType() { if (!_parsed) parseDefinition();