forked from izrik/FbxSharp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Node.cs
453 lines (395 loc) · 19.8 KB
/
Node.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
using System;
using System.Collections.Generic;
using System.Linq;
namespace FbxSharp
{
public class Node : FbxObject
{
public Node(string name="")
{
this.Properties.AddRange(
new Property[] {
LclTranslation,
LclRotation,
LclScaling,
Visibility,
VisibilityInheritance,
QuaternionInterpolate,
RotationOffset,
RotationPivot,
ScalingOffset,
ScalingPivot,
TranslationActive,
TranslationMin,
TranslationMax,
TranslationMinX,
TranslationMinY,
TranslationMinZ,
TranslationMaxX,
TranslationMaxY,
TranslationMaxZ,
RotationOrder,
RotationSpaceForLimitOnly,
RotationStiffnessX,
RotationStiffnessY,
RotationStiffnessZ,
AxisLen,
PreRotation,
PostRotation,
RotationActive,
RotationMin,
RotationMax,
RotationMinX,
RotationMinY,
RotationMinZ,
RotationMaxX,
RotationMaxY,
RotationMaxZ,
InheritType,
ScalingActive,
ScalingMin,
ScalingMax,
ScalingMinX,
ScalingMinY,
ScalingMinZ,
ScalingMaxX,
ScalingMaxY,
ScalingMaxZ,
GeometricTranslation,
GeometricRotation,
GeometricScaling,
MinDampRangeX,
MinDampRangeY,
MinDampRangeZ,
MaxDampRangeX,
MaxDampRangeY,
MaxDampRangeZ,
MinDampStrengthX,
MinDampStrengthY,
MinDampStrengthZ,
MaxDampStrengthX,
MaxDampStrengthY,
MaxDampStrengthZ,
PreferedAngleX,
PreferedAngleY,
PreferedAngleZ,
LookAtProperty,
UpVectorProperty,
Show,
NegativePercentShapeSupport,
DefaultAttributeIndex,
Freeze,
LODBox});
this.ChildNodes = SrcObjects.CreateCollectionView<Node>();
_parentNode = DstObjects.CreateObjectView<Node>();
DefaultAttributeIndex.Set(-1);
nodeAttributes = SrcObjects.CreateCollectionView<NodeAttribute>();
Materials = SrcObjects.CreateCollectionView<SurfaceMaterial>();
}
public bool MultiLayer;
public bool MultiTake;
public bool Shading;
public string Culling;
#region Node Tree Management
//Get the parent node.
public Node GetParent()
{
return ParentNode;
}
//Add a child node and its underlying node tree.
public bool AddChild(Node pNode)
{
if (pNode == null)
return false;
this.ConnectSrcObject(pNode);
return true;
}
void ConnectScene(FbxObject obj)
{
if (obj.Scene != this.Scene)
{
if (obj.Scene != null)
{
obj.DisconnectDstObject(obj.Scene);
}
if (this.Scene != null)
{
obj.ConnectDstObject(this.Scene);
}
}
var node = obj as Node;
if (node != null)
{
foreach (var child in node.ChildNodes)
{
ConnectScene(child);
}
}
}
//Remove the child node.
public Node RemoveChild(Node pNode)
{
if (this.DisconnectSrcObject(pNode))
{
return pNode;
}
return null;
}
public override bool DisconnectSrcObject(FbxObject pObject)
{
var ret = base.DisconnectSrcObject(pObject);
if (pObject is Node)
{
DisconnectScene((Node)pObject);
}
return ret;
}
void DisconnectScene(Node child)
{
if (child.Scene != null)
{
child.DisconnectDstObject(child.Scene);
}
foreach (var subchild in child.ChildNodes)
{
DisconnectScene(subchild);
}
}
//Get the number of children nodes.
public int GetChildCount()//bool pRecursive = false)
{
return ChildNodes.Count;
}
//Get child by index.
public Node GetChild(int pIndex)
{
return ChildNodes[pIndex];
}
private ObjectView<Node> _parentNode;
public Node ParentNode
{
get { return _parentNode.Get(); }
}
public readonly CollectionView<Node> ChildNodes;
//Finds a child node by name.
//FbxNode * FindChild (const char *pName, bool pRecursive=true, bool pInitial=false)
#endregion
#region Node Attribute Management
readonly CollectionView<NodeAttribute> nodeAttributes;
public NodeAttribute SetNodeAttribute(NodeAttribute pNodeAttribute)
{
ConnectSrcObject(pNodeAttribute);
if (DefaultAttributeIndex.Get() < 0)
{
DefaultAttributeIndex.Set(nodeAttributes.IndexOf(pNodeAttribute));
}
return pNodeAttribute;
}
public NodeAttribute GetNodeAttribute()
{
if (DefaultAttributeIndex.Get() < 0) return null;
if (DefaultAttributeIndex.Get() >= nodeAttributes.Count) return null;
return nodeAttributes[DefaultAttributeIndex.Get()];
}
public int GetNodeAttributeCount()
{
return nodeAttributes.Count;
}
public int GetDefaultNodeAttributeIndex()
{
return DefaultAttributeIndex.Get();
}
public bool SetDefaultNodeAttributeIndex(int pIndex /*, FbxStatus=null*/)
{
throw new NotImplementedException();
}
public NodeAttribute GetNodeAttributeByIndex(int pIndex)
{
return nodeAttributes[pIndex];
}
public int GetNodeAttributeIndex(NodeAttribute nodeattr /*, FbxStatus=null*/)
{
return nodeAttributes.IndexOf(nodeattr);
}
#endregion
#region Node Evaluation Functions
public AnimEvaluator GetAnimationEvaluator()
{
if (Scene != null)
return Scene.GetAnimationEvaluator();
return AnimEvaluator.Default;
}
public Matrix EvaluateGlobalTransform()
{
return EvaluateGlobalTransform(FbxTime.Infinite);
}
public Matrix EvaluateGlobalTransform(FbxTime pTime, Node.EPivotSet pPivotSet=Node.EPivotSet.eSourcePivot, bool pApplyTarget=false, bool pForceEval=false)
{
return GetAnimationEvaluator().GetNodeGlobalTransform(this, pTime, pPivotSet, pApplyTarget, pForceEval);
}
public Matrix EvaluateLocalTransform()
{
return EvaluateLocalTransform(FbxTime.Infinite);
}
public Matrix EvaluateLocalTransform(FbxTime pTime, Node.EPivotSet pPivotSet=Node.EPivotSet.eSourcePivot, bool pApplyTarget=false, bool pForceEval=false)
{
return GetAnimationEvaluator().GetNodeLocalTransform(this, pTime, pPivotSet, pApplyTarget, pForceEval);
}
public Vector4 EvaluateLocalTranslation()
{
return EvaluateLocalTranslation(FbxTime.Infinite);
}
public Vector4 EvaluateLocalTranslation(FbxTime pTime, Node.EPivotSet pPivotSet=Node.EPivotSet.eSourcePivot, bool pApplyTarget=false, bool pForceEval=false)
{
throw new NotImplementedException();
}
public Vector4 EvaluateLocalRotation()
{
return EvaluateLocalRotation(FbxTime.Infinite);
}
public Vector4 EvaluateLocalRotation(FbxTime pTime, Node.EPivotSet pPivotSet=Node.EPivotSet.eSourcePivot, bool pApplyTarget=false, bool pForceEval=false)
{
throw new NotImplementedException();
}
public Vector4 EvaluateLocalScaling()
{
return EvaluateLocalScaling(FbxTime.Infinite);
}
public Vector4 EvaluateLocalScaling(FbxTime pTime, Node.EPivotSet pPivotSet=Node.EPivotSet.eSourcePivot, bool pApplyTarget=false, bool pForceEval=false)
{
throw new NotImplementedException();
}
//public bool EvaluateGlobalBoundingBoxMinMaxCenter(out Vector4 pBBoxMin, out Vector4 pBBoxMax, out Vector4 pBBoxCenter, FbxTime pTime=FBXSDK_TIME_INFINITE)
//{
// throw new NotImplementedException();
//}
//public bool EvaluateRayIntersectionPoint(out Vector4 pOut, Vector4 pRayOrigin, Vector4 pRayDir, bool pCulling=false, FbxTime pTime=FBXSDK_TIME_INFINITE)
//{
// throw new NotImplementedException();
//}
#endregion
#region Material Management
public readonly CollectionView<SurfaceMaterial> Materials;
public int AddMaterial(SurfaceMaterial pMaterial)
{
ConnectSrcObject(pMaterial);
return Materials.IndexOf(pMaterial);
}
public bool RemoveMaterial(SurfaceMaterial pMaterial)
{
return DisconnectSrcObject(pMaterial);
}
public int GetMaterialCount()
{
return Materials.Count;
}
public SurfaceMaterial GetMaterial(int pIndex)
{
return Materials[pIndex];
}
public void RemoveAllMaterials()
{
foreach (var m in Materials.ToArray())
{
RemoveMaterial(m);
}
}
public int GetMaterialIndex(string pName)
{
return Materials.ToList().FindIndex(m => m.Name == pName);
}
#endregion
#region Public and Fast Access Properties
public PropertyT<Vector3> LclTranslation = new PropertyT<Vector3>("Lcl Translation");
public PropertyT<Vector3> LclRotation = new PropertyT<Vector3>("Lcl Rotation");
public PropertyT<Vector3> LclScaling = new PropertyT<Vector3>("Lcl Scaling", Vector3.One);
public PropertyT<double> Visibility = new PropertyT<double>("Visibility");
public PropertyT<bool> VisibilityInheritance = new PropertyT<bool>("Visibility Inheritance");
public PropertyT<EQuatInterpMode> QuaternionInterpolate = new PropertyT<EQuatInterpMode>("QuaternionInterpolate");
public PropertyT<Vector3> RotationOffset = new PropertyT<Vector3>("RotationOffset");
public PropertyT<Vector3> RotationPivot = new PropertyT<Vector3>("RotationPivot");
public PropertyT<Vector3> ScalingOffset = new PropertyT<Vector3>("ScalingOffset");
public PropertyT<Vector3> ScalingPivot = new PropertyT<Vector3>("ScalingPivot");
public PropertyT<bool> TranslationActive = new PropertyT<bool>("TranslationActive");
public PropertyT<Vector3> TranslationMin = new PropertyT<Vector3>("TranslationMin");
public PropertyT<Vector3> TranslationMax = new PropertyT<Vector3>("TranslationMax");
public PropertyT<bool> TranslationMinX = new PropertyT<bool>("TranslationMinX");
public PropertyT<bool> TranslationMinY = new PropertyT<bool>("TranslationMinY");
public PropertyT<bool> TranslationMinZ = new PropertyT<bool>("TranslationMinZ");
public PropertyT<bool> TranslationMaxX = new PropertyT<bool>("TranslationMaxX");
public PropertyT<bool> TranslationMaxY = new PropertyT<bool>("TranslationMaxY");
public PropertyT<bool> TranslationMaxZ = new PropertyT<bool>("TranslationMaxZ");
public PropertyT<ERotationOrder> RotationOrder = new PropertyT<ERotationOrder>("RotationOrder");
public PropertyT<bool> RotationSpaceForLimitOnly = new PropertyT<bool>("RotationSpaceForLimitOnly");
public PropertyT<double> RotationStiffnessX = new PropertyT<double>("RotationStiffnessX");
public PropertyT<double> RotationStiffnessY = new PropertyT<double>("RotationStiffnessY");
public PropertyT<double> RotationStiffnessZ = new PropertyT<double>("RotationStiffnessZ");
public PropertyT<double> AxisLen = new PropertyT<double>("AxisLen");
public PropertyT<Vector3> PreRotation = new PropertyT<Vector3>("PreRotation");
public PropertyT<Vector3> PostRotation = new PropertyT<Vector3>("PostRotation");
public PropertyT<bool> RotationActive = new PropertyT<bool>("RotationActive");
public PropertyT<Vector3> RotationMin = new PropertyT<Vector3>("RotationMin");
public PropertyT<Vector3> RotationMax = new PropertyT<Vector3>("RotationMax");
public PropertyT<bool> RotationMinX = new PropertyT<bool>("RotationMinX");
public PropertyT<bool> RotationMinY = new PropertyT<bool>("RotationMinY");
public PropertyT<bool> RotationMinZ = new PropertyT<bool>("RotationMinZ");
public PropertyT<bool> RotationMaxX = new PropertyT<bool>("RotationMaxX");
public PropertyT<bool> RotationMaxY = new PropertyT<bool>("RotationMaxY");
public PropertyT<bool> RotationMaxZ = new PropertyT<bool>("RotationMaxZ");
public PropertyT<Transform.EInheritType> InheritType = new PropertyT<Transform.EInheritType>("InheritType");
public PropertyT<bool> ScalingActive = new PropertyT<bool>("ScalingActive");
public PropertyT<Vector3> ScalingMin = new PropertyT<Vector3>("ScalingMin");
public PropertyT<Vector3> ScalingMax = new PropertyT<Vector3>("ScalingMax");
public PropertyT<bool> ScalingMinX = new PropertyT<bool>("ScalingMinX");
public PropertyT<bool> ScalingMinY = new PropertyT<bool>("ScalingMinY");
public PropertyT<bool> ScalingMinZ = new PropertyT<bool>("ScalingMinZ");
public PropertyT<bool> ScalingMaxX = new PropertyT<bool>("ScalingMaxX");
public PropertyT<bool> ScalingMaxY = new PropertyT<bool>("ScalingMaxY");
public PropertyT<bool> ScalingMaxZ = new PropertyT<bool>("ScalingMaxZ");
public PropertyT<Vector3> GeometricTranslation = new PropertyT<Vector3>("GeometricTranslation");
public PropertyT<Vector3> GeometricRotation = new PropertyT<Vector3>("GeometricRotation");
public PropertyT<Vector3> GeometricScaling = new PropertyT<Vector3>("GeometricScaling");
public PropertyT<double> MinDampRangeX = new PropertyT<double>("MinDampRangeX");
public PropertyT<double> MinDampRangeY = new PropertyT<double>("MinDampRangeY");
public PropertyT<double> MinDampRangeZ = new PropertyT<double>("MinDampRangeZ");
public PropertyT<double> MaxDampRangeX = new PropertyT<double>("MaxDampRangeX");
public PropertyT<double> MaxDampRangeY = new PropertyT<double>("MaxDampRangeY");
public PropertyT<double> MaxDampRangeZ = new PropertyT<double>("MaxDampRangeZ");
public PropertyT<double> MinDampStrengthX = new PropertyT<double>("MinDampStrengthX");
public PropertyT<double> MinDampStrengthY = new PropertyT<double>("MinDampStrengthY");
public PropertyT<double> MinDampStrengthZ = new PropertyT<double>("MinDampStrengthZ");
public PropertyT<double> MaxDampStrengthX = new PropertyT<double>("MaxDampStrengthX");
public PropertyT<double> MaxDampStrengthY = new PropertyT<double>("MaxDampStrengthY");
public PropertyT<double> MaxDampStrengthZ = new PropertyT<double>("MaxDampStrengthZ");
public PropertyT<double> PreferedAngleX = new PropertyT<double>("PreferedAngleX");
public PropertyT<double> PreferedAngleY = new PropertyT<double>("PreferedAngleY");
public PropertyT<double> PreferedAngleZ = new PropertyT<double>("PreferedAngleZ");
public PropertyT<FbxObject> LookAtProperty = new PropertyT<FbxObject>("LookAtProperty");
public PropertyT<FbxObject> UpVectorProperty = new PropertyT<FbxObject>("UpVectorProperty");
public PropertyT<bool> Show = new PropertyT<bool>("Show");
public PropertyT<bool> NegativePercentShapeSupport = new PropertyT<bool>("NegativePercentShapeSupport");
public PropertyT<int> DefaultAttributeIndex = new PropertyT<int>("DefaultAttributeIndex");
public PropertyT<bool> Freeze = new PropertyT<bool>("Freeze");
public PropertyT<bool> LODBox = new PropertyT<bool>("LODBox");
#endregion
public enum ERotationOrder
{
OrderXYZ,
OrderXZY,
OrderYZX,
OrderYXZ,
OrderZXY,
OrderZYX,
OrderSphericXYZ,
}
public enum EPivotSet
{
eSourcePivot,
eDestinationPivot,
}
public override string GetNameSpacePrefix()
{
return "Model::";
}
}
}