예제 #1
0
        public static GameObject LoadModelGameObject(string path, Material material = null)
        {
            RuntimeModelLoader.Mesh runtimeMesh = ModelLoader.Load(path);
            if (runtimeMesh == null)
            {
                return(null);
            }

            List <Vector3> vertices  = Converter.GetVerticesVector3(runtimeMesh);
            List <int>     triangles = Converter.GetTriangules(runtimeMesh);

            GameObject go = new GameObject();

            UnityEngine.Mesh goMesh = new UnityEngine.Mesh();
            goMesh.vertices  = vertices.ToArray();
            goMesh.triangles = triangles.ToArray();

            MeshFilter meshFilter = go.AddComponent <MeshFilter>();

            meshFilter.mesh = goMesh;

            MeshRenderer renderer = go.AddComponent <MeshRenderer>();

            renderer.material = material;

            return(go);
        }
예제 #2
0
        public static List <int> GetTriangules(RuntimeModelLoader.Mesh mesh)
        {
            List <int> triangles = new List <int>();

            foreach (Face face in mesh.faces)
            {
                if (face.vertexIndices.Length == 3)
                {
                    triangles.Add(face.vertexIndices[0]);
                    triangles.Add(face.vertexIndices[1]);
                    triangles.Add(face.vertexIndices[2]);
                }
                else if (face.vertexIndices.Length == 4)
                {
                    triangles.Add(face.vertexIndices[0]);
                    triangles.Add(face.vertexIndices[1]);
                    triangles.Add(face.vertexIndices[2]);

                    triangles.Add(face.vertexIndices[0]);
                    triangles.Add(face.vertexIndices[2]);
                    triangles.Add(face.vertexIndices[3]);
                }
            }
            return(triangles);
        }
예제 #3
0
        public static List <Vector3> GetVerticesVector3(RuntimeModelLoader.Mesh mesh)
        {
            List <Vector3> vertices = new List <Vector3>();

            foreach (Vec3 vec3 in mesh.vertices)
            {
                Vector3 vector3 = Converter.Vec3ToVector3(vec3);
                vertices.Add(vector3);
            }
            return(vertices);
        }
예제 #4
0
        public bool Load()
        {
            RuntimeModelLoader.Mesh runtimeMesh = ModelLoader.Load(path);
            if (runtimeMesh == null)
            {
                return(false);
            }

            List <Vector3> vertices  = Converter.GetVerticesVector3(runtimeMesh);
            List <int>     triangles = Converter.GetTriangules(runtimeMesh);

            UnityEngine.Mesh goMesh = new UnityEngine.Mesh();
            goMesh.vertices  = vertices.ToArray();
            goMesh.triangles = triangles.ToArray();

            _meshFilter.mesh = goMesh;

            return(true);
        }