-
Notifications
You must be signed in to change notification settings - Fork 3
/
LUX.GPU.OpenGL.Shaper.pas
1452 lines (1144 loc) · 37.2 KB
/
LUX.GPU.OpenGL.Shaper.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
unit LUX.GPU.OpenGL.Shaper;
interface //#################################################################### ■
uses System.UITypes,
Winapi.OpenGL, Winapi.OpenGLext,
LUX, LUX.D2, LUX.D3, LUX.D4x4,
LUX.GPU.OpenGL,
LUX.GPU.OpenGL.Atom.Buffer,
LUX.GPU.OpenGL.Atom.Buffer.VerBuf,
LUX.GPU.OpenGL.Atom.Buffer.EleBuf,
LUX.GPU.OpenGL.Scener,
LUX.GPU.OpenGL.Matery;
type //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$【型】
TGLShaper = class;
TGLShaperPoin = class;
TGLShaperLine = class;
TGLShaperFace = class;
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$【レコード】
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$【クラス】
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% TGLShaper
TGLShaper = class( TGLObject, IGLShaper )
private
protected
_Matery :IGLMatery;
public
constructor Create; override;
destructor Destroy; override;
///// プロパティ
property Matery :IGLMatery read _Matery write _Matery;
///// メソッド
procedure BeginDraw; override;
procedure EndDraw; override;
end;
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% TGLShaperZeroPoins
TGLShaperZeroPoins = class( TGLShaper )
private
protected
_PoinsN :Integer;
///// アクセス
function GetPoinsN :Integer;
procedure SetPoinsN( const PoinsN_:Integer );
public
constructor Create; override;
destructor Destroy; override;
///// プロパティ
property PoinsN :Integer read GetPoinsN write SetPoinsN;
///// メソッド
procedure BeginDraw; override;
procedure DrawMain; override;
procedure EndDraw; override;
end;
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% TGLShaperZeroLines
TGLShaperZeroLines = class( TGLShaper )
private
protected
_LinesN :Integer;
///// アクセス
function GetLinesN :Integer;
procedure SetLinesN( const LinesN_:Integer );
public
constructor Create; override;
destructor Destroy; override;
///// プロパティ
property LinesN :Integer read GetLinesN write SetLinesN;
///// メソッド
procedure BeginDraw; override;
procedure DrawMain; override;
procedure EndDraw; override;
end;
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% TGLShaperZeroTrias
TGLShaperZeroTrias = class( TGLShaper )
private
protected
_TriasN :Integer;
///// アクセス
function GetTriasN :Integer;
procedure SetTriasN( const TriasN_:Integer );
public
constructor Create; override;
destructor Destroy; override;
///// プロパティ
property TriasN :Integer read GetTriasN write SetTriasN;
///// メソッド
procedure BeginDraw; override;
procedure DrawMain; override;
procedure EndDraw; override;
end;
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% TGLShaperPoin
TGLShaperPoin = class( TGLShaper )
private
protected
_PosBuf :TGLVerBufS<TSingle3D>;
_NorBuf :TGLVerBufS<TSingle3D>;
_TexBuf :TGLVerBufS<TSingle2D>;
public
constructor Create; override;
destructor Destroy; override;
///// プロパティ
property PosBuf :TGLVerBufS<TSingle3D> read _PosBuf;
property NorBuf :TGLVerBufS<TSingle3D> read _NorBuf;
property TexBuf :TGLVerBufS<TSingle2D> read _TexBuf;
///// メソッド
procedure BeginDraw; override;
procedure DrawMain; override;
procedure EndDraw; override;
procedure CalcBouBox; override;
procedure LoadFromFunc( const Func_:TConstFunc<TdSingle2D,TdSingle3D>; const DivU_,DivV_:Integer ); virtual;
procedure LoadFromFileSTL( const FileName_:String );
procedure LoadFromFileOBJ( const FileName_:String );
end;
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% TGLShaperLine
TGLShaperLine = class( TGLShaperPoin )
private
protected
_EleBuf :TGLEleBufLine32;
_LineW :Single;
public
constructor Create; override;
destructor Destroy; override;
///// プロパティ
property EleBuf :TGLEleBufLine32 read _EleBuf ;
property LineW :Single read _LineW write _LineW;
///// メソッド
procedure BeginDraw; override;
procedure DrawMain; override;
procedure EndDraw; override;
procedure LoadFromFunc( const Func_:TConstFunc<TdSingle2D,TdSingle3D>; const DivU_,DivV_:Integer ); override;
procedure LoadFromFileSTL( const FileName_:String );
procedure LoadFromFileOBJ( const FileName_:String );
end;
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% TGLShaperQuadLine
TGLShaperQuadLine = class( TGLShaperPoin )
private
protected
_EleBuf :TGLEleBufQuadLines32;
_LineW :Single;
public
constructor Create; override;
destructor Destroy; override;
///// プロパティ
property EleBuf :TGLEleBufQuadLines32 read _EleBuf ;
property LineW :Single read _LineW write _LineW;
///// メソッド
procedure BeginDraw; override;
procedure DrawMain; override;
procedure EndDraw; override;
end;
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% TGLShaperFace
TGLShaperFace = class( TGLShaperPoin )
private
protected
_EleBuf :TGLEleBufFace32;
public
constructor Create; override;
destructor Destroy; override;
///// プロパティ
property EleBuf :TGLEleBufFace32 read _EleBuf;
///// メソッド
procedure DrawMain; override;
procedure LoadFromFunc( const Func_:TConstFunc<TdSingle2D,TdSingle3D>; const DivU_,DivV_:Integer ); override;
procedure LoadFromFileSTL( const FileName_:String );
procedure LoadFromFileOBJ( const FileName_:String );
end;
//const //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$【定数】
//var //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$【変数】
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$【ルーチン】
implementation //############################################################### ■
uses System.SysUtils, System.Classes, System.RegularExpressions, System.Generics.Collections;
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$【レコード】
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$【クラス】
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% TGLShaper
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& private
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& protected
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& public
constructor TGLShaper.Create;
begin
inherited;
_HitTest := True;
end;
destructor TGLShaper.Destroy;
begin
inherited;
end;
/////////////////////////////////////////////////////////////////////// メソッド
procedure TGLShaper.BeginDraw;
begin
inherited;
if Assigned( _Matery ) then _Matery.Use;
end;
procedure TGLShaper.EndDraw;
begin
if Assigned( _Matery ) then _Matery.Unuse;
inherited;
end;
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% TGLShaperZeroPoins
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& private
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& protected
/////////////////////////////////////////////////////////////////////// アクセス
function TGLShaperZeroPoins.GetPoinsN :Integer;
begin
Result := _PoinsN;
end;
procedure TGLShaperZeroPoins.SetPoinsN( const PoinsN_:Integer );
begin
_PoinsN := PoinsN_;
end;
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& public
constructor TGLShaperZeroPoins.Create;
begin
inherited;
_PoinsN := 0;
end;
destructor TGLShaperZeroPoins.Destroy;
begin
inherited;
end;
/////////////////////////////////////////////////////////////////////// メソッド
procedure TGLShaperZeroPoins.BeginDraw;
begin
inherited;
end;
procedure TGLShaperZeroPoins.DrawMain;
begin
glDrawArrays( GL_POINTS, 0, _PoinsN );
end;
procedure TGLShaperZeroPoins.EndDraw;
begin
inherited;
end;
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% TGLShaperZeroLines
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& private
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& protected
/////////////////////////////////////////////////////////////////////// アクセス
function TGLShaperZeroLines.GetLinesN :Integer;
begin
Result := _LinesN;
end;
procedure TGLShaperZeroLines.SetLinesN( const LinesN_:Integer );
begin
_LinesN := LinesN_;
end;
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& public
constructor TGLShaperZeroLines.Create;
begin
inherited;
_LinesN := 0;
end;
destructor TGLShaperZeroLines.Destroy;
begin
inherited;
end;
/////////////////////////////////////////////////////////////////////// メソッド
procedure TGLShaperZeroLines.BeginDraw;
begin
inherited;
end;
procedure TGLShaperZeroLines.DrawMain;
begin
glDrawArrays( GL_LINES, 0, _LinesN );
end;
procedure TGLShaperZeroLines.EndDraw;
begin
inherited;
end;
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% TGLShaperZeroTrias
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& private
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& protected
/////////////////////////////////////////////////////////////////////// アクセス
function TGLShaperZeroTrias.GetTriasN :Integer;
begin
Result := _TriasN;
end;
procedure TGLShaperZeroTrias.SetTriasN( const TriasN_:Integer );
begin
_TriasN := TriasN_;
end;
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& public
constructor TGLShaperZeroTrias.Create;
begin
inherited;
_TriasN := 0;
end;
destructor TGLShaperZeroTrias.Destroy;
begin
inherited;
end;
/////////////////////////////////////////////////////////////////////// メソッド
procedure TGLShaperZeroTrias.BeginDraw;
begin
inherited;
end;
procedure TGLShaperZeroTrias.DrawMain;
begin
glDrawArrays( GL_TRIANGLES, 0, _TriasN );
end;
procedure TGLShaperZeroTrias.EndDraw;
begin
inherited;
end;
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% TGLShaperPoin
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& private
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& protected
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& public
constructor TGLShaperPoin.Create;
begin
inherited;
_PosBuf := TGLVerBufS<TSingle3D>.Create( GL_STATIC_DRAW );
_NorBuf := TGLVerBufS<TSingle3D>.Create( GL_STATIC_DRAW );
_TexBuf := TGLVerBufS<TSingle2D>.Create( GL_STATIC_DRAW );
end;
destructor TGLShaperPoin.Destroy;
begin
_PosBuf.Free;
_NorBuf.Free;
_TexBuf.Free;
inherited;
end;
/////////////////////////////////////////////////////////////////////// メソッド
procedure TGLShaperPoin.BeginDraw;
begin
inherited;
_PosBuf.Use( 0{BinP} );
_NorBuf.Use( 1{BinP} );
_TexBuf.Use( 2{BinP} );
end;
procedure TGLShaperPoin.DrawMain;
begin
glDrawArrays( GL_POINTS, 0, _PosBuf.Count );
end;
procedure TGLShaperPoin.EndDraw;
begin
_PosBuf.Unuse( 0{BinP} );
_NorBuf.Unuse( 1{BinP} );
_TexBuf.Unuse( 2{BinP} );
inherited;
end;
//------------------------------------------------------------------------------
procedure TGLShaperPoin.CalcBouBox;
var
B :TSingleArea3D;
I :Integer;
begin
inherited;
B := TSingleArea3D.NeMax;
with _PosBuf.Map( GL_READ_ONLY ) do
begin
for I := 0 to Count-1 do
begin
with Items[ I ] do
begin
if X < B.Min.X then B.Min.X := X;
if B.Max.X < X then B.Max.X := X;
if Y < B.Min.Y then B.Min.Y := Y;
if B.Max.Y < Y then B.Max.Y := Y;
if Z < B.Min.Z then B.Min.Z := Z;
if B.Max.Z < Z then B.Max.Z := Z;
end;
end;
Free;
end;
_Inform.BouBox := B;
end;
//------------------------------------------------------------------------------
procedure TGLShaperPoin.LoadFromFunc( const Func_:TConstFunc<TdSingle2D,TdSingle3D>; const DivU_,DivV_:Integer );
//··································
function XYtoI( const X_,Y_:Integer ) :Integer;
begin
Result := ( DivU_ + 1 ) * Y_ + X_;
end;
//··································
var
C, X, Y, I :Integer;
Ps, Ns :TGLBufferData<TSingle3D>;
Ts :TGLBufferData<TSingle2D>;
T :TSingle2D;
M :TSingleM4;
begin
C := ( DivV_ + 1 ) * ( DivU_ + 1 );
_PosBuf.Count := C;
_NorBuf.Count := C;
_TexBuf.Count := C;
Ps := _PosBuf.Map( GL_WRITE_ONLY );
Ns := _NorBuf.Map( GL_WRITE_ONLY );
Ts := _TexBuf.Map( GL_WRITE_ONLY );
for Y := 0 to DivV_ do
begin
T.V := Y / DivV_;
for X := 0 to DivU_ do
begin
T.U := X / DivU_;
I := XYtoI( X, Y );
Ts[ I ] := T;
M := Tensor( T, Func_ );
Ps[ I ] := M.AxisP;
Ns[ I ] := M.AxisZ;
end;
end;
Ps.Free;
Ns.Free;
Ts.Free;
CalcBouBox;
end;
//------------------------------------------------------------------------------
procedure TGLShaperPoin.LoadFromFileSTL( const FileName_:String );
var
F :TFileStream;
Hs :array [ 0..80-1 ] of AnsiChar;
FsN, I :Cardinal;
Fs :array of packed record
Nor :TSingle3D;
Pos1 :TSingle3D;
Pos2 :TSingle3D;
Pos3 :TSingle3D;
_ :Word;
end;
Ps, Ns :TGLBufferData<TSingle3D>;
E :TCardinal3D;
begin
F := TFileStream.Create( FileName_, fmOpenRead );
try
F.Read( Hs, SizeOf( Hs ) );
F.Read( FsN, SizeOf( FsN ) );
SetLength( Fs, FsN );
F.Read( Fs[0], 50 * FsN );
finally
F.Free;
end;
_PosBuf.Count := 3 * FsN;
_NorBuf.Count := 3 * FsN;
Ps := _PosBuf.Map( GL_WRITE_ONLY );
Ns := _NorBuf.Map( GL_WRITE_ONLY );
E.X := 0;
E.Y := 1;
E.Z := 2;
for I := 0 to FsN-1 do
begin
with Fs[ I ] do
begin
Ps[ E.X ] := Pos1;
Ps[ E.Y ] := Pos2;
Ps[ E.Z ] := Pos3;
Ns[ E.X ] := Nor;
Ns[ E.Y ] := Nor;
Ns[ E.Z ] := Nor;
end;
Inc( E.X, 3 );
Inc( E.Y, 3 );
Inc( E.Z, 3 );
end;
Ps.Free;
Ns.Free;
CalcBouBox;
end;
//------------------------------------------------------------------------------
procedure TGLShaperPoin.LoadFromFileOBJ( const FileName_:String );
type
TVert = record
P :Integer;
N :Integer;
T :Integer;
end;
var
Vs :TDictionary<TVert,Integer>;
//·····································
function ReadVert( const M_:TMatch ) :Cardinal;
var
V :TVert;
begin
with V do
begin
P := StrToIntDef( M_.Groups[ 1 ].Value, 0 ) - 1;
T := StrToIntDef( M_.Groups[ 2 ].Value, 0 ) - 1;
N := StrToIntDef( M_.Groups[ 3 ].Value, 0 ) - 1;
end;
if Vs.ContainsKey( V ) then Result := Vs[ V ]
else
begin
Result := Vs.Count; Vs.Add( V, Result );
end;
end;
//·····································
var
F :TStreamReader;
RV, RN, RT, RF, RI :TRegEx;
Ps, Ns :TArray<TSingle3D>;
Ts :TArray<TSingle2D>;
L :String;
P, N :TSingle3D;
T :TSingle2D;
Ms :TMatchCollection;
K :Integer;
V :TPair<TVert,Integer>;
begin
Vs := TDictionary<TVert,Integer>.Create;
F := TStreamReader.Create( FileName_, TEncoding.Default );
try
RV := TRegEx.Create( 'v[ \t]+([^ \t]+)[ \t]+([^ \t]+)[ \t]+([^ \t\n]+)' );
RN := TRegEx.Create( 'vn[ \t]+([^ \t]+)[ \t]+([^ \t]+)[ \t]+([^ \t\n]+)' );
RT := TRegEx.Create( 'vt[ \t]+([^ \t]+)[ \t]+([^ \t]+)' );
RF := TRegEx.Create( 'f( [^\n]+)' );
RI := TRegEx.Create( '[ \t]+(\d+)/?(\d*)/?(\d*)' );
Ps := [];
Ns := [];
Ts := [];
while not F.EndOfStream do
begin
L := F.ReadLine;
with RV.Match( L ) do
begin
if Success then
begin
P.X := Groups[ 1 ].Value.ToSingle;
P.Y := Groups[ 2 ].Value.ToSingle;
P.Z := Groups[ 3 ].Value.ToSingle;
Ps := Ps + [ P ];
end;
end;
with RN.Match( L ) do
begin
if Success then
begin
N.X := Groups[ 1 ].Value.ToSingle;
N.Y := Groups[ 2 ].Value.ToSingle;
N.Z := Groups[ 3 ].Value.ToSingle;
Ns := Ns + [ N ];
end;
end;
with RT.Match( L ) do
begin
if Success then
begin
T.X := Groups[ 1 ].Value.ToSingle;
T.Y := Groups[ 2 ].Value.ToSingle;
Ts := Ts + [ T ];
end;
end;
with RF.Match( L ) do
begin
if Success then
begin
Ms := RI.Matches( Groups[ 1 ].Value );
for K := 0 to Ms.Count-1 do ReadVert( Ms[ K ] );
end;
end;
end;
finally
F.Free;
end;
if Length( Ps ) > 0 then
begin
with _PosBuf do
begin
Count := Vs.Count;
with Map( GL_WRITE_ONLY ) do
begin
for V in Vs do Items[ V.Value ] := Ps[ V.Key.P ];
Free;
end;
end;
end;
if Length( Ns ) > 0 then
begin
with _NorBuf do
begin
Count := Vs.Count;
with Map( GL_WRITE_ONLY ) do
begin
for V in Vs do Items[ V.Value ] := Ns[ V.Key.N ];
Free;
end;
end;
end;
if Length( Ts ) > 0 then
begin
with _TexBuf do
begin
Count := Vs.Count;
with Map( GL_WRITE_ONLY ) do
begin
for V in Vs do Items[ V.Value ] := Ts[ V.Key.T ];
Free;
end;
end;
end;
Vs.Free;
CalcBouBox;
end;
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% TGLShaperLine
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& private
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& protected
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& public
constructor TGLShaperLine.Create;
begin
inherited;
_EleBuf := TGLEleBufLine32.Create( GL_STATIC_DRAW );
_LineW := 1;
end;
destructor TGLShaperLine.Destroy;
begin
_EleBuf.Free;
inherited;
end;
/////////////////////////////////////////////////////////////////////// メソッド
procedure TGLShaperLine.BeginDraw;
begin
inherited;
glLineWidth( _LineW );
end;
procedure TGLShaperLine.DrawMain;
begin
_EleBuf.Draw;
end;
procedure TGLShaperLine.EndDraw;
begin
inherited;
end;
//------------------------------------------------------------------------------
procedure TGLShaperLine.LoadFromFunc( const Func_:TConstFunc<TdSingle2D,TdSingle3D>; const DivU_,DivV_:Integer );
//··································
function XYtoI( const X_,Y_:Integer ) :Integer;
begin
Result := ( DivU_ + 1 ) * Y_ + X_;
end;
//··································
var
Es :TGLBufferData<TCardinal2D>;
X, Y, I, I0, I1 :Integer;
begin
inherited;
_EleBuf.Count := DivV_ * ( DivU_+1 ) + ( DivV_+1 ) * DivU_;
Es := _EleBuf.Map( GL_WRITE_ONLY );
I := 0;
for Y := 0 to DivV_ do
begin
for X := 0 to DivU_-1 do
begin
I0 := XYtoI( X+0, Y );
I1 := XYtoI( X+1, Y );
Es[ I ] := TCardinal2D.Create( I0, I1 ); Inc( I );
end;
end;
for X := 0 to DivU_ do
begin
for Y := 0 to DivV_-1 do
begin
I0 := XYtoI( X, Y+0 );
I1 := XYtoI( X, Y+1 );
Es[ I ] := TCardinal2D.Create( I0, I1 ); Inc( I );
end;
end;
Es.Free;
end;
//------------------------------------------------------------------------------
procedure TGLShaperLine.LoadFromFileSTL( const FileName_:String );
var
F :TFileStream;
Hs :array [ 0..80-1 ] of AnsiChar;
FsN, I :Cardinal;
Fs :array of packed record
Nor :TSingle3D;
Pos1 :TSingle3D;
Pos2 :TSingle3D;
Pos3 :TSingle3D;
_ :Word;
end;
Ps, Ns :TGLBufferData<TSingle3D>;
Es :TGLBufferData<TCardinal2D>;
E :TCardinal3D;
begin
F := TFileStream.Create( FileName_, fmOpenRead );
try
F.Read( Hs, SizeOf( Hs ) );
F.Read( FsN, SizeOf( FsN ) );
SetLength( Fs, FsN );
F.Read( Fs[0], 50 * FsN );
finally
F.Free;
end;
_PosBuf.Count := 3 * FsN;
_NorBuf.Count := 3 * FsN;
_EleBuf.Count := 3 * FsN;
Ps := _PosBuf.Map( GL_WRITE_ONLY );
Ns := _NorBuf.Map( GL_WRITE_ONLY );
Es := _EleBuf.Map( GL_WRITE_ONLY );
E.X := 0;
E.Y := 1;
E.Z := 2;
for I := 0 to FsN-1 do
begin
with Fs[ I ] do
begin
Ps[ E.X ] := Pos1;
Ps[ E.Y ] := Pos2;
Ps[ E.Z ] := Pos3;
Ns[ E.X ] := Nor;
Ns[ E.Y ] := Nor;
Ns[ E.Z ] := Nor;
end;
Es[ I*3+0 ] := TCardinal2D.Create( E.X, E.Y );
Es[ I*3+1 ] := TCardinal2D.Create( E.Y, E.Z );
Es[ I*3+2 ] := TCardinal2D.Create( E.Z, E.X );
Inc( E.X, 3 );
Inc( E.Y, 3 );
Inc( E.Z, 3 );
end;
Ps.Free;
Ns.Free;
Es.Free;
CalcBouBox;
end;
//------------------------------------------------------------------------------
procedure TGLShaperLine.LoadFromFileOBJ( const FileName_:String );
type
TVert = record
P :Integer;
N :Integer;
T :Integer;
end;
var
Vs :TDictionary<TVert,Integer>;
//·····································
function ReadVert( const M_:TMatch ) :Cardinal;
var
V :TVert;
begin
with V do
begin
P := StrToIntDef( M_.Groups[ 1 ].Value, 0 ) - 1;
T := StrToIntDef( M_.Groups[ 2 ].Value, 0 ) - 1;
N := StrToIntDef( M_.Groups[ 3 ].Value, 0 ) - 1;
end;
if Vs.ContainsKey( V ) then Result := Vs[ V ]
else
begin
Result := Vs.Count; Vs.Add( V, Result );
end;
end;
//·····································
var
F :TStreamReader;
RV, RN, RT, RF, RI :TRegEx;
Ps, Ns :TArray<TSingle3D>;
Ts :TArray<TSingle2D>;
L :String;
P, N :TSingle3D;
T :TSingle2D;
Es :TArray<TCardinal2D>;
Ms :TMatchCollection;
E :TCardinal2D;
K :Integer;
V :TPair<TVert,Integer>;
begin
Vs := TDictionary<TVert,Integer>.Create;
F := TStreamReader.Create( FileName_, TEncoding.Default );
try
RV := TRegEx.Create( 'v[ \t]+([^ \t]+)[ \t]+([^ \t]+)[ \t]+([^ \t\n]+)' );
RN := TRegEx.Create( 'vn[ \t]+([^ \t]+)[ \t]+([^ \t]+)[ \t]+([^ \t\n]+)' );
RT := TRegEx.Create( 'vt[ \t]+([^ \t]+)[ \t]+([^ \t]+)' );
RF := TRegEx.Create( 'f( [^\n]+)' );
RI := TRegEx.Create( '[ \t]+(\d+)/?(\d*)/?(\d*)' );
Ps := [];
Ns := [];
Ts := [];
Es := [];
while not F.EndOfStream do
begin
L := F.ReadLine;
with RV.Match( L ) do
begin
if Success then
begin
P.X := Groups[ 1 ].Value.ToSingle;
P.Y := Groups[ 2 ].Value.ToSingle;
P.Z := Groups[ 3 ].Value.ToSingle;
Ps := Ps + [ P ];
end;
end;
with RN.Match( L ) do
begin
if Success then
begin
N.X := Groups[ 1 ].Value.ToSingle;
N.Y := Groups[ 2 ].Value.ToSingle;
N.Z := Groups[ 3 ].Value.ToSingle;
Ns := Ns + [ N ];
end;
end;
with RT.Match( L ) do
begin
if Success then
begin