mirror of
https://github.com/syoyo/tinygltf.git
synced 2026-06-09 19:53:49 +00:00
Compare commits
15 Commits
store-json
...
mingw-fix
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
125d8e50a9 | ||
|
|
45cac78709 | ||
|
|
a9d86c1af4 | ||
|
|
2f26eddac4 | ||
|
|
a0939550ca | ||
|
|
58ab95be2f | ||
|
|
bf0e4f8e45 | ||
|
|
30f333c607 | ||
|
|
419162716e | ||
|
|
9533c352a1 | ||
|
|
9ff3d93084 | ||
|
|
aea514a975 | ||
|
|
05a4456948 | ||
|
|
fb256609f2 | ||
|
|
5cecef2b92 |
11
.travis.yml
11
.travis.yml
@@ -31,6 +31,17 @@ matrix:
|
||||
- addons: *1
|
||||
compiler: clang
|
||||
env: COMPILER_VERSION=3.9 BUILD_TYPE=Debug CFLAGS="-O0" CXXFLAGS="-O0"
|
||||
- addons: &3
|
||||
apt:
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
packages:
|
||||
- g++-4.8
|
||||
compiler: gcc
|
||||
env: COMPILER_VERSION=4.8 BUILD_TYPE=Debug
|
||||
- addons: *3
|
||||
compiler: gcc
|
||||
env: COMPILER_VERSION=4.8 BUILD_TYPE=Release
|
||||
|
||||
before_install:
|
||||
- ./.travis-before-install.sh
|
||||
|
||||
@@ -4,14 +4,21 @@ PROJECT (tinygltf)
|
||||
|
||||
SET(CMAKE_CXX_STANDARD 11)
|
||||
|
||||
ADD_EXECUTABLE ( loader_example
|
||||
loader_example.cc
|
||||
)
|
||||
option(TINYGLTF_BUILD_EXAMPLES "Build examples" ON)
|
||||
|
||||
ADD_SUBDIRECTORY ( examples/gltfutil )
|
||||
ADD_SUBDIRECTORY ( examples/glview )
|
||||
ADD_SUBDIRECTORY ( examples/validator )
|
||||
if (TINYGLTF_BUILD_EXAMPLES)
|
||||
ADD_EXECUTABLE ( loader_example
|
||||
loader_example.cc
|
||||
)
|
||||
|
||||
ADD_SUBDIRECTORY ( examples/gltfutil )
|
||||
ADD_SUBDIRECTORY ( examples/glview )
|
||||
ADD_SUBDIRECTORY ( examples/validator )
|
||||
endif (TINYGLTF_BUILD_EXAMPLES)
|
||||
|
||||
#
|
||||
# TinuGLTF is a header-only library, so no library build. just install header files.
|
||||
#
|
||||
INSTALL ( FILES
|
||||
json.hpp
|
||||
stb_image.h
|
||||
|
||||
@@ -75,9 +75,10 @@ In extension(`ExtensionMap`), JSON number value is parsed as int or float(number
|
||||
* GLTF loader plugin for OGRE 2.1. Support for PBR materials via HLMS/PBS https://github.com/Ybalrid/Ogre_glTF
|
||||
* [TinyGltfImporter](http://doc.magnum.graphics/magnum/classMagnum_1_1Trade_1_1TinyGltfImporter.html) plugin for [Magnum](https://github.com/mosra/magnum), a lightweight and modular C++11/C++14 graphics middleware for games and data visualization.
|
||||
* [Diligent Engine](https://github.com/DiligentGraphics/DiligentEngine) - A modern cross-platform low-level graphics library and rendering framework
|
||||
* Lighthouse 2: a rendering framework for real-time ray tracing / path tracing experiments. https://github.com/jbikker/lighthouse2
|
||||
* Lighthouse 2: a rendering framework for real-time ray tracing / path tracing experiments. https://github.com/jbikker/lighthouse2
|
||||
* [QuickLook GLTF](https://github.com/toshiks/glTF-quicklook) - quicklook plugin for macos. Also SceneKit wrapper for tinygltf.
|
||||
* [GlslViewer](https://github.com/patriciogonzalezvivo/glslViewer) - live GLSL coding for MacOS and Linux
|
||||
* [Vulkan-Samples](https://github.com/KhronosGroup/Vulkan-Samples) - The Vulkan Samples is collection of resources to help you develop optimized Vulkan applications.
|
||||
* Your projects here! (Please send PR)
|
||||
|
||||
## TODOs
|
||||
|
||||
97
tiny_gltf.h
97
tiny_gltf.h
@@ -1415,6 +1415,7 @@ class TinyGLTF {
|
||||
#include <algorithm>
|
||||
//#include <cassert>
|
||||
#ifndef TINYGLTF_NO_FS
|
||||
#include <cstdio>
|
||||
#include <fstream>
|
||||
#endif
|
||||
#include <sstream>
|
||||
@@ -1541,6 +1542,13 @@ class TinyGLTF {
|
||||
#undef NOMINMAX
|
||||
#endif
|
||||
|
||||
#if defined(__GLIBCXX__) // mingw
|
||||
|
||||
#include <ext/stdio_filebuf.h> // fstream (all sorts of IO stuff) + stdio_filebuf (=streambuf)
|
||||
#include <fcntl.h> // _O_RDONLY
|
||||
|
||||
#endif
|
||||
|
||||
#elif !defined(__ANDROID__)
|
||||
#include <wordexp.h>
|
||||
#endif
|
||||
@@ -2364,6 +2372,15 @@ bool WriteImageData(const std::string *basepath, const std::string *filename,
|
||||
|
||||
void TinyGLTF::SetFsCallbacks(FsCallbacks callbacks) { fs = callbacks; }
|
||||
|
||||
#ifdef _WIN32
|
||||
static inline std::wstring UTF8ToWchar(const std::string &str) {
|
||||
int wstr_size = MultiByteToWideChar(CP_UTF8, 0, str.data(), (int)str.size(), nullptr, 0);
|
||||
std::wstring wstr(wstr_size, 0);
|
||||
MultiByteToWideChar(CP_UTF8, 0, str.data(), (int)str.size(), &wstr[0], (int)wstr.size());
|
||||
return wstr;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef TINYGLTF_NO_FS
|
||||
// Default implementations of filesystem functions
|
||||
|
||||
@@ -2383,11 +2400,20 @@ bool FileExists(const std::string &abs_filename, void *) {
|
||||
}
|
||||
#else
|
||||
#ifdef _WIN32
|
||||
FILE *fp;
|
||||
#if defined(_MSC_VER) || defined(__GLIBCXX__)
|
||||
FILE *fp = nullptr;
|
||||
errno_t err = _wfopen_s(&fp, UTF8ToWchar(abs_filename).c_str(), L"rb");
|
||||
if (err != 0) {
|
||||
return false;
|
||||
}
|
||||
#else
|
||||
FILE *fp = nullptr;
|
||||
errno_t err = fopen_s(&fp, abs_filename.c_str(), "rb");
|
||||
if (err != 0) {
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
#else
|
||||
FILE *fp = fopen(abs_filename.c_str(), "rb");
|
||||
#endif
|
||||
@@ -2479,7 +2505,19 @@ bool ReadWholeFile(std::vector<unsigned char> *out, std::string *err,
|
||||
return false;
|
||||
}
|
||||
#else
|
||||
#ifdef _WIN32
|
||||
#if defined(__GLIBCXX__) // mingw
|
||||
int file_descriptor = _wopen(UTF8ToWchar(filepath).c_str(), _O_RDONLY | _O_BINARY);
|
||||
__gnu_cxx::stdio_filebuf<char> wfile_buf(file_descriptor, std::ios_base::in);
|
||||
std::istream f(&wfile_buf);
|
||||
#elif defined(_MSC_VER)
|
||||
std::ifstream f(UTF8ToWchar(filepath).c_str(), std::ifstream::binary);
|
||||
#else // clang?
|
||||
std::ifstream f(filepath.c_str(), std::ifstream::binary);
|
||||
#endif
|
||||
#else
|
||||
std::ifstream f(filepath.c_str(), std::ifstream::binary);
|
||||
#endif
|
||||
if (!f) {
|
||||
if (err) {
|
||||
(*err) += "File open error : " + filepath + "\n";
|
||||
@@ -2507,7 +2545,6 @@ bool ReadWholeFile(std::vector<unsigned char> *out, std::string *err,
|
||||
out->resize(sz);
|
||||
f.read(reinterpret_cast<char *>(&out->at(0)),
|
||||
static_cast<std::streamsize>(sz));
|
||||
f.close();
|
||||
|
||||
return true;
|
||||
#endif
|
||||
@@ -2515,7 +2552,19 @@ bool ReadWholeFile(std::vector<unsigned char> *out, std::string *err,
|
||||
|
||||
bool WriteWholeFile(std::string *err, const std::string &filepath,
|
||||
const std::vector<unsigned char> &contents, void *) {
|
||||
#ifdef _WIN32
|
||||
#if defined(__GLIBCXX__) // mingw
|
||||
int file_descriptor = _wopen(UTF8ToWchar(filepath).c_str(), _O_WRONLY | _O_BINARY);
|
||||
__gnu_cxx::stdio_filebuf<char> wfile_buf(file_descriptor, std::ios_base::in);
|
||||
std::ostream f(&wfile_buf);
|
||||
#elif defined(_MSC_VER)
|
||||
std::ofstream f(UTF8ToWchar(filepath).c_str(), std::ofstream::binary);
|
||||
#else // clang?
|
||||
std::ofstream f(filepath.c_str(), std::ofstream::binary);
|
||||
#endif
|
||||
#else
|
||||
std::ofstream f(filepath.c_str(), std::ofstream::binary);
|
||||
#endif
|
||||
if (!f) {
|
||||
if (err) {
|
||||
(*err) += "File open error for writing : " + filepath + "\n";
|
||||
@@ -2532,7 +2581,6 @@ bool WriteWholeFile(std::string *err, const std::string &filepath,
|
||||
return false;
|
||||
}
|
||||
|
||||
f.close();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -6232,11 +6280,25 @@ static void SerializeGltfBufferData(const std::vector<unsigned char> &data,
|
||||
|
||||
static bool SerializeGltfBufferData(const std::vector<unsigned char> &data,
|
||||
const std::string &binFilename) {
|
||||
#ifdef _WIN32
|
||||
#if defined(__GLIBCXX__) // mingw
|
||||
int file_descriptor = _wopen(UTF8ToWchar(binFilename).c_str(), _O_WRONLY | _O_BINARY);
|
||||
__gnu_cxx::stdio_filebuf<char> wfile_buf(file_descriptor, std::ios_base::in);
|
||||
std::ostream output(&wfile_buf);
|
||||
if (!wfile_buf.is_open()) return false;
|
||||
#elif defined(_MSC_VER)
|
||||
std::ofstream output(UTF8ToWchar(binFilename).c_str(), std::ofstream::binary);
|
||||
if (!output.is_open()) return false;
|
||||
#else
|
||||
std::ofstream output(binFilename.c_str(), std::ofstream::binary);
|
||||
if (!output.is_open()) return false;
|
||||
#endif
|
||||
#else
|
||||
std::ofstream output(binFilename.c_str(), std::ofstream::binary);
|
||||
if (!output.is_open()) return false;
|
||||
#endif
|
||||
output.write(reinterpret_cast<const char *>(&data[0]),
|
||||
std::streamsize(data.size()));
|
||||
output.close();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -6597,7 +6659,8 @@ static void SerializeGltfMaterial(Material &material, json &o) {
|
||||
SerializeStringProperty("alphaMode", material.alphaMode, o);
|
||||
}
|
||||
|
||||
JsonAddMember(o, "doubleSided", json(material.doubleSided));
|
||||
if(material.doubleSided != false)
|
||||
JsonAddMember(o, "doubleSided", json(material.doubleSided));
|
||||
|
||||
if (material.normalTexture.index > -1) {
|
||||
json texinfo;
|
||||
@@ -7090,8 +7153,22 @@ static bool WriteGltfStream(std::ostream &stream, const std::string &content) {
|
||||
|
||||
static bool WriteGltfFile(const std::string &output,
|
||||
const std::string &content) {
|
||||
#ifdef _WIN32
|
||||
#if defined(_MSC_VER)
|
||||
std::ofstream gltfFile(UTF8ToWchar(output).c_str());
|
||||
#elif defined(__GLIBCXX__)
|
||||
int file_descriptor = _wopen(UTF8ToWchar(output).c_str(), _O_WRONLY | _O_BINARY);
|
||||
__gnu_cxx::stdio_filebuf<char> wfile_buf(file_descriptor, std::ios_base::in);
|
||||
std::ostream gltfFile(&wfile_buf);
|
||||
if (!wfile_buf.is_open()) return false;
|
||||
#else
|
||||
std::ofstream gltfFile(output.c_str());
|
||||
if (!gltfFile.is_open()) return false;
|
||||
#endif
|
||||
#else
|
||||
std::ofstream gltfFile(output.c_str());
|
||||
if (!gltfFile.is_open()) return false;
|
||||
#endif
|
||||
return WriteGltfStream(gltfFile, content);
|
||||
}
|
||||
|
||||
@@ -7127,7 +7204,17 @@ static void WriteBinaryGltfStream(std::ostream &stream,
|
||||
|
||||
static void WriteBinaryGltfFile(const std::string &output,
|
||||
const std::string &content) {
|
||||
#ifdef _WIN32
|
||||
#if defined(_MSC_VER)
|
||||
std::ofstream gltfFile(UTF8ToWchar(output).c_str(), std::ios::binary);
|
||||
#elif defined(__GLIBCXX__)
|
||||
std::ofstream gltfFile(output.c_str(), std::ios::binary);
|
||||
#else
|
||||
std::ofstream gltfFile(output.c_str(), std::ios::binary);
|
||||
#endif
|
||||
#else
|
||||
std::ofstream gltfFile(output.c_str(), std::ios::binary);
|
||||
#endif
|
||||
WriteBinaryGltfStream(gltfFile, content);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user