// 添加穿刺点 public void AddPuncturePoint(SoftBody deformer, int vidx) { FollowForce force = MeshDeformerInput.instance.AddFollowForce(deformer, vidx, deformer.GetWorldPosOfOriginalVertex(vidx)); // update rope fragments.Add(force.transform); }
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) { AddMeshForce(hit.point + hit.normal * 0.01f, 1f); } } } 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); } } } }
public void Clear() { for (int i = 1; i < fragments.Count; i++) { FollowForce force = fragments [i].GetComponent <FollowForce> (); force.ClearTargetVertex(); Destroy(force.gameObject); } fragments.RemoveRange(1, fragments.Count - 1); }
// Use this for initialization void Awake() { head = transform.Find("head").GetComponent <FollowForce> (); head.followForceSpingMax += delegate() { Debug.Log("Pin:head.followForceSpingMax"); head.ClearTargetVertex(); state = KnifeState.Out; }; }
public FollowForce AddFollowForce(SoftBody meshdeformer, int vidx, Vector3 pos) { GameObject go = GameObject.Instantiate(FollowForcePrefab); FollowForce followForce = go.GetComponent <FollowForce> (); followForce.SetTargetVertex(meshdeformer, vidx); go.transform.SetParent(transform); go.transform.localRotation = Quaternion.identity; go.transform.localScale = Vector3.one * GlobalScale; go.transform.position = pos; return(followForce); }
// Use this for initialization void Awake() { head = transform.Find("head").GetComponent <FollowForce> (); tail = transform.Find("tail").GetComponent <FollowForce> (); head.followForceSpingMax += delegate() { Debug.Log("Pin:head.followForceSpingMax"); SoftBody deformer = head.target; int vidx = head.VertexIdx; Debug.Log("deformer " + deformer + " " + vidx); head.ClearTargetVertex(); state = PinState.Out; if (PinRope.instance) { PinRope.instance.AddPuncturePoint(deformer, vidx); } }; }
public void Tighten() { float deltaL = 0.01f; Vector3[] offsets = new Vector3[fragments.Count]; for (int i = 0; i < fragments.Count - 1; i++) { offsets[i] = fragments [i + 1].position - fragments [i].position; } for (int i = 1; i < fragments.Count; i++) { FollowForce force = fragments [i].GetComponent <FollowForce> (); //Debug.Log ("force "+force.Force); if (i == 1) { Vector3 dir = fragments[i + 1].position - fragments[i].position; Vector3 dir2 = fragments [i - 1].position - fragments [i].position; Vector3 move = (dir + dir2 * 0.01f) * 0.1f; force.SimpleMove(move); } else if (i == fragments.Count - 1) { Vector3 dir = pin.TailPosition - fragments [i].position; Vector3 dir2 = fragments [i - 1].position - fragments [i].position; Vector3 move = (dir * 0.1f + dir2) * 0.1f; force.SimpleMove(move); } else { Vector3 dir = fragments[i + 1].position - fragments[i].position; Vector3 dir2 = fragments [i - 1].position - fragments [i].position; Vector3 move = (dir + dir2) * 0.1f; force.SimpleMove(move); } } }
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)) { SoftBody deformer = hit.collider.GetComponent <SoftBody> (); if (deformer) { int fidx = hit.triangleIndex; Vector3 vertex; int vidx = deformer.FindNearestVertexInTriangle(fidx, hit.point, out vertex); AddFollowForce(deformer, vidx, hit.point + hit.normal * 0.01f); } } } 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); } } } }
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); } } } }