Beispiel #1
0
    public void WriteToFile(string Filename)
    {
        int  Major, Minor, Revision;
        bool Status = true;

        int  FileFormat  = -1;
        bool bEmbedMedia = false;

        // Create an exporter.
        FbxExporter Exporter = FbxExporter.Create(SdkManager, "");

        // set file format
        // Write in fall back format if pEmbedMedia is true
        FileFormat = SdkManager.GetIOPluginRegistry().GetNativeWriterFormat();
        FbxIOSettings IOS_REF = SdkManager.GetIOSettings();

        // Set the export states. By default, the export states are always set to
        // true except for the option eEXPORT_TEXTURE_AS_EMBEDDED. The code below
        // shows how to change these states.


        IOS_REF.SetBoolProp(fbx_wrapper.EXP_FBX_MATERIAL, true);
        IOS_REF.SetBoolProp(fbx_wrapper.EXP_FBX_TEXTURE, true);
        IOS_REF.SetBoolProp(fbx_wrapper.EXP_FBX_EMBEDDED, bEmbedMedia);
        IOS_REF.SetBoolProp(fbx_wrapper.EXP_FBX_SHAPE, true);
        IOS_REF.SetBoolProp(fbx_wrapper.EXP_FBX_GOBO, true);
        IOS_REF.SetBoolProp(fbx_wrapper.EXP_FBX_ANIMATION, true);
        IOS_REF.SetBoolProp(fbx_wrapper.EXP_FBX_GLOBAL_SETTINGS, true);

        string CompatibilitySetting = fbx_wrapper.FBX_2013_00_COMPATIBLE;

        if (!Exporter.SetFileExportVersion(new FbxString(CompatibilitySetting), FbxSceneRenamer.ERenamingMode.eNone))
        {
            Debug.LogWarning("Call to KFbxExporter::SetFileExportVersion(FBX_2013_00_COMPATIBLE) to export 2013 fbx file format failed.\n");
        }

        //// Initialize the exporter by providing a filename.
        if (!Exporter.Initialize(Filename, FileFormat, SdkManager.GetIOSettings()))
        {
            Debug.LogWarning("Call to KFbxExporter::Initialize() failed.\n");
            string errorString = Exporter.GetStatus().GetErrorString();
            Debug.LogWarning("Error returned:" + errorString);
            return;
        }

        //FbxManager.GetFileFormatVersion(Major, Minor, Revision);

        // Export the scene.
        Status = Exporter.Export(Scene);

        if (!Status)
        {
            string errorString = Exporter.GetStatus().GetErrorString();
            Debug.LogWarning("Error returned:" + errorString);
        }
        Clear();

        return;
    }
        private void FbxImportAndTestBlendshapes(string fbxPath)
        {
            // Create the FBX manager
            using (var fbxManager = FbxManager.Create())
            {
                FbxIOSettings fbxIOSettings = FbxIOSettings.Create(fbxManager, Globals.IOSROOT);

                // Configure the IO settings.
                fbxManager.SetIOSettings(fbxIOSettings);

                // Create the importer
                var fbxImporter = FbxImporter.Create(fbxManager, "Importer");

                // Initialize the importer.
                int fileFormat = -1;

                bool      status    = fbxImporter.Initialize(fbxPath, fileFormat, fbxIOSettings);
                FbxStatus fbxStatus = fbxImporter.GetStatus();

                Assert.That(status, Is.True, fbxStatus.GetErrorString());
                Assert.That(fbxImporter.IsFBX(), "file does not contain FBX data");

                // Import options. Determine what kind of data is to be imported.
                // The default is true, but here we set the options explictly.
                fbxIOSettings.SetBoolProp(Globals.IMP_FBX_MATERIAL, false);
                fbxIOSettings.SetBoolProp(Globals.IMP_FBX_TEXTURE, false);
                fbxIOSettings.SetBoolProp(Globals.IMP_FBX_ANIMATION, false);
                fbxIOSettings.SetBoolProp(Globals.IMP_FBX_EXTRACT_EMBEDDED_DATA, false);
                fbxIOSettings.SetBoolProp(Globals.IMP_FBX_GLOBAL_SETTINGS, true);

                // Create a scene
                var fbxScene = FbxScene.Create(fbxManager, "Scene");

                // Import the scene to the file.
                status    = fbxImporter.Import(fbxScene);
                fbxStatus = fbxImporter.GetStatus();
                Assert.That(status, Is.True, fbxStatus.GetErrorString());

                // Get blendshapes and check that the FbxShapes all have names
                var rootNode = fbxScene.GetRootNode();
                TestFbxShapeNamesNotEmpty(rootNode);
            }
        }
Beispiel #3
0
            /// <summary>
            /// Import all from scene.
            /// Return the number of objects we imported.
            /// </summary>
            public int ImportAll()
            {
                // Create the FBX manager
                using (var fbxManager = FbxManager.Create())
                {
                    FbxIOSettings fbxIOSettings = FbxIOSettings.Create(fbxManager, Globals.IOSROOT);

                    // Configure the IO settings.
                    fbxManager.SetIOSettings(fbxIOSettings);

                    // Get the version number of the FBX files generated by the
                    // version of FBX SDK that you are using.
                    int sdkMajor = -1, sdkMinor = -1, sdkRevision = -1;
                    FbxManager.GetFileFormatVersion(out sdkMajor, out sdkMinor, out sdkRevision);

                    // Create the importer
                    var fbxImporter = FbxImporter.Create(fbxManager, "Importer");

                    // Initialize the importer.
                    int fileFormat = -1;

                    bool      status    = fbxImporter.Initialize(LastFilePath, fileFormat, fbxIOSettings);
                    FbxStatus fbxStatus = fbxImporter.GetStatus();

                    // Get the version number of the FBX file format.
                    int fileMajor = -1, fileMinor = -1, fileRevision = -1;
                    fbxImporter.GetFileVersion(out fileMajor, out fileMinor, out fileRevision);

                    // Check that initialization of the fbxImporter was successful
                    if (!status)
                    {
                        Debug.LogError(string.Format("failed to initialize FbxImporter, error returned {0}",
                                                     fbxStatus.GetErrorString()));

                        if (fbxStatus.GetCode() == FbxStatus.EStatusCode.eInvalidFileVersion)
                        {
                            Debug.LogError(string.Format("Invalid file version detected\nSDK version: {0}.{1}.{2}\nFile version: {3}.{4}.{5}",
                                                         sdkMajor, sdkMinor, sdkRevision,
                                                         fileMajor, fileMinor, fileRevision));
                        }

                        return(0);
                    }

                    // Import options. Determine what kind of data is to be imported.
                    // The default is true, but here we set the options explictly.
                    fbxIOSettings.SetBoolProp(Globals.IMP_FBX_MATERIAL, false);
                    fbxIOSettings.SetBoolProp(Globals.IMP_FBX_TEXTURE, false);
                    fbxIOSettings.SetBoolProp(Globals.IMP_FBX_ANIMATION, false);
                    fbxIOSettings.SetBoolProp(Globals.IMP_FBX_EXTRACT_EMBEDDED_DATA, false);
                    fbxIOSettings.SetBoolProp(Globals.IMP_FBX_GLOBAL_SETTINGS, true);

                    // Create a scene
                    var fbxScene = FbxScene.Create(fbxManager, "Scene");

                    // Import the scene to the file.
                    status = fbxImporter.Import(fbxScene);

                    if (status == false)
                    {
                        Debug.LogError(string.Format("failed to import file ({0})",
                                                     fbxImporter.GetStatus().GetErrorString()));
                    }
                    else
                    {
                        // import data into scene
                        ProcessScene(fbxScene);
                    }

                    // cleanup
                    fbxScene.Destroy();
                    fbxImporter.Destroy();

                    return(status == true ? NumNodes : 0);
                }
            }
Beispiel #4
0
        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;
            }
        }
Beispiel #5
0
            /// <summary>
            /// Import all from scene.
            /// Return the number of objects we imported.
            /// </summary>
            public int ImportAll(IEnumerable <UnityEngine.Object> unitySelectionSet)
            {
                // Create the FBX manager
                using (var fbxManager = FbxManager.Create())
                {
                    FbxIOSettings fbxIOSettings = FbxIOSettings.Create(fbxManager, Globals.IOSROOT);

                    // Configure the IO settings.
                    fbxManager.SetIOSettings(fbxIOSettings);

                    // Get the version number of the FBX files generated by the
                    // version of FBX SDK that you are using.
                    int sdkMajor = -1, sdkMinor = -1, sdkRevision = -1;

                    FbxManager.GetFileFormatVersion(out sdkMajor, out sdkMinor, out sdkRevision);

                    // Create the importer
                    var fbxImporter = FbxImporter.Create(fbxManager, "Importer");

                    // Initialize the importer.
                    int fileFormat = -1;

                    bool      status    = fbxImporter.Initialize(LastFilePath, fileFormat, fbxIOSettings);
                    FbxStatus fbxStatus = fbxImporter.GetStatus();

                    // Get the version number of the FBX file format.
                    int fileMajor = -1, fileMinor = -1, fileRevision = -1;
                    fbxImporter.GetFileVersion(out fileMajor, out fileMinor, out fileRevision);

                    // Check that initialization of the fbxImporter was successful
                    if (!status)
                    {
                        Debug.LogError(string.Format("failed to initialize FbxImporter, error returned {0}",
                                                     fbxStatus.GetErrorString()));

                        if (fbxStatus.GetCode() == FbxStatus.EStatusCode.eInvalidFileVersion)
                        {
                            Debug.LogError(string.Format("Invalid file version detected\nSDK version: {0}.{1}.{2}\nFile version: {3}.{4}.{5}",
                                                         sdkMajor, sdkMinor, sdkRevision,
                                                         fileMajor, fileMinor, fileRevision));
                        }

                        return(0);
                    }

                    MsgLine.Add("Import Scene Report");
                    MsgLine.Add(kBorderLine);

                    MsgLine.Add(kPadding + string.Format("FilePath: {0}", LastFilePath));
                    MsgLine.Add(kPadding + string.Format("SDK version: {0}.{1}.{2}",
                                                         sdkMajor, sdkMinor, sdkRevision));

                    if (!fbxImporter.IsFBX())
                    {
                        Debug.LogError(string.Format("file does not contain FBX data {0}", LastFilePath));
                        return(0);
                    }

                    MsgLine.Add(kPadding + string.Format("File version: {0}.{1}.{2}",
                                                         fileMajor, fileMinor, fileRevision));

                    MsgLine.Add(kBorderLine);
                    MsgLine.Add("Animation");
                    MsgLine.Add(kBorderLine);

                    int numAnimStack = fbxImporter.GetAnimStackCount();

                    MsgLine.Add(kPadding + string.Format("number of stacks: {0}", numAnimStack));
                    MsgLine.Add(kPadding + string.Format("active animation stack: \"{0}\"\n", fbxImporter.GetActiveAnimStackName()));

                    for (int i = 0; i < numAnimStack; i++)
                    {
#if UNI_18972
                        FbxTakeInfo fbxTakeInfo = fbxImporter.GetTakeInfo(i);
                        MsgLine.Add(kPadding + string.Format("Animation Stack ({0})", i));
                        MsgLine.Add(kPadding + string.Format("name: \"{0}\"", fbxTakeInfo.mName) + string.kNewLine);
                        MsgLine.Add(kPadding + string.Format("description: \"{0}\"", fbxTakeInfo.mDescription));
                        MsgLine.Add(kPadding + string.Format("import name: \"{0}\"", fbxTakeInfo.mImportName));
                        MsgLine.Add(kPadding + string.Format("import state: \"{0}\"", fbxTakeInfo.mSelect));
#endif
                    }

                    // Import options. Determine what kind of data is to be imported.
                    // The default is true, but here we set the options explictly.
                    fbxIOSettings.SetBoolProp(Globals.IMP_FBX_MATERIAL, false);
                    fbxIOSettings.SetBoolProp(Globals.IMP_FBX_TEXTURE, false);
                    fbxIOSettings.SetBoolProp(Globals.IMP_FBX_ANIMATION, false);
                    fbxIOSettings.SetBoolProp(Globals.IMP_FBX_EXTRACT_EMBEDDED_DATA, false);
                    fbxIOSettings.SetBoolProp(Globals.IMP_FBX_GLOBAL_SETTINGS, true);

                    // Create a scene
                    var fbxScene = FbxScene.Create(fbxManager, "Scene");

                    // Import the scene to the file.
                    status    = fbxImporter.Import(fbxScene);
                    fbxStatus = fbxImporter.GetStatus();

                    if (status == false)
                    {
                        if (fbxStatus.GetCode() == FbxStatus.EStatusCode.ePasswordError)
                        {
                            Debug.LogError(string.Format("failed to import, file is password protected ({0})", fbxStatus.GetErrorString()));
                        }
                        else
                        {
                            Debug.LogError(string.Format("failed to import file ({0})", fbxStatus.GetErrorString()));
                        }
                    }
                    else
                    {
                        // import data into scene
                        ProcessScene(fbxScene, unitySelectionSet);
                    }

                    // cleanup
                    fbxScene.Destroy();
                    fbxImporter.Destroy();

                    return(status == true ? NumNodes : 0);
                }
            }