Exemplo n.º 1
0
    public void nearestPointOnPlane_is_projectedVertex()
    {
        Debug.Log(" === known plane-projected vertex test === ");

        // test point @ origin
        Vector3 p = new Vector3(0, 0, 0);

        // test mesh is 1x1 plane at z = 1
        GameObject plane = new GameObject("testPlane");
        MeshFilter mf    = (MeshFilter)plane.AddComponent(typeof(MeshFilter));

        Vector3[] pl = new Vector3[] { new Vector3(1, 1, 1),
                                       new Vector3(1, -1, 1),
                                       new Vector3(-1, 1, 1),
                                       new Vector3(-1, -1, 1) };

        mf.mesh = CreateMesh(pl);



        Vector3 projection = new Vector3(0, 0, 1);
        Vector3 result     = NearestPointOnMesh.getNearestPointOnMesh(p, mf);

        UUnitAssert.Equals(projection, result);
    }
Exemplo n.º 2
0
    public void nearestPointOnPrimitivePlane_is_projectedVertex()
    {
        Debug.Log(" === known PrimitiveType.Plane-projected vertex test === ");

        // test point @ origin
        Vector3 p = new Vector3(1, 1, 1);

        // test mesh is 1x1 plane at z = 1
        //GameObject pl = new GameObject("testPlane");
        GameObject pl = GameObject.CreatePrimitive(PrimitiveType.Plane);
        MeshFilter mf = pl.GetComponent <MeshFilter>();

        Vector3 projection = new Vector3(1, 0, 1);
        Vector3 result     = NearestPointOnMesh.getNearestPointOnMesh(p, mf);

        UUnitAssert.Equals(projection, result);
    }
Exemplo n.º 3
0
    public static Vector3 lerpNearest(Vector3 from, MeshFilter to, float t)
    {
        //Linearly interpolates between given point and nearest point on mesh by fraction t
        Mesh        mesh       = to.mesh;
        VertTriList vt         = new VertTriList(mesh);
        Vector3     objSpacePt = from;    // to.transform.InverseTransformPoint(from);

        Vector3[] verts   = mesh.vertices;
        KDTree    kd      = KDTree.MakeFromPoints(verts);
        Vector3   meshPt  = NearestPointOnMesh.getNearestPointOnMesh(objSpacePt, verts, kd, mesh.triangles, vt);
        Vector3   closest = meshPt;       //= to.transform.TransformPoint(meshPt);

        Debug.Log("selected:" + from.ToString() + " nearest:" + closest.ToString());
        Vector3 towards = Vector3.Lerp(from, closest, t);

        Debug.Log("lerp point" + towards.ToString());
        return(towards);
    }
Exemplo n.º 4
0
    public void nearestPointOnScaledCube_is_scaled()
    {
        // ensures that a point at 1,0,0 moves to a point at .5,0,0 if cube at origin w/ scale .5,.5,.5
        Debug.Log(" === scaled cube test === ");


        Vector3 p = new Vector3(1, 2, 2);

        GameObject cu = GameObject.CreatePrimitive(PrimitiveType.Cube);

        cu.transform.localScale = new Vector3(0.5f, 2f, 2f);
        MeshFilter mf = cu.GetComponent <MeshFilter>();

        Vector3 expected = new Vector3(.5f, 2f, 2f);
        Vector3 result   = NearestPointOnMesh.getNearestPointOnMesh(p, mf);

        Debug.Log(expected.ToString() + "=?=" + result.ToString());

        UUnitAssert.Equals(expected, result);
    }