mirror of
https://github.com/syoyo/tinygltf.git
synced 2026-06-13 18:58:53 +00:00
Compare commits
28 Commits
github-act
...
empty-mate
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1923067982 | ||
|
|
68adc4ba5e | ||
|
|
42a8cd50ff | ||
|
|
0543640a83 | ||
|
|
9c59a0b64c | ||
|
|
452541a231 | ||
|
|
78fe8d9b89 | ||
|
|
51e5508fa0 | ||
|
|
91da299729 | ||
|
|
50ae8a31a8 | ||
|
|
0af0435ef1 | ||
|
|
7c342533e9 | ||
|
|
7842c1276f | ||
|
|
125e4a2033 | ||
|
|
c9d6c5b9b4 | ||
|
|
96a8b2c69b | ||
|
|
01d54380ac | ||
|
|
6cd8fdb2c8 | ||
|
|
fe01af2f01 | ||
|
|
efdd2b04dc | ||
|
|
2e642b3322 | ||
|
|
1739d025a9 | ||
|
|
39418e5728 | ||
|
|
5622d2762d | ||
|
|
3d939fd3ee | ||
|
|
fbbeb4d6a9 | ||
|
|
cef1787ef8 | ||
|
|
2f5aa9f13b |
1
.github/ISSUE_TEMPLATE/config.yml
vendored
Normal file
1
.github/ISSUE_TEMPLATE/config.yml
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
blank_issues_enabled: false
|
||||||
30
.github/ISSUE_TEMPLATE/issue-report.md
vendored
Normal file
30
.github/ISSUE_TEMPLATE/issue-report.md
vendored
Normal 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.
|
||||||
@@ -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)
|
||||||
|
|||||||
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
|
||||||
|
|||||||
36
examples/dxview/CMakeLists.txt
Normal file
36
examples/dxview/CMakeLists.txt
Normal 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
37
examples/dxview/README.md
Normal 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
|
||||||
|
```
|
||||||
3
examples/dxview/res/gray.hlsl
Normal file
3
examples/dxview/res/gray.hlsl
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
float4 main() : SV_Target {
|
||||||
|
return float4(0.5, 0.5, 0.5, 1.0);
|
||||||
|
}
|
||||||
52
examples/dxview/res/lighting.hlsl
Normal file
52
examples/dxview/res/lighting.hlsl
Normal 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;
|
||||||
|
}
|
||||||
46
examples/dxview/res/primitive.hlsl
Normal file
46
examples/dxview/res/primitive.hlsl
Normal 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;
|
||||||
|
}
|
||||||
1292
examples/dxview/src/Viewer.cc
Normal file
1292
examples/dxview/src/Viewer.cc
Normal file
File diff suppressed because it is too large
Load Diff
130
examples/dxview/src/Viewer.h
Normal file
130
examples/dxview/src/Viewer.h
Normal 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
|
||||||
90
examples/dxview/src/dxview.cc
Normal file
90
examples/dxview/src/dxview.cc
Normal 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);
|
||||||
|
}
|
||||||
Binary file not shown.
@@ -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,3 +415,41 @@ 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["asset"].is_null());
|
||||||
|
REQUIRE(j["materials"][0].is_object());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifndef TINYGLTF_NO_FS
|
||||||
|
TEST_CASE("expandpath-utf-8", "[pr-226]") {
|
||||||
|
|
||||||
|
std::string s1 = "\xe5\xaf\xb9"; // utf-8 string
|
||||||
|
|
||||||
|
std::string ret = tinygltf::ExpandFilePath(s1, /* userdata */nullptr);
|
||||||
|
|
||||||
|
// expected: E5 AF B9
|
||||||
|
REQUIRE(3 == ret.size());
|
||||||
|
|
||||||
|
REQUIRE(0xe5 == static_cast<uint8_t>(ret[0]));
|
||||||
|
REQUIRE(0xaf == static_cast<uint8_t>(ret[1]));
|
||||||
|
REQUIRE(0xb9 == static_cast<uint8_t>(ret[2]));
|
||||||
|
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|||||||
69
tiny_gltf.h
69
tiny_gltf.h
@@ -26,6 +26,7 @@
|
|||||||
// THE SOFTWARE.
|
// THE SOFTWARE.
|
||||||
|
|
||||||
// Version:
|
// Version:
|
||||||
|
// - 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.
|
||||||
@@ -664,6 +665,8 @@ struct Image {
|
|||||||
width = -1;
|
width = -1;
|
||||||
height = -1;
|
height = -1;
|
||||||
component = -1;
|
component = -1;
|
||||||
|
bits = -1;
|
||||||
|
pixel_type = -1;
|
||||||
}
|
}
|
||||||
DEFAULT_METHODS(Image)
|
DEFAULT_METHODS(Image)
|
||||||
|
|
||||||
@@ -996,6 +999,7 @@ struct Primitive {
|
|||||||
Primitive() {
|
Primitive() {
|
||||||
material = -1;
|
material = -1;
|
||||||
indices = -1;
|
indices = -1;
|
||||||
|
mode = -1;
|
||||||
}
|
}
|
||||||
DEFAULT_METHODS(Primitive)
|
DEFAULT_METHODS(Primitive)
|
||||||
bool operator==(const Primitive &) const;
|
bool operator==(const Primitive &) const;
|
||||||
@@ -1249,7 +1253,14 @@ struct FsCallbacks {
|
|||||||
|
|
||||||
bool FileExists(const std::string &abs_filename, void *);
|
bool FileExists(const std::string &abs_filename, void *);
|
||||||
|
|
||||||
std::string ExpandFilePath(const std::string &filepath, void *);
|
///
|
||||||
|
/// 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.
|
||||||
|
///
|
||||||
|
std::string ExpandFilePath(const std::string &filepath, void *userdata);
|
||||||
|
|
||||||
bool ReadWholeFile(std::vector<unsigned char> *out, std::string *err,
|
bool ReadWholeFile(std::vector<unsigned char> *out, std::string *err,
|
||||||
const std::string &filepath, void *);
|
const std::string &filepath, void *);
|
||||||
@@ -2483,6 +2494,15 @@ static inline std::wstring UTF8ToWchar(const std::string &str) {
|
|||||||
(int)wstr.size());
|
(int)wstr.size());
|
||||||
return wstr;
|
return wstr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
std::string str(str_size, 0);
|
||||||
|
WideCharToMultiByte(CP_UTF8, 0, wstr.data(), (int)wstr.size(), &str[0],
|
||||||
|
(int)str.size(), NULL, NULL);
|
||||||
|
return str;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef TINYGLTF_NO_FS
|
#ifndef TINYGLTF_NO_FS
|
||||||
@@ -2534,15 +2554,16 @@ bool FileExists(const std::string &abs_filename, void *) {
|
|||||||
|
|
||||||
std::string ExpandFilePath(const std::string &filepath, void *) {
|
std::string ExpandFilePath(const std::string &filepath, void *) {
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
DWORD len = ExpandEnvironmentStringsA(filepath.c_str(), NULL, 0);
|
// Assume input `filepath` is encoded in UTF-8
|
||||||
char *str = new char[len];
|
std::wstring wfilepath = UTF8ToWchar(filepath);
|
||||||
ExpandEnvironmentStringsA(filepath.c_str(), str, len);
|
DWORD wlen = ExpandEnvironmentStringsW(wfilepath.c_str(), nullptr, 0);
|
||||||
|
wchar_t *wstr = new wchar_t[wlen];
|
||||||
|
ExpandEnvironmentStringsW(wfilepath.c_str(), wstr, wlen);
|
||||||
|
|
||||||
std::string s(str);
|
std::wstring ws(wstr);
|
||||||
|
delete[] wstr;
|
||||||
|
return WcharToUTF8(ws);
|
||||||
|
|
||||||
delete[] str;
|
|
||||||
|
|
||||||
return s;
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
#if defined(TARGET_OS_IPHONE) || defined(TARGET_IPHONE_SIMULATOR) || \
|
#if defined(TARGET_OS_IPHONE) || defined(TARGET_IPHONE_SIMULATOR) || \
|
||||||
@@ -2619,7 +2640,8 @@ bool ReadWholeFile(std::vector<unsigned char> *out, std::string *err,
|
|||||||
__gnu_cxx::stdio_filebuf<char> wfile_buf(file_descriptor, std::ios_base::in);
|
__gnu_cxx::stdio_filebuf<char> wfile_buf(file_descriptor, std::ios_base::in);
|
||||||
std::istream f(&wfile_buf);
|
std::istream f(&wfile_buf);
|
||||||
#elif defined(_MSC_VER) || defined(_LIBCPP_VERSION)
|
#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);
|
std::ifstream f(UTF8ToWchar(filepath).c_str(), std::ifstream::binary);
|
||||||
#else
|
#else
|
||||||
// Unknown compiler/runtime
|
// Unknown compiler/runtime
|
||||||
@@ -2981,7 +3003,9 @@ json_const_iterator ObjectEnd(const json &o) {
|
|||||||
#endif
|
#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
|
#ifdef TINYGLTF_USE_RAPIDJSON
|
||||||
return it->name.GetString();
|
return it->name.GetString();
|
||||||
#else
|
#else
|
||||||
@@ -5686,10 +5710,13 @@ bool TinyGLTF::LoadFromString(Model *model, std::string *err, std::string *warn,
|
|||||||
|
|
||||||
for (auto &target : primitive.targets) {
|
for (auto &target : primitive.targets) {
|
||||||
for (auto &attribute : target) {
|
for (auto &attribute : target) {
|
||||||
model
|
auto bufferView =
|
||||||
->bufferViews[size_t(
|
model->accessors[size_t(attribute.second)].bufferView;
|
||||||
model->accessors[size_t(attribute.second)].bufferView)]
|
// bufferView could be null(-1) for sparse morph target
|
||||||
.target = TINYGLTF_TARGET_ARRAY_BUFFER;
|
if (bufferView >= 0) {
|
||||||
|
model->bufferViews[size_t(bufferView)].target =
|
||||||
|
TINYGLTF_TARGET_ARRAY_BUFFER;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -7199,6 +7226,15 @@ 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));
|
||||||
@@ -7324,8 +7360,9 @@ static void SerializeGltfModel(Model *model, json &o) {
|
|||||||
|
|
||||||
// Also add "KHR_lights_punctual" to `extensionsUsed`
|
// Also add "KHR_lights_punctual" to `extensionsUsed`
|
||||||
{
|
{
|
||||||
auto has_khr_lights_punctual = std::find_if(
|
auto has_khr_lights_punctual =
|
||||||
extensionsUsed.begin(), extensionsUsed.end(), [](const std::string &s) {
|
std::find_if(extensionsUsed.begin(), extensionsUsed.end(),
|
||||||
|
[](const std::string &s) {
|
||||||
return (s.compare("KHR_lights_punctual") == 0);
|
return (s.compare("KHR_lights_punctual") == 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user