-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathGLTFStreams.h
54 lines (44 loc) · 1.68 KB
/
GLTFStreams.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.
#pragma once
#include <filesystem>
#include <GLTFSDK/IStreamReader.h>
#include <GLTFSDK/IStreamWriter.h>
namespace Microsoft::glTF::Toolkit::UWP
{
class GLTFStreamReader : public IStreamReader
{
public:
GLTFStreamReader(Windows::Storage::StorageFolder^ gltfFolder)
{
m_uriBase = std::experimental::filesystem::path(gltfFolder->Path->Data());
}
virtual ~GLTFStreamReader() override {}
virtual std::shared_ptr<std::istream> GetInputStream(const std::string& filename) const override
{
std::wstring filenameW(filename.begin(), filename.end());
std::experimental::filesystem::path path(filenameW);
auto absolutePath = path.wstring();
if (path.is_relative())
{
absolutePath = (m_uriBase / path).wstring();
}
return std::make_shared<std::ifstream>(absolutePath, std::ios::binary);
}
private:
std::experimental::filesystem::path m_uriBase;
};
class GLBStreamWriter : public Microsoft::glTF::IStreamWriter
{
public:
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::ostream> GetOutputStream(const std::string&) const override
{
return m_stream;
}
private:
std::shared_ptr<std::ofstream> m_stream;
};
}