Skip to content

Commit

Permalink
[example] use gltf 2.0 custom file writer if enable
Browse files Browse the repository at this point in the history
  • Loading branch information
MathiasPaulin committed Jul 19, 2023
1 parent 42f9128 commit ca95874
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 29 deletions.
17 changes: 4 additions & 13 deletions examples/MaterialEdition/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,10 @@ add_executable(${PROJECT_NAME} ${app_sources} ${app_headers} ${app_uis} ${app_re
target_link_libraries(${PROJECT_NAME} PUBLIC Radium::Gui ${Qt_LIBRARIES})

# ------------------------------------------------------------------------------
# RadiumGlTF is available here https://gitlab.irit.fr/storm/repos/radium/libgltf.git (branch
# Material_Edition_#950). Compile and install RadiumGlTF first, e.g. into
# "path/to/RadiumGlTFinstall/", then configure using cmake [your configure args]
# -DRadiumGlTF_DIR="path/to/RadiumGlTFinstall/lib/cmake" -DUSE_RADIUMGLTF=ON to use it for this
# example.
option(USE_RADIUMGLTF "Enable loading/saving files with RadiumGltf extension" OFF)
if(USE_RADIUMGLTF)
message(STATUS "${PROJECT_NAME} uses RadiumGltf extension")
# TODO : find why this find_package is needed (at least on MacOs whe ).
find_package(OpenMP QUIET)
find_package(RadiumGlTF REQUIRED)
target_compile_definitions(${PROJECT_NAME} PUBLIC USE_RADIUMGLTF)
target_link_libraries(${PROJECT_NAME} PUBLIC RadiumGlTF::RadiumGlTF)
get_target_property(HAS_GLTF_WRITER Radium::IO IO_HAS_GLTF_WRITER)
if(HAS_GLTF_WRITER)
message(STATUS "${PROJECT_NAME} uses RadiumGltf writer extension")
target_compile_definitions(${PROJECT_NAME} PRIVATE HAS_GLTF_WRITER)
endif()

configure_radium_app(NAME ${PROJECT_NAME})
20 changes: 4 additions & 16 deletions examples/MaterialEdition/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,9 @@
#include <QMenuBar>
#include <QSettings>

#ifdef USE_RADIUMGLTF
#ifdef HAS_GLTF_WRITER
# include <Engine/Scene/SystemDisplay.hpp>
# include <IO/Gltf/Loader/glTFFileLoader.hpp>
# include <IO/Gltf/Writer/glTFFileWriter.hpp>
# include <glTFLibrary.hpp>
#endif

using namespace Ra::Gui::Widgets;
Expand Down Expand Up @@ -74,7 +72,7 @@ class DemoWindow : public Ra::Gui::SimpleWindow
allexts.append( exts + " " );
filter.append( QString::fromStdString( loader->name() ) + " (" + exts + ");;" );
}
// add a filter concetenatting all the supported extensions
// add a filter concatenatting all the supported extensions
filter.prepend( "Supported files (" + allexts + ");;" );

// remove the last ";;" of the string
Expand All @@ -95,11 +93,7 @@ class DemoWindow : public Ra::Gui::SimpleWindow
};
connect( fileOpenAction, &QAction::triggered, openFile );

#ifdef USE_RADIUMGLTF
// register the gltf loader
std::shared_ptr<Ra::Core::Asset::FileLoaderInterface> loader =
std::make_shared<GLTF::glTFFileLoader>();
Ra::Engine::RadiumEngine::getInstance()->registerFileLoader( loader );
#ifdef HAS_GLTF_WRITER

// allow to save in gltf format
auto fileSaveAction = new QAction( "&Save..." );
Expand All @@ -117,7 +111,7 @@ class DemoWindow : public Ra::Gui::SimpleWindow
entities.begin(), entities.end(), std::back_inserter( toExport ), []( auto e ) {
return e != Ra::Engine::Scene::SystemEntity::getInstance();
} );
GLTF::glTFFileWriter writer { fileName.toStdString(), "textures/", false };
Ra::IO::GLTF::glTFFileWriter writer { fileName.toStdString(), "textures/", false };
writer.write( toExport );
};
connect( fileSaveAction, &QAction::triggered, saveFile );
Expand Down Expand Up @@ -196,12 +190,6 @@ int main( int argc, char* argv[] ) {

//! [Initializing the application]
app.initialize( DemoWindowFactory() );
#ifdef USE_RADIUMGLTF
app.m_mainWindow->getViewer()->makeCurrent();
// initialize the use of GLTF library
GLTF::initializeGltf();
app.m_mainWindow->getViewer()->doneCurrent();
#endif
app.setContinuousUpdate( false );
//! [Initializing the application]

Expand Down

0 comments on commit ca95874

Please sign in to comment.