Working on meshes

This commit is contained in:
Yousef Khadadeh 2026-05-23 18:27:45 +03:00
parent c479ccb9e2
commit 7b472fe18d
652 changed files with 81120 additions and 852 deletions

View file

@ -21,7 +21,6 @@
#include "../../MainProgram.hpp"
#include "../../DrawData.hpp"
#include "DrawingProgramToolBase.hpp"
#include "../../CanvasComponents/BrushStrokeCanvasComponent.hpp"
#include "../../CanvasComponents/CanvasComponentContainer.hpp"
#include "Helpers/MathExtras.hpp"
@ -63,26 +62,26 @@ void LineDrawTool::input_mouse_button_on_canvas_callback(const InputManager::Mou
if(button.button == InputManager::MouseButton::LEFT) {
auto& toolConfig = drawP.world.main.toolConfig;
if(button.down && drawP.layerMan.is_a_layer_being_edited() && !objInfoBeingEdited && !drawP.world.main.g.gui.cursor_obstructed()) {
auto relativeWidthResult = drawP.world.main.toolConfig.get_relative_width_stroke_size(drawP, drawP.world.drawData.cam.c.inverseScale);
if(!relativeWidthResult.first.has_value()) {
drawP.world.main.toolConfig.print_relative_width_fail_message(relativeWidthResult.second);
return;
}
float width = relativeWidthResult.first.value();
//auto relativeWidthResult = drawP.world.main.toolConfig.get_relative_width_stroke_size(drawP, drawP.world.drawData.cam.c.inverseScale);
//if(!relativeWidthResult.first.has_value()) {
// drawP.world.main.toolConfig.print_relative_width_fail_message(relativeWidthResult.second);
// return;
//}
//float width = relativeWidthResult.first.value();
CanvasComponentContainer* newBrushStrokeContainer = new CanvasComponentContainer(drawP.world.netObjMan, CanvasComponentType::BRUSHSTROKE);
BrushStrokeCanvasComponent& newBrushStroke = static_cast<BrushStrokeCanvasComponent&>(newBrushStrokeContainer->get_comp());
//CanvasComponentContainer* newBrushStrokeContainer = new CanvasComponentContainer(drawP.world.netObjMan, CanvasComponentType::BRUSHSTROKE);
//BrushStrokeCanvasComponent& newBrushStroke = static_cast<BrushStrokeCanvasComponent&>(newBrushStrokeContainer->get_comp());
BrushStrokeCanvasComponentPoint p;
p.pos = drawP.world.main.input.mouse.pos;
p.width = width;
newBrushStroke.d.points->emplace_back(p);
p.pos = ensure_points_have_distance(p.pos, p.pos, 1.0f);
newBrushStroke.d.points->emplace_back(p);
newBrushStroke.d.color = toolConfig.globalConf.foregroundColor;
newBrushStroke.d.hasRoundCaps = toolConfig.lineDraw.hasRoundCaps;
newBrushStrokeContainer->coords = drawP.world.drawData.cam.c;
objInfoBeingEdited = drawP.layerMan.add_component_to_layer_being_edited(newBrushStrokeContainer);
//BrushStrokeCanvasComponentPoint p;
//p.pos = drawP.world.main.input.mouse.pos;
//p.width = width;
//newBrushStroke.d.points->emplace_back(p);
//p.pos = ensure_points_have_distance(p.pos, p.pos, 1.0f);
//newBrushStroke.d.points->emplace_back(p);
//newBrushStroke.d.color = toolConfig.globalConf.foregroundColor;
//newBrushStroke.d.hasRoundCaps = toolConfig.lineDraw.hasRoundCaps;
//newBrushStrokeContainer->coords = drawP.world.drawData.cam.c;
//objInfoBeingEdited = drawP.layerMan.add_component_to_layer_being_edited(newBrushStrokeContainer);
}
else if(!button.down && objInfoBeingEdited)
commit();
@ -91,22 +90,22 @@ void LineDrawTool::input_mouse_button_on_canvas_callback(const InputManager::Mou
void LineDrawTool::input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion) {
if(objInfoBeingEdited) {
constexpr float SNAP_DIVISION_COUNT = 12.0f;
NetworkingObjects::NetObjOwnerPtr<CanvasComponentContainer>& containerPtr = objInfoBeingEdited->obj;
BrushStrokeCanvasComponent& brushStroke = static_cast<BrushStrokeCanvasComponent&>(containerPtr->get_comp());
Vector2f newPos = containerPtr->coords.from_cam_space_to_this(drawP.world, motion.pos);
Vector2f oldPos = brushStroke.d.points->front().pos;
if(drawP.world.main.input.key(InputManager::KEY_GENERIC_LSHIFT).held) {
Vector2f diff = (newPos - oldPos);
float diffLength = diff.norm();
diff.normalize();
float angle = (std::atan2(diff.y(), diff.x()) / std::numbers::pi) * SNAP_DIVISION_COUNT;
angle = std::round(angle);
angle = (angle * std::numbers::pi) / SNAP_DIVISION_COUNT;
newPos = oldPos + diffLength * Vector2f{cos(angle), sin(angle)};
}
brushStroke.d.points->back().pos = ensure_points_have_distance(oldPos, newPos, 1.0f);
commitUpdate = true;
//constexpr float SNAP_DIVISION_COUNT = 12.0f;
//NetworkingObjects::NetObjOwnerPtr<CanvasComponentContainer>& containerPtr = objInfoBeingEdited->obj;
//BrushStrokeCanvasComponent& brushStroke = static_cast<BrushStrokeCanvasComponent&>(containerPtr->get_comp());
//Vector2f newPos = containerPtr->coords.from_cam_space_to_this(drawP.world, motion.pos);
//Vector2f oldPos = brushStroke.d.points->front().pos;
//if(drawP.world.main.input.key(InputManager::KEY_GENERIC_LSHIFT).held) {
// Vector2f diff = (newPos - oldPos);
// float diffLength = diff.norm();
// diff.normalize();
// float angle = (std::atan2(diff.y(), diff.x()) / std::numbers::pi) * SNAP_DIVISION_COUNT;
// angle = std::round(angle);
// angle = (angle * std::numbers::pi) / SNAP_DIVISION_COUNT;
// newPos = oldPos + diffLength * Vector2f{cos(angle), sin(angle)};
//}
//brushStroke.d.points->back().pos = ensure_points_have_distance(oldPos, newPos, 1.0f);
//commitUpdate = true;
}
}