Skip to content
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

Update glTF.CPP to 1.5.19 #34

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
31 changes: 10 additions & 21 deletions WindowsMRAssetConverter/WindowsMRAssetConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#include <GLTFSDK/GLTF.h>
#include <GLTFSDK/Deserialize.h>
#include <GLTFSDK/IStreamFactory.h>
#include <GLTFSDK/IStreamWriter.h>
#include <GLTFSDK/GLBResourceReader.h>
#include <GLTFTexturePackingUtils.h>
#include <GLTFTextureCompressionUtils.h>
Expand Down Expand Up @@ -42,34 +42,23 @@ class GLTFStreamReader : public IStreamReader
const std::wstring m_uriBase;
};

class GLBStreamFactory : public Microsoft::glTF::IStreamFactory
class GLBStreamWriter : public Microsoft::glTF::IStreamWriter
{
public:
GLBStreamFactory(const std::wstring& filename) :
m_stream(std::make_shared<std::ofstream>(filename, std::ios_base::binary | std::ios_base::out)),
m_tempStream(std::make_shared<std::stringstream>(std::ios_base::binary | std::ios_base::in | std::ios_base::out))
GLBStreamWriter(const std::wstring& filename) :
m_stream(std::make_shared<std::ofstream>(filename, std::ios_base::binary | std::ios_base::out))
{ }

std::shared_ptr<std::istream> GetInputStream(const std::string&) const override
{
throw std::logic_error("Not implemented");
}

std::shared_ptr<std::ostream> GetOutputStream(const std::string&) const override
{
return m_stream;
}

std::shared_ptr<std::iostream> GetTemporaryStream(const std::string&) const override
{
return m_tempStream;
}
private:
std::shared_ptr<std::ofstream> m_stream;
std::shared_ptr<std::stringstream> m_tempStream;
};

GLTFDocument LoadAndConvertDocumentForWindowsMR(
Document LoadAndConvertDocumentForWindowsMR(
std::wstring& inputFilePath,
AssetType inputAssetType,
const std::wstring& tempDirectory,
Expand Down Expand Up @@ -100,11 +89,11 @@ GLTFDocument LoadAndConvertDocumentForWindowsMR(
}

auto stream = std::make_shared<std::ifstream>(inputFilePath, std::ios::in);
GLTFDocument document = DeserializeJson(*stream);
Document document = Deserialize(*stream);

// Get the base path from where to read all the assets

GLTFStreamReader streamReader(FileSystem::GetBasePath(inputFilePath));
auto streamReader = std::make_shared<GLTFStreamReader>(FileSystem::GetBasePath(inputFilePath));

if (processTextures)
{
Expand Down Expand Up @@ -200,7 +189,7 @@ int wmain(int argc, wchar_t *argv[])
{
std::wcout << L"Merging LODs..." << std::endl;

std::vector<GLTFDocument> lodDocuments;
std::vector<Document> lodDocuments;
std::vector<std::wstring> lodDocumentRelativePaths;
lodDocuments.push_back(document);

Expand Down Expand Up @@ -251,8 +240,8 @@ int wmain(int argc, wchar_t *argv[])
return accessor.componentType;
};

GLTFStreamReader streamReader(FileSystem::GetBasePath(inputFilePath));
SerializeBinary(document, streamReader, std::make_unique<GLBStreamFactory>(outFilePath), accessorConversion);
auto streamReader = std::make_shared<GLTFStreamReader>(FileSystem::GetBasePath(inputFilePath));
SerializeBinary(document, streamReader, std::make_shared<GLBStreamWriter>(outFilePath), accessorConversion);

std::wcout << L"Done!" << std::endl;
std::wcout << L"Output file: " << outFilePath << std::endl;
Expand Down
8 changes: 4 additions & 4 deletions WindowsMRAssetConverter/WindowsMRAssetConverter.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -206,15 +206,15 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
<Import Project="..\packages\rapidjson.temprelease.0.0.2.20\build\native\rapidjson.temprelease.targets" Condition="Exists('..\packages\rapidjson.temprelease.0.0.2.20\build\native\rapidjson.temprelease.targets')" />
<Import Project="..\packages\directxtex_desktop_2015.2018.2.9.1\build\native\directxtex_desktop_2015.targets" Condition="Exists('..\packages\directxtex_desktop_2015.2018.2.9.1\build\native\directxtex_desktop_2015.targets')" />
<Import Project="..\packages\Microsoft.glTF.CPP.1.3.46.0\build\native\Microsoft.glTF.CPP.targets" Condition="Exists('..\packages\Microsoft.glTF.CPP.1.3.46.0\build\native\Microsoft.glTF.CPP.targets')" />
<Import Project="..\packages\directxtex_desktop_2015.2018.6.1.2\build\native\directxtex_desktop_2015.targets" Condition="Exists('..\packages\directxtex_desktop_2015.2018.6.1.2\build\native\directxtex_desktop_2015.targets')" />
<Import Project="..\packages\Microsoft.glTF.CPP.1.5.19.0\build\native\Microsoft.glTF.CPP.targets" Condition="Exists('..\packages\Microsoft.glTF.CPP.1.5.19.0\build\native\Microsoft.glTF.CPP.targets')" />
</ImportGroup>
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\rapidjson.temprelease.0.0.2.20\build\native\rapidjson.temprelease.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\rapidjson.temprelease.0.0.2.20\build\native\rapidjson.temprelease.targets'))" />
<Error Condition="!Exists('..\packages\directxtex_desktop_2015.2018.2.9.1\build\native\directxtex_desktop_2015.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\directxtex_desktop_2015.2018.2.9.1\build\native\directxtex_desktop_2015.targets'))" />
<Error Condition="!Exists('..\packages\Microsoft.glTF.CPP.1.3.46.0\build\native\Microsoft.glTF.CPP.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.glTF.CPP.1.3.46.0\build\native\Microsoft.glTF.CPP.targets'))" />
<Error Condition="!Exists('..\packages\directxtex_desktop_2015.2018.6.1.2\build\native\directxtex_desktop_2015.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\directxtex_desktop_2015.2018.6.1.2\build\native\directxtex_desktop_2015.targets'))" />
<Error Condition="!Exists('..\packages\Microsoft.glTF.CPP.1.5.19.0\build\native\Microsoft.glTF.CPP.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.glTF.CPP.1.5.19.0\build\native\Microsoft.glTF.CPP.targets'))" />
</Target>
</Project>
4 changes: 2 additions & 2 deletions WindowsMRAssetConverter/packages.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="directxtex_desktop_2015" version="2018.2.9.1" targetFramework="native" />
<package id="Microsoft.glTF.CPP" version="1.3.46.0" targetFramework="native" />
<package id="directxtex_desktop_2015" version="2018.6.1.2" targetFramework="native" />
<package id="Microsoft.glTF.CPP" version="1.5.19.0" targetFramework="native" />
<package id="rapidjson.temprelease" version="0.0.2.20" targetFramework="native" />
</packages>
49 changes: 19 additions & 30 deletions glTF-Toolkit.Test/GLBSerializerTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <CppUnitTest.h>

#include "GLTFSDK/IStreamWriter.h"
#include "GLTFSDK/GLTFConstants.h"
#include "GLTFSDK/Constants.h"
#include "GLTFSDK/Deserialize.h"
#include "GLTFSDK/GLBResourceWriter.h"
#include "GLTFSDK/GLBResourceReader.h"
Expand All @@ -23,31 +23,20 @@ using namespace Microsoft::glTF::Toolkit;

namespace Microsoft::glTF::Toolkit::Test
{
class InMemoryStreamFactory : public Microsoft::glTF::IStreamFactory
class InMemoryStream : public Microsoft::glTF::IStreamWriter
{
public:
InMemoryStreamFactory(std::shared_ptr<std::stringstream> stream) :
m_stream(stream),
m_tempStream(std::make_shared<std::stringstream>(std::ios_base::app | std::ios_base::binary | std::ios_base::in | std::ios_base::out))
InMemoryStream(std::shared_ptr<std::stringstream> stream) :
m_stream(stream)
{ }

std::shared_ptr<std::istream> GetInputStream(const std::string& uri) const override
std::shared_ptr<std::ostream> GetOutputStream(const std::string&) const
{
return uri == GLB_BUFFER_ID ? m_tempStream : m_stream;
return m_stream;
}

std::shared_ptr<std::ostream> GetOutputStream(const std::string& uri) const override
{
return uri == GLB_BUFFER_ID ? m_tempStream : m_stream;
}

std::shared_ptr<std::iostream> GetTemporaryStream(const std::string&) const override
{
return m_tempStream;
}
private:
std::shared_ptr<std::stringstream> m_stream;
std::shared_ptr<std::stringstream> m_tempStream;
};

TEST_CLASS(GLBSerializerTests)
Expand All @@ -60,24 +49,24 @@ namespace Microsoft::glTF::Toolkit::Test
return json;
}

static std::shared_ptr<GLTFDocument> ImportGLB(const std::shared_ptr<IStreamReader>& streamReader, const std::shared_ptr<std::istream>& glbStream)
static std::shared_ptr<Document> ImportGLB(const std::shared_ptr<IStreamReader>& streamReader, const std::shared_ptr<std::istream>& glbStream)
{
GLBResourceReader resourceReader(*streamReader, glbStream);
GLBResourceReader resourceReader(streamReader, glbStream);
auto json = resourceReader.GetJson();

auto doc = DeserializeJson(json);
auto doc = Deserialize(json);

return std::make_shared<GLTFDocument>(doc);
return std::make_shared<Document>(doc);
}

static std::shared_ptr<GLTFDocument> ImportGLTF(const std::shared_ptr<IStreamReader>& streamReader, const std::shared_ptr<std::istream>& stream)
static std::shared_ptr<Document> ImportGLTF(const std::shared_ptr<IStreamReader>& streamReader, const std::shared_ptr<std::istream>& stream)
{
GLTFResourceReader resourceReader(*streamReader);
GLTFResourceReader resourceReader(streamReader);
auto json = std::string(std::istreambuf_iterator<char>(*stream), std::istreambuf_iterator<char>());

auto doc = DeserializeJson(json);
auto doc = Deserialize(json);

return std::make_shared<GLTFDocument>(doc);
return std::make_shared<Document>(doc);
}

const char* c_waterBottleJson = "Resources\\gltf\\WaterBottle\\WaterBottle.gltf";
Expand All @@ -90,17 +79,17 @@ namespace Microsoft::glTF::Toolkit::Test
{
// Deserialize input json
auto inputJson = std::string(std::istreambuf_iterator<char>(*input), std::istreambuf_iterator<char>());
auto doc = DeserializeJson(inputJson);
auto doc = Deserialize(inputJson);

// Serialize GLTFDocument to GLB
TestStreamReader streamReader(TestUtils::GetAbsolutePath(c_waterBottleJson));
// Serialize Document to GLB
auto streamReader = std::make_shared<TestStreamReader>(TestUtils::GetAbsolutePath(c_waterBottleJson));
auto stream = std::make_shared<std::stringstream>(std::ios_base::app | std::ios_base::binary | std::ios_base::in | std::ios_base::out);
SerializeBinary(doc, streamReader, std::make_unique<InMemoryStreamFactory>(stream));
SerializeBinary(doc, streamReader, std::make_shared<InMemoryStream>(stream));

// Deserialize the GLB again
auto glbReader = std::make_unique<GLBResourceReader>(streamReader, stream);
auto outputJson = glbReader->GetJson();
auto outputDoc = DeserializeJson(outputJson);
auto outputDoc = Deserialize(outputJson);

// Check some structural elements
Assert::AreEqual(doc.nodes.Size(), outputDoc.nodes.Size());
Expand Down
14 changes: 7 additions & 7 deletions glTF-Toolkit.Test/GLBtoGLTFTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <CppUnitTest.h>

#include <numeric>
#include <GLTFSDK/GLTFDocument.h>
#include <GLTFSDK/Document.h>
#include <GLTFSDK/Deserialize.h>
#include <GLTFSDK/Serialize.h>
#include <GLBtoGLTF.h>
Expand Down Expand Up @@ -37,9 +37,9 @@ namespace Microsoft::glTF::Toolkit::Test
}

// Setup a GLTF document with 3 bufferviews and 2 images
GLTFDocument setupGLBDocument1()
Document setupGLBDocument1()
{
GLTFDocument glbDoc("0", {});
Document glbDoc;
Scene sc; sc.id = "0";
glbDoc.scenes.Append(std::move(sc));
Accessor acc0; acc0.bufferViewId = "0"; acc0.byteOffset = 0; acc0.id = "0";
Expand Down Expand Up @@ -88,7 +88,7 @@ namespace Microsoft::glTF::Toolkit::Test
{
TEST_METHOD(GLBtoGLTF_NoImagesJSON)
{
GLTFDocument glbDoc("0", {});
Document glbDoc;
Scene s1; s1.id = "0";
glbDoc.scenes.Append(std::move(s1));
Accessor acc; acc.bufferViewId = "0"; acc.byteOffset = 36; acc.id = "0";
Expand All @@ -112,7 +112,7 @@ namespace Microsoft::glTF::Toolkit::Test
{
glbDoc.images.Append(std::move(img));
});
GLTFDocument expectedGLTFDoc("0", {});
Document expectedGLTFDoc;
Scene s2; s2.id = "0";
expectedGLTFDoc.scenes.Append(std::move(s2));
auto actualGLTFDoc = GLBToGLTF::CreateGLTFDocument(glbDoc, "name");
Expand All @@ -125,7 +125,7 @@ namespace Microsoft::glTF::Toolkit::Test

TEST_METHOD(GLBtoGLTF_ImagesWithOffsetJSON)
{
GLTFDocument glbDoc("0", {});
Document glbDoc;
Scene sc; sc.id = "0";
glbDoc.scenes.Append(std::move(sc));
Accessor acc0; acc0.bufferViewId = "0"; acc0.byteOffset = 0; acc0.id = "0";
Expand Down Expand Up @@ -161,7 +161,7 @@ namespace Microsoft::glTF::Toolkit::Test
});
auto actualGLTFDoc = GLBToGLTF::CreateGLTFDocument(glbDoc, "test");

GLTFDocument expectedGLTFDoc("0", {});
Document expectedGLTFDoc;
Accessor exp_acc0; exp_acc0.bufferViewId = "0"; exp_acc0.byteOffset = 0; exp_acc0.id = "0";
Accessor exp_acc1; exp_acc1.bufferViewId = "1"; exp_acc1.byteOffset = 4; exp_acc1.id = "3";
expectedGLTFDoc.accessors.Append(std::move(exp_acc0));
Expand Down
Loading