-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathTDEDITB.PAS
2636 lines (2359 loc) · 71.1 KB
/
TDEDITB.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 Tdeditb;
{$X+}{$g+}{$a+}
{Pascal 3d edting unit by Tim Lewis (c) 1996 -Real maths version 2.0}
{Please note that all window referenceing operations are performed on
'edit_view', a pointer to the currently selected 'delta_3d' view}
INTERFACE
uses
ttypes,Diskop,tmaths,msmouse,SinCos,
gbasics,ggraph,vectfont,colour,
Basic3d,tdb,crt2;
{////GLOBALS///////////////////////////////////}
const
edit_orientation:byte=0;
{////ERROR LEVELS//////////////////////////////}
ERRnone=0;
ERRnovectors=1;
ERRnojoins=2;
ERRnopolys=3;
ERRnotselected=4;
ERRfileerror=5;
ERRoneselected=6;
ERRparseerror=7;
ERRlineexists=100;
ERRpolygonexists=101;
ErrorLevel:word=ERRnone;
loadscale:real=1;
{////SELECTION LIST/////////////////////////////}
SMnewlist=0;
SMaddtolist=1;
SMcutfromlist=2;
SMintersect=3;
{////DRAWING MODE///////////////////////////////}
render_mode:word=CMDlines;
maxrotate:real=2*pi;
{///COLOUR INDEXS///////////////////////////////}
fgtexture:byte=15;
bktexture:byte=0;
crs:VectorReal=(x:0;y:0;z:0);
{////DATA TYPES : USED IN PARSING///////////////}
DTstring=1;
DTreal=2;
DTint=3;
CurrFile_Version=1;
CurrFile_Header:array[0..5] of char=('C','L','A','Y','T','L');
var
CTM:matrix3x4type;
Type
ClayFileheader=record
header:array[0..5]of char;
version:byte;
maxtextures:byte;
maxpoints,maxjoins,maxpolys:word;
filler:array[0..64-15]of byte;
end;
MatrixElem=^MatrixElem_;
MatrixElem_=object(belem)
Mat:matrix3x4type_;
end;
tokenstring=string[30];
longintlist=^longintlist_;
longintlist_=object(belem)
data:longint;
end;
prototype=^prototype_;
prototype_=object(belem)
name:tokenstring;
bufpos:longint;
end;
tokentype=^tokentype_;
tokentype_=object(belem)
token:tokenstring;
end;
realrgb=record
r,g,b:real;
end;
edit_objtype=^edit_objtype_;
edit_objtype_=object(objtype_)
Function getnode(id:byte;xps,yps:integer;getselected:boolean):integer;
Function getselectlist(id:byte;R:trect;selmode:byte):boolean;
procedure selectall;
procedure selectconnected(noderef:word);
Function getselectlistconnected(id:byte;R:trect):boolean;
function getallconnectedpolygons(poly:polygonptr):linkedlistptr;
procedure selectnode(noderef:word);
procedure selectpoly(polyref:word);
procedure clearselection;
procedure calcselectedpolys;
function counttriangles:integer;
Procedure copyobj(copymode:byte;extrude,reselect:boolean);
Procedure copypoint(dot:word);
Procedure addvector(xa,ya,za:real);
procedure addjoin(dot1,dot2:word);
procedure addjoincheck(dot1,dot2:word);
procedure addpolygon(startp,count:word;attrib_:byte;mode:word);
procedure addpolygonByRef(startp:wordarray;count:word;attrib_:byte;mode:word);
procedure addquad(p1,p2,p3,p4:word;attrib_:word);
procedure addtriangle(p1,p2,p3:word;attrib_:word);
procedure addline(p1,p2:word;attrib_:word);
procedure connect(p1,p2,count:word;attrib_:byte;connectup:boolean);
Procedure connectbyref(p1:word;list:wordarray;count:word;attrib:byte);
Procedure ConnectPoint(p1,point,count:word;attrib_:byte);
procedure delete_select(whattodel:byte);
procedure deletejoin(lineno:word);
procedure deletepoly(polyno:word);
procedure merge;
{procedure deleteduplicatereferences(var p:polygontype);}
Procedure flip(direction:byte);
Procedure FlipSelectedNormals;
Procedure SetSelectedTexture(textureref_:byte);
Procedure SetSelectedAttrib(attrib_: word; mode: byte);
Procedure QuadDivideSelected;
Procedure TriangulateSelected;
procedure TriangulatePoly(polyref:word;from_p:byte);
procedure splitpolygons;
procedure mktext(x1,y1,z1:real;txt:string;var vfont:font_type);
Procedure mkcircle(cx,cy,rx,ry,z1:real;stp:word;startangle:real;mode:byte;attrib_:byte);
Procedure mksquare(x1,y1,x2,y2,z1:real;attrib_:byte);
procedure mkcylinder(cx,cy,rx1,ry1,rx2,ry2,z1,z2:real;stp:word;startangle:real;attrib_:byte);
Procedure mksphere(cx,cy,cz,rx,ry,rz:real;stp,stpz:word;startangle:real;attrib_:byte);
procedure mkcone(cx,cy,rx,ry,z1,z2:real;stp:word;startangle:real;attrib_:byte);
procedure mkcube(x1,y1,z1,x2,y2,z2:real;attrib_:byte);
procedure mkgrid(x1,y1,x2,y2,z1:real;xstp,ystp:word;sineornot,checkornot:boolean;attrib_:byte);
Procedure mkgridfrompic(x1,y1,x2,y2,z1:real;pic:bitmaptypeptr;checkornot:boolean;attrib_:byte);
procedure rotateobj(axis:byte;stp,attrib:byte);
procedure extrudepath(path:objtype;attrib:byte;extrude:boolean);
procedure splitline(line:word);
procedure readgor(filename:string;append:boolean);
procedure readVTek(filename:string);
procedure read3d(filename:string;append:boolean);
procedure readEAfile(filename:string);
procedure readOBJ(filename:string);
Procedure readGEO(filename:string);
procedure readRW(filename:string);
procedure readVRML(filename:string);
procedure writegor(filename:string);
procedure writeVRML(filename:string);
procedure writejava(filename:string);
procedure write3d(filename:string);
procedure writePLG(filename:string);
procedure writeSG(filename:string);
procedure writeRW(filename:string);
procedure writePOV(filename:string);
procedure writeOBJ(filename:string);
Procedure writeGEO(filename:string);
procedure write3ds(filename:string);
procedure write3dsasc(filename:string);
procedure writeCOBasc(filename:string);
end;
Procedure conv2d_3d(id:byte;xp,yp:real;filter,dot:VectorRealptr);
Procedure conv3d_2d(id:byte;dot:VectorRealptr;var x,y:integer);
IMPLEMENTATION
function createMATRIX(const mat:matrix3x4type):matrixelem;
var newmat:matrixelem;
begin
getmem(newmat,sizeof(matrixelem_));
newmat^.mat:=mat^;
createMATRIX:=newmat;
end;
function createTOKEN(const token:tokenstring):tokentype;
var newtoken:tokentype;
begin
getmem(newtoken,sizeof(tokentype_));
newtoken^.token:=token;
createTOKEN:=newtoken;
end;
function createPROTOTYPE(const protoname:tokenstring;filepos:longint):prototype;
var newproto:prototype;
begin
getmem(newproto,sizeof(prototype_));
newproto^.name:=protoname;
newproto^.bufpos:=filepos;
createPROTOTYPE:=newproto;
end;
function createLONGINT(data:longint):longintlist;
var newlongint:longintlist;
begin
getmem(newlongint,sizeof(longintlist_));
newLONGINT^.data:=data;
createLONGINT:=newlongint;
end;
{This will take a 2d point and convert it to 3d space, the missing
axis (x,y or z) being in the apropriate position in 'filter'.
Scaling (via the global real 'scale') IS performed}
Procedure conv2d_3d(id:byte;xp,yp:real;filter,dot:VectorRealPtr);
Begin
xp:=xp/scale;
yp:=yp/scale;
with dot^ do
case id of
XY_view:moveto(xp,yp,filter^.z);
XZ_view:moveto(xp,filter^.y,yp);
ZY_view:moveto(filter^.x,yp,xp);
End;
End;
{This will parallel project from (real) 3d to (integer)2d along
x/y, z/y or x/z depending on 'id'. Scaling is performed using
the global 'scale'
}
Procedure conv3d_2d(id:byte;dot:VectorRealPtr;var x,y:integer);
Begin
case id of
XY_view:Begin x:=round(dot^.x*scale);y:=round(dot^.y*scale);End;
XZ_view:Begin x:=round(dot^.x*scale);y:=round(dot^.z*scale);End;
ZY_view:Begin x:=round(dot^.z*scale);y:=round(dot^.y*scale);End;
end;
End;
{////EDIT_OBJTYPE///////////////////////////////}
Procedure edit_objtype_.copyobj(copymode:byte;extrude,reselect:boolean);
{var retcopy:edit_objtype;}
var lop,oldmax,oldmaxp:word;
oldtexture:byte;
function getspos(node:word):word;
var sublop:word;
begin
{if maxselect<oldmaxp-1 then begin}
sublop:=0;
while (select^[sublop]<>node) and (sublop<maxselect) do
inc(sublop);
{end else
sublop:=node;}
getspos:=sublop+oldmaxp;
end;
Begin
if maxselect=0 then begin
ErrorLevel:=ERRnotselected;
end else begin
oldmaxp:=maxpoints;
if Extrude then
connectbyref(maxpoints,select,maxselect,0);
if errorlevel>ERRnone then exit;
for lop:=0 to maxselect-1 do
copypoint(select^[lop]);
oldmax:=maxjoins;
if (copymode and CMjoins<>0)and(maxjoins>0) then
for lop:=0 to oldmax-1 do with jointo^[lop] do
if (thred^[f].Nattrib and Naselected<>0) and (thred^[t].Nattrib and Naselected<>0) then begin
{fgtexture:=colour;}
addjoin(getspos(f),getspos(t));
end;
if errorlevel>ERRnone then exit;
oldmax:=maxpolys;
if (copymode and CMpolys<>0)and(maxpolys>0) then begin
oldtexture:=fgtexture;
for lop:=0 to oldmax-1 do with polys^[lop] do
if allselected(thred) then begin
fgtexture:=textureref;
case numsides of
2:addline(getspos(p[1]),getspos(p[0]),pattrib and PAsetmask3d);
3:addtriangle(getspos(p[2]),getspos(p[1]),getspos(p[0]),pattrib and PAsetmask3d);
4:addquad(getspos(p[3]),getspos(p[2]),getspos(p[1]),getspos(p[0]),pattrib and PAsetmask3d);
end;
end;
fgtexture:=oldtexture;
end;
{select new points}
if reselect then
for lop:=0 to maxselect-1 do begin
with thred^[select^[lop]] do Nattrib:=Nattrib and not NaSelected;
select^[lop]:=oldmaxp+lop;
with thred^[oldmaxp+lop] do Nattrib:=Nattrib or NaSelected;
end;
calcselectedpolys;
end;
end;
{splits a lines and any related faces}
Procedure edit_objtype_.splitline(line:word);
var
newvec:vectorreal;
count:integer;
lop:byte;
join:joinptr;
begin
join:=@jointo^[line];
newvec:=thred^[join^.f];
with thred^[join^.t] do
newvec.add(x,y,z);
newvec.divide(2);
addvector(newvec.x,newvec.y,newvec.z);
addjoin(join^.f,maxpoints-1);
addjoin(maxpoints-1,join^.t);
count:=maxpolys-1;
while (count>=0) do begin
if jointo^[line].insidepoly(polys^[count]) then with polys^[count] do begin
lop:=0;
while (p[lop]<>join^.f)or(p[lop]<>join^.t) do
inc(lop);
{split up faces here! do it tomorrow}
count:=maxpolys;
end;
dec(count);
end;
end;
Procedure edit_objtype_.quaddivideselected;
Var lop,lop2,sublop:word;
pointlop:byte;
new:vectorreal;
oldtexture:byte;
begin
if (maxpolys>0) then begin
CTM:=@unitmatrix;
for lop:=0 to maxpolys-1 do with polys^[lop] do
if (allselected(thred))and(numsides>2) then begin
oldtexture:=fgtexture;
fgtexture:=textureref;
if (numsides=4) then begin
lop2:=0;
while (lop2<maxjoins)and(maxjoins>=0) do begin {delete affected lines}
if jointo^[lop2].insidepoly(polys^[lop]) then
deletejoin(lop2)
else
inc(lop2);
end;
new.moveto(0,0,0);
for pointlop:=0 to 3 do with thred^[p[pointlop]] do
new.add(x,y,z);
new.divide(4);
with new do begin
{sub(x,y,z);}
addvector(x,y,z);
end;
for pointlop:=0 to 2 do begin
new:=thred^[p[pointlop]];
with thred^[p[pointlop+1]] do
new.add(x,y,z);
new.divide(2);
with new do
addvector(x,y,z);
end;
new:=thred^[p[3]];
with thred^[p[0]] do
new.add(x,y,z);
new.divide(2);
with new do
addvector(x,y,z);
addjoincheck(maxpoints-1,maxpoints-5);
addjoincheck(maxpoints-5,maxpoints-3);
addjoincheck(maxpoints-4,maxpoints-5);
addjoincheck(maxpoints-5,maxpoints-2);
addjoincheck(p[0],maxpoints-4);
addjoincheck(maxpoints-4,p[1]);
addjoincheck(p[1],maxpoints-3);
addjoincheck(maxpoints-3,p[2]);
addjoincheck(p[2],maxpoints-2);
addjoincheck(maxpoints-2,p[3]);
addjoincheck(p[3],maxpoints-1);
addjoincheck(maxpoints-1,p[0]);
addquad(maxpoints-4,p[1],maxpoints-3,maxpoints-5,pattrib or PaClockWise);
addquad(maxpoints-5,maxpoints-3,p[2],maxpoints-2,pattrib or PaClockWise);
addquad(maxpoints-1,maxpoints-5,maxpoints-2,p[3],pattrib or PaClockWise);
p[1]:=maxpoints-4;
p[2]:=maxpoints-5;
p[3]:=maxpoints-1;
end;
fgtexture:=oldtexture;
end;
end
else ErrorLevel:=ERRnotselected;
end;
procedure edit_objtype_.TriangulatePoly(polyref:word;from_p:byte);
var oldtexture:byte;
to_p:byte;
begin
with polys^[polyref] do begin
oldtexture:=fgtexture;
fgtexture:=textureref;
if (numsides>3) then begin
to_p:=(from_p +2) mod numsides;
from_p:=from_p mod numsides;
addjoincheck(p[from_p],p[to_p]);
addtriangle(p[from_p],p[(from_p+1)mod numsides],p[to_p],pattrib or PaClockWise or Paallselected);
numsides:=3;
p[0]:=from_p;
p[1]:=to_p;
p[2]:=(to_p +1 ) and 3;
fgtexture:=oldtexture;
end;
end;
end;
procedure edit_objtype_.splitpolygons;
var lop:word;
selected:byte;
begin
if (maxpolys>0)and(maxselect>0)and(maxselect<3) then begin
for lop:=0 to maxpolys do with polys^[lop] do if numsides=4 then begin
selected:=GetFirstSelected(thred);
if selected<>255 then begin
{if thred^[p[selected+2]].nattrib and NAselected<>0 then begin}
triangulatepoly(lop,selected);
{end;}
end else begin
{sound(100);delay(10);nosound;}
end;
end;
end else
ErrorLevel:=ERRnotselected;
end;
Procedure edit_objtype_.Triangulateselected;
Var lop:word;
oldtexture:byte;
begin
if maxpolys>0 then begin
CTM:=@unitmatrix;
for lop:=0 to maxpolys-1 do with polys^[lop] do
if (allselected(thred))and(numsides=4) then begin
oldtexture:=fgtexture;
fgtexture:=textureref;
addjoincheck(p[1],p[3]);
addtriangle(p[1],p[2],p[3],pattrib or PaClockWise or Paallselected);
numsides:=3;
p[2]:=p[3];
p[3]:=0;
fgtexture:=oldtexture;
end;
end else
ErrorLevel:=ERRnotselected;
end;
Procedure edit_objtype_.connectbyref(p1:word;list:wordarray;count:word;attrib:byte);
Var lop:word;
pf,pt:word;
function getspos(node:word;var pos:word):boolean;
var
found:boolean;
begin
pos:=0;
found:=false;
while (not found) and (pos<maxselect) do begin
found:=select^[pos]=node;
inc(pos);
end;
dec(pos);
inc(pos,maxpoints);
getspos:=found;
end;
Begin
For lop:=0 to count-1 do
addjoin(p1+lop,list^[lop]);
For lop:=0 to maxjoins-2 do with jointo^[lop] do begin
if (allselected(thred))and(getspos(f,pf))and(getspos(t,pt)) then begin
addquad(pf,pt,t,f,attrib);
end;
end;
End;
Procedure edit_objtype_.copypoint(dot:word);
Begin
addvector(thred^[dot].x,thred^[dot].y,thred^[dot].z);
End;
Function edit_objtype_.getnode(id:byte;xps,yps:integer;getselected:boolean):integer;
const border=3;
var lop:word;ans:integer;chk:pointtype;
Begin
lop:=0;ans:=-1;
while (ans=-1) and (lop<maxpoints) do
Begin
conv3d_2d(id,@thred^[lop],chk.x,chk.y);
with chk do
if (xps>x-border) and (xps<x+border) and
(yps<y+border) and (yps>y-border) and
(((getselected) and (thred^[lop].Nattrib and NaSelected<>0))or not getselected) then ans:=lop;
inc(lop);
End;
getnode:=ans;
End;{of function}
Procedure edit_objtype_.addvector(xa,ya,za:real);
begin
if maxpoints<pointsize then
with thred^[maxpoints] do begin
moveto(xa,ya,za);
multmatrix(CTM);
Nattrib:=0;
inc(maxpoints);
end
else
ErrorLevel:=ERRnovectors;
end;
{this routine is the basis of 2d-to-3d operations.
Scale factors and cursor position are taken into account.
Always draws in X/Y. The CTM can rotate and translate into
any other orientation in the routines 'addvector'
}
procedure edit_objtype_.addjoin(dot1,dot2:word);
begin
if (maxjoins<joinsize) then begin
with jointo^[maxjoins] do begin
f:=dot1;
t:=dot2;
end;
inc(maxjoins);
end else
ErrorLevel:=ERRnoJoins;
end;
procedure edit_objtype_.addjoincheck(dot1,dot2:word);
var exists:boolean;
lop:word;
newjoin:jointype;
begin
lop:=0;
exists:=false;
with newjoin do begin
f:=dot1;
t:=dot2;
end;
while (lop<maxjoins)and(not exists) do begin
exists:=jointo^[lop].equals(newjoin);
inc(lop);
end;
if not exists then begin
if (maxjoins<joinsize) then begin
jointo^[maxjoins]:=newjoin;
inc(maxjoins);
end else
ErrorLevel:=ERRnoJoins;
end;
end;
procedure edit_objtype_.addpolygon(startp,count:word;attrib_:byte;mode:word);
var lop:word;
{checks if a horizontal line ( x to inf.,y) intersects xa,ya to xb,yb)}
function intersect(x,y,xa,ya,xb,yb:integer):boolean;
begin
if ya>yb then begin fswap(ya,yb,2);fswap(xa,xb,2);end;
intersect:=(y>=ya)and(y<=yb)and((x>=xa)or(x>=xb));
end;
begin
if mode and PClines<>0 then begin
for lop:=0 to count-2 do
if mode and PCchecklines<>0 then
addjoincheck(startp+lop,startp+lop+1)
else
addjoin(startp+lop,startp+lop+1);
if attrib_ and PaConnected<>0 then
if mode and PCchecklines<>0 then
addjoincheck(startp+count-1,startp)
else
addjoin(startp+count-1,startp);
end;
if mode and PCpolys<>0 then
if count=2 then
addline(startp,startp+1,attrib_)
else begin
if count>3 then begin
for lop:=0 to (count shr 1)-2 do
addquad(startp+lop,startp+lop+1,startp+count-lop-2,startp+count-lop-1,attrib_);
inc(lop);
end else
lop:=0;
inc(lop,startp);
if (count mod 2)=1 then
addtriangle(lop,lop+1,lop+2,attrib_);
end;
end;
procedure edit_objtype_.AddPolygonByRef(startp:wordarray;count:word;attrib_:byte;mode:word);
var lop:word;
begin
if mode and PClines<>0 then begin
for lop:=0 to count-2 do
if mode and PCchecklines<>0 then
addjoincheck(startp^[lop],startp^[lop+1])
else
addjoin(startp^[lop],startp^[lop+1]);
if attrib_ and PaConnected<>0 then
if mode and PCchecklines<>0 then
addjoincheck(startp^[count-1],startp^[0])
else
addjoin(startp^[count-1],startp^[0])
end;
if mode and PCpolys<>0 then begin
if count=2 then
addline(startp^[count-1],startp^[count-2],attrib_)
else begin
if count>3 then begin
for lop:=0 to (count shr 1)-2 do begin
addquad(startp^[lop],startp^[1+lop],startp^[count-lop-2],startp^[count-lop-1],attrib_);
{with polys^[maxpolys-1] do
if allselected(@thred) then pattrib:=pattrib or PAallselected; }
end;
inc(lop);
end else
lop:=0;
if (count mod 2)=1 then begin
addtriangle(startp^[lop],startp^[lop+1],startp^[lop+2],attrib_);
{with polys^[maxpolys-1] do
if allselected(@thred) then pattrib:=pattrib or PAallselected;}
end;
end;
calcselectedpolys;
end;
end;
Procedure edit_objtype_.addquad(p1,p2,p3,p4:word;attrib_:word);
Begin
if maxpolys<polysize then
with polys^[maxpolys] do begin
textureref:=fgtexture;
numsides:=4;
pattrib:=attrib_ and PAsetmask3d;
if (attrib_ and PAclockwise<>0) then begin
p[0]:=p1;p[1]:=p2;
p[2]:=p3;p[3]:=p4;
end else begin
p[3]:=p1;p[2]:=p2;
p[1]:=p3;p[0]:=p4;
end;
if not anyduplicates then
inc(maxpolys);
End
Else
ErrorLevel:=ERRnopolys;
End;
Procedure edit_objtype_.addtriangle(p1,p2,p3:word;attrib_:word);
Begin
if maxpolys<polysize then
with polys^[maxpolys] do begin
textureref:=fgtexture;
numsides:=3;
pattrib:=attrib_ and PAsetmask3d;
if ((attrib_ and PAclockwise<>0)) then begin
p[0]:=p1;p[1]:=p2;p[2]:=p3;
end else begin
p[0]:=p3;p[1]:=p2;p[2]:=p1;
end;
if not anyduplicates then
inc(maxpolys);
End
Else
ErrorLevel:=ERRnopolys;
End;
Procedure edit_objtype_.addline(p1,p2:word;attrib_:word);
Begin
if maxpolys<polysize then
with polys^[maxpolys] do begin
textureref:=fgtexture;
numsides:=2;
pattrib:=attrib_ and PAsetmask3d;
p[0]:=p1;p[1]:=p2;
if not anyduplicates then
inc(maxpolys);
End
Else
ErrorLevel:=ERRnopolys;
End;
{Procedure edit_objtype_.linering(start,fin,off:word);
var lop:byte;
Begin
For lop:=0 to fin-2 do
addjoin(start+lop,start+lop+off);
addjoin(start,start+fin-2+off);
End;}
Procedure edit_objtype_.connect(p1,p2,count:word;attrib_:byte;connectup:boolean);
Var lop:word;
Cstart:word;
Begin
Cstart:=0;
For lop:=0 to count-1 do Begin
addjoin(p1+lop,p2+lop);
if lop<count-1 then
addquad(p1+lop,p1+lop+1,p2+1+lop,p2+lop,attrib_);
End;
if connectup then
addquad(p1+count-1,p1,p2,p2+count-1,attrib_);
End;
Procedure edit_objtype_.ConnectPoint(p1,point,count:word;attrib_:byte);
var lop:word;
begin
for lop:=0 to count-1 do
addjoin(p1+lop,point);
For lop:=0 to count-2 do
addtriangle(p1+lop+1,p1+lop,point,attrib_);
addtriangle(p1,p1+count-1,point,attrib_);
End;
procedure edit_objtype_.calcselectedpolys;
var lop:word;
nlop,nselected:byte;
begin
if maxpolys>0 then begin
for lop:=0 to maxpolys-1 do with polys^[lop] do begin
nselected:=numsides;
for nlop:=0 to numsides-1 do begin
if thred^[p[nlop]].nattrib and NAselected<>0 then
dec(nselected);
end;
pattrib:=pattrib and (not PAallselected+PAsomeselected);
if nselected=0 then
pattrib:=pattrib or PAallselected
else if nselected<numsides then
pattrib:=pattrib or PAsomeselected;
end;
end;
end;
function edit_objtype_.getallconnectedpolygons(poly:polygonptr):linkedlistptr;
var list:linkedlistptr;
lop:word;
begin
new(list,create(sizeof(wordlistelem)));
for lop:=0 to maxpolys-1 do begin
if polys^[lop].anyequal(poly) then
if not polys^[lop].allselected(thred) then
list^.add(createwordelem(lop));
end;
getallconnectedpolygons:=list;
end;
procedure edit_objtype_.selectconnected(noderef:word);
procedure GetNextPoly(currpoly:polygonptr);
var list:linkedlistptr;
elem:wordlistelemptr;
begin
list:=getallconnectedpolygons(currpoly);
elem:=list^.first;
while elem<>nil do begin
selectpoly(elem^.data);
elem:=elem^.next;
end;
elem:=list^.first;
while elem<>nil do begin
GetNextPoly(@polys^[elem^.data]);
elem:=elem^.next;
end;
dispose(list,done);
end;
var lop,nlop:word;
polyref:integer;
begin
polyref:=-1;
lop:=0;
while (polyref=-1)and (lop<maxpolys) do with polys^[lop] do begin
for nlop:=0 to numsides-1 do
if p[nlop]=noderef then
polyref:=lop;
inc(lop);
end;
if polyref<>-1 then begin
GetNextPoly(@polys^[polyref]);
end;
end;
Function edit_objtype_.getselectlistconnected(id:byte;R:trect):boolean;
var
lop:word;
noderef:integer;
chkpoint:pointtype;
Begin
if maxpoints>0 then with R do begin
lop:=0;
clearselection;
while (lop<maxpoints) do with chkpoint do begin
if (thred^[lop].Nattrib and NAselected=0) then begin
conv3d_2d(id,@thred^[lop],x,y);
if (x>=x1) and (x<=x2) and (y>=y1) and (y<=y2) then
selectconnected(lop);
end;
inc(lop);
end;
getmaxmin;
end;
End;{of procedure}
function close_to(x,y,xm,ym,howclose:integer):boolean;
begin
close_to:=(xm>=x-howclose)and(ym>=y-howclose)and
(xm<=x+howclose)and(ym<=y+howclose);
end;
Function edit_objtype_.getselectlist(id:byte;R:trect;selmode:byte):boolean;
var lop,cnt:word;
chkpoint:pointtype;
Begin
if maxpoints>0 then with R do begin
{freemem(select,maxselect);}
with chkpoint do
case selmode of
SMintersect:if (maxselect>0) then
for lop:=0 to maxpoints-1 do begin
conv3d_2d(id,@thred^[lop],x,y);
if not(r.contains(x,y)) then
with thred^[lop] do Nattrib:=Nattrib and not NaSelected;
end;
SMcutfromlist:if (maxselect>0) then
for lop:=0 to maxpoints-1 do begin
conv3d_2d(id,@thred^[lop],x,y);
if (r.contains(x,y)) then
with thred^[lop] do Nattrib:=Nattrib and not NaSelected;
end;
SMnewlist:
for lop:=0 to maxpoints-1 do begin
conv3d_2d(id,@thred^[lop],x,y);
if (r.contains(x,y)) then
with thred^[lop] do Nattrib:=Nattrib or NaSelected
else
with thred^[lop] do Nattrib:=Nattrib and not NaSelected;
end;
SMaddtolist:
for lop:=0 to maxpoints-1 do begin
conv3d_2d(id,@thred^[lop],x,y);
if (r.contains(x,y)) then
with thred^[lop] do Nattrib:=Nattrib or NaSelected;
end;
end;
{find out how many are selected}
maxselect:=0;
for lop:=0 to maxpoints-1 do begin
with thred^[lop] do
if Nattrib and NAselected<>0 then inc(maxselect);
end;
{GetMem(select,maxselect);}
cnt:=0;
for lop:=0 to maxpoints-1 do begin
with thred^[lop] do
if Nattrib and NAselected<>0 then begin
select^[cnt]:=lop;
inc(cnt);
end;
end;
getmaxmin;
calcselectedpolys;
end;
End;{of procedure}
procedure edit_objtype_.selectpoly(polyref:word);
var lop:byte;
begin
with polys^[polyref] do begin
for lop:=0 to numsides-1 do
selectnode(p[lop]);
Pattrib:=Pattrib or PAallselected;
end;
end;
procedure edit_objtype_.selectnode(noderef:word);
begin
if thred^[noderef].nattrib and NAselected=0 then begin
thred^[noderef].Nattrib:=thred^[noderef].Nattrib or NAselected;
select^[maxselect]:=noderef;
inc(maxselect);
end;
end;
procedure edit_objtype_.clearselection;
var lop:word;
begin
if maxselect>0 then begin
for lop:=0 to maxselect-1 do
with thred^[Select^[lop]] do Nattrib:=Nattrib and not NaSelected;
maxselect:=0;
for lop:=0 to maxpolys do with polys^[lop] do begin
Pattrib:=Pattrib and (not PAselected);
end;
end;
end;
Procedure edit_objtype_.FlipSelectedNormals;
var lop:word;
begin
if maxselect>0 then begin
if maxjoins>0 then
for lop:=0 to maxjoins-1 do with jointo^[lop] do
if allselected(thred) then reverse;
if maxpolys>0 then
for lop:=0 to maxpolys-1 do with polys^[lop] do
if allselected(thred) then reverse;
end else
ErrorLevel:=ERRnotselected;
end;
Procedure edit_objtype_.SetSelectedTexture(textureref_:byte);
var lop:word;
begin
if maxselect>0 then begin
if maxpolys>0 then
for lop:=0 to maxpolys-1 do with polys^[lop] do
if allselected(thred) then
textureref:=textureref_;
end else
ErrorLevel:=ERRnotselected;
{if maxjoins>0 then
for lop:=0 to maxjoins-1 do with jointo^[lop] do
if (thred^[f].selected) and (thred^[t].selected) then colour:=col;}
end;
Procedure edit_objtype_.SetSelectedAttrib(attrib_: word; mode: byte);
var lop:word;
begin
if maxselect>0 then begin
if maxpolys>0 then
for lop:=0 to maxpolys-1 do with polys^[lop] do
if allselected(thred) then SetAttrib(attrib_,mode);
end else
ErrorLevel:=ERRnotselected;