Skip to content

Commit

Permalink
Add support for armature visualization
Browse files Browse the repository at this point in the history
  • Loading branch information
Meakk committed Dec 20, 2024
1 parent d43b451 commit 6fdc198
Show file tree
Hide file tree
Showing 35 changed files with 237 additions and 52 deletions.
2 changes: 1 addition & 1 deletion .github/actions/vtk_commit_sha
Original file line number Diff line number Diff line change
@@ -1 +1 @@
d085bfba2e97c65a031daacae3499c051bb8f18b
e5226e04401e93dc8aabd83d082cfbb111811c53
5 changes: 3 additions & 2 deletions application/F3DOptionsTools.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,16 @@ static inline const std::array<CLIGroup, 8> CLIOptions = {{
{ "grid-subdivisions", "", "Number of grid subdivisions", "<value>", "" },
{ "grid-color", "", "Color of main grid lines", "<R,G,B>", "" },
{ "edges", "e", "Show cell edges", "<bool>", "1" },
{ "armature", "", "Enable armature visualization", "<bool>", "1" },
{ "camera-index", "", "Select the camera to use", "<index>", "" },
{ "trackball", "k", "Enable trackball interaction", "<bool>", "1" },
{ "invert-zoom", "", "Invert zoom direction with right mouse click", "<bool>", "1" },
{ "animation-autoplay", "", "Automatically start animation", "<bool>", "1" },
{ "animation-index", "", "Select animation to show", "<index>", "" },
{ "animation-speed-factor", "", "Set animation speed factor", "<factor>", "" },
{ "animation-time", "", "Set animation time to load", "<time>", "" },
{"font-file", "", "Path to a FreeType compatible font file", "<file_path>", ""},
{"command-script", "", "Path to a script file containing commands to execute", "<file_path>", "" } } },
{ "font-file", "", "Path to a FreeType compatible font file", "<file_path>", ""},
{ "command-script", "", "Path to a script file containing commands to execute", "<file_path>", "" } } },
{ "Material",
{ {"point-sprites", "o", "Show sphere sprites instead of surfaces", "<bool>", "1" },
{"point-sprites-type", "", "Point sprites type", "<sphere|gaussian>", ""},
Expand Down
1 change: 1 addition & 0 deletions application/F3DOptionsTools.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ static inline const std::map<std::string_view, std::string_view> LibOptionsNames
{ "grid-subdivisions", "render.grid.subdivisions" },
{ "grid-color", "render.grid.color" },
{ "edges", "render.show_edges" },
{ "armature", "render.armature.enable" },
{ "camera-index", "scene.camera.index" },
{ "trackball", "interactor.trackball" },
{ "invert-zoom", "interactor.invert_zoom" },
Expand Down
7 changes: 7 additions & 0 deletions application/testing/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,13 @@ f3d_test(NAME TestInteractionAnimationInvert DATA f3d.glb ARGS --animation-speed
f3d_test(NAME TestVerboseAnimationWrongAnimationTimeHigh DATA BoxAnimated.gltf ARGS --animation-time=10 --verbose REGEXP "Animation time 10 is outside of range \\[0, 3\\.70833\\], using 3\\.70833" NO_BASELINE)
f3d_test(NAME TestVerboseAnimationWrongAnimationTimeLow DATA BoxAnimated.gltf ARGS --animation-time=-5 --verbose REGEXP "Animation time -5 is outside of range \\[0, 3\\.70833\\], using 0" NO_BASELINE)

# Armature test
f3d_test(NAME TestGLTFRigNoArmature DATA RiggedFigure.glb ARGS --animation-time=1)
if(VTK_VERSION VERSION_GREATER_EQUAL 9.2.20241219)
f3d_test(NAME TestGLTFRigArmature DATA RiggedFigure.glb ARGS --animation-time=1 --armature)
f3d_test(NAME TestGLTFRigArmatureSphereTube DATA RiggedFigure.glb ARGS --animation-time=1 --armature --point-size=20 --line-width=5)
endif()

# Test exit hotkey
f3d_test(NAME TestInteractionSimpleExit DATA cow.vtp REGEXP "Interactor has been stopped" INTERACTION NO_BASELINE) #CTRL+Q

Expand Down
1 change: 1 addition & 0 deletions doc/libf3d/OPTIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ render.background.skybox|bool<br>false<br>render|Show the *HDRI* image as a skyb
render.background.blur.enable|bool<br>false<br>render|Blur background, useful with a skybox.|\-\-blur-background
render.background.blur.coc|double<br>20.0<br>render|Blur background circle of confusion radius.|\-\-blur-coc
render.light.intensity|double<br>1.0<br>render|Adjust the intensity of every light in the scene.|\-\-light-intensity
render.armature.enable|bool<br>false<br>render|Display armatures if present in the scene (glTF only).|\-\-armature

## UI Options

Expand Down
1 change: 1 addition & 0 deletions doc/user/OPTIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Options|Default|Description
\-\-grid\-subdivisions=\<count\>||Set the number of subdivisions for the grid.
\-\-grid\-color=\<color\>|(0,0,0)|Set the color grid lines.
-e, \-\-edges||Show the *cell edges*.
\-\-armature||Show armature if present (glTF only).
\-\-camera-index=\<idx\>||Select the scene camera to use when available in the file. Automatically computed by default.
-k, \-\-trackball||Enable trackball interaction.
\-\-animation-autoplay||Automatically start animation.
Expand Down
6 changes: 6 additions & 0 deletions library/options.json
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,12 @@
"type": "double",
"default_value": "1.0"
}
},
"armature": {
"enable": {
"type": "bool",
"default_value": "false"
}
}
},
"ui": {
Expand Down
1 change: 1 addition & 0 deletions library/src/interactor_impl.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -918,6 +918,7 @@ interactor& interactor_impl::initBindings()
this->addBinding({mod_t::NONE, "J"}, "toggle render.background.skybox","Scene", std::bind(docTgl, "Toggle HDRI skybox", std::cref(opts.render.background.skybox)));
this->addBinding({mod_t::NONE, "L"}, "increase_light_intensity", "Scene", std::bind(docDbl, "Increase lights intensity", std::cref(opts.render.light.intensity)));
this->addBinding({mod_t::SHIFT, "L"}, "decrease_light_intensity", "Scene", std::bind(docDbl, "Decrease lights intensity", std::cref(opts.render.light.intensity)));
this->addBinding({mod_t::SHIFT, "A"}, "toggle render.armature.enable","Scene", std::bind(docTgl, "Toggle armature", std::cref(opts.render.armature.enable)));
this->addBinding({mod_t::ANY, "1"}, "set_camera front", "Camera", std::bind(docStr, "Front View camera"));
this->addBinding({mod_t::ANY, "3"}, "set_camera right", "Camera", std::bind(docStr, "Right View camera"));
this->addBinding({mod_t::ANY, "4"}, "roll_camera -90", "Camera", std::bind(docStr, "Rotate camera right"));
Expand Down
1 change: 1 addition & 0 deletions library/src/window_impl.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@ void window_impl::UpdateDynamicOptions()
renderer->ShowConsole(opt.ui.console);
renderer->ShowDropZone(opt.ui.dropzone);
renderer->SetDropZoneInfo(opt.ui.dropzone_info);
renderer->ShowArmature(opt.render.armature.enable);

renderer->SetUseRaytracing(opt.render.raytracing.enable);
renderer->SetRaytracingSamples(opt.render.raytracing.samples);
Expand Down
2 changes: 1 addition & 1 deletion plugins/draco/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ if(VTK_VERSION VERSION_GREATER_EQUAL 9.3.20240214)
SCORE 90
EXTENSIONS gltf glb
MIMETYPES model/gltf-binary model/gltf+json
VTK_IMPORTER vtkF3DGLTFImporter
VTK_IMPORTER vtkF3DGLTFDracoImporter
FORMAT_DESCRIPTION "GL Transmission Format"
)
endif()
Expand Down
4 changes: 2 additions & 2 deletions plugins/draco/module/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ set(classes
# Needs https://gitlab.kitware.com/vtk/vtk/-/merge_requests/10884
if(VTK_VERSION VERSION_GREATER_EQUAL 9.3.20240214)
set(classes ${classes}
vtkF3DGLTFDocumentLoader
vtkF3DGLTFImporter
vtkF3DGLTFDracoDocumentLoader
vtkF3DGLTFDracoImporter
)
endif()

Expand Down
1 change: 1 addition & 0 deletions plugins/draco/module/vtk.module
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ NAME
DESCRIPTION
A VTK module for the Draco plugin
DEPENDS
f3d::vtkextPrivate
VTK::CommonCore
VTK::CommonExecutionModel
VTK::IOGeometry
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "vtkF3DGLTFDocumentLoader.h"
#include "vtkF3DGLTFDracoDocumentLoader.h"

#include <vtkObjectFactory.h>

Expand Down Expand Up @@ -101,18 +101,18 @@ std::vector<char> DecodeVertexBuffer(vtkGLTFDocumentLoader::ComponentType compTy
}

//----------------------------------------------------------------------------
vtkStandardNewMacro(vtkF3DGLTFDocumentLoader);
vtkStandardNewMacro(vtkF3DGLTFDracoDocumentLoader);

//----------------------------------------------------------------------------
std::vector<std::string> vtkF3DGLTFDocumentLoader::GetSupportedExtensions()
std::vector<std::string> vtkF3DGLTFDracoDocumentLoader::GetSupportedExtensions()
{
std::vector<std::string> extensions = this->Superclass::GetSupportedExtensions();
extensions.emplace_back("KHR_draco_mesh_compression");
return extensions;
}

//----------------------------------------------------------------------------
void vtkF3DGLTFDocumentLoader::PrepareData()
void vtkF3DGLTFDracoDocumentLoader::PrepareData()
{
std::shared_ptr<Model> model = this->GetInternalModel();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
/**
* @class vtkF3DGLTFDocumentLoader
* @class vtkF3DGLTFDracoDocumentLoader
* @brief Specialized GLTF document loader with Draco buffer decoding
*
* This class subclasses vtkGLTFDocumentLoader to handle Draco metadata
*/

#ifndef vtkF3DGLTFDocumentLoader_h
#define vtkF3DGLTFDocumentLoader_h
#ifndef vtkF3DGLTFDracoDocumentLoader_h
#define vtkF3DGLTFDracoDocumentLoader_h

#include <vtkGLTFDocumentLoader.h>

class vtkF3DGLTFDocumentLoader : public vtkGLTFDocumentLoader
class vtkF3DGLTFDracoDocumentLoader : public vtkGLTFDocumentLoader
{
public:
static vtkF3DGLTFDocumentLoader* New();
vtkTypeMacro(vtkF3DGLTFDocumentLoader, vtkGLTFDocumentLoader);
static vtkF3DGLTFDracoDocumentLoader* New();
vtkTypeMacro(vtkF3DGLTFDracoDocumentLoader, vtkGLTFDocumentLoader);

/**
* Overridden to add KHR_draco_mesh_compression support
Expand All @@ -29,12 +29,12 @@ class vtkF3DGLTFDocumentLoader : public vtkGLTFDocumentLoader
void PrepareData() override;

protected:
vtkF3DGLTFDocumentLoader() = default;
~vtkF3DGLTFDocumentLoader() override = default;
vtkF3DGLTFDracoDocumentLoader() = default;
~vtkF3DGLTFDracoDocumentLoader() override = default;

private:
vtkF3DGLTFDocumentLoader(const vtkF3DGLTFDocumentLoader&) = delete;
void operator=(const vtkF3DGLTFDocumentLoader&) = delete;
vtkF3DGLTFDracoDocumentLoader(const vtkF3DGLTFDracoDocumentLoader&) = delete;
void operator=(const vtkF3DGLTFDracoDocumentLoader&) = delete;
};

#endif
14 changes: 14 additions & 0 deletions plugins/draco/module/vtkF3DGLTFDracoImporter.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include "vtkF3DGLTFDracoImporter.h"

#include "vtkF3DGLTFDracoDocumentLoader.h"

#include <vtkObjectFactory.h>

//----------------------------------------------------------------------------
vtkStandardNewMacro(vtkF3DGLTFDracoImporter);

//----------------------------------------------------------------------------
void vtkF3DGLTFDracoImporter::InitializeLoader()
{
this->Loader = vtkSmartPointer<vtkF3DGLTFDracoDocumentLoader>::New();
}
34 changes: 34 additions & 0 deletions plugins/draco/module/vtkF3DGLTFDracoImporter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* @class vtkF3DGLTFDracoImporter
* @brief VTK GLTF importer with Draco support
*
* Subclasses the default importer to initialize our own loader.
* @sa vtkF3DGLTFDracoDocumentLoader
*/

#ifndef vtkF3DGLTFDracoImporter_h
#define vtkF3DGLTFDracoImporter_h

#include <vtkF3DGLTFImporter.h>

class vtkF3DGLTFDracoImporter : public vtkF3DGLTFImporter
{
public:
static vtkF3DGLTFDracoImporter* New();
vtkTypeMacro(vtkF3DGLTFDracoImporter, vtkF3DGLTFImporter);

protected:
vtkF3DGLTFDracoImporter() = default;
~vtkF3DGLTFDracoImporter() override = default;

/**
* Overridden to instantiate our own document loader
*/
void InitializeLoader() override;

private:
vtkF3DGLTFDracoImporter(const vtkF3DGLTFDracoImporter&) = delete;
void operator=(const vtkF3DGLTFDracoImporter&) = delete;
};

#endif
14 changes: 0 additions & 14 deletions plugins/draco/module/vtkF3DGLTFImporter.cxx

This file was deleted.

2 changes: 1 addition & 1 deletion plugins/native/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ f3d_plugin_declare_reader(
SCORE 80
EXTENSIONS gltf glb
MIMETYPES model/gltf-binary model/gltf+json
VTK_IMPORTER vtkGLTFImporter
VTK_IMPORTER vtkF3DGLTFImporter
FORMAT_DESCRIPTION "GL Transmission Format"
)

Expand Down
1 change: 1 addition & 0 deletions plugins/native/module/vtk.module
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ NAME
DESCRIPTION
A VTK module for the native plugin
DEPENDS
f3d::vtkextPrivate
VTK::CommonCore
VTK::CommonExecutionModel
TEST_DEPENDS
Expand Down
3 changes: 3 additions & 0 deletions testing/baselines/TestGLTFRigArmature.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions testing/baselines/TestGLTFRigArmatureSphereTube.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions testing/baselines/TestGLTFRigNoArmature.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions testing/baselines/TestInteractionCheatsheetAnimationName.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions testing/baselines/TestInteractionCheatsheetConfigFile.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions testing/baselines/TestInteractionCheatsheetScalars.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions testing/baselines/TestSkinningManyBones.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions testing/data/DATA_LICENSES.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
- Crosterian.ttf: Denis Ignatov : [OFL (SIL Open Font License)](https://scripts.sil.org/cms/scripts/page.php?site_id=nrsi&id=OFL)
- SimpleMorph.gltf: glTF-Sample-Models: Public Domain
- SimpleSkin.gltf: glTF-Sample-Models: Public Domain
- RiggedFigure.glb: glTF-Sample-Models: Public Domain
- samplePTS.pts: VTK Data: BSD-3-Clause
- skin.png: Blender: [CC0](https://creativecommons.org/publicdomain/zero/1.0/)
- small.ex2: VTK Data: BSD-3-Clause
Expand Down
3 changes: 3 additions & 0 deletions testing/data/RiggedFigure.glb
Git LFS file not shown
1 change: 1 addition & 0 deletions vtkext/private/module/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ set(classes
vtkF3DConsoleOutputWindow
vtkF3DDropZoneActor
vtkF3DExternalRenderWindow
vtkF3DGLTFImporter
vtkF3DGenericImporter
vtkF3DHexagonalBokehBlurPass
vtkF3DInteractorEventRecorder
Expand Down
41 changes: 41 additions & 0 deletions vtkext/private/module/vtkF3DGLTFImporter.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include "vtkF3DGLTFImporter.h"

#include "vtkF3DRenderPass.h"

#include <vtkActor.h>
#include <vtkInformation.h>
#include <vtkObjectFactory.h>
#include <vtkOpenGLShaderProperty.h>

//----------------------------------------------------------------------------
vtkStandardNewMacro(vtkF3DGLTFImporter);

//----------------------------------------------------------------------------
#if VTK_VERSION_NUMBER >= VTK_VERSION_CHECK(9, 4, 20241219)
vtkF3DGLTFImporter::vtkF3DGLTFImporter()
{
this->SetImportArmature(true);
}
#else
vtkF3DGLTFImporter::vtkF3DGLTFImporter() = default;
#endif

//----------------------------------------------------------------------------
#if VTK_VERSION_NUMBER >= VTK_VERSION_CHECK(9, 4, 20241219)
void vtkF3DGLTFImporter::ApplyArmatureProperties(vtkActor* actor)
{
this->Superclass::ApplyArmatureProperties(actor);

vtkNew<vtkInformation> info;
info->Set(vtkF3DRenderPass::ACTOR_IS_ARMATURE(), 1);
actor->SetPropertyKeys(info);

// armature on top
//vtkOpenGLShaderProperty* sp = vtkOpenGLShaderProperty::SafeDownCast(actor->GetShaderProperty());
//if (sp)
//{
// // compress the depth value to the first thousandth slice in front of the camera to make sure it's displayed on top
// sp->AddFragmentShaderReplacement("//VTK::Depth::Impl", false, "gl_FragDepth = gl_FragDepth * 0.001;\n", false);
//}
}
#endif
Loading

0 comments on commit 6fdc198

Please sign in to comment.