Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add spring primitive #53

Merged
merged 2 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ if(BUILD_TESTS)
include(FetchContent)
FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/b796f7d44681514f58a683a3a71ff17c94edb0c1.zip
URL https://github.com/google/googletest/archive/f8d7d77c06936315286eb55f8de22cd23c188571.zip
)
# For Windows: Prevent overriding the parent project's compiler/linker settings
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
Expand Down
1 change: 1 addition & 0 deletions resources/resource.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@
<file>capsule.png</file>
<file>roundedbox.png</file>
<file>addVertice.png</file>
<file>spring.png</file>
</qresource>
</RCC>
Binary file added resources/spring.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
47 changes: 18 additions & 29 deletions src/PrimitiveObject.cpp
Original file line number Diff line number Diff line change
@@ -1,30 +1,3 @@
/*/////////////////////////////////////////////////////////////////////////////////
/// A QtMeshEditor file
///
/// Copyright (c) HogPog Team (www.hogpog.com.br)
///
/// The MIT License
///
/// Permission is hereby granted, free of charge, to any person obtaining a copy
/// of this software and associated documentation files (the "Software"), to deal
/// in the Software without restriction, including without limitation the rights
/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
/// copies of the Software, and to permit persons to whom the Software is
/// furnished to do so, subject to the following conditions:
///
/// The above copyright notice and this permission notice shall be included in
/// all copies or substantial portions of the Software.
///
/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
/// THE SOFTWARE.
////////////////////////////////////////////////////////////////////////////////*/


#include <QString>

#include <OgreAny.h>
Expand All @@ -43,10 +16,9 @@
#include "ProceduralIcoSphereGenerator.h"
#include "ProceduralCapsuleGenerator.h"
#include "ProceduralRoundedBoxGenerator.h"
#include "ProceduralSpringGenerator.h"


// TODO add spring primitive

// TODO play with numTextureCoord (require to change the UI)

// TODO fix the bug in the num of segment for rounded box
Expand Down Expand Up @@ -141,7 +113,14 @@ void PrimitiveObject::setDefaultParams()
mNumSegX = 1; mNumSegY = 1; mNumSegZ = 1;
mUTile = 1.0f; mVTile = 1.0f; mSwitchUV = false;
break;
case AP_SPRING:
mSizeX = 0.0f; mSizeY = 0.0f; mSizeZ = 0.0f;
mRadius = 0.0f; mRadius2 = 0.0f; mHeight = 0.0f;
mNumSegX = 10; mNumSegY = 10; mNumSegZ = 0;
mUTile = 1.0f; mVTile = 1.0f; mSwitchUV = false;
break;
case AP_NONE:
default:
break;
}
}
Expand Down Expand Up @@ -232,6 +211,11 @@ Ogre::SceneNode* PrimitiveObject::createRoundedBox(const QString& name)
PrimitiveObject* newPrimitive = new PrimitiveObject(name, AP_ROUNDEDBOX);
return newPrimitive->createPrimitive();
}
Ogre::SceneNode* PrimitiveObject::createSpring(const QString& name)
{
PrimitiveObject* newPrimitive = new PrimitiveObject(name, AP_SPRING);
return newPrimitive->createPrimitive();
}

////////////////////////////////////////
/// Accessors
Expand Down Expand Up @@ -613,6 +597,11 @@ Ogre::MeshPtr PrimitiveObject::createMesh()
.setUTile(mUTile).setVTile(mVTile).setSwitchUV(mSwitchUV)
.realizeMesh(name.data());
break;
case AP_SPRING:
mp = Procedural::SpringGenerator().setNumSegCircle(mNumSegX).setNumSegPath(mNumSegY)
.setUTile(mUTile).setVTile(mVTile).setSwitchUV(mSwitchUV)
.realizeMesh(name.data());
break;
default:
mp.reset();
break;
Expand Down
30 changes: 3 additions & 27 deletions src/PrimitiveObject.h
Original file line number Diff line number Diff line change
@@ -1,29 +1,3 @@
/*/////////////////////////////////////////////////////////////////////////////////
/// A QtMeshEditor file
///
/// Copyright (c) HogPog Team (www.hogpog.com.br)
///
/// The MIT License
///
/// Permission is hereby granted, free of charge, to any person obtaining a copy
/// of this software and associated documentation files (the "Software"), to deal
/// in the Software without restriction, including without limitation the rights
/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
/// copies of the Software, and to permit persons to whom the Software is
/// furnished to do so, subject to the following conditions:
///
/// The above copyright notice and this permission notice shall be included in
/// all copies or substantial portions of the Software.
///
/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
/// THE SOFTWARE.
////////////////////////////////////////////////////////////////////////////////*/

#ifndef PRIMITIVES_OBJECT_H
#define PRIMITIVES_OBJECT_H

Expand Down Expand Up @@ -59,7 +33,8 @@ class PrimitiveObject
AP_TUBE,
AP_CAPSULE,
AP_ICOSPHERE,
AP_ROUNDEDBOX
AP_ROUNDEDBOX,
AP_SPRING
};

PrimitiveObject(const QString& name);
Expand All @@ -83,6 +58,7 @@ class PrimitiveObject
static Ogre::SceneNode* createCapsule(const QString& name);
static Ogre::SceneNode* createIcoSphere(const QString& name);
static Ogre::SceneNode* createRoundedBox(const QString& name);
static Ogre::SceneNode* createSpring(const QString& name);

const QString& getName() const;
Ogre::SceneNode* getSceneNode() const;
Expand Down
35 changes: 33 additions & 2 deletions src/PrimitivesWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@

#include "mainwindow.h"

// TODO add spring primitive

// TODO play with numTextureCoord (require to change the UI)

// TODO fix the bug in the num of segment for rounded box
Expand Down Expand Up @@ -490,6 +488,22 @@ void PrimitivesWidget::setUiRoundedBox()

}

void PrimitivesWidget::setUiSpring()
{
edit_type->setText(tr("Spring"));

gb_Mesh->show();

label_numSegX->show();
label_numSegY->show();

edit_numSegX->show();
edit_numSegY->show();

label_numSegX->setText(tr("Circle Segments"));
label_numSegY->setText(tr("Path Segments"));
}

void PrimitivesWidget::updateUiFromParams()
{
blockEditSignals(true);
Expand Down Expand Up @@ -661,6 +675,9 @@ void PrimitivesWidget::onSelectionChanged()
case PrimitiveObject::AP_ROUNDEDBOX:
updateUiFromParams();setUiRoundedBox();
break;
case PrimitiveObject::AP_SPRING:
updateUiFromParams();setUiSpring();
break;
default:
setUiMesh();
break;
Expand Down Expand Up @@ -939,5 +956,19 @@ void PrimitivesWidget::createRoundedBox()
PrimitiveObject::createRoundedBox(name);
//createPrimitive(PrimitiveObject::AP_ROUNDEDBOX, name);
}
void PrimitivesWidget::createSpring()
{
bool ok;
QString name = QInputDialog::getText(Manager::getSingleton()->getMainWindow(), tr("New Spring"),
tr("Spring name:"), QLineEdit::Normal,
"", &ok);
name=(ok&&name.size())?name:tr("Spring");

if(!ok)
return;

PrimitiveObject::createSpring(name);
//createPrimitive(PrimitiveObject::AP_SPRING, name);
}


2 changes: 2 additions & 0 deletions src/PrimitivesWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public slots:
void createCapsule();
void createIcoSphere();
void createRoundedBox();
void createSpring();

protected:
void setUiEmpty();
Expand All @@ -42,6 +43,7 @@ public slots:
void setUiCapsule();
void setUiIcoSphere();
void setUiRoundedBox();
void setUiSpring();
void createPrimitive(PrimitiveObject::PrimitiveType newPrimitive, const QString& name);
PrimitiveObject::PrimitiveType getSelectedPrimitive();
void blockEditSignals(bool block);
Expand Down
13 changes: 13 additions & 0 deletions src/PrimitivesWidget_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class PrimitivesWidgetTest : public ::testing::Test
delete app;
}

private:
QApplication* app;
};

Expand Down Expand Up @@ -147,6 +148,18 @@ TEST_F(PrimitivesWidgetTest, CreateRoundedBox)
ASSERT_EQ(primitiveType, "Rounded Box");
}

TEST_F(PrimitivesWidgetTest, CreateSpring)
{
PrimitivesWidget widget;
QLineEdit* primitiveTypeLineEdit = widget.findChild<QLineEdit*>("edit_type");
ASSERT_TRUE(primitiveTypeLineEdit != nullptr);

PrimitiveObject::createSpring("Spring");

QString primitiveType = primitiveTypeLineEdit->text();
ASSERT_EQ(primitiveType, "Spring");
}

TEST_F(PrimitivesWidgetTest, UpdateUiFromParams)
{
PrimitivesWidget widget;
Expand Down
3 changes: 3 additions & 0 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ void MainWindow::initToolBar()
QAction* pAddCapsule = new QAction(QIcon(":/icones/capsule.png"),tr("Capsule"), addPrimitiveButton);
QAction* pAddIcoSphere = new QAction(QIcon(":/icones/sphere.png"),tr("IcoSphere"), addPrimitiveButton);
QAction* pAddRoundedBox = new QAction(QIcon(":/icones/roundedbox.png"),tr("Rounded Box"), addPrimitiveButton);
QAction* pAddSpring = new QAction(QIcon(":/icones/spring.png"),tr("Spring"), addPrimitiveButton);

addPrimitiveMenu->addAction(pAddCube);
addPrimitiveMenu->addAction(pAddSphere);
Expand All @@ -215,6 +216,7 @@ void MainWindow::initToolBar()
addPrimitiveMenu->addAction(pAddCapsule);
addPrimitiveMenu->addAction(pAddIcoSphere);
addPrimitiveMenu->addAction(pAddRoundedBox);
addPrimitiveMenu->addAction(pAddSpring);

addPrimitiveButton->setMenu(addPrimitiveMenu);
ui->objectsToolbar->addWidget(addPrimitiveButton);
Expand All @@ -229,6 +231,7 @@ void MainWindow::initToolBar()
connect(pAddCapsule, SIGNAL(triggered()),m_pPrimitivesWidget,SLOT(createCapsule()));
connect(pAddIcoSphere, SIGNAL(triggered()),m_pPrimitivesWidget,SLOT(createIcoSphere()));
connect(pAddRoundedBox, SIGNAL(triggered()),m_pPrimitivesWidget,SLOT(createRoundedBox()));
connect(pAddSpring, SIGNAL(triggered()),m_pPrimitivesWidget,SLOT(createSpring()));

// Animation tab
AnimationWidget *pAnimationWidget = new AnimationWidget(this->ui->tabWidget);
Expand Down
5 changes: 3 additions & 2 deletions src/materialeditor_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
#include <QApplication>

class MaterialEditorTest : public ::testing::Test {
protected:
std::unique_ptr<QApplication> app;
protected:
void SetUp() override {
int argc{0};
char* argv[] = { nullptr };
app = std::make_unique<QApplication>(argc, argv);
}
private:
std::unique_ptr<QApplication> app;
};

TEST_F(MaterialEditorTest, SetMaterialTextTest) {
Expand Down
Loading