public void Node_SetNodeAttribute_SetsNodeAttribute() { // given: var node = new FbxNode("Node"); var nullattr = new FbxNull("nullattr"); // require: Assert.AreEqual(0, node.GetSrcObjectCount()); Assert.AreEqual(0, node.GetDstObjectCount()); Assert.AreEqual(0, node.GetSrcPropertyCount()); Assert.AreEqual(0, node.GetDstPropertyCount()); Assert.AreEqual(0, node.GetNodeAttributeCount()); Assert.AreEqual(null, node.GetNodeAttribute()); Assert.AreEqual(-1, node.GetDefaultNodeAttributeIndex()); Assert.AreEqual(0, nullattr.GetSrcObjectCount()); Assert.AreEqual(0, nullattr.GetDstObjectCount()); Assert.AreEqual(0, nullattr.GetSrcPropertyCount()); Assert.AreEqual(0, nullattr.GetDstPropertyCount()); Assert.AreEqual(0, nullattr.GetNodeCount()); // when: node.SetNodeAttribute(nullattr); // then: Assert.AreEqual(1, node.GetSrcObjectCount()); Assert.AreEqual(nullattr, node.GetSrcObject(0)); Assert.AreEqual(0, node.GetDstObjectCount()); Assert.AreEqual(0, node.GetSrcPropertyCount()); Assert.AreEqual(0, node.GetDstPropertyCount()); Assert.AreEqual(1, node.GetNodeAttributeCount()); Assert.AreEqual(nullattr, node.GetNodeAttribute()); Assert.AreEqual(0, node.GetDefaultNodeAttributeIndex()); Assert.AreEqual(nullattr, node.GetNodeAttributeByIndex(0)); Assert.AreEqual(0, nullattr.GetSrcObjectCount()); Assert.AreEqual(1, nullattr.GetDstObjectCount()); Assert.AreEqual(node, nullattr.GetDstObject(0)); Assert.AreEqual(0, nullattr.GetSrcPropertyCount()); Assert.AreEqual(0, nullattr.GetDstPropertyCount()); Assert.AreEqual(1, nullattr.GetNodeCount()); Assert.AreEqual(node, nullattr.GetNode()); Assert.AreEqual(node, nullattr.GetNode(0)); }
private GameObject ImportNodes( FbxNode node, float fbxUnitToTiltUnit, ref long completedVerts, long totalVerts) { FbxNodeAttribute a = node.GetNodeAttribute(); int nChildren = node.GetChildCount(); GameObject go = null; if (a != null) { var attrType = a.GetAttributeType(); if (attrType == FbxNodeAttribute.EType.eMesh) { go = ImportMesh( node, fbxUnitToTiltUnit, ref completedVerts, totalVerts); } else if (attrType == FbxNodeAttribute.EType.eNurbs || attrType == FbxNodeAttribute.EType.eSubDiv || attrType == FbxNodeAttribute.EType.eNurbsSurface) { warnings.Add("Ignoring non-mesh geometry"); } } for (int i = 0; i < nChildren; i++) { GameObject child = ImportNodes( node.GetChild(i), fbxUnitToTiltUnit, ref completedVerts, totalVerts); if (child != null) { if (go == null) { go = new GameObject("Node"); } child.transform.parent = go.transform; } } if (go != null) { ApplyTransform(node, go.transform, fbxUnitToTiltUnit); } return(go); }
public static FbxNodeAttribute[] GetAttributes(FbxNode node) { //не null только когда node.GetNodeAttributeCount()==1. Иначе использовать GetNodeAttributeByIndex var attribute = node.GetNodeAttribute(); if (attribute != null) { return new[] { attribute } } ; var ret = new FbxNodeAttribute[node.GetNodeAttributeCount()]; for (int i = 0; i < ret.Length; i++) { ret[i] = node.GetNodeAttributeByIndex(i); } return(ret); }
static void LoadSkinsFromNodeRecursive(FbxNode pNode, List <FbxSkin> skinsResult) { FbxNodeAttribute pNodeAttribute = pNode.GetNodeAttribute(); if (pNodeAttribute?.GetAttributeType() == FbxNodeAttribute.EType.eMesh) { FbxMesh pMesh = pNode.GetMesh(); int skinCount = pMesh.GetDeformerCount(FbxDeformer.EDeformerType.eSkin); for (int i = 0; i < skinCount; i++) { FbxSkin pSkin = FbxSkin.Cast(pMesh.GetDeformer(i, FbxDeformer.EDeformerType.eSkin)); skinsResult.Add(pSkin); } } for (int i = 0; i < pNode.GetChildCount(); i++) { LoadSkinsFromNodeRecursive(pNode.GetChild(i), skinsResult); } }
private static long GetTotalVerts(FbxNode node) { FbxNodeAttribute a = node.GetNodeAttribute(); int nChildren = node.GetChildCount(); long vertCount = 0; if (a != null) { var attrType = a.GetAttributeType(); if (attrType == FbxNodeAttribute.EType.eMesh) { FbxMesh fbxMesh = node.GetMesh(); fbxMesh.SplitPoints(); vertCount = fbxMesh.GetControlPointsCount(); } } for (int i = 0; i < nChildren; i++) { vertCount += GetTotalVerts(node.GetChild(i)); } return(vertCount); }
void Run() { FbxManager manager = FbxManager.Create(); FbxIOSettings setting = FbxIOSettings.Create(manager, "IOSRoot"); manager.SetIOSettings(setting); FbxImporter impoter = FbxImporter.Create(manager, ""); bool status = impoter.Initialize(@"D:\develop\FbxWrapper\1.fbx", -1, setting); Log.Info(status); if (!status) { return; } FbxScene scene = FbxScene.Create(manager, "scene1"); status = impoter.Import(scene); Log.Info(status); int numTrack = scene.GetSrcObjectCount(FbxAnimStack.ClassId); Log.Info("num stack " + numTrack); FbxObject obj = scene.GetSrcObject(FbxAnimStack.ClassId, 0); FbxAnimStack stack = FbxAnimStack.Cast(obj); if (stack == null) { Log.Error("can not get anim stack!"); return; } FbxCriteria cri = FbxCriteria.ObjectTypeStrict(FbxAnimLayer.ClassId); int numLayer = stack.GetMemberCount(cri); Log.Info("anim layer count : " + numLayer); FbxAnimLayer layer = null; if (numLayer > 0) { FbxObject layerobj = stack.GetMember(cri, 0); layer = FbxAnimLayer.Cast(layerobj); if (layer == null) { Log.Error("anim layer is null!"); return; } Log.Info("anim layer name " + layer.GetName()); } Log.Info("node count " + scene.GetNodeCount()); for (int i = 0; i < scene.GetNodeCount(); i++) { FbxNode node = scene.GetNode(i); Log.Info("node " + i + " " + node.GetName()); if (node.LclTranslation.IsAnimated(layer)) { FbxAnimCurveNode curveNode = node.LclTranslation.GetCurveNode(layer); if (curveNode == null) { Log.Error("curve node is null"); } else { for (int c = 0; c < curveNode.GetCurveCount(0); c++) { FbxAnimCurve curve = curveNode.GetCurve(0, (uint)c); if (curve != null) { Log.Info("curve " + curve.GetName()); Log.Info("key count " + curve.KeyGetCount()); FbxAnimCurveKey key = curve.KeyGet(0); FbxTime t = key.GetTime(); Log.Info("key " + t.GetTimeString() + " value " + key.GetValue()); } } } } if (node.GetNodeAttribute() != null) { Log.Info("got attribu"); FbxNodeAttribute att = node.GetNodeAttribute(); PrintAttribute(att); } else { Log.Info("att count " + node.GetNodeAttributeCount()); for (int j = 0; j < node.GetNodeAttributeCount(); j++) { FbxNodeAttribute att = node.GetNodeAttributeByIndex(j); PrintAttribute(att); } } FbxVector4 rot = node.GetPostRotation(FbxNode.EPivotSet.eSourcePivot); FbxQuaternion q; } }
void Run() { FbxManager manager = FbxManager.Create(); FbxIOSettings setting = FbxIOSettings.Create(manager, "IOSRoot"); //fbxiosettingspath.h //PostProcessSteps.CalculateTangentSpace = #define EXP_TANGENTSPACE EXP_GEOMETRY "|" IOSN_TANGENTS_BINORMALS //PostProcessSteps.JoinIdenticalVertices = #define IOSN_DXF_WELD_VERTICES "WeldVertices" //PostProcessSteps.Triangulate = #define IOSN_TRIANGULATE "Triangulate" //PostProcessSteps.RemoveComponent = //PostProcessSteps.GenerateSmoothNormals = //setting.AddProperty() setting.SetBoolProp("Import|AdvOptGrp|Dxf|WeldVertices", true); setting.SetBoolProp("Triangulate", true); manager.SetIOSettings(setting); FbxImporter impoter = FbxImporter.Create(manager, ""); bool status = impoter.Initialize(@"1.fbx", -1, setting); Log.Info(status); if (!status) { return; } FbxScene scene = FbxScene.Create(manager, "scene1"); status = impoter.Import(scene); Log.Info(status); int numTrack = scene.GetSrcObjectCount(FbxCriteria.ObjectType(FbxAnimStack.ClassId)); Log.Info("num stack " + numTrack); FbxObject obj = scene.GetSrcObject(FbxCriteria.ObjectType(FbxAnimStack.ClassId), 0); FbxAnimStack stack = FbxAnimStack.Cast(obj); if (stack == null) { Log.Error("can not get anim stack!"); return; } FbxCriteria cri = FbxCriteria.ObjectTypeStrict(FbxAnimLayer.ClassId); int numLayer = stack.GetMemberCount(cri); Log.Info("anim layer count : " + numLayer); FbxAnimLayer layer = null; if (numLayer > 0) { FbxObject layerobj = stack.GetMember(cri, 0); layer = FbxAnimLayer.Cast(layerobj); if (layer == null) { Log.Error("anim layer is null!"); return; } Log.Info("anim layer name " + layer.GetName()); } Log.Info("node count " + scene.GetNodeCount()); for (int i = 0; i < scene.GetNodeCount(); i++) { FbxNode node = scene.GetNode(i); Log.Info("node " + i + " " + node.GetName() + " ChildCount:" + node.GetChildCount()); //---------------- //node.LclTranslation.IsAnimated //---------------- //ToDo : if (node.LclTranslation.IsAnimated(layer)) { FbxAnimCurveNode curveNode = node.LclTranslation.GetCurveNode(layer); if (curveNode == null) { Log.Error("curve node is null"); } else { for (int c = 0; c < curveNode.GetCurveCount(0); c++) { FbxAnimCurve curve = curveNode.GetCurve(0, (uint)c); if (curve != null) { Log.Info("curve " + curve.GetName()); Log.Info("key count " + curve.KeyGetCount()); FbxAnimCurveKey key = curve.KeyGet(0); FbxTime t = key.GetTime(); Log.Info("key " + t.GetTimeString() + " value " + key.GetValue()); } } } } if (node.GetNodeAttribute() != null) { Log.Info("got attribu"); FbxNodeAttribute att = node.GetNodeAttribute(); PrintAttribute(manager, att); } else { Log.Info("att count " + node.GetNodeAttributeCount()); for (int j = 0; j < node.GetNodeAttributeCount(); j++) { FbxNodeAttribute att = node.GetNodeAttributeByIndex(j); PrintAttribute(manager, att); } } FbxVector4 rot = node.GetPostRotation(FbxNode.EPivotSet.eSourcePivot); FbxQuaternion q; } }