Beispiel #1
0
    private void BuildSection(SlideNode n)
    {
        Vector3[] verticesShape = new Vector3[]
        {
            new Vector3(1, 0, 0),
            new Vector3(2, 1, 0),
            new Vector3(2, 1, 0),

            new Vector3(1, 0, 0),
            new Vector3(2, 1, 0),
            new Vector3(1, 0, 0),

            new Vector3(-1, 0, 0),
            new Vector3(1, 0, 0),
            new Vector3(1, 0, 0),

            new Vector3(-1, 0, 0),
            new Vector3(1, 0, 0),
            new Vector3(-1, 0, 0),

            new Vector3(-2, 1, 0),
            new Vector3(-1, 0, 0),
            new Vector3(-1, 0, 0),

            new Vector3(-2, 1, 0),
            new Vector3(-1, 0, 0),
            new Vector3(-2, 1, 0),
        };

        int[] trianglesShape = new int[]
        {
            0, 1, 2,
            3, 4, 5,
            6, 7, 8,
            9, 10, 11,
            12, 13, 14,
            15, 16, 17
        };

        //print(n.LastPosition);
        //print(n.Position);

        verticesShape[0] += n.LastPosition;
        verticesShape[1] += n.LastPosition;
        verticesShape[2] += n.Position + n.MeshObject.transform.right + n.MeshObject.transform.up + n.MeshObject.transform.forward;

        verticesShape[3] += n.LastPosition;
        verticesShape[4] += n.Position;
        verticesShape[5] += n.Position;

        verticesShape[6] += n.LastPosition;
        verticesShape[7] += n.LastPosition;
        verticesShape[8] += n.Position;

        verticesShape[9]  += n.LastPosition;
        verticesShape[10] += n.Position;
        verticesShape[11] += n.Position;

        verticesShape[12] += n.LastPosition;
        verticesShape[13] += n.LastPosition;
        verticesShape[14] += n.Position;

        verticesShape[15] += n.LastPosition;
        verticesShape[16] += n.Position;
        verticesShape[17] += n.Position;

        //for(int i = 0; i < verticesShape.Length; i++)
        //{
        //    print(verticesShape[i].ToString());
        //}

        verticesB = verticesShape;

        Mesh mesh = new Mesh()
        {
            vertices  = verticesShape,
            triangles = trianglesShape,
            name      = "Slide section"
        };

        mesh.Optimize();
        mesh.RecalculateNormals();
        mesh.RecalculateBounds();

        n.MeshObject.GetComponent <MeshFilter>().mesh         = mesh;
        n.MeshObject.GetComponent <MeshCollider>().sharedMesh = mesh;
    }