Пример #1
0
            public ModelGeometry GetGeometry()
            {
                List <Vector3>           tvertices       = new List <Vector3>();
                Dictionary <string, int> vertsDictionary = new Dictionary <string, int>();
                List <Vector2>           tuvs            = new List <Vector2>();
                List <Vector3>           tnormals        = new List <Vector3>();
                List <int> ttris = new List <int>();

                ObjectData od = objects[0];

                string newKey;
                int    k = 0;
                int    vNum;

                foreach (FaceIndices fi in od.allFaces)
                {
                    newKey = fi.vi + "|" + fi.vn + "|" + fi.vu;
                    if (!vertsDictionary.TryGetValue(newKey, out vNum))
                    {
                        vertsDictionary.Add(newKey, k);
                        vNum = k;
                        tvertices.Add(vertices[fi.vi]);
                        if (HasNormals)
                        {
                            tnormals.Add(normals[fi.vn]);
                        }
                        if (HasUVs)
                        {
                            tuvs.Add(uvs[fi.vu]);
                        }
                        k++;
                    }
                    ttris.Add(vNum);
                }

                ModelGeometry Model = new ModelGeometry(
                    tvertices.ToArray(),
                    null,
                    HasUVs ? tuvs.ToArray() : null,
                    ttris.ToArray(),
                    null,
                    HasNormals? tnormals.ToArray() : null
                    );

                tvertices.Clear();
                vertsDictionary.Clear();
                tuvs.Clear();
                tnormals.Clear();
                ttris.Clear();

                return(Model);
            }
Пример #2
0
        public static ModelGeometry[] Load(string path)
        {
            if (NativeLoader == null)
            {
                NativeLoader = new FbxNativeLoader();
            }

            Scene scene = NativeLoader.LoadScene(path);

            ModelGeometry[] result = new ModelGeometry[scene.Meshes.Count];
            Mesh            mesh;

            for (int k = 0; k < result.Length; k++)
            {
                mesh = scene.Meshes[k];
                //TODO: scene childs, mats and so on
                int       vertCount = mesh.VertexCount;
                Vector3[] verts     = new Vector3[vertCount];
                Vector3[] norms     = new Vector3[vertCount];
                Vector2[] uvs       = new Vector2[vertCount];
                Vector4[] colrs     = new Vector4[vertCount];

                int        i;
                MeshVertex mv;
                for (i = 0; i < vertCount; i++)
                {
                    mv       = mesh.Vertices[i];
                    verts[i] = mv.Position;
                    norms[i] = mv.Normal;
                    uvs[i]   = mv.TexCoord0;
                    colrs[i] = mv.Color0.ToVector4();
                }

                int[] indxs = new int[mesh.IndexCount];
                int   j     = 0;
                for (i = 0; i < mesh.TriangleCount; i++)
                {
                    indxs[j]     = mesh.Triangles[i].Index0;
                    indxs[j + 1] = mesh.Triangles[i].Index1;
                    indxs[j + 2] = mesh.Triangles[i].Index2;
                    j           += 3;
                }
                result[k] = new ModelGeometry(verts, colrs, uvs, indxs, null, norms);
            }

            return(result);
        }
Пример #3
0
        static public ModelGeometry Load(string objPath)
        {
            if (CachedModels.ContainsKey(objPath))
            {
                return(CachedModels[objPath]);
            }

            string         l;
            GeometryBuffer gBuffer = new GeometryBuffer();

            using (StreamReader sr = new StreamReader(objPath)) {
                while ((l = sr.ReadLine()) != null)
                {
                    ProcessOBJLine(gBuffer, l);
                }
            }
            ModelGeometry MG = gBuffer.GetGeometry();

            CachedModels.Add(objPath, MG);
            //Engine.Log("ModelGeometry.Count = " + MG.Count.ToString());

            return(MG);
        }