-
Notifications
You must be signed in to change notification settings - Fork 39
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
Handle merges where GLTF resources are in different directories #7
Conversation
std::wstring FileSystem::GetRelativePathWithTrailingSeparator(std::wstring from, std::wstring to) | ||
{ | ||
wchar_t outPath[MAX_PATH] = L""; | ||
if (PathRelativePathTo(outPath, from.c_str(), FILE_ATTRIBUTE_DIRECTORY, to.c_str(), FILE_ATTRIBUTE_DIRECTORY)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This API will only work on desktop. Can you please use std::filesystem instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, np. I'll take that as a go-ahead to replace the other two shlwapi calls (PathFindFileName, PathRemoveExtension) that were already in the code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A closer inspection reveals that msvc doesn't support std::filesystem::relative (c++17), which would be the natural replacement for PathRelativePathTo. I was really hoping to avoid re-implementing that.
glTF-Toolkit/glTF-Toolkit.vcxproj
Outdated
@@ -148,8 +148,7 @@ | |||
<GenerateDebugInformation>true</GenerateDebugInformation> | |||
</Link> | |||
<Lib> | |||
<AdditionalDependencies> | |||
</AdditionalDependencies> | |||
<AdditionalDependencies>shlwapi.lib</AdditionalDependencies> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove - this doesn't work with UWP
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
glTF-Toolkit/inc/GLTFLODUtils.h
Outdated
@@ -30,7 +30,7 @@ namespace Microsoft::glTF::Toolkit | |||
/// </summary> | |||
/// <returns>The primary GLTF Document with the inserted LOD node.</returns> | |||
/// <param name="docs">A vector of glTF documents to merge as LODs. The first element of the vector is assumed to be the primary LOD.</param> | |||
static GLTFDocument MergeDocumentsAsLODs(const std::vector<GLTFDocument>& docs); | |||
static GLTFDocument MergeDocumentsAsLODs(const std::vector<GLTFDocument>& docs, const std::vector<std::wstring>& relativePaths); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should have an option without this parameter that assumes everything is in the same directory
glTF-Toolkit/inc/GLTFLODUtils.h
Outdated
@@ -40,7 +40,7 @@ namespace Microsoft::glTF::Toolkit | |||
/// <param name="docs">A vector of glTF documents to merge as LODs. The first element of the vector is assumed to be the primary LOD.</param> | |||
/// <param name="screenCoveragePercentages">A vector with the screen coverage percentages corresponding to each LOD. If the size of this | |||
/// vector is larger than the size of <see name="docs" />, lower coverage values will cause the asset to be invisible.</param> | |||
static GLTFDocument MergeDocumentsAsLODs(const std::vector<GLTFDocument>& docs, const std::vector<double>& screenCoveragePercentages); | |||
static GLTFDocument MergeDocumentsAsLODs(const std::vector<GLTFDocument>& docs, const std::vector<std::wstring>& relativePaths, const std::vector<double>& screenCoveragePercentages); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should have an option without this parameter that assumes everything is in the same directory
glTF-Toolkit/src/GLTFLODUtils.cpp
Outdated
@@ -375,7 +386,7 @@ GLTFDocument GLTFLODUtils::MergeDocumentsAsLODs(const std::vector<GLTFDocument>& | |||
|
|||
for (size_t i = 1; i < docs.size(); i++) | |||
{ | |||
gltfPrimary = AddGLTFNodeLOD(gltfPrimary, lods, docs[i]); | |||
gltfPrimary = AddGLTFNodeLOD(gltfPrimary, lods, docs[i], relativePaths[i]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the first element of relativePaths is always ignored. Maybe the input should be only the non-lod0 relative paths?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
true, I'll make it so
This removes the shlwapi.lib dependency.
Add some documentation. Revert the changes to the tests since passing relativePaths is no longer required.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for your work on this! :)
@@ -16,6 +16,8 @@ | |||
#include <algorithm> | |||
#include <iostream> | |||
#include <set> | |||
#include <codecvt> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<codecvt> is deprecated: www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0618r0.html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general I've been using the naïve conversion from wstring to string elsewhere. I don't have a great solution for this - it's unfortunate that the GLTF SDK works with std::string everywhere, while files can have non-ansi chars.
If this conversion is the best, we should put it in a helper function and use it everywhere (probably with a unit test to ensure it does what we want)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that the GLTF spec states that "JSON must use UTF-8 encoding without BOM." my patch assumes that the std::string entries are UTF-8 encoded. I think that using codecvt way is better than the naïve approach, and agree that unit-testing this would be good.
Not sure about the timeframe for getting a c++ standard replacement for codecvt, another option would be to include a third-party lib e.g libiconv.
glTF-Toolkit/inc/pch.h
Outdated
@@ -24,6 +24,7 @@ | |||
#include <windows.h> | |||
#include <wincodec.h> | |||
#include <pathcch.h> | |||
#include <shlwapi.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider it gone.
@@ -15,6 +15,7 @@ | |||
|
|||
#include "CommandLine.h" | |||
#include "FileSystem.h" | |||
#include <filesystem> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Already included in FileSystem.h? Otherwise this should be there?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, will move it there.
No description provided.