mirror of
https://github.com/syoyo/tinygltf.git
synced 2026-06-13 18:58:53 +00:00
Compare commits
23 Commits
v2.4.0
...
write-asse
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b702de755f | ||
|
|
58ceed1d89 | ||
|
|
d1b6b3a5aa | ||
|
|
c56d069726 | ||
|
|
d1e32865f1 | ||
|
|
869a9d273c | ||
|
|
1208f057d6 | ||
|
|
f684dde9f1 | ||
|
|
7905a5b4dc | ||
|
|
f161782001 | ||
|
|
654bcf733c | ||
|
|
2c521b3432 | ||
|
|
a159945db9 | ||
|
|
010ee9c67b | ||
|
|
a23971c603 | ||
|
|
1923067982 | ||
|
|
68adc4ba5e | ||
|
|
42a8cd50ff | ||
|
|
0543640a83 | ||
|
|
9c59a0b64c | ||
|
|
452541a231 | ||
|
|
78fe8d9b89 | ||
|
|
51e5508fa0 |
@@ -6,7 +6,8 @@ SET(CMAKE_CXX_STANDARD 11)
|
|||||||
|
|
||||||
option(TINYGLTF_BUILD_LOADER_EXAMPLE "Build loader_example" ON)
|
option(TINYGLTF_BUILD_LOADER_EXAMPLE "Build loader_example" ON)
|
||||||
option(TINYGLTF_BUILD_GL_EXAMPLES "Build GL exampels(requires glfw, OpenGL, etc)" OFF)
|
option(TINYGLTF_BUILD_GL_EXAMPLES "Build GL exampels(requires glfw, OpenGL, etc)" OFF)
|
||||||
option(TINYGLTF_BUILD_VALIDATOR_EXAMPLE "Build validator exampe" OFF)
|
option(TINYGLTF_BUILD_VALIDATOR_EXAMPLE "Build validator example" OFF)
|
||||||
|
option(TINYGLTF_BUILD_BUILDER_EXAMPLE "Build glTF builder example" OFF)
|
||||||
|
|
||||||
if (TINYGLTF_BUILD_LOADER_EXAMPLE)
|
if (TINYGLTF_BUILD_LOADER_EXAMPLE)
|
||||||
ADD_EXECUTABLE ( loader_example
|
ADD_EXECUTABLE ( loader_example
|
||||||
@@ -22,6 +23,11 @@ endif (TINYGLTF_BUILD_GL_EXAMPLES)
|
|||||||
if (TINYGLTF_BUILD_VALIDATOR_EXAMPLE)
|
if (TINYGLTF_BUILD_VALIDATOR_EXAMPLE)
|
||||||
ADD_SUBDIRECTORY ( examples/validator )
|
ADD_SUBDIRECTORY ( examples/validator )
|
||||||
endif (TINYGLTF_BUILD_VALIDATOR_EXAMPLE)
|
endif (TINYGLTF_BUILD_VALIDATOR_EXAMPLE)
|
||||||
|
|
||||||
|
if (TINYGLTF_BUILD_BUILDER_EXAMPLE)
|
||||||
|
ADD_SUBDIRECTORY ( examples/build-gltf )
|
||||||
|
endif (TINYGLTF_BUILD_BUILDER_EXAMPLE)
|
||||||
|
|
||||||
#
|
#
|
||||||
# TinuGLTF is a header-only library, so no library build. just install header files.
|
# TinuGLTF is a header-only library, so no library build. just install header files.
|
||||||
#
|
#
|
||||||
|
|||||||
12
README.md
12
README.md
@@ -3,7 +3,7 @@
|
|||||||
`TinyGLTF` is a header only C++11 glTF 2.0 https://github.com/KhronosGroup/glTF library.
|
`TinyGLTF` is a header only C++11 glTF 2.0 https://github.com/KhronosGroup/glTF library.
|
||||||
|
|
||||||
`TinyGLTF` uses Niels Lohmann's json library(https://github.com/nlohmann/json), so now it requires C++11 compiler.
|
`TinyGLTF` uses Niels Lohmann's json library(https://github.com/nlohmann/json), so now it requires C++11 compiler.
|
||||||
If you are looking for old, C++03 version, please use `devel-picojson` branch.
|
If you are looking for old, C++03 version, please use `devel-picojson` branch(but not maintained anymore).
|
||||||
|
|
||||||
## Status
|
## Status
|
||||||
|
|
||||||
@@ -13,6 +13,10 @@ If you are looking for old, C++03 version, please use `devel-picojson` branch.
|
|||||||
- v2.1.0 release(Draco support)
|
- v2.1.0 release(Draco support)
|
||||||
- v2.0.0 release(22 Aug, 2018)!
|
- v2.0.0 release(22 Aug, 2018)!
|
||||||
|
|
||||||
|
### Branches
|
||||||
|
|
||||||
|
* `sajson` : Use sajson to parse JSON. Parsing only but faster compile time(2x reduction compared to json.hpp and RapidJson)
|
||||||
|
|
||||||
## Builds
|
## Builds
|
||||||
|
|
||||||
[](https://travis-ci.org/syoyo/tinygltf)
|
[](https://travis-ci.org/syoyo/tinygltf)
|
||||||
@@ -73,6 +77,7 @@ In extension(`ExtensionMap`), JSON number value is parsed as int or float(number
|
|||||||
* [glview](examples/glview) : Simple glTF geometry viewer.
|
* [glview](examples/glview) : Simple glTF geometry viewer.
|
||||||
* [validator](examples/validator) : Simple glTF validator with JSON schema.
|
* [validator](examples/validator) : Simple glTF validator with JSON schema.
|
||||||
* [basic](examples/basic) : Basic glTF viewer with texturing support.
|
* [basic](examples/basic) : Basic glTF viewer with texturing support.
|
||||||
|
* [build-gltf](examples/build-gltf) : Build simple glTF scene from a scratch.
|
||||||
|
|
||||||
## Projects using TinyGLTF
|
## Projects using TinyGLTF
|
||||||
|
|
||||||
@@ -86,6 +91,7 @@ In extension(`ExtensionMap`), JSON number value is parsed as int or float(number
|
|||||||
* [GlslViewer](https://github.com/patriciogonzalezvivo/glslViewer) - live GLSL coding for MacOS and Linux
|
* [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.
|
* [Vulkan-Samples](https://github.com/KhronosGroup/Vulkan-Samples) - The Vulkan Samples is collection of resources to help you develop optimized Vulkan applications.
|
||||||
* [TDME2](https://github.com/andreasdr/tdme2) - TDME2 - ThreeDeeMiniEngine2 is a lightweight 3D engine including tools suited for 3D game development using C++11
|
* [TDME2](https://github.com/andreasdr/tdme2) - TDME2 - ThreeDeeMiniEngine2 is a lightweight 3D engine including tools suited for 3D game development using C++11
|
||||||
|
* [SanityEngine](https://github.com/DethRaid/SanityEngine) - A C++/D3D12 renderer focused on the personal and proessional development of its developer
|
||||||
* Your projects here! (Please send PR)
|
* Your projects here! (Please send PR)
|
||||||
|
|
||||||
## TODOs
|
## TODOs
|
||||||
@@ -151,6 +157,10 @@ if (!ret) {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### Loader options
|
||||||
|
|
||||||
|
* `TinyGLTF::SetPreserveimageChannels(bool onoff)`. `true` to preserve image channels as stored in image file for loaded image. `false` by default for backward compatibility(image channels are widen to `RGBA` 4 channels). Effective only when using builtin image loader(STB image loader).
|
||||||
|
|
||||||
## Compile options
|
## Compile options
|
||||||
|
|
||||||
* `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_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.
|
||||||
|
|||||||
1
examples/basic/.gitignore
vendored
1
examples/basic/.gitignore
vendored
@@ -1,5 +1,6 @@
|
|||||||
.vs
|
.vs
|
||||||
Debug
|
Debug
|
||||||
|
Release
|
||||||
x64
|
x64
|
||||||
packages
|
packages
|
||||||
|
|
||||||
|
|||||||
@@ -22,32 +22,32 @@
|
|||||||
<VCProjectVersion>15.0</VCProjectVersion>
|
<VCProjectVersion>15.0</VCProjectVersion>
|
||||||
<ProjectGuid>{0589AC44-0CF3-40D8-8D89-68393CFD40F3}</ProjectGuid>
|
<ProjectGuid>{0589AC44-0CF3-40D8-8D89-68393CFD40F3}</ProjectGuid>
|
||||||
<RootNamespace>basic</RootNamespace>
|
<RootNamespace>basic</RootNamespace>
|
||||||
<WindowsTargetPlatformVersion>10.0.17134.0</WindowsTargetPlatformVersion>
|
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||||
<ConfigurationType>Application</ConfigurationType>
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
<UseDebugLibraries>true</UseDebugLibraries>
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
<PlatformToolset>v141</PlatformToolset>
|
<PlatformToolset>v142</PlatformToolset>
|
||||||
<CharacterSet>MultiByte</CharacterSet>
|
<CharacterSet>MultiByte</CharacterSet>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||||
<ConfigurationType>Application</ConfigurationType>
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
<UseDebugLibraries>false</UseDebugLibraries>
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
<PlatformToolset>v141</PlatformToolset>
|
<PlatformToolset>v142</PlatformToolset>
|
||||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||||
<CharacterSet>MultiByte</CharacterSet>
|
<CharacterSet>MultiByte</CharacterSet>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||||
<ConfigurationType>Application</ConfigurationType>
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
<UseDebugLibraries>true</UseDebugLibraries>
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
<PlatformToolset>v141</PlatformToolset>
|
<PlatformToolset>v142</PlatformToolset>
|
||||||
<CharacterSet>MultiByte</CharacterSet>
|
<CharacterSet>MultiByte</CharacterSet>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||||
<ConfigurationType>Application</ConfigurationType>
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
<UseDebugLibraries>false</UseDebugLibraries>
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
<PlatformToolset>v141</PlatformToolset>
|
<PlatformToolset>v142</PlatformToolset>
|
||||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||||
<CharacterSet>MultiByte</CharacterSet>
|
<CharacterSet>MultiByte</CharacterSet>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|||||||
@@ -329,7 +329,7 @@ static void error_callback(int error, const char *description) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
std::string filename = "../../models/Cube/Cube.gltf";
|
std::string filename = "../../../models/Cube/Cube.gltf";
|
||||||
|
|
||||||
if (argc > 1) {
|
if (argc > 1) {
|
||||||
filename = argv[1];
|
filename = argv[1];
|
||||||
@@ -341,9 +341,12 @@ int main(int argc, char **argv) {
|
|||||||
|
|
||||||
// Force create OpenGL 3.3
|
// Force create OpenGL 3.3
|
||||||
// NOTE(syoyo): Linux + NVIDIA driver segfaults for some reason? commenting out glfwWindowHint will work.
|
// NOTE(syoyo): Linux + NVIDIA driver segfaults for some reason? commenting out glfwWindowHint will work.
|
||||||
|
// Note (PE): On laptops with intel hd graphics card you can overcome the segfault by enabling experimental, see below (tested on lenovo thinkpad)
|
||||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
||||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
|
||||||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
||||||
|
glewExperimental = GL_TRUE;
|
||||||
|
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
|
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
2
examples/build-gltf/Makefile
Normal file
2
examples/build-gltf/Makefile
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
all:
|
||||||
|
$(CXX) -o create_triangle_gltf -I../../ create_triangle_gltf.cpp
|
||||||
121
examples/build-gltf/create_triangle_gltf.cpp
Normal file
121
examples/build-gltf/create_triangle_gltf.cpp
Normal file
@@ -0,0 +1,121 @@
|
|||||||
|
// An example of how to generate a gltf file from scratch. This example
|
||||||
|
// was translated from the pygltlib documentation in the pypi project page,
|
||||||
|
// which in turn is based on the Khronos Sample Models at:
|
||||||
|
//
|
||||||
|
// https://github.com/KhronosGroup/glTF-Sample-Models
|
||||||
|
//
|
||||||
|
// This example is released under the MIT license.
|
||||||
|
//
|
||||||
|
// 2021-02-25 Thu
|
||||||
|
// Dov Grobgeld <dov.grobgeld@gmail.com>
|
||||||
|
|
||||||
|
|
||||||
|
// Define these only in *one* .cc file.
|
||||||
|
#define TINYGLTF_IMPLEMENTATION
|
||||||
|
#define STB_IMAGE_IMPLEMENTATION
|
||||||
|
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
||||||
|
|
||||||
|
// #define TINYGLTF_NOEXCEPTION // optional. disable exception handling.
|
||||||
|
#include "tiny_gltf.h"
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
// Create a model with a single mesh and save it as a gltf file
|
||||||
|
tinygltf::Model m;
|
||||||
|
tinygltf::Scene scene;
|
||||||
|
tinygltf::Mesh mesh;
|
||||||
|
tinygltf::Primitive primitive;
|
||||||
|
tinygltf::Node node;
|
||||||
|
tinygltf::Buffer buffer;
|
||||||
|
tinygltf::BufferView bufferView1;
|
||||||
|
tinygltf::BufferView bufferView2;
|
||||||
|
tinygltf::Accessor accessor1;
|
||||||
|
tinygltf::Accessor accessor2;
|
||||||
|
tinygltf::Asset asset;
|
||||||
|
|
||||||
|
// This is the raw data buffer.
|
||||||
|
buffer.data = {
|
||||||
|
// 6 bytes of indices and two bytes of padding
|
||||||
|
0x00,0x00,0x01,0x00,0x02,0x00,0x00,0x00,
|
||||||
|
// 36 bytes of floating point numbers
|
||||||
|
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||||
|
0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x3f,
|
||||||
|
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||||
|
0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x3f,
|
||||||
|
0x00,0x00,0x00,0x00};
|
||||||
|
|
||||||
|
// "The indices of the vertices (ELEMENT_ARRAY_BUFFER) take up 6 bytes in the
|
||||||
|
// start of the buffer.
|
||||||
|
bufferView1.buffer = 0;
|
||||||
|
bufferView1.byteOffset=0;
|
||||||
|
bufferView1.byteLength=6;
|
||||||
|
bufferView1.target = TINYGLTF_TARGET_ELEMENT_ARRAY_BUFFER;
|
||||||
|
|
||||||
|
// The vertices take up 36 bytes (3 vertices * 3 floating points * 4 bytes)
|
||||||
|
// at position 8 in the buffer and are of type ARRAY_BUFFER
|
||||||
|
bufferView2.buffer = 0;
|
||||||
|
bufferView2.byteOffset=8;
|
||||||
|
bufferView2.byteLength=36;
|
||||||
|
bufferView2.target = TINYGLTF_TARGET_ARRAY_BUFFER;
|
||||||
|
|
||||||
|
// Describe the layout of bufferView1, the indices of the vertices
|
||||||
|
accessor1.bufferView = 0;
|
||||||
|
accessor1.byteOffset = 0;
|
||||||
|
accessor1.componentType = TINYGLTF_COMPONENT_TYPE_UNSIGNED_SHORT;
|
||||||
|
accessor1.count = 3;
|
||||||
|
accessor1.type = TINYGLTF_TYPE_SCALAR;
|
||||||
|
accessor1.maxValues.push_back(2);
|
||||||
|
accessor1.minValues.push_back(0);
|
||||||
|
|
||||||
|
// Describe the layout of bufferView2, the vertices themself
|
||||||
|
accessor2.bufferView = 1;
|
||||||
|
accessor2.byteOffset = 0;
|
||||||
|
accessor2.componentType = TINYGLTF_COMPONENT_TYPE_FLOAT;
|
||||||
|
accessor2.count = 3;
|
||||||
|
accessor2.type = TINYGLTF_TYPE_VEC3;
|
||||||
|
accessor2.maxValues = {1.0, 1.0, 0.0};
|
||||||
|
accessor2.minValues = {0.0, 0.0, 0.0};
|
||||||
|
|
||||||
|
// Build the mesh primitive and add it to the mesh
|
||||||
|
primitive.indices = 0; // The index of the accessor for the vertex indices
|
||||||
|
primitive.attributes["POSITION"] = 1; // The index of the accessor for positions
|
||||||
|
primitive.material = 0;
|
||||||
|
primitive.mode = TINYGLTF_MODE_TRIANGLES;
|
||||||
|
mesh.primitives.push_back(primitive);
|
||||||
|
|
||||||
|
// Other tie ups
|
||||||
|
node.mesh = 0;
|
||||||
|
scene.nodes.push_back(0); // Default scene
|
||||||
|
|
||||||
|
// Define the asset. The version is required
|
||||||
|
asset.version = "2.0";
|
||||||
|
asset.generator = "tinygltf";
|
||||||
|
|
||||||
|
// Now all that remains is to tie back all the loose objects into the
|
||||||
|
// our single model.
|
||||||
|
m.scenes.push_back(scene);
|
||||||
|
m.meshes.push_back(mesh);
|
||||||
|
m.nodes.push_back(node);
|
||||||
|
m.buffers.push_back(buffer);
|
||||||
|
m.bufferViews.push_back(bufferView1);
|
||||||
|
m.bufferViews.push_back(bufferView2);
|
||||||
|
m.accessors.push_back(accessor1);
|
||||||
|
m.accessors.push_back(accessor2);
|
||||||
|
m.asset = asset;
|
||||||
|
|
||||||
|
// Create a simple material
|
||||||
|
tinygltf::Material mat;
|
||||||
|
mat.pbrMetallicRoughness.baseColorFactor = {1.0f, 0.9f, 0.9f, 1.0f};
|
||||||
|
mat.doubleSided = true;
|
||||||
|
m.materials.push_back(mat);
|
||||||
|
|
||||||
|
// Save it to a file
|
||||||
|
tinygltf::TinyGLTF gltf;
|
||||||
|
gltf.WriteGltfSceneToFile(&m, "triangle.gltf",
|
||||||
|
true, // embedImages
|
||||||
|
true, // embedBuffers
|
||||||
|
true, // pretty print
|
||||||
|
false); // write binary
|
||||||
|
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
@@ -610,7 +610,7 @@ void Viewer::buildSamplerDescs() {
|
|||||||
|
|
||||||
samplerDesc.AddressU = toTextureAddressMode(glTFSampler.wrapS);
|
samplerDesc.AddressU = toTextureAddressMode(glTFSampler.wrapS);
|
||||||
samplerDesc.AddressV = toTextureAddressMode(glTFSampler.wrapT);
|
samplerDesc.AddressV = toTextureAddressMode(glTFSampler.wrapT);
|
||||||
samplerDesc.AddressW = toTextureAddressMode(glTFSampler.wrapR);
|
samplerDesc.AddressW = D3D12_TEXTURE_ADDRESS_MODE_WRAP;
|
||||||
samplerDesc.MaxLOD = 256;
|
samplerDesc.MaxLOD = 256;
|
||||||
|
|
||||||
samplerDescs_.push_back(samplerDesc);
|
samplerDescs_.push_back(samplerDesc);
|
||||||
@@ -1289,4 +1289,4 @@ void Viewer::drawNode(uint64_t nodeIndex) {
|
|||||||
for (auto childNodeIndex : glTFNode.children) {
|
for (auto childNodeIndex : glTFNode.children) {
|
||||||
drawNode(childNodeIndex);
|
drawNode(childNodeIndex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,9 @@
|
|||||||
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
||||||
#include "tiny_gltf.h"
|
#include "tiny_gltf.h"
|
||||||
|
|
||||||
|
// Nlohmann json(include ../json.hpp)
|
||||||
|
#include "json.hpp"
|
||||||
|
|
||||||
#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file
|
#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file
|
||||||
#include "catch.hpp"
|
#include "catch.hpp"
|
||||||
|
|
||||||
@@ -412,6 +415,27 @@ TEST_CASE("image-uri-spaces", "[issue-236]") {
|
|||||||
REQUIRE(true == ret);
|
REQUIRE(true == ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE("serialize-empty-material", "[issue-294]") {
|
||||||
|
|
||||||
|
tinygltf::Model m;
|
||||||
|
|
||||||
|
tinygltf::Material mat;
|
||||||
|
mat.pbrMetallicRoughness.baseColorFactor = {1.0f, 1.0f, 1.0f, 1.0f}; // default baseColorFactor
|
||||||
|
m.materials.push_back(mat);
|
||||||
|
|
||||||
|
std::stringstream os;
|
||||||
|
|
||||||
|
tinygltf::TinyGLTF ctx;
|
||||||
|
ctx.WriteGltfSceneToStream(&m, os, false, false);
|
||||||
|
|
||||||
|
// use nlohmann json
|
||||||
|
nlohmann::json j = nlohmann::json::parse(os.str());
|
||||||
|
|
||||||
|
REQUIRE(1 == j["materials"].size());
|
||||||
|
REQUIRE(j["materials"][0].is_object());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
#ifndef TINYGLTF_NO_FS
|
#ifndef TINYGLTF_NO_FS
|
||||||
TEST_CASE("expandpath-utf-8", "[pr-226]") {
|
TEST_CASE("expandpath-utf-8", "[pr-226]") {
|
||||||
|
|
||||||
|
|||||||
175
tiny_gltf.h
175
tiny_gltf.h
@@ -4,7 +4,7 @@
|
|||||||
//
|
//
|
||||||
// The MIT License (MIT)
|
// The MIT License (MIT)
|
||||||
//
|
//
|
||||||
// Copyright (c) 2015 - 2020 Syoyo Fujita, Aurélien Chatelain and many
|
// Copyright (c) 2015 - Present Syoyo Fujita, Aurélien Chatelain and many
|
||||||
// contributors.
|
// contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
@@ -26,6 +26,9 @@
|
|||||||
// THE SOFTWARE.
|
// THE SOFTWARE.
|
||||||
|
|
||||||
// Version:
|
// Version:
|
||||||
|
// - v2.5.0 Add SetPreserveImageChannels() option to load image data as is.
|
||||||
|
// - v2.4.3 Fix null object output when when material has all default
|
||||||
|
// parameters.
|
||||||
// - v2.4.2 Decode percent-encoded URI.
|
// - v2.4.2 Decode percent-encoded URI.
|
||||||
// - v2.4.1 Fix some glTF object class does not have `extensions` and/or
|
// - v2.4.1 Fix some glTF object class does not have `extensions` and/or
|
||||||
// `extras` property.
|
// `extras` property.
|
||||||
@@ -295,7 +298,7 @@ class Value {
|
|||||||
|
|
||||||
DEFAULT_METHODS(Value)
|
DEFAULT_METHODS(Value)
|
||||||
|
|
||||||
char Type() const { return static_cast<const char>(type_); }
|
char Type() const { return static_cast<char>(type_); }
|
||||||
|
|
||||||
bool IsBool() const { return (type_ == BOOL_TYPE); }
|
bool IsBool() const { return (type_ == BOOL_TYPE); }
|
||||||
|
|
||||||
@@ -611,7 +614,7 @@ struct Sampler {
|
|||||||
int wrapT =
|
int wrapT =
|
||||||
TINYGLTF_TEXTURE_WRAP_REPEAT; // ["CLAMP_TO_EDGE", "MIRRORED_REPEAT",
|
TINYGLTF_TEXTURE_WRAP_REPEAT; // ["CLAMP_TO_EDGE", "MIRRORED_REPEAT",
|
||||||
// "REPEAT"], default "REPEAT"
|
// "REPEAT"], default "REPEAT"
|
||||||
int wrapR = TINYGLTF_TEXTURE_WRAP_REPEAT; // TinyGLTF extension
|
//int wrapR = TINYGLTF_TEXTURE_WRAP_REPEAT; // TinyGLTF extension. currently not used.
|
||||||
|
|
||||||
Value extras;
|
Value extras;
|
||||||
ExtensionMap extensions;
|
ExtensionMap extensions;
|
||||||
@@ -624,8 +627,7 @@ struct Sampler {
|
|||||||
: minFilter(-1),
|
: minFilter(-1),
|
||||||
magFilter(-1),
|
magFilter(-1),
|
||||||
wrapS(TINYGLTF_TEXTURE_WRAP_REPEAT),
|
wrapS(TINYGLTF_TEXTURE_WRAP_REPEAT),
|
||||||
wrapT(TINYGLTF_TEXTURE_WRAP_REPEAT),
|
wrapT(TINYGLTF_TEXTURE_WRAP_REPEAT) {}
|
||||||
wrapR(TINYGLTF_TEXTURE_WRAP_REPEAT) {}
|
|
||||||
DEFAULT_METHODS(Sampler)
|
DEFAULT_METHODS(Sampler)
|
||||||
bool operator==(const Sampler &) const;
|
bool operator==(const Sampler &) const;
|
||||||
};
|
};
|
||||||
@@ -848,8 +850,10 @@ struct Accessor {
|
|||||||
std::string extras_json_string;
|
std::string extras_json_string;
|
||||||
std::string extensions_json_string;
|
std::string extensions_json_string;
|
||||||
|
|
||||||
std::vector<double> minValues; // optional
|
std::vector<double>
|
||||||
std::vector<double> maxValues; // optional
|
minValues; // optional. integer value is promoted to double
|
||||||
|
std::vector<double>
|
||||||
|
maxValues; // optional. integer value is promoted to double
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
int count;
|
int count;
|
||||||
@@ -1067,7 +1071,7 @@ struct Buffer {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct Asset {
|
struct Asset {
|
||||||
std::string version; // required
|
std::string version = "2.0"; // required
|
||||||
std::string generator;
|
std::string generator;
|
||||||
std::string minVersion;
|
std::string minVersion;
|
||||||
std::string copyright;
|
std::string copyright;
|
||||||
@@ -1189,7 +1193,8 @@ enum SectionCheck {
|
|||||||
///
|
///
|
||||||
typedef bool (*LoadImageDataFunction)(Image *, const int, std::string *,
|
typedef bool (*LoadImageDataFunction)(Image *, const int, std::string *,
|
||||||
std::string *, int, int,
|
std::string *, int, int,
|
||||||
const unsigned char *, int, void *);
|
const unsigned char *, int,
|
||||||
|
void *user_pointer);
|
||||||
|
|
||||||
///
|
///
|
||||||
/// WriteImageDataFunction type. Signature for custom image writing callbacks.
|
/// WriteImageDataFunction type. Signature for custom image writing callbacks.
|
||||||
@@ -1254,7 +1259,7 @@ bool FileExists(const std::string &abs_filename, void *);
|
|||||||
|
|
||||||
///
|
///
|
||||||
/// Expand file path(e.g. `~` to home directory on posix, `%APPDATA%` to
|
/// Expand file path(e.g. `~` to home directory on posix, `%APPDATA%` to
|
||||||
/// `C:\Users\tinygltf\AppData`)
|
/// `C:\\Users\\tinygltf\\AppData`)
|
||||||
///
|
///
|
||||||
/// @param[in] filepath File path string. Assume UTF-8
|
/// @param[in] filepath File path string. Assume UTF-8
|
||||||
/// @param[in] userdata User data. Set to `nullptr` if you don't need it.
|
/// @param[in] userdata User data. Set to `nullptr` if you don't need it.
|
||||||
@@ -1345,6 +1350,11 @@ class TinyGLTF {
|
|||||||
///
|
///
|
||||||
void SetImageLoader(LoadImageDataFunction LoadImageData, void *user_data);
|
void SetImageLoader(LoadImageDataFunction LoadImageData, void *user_data);
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Unset(remove) callback of loading image data
|
||||||
|
///
|
||||||
|
void RemoveImageLoader();
|
||||||
|
|
||||||
///
|
///
|
||||||
/// Set callback to use for writing image data
|
/// Set callback to use for writing image data
|
||||||
///
|
///
|
||||||
@@ -1383,6 +1393,16 @@ class TinyGLTF {
|
|||||||
return store_original_json_for_extras_and_extensions_;
|
return store_original_json_for_extras_and_extensions_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Specify whether preserve image channales when loading images or not.
|
||||||
|
/// (Not effective when the user suppy their own LoadImageData callbacks)
|
||||||
|
///
|
||||||
|
void SetPreserveImageChannels(bool onoff) {
|
||||||
|
preserve_image_channels_ = onoff;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool GetPreserveImageChannels() const { return preserve_image_channels_; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
///
|
///
|
||||||
/// Loads glTF asset from string(memory).
|
/// Loads glTF asset from string(memory).
|
||||||
@@ -1402,6 +1422,9 @@ class TinyGLTF {
|
|||||||
|
|
||||||
bool store_original_json_for_extras_and_extensions_ = false;
|
bool store_original_json_for_extras_and_extensions_ = false;
|
||||||
|
|
||||||
|
bool preserve_image_channels_ = false; /// Default false(expand channels to
|
||||||
|
/// RGBA) for backward compatibility.
|
||||||
|
|
||||||
FsCallbacks fs = {
|
FsCallbacks fs = {
|
||||||
#ifndef TINYGLTF_NO_FS
|
#ifndef TINYGLTF_NO_FS
|
||||||
&tinygltf::FileExists, &tinygltf::ExpandFilePath,
|
&tinygltf::FileExists, &tinygltf::ExpandFilePath,
|
||||||
@@ -1421,7 +1444,8 @@ class TinyGLTF {
|
|||||||
#else
|
#else
|
||||||
nullptr;
|
nullptr;
|
||||||
#endif
|
#endif
|
||||||
void *load_image_user_data_ = reinterpret_cast<void *>(&fs);
|
void *load_image_user_data_{nullptr};
|
||||||
|
bool user_image_loader_{false};
|
||||||
|
|
||||||
WriteImageDataFunction WriteImageData =
|
WriteImageDataFunction WriteImageData =
|
||||||
#ifndef TINYGLTF_NO_STB_IMAGE_WRITE
|
#ifndef TINYGLTF_NO_STB_IMAGE_WRITE
|
||||||
@@ -1429,7 +1453,7 @@ class TinyGLTF {
|
|||||||
#else
|
#else
|
||||||
nullptr;
|
nullptr;
|
||||||
#endif
|
#endif
|
||||||
void *write_image_user_data_ = reinterpret_cast<void *>(&fs);
|
void *write_image_user_data_{nullptr};
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef __clang__
|
#ifdef __clang__
|
||||||
@@ -1683,6 +1707,19 @@ void JsonParse(JsonDocument &doc, const char *str, size_t length,
|
|||||||
|
|
||||||
namespace tinygltf {
|
namespace tinygltf {
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Internal LoadImageDataOption struct.
|
||||||
|
/// This struct is passed through `user_pointer` in LoadImageData.
|
||||||
|
/// The struct is not passed when the user supply their own LoadImageData
|
||||||
|
/// callbacks.
|
||||||
|
///
|
||||||
|
struct LoadImageDataOption {
|
||||||
|
// true: preserve image channels(e.g. load as RGB image if the image has RGB
|
||||||
|
// channels) default `false`(channels are expanded to RGBA for backward
|
||||||
|
// compatiblity).
|
||||||
|
bool preserve_channels{false};
|
||||||
|
};
|
||||||
|
|
||||||
// Equals function for Value, for recursivity
|
// Equals function for Value, for recursivity
|
||||||
static bool Equals(const tinygltf::Value &one, const tinygltf::Value &other) {
|
static bool Equals(const tinygltf::Value &one, const tinygltf::Value &other) {
|
||||||
if (one.Type() != other.Type()) return false;
|
if (one.Type() != other.Type()) return false;
|
||||||
@@ -1895,8 +1932,9 @@ bool Sampler::operator==(const Sampler &other) const {
|
|||||||
return this->extensions == other.extensions && this->extras == other.extras &&
|
return this->extensions == other.extensions && this->extras == other.extras &&
|
||||||
this->magFilter == other.magFilter &&
|
this->magFilter == other.magFilter &&
|
||||||
this->minFilter == other.minFilter && this->name == other.name &&
|
this->minFilter == other.minFilter && this->name == other.name &&
|
||||||
this->wrapR == other.wrapR && this->wrapS == other.wrapS &&
|
|
||||||
this->wrapT == other.wrapT;
|
this->wrapT == other.wrapT;
|
||||||
|
|
||||||
|
//this->wrapR == other.wrapR && this->wrapS == other.wrapS &&
|
||||||
}
|
}
|
||||||
bool Scene::operator==(const Scene &other) const {
|
bool Scene::operator==(const Scene &other) const {
|
||||||
return this->extensions == other.extensions && this->extras == other.extras &&
|
return this->extensions == other.extensions && this->extras == other.extras &&
|
||||||
@@ -2297,22 +2335,40 @@ static bool LoadExternalFile(std::vector<unsigned char> *out, std::string *err,
|
|||||||
void TinyGLTF::SetImageLoader(LoadImageDataFunction func, void *user_data) {
|
void TinyGLTF::SetImageLoader(LoadImageDataFunction func, void *user_data) {
|
||||||
LoadImageData = func;
|
LoadImageData = func;
|
||||||
load_image_user_data_ = user_data;
|
load_image_user_data_ = user_data;
|
||||||
|
user_image_loader_ = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TinyGLTF::RemoveImageLoader() {
|
||||||
|
LoadImageData =
|
||||||
|
#ifndef TINYGLTF_NO_STB_IMAGE
|
||||||
|
&tinygltf::LoadImageData;
|
||||||
|
#else
|
||||||
|
nullptr;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
load_image_user_data_ = nullptr;
|
||||||
|
user_image_loader_ = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef TINYGLTF_NO_STB_IMAGE
|
#ifndef TINYGLTF_NO_STB_IMAGE
|
||||||
bool LoadImageData(Image *image, const int image_idx, std::string *err,
|
bool LoadImageData(Image *image, const int image_idx, std::string *err,
|
||||||
std::string *warn, int req_width, int req_height,
|
std::string *warn, int req_width, int req_height,
|
||||||
const unsigned char *bytes, int size, void *user_data) {
|
const unsigned char *bytes, int size, void *user_data) {
|
||||||
(void)user_data;
|
|
||||||
(void)warn;
|
(void)warn;
|
||||||
|
|
||||||
|
LoadImageDataOption option;
|
||||||
|
if (user_data) {
|
||||||
|
option = *reinterpret_cast<LoadImageDataOption *>(user_data);
|
||||||
|
}
|
||||||
|
|
||||||
int w = 0, h = 0, comp = 0, req_comp = 0;
|
int w = 0, h = 0, comp = 0, req_comp = 0;
|
||||||
|
|
||||||
unsigned char *data = nullptr;
|
unsigned char *data = nullptr;
|
||||||
|
|
||||||
// force 32-bit textures for common Vulkan compatibility. It appears that
|
// preserve_channels true: Use channels stored in the image file.
|
||||||
// some GPU drivers do not support 24-bit images for Vulkan
|
// false: force 32-bit textures for common Vulkan compatibility. It appears
|
||||||
req_comp = 4;
|
// that some GPU drivers do not support 24-bit images for Vulkan
|
||||||
|
req_comp = option.preserve_channels ? 0 : 4;
|
||||||
int bits = 8;
|
int bits = 8;
|
||||||
int pixel_type = TINYGLTF_COMPONENT_TYPE_UNSIGNED_BYTE;
|
int pixel_type = TINYGLTF_COMPONENT_TYPE_UNSIGNED_BYTE;
|
||||||
|
|
||||||
@@ -2384,13 +2440,18 @@ bool LoadImageData(Image *image, const int image_idx, std::string *err,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (req_comp != 0) {
|
||||||
|
// loaded data has `req_comp` channels(components)
|
||||||
|
comp = req_comp;
|
||||||
|
}
|
||||||
|
|
||||||
image->width = w;
|
image->width = w;
|
||||||
image->height = h;
|
image->height = h;
|
||||||
image->component = req_comp;
|
image->component = comp;
|
||||||
image->bits = bits;
|
image->bits = bits;
|
||||||
image->pixel_type = pixel_type;
|
image->pixel_type = pixel_type;
|
||||||
image->image.resize(static_cast<size_t>(w * h * req_comp) * size_t(bits / 8));
|
image->image.resize(static_cast<size_t>(w * h * comp) * size_t(bits / 8));
|
||||||
std::copy(data, data + w * h * req_comp * (bits / 8), image->image.begin());
|
std::copy(data, data + w * h * comp * (bits / 8), image->image.begin());
|
||||||
stbi_image_free(data);
|
stbi_image_free(data);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -5028,12 +5089,12 @@ static bool ParseSampler(Sampler *sampler, std::string *err, const json &o,
|
|||||||
int magFilter = -1;
|
int magFilter = -1;
|
||||||
int wrapS = TINYGLTF_TEXTURE_WRAP_REPEAT;
|
int wrapS = TINYGLTF_TEXTURE_WRAP_REPEAT;
|
||||||
int wrapT = TINYGLTF_TEXTURE_WRAP_REPEAT;
|
int wrapT = TINYGLTF_TEXTURE_WRAP_REPEAT;
|
||||||
int wrapR = TINYGLTF_TEXTURE_WRAP_REPEAT;
|
//int wrapR = TINYGLTF_TEXTURE_WRAP_REPEAT;
|
||||||
ParseIntegerProperty(&minFilter, err, o, "minFilter", false);
|
ParseIntegerProperty(&minFilter, err, o, "minFilter", false);
|
||||||
ParseIntegerProperty(&magFilter, err, o, "magFilter", false);
|
ParseIntegerProperty(&magFilter, err, o, "magFilter", false);
|
||||||
ParseIntegerProperty(&wrapS, err, o, "wrapS", false);
|
ParseIntegerProperty(&wrapS, err, o, "wrapS", false);
|
||||||
ParseIntegerProperty(&wrapT, err, o, "wrapT", false);
|
ParseIntegerProperty(&wrapT, err, o, "wrapT", false);
|
||||||
ParseIntegerProperty(&wrapR, err, o, "wrapR", false); // tinygltf extension
|
//ParseIntegerProperty(&wrapR, err, o, "wrapR", false); // tinygltf extension
|
||||||
|
|
||||||
// TODO(syoyo): Check the value is alloed one.
|
// TODO(syoyo): Check the value is alloed one.
|
||||||
// (e.g. we allow 9728(NEAREST), but don't allow 9727)
|
// (e.g. we allow 9728(NEAREST), but don't allow 9727)
|
||||||
@@ -5042,7 +5103,7 @@ static bool ParseSampler(Sampler *sampler, std::string *err, const json &o,
|
|||||||
sampler->magFilter = magFilter;
|
sampler->magFilter = magFilter;
|
||||||
sampler->wrapS = wrapS;
|
sampler->wrapS = wrapS;
|
||||||
sampler->wrapT = wrapT;
|
sampler->wrapT = wrapT;
|
||||||
sampler->wrapR = wrapR;
|
//sampler->wrapR = wrapR;
|
||||||
|
|
||||||
ParseExtensionsProperty(&(sampler->extensions), err, o);
|
ParseExtensionsProperty(&(sampler->extensions), err, o);
|
||||||
ParseExtrasProperty(&(sampler->extras), o);
|
ParseExtrasProperty(&(sampler->extras), o);
|
||||||
@@ -5825,6 +5886,18 @@ bool TinyGLTF::LoadFromString(Model *model, std::string *err, std::string *warn,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 11. Parse Image
|
// 11. Parse Image
|
||||||
|
void *load_image_user_data{nullptr};
|
||||||
|
|
||||||
|
LoadImageDataOption load_image_option;
|
||||||
|
|
||||||
|
if (user_image_loader_) {
|
||||||
|
// Use user supplied pointer
|
||||||
|
load_image_user_data = load_image_user_data_;
|
||||||
|
} else {
|
||||||
|
load_image_option.preserve_channels = preserve_image_channels_;
|
||||||
|
load_image_user_data = reinterpret_cast<void *>(&load_image_option);
|
||||||
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
int idx = 0;
|
int idx = 0;
|
||||||
bool success = ForEachInArray(v, "images", [&](const json &o) {
|
bool success = ForEachInArray(v, "images", [&](const json &o) {
|
||||||
@@ -5837,7 +5910,7 @@ bool TinyGLTF::LoadFromString(Model *model, std::string *err, std::string *warn,
|
|||||||
Image image;
|
Image image;
|
||||||
if (!ParseImage(&image, idx, err, warn, o,
|
if (!ParseImage(&image, idx, err, warn, o,
|
||||||
store_original_json_for_extras_and_extensions_, base_dir,
|
store_original_json_for_extras_and_extensions_, base_dir,
|
||||||
&fs, &this->LoadImageData, load_image_user_data_)) {
|
&fs, &this->LoadImageData, load_image_user_data)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -5875,7 +5948,7 @@ bool TinyGLTF::LoadFromString(Model *model, std::string *err, std::string *warn,
|
|||||||
bool ret = LoadImageData(
|
bool ret = LoadImageData(
|
||||||
&image, idx, err, warn, image.width, image.height,
|
&image, idx, err, warn, image.width, image.height,
|
||||||
&buffer.data[bufferView.byteOffset],
|
&buffer.data[bufferView.byteOffset],
|
||||||
static_cast<int>(bufferView.byteLength), load_image_user_data_);
|
static_cast<int>(bufferView.byteLength), load_image_user_data);
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -6551,8 +6624,33 @@ static void SerializeGltfAccessor(Accessor &accessor, json &o) {
|
|||||||
|
|
||||||
SerializeNumberProperty<int>("componentType", accessor.componentType, o);
|
SerializeNumberProperty<int>("componentType", accessor.componentType, o);
|
||||||
SerializeNumberProperty<size_t>("count", accessor.count, o);
|
SerializeNumberProperty<size_t>("count", accessor.count, o);
|
||||||
SerializeNumberArrayProperty<double>("min", accessor.minValues, o);
|
|
||||||
SerializeNumberArrayProperty<double>("max", accessor.maxValues, o);
|
if ((accessor.componentType == TINYGLTF_COMPONENT_TYPE_FLOAT) ||
|
||||||
|
(accessor.componentType == TINYGLTF_COMPONENT_TYPE_DOUBLE)) {
|
||||||
|
SerializeNumberArrayProperty<double>("min", accessor.minValues, o);
|
||||||
|
SerializeNumberArrayProperty<double>("max", accessor.maxValues, o);
|
||||||
|
} else {
|
||||||
|
// Issue #301. Serialize as integer.
|
||||||
|
// Assume int value is within [-2**31-1, 2**31-1]
|
||||||
|
{
|
||||||
|
std::vector<int> values;
|
||||||
|
std::transform(accessor.minValues.begin(), accessor.minValues.end(),
|
||||||
|
std::back_inserter(values),
|
||||||
|
[](double v) { return static_cast<int>(v); });
|
||||||
|
|
||||||
|
SerializeNumberArrayProperty<int>("min", values, o);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
std::vector<int> values;
|
||||||
|
std::transform(accessor.maxValues.begin(), accessor.maxValues.end(),
|
||||||
|
std::back_inserter(values),
|
||||||
|
[](double v) { return static_cast<int>(v); });
|
||||||
|
|
||||||
|
SerializeNumberArrayProperty<int>("max", values, o);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (accessor.normalized)
|
if (accessor.normalized)
|
||||||
SerializeValue("normalized", Value(accessor.normalized), o);
|
SerializeValue("normalized", Value(accessor.normalized), o);
|
||||||
std::string type;
|
std::string type;
|
||||||
@@ -6662,10 +6760,15 @@ static void SerializeGltfAsset(Asset &asset, json &o) {
|
|||||||
SerializeStringProperty("copyright", asset.copyright, o);
|
SerializeStringProperty("copyright", asset.copyright, o);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!asset.version.empty()) {
|
if (asset.version.empty()) {
|
||||||
SerializeStringProperty("version", asset.version, o);
|
// Just in case
|
||||||
|
// `version` must be defined
|
||||||
|
asset.version = "2.0";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO(syoyo): Do we need to check if `version` is greater or equal to 2.0?
|
||||||
|
SerializeStringProperty("version", asset.version, o);
|
||||||
|
|
||||||
if (asset.extras.Keys().size()) {
|
if (asset.extras.Keys().size()) {
|
||||||
SerializeValue("extras", asset.extras, o);
|
SerializeValue("extras", asset.extras, o);
|
||||||
}
|
}
|
||||||
@@ -7063,7 +7166,7 @@ static void SerializeGltfSampler(Sampler &sampler, json &o) {
|
|||||||
if (sampler.minFilter != -1) {
|
if (sampler.minFilter != -1) {
|
||||||
SerializeNumberProperty("minFilter", sampler.minFilter, o);
|
SerializeNumberProperty("minFilter", sampler.minFilter, o);
|
||||||
}
|
}
|
||||||
SerializeNumberProperty("wrapR", sampler.wrapR, o);
|
//SerializeNumberProperty("wrapR", sampler.wrapR, o);
|
||||||
SerializeNumberProperty("wrapS", sampler.wrapS, o);
|
SerializeNumberProperty("wrapS", sampler.wrapS, o);
|
||||||
SerializeNumberProperty("wrapT", sampler.wrapT, o);
|
SerializeNumberProperty("wrapT", sampler.wrapT, o);
|
||||||
|
|
||||||
@@ -7225,6 +7328,16 @@ static void SerializeGltfModel(Model *model, json &o) {
|
|||||||
for (unsigned int i = 0; i < model->materials.size(); ++i) {
|
for (unsigned int i = 0; i < model->materials.size(); ++i) {
|
||||||
json material;
|
json material;
|
||||||
SerializeGltfMaterial(model->materials[i], material);
|
SerializeGltfMaterial(model->materials[i], material);
|
||||||
|
|
||||||
|
if (JsonIsNull(material)) {
|
||||||
|
// Issue 294.
|
||||||
|
// `material` does not have any required parameters
|
||||||
|
// so the result may be null(unmodified) when all material parameters
|
||||||
|
// have default value.
|
||||||
|
//
|
||||||
|
// null is not allowed thus we create an empty JSON object.
|
||||||
|
JsonSetObject(material);
|
||||||
|
}
|
||||||
JsonPushBack(materials, std::move(material));
|
JsonPushBack(materials, std::move(material));
|
||||||
}
|
}
|
||||||
JsonAddMember(o, "materials", std::move(materials));
|
JsonAddMember(o, "materials", std::move(materials));
|
||||||
@@ -7363,7 +7476,7 @@ static void SerializeGltfModel(Model *model, json &o) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Extensions used
|
// Extensions used
|
||||||
if (model->extensionsUsed.size()) {
|
if (extensionsUsed.size()) {
|
||||||
SerializeStringArrayProperty("extensionsUsed", extensionsUsed, o);
|
SerializeStringArrayProperty("extensionsUsed", extensionsUsed, o);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user