Compare commits

..

16 Commits

Author SHA1 Message Date
Syoyo Fujita
91da299729 Fix inequality. Should allow 0 for bufferView. 2020-07-15 13:52:39 +09:00
Syoyo Fujita
50ae8a31a8 Merge branch 'master' of github.com:syoyo/tinygltf 2020-07-14 22:05:28 +09:00
Syoyo Fujita
0af0435ef1 Renamed directory name. 2020-07-14 22:04:26 +09:00
Syoyo Fujita
7c342533e9 Add scene date for issue 280 2020-07-14 22:02:51 +09:00
Syoyo Fujita
7842c1276f Merge pull request #281 from rbsheth/sparse_morph_fix
Fix sparse morph targets
2020-07-14 15:35:37 +09:00
Rahul Sheth
125e4a2033 Fix sparse morph targets 2020-07-13 13:56:50 -04:00
Syoyo Fujita
c9d6c5b9b4 Merge pull request #278 from rbsheth/string_fix
Use std::string for GetKey function
2020-07-11 03:41:11 +09:00
Rahul Sheth
96a8b2c69b Run clang-format 2020-07-10 14:27:46 -04:00
Rahul Sheth
01d54380ac Use std::string instead of const char* for GetKey function 2020-07-10 14:27:37 -04:00
Syoyo Fujita
6cd8fdb2c8 Merge pull request #274 from daemyung/dxview
Add dxview
2020-07-04 16:48:08 +09:00
daemyung jang
fe01af2f01 Add README.md for dxview 2020-07-04 09:24:00 +09:00
daemyung jang
efdd2b04dc Add dxview 2020-07-04 01:29:41 +09:00
Syoyo Fujita
2e642b3322 Merge pull request #273 from daemyung/dxview
Initialize member variables
2020-07-03 15:38:46 +09:00
daemyung jang
1739d025a9 Initialize member variables 2020-07-03 13:27:39 +09:00
Syoyo
39418e5728 Disable blank issue. 2020-06-26 02:01:16 +09:00
Syoyo Fujita
5622d2762d Update issue templates 2020-06-19 16:31:37 +09:00
13 changed files with 1743 additions and 205 deletions

1
.github/ISSUE_TEMPLATE/config.yml vendored Normal file
View File

@@ -0,0 +1 @@
blank_issues_enabled: false

30
.github/ISSUE_TEMPLATE/issue-report.md vendored Normal file
View File

@@ -0,0 +1,30 @@
---
name: Issue report
about: Create a report
title: ''
labels: ''
assignees: ''
---
**Describe the issue**
A clear and concise description of what the issue is.
**To Reproduce**
- OS
- Compiler, compiler version, compile options
- Please attach minimal and reproducible .glTF file if you got an issue related to .glTF data
**Expected behaviour**
A clear and concise description of what you expected to happen.
**Screenshots**
If applicable, add screenshots to help explain your problem.
**Additional context**
Add any other context about the problem here.

View File

@@ -153,7 +153,6 @@ if (!ret) {
## Compile options
* `TINYGLTF_ENABLE_SERIALIZER` : Enable glTF serialization feature.
* `TINYGLTF_NOEXCEPTION` : Disable C++ exception in JSON parsing. You can use `-fno-exceptions` or by defining the symbol `JSON_NOEXCEPTION` and `TINYGLTF_NOEXCEPTION` to fully remove C++ exception codes when compiling TinyGLTF.
* `TINYGLTF_NO_STB_IMAGE` : Do not load images with stb_image. Instead use `TinyGLTF::SetImageLoader(LoadimageDataFunction LoadImageData, void *user_data)` to set a callback for loading images.
* `TINYGLTF_NO_STB_IMAGE_WRITE` : Do not write images with stb_image_write. Instead use `TinyGLTF::SetImageWriter(WriteimageDataFunction WriteImageData, void *user_data)` to set a callback for writing images.

View File

@@ -0,0 +1,36 @@
cmake_minimum_required(VERSION 3.5)
project(dxview)
find_package(glfw3 CONFIG REQUIRED)
find_package(spdlog CONFIG REQUIRED)
add_executable(dxview
src/Viewer.h
src/Viewer.cc
src/dxview.cc
)
target_include_directories(dxview
PRIVATE
../../
)
target_compile_definitions(dxview
PRIVATE
DXVIEW_SWAP_CHAIN_BUFFER_COUNT=3
DXVIEW_RES_DIR=L"${PROJECT_SOURCE_DIR}/res"
)
target_link_libraries(dxview
PRIVATE
dxgi
d3dcompiler
d3d12
glfw
spdlog::spdlog
)
set_target_properties(dxview
PROPERTIES
CXX_STANDARD 17
)

37
examples/dxview/README.md Normal file
View File

@@ -0,0 +1,37 @@
# DirectX glTF Viewer
## Overview
This project was motivated by a lack of sample code demonstrating the graphics API agnostic nature of the glTF specification. The sample code is written using modern C++ and DirectX 12 for the client application.
## Features
* [x] DirectX 12
* [ ] Loader
* [ ] Animation
* [ ] Morph Target
* [ ] Physical Base Rendering
* [ ] Environment Map
## Dependencies
* [CMake](https://github.com/Kitware/CMake)
* [Vcpkg](https://github.com/Microsoft/vcpkg)
* [GLFW](https://github.com/glfw/glfw)
* [spdlog](https://github.com/gabime/spdlog)
## Building
### Install dependencies
```
vcpkg install glfw3:x64-windows
vcpkg install spdlog:x64-windows
```
### Generate Project Files
```
mkdir build
cmake . -B build -DCMAKE_TOOLCHAIN_FILE=${VCPKG_DIR}/script/buildsystem/vcpkg.cmake
```

View File

@@ -0,0 +1,3 @@
float4 main() : SV_Target {
return float4(0.5, 0.5, 0.5, 1.0);
}

View File

@@ -0,0 +1,52 @@
struct RS2PS {
float4 position : SV_POSITION;
#ifdef HAS_TEXCOORD_0
float2 texcoord_0: TEXCOORD_0;
#endif
};
struct TextureInfo {
uint textureIndex;
uint samplerIndex;
};
struct PBRMetallicRoughness {
float4 baseColorFactor;
TextureInfo baseColorTexture;
float metallicFactor;
float roughnessFactor;
TextureInfo metallicRoughnessTexture;
};
cbuffer Material : register(b2) {
PBRMetallicRoughness pbrMetallicRoughness;
};
Texture2D textures[5] : register(t0);
SamplerState samplerState[5] : register(s0);
float4 getBaseColor(float2 uv) {
float4 baseColor = pbrMetallicRoughness.baseColorFactor;
#ifdef HAS_TEXCOORD_0
TextureInfo baseColorTexture = pbrMetallicRoughness.baseColorTexture;
if (baseColorTexture.textureIndex >= 0) {
baseColor *= textures[baseColorTexture.textureIndex].Sample(samplerState[baseColorTexture.samplerIndex], uv);
}
#endif
return baseColor;
}
float4 main(RS2PS input) : SV_Target {
float2 uv = float2(0.0, 0.0);
#ifdef HAS_TEXCOORD_0
uv = input.texcoord_0;
#endif
float4 color = getBaseColor(uv);
return color;
}

View File

@@ -0,0 +1,46 @@
struct IA2VS {
float3 position : POSITION;
#ifdef HAS_NORMAL
float3 normal : NORMAL;
#endif
#ifdef HAS_TANGENT
float4 tangent : TANGENT;
#endif
#ifdef HAS_TEXCOORD_0
float2 texcoord_0: TEXCOORD_0;
#endif
};
struct VS2RS {
float4 position : SV_POSITION;
#ifdef HAS_TEXCOORD_0
float2 texcoord_0: TEXCOORD_0;
#endif
};
cbuffer Camera : register(b0) {
float4x4 V;
float4x4 P;
float4x4 VP;
};
cbuffer Node : register(b1) {
float4x4 M;
};
VS2RS main(IA2VS input) {
VS2RS output;
output.position = mul(float4(input.position, 1.0), M);
output.position = mul(output.position, V);
output.position = mul(output.position, P);
#ifdef HAS_TEXCOORD_0
output.texcoord_0 = input.texcoord_0;
#endif
return output;
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,130 @@
#ifndef DXVIEW_VIEWER_GUARD
#define DXVIEW_VIEWER_GUARD
#include <DirectXMath.h>
#include <d3d12.h>
#include <dxgi1_6.h>
#include <tiny_gltf.h>
#include <wrl.h>
#include <filesystem>
#include <map>
#include <string>
#include <vector>
using Microsoft::WRL::ComPtr;
enum RenderPassType { RENDER_PASS_TYPE_PRESENT = 0, RENDER_PASS_TYPE_COUNT };
struct RenderTarget {
ComPtr<ID3D12Resource> pTexture;
D3D12_CPU_DESCRIPTOR_HANDLE viewDescriptor;
};
struct TextureInfo {
int32_t textureIndex;
int32_t samplerIndex;
};
struct PBRMetallicRoughness {
DirectX::XMFLOAT4 baseColorFactor;
TextureInfo baseColorTexture;
float metallicFactor;
float roughnessFactor;
TextureInfo metallicRoughnessTexture;
};
struct Material {
std::string name;
D3D12_BLEND_DESC blendDesc;
D3D12_RASTERIZER_DESC rasterizerDesc;
ComPtr<ID3D12Resource> pBuffer;
void* pBufferData;
ComPtr<ID3D12DescriptorHeap> pSRVDescriptorHeap;
ComPtr<ID3D12DescriptorHeap> pSamplerDescriptorHeap;
};
struct Attribute {
std::string name;
DXGI_FORMAT format;
D3D12_VERTEX_BUFFER_VIEW vertexBufferView;
};
struct Primitive {
std::vector<Attribute> attributes;
uint32_t vertexCount;
D3D12_PRIMITIVE_TOPOLOGY primitiveTopology;
D3D12_INDEX_BUFFER_VIEW indexBufferView;
uint32_t indexCount;
Material* pMaterial;
ComPtr<ID3D12RootSignature> pRootSignature;
ComPtr<ID3D12PipelineState> pPipelineState;
};
struct Mesh {
std::string name;
std::vector<Primitive> primitives;
};
struct Node {
DirectX::XMFLOAT4X4 M;
};
struct Camera {
DirectX::XMFLOAT4X4 V;
DirectX::XMFLOAT4X4 P;
DirectX::XMFLOAT4X4 VP;
};
class Viewer {
public:
Viewer(HWND window, tinygltf::Model* pModel);
void update(double deltaTime);
void render(double deltaTime);
private:
void initDirectX(HWND window);
void buildRenderTargets();
void buildResources();
void buildBuffers(std::vector<ComPtr<ID3D12Resource> >* pStagingResources);
void buildImages(std::vector<ComPtr<ID3D12Resource> >* pStagingResources);
void buildSamplerDescs();
void buildMaterials();
void buildMeshes();
void buildNodes();
void drawNode(uint64_t nodeIndex);
private:
tinygltf::Model* pModel_;
ComPtr<IDXGIFactory1> pFactory_;
ComPtr<IDXGIAdapter1> pAdapter_;
ComPtr<ID3D12Device> pDevice_;
ComPtr<ID3D12CommandQueue> pDirectCommandQueue_;
UINT64 directFenceValue_;
ComPtr<ID3D12Fence> pDirectFence_;
ComPtr<ID3D12CommandQueue> pCopyCommandQueue_;
UINT64 copyFenceValue_;
ComPtr<ID3D12Fence> pCopyFence_;
ComPtr<IDXGISwapChain3> pSwapChain_;
ComPtr<ID3D12Resource> pSwapChainBuffers_[DXVIEW_SWAP_CHAIN_BUFFER_COUNT];
ComPtr<ID3D12CommandAllocator>
pDirectCommandAllocators_[DXVIEW_SWAP_CHAIN_BUFFER_COUNT];
ComPtr<ID3D12GraphicsCommandList> pDirectCommandList_;
ComPtr<ID3D12CommandAllocator> pCopyCommandAllocator_;
ComPtr<ID3D12GraphicsCommandList> pCopyCommandList_;
UINT descriptorIncrementSize_[D3D12_DESCRIPTOR_HEAP_TYPE_NUM_TYPES];
ComPtr<ID3D12DescriptorHeap>
pRTVDescriptorHeaps_[DXVIEW_SWAP_CHAIN_BUFFER_COUNT];
std::vector<RenderTarget> renderTargets_[DXVIEW_SWAP_CHAIN_BUFFER_COUNT];
std::vector<ComPtr<ID3D12Resource> > pBuffers_;
std::vector<ComPtr<ID3D12Resource> > pTextures_;
std::vector<D3D12_SAMPLER_DESC> samplerDescs_;
std::vector<Material> materials_;
std::vector<Mesh> meshes_;
std::vector<ComPtr<ID3D12Resource> > pNodeBuffers_;
ComPtr<ID3D12Resource> pCameraBuffer_;
};
#endif

View File

@@ -0,0 +1,90 @@
#define GLFW_EXPOSE_NATIVE_WIN32
#define TINYGLTF_IMPLEMENTATION
#define STBI_MSC_SECURE_CRT
#define STB_IMAGE_IMPLEMENTATION
#define STB_IMAGE_WRITE_IMPLEMENTATION
#include <GLFW/glfw3.h>
#include <GLFW/glfw3native.h>
#include <spdlog/spdlog.h>
#include <tiny_gltf.h>
#undef GLFW_EXPOSE_NATIVE_WIN32
#undef TINYGLTF_IMPLEMENTATION
#undef STBI_MSC_SECURE_CRT
#undef STB_IMAGE_IMPLEMENTATION
#undef STB_IMAGE_WRITE_IMPLEMENTATION
#include <iostream>
#include <string>
#include "Viewer.h"
static void onError(int error, const char* message) {
spdlog::error("[{}] {}", error, message);
}
static void onRender(Viewer* pViewer, double deltaTime) {
pViewer->update(deltaTime);
pViewer->render(deltaTime);
}
int main(int argc, char* argv[]) {
tinygltf::TinyGLTF context;
tinygltf::Model model;
std::string error;
std::string warning;
if (!context.LoadASCIIFromFile(&model, &error, &warning, argv[1])) {
if (!error.empty()) {
spdlog::error("{}", error);
}
if (!warning.empty()) {
spdlog::warn("{}", warning);
}
exit(EXIT_FAILURE);
}
GLFWwindow* pWindow;
glfwSetErrorCallback(onError);
if (!glfwInit()) {
spdlog::error("Fail to initialize GLFW!!!");
exit(EXIT_FAILURE);
}
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);
pWindow = glfwCreateWindow(512, 512, "dxview", nullptr, nullptr);
if (!pWindow) {
spdlog::error("Fail to create GLFWwindow!!!");
glfwTerminate();
exit(EXIT_FAILURE);
}
auto pViewer = std::make_unique<Viewer>(glfwGetWin32Window(pWindow), &model);
if (!pViewer) {
spdlog::error("Fail to create Viewer");
glfwDestroyWindow(pWindow);
glfwTerminate();
exit(EXIT_FAILURE);
}
auto prevTimeStamp = glfwGetTime();
while (!glfwWindowShouldClose(pWindow)) {
auto currTimeStamp = glfwGetTime();
onRender(pViewer.get(), currTimeStamp - prevTimeStamp);
prevTimeStamp = currTimeStamp;
glfwPollEvents();
}
glfwDestroyWindow(pWindow);
glfwTerminate();
exit(EXIT_SUCCESS);
}

View File

@@ -26,8 +26,6 @@
// THE SOFTWARE.
// Version:
// - v2.4.3 Experimental sajson(lightweight JSON parser) backend support.
// Introduce TINYGLTF_ENABLE_SERIALIZER.
// - v2.4.2 Decode percent-encoded URI.
// - v2.4.1 Fix some glTF object class does not have `extensions` and/or
// `extras` property.
@@ -45,7 +43,6 @@
//
// Tiny glTF loader is using following third party libraries:
//
// - sajso: Lightweight C++ JSON library.
// - jsonhpp: C++ JSON library.
// - base64: base64 decode/encode library.
// - stb_image: Image loading library.
@@ -667,6 +664,8 @@ struct Image {
width = -1;
height = -1;
component = -1;
bits = -1;
pixel_type = -1;
}
DEFAULT_METHODS(Image)
@@ -999,6 +998,7 @@ struct Primitive {
Primitive() {
material = -1;
indices = -1;
mode = -1;
}
DEFAULT_METHODS(Primitive)
bool operator==(const Primitive &) const;
@@ -1253,7 +1253,8 @@ struct FsCallbacks {
bool FileExists(const std::string &abs_filename, void *);
///
/// Expand file path(e.g. `~` to home directory on posix, `%APPDATA%` to `C:\Users\tinygltf\AppData`)
/// Expand file path(e.g. `~` to home directory on posix, `%APPDATA%` to
/// `C:\Users\tinygltf\AppData`)
///
/// @param[in] filepath File path string. Assume UTF-8
/// @param[in] userdata User data. Set to `nullptr` if you don't need it.
@@ -1326,8 +1327,6 @@ class TinyGLTF {
const std::string &base_dir = "",
unsigned int check_sections = REQUIRE_VERSION);
#if defined(TINYGLTF_ENABLE_SERIALIZER)
///
/// Write glTF to stream, buffers and images will be embeded
///
@@ -1341,22 +1340,16 @@ class TinyGLTF {
bool embedImages, bool embedBuffers,
bool prettyPrint, bool writeBinary);
#endif
///
/// Set callback to use for loading image data
///
void SetImageLoader(LoadImageDataFunction LoadImageData, void *user_data);
#if defined(TINYGLTF_ENABLE_SERIALIZER)
///
/// Set callback to use for writing image data
///
void SetImageWriter(WriteImageDataFunction WriteImageData, void *user_data);
#endif
///
/// Set callbacks to use for filesystem (fs) access and their user data
///
@@ -1518,38 +1511,14 @@ class TinyGLTF {
#endif // __GNUC__
#ifndef TINYGLTF_NO_INCLUDE_JSON
#if defined(TINYGLTF_USE_RAPIDJSON)
#ifndef TINYGLTF_USE_RAPIDJSON
#include "json.hpp"
#else
#include "document.h"
#include "prettywriter.h"
#include "rapidjson.h"
#include "stringbuffer.h"
#include "writer.h"
#elif defined(TINYGLTF_USE_SAJSON)
#ifdef __clang__
#if __has_warning("-Wc99-extensions")
#pragma clang diagnostic ignored "-Wc99-extensions"
#endif
#if __has_warning("-Wshadow-field-in-constructor")
#pragma clang diagnostic ignored "-Wshadow-field-in-constructor"
#endif
#endif
#include "sajson.h"
// Serialization is not available for sajson backend.
#ifdef TINYGLTF_ENABLE_SERIALIZER
#undef TINYGLTF_ENABLE_SERIALIZER
#endif
#else
// Default = nlohmann json
#include "json.hpp"
#endif
#endif
@@ -1685,62 +1654,7 @@ struct JsonDocument : public rapidjson::Document {
#endif // TINYGLTF_USE_RAPIDJSON_CRTALLOCATOR
#elif defined(TINYGLTF_USE_SAJSON)
using json = sajson::value;
using JsonDocument = json;
// TODO(syoyo): Implement
// muda
class sajson_const_iterator
{
public:
sajson_const_iterator() = default;
sajson_const_iterator(const sajson::value &v) : _v(v) {
}
sajson_const_iterator(const sajson_const_iterator &rhs) = default;
sajson_const_iterator &operator=(const sajson_const_iterator &rhs) = default;
std::string key() const {
}
sajson::value &value() {
return _v;
}
sajson::value *begin() {
return &_v;
}
bool operator!=(sajson_const_iterator &rhs) {
// TODO
assert(0);
return false;
}
sajson_const_iterator &operator++() {
// TODO
assert(0);
return (*this);
}
sajson::value &operator*() {
return _v;
}
private:
// `sajson::value` itself is a small struct, so having a copy of it
// does not affect performance and memory consumption.
sajson::value _v;
};
using json_const_iterator = sajson_const_iterator;
using json_const_array_iterator = json_const_iterator;
#else // nlohmann JSON
#else
using nlohmann::json;
using json_const_iterator = json::const_iterator;
using json_const_array_iterator = json_const_iterator;
@@ -1752,14 +1666,6 @@ void JsonParse(JsonDocument &doc, const char *str, size_t length,
#ifdef TINYGLTF_USE_RAPIDJSON
(void)throwExc;
doc.Parse(str, length);
#elif defined(TINYGLTF_USE_SAJSON)
// This code path is not available.
(void)doc;
(void)str;
(void)length;
(void)throwExc;
//doc = sajson::parse(sajson::dynamic_allocation(), sajson::mutable_string_view(length, const_cast<char *>(str)));
//doc.parse(sajson::dynamic_allocation(), sajson::mutable_string_view(length, const_cast<char *>(str)));
#else
doc = json::parse(str, str + length, nullptr, throwExc);
#endif
@@ -2491,15 +2397,11 @@ bool LoadImageData(Image *image, const int image_idx, std::string *err,
}
#endif
#if defined(TINYGLTF_ENABLE_SERIALIZER)
void TinyGLTF::SetImageWriter(WriteImageDataFunction func, void *user_data) {
WriteImageData = func;
write_image_user_data_ = user_data;
}
#endif
#ifndef TINYGLTF_NO_STB_IMAGE_WRITE
static void WriteToMemory_stbi(void *context, void *data, int size) {
std::vector<unsigned char> *buffer =
@@ -2594,7 +2496,7 @@ static inline std::wstring UTF8ToWchar(const std::string &str) {
static inline std::string WcharToUTF8(const std::wstring &wstr) {
int str_size = WideCharToMultiByte(CP_UTF8, 0, wstr.data(), (int)wstr.size(),
nullptr, 0, NULL, NULL);
nullptr, 0, NULL, NULL);
std::string str(str_size, 0);
WideCharToMultiByte(CP_UTF8, 0, wstr.data(), (int)wstr.size(), &str[0],
(int)str.size(), NULL, NULL);
@@ -2737,7 +2639,8 @@ bool ReadWholeFile(std::vector<unsigned char> *out, std::string *err,
__gnu_cxx::stdio_filebuf<char> wfile_buf(file_descriptor, std::ios_base::in);
std::istream f(&wfile_buf);
#elif defined(_MSC_VER) || defined(_LIBCPP_VERSION)
// For libcxx, assume _LIBCPP_HAS_OPEN_WITH_WCHAR is defined to accept `wchar_t *`
// For libcxx, assume _LIBCPP_HAS_OPEN_WITH_WCHAR is defined to accept
// `wchar_t *`
std::ifstream f(UTF8ToWchar(filepath).c_str(), std::ifstream::binary);
#else
// Unknown compiler/runtime
@@ -2990,15 +2893,6 @@ bool GetInt(const json &o, int &val) {
}
}
return false;
#elif defined(TINYGLTF_USE_SAJSON)
auto type = o.get_type();
if (type == sajson::TYPE_INTEGER) {
val = static_cast<int>(o.get_number_value());
return true;
}
return false;
#else
auto type = o.type();
@@ -3031,16 +2925,6 @@ bool GetNumber(const json &o, double &val) {
return true;
}
return false;
#elif defined(TINYGLTF_USE_SAJSON)
auto type = o.get_type();
if ((type == sajson::TYPE_DOUBLE) ||
(type == sajson::TYPE_INTEGER)) {
val = static_cast<double>(o.get_number_value());
return true;
}
return false;
#else
if (o.is_number()) {
@@ -3059,15 +2943,6 @@ bool GetString(const json &o, std::string &val) {
return true;
}
return false;
#elif defined(TINYGLTF_USE_SAJSON)
auto type = o.get_type();
if (type == sajson::TYPE_STRING) {
val = o.as_string();
return true;
}
return false;
#else
if (o.type() == json::value_t::string) {
@@ -3082,8 +2957,6 @@ bool GetString(const json &o, std::string &val) {
bool IsArray(const json &o) {
#ifdef TINYGLTF_USE_RAPIDJSON
return o.IsArray();
#elif defined(TINYGLTF_USE_SAJSON)
return o.get_type() == sajson::TYPE_ARRAY;
#else
return o.is_array();
#endif
@@ -3092,10 +2965,6 @@ bool IsArray(const json &o) {
json_const_array_iterator ArrayBegin(const json &o) {
#ifdef TINYGLTF_USE_RAPIDJSON
return o.Begin();
#elif TINYGLTF_USE_SAJSON
// TODO(syoyo): Implement
assert(0);
return json_const_array_iterator(o);
#else
return o.begin();
#endif
@@ -3104,10 +2973,6 @@ json_const_array_iterator ArrayBegin(const json &o) {
json_const_array_iterator ArrayEnd(const json &o) {
#ifdef TINYGLTF_USE_RAPIDJSON
return o.End();
#elif TINYGLTF_USE_SAJSON
// TODO(syoyo): Implement
assert(0);
return json_const_array_iterator(o);
#else
return o.end();
#endif
@@ -3116,8 +2981,6 @@ json_const_array_iterator ArrayEnd(const json &o) {
bool IsObject(const json &o) {
#ifdef TINYGLTF_USE_RAPIDJSON
return o.IsObject();
#elif defined(TINYGLTF_USE_SAJSON)
return o.get_type() == sajson::TYPE_OBJECT;
#else
return o.is_object();
#endif
@@ -3126,11 +2989,6 @@ bool IsObject(const json &o) {
json_const_iterator ObjectBegin(const json &o) {
#ifdef TINYGLTF_USE_RAPIDJSON
return o.MemberBegin();
#elif defined(TINYGLTF_USE_SAJSON)
assert(o.get_type() == sajson::TYPE_OBJECT);
// TODO(syoyo): Implement
assert(0);
return json_const_iterator(o);
#else
return o.begin();
#endif
@@ -3139,23 +2997,16 @@ json_const_iterator ObjectBegin(const json &o) {
json_const_iterator ObjectEnd(const json &o) {
#ifdef TINYGLTF_USE_RAPIDJSON
return o.MemberEnd();
#elif defined(TINYGLTF_USE_SAJSON)
assert(o.get_type() == sajson::TYPE_OBJECT);
// TODO(syoyo): Implement
assert(0);
return json_const_iterator(o);
#else
return o.end();
#endif
}
const char *GetKey(json_const_iterator &it) {
// Making this a const char* results in a pointer to a temporary when
// TINYGLTF_USE_RAPIDJSON is off.
std::string GetKey(json_const_iterator &it) {
#ifdef TINYGLTF_USE_RAPIDJSON
return it->name.GetString();
#elif defined(TINYGLTF_USE_SAJSON)
// TODO(syoyo): Implement
assert(0);
return nullptr;
#else
return it.key().c_str();
#endif
@@ -3168,10 +3019,6 @@ bool FindMember(const json &o, const char *member, json_const_iterator &it) {
}
it = o.FindMember(member);
return it != o.MemberEnd();
#elif defined(TINYGLTF_USE_SAJSON)
// TODO(syoyo): Implement
assert(0);
return false;
#else
it = o.find(member);
return it != o.end();
@@ -3181,10 +3028,6 @@ bool FindMember(const json &o, const char *member, json_const_iterator &it) {
const json &GetValue(json_const_iterator &it) {
#ifdef TINYGLTF_USE_RAPIDJSON
return it->value;
#elif defined(TINYGLTF_USE_SAJSON)
// TODO(syoyo): Implement
assert(0);
return it.value();
#else
return it.value();
#endif
@@ -3203,11 +3046,6 @@ std::string JsonToString(const json &o, int spacing = -1) {
o.Accept(writer);
}
return buffer.GetString();
#elif defined(TINYGLTF_USE_SAJSON)
// Serialize is not available for Sajson
(void)o;
(void)spacing;
return std::string();
#else
return o.dump(spacing);
#endif
@@ -3263,10 +3101,7 @@ static bool ParseJsonAsValue(Value *ret, const json &o) {
break;
// all types are covered, so no `case default`
}
#elif defined(TINYGLTF_USE_SAJSON)
// TODO
assert(0);
#else // json.hpp
#else
switch (o.type()) {
case json::value_t::object: {
Value::Object value_object;
@@ -3349,11 +3184,6 @@ static bool ParseBooleanProperty(bool *ret, std::string *err, const json &o,
if (isBoolean) {
boolValue = value.GetBool();
}
#elif defined(TINYGLTF_USE_SAJSON)
isBoolean = value.is_boolean();
if (isBoolean) {
boolValue = value.get_boolean_value();
}
#else
isBoolean = value.is_boolean();
if (isBoolean) {
@@ -3443,11 +3273,6 @@ static bool ParseUnsignedProperty(size_t *ret, std::string *err, const json &o,
uValue = value.GetUint64();
isUValue = true;
}
#elif defined(TINYGLTF_USE_SAJSON)
isUValue = value.get_type() == sajson::TYPE_INTEGER;
if (isUValue) {
uValue = value.get_integer_value();
}
#else
isUValue = value.is_number_unsigned();
if (isUValue) {
@@ -5884,10 +5709,13 @@ bool TinyGLTF::LoadFromString(Model *model, std::string *err, std::string *warn,
for (auto &target : primitive.targets) {
for (auto &attribute : target) {
model
->bufferViews[size_t(
model->accessors[size_t(attribute.second)].bufferView)]
.target = TINYGLTF_TARGET_ARRAY_BUFFER;
auto bufferView =
model->accessors[size_t(attribute.second)].bufferView;
// bufferView could be null(-1) for sparse morph target
if (bufferView >= 0) {
model->bufferViews[size_t(bufferView)].target =
TINYGLTF_TARGET_ARRAY_BUFFER;
}
}
}
}
@@ -6226,13 +6054,10 @@ bool TinyGLTF::LoadFromString(Model *model, std::string *err, std::string *warn,
// 19. Parse Extras
ParseExtrasProperty(&model->extras, v);
#if !defined(TINYGLTF_USE_SAJSON)
// TODO(syoyo): Support SAJSON backend
if (store_original_json_for_extras_and_extensions_) {
model->extras_json_string = JsonToString(v["extras"]);
model->extensions_json_string = JsonToString(v["extensions"]);
}
#endif
return true;
}
@@ -6399,8 +6224,6 @@ bool TinyGLTF::LoadBinaryFromFile(Model *model, std::string *err,
return ret;
}
#if defined(TINYGLTF_ENABLE_SERIALIZER)
///////////////////////
// GLTF Serialization
///////////////////////
@@ -7527,8 +7350,9 @@ static void SerializeGltfModel(Model *model, json &o) {
// Also add "KHR_lights_punctual" to `extensionsUsed`
{
auto has_khr_lights_punctual = std::find_if(
extensionsUsed.begin(), extensionsUsed.end(), [](const std::string &s) {
auto has_khr_lights_punctual =
std::find_if(extensionsUsed.begin(), extensionsUsed.end(),
[](const std::string &s) {
return (s.compare("KHR_lights_punctual") == 0);
});
@@ -7806,8 +7630,6 @@ bool TinyGLTF::WriteGltfSceneToFile(Model *model, const std::string &filename,
return true;
}
#endif // TINYGLTF_ENABLE_SERIALIZER
} // namespace tinygltf
#ifdef __clang__