Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
mmha committed Apr 30, 2017
0 parents commit 0849127
Show file tree
Hide file tree
Showing 49 changed files with 1,102 additions and 0 deletions.
40 changes: 40 additions & 0 deletions .clang-format
@@ -0,0 +1,40 @@
Language: Cpp
Standard: Cpp11
IndentWidth: 4
TabWidth: 4
UseTab: Always
ColumnLimit: 120
AccessModifierOffset: 0
AlignEscapedNewlinesLeft: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: true
AllowShortFunctionsOnASingleLine: None
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: true
BinPackParameters: false
BreakBeforeBinaryOperators: false
BreakBeforeTernaryOperators: false
BreakConstructorInitializersBeforeComma: true
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
IndentCaseLabels: true
IndentWrappedFunctionNames: true
KeepEmptyLinesAtTheStartOfBlocks: false
MaxEmptyLinesToKeep: 3
NamespaceIndentation: All
PointerAlignment: Right
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: Never
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 4
SpacesInAngles: false
SpacesInCStyleCastParentheses: false
SpacesInContainerLiterals: true
SpacesInParentheses: false
8 changes: 8 additions & 0 deletions .clang-tidy
@@ -0,0 +1,8 @@
---
Checks: 'clang-diagnostic-*,clang-analyzer-*,clang-analyzer-alpha*,cppcoreguidelines-*,modernize-*,performance-*,readability-*,-readability-named-parameter,misc-*,google-runtime-int,llvm-include-order'

WarningsAsErrors: ''
HeaderFilterRegex: ''
AnalyzeTemporaryDtors: false
...

6 changes: 6 additions & 0 deletions .gitignore
@@ -0,0 +1,6 @@
build*/
cmake-build*/
.idea/
.directory
.kdev4/
*.kdev4
9 changes: 9 additions & 0 deletions .gitmodules
@@ -0,0 +1,9 @@
[submodule "3rdparty/boost.outcome"]
path = 3rdparty/boost.outcome
url = https://github.com/ned14/boost.outcome.git
[submodule "3rdparty/GSL"]
path = 3rdparty/GSL
url = https://github.com/Microsoft/GSL.git
[submodule "3rdparty/json"]
path = 3rdparty/json
url = https://github.com/nlohmann/json
9 changes: 9 additions & 0 deletions 3rdparty/CMakeLists.txt
@@ -0,0 +1,9 @@
add_library(nlohmann_json INTERFACE)
target_include_directories(nlohmann_json SYSTEM INTERFACE json/src)

add_library(microsoft_gsl INTERFACE)
target_include_directories(microsoft_gsl SYSTEM INTERFACE GSL/include)

add_library(boost_outcome INTERFACE)
target_include_directories(boost_outcome SYSTEM INTERFACE "boost.outcome/include")
target_compile_definitions(boost_outcome INTERFACE BOOST_OUTCOME_ENABLE_ADVANCED)
1 change: 1 addition & 0 deletions 3rdparty/GSL
Submodule GSL added at 8b320e
1 change: 1 addition & 0 deletions 3rdparty/boost.outcome
Submodule boost.outcome added at bdfae0
1 change: 1 addition & 0 deletions 3rdparty/json
Submodule json added at c42273
38 changes: 38 additions & 0 deletions CMakeLists.txt
@@ -0,0 +1,38 @@
cmake_minimum_required(VERSION 3.8)
project(gltfpp VERSION 1.0)

set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
include(GenerateClangTidyTarget)
include(ExternalProject)

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
if(UNIX OR MINGW)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic -fdiagnostics-color=always")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -flto -march=native")
endif()
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fmodules -fimplicit-module-maps -fbuiltin-module-map -Wdocumentation -Wthread-safety")
endif()

# find_package(Doxygen)
# if(Doxygen_FOUND)
# file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/doc)
# if(DOXYGEN_DOT_FOUND)
# set(USE_DOT "YES")
# else()
# set(USE_DOT "NO")
# endif()
# configure_file("${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in" "${CMAKE_CURRENT_BINARY_DIR}/Doxyfile" @ONLY)
# add_custom_target(gltfpp_doc
# ${DOXYGEN_EXECUTABLE} "${CMAKE_CURRENT_BINARY_DIR}/Doxyfile"
# SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in"
# DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/Doxyfile"
# WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/doc")
# endif()

add_subdirectory(3rdparty)
add_subdirectory(gltfpp)
enable_testing()
add_subdirectory(test test EXCLUDE_FROM_ALL)
23 changes: 23 additions & 0 deletions LICENSE
@@ -0,0 +1,23 @@
Boost Software License - Version 1.0 - August 17th, 2003

Permission is hereby granted, free of charge, to any person or organization
obtaining a copy of the software and accompanying documentation covered by
this license (the "Software") to use, reproduce, display, distribute,
execute, and transmit the Software, and to prepare derivative works of the
Software, and to permit third-parties to whom the Software is furnished to
do so, all subject to the following:

The copyright notices in the Software and this entire statement, including
the above license grant, this restriction and the following disclaimer,
must be included in all copies of the Software, in whole or in part, and
all derivative works of the Software, unless such copies or derivative
works are solely in the form of machine-executable object code generated by
a source language processor.

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, TITLE AND NON-INFRINGEMENT. IN NO EVENT
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
27 changes: 27 additions & 0 deletions README.md
@@ -0,0 +1,27 @@
gltfpp
======
gltfpp is a glTF 2.0 loader written in C++14 targeting desktop platforms and WebAssembly with a focus on ease of use, type safety and extensibility.

**WORK IN PROGRESS!** This library is not finished yet.

Requirements
------------
- gcc >= 6 or clang >= 3.5
- CMake >= 3.8

When using clang, modules are used to decrease build time.

Finished tasks
------
- Parsing infrastructure (trivial properties can be parsed simply by declaring their fields)
- Finished properties: `Asset`

TODO
----
- generalized (and type safe) enum parsing
- deserialization of buffer data (embedded base64, GLB)
- Networking (HTTP on desktop, XHR on WebAssembly), asynchronous loading
- CMake support for Emscripten
- Proper documentation
- out of tree extensions?
- a small viewer based on the loader
9 changes: 9 additions & 0 deletions cmake/FindCatch.cmake
@@ -0,0 +1,9 @@
find_path(CATCH_INCLUDE_DIR NAMES catch.hpp)

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Catch REQUIRED_VARS CATCH_INCLUDE_DIR)

add_library(Catch::Catch INTERFACE IMPORTED)
set_target_properties(Catch::Catch PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${CATCH_INCLUDE_DIR})

mark_as_advanced(CATCH_INCLUDE_DIR)
18 changes: 18 additions & 0 deletions cmake/GenerateClangTidyTarget.cmake
@@ -0,0 +1,18 @@
function(add_clang_tidy_check target)
get_target_property(rel_source_files ${target} SOURCES)

foreach(f ${rel_source_files})
get_filename_component(abs_file ${f} ABSOLUTE)
list(APPEND source_files ${abs_file})
endforeach()

add_custom_target(${target}_check)
add_custom_command(TARGET ${target}_check POST_BUILD
COMMAND clang-tidy "-p=${PROJECT_BINARY_DIR}"
"-config='${ARGV1}'"
"-extra-arg='-fdiagnostics-color=always'"
"-export-fixes='${CMAKE_CURRENT_BINARY_DIR}/${target}_suggested_fixes.yaml'"
${source_files}
BYPRODUCTS "${CMAKE_CURRENT_BINARY_DIR}/${target}_suggested_fixes.yaml"
)
endfunction()
2 changes: 2 additions & 0 deletions format.sh
@@ -0,0 +1,2 @@
#!/bin/sh
for x in $(find test/ gltfpp/ -name '*.cpp' -o -name '*.h'); do clang-format -style=file -i $x; done
1 change: 1 addition & 0 deletions gltfpp/CMakeLists.txt
@@ -0,0 +1 @@
add_subdirectory(src)
11 changes: 11 additions & 0 deletions gltfpp/include/Accessor.h
@@ -0,0 +1,11 @@
#pragma once
#include "BufferView.h"
#include <boost/hana/define_struct.hpp>

namespace gltfpp {
inline namespace v1 {
struct Accessor {
BOOST_HANA_DEFINE_STRUCT(Accessor, (BufferView, bufferView));
};
} // namespace v1
} // namespace gltfpp
32 changes: 32 additions & 0 deletions gltfpp/include/Animation.h
@@ -0,0 +1,32 @@
#pragma once
#include "Error.h"
#include <boost/hana/define_struct.hpp>
#include <json.hpp>

namespace gltfpp {
inline namespace v1 {
struct Channel { // TODO generic enum parsing
BOOST_HANA_DEFINE_STRUCT(Channel

);
};

struct AnimationSampler {
BOOST_HANA_DEFINE_STRUCT(AnimationSampler,
(int, input),
(int, output),
(option<std::string>, interpolation), // TODO default = linear
(option<nlohmann::json>, extensions),
(option<nlohmann::json>, extras));
};

struct Animation {
BOOST_HANA_DEFINE_STRUCT(Animation,
(std::vector<Channel>, channels),
(std::vector<AnimationSampler>, samplers),
(option<std::string>, name),
(option<nlohmann::json>, extensions),
(option<nlohmann::json>, extras));
};
} // namespace v1
} // namespace gltfpp
19 changes: 19 additions & 0 deletions gltfpp/include/Asset.h
@@ -0,0 +1,19 @@
#pragma once
#include "Error.h"
#include <boost/hana/define_struct.hpp>
#include <json.hpp>

namespace gltfpp {
inline namespace v1 {
struct Asset {
BOOST_HANA_DEFINE_STRUCT(Asset,
(option<std::string>, copyright),
(option<std::string>, generator),
(option<std::string>, minVersion),
(std::string, version),

(option<nlohmann::json>, extensions),
(option<nlohmann::json>, extras));
};
} // namespace v1
} // namespace gltfpp
29 changes: 29 additions & 0 deletions gltfpp/include/Buffer.h
@@ -0,0 +1,29 @@
#pragma once
#include "Error.h"
#include "detail/Byte.h"
#include <json.hpp>
#include <vector>

namespace gltfpp {
inline namespace v1 {
class Buffer {
public:
Buffer() = default;

std::vector<byte> &operator*();
const std::vector<byte> &operator*() const;
std::vector<byte> *operator->();
const std::vector<byte> *operator->() const;
std::vector<byte> &get();
const std::vector<byte> &get() const;

option<std::string> uri;
option<std::string> name;
option<nlohmann::json> extensions;
option<nlohmann::json> extras;
std::vector<byte> data;
};

auto parse(Buffer &b);
} // namespace v1
} // namespace gltfpp
29 changes: 29 additions & 0 deletions gltfpp/include/BufferView.h
@@ -0,0 +1,29 @@
#pragma once
#include "Buffer.h"
#include "Error.h"
#include <boost/hana/define_struct.hpp>
#include <gsl/span>
#include <json.hpp>

namespace gltfpp {
inline namespace v1 {
struct BufferView {
BufferView()
: byteStride{0} {
}

enum Target { ARRAY_BUFFER = 34962, ELEMENT_ARRAY_BUFFER = 34963 };

BOOST_HANA_DEFINE_STRUCT(BufferView,
(int, target), // TODO enum parsing
(option<std::string>, name),
(uint8_t, byteStride),
(option<nlohmann::json>, extensions),
(option<nlohmann::json>, extras));
gsl::span<const byte> span;
const Buffer *buffer;
};

auto parse(BufferView &);
} // namespace v1
} // namespace gltfpp
10 changes: 10 additions & 0 deletions gltfpp/include/Camera.h
@@ -0,0 +1,10 @@
#pragma once
#include <boost/hana/define_struct.hpp>

namespace gltfpp {
inline namespace v1 {
struct Camera {
BOOST_HANA_DEFINE_STRUCT(Camera);
};
} // namespace v1
} // namespace gltfpp

0 comments on commit 0849127

Please sign in to comment.