Skip to content

Commit

Permalink
Removed glm dependencies for LogWood implementations for Swift transl…
Browse files Browse the repository at this point in the history
…ation. (#12)
  • Loading branch information
edisonlee0212 authored Oct 9, 2024
1 parent 12cb88b commit 2da68e8
Show file tree
Hide file tree
Showing 6 changed files with 883 additions and 776 deletions.
7 changes: 2 additions & 5 deletions EvoEngine_Plugins/EcoSysLab/src/DynamicStrandsRender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,8 @@ void DynamicStrands::Render(const StepParameters::RenderParameters& render_param
scissor.extent.width = render_parameters.target_camera->GetSize().x;
scissor.extent.height = render_parameters.target_camera->GetSize().y;
#pragma endregion

std::vector<VkRenderingAttachmentInfo> color_attachment_infos;
render_parameters.target_camera->GetRenderTexture()->AppendColorAttachmentInfos(
color_attachment_infos, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE);
render_pipeline->states.ResetAllStates(color_attachment_infos.size());
//1 here means we only have 1 color attachment. (For deferred shading we will have multiple attachments for GBuffer)
render_pipeline->states.ResetAllStates(1);
render_pipeline->states.view_port = viewport;
render_pipeline->states.scissor = scissor;
render_pipeline->states.polygon_mode = VK_POLYGON_MODE_FILL;
Expand Down
46 changes: 23 additions & 23 deletions EvoEngine_Plugins/LogGrading/include/LogGrader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@ using namespace evo_engine;
using namespace eco_sys_lab_plugin;
namespace log_grading_plugin {
struct LogWoodMeshGenerationSettings {
float m_ySubdivision = 0.02f;
float m_y_subdivision = 0.02f;
};

class ProceduralLogParameters {
public:
bool m_bottom = true;
bool m_soundDefect = false;
float m_lengthWithoutTrimInFeet = 16.0f;
float m_lengthStepInInches = 1.f;
float m_largeEndDiameterInInches = 25.f;
float m_smallEndDiameterInInches = 20.f;
bool m_sound_defect = false;
float m_length_without_trim_in_feet = 16.0f;
float m_length_step_in_inches = 1.f;
float m_large_end_diameter_in_inches = 25.f;
float m_small_end_diameter_in_inches = 20.f;

unsigned m_mode = 0;
float m_spanInInches = 0.0f;
float m_span_in_inches = 0.0f;
float m_angle = 180.0f;
float m_crookRatio = 0.7f;
float m_crook_ratio = 0.7f;

bool OnInspect();
};
Expand All @@ -39,26 +39,26 @@ class LogGrader : public IPrivateComponent {
std::shared_ptr<Mesh> m_tempFlatMesh2{};
std::shared_ptr<Mesh> m_tempFlatMesh3{};
std::shared_ptr<Mesh> m_tempFlatMesh4{};
void RefreshMesh(const LogGrading& logGrading) const;
void RefreshMesh(const LogGrading& log_grading) const;

public:
int m_bestGradingIndex = 0;
std::vector<LogGrading> m_availableBestGrading{};
ProceduralLogParameters m_proceduralLogParameters;
AssetRef m_branchShape{};
bool OnInspect(const std::shared_ptr<EditorLayer>& editorLayer) override;
void InitializeLogRandomly(const ProceduralLogParameters& proceduralLogParameters,
const std::shared_ptr<BarkDescriptor>& branchShape);
LogWoodMeshGenerationSettings m_logWoodMeshGenerationSettings{};
LogWood m_logWood{};
int m_best_grading_index = 0;
std::vector<LogGrading> m_available_best_grading{};
ProceduralLogParameters m_procedural_log_parameters;
AssetRef m_branch_shape{};
bool OnInspect(const std::shared_ptr<EditorLayer>& editor_layer) override;
void InitializeLogRandomly(const ProceduralLogParameters& procedural_log_parameters,
const std::shared_ptr<BarkDescriptor>& branch_shape);
LogWoodMeshGenerationSettings m_log_wood_mesh_generation_settings{};
LogWood m_log_wood{};
void GenerateCylinderMesh(const std::shared_ptr<Mesh>& mesh,
const LogWoodMeshGenerationSettings& meshGeneratorSettings) const;
void GenerateFlatMesh(const std::shared_ptr<Mesh>& mesh, const LogWoodMeshGenerationSettings& meshGeneratorSettings,
int startX, int endX) const;
const LogWoodMeshGenerationSettings& mesh_generator_settings) const;
void GenerateFlatMesh(const std::shared_ptr<Mesh>& mesh, const LogWoodMeshGenerationSettings& mesh_generator_settings,
int start_x, int end_x) const;
void GenerateSurface(const std::shared_ptr<ParticleInfoList>& surface,
const LogWoodMeshGenerationSettings& meshGeneratorSettings, int startX, int endX) const;
const LogWoodMeshGenerationSettings& mesh_generator_settings, int start_x, int end_x) const;
void OnCreate() override;
void InitializeMeshRenderer(const LogWoodMeshGenerationSettings& meshGeneratorSettings) const;
void InitializeMeshRenderer(const LogWoodMeshGenerationSettings& mesh_generator_settings) const;
void ClearMeshRenderer() const;
};
} // namespace eco_sys_lab_plugin
153 changes: 99 additions & 54 deletions EvoEngine_Plugins/LogGrading/include/LogWood.hpp
Original file line number Diff line number Diff line change
@@ -1,53 +1,88 @@
#pragma once
using namespace evo_engine;
namespace log_grading_plugin {
struct Vec4 {
float v0 = 0;
float v1 = 0;
float v2 = 0;
float v3 = 0;
Vec4 Multiply(float other) const;

Vec4 Add(const Vec4& other) const;
};
struct Vec3 {
float v0 = 0;
float v1 = 0;
float v2 = 0;

Vec3 Add(const Vec3& other) const;

Vec3 Subtract(const Vec3& other) const;

Vec3 Div(float other) const;

Vec3 Multiply(float other) const;

float Distance(const Vec3& other) const;

float Dot(const Vec3& other) const;
};
struct Vec2 {
float v0 = 0;
float v1 = 0;

Vec2 Multiply(float rhs) const;

Vec2 Add(const Vec2& rhs) const;
};

struct LogWoodIntersectionBoundaryPoint {
float m_centerDistance = 0.0f;
float m_defectStatus = 0.0f;
glm::vec4 m_color = glm::vec4(1.0f);
float m_center_distance = 0.0f;
float m_defect_status = 0.0f;
Vec4 m_color = Vec4{1.0f, 1.0f, 1.0f, 1.0f};
};
class LogWoodIntersection {
public:
glm::vec2 m_center = glm::vec2(0.0f);
Vec2 m_center = Vec2{0.0f, 0.0f};
std::vector<LogWoodIntersectionBoundaryPoint> m_boundary{};
[[nodiscard]] float GetCenterDistance(float angle) const;
[[nodiscard]] glm::vec2 GetBoundaryPoint(float angle) const;
[[nodiscard]] float GetDefectStatus(float angle) const;
[[nodiscard]] glm::vec4 GetColor(float angle) const;
[[nodiscard]] float GetAverageDistance() const;
[[nodiscard]] float GetMaxDistance() const;
[[nodiscard]] float GetMinDistance() const;
float GetCenterDistance(float angle) const;
Vec2 GetBoundaryPoint(float angle) const;
float GetDefectStatus(float angle) const;
Vec4 GetColor(float angle) const;
float GetAverageDistance() const;
float GetMaxDistance() const;
float GetMinDistance() const;
};

struct LogGradeFaceCutting {
float m_startInMeters = 0;
float m_endInMeters = 0;
float m_start_in_meters = 0;
float m_end_in_meters = 0;
};

struct LogGradingFace {
int m_faceIndex = 0;
int m_startAngle = 0;
int m_endAngle = 0;
int m_faceGrade = 0;
std::vector<LogGradeFaceCutting> m_clearCuttings{};
float m_clearCuttingMinLengthInMeters = 0;
float m_clearCuttingMinProportion = 0;
int m_face_index = 0;
int m_start_angle = 0;
int m_end_angle = 0;
int m_face_grade = 0;
std::vector<LogGradeFaceCutting> m_clear_cuttings{};
float m_clear_cutting_min_length_in_meters = 0;
float m_clear_cutting_min_proportion = 0;
};

struct LogGrading {
float m_doyleRuleScale = 0.0f;
float m_scribnerRuleScale = 0.0f;
float m_internationalRuleScale = 0.0f;

float m_crookDeduction = 0.0f;
float m_sweepDeduction = 0.0f;
int m_angleOffset = 0;
float m_lengthWithoutTrimInMeters = 0.0f;
float m_scalingDiameterInMeters = 0;
int m_gradeDetermineFaceIndex = 0;
float m_doyle_rule_scale = 0.0f;
float m_scribner_rule_scale = 0.0f;
float m_international_rule_scale = 0.0f;

float m_crook_deduction = 0.0f;
float m_sweep_deduction = 0.0f;
int m_angle_offset = 0;
float m_length_without_trim_in_meters = 0.0f;
float m_scaling_diameter_in_meters = 0;
int m_grade_determine_face_index = 0;
int m_grade = 0;
int m_startIntersectionIndex = 0;
float m_startHeightInMeters = 0.0f;
int m_start_intersection_index = 0;
float m_start_height_in_meters = 0.0f;
LogGradingFace m_faces[4]{};
};

Expand All @@ -57,33 +92,43 @@ class LogWood {
static float FeetToMeter(float feet);
static float MetersToInches(float meters);
static float MetersToFeet(float meters);
static Vec3 ClosestPointOnLine(const Vec3& point, const Vec3& a, const Vec3& b) {
const float line_length = a.Distance(b);
const Vec3 vector = point.Subtract(a);
const Vec3 line_direction = b.Subtract(a).Div(line_length);

// Project Vector to LineDirection to get the distance of point from a
const float distance = vector.Dot(line_direction);
return a.Add(line_direction.Multiply(distance));
}

bool m_butt = true;
float m_length = 0.0f;
float m_sweepInInches = 0.0f;
float m_crookCInInches = 0.0f;
float m_crookCLInFeet = 0.0f;
bool m_soundDefect = false;
float m_sweep_in_inches = 0.0f;
float m_crook_cl_in_inches = 0.0f;
float m_crook_cl_in_feet = 0.0f;
bool m_sound_defect = false;
std::vector<LogWoodIntersection> m_intersections;
[[nodiscard]] glm::vec2 GetSurfacePoint(float height, float angle) const;
[[nodiscard]] float GetCenterDistance(float height, float angle) const;
[[nodiscard]] float GetDefectStatus(float height, float angle) const;
[[nodiscard]] glm::vec4 GetColor(float height, float angle) const;
Vec2 GetSurfacePoint(float height, float angle) const;
float GetCenterDistance(float height, float angle) const;
float GetDefectStatus(float height, float angle) const;
Vec4 GetColor(float height, float angle) const;

[[nodiscard]] LogWoodIntersectionBoundaryPoint& GetBoundaryPoint(float height, float angle);
LogWoodIntersectionBoundaryPoint& GetBoundaryPoint(float height, float angle);
void Rotate(int degrees);
[[nodiscard]] float GetAverageDistance(float height) const;
[[nodiscard]] float GetAverageDistance() const;
[[nodiscard]] float GetMaxAverageDistance() const;
[[nodiscard]] float GetMinAverageDistance() const;
[[nodiscard]] float GetMaxDistance() const;
[[nodiscard]] float GetMinDistance() const;
void MarkDefectRegion(float height, float angle, float heightRange, float angleRange);
void EraseDefectRegion(float height, float angle, float heightRange, float angleRange);
float GetAverageDistance(float height) const;
float GetAverageDistance() const;
float GetMaxAverageDistance() const;
float GetMinAverageDistance() const;
float GetMaxDistance() const;
float GetMinDistance() const;
void MarkDefectRegion(float height, float angle, float height_range, float angle_range);
void EraseDefectRegion(float height, float angle, float height_range, float angle_range);
void ClearDefects();
[[nodiscard]] bool RayCastSelection(const glm::mat4& transform, float pointDistanceThreshold, const Ray& ray,
float& height, float& angle) const;
bool RayCastSelection(const glm::mat4& transform, float point_distance_threshold, const Ray& ray, float& height,
float& angle) const;

void CalculateGradingData(std::vector<LogGrading>& logGrading) const;
void ColorBasedOnGrading(const LogGrading& logGradingData);
void CalculateGradingData(std::vector<LogGrading>& log_grading) const;
void ColorBasedOnGrading(const LogGrading& log_grading_data);
};
} // namespace eco_sys_lab_plugin
} // namespace log_grading_plugin
Loading

0 comments on commit 2da68e8

Please sign in to comment.