Dev/terrain material editing (#815)
* terrain material editing * serialization updates, refactors --------- Co-authored-by: Turánszki János <turanszkij@users.noreply.github.com>
This commit is contained in:
+132
-33
@@ -629,7 +629,7 @@ void TerrainWindow::Create(EditorComponent* _editor)
|
||||
ClearTransform();
|
||||
|
||||
wi::gui::Window::Create(ICON_TERRAIN " Terrain", wi::gui::Window::WindowControls::COLLAPSE | wi::gui::Window::WindowControls::CLOSE);
|
||||
SetSize(XMFLOAT2(420, 980));
|
||||
SetSize(XMFLOAT2(420, 1000));
|
||||
|
||||
closeButton.SetTooltip("Delete Terrain.");
|
||||
OnClose([=](wi::gui::EventArgs args) {
|
||||
@@ -1063,6 +1063,58 @@ void TerrainWindow::Create(EditorComponent* _editor)
|
||||
});
|
||||
AddWidget(®ion3Slider);
|
||||
|
||||
materialCombos[wi::terrain::MATERIAL_BASE].Create("Base material: ");
|
||||
materialCombos[wi::terrain::MATERIAL_SLOPE].Create("Slope material: ");
|
||||
materialCombos[wi::terrain::MATERIAL_LOW_ALTITUDE].Create("Low altitude material: ");
|
||||
materialCombos[wi::terrain::MATERIAL_HIGH_ALTITUDE].Create("High altitude material: ");
|
||||
|
||||
for (size_t i = 0; i < arraysize(materialCombos); ++i)
|
||||
{
|
||||
materialCombos[i].SetTooltip("Select material entity");
|
||||
materialCombos[i].SetSize(XMFLOAT2(wid, hei));
|
||||
materialCombos[i].SetPos(XMFLOAT2(x, y += step));
|
||||
materialCombos[i].OnSelect([&, i](wi::gui::EventArgs args) {
|
||||
const Scene& scene = editor->GetCurrentScene();
|
||||
wi::ecs::Entity entity = static_cast<wi::ecs::Entity>(args.userdata);
|
||||
if (entity != INVALID_ENTITY && scene.materials.Contains(entity))
|
||||
{
|
||||
if (terrain->materialEntities[i] != entity)
|
||||
{
|
||||
terrain->materialEntities[i] = entity;
|
||||
terrain->Generation_Restart();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
terrain->materialEntities[i] = INVALID_ENTITY;
|
||||
}
|
||||
});
|
||||
|
||||
AddWidget(&materialCombos[i]);
|
||||
}
|
||||
|
||||
materialCombo_GrassParticle.Create("Grass material: ");
|
||||
materialCombo_GrassParticle.SetTooltip("Select material entity");
|
||||
materialCombo_GrassParticle.SetSize(XMFLOAT2(wid, hei));
|
||||
materialCombo_GrassParticle.SetPos(XMFLOAT2(x, y += step));
|
||||
materialCombo_GrassParticle.OnSelect([&](wi::gui::EventArgs args) {
|
||||
const Scene& scene = editor->GetCurrentScene();
|
||||
wi::ecs::Entity entity = static_cast<wi::ecs::Entity>(args.userdata);
|
||||
if (entity != INVALID_ENTITY && scene.materials.Contains(entity))
|
||||
{
|
||||
if (terrain->grassEntity != entity)
|
||||
{
|
||||
terrain->grassEntity = entity;
|
||||
terrain->Generation_Restart();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
terrain->grassEntity = INVALID_ENTITY;
|
||||
}
|
||||
});
|
||||
AddWidget(&materialCombo_GrassParticle);
|
||||
|
||||
propsWindow.reset(new PropsWindow(editor));
|
||||
AddWidget(propsWindow.get());
|
||||
|
||||
@@ -1261,6 +1313,35 @@ void TerrainWindow::SetEntity(Entity entity)
|
||||
region2Slider.SetValue(terrain->region2);
|
||||
region3Slider.SetValue(terrain->region3);
|
||||
|
||||
auto fillMaterialCombo = [&](wi::gui::ComboBox& comboBox, Entity selected) {
|
||||
comboBox.ClearItems();
|
||||
comboBox.AddItem("NO MATERIAL", INVALID_ENTITY);
|
||||
for (size_t i = 0; i < scene.materials.GetCount(); ++i)
|
||||
{
|
||||
Entity entity = scene.materials.GetEntity(i);
|
||||
if (scene.names.Contains(entity))
|
||||
{
|
||||
const NameComponent& name = *scene.names.GetComponent(entity);
|
||||
comboBox.AddItem(name.name, entity);
|
||||
}
|
||||
else
|
||||
{
|
||||
comboBox.AddItem(std::to_string(entity), entity);
|
||||
}
|
||||
|
||||
if (selected == entity)
|
||||
{
|
||||
comboBox.SetSelectedWithoutCallback(int(i + 1));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
for (size_t i = 0; i < arraysize(materialCombos); ++i)
|
||||
{
|
||||
fillMaterialCombo(materialCombos[i], terrain->materialEntities[i]);
|
||||
}
|
||||
fillMaterialCombo(materialCombo_GrassParticle, terrain->grassEntity);
|
||||
|
||||
for (auto& x : terrain->modifiers)
|
||||
{
|
||||
switch (x->type)
|
||||
@@ -1314,23 +1395,37 @@ void TerrainWindow::SetupAssets()
|
||||
return;
|
||||
|
||||
// Customize terrain generator before it's initialized:
|
||||
terrain_preset.material_Base.SetRoughness(1);
|
||||
terrain_preset.material_Base.SetReflectance(0.005f);
|
||||
terrain_preset.material_Slope.SetRoughness(0.1f);
|
||||
terrain_preset.material_LowAltitude.SetRoughness(1);
|
||||
terrain_preset.material_HighAltitude.SetRoughness(1);
|
||||
terrain_preset.material_Base.textures[MaterialComponent::BASECOLORMAP].name = wi::helper::GetCurrentPath() + "/terrain/base.jpg";
|
||||
terrain_preset.material_Base.textures[MaterialComponent::NORMALMAP].name = wi::helper::GetCurrentPath() + "/terrain/base_nor.jpg";
|
||||
terrain_preset.material_Slope.textures[MaterialComponent::BASECOLORMAP].name = wi::helper::GetCurrentPath() + "/terrain/slope.jpg";
|
||||
terrain_preset.material_Slope.textures[MaterialComponent::NORMALMAP].name = wi::helper::GetCurrentPath() + "/terrain/slope_nor.jpg";
|
||||
terrain_preset.material_LowAltitude.textures[MaterialComponent::BASECOLORMAP].name = wi::helper::GetCurrentPath() + "/terrain/low_altitude.jpg";
|
||||
terrain_preset.material_LowAltitude.textures[MaterialComponent::NORMALMAP].name = wi::helper::GetCurrentPath() + "/terrain/low_altitude_nor.jpg";
|
||||
terrain_preset.material_HighAltitude.textures[MaterialComponent::BASECOLORMAP].name = wi::helper::GetCurrentPath() + "/terrain/high_altitude.jpg";
|
||||
terrain_preset.material_HighAltitude.textures[MaterialComponent::NORMALMAP].name = wi::helper::GetCurrentPath() + "/terrain/high_altitude_nor.jpg";
|
||||
terrain_preset.material_Base.CreateRenderData();
|
||||
terrain_preset.material_Slope.CreateRenderData();
|
||||
terrain_preset.material_LowAltitude.CreateRenderData();
|
||||
terrain_preset.material_HighAltitude.CreateRenderData();
|
||||
Scene& currentScene = editor->GetCurrentScene();
|
||||
|
||||
for (int i = 0; i < wi::terrain::MATERIAL_COUNT; ++i)
|
||||
{
|
||||
terrain_preset.materialEntities[i] = CreateEntity();
|
||||
currentScene.materials.Create(terrain_preset.materialEntities[i]);
|
||||
currentScene.Component_Attach(terrain_preset.materialEntities[i], entity);
|
||||
}
|
||||
|
||||
MaterialComponent* material_Base = currentScene.materials.GetComponent(terrain_preset.materialEntities[wi::terrain::MATERIAL_BASE]);
|
||||
MaterialComponent* material_Slope = currentScene.materials.GetComponent(terrain_preset.materialEntities[wi::terrain::MATERIAL_SLOPE]);
|
||||
MaterialComponent* material_LowAltitude = currentScene.materials.GetComponent(terrain_preset.materialEntities[wi::terrain::MATERIAL_LOW_ALTITUDE]);
|
||||
MaterialComponent* material_HighAltitude = currentScene.materials.GetComponent(terrain_preset.materialEntities[wi::terrain::MATERIAL_HIGH_ALTITUDE]);
|
||||
|
||||
material_Base->SetRoughness(1);
|
||||
material_Base->SetReflectance(0.005f);
|
||||
material_Slope->SetRoughness(0.1f);
|
||||
material_LowAltitude->SetRoughness(1);
|
||||
material_HighAltitude->SetRoughness(1);
|
||||
material_Base->textures[MaterialComponent::BASECOLORMAP].name = wi::helper::GetCurrentPath() + "/terrain/base.jpg";
|
||||
material_Base->textures[MaterialComponent::NORMALMAP].name = wi::helper::GetCurrentPath() + "/terrain/base_nor.jpg";
|
||||
material_Slope->textures[MaterialComponent::BASECOLORMAP].name = wi::helper::GetCurrentPath() + "/terrain/slope.jpg";
|
||||
material_Slope->textures[MaterialComponent::NORMALMAP].name = wi::helper::GetCurrentPath() + "/terrain/slope_nor.jpg";
|
||||
material_LowAltitude->textures[MaterialComponent::BASECOLORMAP].name = wi::helper::GetCurrentPath() + "/terrain/low_altitude.jpg";
|
||||
material_LowAltitude->textures[MaterialComponent::NORMALMAP].name = wi::helper::GetCurrentPath() + "/terrain/low_altitude_nor.jpg";
|
||||
material_HighAltitude->textures[MaterialComponent::BASECOLORMAP].name = wi::helper::GetCurrentPath() + "/terrain/high_altitude.jpg";
|
||||
material_HighAltitude->textures[MaterialComponent::NORMALMAP].name = wi::helper::GetCurrentPath() + "/terrain/high_altitude_nor.jpg";
|
||||
material_Base->CreateRenderData();
|
||||
material_Slope->CreateRenderData();
|
||||
material_LowAltitude->CreateRenderData();
|
||||
material_HighAltitude->CreateRenderData();
|
||||
|
||||
std::string terrain_path = wi::helper::GetCurrentPath() + "/terrain/";
|
||||
wi::config::File config;
|
||||
@@ -1431,43 +1526,42 @@ void TerrainWindow::SetupAssets()
|
||||
}
|
||||
|
||||
// Grass config:
|
||||
terrain_preset.material_GrassParticle.alphaRef = 0.75f;
|
||||
terrain_preset.grass_properties.length = 2;
|
||||
terrain_preset.grass_properties.frameCount = 2;
|
||||
terrain_preset.grass_properties.framesX = 1;
|
||||
terrain_preset.grass_properties.framesY = 2;
|
||||
terrain_preset.grass_properties.frameStart = 0;
|
||||
|
||||
terrain_preset.grassEntity = CreateEntity();
|
||||
currentScene.Component_Attach(terrain_preset.grassEntity, entity);
|
||||
currentScene.materials.Create(terrain_preset.grassEntity);
|
||||
currentScene.hairs.Create(terrain_preset.grassEntity);
|
||||
MaterialComponent* material_Grass = currentScene.materials.GetComponent(terrain_preset.grassEntity);
|
||||
wi::HairParticleSystem* grass = currentScene.hairs.GetComponent(terrain_preset.grassEntity);
|
||||
wi::config::File grass_config;
|
||||
grass_config.Open(std::string(terrain_path + "grass.ini").c_str());
|
||||
if (grass_config.Has("texture"))
|
||||
{
|
||||
terrain_preset.material_GrassParticle.textures[MaterialComponent::BASECOLORMAP].name = terrain_path + grass_config.GetText("texture");
|
||||
terrain_preset.material_GrassParticle.CreateRenderData();
|
||||
material_Grass->textures[MaterialComponent::BASECOLORMAP].name = terrain_path + grass_config.GetText("texture");
|
||||
material_Grass->CreateRenderData();
|
||||
}
|
||||
if (grass_config.Has("alphaRef"))
|
||||
{
|
||||
terrain_preset.material_GrassParticle.alphaRef = grass_config.GetFloat("alphaRef");
|
||||
material_Grass->alphaRef = grass_config.GetFloat("alphaRef");
|
||||
}
|
||||
if (grass_config.Has("length"))
|
||||
{
|
||||
terrain_preset.grass_properties.length = grass_config.GetFloat("length");
|
||||
grass->length = grass_config.GetFloat("length");
|
||||
}
|
||||
if (grass_config.Has("frameCount"))
|
||||
{
|
||||
terrain_preset.grass_properties.frameCount = grass_config.GetInt("frameCount");
|
||||
grass->frameCount = grass_config.GetInt("frameCount");
|
||||
}
|
||||
if (grass_config.Has("framesX"))
|
||||
{
|
||||
terrain_preset.grass_properties.framesX = grass_config.GetInt("framesX");
|
||||
grass->framesX = grass_config.GetInt("framesX");
|
||||
}
|
||||
if (grass_config.Has("framesY"))
|
||||
{
|
||||
terrain_preset.grass_properties.framesY = grass_config.GetInt("framesY");
|
||||
grass->framesY = grass_config.GetInt("framesY");
|
||||
}
|
||||
if (grass_config.Has("frameCount"))
|
||||
{
|
||||
terrain_preset.grass_properties.frameStart = grass_config.GetInt("frameStart");
|
||||
grass->frameStart = grass_config.GetInt("frameStart");
|
||||
}
|
||||
|
||||
terrain = &terrain_preset;
|
||||
@@ -1547,6 +1641,11 @@ void TerrainWindow::ResizeLayout()
|
||||
add(region1Slider);
|
||||
add(region2Slider);
|
||||
add(region3Slider);
|
||||
for (size_t i = 0; i < arraysize(materialCombos); ++i)
|
||||
{
|
||||
add(materialCombos[i]);
|
||||
}
|
||||
add(materialCombo_GrassParticle);
|
||||
add(saveHeightmapButton);
|
||||
add(saveRegionButton);
|
||||
add(addModifierCombo);
|
||||
|
||||
Reference in New Issue
Block a user