Exemplo n.º 1
0
    private Mesh Morph(Mesh m, MazeStructure mazeStruct, VectorSpaceish vectors, bool invertTris)
    {
        Mesh result = new Mesh();

        // create new vertices, the Vector Space given by x,y,z, with base at a
        Vector3[] verts = new Vector3[m.vertices.Length];
        for (int i = 0; i < verts.Length; ++i)
        {
            verts[i] = (100 * m.vertices[i]) + new Vector3(1, 0, 1);
            if (verts[i].x <-0.01f || verts[i].y <-0.01f || verts[i].z <-0.01f || verts[i].x> 1.01f || verts[i].y> 1.01f || verts[i].z> 1.01f)
            {
                throw new Exception("Mesh vertices out of range for MazeCell (mesh is " + m.name + ", vertex is at (" + verts[i].x + ", " + verts[i].y + ", " + verts[i].z + "))");
            }
            Vector3 floor = vectors.Translate(verts[i], false);
            verts[i] = vectors.Translate(verts[i], true);
            verts[i] = mazeStruct.Vector3FromCubeToSphere(verts[i], floor);
        }
        result.vertices = verts;

        // handle triangles
        if (invertTris)
        {
            int[] tris = new int[m.triangles.Length];
            for (int i = 0; i < tris.Length; ++i)
            {
                tris[i] = m.triangles[tris.Length - i - 1];
            }
            result.triangles = tris;
        }
        else
        {
            result.triangles = (int[])m.triangles.Clone();
        }

        // directly copy uvs, calculate normals, optimize
        result.uv = (Vector2[])m.uv.Clone();
        result.RecalculateNormals();
        result.Optimize();
        return(result);
    }
Exemplo n.º 2
0
    /// <summary>
    /// Uses pathfinding to generate a path between the 2 given points in game-space.
    /// </summary>
    private void CalcPath(Point3 playerPos, Point3 monsterPos)
    {
        // path find around the monster, find path to player
        print("playerPos: " + playerPos);
        print("monsterPos: " + monsterPos);
        Pathfinding pathfinding = mazeStruct.Pathfind(monsterPos);

        path = pathfinding.PathToPoint(playerPos);

        // fill in positions
        distance = 0;
        //Debug.Log("path: "+path);
        //Debug.Log("path length: "+path.Length);
        positions = new Vector3[path.Length];
        for (int i = 0; i < positions.Length; ++i)
        {
            Point3  p = path[i];
            Vector3 v = mazeStruct.FromGameToCube(p);
            positions[i] = mazeStruct.Vector3FromCubeToSphere(v);
            //print(path[i]+" -> "+v+" -> "+v+" -> "+positions[i]);
        }
    }