Skip to content

Commit

Permalink
Merge pull request #27 from xissburg/refactor
Browse files Browse the repository at this point in the history
Refactor
  • Loading branch information
Ybalrid committed Sep 5, 2019
2 parents 47a6c3f + c36d871 commit f83073b
Show file tree
Hide file tree
Showing 44 changed files with 743 additions and 689 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,6 @@ Doxygen/
*.exe
*.out
*.app

# VSCode
.vscode
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ script:
- export CC=/usr/bin/gcc-7
- export CXX=/usr/bin/g++-7
- gcc -v && g++ -v && cmake --version
- mkdir build
- cd build
- cmake ..
- make
Expand Down
41 changes: 41 additions & 0 deletions CMake/Ogre_glTF_ConfigTargets.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
function(Ogre_glTF_config_sample PROJECTNAME)
file(GLOB SOURCES ./*.cpp ./*.hpp ./include/*.hpp)

add_executable(${PROJECTNAME} WIN32 MACOSX_BUNDLE ${SAMPLES_COMMON_HEADER_FILES} ${SAMPLES_COMMON_SOURCE_FILES} ${SOURCES})
add_dependencies(${PROJECTNAME} Ogre_glTF)

target_include_directories( ${PROJECTNAME} PUBLIC
#Ogre and the physics based high level material system
${OGRE_INCLUDE_DIRS}
${OGRE_HlmsPbs_INCLUDE_DIRS}
${OGRE_INCLUDE_DIR}/Hlms/Common
${CMAKE_SOURCE_DIR}/Samples/Common
)

target_link_libraries(${PROJECTNAME}
${OGRE_LIBRARIES}
${OGRE_HlmsPbs_LIBRARIES}
Ogre_glTF
)

if (Ogre_glTF_STATIC AND UNIX)
target_link_libraries(${PROJECTNAME}
${OGRE_RenderSystem_GL3Plus_LIBRARIES}
)

if (NOT APPLE)
target_link_libraries(${PROJECTNAME}
dl
pthread
Xt
X11
Xaw
Xrandr
)
endif ()
endif ()

set_target_properties(${PROJECTNAME} PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
set_property(TARGET ${PROJECTNAME} PROPERTY VS_DEBUGGER_WORKING_DIRECTORY ${PROJECT_BINARY_DIR})
endfunction(Ogre_glTF_config_sample)
98 changes: 21 additions & 77 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,36 @@ project(Ogre_glTF)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_INSTALL_PREFIX "./output")
set( CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG=1 -D_DEBUG=1")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG=1 -D_DEBUG=1")

if(NOT CMAKE_DEBUG_POSTFIX)
set(CMAKE_DEBUG_POSTFIX "_d")
endif()

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/CMake)

#get Ogre from your system. May need to set some variable for Windows folks
include(Ogre_glTF_ConfigTargets)

option(Ogre_glTF_STATIC "Static build" FALSE)

if (Ogre_glTF_STATIC)
add_definitions(-DOgre_glTF_STATIC)
set(Ogre_glTF_LIB_TYPE STATIC)
set(Ogre_glTF_LIB_SUFFIX "Static")
else ()
set(Ogre_glTF_LIB_TYPE SHARED)
set(Ogre_glTF_LIB_SUFFIX "")
endif ()

#Get Ogre from your system. May need to set some variables for Windows folks
find_package(OGRE COMPONENTS HlmsPbs REQUIRED)
file(GLOB librarySources ./src/*.cpp ./src/private_headers/*.hpp ./include/*.hpp)
file(GLOB testSources ./test/*.cpp ./test/*.hpp ./include/*.hpp)
file(GLOB pluginTestSources ./pluginTest/*.cpp ./pluginTest/*.hpp ./include/*.hpp)

add_library(Ogre_glTF SHARED ${librarySources})
#add_library(Ogre_glTF_static STATIC ${librarySources})
add_library(${PROJECT_NAME} ${Ogre_glTF_LIB_TYPE} ${librarySources})

target_compile_definitions(Ogre_glTF PUBLIC Ogre_glTF_DLL_EXPORT_CONFIG_ON)
target_compile_definitions(${PROJECT_NAME} PUBLIC Ogre_glTF_DLL_EXPORT_CONFIG_ON)

if(MSVC)
add_executable(Ogre_glTF_TEST WIN32 ${testSources})
add_executable(Ogre_gltf_PluginTest WIN32 ${pluginTestSources})
#add_executable(Ogre_glTF_TEST_static WIN32 ${testSources})
else()
add_executable(Ogre_glTF_TEST ${testSources})
add_executable(Ogre_gltf_PluginTest ${pluginTestSources})
#add_executable(Ogre_glTF_TEST_static ${testSources})
endif(MSVC)
set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME ${PROJECT_NAME}${Ogre_glTF_LIB_SUFFIX})

target_include_directories( Ogre_glTF PUBLIC
#Ogre and the physics based high level material system
Expand All @@ -46,79 +48,21 @@ target_include_directories( Ogre_glTF PUBLIC
./thirdParty/tinygltf/
)

#target_include_directories( Ogre_glTF_static PUBLIC
# #Ogre and the physics based high level material system
# ${OGRE_INCLUDE_DIRS}
# ${OGRE_HlmsPbs_INCLUDE_DIRS}

# #local include directory
# ./include
# ./src/private_headers
# ./thirdParty/tinygltf/
#)

target_include_directories( Ogre_glTF_TEST PUBLIC
#Ogre and the physics based high level material system
${OGRE_INCLUDE_DIRS}
${OGRE_HlmsPbs_INCLUDE_DIRS}
${OGRE_INCLUDE_DIR}/Hlms/Common

#local include directory
./include
)


# target_include_directories( Ogre_glTF_TEST_static PUBLIC
# #Ogre and the physics based high level material system
# ${OGRE_INCLUDE_DIRS}
# ${OGRE_HlmsPbs_INCLUDE_DIRS}
#
# #local include directory
# ./include
#)

target_include_directories(Ogre_gltf_PluginTest PUBLIC
${OGRE_INCLUDE_DIRS}
${OGRE_HlmsPbs_INCLUDE_DIRS}
${OGRE_INCLUDE_DIR}/Hlms/Common
./include
)

target_link_libraries(Ogre_glTF
${OGRE_LIBRARIES}
${OGRE_HlmsPbs_LIBRARIES}
)

target_link_libraries(Ogre_glTF_TEST
${OGRE_LIBRARIES}
${OGRE_HlmsPbs_LIBRARIES}

#the library we just built
Ogre_glTF
)

target_link_libraries(Ogre_gltf_PluginTest
${OGRE_LIBRARIES}
${OGRE_HlmsPbs_LIBRARIES}
)

add_dependencies(Ogre_gltf_PluginTest Ogre_glTF)

#target_link_libraries(Ogre_glTF_TEST_static
# ${OGRE_LIBRARIES}
# ${OGRE_HlmsPbs_LIBRARIES}
#
# #the library we just built
# Ogre_glTF_static
#)
add_subdirectory(Samples)

#installation

install(TARGETS Ogre_glTF DESTINATION "bin")
install(FILES
./include/Ogre_glTF.hpp
./include/Ogre_glTF_OgrePlugin.hpp
./include/Ogre_glTF_OgreResource.hpp
./include/Ogre_glTF_DLL.hpp
DESTINATION
"include")

install(TARGETS Ogre_glTF DESTINATION "bin")
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file added Media/blob.glb
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file added Media/spring.glb
Binary file not shown.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ auto glTFLoader = gltfPluginAccessor::findPlugin()->getLoader();
Ogre::Item* cesiumMan = glTFLoader->getModelData("CesiumMan.glb", glTFLoaderInterface::LoadFrom::ResourceManager).makeItem(smgr);
```
In case you cloned without `--recursive`, `cd` into the `Ogre_glTF` directory and use `git submodule update --init --recursive` to download dependencies correctly.
## Building the source code
Expand Down
7 changes: 7 additions & 0 deletions Samples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
add_subdirectory(Common)
add_subdirectory(LoadMesh)
add_subdirectory(SkinnedMesh)

add_custom_target(CopyHLMS ALL
${CMAKE_COMMAND} -E copy_directory ${OGRE_MEDIA_DIR}/Hlms ${PROJECT_BINARY_DIR}/Media/Hlms
)
2 changes: 2 additions & 0 deletions Samples/Common/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
set(SAMPLES_COMMON_HEADER_FILES SamplesCommon.h)
set(SAMPLES_COMMON_SOURCE_FILES SamplesCommon.cpp)
Empty file.
95 changes: 95 additions & 0 deletions Samples/Common/SamplesCommon.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#include <Ogre.h>
//To create workspace definitions and workspaces
#include <Compositor/OgreCompositorManager2.h>
//To use the hlms
#include <Hlms/Pbs/OgreHlmsPbs.h>
#include <OgreHlms.h>
//To load Hlms
#include <OgreArchive.h>
//To use objects
#include <OgreItem.h>
#include <OgreMesh2.h>
#include <OgreSubMesh2.h>
#include <Hlms/Pbs/OgreHlmsPbsDatablock.h>
//To play animations
#include <Animation/OgreSkeletonAnimation.h>
//To use smart pointers
#include <memory>

//The library we are trying out in this program
#include <Ogre_glTF.hpp>

#ifdef _DEBUG
const char GL_RENDER_PLUGIN[] = "RenderSystem_GL3Plus_d";
#else
const char GL_RENDER_PLUGIN[] = "RenderSystem_GL3Plus";
#endif

#ifdef _WIN32
#ifdef _DEBUG
const char D3D11_RENDER_PLUGIN[] = "RenderSystem_Direct3D11_d";
#else
const char D3D11_RENDER_PLUGIN[] = "RenderSystem_Direct3D11";
#endif
#endif

#ifdef Ogre_glTF_STATIC
#include <RenderSystems/GL3Plus/OgreGL3PlusPlugin.h>
#endif

#ifdef _WIN32
#define NOMINMAX
#include <windows.h>
#define main() WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT)
#else
#define main() main(int argc, char* argv[])
#endif

void DeclareHlmsLibrary(Ogre::String dataFolder)
{
//Make sure the string we got is a valid path
if(dataFolder.empty())
dataFolder = "./";
else if(dataFolder[dataFolder.size() - 1] != '/')
dataFolder += '/';

//For retrieval of the paths to the different folders needed
Ogre::String dataFolderPath;
Ogre::StringVector libraryFoldersPaths;

#ifdef USE_UNLIT //We are loading materials based on physics
//Get the path to all the subdirectories used by HlmsUnlit
Ogre::HlmsUnlit::getDefaultPaths(dataFolderPath, libraryFoldersPaths);

//Create the Ogre::Archive objects needed
Ogre::Archive* archiveUnlit = Ogre::ArchiveManager::getSingletonPtr()->load(dataFolder + dataFolderPath, "FileSystem", true);
Ogre::ArchiveVec archiveUnlitLibraryFolders;
for(const auto& libraryFolderPath : libraryFoldersPaths)
{
Ogre::Archive* archiveLibrary = Ogre::ArchiveManager::getSingletonPtr()->load(dataFolder + libraryFolderPath, "FileSystem", true);
archiveUnlitLibraryFolders.push_back(archiveLibrary);
}

//Create and register the unlit Hlms
Ogre::HlmsUnlit* hlmsUnlit = OGRE_NEW Ogre::HlmsUnlit(archiveUnlit, &archiveUnlitLibraryFolders);
Ogre::Root::getSingleton().getHlmsManager()->registerHlms(hlmsUnlit);
hlmsUnlit->setDebugOutputPath(false, false);
#endif

//Do the same for HlmsPbs:
Ogre::HlmsPbs::getDefaultPaths(dataFolderPath, libraryFoldersPaths);
Ogre::Archive* archivePbs = Ogre::ArchiveManager::getSingletonPtr()->load(dataFolder + dataFolderPath, "FileSystem", true);

//Get the library archive(s)
Ogre::ArchiveVec archivePbsLibraryFolders;
for(const auto& libraryFolderPath : libraryFoldersPaths)
{
Ogre::Archive* archiveLibrary = Ogre::ArchiveManager::getSingletonPtr()->load(dataFolder + libraryFolderPath, "FileSystem", true);
archivePbsLibraryFolders.push_back(archiveLibrary);
}

//Create and register
Ogre::HlmsPbs* hlmsPbs = OGRE_NEW Ogre::HlmsPbs(archivePbs, &archivePbsLibraryFolders);
Ogre::Root::getSingleton().getHlmsManager()->registerHlms(hlmsPbs);
hlmsPbs->setDebugOutputPath(false, false);
}
1 change: 1 addition & 0 deletions Samples/LoadMesh/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Ogre_glTF_config_sample(LoadMesh)
Loading

0 comments on commit f83073b

Please sign in to comment.