forked from thargor6/mb3d
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAnimation.pas
1630 lines (1546 loc) · 57.2 KB
/
Animation.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 Animation;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, ExtCtrls, FileHandling, Mand, Buttons, StdCtrls,
LightAdjust, HeaderTrafos, TypeDefinitions, Math3D;
type
TKeyFrame = record
KFcount, KFtime, KFsmooth: Integer;
PrevBMP: TBitmap;
HeaderParas: TMandHeader10;
HAddOn: THeaderCustomAddon;
end;
TAnimationForm = class(TForm)
Panel2: TPanel;
Panel3: TPanel;
Shape1: TShape;
SpeedButton1: TSpeedButton;
Button1: TButton;
Button2: TButton;
Edit2: TEdit;
Button3: TButton;
OpenDialog4: TOpenDialog;
SpeedButton11: TSpeedButton;
GroupBox1: TGroupBox;
Button4: TButton;
Label9: TLabel;
Label11: TLabel;
Label12: TLabel;
Label13: TLabel;
Label14: TLabel;
SpeedButton4: TSpeedButton;
Timer2: TTimer;
PaintBox1: TPaintBox;
Shape2: TShape;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
SpeedButton2: TSpeedButton;
SpeedButton3: TSpeedButton;
SpeedButton5: TSpeedButton;
SpeedButton6: TSpeedButton;
SpeedButton7: TSpeedButton;
SpeedButton8: TSpeedButton;
Edit1: TEdit;
Label19: TLabel;
SpeedButton9: TSpeedButton;
SaveDialog1: TSaveDialog;
Label22: TLabel;
GroupBox2: TGroupBox;
Label7: TLabel;
Label8: TLabel;
Edit3: TEdit;
Edit4: TEdit;
GroupBox3: TGroupBox;
Label17: TLabel;
Label18: TLabel;
Label24: TLabel;
Edit6: TEdit;
Edit7: TEdit;
Label6: TLabel;
Edit8: TEdit;
Label10: TLabel;
Edit9: TEdit;
Edit10: TEdit;
Timer3: TTimer;
SpeedButton10: TSpeedButton;
Label16: TLabel;
Label25: TLabel;
RadioGroup2: TRadioGroup;
CheckBox2: TCheckBox;
RadioGroup3: TRadioGroup;
GroupBox4: TGroupBox;
Label20: TLabel;
Label15: TLabel;
Edit5: TEdit;
CheckBox1: TCheckBox;
Label21: TLabel;
RadioGroup1: TRadioGroup;
CheckBox3: TCheckBox;
CheckBox4: TCheckBox;
CheckBox5: TCheckBox;
CheckBox6: TCheckBox;
CheckBox7: TCheckBox;
Label23: TLabel;
Label26: TLabel;
Label27: TLabel;
Label28: TLabel;
Label29: TLabel;
Label30: TLabel;
Edit11: TEdit;
SpeedButton12: TSpeedButton;
Edit21: TEdit;
UpDown3: TUpDown;
Edit12: TEdit;
UpDown1: TUpDown;
Edit13: TEdit;
UpDown2: TUpDown;
SpeedButton13: TSpeedButton;
SpeedButton14: TSpeedButton;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Shape1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure Shape1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure SpeedButton1Click(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure Edit1Change(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure SpeedButton11Click(Sender: TObject);
procedure SpeedButton4Click(Sender: TObject);
procedure SpeedButton7Click(Sender: TObject);
procedure SpeedButton6Click(Sender: TObject);
procedure SpeedButton5Click(Sender: TObject);
procedure SpeedButton2Click(Sender: TObject);
procedure SpeedButton3Click(Sender: TObject);
procedure SpeedButton8Click(Sender: TObject);
procedure PaintBox1Paint(Sender: TObject);
procedure SpinEdit1Change(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Timer2Timer(Sender: TObject);
procedure SpeedButton9Click(Sender: TObject);
procedure Edit6Change(Sender: TObject);
procedure Edit3Change(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Timer3Timer(Sender: TObject);
procedure SpeedButton10Click(Sender: TObject);
procedure Edit5Change(Sender: TObject);
procedure FormKeyPress(Sender: TObject; var Key: Char);
procedure CheckBox4Click(Sender: TObject);
procedure SpeedButton12Click(Sender: TObject);
procedure SpeedButton13Click(Sender: TObject);
procedure SpeedButton14Click(Sender: TObject);
procedure Edit1Exit(Sender: TObject);
procedure Edit2Change(Sender: TObject);
private
{ Private-Deklarationen }
CalcThreadStats: TCalcThreadStats;
bFirstRender: LongBool;
MStartPos: TPoint;
S1leftStart: Integer;
FirstShow: LongBool;
iTotalBMPsToRender: Integer;
RenderedSoFar: Integer;
PrevRenderNr: Integer;
RenderStartTime, RenderTime: TDateTime;
siLight5: array of TsiLight5;
siLwid, siLhei: Integer;
aFSIstart: Integer;
aFSIoffset: Integer;
bUserChange: LongBool;
bLoopAni: LongBool;
iActiveThreads: Integer;
AniOutFileName: String;
procedure IncKFabove(nr: Integer);
function LUTpos(nr: Integer): Integer;
procedure calcTimeForPreviewRender;
procedure IncSubFrame;
procedure SetScrollButton;
procedure StartCalc;
procedure ShowProjectName;
procedure EndRendering;
protected
procedure WmThreadReady(var Msg: TMessage); message WM_ThreadReady;
public
{ Public-Deklarationen }
KFposLUT: array of Integer;
KeyFrames: array of TKeyFrame;
isCalculating: LongBool;
AniWidth: Integer;
AniHeight: Integer;
AniScale: Integer;
AniCalc3D: LongBool;
bCalcStop: LongBool;
AniStereoMode: LongBool;
AniRightImage: LongBool;
ActualKeyFrame: Integer;
ActualKFsubframe: Integer;
HeaderCount: Integer;
CurrentNr: Integer;
AniFileIndex: Integer;
AniOption: Integer;
AniIpolType: Integer;
AniOutputFormat: Integer;
AniOutputFolder: String;
AniProjectName: String;
AniOutFile: TFileStream;
HybridCustoms: array[0..5] of TCustomFormula;
procedure IniKFHeader(nr: Integer);
procedure RenderPrevBMP(nr: Integer);
procedure DisableButtons;
procedure EnableButtons;
procedure NextSubFrame;
function LoadAni(FileName: String): Boolean;
procedure WndProc(var Message: TMessage); override;
function TotalBMPsToRender(StartKF, stopKF, Step: Integer): Integer;
procedure InsertFromHeader(Header: TPMandHeader10);
procedure InsertAniWidHei(Header: TPMandHeader10);
function SubFramesToKF(KFnr: Integer): Integer;
function OccupyDFile(Fname: String): LongBool;
procedure CloseOutPutStream;
end;
var
AnimationForm: TAnimationForm;
AFormCreated: LongBool = False;
AniStartLoad: LongBool = False;
implementation
uses Math, DivUtils, AniPreviewWindow, Calc, ImageProcess, AniProcess, CalcSR,
CustomFormulas, DOF, Paint, CalcHardShadow, Interpolation, PaintThread,
Navigator, Maps, MapSequences;
{$R *.dfm}
procedure TAnimationForm.WmThreadReady(var Msg: TMessage);
begin
Dec(iActiveThreads);
if iActiveThreads = 0 then Timer3.Interval := 5; //Timer3Timer(Self); //only for previewBMP
end;
procedure TAnimationForm.StartCalc; //only for preview bmp, the animation uses the main calculation process
begin
CalcVolLightMap(@InterpolHeader, @InterpolLightVals);
siLwid := InterpolHeader.Width;
siLhei := InterpolHeader.Height;
SetLength(siLight5, siLwid * siLhei);
CalcThreadStats.pLBcalcStop := @bCalcStop;
CalcThreadStats.pMessageHwnd := Self.Handle;
CalcThreadStats.iProcessingType := 1;
CalcThreadStats.iAllProcessingOptions := AllAutoProcessings(@InterpolHeader);
if CalcMandT(@InterpolHeader, @InterpolLightVals, @CalcThreadStats,
@siLight5[0], InterpolHeader.Width * 18, aFSIstart, aFSIoffset, Rect(0, 0, InterpolHeader.Width - 1, InterpolHeader.Height - 1)) then
begin
iActiveThreads := CalcThreadStats.iTotalThreadCount;
Timer3.Enabled := True;
end;
end;
function TAnimationForm.OccupyDFile(Fname: String): LongBool;
begin //Try to open OutFile in write access mode
Result := False;
CloseOutPutStream;
AniOutFileName := '';
if Fname = '' then Exit;
try
AniOutFile := TFileStream.Create(Fname, fmCreate or fmShareExclusive);
Result := True;
except
Result := False;
end;
if not Result then FreeAndNil(AniOutFile) else AniOutFileName := Fname;
end;
procedure TAnimationForm.CloseOutPutStream;
begin
if not Assigned(AniOutFile) then Exit;
FreeAndNil(AniOutFile);
if (AniOutFileName <> '') and not FileIsBigger1(AniOutFileName) then
DeleteFile(AniOutFileName);
AniOutFileName := '';
end;
procedure TAnimationForm.SetScrollButton;
begin
if HeaderCount > 1 then
Shape1.Left := Min(Panel3.Width - Shape1.Width,
Max(0, Round((CurrentNr - 0.5) * (Panel3.Width - Shape1.Width) /
HeaderCount) - (Shape1.Width shr 1)));
end;
procedure TAnimationForm.WndProc(var Message: TMessage);
var xDif, yDif: Integer;
begin
if Message.Msg = WM_Move then
begin
yDif := Abs(Top - Mand3DForm.Top - Mand3DForm.Height);
if yDif < 17 then
begin
xDif := Abs(Left - Mand3DForm.Left);
if xDif < 17 then Mand3DForm.bAniFormStick := 1;
end
else Mand3DForm.bAniFormStick := 0;
end;
inherited WndProc(Message);
end;
function TAnimationForm.TotalBMPsToRender(StartKF, StopKF, Step: Integer): Integer;
var i, sf, t, ie: Integer;
begin
bLoopAni := CheckBox2.Checked;
Result := 0;
sf := 0;
if bLoopAni then ie := StopKF - 1 else ie := StopKF - 2;
i := StartKF - 1;
while i <= ie do
begin
t := (KeyFrames[KFposLUT[i]].KFcount - sf) div Step;
Inc(Result, t);
sf := sf + t * Step - KeyFrames[KFposLUT[i]].KFcount;
Inc(i);
end;
if (not bLoopAni) and (sf = 0) and (KeyFrames[KFposLUT[StopKF - 1]].KFcount > 0) then Inc(Result);
end;
procedure TAnimationForm.calcTimeForPreviewRender;
var i, startKF, stopKF, t, ie: Integer;
d, ds: Double;
begin
if HeaderCount > 0 then
begin
bLoopAni := CheckBox2.Checked;
Val(Trim(Edit9.Text), startKF, i);
if i <> 0 then Edit9.Font.Color := clMaroon else Edit9.Font.Color := clWindowText;
if startKF < 1 then startKF := 1;
Val(Trim(Edit10.Text), stopKF, i);
if i <> 0 then stopKF := HeaderCount;
if (stopKF < 1) or (stopKF > HeaderCount) then stopKF := HeaderCount;
d := 0;
t := 0; //downscale
ds := Sqr(AniWidth / Max(1, KeyFrames[KFposLUT[0]].prevBMP.Width * UpDown2.Position)) //fp error
/ (UpDown1.Position * (1.2 - Sqr(UpDown2.Position - 3) * 0.012));
if bLoopAni then ie := stopKF - 1 else ie := stopKF - 2;
for i := startKF - 1 to ie do
begin
d := d + KeyFrames[KFposLUT[i]].KFcount *
((KeyFrames[KFposLUT[i]].KFtime + KeyFrames[KFposLUT[(i + 1) mod HeaderCount]].KFtime) * ds * 0.5
+ 0.08 / UpDown1.Position);
t := t + KeyFrames[KFposLUT[i]].KFcount; //every Nth frame
end;
if d >= 86400000 then
Label14.Caption := '+d ' + FormatDateTime('h:nn:ss', d / 86400000)
else
Label14.Caption := FormatDateTime('h:nn:ss', d / 86400000);
d := Round(t * 4.0 * AniWidth * AniHeight /
(UpDown1.Position * Sqr(UpDown2.Position)));
if d * 1.2 > PhysikMemAvail then Label25.Font.Color := clRed else
if d * 1.5 > PhysikMemAvail then Label25.Font.Color := $60C0 else //orange, yellow is too bright
Label25.Font.Color := clBlack;
Label25.Caption := IntToStr(Round(d * 0.954e-6)) + ' MB';
end
else
begin
Label14.Caption := '0:00';
Label25.Caption := ' MB';
end;
end;
procedure TAnimationForm.DisableButtons;
begin
isCalculating := True; //must be set before, because aniform will be repainted on disabling!
SpeedButton1.Enabled := False;
SpeedButton2.Enabled := False;
SpeedButton3.Enabled := False;
SpeedButton4.Enabled := False;
SpeedButton5.Enabled := False;
SpeedButton8.Enabled := False;
SpeedButton9.Enabled := False;
SpeedButton10.Enabled := False;
SpeedButton11.Enabled := False;
SpeedButton12.Enabled := False;
SpeedButton14.Enabled := False;
UpDown3.Enabled := False;
Edit1.Enabled := False;
Button2.Enabled := (Button2.Caption = 'Pause rendering');
Button3.Enabled := False;
Button4.Enabled := False;
if AniOption > 0 then
begin
Mand3dForm.UpDown1.Enabled := False;
Mand3dForm.SpeedButton3.Enabled := False;
Mand3dForm.SpeedButton13.Enabled := False;
Mand3dForm.SpeedButton5.Enabled := False;
Mand3dForm.SpeedButton6.Enabled := False;
end;
AniProcessForm.Visible := False;
end;
procedure TAnimationForm.EnableButtons;
begin
SpeedButton1.Enabled := True;
SpeedButton9.Enabled := True;
SpeedButton10.Enabled := True;
SpeedButton11.Enabled := True;
Edit1.Enabled := True;
Button3.Enabled := True;
Button2.Enabled := HeaderCount > 1;
Button4.Enabled := Button2.Enabled and not AniPreviewForm.Visible;
UpDown3.Enabled := True;
isCalculating := False;
Mand3dForm.UpDown1.Enabled := True;
Mand3dForm.SpeedButton3.Enabled := True;
Mand3dForm.SpeedButton13.Enabled := True;
Mand3dForm.SpeedButton5.Enabled := True;
Mand3dForm.SpeedButton6.Enabled := True;
SetScrollButton;
Invalidate;
end;
procedure TAnimationForm.FormCreate(Sender: TObject);
var i: Integer;
begin
HeaderCount := 0;
AniOption := 0;
CurrentNr := 1;
FirstShow := True;
bUserChange := True;
isCalculating := False;
for i := 0 to 5 do IniCustomF(@HybridCustoms[i]);
end;
procedure TAnimationForm.FormDestroy(Sender: TObject);
var i: Integer;
begin
IniVal[7] := Edit5.Text;
IniVal[9] := IntToStr(RadioGroup2.ItemIndex);
for i := 0 to HeaderCount - 1 do FreeAndNil(KeyFrames[i].PrevBMP);
for i := 0 to 5 do FreeCF(@HybridCustoms[i]);
end;
procedure TAnimationForm.Button1Click(Sender: TObject);
begin
Visible := False;
end;
procedure TAnimationForm.Shape1MouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
if Button = mbLeft then
begin
GetCursorPos(MStartPos);
S1leftStart := Shape1.Left;
end;
end;
procedure TAnimationForm.Shape1MouseMove(Sender: TObject;
Shift: TShiftState; X, Y: Integer);
var MPos: TPoint;
cn: Integer;
begin
if ssLeft in Shift then
begin
GetCursorPos(MPos);
Shape1.Left := Max(0, Min(Panel3.Width - Shape1.Width, S1leftStart + MPos.X - MStartPos.X));
cn := Max(0, Min(HeaderCount, Round(Shape1.Left * HeaderCount /
(Panel3.Width - Shape1.Width)))) + 1;
if cn <> CurrentNr then
begin
CurrentNr := cn;
PaintBox1.Invalidate;
end;
end;
end;
procedure TAnimationForm.IniKFHeader(nr: Integer);
var i: Integer;
begin
with KeyFrames[nr] do
begin
HeaderParas.PCFAddon := @HAddOn;
for i := 0 to 5 do HeaderParas.PHCustomF[i] := @HybridCustoms[i];
InsertAniWidHei(@HeaderParas);
HeaderParas.bHScalculated := 0;
HeaderParas.bStereoMode := 0;//StereoMode;
end;
end;
procedure TAnimationForm.InsertFromHeader(Header: TPMandHeader10);
begin
if CurrentNr = HeaderCount + 1 then
begin
Setlength(KeyFrames, CurrentNr);
Setlength(KFposLUT, CurrentNr);
KeyFrames[HeaderCount].PrevBMP := TBitmap.Create;
KeyFrames[HeaderCount].KFcount := StrToIntTrim(Edit5.Text);
// KeyFrames[HeaderCount].KFsmooth := SpinEdit3.Value;
KFposLUT[HeaderCount] := HeaderCount;
HeaderCount := CurrentNr;
Edit1.Text := Edit5.Text;
end;
IniKFHeader(KFposLUT[CurrentNr - 1]);
AssignHeader(@KeyFrames[KFposLUT[CurrentNr - 1]].HeaderParas, Header);
KeyFrames[KFposLUT[CurrentNr - 1]].HeaderParas.bCalc3D := Byte(RadioGroup1.ItemIndex = 0);
if CurrentNr = 1 then
begin
AniScale := Max(1, Header.bImageScale);
AniWidth := Header.Width div AniScale;
AniHeight := Header.Height div AniScale;
Edit6.Text := IntToStr(AniWidth);
Edit7.Text := IntToStr(AniHeight);
UpDown3.Position := AniScale;
end;
RenderPrevBMP(KFposLUT[CurrentNr - 1]);
if CheckBox1.Checked then Inc(CurrentNr);
end;
procedure TAnimationForm.SpeedButton1Click(Sender: TObject); // insert paras to this KF
begin
Mand3DForm.MakeHeader;
InsertFromHeader(@Mand3DForm.MHeader);
end;
procedure TAnimationForm.SpeedButton4Click(Sender: TObject); //insert KF in between
begin
Inc(HeaderCount);
Setlength(KeyFrames, HeaderCount);
Setlength(KFposLUT, HeaderCount);
IncKFabove(CurrentNr + 1);
KeyFrames[HeaderCount - 1].PrevBMP := TBitmap.Create;
KeyFrames[HeaderCount - 1].KFcount := StrToIntTry(Edit5.Text, 50);
// KeyFrames[HeaderCount - 1].KFsmooth := SpinEdit3.Value;
KFposLUT[CurrentNr] := HeaderCount - 1;
Mand3DForm.MakeHeader;
IniKFHeader(HeaderCount - 1);
AssignHeader(@KeyFrames[HeaderCount - 1].HeaderParas, @Mand3DForm.MHeader);
KeyFrames[HeaderCount - 1].HeaderParas.bCalc3D := Byte(RadioGroup1.ItemIndex = 0);
RenderPrevBMP(HeaderCount - 1);
Inc(CurrentNr);
end;
procedure TAnimationForm.IncKFabove(nr: Integer);
var i: Integer;
begin
for i := HeaderCount - 1 downto nr do KFposLUT[i] := KFposLUT[i - 1];
end;
procedure TAnimationForm.ShowProjectName;
begin
Caption := 'Animation maker (' + AniProjectName + ')';
// Edit11.Text := AniProjectName;
end;
procedure TAnimationForm.FormShow(Sender: TObject);
var c: Integer;
begin
if FirstShow then
begin
FirstShow := False;
Edit21.Hint := '1: none' + #13#10 + '2: 2x2' + #13#10 + '3: 3x3';
SetDialogDirectory(SaveDialog1, IniDirs[4]);
SetDialogDirectory(OpenDialog4, IniDirs[4]);
if not AniStartLoad then
begin
RadioGroup2.ItemIndex := Min(2, StrToIntTry(IniVal[9], 1));
AniOutputFolder := IniDirs[5];
Edit2.Text := AniOutputFolder;
AniProjectName := 'new';
ShowProjectName;
end;
AniStartLoad := False;
c := ColorToRGB(clBtnFace);
if (c and $FF00) > $80 then c := $F04000 else c := $FFA040;
Label29.Font.Color := c;
end;
Edit5.Text := IniVal[7];
AFormCreated := True;
end;
procedure TAnimationForm.Edit1Change(Sender: TObject);
var i, c: Integer;
begin
if bUserChange and (CurrentNr <= HeaderCount) then
begin
Val(Trim(Edit1.Text), i, c);
if c = 0 then
begin
KeyFrames[KFposLUT[CurrentNr - 1]].KFcount := i;
calcTimeForPreviewRender;
end;
end;
end;
procedure TAnimationForm.Edit1Exit(Sender: TObject);
begin
if CurrentNr < HeaderCount then
RenderPrevBMP(KFposLUT[CurrentNr]);
end;
procedure TAnimationForm.Edit2Change(Sender: TObject);
begin
AniOutputFolder := Edit2.Text;
end;
procedure TAnimationForm.Button3Click(Sender: TObject);
begin
AniOutputFolder := GetDirectory(IniDirs[5], AnimationForm);
Edit2.Text := AniOutputFolder;
end;
function TAnimationForm.LoadAni(FileName: String): Boolean; //Load Ani file
var i, n, y, x, HC, v: Integer;
f: file;
buf: array of Cardinal;
pc: PCardinal;
s: ShortString;
tHeader: TMandHeader9;
begin
Result := False;
if FileExists(FileName) and not isCalculating then
begin
AssignFile(f, FileName);
try
Reset(f, 1);
for i := 0 to HeaderCount - 1 do FreeAndNil(KeyFrames[i].PrevBMP);
HeaderCount := 0;
CurrentNr := 1;
BlockRead(f, v, 4); //version
if v > 5 then
begin
ShowMessage('The file version is to high, use a more actual program version');
Exit;
end;
BlockRead(f, AniWidth, 4);
BlockRead(f, AniHeight, 4);
BlockRead(f, AniScale, 4);
BlockRead(f, AniCalc3D, 4); //obs?
BlockRead(f, s[0], 256);
AniOutputFolder := s;
CheckBox2.Checked := False;
CheckBox4.Checked := False; //Stereo
CheckBox5.Checked := False; //only left-eye
CheckBox6.Checked := True; //overwrite existing images
CheckBox7.Checked := False; //save z-buffer
RadioGroup3.ItemIndex := 0;
if v > 1 then
begin
BlockRead(f, i, 4);
if v = 5 then
begin
RadioGroup2.ItemIndex := (i and 3);
CheckBox2.Checked := (i and 4) <> 0; // loop ani
RadioGroup3.ItemIndex := (i shr 3) and 7;
CheckBox4.Checked := (i and 64) <> 0;
CheckBox5.Checked := (i and 128) <> 0;
CheckBox6.Checked := (i and 256) = 0;
CheckBox7.Checked := (i and 512) <> 0;
end
else
begin
if v < 3 then RadioGroup2.ItemIndex := 1
else RadioGroup2.ItemIndex := Min(1, (i and 3) div 2);
end;
end;
BlockRead(f, HC, 4); //HeaderCount
if (HC < 1) or (HC > 4095) then Exit;
SetLength(KeyFrames, HC);
Setlength(KFposLUT, HC);
for i := 0 to HC - 1 do
begin
KFposLUT[i] := i;
BlockRead(f, KeyFrames[i].KFcount, 4);
BlockRead(f, KeyFrames[i].KFtime, 4);
BlockRead(f, KeyFrames[i].KFsmooth, 4);
if v < 3 then KeyFrames[i].KFsmooth := RadioGroup2.ItemIndex;
if v < 5 then BlockRead(f, tHeader, SizeOf(TMandHeader9))
else BlockRead(f, KeyFrames[i].HeaderParas, SizeOf(TMandHeader10));
if v < 5 then
begin
tHeader.PCFAddon := @KeyFrames[i].HAddOn;
for y := 0 to 5 do tHeader.PHCustomF[y] := @HybridCustoms[y];
if not ConvertHeaderFromOldParas(TMandHeader8(tHeader), True) then Exit;
FastMove(tHeader, KeyFrames[i].HeaderParas, SizeOf(TMandHeader9) - SizeOf(TLightingParas8));
ConvertLight8to9(tHeader.Light, KeyFrames[i].HeaderParas.Light);
end;
IniKFHeader(i);
if v > 3 then LoadHAddon(f, @KeyFrames[i].HAddon);
if KeyFrames[i].HeaderParas.MandId < 20 then
begin
UpdateFormulaOptionTo20(PTHeaderCustomAddon(KeyFrames[i].HeaderParas.PCFAddon));
end
else if (i = 0) then LoadBackgroundPicT(@KeyFrames[i].HeaderParas.Light);
UpdateFormulaOptionAbove20(KeyFrames[i].HeaderParas);
UpdateLightParasAbove3(KeyFrames[i].HeaderParas.Light);
// IniKFHeader(i);
IniCFsFromHAddon(@KeyFrames[i].HAddon, KeyFrames[i].HeaderParas.PHCustomF);
// do it just before interpolating,or in interpolatefunc, no customF's here!
end;
for i := 0 to HC - 1 do
begin
KeyFrames[i].PrevBMP := TBitmap.Create;
HeaderCount := i + 1;
KeyFrames[i].PrevBMP.PixelFormat := pf32bit;
BlockRead(f, n, 4);
// KeyFrames[i].PrevBMP.Width := n;
SetLength(buf, n);
BlockRead(f, y, 4);
KeyFrames[i].PrevBMP.SetSize(n, y);
while y > 0 do
begin
Dec(y);
pc := KeyFrames[KFposLUT[i]].PrevBMP.ScanLine[y];
BlockRead(f, buf[0], 4 * n);
for x := 0 to n - 1 do
begin
pc^ := buf[x];
Inc(pc);
end;
end;
end;
Result := True;
AniProjectName := ChangeFileExtSave(ExtractFileName(FileName), '');
ShowProjectName;
finally
CloseFile(f);
Edit6.Text := IntToStr(AniWidth);
Edit7.Text := IntToStr(AniHeight);
Edit2.Text := AniOutputFolder;
UpDown3.Position := AniScale;
PaintBox1.Invalidate;
Mand3DForm.EnableButtons;
calcTimeForPreviewRender;
end;
SetDialogName(SaveDialog1, OpenDialog4.FileName);
end;
end;
procedure TAnimationForm.SpeedButton11Click(Sender: TObject); //Load Ani file
begin
if OpenDialog4.Execute then LoadAni(OpenDialog4.FileName);
end;
procedure TAnimationForm.RenderPrevBMP(nr: Integer);
var d: Double;
w, h: Integer;
begin
TMapSequenceFrameNumberHolder.SetCurrFrameNumber(TotalBMPsToRender(1, nr + 1, 1));
if AniWidth >= AniHeight * 1.25 then d := 100 / AniWidth
else d := 80 / AniHeight;
w := Round(AniWidth * d);
h := Max(2, Round(AniHeight * d));
KeyFrames[nr].PrevBMP.PixelFormat := pf32Bit;
KeyFrames[nr].PrevBMP.Width := w;
KeyFrames[nr].PrevBMP.Height := h;
KeyFrames[nr].HeaderParas.bCalc3D := Byte(RadioGroup1.ItemIndex = 0);
aFSIstart := Integer(KeyFrames[nr].PrevBMP.Scanline[0]);
aFSIoffset := Integer(KeyFrames[nr].PrevBMP.Scanline[1]) - aFSIstart;
PrevRenderNr := nr;
IniInterpolHeader;
AssignHeader(@InterpolHeader, @KeyFrames[nr].HeaderParas);
IniCFsFromHAddon(@InterpolHAddon, InterpolHeader.PHCustomF);
d := w / AniWidth;
InterpolHeader.Width := w;
InterpolHeader.Height := h;
InterpolHeader.sDEstop := InterpolHeader.sDEstop * d;
InterpolHeader.sDOFclipR := InterpolHeader.sDOFclipR * d;
InterpolHeader.bSliceCalc := 2;
InterpolHeader.bHScalculated := 0;
MakeLightValsFromHeaderLight(@InterpolHeader, @InterpolLightVals, 1, 0);
AniOption := 1;
bCalcStop := False;
Mand3DForm.DisableButtons;
StartCalc;
end;
procedure TAnimationForm.SpeedButton7Click(Sender: TObject); //scoll left by 1
begin
if CurrentNr > 1 then
begin
Dec(CurrentNr);
SetScrollButton;
PaintBox1.Invalidate;
end;
end;
procedure TAnimationForm.SpeedButton6Click(Sender: TObject);
begin
if CurrentNr <= HeaderCount then
begin
Inc(CurrentNr);
SetScrollButton;
PaintBox1.Invalidate;
end;
end;
function TAnimationForm.LUTpos(nr: Integer): Integer;
var i: Integer;
begin
i := 0;
while (i < HeaderCount) do
begin
if KFposLUT[i] = nr then Break;
Inc(i);
end;
Result := Min(i, HeaderCount - 1);
end;
procedure TAnimationForm.SpeedButton5Click(Sender: TObject); //delete KF
var i, i2: Integer;
begin
if CurrentNr <= HeaderCount then
begin
i := KFposLUT[CurrentNr - 1]; //Frame to delete
if i < HeaderCount - 1 then
begin //copy last frame to actpos and delete last frame
KFposLUT[LUTpos(HeaderCount - 1)] := i;
KeyFrames[i].PrevBMP.Assign(KeyFrames[HeaderCount - 1].PrevBMP);
KeyFrames[i].KFcount := KeyFrames[HeaderCount - 1].KFcount;
KeyFrames[i].KFtime := KeyFrames[HeaderCount - 1].KFtime;
KeyFrames[i].KFsmooth := KeyFrames[HeaderCount - 1].KFsmooth;
AssignHeader(@KeyFrames[i].HeaderParas, @KeyFrames[HeaderCount - 1].HeaderParas);
end;
for i2 := CurrentNr - 1 to HeaderCount - 2 do
KFposLUT[i2] := KFposLUT[i2 + 1];
Dec(HeaderCount);
KeyFrames[HeaderCount].PrevBMP.Free;
PaintBox1.Invalidate;
if HeaderCount < 2 then
begin
Button2.Enabled := False;
Button4.Enabled := False;
end;
calcTimeForPreviewRender;
SetScrollButton;
end;
end;
procedure TAnimationForm.SpeedButton2Click(Sender: TObject); //change with prev frame
var i1, i2: Integer;
begin
i1 := KFposLUT[CurrentNr - 1];
i2 := KFposLUT[CurrentNr - 2];
KFposLUT[CurrentNr - 1] := i2;
KFposLUT[CurrentNr - 2] := i1;
PaintBox1.Invalidate;
end;
procedure TAnimationForm.SpeedButton3Click(Sender: TObject); //change with next frame
var i1, i2: Integer;
begin
i1 := KFposLUT[CurrentNr - 1];
i2 := KFposLUT[CurrentNr];
KFposLUT[CurrentNr - 1] := i2;
KFposLUT[CurrentNr] := i1;
PaintBox1.Invalidate;
end;
procedure TAnimationForm.SpeedButton8Click(Sender: TObject); //copy Paras from KF to Mand3D
begin
AssignHeader(@Mand3DForm.MHeader, @KeyFrames[KFposLUT[CurrentNr - 1]].HeaderParas);
IniCFsFromHAddon(Mand3DForm.MHeader.PCFAddon, Mand3DForm.MHeader.PHCustomF);
Mand3DForm.MHeader.Width := AniWidth * AniScale;
Mand3DForm.MHeader.Height := AniHeight * AniScale;
Mand3DForm.MHeader.bImageScale := AniScale;
Mand3DForm.MHeader.bStereoMode := 0;
Mand3DForm.Authors[0] := '?';
Mand3DForm.Authors[1] := '';
Mand3DForm.SetEditsFromHeader;
LightAdjustForm.SetLightFromHeader(Mand3DForm.MHeader);
Mand3DForm.Caption := 'Keyframe #' + IntToStr(CurrentNr);
Mand3DForm.ParasChanged;
SetFocus;
//+paint2D?
end;
function TAnimationForm.SubFramesToKF(KFnr: Integer): Integer;
var i: Integer;
begin
Result := 0;
for i := 0 to Min(HeaderCount, KFnr) - 1 do
Result := Result + KeyFrames[KFposLUT[i]].KFcount;
end;
procedure TAnimationForm.PaintBox1Paint(Sender: TObject);
var i, i2, i3, i4: Integer;
begin
if CurrentNr <= HeaderCount + 1 then
begin
if CurrentNr > 2 then
begin
Label1.Caption := IntToStr(CurrentNr - 2);
Label23.Caption := IntToStr(KeyFrames[KFposLUT[CurrentNr - 3]].KFcount);
end else begin
Label1.Caption := '';
Label23.Caption := '';
end;
if CurrentNr > 1 then
begin
Label2.Caption := IntToStr(CurrentNr - 1);
Label26.Caption := IntToStr(KeyFrames[KFposLUT[CurrentNr - 2]].KFcount);
end else begin
Label2.Caption := '';
Label26.Caption := '';
end;
Label3.Caption := IntToStr(CurrentNr);
Label29.Caption := IntToStr(SubFramesToKF(CurrentNr));
if CurrentNr < HeaderCount then
begin
Label4.Caption := IntToStr(CurrentNr + 1);
Label27.Caption := IntToStr(KeyFrames[KFposLUT[CurrentNr]].KFcount);
end else begin
Label4.Caption := '';
Label27.Caption := '';
end;
if CurrentNr < HeaderCount - 1 then
begin
Label5.Caption := IntToStr(CurrentNr + 2);
Label28.Caption := IntToStr(KeyFrames[KFposLUT[CurrentNr + 1]].KFcount);
end else begin
Label5.Caption := '';
Label28.Caption := '';
end;
Edit1.Visible := HeaderCount >= CurrentNr;
if Edit1.Visible then
begin
bUserChange := False;
Edit1.Text := IntToStr(KeyFrames[KFposLUT[CurrentNr - 1]].KFcount);
bUserChange := True;
end;
if not isCalculating then
begin
SpeedButton2.Enabled := (CurrentNr > 1) and (CurrentNr <= HeaderCount); //exchange KF with prev
SpeedButton3.Enabled := CurrentNr < HeaderCount; //exchange KF with next
SpeedButton4.Enabled := CurrentNr < HeaderCount; //insert Frame between
SpeedButton5.Enabled := CurrentNr <= HeaderCount; //delete KF
SpeedButton8.Enabled := CurrentNr <= HeaderCount; //Copy pars to main
SpeedButton14.Enabled := CurrentNr <= HeaderCount;
SpeedButton12.Enabled := CurrentNr < HeaderCount;
end;
if AniProcessForm.Visible then
begin
AniProcessForm.Button2.Enabled := HeaderCount > 0;
AniProcessForm.Button5.Enabled := HeaderCount > 0;
AniProcessForm.Button3.Enabled := CurrentNr <= HeaderCount;
AniProcessForm.Button4.Enabled := CurrentNr <= HeaderCount;
AniProcessForm.Button6.Enabled := CurrentNr <= HeaderCount;
end;
SpeedButton6.Enabled := CurrentNr <= HeaderCount; //scroll by 1 higher
SpeedButton7.Enabled := CurrentNr > 1; //scroll by 1 lower
//draw bmp's
PaintBox1.Canvas.Brush.Color := clBtnFace;
i4 := SpeedButton5.Top + SpeedButton5.Height + 2;
// if HeaderCount > 0 then i4 := i4 + //bmp centering
for i := 0 to 4 do
begin
i2 := i + CurrentNr - 3;
i3 := i * (Label2.Left - Label1.Left) + 14;
if (i2 >= 0) and (i2 < HeaderCount) then
PaintBox1.Canvas.Draw(i3, i4, KeyFrames[KFposLUT[i2]].PrevBMP)
else
PaintBox1.Canvas.FillRect(Rect(i3, i4, i3 + 101, i4 + 80));
end;
end;
end;
procedure TAnimationForm.SpinEdit1Change(Sender: TObject);
begin
calcTimeForPreviewRender;
end;
procedure TAnimationForm.Button2Click(Sender: TObject); // start rendering
begin
if Button2.Caption = 'Pause rendering' then
begin
Button2.Caption := 'Pausing on next frame...';
Button2.Enabled := False;
end
else if Button2.Caption = 'Paused, press to continue' then
begin
Button2.Caption := 'Pause rendering';
end else begin
// DummyFile := '';
AniOption := 3; //for DisableButtons to disable prevButtons etc.
Mand3DForm.DisableButtons;
Button2.Caption := 'Pause rendering';
Button2.Enabled := True;
RenderStartTime := now;
AniFileIndex := StrToIntTrim(Edit3.Text);
TMapSequenceFrameNumberHolder.SetCurrFrameNumber(AniFileIndex);
iTotalBMPsToRender := TotalBMPsToRender(1, HeaderCount, 1);
AniIpolType := RadioGroup2.ItemIndex;
AniOutputFormat := RadioGroup3.ItemIndex;
AniStereoMode := CheckBox4.Checked;
AniScale := UpDown3.Position;
AniRightImage := True;
if AniStereoMode and CheckBox5.Checked then AniRightImage := False;
RenderedSoFar := 0;
ActualKeyFrame := 0;
ActualKFsubframe := 0;
bCalcStop := False;
bFirstRender := True;
isCalculating := True;
// if (not CheckBox6.Checked) and (not AniFileAlreadyExists(DummyFile)) then
// MakeDummyFile(DummyFile);
Timer2.Enabled := True;
end;
end;
{
TFileStream.Create(FileName, fmOpenWrite or fmShareExclusive)