Skip to content

Commit

Permalink
Refactor MeshWarpingTabSharedState to use CustomRenderingOptions and …
Browse files Browse the repository at this point in the history
…OverlayDecorationOptions (#892)
  • Loading branch information
adamkewley committed Jun 25, 2024
1 parent 777ad37 commit ecaa603
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 28 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
the splash tab
- When a model editor tab is active, it now shows the filename of the osim file--if there is
one--in the application window's title
- The "Axis Lines" overlay option now extends the lines out to 5 meters (previously: 1 m)
- Internal: Added `src/OpenSimThirdPartyPlugins`, for housing copy+pasted OpenSim
plugin code sourced from the internet (e.g. SimTK.org)

Expand Down
9 changes: 9 additions & 0 deletions src/OpenSimCreator/Graphics/CustomRenderingOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <OpenSimCreator/Graphics/CustomRenderingOptionFlags.h>

#include <oscar/Graphics/Scene/SceneRendererParams.h>
#include <oscar/Utils/Algorithms.h>
#include <oscar/Utils/CStringView.h>
#include <oscar/Utils/EnumHelpers.h>
Expand Down Expand Up @@ -89,3 +90,11 @@ void osc::CustomRenderingOptions::tryUpdFromValues(std::string_view keyPrefix, c
}
}
}

void osc::CustomRenderingOptions::applyTo(SceneRendererParams& params) const
{
params.draw_floor = getDrawFloor();
params.draw_rims = getDrawSelectionRims();
params.draw_mesh_normals = getDrawMeshNormals();
params.draw_shadows = getDrawShadows();
}
4 changes: 4 additions & 0 deletions src/OpenSimCreator/Graphics/CustomRenderingOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include <string_view>
#include <unordered_map>

namespace osc { struct SceneRendererParams; }

namespace osc
{
class CustomRenderingOptions final {
Expand All @@ -35,6 +37,8 @@ namespace osc
void forEachOptionAsAppSettingValue(const std::function<void(std::string_view, const AppSettingValue&)>&) const;
void tryUpdFromValues(std::string_view keyPrefix, const std::unordered_map<std::string, AppSettingValue>&);

void applyTo(SceneRendererParams&) const;

friend bool operator==(const CustomRenderingOptions&, const CustomRenderingOptions&) = default;

private:
Expand Down
38 changes: 18 additions & 20 deletions src/OpenSimCreator/Graphics/OpenSimGraphicsHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,25 @@ SceneRendererParams osc::CalcSceneRendererParams(
AntiAliasingLevel antiAliasingLevel,
float fixupScaleFactor)
{
SceneRendererParams params;
if (viewportDims.x >= 1.0f && viewportDims.y >= 1.0f)
{
params.dimensions = viewportDims;
SceneRendererParams rv;

if (viewportDims.x >= 1.0f && viewportDims.y >= 1.0f) {
rv.dimensions = viewportDims;
}
params.antialiasing_level = antiAliasingLevel;
params.light_direction = recommended_light_direction(renderParams.camera);
params.draw_floor = renderParams.renderingOptions.getDrawFloor();
params.view_matrix = renderParams.camera.view_matrix();
params.projection_matrix = renderParams.camera.projection_matrix(aspect_ratio_of(viewportDims));
params.near_clipping_plane = renderParams.camera.znear;
params.far_clipping_plane = renderParams.camera.zfar;
params.view_pos = renderParams.camera.position();
params.fixup_scale_factor = fixupScaleFactor;
params.draw_rims = renderParams.renderingOptions.getDrawSelectionRims();
params.draw_mesh_normals = renderParams.renderingOptions.getDrawMeshNormals();
params.draw_shadows = renderParams.renderingOptions.getDrawShadows();
params.light_color = renderParams.lightColor;
params.background_color = renderParams.backgroundColor;
params.floor_location = renderParams.floorLocation;
return params;

rv.antialiasing_level = antiAliasingLevel;
rv.light_direction = recommended_light_direction(renderParams.camera);
renderParams.renderingOptions.applyTo(rv);
rv.view_matrix = renderParams.camera.view_matrix();
rv.projection_matrix = renderParams.camera.projection_matrix(aspect_ratio_of(viewportDims));
rv.near_clipping_plane = renderParams.camera.znear;
rv.far_clipping_plane = renderParams.camera.zfar;
rv.view_pos = renderParams.camera.position();
rv.fixup_scale_factor = fixupScaleFactor;
rv.light_color = renderParams.lightColor;
rv.background_color = renderParams.backgroundColor;
rv.floor_location = renderParams.floorLocation;
return rv;
}

void osc::GenerateDecorations(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include <OpenSimCreator/Graphics/OverlayDecorationGenerator.h>
#include <OpenSimCreator/UI/MeshWarper/MeshWarpingTabSharedState.h>

#include <oscar/Graphics/Color.h>
Expand All @@ -26,17 +27,20 @@ namespace osc
});

// if requested, also draw wireframe overlays for the mesh
if (wireframeMode)
{
if (wireframeMode) {
out({
.mesh = tpsSourceOrDestinationMesh,
.material = sharedState.wireframe_material(),
});
}

// add grid decorations
draw_xz_grid(sharedState.updSceneCache(), out);
draw_xz_floor_lines(sharedState.updSceneCache(), out, 100.0f);
// add overlay decorations
GenerateOverlayDecorations(
sharedState.updSceneCache(),
sharedState.getOverlayDecorationOptions(),
BVH{}, // TODO: should have a scene BVH by this point
out
);
}

// returns the amount by which non-participating landmarks should be scaled w.r.t. pariticpating ones
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,12 @@ namespace osc
const std::optional<RayCollision>& maybeMeshCollision,
const std::optional<MeshWarpingTabHover>& maybeLandmarkCollision)
{
const SceneRendererParams params = calc_standard_dark_scene_render_params(
SceneRendererParams params = calc_standard_dark_scene_render_params(
m_Camera,
App::get().anti_aliasing_level(),
dims
);
m_State->getCustomRenderingOptions().applyTo(params);
const std::vector<SceneDecoration> decorations = generateDecorations(maybeMeshCollision, maybeLandmarkCollision);
return m_CachedRenderer.render(decorations, params);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,11 +259,12 @@ namespace osc
RenderTexture& renderScene(Vec2 dims)
{
const std::vector<SceneDecoration> decorations = generateDecorations();
const SceneRendererParams params = calc_standard_dark_scene_render_params(
SceneRendererParams params = calc_standard_dark_scene_render_params(
m_Camera,
App::get().anti_aliasing_level(),
dims
);
m_State->getCustomRenderingOptions().applyTo(params);
return m_CachedRenderer.render(decorations, params);
}

Expand Down
16 changes: 16 additions & 0 deletions src/OpenSimCreator/UI/MeshWarper/MeshWarpingTabSharedState.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include <OpenSimCreator/Documents/MeshWarper/TPSDocumentInputIdentifier.h>
#include <OpenSimCreator/Documents/MeshWarper/TPSWarpResultCache.h>
#include <OpenSimCreator/Documents/MeshWarper/UndoableTPSDocument.h>
#include <OpenSimCreator/Graphics/CustomRenderingOptions.h>
#include <OpenSimCreator/Graphics/OverlayDecorationOptions.h>
#include <OpenSimCreator/UI/MeshWarper/MeshWarpingTabHover.h>
#include <OpenSimCreator/UI/MeshWarper/MeshWarpingTabUserSelection.h>

Expand Down Expand Up @@ -44,6 +46,9 @@ namespace osc
m_SceneCache{std::move(sceneCache_)}
{
OSC_ASSERT(m_SceneCache != nullptr);
m_OverlayDecorationOptions.setDrawXZGrid(true);
m_OverlayDecorationOptions.setDrawAxisLines(true);
m_CustomRenderingOptions.setDrawFloor(false);
}

void on_mount()
Expand Down Expand Up @@ -242,6 +247,11 @@ namespace osc
m_LinkedCameraBase = newCamera;
}

const CustomRenderingOptions& getCustomRenderingOptions() const { return m_CustomRenderingOptions; }
CustomRenderingOptions& updCustomRenderingOptions() { return m_CustomRenderingOptions; }
const OverlayDecorationOptions& getOverlayDecorationOptions() const { return m_OverlayDecorationOptions; }
OverlayDecorationOptions& updOverlayDecorationOptions() { return m_OverlayDecorationOptions; }

private:
// ID of the top-level TPS3D tab
UID m_TabID;
Expand Down Expand Up @@ -281,5 +291,11 @@ namespace osc

// currently active tab-wide popups
PopupManager m_PopupManager;

// user-editable rendering options
CustomRenderingOptions m_CustomRenderingOptions;

// user-editable overlay decoration options
OverlayDecorationOptions m_OverlayDecorationOptions;
};
}
2 changes: 1 addition & 1 deletion src/oscar/Graphics/Scene/SceneHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ namespace osc
void draw_xz_floor_lines(
SceneCache&,
const std::function<void(SceneDecoration&&)>& out,
float scale = 1.0f
float scale = 5.0f
);

void draw_xz_grid(
Expand Down

0 comments on commit ecaa603

Please sign in to comment.