Exemple #1
0
        public (GameObject, List <string> warnings, ImportMaterialCollector) Import()
        {
            FbxManager    fbxManager = FbxManager.Create();
            FbxIOSettings ioSettings = FbxIOSettings.Create(fbxManager, Globals.IOSROOT);

            fbxManager.SetIOSettings(ioSettings);
            FbxImporter fbxImporter = FbxImporter.Create(fbxManager, "");

            if (!fbxImporter.Initialize(m_path, -1, ioSettings))
            {
                warnings.Add("Failed to initialize FBX importer");
                return(null, warnings, null);
            }
            FbxScene scene = FbxScene.Create(fbxManager, "scene");

            fbxImporter.Import(scene);

            FbxNode root = scene.GetRootNode();

            SetPivots(root);
            root.ConvertPivotAnimationRecursive(null, FbxNode.EPivotSet.eDestinationPivot, 30);
            long totalVerts     = GetTotalVerts(root);
            long completedVerts = 0;

            float fbxUnitToTiltUnit; {
                var unit = scene.GetGlobalSettings().GetSystemUnit();
                if (Path.GetExtension(m_path).ToLower() == ".obj")
                {
                    // Obj doesn't specify units. We'd rather assume m, but fbx assumes cm.
                    unit = FbxSystemUnit.m;
                }
                fbxUnitToTiltUnit = (float)unit.GetConversionFactorTo(FbxSystemUnit.m)
                                    * App.METERS_TO_UNITS;
            }

            GameObject go = ImportNodes(
                root, fbxUnitToTiltUnit, ref completedVerts, totalVerts);

            Debug.Assert(completedVerts == totalVerts);
            fbxImporter.Destroy();
            ioSettings.Destroy();
            fbxManager.Destroy();

            return(go, warnings.Distinct().ToList(), m_collector);
        }