-
Notifications
You must be signed in to change notification settings - Fork 1
/
multimodel.pas
713 lines (640 loc) · 21.4 KB
/
multimodel.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
unit multimodel;
{$mode objfpc}{$H+}
{$define logevents}
interface
uses
Classes, SysUtils, Math,
CastleColors, CastleTriangles, CastleShapes, CastleVectors,
CastleSceneCore, CastleScene, CastleTransform,
CastleViewport, CastleCameras, CastleProjection,
X3DNodes, X3DFields, X3DTIme, X3DLoad, CastleBoxes,
CastleImages, CastleGLImages, CastleDebugTransform,
CastleTextureImages, CastleClassUtils,
CastleLog, CastleTimeUtils, CastleRectangles, CastleRenderOptions,
CastleQuaternions, AniTakeUtils, MiscFunctions;
type
{ TAnimationInfo }
PAnimationInfo = ^TAnimationInfo;
TAnimationInfo = Class(TComponent)
private
AnimNode: TTimeSensorNode;
fAnimName: String;
AnimStart: TFloatTime; // Time the animation starts, may be after AnimLow
AnimStop: TFloatTime; // Time the animation ends, may be before AnimHigh
AnimLow: TFloatTime; // Always Zero
AnimHigh: TFloatTime; // Always CycleInterval
AnimLast: TFloatTime; // Stores time animation paused at
IsPaused: Boolean; // Is animation paused
IsLooped: Boolean;
IsTakeOne: Boolean;
IsUserDefined: Boolean;
IsHidden: Boolean;
fParentAnim: TAnimationInfo;
fIsMapped: Boolean;
procedure ReceivedIsActive(const Event: TX3DEvent; const Value: TX3DField; const Time: TX3DTime);
procedure ReceivedElapsedTime(const Event: TX3DEvent; const Value: TX3DField; const Time: TX3DTime);
public
constructor Create(AOwner: TComponent); override;
constructor Create(AOwner: TComponent; const AName: String; const ASensor: TTimeSensorNode; const AIsLooped: Boolean = True);
constructor Create(AOwner: TComponent; const ATake: TAniTake; const ASensor: TTimeSensorNode; const AParent: TAnimationInfo; const AIsLooped: Boolean = True; const ATakeFPS: Single = 30);
property Sensor: TTimeSensorNode read AnimNode write AnimNode;
property ParentAnim: TAnimationInfo read fParentAnim write fParentAnim;
property IsMapped: Boolean read fIsMapped write fIsMapped;
property AnimName: String read fAnimName write fAnimName;
end;
TAnimationInfoArray = Array of TAnimationInfo;
TSpotArray = Array[0..5] of TSpotLightNode;
{ TCastleModel }
TCastleModel = class(TCastleComponent)
private
fActions: TStringList;
fCurrentAnimation: Integer;
fHasAnimations: Boolean;
fIsLocked: Boolean;
fLockedScale: Single;
fModelName: String;
fSpotNode: TSpotArray;
fRootNode: TX3DRootNode;
fScene: TCastleScene;
fSceneNode: TX3DRootNode;
fTransform: TTransformNode;
fDebug: TDebugTransformBox;
fBaseRotation: TVector3;
fBaseQuaternion: TQuaternion;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
function GetSpatial: TSceneSpatialStructures;
procedure SetSpatial(const Value: TSceneSpatialStructures);
function GetIsLooped: Boolean;
procedure SetIsLooped(const Value: Boolean);
function GetAnimation(I: Cardinal): TAnimationInfo;
property Actions: TStringList read fActions write fActions;
property Animations[I: Cardinal]: TAnimationInfo read GetAnimation;
procedure AddAllAnimations;
property Debug: TDebugTransformBox read fDebug write fDebug;
procedure FreeAllAnimations;
property CurrentAnimation: Integer read fCurrentAnimation write fCurrentAnimation;
property HasAnimations: Boolean read fHasAnimations write fHasAnimations;
property IsLocked: Boolean read fIsLocked write fIsLocked;
property LockedScale: Single read fLockedScale write fLockedScale;
property ModelName: String read fModelName write fModelName;
property BaseRotation: TVector3 read fBaseRotation write fBaseRotation;
property BaseQuaternion: TQuaternion read fBaseQuaternion write fBaseQuaternion;
property RootNode: TX3DRootNode read fRootNode write fRootNode;
property Scene: TCastleScene read fScene write fScene;
property Transform: TTransformNode read fTransform write fTransform;
property Spatial: TSceneSpatialStructures read GetSpatial write SetSpatial default [];
property IsLooped: Boolean read GetIsLooped write SetIsLooped default True;
property SpotNode: TSpotArray read fSpotNode write fSpotNode;
procedure ResetAnimationState(const IgnoreAffectedBy: TTimeSensorNode = nil);
procedure PrepareResources(const Options: TPrepareResourcesOptions;
const ProgressStep: boolean; const Params: TPrepareParams);
procedure Load(const AURL: string; const AOptions: TSceneLoadOptions = []);
procedure FreeScene;
procedure RemoveScene(var AViewport: TCastleViewport);
procedure AddAnimation(const AAction: String; const ASensor: TTimeSensorNode; const AIsLooped: Boolean = True);
function AddAnimation(const ATake: TAniTake; const ASensor: TTimeSensorNode; const AParent: TAnimationInfo; const AIsLooped: Boolean = True; const ATakeFPS: Single = 30): TAnimationInfo;
function CurrentFrame: TFloatTime;
function TotalFrames: TFloatTime;
function IsPaused: Boolean;
procedure Normalize;
procedure GoToFrame(const AFrame: TFloatTime);
procedure Pause;
procedure Resume;
procedure Start;
procedure Stop;
procedure SelectAnimation(const AName: String; const StartPlaying: Boolean = False);
procedure SetAllSpots(const AUseSpots: Boolean);
end;
TCastleModelArray = Array of TCastleModel;
implementation
{ TAnimationInfo }
constructor TAnimationInfo.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
end;
constructor TAnimationInfo.Create(AOwner: TComponent; const AName: String; const ASensor: TTimeSensorNode; const AIsLooped: Boolean = True);
begin
Create(AOwner);
AnimNode := ASensor;
AnimName := AName;
AnimStart := 0;
AnimStop := ASensor.CycleInterval;
AnimLow := 0;
AnimHigh := ASensor.CycleInterval;
AnimLast := 0;
IsLooped := AIsLooped;
IsTakeOne := False;
IsMapped := False;
ParentAnim := Self;
IsUserDefined := False;
IsHidden := False;
IsPaused := False;
AnimNode.EventIsActive.AddNotification(@ReceivedIsActive);
AnimNode.EventElapsedTime.AddNotification(@ReceivedElapsedTime);
end;
constructor TAnimationInfo.Create(AOwner: TComponent; const ATake: TAniTake; const ASensor: TTimeSensorNode; const AParent: TAnimationInfo; const AIsLooped: Boolean = True; const ATakeFPS: Single = 30);
begin
Create(AOwner);
AnimNode := ASensor;
AnimName := ATake.TakeName;
AnimStart := ATake.TakeStart / ATakeFPS;
AnimStop := (ATake.TakeStop + 1) / ATakeFPS;
AnimLow := 0;
AnimHigh := ASensor.CycleInterval;
AnimLast := 0;
IsLooped := AIsLooped;
IsTakeOne := True;
IsMapped := False;
ParentAnim := AParent;
IsUserDefined := True;
IsHidden := False;
IsPaused := True;
WriteLnLog(AnimName + ' - ' + FloatToStr(AnimStart) + ' - ' + FloatToStr(AnimStop));
end;
procedure TAnimationInfo.ReceivedIsActive(const Event: TX3DEvent; const Value: TX3DField; const Time: TX3DTime);
var
Val: Boolean;
begin
Val := (Value as TSFBool).Value;
if not(Val) then
begin
if not IsPaused then
begin
{$ifdef logevents}
WriteLnLog('TAnimationInfo.ReceivedIsActive - ' + BoolToStr(Val) + ' -> Starting : ' + FloatToStr(AnimStart));
{$endif}
AnimNode.Start(False, True, AnimStart);
end
{$ifndef logevents}
;
{$else}
else
WriteLnLog('TAnimationInfo.ReceivedIsActive - ' + BoolToStr(Val) + ' -> Paused');
{$endif}
end;
{$ifdef logevents}
WriteLnLog('TAnimationInfo.ReceivedIsActive - ' + BoolToStr(Val));
{$endif}
end;
procedure TAnimationInfo.ReceivedElapsedTime(const Event: TX3DEvent; const Value: TX3DField; const Time: TX3DTime);
var
Val: Double;
begin
Val := (Value as TSFTime).Value;
if Val >= AnimStop then
begin
AnimNode.Stop;
{$ifdef logevents}
WriteLnLog('TAnimationInfo.ReceivedElapsedTime - ' + FloatToStr(Val) + ' -> Stopping');
{$endif}
end;
end;
{ TCastleModel - Internal Scene Access }
function TCastleModel.GetSpatial: TSceneSpatialStructures;
begin
Result := fScene.Spatial;
end;
procedure TCastleModel.SetSpatial(const Value: TSceneSpatialStructures);
begin
fScene.Spatial := Value;
end;
function TCastleModel.GetAnimation(I: Cardinal): TAnimationInfo;
begin
if(I >= 0) and (I < fActions.Count) then
Result := TAnimationInfo(fActions.Objects[I])
else
raise Exception.Create('Animation index out of bounds');
end;
function TCastleModel.GetIsLooped: Boolean;
var
ANode: TAnimationInfo;
begin
if(fCurrentAnimation >= 0) and (fCurrentAnimation < fActions.Count) then
begin
ANode := TAnimationInfo(fActions.Objects[fCurrentAnimation]);
Result := ANode.IsLooped;
end;
Result := False;
end;
procedure TCastleModel.SetIsLooped(const Value: Boolean);
var
ANode: TAnimationInfo;
begin
if(fCurrentAnimation >= 0) and (fCurrentAnimation < fActions.Count) then
begin
ANode := TAnimationInfo(fActions.Objects[fCurrentAnimation]);
ANode.IsLooped := Value;
end;
end;
procedure TCastleModel.ResetAnimationState(const IgnoreAffectedBy: TTimeSensorNode = nil);
begin
if not(fCurrentAnimation = -1) then
begin
Stop; // Also resets IsPaused
end;
fCurrentAnimation := -1;
fScene.ResetAnimationState(IgnoreAffectedBy);
end;
procedure TCastleModel.PrepareResources(const Options: TPrepareResourcesOptions;
const ProgressStep: boolean; const Params: TPrepareParams);
begin
fScene.PrepareResources(Options, ProgressStep, Params);
end;
procedure TCastleModel.RemoveScene(var AViewport: TCastleViewport);
begin
if not(fScene = nil) then
begin
AViewport.Items.Remove(fScene);
end;
end;
procedure TCastleModel.FreeScene;
begin
if not(fScene = nil) then
begin
if fScene.OwnsRootNode then
FreeAndNil(fScene);
end;
end;
procedure TCastleModel.Load(const AURL: string; const AOptions: TSceneLoadOptions);
begin
if not(fSceneNode = nil) then
FreeAndNil(fSceneNode);
fSceneNode := LoadNode(AURL, True);
if not(fSceneNode = nil) Then
begin
fRootNode := TX3DRootNode.Create;
fTransform := TTransformNode.Create;
fTransform.AddChildren(fSceneNode);
fRootNode.AddChildren(fTransform);
fSpotNode[0] := CreateSpotLight(Vector3(0.0, 1.0, 3.0), Vector3(0.0, 0.0, -1.0));
fRootNode.AddChildren(fSpotNode[0]);
fSpotNode[1] := CreateSpotLight(Vector3(0.0, 1.0, -3.0), Vector3(0.0, 0.0, 1.0));
fRootNode.AddChildren(fSpotNode[1]);
fSpotNode[2] := CreateSpotLight(Vector3(3.0, 1.0, 0.0), Vector3(-1.0, 0.0, 0.0));
fRootNode.AddChildren(fSpotNode[2]);
fSpotNode[3] := CreateSpotLight(Vector3(-3.0, 1.0, 0.0), Vector3(1.0, 0.0, 0.0));
fRootNode.AddChildren(fSpotNode[3]);
fSpotNode[4] := CreateSpotLight(Vector3(0.0, 3.0, 0.0), Vector3(0.0, -1.0, 0.0));
fRootNode.AddChildren(fSpotNode[4]);
fSpotNode[5] := CreateSpotLight(Vector3(0.0, -3.0, 0.0), Vector3(0.0, 1.0, 0.0));
fRootNode.AddChildren(fSpotNode[5]);
fScene := TCastleScene.Create(Self);
fScene.Load(fRootNode, True, AOptions);
fModelName := AURL;
AddAllAnimations;
fDebug := TDebugTransformBox.Create(fScene);
fDebug.Parent := fScene;
fDebug.BoxColor := Vector4(0,0,0, 1);
fDebug.Exists := False;
Normalize;
end;
end;
{ TCastleModel }
procedure TCastleModel.AddAllAnimations;
var
I: Integer;
begin
if(fScene.AnimationsList.Count > 0) then
begin
fScene.ProcessEvents := True;
fHasAnimations := True;
fActions := TStringList.Create;
fActions.Sorted := True;
fActions.Duplicates := dupError;
for I := 0 to fScene.AnimationsList.Count - 1 do
begin
AddAnimation(fScene.AnimationsList[I], fScene.AnimationTimeSensor(fScene.AnimationsList[I]));
end;
end
else
fHasAnimations := False;
end;
procedure TCastleModel.FreeAllAnimations;
var
I: Integer;
obj: TAnimationInfo;
begin
if fHasAnimations then
begin
if(fActions.Count > 0) then
begin
for I := 0 to fActions.Count - 1 do
begin
obj := TAnimationInfo(fActions.Objects[I]);
obj.AnimNode := nil;
obj.fParentAnim := nil;
FreeAndNil(obj);
end;
end;
end;
end;
procedure TCastleModel.AddAnimation(const AAction: String; const ASensor: TTimeSensorNode; const AIsLooped: Boolean = True);
var
ainfo: TAnimationInfo;
begin
ainfo := TAnimationInfo.Create(Self, AAction, ASensor, IsLooped);
fActions.AddObject(AAction, ainfo);
end;
function TCastleModel.AddAnimation(const ATake: TAniTake; const ASensor: TTimeSensorNode; const AParent: TAnimationInfo; const AIsLooped: Boolean = True; const ATakeFPS: Single = 30): TAnimationInfo;
var
ainfo: TAnimationInfo;
begin
if fActions = nil then
begin
fScene.ProcessEvents := True;
fHasAnimations := True;
fActions := TStringList.Create;
fActions.Sorted := True;
fActions.Duplicates := dupError;
end;
ainfo := TAnimationInfo.Create(Self, ATake, ASensor, AParent);
fActions.AddObject(ATake.TakeName, ainfo);
Result := ainfo;
end;
procedure TCastleModel.Normalize;
begin
if not(fScene = nil) then
begin
if not fScene.BoundingBox.IsEmptyOrZero then
begin
if fScene.BoundingBox.MaxSize > 0 then
begin
fScene.Center := Vector3(Min(fScene.BoundingBox.Data[0].X, fScene.BoundingBox.Data[1].X) + (fScene.BoundingBox.SizeX / 2),
Min(fScene.BoundingBox.Data[0].Y, fScene.BoundingBox.Data[1].Y) + (fScene.BoundingBox.SizeY / 2),
Min(fScene.BoundingBox.Data[0].Z, fScene.BoundingBox.Data[1].Z) + (fScene.BoundingBox.SizeZ / 2));
fScene.Scale := Vector3(2 / fScene.BoundingBox.MaxSize,
2 / fScene.BoundingBox.MaxSize,
2 / fScene.BoundingBox.MaxSize);
fScene.Translation := -fScene.Center;
if not(fTransform = nil) then
begin
fTransform.Center := fScene.Center;
end;
end;
end;
end;
end;
constructor TCastleModel.Create(AOwner: TComponent);
var
i: Integer;
begin
inherited;
fActions := nil;
fCurrentAnimation := -1;
fHasAnimations := False;
fIsLocked := False;
fLockedScale := 1.0;
fModelName := EmptyStr;
fBaseRotation := Vector3(0, 0, 0);
fBaseQuaternion := QuatFromAxisAngle(Vector4(0, 1, 0, 0));
fRootNode := nil;
fTransform := nil;
fSceneNode := nil;
fScene := nil;
for i := 0 to High(fSpotNode) do
fSpotNode[i] := nil;
end;
destructor TCastleModel.Destroy;
begin
FreeAllAnimations;
FreeAndNil(fActions);
fDebug.Exists := False;
FreeAndNil(fDebug);
inherited;
end;
procedure TCastleModel.Resume;
var
ANode: TAnimationInfo;
PNode: TAnimationInfo;
begin
if(fCurrentAnimation >= 0) and (fCurrentAnimation < fActions.Count) then
begin
ANode := TAnimationInfo(fActions.Objects[fCurrentAnimation]);
ANode.IsPaused := False;
if ANode.IsTakeOne then
begin
PNode := ANode.ParentAnim;
if not(PNode = nil) then
begin
PNode.IsPaused := False;
PNode.AnimNode.Start(False, True, PNode.AnimLast);
end;
end
else
ANode.AnimNode.Start(False, True, ANode.AnimLast);
end;
end;
procedure TCastleModel.Start;
var
ANode: TAnimationInfo;
PNode: TAnimationInfo;
begin
if(fCurrentAnimation >= 0) and (fCurrentAnimation < fActions.Count) then
begin
ANode := TAnimationInfo(fActions.Objects[fCurrentAnimation]);
ANode.IsPaused := False;
if ANode.IsTakeOne then
begin
PNode := ANode.ParentAnim;
if not(PNode = nil) then
begin
PNode.IsPaused := False;
PNode.AnimLast := PNode.AnimStart;
PNode.AnimNode.FakeTime(PNode.AnimLast, False, True, fScene.NextEventTime);
PNode.AnimNode.Start(False, True, PNode.AnimStart);
end;
end
else
ANode.AnimNode.Start(False, True, ANode.AnimStart);
end;
end;
procedure TCastleModel.Stop;
var
ANode: TAnimationInfo;
PNode: TAnimationInfo;
begin
if(fCurrentAnimation >= 0) and (fCurrentAnimation < fActions.Count) then
begin
WriteLnLog('TCastleModel.Stop - Stopping - ' + IntToStr(fCurrentAnimation));
ANode := TAnimationInfo(fActions.Objects[fCurrentAnimation]);
PNode := ANode.ParentAnim;
if not(PNode = nil) then
begin
PNode.AnimNode.Stop;
PNode.IsPaused := True;
end
else
begin
ANode.AnimNode.Stop;
ANode.IsPaused := True;
end;
end;
end;
procedure TCastleModel.Pause;
var
ANode: TAnimationInfo;
PNode: TAnimationInfo;
begin
if(fCurrentAnimation >= 0) and (fCurrentAnimation < fActions.Count) then
begin
ANode := TAnimationInfo(fActions.Objects[fCurrentAnimation]);
if ANode.IsPaused then
begin
WriteLnLog('TCastleModel.Pause - Resuming - ' + IntToStr(fCurrentAnimation));
Resume;
end
else
begin
if ANode.IsTakeOne then
begin
PNode := ANode.ParentAnim;
if not(PNode = nil) then
begin
PNode.AnimNode.Stop;
PNode.AnimLast := PNode.AnimNode.ElapsedTimeInCycle;
PNode.IsPaused := True;
ANode.AnimLast := PNode.AnimLast;
ANode.IsPaused := True;
end;
end
else
begin
ANode.AnimNode.Stop;
ANode.AnimLast := ANode.AnimNode.ElapsedTimeInCycle;
ANode.IsPaused := True;
end;
end;
end;
end;
procedure TCastleModel.GoToFrame(const AFrame: TFloatTime);
var
ANode: TAnimationInfo;
PNode: TAnimationInfo;
begin
WriteLnLog('TCastleModel.GoToFrame - ' + FloatToStr(AFrame) + ' (' + IntToStr(fCurrentAnimation) + ')');
if(fCurrentAnimation >= 0) and (fCurrentAnimation < fActions.Count) then
begin
ANode := TAnimationInfo(fActions.Objects[fCurrentAnimation]);
if ANode.IsTakeOne then
begin
PNode := ANode.ParentAnim;
if not(PNode = nil) then
begin
PNode.AnimLast := AFrame;
PNode.AnimNode.FakeTime(ANode.AnimLast, False, True, fScene.NextEventTime);
ANode.AnimLast := AFrame;
end;
end
else
begin
ANode.AnimLast := AFrame;
ANode.AnimNode.FakeTime(ANode.AnimLast, False, True, fScene.NextEventTime);
end;
end;
end;
procedure TCastleModel.SelectAnimation(const AName: String; const StartPlaying: Boolean = False);
var
ANode: TAnimationInfo;
PNode: TAnimationInfo;
I: Integer;
PrevAnimWasRunning: Boolean;
PrevAnimWasTPose: Boolean;
begin
PrevAnimWasTPose := False;
PrevAnimWasRunning := False;
if fActions.Find(AName, I) then
begin
if(fCurrentAnimation >= 0) and (fCurrentAnimation < fActions.Count) then
begin
if not(fCurrentAnimation = I) then
begin
ANode := TAnimationInfo(fActions.Objects[fCurrentAnimation]);
if not(ANode.IsPaused) then
begin
Stop;
PrevAnimWasRunning := True;
end;
end;
end
else
PrevAnimWasTPose := True;
WriteLnLog('TCastleModel.SelectAnimation - ' + AName + ' (' + IntToStr(fCurrentAnimation) + ' / ' + IntToStr(I) + ')');
fCurrentAnimation := I;
ANode := TAnimationInfo(fActions.Objects[fCurrentAnimation]);
if ANode.IsTakeOne then
begin
PNode := ANode.ParentAnim;
if not(PNode = nil) then
begin
PNode.AnimStart := ANode.AnimStart;
PNode.AnimStop := ANode.AnimStop;
PNode.AnimLast := PNode.AnimStart;
PNode.IsPaused := True;
ANode.IsPaused := True;
PNode.AnimNode.FakeTime(PNode.AnimLast, False, True, fScene.NextEventTime);
// Start;
end;
end
else
begin
GotoFrame(ANode.AnimStart);
if PrevAnimWasRunning then
Start
else
begin
if PrevAnimWasTPose then
begin
if StartPlaying then
Start
else
ANode.IsPaused := True;
end
else
Stop;
end;
end;
end;
end;
function TCastleModel.CurrentFrame: TFloatTime;
var
ANode: TAnimationInfo;
begin
Result := -1;
if(fCurrentAnimation >= 0) and (fCurrentAnimation < fActions.Count) then
begin
ANode := TAnimationInfo(fActions.Objects[fCurrentAnimation]);
Result := ANode.AnimNode.ElapsedTimeInCycle;
end;
end;
function TCastleModel.TotalFrames: TFloatTime;
var
ANode: TAnimationInfo;
begin
Result := -1;
if(fCurrentAnimation >= 0) and (fCurrentAnimation < fActions.Count) then
begin
ANode := TAnimationInfo(fActions.Objects[fCurrentAnimation]);
Result := ANode.AnimHigh;
end;
end;
function TCastleModel.IsPaused: Boolean;
var
ANode: TAnimationInfo;
begin
Result := False;
if(fCurrentAnimation >= 0) and (fCurrentAnimation < fActions.Count) then
begin
ANode := TAnimationInfo(fActions.Objects[fCurrentAnimation]);
Result := ANode.IsPaused;
end;
end;
procedure TCastleModel.SetAllSpots(const AUseSpots: Boolean);
var
i: Integer;
begin
for i := 0 to High(SpotNode) do
SpotNode[i].IsOn := AUseSpots;
end;
end.