示例#1
0
        public static FbxAsset Import(string path)
        {
            if (!File.Exists(path))
            {
                throw new FileNotFoundException("The file could not be found", path);
            }

            var document     = FbxIO.ReadBinary("E:\\projects\\NEngineResources\\Glock.fbx");
            var verticesNode = document.GetRelative("Objects/Geometry/Vertices");

            var fbxAsset = new FbxAsset();

            fbxAsset.Mesh = new Mesh();

            if (verticesNode.Properties[0] is double[] vertices)
            {
                fbxAsset.Mesh.Vertices = new Vector3[vertices.Length / 3];
                for (int i = 0, j = 0, len = vertices.Length; i < len; i += 3, j++)
                {
                    var xPos = vertices[i];
                    var yPos = vertices[i + 1];
                    var zPos = vertices[i + 2];
                    fbxAsset.Mesh.Vertices[j] = new Vector3(xPos, yPos, zPos);
                }
            }

            var polygonVertexIndexNode = document.GetRelative("Objects/Geometry/PolygonVertexIndex");

            if (polygonVertexIndexNode.Properties[0] is int[] polygonVertexIndex && polygonVertexIndex.Length >= 2)
            {
                bool quadMode = polygonVertexIndex[2] >= 0;

                if (quadMode)
                {
                    fbxAsset.Mesh.Triangles = new Triangle[(polygonVertexIndex.Length / 4) * 2];
                    for (int i = 0, j = 0, len = polygonVertexIndex.Length; i < len; i += 4, j += 2)
                    {
                        var v1 = polygonVertexIndex[i];
                        var v2 = polygonVertexIndex[i + 1];
                        var v3 = polygonVertexIndex[i + 2];
                        var v4 = -polygonVertexIndex[i + 3] - 1;
                        fbxAsset.Mesh.Triangles[j]     = new Triangle(v1, v2, v4);
                        fbxAsset.Mesh.Triangles[j + 1] = new Triangle(v4, v2, v3);
                    }
                }
                else
                {
                    fbxAsset.Mesh.Triangles = new Triangle[polygonVertexIndex.Length / 3];
                    for (int i = 0, j = 0, len = polygonVertexIndex.Length; i < len; i += 3, j++)
                    {
                        var v1 = polygonVertexIndex[i];
                        var v2 = polygonVertexIndex[i + 1];
                        var v3 = -polygonVertexIndex[i + 2] - 1;
                        fbxAsset.Mesh.Triangles[j] = new Triangle(v1, v2, v3);
                    }
                }
            }

            return(fbxAsset);
        }
示例#2
0
        public void Load(string path)
        {
            var rootNode = new View.FbxNodeItem(System.IO.Path.GetFileName(path));
            var content  = FbxIO.ReadBinary(path);

            foreach (var item in content.Nodes.Where(n => n != null))
            {
                SeekNode(rootNode, item);
            }
            nodeModel.Nodes.Add(rootNode);
        }
示例#3
0
        static void Test1()
        {
            string dir   = @"C:\Users\dell\AppData\Local\Colossal Order\Cities_Skylines\Addons\Import\ARDumps\";
            string file1 = "RoadMediumNode._ascii.fbx";

            var    doc   = FbxIO.ReadAscii(dir + file1);
            string fileA = "testA_" + file1;

            FbxIO.WriteAscii(doc, dir + fileA);

            doc = FbxIO.ReadAscii(dir + fileA);
            string fileB = "testB_" + file1;

            FbxIO.WriteBinary(doc, dir + fileB); // i can't open this

            doc = FbxIO.ReadBinary(dir + fileB);
            FbxIO.WriteAscii(doc, dir + "testC_" + file1); // i can open this
        }
示例#4
0
        static void Test4()
        {
            Test3();
            string dir   = @"C:\Users\dell\AppData\Local\Colossal Order\Cities_Skylines\Addons\Import\ARDumps\";
            string file1 = "RoadMediumNode._ascii.fbx";       // can open this
            string file2 = "TEST3_RoadMediumNode.binary.fbx"; // can open this
            string file3 = "TEST3_RoadMediumNode.ascii.fbx";
            string fileB = "TEST3B_RoadMediumNode.binary.fbx";

            Console.WriteLine("reading binary ...");
            var doc1 = FbxIO.ReadBinary(dir + file2);

            FbxIO.WriteAscii(doc1, dir + file3);
            var doc2 = FbxIO.ReadAscii(dir + file3);

            doc1.Diff(doc2);

            FbxIO.WriteBinary(doc2, dir + fileB);
        }