added cgltf (https://github.com/jkuhlmann/cgltf) to 3rdparty
This commit is contained in:
parent
e829a18299
commit
78138af6bf
13
3rdparty/cgltf/.travis.yml
vendored
Normal file
13
3rdparty/cgltf/.travis.yml
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
os:
|
||||
- linux
|
||||
- osx
|
||||
- windows
|
||||
language: c
|
||||
compiler:
|
||||
- gcc
|
||||
- clang
|
||||
sudo: false
|
||||
script:
|
||||
- cd test/
|
||||
- ./test_all.py
|
||||
|
7
3rdparty/cgltf/LICENSE
vendored
Normal file
7
3rdparty/cgltf/LICENSE
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
Copyright (c) 2018 Johannes Kuhlmann
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
141
3rdparty/cgltf/README.md
vendored
Normal file
141
3rdparty/cgltf/README.md
vendored
Normal file
@ -0,0 +1,141 @@
|
||||
# cgltf
|
||||
**Single-file/stb-style C glTF loader and writer**
|
||||
|
||||
[![Build Status](https://travis-ci.org/jkuhlmann/cgltf.svg?branch=master)](https://travis-ci.org/jkuhlmann/cgltf)
|
||||
|
||||
## Usage: Loading
|
||||
Loading from file:
|
||||
```c
|
||||
#include "cgltf.h"
|
||||
|
||||
cgltf_options options = {0};
|
||||
cgltf_data* data = NULL;
|
||||
cgltf_result result = cgltf_parse_file(&options, "scene.gltf", &data);
|
||||
if (result == cgltf_result_success)
|
||||
{
|
||||
/* TODO make awesome stuff */
|
||||
cgltf_free(data);
|
||||
}
|
||||
```
|
||||
|
||||
Loading from memory:
|
||||
```c
|
||||
#include "cgltf.h"
|
||||
|
||||
void* buf; /* Pointer to glb or gltf file data */
|
||||
size_t size; /* Size of the file data */
|
||||
|
||||
cgltf_options options = {0};
|
||||
cgltf_data* data = NULL;
|
||||
cgltf_result result = cgltf_parse(&options, buf, size, &data);
|
||||
if (result == cgltf_result_success)
|
||||
{
|
||||
/* TODO make awesome stuff */
|
||||
cgltf_free(data);
|
||||
}
|
||||
```
|
||||
|
||||
Note that cgltf does not load the contents of extra files such as buffers or images into memory by default. You'll need to read these files yourself using URIs from `data.buffers[]` or `data.images[]` respectively.
|
||||
For buffer data, you can alternatively call `cgltf_load_buffers`, which will use `FILE*` APIs to open and read buffer files.
|
||||
|
||||
**For more in-depth documentation and a description of the public interface refer to the top of the `cgltf.h` file.**
|
||||
|
||||
## Usage: Writing
|
||||
When writing glTF data, you need a valid `cgltf_data` structure that represents a valid glTF document. You can construct such a structure yourself or load it using the loader functions described above. The writer functions do not deallocate any memory. So, you either have to do it manually or call `cgltf_free()` if you got the data by loading it from a glTF document.
|
||||
|
||||
Writing to file:
|
||||
```c
|
||||
#include "cgltf_write.h"
|
||||
|
||||
cgltf_options options = {0};
|
||||
cgltf_data* data = /* TODO must be valid data */;
|
||||
cgltf_result result = cgltf_write_file(&options, "out.gltf", data);
|
||||
if (result != cgltf_result_success)
|
||||
{
|
||||
/* TODO handle error */
|
||||
}
|
||||
```
|
||||
|
||||
Writing to memory:
|
||||
```c
|
||||
#include "cgltf_write.h"
|
||||
cgltf_options options = {0};
|
||||
cgltf_data* data = /* TODO must be valid data */;
|
||||
|
||||
cgltf_size size = cgltf_write(&options, NULL, 0, data);
|
||||
|
||||
char* buf = malloc(size);
|
||||
|
||||
cgltf_size written = cgltf_write(&options, buf, size, data);
|
||||
if (written != size)
|
||||
{
|
||||
/* TODO handle error */
|
||||
}
|
||||
```
|
||||
|
||||
Note that cgltf does not write the contents of extra files such as buffers or images. You'll need to write this data yourself.
|
||||
|
||||
Writing does not yet support "extras" data.
|
||||
|
||||
**For more in-depth documentation and a description of the public interface refer to the top of the `cgltf_write.h` file.**
|
||||
|
||||
|
||||
## Features
|
||||
cgltf supports core glTF 2.0:
|
||||
- glb (binary files) and gltf (JSON files)
|
||||
- meshes (including accessors, buffer views, buffers)
|
||||
- materials (including textures, samplers, images)
|
||||
- scenes and nodes
|
||||
- skins
|
||||
- animations
|
||||
- cameras
|
||||
- morph targets
|
||||
- extras data
|
||||
|
||||
cgltf also supports some glTF extensions:
|
||||
- KHR_lights_punctual
|
||||
- KHR_materials_pbrSpecularGlossiness
|
||||
- KHR_materials_unlit
|
||||
- KHR_texture_transform
|
||||
|
||||
cgltf does **not** yet support unlisted extensions.
|
||||
|
||||
## Building
|
||||
The easiest approach is to integrate the `cgltf.h` header file into your project. If you are unfamiliar with single-file C libraries (also known as stb-style libraries), this is how it goes:
|
||||
|
||||
1. Include `cgltf.h` where you need the functionality.
|
||||
1. Have exactly one source file that defines `CGLTF_IMPLEMENTATION` before including `cgltf.h`.
|
||||
1. Use the cgltf functions as described above.
|
||||
|
||||
Support for writing can be found in a separate file called `cgltf_write.h` (which includes `cgltf.h`). Building it works analogously using the `CGLTF_WRITE_IMPLEMENTATION` define.
|
||||
|
||||
## Contributing
|
||||
Everyone is welcome to contribute to the library. If you find any problems, you can submit them using [GitHub's issue system](https://github.com/jkuhlmann/cgltf/issues). If you want to contribute code, you should fork the project and then send a pull request.
|
||||
|
||||
|
||||
## Dependencies
|
||||
None.
|
||||
|
||||
C headers being used by implementation:
|
||||
```
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <limits.h>
|
||||
```
|
||||
|
||||
Note, this library has a copy of the [JSMN JSON parser](https://github.com/zserge/jsmn) embedded in its source.
|
||||
|
||||
## Testing
|
||||
There is a Python script in the `test/` folder that retrieves the glTF 2.0 sample files from the glTF-Sample-Models repository (https://github.com/KhronosGroup/glTF-Sample-Models/tree/master/2.0) and runs the library against all gltf and glb files.
|
||||
|
||||
Here's one way to build and run the test:
|
||||
|
||||
cd test ; mkdir build ; cd build ; cmake .. -DCMAKE_BUILD_TYPE=Debug
|
||||
make -j
|
||||
cd ..
|
||||
./test_all.py
|
||||
|
||||
There is also a llvm-fuzz test in `fuzz/`. See http://llvm.org/docs/LibFuzzer.html for more information.
|
4837
3rdparty/cgltf/cgltf.h
vendored
Normal file
4837
3rdparty/cgltf/cgltf.h
vendored
Normal file
File diff suppressed because it is too large
Load Diff
1006
3rdparty/cgltf/cgltf_write.h
vendored
Normal file
1006
3rdparty/cgltf/cgltf_write.h
vendored
Normal file
File diff suppressed because it is too large
Load Diff
BIN
3rdparty/cgltf/fuzz/data/Box.glb
vendored
Normal file
BIN
3rdparty/cgltf/fuzz/data/Box.glb
vendored
Normal file
Binary file not shown.
53
3rdparty/cgltf/fuzz/data/TriangleWithoutIndices.gltf
vendored
Normal file
53
3rdparty/cgltf/fuzz/data/TriangleWithoutIndices.gltf
vendored
Normal file
@ -0,0 +1,53 @@
|
||||
{
|
||||
"scenes" : [
|
||||
{
|
||||
"nodes" : [ 0 ]
|
||||
}
|
||||
],
|
||||
|
||||
"nodes" : [
|
||||
{
|
||||
"mesh" : 0
|
||||
}
|
||||
],
|
||||
|
||||
"meshes" : [
|
||||
{
|
||||
"primitives" : [ {
|
||||
"attributes" : {
|
||||
"POSITION" : 0
|
||||
}
|
||||
} ]
|
||||
}
|
||||
],
|
||||
|
||||
"buffers" : [
|
||||
{
|
||||
"uri" : "data:application/octet-stream;base64,AAAAAAAAAAAAAAAAAACAPwAAAAAAAAAAAAAAAAAAgD8AAAAA",
|
||||
"byteLength" : 36
|
||||
}
|
||||
],
|
||||
"bufferViews" : [
|
||||
{
|
||||
"buffer" : 0,
|
||||
"byteOffset" : 0,
|
||||
"byteLength" : 36,
|
||||
"target" : 34962
|
||||
}
|
||||
],
|
||||
"accessors" : [
|
||||
{
|
||||
"bufferView" : 0,
|
||||
"byteOffset" : 0,
|
||||
"componentType" : 5126,
|
||||
"count" : 3,
|
||||
"type" : "VEC3",
|
||||
"max" : [ 1.0, 1.0, 0.0 ],
|
||||
"min" : [ 0.0, 0.0, 0.0 ]
|
||||
}
|
||||
],
|
||||
|
||||
"asset" : {
|
||||
"version" : "2.0"
|
||||
}
|
||||
}
|
172
3rdparty/cgltf/fuzz/data/WaterBottle.gltf
vendored
Normal file
172
3rdparty/cgltf/fuzz/data/WaterBottle.gltf
vendored
Normal file
@ -0,0 +1,172 @@
|
||||
{
|
||||
"accessors": [
|
||||
{
|
||||
"bufferView": 0,
|
||||
"componentType": 5126,
|
||||
"count": 2549,
|
||||
"type": "VEC2"
|
||||
},
|
||||
{
|
||||
"bufferView": 1,
|
||||
"componentType": 5126,
|
||||
"count": 2549,
|
||||
"type": "VEC3"
|
||||
},
|
||||
{
|
||||
"bufferView": 2,
|
||||
"componentType": 5126,
|
||||
"count": 2549,
|
||||
"type": "VEC4"
|
||||
},
|
||||
{
|
||||
"bufferView": 3,
|
||||
"componentType": 5126,
|
||||
"count": 2549,
|
||||
"type": "VEC3",
|
||||
"max": [
|
||||
0.05445001,
|
||||
0.130220339,
|
||||
0.0544500239
|
||||
],
|
||||
"min": [
|
||||
-0.05445001,
|
||||
-0.130220339,
|
||||
-0.0544500239
|
||||
]
|
||||
},
|
||||
{
|
||||
"bufferView": 4,
|
||||
"componentType": 5123,
|
||||
"count": 13530,
|
||||
"type": "SCALAR"
|
||||
}
|
||||
],
|
||||
"asset": {
|
||||
"generator": "glTF Tools for Unity",
|
||||
"version": "2.0"
|
||||
},
|
||||
"bufferViews": [
|
||||
{
|
||||
"buffer": 0,
|
||||
"byteLength": 20392
|
||||
},
|
||||
{
|
||||
"buffer": 0,
|
||||
"byteOffset": 20392,
|
||||
"byteLength": 30588
|
||||
},
|
||||
{
|
||||
"buffer": 0,
|
||||
"byteOffset": 50980,
|
||||
"byteLength": 40784
|
||||
},
|
||||
{
|
||||
"buffer": 0,
|
||||
"byteOffset": 91764,
|
||||
"byteLength": 30588
|
||||
},
|
||||
{
|
||||
"buffer": 0,
|
||||
"byteOffset": 122352,
|
||||
"byteLength": 27060
|
||||
}
|
||||
],
|
||||
"buffers": [
|
||||
{
|
||||
"uri": "WaterBottle.bin",
|
||||
"byteLength": 149412
|
||||
}
|
||||
],
|
||||
"images": [
|
||||
{
|
||||
"uri": "WaterBottle_baseColor.png"
|
||||
},
|
||||
{
|
||||
"uri": "WaterBottle_occlusionRoughnessMetallic.png"
|
||||
},
|
||||
{
|
||||
"uri": "WaterBottle_normal.png"
|
||||
},
|
||||
{
|
||||
"uri": "WaterBottle_emissive.png"
|
||||
}
|
||||
],
|
||||
"meshes": [
|
||||
{
|
||||
"primitives": [
|
||||
{
|
||||
"attributes": {
|
||||
"TEXCOORD_0": 0,
|
||||
"NORMAL": 1,
|
||||
"TANGENT": 2,
|
||||
"POSITION": 3
|
||||
},
|
||||
"indices": 4,
|
||||
"material": 0
|
||||
}
|
||||
],
|
||||
"name": "WaterBottle"
|
||||
}
|
||||
],
|
||||
"materials": [
|
||||
{
|
||||
"pbrMetallicRoughness": {
|
||||
"baseColorTexture": {
|
||||
"index": 0
|
||||
},
|
||||
"metallicRoughnessTexture": {
|
||||
"index": 1
|
||||
}
|
||||
},
|
||||
"normalTexture": {
|
||||
"index": 2
|
||||
},
|
||||
"occlusionTexture": {
|
||||
"index": 1
|
||||
},
|
||||
"emissiveFactor": [
|
||||
1.0,
|
||||
1.0,
|
||||
1.0
|
||||
],
|
||||
"emissiveTexture": {
|
||||
"index": 3
|
||||
},
|
||||
"name": "BottleMat"
|
||||
}
|
||||
],
|
||||
"nodes": [
|
||||
{
|
||||
"mesh": 0,
|
||||
"rotation": [
|
||||
0.0,
|
||||
1.0,
|
||||
0.0,
|
||||
0.0
|
||||
],
|
||||
"name": "WaterBottle"
|
||||
}
|
||||
],
|
||||
"scene": 0,
|
||||
"scenes": [
|
||||
{
|
||||
"nodes": [
|
||||
0
|
||||
]
|
||||
}
|
||||
],
|
||||
"textures": [
|
||||
{
|
||||
"source": 0
|
||||
},
|
||||
{
|
||||
"source": 1
|
||||
},
|
||||
{
|
||||
"source": 2
|
||||
},
|
||||
{
|
||||
"source": 3
|
||||
}
|
||||
]
|
||||
}
|
201
3rdparty/cgltf/fuzz/gltf.dict
vendored
Normal file
201
3rdparty/cgltf/fuzz/gltf.dict
vendored
Normal file
@ -0,0 +1,201 @@
|
||||
#
|
||||
# AFL dictionary for JSON
|
||||
# -----------------------
|
||||
#
|
||||
# Just the very basics.
|
||||
#
|
||||
# Inspired by a dictionary by Jakub Wilk <jwilk@jwilk.net>
|
||||
#
|
||||
|
||||
"0"
|
||||
",0"
|
||||
":0"
|
||||
"0:"
|
||||
"-1.2e+3"
|
||||
|
||||
"true"
|
||||
"false"
|
||||
"null"
|
||||
|
||||
"\"\""
|
||||
",\"\""
|
||||
":\"\""
|
||||
"\"\":"
|
||||
|
||||
"{}"
|
||||
",{}"
|
||||
":{}"
|
||||
"{\"\":0}"
|
||||
"{{}}"
|
||||
|
||||
"[]"
|
||||
",[]"
|
||||
":[]"
|
||||
"[0]"
|
||||
"[[]]"
|
||||
|
||||
"''"
|
||||
"\\"
|
||||
"\\b"
|
||||
"\\f"
|
||||
"\\n"
|
||||
"\\r"
|
||||
"\\t"
|
||||
"\\u0000"
|
||||
"\\x00"
|
||||
"\\0"
|
||||
"\\uD800\\uDC00"
|
||||
"\\uDBFF\\uDFFF"
|
||||
|
||||
"\"\":0"
|
||||
"//"
|
||||
"/**/"
|
||||
|
||||
#
|
||||
# AFL dictionary for GLTF core
|
||||
# -----------------------
|
||||
|
||||
"5120"
|
||||
"5121"
|
||||
"5122"
|
||||
"5123"
|
||||
"5125"
|
||||
"5126"
|
||||
"\"BLEND\""
|
||||
"\"CUBICSPLINE\""
|
||||
"\"LINEAR\""
|
||||
"\"MASK\""
|
||||
"\"MAT2\""
|
||||
"\"MAT3\""
|
||||
"\"MAT4\""
|
||||
"\"OPAQUE\""
|
||||
"\"SCALAR\""
|
||||
"\"STEP\""
|
||||
"\"VEC2\""
|
||||
"\"VEC3\""
|
||||
"\"VEC4\""
|
||||
"\"accessor\""
|
||||
"\"accessors\""
|
||||
"\"alphaCutoff\""
|
||||
"\"alphaMode\""
|
||||
"\"animations\""
|
||||
"\"aspectRatio\""
|
||||
"\"asset\""
|
||||
"\"attributes\""
|
||||
"\"baseColorFactor\""
|
||||
"\"baseColorTexture\""
|
||||
"\"bufferView\""
|
||||
"\"bufferViews\""
|
||||
"\"buffer\""
|
||||
"\"buffers\""
|
||||
"\"byteLength\""
|
||||
"\"byteOffset\""
|
||||
"\"byteStride\""
|
||||
"\"camera\""
|
||||
"\"cameras\""
|
||||
"\"channel\""
|
||||
"\"channels\""
|
||||
"\"children\""
|
||||
"\"componentType\""
|
||||
"\"copyright\""
|
||||
"\"count\""
|
||||
"\"doubleSided\""
|
||||
"\"emissiveFactor\""
|
||||
"\"emissiveTexture\""
|
||||
"\"extensionsRequired\""
|
||||
"\"extensionsUsed\""
|
||||
"\"extensions\""
|
||||
"\"extras\""
|
||||
"\"generator\""
|
||||
"\"image\""
|
||||
"\"images\""
|
||||
"\"index\""
|
||||
"\"indices\""
|
||||
"\"input\""
|
||||
"\"interpolation\""
|
||||
"\"inverseBindMatrices\""
|
||||
"\"joints\""
|
||||
"\"magFilter\""
|
||||
"\"material\""
|
||||
"\"materials\""
|
||||
"\"matrix\""
|
||||
"\"max\""
|
||||
"\"mesh\""
|
||||
"\"meshes\""
|
||||
"\"metallicFactor\""
|
||||
"\"metallicRoughnessTexture\""
|
||||
"\"mimeType\""
|
||||
"\"minFilter\""
|
||||
"\"minVersion\""
|
||||
"\"min\""
|
||||
"\"mode\""
|
||||
"\"name\""
|
||||
"\"node\""
|
||||
"\"nodes\""
|
||||
"\"normalTextureInfo\""
|
||||
"\"normalTexture\""
|
||||
"\"normalized\""
|
||||
"\"occlusionTextureInfo\""
|
||||
"\"occlusionTexture\""
|
||||
"\"orthographic\""
|
||||
"\"output\""
|
||||
"\"path\""
|
||||
"\"pbrMetallicRoughness\""
|
||||
"\"perspective\""
|
||||
"\"primitive\""
|
||||
"\"primitives\""
|
||||
"\"rotation\""
|
||||
"\"roughnessFactor\""
|
||||
"\"sampler\""
|
||||
"\"samplers\""
|
||||
"\"scale\""
|
||||
"\"scene\""
|
||||
"\"scenes\""
|
||||
"\"skeleton\""
|
||||
"\"skin\""
|
||||
"\"skins\""
|
||||
"\"source\""
|
||||
"\"sparse\""
|
||||
"\"strength\""
|
||||
"\"target\""
|
||||
"\"targets\""
|
||||
"\"texCoord\""
|
||||
"\"textureInfo\""
|
||||
"\"texture\""
|
||||
"\"textures\""
|
||||
"\"translation\""
|
||||
"\"type\""
|
||||
"\"uri\""
|
||||
"\"values\""
|
||||
"\"version\""
|
||||
"\"weights\""
|
||||
"\"wrapS\""
|
||||
"\"wrapT\""
|
||||
"\"xmag\""
|
||||
"\"yfov\""
|
||||
"\"ymag\""
|
||||
"\"zfar\""
|
||||
"\"znear\""
|
||||
|
||||
#
|
||||
# AFL dictionary for GLTF extensions
|
||||
# -----------------------
|
||||
"\"KHR_materials_pbrSpecularGlossiness\""
|
||||
"\"diffuseFactor\""
|
||||
"\"diffuseTexture\""
|
||||
"\"specularFactor\""
|
||||
"\"glossinessFactor\""
|
||||
"\"specularGlossinessTexture\""
|
||||
"\"KHR_materials_unlit\""
|
||||
"\"KHR_texture_transform\""
|
||||
"\"offset\""
|
||||
"\"rotation\""
|
||||
"\"scale\""
|
||||
"\"texCoord\""
|
||||
"\"KHR_lights_punctual\""
|
||||
"\"color\""
|
||||
"\"intensity\""
|
||||
"\"type\""
|
||||
"\"range\""
|
||||
"\"innerConeAngle\""
|
||||
"\"outerConeAngle\""
|
22
3rdparty/cgltf/fuzz/main.c
vendored
Normal file
22
3rdparty/cgltf/fuzz/main.c
vendored
Normal file
@ -0,0 +1,22 @@
|
||||
/* How to fuzz:
|
||||
|
||||
clang main.c -O2 -g -fsanitize=address,fuzzer -o fuzz
|
||||
cp -r data temp
|
||||
./fuzz temp/ -dict=gltf.dict -jobs=12 -workers=12
|
||||
|
||||
*/
|
||||
#define CGLTF_IMPLEMENTATION
|
||||
#include "../cgltf.h"
|
||||
|
||||
int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
|
||||
{
|
||||
cgltf_options options = {0};
|
||||
cgltf_data* data = NULL;
|
||||
cgltf_result res = cgltf_parse(&options, Data, Size, &data);
|
||||
if (res == cgltf_result_success)
|
||||
{
|
||||
cgltf_validate(data);
|
||||
cgltf_free(data);
|
||||
}
|
||||
return 0;
|
||||
}
|
23
3rdparty/cgltf/test/CMakeLists.txt
vendored
Normal file
23
3rdparty/cgltf/test/CMakeLists.txt
vendored
Normal file
@ -0,0 +1,23 @@
|
||||
cmake_minimum_required( VERSION 2.8 )
|
||||
|
||||
include_directories( ${CMAKE_CURRENT_SOURCE_DIR} )
|
||||
|
||||
set( EXE_NAME cgltf_test )
|
||||
add_executable( ${EXE_NAME} main.c )
|
||||
set_property( TARGET ${EXE_NAME} PROPERTY C_STANDARD 99 )
|
||||
install( TARGETS ${EXE_NAME} RUNTIME DESTINATION bin )
|
||||
|
||||
set( EXE_NAME test_conversion )
|
||||
add_executable( ${EXE_NAME} test_conversion.cpp )
|
||||
set_property( TARGET ${EXE_NAME} PROPERTY CXX_STANDARD 11 )
|
||||
install( TARGETS ${EXE_NAME} RUNTIME DESTINATION bin )
|
||||
|
||||
set( EXE_NAME test_write )
|
||||
add_executable( ${EXE_NAME} test_write.cpp )
|
||||
set_property( TARGET ${EXE_NAME} PROPERTY CXX_STANDARD 11 )
|
||||
install( TARGETS ${EXE_NAME} RUNTIME DESTINATION bin )
|
||||
|
||||
set( EXE_NAME test_math )
|
||||
add_executable( ${EXE_NAME} test_math.cpp )
|
||||
set_property( TARGET ${EXE_NAME} PROPERTY CXX_STANDARD 11 )
|
||||
install( TARGETS ${EXE_NAME} RUNTIME DESTINATION bin )
|
37
3rdparty/cgltf/test/main.c
vendored
Normal file
37
3rdparty/cgltf/test/main.c
vendored
Normal file
@ -0,0 +1,37 @@
|
||||
|
||||
|
||||
#define CGLTF_IMPLEMENTATION
|
||||
#include "../cgltf.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
if (argc < 2)
|
||||
{
|
||||
printf("err\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
cgltf_options options = {0};
|
||||
cgltf_data* data = NULL;
|
||||
cgltf_result result = cgltf_parse_file(&options, argv[1], &data);
|
||||
|
||||
if (result == cgltf_result_success)
|
||||
result = cgltf_load_buffers(&options, data, argv[1]);
|
||||
|
||||
if (result == cgltf_result_success)
|
||||
result = cgltf_validate(data);
|
||||
|
||||
printf("Result: %d\n", result);
|
||||
|
||||
if (result == cgltf_result_success)
|
||||
{
|
||||
printf("Type: %u\n", data->file_type);
|
||||
printf("Meshes: %lu\n", data->meshes_count);
|
||||
}
|
||||
|
||||
cgltf_free(data);
|
||||
|
||||
return result;
|
||||
}
|
66
3rdparty/cgltf/test/test_all.py
vendored
Normal file
66
3rdparty/cgltf/test/test_all.py
vendored
Normal file
@ -0,0 +1,66 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import os, sys
|
||||
from sys import platform
|
||||
|
||||
num_tested = 0
|
||||
num_errors = 0
|
||||
|
||||
def get_executable_path(name):
|
||||
if platform == "win32":
|
||||
return "build\\Debug\\" + name
|
||||
else:
|
||||
return "build/" + name
|
||||
|
||||
def collect_files(path, type, name):
|
||||
global num_tested
|
||||
global num_errors
|
||||
exe = get_executable_path(name)
|
||||
for the_file in os.listdir(path):
|
||||
file_path = os.path.join(os.path.normpath(path), the_file)
|
||||
if os.path.isfile(file_path):
|
||||
if the_file.endswith(type):
|
||||
num_tested = num_tested +1
|
||||
print("### " + name + " " + file_path)
|
||||
result = os.system("{0} \"{1}\"".format(exe, file_path))
|
||||
print("### Result: " + str(result) + "\n")
|
||||
if result != 0:
|
||||
num_errors = num_errors + 1
|
||||
print("Error.")
|
||||
sys.exit(1)
|
||||
elif os.path.isdir(file_path):
|
||||
collect_files(file_path, type, name)
|
||||
|
||||
if __name__ == "__main__":
|
||||
if not os.path.exists("build/"):
|
||||
os.makedirs("build/")
|
||||
os.chdir("build/")
|
||||
os.system("cmake ..")
|
||||
if os.system("cmake --build .") != 0:
|
||||
print("Unable to build.")
|
||||
exit(1)
|
||||
os.chdir("..")
|
||||
if not os.path.exists("glTF-Sample-Models/"):
|
||||
os.system("git init glTF-Sample-Models")
|
||||
os.chdir("glTF-Sample-Models")
|
||||
os.system("git remote add origin https://github.com/KhronosGroup/glTF-Sample-Models.git")
|
||||
os.system("git config core.sparsecheckout true")
|
||||
f = open(".git/info/sparse-checkout", "w+")
|
||||
f.write("2.0/*\n")
|
||||
f.close()
|
||||
os.system("git pull --depth=1 origin master")
|
||||
os.chdir("..")
|
||||
collect_files("glTF-Sample-Models/2.0/", ".glb", "cgltf_test")
|
||||
collect_files("glTF-Sample-Models/2.0/", ".gltf", "cgltf_test")
|
||||
collect_files("glTF-Sample-Models/2.0/", ".glb", "test_conversion")
|
||||
collect_files("glTF-Sample-Models/2.0/", ".gltf", "test_conversion")
|
||||
collect_files("glTF-Sample-Models/2.0/", ".gltf", "test_write")
|
||||
|
||||
result = os.system(get_executable_path("test_math"))
|
||||
if result != 0:
|
||||
num_errors = num_errors + 1
|
||||
print("Error.")
|
||||
sys.exit(1)
|
||||
|
||||
print("Tested files: " + str(num_tested))
|
||||
print("Errors: " + str(num_errors))
|
69
3rdparty/cgltf/test/test_conversion.cpp
vendored
Normal file
69
3rdparty/cgltf/test/test_conversion.cpp
vendored
Normal file
@ -0,0 +1,69 @@
|
||||
#define CGLTF_IMPLEMENTATION
|
||||
#include "../cgltf.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <cstdio>
|
||||
#include <limits>
|
||||
|
||||
static bool is_near(cgltf_float a, cgltf_float b)
|
||||
{
|
||||
return std::abs(a - b) < 10 * std::numeric_limits<cgltf_float>::min();
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
if (argc < 2)
|
||||
{
|
||||
printf("err\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
cgltf_options options = {};
|
||||
cgltf_data* data = NULL;
|
||||
cgltf_result result = cgltf_parse_file(&options, argv[1], &data);
|
||||
|
||||
if (result == cgltf_result_success)
|
||||
result = cgltf_load_buffers(&options, data, argv[1]);
|
||||
|
||||
if (result != cgltf_result_success || strstr(argv[1], "Draco"))
|
||||
return result;
|
||||
|
||||
const cgltf_accessor* blobs = data->accessors;
|
||||
cgltf_float element[16];
|
||||
for (cgltf_size blob_index = 0; blob_index < data->accessors_count; ++blob_index)
|
||||
{
|
||||
const cgltf_accessor* blob = data->accessors + blob_index;
|
||||
if (blob->is_sparse)
|
||||
{
|
||||
cgltf_size nfloats = cgltf_num_components(blob->type) * blob->count;
|
||||
cgltf_float* dense = (cgltf_float*) malloc(nfloats * sizeof(cgltf_float));
|
||||
if (cgltf_accessor_unpack_floats(blob, dense, nfloats) < nfloats) {
|
||||
printf("Unable to completely unpack a sparse accessor.\n");
|
||||
return -1;
|
||||
}
|
||||
free(dense);
|
||||
continue;
|
||||
}
|
||||
if (blob->has_max && blob->has_min)
|
||||
{
|
||||
cgltf_float min0 = std::numeric_limits<float>::max();
|
||||
cgltf_float max0 = std::numeric_limits<float>::lowest();
|
||||
for (cgltf_size index = 0; index < blob->count; index++)
|
||||
{
|
||||
cgltf_accessor_read_float(blob, index, element, 16);
|
||||
min0 = std::min(min0, element[0]);
|
||||
max0 = std::max(max0, element[0]);
|
||||
}
|
||||
if (!is_near(min0, blob->min[0]) || !is_near(max0, blob->max[0]))
|
||||
{
|
||||
printf("Computed [%f, %f] but expected [%f, %f]\n", min0, max0, blob->min[0], blob->max[0]);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cgltf_free(data);
|
||||
|
||||
return result;
|
||||
}
|
52
3rdparty/cgltf/test/test_math.cpp
vendored
Normal file
52
3rdparty/cgltf/test/test_math.cpp
vendored
Normal file
@ -0,0 +1,52 @@
|
||||
#define CGLTF_IMPLEMENTATION
|
||||
#include "../cgltf.h"
|
||||
|
||||
// Performs matrix-vector multiplication, as in (4x4) * (4x1) = (4x1)
|
||||
static void transform(const cgltf_float matrix[16], const cgltf_float source[4], cgltf_float target[4]) {
|
||||
target[0] = matrix[0] * source[0] + matrix[4] * source[1] + matrix[ 8] * source[2] + matrix[12] * source[3];
|
||||
target[1] = matrix[1] * source[0] + matrix[5] * source[1] + matrix[ 9] * source[2] + matrix[13] * source[3];
|
||||
target[2] = matrix[2] * source[0] + matrix[6] * source[1] + matrix[10] * source[2] + matrix[14] * source[3];
|
||||
target[3] = matrix[3] * source[0] + matrix[7] * source[1] + matrix[11] * source[2] + matrix[15] * source[3];
|
||||
}
|
||||
|
||||
static void set(cgltf_float target[3], float x, float y, float z) {
|
||||
target[0] = x;
|
||||
target[1] = y;
|
||||
target[2] = z;
|
||||
}
|
||||
|
||||
static void check(cgltf_float target[3], float x, float y, float z) {
|
||||
if (target[0] != x || target[1] != y || target[2] != z) {
|
||||
fprintf(stderr, "Mismatch detected.\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
cgltf_node node = {};
|
||||
|
||||
cgltf_float matrix[16];
|
||||
cgltf_float source[4] = {1, 2, 3, 1};
|
||||
cgltf_float target[4];
|
||||
|
||||
set(node.scale, 1, 1, 1);
|
||||
set(node.translation, 1, 0, 0);
|
||||
cgltf_node_transform_local(&node, matrix);
|
||||
transform(matrix, source, target);
|
||||
check(target, 2, 2, 3);
|
||||
|
||||
set(node.scale, 3, 1, 1);
|
||||
set(node.translation, 0, 0, 0);
|
||||
cgltf_node_transform_local(&node, matrix);
|
||||
transform(matrix, source, target);
|
||||
check(target, 3, 2, 3);
|
||||
|
||||
set(node.scale, 1, 3, 1);
|
||||
set(node.translation, 1, 0, 0);
|
||||
cgltf_node_transform_local(&node, matrix);
|
||||
transform(matrix, source, target);
|
||||
check(target, 2, 6, 3);
|
||||
|
||||
return 0;
|
||||
}
|
45
3rdparty/cgltf/test/test_write.cpp
vendored
Normal file
45
3rdparty/cgltf/test/test_write.cpp
vendored
Normal file
@ -0,0 +1,45 @@
|
||||
#define CGLTF_IMPLEMENTATION
|
||||
#define CGLTF_WRITE_IMPLEMENTATION
|
||||
#include "../cgltf_write.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <cstdio>
|
||||
#include <limits>
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
if (argc < 2)
|
||||
{
|
||||
printf("err\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
cgltf_options options = {};
|
||||
cgltf_data* data0 = NULL;
|
||||
cgltf_result result = cgltf_parse_file(&options, argv[1], &data0);
|
||||
|
||||
// Silently skip over files that are unreadable since this is a writing test.
|
||||
if (result != cgltf_result_success)
|
||||
{
|
||||
return cgltf_result_success;
|
||||
}
|
||||
|
||||
result = cgltf_write_file(&options, "out.gltf", data0);
|
||||
if (result != cgltf_result_success)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
cgltf_data* data1 = NULL;
|
||||
result = cgltf_parse_file(&options, "out.gltf", &data1);
|
||||
if (result != cgltf_result_success)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
if (data0->meshes_count != data1->meshes_count) {
|
||||
return -1;
|
||||
}
|
||||
cgltf_free(data1);
|
||||
cgltf_free(data0);
|
||||
return cgltf_result_success;
|
||||
}
|
Loading…
Reference in New Issue
Block a user