Skip to content

Commit

Permalink
Add 'Generated Mesh' option to mesh warping UI
Browse files Browse the repository at this point in the history
  • Loading branch information
adamkewley committed Jun 18, 2024
1 parent 9640b22 commit c25f247
Show file tree
Hide file tree
Showing 27 changed files with 130 additions and 10 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

- The model warping workflow now writes the warped meshes to disk at `$MODEL_DIR/WarpedGeometry`
(previously: it kept them in-memory, which was only really useful for development, #889)
- The mesh input (source/destination) panels in the mesh importer now have the option to import
generated meshes, which is handy for debugging/demos
- The [opensim-jam-org/jam-plugin](https://github.com/opensim-jam-org/jam-plugin) is
now built alongside OpenSimCreator, which enables loading models containing
`Smith2018ArticularContactForce` and `Smith2018ContactMesh` (#884)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,20 +176,26 @@ void osc::ActionDeleteElementByID(UndoableTPSDocument& doc, UID id)
}
}

void osc::ActionLoadMesh(
UndoableTPSDocument& doc,
const Mesh& mesh,
TPSDocumentInputIdentifier which)
{
UpdMesh(doc.upd_scratch(), which) = mesh;
doc.commit_scratch("changed mesh");
}

void osc::ActionLoadMeshFile(
UndoableTPSDocument& doc,
TPSDocumentInputIdentifier which)
{
const std::optional<std::filesystem::path> maybeMeshPath =
prompt_user_to_select_file(GetSupportedSimTKMeshFormats());
if (!maybeMeshPath)
{
if (not maybeMeshPath) {
return; // user didn't select anything
}

UpdMesh(doc.upd_scratch(), which) = LoadMeshViaSimTK(*maybeMeshPath);

doc.commit_scratch("changed mesh");
ActionLoadMesh(doc, LoadMeshViaSimTK(*maybeMeshPath), which);
}

void osc::ActionLoadLandmarksFromCSV(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ namespace osc
void ActionDeleteSceneElementsByID(UndoableTPSDocument&, const std::unordered_set<TPSDocumentElementID>&);
void ActionDeleteElementByID(UndoableTPSDocument&, UID);

// assigns the given mesh to the document
void ActionLoadMesh(UndoableTPSDocument&, const Mesh&, TPSDocumentInputIdentifier);

// prompts the user to browse for an input mesh and assigns it to the document
void ActionLoadMeshFile(UndoableTPSDocument&, TPSDocumentInputIdentifier);

Expand Down
22 changes: 21 additions & 1 deletion src/OpenSimCreator/UI/MeshWarper/MeshWarpingTabInputMeshPanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <oscar/Graphics/Color.h>
#include <oscar/Graphics/Mesh.h>
#include <oscar/Graphics/RenderTexture.h>
#include <oscar/Graphics/Geometries/SolidGeometries.h>
#include <oscar/Graphics/Scene/CachedSceneRenderer.h>
#include <oscar/Graphics/Scene/SceneCache.h>
#include <oscar/Graphics/Scene/SceneDecoration.h>
Expand All @@ -34,6 +35,7 @@
#include <oscar/UI/ImGuiHelpers.h>
#include <oscar/UI/oscimgui.h>
#include <oscar/Utils/CStringView.h>
#include <oscar/Utils/Typelist.h>

#include <functional>
#include <memory>
Expand Down Expand Up @@ -490,10 +492,14 @@ namespace osc
ui::draw_button(ICON_FA_FILE_IMPORT " import" ICON_FA_CARET_DOWN);
if (ui::begin_popup_context_menu("##importcontextmenu", ImGuiPopupFlags_MouseButtonLeft))
{
if (ui::draw_menu_item("Mesh"))
if (ui::draw_menu_item("Mesh File"))
{
ActionLoadMeshFile(m_State->updUndoable(), m_DocumentIdentifier);
}
if (ui::begin_menu("Generated Mesh")) {
drawGeneratedMeshOptions(SolidGeometries{});
ui::end_menu();
}
if (ui::draw_menu_item("Landmarks from CSV"))
{
ActionLoadLandmarksFromCSV(m_State->updUndoable(), m_DocumentIdentifier);
Expand All @@ -507,6 +513,20 @@ namespace osc
}
}

template<typename... Geometries>
void drawGeneratedMeshOptions(Typelist<Geometries...>)
{
(drawGeneratedMeshOption<Geometries>(), ...);
}

template<typename Geometry>
void drawGeneratedMeshOption()
{
if (ui::draw_menu_item(Geometry::name())) {
ActionLoadMesh(m_State->updUndoable(), Geometry{}, m_DocumentIdentifier);
}
}

// draws an export button that enables the user to export things from this input
void drawExportButton()
{
Expand Down
2 changes: 1 addition & 1 deletion src/OpenSimThirdPartyPlugins/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ target_compile_features(OpenSimThirdPartyPlugins PRIVATE cxx_std_14)
set_target_properties(OpenSimThirdPartyPlugins PROPERTIES
CXX_EXTENSIONS OFF
CXX_STANDARD_REQUIRED ON
)
)
5 changes: 3 additions & 2 deletions src/oscar/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ add_library(oscar STATIC
Graphics/Geometries/PolyhedronGeometry.h
Graphics/Geometries/RingGeometry.cpp
Graphics/Geometries/RingGeometry.h
Graphics/Geometries/SolidGeometries.h
Graphics/Geometries/SphereGeometry.cpp
Graphics/Geometries/SphereGeometry.h
Graphics/Geometries/TetrahedronGeometry.cpp
Expand Down Expand Up @@ -421,7 +422,7 @@ add_library(oscar STATIC
UI.h
Utils.h
Variant.h
)
)

target_include_directories(oscar PUBLIC

Expand Down Expand Up @@ -450,4 +451,4 @@ target_link_libraries(oscar PUBLIC
set_target_properties(oscar PROPERTIES
CXX_EXTENSIONS OFF
CXX_STANDARD_REQUIRED ON
)
)
1 change: 1 addition & 0 deletions src/oscar/Graphics/Geometries.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <oscar/Graphics/Geometries/PlaneGeometry.h>
#include <oscar/Graphics/Geometries/PolyhedronGeometry.h>
#include <oscar/Graphics/Geometries/RingGeometry.h>
#include <oscar/Graphics/Geometries/SolidGeometries.h>
#include <oscar/Graphics/Geometries/SphereGeometry.h>
#include <oscar/Graphics/Geometries/TetrahedronGeometry.h>
#include <oscar/Graphics/Geometries/TorusGeometry.h>
Expand Down
3 changes: 3 additions & 0 deletions src/oscar/Graphics/Geometries/AABBGeometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

#include <oscar/Graphics/Mesh.h>
#include <oscar/Maths/AABB.h>
#include <oscar/Utils/CStringView.h>

namespace osc
{
class AABBGeometry final {
public:
static constexpr CStringView name() { return "AABB"; }

AABBGeometry(const AABB& = {.min = {-1.0f, -1.0f, -1.0f}, .max = {1.0f, 1.0f, 1.0f}});

const Mesh& mesh() const { return mesh_; }
Expand Down
3 changes: 3 additions & 0 deletions src/oscar/Graphics/Geometries/BoxGeometry.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
#pragma once

#include <oscar/Graphics/Mesh.h>
#include <oscar/Utils/CStringView.h>

#include <cstddef>

namespace osc
{
class BoxGeometry final {
public:
static constexpr CStringView name() { return "Box"; }

BoxGeometry(
float width = 1.0f,
float height = 1.0f,
Expand Down
3 changes: 3 additions & 0 deletions src/oscar/Graphics/Geometries/CircleGeometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@

#include <oscar/Graphics/Mesh.h>
#include <oscar/Maths/Angle.h>
#include <oscar/Utils/CStringView.h>

#include <cstddef>

namespace osc
{
class CircleGeometry final {
public:
static constexpr CStringView name() { return "Circle"; }

CircleGeometry(
float radius = 1.0f,
size_t num_segments = 32,
Expand Down
3 changes: 3 additions & 0 deletions src/oscar/Graphics/Geometries/ConeGeometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@

#include <oscar/Graphics/Mesh.h>
#include <oscar/Maths/Angle.h>
#include <oscar/Utils/CStringView.h>

#include <cstddef>

namespace osc
{
class ConeGeometry final {
public:
static constexpr CStringView name() { return "Cone"; }

ConeGeometry(
float radius = 1.0f,
float height = 1.0f,
Expand Down
3 changes: 3 additions & 0 deletions src/oscar/Graphics/Geometries/CylinderGeometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@

#include <oscar/Graphics/Mesh.h>
#include <oscar/Maths/Angle.h>
#include <oscar/Utils/CStringView.h>

#include <cstddef>

namespace osc
{
class CylinderGeometry final {
public:
static constexpr CStringView name() { return "Cylinder"; }

CylinderGeometry(
float radius_top = 1.0f,
float radius_bottom = 1.0f,
Expand Down
3 changes: 3 additions & 0 deletions src/oscar/Graphics/Geometries/DodecahedronGeometry.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
#pragma once

#include <oscar/Graphics/Mesh.h>
#include <oscar/Utils/CStringView.h>

#include <cstddef>

namespace osc
{
class DodecahedronGeometry final {
public:
static constexpr CStringView name() { return "Dodecahedron"; }

DodecahedronGeometry(
float radius = 1.0f,
size_t detail = 0
Expand Down
3 changes: 3 additions & 0 deletions src/oscar/Graphics/Geometries/GridGeometry.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
#pragma once

#include <oscar/Graphics/Mesh.h>
#include <oscar/Utils/CStringView.h>

#include <cstddef>

namespace osc
{
class GridGeometry final {
public:
static constexpr CStringView name() { return "Grid"; }

GridGeometry(
float size = 2.0f,
size_t num_divisions = 10
Expand Down
3 changes: 3 additions & 0 deletions src/oscar/Graphics/Geometries/IcosahedronGeometry.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
#pragma once

#include <oscar/Graphics/Mesh.h>
#include <oscar/Utils/CStringView.h>

#include <cstddef>

namespace osc
{
class IcosahedronGeometry final {
public:
static constexpr CStringView name() { return "Icosahedron"; }

IcosahedronGeometry(
float radius = 1.0f,
size_t detail = 0
Expand Down
3 changes: 3 additions & 0 deletions src/oscar/Graphics/Geometries/LatheGeometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <oscar/Graphics/Mesh.h>
#include <oscar/Maths/Angle.h>
#include <oscar/Maths/Vec2.h>
#include <oscar/Utils/CStringView.h>

#include <cstddef>
#include <span>
Expand All @@ -15,6 +16,8 @@ namespace osc
// (ported from three.js:LatheGeometry)
class LatheGeometry final {
public:
static constexpr CStringView name() { return "Lathe"; }

LatheGeometry(
std::span<const Vec2> points = std::vector<Vec2>{{0.0f, -0.5f}, {0.5f, 0.0f}, {0.0f, 0.5f}},
size_t num_segments = 12,
Expand Down
3 changes: 3 additions & 0 deletions src/oscar/Graphics/Geometries/OctahedronGeometry.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
#pragma once

#include <oscar/Graphics/Mesh.h>
#include <oscar/Utils/CStringView.h>

#include <cstddef>

namespace osc
{
class OctahedronGeometry final {
public:
static constexpr CStringView name() { return "Octahedron"; }

OctahedronGeometry(
float radius = 1.0f,
size_t detail = 0
Expand Down
3 changes: 3 additions & 0 deletions src/oscar/Graphics/Geometries/PlaneGeometry.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
#pragma once

#include <oscar/Graphics/Mesh.h>
#include <oscar/Utils/CStringView.h>

#include <cstddef>

namespace osc
{
class PlaneGeometry final {
public:
static constexpr CStringView name() { return "Plane"; }

PlaneGeometry(
float width = 1.0f,
float height = 1.0f,
Expand Down
3 changes: 3 additions & 0 deletions src/oscar/Graphics/Geometries/PolyhedronGeometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <oscar/Graphics/Mesh.h>
#include <oscar/Maths/Vec3.h>
#include <oscar/Utils/CStringView.h>

#include <cstddef>
#include <cstdint>
Expand All @@ -14,6 +15,8 @@ namespace osc
// by dividing them up to the desired `detail_level`
class PolyhedronGeometry final {
public:
static constexpr CStringView name() { return "Polyhedron"; }

PolyhedronGeometry(
std::span<const Vec3> vertices,
std::span<const uint32_t> indices,
Expand Down
3 changes: 3 additions & 0 deletions src/oscar/Graphics/Geometries/RingGeometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@

#include <oscar/Graphics/Mesh.h>
#include <oscar/Maths/Angle.h>
#include <oscar/Utils/CStringView.h>

#include <cstddef>

namespace osc
{
class RingGeometry final {
public:
static constexpr CStringView name() { return "Ring"; }

RingGeometry(
float inner_radius = 0.5f,
float outer_radius = 1.0f,
Expand Down
33 changes: 33 additions & 0 deletions src/oscar/Graphics/Geometries/SolidGeometries.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#pragma once

#include <oscar/Graphics/Geometries/BoxGeometry.h>
#include <oscar/Graphics/Geometries/CircleGeometry.h>
#include <oscar/Graphics/Geometries/ConeGeometry.h>
#include <oscar/Graphics/Geometries/CylinderGeometry.h>
#include <oscar/Graphics/Geometries/DodecahedronGeometry.h>
#include <oscar/Graphics/Geometries/IcosahedronGeometry.h>
#include <oscar/Graphics/Geometries/OctahedronGeometry.h>
#include <oscar/Graphics/Geometries/RingGeometry.h>
#include <oscar/Graphics/Geometries/SphereGeometry.h>
#include <oscar/Graphics/Geometries/TetrahedronGeometry.h>
#include <oscar/Graphics/Geometries/TorusGeometry.h>
#include <oscar/Graphics/Geometries/TorusKnotGeometry.h>
#include <oscar/Utils/Typelist.h>

namespace osc
{
using SolidGeometries = Typelist<
BoxGeometry,
CircleGeometry,
ConeGeometry,
CylinderGeometry,
DodecahedronGeometry,
IcosahedronGeometry,
OctahedronGeometry,
RingGeometry,
SphereGeometry,
TetrahedronGeometry,
TorusGeometry,
TorusKnotGeometry
>;
}
Loading

0 comments on commit c25f247

Please sign in to comment.