-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcommandsparser.pas
More file actions
5166 lines (4624 loc) · 218 KB
/
commandsparser.pas
File metadata and controls
5166 lines (4624 loc) · 218 KB
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 CommandsParser;
{$mode objfpc}{$H+}
interface
uses
ogf_parser, basedefs, tempbuffer, commandsstorage, SelectionArea, CommandsHelpers;
type
TSlotsContainer = class;
TSlotId = integer;
{ TSlotFilteringCommands }
TModelSlot = class;
TSlotFilteringCommands = class(TFilteringCommands)
_slot:TModelSlot;
public
constructor Create(slot:TModelSlot);
end;
{ TChildrenCommands }
TChildrenCommands = class(TSlotFilteringCommands)
public
constructor Create(slot:TModelSlot);
function GetFilteringItemTypeName(item_id:integer):string; override;
function GetFilteringItemsCount():integer; override;
function CheckFiltersForItem(item_id:integer; filters:TIndexFilters; var filter_passed:boolean):boolean; override;
end;
{ TBonesCommands }
TBonesCommands = class(TSlotFilteringCommands)
public
constructor Create(slot:TModelSlot);
function GetFilteringItemTypeName(item_id:integer):string; override;
function GetFilteringItemsCount():integer; override;
function CheckFiltersForItem(item_id:integer; filters:TIndexFilters; var filter_passed:boolean):boolean; override;
end;
{ TAnimationsCommands }
TAnimationsCommands = class(TSlotFilteringCommands)
public
constructor Create(slot:TModelSlot);
function GetFilteringItemTypeName(item_id:integer):string; override;
function GetFilteringItemsCount():integer; override;
function CheckFiltersForItem(item_id:integer; filters:TIndexFilters; var filter_passed:boolean):boolean; override;
end;
TParsedBonesExpressionMode = (ParsedBoneExpressionModeDefault, ParsedBoneExpressionModeAnd, ParsedBoneExpressionModeOr);
{ TParsedBonesExpression }
TParsedBonesExpression = class
_ids:array of TBoneID;
_inversed: array of boolean;
_mode:TParsedBonesExpressionMode;
public
constructor Create();
destructor Destroy; override;
procedure AddParsed(boneid:TBoneId; is_inversed:boolean);
function ParsedCount():integer;
function GetParsedBoneId(parsedid:integer):TBoneID;
function IsParsedBoneIdInversed(parsedid:integer):boolean;
function GetMode():TParsedBonesExpressionMode;
procedure SetMode(m:TParsedBonesExpressionMode);
function IsLinksMatch(links:TVertexBones):boolean;
function IsBoneIdMatches(boneid:TBoneID):boolean;
function GetBoneIdIndexInParsed(boneid:TBoneID):integer;
end;
{ TModelSlot }
TModelSlot = class
_data:TOgfParser;
_id:TSlotId;
_container:TSlotsContainer;
_selectionarea:TSelectionArea;
_iksolver:TOgfIKSolverBase;
_commands_selection:TCommandsStorage;
_commands_upperlevel:TCommandsStorage;
_commands_mesh:TCommandsStorage;
_commands_children:TChildrenCommands;
_commands_skeleton:TCommandsStorage;
_commands_bones:TBonesCommands;
_commands_animbones:TBonesCommands;
_commands_animations:TAnimationsCommands;
_commands_mmarks:TCommandsStorage;
_commands_iksolver:TCommandsStorage;
function _CmdSetPivot(var args:string; cmd:TCommandSetup; result_description:TCommandResult; userdata:TObject):boolean;
function _CmdSelectionSphere(var args:string; cmd:TCommandSetup; result_description:TCommandResult; userdata:TObject):boolean;
function _CmdSelectionBox(var args:string; cmd:TCommandSetup; result_description:TCommandResult; userdata:TObject):boolean;
function _CmdSelectionClear(var args:string; cmd:TCommandSetup; result_description:TCommandResult; userdata:TObject):boolean;
function _CmdSelectionInfo(var args:string; cmd:TCommandSetup; result_description:TCommandResult; userdata:TObject):boolean;
function _CmdSelectionTestPoint(var args:string; cmd:TCommandSetup; result_description:TCommandResult; userdata:TObject):boolean;
function _CmdSelectionInverse(var args:string; cmd:TCommandSetup; result_description:TCommandResult; userdata:TObject):boolean;
function _CmdSelectionSelectPickVertices(var args:string; cmd:TCommandSetup; result_description:TCommandResult; userdata:TObject):boolean;
function _CmdSelectionSelectPickElement(var args:string; cmd:TCommandSetup; result_description:TCommandResult; userdata:TObject):boolean;
function _IsModelLoadedPrecondition(args:string; cmd:TCommandSetup; result_description:TCommandResult; userdata:TObject):boolean;
function _IsModelNotLoadedPrecondition(args:string; cmd:TCommandSetup; result_description:TCommandResult; userdata:TObject):boolean;
function _IsModelHasSkeletonPrecondition(args:string; cmd:TCommandSetup; result_description:TCommandResult; userdata:TObject):boolean;
function _IsAnimationsLoadedPrecondition(args:string; cmd:TCommandSetup; result_description:TCommandResult; userdata:TObject):boolean;
function ExtractBoneIdFromString(var inoutstr:string; var boneid:TBoneId):boolean;
function ExtractMultipleBoneIdsFromString(var inoutstr:string; out_data:TParsedBonesExpression):boolean;
function GetBoneNameById(boneid: TBoneId): string;
function CheckAndCorrectFrameId(var frameid:integer; anim_name:string):boolean;
function ReplaceWildcards(s:string; arg:TCommandIndexArg):string;
function _CmdLoadFromFile(var args:string; cmd:TCommandSetup; result_description:TCommandResult; userdata:TObject):boolean;
function _CmdLoadAnimsFromFile(var args:string; cmd:TCommandSetup; result_description:TCommandResult; userdata:TObject):boolean;
function _CmdSaveToFile(var args:string; cmd:TCommandSetup; result_description:TCommandResult; userdata:TObject):boolean;
function _CmdSaveAnimsToFile(var args:string; cmd:TCommandSetup; result_description:TCommandResult; userdata:TObject):boolean;
function _CmdMergeAnimsWithFile(var args:string; cmd:TCommandSetup; result_description:TCommandResult; userdata:TObject):boolean;
function _CmdUnload(var args:string; cmd:TCommandSetup; result_description:TCommandResult; userdata:TObject):boolean;
function _CmdInfo(var args:string; cmd:TCommandSetup; result_description:TCommandResult; userdata:TObject):boolean;
function _CmdClipboardMode(var args:string; cmd:TCommandSetup; result_description:TCommandResult; userdata:TObject):boolean;
function _CmdMeshInfo(var args:string; cmd:TCommandSetup; result_description:TCommandResult; userdata:TObject):boolean;
function _CmdPasteMeshFromTempBuf(var args:string; cmd:TCommandSetup; result_description:TCommandResult; userdata:TObject):boolean;
function _CmdRemoveCollapsedMeshes(var args:string; cmd:TCommandSetup; result_description:TCommandResult; userdata:TObject):boolean;
function _CmdAddMotionRef(var args:string; cmd:TCommandSetup; result_description:TCommandResult; userdata:TObject):boolean;
function _CmdResetMotionRefs(var args:string; cmd:TCommandSetup; result_description:TCommandResult; userdata:TObject):boolean;
function _CmdCalcMeshBounds(var args:string; cmd:TCommandSetup; result_description:TCommandResult; userdata:TObject):boolean;
function _CmdCopyMeshBounds(var args:string; cmd:TCommandSetup; result_description:TCommandResult; userdata:TObject):boolean;
function _CmdPasteMeshBounds(var args:string; cmd:TCommandSetup; result_description:TCommandResult; userdata:TObject):boolean;
function _CmdChildInfo(var args:string; cmd:TCommandSetup; result_description:TCommandResult; userdata:TObject):boolean;
function _CmdChildSetTexture(var args:string; cmd:TCommandSetup; result_description:TCommandResult; userdata:TObject):boolean;
function _CmdChildSetShader(var args:string; cmd:TCommandSetup; result_description:TCommandResult; userdata:TObject):boolean;
function _CmdChildRemove(var args:string; cmd:TCommandSetup; result_description:TCommandResult; userdata:TObject):boolean;
function _CmdChildCopy(var args:string; cmd:TCommandSetup; result_description:TCommandResult; userdata:TObject):boolean;
function _CmdChildPasteData(var args:string; cmd:TCommandSetup; result_description:TCommandResult; userdata:TObject):boolean;
function _CmdChildMoveAll(var args:string; cmd:TCommandSetup; result_description:TCommandResult; userdata:TObject):boolean;
function _CmdChildRotateAll(var args:string; cmd:TCommandSetup; result_description:TCommandResult; userdata:TObject):boolean;
function _CmdChildScaleAll(var args:string; cmd:TCommandSetup; result_description:TCommandResult; userdata:TObject):boolean;
function _CmdChildMoveSelected(var args:string; cmd:TCommandSetup; result_description:TCommandResult; userdata:TObject):boolean;
function _CmdChildRotateSelected(var args:string; cmd:TCommandSetup; result_description:TCommandResult; userdata:TObject):boolean;
function _CmdChildScaleSelected(var args:string; cmd:TCommandSetup; result_description:TCommandResult; userdata:TObject):boolean;
function _CmdChildRebindAll(var args:string; cmd:TCommandSetup; result_description:TCommandResult; userdata:TObject):boolean;
function _CmdChildRebindSelected(var args:string; cmd:TCommandSetup; result_description:TCommandResult; userdata:TObject):boolean;
function _CmdChildBonestats(var args:string; cmd:TCommandSetup; result_description:TCommandResult; userdata:TObject):boolean;
function _CmdChildFilterBone(var args:string; cmd:TCommandSetup; result_description:TCommandResult; userdata:TObject):boolean;
function _cmdChildSaveToFile(var args:string; cmd:TCommandSetup; result_description:TCommandResult; userdata:TObject):boolean;
function _cmdChildLodLevelSelect(var args:string; cmd:TCommandSetup; result_description:TCommandResult; userdata:TObject):boolean;
function _cmdChildLodLevelsRemove(var args:string; cmd:TCommandSetup; result_description:TCommandResult; userdata:TObject):boolean;
function _CmdChildRemoveSelected(var args:string; cmd:TCommandSetup; result_description:TCommandResult; userdata:TObject):boolean;
function _CmdChildSplitSelected(var args:string; cmd:TCommandSetup; result_description:TCommandResult; userdata:TObject):boolean;
function _CmdSkeletonUniformScale(var args:string; cmd:TCommandSetup; result_description:TCommandResult; userdata:TObject):boolean;
function _CmdSkeletonHierarchy(var args:string; cmd:TCommandSetup; result_description:TCommandResult; userdata:TObject):boolean;
function _CmdSkeletonAddBone(var args:string; cmd:TCommandSetup; result_description:TCommandResult; userdata:TObject):boolean;
function _CmdSyncAnimBones(var args:string; cmd:TCommandSetup; result_description:TCommandResult; userdata:TObject):boolean;
function _CmdBoneInfo(var args:string; cmd:TCommandSetup; result_description:TCommandResult; userdata:TObject):boolean;
function _CmdBoneReparent(var args:string; cmd:TCommandSetup; result_description:TCommandResult; userdata:TObject):boolean;
function _CmdBoneRename(var args:string; cmd:TCommandSetup; result_description:TCommandResult; userdata:TObject):boolean;
function _CmdBoneSetBindTransform(var args:string; cmd:TCommandSetup; result_description:TCommandResult; userdata:TObject):boolean;
function _CmdBoneBindPoseMove(var args:string; cmd:TCommandSetup; result_description:TCommandResult; userdata:TObject):boolean;
function _CmdBoneBindPoseRotateAroundSelf(var args:string; cmd:TCommandSetup; result_description:TCommandResult; userdata:TObject):boolean;
function _CmdBoneCopySettings(var args:string; cmd:TCommandSetup; result_description:TCommandResult; userdata:TObject):boolean;
function _CmdBoneApplySettings(var args:string; cmd:TCommandSetup; result_description:TCommandResult; userdata:TObject):boolean;
function _CmdBoneGenerateShape(var args:string; cmd:TCommandSetup; result_description:TCommandResult; userdata:TObject):boolean;
function _CmdBoneSetMaterial(var args:string; cmd:TCommandSetup; result_description:TCommandResult; userdata:TObject):boolean;
function _CmdAnimInfo(var args:string; cmd:TCommandSetup; result_description:TCommandResult; userdata:TObject):boolean;
function _CmdAnimSetAccrue(var args:string; cmd:TCommandSetup; result_description:TCommandResult; userdata:TObject):boolean;
function _CmdAnimSetFalloff(var args:string; cmd:TCommandSetup; result_description:TCommandResult; userdata:TObject):boolean;
function _CmdAnimSetPower(var args:string; cmd:TCommandSetup; result_description:TCommandResult; userdata:TObject):boolean;
function _CmdAnimSetSpeed(var args:string; cmd:TCommandSetup; result_description:TCommandResult; userdata:TObject):boolean;
function _CmdAnimSetFlags(var args:string; cmd:TCommandSetup; result_description:TCommandResult; userdata:TObject):boolean;
function _CmdAnimRemove(var args:string; cmd:TCommandSetup; result_description:TCommandResult; userdata:TObject):boolean;
function _CmdAnimRename(var args:string; cmd:TCommandSetup; result_description:TCommandResult; userdata:TObject):boolean;
function _CmdAnimKeyInfo(var args:string; cmd:TCommandSetup; result_description:TCommandResult; userdata:TObject):boolean;
function _CmdAnimKeyPoseCopy(var args:string; cmd:TCommandSetup; result_description:TCommandResult; userdata:TObject):boolean;
function _CmdAnimBindPoseCopy(var args:string; cmd:TCommandSetup; result_description:TCommandResult; userdata:TObject):boolean;
function _CmdAnimKeyPosePaste(var args:string; cmd:TCommandSetup; result_description:TCommandResult; userdata:TObject):boolean;
function _CmdAnimTrackDuplicate(var args:string; cmd:TCommandSetup; result_description:TCommandResult; userdata:TObject):boolean;
function _CmdAnimTrackCopy(var args:string; cmd:TCommandSetup; result_description:TCommandResult; userdata:TObject):boolean;
function _CmdAnimTrackPaste(var args:string; cmd:TCommandSetup; result_description:TCommandResult; userdata:TObject):boolean;
function _CmdAnimTrackSetLength(var args:string; cmd:TCommandSetup; result_description:TCommandResult; userdata:TObject):boolean;
function _CmdAnimAddMotionMark(var args:string; cmd:TCommandSetup; result_description:TCommandResult; userdata:TObject):boolean;
function _CmdAnimResetMotionMarks(var args:string; cmd:TCommandSetup; result_description:TCommandResult; userdata:TObject):boolean;
function _CmdAnimIkRefPose(var args:string; cmd:TCommandSetup; result_description:TCommandResult; userdata:TObject):boolean;
function _CmdIKSolverReset(var args:string; cmd:TCommandSetup; result_description:TCommandResult; userdata:TObject):boolean;
function _CmdIKSolverSimpleLimb(var args:string; cmd:TCommandSetup; result_description:TCommandResult; userdata:TObject):boolean;
function _CmdAnimBoneMove(var args:string; cmd:TCommandSetup; result_description:TCommandResult; userdata:TObject):boolean;
function _CmdAnimBoneRotate(var args:string; cmd:TCommandSetup; result_description:TCommandResult; userdata:TObject):boolean;
function _CmdAnimBoneInterMove(var args:string; cmd:TCommandSetup; result_description:TCommandResult; userdata:TObject):boolean;
function _CmdAnimBoneInterRotate(var args:string; cmd:TCommandSetup; result_description:TCommandResult; userdata:TObject):boolean;
function _CmdAnimBoneSetOrientation(var args:string; cmd:TCommandSetup; result_description:TCommandResult; userdata:TObject):boolean;
function _CmdAnimBoneSetPosition(var args:string; cmd:TCommandSetup; result_description:TCommandResult; userdata:TObject):boolean;
function _CmdAnimBoneAim(var args:string; cmd:TCommandSetup; result_description:TCommandResult; userdata:TObject):boolean;
function _CmdAnimBoneAimToBone(var args:string; cmd:TCommandSetup; result_description:TCommandResult; userdata:TObject):boolean;
function _CmdAnimBoneFollow(var args:string; cmd:TCommandSetup; result_description:TCommandResult; userdata:TObject):boolean;
function _CmdAnimBoneCopyKeyToKeys(var args:string; cmd:TCommandSetup; result_description:TCommandResult; userdata:TObject):boolean;
function _CmdAnimBoneSlerpKeys(var args:string; cmd:TCommandSetup; result_description:TCommandResult; userdata:TObject):boolean;
function _CmdAnimBoneApplyDiff(var args:string; cmd:TCommandSetup; result_description:TCommandResult; userdata:TObject):boolean;
public
constructor Create(id:TSlotId; container:TSlotsContainer);
destructor Destroy; override;
function SlotId():TSlotId;
function Data():TOgfParser;
function ExecuteCmd(cmd:string):TCommandResult;
end;
{ TSlotsContainer }
TSlotsContainer = class
_model_slots:array of TModelSlot;
_temp_buffer:TTempBuffer;
public
constructor Create();
destructor Destroy(); override;
function GetModelSlotById(id:TSlotId):TModelSlot;
function GetTempBuffer():TTempBuffer;
function TryGetSlotRefByString(in_string:string; var rest_string:string):TModelSlot;
end;
implementation
uses sysutils, strutils, ChunkedFileParser, Math;
const
BUFFER_TYPE_CHILDMESH:integer=100;
BUFFER_TYPE_BONEDATA:integer=101;
BUFFER_TYPE_SKELETONPOSE:integer=102;
BUFFER_TYPE_SKELETONTRACK:integer=103;
BUFFER_TYPE_MODELBLIMITS:integer=104;
{ TParsedBonesExpression }
constructor TParsedBonesExpression.Create();
begin
setlength(_ids, 0);
setlength(_inversed, 0);
_mode:=ParsedBoneExpressionModeDefault;
end;
destructor TParsedBonesExpression.Destroy;
begin
setlength(_ids, 0);
setlength(_inversed, 0);
inherited Destroy;
end;
procedure TParsedBonesExpression.AddParsed(boneid: TBoneId; is_inversed: boolean);
var
i:integer;
begin
i:=length(_ids);
setlength(_ids, i+1);
setlength(_inversed, i+1);
_ids[i]:=boneid;
_inversed[i]:=is_inversed;
end;
function TParsedBonesExpression.ParsedCount(): integer;
begin
result:=length(_ids);
end;
function TParsedBonesExpression.GetParsedBoneId(parsedid: integer): TBoneID;
begin
result:=INVALID_BONE_ID;
if (parsedid>=0) and (parsedid < length(_ids)) then begin
result:=_ids[parsedid];
end;
end;
function TParsedBonesExpression.IsParsedBoneIdInversed(parsedid: integer): boolean;
begin
result:=false;
if (parsedid>=0) and (parsedid < length(_inversed)) then begin
result:=_inversed[parsedid];
end;
end;
function TParsedBonesExpression.GetMode(): TParsedBonesExpressionMode;
begin
result:=_mode;
end;
procedure TParsedBonesExpression.SetMode(m: TParsedBonesExpressionMode);
begin
_mode:=m;
end;
function TParsedBonesExpression.IsLinksMatch(links: TVertexBones): boolean;
var
mode:TParsedBonesExpressionMode;
boneid:TBoneID;
matches_filter:boolean;
i:integer;
begin
mode:=GetMode();
if (mode = ParsedBoneExpressionModeOr) then begin
result:=false;
end else if (mode = ParsedBoneExpressionModeAnd) then begin
result:=true;
end else begin
result:=true;
exit;
end;
for i:=0 to ParsedCount()-1 do begin
boneid:=GetParsedBoneId(i);
if boneid= INVALID_BONE_ID then continue;
matches_filter:=links.GetWeightForBoneId(boneid)>0;
if IsParsedBoneIdInversed(i) then begin
matches_filter:=not matches_filter;
end;
if matches_filter and (mode = ParsedBoneExpressionModeOr) then begin
result:=true;
break;
end else if not matches_filter and (mode = ParsedBoneExpressionModeAnd) then begin
result:=false;
break;
end;
end;
end;
function TParsedBonesExpression.IsBoneIdMatches(boneid: TBoneID): boolean;
var
links:TVertexBones;
bone:TVertexBone;
begin
result:=false;
links:=TVertexBones.Create();
try
bone.bone_id:=boneid;
bone.weight:=1.0;
if links.AddBone(bone, false) then begin
result:=IsLinksMatch(links);
end;
finally
FreeAndNil(links);
end;
end;
function TParsedBonesExpression.GetBoneIdIndexInParsed(boneid: TBoneID): integer;
var
i:integer;
begin
result:=-1;
for i:=0 to length(_ids)-1 do begin
if _ids[i]=boneid then begin
result:=i;
break;
end;
end;
end;
{ TSlotFilteringCommands }
constructor TSlotFilteringCommands.Create(slot: TModelSlot);
begin
inherited Create(true);
_slot:=slot;
end;
{ TChildrenCommands }
constructor TChildrenCommands.Create(slot: TModelSlot);
begin
inherited;
RegisterFilter('texture');
RegisterFilter('shader');
//TODO: Filter by ID - exact and in range
// RegisterFilter('id');
end;
function TChildrenCommands.GetFilteringItemTypeName(item_id: integer): string;
begin
result:='child';
end;
function TChildrenCommands.GetFilteringItemsCount(): integer;
begin
result:=0;
if _slot.Data()<> nil then begin
if _slot.Data().Meshes()<>nil then begin
result:=_slot.Data().Meshes().Count();
end;
end;
end;
function TChildrenCommands.CheckFiltersForItem(item_id: integer; filters:TIndexFilters; var filter_passed:boolean): boolean;
begin
filter_passed:= IsMatchFilter(_slot.Data().Meshes().Get(item_id).GetTextureData().texture, filters[0], FILTER_MODE_EXACT)
and IsMatchFilter(_slot.Data().Meshes().Get(item_id).GetTextureData().shader, filters[1], FILTER_MODE_EXACT);
result:=true;
end;
{ TBonesCommands }
constructor TBonesCommands.Create(slot: TModelSlot);
begin
inherited;
RegisterFilter('name');
RegisterFilter('id');
RegisterFilter('expr');
end;
function TBonesCommands.GetFilteringItemTypeName(item_id: integer): string;
begin
result:='bone';
end;
function TBonesCommands.GetFilteringItemsCount(): integer;
begin
result:=0;
if _slot.Data()<>nil then begin
if _slot.Data().Skeleton()<>nil then begin
result:=_slot.Data().Skeleton().GetBonesCount();
end;
end;
end;
function TBonesCommands.CheckFiltersForItem(item_id: integer; filters:TIndexFilters; var filter_passed:boolean): boolean;
var
parsed_bones:TParsedBonesExpression;
expr:string;
begin
result:=true;
filter_passed:=IsMatchFilter(_slot.Data().Skeleton().GetBoneName(item_id), filters[0], FILTER_MODE_EXACT)
and IsMatchFilter(inttostr(item_id), filters[1], FILTER_MODE_EXACT);
expr:=filters[2].value;
if filter_passed and (length(expr)>0) then begin
parsed_bones:=TParsedBonesExpression.Create();
try
if _slot.ExtractMultipleBoneIdsFromString(expr, parsed_bones) then begin
filter_passed:=parsed_bones.IsBoneIdMatches(item_id);
if filters[2].inverse then begin
filter_passed:=not filter_passed;
end;
end else begin
filter_passed:=false;
result:=false;
end;
finally
FreeAndNil(parsed_bones);
end;
end;
end;
{ TAnimationsCommands }
constructor TAnimationsCommands.Create(slot: TModelSlot);
begin
inherited;
RegisterFilter('name');
end;
function TAnimationsCommands.GetFilteringItemTypeName(item_id: integer): string;
begin
result:='animation';
end;
function TAnimationsCommands.GetFilteringItemsCount(): integer;
begin
result:=0;
if _slot.Data()<>nil then begin
if _slot.Data().Animations()<>nil then begin
result:=_slot.Data().Animations().AnimationsCount();
end;
end;
end;
function TAnimationsCommands.CheckFiltersForItem(item_id: integer; filters: TIndexFilters; var filter_passed:boolean): boolean;
begin
result:=true;
filter_passed:=IsMatchFilter(_slot.Data().Animations().GetAnimationParams(item_id).name, filters[0], FILTER_MODE_EXACT);
end;
{ TModelSlot }
//////////////////////////////////////////////////////// Preconditions ////////////////////////////////////////////////////
function TModelSlot._IsModelLoadedPrecondition(args: string; cmd: TCommandSetup; result_description: TCommandResult; userdata: TObject): boolean;
begin
result:=true;
if not _data.Loaded() then begin
result_description.SetDescription('Slot is empty. Load data first');
result:=false;
end;
end;
function TModelSlot._IsModelNotLoadedPrecondition(args: string; cmd: TCommandSetup; result_description: TCommandResult; userdata: TObject): boolean;
begin
result:=true;
if _data.Loaded() then begin
result_description.SetDescription('Slot is not empty. Unload data first');
result:=false;
end;
end;
function TModelSlot._IsModelHasSkeletonPrecondition(args: string; cmd: TCommandSetup; result_description: TCommandResult; userdata: TObject): boolean;
begin
result:=true;
if not _data.Loaded() then begin
result_description.SetDescription('Slot is empty. Load data first');
result:=false;
end else if _data.Skeleton()=nil then begin
result_description.SetDescription('Loaded model has no skeleton');
result:=false;
end;
end;
function TModelSlot._IsAnimationsLoadedPrecondition(args: string; cmd: TCommandSetup; result_description: TCommandResult; userdata: TObject): boolean;
begin
result:=true;
if not _data.Loaded() then begin
result_description.SetDescription('Slot is empty. Load data first');
result:=false;
end else if _data.Skeleton()=nil then begin
result_description.SetDescription('Loaded model has no skeleton');
result:=false;
end else if _data.Animations()=nil then begin
result_description.SetDescription('No animations loaded');
result:=false;
end;
end;
//////////////////////////////////////////////////////// Helper functions ////////////////////////////////////////////////////
function TModelSlot.ExtractBoneIdFromString(var inoutstr:string; var boneid:TBoneId):boolean;
var
tmpid, tmpstr:string;
tmp_num:integer;
begin
result:=false;
// Try to extract bone ID using argument as bone name
tmpstr:=inoutstr;
tmpid:=ExtractABNString(tmpstr);
tmpstr:=TrimLeft(tmpstr);
tmpid:=trim(tmpid);
tmp_num:=_data.Skeleton().GetBoneIdxByName(tmpid);
if tmp_num = INVALID_BONE_ID then begin
// Try to extract the index itself
// Index in the output can be invalid! Check it before using!
tmpstr:=inoutstr;
tmpid:=ExtractNumericString(tmpstr, true);
tmpstr:=TrimLeft(tmpstr);
tmp_num:=strtointdef(tmpid, -2);
if (tmp_num <> -2) then begin
result:=(_data.Skeleton().GetBonesCount() > tmp_num);
end;
end else begin
result:=true;
end;
if result then begin
inoutstr:=tmpstr;
boneid:=tmp_num;
end;
end;
function TModelSlot.ExtractMultipleBoneIdsFromString(var inoutstr: string; out_data: TParsedBonesExpression): boolean;
var
inversed:boolean;
c:char;
boneid:TBoneID;
mode:TParsedBonesExpressionMode;
wait_boolop:boolean;
begin
result:=false;
inversed:=false;
inoutstr:=TrimLeft(inoutstr);
mode:=ParsedBoneExpressionModeDefault;
wait_boolop:=false;
while(length(inoutstr) > 0) do begin
c:=inoutstr[1];
if c = '&' then begin
if not wait_boolop then begin
result:=false;
break;
end;
if (mode <> ParsedBoneExpressionModeDefault) and (mode <> ParsedBoneExpressionModeAnd) then begin
result:=false;
break;
end;
mode:=ParsedBoneExpressionModeAnd;
out_data.SetMode(mode);
inversed:=false;
wait_boolop:=false;
AdvanceString(inoutstr, 1);
inoutstr:=TrimLeft(inoutstr);
continue;
end else if c = '|' then begin
if not wait_boolop then begin
result:=false;
break;
end;
if (mode <> ParsedBoneExpressionModeDefault) and (mode <> ParsedBoneExpressionModeOr) then begin
result:=false;
break;
end;
mode:=ParsedBoneExpressionModeOr;
out_data.SetMode(mode);
inversed:=false;
wait_boolop:=false;
AdvanceString(inoutstr, 1);
inoutstr:=TrimLeft(inoutstr);
continue;
end else if c = COMMANDS_ARGUMENTS_SEPARATOR then begin
break;
end else if wait_boolop then begin
result:=false;
break;
end else if c = COMMANDS_ARGUMENT_INVERSE then begin
inversed:=true;
AdvanceString(inoutstr, 1);
end;
inoutstr:=TrimLeft(inoutstr);
if ExtractBoneIdFromString(inoutstr, boneid) and (boneid<>INVALID_BONE_ID) then begin
out_data.AddParsed(boneid, inversed);
wait_boolop:=true;
result:=true;
end else begin
result:=false;
break;
end;
end;
if result and (out_data.GetMode() = ParsedBoneExpressionModeDefault) then begin
out_data.SetMode(ParsedBoneExpressionModeOr);
end;
end;
function TModelSlot.GetBoneNameById(boneid: TBoneId): string;
var
s:TOgfSkeleton;
begin
result:='[none]';
if not _data.Loaded() then exit;
s:=_data.Skeleton();
if s = nil then exit;
if boneid = INVALID_BONE_ID then begin
result:='[all]';
exit;
end;
if (boneid<s.GetBonesCount()) then begin
result:=s.GetBoneName(boneid);
end;
end;
function TModelSlot.CheckAndCorrectFrameId(var frameid: integer; anim_name: string): boolean;
var
frames_cnt:integer;
begin
frames_cnt:=_data.Animations().GetAnimationFramesCount(anim_name);
if (frameid < 0) then begin
frameid:=frames_cnt+frameid;
end;
result:=(frameid >= 0) and (frameid < frames_cnt);
end;
function TModelSlot.ReplaceWildcards(s: string; arg: TCommandIndexArg): string;
var
wildcard_text_start, wildcard_text_end:string;
wildcard_flags:TWildcardFlags;
begin
wildcard_flags:=arg.GetWildcardText(wildcard_text_start, wildcard_text_end);
if ((wildcard_flags and START_WILDCARD_FOUND)<>0) and ((wildcard_flags and END_WILDCARD_FOUND)<>0) then begin
result:=StringReplace(s, '*', wildcard_text_start, []);
result:=StringReplace(result, '*', wildcard_text_end, [])
end else if (wildcard_flags and START_WILDCARD_FOUND)<>0 then begin
result:=StringReplace(s, '*', wildcard_text_end, [rfReplaceAll]);
end else if (wildcard_flags and END_WILDCARD_FOUND)<>0 then begin
result:=StringReplace(s, '*', wildcard_text_end, [rfReplaceAll]);
end else begin
result:=s;
end;
end;
function ShapeTypeById(shape:word):string;
begin
if shape = OGF_SHAPE_TYPE_BOX then begin
result:='BOX';
end else if shape = OGF_SHAPE_TYPE_CYLINDER then begin
result:='CYLINDER';
end else if shape = OGF_SHAPE_TYPE_INVALID then begin
result:='INVALID';
end else if shape = OGF_SHAPE_TYPE_SPHERE then begin
result:='SPHERE';
end else if shape = OGF_SHAPE_TYPE_NONE then begin
result:='NONE';
end else begin
result:='[unknown]';
end;
end;
//////////////////////////////////////////////////////// Selection //////////////////////////////////////////////////////////
function TModelSlot._CmdSetPivot(var args: string; cmd: TCommandSetup; result_description: TCommandResult; userdata: TObject): boolean;
var
v:FVector3;
argsparser:TCommandsArgumentsParser;
begin
result:=false;
set_zero(v{%H-});
argsparser:=TCommandsArgumentsParser.Create();
try
argsparser.RegisterArgument(TCommandsArgumentsParserArgSingle, false, 'X component of new pivot position');
argsparser.RegisterArgument(TCommandsArgumentsParserArgSingle, false, 'Y component of new pivot position');
argsparser.RegisterArgument(TCommandsArgumentsParserArgSingle, false, 'Z component of new pivot position');
if argsparser.Parse(args) and argsparser.GetAsSingle(0, v.x) and argsparser.GetAsSingle(1, v.y) and argsparser.GetAsSingle(2, v.z) then begin
_selectionarea.SetPivot(v);
result:=true;
end else begin
result_description.SetDescription(argsparser.GetLastErr());
if length(result_description.GetDescription())=0 then begin
result_description.SetDescription('can''t get parsed arguments');
end;
end;
finally
FreeAndNil(argsparser);
end;
end;
function TModelSlot._CmdSelectionSphere(var args: string; cmd: TCommandSetup; result_description: TCommandResult; userdata: TObject): boolean;
var
v:FVector3;
r:single;
argsparser:TCommandsArgumentsParser;
begin
result:=false;
argsparser:=TCommandsArgumentsParser.Create();
try
argsparser.RegisterArgument(TCommandsArgumentsParserArgSingle, false, 'X coordinate of sphere center');
argsparser.RegisterArgument(TCommandsArgumentsParserArgSingle, false, 'Y coordinate of sphere center');
argsparser.RegisterArgument(TCommandsArgumentsParserArgSingle, false, 'Z coordinate of sphere center');
argsparser.RegisterArgument(TCommandsArgumentsParserArgSingle, false, 'radius of the sphere');
if argsparser.Parse(args) and
argsparser.GetAsSingle(0, v.x) and
argsparser.GetAsSingle(1, v.y) and
argsparser.GetAsSingle(2, v.z) and
argsparser.GetAsSingle(3, r)
then begin
_selectionarea.SetSelectionAreaAsSphere(v, r);
result:=true;
end else begin
result_description.SetDescription(argsparser.GetLastErr());
if length(result_description.GetDescription())=0 then begin
result_description.SetDescription('can''t get parsed arguments');
end;
end;
finally
FreeAndNil(argsparser);
end;
end;
function TModelSlot._CmdSelectionBox(var args: string; cmd: TCommandSetup; result_description: TCommandResult; userdata: TObject): boolean;
var
p1, p2:FVector3;
argsparser:TCommandsArgumentsParser;
begin
result:=false;
argsparser:=TCommandsArgumentsParser.Create();
try
argsparser.RegisterArgument(TCommandsArgumentsParserArgSingle, false, 'X coordinate of the 1st point');
argsparser.RegisterArgument(TCommandsArgumentsParserArgSingle, false, 'Y coordinate of the 1st point');
argsparser.RegisterArgument(TCommandsArgumentsParserArgSingle, false, 'Z coordinate of the 1st point');
argsparser.RegisterArgument(TCommandsArgumentsParserArgSingle, false, 'X coordinate of the 2nd point');
argsparser.RegisterArgument(TCommandsArgumentsParserArgSingle, false, 'Y coordinate of the 2nd point');
argsparser.RegisterArgument(TCommandsArgumentsParserArgSingle, false, 'Z coordinate of the 2nd point');
if argsparser.Parse(args) and
argsparser.GetAsSingle(0, p1.x) and
argsparser.GetAsSingle(1, p1.y) and
argsparser.GetAsSingle(2, p1.z) and
argsparser.GetAsSingle(3, p2.x) and
argsparser.GetAsSingle(4, p2.y) and
argsparser.GetAsSingle(5, p2.z)
then begin
_selectionarea.SetSelectionAreaAsBox(p1, p2);
result:=true;
end else begin
result_description.SetDescription(argsparser.GetLastErr());
if length(result_description.GetDescription())=0 then begin
result_description.SetDescription('can''t get parsed arguments');
end;
end;
finally
FreeAndNil(argsparser);
end;
end;
function TModelSlot._CmdSelectionClear(var args: string; cmd: TCommandSetup; result_description: TCommandResult; userdata: TObject): boolean;
begin
_selectionarea.ResetSelection();
result:=true;
end;
type
TVertexCounterCallbackData = record
selection_area:TSelectionArea;
vcnt:integer;
child_id:integer;
end;
pTVertexCounterCallbackData = ^TVertexCounterCallbackData;
function VertexCounterCallback(vertex_id:integer; data:pTOgfVertexCommonData; uv:pFVector2; links:TVertexBones; userdata:pointer):boolean;
var
cbdata:pTVertexCounterCallbackData;
begin
result:=true;
if (userdata = nil) or (data = nil) then exit;
cbdata:=pTVertexCounterCallbackData(userdata);
if cbdata^.selection_area.IsVertexInSelection(cbdata^.child_id, vertex_id, data^.pos) then begin
cbdata^.vcnt:=cbdata^.vcnt+1;
end;
end;
function TModelSlot._CmdSelectionInfo(var args: string; cmd: TCommandSetup; result_description: TCommandResult; userdata: TObject): boolean;
var
r:string;
r_bones:string;
i:integer;
cbdata:TVertexCounterCallbackData;
v:FVector3;
begin
r:=_selectionarea.Info();
if _data.Loaded() then begin
cbdata.selection_area:=_selectionarea;
cbdata.vcnt:=0;
for i:=0 to _data.Meshes().Count()-1 do begin
cbdata.child_id:=i;
_data.Meshes().Get(i).IterateVertices(@VertexCounterCallback, @cbdata);
end;
r:=r+chr($0d)+chr($0a)+'Selected vertices count: '+inttostr(cbdata.vcnt);
r_bones:='';
for i:=0 to _data.Skeleton().GetBonesCount()-1 do begin
if data.Skeleton().GetGlobalBonePositionInPose(i, '', -1, v) and _selectionarea.IsPointInSelection(v) then begin
if length(r_bones)=0 then begin
r_bones:=r_bones+chr($0d)+chr($0a)+'Selected bones:'+chr($0d)+chr($0a);
end;
r_bones:=r_bones+'- '+_data.Skeleton().GetBoneName(i)+' ('+floattostr(v.x)+', '+floattostr(v.y)+', '+floattostr(v.z)+')'+chr($0d)+chr($0a);
end;
end;
end;
result_description.SetDescription(r+r_bones);
result:=true;
end;
function TModelSlot._CmdSelectionTestPoint(var args: string; cmd: TCommandSetup; result_description: TCommandResult; userdata: TObject): boolean;
var
v:FVector3;
argsparser:TCommandsArgumentsParser;
begin
result:=false;
argsparser:=TCommandsArgumentsParser.Create();
try
argsparser.RegisterArgument(TCommandsArgumentsParserArgSingle, false, 'point X coordinate');
argsparser.RegisterArgument(TCommandsArgumentsParserArgSingle, false, 'point Y coordinate');
argsparser.RegisterArgument(TCommandsArgumentsParserArgSingle, false, 'point Z coordinate');
if argsparser.Parse(args) and
argsparser.GetAsSingle(0, v.x) and
argsparser.GetAsSingle(1, v.y) and
argsparser.GetAsSingle(2, v.z)
then begin
if not _selectionarea.IsSpatialSelectionModeActive() then begin
result_description.SetDescription('Please activate spatial selection mode first');
end else if _selectionarea.IsPointInSelection(v) then begin
result_description.SetDescription('Point is inside the selected area');
end else begin
result_description.SetDescription('Point is not in the selected area');
end;
result:=true;
end else begin
result_description.SetDescription(argsparser.GetLastErr());
if length(result_description.GetDescription())=0 then begin
result_description.SetDescription('can''t get parsed arguments');
end;
end;
finally
FreeAndNil(argsparser);
end;
end;
function TModelSlot._CmdSelectionInverse(var args: string; cmd: TCommandSetup; result_description: TCommandResult; userdata: TObject): boolean;
begin
result:=true;
_selectionarea.InverseSelection();
end;
type
TVertexPickingCallbackData = record
selection_area:TSelectionArea;
verts:array of integer;
childs:array of integer;
child_id:integer;
end;
pTVertexPickingCallbackData = ^TVertexPickingCallbackData;
function VertexPickingCallback(vertex_id:integer; data:pTOgfVertexCommonData; uv:pFVector2; links:TVertexBones; userdata:pointer):boolean;
var
cbdata:pTVertexPickingCallbackData;
i:integer;
begin
result:=true;
if (userdata = nil) or (data = nil) then exit;
cbdata:=pTVertexPickingCallbackData(userdata);
if cbdata^.selection_area.IsPointInSelection(data^.pos) then begin
i:=length(cbdata^.verts);
setlength(cbdata^.verts, i+1);
setlength(cbdata^.childs, i+1);
cbdata^.verts[i]:=vertex_id;
cbdata^.childs[i]:=cbdata^.child_id;
end;
end;
function TModelSlot._CmdSelectionSelectPickVertices(var args: string; cmd: TCommandSetup; result_description: TCommandResult; userdata: TObject): boolean;
var
p1, p2:FVector3;
mode:string;
argsparser:TCommandsArgumentsParser;
_stashedselection:TSelectionArea;
cbdata:TVertexPickingCallbackData;
i:integer;
begin
result:=false;
if not _data.Loaded() then exit;
argsparser:=TCommandsArgumentsParser.Create();
try
argsparser.RegisterArgument(TCommandsArgumentsParserArgABNString, true, 'mode');
argsparser.RegisterArgument(TCommandsArgumentsParserArgSingle, true, 'point X coordinate');
argsparser.RegisterArgument(TCommandsArgumentsParserArgSingle, true, 'point Y coordinate');
argsparser.RegisterArgument(TCommandsArgumentsParserArgSingle, true, 'point Z coordinate');
argsparser.RegisterArgument(TCommandsArgumentsParserArgSingle, true, 'sphere radius or box second point X coordinate');
argsparser.RegisterArgument(TCommandsArgumentsParserArgSingle, true, 'box second point Y coordinate');
argsparser.RegisterArgument(TCommandsArgumentsParserArgSingle, true, 'box second point Z coordinate');
if argsparser.Parse(args) and
argsparser.GetAsString(0, mode, '') and
argsparser.GetAsSingle(1, p1.x, 0) and
argsparser.GetAsSingle(2, p1.y, 0) and
argsparser.GetAsSingle(3, p1.z, 0) and
argsparser.GetAsSingle(4, p2.x, 0) and
argsparser.GetAsSingle(5, p2.y, 0) and
argsparser.GetAsSingle(6, p2.z, 0)
then begin
_stashedselection:=nil;
if mode = 'box' then begin
if _selectionarea.IsVertsSelectionModeActive() then begin
_stashedselection:=_selectionarea;
_selectionarea:=TSelectionArea.Create();