Skip to content

Commit

Permalink
Reorganize shader, improved icons (#114)
Browse files Browse the repository at this point in the history
  • Loading branch information
edisonlee0212 authored Dec 31, 2024
1 parent ff79c69 commit d8782fb
Show file tree
Hide file tree
Showing 94 changed files with 898 additions and 314 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class SorghumDescriptor : public IAsset {
void Serialize(YAML::Emitter& out) const override;
void Deserialize(const YAML::Node& in) override;
[[maybe_unused]] Entity CreateEntity(const std::string& name) const;

[[nodiscard]] std::shared_ptr<Texture2D> GenerateThumbnailTexture() override;
void ImportPrediction(const std::filesystem::path& yaml_path);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class SorghumField : public IAsset {
bool OnInspect(const std::shared_ptr<EditorLayer>& editor_layer) override;
void Serialize(YAML::Emitter& out) const override;
void Deserialize(const YAML::Node& in) override;
[[nodiscard]] std::shared_ptr<Texture2D> GenerateThumbnailTexture() override;
void CollectAssetRef(std::vector<AssetRef>& list) override;
};
} // namespace digital_agriculture_plugin
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#pragma once

#include "Plot2D.hpp"
#include "SorghumGrowthStages.hpp"
#include "SorghumDescriptor.hpp"
#include "SorghumGrowthStages.hpp"
using namespace evo_engine;
namespace digital_agriculture_plugin {

Expand Down Expand Up @@ -42,9 +42,10 @@ class SorghumGenerator : public IAsset {
bool OnInspect(const std::shared_ptr<EditorLayer>& editor_layer) override;
void Serialize(YAML::Emitter& out) const override;
void Deserialize(const YAML::Node& in) override;

[[nodiscard]] std::shared_ptr<Texture2D> GenerateThumbnailTexture() override;
[[nodiscard]] Entity CreateEntity(unsigned int seed = 0) const;
void Apply(const std::shared_ptr<SorghumDescriptor>& target_sorghum_descriptor, unsigned int seed = 0) const;
void Apply(const std::shared_ptr<SorghumState>& target_sorghum_state, unsigned int seed = 0) const;
};

} // namespace digital_agriculture_plugin
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class SorghumGrowthStages : public IAsset {
bool OnInspect(const std::shared_ptr<EditorLayer>& editor_layer) override;
void Serialize(YAML::Emitter& out) const override;
void Deserialize(const YAML::Node& in) override;

[[nodiscard]] std::shared_ptr<Texture2D> GenerateThumbnailTexture() override;
[[nodiscard]] Entity CreateEntity(float time = 0.0f) const;
};
} // namespace digital_agriculture_plugin
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once
#include "Curve.hpp"
#include "Plot2D.hpp"
#include "SorghumDescriptor.hpp"
#include "Curve.hpp"
using namespace evo_engine;
namespace digital_agriculture_plugin {
#pragma region States
Expand All @@ -17,7 +17,7 @@ struct SorghumPanicleState {
bool OnInspectImpl();
void Serialize(YAML::Emitter& out) const;
void Deserialize(const YAML::Node& in);
void Apply(SorghumPanicleDescriptor &target_sorghum_panicle_descriptor) const;
void Apply(SorghumPanicleDescriptor& target_sorghum_panicle_descriptor) const;
};
struct SorghumStemState {
BezierSpline spline;
Expand Down Expand Up @@ -57,14 +57,15 @@ struct SorghumLeafState {
bool OnInspectImpl(int mode);
void Apply(const SorghumStemState& stem_state, SorghumLeafDescriptor& target_sorghum_leaf_descriptor) const;

void ChangeWaviness(float factor,
const SorghumStemState& stem_state,
const SorghumMeshGeneratorSettings& mesh_generator_settings, SorghumLeafState& target_leaf_state) const;
void ChangeWaviness(float factor, const SorghumStemState& stem_state,
const SorghumMeshGeneratorSettings& mesh_generator_settings,
SorghumLeafState& target_leaf_state) const;
};
#pragma endregion

class SorghumState : public IAsset {
friend class SorghumGrowthStages;

public:
SorghumState();
bool saved = false;
Expand All @@ -78,8 +79,9 @@ class SorghumState : public IAsset {
void Serialize(YAML::Emitter& out) const override;
void Deserialize(const YAML::Node& in) override;
[[maybe_unused]] Entity CreateEntity(const std::string& name) const;
[[nodiscard]] std::shared_ptr<Texture2D> GenerateThumbnailTexture() override;


void ChangeWaviness(float factor, const SorghumMeshGeneratorSettings& mesh_generator_settings, SorghumState& target_sorghum_state) const;
void ChangeWaviness(float factor, const SorghumMeshGeneratorSettings& mesh_generator_settings,
SorghumState& target_sorghum_state) const;
};
} // namespace digital_agriculture_plugin
10 changes: 10 additions & 0 deletions EvoEngine_Plugins/DigitalAgriculture/src/SorghumDescriptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,16 @@ Entity SorghumDescriptor::CreateEntity(const std::string& name) const {
return sorghum_entity;
}

std::shared_ptr<Texture2D> SorghumDescriptor::GenerateThumbnailTexture() {
static std::shared_ptr<Texture2D> thumbnail;
if (!thumbnail) {
thumbnail = ProjectManager::CreateTemporaryAsset<Texture2D>();
thumbnail->Import(std::filesystem::absolute(std::filesystem::path("./DigitalAgricultureResources") /
"Icons/SorghumDescriptor.png"));
}
return thumbnail;
}

void SorghumDescriptor::ImportPrediction(const std::filesystem::path& yaml_path) {
if (!std::filesystem::exists(yaml_path)) {
EVOENGINE_ERROR("File not exist!")
Expand Down
13 changes: 12 additions & 1 deletion EvoEngine_Plugins/DigitalAgriculture/src/SorghumField.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
#include "Scene.hpp"
#include "Soil.hpp"
#include "Sorghum.hpp"
#include "SorghumLayer.hpp"
#include "SorghumGenerator.hpp"
#include "SorghumLayer.hpp"
#include "TransformGraph.hpp"
using namespace digital_agriculture_plugin;
using namespace eco_sys_lab_plugin;
Expand Down Expand Up @@ -92,6 +92,17 @@ void SorghumField::Deserialize(const YAML::Node& in) {
}
}
}

std::shared_ptr<Texture2D> SorghumField::GenerateThumbnailTexture() {
static std::shared_ptr<Texture2D> thumbnail;
if (!thumbnail) {
thumbnail = ProjectManager::CreateTemporaryAsset<Texture2D>();
thumbnail->Import(
std::filesystem::absolute(std::filesystem::path("./DigitalAgricultureResources") / "Icons/SorghumField.png"));
}
return thumbnail;
}

void SorghumField::CollectAssetRef(std::vector<AssetRef>& list) {
for (auto& i : matrices) {
list.push_back(i.first);
Expand Down
21 changes: 16 additions & 5 deletions EvoEngine_Plugins/DigitalAgriculture/src/SorghumGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,16 @@ void SorghumGenerator::Deserialize(const YAML::Node& in) {
curling_along_leaf.Load("curling_along_leaf", in);
}

std::shared_ptr<Texture2D> SorghumGenerator::GenerateThumbnailTexture() {
static std::shared_ptr<Texture2D> thumbnail;
if (!thumbnail) {
thumbnail = ProjectManager::CreateTemporaryAsset<Texture2D>();
thumbnail->Import(std::filesystem::absolute(std::filesystem::path("./DigitalAgricultureResources") /
"Icons/SorghumGenerator.png"));
}
return thumbnail;
}

Entity SorghumGenerator::CreateEntity(const unsigned int seed) const {
const auto scene = Application::GetActiveScene();
const auto entity = scene->CreateEntity(GetTitle());
Expand All @@ -263,7 +273,8 @@ Entity SorghumGenerator::CreateEntity(const unsigned int seed) const {
return entity;
}

void SorghumGenerator::Apply(const std::shared_ptr<SorghumDescriptor>& target_sorghum_descriptor, const unsigned int seed) const {
void SorghumGenerator::Apply(const std::shared_ptr<SorghumDescriptor>& target_sorghum_descriptor,
const unsigned int seed) const {
const auto sorghum_state = ProjectManager::CreateTemporaryAsset<SorghumState>();
Apply(sorghum_state, seed);
sorghum_state->Apply(target_sorghum_descriptor);
Expand All @@ -272,13 +283,13 @@ void SorghumGenerator::Apply(const std::shared_ptr<SorghumDescriptor>& target_so
void SorghumGenerator::Apply(const std::shared_ptr<SorghumState>& target_sorghum_state, const unsigned seed) const {
if (seed > 0)
srand(seed);
//Panicle
// Panicle
target_sorghum_state->panicle.seed_amount = static_cast<int>(panicle_seed_amount.GetValue());
const auto current_panicle_size = this->panicle_size.GetValue();
target_sorghum_state->panicle.panicle_size =
glm::vec3(current_panicle_size.x, current_panicle_size.y, current_panicle_size.x);
target_sorghum_state->panicle.seed_radius = panicle_seed_radius.GetValue();
//Stem
// Stem
constexpr auto up_direction = glm::vec3(0, 1, 0);
auto front_direction = glm::vec3(0, 0, -1);
front_direction = glm::rotate(front_direction, glm::radians(glm::linearRand(0.0f, 360.0f)), up_direction);
Expand All @@ -289,7 +300,7 @@ void SorghumGenerator::Apply(const std::shared_ptr<SorghumState>& target_sorghum
target_sorghum_state->stem.length =
internode_length.GetValue() * static_cast<float>(leaf_size) / (1.f - leaf_starting_point.GetValue(0));
target_sorghum_state->stem.width_along_stem = {0.0f, stem_width.GetValue(), width_along_stem};
//Leaves
// Leaves
target_sorghum_state->leaves.resize(leaf_size);
for (int leaf_index = 0; leaf_index < leaf_size; leaf_index++) {
const float step = static_cast<float>(leaf_index) / (static_cast<float>(leaf_size) - 1.0f);
Expand All @@ -303,7 +314,7 @@ void SorghumGenerator::Apply(const std::shared_ptr<SorghumState>& target_sorghum
leaf_state.waviness_along_leaf = {0.0f, leaf_waviness.GetValue(step) * 2.0f, waviness_along_leaf};
leaf_state.width_along_leaf = {0.0f, leaf_width.GetValue(step) * 2.0f, width_along_leaf};
const auto curling = glm::clamp(leaf_curling.GetValue(step), 0.0f, 90.0f) / 90.0f;
//leaf_state.curling_along_leaf = {0.0f, curling * 90.0f, curling_along_leaf};
// leaf_state.curling_along_leaf = {0.0f, curling * 90.0f, curling_along_leaf};
leaf_state.curling_along_leaf = {0.0f, curling * 90.0f, {1.f, 1.f}};
leaf_state.branching_angle = leaf_branching_angle.GetValue(step);
leaf_state.roll_angle = glm::mod((leaf_index % 2) * 180.0f + leaf_roll_angle.GetValue(step), 360.0f);
Expand Down
10 changes: 10 additions & 0 deletions EvoEngine_Plugins/DigitalAgriculture/src/SorghumGrowthStages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,16 @@ void SorghumGrowthStages::Deserialize(const YAML::Node& in) {
}
}

std::shared_ptr<Texture2D> SorghumGrowthStages::GenerateThumbnailTexture() {
static std::shared_ptr<Texture2D> thumbnail;
if (!thumbnail) {
thumbnail = ProjectManager::CreateTemporaryAsset<Texture2D>();
thumbnail->Import(std::filesystem::absolute(std::filesystem::path("./DigitalAgricultureResources") /
"Icons/SorghumGrowthStages.png"));
}
return thumbnail;
}

Entity SorghumGrowthStages::CreateEntity(const float time) const {
const auto scene = Application::GetActiveScene();
const auto entity = scene->CreateEntity(GetTitle());
Expand Down
14 changes: 0 additions & 14 deletions EvoEngine_Plugins/DigitalAgriculture/src/SorghumLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,6 @@ AssetRegistration<SkyIlluminance> si_registry("SkyIlluminance", {".skyilluminanc
AssetRegistration<SorghumCoordinates> sc_registry("SorghumCoordinates", {".sorghumcoords"});

void SorghumLayer::OnCreate() {
if (const auto editor_layer = Application::GetLayer<EditorLayer>()) {
auto texture_2d = ProjectManager::CreateTemporaryAsset<Texture2D>();
texture_2d->Import(std::filesystem::absolute(std::filesystem::path("./DigitalAgricultureResources/Textures") /
"SorghumGrowthDescriptor.png"));
texture_2d = ProjectManager::CreateTemporaryAsset<Texture2D>();
texture_2d->Import(std::filesystem::absolute(std::filesystem::path("./DigitalAgricultureResources/Textures") /
"SorghumDescriptor.png"));
texture_2d = ProjectManager::CreateTemporaryAsset<Texture2D>();
texture_2d->Import(std::filesystem::absolute(std::filesystem::path("./DigitalAgricultureResources/Textures") /
"PositionsField.png"));
texture_2d->Import(std::filesystem::absolute(std::filesystem::path("./DigitalAgricultureResources/Textures") /
"GeneralDataPipeline.png"));
}

if (!leaf_material.Get<Material>()) {
const auto material = ProjectManager::CreateTemporaryAsset<Material>();
leaf_material = material;
Expand Down
46 changes: 26 additions & 20 deletions EvoEngine_Plugins/DigitalAgriculture/src/SorghumState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,15 @@
#include "EditorLayer.hpp"
#include "Scene.hpp"

#include "Sorghum.hpp"
#include "SorghumGenerator.hpp"
#include "SorghumGrowthStages.hpp"
#include "SorghumLayer.hpp"
#include "SorghumGenerator.hpp"
#include "Times.hpp"
#include "Utilities.hpp"
#include "rapidcsv.h"
#include "Sorghum.hpp"
using namespace digital_agriculture_plugin;



bool SorghumPanicleState::OnInspectImpl() {
bool changed = false;
if (ImGui::DragFloat("Panicle width", &panicle_size.x, 0.001f)) {
Expand Down Expand Up @@ -49,8 +47,7 @@ void SorghumPanicleState::Deserialize(const YAML::Node& in) {
saved = true;
}

void SorghumPanicleState::Apply(
SorghumPanicleDescriptor& target_sorghum_panicle_descriptor) const {
void SorghumPanicleState::Apply(SorghumPanicleDescriptor& target_sorghum_panicle_descriptor) const {
target_sorghum_panicle_descriptor.panicle_size = panicle_size;
target_sorghum_panicle_descriptor.seed_amount = seed_amount;
target_sorghum_panicle_descriptor.seed_radius = seed_radius;
Expand Down Expand Up @@ -126,8 +123,8 @@ void SorghumStemState::Apply(SorghumStemDescriptor& target_sorghum_stem_descript
stem_node_position = direction * stem_unit_length * static_cast<float>(i);

const auto up = glm::normalize(glm::cross(direction, stem_left));
target_sorghum_stem_descriptor.spline.segments.emplace_back(stem_node_position, up, direction, stem_width, 180.f,
0, 0);
target_sorghum_stem_descriptor.spline.segments.emplace_back(stem_node_position, up, direction, stem_width, 180.f, 0,
0);
}
}

Expand Down Expand Up @@ -223,13 +220,14 @@ void SorghumLeafState::Apply(const SorghumStemState& stem_state,

const auto up = glm::normalize(glm::cross(stem_state.direction, leaf_left));
target_sorghum_leaf_descriptor.spline.segments.emplace_back(
glm::normalize(stem_state.direction) * current_root_to_sheath_point * stem_state.length + stem_offset, up, stem_state.direction,
stem_width, 180.f, 0, 0);
glm::normalize(stem_state.direction) * current_root_to_sheath_point * stem_state.length + stem_offset, up,
stem_state.direction, stem_width, 180.f, 0, 0);
}
}
/*
int sheath_node_count =
static_cast<int>(glm::max(2.0f, stem_state.length * back_track_ratio / sorghum_layer->vertical_subdivision_length));
static_cast<int>(glm::max(2.0f, stem_state.length * back_track_ratio /
sorghum_layer->vertical_subdivision_length));
for (int i = 0; i <= sheath_node_count; i++) {
float factor = static_cast<float>(i) / static_cast<float>(sheath_node_count);
Expand All @@ -240,8 +238,9 @@ void SorghumLeafState::Apply(const SorghumStemState& stem_state,
const auto up = glm::normalize(glm::cross(actual_direction, leaf_left));
target_sorghum_leaf_descriptor.spline.segments.emplace_back(
glm::normalize(stem_state.direction) * current_sheath_point * stem_state.length + stem_offset, up, actual_direction, stem_width + 0.002f * static_cast<float>(i) / static_cast<float>(sheath_node_count),
180.0f - 90.0f * static_cast<float>(i) / static_cast<float>(sheath_node_count), 0, 0);
glm::normalize(stem_state.direction) * current_sheath_point * stem_state.length + stem_offset, up,
actual_direction, stem_width + 0.002f * static_cast<float>(i) / static_cast<float>(sheath_node_count), 180.0f - 90.0f
* static_cast<float>(i) / static_cast<float>(sheath_node_count), 0, 0);
}
*/
int node_amount = static_cast<int>(glm::max(4.0f, length / sorghum_layer->vertical_subdivision_length));
Expand Down Expand Up @@ -272,13 +271,11 @@ void SorghumLeafState::Apply(const SorghumStemState& stem_state,

const auto up = glm::normalize(glm::cross(current_direction, leaf_left));
target_sorghum_leaf_descriptor.spline.segments.emplace_back(
node_position, up, current_direction, width, angle,
waviness * glm::simplex(glm::vec2(current_period.x, 0.f)),
waviness * glm::simplex(glm::vec2(0.f, current_period.y)));
node_position, up, current_direction, width, angle, waviness * glm::simplex(glm::vec2(current_period.x, 0.f)),
waviness * glm::simplex(glm::vec2(0.f, current_period.y)));
}
}


void SorghumLeafState::Serialize(YAML::Emitter& out) const {
out << YAML::Key << "dead" << YAML::Value << dead;
out << YAML::Key << "index" << YAML::Value << index;
Expand Down Expand Up @@ -502,7 +499,6 @@ bool SorghumState::OnInspect(const std::shared_ptr<EditorLayer>& editor_layer) {
}
}


static int state_mode = static_cast<int>(StateMode::Default);
static const char* state_modes[]{"Default", "Cubic-Bezier"};
if (ImGui::Combo("Mode", &state_mode, state_modes, IM_ARRAYSIZE(state_modes))) {
Expand Down Expand Up @@ -575,6 +571,16 @@ Entity SorghumState::CreateEntity(const std::string& name) const {
return sorghum_entity;
}

std::shared_ptr<Texture2D> SorghumState::GenerateThumbnailTexture() {
static std::shared_ptr<Texture2D> thumbnail;
if (!thumbnail) {
thumbnail = ProjectManager::CreateTemporaryAsset<Texture2D>();
thumbnail->Import(std::filesystem::absolute(std::filesystem::path("./DigitalAgricultureResources") /
"Icons/SorghumDescriptor.png"));
}
return thumbnail;
}

void SorghumState::ChangeWaviness(const float factor, const SorghumMeshGeneratorSettings& mesh_generator_settings,
SorghumState& target_sorghum_state) const {
target_sorghum_state = *this;
Expand Down Expand Up @@ -608,7 +614,7 @@ void SorghumLeafState::ChangeWaviness(const float factor, const SorghumStemState

Apply(stem_state, sorghum_leaf_descriptor);
sorghum_leaf_descriptor.GenerateGeometry(vertices, indices, mesh_generator_settings);

const float target_total_area = calculate_total_area();

float width_factor_upper_bound = 2.f;
Expand All @@ -629,7 +635,7 @@ void SorghumLeafState::ChangeWaviness(const float factor, const SorghumStemState

if (calculate_total_area() >= target_total_area) {
width_factor_upper_bound = mid_width_factor;
}else {
} else {
width_factor_lower_bound = mid_width_factor;
}
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit d8782fb

Please sign in to comment.