-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathPasGLTF.pas
6810 lines (6502 loc) · 244 KB
/
PasGLTF.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
(******************************************************************************
* PasGLTF *
******************************************************************************
* Version 2023-10-26-00-50 *
******************************************************************************
* zlib license *
*============================================================================*
* *
* Copyright (C) 2018-2023, Benjamin Rosseaux ([email protected]) *
* *
* This software is provided 'as-is', without any express or implied *
* warranty. In no event will the authors be held liable for any damages *
* arising from the use of this software. *
* *
* Permission is granted to anyone to use this software for any purpose, *
* including commercial applications, and to alter it and redistribute it *
* freely, subject to the following restrictions: *
* *
* 1. The origin of this software must not be misrepresented; you must not *
* claim that you wrote the original software. If you use this software *
* in a product, an acknowledgement in the product documentation would be *
* appreciated but is not required. *
* 2. Altered source versions must be plainly marked as such, and must not be *
* misrepresented as being the original software. *
* 3. This notice may not be removed or altered from any source distribution. *
* *
******************************************************************************
* General guidelines for code contributors *
*============================================================================*
* *
* 1. Make sure you are legally allowed to make a contribution under the zlib *
* license. *
* 2. The zlib license header goes at the top of each source file, with *
* appropriate copyright notice. *
* 3. After a pull request, check the status of your pull request on *
* http://github.com/BeRo1985/pasGLTF *
* 4. Write code which's compatible with newer modern Delphi versions and *
* FreePascal >= 3.0.0 *
* 5. Don't use Delphi-only, FreePascal-only or Lazarus-only libraries/units, *
* but if needed, make it out-ifdef-able. *
* 6. No use of third-party libraries/units as possible, but if needed, make *
* it out-ifdef-able. *
* 7. Try to use const when possible. *
* 8. Make sure to comment out writeln, used while debugging. *
* 9. Make sure the code compiles on 32-bit and 64-bit platforms (x86-32, *
* x86-64, ARM, ARM64, etc.). *
* *
******************************************************************************)
unit PasGLTF;
{$ifdef fpc}
{$mode delphi}
{$ifdef cpui386}
{$define cpu386}
{$endif}
{$ifdef cpu386}
{$asmmode intel}
{$endif}
{$ifdef cpuamd64}
{$asmmode intel}
{$endif}
{$ifdef FPC_LITTLE_ENDIAN}
{$define LITTLE_ENDIAN}
{$else}
{$ifdef FPC_BIG_ENDIAN}
{$define BIG_ENDIAN}
{$endif}
{$endif}
{-$pic off}
{$ifdef fpc_has_internal_sar}
{$define HasSAR}
{$endif}
{$ifdef FPC_HAS_TYPE_EXTENDED}
{$define HAS_TYPE_EXTENDED}
{$else}
{$undef HAS_TYPE_EXTENDED}
{$endif}
{$ifdef FPC_HAS_TYPE_DOUBLE}
{$define HAS_TYPE_DOUBLE}
{$else}
{$undef HAS_TYPE_DOUBLE}
{$endif}
{$ifdef FPC_HAS_TYPE_SINGLE}
{$define HAS_TYPE_SINGLE}
{$else}
{$undef HAS_TYPE_SINGLE}
{$endif}
{$define CAN_INLINE}
{$define HAS_ADVANCED_RECORDS}
{$else}
{$realcompatibility off}
{$localsymbols on}
{$define LITTLE_ENDIAN}
{$ifndef cpu64}
{$define cpu32}
{$endif}
{$define HAS_TYPE_EXTENDED}
{$define HAS_TYPE_DOUBLE}
{$define HAS_TYPE_SINGLE}
{$undef CAN_INLINE}
{$undef HAS_ADVANCED_RECORDS}
{$ifndef BCB}
{$ifdef ver120}
{$define Delphi4or5}
{$endif}
{$ifdef ver130}
{$define Delphi4or5}
{$endif}
{$ifdef ver140}
{$define Delphi6}
{$endif}
{$ifdef ver150}
{$define Delphi7}
{$endif}
{$ifdef ver170}
{$define Delphi2005}
{$endif}
{$else}
{$ifdef ver120}
{$define Delphi4or5}
{$define BCB4}
{$endif}
{$ifdef ver130}
{$define Delphi4or5}
{$endif}
{$endif}
{$ifdef conditionalexpressions}
{$if CompilerVersion>=24.0}
{$legacyifend on}
{$ifend}
{$if CompilerVersion>=14.0}
{$if CompilerVersion=14.0}
{$define Delphi6}
{$ifend}
{$define Delphi6AndUp}
{$ifend}
{$if CompilerVersion>=15.0}
{$if CompilerVersion=15.0}
{$define Delphi7}
{$ifend}
{$define Delphi7AndUp}
{$ifend}
{$if CompilerVersion>=17.0}
{$if CompilerVersion=17.0}
{$define Delphi2005}
{$ifend}
{$define Delphi2005AndUp}
{$ifend}
{$if CompilerVersion>=18.0}
{$if CompilerVersion=18.0}
{$define BDS2006}
{$define Delphi2006}
{$ifend}
{$define Delphi2006AndUp}
{$define CAN_INLINE}
{$define HAS_ADVANCED_RECORDS}
{$ifend}
{$if CompilerVersion>=18.5}
{$if CompilerVersion=18.5}
{$define Delphi2007}
{$ifend}
{$define Delphi2007AndUp}
{$ifend}
{$if CompilerVersion=19.0}
{$define Delphi2007Net}
{$ifend}
{$if CompilerVersion>=20.0}
{$if CompilerVersion=20.0}
{$define Delphi2009}
{$ifend}
{$define Delphi2009AndUp}
{$ifend}
{$if CompilerVersion>=21.0}
{$if CompilerVersion=21.0}
{$define Delphi2010}
{$ifend}
{$define Delphi2010AndUp}
{$ifend}
{$if CompilerVersion>=22.0}
{$if CompilerVersion=22.0}
{$define DelphiXE}
{$ifend}
{$define DelphiXEAndUp}
{$ifend}
{$if CompilerVersion>=23.0}
{$if CompilerVersion=23.0}
{$define DelphiXE2}
{$ifend}
{$define DelphiXE2AndUp}
{$ifend}
{$if CompilerVersion>=24.0}
{$legacyifend on}
{$if CompilerVersion=24.0}
{$define DelphiXE3}
{$ifend}
{$define DelphiXE3AndUp}
{$ifend}
{$if CompilerVersion>=25.0}
{$if CompilerVersion=25.0}
{$define DelphiXE4}
{$ifend}
{$define DelphiXE4AndUp}
{$ifend}
{$if CompilerVersion>=26.0}
{$if CompilerVersion=26.0}
{$define DelphiXE5}
{$ifend}
{$define DelphiXE5AndUp}
{$ifend}
{$if CompilerVersion>=27.0}
{$if CompilerVersion=27.0}
{$define DelphiXE6}
{$ifend}
{$define DelphiXE6AndUp}
{$ifend}
{$if CompilerVersion>=28.0}
{$if CompilerVersion=28.0}
{$define DelphiXE7}
{$ifend}
{$define DelphiXE7AndUp}
{$ifend}
{$if CompilerVersion>=29.0}
{$if CompilerVersion=29.0}
{$define DelphiXE8}
{$ifend}
{$define DelphiXE8AndUp}
{$ifend}
{$if CompilerVersion>=30.0}
{$if CompilerVersion=30.0}
{$define Delphi10Seattle}
{$ifend}
{$define Delphi10SeattleAndUp}
{$ifend}
{$if CompilerVersion>=31.0}
{$if CompilerVersion=31.0}
{$define Delphi10Berlin}
{$ifend}
{$define Delphi10BerlinAndUp}
{$ifend}
{$if CompilerVersion>=32.0}
{$if CompilerVersion=32.0}
{$define Delphi10Tokyo}
{$ifend}
{$define Delphi10TokyoAndUp}
{$ifend}
{$if CompilerVersion>=33.0}
{$if CompilerVersion=33.0}
{$define Delphi10Rio}
{$ifend}
{$define Delphi10RioAndUp}
{$ifend}
{$endif}
{$ifndef Delphi4or5}
{$ifndef BCB}
{$define Delphi6AndUp}
{$endif}
{$ifndef Delphi6}
{$define BCB6OrDelphi7AndUp}
{$ifndef BCB}
{$define Delphi7AndUp}
{$endif}
{$ifndef BCB}
{$ifndef Delphi7}
{$ifndef Delphi2005}
{$define BDS2006AndUp}
{$endif}
{$endif}
{$endif}
{$endif}
{$endif}
{$ifdef Delphi6AndUp}
{$warn symbol_platform off}
{$warn symbol_deprecated off}
{$endif}
{$endif}
{$if defined(Win32) or defined(Win64)}
{$define Windows}
{$ifend}
{$rangechecks off}
{$extendedsyntax on}
{$writeableconst on}
{$hints off}
{$booleval off}
{$typedaddress off}
{$stackframes off}
{$varstringchecks on}
{$typeinfo on}
{$overflowchecks off}
{$longstrings on}
{$openstrings on}
{$ifndef HAS_TYPE_SINGLE}
{$error No single floating point precision}
{$endif}
{$ifndef HAS_TYPE_DOUBLE}
{$error No double floating point precision}
{$endif}
{$scopedenums on}
{$ifndef fpc}
{$ifdef conditionalexpressions}
{$if CompilerVersion>=24.0}
{$legacyifend on}
{$ifend}
{$endif}
{$endif}
interface
uses SysUtils,
Classes,
Math,
PasJSON;
type PPPasGLTFInt8=^PPasGLTFInt8;
PPasGLTFInt8=^TPasGLTFInt8;
TPasGLTFInt8={$ifdef fpc}Int8{$else}shortint{$endif};
PPPasGLTFInt8Array=^PPasGLTFInt8Array;
PPasGLTFInt8Array=^TPasGLTFInt8Array;
TPasGLTFInt8Array=array[0..65535] of TPasGLTFInt8;
PPPasGLTFUInt8=^PPasGLTFUInt8;
PPasGLTFUInt8=^TPasGLTFUInt8;
TPasGLTFUInt8={$ifdef fpc}UInt8{$else}byte{$endif};
PPPasGLTFUInt8Array=^PPasGLTFUInt8Array;
PPasGLTFUInt8Array=^TPasGLTFUInt8Array;
TPasGLTFUInt8Array=array[0..65535] of TPasGLTFUInt8;
TPasGLTFUInt8DynamicArray=array of TPasGLTFUInt8;
PPPasGLTFInt16=^PPasGLTFInt16;
PPasGLTFInt16=^TPasGLTFInt16;
TPasGLTFInt16={$ifdef fpc}Int16{$else}smallint{$endif};
PPPasGLTFInt16Array=^PPasGLTFInt16Array;
PPasGLTFInt16Array=^TPasGLTFInt16Array;
TPasGLTFInt16Array=array[0..65535] of TPasGLTFInt16;
PPPasGLTFUInt16=^PPasGLTFUInt16;
PPasGLTFUInt16=^TPasGLTFUInt16;
TPasGLTFUInt16={$ifdef fpc}UInt16{$else}word{$endif};
PPPasGLTFUInt16Array=^PPasGLTFUInt16Array;
PPasGLTFUInt16Array=^TPasGLTFUInt16Array;
TPasGLTFUInt16Array=array[0..65535] of TPasGLTFUInt16;
PPPasGLTFInt32=^PPasGLTFInt32;
PPasGLTFInt32=^TPasGLTFInt32;
TPasGLTFInt32={$ifdef fpc}Int32{$else}longint{$endif};
PPPasGLTFInt32Array=^PPasGLTFInt32Array;
PPasGLTFInt32Array=^TPasGLTFInt32Array;
TPasGLTFInt32Array=array[0..65535] of TPasGLTFInt32;
TPasGLTFInt32DynamicArray=array of TPasGLTFInt32;
PPPasGLTFUInt32=^PPasGLTFUInt32;
PPasGLTFUInt32=^TPasGLTFUInt32;
TPasGLTFUInt32={$ifdef fpc}UInt32{$else}longword{$endif};
PPPasGLTFUInt32Array=^PPasGLTFUInt32Array;
PPasGLTFUInt32Array=^TPasGLTFUInt32Array;
TPasGLTFUInt32Array=array[0..65535] of TPasGLTFUInt32;
TPasGLTFUInt32DynamicArray=array of TPasGLTFUInt32;
PPPasGLTFInt64=^PPasGLTFInt64;
PPasGLTFInt64=^TPasGLTFInt64;
TPasGLTFInt64=Int64;
TPasGLTFInt64DynamicArray=array of TPasGLTFInt64;
PPPasGLTFUInt64=^PPasGLTFUInt64;
PPasGLTFUInt64=^TPasGLTFUInt64;
TPasGLTFUInt64=UInt64;
TPasGLTFUInt64DynamicArray=array of TPasGLTFUInt64;
PPPasGLTFChar=^PAnsiChar;
PPasGLTFChar=PAnsiChar;
TPasGLTFChar=AnsiChar;
PPPasGLTFRawByteChar=^PAnsiChar;
PPasGLTFRawByteChar=PAnsiChar;
TPasGLTFRawByteChar=AnsiChar;
PPPasGLTFUTF16Char=^PWideChar;
PPasGLTFUTF16Char=PWideChar;
TPasGLTFUTF16Char=WideChar;
PPPasGLTFPointer=^PPasGLTFPointer;
PPasGLTFPointer=^TPasGLTFPointer;
TPasGLTFPointer=Pointer;
PPPasGLTFPointers=^PPasGLTFPointers;
PPasGLTFPointers=^TPasGLTFPointers;
TPasGLTFPointers=array[0..65535] of TPasGLTFPointer;
PPPasGLTFVoid=^PPasGLTFVoid;
PPasGLTFVoid=TPasGLTFPointer;
PPPasGLTFFloat=^PPasGLTFFloat;
PPasGLTFFloat=^TPasGLTFFloat;
TPasGLTFFloat=Single;
TPasGLTFFloatDynamicArray=array of TPasGLTFFloat;
PPPasGLTFDouble=^PPasGLTFDouble;
PPasGLTFDouble=^TPasGLTFDouble;
TPasGLTFDouble=Double;
TPasGLTFDoubleDynamicArray=array of TPasGLTFDouble;
PPPasGLTFPtrUInt=^PPasGLTFPtrUInt;
PPPasGLTFPtrInt=^PPasGLTFPtrInt;
PPasGLTFPtrUInt=^TPasGLTFPtrUInt;
PPasGLTFPtrInt=^TPasGLTFPtrInt;
{$ifdef fpc}
TPasGLTFPtrUInt=PtrUInt;
TPasGLTFPtrInt=PtrInt;
{$undef OldDelphi}
{$else}
{$ifdef conditionalexpressions}
{$if CompilerVersion>=23.0}
{$undef OldDelphi}
TPasGLTFPtrUInt=NativeUInt;
TPasGLTFPtrInt=NativeInt;
{$else}
{$define OldDelphi}
{$ifend}
{$else}
{$define OldDelphi}
{$endif}
{$endif}
{$ifdef OldDelphi}
{$ifdef cpu64}
TPasGLTFPtrUInt=uint64;
TPasGLTFPtrInt=int64;
{$else}
TPasGLTFPtrUInt=longword;
TPasGLTFPtrInt=longint;
{$endif}
{$endif}
PPPasGLTFSizeUInt=^PPasGLTFSizeUInt;
PPasGLTFSizeUInt=^TPasGLTFSizeUInt;
TPasGLTFSizeUInt=TPasGLTFPtrUInt;
TPasGLTFSizeUIntDynamicArray=array of TPasGLTFSizeUInt;
PPPasGLTFSizeInt=^PPasGLTFSizeInt;
PPasGLTFSizeInt=^TPasGLTFSizeInt;
TPasGLTFSizeInt=TPasGLTFPtrInt;
TPasGLTFSizeIntDynamicArray=array of TPasGLTFSizeInt;
PPPasGLTFNativeUInt=^PPasGLTFNativeUInt;
PPasGLTFNativeUInt=^TPasGLTFNativeUInt;
TPasGLTFNativeUInt=TPasGLTFPtrUInt;
PPPasGLTFNativeInt=^PPasGLTFNativeInt;
PPasGLTFNativeInt=^TPasGLTFNativeInt;
TPasGLTFNativeInt=TPasGLTFPtrInt;
PPPasGLTFSize=^PPasGLTFSizeUInt;
PPasGLTFSize=^TPasGLTFSizeUInt;
TPasGLTFSize=TPasGLTFPtrUInt;
PPPasGLTFPtrDiff=^PPasGLTFPtrDiff;
PPasGLTFPtrDiff=^TPasGLTFPtrDiff;
TPasGLTFPtrDiff=TPasGLTFPtrInt;
PPPasGLTFRawByteString=^PPasGLTFRawByteString;
PPasGLTFRawByteString=^TPasGLTFRawByteString;
TPasGLTFRawByteString={$if declared(RawByteString)}RawByteString{$else}AnsiString{$ifend};
PPPasGLTFUTF8String=^PPasGLTFUTF8String;
PPasGLTFUTF8String=^TPasGLTFUTF8String;
TPasGLTFUTF8String={$if declared(UTF8String)}UTF8String{$else}AnsiString{$ifend};
PPPasGLTFUTF16String=^PPasGLTFUTF16String;
PPasGLTFUTF16String=^TPasGLTFUTF16String;
TPasGLTFUTF16String={$if declared(UnicodeString)}UnicodeString{$else}WideString{$ifend};
EPasGLTF=class(Exception);
EPasGLTFInvalidDocument=class(EPasGLTF);
EPasGLTFInvalidBase64=class(EPasGLTF);
TPasGLTFTypedSort<T>=class
private
type TStackItem=record
Left:TPasGLTFSizeInt;
Right:TPasGLTFSizeInt;
Depth:TPasGLTFInt32;
end;
PStackItem=^TStackItem;
public
type TPasGLTFTypedSortCompareFunction=function(const a,b:T):TPasGLTFInt32;
{$ifndef fpc}
private
class function BSRDWord(aValue:TPasGLTFUInt32):TPasGLTFInt32; static;
{$endif}
public
class procedure IntroSort(const pItems:TPasGLTFPointer;const pLeft,pRight:TPasGLTFSizeInt;const pCompareFunc:TPasGLTFTypedSortCompareFunction); static;
end;
TPasGLTFDynamicArray<T>=class
private
type TValueEnumerator=record
private
fDynamicArray:TPasGLTFDynamicArray<T>;
fIndex:TPasGLTFSizeInt;
function GetCurrent:T; inline;
public
constructor Create(const aDynamicArray:TPasGLTFDynamicArray<T>);
function MoveNext:boolean; inline;
property Current:T read GetCurrent;
end;
private
fItems:array of T;
fCount:TPasGLTFSizeInt;
fAllocated:TPasGLTFSizeInt;
procedure SetCount(const pNewCount:TPasGLTFSizeInt);
function GetItem(const pIndex:TPasGLTFSizeInt):T; inline;
procedure SetItem(const pIndex:TPasGLTFSizeInt;const pItem:T); inline;
protected
public
constructor Create;
destructor Destroy; override;
procedure Clear;
function Add(const pItem:T):TPasGLTFSizeInt; overload;
function Add(const pItems:array of T):TPasGLTFSizeInt; overload;
procedure Insert(const pIndex:TPasGLTFSizeInt;const pItem:T);
procedure Delete(const pIndex:TPasGLTFSizeInt);
procedure Exchange(const pIndex,pWithIndex:TPasGLTFSizeInt); inline;
function GetEnumerator:TValueEnumerator;
function Memory:TPasGLTFPointer; inline;
property Count:TPasGLTFSizeInt read fCount write SetCount;
property Allocated:TPasGLTFSizeInt read fAllocated;
property Items[const pIndex:TPasGLTFSizeInt]:T read GetItem write SetItem; default;
end;
TPasGLTFObjectList<T:class>=class
private
type TValueEnumerator=record
private
fObjectList:TPasGLTFObjectList<T>;
fIndex:TPasGLTFSizeInt;
function GetCurrent:T; inline;
public
constructor Create(const aObjectList:TPasGLTFObjectList<T>);
function MoveNext:boolean; inline;
property Current:T read GetCurrent;
end;
private
fItems:array of T;
fCount:TPasGLTFSizeInt;
fAllocated:TPasGLTFSizeInt;
fOwnsObjects:boolean;
function RoundUpToPowerOfTwoSizeUInt(x:TPasGLTFSizeUInt):TPasGLTFSizeUInt;
procedure SetCount(const pNewCount:TPasGLTFSizeInt);
function GetItem(const pIndex:TPasGLTFSizeInt):T;
procedure SetItem(const pIndex:TPasGLTFSizeInt;const pItem:T);
public
constructor Create;
destructor Destroy; override;
procedure Clear;
function IndexOf(const pItem:T):TPasGLTFSizeInt;
function Add(const pItem:T):TPasGLTFSizeInt;
procedure Insert(const pIndex:TPasGLTFSizeInt;const pItem:T);
procedure Delete(const pIndex:TPasGLTFSizeInt);
procedure Remove(const pItem:T);
procedure Exchange(const pIndex,pWithIndex:TPasGLTFSizeInt);
function GetEnumerator:TValueEnumerator;
property Count:TPasGLTFSizeInt read fCount write SetCount;
property Allocated:TPasGLTFSizeInt read fAllocated;
property Items[const pIndex:TPasGLTFSizeInt]:T read GetItem write SetItem; default;
property OwnsObjects:boolean read fOwnsObjects write fOwnsObjects;
end;
TPasGLTFHashMapEntityIndices=array of TPasGLTFInt32;
TPasGLTFHashMapUInt128=array[0..1] of TPasGLTFUInt64;
TPasGLTFUTF8StringHashMap<TPasGLTFHashMapValue>=class
public
const CELL_EMPTY=-1;
CELL_DELETED=-2;
ENT_EMPTY=-1;
ENT_DELETED=-2;
type TPasGLTFHashMapKey=TPasGLTFUTF8String;
PPasGLTFHashMapEntity=^TPasGLTFHashMapEntity;
TPasGLTFHashMapEntity=record
Key:TPasGLTFHashMapKey;
Value:TPasGLTFHashMapValue;
end;
TPasGLTFHashMapEntities=array of TPasGLTFHashMapEntity;
private
type TPasGLTFHashMapEntityEnumerator=record
private
fHashMap:TPasGLTFUTF8StringHashMap<TPasGLTFHashMapValue>;
fIndex:TPasGLTFSizeInt;
function GetCurrent:TPasGLTFHashMapEntity; inline;
public
constructor Create(const aHashMap:TPasGLTFUTF8StringHashMap<TPasGLTFHashMapValue>);
function MoveNext:boolean; inline;
property Current:TPasGLTFHashMapEntity read GetCurrent;
end;
TPasGLTFHashMapKeyEnumerator=record
private
fHashMap:TPasGLTFUTF8StringHashMap<TPasGLTFHashMapValue>;
fIndex:TPasGLTFSizeInt;
function GetCurrent:TPasGLTFHashMapKey; inline;
public
constructor Create(const aHashMap:TPasGLTFUTF8StringHashMap<TPasGLTFHashMapValue>);
function MoveNext:boolean; inline;
property Current:TPasGLTFHashMapKey read GetCurrent;
end;
TPasGLTFHashMapValueEnumerator=record
private
fHashMap:TPasGLTFUTF8StringHashMap<TPasGLTFHashMapValue>;
fIndex:TPasGLTFSizeInt;
function GetCurrent:TPasGLTFHashMapValue; inline;
public
constructor Create(const aHashMap:TPasGLTFUTF8StringHashMap<TPasGLTFHashMapValue>);
function MoveNext:boolean; inline;
property Current:TPasGLTFHashMapValue read GetCurrent;
end;
TPasGLTFHashMapEntitiesObject=class
private
fOwner:TPasGLTFUTF8StringHashMap<TPasGLTFHashMapValue>;
public
constructor Create(const aOwner:TPasGLTFUTF8StringHashMap<TPasGLTFHashMapValue>);
function GetEnumerator:TPasGLTFHashMapEntityEnumerator;
end;
TPasGLTFHashMapKeysObject=class
private
fOwner:TPasGLTFUTF8StringHashMap<TPasGLTFHashMapValue>;
public
constructor Create(const aOwner:TPasGLTFUTF8StringHashMap<TPasGLTFHashMapValue>);
function GetEnumerator:TPasGLTFHashMapKeyEnumerator;
end;
TPasGLTFHashMapValuesObject=class
private
fOwner:TPasGLTFUTF8StringHashMap<TPasGLTFHashMapValue>;
function GetValue(const Key:TPasGLTFHashMapKey):TPasGLTFHashMapValue; inline;
procedure SetValue(const Key:TPasGLTFHashMapKey;const aValue:TPasGLTFHashMapValue); inline;
public
constructor Create(const aOwner:TPasGLTFUTF8StringHashMap<TPasGLTFHashMapValue>);
function GetEnumerator:TPasGLTFHashMapValueEnumerator;
property Values[const Key:TPasGLTFHashMapKey]:TPasGLTFHashMapValue read GetValue write SetValue; default;
end;
private
fRealSize:TPasGLTFInt32;
fLogSize:TPasGLTFInt32;
fSize:TPasGLTFInt32;
fEntities:TPasGLTFHashMapEntities;
fEntityToCellIndex:TPasGLTFHashMapEntityIndices;
fCellToEntityIndex:TPasGLTFHashMapEntityIndices;
fDefaultValue:TPasGLTFHashMapValue;
fCanShrink:boolean;
fEntitiesObject:TPasGLTFHashMapEntitiesObject;
fKeysObject:TPasGLTFHashMapKeysObject;
fValuesObject:TPasGLTFHashMapValuesObject;
function HashData(const Data:TPasGLTFPointer;const DataLength:TPasGLTFSizeUInt):TPasGLTFUInt32;
function HashKey(const Key:TPasGLTFHashMapKey):TPasGLTFUInt32;
function CompareKey(const KeyA,KeyB:TPasGLTFHashMapKey):boolean;
function FindCell(const Key:TPasGLTFHashMapKey):TPasGLTFUInt32;
procedure Resize;
protected
function GetValue(const Key:TPasGLTFHashMapKey):TPasGLTFHashMapValue;
procedure SetValue(const Key:TPasGLTFHashMapKey;const Value:TPasGLTFHashMapValue);
public
constructor Create(const DefaultValue:TPasGLTFHashMapValue);
destructor Destroy; override;
procedure Clear;
function Add(const Key:TPasGLTFHashMapKey;const Value:TPasGLTFHashMapValue):PPasGLTFHashMapEntity;
function Get(const Key:TPasGLTFHashMapKey;const CreateIfNotExist:boolean=false):PPasGLTFHashMapEntity;
function TryGet(const Key:TPasGLTFHashMapKey;out Value:TPasGLTFHashMapValue):boolean;
function ExistKey(const Key:TPasGLTFHashMapKey):boolean;
function Delete(const Key:TPasGLTFHashMapKey):boolean;
property EntityValues[const Key:TPasGLTFHashMapKey]:TPasGLTFHashMapValue read GetValue write SetValue; default;
property Entities:TPasGLTFHashMapEntitiesObject read fEntitiesObject;
property Keys:TPasGLTFHashMapKeysObject read fKeysObject;
property Values:TPasGLTFHashMapValuesObject read fValuesObject;
property CanShrink:boolean read fCanShrink write fCanShrink;
end;
TPasGLTF=class
public
type TBase64=class
public
const EncodingLookUpTable:array[0..63] of TPasGLTFRawByteChar=
(
'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P',
'Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f',
'g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v',
'w','x','y','z','0','1','2','3','4','5','6','7','8','9','+','/'
);
DecodingLookUpTable:array[TPasGLTFRawByteChar] of TPasGLTFInt8=
(
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,62,-1,-1,-1,63,
52,53,54,55,56,57,58,59,60,61,-1,-1,-1,-1,-1,-1,
-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,
15,16,17,18,19,20,21,22,23,24,25,-1,-1,-1,-1,-1,
-1,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,
41,42,43,44,45,46,47,48,49,50,51,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1
);
public
class function Encode(const aData;const aDataLength:TPasGLTFSizeInt):TPasGLTFRawByteString; overload; static;
class function Encode(const aData:array of TPasGLTFUInt8):TPasGLTFRawByteString; overload; static;
class function Encode(const aData:TPasGLTFRawByteString):TPasGLTFRawByteString; overload; static;
class function Encode(const aData:TStream):TPasGLTFRawByteString; overload; static;
class function Decode(const aInput:TPasGLTFRawByteString;const aOutput:TStream):boolean; overload; static;
end;
TChunkHeader=packed record
ChunkLength:TPasGLTFUInt32;
ChunkType:TPasGLTFUInt32;
end;
PChunkHeader=^TChunkHeader;
TGLBHeader=packed record
Magic:TPasGLTFUInt32;
Version:TPasGLTFUInt32;
Length:TPasGLTFUInt32;
JSONChunkHeader:TChunkHeader;
end;
TVector2=array[0..1] of TPasGLTFFloat;
PVector2=^TVector2;
TVector2DynamicArray=array of TVector2;
TVector3=array[0..2] of TPasGLTFFloat;
PVector3=^TVector3;
TVector3DynamicArray=array of TVector3;
TVector4=array[0..3] of TPasGLTFFloat;
PVector4=^TVector4;
TVector4DynamicArray=array of TVector4;
TInt32Vector4=array[0..3] of TPasGLTFInt32;
PInt32Vector4=^TInt32Vector4;
TInt32Vector4DynamicArray=array of TInt32Vector4;
TUInt32Vector4=array[0..3] of TPasGLTFUInt32;
PUInt32Vector4=^TUInt32Vector4;
TUInt32Vector4DynamicArray=array of TUInt32Vector4;
TMatrix2x2=array[0..3] of TPasGLTFFloat;
PMatrix2x2=^TMatrix2x2;
TMatrix2x2DynamicArray=array of TMatrix2x2;
TMatrix3x3=array[0..9] of TPasGLTFFloat;
PMatrix3x3=^TMatrix3x3;
TMatrix3x3DynamicArray=array of TMatrix3x3;
TMatrix4x4=array[0..15] of TPasGLTFFloat;
PMatrix4x4=^TMatrix4x4;
TMatrix4x4DynamicArray=array of TMatrix4x4;
const ChunkHeaderSize=SizeOf(TChunkHeader);
GLBHeaderSize=SizeOf(TGLBHeader);
GLBHeaderMagicNativeEndianness=TPasGLTFUInt32($46546c67);
GLBHeaderMagicOtherEndianness=TPasGLTFUInt32($676c5446);
GLBChunkJSONNativeEndianness=TPasGLTFUInt32($4e4f534a);
GLBChunkJSONOtherEndianness=TPasGLTFUInt32($4a534f4e);
GLBChunkBinaryNativeEndianness=TPasGLTFUInt32($004e4942);
GLBChunkBinaryOtherEndianness=TPasGLTFUInt32($42494e00);
MimeTypeApplicationOctet='application/octet-stream';
MimeTypeImagePNG='image/png';
MimeTypeImageJPG='image/jpg';
type TDefaults=class
public
const AccessorNormalized=false;
MaterialAlphaCutoff=0.5;
MaterialDoubleSided=false;
IdentityScalar=1.0;
FloatSentinel=1e+27;
NullVector3:TVector3=(0.0,0.0,0.0);
IdentityVector3:TVector3=(1.0,1.0,1.0);
IdentityVector4:TVector4=(1.0,1.0,1.0,1.0);
IdentityQuaternion:TVector4=(0.0,0.0,0.0,1.0);
NullMatrix4x4:TMatrix4x4=(0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0);
IdentityMatrix4x4:TMatrix4x4=(1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0);
end;
TDocument=class;
TBaseObject=class
private
fDocument:TDocument;
public
constructor Create(const aDocument:TDocument); reintroduce; virtual;
destructor Destroy; override;
end;
TBaseExtensionsExtrasObject=class(TBaseObject)
private
fExtensions:TPasJSONItemObject;
fExtras:TPasJSONItemObject;
public
constructor Create(const aDocument:TDocument); override;
destructor Destroy; override;
published
property Extensions:TPasJSONItemObject read fExtensions;
property Extras:TPasJSONItemObject read fExtras;
end;
TAttributes=TPasGLTFUTF8StringHashMap<TPasGLTFSizeInt>;
TAttributesList=TPasGLTFObjectList<TAttributes>;
TAccessor=class(TBaseExtensionsExtrasObject)
public
type TComponentType=
(
None=0,
SignedByte=5120,
UnsignedByte=5121,
SignedShort=5122,
UnsignedShort=5123,
UnsignedInt=5125,
Float=5126
);
PComponentType=^TComponentType;
TComponentTypeHelper=record helper for TComponentType
function GetSize:TPasGLTFSizeInt; inline;
end;
TRawComponentType=TPasGLTFUInt16;
PRawComponentType=^TRawComponentType;
TAccessorType=
(
None=0,
Scalar=1,
Vec2=2,
Vec3=3,
Vec4=4,
Mat2=5,
Mat3=6,
Mat4=7
);
PAccessorType=^TAccessorType;
TAccessorTypeHelper=record helper for TAccessorType
function GetComponentCount:TPasGLTFSizeInt; inline;
end;
TType=TAccessorType;
PType=PAccessorType;
TRawType=TPasGLTFUInt8;
PRawType=^TRawType;
TMinMaxDynamicArray=TPasGLTFDynamicArray<TPasGLTFFloat>;
TSparse=class(TBaseExtensionsExtrasObject)
public
type TIndices=class(TBaseExtensionsExtrasObject)
private
fComponentType:TComponentType;
fBufferView:TPasGLTFSizeInt;
fByteOffset:TPasGLTFSizeUInt;
fEmpty:boolean;
public
constructor Create(const aDocument:TDocument); override;
destructor Destroy; override;
published
property ComponentType:TComponentType read fComponentType write fComponentType default TComponentType.None;
property BufferView:TPasGLTFSizeInt read fBufferView write fBufferView default 0;
property ByteOffset:TPasGLTFSizeUInt read fByteOffset write fByteOffset default 0;
property Empty:boolean read fEmpty write fEmpty;
end;
TValues=class(TBaseExtensionsExtrasObject)
private
fBufferView:TPasGLTFSizeInt;
fByteOffset:TPasGLTFSizeUInt;
fEmpty:boolean;
public
constructor Create(const aDocument:TDocument); override;
destructor Destroy; override;
published
property BufferView:TPasGLTFSizeInt read fBufferView write fBufferView default 0;
property ByteOffset:TPasGLTFSizeUInt read fByteOffset write fByteOffset default 0;
property Empty:boolean read fEmpty write fEmpty;
end;
private
fCount:TPasGLTFSizeInt;
fIndices:TIndices;
fValues:TValues;
function GetEmpty:boolean;
public
constructor Create(const aDocument:TDocument); override;
destructor Destroy; override;
published
property Count:TPasGLTFSizeInt read fCount write fCount default 0;
property Indices:TIndices read fIndices;
property Values:TValues read fValues;
property Empty:boolean read GetEmpty;
end;
const TypeComponentCountTable:array[TType] of TPasGLTFSizeInt=(0,1,2,3,4,4,9,16);
private
fName:TPasGLTFUTF8String;
fComponentType:TComponentType;
fType:TAccessorType;
fBufferView:TPasGLTFSizeInt;
fByteOffset:TPasGLTFSizeUInt;
fCount:TPasGLTFSizeUInt;
fNormalized:boolean;
fMinArray:TMinMaxDynamicArray;
fMaxArray:TMinMaxDynamicArray;
fSparse:TSparse;
public
constructor Create(const aDocument:TDocument); override;
destructor Destroy; override;
function DecodeAsDoubleArray(const aForVertex:boolean=true):TPasGLTFDoubleDynamicArray;
function DecodeAsInt32Array(const aForVertex:boolean=true):TPasGLTFInt32DynamicArray;
function DecodeAsUInt32Array(const aForVertex:boolean=true):TPasGLTFUInt32DynamicArray;
function DecodeAsInt64Array(const aForVertex:boolean=true):TPasGLTFInt64DynamicArray;
function DecodeAsUInt64Array(const aForVertex:boolean=true):TPasGLTFUInt64DynamicArray;
function DecodeAsFloatArray(const aForVertex:boolean=true):TPasGLTFFloatDynamicArray;
function DecodeAsVector2Array(const aForVertex:boolean=true):TVector2DynamicArray;
function DecodeAsVector3Array(const aForVertex:boolean=true):TVector3DynamicArray;
function DecodeAsVector4Array(const aForVertex:boolean=true):TVector4DynamicArray;
function DecodeAsInt32Vector4Array(const aForVertex:boolean=true):TInt32Vector4DynamicArray;
function DecodeAsUInt32Vector4Array(const aForVertex:boolean=true):TUInt32Vector4DynamicArray;
function DecodeAsColorArray(const aForVertex:boolean=true):TVector4DynamicArray;
function DecodeAsMatrix2x2Array(const aForVertex:boolean=true):TMatrix2x2DynamicArray;
function DecodeAsMatrix3x3Array(const aForVertex:boolean=true):TMatrix3x3DynamicArray;
function DecodeAsMatrix4x4Array(const aForVertex:boolean=true):TMatrix4x4DynamicArray;
published
property ComponentType:TComponentType read fComponentType write fComponentType default TComponentType.None;
property Type_:TAccessorType read fType write fType default TAccessorType.None;
property BufferView:TPasGLTFSizeInt read fBufferView write fBufferView default -1;
property ByteOffset:TPasGLTFSizeUInt read fByteOffset write fByteOffset default 0;
property Count:TPasGLTFSizeUInt read fCount write fCount default 0;
property MinArray:TMinMaxDynamicArray read fMinArray;
property MaxArray:TMinMaxDynamicArray read fMaxArray;
property Normalized:boolean read fNormalized write fNormalized default false;
property Sparse:TSparse read fSparse;
end;
TAccessors=TPasGLTFObjectList<TAccessor>;
TAnimation=class(TBaseExtensionsExtrasObject)
public
type TChannel=class(TBaseExtensionsExtrasObject)
public
type TTarget=class(TBaseExtensionsExtrasObject)
private
fNode:TPasGLTFSizeInt;
fPath:TPasGLTFUTF8String;
fEmpty:boolean;
public
constructor Create(const aDocument:TDocument); override;
destructor Destroy; override;
published
property Node:TPasGLTFSizeInt read fNode write fNode default -1;
property Path:TPasGLTFUTF8String read fPath write fPath;
property Empty:boolean read fEmpty write fEmpty;
end;
private
fSampler:TPasGLTFSizeInt;
fTarget:TChannel.TTarget;
public
constructor Create(const aDocument:TDocument); override;
destructor Destroy; override;
published
property Sampler:TPasGLTFSizeInt read fSampler write fSampler default -1;
property Target:TChannel.TTarget read fTarget;
end;
TChannels=TPasGLTFObjectList<TChannel>;
TSampler=class(TBaseExtensionsExtrasObject)
public
type TSamplerInterpolationType=
(
Linear=0,
Step=1,
CubicSpline=2
);
PSamplerInterpolationType=^TSamplerInterpolationType;
TType=TSamplerInterpolationType;
PType=PSamplerInterpolationType;
private
fInput:TPasGLTFSizeInt;
fOutput:TPasGLTFSizeInt;
fInterpolation:TType;
public
constructor Create(const aDocument:TDocument); override;
destructor Destroy; override;
published
property Input:TPasGLTFSizeInt read fInput write fInput default -1;
property Output:TPasGLTFSizeInt read fOutput write fOutput default -1;
property Interpolation:TSamplerInterpolationType read fInterpolation write fInterpolation default TSamplerInterpolationType.Linear;
end;
TSamplers=TPasGLTFObjectList<TSampler>;
private
fName:TPasGLTFUTF8String;
fChannels:TChannels;
fSamplers:TSamplers;
public
constructor Create(const aDocument:TDocument); override;
destructor Destroy; override;
published
property Name:TPasGLTFUTF8String read fName write fName;
property Channels:TChannels read fChannels;
property Samplers:TSamplers read fSamplers;
end;
TAnimations=TPasGLTFObjectList<TAnimation>;
TAsset=class(TBaseExtensionsExtrasObject)
private
fCopyright:TPasGLTFUTF8String;
fGenerator:TPasGLTFUTF8String;