-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommands_NiAVObject.cpp
More file actions
1169 lines (1087 loc) · 43.6 KB
/
Commands_NiAVObject.cpp
File metadata and controls
1169 lines (1087 loc) · 43.6 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 "Commands_NiAVObject.h"
#include "obj/NiObject.h"
#include "obj/NiObjectNET.h"
#include "obj/NiAVObject.h"
using Niflib::NiAVObjectRef;
#include "NiProperties.h"
#include "obj/NiCollisionObject.h"
#include "Command_Macros.h"
// gets the local transformation of the
// specified NiAVObject
static bool Cmd_NiAVObjectGetLocalTransform_Execute(COMMAND_ARGS) {
*result = 0;
vector<OBSEElement> vmatrix = vector<OBSEElement>();
OBSEArray* omatrix = NULL;
int nifID = -1;
UInt32 blockID = 0;
if (ExtractArgs(PASS_EXTRACT_ARGS, &nifID, &blockID)) {
UInt8 modID = scriptObj->GetModIndex();
dPrintAndLog("NiAVObjectGetLocalTransform","Getting local Transform of Child #"+UIntToString(blockID)+" of nif #"+UIntToString(modID)+"-"+UIntToString(nifID));
NifFile* nifPtr = NULL;
if ( NifFile::getRegNif(modID, nifID, nifPtr) ) {
if ( nifPtr->root ) {
if ( blockID < nifPtr->nifList.size() ) {
NiAVObjectRef avObj = Niflib::DynamicCast<Niflib::NiAVObject>(nifPtr->nifList[blockID]);
if ( avObj ) {
try {
Niflib::Matrix44 nmatrix = avObj->GetLocalTransform();
vector<vector<OBSEElement> > vrow;
OBSEArray* orow = NULL;
for ( int i = 0; i < 4; ++i ) {
vrow.push_back(vector<OBSEElement>());
for ( int j = 0; j < 4; ++j ) {
vrow[i].push_back(nmatrix.rows[i][j]);
}
orow = ArrayFromStdVector(vrow[i], scriptObj);
vmatrix.push_back(orow);
}
omatrix = ArrayFromStdVector(vmatrix, scriptObj);
}
catch (std::exception e) {
omatrix = NULL;
dPrintAndLog("NiAVObjectGetLocalTransform","Exception \""+string(e.what())+"\" thrown.");
}
}
else
dPrintAndLog("NiAVObjectGetLocalTransform","Not NiAVObject.");
}
else
dPrintAndLog("NiAVObjectGetLocalTransform","Block index out of range.");
}
else
dPrintAndLog("NiAVObjectGetLocalTransform","Nif root bad.");
}
else
dPrintAndLog("NiAVObjectGetLocalTransform","Could not find Nif.");
}
else
dPrintAndLog("NiAVObjectGetLocalTransform","Error extracting arguments");
if ( arrInterface->AssignCommandResult(omatrix, result) )
dPrintAndLog("NiAVObjectGetLocalTransform","Returning child's local transform.\n");
else
dPrintAndLog("NiAVObjectGetLocalTransform","Failed to create and return array.\n");
return true;
}
DEFINE_CMD_PLUGIN_ALT(
NiAVObjectGetLocalTransform,
NiAVObjGetLocTransf,
"Gets the local transform of the Nth Child of the given Nif.",
0,
kParams_OneInt_OneOptionalInt
);
// gets the local translation of the
// specified NiAVObject
static bool Cmd_NiAVObjectGetLocalTranslation_Execute(COMMAND_ARGS) {
*result = 0;
OBSEArray* arr = NULL;
int nifID = -1;
UInt32 blockID = 0;
if (ExtractArgs(PASS_EXTRACT_ARGS, &nifID, &blockID)) {
UInt8 modID = scriptObj->GetModIndex();
dPrintAndLog("NiAVObjectGetLocalTranslation","Getting local Translation of Child #"+UIntToString(blockID)+" of nif #"+UIntToString(modID)+"-"+UIntToString(nifID));
NifFile* nifPtr = NULL;
if ( NifFile::getRegNif(modID, nifID, nifPtr) ) {
if ( nifPtr->root ) {
if ( blockID < nifPtr->nifList.size() ) {
NiAVObjectRef avObj = Niflib::DynamicCast<Niflib::NiAVObject>(nifPtr->nifList[blockID]);
if ( avObj ) {
try {
Niflib::Vector3 ntransl = avObj->GetLocalTranslation();
vector<OBSEElement> vtransl;
vtransl.push_back(ntransl.x);
vtransl.push_back(ntransl.y);
vtransl.push_back(ntransl.z);
arr = ArrayFromStdVector(vtransl, scriptObj);
}
catch (std::exception e) {
arr = NULL;
dPrintAndLog("NiAVObjectGetLocalTranslation","Exception \""+string(e.what())+"\" thrown.");
}
}
else
dPrintAndLog("NiAVObjectGetLocalTranslation","Not NiAVObject.");
}
else
dPrintAndLog("NiAVObjectGetLocalTranslation","Block index out of range.");
}
else
dPrintAndLog("NiAVObjectGetLocalTranslation","Nif root bad.");
}
else
dPrintAndLog("NiAVObjectGetLocalTranslation","Could not find Nif.");
}
else
dPrintAndLog("NiAVObjectGetLocalTranslation","Error extracting arguments");
if ( arrInterface->AssignCommandResult(arr, result) )
dPrintAndLog("NiAVObjectGetLocalTranslation","Returning child's local translation.\n");
else
dPrintAndLog("NiAVObjectGetLocalTranslation","Failed to create and return array.\n");
return true;
}
DEFINE_CMD_PLUGIN_ALT(
NiAVObjectGetLocalTranslation,
NiAVObjGetLocTransl,
"Gets the local translation of the Nth Child of the given Nif.",
0,
kParams_OneInt_OneOptionalInt
);
// gets the local rotation of the
// specified NiAVObject
static bool Cmd_NiAVObjectGetLocalRotation_Execute(COMMAND_ARGS) {
*result = 0;
vector<OBSEElement> vmatrix = vector<OBSEElement>();
OBSEArray* omatrix = NULL;
int nifID = -1;
UInt32 blockID = 0;
if (ExtractArgs(PASS_EXTRACT_ARGS, &nifID, &blockID)) {
UInt8 modID = scriptObj->GetModIndex();
dPrintAndLog("NiAVObjectGetLocalRotation","Getting local Rotation of Child #"+UIntToString(blockID)+" of nif #"+UIntToString(modID)+"-"+UIntToString(nifID));
NifFile* nifPtr = NULL;
if ( NifFile::getRegNif(modID, nifID, nifPtr) ) {
if ( nifPtr->root ) {
if ( blockID < nifPtr->nifList.size() ) {
NiAVObjectRef avObj = Niflib::DynamicCast<Niflib::NiAVObject>(nifPtr->nifList[blockID]);
if ( avObj ) {
try {
Niflib::Matrix33 nmatrix = avObj->GetLocalRotation();
vector<vector<OBSEElement> > vrow;
OBSEArray* orow = NULL;
for ( int i = 0; i < 3; ++i ) {
vrow.push_back(vector<OBSEElement>());
for ( int j = 0; j < 3; ++j ) {
vrow[i].push_back(nmatrix.rows[i][j]);
}
orow = ArrayFromStdVector(vrow[i], scriptObj);
vmatrix.push_back(orow);
}
omatrix = ArrayFromStdVector(vmatrix, scriptObj);
}
catch (std::exception e) {
omatrix = NULL;
dPrintAndLog("NiAVObjectGetLocalRotation","Exception \""+string(e.what())+"\" thrown.");
}
}
else
dPrintAndLog("NiAVObjectGetLocalRotation","Selected block is not an AV Object.");
}
else
dPrintAndLog("NiAVObjectGetLocalRotation","Block index is out of range.");
}
else
dPrintAndLog("NiAVObjectGetLocalRotation","Nif root is bad.");
}
else
dPrintAndLog("NiAVObjectGetLocalRotation","Nif is not registered.");
}
else
dPrintAndLog("NiAVObjectGetLocalRotation","Failed to extract arguments.");
if ( arrInterface->AssignCommandResult(omatrix, result) )
dPrintAndLog("NiAVObjectGetLocalRotation","Returning child's local rotation.\n");
else
dPrintAndLog("NiAVObjectGetLocalRotation","Failed to create and return array.\n");
return true;
}
DEFINE_CMD_PLUGIN_ALT(
NiAVObjectGetLocalRotation,
NiAVObjGetLocRot,
"Gets the local rotation of the Nth Child of the given Nif.",
0,
kParams_OneInt_OneOptionalInt
);
// gets the local scale of the
// specified NiAVObject
static bool Cmd_NiAVObjectGetLocalScale_Execute(COMMAND_ARGS) {
*result = 0;
int nifID = -1;
UInt32 blockID = 0;
if (ExtractArgs(PASS_EXTRACT_ARGS, &nifID, &blockID)) {
UInt8 modID = scriptObj->GetModIndex();
dPrintAndLog("NiAVObjectGetLocalScale","Getting local Scale of Child #"+UIntToString(blockID)+" of nif #"+UIntToString(modID)+"-"+UIntToString(nifID));
NifFile* nifPtr = NULL;
if ( NifFile::getRegNif(modID, nifID, nifPtr) ) {
if ( nifPtr->root ) {
if ( blockID < nifPtr->nifList.size() ) {
NiAVObjectRef avObj = Niflib::DynamicCast<Niflib::NiAVObject>(nifPtr->nifList[blockID]);
if ( avObj ) {
try {
*result = avObj->GetLocalScale();
dPrintAndLog("NiAVObjectGetLocalScale","Returning "+FloatToString(*result)+".\n");
}
catch (std::exception e) {
*result = 0;
dPrintAndLog("NiAVObjectGetLocalTransform","Exception \""+string(e.what())+"\" thrown.\n");
}
}
else
dPrintAndLog("NiAVObjectGetLocalScale","Not NiAVObject.\n");
}
else
dPrintAndLog("NiAVObjectGetLocalScale","Block index out of range.\n");
}
else
dPrintAndLog("NiAVObjectGetLocalScale","Nif root bad.\n");
}
else
dPrintAndLog("NiAVObjectGetLocalScale","Could not find Nif.\n");
}
else
dPrintAndLog("NiAVObjectGetLocalScale","Error extracting arguments\n");
return true;
}
DEFINE_CMD_PLUGIN_ALT(
NiAVObjectGetLocalScale,
NiAVObjGetLocScale,
"Gets the local scale of the Nth Child of the given Nif.",
0,
kParams_OneInt_OneOptionalInt
);
// sets the local transformation of the
// specified NiAVObject
static bool Cmd_NiAVObjectSetLocalTransform_Execute(COMMAND_ARGS) {
*result = 0;
OBSEArray* arr = NULL;
int nifID = -1;
UInt32 blockID = 0;
UInt8 modID;
if (ExtractArgs(PASS_EXTRACT_ARGS, &arr, &nifID, &blockID)) {
modID = scriptObj->GetModIndex();
dPrintAndLog("NiAVObjectSetLocalTransform","Setting local Transform of Child #"+UIntToString(blockID)+" of nif #"+UIntToString(modID)+"-"+UIntToString(nifID));
if ( arr ) {
UInt32 arrSize = arrInterface->GetArraySize(arr);
if ( arrSize == 4 ) {
vector<OBSEArray*> row = vector<OBSEArray*>();
OBSEElement ele;
arrInterface->GetElement(arr, (double)0, ele);
row.push_back(ele.Array());
arrInterface->GetElement(arr, (double)1, ele);
row.push_back(ele.Array());
arrInterface->GetElement(arr, (double)2, ele);
row.push_back(ele.Array());
arrInterface->GetElement(arr, (double)3, ele);
row.push_back(ele.Array());
if ( row[0] && row[1] && row[2] && row[3] ) {
unsigned long row0Size = arrInterface->GetArraySize(row[0]);
unsigned long row1Size = arrInterface->GetArraySize(row[1]);
unsigned long row2Size = arrInterface->GetArraySize(row[2]);
unsigned long row3Size = arrInterface->GetArraySize(row[3]);
if ( row0Size == 4 && row1Size == 4 && row2Size ==4 && row3Size == 4 ) {
NifFile* nifPtr = NULL;
if ( NifFile::getRegNif(modID, nifID, nifPtr) ) {
if ( nifPtr->root ) {
if ( nifPtr->editable ) {
if ( blockID < nifPtr->nifList.size() ) {
NiAVObjectRef avObj = Niflib::DynamicCast<Niflib::NiAVObject>(nifPtr->nifList[blockID]);
if ( avObj ) {
Niflib::Matrix44 newTransform (0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
for ( UInt32 i = 0; i < 4; ++i ) {
for ( UInt32 j = 0; j < 4; ++j ) {
arrInterface->GetElement(row[i], j, ele);
if ( ele.GetType() == OBSEArrayVarInterface::Element::kType_Numeric )
newTransform[i][j] = ele.Number();
else {
dPrintAndLog("NiAVObjectSetLocalTransform","Array element is not a number. Array must be a 4x4 matrix.\n");
return true;
}
}
}
try {
avObj->SetLocalTransform(newTransform);
*result = 1;
nifPtr->logChange(blockID,kNiflibType_NiAVObject,kNiAVObjAct_SetLocTransf,MatrixToString(newTransform),true);
dPrintAndLog("NiAVObjectSetLocalTransform","Local transform set.\n");
}
catch (std::exception e) {
*result = 0;
dPrintAndLog("NiAVObjectSetLocalTransform","Exception \""+string(e.what())+"\" thrown.\n");
}
}
else
dPrintAndLog("NiAVObjectSetLocalTransform","Not NiAVObject.\n");
}
else
dPrintAndLog("NiAVObjectSetLocalTransform","Block index out of range.\n");
}
else
dPrintAndLog("NiAVObjectSetLocalTransform","Nif is not editable.\n");
}
else
dPrintAndLog("NiAVObjectSetLocalTransform","Nif root bad.\n");
}
else
dPrintAndLog("NiAVObjectSetLocalTransform","Could not find Nif.\n");
}
else
dPrintAndLog("NiAVObjectSetLocalTransform","Not every row has size 4. Array must be a 4x4 matrix.\n");
}
else
dPrintAndLog("NiAVObjectSetLocalTransform","Array is not fully 2-dimensional. Array must be 4x4 matrix.\n");
}
else
dPrintAndLog("NiAVObjectSetLocalTransform","Array does not have size 4. Array must be a 4x4 matrix.\n");
}
else
dPrintAndLog("NiAVObjectSetLocalTransform","Array not found.\n");
}
else
dPrintAndLog("NiAVObjectSetLocalTransform","Error extracting arguments.\n");
return true;
}
DEFINE_CMD_PLUGIN_ALT(
NiAVObjectSetLocalTransform,
NiAVObjSetLocTransf,
"Sets the local transform of the Nth Child of the given Nif.",
0,
kParams_OneArray_OneInt_OneOptionalInt
);
// sets the local translation of the
// specified NiAVObject
static bool Cmd_NiAVObjectSetLocalTranslation_Execute(COMMAND_ARGS) {
*result = 0;
OBSEArray* arr = NULL;
int nifID = -1;
UInt32 blockID = 0;
UInt8 modID;
if (ExtractArgs(PASS_EXTRACT_ARGS, &arr, &nifID, &blockID)) {
modID = scriptObj->GetModIndex();
dPrintAndLog("NiAVObjectSetLocalTranslation","Setting local Translation of Child #"+UIntToString(blockID)+" of nif #"+UIntToString(modID)+"-"+UIntToString(nifID));
if ( arr ) {
UInt32 arrSize = arrInterface->GetArraySize(arr);
if ( arrSize == 3 ) {
NifFile* nifPtr = NULL;
if ( NifFile::getRegNif(modID, nifID, nifPtr) ) {
if ( nifPtr->root ) {
if ( nifPtr->editable ) {
if ( blockID < nifPtr->nifList.size() ) {
NiAVObjectRef avObj = Niflib::DynamicCast<Niflib::NiAVObject>(nifPtr->nifList[blockID]);
if ( avObj ) {
OBSEElement ele;
Niflib::Vector3 newTranslation (0,0,0);
for ( UInt32 i = 0; i < 3; ++i ) {
arrInterface->GetElement(arr, i, ele);
if ( ele.GetType() == OBSEElement::kType_Numeric ) {
switch (i) {
case 0:
newTranslation.x = ele.Number();
dPrintAndLog("NiAVObjectSetLocalTranslation","x translation set to "+FloatToString(newTranslation.x));
break;
case 1:
newTranslation.y = ele.Number();
dPrintAndLog("NiAVObjectSetLocalTranslation","y translation set to "+FloatToString(newTranslation.y));
break;
case 2:
newTranslation.z = ele.Number();
dPrintAndLog("NiAVObjectSetLocalTranslation","z translation set to "+FloatToString(newTranslation.z));
break;
}
}
else {
dPrintAndLog("NiAVObjectSetLocalTranslation","Array element is not a number. Array must be a 3-vector.\n");
return true;
}
}
try {
avObj->SetLocalTranslation(newTranslation);
*result = 1;
nifPtr->logChange(blockID,kNiflibType_NiAVObject,kNiAVObjAct_SetLocTransl,VectorToString(newTranslation),true);
dPrintAndLog("NiAVObjectSetLocalTranslation","Local translation set.\n");
}
catch (std::exception e) {
*result = 0;
dPrintAndLog("NiAVObjectSetLocalTranslation","Exception \""+string(e.what())+"\" thrown.\n");
}
}
else
dPrintAndLog("NiAVObjectSetLocalTranslation","Not NiAVObject.\n");
}
else
dPrintAndLog("NiAVObjectSetLocalTranslation","Block index out of range.\n");
}
else
dPrintAndLog("NiAVObjectSetLocalTranslation","Nif is not editable.\n");
}
else
dPrintAndLog("NiAVObjectSetLocalTranslation","Nif root bad.\n");
}
else
dPrintAndLog("NiAVObjectSetLocalTranslation","Could not find Nif.\n");
}
else
dPrintAndLog("NiAVObjectSetLocalTranslation","Array does not have size 3. Array must be a 3-vector.\n");
}
else
dPrintAndLog("NiAVObjectSetLocalTranslation","Array not found.\n");
}
else
dPrintAndLog("NiAVObjectSetLocalTranslation","Error extracting arguments.\n");
return true;
}
DEFINE_CMD_PLUGIN_ALT(
NiAVObjectSetLocalTranslation,
NiAVObjSetLocTransl,
"Sets the local translation of the Nth Child of the given Nif.",
0,
kParams_OneArray_OneInt_OneOptionalInt
);
// sets the local rotation of the
// specified NiAVObject
static bool Cmd_NiAVObjectSetLocalRotation_Execute(COMMAND_ARGS) {
*result = 0;
OBSEArray* arr = NULL;
int nifID = -1;
UInt32 blockID = 0;
UInt8 modID;
if (ExtractArgs(PASS_EXTRACT_ARGS, &arr, &nifID, &blockID)) {
modID = scriptObj->GetModIndex();
dPrintAndLog("NiAVObjectSetLocalRotation","Setting local Rotation of Child #"+UIntToString(blockID)+" of nif #"+UIntToString(modID)+"-"+UIntToString(nifID));
if ( arr ) {
UInt32 arrSize = arrInterface->GetArraySize(arr);
if ( arrSize == 3 ) {
vector<OBSEArray*> row = vector<OBSEArray*>();
OBSEElement ele;
arrInterface->GetElement(arr, (double)0, ele);
row.push_back(ele.Array());
arrInterface->GetElement(arr, (double)1, ele);
row.push_back(ele.Array());
arrInterface->GetElement(arr, (double)2, ele);
row.push_back(ele.Array());
if ( row[0] && row[1] && row[2] ) {
unsigned long row0Size = arrInterface->GetArraySize(row[0]);
unsigned long row1Size = arrInterface->GetArraySize(row[1]);
unsigned long row2Size = arrInterface->GetArraySize(row[2]);
if ( row0Size == 3 && row1Size == 3 && row2Size == 3 ) {
NifFile* nifPtr = NULL;
if ( NifFile::getRegNif(modID, nifID, nifPtr) ) {
if ( nifPtr->root ) {
if ( nifPtr->editable ) {
if ( blockID < nifPtr->nifList.size() ) {
NiAVObjectRef avObj = Niflib::DynamicCast<Niflib::NiAVObject>(nifPtr->nifList[blockID]);
if ( avObj ) {
Niflib::Matrix33 newRotation (0,0,0,0,0,0,0,0,0);
for ( UInt32 i = 0; i < 3; ++i ) {
for ( UInt32 j = 0; j < 3; ++j ) {
if ( arrInterface->GetElement(row[i], j, ele) ) {
if ( ele.GetType() == OBSEArrayVarInterface::Element::kType_Numeric )
newRotation[i][j] = ele.Number();
else {
dPrintAndLog("NiAVObjectSetLocalRotation","Array element is not a number. Array must be a 3x3 matrix.\n");
return true;
}
}
else
dPrintAndLog("NiAVObjectSetLocalRotation","Array element could not be gotten.\n");
}
}
try {
avObj->SetLocalRotation(newRotation);
*result = 1;
nifPtr->logChange(blockID,kNiflibType_NiAVObject,kNiAVObjAct_SetLocRot,MatrixToString(newRotation),true);
dPrintAndLog("NiAVObjectSetLocalRotation","Local rotation set.\n");
}
catch (std::exception e) {
*result = 0;
dPrintAndLog("NiAVObjectSetLocalRotation","Exception \""+string(e.what())+"\" thrown.\n");
}
}
else
dPrintAndLog("NiAVObjectSetLocalRotation","Child not found.\n");
}
else
dPrintAndLog("NiAVObjectSetLocalRotation","Child index out of range.\n");
}
else
dPrintAndLog("NiAVObjectSetLocalRotation","Nif not editable.\n");
}
else
dPrintAndLog("NiAVObjectSetLocalRotation","Nif not found.\n");
}
else
dPrintAndLog("NiAVObjectSetLocalRotation","Nif not found.\n");
}
else
dPrintAndLog("NiAVObjectSetLocalRotation","Not every row has size 3. Array must be a 3x3 matrix.\n");
}
else
dPrintAndLog("NiAVObjectSetLocalRotation","Array is not fully 2-dimensional. Array must be 3x3 matrix.\n");
}
else
dPrintAndLog("NiAVObjectSetLocalRotation","Array does not have size 3. Array must be a 3x3 matrix.\n");
}
else
dPrintAndLog("NiAVObjectSetLocalRotation","Array not found.\n");
}
else
dPrintAndLog("NiAVObjectSetLocalRotation","Error extracting arguments.\n");
return true;
}
DEFINE_CMD_PLUGIN_ALT(
NiAVObjectSetLocalRotation,
NiAVObjSetLocRot,
"Sets the local rotation of the Nth Child of the given Nif.",
0,
kParams_OneArray_OneInt_OneOptionalInt
);
// sets the local scale of the
// specified NiAVObject
static bool Cmd_NiAVObjectSetLocalScale_Execute(COMMAND_ARGS) {
*result = 0;
float nuScale = 0;
int nifID = -1;
UInt32 blockID = 0;
UInt8 modID;
if (ExtractArgs(PASS_EXTRACT_ARGS, &nuScale, &nifID, &blockID)) {
modID = scriptObj->GetModIndex();
dPrintAndLog("NiAVObjectSetLocalScale","Setting local Scale of Child #"+UIntToString(blockID)+" of nif #"+UIntToString(modID)+"-"+UIntToString(nifID));
NifFile* nifPtr = NULL;
if ( NifFile::getRegNif(modID, nifID, nifPtr) ) {
if ( nifPtr->root ) {
if ( nifPtr->editable ) {
if ( blockID < nifPtr->nifList.size() ) {
NiAVObjectRef avObj = Niflib::DynamicCast<Niflib::NiAVObject>(nifPtr->nifList[blockID]);
if ( avObj ) {
try {
avObj->SetLocalScale(nuScale);
*result = 1;
nifPtr->logChange(blockID,kNiflibType_NiAVObject,kNiAVObjAct_SetLocScale,FloatToString(nuScale),true);
dPrintAndLog("NiAVObjectSetLocalScale","Local scale set.\n");
}
catch (std::exception e) {
*result = 0;
dPrintAndLog("NiAVObjectSetLocalScale","Exception \""+string(e.what())+"\" thrown.\n");
}
}
else
dPrintAndLog("NiAVObjectSetLocalScale","Not NiAVObject.\n");
}
else
dPrintAndLog("NiAVObjectSetLocalScale","Block index out of range.\n");
}
else
dPrintAndLog("NiAVObjectSetLocalScale","Nif is not editable.\n");
}
else
dPrintAndLog("NiAVObjectSetLocalScale","Nif root bad.\n");
}
else
dPrintAndLog("NiAVObjectSetLocalScale","Could not find Nif.\n");
}
else
dPrintAndLog("NiAVObjectSetLocalScale","Error extracting arguments.\n");
return true;
}
DEFINE_CMD_PLUGIN_ALT(
NiAVObjectSetLocalScale,
NiAVObjSetLocScale,
"Sets the local scale of the chosen AVObject.",
0,
kParams_OneFloat_OneInt_OneOptionalInt
);
// gets the number of properties that the NiAVObject has
static bool Cmd_NiAVObjectGetNumProperties_Execute(COMMAND_ARGS) {
*result = 0;
int nifID = -1;
UInt32 blockID = 0;
if (ExtractArgs(PASS_EXTRACT_ARGS, &nifID, &blockID)) {
UInt8 modID = scriptObj->GetModIndex();
dPrintAndLog("NiAVObjectGetNumProperties","Getting the number of properties held by of Child #"+UIntToString(blockID)+" of nif #"+UIntToString(modID)+"-"+UIntToString(nifID));
NifFile* nifPtr = NULL;
if ( NifFile::getRegNif(modID, nifID, nifPtr) ) {
if ( nifPtr->root ) {
if ( blockID < nifPtr->nifList.size() ) {
NiAVObjectRef avObj = Niflib::DynamicCast<Niflib::NiAVObject>(nifPtr->nifList[blockID]);
if ( avObj ) {
try {
*result = avObj->GetProperties().size();
dPrintAndLog("NiAVObjectGetNumProperties","Returning "+UIntToString(*result)+".");
}
catch (std::exception e) {
*result = 0;
dPrintAndLog("NiAVObjectGetNumProperties","Exception \""+string(e.what())+"\" thrown.\n");
}
}
else
dPrintAndLog("NiAVObjectGetNumProperties","Not NiAVObject.\n");
}
else
dPrintAndLog("NiAVObjectGetNumProperties","Block index out of range.\n");
}
else
dPrintAndLog("NiAVObjectGetNumProperties","Nif root bad.\n");
}
else
dPrintAndLog("NiAVObjectGetNumProperties","Could not find Nif.\n");
}
else
dPrintAndLog("NiAVObjectGetNumProperties","Error extracting arguments.\n");
return true;
}
DEFINE_CMD_PLUGIN_ALT(
NiAVObjectGetNumProperties,
NiAVObjGetNumProps,
"Gets the number of properties to the given AVObject.",
0,
kParams_OneInt_OneOptionalInt
);
// gets an array of properties that the AVObject has
static bool Cmd_NiAVObjectGetProperties_Execute(COMMAND_ARGS) {
*result = 0;
OBSEArray* arr = NULL;
int nifID = -1;
UInt32 blockID = 0;
if (ExtractArgs(PASS_EXTRACT_ARGS, &nifID, &blockID)) {
UInt8 modID = scriptObj->GetModIndex();
dPrintAndLog("NiAVObjectGetProperties","Getting the properties held by of Child #"+UIntToString(blockID)+" of nif #"+UIntToString(modID)+"-"+UIntToString(nifID));
NifFile* nifPtr = NULL;
if ( NifFile::getRegNif(modID, nifID, nifPtr) ) {
if ( nifPtr->root ) {
if ( blockID < nifPtr->nifList.size() ) {
NiAVObjectRef avObj = Niflib::DynamicCast<Niflib::NiAVObject>(nifPtr->nifList[blockID]);
if ( avObj ) {
try {
vector<OBSEElement> prvec = vector<OBSEElement>();
vector<Niflib::NiPropertyRef> prs = avObj->GetProperties();
for ( vector<Niflib::NiPropertyRef>::iterator i = prs.begin(); i != prs.end(); ++i )
prvec.push_back((*i)->internal_block_number);
arr = ArrayFromStdVector(prvec, scriptObj);
}
catch (std::exception e) {
arr = NULL;
dPrintAndLog("NiAVObjectGetProperties","Exception \""+string(e.what())+"\" thrown.");
}
}
else
dPrintAndLog("NiAVObjectGetProperties","Not NiAVObject.");
}
else
dPrintAndLog("NiAVObjectGetProperties","Block index out of range.");
}
else
dPrintAndLog("NiAVObjectGetProperties","Nif root bad.");
}
else
dPrintAndLog("NiAVObjectGetProperties","Could not find Nif.");
}
else
dPrintAndLog("NiAVObjectGetProperties","Error extracting arguments.");
if ( arrInterface->AssignCommandResult(arr, result) )
dPrintAndLog("NiAVObjectGetProperties","Returning node's properties.\n");
else
dPrintAndLog("NiAVObjectGetProperties","Failed to create and return array.\n");
return true;
}
DEFINE_CMD_PLUGIN_ALT(
NiAVObjectGetProperties,
NiAVObjGetProps,
"Gets the properties to the given AVObject.",
0,
kParams_OneInt_OneOptionalInt
);
static bool Cmd_NiAVObjectGetPropertyByType_Execute(COMMAND_ARGS) {
*result = -1;
int prType = -1;
int nifID = -1;
UInt32 blockID = 0;
if (ExtractArgs(PASS_EXTRACT_ARGS, &prType, &nifID, &blockID)) {
UInt8 modID = scriptObj->GetModIndex();
dPrintAndLog("NiAVObjectGetPropertyByType","Getting the index of the \""+UIntToString(prType)+"\" Property of nif #"+UIntToString(modID)+"-"+UIntToString(nifID)+" block #"+UIntToString(blockID)+".");
NifFile* nifPtr = NULL;
if ( NifFile::getRegNif(modID, nifID, nifPtr) ) {
if ( nifPtr->root ) {
if ( blockID < nifPtr->nifList.size() ) {
Niflib::NiAVObjectRef avObj = Niflib::DynamicCast<Niflib::NiAVObject>(nifPtr->nifList[blockID]);
if ( avObj ) {
try {
Niflib::NiPropertyRef prRef = avObj->GetPropertyByType(*(getNiflibType(prType)));
if ( prRef ) {
*result = prRef->internal_block_number;
dPrintAndLog("NiAVObjectGetPropertyByType","Returning "+UIntToString(*result)+".\n");
}
else
dPrintAndLog("NiAVObjectGetPropertyByType","NiAVObject does not have a property of this type.\n");
}
catch (std::exception e) {
*result = -1;
dPrintAndLog("NiAVObjectGetPropertyByType","Exception \""+string(e.what())+"\" thrown.\n");
}
}
else
dPrintAndLog("NiAVObjectGetPropertyByType","Not NiAVObject.\n");
}
else
dPrintAndLog("NiAVObjectGetPropertyByType","Block index out of range.\n");
}
else
dPrintAndLog("NiAVObjectGetPropertyByType","Nif root bad.\n");
}
else
dPrintAndLog("NiAVObjectGetPropertyByType","Could not find Nif.\n");
}
else
dPrintAndLog("NiAVObjectGetPropertyByType","Error extracting arguments.\n");
return true;
}
DEFINE_CMD_PLUGIN_ALT(
NiAVObjectGetPropertyByType,
NiAVObjGetEDByType,
"Returns the index of the Property of the given type on the specified Nif.",
0,
kParams_TwoInts_OneOptionalInt
);
static bool Cmd_NiAVObjectAddProperty_Execute(COMMAND_ARGS) {
*result = 0;
char name[kMaxMessageLength];
UInt32 typeID = 0;
int nifID = -1;
UInt32 blockID = 0;
if (ExtractArgs(PASS_EXTRACT_ARGS, &name, &typeID, &nifID, &blockID)) {
UInt8 modID = scriptObj->GetModIndex();
dPrintAndLog("NiAVObjectAddProperty","Adding Property \""+string(name)+"\" of type #"+UIntToString(typeID)+" to nif #"+UIntToString(modID)+"-"+UIntToString(nifID)+" block #"+UIntToString(blockID)+".");
NifFile* nifPtr = NULL;
if ( NifFile::getRegNif(modID, nifID, nifPtr) ) {
if ( nifPtr->root ) {
if ( nifPtr->editable ) {
if ( blockID < nifPtr->nifList.size() ) {
Niflib::NiAVObjectRef avObj = Niflib::DynamicCast<Niflib::NiAVObject>(nifPtr->nifList[blockID]);
if ( avObj ) {
try {
*result = Util_NiAVObjectAddProperty(nifPtr, avObj, typeID, name);
nifPtr->logChange(avObj->internal_block_number,kNiflibType_NiAVObject,kNiAVObjAct_AddProp,UIntToString(typeID)+logValType+name);
dPrintAndLog("NiAVObjectAddProperty","Addition successful; property is block #"+UIntToString(*result)+".\n");
}
catch (std::exception e) {
*result = -1;
dPrintAndLog("NiAVObjectAddProperty","Addition failed; exception \""+string(e.what())+"\" thrown.");
}
}
else
dPrintAndLog("NiAVObjectAddProperty","Nif node not an extra-data-supporting type.\n");
}
else
dPrintAndLog("NiAVObjectAddProperty","Nif node index out of bounds.\n");
}
else
dPrintAndLog("NiAVObjectAddProperty","Nif not editable.\n");
}
else
dPrintAndLog("NiAVObjectAddProperty","Nif not found.\n");
}
else
dPrintAndLog("NiAVObjectAddProperty","Nif not found.\n");
}
else
dPrintAndLog("NiAVObjectAddProperty","Error extracting arguments.\n");
return true;
}
DEFINE_CMD_PLUGIN_ALT(
NiAVObjectAddProperty,
NiAVObjAddED,
"Adds an Property node of the given type to the given Nif",
0,
kParams_OneString_TwoInts_OneOptionalInt
);
static bool Cmd_NiAVObjectDeleteProperty_Execute(COMMAND_ARGS) {
*result = 0;
int nifID = -1;
int prID = -1;
UInt32 blockID = 0;
if (ExtractArgs(PASS_EXTRACT_ARGS, &prID, &nifID, &blockID)) {
UInt8 modID = scriptObj->GetModIndex();
dPrintAndLog("NiAVObjectDeleteProperty","Deleting Property with Block #"+UIntToString(prID)+" of nif #"+UIntToString(modID)+"-"+UIntToString(nifID)+" block #"+UIntToString(blockID)+".");
NifFile* nifPtr = NULL;
if ( NifFile::getRegNif(modID, nifID, nifPtr) ) {
if ( nifPtr->root ) {
if ( nifPtr->editable ) {
if ( blockID < nifPtr->nifList.size() ) {
Niflib::NiAVObjectRef avObj = Niflib::DynamicCast<Niflib::NiAVObject>(nifPtr->nifList[blockID]);
if ( avObj ) {
if ( prID < nifPtr->nifList.size() ) {
Niflib::NiPropertyRef pr = Niflib::DynamicCast<Niflib::NiProperty>(nifPtr->nifList[prID]);
if ( pr ) {
avObj->RemoveProperty(pr);
*result = 1;
dPrintAndLog("NiAVObjectDeleteProperty","Property deleted.\n");
nifPtr->logChange(blockID,kNiflibType_NiAVObject,kNiAVObjAct_DelProp,UIntToString(prID));
}
else
dPrintAndLog("NiAVObjectDeleteProperty","Block not NiProperty; not deleted. Block type: \""+nifPtr->nifList[prID]->GetType().GetTypeName()+"\".\n");
}
else
dPrintAndLog("NiAVObjectDeleteProperty","Block indicated for Property is out of range; block not deleted.\n");
}
else
dPrintAndLog("NiAVObjectDeleteProperty","Block not NiObjectNET; ExtraData not deleted. Block type: \""+nifPtr->nifList[blockID]->GetType().GetTypeName()+"\".\n");
}
else
dPrintAndLog("NiAVObjectDeleteProperty","Block indicated for ObjectNET is out of range; ExtraData not deleted.\n");
}
else
dPrintAndLog("NiAVObjectDeleteProperty","Nif is not editable.\n");
}
else
dPrintAndLog("NiAVObjectDeleteProperty","Nif root is bad.\n");
}
else
dPrintAndLog("NiAVObjectDeleteProperty","Nif not found.\n");
}
else
dPrintAndLog("NiAVObjectDeleteProperty","Could not extract arguments.\n");
return true;
}
DEFINE_CMD_PLUGIN_ALT(
NiAVObjectDeleteProperty,
NiAVObjDelED,
"Deletes the Nth block of the given Nif if it is an Property",
0,
kParams_TwoInts_OneOptionalInt
);
STDNIFLIBGET(NiAVObject, GetCollisionMode, NiAVObjGetCollMode, UInt, collision mode);
STDNIFLIBSETUINTCAST(NiAVObject, SetCollisionMode, NiAVObjSetCollMode, kNiAVObjAct_SetCollMode, true, collision mode, Niflib::NiAVObject::CollisionType);
STDNIFLIBGETBLOCK(NiAVObject, GetCollisionObject, NiAVObjectGetCollisionObject, NiAVObjGetCollObj, NiCollisionObject, collision object);
static bool Cmd_NiAVObjectClearCollisionObject_Execute(COMMAND_ARGS) {
*result = 0;
int nifID = -1;
UInt32 blockID = 0;
if (ExtractArgs(PASS_EXTRACT_ARGS, &nifID, &blockID)) {
UInt8 modID = scriptObj->GetModIndex();
dPrintAndLog("NiAVObjectClearCollisionObject", "Clearing the collision object of NiAVObject (nif " NIFIDSTR+").");
try {
GETBLOCK(NiAVObject, block);
if ( block->GetCollisionObject() )
block->GetCollisionObject()->SetTarget((Niflib::NiAVObject*)NULL);
block->SetCollisionObject((Niflib::NiCollisionObject*)NULL);
*result = 1;
dPrintAndLog("NiAVObjectClearCollisionObject", "Collision object cleared.\n");
} catch (std::exception e) {
*result = 0;
dPrintAndLog("NiAVObjectClearCollisionObject", "Exception \""+string(e.what())+"\" thrown.\n");
}
} else
dPrintAndLog("NiAVObjectClearCollisionObject", "Error extracting arguments.\n");
return true;
}
DEFINE_CMD_PLUGIN_ALT(
NiAVObjectClearCollisionObject,
NiAVObjClrCollObj,
"Clears the collision object of the given NiAVObject.",
0,
kParams_OneInt_OneOptionalInt
);
static bool Cmd_NiAVObjectCopyCollisionObject_Execute(COMMAND_ARGS) {
*result = 0;
int nifIDfrom = -1;
int blockIDfrom = -1;
int nifIDto = -1;
UInt32 blockIDto = 0;
if (ExtractArgs(PASS_EXTRACT_ARGS, &nifIDfrom, &blockIDfrom, &nifIDto, &blockIDto)) {
UInt8 modID = scriptObj->GetModIndex();
dPrintAndLog("NiAVObjectCopyCollisionObject","Copying NiCollisionObject (Nif #"+UIntToString(modID)+"-"+UIntToString(nifIDfrom)+" block #"+UIntToString(blockIDfrom)+") as the collision object of NiAVObject (Nif #"+UIntToString(modID)+"-"+UIntToString(nifIDto)+" block #"+UIntToString(blockIDto)+").");
NifFile* nifFromPtr = NULL;
NifFile* nifToPtr = NULL;
if ( NifFile::getRegNif(modID, nifIDfrom, nifFromPtr) && NifFile::getRegNif(modID, nifIDto, nifToPtr) ) {
try {
*result = Util_NiAVObjectCopyCollision(nifFromPtr, blockIDfrom, nifToPtr, blockIDto);
nifFromPtr->frzChange(nifToPtr);
nifToPtr->logChange(blockIDto, kNiflibType_NiAVObject, kNiAVObjAct_CopyCollObj, UIntToString(nifIDfrom) +logValType+ UIntToString(blockIDfrom));
dPrintAndLog("NiAVObjectCopyCollisionObject","Collision object successfully copied.\n");
}
catch (std::exception e) {
*result = 0;
dPrintAndLog("NiAVObjectCopyCollisionObject",e.what());
}
}
else
dPrintAndLog("NiAVObjectCopyCollisionObject","Nif to copy to not found.\n");
}
else
dPrintAndLog("NiAVObjectCopyCollisionObject","Error extracting arguments.\n");
return true;
}
DEFINE_CMD_PLUGIN_ALT(
NiAVObjectCopyCollisionObject,
NiAVObjCopyCollObj,
"Copies the collision object of the first Nif as the collision object of the NiAVObject of the second Nif.",
0,
kParams_ThreeInts_OneOptionalInt
);
UInt32 Util_NiAVObjectAddProperty(NifFile* nifPtr, Niflib::NiAVObjectRef avObj, UInt32 typeID, const string& name) {
Niflib::NiPropertyRef nuProp = Niflib::DynamicCast<Niflib::NiProperty>(getNiflibType(typeID)->Create());
if ( nuProp ) {
nuProp->SetName(name);
nuProp->internal_block_number = nifPtr->nifList.size();
avObj->AddProperty(nuProp);
nifPtr->nifList.push_back(Niflib::StaticCast<Niflib::NiObject>(nuProp));
return nuProp->internal_block_number;
}
else
throw std::exception("Passed type is not derived from NiProperty.");
}
UInt32 Util_NiAVObjectCopyCollision(NifFile* nifFromPtr, UInt32 blockIDfrom, NifFile* nifToPtr, UInt32 blockIDto) {
try {
if ( nifFromPtr->root && nifToPtr->root ) {
if ( nifToPtr->editable ) {
if ( blockIDfrom < nifFromPtr->nifList.size() && blockIDto < nifToPtr->nifList.size() ) {
Niflib::NiNodeRef avObj = Niflib::DynamicCast<Niflib::NiNode>(nifToPtr->nifList[blockIDto]);
Niflib::NiCollisionObjectRef coll = Niflib::DynamicCast<Niflib::NiCollisionObject>(nifFromPtr->nifList[blockIDfrom]);
if ( avObj && coll ) {
coll->SetTarget(NULL);
std::stringstream* nifStream = new std::stringstream(std::ios::binary|std::ios::in|std::ios::out);
Niflib::WriteNifTree(*nifStream, Niflib::StaticCast<Niflib::NiObject>(coll), *(nifFromPtr->headerInfo));
vector<Niflib::NiObjectRef> copiedBranch = Niflib::ReadNifList(*nifStream, nifFromPtr->headerInfo);
if ( !(copiedBranch.empty()) ) {