forked from 20tab/UnrealEnginePython
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathUEPySequencer.cpp
More file actions
2098 lines (1660 loc) · 66.9 KB
/
UEPySequencer.cpp
File metadata and controls
2098 lines (1660 loc) · 66.9 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
#include "UEPySequencer.h"
#include "Runtime/MovieScene/Public/MovieScene.h"
#include "Runtime/MovieScene/Public/MovieScenePossessable.h"
#include "Runtime/MovieScene/Public/MovieSceneBinding.h"
#include "Runtime/MovieScene/Public/MovieSceneTrack.h"
#include "Runtime/MovieScene/Public/MovieSceneNameableTrack.h"
#include "Runtime/LevelSequence/Public/LevelSequence.h"
#if WITH_EDITOR
#if ENGINE_MINOR_VERSION >= 24
#include "Subsystems/AssetEditorSubsystem.h"
#endif
#if ENGINE_MINOR_VERSION >= 25
#include "Editor/MovieSceneTools/Public/MovieSceneToolHelpers.h"
#include "Runtime/MovieSceneTracks/Public/Sections/MovieSceneCameraCutSection.h"
#endif
#include "Editor/Sequencer/Public/ISequencer.h"
#include "Editor/Sequencer/Public/ISequencerModule.h"
#include "Editor/UnrealEd/Public/Toolkits/AssetEditorManager.h"
#include "Editor/UnrealEd/Public/LevelEditorViewport.h"
#include "Editor/Sequencer/Private/Sequencer.h"
#include "Camera/CameraActor.h"
#include "CinematicCamera/Public/CineCameraActor.h"
#if ENGINE_MINOR_VERSION >= 20
#include "LevelSequenceEditor/Private/LevelSequenceEditorToolkit.h"
#else
#include "Private/LevelSequenceEditorToolkit.h"
#endif
#include "Tracks/MovieSceneCameraCutTrack.h"
#if ENGINE_MINOR_VERSION < 20
#include "Sections/IKeyframeSection.h"
#endif
#include "Sections/MovieSceneFloatSection.h"
#include "Sections/MovieSceneBoolSection.h"
#include "Sections/MovieScene3DTransformSection.h"
#include "Sections/MovieSceneVectorSection.h"
#include "Runtime/MovieScene/Public/MovieSceneFolder.h"
#include "Runtime/MovieScene/Public/MovieSceneSpawnable.h"
#include "Runtime/MovieScene/Public/MovieScenePossessable.h"
#if ENGINE_MINOR_VERSION < 18
#include "Editor/UnrealEd/Private/FbxImporter.h"
#else
#include "Editor/UnrealEd/Public/FbxImporter.h"
#endif
#include "Editor/MovieSceneTools/Public/MatineeImportTools.h"
#endif
#include "GameFramework/Actor.h"
#include "Runtime/LevelSequence/Public/LevelSequence.h"
#include "Engine/World.h"
#if ENGINE_MINOR_VERSION >= 20
#include "Wrappers/UEPyFFrameNumber.h"
#endif
#if ENGINE_MINOR_VERSION >= 20
static bool magic_get_frame_number(UMovieScene *MovieScene, PyObject *py_obj, FFrameNumber *dest)
{
ue_PyFFrameNumber *py_frame_number = py_ue_is_fframe_number(py_obj);
if (py_frame_number)
{
*dest = py_frame_number->frame_number;
return true;
}
if (PyNumber_Check(py_obj))
{
PyObject *f_value = PyNumber_Float(py_obj);
float value = PyFloat_AsDouble(f_value);
Py_DECREF(f_value);
*dest = MovieScene->GetTickResolution().AsFrameNumber(value);
return true;
}
return false;
}
#if WITH_EDITOR
#if ENGINE_MINOR_VERSION > 21
static void ImportTransformChannel(const FRichCurve& Source, FMovieSceneFloatChannel* Dest, FFrameRate DestFrameRate, bool bNegateTangents)
{
TMovieSceneChannelData<FMovieSceneFloatValue> ChannelData = Dest->GetData();
ChannelData.Reset();
double DecimalRate = DestFrameRate.AsDecimal();
for (int32 KeyIndex = 0; KeyIndex < Source.Keys.Num(); ++KeyIndex)
{
float ArriveTangent = Source.Keys[KeyIndex].ArriveTangent;
if (KeyIndex > 0)
{
ArriveTangent = ArriveTangent / ((Source.Keys[KeyIndex].Value - Source.Keys[KeyIndex - 1].Value) * DecimalRate);
}
float LeaveTangent = Source.Keys[KeyIndex].LeaveTangent;
if (KeyIndex < Source.Keys.Num() - 1)
{
LeaveTangent = LeaveTangent / ((Source.Keys[KeyIndex + 1].Value - Source.Keys[KeyIndex].Value) * DecimalRate);
}
if (bNegateTangents)
{
ArriveTangent = -ArriveTangent;
LeaveTangent = -LeaveTangent;
}
FFrameNumber KeyTime = (Source.Keys[KeyIndex].Value * DestFrameRate).RoundToFrame();
if (ChannelData.FindKey(KeyTime) == INDEX_NONE)
{
FMovieSceneFloatValue NewKey(Source.Keys[KeyIndex].Value);
NewKey.InterpMode = Source.Keys[KeyIndex].InterpMode;
NewKey.TangentMode = Source.Keys[KeyIndex].TangentMode;
NewKey.Tangent.ArriveTangent = ArriveTangent / DestFrameRate.AsDecimal();
NewKey.Tangent.LeaveTangent = LeaveTangent / DestFrameRate.AsDecimal();
NewKey.Tangent.TangentWeightMode = RCTWM_WeightedNone;
NewKey.Tangent.ArriveTangentWeight = 0.0f;
NewKey.Tangent.LeaveTangentWeight = 0.0f;
ChannelData.AddKey(KeyTime, NewKey);
}
}
Dest->AutoSetTangents();
}
#else
static void ImportTransformChannel(const FInterpCurveFloat& Source, FMovieSceneFloatChannel* Dest, FFrameRate DestFrameRate, bool bNegateTangents)
{
TMovieSceneChannelData<FMovieSceneFloatValue> ChannelData = Dest->GetData();
ChannelData.Reset();
double DecimalRate = DestFrameRate.AsDecimal();
for (int32 KeyIndex = 0; KeyIndex < Source.Points.Num(); ++KeyIndex)
{
float ArriveTangent = Source.Points[KeyIndex].ArriveTangent;
if (KeyIndex > 0)
{
ArriveTangent = ArriveTangent / ((Source.Points[KeyIndex].InVal - Source.Points[KeyIndex - 1].InVal) * DecimalRate);
}
float LeaveTangent = Source.Points[KeyIndex].LeaveTangent;
if (KeyIndex < Source.Points.Num() - 1)
{
LeaveTangent = LeaveTangent / ((Source.Points[KeyIndex + 1].InVal - Source.Points[KeyIndex].InVal) * DecimalRate);
}
if (bNegateTangents)
{
ArriveTangent = -ArriveTangent;
LeaveTangent = -LeaveTangent;
}
FFrameNumber KeyTime = (Source.Points[KeyIndex].InVal * DestFrameRate).RoundToFrame();
#if ENGINE_MINOR_VERSION > 20
FMatineeImportTools::SetOrAddKey(ChannelData, KeyTime, Source.Points[KeyIndex].OutVal, ArriveTangent, LeaveTangent, Source.Points[KeyIndex].InterpMode, DestFrameRate);
#else
FMatineeImportTools::SetOrAddKey(ChannelData, KeyTime, Source.Points[KeyIndex].OutVal, ArriveTangent, LeaveTangent, Source.Points[KeyIndex].InterpMode);
#endif
}
Dest->AutoSetTangents();
}
#endif
static bool ImportFBXTransform(FString NodeName, UMovieScene3DTransformSection* TransformSection, UnFbx::FFbxCurvesAPI& CurveAPI)
{
// Look for transforms explicitly
FTransform DefaultTransform;
#if ENGINE_MINOR_VERSION > 21
FRichCurve Translation[3];
FRichCurve EulerRotation[3];
FRichCurve Scale[3];
#else
FInterpCurveFloat Translation[3];
FInterpCurveFloat EulerRotation[3];
FInterpCurveFloat Scale[3];
#endif
#if ENGINE_MINOR_VERSION > 22
CurveAPI.GetConvertedTransformCurveData(NodeName, Translation[0], Translation[1], Translation[2], EulerRotation[0], EulerRotation[1], EulerRotation[2], Scale[0], Scale[1], Scale[2], DefaultTransform, false);
#else
CurveAPI.GetConvertedTransformCurveData(NodeName, Translation[0], Translation[1], Translation[2], EulerRotation[0], EulerRotation[1], EulerRotation[2], Scale[0], Scale[1], Scale[2], DefaultTransform);
#endif
TransformSection->Modify();
FFrameRate FrameRate = TransformSection->GetTypedOuter<UMovieScene>()->GetTickResolution();
FVector Location = DefaultTransform.GetLocation(), Rotation = DefaultTransform.GetRotation().Euler(), Scale3D = DefaultTransform.GetScale3D();
TArrayView<FMovieSceneFloatChannel*> Channels = TransformSection->GetChannelProxy().GetChannels<FMovieSceneFloatChannel>();
Channels[0]->SetDefault(Location.X);
Channels[1]->SetDefault(Location.Y);
Channels[2]->SetDefault(Location.Z);
Channels[3]->SetDefault(Rotation.X);
Channels[4]->SetDefault(Rotation.Y);
Channels[5]->SetDefault(Rotation.Z);
Channels[6]->SetDefault(Scale3D.X);
Channels[7]->SetDefault(Scale3D.Y);
Channels[8]->SetDefault(Scale3D.Z);
ImportTransformChannel(Translation[0], Channels[0], FrameRate, false);
ImportTransformChannel(Translation[1], Channels[1], FrameRate, true);
ImportTransformChannel(Translation[2], Channels[2], FrameRate, false);
ImportTransformChannel(EulerRotation[0], Channels[3], FrameRate, false);
ImportTransformChannel(EulerRotation[1], Channels[4], FrameRate, true);
ImportTransformChannel(EulerRotation[2], Channels[5], FrameRate, true);
ImportTransformChannel(Scale[0], Channels[6], FrameRate, false);
ImportTransformChannel(Scale[1], Channels[7], FrameRate, false);
ImportTransformChannel(Scale[2], Channels[8], FrameRate, false);
return true;
}
#endif
#endif
#if WITH_EDITOR
PyObject *py_ue_sequencer_changed(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
PyObject *py_bool = nullptr;
if (!PyArg_ParseTuple(args, "|O:sequencer_changed", &py_bool))
{
return NULL;
}
bool force_open = false;
if (!self->ue_object->IsA<ULevelSequence>())
return PyErr_Format(PyExc_Exception, "uobject is not a LevelSequence");
ULevelSequence *seq = (ULevelSequence *)self->ue_object;
//UAssetEditorSubsystem* AssetEditorSubsystem = GEditor->GetEditorSubsystem<UAssetEditorSubsystem>();
if (py_bool && PyObject_IsTrue(py_bool))
{
// try to open the editor for the asset
#if ENGINE_MINOR_VERSION >= 24
GEditor->GetEditorSubsystem<UAssetEditorSubsystem>()->OpenEditorForAsset(seq);
#else
FAssetEditorManager::Get().OpenEditorForAsset(seq);
#endif
}
#if ENGINE_MINOR_VERSION >= 24
IAssetEditorInstance* editor = GEditor->GetEditorSubsystem<UAssetEditorSubsystem>()->FindEditorForAsset(seq, true);
#else
IAssetEditorInstance *editor = FAssetEditorManager::Get().FindEditorForAsset(seq, true);
#endif
if (editor)
{
FLevelSequenceEditorToolkit *toolkit = (FLevelSequenceEditorToolkit *)editor;
ISequencer *sequencer = toolkit->GetSequencer().Get();
#if ENGINE_MINOR_VERSION < 13
sequencer->NotifyMovieSceneDataChanged();
#else
#if ENGINE_MINOR_VERSION > 16
sequencer->NotifyMovieSceneDataChanged(EMovieSceneDataChangeType::RefreshAllImmediately);
#else
sequencer->NotifyMovieSceneDataChanged(EMovieSceneDataChangeType::Unknown);
#endif
#endif
}
Py_RETURN_NONE;
}
#endif
PyObject *py_ue_sequencer_possessable_tracks(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
PyObject *py_possessable;
if (!PyArg_ParseTuple(args, "O:sequencer_possessable_tracks", &py_possessable))
{
return NULL;
}
if (!self->ue_object->IsA<ULevelSequence>())
return PyErr_Format(PyExc_Exception, "uobject is not a LevelSequence");
FGuid f_guid;
if (PyUnicodeOrString_Check(py_possessable))
{
const char *guid = UEPyUnicode_AsUTF8(py_possessable);
if (!FGuid::Parse(FString(guid), f_guid))
{
return PyErr_Format(PyExc_Exception, "invalid GUID");
}
}
else
{
FMovieScenePossessable *possessable = (FMovieScenePossessable *)do_ue_py_check_struct(py_possessable, FMovieScenePossessable::StaticStruct());
if (possessable)
{
f_guid = possessable->GetGuid();
}
}
if (!f_guid.IsValid())
{
return PyErr_Format(PyExc_Exception, "invalid GUID");
}
ULevelSequence *seq = (ULevelSequence *)self->ue_object;
UMovieScene *scene = seq->GetMovieScene();
PyObject *py_tracks = PyList_New(0);
FMovieScenePossessable *possessable = scene->FindPossessable(f_guid);
if (!possessable)
return PyErr_Format(PyExc_Exception, "GUID not found");
TArray<FMovieSceneBinding> bindings = scene->GetBindings();
for (FMovieSceneBinding binding : bindings)
{
if (binding.GetObjectGuid() != f_guid)
continue;
for (UMovieSceneTrack *track : binding.GetTracks())
{
ue_PyUObject *ret = ue_get_python_uobject((UObject *)track);
if (!ret)
{
Py_DECREF(py_tracks);
return PyErr_Format(PyExc_Exception, "PyUObject is in invalid state");
}
PyList_Append(py_tracks, (PyObject *)ret);
}
break;
}
return py_tracks;
}
PyObject *py_ue_sequencer_find_possessable(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
char *guid;
PyObject *py_parent = nullptr;
if (!PyArg_ParseTuple(args, "s|O:sequencer_find_possessable", &guid, &py_parent))
{
return nullptr;
}
ULevelSequence *seq = ue_py_check_type<ULevelSequence>(self);
if (!seq)
{
return PyErr_Format(PyExc_Exception, "uobject is not a ULevelSequence");
}
FGuid f_guid;
if (!FGuid::Parse(FString(guid), f_guid))
{
return PyErr_Format(PyExc_Exception, "invalid GUID");
}
#if ENGINE_MINOR_VERSION < 15
UObject *u_obj = seq->FindPossessableObject(f_guid, seq);
#else
UObject *parent = nullptr;
if (py_parent)
{
parent = ue_py_check_type<UObject>(py_parent);
if (!parent)
{
return PyErr_Format(PyExc_Exception, "argument is not a UObject");
}
}
UObject *u_obj = nullptr;
TArray<UObject *, TInlineAllocator<1>> u_objects;
seq->LocateBoundObjects(f_guid, parent, u_objects);
if (u_objects.Num() > 0)
{
u_obj = u_objects[0];
}
#endif
if (!u_obj)
return PyErr_Format(PyExc_Exception, "unable to find uobject with GUID \"%s\"", guid);
Py_RETURN_UOBJECT(u_obj);
}
PyObject *py_ue_sequencer_find_spawnable(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
char *guid;
if (!PyArg_ParseTuple(args, "s:sequencer_find_spawnable", &guid))
{
return NULL;
}
if (!self->ue_object->IsA<ULevelSequence>())
return PyErr_Format(PyExc_Exception, "uobject is not a LevelSequence");
FGuid f_guid;
if (!FGuid::Parse(FString(guid), f_guid))
{
return PyErr_Format(PyExc_Exception, "invalid GUID");
}
ULevelSequence *seq = (ULevelSequence *)self->ue_object;
FMovieSceneSpawnable *spawnable = seq->MovieScene->FindSpawnable(f_guid);
PyObject *ret = py_ue_new_owned_uscriptstruct(spawnable->StaticStruct(), (uint8 *)spawnable);
Py_INCREF(ret);
return ret;
}
#if WITH_EDITOR
PyObject *py_ue_sequencer_add_possessable(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
PyObject *py_obj;
if (!PyArg_ParseTuple(args, "O:sequencer_add_possessable", &py_obj))
{
return NULL;
}
if (!self->ue_object->IsA<ULevelSequence>())
return PyErr_Format(PyExc_Exception, "uobject is not a LevelSequence");
ue_PyUObject *py_ue_obj = ue_is_pyuobject(py_obj);
if (!py_ue_obj)
return PyErr_Format(PyExc_Exception, "argument is not a uobject");
ULevelSequence *seq = (ULevelSequence *)self->ue_object;
FString name = py_ue_obj->ue_object->GetName();
AActor *actor = Cast<AActor>(py_ue_obj->ue_object);
if (actor)
name = actor->GetActorLabel();
FGuid new_guid = seq->MovieScene->AddPossessable(name, py_ue_obj->ue_object->GetClass());
if (!new_guid.IsValid())
{
return PyErr_Format(PyExc_Exception, "unable to possess object");
}
seq->BindPossessableObject(new_guid, *(py_ue_obj->ue_object), py_ue_obj->ue_object->GetWorld());
return PyUnicode_FromString(TCHAR_TO_UTF8(*new_guid.ToString()));
}
PyObject *py_ue_sequencer_add_camera(ue_PyUObject *self, PyObject * args)
{
// because of what is likely a bug in Unreal Engine we cannot add cameras via AddActors from 4.22
// only way I can see is to replicate CreateCamera - because cant figure out how to determine
// which camera was created
// NOTA BENE - this code MUST be checked at every Unreal Engine version update to ensure
// it remains consistent with the current CreateCamera
// so far I can see no difference between the CreateCamera function in versions 4.22 and 4.25
// from 4.21 logs we have determined that the python sequence of spawn camera followed by add actor
// seems to be equivalent to adding a camera manually via the GUI - which calls CreateCamera
// current differences to 4.21
// this sets the camera position as the current viewpoint - add_actor just leaves camera object in its incoming position
// using add_actor seems to add an additional camera item in the sequencer window - I think this is just a template camera
// using this function we add just one camera per call (see the Destroy old actor line)
// these are spawned cameras in 4.22
ue_py_check(self);
if (!self->ue_object->IsA<ULevelSequence>())
return PyErr_Format(PyExc_Exception, "uobject is not a LevelSequence");
ULevelSequence *seq = (ULevelSequence *)self->ue_object;
#if ENGINE_MINOR_VERSION >= 24
//UAssetEditorSubsystem* AssetEditorSubsystem = GEditor->GetEditorSubsystem<UAssetEditorSubsystem>();
GEditor->GetEditorSubsystem<UAssetEditorSubsystem>()->OpenEditorForAsset(seq);
IAssetEditorInstance *editor = GEditor->GetEditorSubsystem<UAssetEditorSubsystem>()->FindEditorForAsset(seq, true);
#else
FAssetEditorManager::Get().OpenEditorForAsset(seq);
IAssetEditorInstance *editor = FAssetEditorManager::Get().FindEditorForAsset(seq, true);
#endif
FGuid CameraGuid;
ACineCameraActor* NewCamera = nullptr;
if (editor)
{
FLevelSequenceEditorToolkit *toolkit = (FLevelSequenceEditorToolkit *)editor;
EXTRA_UE_LOG(LogPython, Warning, TEXT("py_ue_sequencer_add_camera: opening editor for asset 1"));
ISequencer *sequencer = toolkit->GetSequencer().Get();
// dangerous type cast here but Im guessing ISequencer is an interface of an FSequencer
// well pigs FSequencer is private - although it does seem UEP uses a number of Private include files
// as of 4.25 cant use most FSequencer symbols as they are not available at link time
EXTRA_UE_LOG(LogPython, Warning, TEXT("py_ue_sequencer_add_camera: fixup 1"));
FSequencer* fsequencer = (FSequencer *)sequencer;
// so all I can do is re-implement CreateCamera here
UWorld* World = GCurrentLevelEditingViewportClient ? GCurrentLevelEditingViewportClient->GetWorld() : nullptr;
if (!World)
{
return PyErr_Format(PyExc_Exception, "cannot get World");
}
// what to do about this
// I think this is for undo actions - as we are doing this in python dont think we need this
//const FScopedTransaction Transaction(NSLOCTEXT("Sequencer", "CreateCameraHere", "Create Camera Here"));
const bool bCreateAsSpawnable = sequencer->GetSequencerSettings()->GetCreateSpawnableCameras();
FActorSpawnParameters SpawnParams;
if (bCreateAsSpawnable)
{
// Don't bother transacting this object if we're creating a spawnable since it's temporary
SpawnParams.ObjectFlags &= ~RF_Transactional;
}
// Set new camera to match viewport
NewCamera = World->SpawnActor<ACineCameraActor>(SpawnParams);
if (!NewCamera)
{
return PyErr_Format(PyExc_Exception, "failed to spawn camera actor");
}
// this is pointless - how can Spawnable ever be not NULL in 2nd line!!
FMovieSceneSpawnable* Spawnable = nullptr;
ESpawnOwnership SavedOwnership = Spawnable ? Spawnable->GetSpawnOwnership() : ESpawnOwnership::InnerSequence;
if (bCreateAsSpawnable)
{
CameraGuid = sequencer->MakeNewSpawnable(*NewCamera);
Spawnable = sequencer->GetFocusedMovieSceneSequence()->GetMovieScene()->FindSpawnable(CameraGuid);
if (ensure(Spawnable))
{
// Override spawn ownership during this process to ensure it never gets destroyed
SavedOwnership = Spawnable->GetSpawnOwnership();
Spawnable->SetSpawnOwnership(ESpawnOwnership::External);
}
// Destroy the old actor
World->EditorDestroyActor(NewCamera, false);
// note that this directly accesses ActiveTemplateIDs.Top() in CreateCamera but GetFocusedTemplateID just calls ActiveTemplateIDs.Top()
for (TWeakObjectPtr<UObject>& Object : fsequencer->FindBoundObjects(CameraGuid, sequencer->GetFocusedTemplateID()))
{
NewCamera = Cast<ACineCameraActor>(Object.Get());
if (NewCamera)
{
break;
}
}
ensure(NewCamera);
}
else
{
CameraGuid = sequencer->CreateBinding(*NewCamera, NewCamera->GetActorLabel());
}
if (!CameraGuid.IsValid())
{
return PyErr_Format(PyExc_Exception, "failed to create valid guid");
}
NewCamera->SetActorLocation( GCurrentLevelEditingViewportClient->GetViewLocation(), false );
NewCamera->SetActorRotation( GCurrentLevelEditingViewportClient->GetViewRotation() );
//pNewCamera->CameraComponent->FieldOfView = ViewportClient->ViewFOV; //@todo set the focal length from this field of view
sequencer->OnActorAddedToSequencer().Broadcast(NewCamera, CameraGuid);
#if ENGINE_MINOR_VERSION >= 25
// annoyingly we dont have access to NewCameraAdded in 4.25
// as before re-implement
// (note that AddActors also calls NewCameraAdded if the Actor is a camera)
// also note that NewCameraAdded at 4.22 does not have the MovieSceneToolHelpers::CameraAdded call because it doesnt exist
// - it does some extra actions which Im assuming somewhere between 4.23 and 4.25 was moved to MovieSceneToolHelpers::CameraAdded
{
sequencer->SetPerspectiveViewportCameraCutEnabled(false);
// Lock the viewport to this camera
if (NewCamera && NewCamera->GetLevel())
{
#if ENGINE_MINOR_VERSION == 27
GCurrentLevelEditingViewportClient->SetCinematicActorLock(nullptr);
#else
GCurrentLevelEditingViewportClient->SetMatineeActorLock(nullptr);
#endif
GCurrentLevelEditingViewportClient->SetActorLock(NewCamera);
GCurrentLevelEditingViewportClient->bLockedCameraView = true;
GCurrentLevelEditingViewportClient->UpdateViewForLockedActor();
GCurrentLevelEditingViewportClient->Invalidate();
}
UMovieSceneSequence* Sequence = sequencer->GetFocusedMovieSceneSequence();
UMovieScene* OwnerMovieScene = Sequence->GetMovieScene();
#if ENGINE_MINOR_VERSION == 27
#ifndef UE_BUILD_DEBUG
#error "don't compile it for production'"
#else
//MovieSceneToolHelpers::CameraAdded(OwnerMovieScene, CameraGuid, sequencer->GetLocalTime().Time.FloorToFrame());
#pragma message(" ====================================================== WARNING! ACHTUNG! Atención! ================================================")
#pragma message("\t\tMovieSceneToolHelpers::CameraAdded(OwnerMovieScene, CameraGuid, sequencer->GetLocalTime().Time.FloorToFrame());")
#pragma message(" ====================================================== WARNING! ACHTUNG! Atención! ================================================")
#endif
#else
MovieSceneToolHelpers::CameraAdded(OwnerMovieScene, CameraGuid, sequencer->GetLocalTime().Time.FloorToFrame());
#endif
}
#else
fsequencer->NewCameraAdded(CameraGuid, NewCamera);
#endif
if (bCreateAsSpawnable && ensure(Spawnable))
{
Spawnable->SetSpawnOwnership(SavedOwnership);
}
sequencer->NotifyMovieSceneDataChanged(EMovieSceneDataChangeType::MovieSceneStructureItemAdded);
}
else
{
return PyErr_Format(PyExc_Exception, "unable to access sequencer");
}
ue_PyUObject *py_camera = ue_get_python_uobject_inc(NewCamera);
if (!py_camera)
return PyErr_Format(PyExc_Exception, "uobject is in invalid state");
// we need a tuple return as we want both the camera uobject and the guid
PyObject *ret = PyTuple_New(2);
PyTuple_SetItem(ret, 0, (PyObject*)py_camera);
PyTuple_SetItem(ret, 1, PyUnicode_FromString(TCHAR_TO_UTF8(*CameraGuid.ToString())));
return ret;
}
PyObject *py_ue_sequencer_add_actor(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
EXTRA_UE_LOG(LogPython, Warning, TEXT("py_ue_sequencer_add_actor: starting"));
PyObject *py_obj;
if (!PyArg_ParseTuple(args, "O:sequencer_add_actor", &py_obj))
{
return NULL;
}
EXTRA_UE_LOG(LogPython, Warning, TEXT("py_ue_sequencer_add_actor: 1"));
if (!self->ue_object->IsA<ULevelSequence>())
return PyErr_Format(PyExc_Exception, "uobject is not a LevelSequence");
EXTRA_UE_LOG(LogPython, Warning, TEXT("py_ue_sequencer_add_actor: 2"));
ue_PyUObject *py_ue_obj = ue_is_pyuobject(py_obj);
if (!py_ue_obj)
return PyErr_Format(PyExc_Exception, "argument is not a uobject");
EXTRA_UE_LOG(LogPython, Warning, TEXT("py_ue_sequencer_add_actor: 3"));
#if ENGINE_MINOR_VERSION > 21
if (py_ue_obj->ue_object->IsA<ACameraActor>())
return PyErr_Format(PyExc_Exception, "argument is a camera actor");
#endif
EXTRA_UE_LOG(LogPython, Warning, TEXT("py_ue_sequencer_add_actor: 4"));
ULevelSequence *seq = (ULevelSequence *)self->ue_object;
EXTRA_UE_LOG(LogPython, Warning, TEXT("py_ue_sequencer_add_actor: 5"));
TArray<TWeakObjectPtr<AActor>> actors;
actors.Add((AActor *)py_ue_obj->ue_object);
// try to open the editor for the asset
EXTRA_UE_LOG(LogPython, Warning, TEXT("py_ue_sequencer_add_actor: opening editor for asset"));
#if ENGINE_MINOR_VERSION >= 24
//UAssetEditorSubsystem* AssetEditorSubsystem = GEditor->GetEditorSubsystem<UAssetEditorSubsystem>();
GEditor->GetEditorSubsystem<UAssetEditorSubsystem>()->OpenEditorForAsset(seq);
IAssetEditorInstance *editor = GEditor->GetEditorSubsystem<UAssetEditorSubsystem>()->FindEditorForAsset(seq, true);
#else
FAssetEditorManager::Get().OpenEditorForAsset(seq);
IAssetEditorInstance *editor = FAssetEditorManager::Get().FindEditorForAsset(seq, true);
#endif
if (editor)
{
FLevelSequenceEditorToolkit *toolkit = (FLevelSequenceEditorToolkit *)editor;
EXTRA_UE_LOG(LogPython, Warning, TEXT("py_ue_sequencer_add_actor: opening editor for asset 1"));
ISequencer *sequencer = toolkit->GetSequencer().Get();
EXTRA_UE_LOG(LogPython, Warning, TEXT("py_ue_sequencer_add_actor: opening editor for asset 2"));
sequencer->AddActors(actors);
EXTRA_UE_LOG(LogPython, Warning, TEXT("py_ue_sequencer_add_actor: opening editor for asset 3"));
}
else
{
return PyErr_Format(PyExc_Exception, "unable to access sequencer");
}
UObject& u_obj = *actors[0];
EXTRA_UE_LOG(LogPython, Warning, TEXT("py_ue_sequencer_add_actor: opening editor for asset 4"));
#if ENGINE_MINOR_VERSION < 15
FGuid new_guid = seq->FindPossessableObjectId(u_obj);
#else
FGuid new_guid = seq->FindPossessableObjectId(u_obj, u_obj.GetWorld());
#endif
EXTRA_UE_LOG(LogPython, Warning, TEXT("py_ue_sequencer_add_actor: opening editor for asset 5"));
if (!new_guid.IsValid())
{
return PyErr_Format(PyExc_Exception, "unable to find guid");
}
return PyUnicode_FromString(TCHAR_TO_UTF8(*new_guid.ToString()));
}
PyObject *py_ue_sequencer_add_actor_component(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
PyObject *py_obj;
if (!PyArg_ParseTuple(args, "O:sequencer_add_actor_component", &py_obj))
{
return NULL;
}
if (!self->ue_object->IsA<ULevelSequence>())
return PyErr_Format(PyExc_Exception, "uobject is not a LevelSequence");
ue_PyUObject *py_ue_obj = ue_is_pyuobject(py_obj);
if (!py_ue_obj)
return PyErr_Format(PyExc_Exception, "argument is not a uobject");
if (!py_ue_obj->ue_object->IsA<UActorComponent>())
return PyErr_Format(PyExc_Exception, "argument is not an actorcomponent");
ULevelSequence *seq = (ULevelSequence *)self->ue_object;
UActorComponent* actorComponent = (UActorComponent *)py_ue_obj->ue_object;
// try to open the editor for the asset
#if ENGINE_MINOR_VERSION >= 24
UAssetEditorSubsystem* AssetEditorSubsystem = GEditor->GetEditorSubsystem<UAssetEditorSubsystem>();
AssetEditorSubsystem->OpenEditorForAsset(seq);
IAssetEditorInstance *editor = AssetEditorSubsystem->FindEditorForAsset(seq, true);
#else
FAssetEditorManager::Get().OpenEditorForAsset(seq);
IAssetEditorInstance *editor = FAssetEditorManager::Get().FindEditorForAsset(seq, true);
#endif
FGuid new_guid;
if (editor)
{
FLevelSequenceEditorToolkit *toolkit = (FLevelSequenceEditorToolkit *)editor;
ISequencer *sequencer = toolkit->GetSequencer().Get();
new_guid = sequencer->GetHandleToObject(actorComponent);
}
else
{
return PyErr_Format(PyExc_Exception, "unable to access sequencer");
}
if (!new_guid.IsValid())
{
return PyErr_Format(PyExc_Exception, "unable to find guid");
}
return PyUnicode_FromString(TCHAR_TO_UTF8(*new_guid.ToString()));
}
PyObject *py_ue_sequencer_make_new_spawnable(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
PyObject *py_obj;
if (!PyArg_ParseTuple(args, "O:sequencer_make_new_spawnable", &py_obj))
{
return NULL;
}
if (!self->ue_object->IsA<ULevelSequence>())
return PyErr_Format(PyExc_Exception, "uobject is not a LevelSequence");
ue_PyUObject *py_ue_obj = ue_is_pyuobject(py_obj);
if (!py_ue_obj)
return PyErr_Format(PyExc_Exception, "argument is not a uobject");
if (!py_ue_obj->ue_object->IsA<AActor>())
return PyErr_Format(PyExc_Exception, "argument is not an actor");
AActor *actor = (AActor *)py_ue_obj->ue_object;
ULevelSequence *seq = (ULevelSequence *)self->ue_object;
// try to open the editor for the asset
#if ENGINE_MINOR_VERSION >= 24
//UAssetEditorSubsystem* AssetEditorSubsystem = GEditor->GetEditorSubsystem<UAssetEditorSubsystem>();
GEditor->GetEditorSubsystem<UAssetEditorSubsystem>()->OpenEditorForAsset(seq);
IAssetEditorInstance *editor = GEditor->GetEditorSubsystem<UAssetEditorSubsystem>()->FindEditorForAsset(seq, true);
#else
FAssetEditorManager::Get().OpenEditorForAsset(seq);
IAssetEditorInstance *editor = FAssetEditorManager::Get().FindEditorForAsset(seq, true);
#endif
if (!editor)
{
return PyErr_Format(PyExc_Exception, "unable to access sequencer");
}
FLevelSequenceEditorToolkit *toolkit = (FLevelSequenceEditorToolkit *)editor;
ISequencer *sequencer = toolkit->GetSequencer().Get();
FGuid new_guid = sequencer->MakeNewSpawnable(*actor);
return PyUnicode_FromString(TCHAR_TO_UTF8(*new_guid.ToString()));
}
#endif
#if WITH_EDITOR
#if ENGINE_MINOR_VERSION >= 25
PyObject *py_ue_sequencer_set_section_camera_guid(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
UMovieSceneCameraCutSection *section = ue_py_check_type<UMovieSceneCameraCutSection>(self);
if (!section)
return PyErr_Format(PyExc_Exception, "uobject is not a MovieSceneCameraCutSection");
char *guid;
if (!PyArg_ParseTuple(args, "s:sequencer_set_section_camera_guid", &guid))
{
return NULL;
}
FGuid f_guid;
if (!FGuid::Parse(FString(guid), f_guid))
{
return PyErr_Format(PyExc_Exception, "invalid guid");
}
section->SetCameraGuid(f_guid);
Py_RETURN_NONE;
}
#endif
#endif
PyObject *py_ue_sequencer_master_tracks(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
if (!self->ue_object->IsA<ULevelSequence>())
return PyErr_Format(PyExc_Exception, "uobject is not a LevelSequence");
ULevelSequence *seq = (ULevelSequence *)self->ue_object;
UMovieScene *scene = seq->GetMovieScene();
PyObject *py_tracks = PyList_New(0);
TArray<UMovieSceneTrack *> tracks = scene->GetMasterTracks();
for (UMovieSceneTrack *track : tracks)
{
ue_PyUObject *ret = ue_get_python_uobject((UObject *)track);
if (!ret)
{
Py_DECREF(py_tracks);
return PyErr_Format(PyExc_Exception, "PyUObject is in invalid state");
}
PyList_Append(py_tracks, (PyObject *)ret);
}
return py_tracks;
}
PyObject *py_ue_sequencer_get_camera_cut_track(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
if (!self->ue_object->IsA<ULevelSequence>())
return PyErr_Format(PyExc_Exception, "uobject is not a LevelSequence");
ULevelSequence *seq = (ULevelSequence *)self->ue_object;
UMovieScene *scene = seq->GetMovieScene();
UMovieSceneTrack *track = scene->GetCameraCutTrack();
if (!track)
{
return PyErr_Format(PyExc_Exception, "unable to find camera cut track");
}
Py_RETURN_UOBJECT(track);
}
PyObject *py_ue_sequencer_possessables(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
if (!self->ue_object->IsA<ULevelSequence>())
return PyErr_Format(PyExc_Exception, "uobject is not a LevelSequence");
ULevelSequence *seq = (ULevelSequence *)self->ue_object;
UMovieScene *scene = seq->GetMovieScene();
PyObject *py_possessables = PyList_New(0);
for (int32 i = 0; i < scene->GetPossessableCount(); i++)
{
FMovieScenePossessable possessable = scene->GetPossessable(i);
PyObject *py_possessable = py_ue_new_owned_uscriptstruct(possessable.StaticStruct(), (uint8 *)&possessable);
PyList_Append(py_possessables, py_possessable);
}
return py_possessables;
}
PyObject *py_ue_sequencer_possessables_guid(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
if (!self->ue_object->IsA<ULevelSequence>())
return PyErr_Format(PyExc_Exception, "uobject is not a LevelSequence");
ULevelSequence *seq = (ULevelSequence *)self->ue_object;
UMovieScene *scene = seq->GetMovieScene();
PyObject *py_possessables = PyList_New(0);
for (int32 i = 0; i < scene->GetPossessableCount(); i++)
{
FMovieScenePossessable possessable = scene->GetPossessable(i);
PyObject *py_possessable = PyUnicode_FromString(TCHAR_TO_UTF8(*possessable.GetGuid().ToString()));
PyList_Append(py_possessables, py_possessable);
}
return py_possessables;
}
#if WITH_EDITOR
PyObject *py_ue_sequencer_folders(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
if (!self->ue_object->IsA<ULevelSequence>())
return PyErr_Format(PyExc_Exception, "uobject is not a LevelSequence");
PyObject *py_obj = nullptr;
if (!PyArg_ParseTuple(args, "|O:sequencer_folders", &py_obj))
{
return NULL;
}
UMovieSceneFolder *parent_folder = nullptr;
if (py_obj)
{
ue_PyUObject *ue_py_obj = ue_is_pyuobject(py_obj);
if (!ue_py_obj)