Exemplo n.º 1
0
    public void Save(Mesh mesh, string name)
    {
        BinaryFormatter bf     = new BinaryFormatter();
        FileStream      stream = new FileStream(Application.dataPath + "/" + name + ".mesh", FileMode.Create);
        SerializeMesh   m      = new SerializeMesh(mesh, name);

        bf.Serialize(stream, m);
        stream.Close();
    }
Exemplo n.º 2
0
    public Mesh Load(string name)
    {
        if (File.Exists(Application.dataPath + "/Resources/" + name + ".mesh"))
        {
            BinaryFormatter bf     = new BinaryFormatter();
            FileStream      stream = new FileStream(Application.dataPath + "/Resources/" + name + ".mesh", FileMode.Open);

            SerializeMesh data = bf.Deserialize(stream) as SerializeMesh;

            stream.Close();
            return(data.GetMesh());//data;
        }
        else
        {
            print("nahhh");
            return(new Mesh());
        }
    }
Exemplo n.º 3
0
    public Mesh Load(string name)
    {
        if (File.Exists(Application.streamingAssetsPath + "/" + name + ".mesh"))
        {
            BinaryFormatter bf = new BinaryFormatter();
            //FileStream stream = new FileStream(Application.streamingAssetsPath +"/"+name+".mesh",FileMode.OpenRead);
            FileStream stream = File.OpenRead(Application.streamingAssetsPath + "/" + name + ".mesh");

            SerializeMesh data = bf.Deserialize(stream) as SerializeMesh;

//        print("loaded");
            stream.Close();
            return(data.GetMesh());//data;
        }
        else
        {
            // print("nahhh");
            return(new Mesh());
        }
    }
Exemplo n.º 4
0
    void Start()
    {
        buttonObject = Resources.Load("BaseMeshObject") as GameObject;
        foreach (ProvinceNode pn in XmlLoader.GetAllProvinceNode())
        {
            GameObject go = GameObject.Instantiate(buttonObject);
            go.name = pn.provinceName;
            SerializeMesh.GetMeshByName(go.GetComponent <MeshFilter>().mesh, pn.meshSrc);
            if (pn.offset == -1)
            {
                go.transform.localScale = new Vector3(1, -1, 1);
            }
            go.transform.parent = transform;
            go.AddComponent <MeshCollider>();
        }

        transform.position   = new Vector3(-500, 0, -10);
        transform.rotation   = Quaternion.Euler(new Vector3(90, 0, 0));
        transform.localScale = new Vector3(1, 1, -1);
    }
 void OnSceneGUI()
 {
     obj = (SerializeMesh)target;
 }
Exemplo n.º 6
0
    public IEnumerator MakeCityMesh()
    {
        List <Vector3> m_vertices  = new List <Vector3>();
        List <int>     m_triangles = new List <int>();
        List <PointF>  nPolygon    = new List <PointF>();

        m_vertices.Clear();
        m_triangles.Clear();
        GameObject     go         = GameObject.Instantiate(BaseMeshObject, GenerateMap.GetGenerateMap.transform);
        MeshFilter     meshFilter = go.GetComponent <MeshFilter>();
        Mesh           mesh       = meshFilter.mesh;
        List <Vector3> polygon    = new List <Vector3>();
        List <Vector3> hollowPointList;

        foreach (Vector2 vec in GenerateMap.GetGenerateMap.borderPointList)
        {
            if (!polygon.Contains(new Vector3(vec.x, vec.y, 0)))
            {
                polygon.Add(new Vector3(vec.x, vec.y, 0));
                m_vertices.Add(new Vector3(vec.x, vec.y, 0));
                nPolygon.Add(new PointF(vec.x, vec.y));
            }
        }
        while (polygon.Count > 2)
        {
            for (int j = 0; j < polygon.Count; j++)
            {
                hollowPointList = GetHollowPointList(polygon);
                if (!hollowPointList.Contains(polygon[j]) && polygon.Count > 2)
                {
                    Vector3 fVec;
                    Vector3 nVec;
                    Vector3 lVec;
                    if (j > 0 && j < polygon.Count - 1)
                    {
                        fVec = new Vector3(polygon[j - 1].x, polygon[j - 1].y, 0);
                        nVec = new Vector3(polygon[j].x, polygon[j].y, 0);
                        lVec = new Vector3(polygon[j + 1].x, polygon[j + 1].y, 0);
                    }
                    else
                    if (j == 0)
                    {
                        fVec = new Vector3(polygon[polygon.Count - 1].x, polygon[polygon.Count - 1].y, 0);
                        nVec = new Vector3(polygon[j].x, polygon[j].y, 0);
                        lVec = new Vector3(polygon[j + 1].x, polygon[j + 1].y, 0);
                    }
                    else
                    {
                        fVec = new Vector3(polygon[j - 1].x, polygon[j - 1].y, 0);
                        nVec = new Vector3(polygon[j].x, polygon[j].y, 0);
                        lVec = new Vector3(polygon[0].x, polygon[0].y, 0);
                    }
                    if (hollowPointList.Count == 0 || GenerateMap.GetGenerateMap.isContinue || IsPolygonContainLine(nPolygon, fVec, lVec))
                    {
                        for (int i = 0; i < m_vertices.Count; i++)
                        {
                            if (Vector3.Equals(fVec, m_vertices[i]))
                            {
                                m_triangles.Add(i);
                                break;
                            }
                        }
                        for (int i = 0; i < m_vertices.Count; i++)
                        {
                            if (Vector3.Equals(nVec, m_vertices[i]))
                            {
                                m_triangles.Add(i);
                                break;
                            }
                        }
                        for (int i = 0; i < m_vertices.Count; i++)
                        {
                            if (Vector3.Equals(lVec, m_vertices[i]))
                            {
                                m_triangles.Add(i);
                                break;
                            }
                        }
                        GenerateMap.GetGenerateMap.isContinue = false;
                        polygon.Remove(polygon[j]);
                        nPolygon.Remove(nPolygon[j]);
                        j--;
                        mesh.Clear();
                        mesh.vertices  = m_vertices.ToArray();
                        mesh.triangles = m_triangles.ToArray();
                        mesh.RecalculateNormals();
                        yield return(new WaitForFixedUpdate());
                    }
                }
                hollowPointList.Clear();
            }

            mesh.Clear();
            mesh.vertices  = m_vertices.ToArray();
            mesh.triangles = m_triangles.ToArray();
            mesh.RecalculateNormals();
            yield return(new WaitForSeconds(0.1f));
        }
        GenerateMap.GetGenerateMap.provinceNum++;
        mesh.name = GenerateMap.GetGenerateMap.provinceNum.ToString() + "_mesh";
        SerializeMesh.MeshToFile(meshFilter, mesh.name, 1);
        GenerateMap.GetGenerateMap.isDrawMeshOver = true;
    }
Exemplo n.º 7
0
        public IEnumerator MakeCityMesh(GameObject go, List <Vector2> BorderPointList)
        {
            if (go != null)
            {
                go.transform.parent = MapData.BaseGameObject.transform;

                DeleteDeathPoints(BorderPointList);
                yield return(new WaitForSeconds(0.1f));

                NormalizeBorderPoint(BorderPointList);

                List <Vector3> m_vertices  = new List <Vector3>();
                List <int>     m_triangles = new List <int>();
                List <PointF>  nPolygon    = new List <PointF>();
                m_vertices.Clear();
                m_triangles.Clear();
                MeshFilter meshFilter = go.GetComponent <MeshFilter>();
                Mesh       mesh       = new Mesh();
                meshFilter.mesh = mesh;
                List <Vector3> polygon = new List <Vector3>();
                List <Vector3> hollowPointList;
                foreach (Vector2 vec in BorderPointList)
                {
                    if (!polygon.Contains(new Vector3(vec.x, vec.y, 0)))
                    {
                        polygon.Add(new Vector3(vec.x, vec.y, 0));
                        m_vertices.Add(new Vector3(vec.x, vec.y, 0));
                        nPolygon.Add(new PointF(vec.x, vec.y));
                    }
                }
                int mapGenerateCount = 0;
                while (polygon.Count > 2)
                {
                    for (int j = 0; j < polygon.Count; j++)
                    {
                        hollowPointList = GetHollowPointList(polygon);
                        if (!hollowPointList.Contains(polygon[j]) && polygon.Count > 2)
                        {
                            Vector3 fVec;
                            Vector3 nVec;
                            Vector3 lVec;
                            if (j > 0 && j < polygon.Count - 1)
                            {
                                fVec = new Vector3(polygon[j - 1].x, polygon[j - 1].y, 0);
                                nVec = new Vector3(polygon[j].x, polygon[j].y, 0);
                                lVec = new Vector3(polygon[j + 1].x, polygon[j + 1].y, 0);
                            }
                            else
                            if (j == 0)
                            {
                                fVec = new Vector3(polygon[polygon.Count - 1].x, polygon[polygon.Count - 1].y, 0);
                                nVec = new Vector3(polygon[j].x, polygon[j].y, 0);
                                lVec = new Vector3(polygon[j + 1].x, polygon[j + 1].y, 0);
                            }
                            else
                            {
                                fVec = new Vector3(polygon[j - 1].x, polygon[j - 1].y, 0);
                                nVec = new Vector3(polygon[j].x, polygon[j].y, 0);
                                lVec = new Vector3(polygon[0].x, polygon[0].y, 0);
                            }
                            if (hollowPointList.Count == 0 || MapData.IsForceContinue || IsPolygonContainLine(nPolygon, fVec, lVec))
                            {
                                for (int i = 0; i < m_vertices.Count; i++)
                                {
                                    if (Vector3.Equals(fVec, m_vertices[i]))
                                    {
                                        m_triangles.Add(i);
                                        break;
                                    }
                                }
                                for (int i = 0; i < m_vertices.Count; i++)
                                {
                                    if (Vector3.Equals(nVec, m_vertices[i]))
                                    {
                                        m_triangles.Add(i);
                                        break;
                                    }
                                }
                                for (int i = 0; i < m_vertices.Count; i++)
                                {
                                    if (Vector3.Equals(lVec, m_vertices[i]))
                                    {
                                        m_triangles.Add(i);
                                        break;
                                    }
                                }
                                MapData.IsForceContinue = false;
                                polygon.Remove(polygon[j]);
                                nPolygon.Remove(nPolygon[j]);
                                j--;
                            }
                        }
                        hollowPointList.Clear();

                        mapGenerateCount++;
                        if (mapGenerateCount >= MapData.MapGenerateSpeed)
                        {
                            mapGenerateCount = 0;
                            mesh.Clear();
                            mesh.vertices  = m_vertices.ToArray();
                            mesh.triangles = m_triangles.ToArray();
                            mesh.RecalculateNormals();
                            yield return(new WaitForSeconds(0.1f));
                        }
                    }
                }

                mesh.Clear();
                mesh.vertices  = m_vertices.ToArray();
                mesh.triangles = m_triangles.ToArray();
                List <Vector2> uvs = new List <Vector2>();
                for (int i = 0; i < m_vertices.Count; i++)
                {
                    uvs.Add(new Vector2(m_vertices[i].x / MapData.Map.width, m_vertices[i].y / MapData.Map.height));
                }
                mesh.SetUVs(0, uvs);
                mesh.RecalculateNormals();
                yield return(new WaitForEndOfFrame());

                ProvinceNum++;
                mesh.name = ProvinceNum.ToString() + "_mesh";
                go.name   = mesh.name;
                SerializeMesh.MeshToFile(meshFilter, mesh.name, 1);
            }
        }