private void Start()
    {
        Application.targetFrameRate = 60;

        //     4-------5
        //    /|      /|
        //   0-------1 |
        //   | 6-----|-7
        //   |/      |/
        //   2-------3

        mesh.AddPoint(new Vector3(0, 0, 0));
        mesh.AddPoint(new Vector3(0, 1, 0));
        mesh.AddPoint(new Vector3(1, 0, 0));
        mesh.AddPoint(new Vector3(1, 1, 0));

        mesh.AddPoint(new Vector3(0, 0, 1));
        mesh.AddPoint(new Vector3(0, 1, 1));
        mesh.AddPoint(new Vector3(1, 0, 1));
        mesh.AddPoint(new Vector3(1, 1, 1));

        mesh.AddFace(new int[] { 0, 1, 3, 2 });
        mesh.AddFace(new int[] { 1, 5, 7, 3 });
        mesh.AddFace(new int[] { 0, 2, 6, 4 });
        mesh.AddFace(new int[] { 4, 5, 1, 0 });
        mesh.AddFace(new int[] { 7, 6, 2, 3 });
        //		mesh.AddFace(new int[]{5,4,6,7});

        var mf = gameObject.GetComponent <MeshFilter>();

        if (mf)
        {
            mf.sharedMesh = mesh.CreateHullMesh();
        }

        {
            subdiv = new HEMesh[1];
            var srcMesh = mesh;
            for (int i = 0; i < subdiv.Length; i++)
            {
                subdiv[i] = new HEMesh();
                srcMesh.Subdiv(subdiv[i]);
                srcMesh = subdiv[i];
            }

            var subObj = new GameObject("subdiv");
            subObj.transform.SetParent(transform);
            subObj.AddComponent <MeshRenderer>();
            mf      = subObj.AddComponent <MeshFilter>();
            mf.mesh = srcMesh.CreateHullMesh();
        }
    }
Ejemplo n.º 2
0
        public static HEMesh TestCreate()
        {
            var points = new List <Vector3D>()
            {
                new Vector3D(0, 0, 0), new Vector3D(100, 0, 0), new Vector3D(0, 100, 0), new Vector3D(100, 100, 0),
                new Vector3D(0, 0, 100), new Vector3D(100, 0, 100), new Vector3D(0, 100, 100), new Vector3D(100, 100, 100),
            };

            var indice = new List <int>()
            {
                0, 2, 1, 1, 2, 3,
                4, 5, 7, 4, 7, 6,
                0, 4, 2, 4, 6, 2,
                0, 1, 4, 1, 5, 4,
                1, 3, 7, 1, 7, 5,
                3, 2, 7, 2, 6, 7,
            };

            var mesh = new HEMesh();

            foreach (var p in points)
            {
                mesh.AddVertex(p);
            }

            for (int i = 0; i < indice.Count; i += 3)
            {
                mesh.AddFace(new IndexN <int>(indice[i], indice[i + 1], indice[i + 2]));
            }

            mesh.UpdateFaceNormals();
            mesh.UpdateVerticeNormals();
            return(mesh);
        }
Ejemplo n.º 3
0
        public static HEMesh ConvertTo(MeshData data)
        {
            if (data == null)
            {
                return(null);
            }
            var mesh = new HEMesh(data.Vertices.Count);

            foreach (var vertex in data.Vertices)
            {
                mesh.AddVertex(vertex.Position);
            }
            foreach (var face in data.Faces)
            {
                mesh.AddFace(face.Vertices);
            }
            mesh.UpdateFaceNormals();
            mesh.UpdateVerticeNormals();
            return(mesh);
        }