forked from izrik/FbxSharp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFbxProperty.cs
685 lines (550 loc) · 18.9 KB
/
FbxProperty.cs
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
using System;
using System.Collections.Generic;
using System.Linq;
namespace FbxSharp
{
public abstract class FbxProperty
{
static FbxProperty()
{
AddConverter(typeof(FbxVector4), typeof(FbxVector3), (v4) => ((FbxVector4)v4).ToVector3());
AddConverter(typeof(FbxVector3), typeof(FbxVector4), (v3) => ((FbxVector3)v3).ToVector4());
}
protected FbxProperty(string name)
{
Name = name;
Children = new PropertyChildrenCollection(this);
SrcObjects = new PropertySrcObjectCollection(this);
DstObjects = new PropertyDstObjectCollection(this);
}
public override string ToString()
{
return string.Format("{0}: {1}", Name, GetValue());
}
#region Static Public Attributes
public static string sHierarchicalSeparator = "|";
#endregion
#region Property Identification
public string Name { get; protected set; }
public abstract Type PropertyDataType { get; }
public Type GetPropertyDataType()
{
return PropertyDataType;
}
//public Object FbxObject { get; protected set; }
//FbxDataType GetPropertyDataType()
public string GetName()
{
return Name;
}
public string GetHierarchicalName()
{
throw new NotImplementedException();
}
public string GetLabel(bool pReturnNameIfEmpty = true)
{
throw new NotImplementedException();
}
public void SetLabel(string pLabel)
{
throw new NotImplementedException();
}
private FbxObject _parentFbxObject;
public FbxObject ParentFbxObject
{
get { return _parentFbxObject; }
set
{
if (value != _parentFbxObject)
{
if (_parentFbxObject != null)
{
_parentFbxObject.Properties.Remove(this);
}
_parentFbxObject = value;
if (_parentFbxObject != null)
{
_parentFbxObject.Properties.Add(this);
}
}
}
}
public FbxObject GetFbxObject()
{
return ParentFbxObject;
}
#endregion
#region Value Management
public static readonly Dictionary<Tuple<Type,Type>, Func<object, object>> Converters = new Dictionary<Tuple<Type, Type>, Func<object, object>>();
public static void AddConverter(Type from, Type to, Func<object, object> converter)
{
Converters.Add(new Tuple<Type, Type>(from, to), converter);
}
public static bool HasDefaultValue(FbxProperty pProperty)
{
throw new NotImplementedException();
}
public virtual T Get<T>()
{
throw new NotImplementedException();
}
public virtual object GetValue()
{
throw new NotImplementedException();
}
public virtual bool Set<T>(T pValue)
{
throw new NotImplementedException();
}
public virtual bool Set(object value)
{
throw new NotImplementedException();
}
public virtual bool IsValid()
{
return true;
}
public FbxPropertyFlags.EInheritType GetValueInheritType()
{
throw new NotImplementedException();
}
public bool SetValueInheritType(FbxPropertyFlags.EInheritType pType)
{
throw new NotImplementedException();
}
public bool Modified()
{
throw new NotImplementedException();
}
#endregion
#region Hierarchical Properties
private FbxProperty _parentProperty;
public FbxProperty ParentProperty
{
get { return _parentProperty; }
set
{
if (value != _parentProperty)
{
if (_parentProperty != null)
{
_parentProperty.Children.Remove(this);
}
_parentProperty = value;
if (_parentProperty != null)
{
_parentProperty.Children.Add(this);
}
}
}
}
public readonly PropertyChildrenCollection Children;
public bool IsRoot()
{
return (ParentProperty == null);
}
public bool IsChildOf(FbxProperty pParent)
{
return (ParentProperty == pParent);
}
public bool IsDescendentOf(FbxProperty pAncestor)
{
var c = ParentProperty;
while (c != null)
{
if (c == pAncestor) return true;
c = c.GetParent();
}
return false;
}
public FbxProperty GetParent()
{
return ParentProperty;
}
public /*FBX_DEPRECATED*/ bool SetParent(FbxProperty pOther)
{
//throw new NotImplementedException();
//ParentProperty = pOther;
return false;
}
public FbxProperty GetChild()
{
return Children.FirstOrDefault();
}
public FbxProperty GetSibling()
{
if (GetParent() == null) return null;
return GetParent().GetNextDescendent(this);
}
public FbxProperty GetFirstDescendent()
{
return Children.FirstOrDefault();
}
public FbxProperty GetNextDescendent(FbxProperty pProperty)
{
if (pProperty.ParentProperty != this) return null;
var index = Children.IndexOf(pProperty);
if (index + 1 >= Children.Count) return null;
return Children[index + 1];
}
public FbxProperty Find(string pName, bool pCaseSensitive = true)
{
throw new NotImplementedException();
}
//public Property Find(string pName, FbxDataType &pDataType, bool pCaseSensitive=true)
//{
// throw new NotImplementedException();
//}
public FbxProperty FindHierarchical(string pName, bool pCaseSensitive = true)
{
throw new NotImplementedException();
}
//public Property FindHierarchical(string pName, FbxDataType &pDataType, bool pCaseSensitive=true)
//{
// throw new NotImplementedException();
//}
#endregion
#region Animation Curve Management
public FbxAnimEvaluator GetAnimationEvaluator()
{
throw new NotImplementedException();
}
public bool IsAnimated(FbxAnimLayer pAnimLayer=null)
{
// TODO: curve node shouold have channels and curves attached
// TODO: curve node should be attached to scene, stack, and layer
// TODO: pAnimLayer parameter
return (GetCurveNode() != null);
}
public T EvaluateValue<T>()
{
return EvaluateValue<T>(FbxTime.Infinite);
}
public T EvaluateValue<T>(FbxTime pTime, bool pForceEval=false)
{
if (IsAnimated())
{
var acn = GetCurveNode();
float[] values = new float[4]{0,0,0,0};
uint i;
for (i = 0; i < Math.Min(4, acn.GetChannelsCount()); i++)
{
if (acn.GetCurveCount(i) < 1)
//throw new NotImplementedException(
// string.Format(
// "The AnimCurveNode channel #{0} doesn't have any curves attached", i));
continue;
var curve = acn.GetCurve(i);
values[i] = curve.Evaluate(pTime);
}
var type = typeof(T);
if (type == typeof(float))
return (T)(object)values[0];
if (type == typeof(double))
return (T)(object)(double)values[0];
if (type == typeof(FbxVector2))
return (T)(object)(new FbxVector2(values[0], values[1]));
if (type == typeof(FbxVector3))
return (T)(object)(new FbxVector3(values[0], values[1], values[2]));
if (type == typeof(FbxVector4))
return (T)(object)(new FbxVector4(values[0], values[1], values[2], values[3]));
throw new NotImplementedException(
string.Format(
"The property \"{0}\" cannot be evaluated because " +
"the type is not a float, double, or vector",
this.Name));
}
else
{
return Get<T>();
}
}
public /*FbxPropertyValue*/object EvaluateValue()
{
return EvaluateValue(FbxTime.Infinite);
}
public /*FbxPropertyValue*/object EvaluateValue(FbxTime pTime, bool pForceEval=false)
{
throw new NotImplementedException();
}
public FbxAnimCurveNode CreateCurveNode(FbxAnimLayer pAnimLayer)
{
throw new NotImplementedException();
}
public FbxAnimCurveNode GetCurveNode(bool pCreate=false)
{
if (this.ParentFbxObject == null || this.ParentFbxObject.Scene == null) return null;
var stack = this.ParentFbxObject.Scene.GetCurrentAnimationStack();
return GetCurveNode(stack);
}
public FbxAnimCurveNode GetCurveNode(FbxAnimStack pAnimStack, bool pCreate=false)
{
if (pAnimStack == null) return null;
var currentLayers = new HashSet<FbxAnimLayer>(pAnimStack.GetSrcObjects<FbxAnimLayer>());
return (FbxAnimCurveNode)SrcObjects.FirstOrDefault(x =>
{
if (!(x is FbxAnimCurveNode)) return false;
var acn = (FbxAnimCurveNode)x;
var layers = new HashSet<FbxAnimLayer>(acn.GetDstObjects<FbxAnimLayer>());
return layers.Intersect(currentLayers).Any();
});
}
public FbxAnimCurveNode GetCurveNode(FbxAnimLayer pAnimLayer, bool pCreate=false)
{
throw new NotImplementedException();
}
public FbxAnimCurve GetCurve(FbxAnimLayer pAnimLayer, bool pCreate=false)
{
throw new NotImplementedException();
}
public FbxAnimCurve GetCurve(FbxAnimLayer pAnimLayer, string pChannel, bool pCreate=false)
{
throw new NotImplementedException();
}
public FbxAnimCurve GetCurve(FbxAnimLayer pAnimLayer, string pName, string pChannel, bool pCreate)
{
throw new NotImplementedException();
}
#endregion
#region General Object Connection and Relationship Management
public readonly PropertySrcObjectCollection SrcObjects;
public readonly PropertyDstObjectCollection DstObjects;
public bool ConnectSrcObject(FbxObject pObject/*, Connection.EType pType=Connection.EType.None*/)
{
if (SrcObjects.Contains(pObject))
return false;
SrcObjects.Add(pObject);
return true;
}
public bool IsConnectedSrcObject(FbxObject pObject)
{
return SrcObjects.Contains(pObject);
}
public bool DisconnectSrcObject(FbxObject pObject)
{
return SrcObjects.Remove(pObject);
}
public bool DisconnectAllSrcObject()
{
foreach (var src in SrcObjects.ToArray())
{
DisconnectSrcObject(src);
}
return true;
}
//public bool DisconnectAllSrcObject(FbxCriteria pCriteria)
//{
// throw new NotImplementedException();
//}
public int GetSrcObjectCount()
{
return SrcObjects.Count;
}
//public int GetSrcObjectCount(FbxCriteria pCriteria)
//{
// throw new NotImplementedException();
//}
public FbxObject GetSrcObject(int pIndex=0)
{
return SrcObjects[pIndex];
}
//public FbxObject GetSrcObject(FbxCriteria pCriteria, int pIndex=0)
//{
// throw new NotImplementedException();
//}
public FbxObject FindSrcObject(string pName, int pStartIndex=0)
{
throw new NotImplementedException();
}
//public FbxObject FindSrcObject(FbxCriteria pCriteria, string pName, int pStartIndex=0)
//{
// throw new NotImplementedException();
//}
public bool DisconnectAllSrcObject<T>()
where T : FbxObject
{
throw new NotImplementedException();
}
//public bool DisconnectAllSrcObject<T>(FbxCriteria pCriteria)
// where T : FbxObject
//{
// throw new NotImplementedException();
//}
public int GetSrcObjectCount<T>()
where T : FbxObject
{
throw new NotImplementedException();
}
//public int GetSrcObjectCount<T>(FbxCriteria pCriteria)
// where T : FbxObject
//{
// throw new NotImplementedException();
//}
public T GetSrcObject<T>(int pIndex=0)
where T : FbxObject
{
throw new NotImplementedException();
}
//public T GetSrcObject<T>(FbxCriteria pCriteria, int pIndex=0)
// where T : FbxObject
//{
// throw new NotImplementedException();
//}
public T FindSrcObject<T>(string pName, int pStartIndex=0)
where T : FbxObject
{
throw new NotImplementedException();
}
//public T FindSrcObject<T>(FbxCriteria pCriteria, string pName, int pStartIndex=0)
// where T : FbxObject
//{
// throw new NotImplementedException();
//}
public bool ConnectDstObject(FbxObject pObject, FbxConnection.EType pType=FbxConnection.EType.None)
{
if (DstObjects.Contains(pObject))
return false;
DstObjects.Add(pObject);
return true;
}
public bool IsConnectedDstObject(FbxObject pObject)
{
return DstObjects.Contains(pObject);
}
public bool DisconnectDstObject(FbxObject pObject)
{
return DstObjects.Remove(pObject);
}
public bool DisconnectAllDstObject()
{
foreach (var dst in DstObjects.ToArray())
{
DisconnectDstObject(dst);
}
return true;
}
//public bool DisconnectAllDstObject(FbxCriteria pCriteria)
//{
// throw new NotImplementedException();
//}
public int GetDstObjectCount()
{
return DstObjects.Count;
}
//public int GetDstObjectCount(FbxCriteria pCriteria)
//{
// throw new NotImplementedException();
//}
public FbxObject GetDstObject(int pIndex=0)
{
return DstObjects[pIndex];
}
//public FbxObject GetDstObject(FbxCriteria pCriteria, int pIndex=0)
//{
// throw new NotImplementedException();
//}
public FbxObject FindDstObject(string pName, int pStartIndex=0)
{
throw new NotImplementedException();
}
//public FbxObject FindDstObject(FbxCriteria pCriteria, string pName, int pStartIndex=0)
//{
// throw new NotImplementedException();
//}
public bool DisconnectAllDstObject<T>()
where T : FbxObject
{
throw new NotImplementedException();
}
//public bool DisconnectAllDstObject<T>(FbxCriteria pCriteria)
// where T : FbxObject
//{
// throw new NotImplementedException();
//}
public int GetDstObjectCount<T>()
where T : FbxObject
{
throw new NotImplementedException();
}
//public int GetDstObjectCount<T>(FbxCriteria pCriteria)
// where T : FbxObject
//{
// throw new NotImplementedException();
//}
public T GetDstObject<T>(int pIndex=0)
where T : FbxObject
{
throw new NotImplementedException();
}
//public T GetDstObject<T>(FbxCriteria pCriteria, int pIndex=0)
// where T : FbxObject
//{
// throw new NotImplementedException();
//}
public T FindDstObject<T>(string pName, int pStartIndex=0)
where T : FbxObject
{
throw new NotImplementedException();
}
//public T FindDstObject<T>(FbxCriteria pCriteria, string pName, int pStartIndex=0)
// where T : FbxObject
//{
// throw new NotImplementedException();
//}
#endregion
#region General Property Connection and Relationship Management
public bool ConnectSrcProperty(FbxProperty pProperty)
{
throw new NotImplementedException();
}
public bool IsConnectedSrcProperty(FbxProperty pProperty)
{
throw new NotImplementedException();
}
public bool DisconnectSrcProperty(FbxProperty pProperty)
{
throw new NotImplementedException();
}
public int GetSrcPropertyCount()
{
throw new NotImplementedException();
}
public bool ConnectDstProperty(FbxProperty pProperty)
{
throw new NotImplementedException();
}
public bool IsConnectedDstProperty(FbxProperty pProperty)
{
throw new NotImplementedException();
}
public bool DisconnectDstProperty(FbxProperty pProperty)
{
throw new NotImplementedException();
}
public int GetDstPropertyCount()
{
throw new NotImplementedException();
}
public void ClearConnectCache()
{
throw new NotImplementedException();
}
public FbxProperty GetSrcProperty(int pIndex=0)
{
throw new NotImplementedException();
}
public FbxProperty FindSrcProperty(string pName, int pStartIndex=0)
{
throw new NotImplementedException();
}
public FbxProperty GetDstProperty(int pIndex=0)
{
throw new NotImplementedException();
}
public FbxProperty FindDstProperty(string pName, int pStartIndex=0)
{
throw new NotImplementedException();
}
#endregion
}
}