Skip to content

Avkhokhlov/material saving #199

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions BaikalIO/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ set(SOURCES
scene_io.h
scene_test_io.cpp
scene_obj_io.cpp
filesystem.h
)

if (UNIX AND NOT APPLE)
Expand All @@ -25,13 +26,18 @@ endif (BAIKAL_ENABLE_FBX)
add_library(BaikalIO SHARED ${SOURCES})

target_compile_definitions(BaikalIO PRIVATE BAIKAL_EXPORT_API)
target_compile_features(BaikalIO PRIVATE cxx_std_14)
target_compile_features(BaikalIO PRIVATE cxx_std_17)
target_link_libraries(BaikalIO PUBLIC Baikal OpenImageIO::OpenImageIO)

if (UNIX AND NOT APPLE)
if (UNIX OR APPLE)
target_link_libraries(BaikalIO PUBLIC stdc++fs)
endif ()

if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lstdc++fs -lc++experimental")
target_compile_options(BaikalIO PUBLIC -stdlib=libc++)
endif()

target_include_directories(BaikalIO PUBLIC "${Baikal_SOURCE_DIR}/BaikalIO" "${Baikal_SOURCE_DIR}/3rdparty/tinyobjloader/include")

if (BAIKAL_ENABLE_FBX)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#if (defined(__GNUC__) && (__GNUC__ < 8))
#if (defined(__GNUC__) && (__GNUC__ < 8)) || (defined(__clang__) && (__clang_major__ < 7))
#include <experimental/filesystem>
#else
#include <filesystem>
Expand All @@ -16,4 +16,9 @@ namespace std
{
namespace filesystem = experimental::filesystem::v1;
}
#elif (defined(__clang__))
namespace std
{
namespace filesystem = experimental::filesystem;
}
#endif
9 changes: 5 additions & 4 deletions BaikalIO/material_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "SceneGraph/uberv2material.h"
#include "SceneGraph/inputmaps.h"

#include "filesystem.h"
#include "image_io.h"

#include "XML/tinyxml2.h"
Expand Down Expand Up @@ -486,18 +487,18 @@ namespace Baikal
}
else
{
std::string texture_name = texture->GetName();
std::filesystem::path texture_name = texture->GetName();
if (texture_name.empty())
{
std::ostringstream oss;
oss << (std::uint64_t)texture.get() << ".jpg";
texture_name = oss.str();
io.SaveImage(m_base_path + texture_name, texture);
io.SaveImage(m_base_path + texture_name.string(), texture);
}

m_tex2name[texture] = texture_name;
m_tex2name[texture] = texture_name.filename().string();

printer.PushAttribute("value", texture_name.c_str());
printer.PushAttribute("value", m_tex2name[texture].c_str());
}
printer.CloseElement();
break;
Expand Down
7 changes: 7 additions & 0 deletions BaikalStandalone/Application/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -918,6 +918,13 @@ namespace Baikal
}
}

if (ImGui::Button("Save materials"))
{
auto material_io = Baikal::MaterialIo::CreateMaterialIoXML();
material_io->SaveMaterialsFromScene(m_settings.path + "/materials.xml", *m_cl->GetScene());
material_io->SaveIdentityMapping(m_settings.path + "/mapping.xml", *m_cl->GetScene());
}

if (m_settings.time_benchmark && m_settings.samplecount > 511)
{
m_settings.time_benchmark = false;
Expand Down