Skip to content

Commit b7b082a

Browse files
committed
Squashed commit of the following:
commit 0288e5e6a4e49d9ea45ba6da2e6636805937b125 Author: Alex Chi <alexchi@c4g.io> Date: Fri Nov 2 18:02:50 2018 +0800 support more unicode types
1 parent 6b35a5a commit b7b082a

File tree

6 files changed

+72
-42
lines changed

6 files changed

+72
-42
lines changed

.appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: 0.0.1.{build}
1+
version: 0.1.4.{build}
22

33
build:
44
verbosity: minimal

CMakeLists.txt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ set(LIBGLTF_PLATFORM_MACOS FALSE)
1515

1616
option(LIBGLTF_COVERAGE_GCOV "Coverage gcov (debug, Linux builds only)" OFF)
1717
option(LIBGLTF_WITH_UNICODE "Build with UNICODE" OFF)
18+
option(LIBGLTF_USING_CHAR16 "Build using char16_t when with UNICODE" OFF)
19+
option(LIBGLTF_USING_CHAR32 "Build using char32_t when with UNICODE" OFF)
1820

1921
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
2022
set(LIBGLTF_PLATFORM_WINDOWS TRUE)
@@ -79,8 +81,14 @@ if((CMAKE_COMPILER_IS_GNUCC STREQUAL "1") OR (CMAKE_COMPILER_IS_GNUCXX STREQUAL
7981
add_definitions(-DCOMPILER_IS_GCC)
8082
endif()
8183

82-
if(${LIBGLTF_WITH_UNICODE} OR ${LIBGLTF_PLATFORM_WINDOWS})
84+
if(${LIBGLTF_WITH_UNICODE})
8385
add_definitions(-DUNICODE -D_UNICODE)
86+
if(${LIBGLTF_USING_CHAR16})
87+
add_definitions(-DUSING_CHAR16)
88+
endif()
89+
if(${LIBGLTF_USING_CHAR32})
90+
add_definitions(-DUSING_CHAR32)
91+
endif()
8492
endif()
8593

8694
if(LIBGLTF_BUILD_GCOV AND LIBGLTF_PLATFORM_LINUX)

include/libgltf/libgltf.h

Lines changed: 43 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,17 @@
77
#include <memory>
88

99
#define LIBGLTF_MAJOR_VERSION 0
10-
#define LIBGLTF_MINOR_VERSION 1
11-
#define LIBGLTF_PATCH_VERSION 2
10+
#define LIBGLTF_MINOR_VERSION 0
11+
#define LIBGLTF_PATCH_VERSION 0
1212

1313
#if defined(UNICODE)
14+
#if defined(USING_CHAR16)
15+
typedef std::u16string GLTFString;
16+
#elif defined(USING_CHAR32)
17+
typedef std::u32string GLTFString;
18+
#else
1419
typedef std::wstring GLTFString;
20+
#endif
1521
#else
1622
typedef std::string GLTFString;
1723
#endif
@@ -35,7 +41,7 @@ namespace libgltf
3541
SGlTFProperty();
3642

3743
// Check valid
38-
operator bool() const;
44+
virtual operator bool() const;
3945

4046
std::shared_ptr<struct SExtras> extras;
4147
std::shared_ptr<struct SExtension> extensions;
@@ -49,7 +55,7 @@ namespace libgltf
4955
SGlTFChildofRootProperty();
5056

5157
// Check valid
52-
operator bool() const;
58+
virtual operator bool() const;
5359

5460
// The user-defined name of this object.
5561
GLTFString name;
@@ -64,7 +70,7 @@ namespace libgltf
6470
SMaterial();
6571

6672
// Check valid
67-
operator bool() const;
73+
virtual operator bool() const;
6874

6975
// The alpha cutoff value of the material.
7076
float alphaCutoff;
@@ -93,7 +99,7 @@ namespace libgltf
9399
SAsset();
94100

95101
// Check valid
96-
operator bool() const;
102+
virtual operator bool() const;
97103

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

116122
// Check valid
117-
operator bool() const;
123+
virtual operator bool() const;
118124

119125
// s wrapping mode.
120126
int32_t wrapS;
@@ -135,7 +141,7 @@ namespace libgltf
135141
SAnimationSampler();
136142

137143
// Check valid
138-
operator bool() const;
144+
virtual operator bool() const;
139145

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

156162
// Check valid
157-
operator bool() const;
163+
virtual operator bool() const;
158164
};
159165

160166
/*!
@@ -166,7 +172,7 @@ namespace libgltf
166172
SScene();
167173

168174
// Check valid
169-
operator bool() const;
175+
virtual operator bool() const;
170176

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

183189
// Check valid
184-
operator bool() const;
190+
virtual operator bool() const;
185191

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

204210
// Check valid
205-
operator bool() const;
211+
virtual operator bool() const;
206212

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

227233
// Check valid
228-
operator bool() const;
234+
virtual operator bool() const;
229235

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

243249
// Check valid
244-
operator bool() const;
250+
virtual operator bool() const;
245251

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

257263
// Check valid
258-
operator bool() const;
264+
virtual operator bool() const;
259265

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

272278
// Check valid
273-
operator bool() const;
279+
virtual operator bool() const;
274280

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

289295
// Check valid
290-
operator bool() const;
296+
virtual operator bool() const;
291297

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

306312
// Check valid
307-
operator bool() const;
313+
virtual operator bool() const;
308314

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

323329
// Check valid
324-
operator bool() const;
330+
virtual operator bool() const;
325331

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

342348
// Check valid
343-
operator bool() const;
349+
virtual operator bool() const;
344350

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

365371
// Check valid
366-
operator bool() const;
372+
virtual operator bool() const;
367373

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

388394
// Check valid
389-
operator bool() const;
395+
virtual operator bool() const;
390396

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

403409
// Check valid
404-
operator bool() const;
410+
virtual operator bool() const;
405411

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

419425
// Check valid
420-
operator bool() const;
426+
virtual operator bool() const;
421427

422428
operator int32_t() const;
423429

@@ -433,7 +439,7 @@ namespace libgltf
433439
SAccessorSparseIndices();
434440

435441
// Check valid
436-
operator bool() const;
442+
virtual operator bool() const;
437443

438444
// The indices data type.
439445
int32_t componentType;
@@ -452,7 +458,7 @@ namespace libgltf
452458
SNode();
453459

454460
// Check valid
455-
operator bool() const;
461+
virtual operator bool() const;
456462

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

485491
// Check valid
486-
operator bool() const;
492+
virtual operator bool() const;
487493

488494
// 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.
489495
std::vector<std::shared_ptr<struct SAnimationChannel>> channels;
@@ -500,7 +506,7 @@ namespace libgltf
500506
SSkin();
501507

502508
// Check valid
503-
operator bool() const;
509+
virtual operator bool() const;
504510

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

521527
// Check valid
522-
operator bool() const;
528+
virtual operator bool() const;
523529

524530
// The roughness of the material.
525531
float roughnessFactor;
@@ -541,7 +547,7 @@ namespace libgltf
541547
SKHR_draco_mesh_compressionextension();
542548

543549
// Check valid
544-
operator bool() const;
550+
virtual operator bool() const;
545551

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

560566
// Check valid
561-
operator bool() const;
567+
virtual operator bool() const;
562568

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

579585
// Check valid
580-
operator bool() const;
586+
virtual operator bool() const;
581587

582588
// The image's MIME type.
583589
GLTFString mimeType;
@@ -596,7 +602,7 @@ namespace libgltf
596602
STexture();
597603

598604
// Check valid
599-
operator bool() const;
605+
virtual operator bool() const;
600606

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

615621
// Check valid
616-
operator bool() const;
622+
virtual operator bool() const;
617623

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

636642
// Check valid
637-
operator bool() const;
643+
virtual operator bool() const;
638644

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

653659
// Check valid
654-
operator bool() const;
660+
virtual operator bool() const;
655661

656662
// The number of attributes referenced by this accessor.
657663
int32_t count;
@@ -682,7 +688,7 @@ namespace libgltf
682688
SGlTF();
683689

684690
// Check valid
685-
operator bool() const;
691+
virtual operator bool() const;
686692

687693
// An array of textures.
688694
std::vector<std::shared_ptr<struct STexture>> textures;

source/libgltf/libgltfpch.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,27 @@
55
#include <rapidjson/writer.h>
66

77
#if defined(UNICODE)
8+
#if defined(USING_CHAR16) || defined(USING_CHAR32)
9+
# define GLTFTEXT(t) u##t
10+
#else
811
# define GLTFTEXT(t) L##t
12+
#endif
913
#else
1014
# define GLTFTEXT(t) t
1115
#endif
1216

1317
namespace libgltf
1418
{
1519
#if defined(UNICODE)
16-
typedef rapidjson::UTF16<> GLTFCharType;
20+
#if defined(USING_CHAR16)
21+
typedef rapidjson::UTF16<char16_t> GLTFCharType;
22+
#elif defined(USING_CHAR32)
23+
typedef rapidjson::UTF32<char32_t> GLTFCharType;
24+
#else
25+
typedef rapidjson::UTF8<wchar_t> GLTFCharType;
26+
#endif
1727
#else
18-
typedef rapidjson::UTF8<> GLTFCharType;
28+
typedef rapidjson::UTF8<char> GLTFCharType;
1929
#endif
2030

2131
typedef rapidjson::GenericDocument<GLTFCharType> GLTFCharDocument;

0 commit comments

Comments
 (0)