Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit 0288e5e6a4e49d9ea45ba6da2e6636805937b125
Author: Alex Chi <[email protected]>
Date:   Fri Nov 2 18:02:50 2018 +0800

    support more unicode types
  • Loading branch information
alexchicn committed Nov 2, 2018
1 parent 6b35a5a commit b7b082a
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 42 deletions.
2 changes: 1 addition & 1 deletion .appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: 0.0.1.{build}
version: 0.1.4.{build}

build:
verbosity: minimal
Expand Down
10 changes: 9 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ set(LIBGLTF_PLATFORM_MACOS FALSE)

option(LIBGLTF_COVERAGE_GCOV "Coverage gcov (debug, Linux builds only)" OFF)
option(LIBGLTF_WITH_UNICODE "Build with UNICODE" OFF)
option(LIBGLTF_USING_CHAR16 "Build using char16_t when with UNICODE" OFF)
option(LIBGLTF_USING_CHAR32 "Build using char32_t when with UNICODE" OFF)

if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
set(LIBGLTF_PLATFORM_WINDOWS TRUE)
Expand Down Expand Up @@ -79,8 +81,14 @@ if((CMAKE_COMPILER_IS_GNUCC STREQUAL "1") OR (CMAKE_COMPILER_IS_GNUCXX STREQUAL
add_definitions(-DCOMPILER_IS_GCC)
endif()

if(${LIBGLTF_WITH_UNICODE} OR ${LIBGLTF_PLATFORM_WINDOWS})
if(${LIBGLTF_WITH_UNICODE})
add_definitions(-DUNICODE -D_UNICODE)
if(${LIBGLTF_USING_CHAR16})
add_definitions(-DUSING_CHAR16)
endif()
if(${LIBGLTF_USING_CHAR32})
add_definitions(-DUSING_CHAR32)
endif()
endif()

if(LIBGLTF_BUILD_GCOV AND LIBGLTF_PLATFORM_LINUX)
Expand Down
80 changes: 43 additions & 37 deletions include/libgltf/libgltf.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,17 @@
#include <memory>

#define LIBGLTF_MAJOR_VERSION 0
#define LIBGLTF_MINOR_VERSION 1
#define LIBGLTF_PATCH_VERSION 2
#define LIBGLTF_MINOR_VERSION 0
#define LIBGLTF_PATCH_VERSION 0

#if defined(UNICODE)
#if defined(USING_CHAR16)
typedef std::u16string GLTFString;
#elif defined(USING_CHAR32)
typedef std::u32string GLTFString;
#else
typedef std::wstring GLTFString;
#endif
#else
typedef std::string GLTFString;
#endif
Expand All @@ -35,7 +41,7 @@ namespace libgltf
SGlTFProperty();

// Check valid
operator bool() const;
virtual operator bool() const;

std::shared_ptr<struct SExtras> extras;
std::shared_ptr<struct SExtension> extensions;
Expand All @@ -49,7 +55,7 @@ namespace libgltf
SGlTFChildofRootProperty();

// Check valid
operator bool() const;
virtual operator bool() const;

// The user-defined name of this object.
GLTFString name;
Expand All @@ -64,7 +70,7 @@ namespace libgltf
SMaterial();

// Check valid
operator bool() const;
virtual operator bool() const;

// The alpha cutoff value of the material.
float alphaCutoff;
Expand Down Expand Up @@ -93,7 +99,7 @@ namespace libgltf
SAsset();

// Check valid
operator bool() const;
virtual operator bool() const;

// The minimum glTF version that this asset targets.
GLTFString minVersion;
Expand All @@ -114,7 +120,7 @@ namespace libgltf
SSampler();

// Check valid
operator bool() const;
virtual operator bool() const;

// s wrapping mode.
int32_t wrapS;
Expand All @@ -135,7 +141,7 @@ namespace libgltf
SAnimationSampler();

// Check valid
operator bool() const;
virtual operator bool() const;

// The index of an accessor containing keyframe input values, e.g., time.
std::shared_ptr<struct SGlTFId> input;
Expand All @@ -154,7 +160,7 @@ namespace libgltf
SExtras();

// Check valid
operator bool() const;
virtual operator bool() const;
};

/*!
Expand All @@ -166,7 +172,7 @@ namespace libgltf
SScene();

// Check valid
operator bool() const;
virtual operator bool() const;

// The indices of each root node.
std::vector<std::shared_ptr<struct SGlTFId>> nodes;
Expand All @@ -181,7 +187,7 @@ namespace libgltf
SCameraPerspective();

// Check valid
operator bool() const;
virtual operator bool() const;

// The floating-point aspect ratio of the field of view.
float aspectRatio;
Expand All @@ -202,7 +208,7 @@ namespace libgltf
SBufferView();

// Check valid
operator bool() const;
virtual operator bool() const;

// The length of the bufferView in bytes.
int32_t byteLength;
Expand All @@ -225,7 +231,7 @@ namespace libgltf
STextureInfo();

// Check valid
operator bool() const;
virtual operator bool() const;

// The index of the texture.
std::shared_ptr<struct SGlTFId> index;
Expand All @@ -241,7 +247,7 @@ namespace libgltf
SMaterialNormalTextureInfo();

// Check valid
operator bool() const;
virtual operator bool() const;

// The scalar multiplier applied to each normal vector of the normal texture.
float scale;
Expand All @@ -255,7 +261,7 @@ namespace libgltf
SMaterialOcclusionTextureInfo();

// Check valid
operator bool() const;
virtual operator bool() const;

// A scalar multiplier controlling the amount of occlusion applied.
float strength;
Expand All @@ -270,7 +276,7 @@ namespace libgltf
SAccessorSparseValues();

// Check valid
operator bool() const;
virtual operator bool() const;

// The index of the bufferView with sparse values. Referenced bufferView can't have ARRAY_BUFFER or ELEMENT_ARRAY_BUFFER target.
std::shared_ptr<struct SGlTFId> bufferView;
Expand All @@ -287,7 +293,7 @@ namespace libgltf
SAnimationChannelTarget();

// Check valid
operator bool() const;
virtual operator bool() const;

// The index of the node to target.
std::shared_ptr<struct SGlTFId> node;
Expand All @@ -304,7 +310,7 @@ namespace libgltf
SMesh();

// Check valid
operator bool() const;
virtual operator bool() const;

// An array of primitives, each defining geometry to be rendered with a material.
std::vector<std::shared_ptr<struct SMeshPrimitive>> primitives;
Expand All @@ -321,7 +327,7 @@ namespace libgltf
SAccessorSparse();

// Check valid
operator bool() const;
virtual operator bool() const;

// Number of entries stored in the sparse array.
int32_t count;
Expand All @@ -340,7 +346,7 @@ namespace libgltf
SMeshPrimitive();

// Check valid
operator bool() const;
virtual operator bool() const;

// The index of the accessor that contains the indices.
std::shared_ptr<struct SGlTFId> indices;
Expand All @@ -363,7 +369,7 @@ namespace libgltf
SKHR_materials_pbrSpecularGlossinessglTFextension();

// Check valid
operator bool() const;
virtual operator bool() const;

// The specular RGB color of the material.
std::vector<float> specularFactor;
Expand All @@ -386,7 +392,7 @@ namespace libgltf
SExtension();

// Check valid
operator bool() const;
virtual operator bool() const;

// Manual code lines
std::map<GLTFString, std::shared_ptr<struct SObject>> properties;
Expand All @@ -401,7 +407,7 @@ namespace libgltf
SAnimationChannel();

// Check valid
operator bool() const;
virtual operator bool() const;

// The index of the node and TRS property to target.
std::shared_ptr<struct SAnimationChannelTarget> target;
Expand All @@ -417,7 +423,7 @@ namespace libgltf
SGlTFId();

// Check valid
operator bool() const;
virtual operator bool() const;

operator int32_t() const;

Expand All @@ -433,7 +439,7 @@ namespace libgltf
SAccessorSparseIndices();

// Check valid
operator bool() const;
virtual operator bool() const;

// The indices data type.
int32_t componentType;
Expand All @@ -452,7 +458,7 @@ namespace libgltf
SNode();

// Check valid
operator bool() const;
virtual operator bool() const;

// The node's non-uniform scale, given as the scaling factors along the x, y, and z axes.
std::vector<float> scale;
Expand Down Expand Up @@ -483,7 +489,7 @@ namespace libgltf
SAnimation();

// Check valid
operator bool() const;
virtual operator bool() const;

// An array of channels, each of which targets an animation's sampler at a node's property. Different channels of the same animation can't have equal targets.
std::vector<std::shared_ptr<struct SAnimationChannel>> channels;
Expand All @@ -500,7 +506,7 @@ namespace libgltf
SSkin();

// Check valid
operator bool() const;
virtual operator bool() const;

// Indices of skeleton nodes, used as joints in this skin.
std::vector<std::shared_ptr<struct SGlTFId>> joints;
Expand All @@ -519,7 +525,7 @@ namespace libgltf
SMaterialPBRMetallicRoughness();

// Check valid
operator bool() const;
virtual operator bool() const;

// The roughness of the material.
float roughnessFactor;
Expand All @@ -541,7 +547,7 @@ namespace libgltf
SKHR_draco_mesh_compressionextension();

// Check valid
operator bool() const;
virtual operator bool() const;

// A dictionary object, where each key corresponds to an attribute and its unique attribute id stored in the compressed geometry.
std::map<GLTFString, std::shared_ptr<struct SGlTFId>> attributes;
Expand All @@ -558,7 +564,7 @@ namespace libgltf
SCamera();

// Check valid
operator bool() const;
virtual operator bool() const;

// Specifies if the camera uses a perspective or orthographic projection.
GLTFString type;
Expand All @@ -577,7 +583,7 @@ namespace libgltf
SImage();

// Check valid
operator bool() const;
virtual operator bool() const;

// The image's MIME type.
GLTFString mimeType;
Expand All @@ -596,7 +602,7 @@ namespace libgltf
STexture();

// Check valid
operator bool() const;
virtual operator bool() const;

// The index of the image used by this texture.
std::shared_ptr<struct SGlTFId> source;
Expand All @@ -613,7 +619,7 @@ namespace libgltf
SCameraOrthographic();

// Check valid
operator bool() const;
virtual operator bool() const;

// The floating-point horizontal magnification of the view. Must not be zero.
float xmag;
Expand All @@ -634,7 +640,7 @@ namespace libgltf
SBuffer();

// Check valid
operator bool() const;
virtual operator bool() const;

// The length of the buffer in bytes.
int32_t byteLength;
Expand All @@ -651,7 +657,7 @@ namespace libgltf
SAccessor();

// Check valid
operator bool() const;
virtual operator bool() const;

// The number of attributes referenced by this accessor.
int32_t count;
Expand Down Expand Up @@ -682,7 +688,7 @@ namespace libgltf
SGlTF();

// Check valid
operator bool() const;
virtual operator bool() const;

// An array of textures.
std::vector<std::shared_ptr<struct STexture>> textures;
Expand Down
14 changes: 12 additions & 2 deletions source/libgltf/libgltfpch.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,27 @@
#include <rapidjson/writer.h>

#if defined(UNICODE)
#if defined(USING_CHAR16) || defined(USING_CHAR32)
# define GLTFTEXT(t) u##t
#else
# define GLTFTEXT(t) L##t
#endif
#else
# define GLTFTEXT(t) t
#endif

namespace libgltf
{
#if defined(UNICODE)
typedef rapidjson::UTF16<> GLTFCharType;
#if defined(USING_CHAR16)
typedef rapidjson::UTF16<char16_t> GLTFCharType;
#elif defined(USING_CHAR32)
typedef rapidjson::UTF32<char32_t> GLTFCharType;
#else
typedef rapidjson::UTF8<wchar_t> GLTFCharType;
#endif
#else
typedef rapidjson::UTF8<> GLTFCharType;
typedef rapidjson::UTF8<char> GLTFCharType;
#endif

typedef rapidjson::GenericDocument<GLTFCharType> GLTFCharDocument;
Expand Down
Loading

0 comments on commit b7b082a

Please sign in to comment.