mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-07-17 23:39:18 +02:00
3-axis rotation, and some corrections in editor mode
This commit is contained in:
@@ -659,8 +659,9 @@ TAnimModel::export_as_text_( std::ostream &Output ) const {
|
|||||||
Output
|
Output
|
||||||
<< location().x << ' '
|
<< location().x << ' '
|
||||||
<< location().y << ' '
|
<< location().y << ' '
|
||||||
<< location().z << ' '
|
<< location().z << ' ';
|
||||||
<< vAngle.y << ' ';
|
Output
|
||||||
|
<< "0 " ;
|
||||||
// 3d shape
|
// 3d shape
|
||||||
auto modelfile { (
|
auto modelfile { (
|
||||||
pModel ?
|
pModel ?
|
||||||
@@ -698,6 +699,11 @@ TAnimModel::export_as_text_( std::ostream &Output ) const {
|
|||||||
Output << "notransition" << ' ';
|
Output << "notransition" << ' ';
|
||||||
}
|
}
|
||||||
// footer
|
// footer
|
||||||
|
Output << "angles "
|
||||||
|
<< vAngle.x << ' '
|
||||||
|
<< vAngle.y << ' '
|
||||||
|
<< vAngle.z << ' ';
|
||||||
|
// footer
|
||||||
Output
|
Output
|
||||||
<< "endmodel"
|
<< "endmodel"
|
||||||
<< "\n";
|
<< "\n";
|
||||||
|
|||||||
100
editormode.cpp
100
editormode.cpp
@@ -246,16 +246,34 @@ editor_mode::on_cursor_pos( double const Horizontal, double const Vertical ) {
|
|||||||
m_editor.translate( m_node, mouseworldposition, mode_snap() );
|
m_editor.translate( m_node, mouseworldposition, mode_snap() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else if (mode_rotationY())
|
||||||
// rotate selected node
|
{
|
||||||
auto const rotation { glm::vec3 { mousemove.y, mousemove.x, 0 } * 0.25f };
|
// rotate selected node
|
||||||
auto const quantization { (
|
// auto const rotation{glm::vec3{mousemove.y, mousemove.x, 0} * 0.25f};
|
||||||
mode_snap() ?
|
auto const rotation{glm::vec3{0, mousemove.x, 0} * 0.25f};
|
||||||
15.f : // TODO: put quantization value in a variable
|
auto const quantization{(mode_snap() ? 5.f : // TODO: put quantization value in a variable
|
||||||
0.f ) };
|
0.f)};
|
||||||
m_editor.rotate( m_node, rotation, quantization );
|
m_editor.rotate(m_node, rotation, quantization);
|
||||||
}
|
}
|
||||||
|
else if (mode_rotationZ())
|
||||||
|
{
|
||||||
|
// rotate selected node
|
||||||
|
|
||||||
|
// auto const rotation{glm::vec3{mousemove.y, mousemove.x, 0} * 0.25f};
|
||||||
|
auto const rotation{glm::vec3{0, 0, mousemove.x} * 0.25f};
|
||||||
|
auto const quantization{(mode_snap() ? 5.f : // TODO: put quantization value in a variable
|
||||||
|
0.f)};
|
||||||
|
m_editor.rotate(m_node, rotation, quantization);
|
||||||
|
}
|
||||||
|
else if (mode_rotationX())
|
||||||
|
{
|
||||||
|
// rotate selected node
|
||||||
|
// auto const rotation{glm::vec3{mousemove.y, mousemove.x, 0} * 0.25f};
|
||||||
|
auto const rotation{glm::vec3{mousemove.y, 0, 0} * 0.25f};
|
||||||
|
auto const quantization{(mode_snap() ? 5.f : // TODO: put quantization value in a variable
|
||||||
|
0.f)};
|
||||||
|
m_editor.rotate(m_node, rotation, quantization);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -303,9 +321,8 @@ editor_mode::on_mouse_button( int const Button, int const Action, int const Mods
|
|||||||
|
|
||||||
m_node = nullptr;
|
m_node = nullptr;
|
||||||
|
|
||||||
GfxRenderer->Pick_Node_Callback([this, mode](scene::basic_node *node)
|
GfxRenderer->Pick_Node_Callback([this, mode,Action,Button](scene::basic_node *node) {
|
||||||
{
|
editor_ui *ui = static_cast<editor_ui *>(m_userinterface.get());
|
||||||
editor_ui *ui = static_cast<editor_ui*>( m_userinterface.get() );
|
|
||||||
|
|
||||||
if (mode == nodebank_panel::MODIFY) {
|
if (mode == nodebank_panel::MODIFY) {
|
||||||
if (!m_dragging)
|
if (!m_dragging)
|
||||||
@@ -316,7 +333,7 @@ editor_mode::on_mouse_button( int const Button, int const Action, int const Mods
|
|||||||
Application.set_cursor( GLFW_CURSOR_DISABLED );
|
Application.set_cursor( GLFW_CURSOR_DISABLED );
|
||||||
else
|
else
|
||||||
m_dragging = false;
|
m_dragging = false;
|
||||||
ui->set_node( m_node );
|
ui->set_node(m_node);
|
||||||
}
|
}
|
||||||
else if (mode == nodebank_panel::COPY) {
|
else if (mode == nodebank_panel::COPY) {
|
||||||
if (node && typeid(*node) == typeid(TAnimModel)) {
|
if (node && typeid(*node) == typeid(TAnimModel)) {
|
||||||
@@ -360,6 +377,45 @@ editor_mode::on_mouse_button( int const Button, int const Action, int const Mods
|
|||||||
m_takesnapshot = true;
|
m_takesnapshot = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (Button == GLFW_MOUSE_BUTTON_RIGHT)
|
||||||
|
{
|
||||||
|
|
||||||
|
/*if (Action == GLFW_PRESS)
|
||||||
|
{
|
||||||
|
// left button press
|
||||||
|
auto const mode = static_cast<editor_ui *>(m_userinterface.get())->mode();
|
||||||
|
|
||||||
|
m_node = nullptr;
|
||||||
|
|
||||||
|
GfxRenderer->Pick_Node_Callback([this, mode](scene::basic_node *node) {
|
||||||
|
editor_ui *ui = static_cast<editor_ui *>(m_userinterface.get());
|
||||||
|
|
||||||
|
if (mode == nodebank_panel::MODIFY)
|
||||||
|
{
|
||||||
|
if (!m_dragging)
|
||||||
|
return;
|
||||||
|
|
||||||
|
m_node = node;
|
||||||
|
if (m_node)
|
||||||
|
Application.set_cursor(GLFW_CURSOR_DISABLED);
|
||||||
|
else
|
||||||
|
m_dragging = false;
|
||||||
|
ui->set_node(m_node);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
m_dragging = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// left button release
|
||||||
|
if (m_node)
|
||||||
|
Application.set_cursor(GLFW_CURSOR_NORMAL);
|
||||||
|
m_dragging = false;
|
||||||
|
// prime history stack for another snapshot
|
||||||
|
m_takesnapshot = true;
|
||||||
|
}*/
|
||||||
|
}
|
||||||
|
|
||||||
m_input.mouse.button( Button, Action );
|
m_input.mouse.button( Button, Action );
|
||||||
}
|
}
|
||||||
@@ -388,14 +444,24 @@ editor_mode::mode_translation_vertical() const {
|
|||||||
return ( true == Global.shiftState );
|
return ( true == Global.shiftState );
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool editor_mode::mode_rotationY() const
|
||||||
editor_mode::mode_rotation() const {
|
{
|
||||||
|
|
||||||
return ( true == Global.altState );
|
return ((true == Global.altState) && (false == Global.ctrlState) && (false == Global.shiftState));
|
||||||
|
}
|
||||||
|
bool editor_mode::mode_rotationX() const
|
||||||
|
{
|
||||||
|
|
||||||
|
return ((true == Global.altState) && (true == Global.ctrlState) && (false == Global.shiftState));
|
||||||
|
}
|
||||||
|
bool editor_mode::mode_rotationZ() const
|
||||||
|
{
|
||||||
|
|
||||||
|
return ((true == Global.altState) && (true == Global.ctrlState) && (true == Global.shiftState));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
editor_mode::mode_snap() const {
|
editor_mode::mode_snap() const {
|
||||||
|
|
||||||
return ( true == Global.ctrlState );
|
return ((false == Global.altState) && (true == Global.ctrlState) && (false == Global.shiftState));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -73,7 +73,11 @@ private:
|
|||||||
bool
|
bool
|
||||||
mode_translation_vertical() const;
|
mode_translation_vertical() const;
|
||||||
bool
|
bool
|
||||||
mode_rotation() const;
|
mode_rotationY() const;
|
||||||
|
bool
|
||||||
|
mode_rotationX() const;
|
||||||
|
bool
|
||||||
|
mode_rotationZ() const;
|
||||||
bool
|
bool
|
||||||
mode_snap() const;
|
mode_snap() const;
|
||||||
// members
|
// members
|
||||||
|
|||||||
@@ -68,8 +68,10 @@ itemproperties_panel::update( scene::basic_node const *Node ) {
|
|||||||
|
|
||||||
auto const *subnode = static_cast<TAnimModel const *>( node );
|
auto const *subnode = static_cast<TAnimModel const *>( node );
|
||||||
|
|
||||||
textline = "angle: " + to_string( clamp_circular( subnode->vAngle.y, 360.f ), 2 ) + " deg";
|
textline = "angle_x: " + to_string(clamp_circular(subnode->vAngle.x, 360.f), 2) + " deg, " +
|
||||||
textline += "; lights: ";
|
"angle_y: " + to_string(clamp_circular(subnode->vAngle.y, 360.f), 2) + " deg, " +
|
||||||
|
"angle_z: " + to_string(clamp_circular(subnode->vAngle.z, 360.f), 2) + " deg";
|
||||||
|
textline += ";\nlights: ";
|
||||||
if( subnode->iNumLights > 0 ) {
|
if( subnode->iNumLights > 0 ) {
|
||||||
textline += '[';
|
textline += '[';
|
||||||
for( int lightidx = 0; lightidx < subnode->iNumLights; ++lightidx ) {
|
for( int lightidx = 0; lightidx < subnode->iNumLights; ++lightidx ) {
|
||||||
@@ -150,7 +152,7 @@ itemproperties_panel::update( scene::basic_node const *Node ) {
|
|||||||
+ to_string( path.points[ segment_data::point::start ].x, 3 ) + ", "
|
+ to_string( path.points[ segment_data::point::start ].x, 3 ) + ", "
|
||||||
+ to_string( path.points[ segment_data::point::start ].y, 3 ) + ", "
|
+ to_string( path.points[ segment_data::point::start ].y, 3 ) + ", "
|
||||||
+ to_string( path.points[ segment_data::point::start ].z, 3 ) + "]->"
|
+ to_string( path.points[ segment_data::point::start ].z, 3 ) + "]->"
|
||||||
+ "["
|
+ " ["
|
||||||
+ to_string( path.points[ segment_data::point::end ].x, 3 ) + ", "
|
+ to_string( path.points[ segment_data::point::end ].x, 3 ) + ", "
|
||||||
+ to_string( path.points[ segment_data::point::end ].y, 3 ) + ", "
|
+ to_string( path.points[ segment_data::point::end ].y, 3 ) + ", "
|
||||||
+ to_string( path.points[ segment_data::point::end ].z, 3 ) + "] ";
|
+ to_string( path.points[ segment_data::point::end ].z, 3 ) + "] ";
|
||||||
@@ -353,6 +355,42 @@ nodebank_panel::nodebank_panel( std::string const &Name, bool const Isopen ) : u
|
|||||||
return ( Left.first < Right.first ); } );
|
return ( Left.first < Right.first ); } );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
void
|
||||||
|
nodebank_panel::nodebank_reload(){
|
||||||
|
m_nodebank.clear();
|
||||||
|
std::ifstream file;
|
||||||
|
file.open("nodebank.txt", std::ios_base::in | std::ios_base::binary);
|
||||||
|
std::string line;
|
||||||
|
while (std::getline(file, line))
|
||||||
|
{
|
||||||
|
if (line.size() < 4)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
auto const labelend{line.find("node")};
|
||||||
|
auto const nodedata{
|
||||||
|
(labelend == std::string::npos ? "" : labelend == 0 ? line : line.substr(labelend))};
|
||||||
|
auto const label{
|
||||||
|
(labelend == std::string::npos ?
|
||||||
|
line :
|
||||||
|
labelend == 0 ? generate_node_label(nodedata) : line.substr(0, labelend))};
|
||||||
|
|
||||||
|
m_nodebank.push_back({label, std::make_shared<std::string>(nodedata)});
|
||||||
|
}
|
||||||
|
// sort alphabetically content of each group
|
||||||
|
auto groupbegin{m_nodebank.begin()};
|
||||||
|
auto groupend{groupbegin};
|
||||||
|
while (groupbegin != m_nodebank.end())
|
||||||
|
{
|
||||||
|
groupbegin = std::find_if(groupend, m_nodebank.end(), [](auto const &Entry) {
|
||||||
|
return (false == Entry.second->empty());
|
||||||
|
});
|
||||||
|
groupend = std::find_if(groupbegin, m_nodebank.end(),
|
||||||
|
[](auto const &Entry) { return (Entry.second->empty()); });
|
||||||
|
std::sort(groupbegin, groupend,
|
||||||
|
[](auto const &Left, auto const &Right) { return (Left.first < Right.first); });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
nodebank_panel::render() {
|
nodebank_panel::render() {
|
||||||
@@ -378,11 +416,19 @@ nodebank_panel::render() {
|
|||||||
|
|
||||||
if( true == ImGui::Begin( panelname.c_str(), nullptr, flags ) ) {
|
if( true == ImGui::Begin( panelname.c_str(), nullptr, flags ) ) {
|
||||||
|
|
||||||
ImGui::RadioButton("modify node", (int*)&mode, MODIFY);
|
ImGui::RadioButton("Modify node", (int*)&mode, MODIFY);
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
ImGui::RadioButton("insert from bank", (int*)&mode, ADD);
|
ImGui::RadioButton("Insert from bank", (int*)&mode, ADD);
|
||||||
|
ImGui::SameLine();
|
||||||
|
ImGui::RadioButton("Brush", (int*)&mode, BRUSH);
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
ImGui::RadioButton( "copy to bank", (int*)&mode, COPY );
|
ImGui::RadioButton( "Copy to bank", (int*)&mode, COPY );
|
||||||
|
ImGui::SameLine();
|
||||||
|
if (ImGui::Button("Reload Nodebank"))
|
||||||
|
{
|
||||||
|
nodebank_reload();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
ImGui::PushItemWidth(-1);
|
ImGui::PushItemWidth(-1);
|
||||||
ImGui::InputTextWithHint( "Search", "Search node bank", m_nodesearch, IM_ARRAYSIZE( m_nodesearch ) );
|
ImGui::InputTextWithHint( "Search", "Search node bank", m_nodesearch, IM_ARRAYSIZE( m_nodesearch ) );
|
||||||
|
|||||||
@@ -54,13 +54,13 @@ public:
|
|||||||
enum edit_mode {
|
enum edit_mode {
|
||||||
MODIFY,
|
MODIFY,
|
||||||
COPY,
|
COPY,
|
||||||
ADD
|
ADD,
|
||||||
|
BRUSH
|
||||||
};
|
};
|
||||||
|
|
||||||
edit_mode mode = MODIFY;
|
edit_mode mode = MODIFY;
|
||||||
|
|
||||||
nodebank_panel( std::string const &Name, bool const Isopen );
|
nodebank_panel( std::string const &Name, bool const Isopen );
|
||||||
|
void nodebank_reload();
|
||||||
void render() override;
|
void render() override;
|
||||||
void add_template(const std::string &desc);
|
void add_template(const std::string &desc);
|
||||||
const std::string* get_active_template();
|
const std::string* get_active_template();
|
||||||
|
|||||||
@@ -137,7 +137,7 @@ basic_editor::translate_memorycell( TMemCell *Memorycell, float const Offset ) {
|
|||||||
void
|
void
|
||||||
basic_editor::rotate( scene::basic_node *Node, glm::vec3 const &Angle, float const Quantization ) {
|
basic_editor::rotate( scene::basic_node *Node, glm::vec3 const &Angle, float const Quantization ) {
|
||||||
|
|
||||||
glm::vec3 rotation { 0, Angle.y, 0 };
|
glm::vec3 rotation{Angle.x, Angle.y, Angle.z};
|
||||||
|
|
||||||
// quantize resulting angle if requested and type of the node allows it
|
// quantize resulting angle if requested and type of the node allows it
|
||||||
// TBD, TODO: angle quantization for types other than instanced models
|
// TBD, TODO: angle quantization for types other than instanced models
|
||||||
|
|||||||
Reference in New Issue
Block a user