Skip to content
Snippets Groups Projects
Commit 1071d0cd authored by Jonas Johan Solsvik's avatar Jonas Johan Solsvik
Browse files

Started work on integratiing tiny_obj_loader into the internal datastructure

parent 138cd295
No related branches found
No related tags found
No related merge requests found
...@@ -10,6 +10,7 @@ CMakeSettings.json ...@@ -10,6 +10,7 @@ CMakeSettings.json
# ASSETS WHITELIST # ASSETS WHITELIST
# #
# * Whitelist assets we want to keep # * Whitelist assets we want to keep
assets/*
assets/textures/* assets/textures/*
!assets/textures/.gitkeep !assets/textures/.gitkeep
...@@ -20,6 +21,12 @@ assets/shaders/* ...@@ -20,6 +21,12 @@ assets/shaders/*
assets/materials/* assets/materials/*
!assets/materials/.gitkeep !assets/materials/.gitkeep
assets/objs/*
!assets/objs/.gitkeep
!assets/objs/rungholt/.gitkeep
!assets/objs/cube/.gitkeep
!assets/objs/moriknob/.gitkeep
assets/models/* assets/models/*
!assets/models/.gitkeep !assets/models/.gitkeep
......
...@@ -28,6 +28,7 @@ set(GLFW_BUILD_DOCS 0) ...@@ -28,6 +28,7 @@ set(GLFW_BUILD_DOCS 0)
# link to later on. # link to later on.
add_subdirectory("${SRCDIR}/lib/glfw-3.2.1") add_subdirectory("${SRCDIR}/lib/glfw-3.2.1")
add_subdirectory("${SRCDIR}/lib/SOIL-1.07") add_subdirectory("${SRCDIR}/lib/SOIL-1.07")
add_subdirectory("${SRCDIR}/lib/tiny_obj_loader")
# Configure main executeable # Configure main executeable
...@@ -96,6 +97,11 @@ configure_directory(${SRCDIR}/assets/shaders ${BINDIR}/assets/shaders) ...@@ -96,6 +97,11 @@ configure_directory(${SRCDIR}/assets/shaders ${BINDIR}/assets/shaders)
configure_directory(${SRCDIR}/assets/models ${BINDIR}/assets/models) configure_directory(${SRCDIR}/assets/models ${BINDIR}/assets/models)
configure_directory(${SRCDIR}/assets/textures ${BINDIR}/assets/textures) configure_directory(${SRCDIR}/assets/textures ${BINDIR}/assets/textures)
configure_directory(${SRCDIR}/assets/objs/cube ${BINDIR}/assets/objs/cube)
configure_directory(${SRCDIR}/assets/objs/house ${BINDIR}/assets/objs/house)
configure_directory(${SRCDIR}/assets/objs/moriknob ${BINDIR}/assets/objs/moriknob)
configure_file(${SRCDIR}/tool/discover.py ${BINDIR}/tool/discover.py COPYONLY) configure_file(${SRCDIR}/tool/discover.py ${BINDIR}/tool/discover.py COPYONLY)
configure_file(${SRCDIR}/config.yml ${BINDIR}/config.yml COPYONLY) configure_file(${SRCDIR}/config.yml ${BINDIR}/config.yml COPYONLY)
...@@ -131,6 +137,7 @@ target_link_libraries( ...@@ -131,6 +137,7 @@ target_link_libraries(
PRIVATE glfw ${glfw_LIBRARIES} PRIVATE glfw ${glfw_LIBRARIES}
PRIVATE glew32 PRIVATE glew32
PRIVATE SOIL PRIVATE SOIL
PRIVATE tinyobjloader
) )
################################ ################################
...@@ -162,6 +169,7 @@ target_link_libraries( ...@@ -162,6 +169,7 @@ target_link_libraries(
PRIVATE ${GLEW_LIBRARY} PRIVATE ${GLEW_LIBRARY}
PRIVATE glfw PRIVATE glfw
PRIVATE SOIL PRIVATE SOIL
PRIVATE tinyobjloader
) )
endif() endif()
......
...@@ -45,6 +45,7 @@ public: ...@@ -45,6 +45,7 @@ public:
static char MaterialsFolder[StrSize]; static char MaterialsFolder[StrSize];
static char ModelsFolder[StrSize]; static char ModelsFolder[StrSize];
static char ScenesFolder[StrSize]; static char ScenesFolder[StrSize];
static char ObjsFolder[StrSize];
static unsigned int MAX_LIGHTS; //inject it into shaders static unsigned int MAX_LIGHTS; //inject it into shaders
static GLFWwindow* window; static GLFWwindow* window;
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#include <string> #include <string>
#include <unordered_map> #include <unordered_map>
#include <tiny_obj_loader/tiny_obj_loader.h>
#include <overkill/Config.hpp> #include <overkill/Config.hpp>
#include <overkill/Texture.hpp> #include <overkill/Texture.hpp>
#include <overkill/Material.hpp> #include <overkill/Material.hpp>
...@@ -11,6 +13,8 @@ ...@@ -11,6 +13,8 @@
#include <overkill/Model.hpp> #include <overkill/Model.hpp>
#include <overkill/Parser.hpp> #include <overkill/Parser.hpp>
namespace overkill namespace overkill
{ {
...@@ -41,6 +45,7 @@ public: ...@@ -41,6 +45,7 @@ public:
// <summary> Load all model data onto GPU memory. // <summary> Load all model data onto GPU memory.
// Keep model metadata on CPU </summary> // Keep model metadata on CPU </summary>
static void load(); static void load();
static auto loadOBJ(const std::vector<tinyobj::material_t>& materials) -> C::Err;
static void reload(); static void reload();
static auto getIdByTag(const C::Tag& materialTag) -> C::ID; static auto getIdByTag(const C::Tag& materialTag) -> C::ID;
static auto getByTag(const C::Tag& materialTag) -> const Material&; static auto getByTag(const C::Tag& materialTag) -> const Material&;
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#include <string> #include <string>
#include <unordered_map> #include <unordered_map>
#include <tiny_obj_loader/tiny_obj_loader.h>
#include <overkill/Config.hpp> #include <overkill/Config.hpp>
#include <overkill/Model.hpp> #include <overkill/Model.hpp>
#include <overkill/ShaderSystem.hpp> #include <overkill/ShaderSystem.hpp>
...@@ -27,6 +29,9 @@ public: ...@@ -27,6 +29,9 @@ public:
// <summary> Load all model data onto GPU memory. // <summary> Load all model data onto GPU memory.
// Keep model metadata on CPU </summary> // Keep model metadata on CPU </summary>
static void load(); static void load();
static auto loadOBJ(const tinyobj::attrib_t& attributes,
const std::vector<tinyobj::shape_t>& shapes,
const std::vector<tinyobj::material_t>& materials) -> C::Err;
static void reload(); static void reload();
static void clean(); static void clean();
static auto getIdByTag(const C::Tag& modeltag) -> C::ID; static auto getIdByTag(const C::Tag& modeltag) -> C::ID;
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#include <string> #include <string>
#include <unordered_map> #include <unordered_map>
#include <tiny_obj_loader/tiny_obj_loader.h>
#include <overkill/Config.hpp> #include <overkill/Config.hpp>
#include <overkill/Texture.hpp> #include <overkill/Texture.hpp>
#include <overkill/Watcher.hpp> #include <overkill/Watcher.hpp>
...@@ -25,6 +27,7 @@ public: ...@@ -25,6 +27,7 @@ public:
// <summary> Load all texture data onto GPU memory. // <summary> Load all texture data onto GPU memory.
// Keep model metadata on CPU </summary> // Keep model metadata on CPU </summary>
static void load(); static void load();
static auto loadOBJ(const std::vector<tinyobj::material_t>& materials) -> C::Err;
static void clean(); static void clean();
static auto getIdByTag(const C::Tag& textureTag) -> C::ID; static auto getIdByTag(const C::Tag& textureTag) -> C::ID;
static auto getByTag(const C::Tag& textureTag) -> const Texture&; static auto getByTag(const C::Tag& textureTag) -> const Texture&;
......
...@@ -27,6 +27,7 @@ char C::ShadersFolder[C::StrSize] = "assets/shaders"; ...@@ -27,6 +27,7 @@ char C::ShadersFolder[C::StrSize] = "assets/shaders";
char C::MaterialsFolder[C::StrSize] = "assets/materials"; char C::MaterialsFolder[C::StrSize] = "assets/materials";
char C::ModelsFolder[C::StrSize] = "assets/models"; char C::ModelsFolder[C::StrSize] = "assets/models";
char C::ScenesFolder[C::StrSize] = "assets/scenes"; char C::ScenesFolder[C::StrSize] = "assets/scenes";
char C::ObjsFolder[C::StrSize] = "assets/objs";
std::string C::PythonPath = "python3"; std::string C::PythonPath = "python3";
......
...@@ -272,6 +272,15 @@ void Init::Config() ...@@ -272,6 +272,15 @@ void Init::Config()
LOG_INFO("%s: %s",std::string(key).data(), C::ScenesFolder); LOG_INFO("%s: %s",std::string(key).data(), C::ScenesFolder);
} }
// char C::ObjsFolder[MaxString]
if (auto[key, ObjsFolder, err] = p.keyString("ObjsFolder"); err) {
return;
} else {
strcpy(C::ObjsFolder, std::string(ObjsFolder).data());
LOG_INFO("%s: %s",std::string(key).data(), C::ObjsFolder);
}
// //
// SHADERS CONFIG // SHADERS CONFIG
......
...@@ -153,4 +153,14 @@ auto MaterialSystem::makeMaterial(const std::string& materialString, Material* o ...@@ -153,4 +153,14 @@ auto MaterialSystem::makeMaterial(const std::string& materialString, Material* o
return 0; return 0;
} }
auto MaterialSystem::loadOBJ(const std::vector<tinyobj::material_t>& /*materials*/) -> C::Err
{
return 0;
}
} }
...@@ -273,4 +273,15 @@ void ModelSystem::load() ...@@ -273,4 +273,15 @@ void ModelSystem::load()
} }
auto ModelSystem::loadOBJ(const tinyobj::attrib_t& /*attributes*/,
const std::vector<tinyobj::shape_t>& /*shapes*/,
const std::vector<tinyobj::material_t>& /*materials*/) -> C::Err
{
return 0;
}
} // ::overkill } // ::overkill
...@@ -117,4 +117,14 @@ auto TextureSystem::makeTexture(const std::string& filepath, Texture* outTexture ...@@ -117,4 +117,14 @@ auto TextureSystem::makeTexture(const std::string& filepath, Texture* outTexture
return 0; return 0;
} }
auto TextureSystem::loadOBJ(const std::vector<tinyobj::material_t>& /*materials*/) -> C::Err
{
return 0;
}
} }
...@@ -35,6 +35,8 @@ ...@@ -35,6 +35,8 @@
using namespace overkill; using namespace overkill;
void loadOBJFiles();
int main(int argc, char** args) int main(int argc, char** args)
{ {
if (argc > 2) if (argc > 2)
...@@ -63,6 +65,8 @@ int main(int argc, char** args) ...@@ -63,6 +65,8 @@ int main(int argc, char** args)
MaterialSystem::load(); MaterialSystem::load();
ModelSystem::load(); ModelSystem::load();
loadOBJFiles();
LOG_DEBUG("Argc %d, args[1] %s", argc, args[1]); LOG_DEBUG("Argc %d, args[1] %s", argc, args[1]);
...@@ -113,3 +117,67 @@ int main(int argc, char** args) ...@@ -113,3 +117,67 @@ int main(int argc, char** args)
glfwTerminate(); glfwTerminate();
return 0; return 0;
} }
void loadOBJFiles()
{
auto getBaseDir = [](const std::string& filepath) -> std::string
{
if (filepath.find_last_of("/\\") != std::string::npos) {
return filepath.substr(0, filepath.find_last_of("/\\")+1);
}
return ".";
};
std::vector<FileEvent> fevents = Watcher::popEvents("discovered", "objs");
LOG_DEBUG("Loading objs! count: %lu", static_cast<unsigned long>(fevents.size()));
for (auto e: fevents)
{
std::string objFilepath = C::ObjsFolder + ("/" + e.tag + "/" + e.tag + "." + e.extension);
std::string objBasedir = getBaseDir(objFilepath);
LOG_DEBUG("Obj from file: %s", objFilepath.data());
auto attributes = tinyobj::attrib_t{};
auto shapes = std::vector<tinyobj::shape_t>{};
auto materials = std::vector<tinyobj::material_t>{};
auto err = std::string{};
auto success = tinyobj::LoadObj(
&attributes,
&shapes,
&materials,
&err,
objFilepath.c_str(),
objBasedir.c_str() );
if (!err.empty()) {
LOG_ERROR("ERR: %s\n", err.c_str());
}
if (!success) {
LOG_ERROR("!success");
}
if (auto err = TextureSystem::loadOBJ(materials); err) {
LOG_ERROR("TextureSystem failed to load OBJ");
}
if (auto err = MaterialSystem::loadOBJ(materials); err) {
LOG_ERROR("MaterialSystem failed to load OBJ");
}
if (auto err = ModelSystem::loadOBJ(attributes, shapes, materials); err) {
LOG_ERROR("ModelSystem failed to load OBJ");
}
}
}
...@@ -23,6 +23,22 @@ def scan_collection(collection, fileregex): ...@@ -23,6 +23,22 @@ def scan_collection(collection, fileregex):
fname.split(".")[0], fname.split(".")[0],
fname.split(".")[1]) fname.split(".")[1])
def scan_collection_recursive(collection, fileregex):
filenames = glob.glob("assets/" + collection + "/"+ fileregex, recursive=True)
for fname in filenames:
fname = os.path.basename(fname)
if "." not in fname:
continue
fname = os.path.basename(fname)
printToPipe("discovered",
collection,
fname.split(".")[0],
fname.split(".")[1])
if __name__ == "__main__": if __name__ == "__main__":
...@@ -32,3 +48,4 @@ if __name__ == "__main__": ...@@ -32,3 +48,4 @@ if __name__ == "__main__":
scan_collection("materials", "*.yml"); scan_collection("materials", "*.yml");
scan_collection("models", "*.yml"); scan_collection("models", "*.yml");
scan_collection("scenes", "*.yml"); scan_collection("scenes", "*.yml");
scan_collection_recursive("objs", "**/*.obj");
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment