Exemplo n.º 1
0
    bool FindVertexToDeformer()
    {
        Ray        inputRay = new Ray(head.LastPosition, head.transform.forward);
        RaycastHit hit;

        if (Physics.Raycast(inputRay, out hit))
        {
            MeshDeformer deformer = hit.collider.GetComponent <MeshDeformer> ();
            if (deformer)
            {
                Vector3 dir = (head.transform.position - hit.point).normalized;
                float   dot = Vector3.Dot(head.transform.forward, dir);
                //Debug.Log ("dot "+dot);

                if (dot > 0)
                {
                    int     fidx = hit.triangleIndex;
                    Vector3 vertex;
                    int     vidx = deformer.FindNearestVertexInTriangle(fidx, hit.point, out vertex);
                    HitPos = hit.point;
                    Debug.LogFormat("FindVertexToDeformer {0}", vidx);
                    head.SetTargetVertex(deformer, vidx);
                    return(true);
                }
            }
        }

        return(false);
    }
Exemplo n.º 2
0
    void HandleInput()
    {
        /*
         * if (Input.GetMouseButtonDown (0)) {
         *      Debug.Log ("mouse down");
         *      Ray inputRay = Camera.main.ScreenPointToRay(Input.mousePosition);
         *      RaycastHit hit;
         *
         *      if (Physics.Raycast (inputRay, out hit)) {
         *              MeshDeformer deformer = hit.collider.GetComponent<MeshDeformer> ();
         *              if (deformer) {
         *                      Vector3 point = hit.point;
         *                      point += hit.normal * 0.05f;
         *                      AddMeshForce (point, 0.1f);
         *              }
         *      }
         * }
         */

        if (Input.GetMouseButtonDown(0))
        {
            Debug.Log("mouse down");
            Ray        inputRay = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;

            if (Physics.Raycast(inputRay, out hit))
            {
                MeshDeformer deformer = hit.collider.GetComponent <MeshDeformer> ();
                if (deformer)
                {
                    int     fidx = hit.triangleIndex;
                    Vector3 vertex;
                    int     vidx = deformer.FindNearestVertexInTriangle(fidx, hit.point, out vertex);

                    GameObject  go          = GameObject.CreatePrimitive(PrimitiveType.Sphere);
                    FollowForce followForce = go.AddComponent <FollowForce> ();
                    followForce.SetTargetVertex(deformer, vidx);
                    go.transform.SetParent(transform);
                    go.transform.localRotation = Quaternion.identity;
                    go.transform.localScale    = new Vector3(0.1f, 0.1f, 0.1f);
                    go.transform.position      = hit.point + hit.normal * 0.05f;
                }
            }
        }

        if (Input.GetMouseButtonDown(1))
        {
            Debug.Log("mouse down");
            Ray        inputRay = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;

            if (Physics.Raycast(inputRay, out hit))
            {
                FollowForce force = hit.collider.GetComponent <FollowForce> ();
                if (force)
                {
                    Destroy(force.gameObject);
                }
            }
        }
    }