public void Sync() { foreach (var x in surface) { edges.UnionWith(x.edges); } int count = 0; foreach (var x in edges) { //edgesのjointingの順番整理 int deepness = x.jointing[0].hight - x.jointing[1].hight; if (deepness < 0) { OriFace f = x.jointing[0]; x.jointing[0] = x.jointing[1]; x.jointing[1] = f; deepness = -1 * deepness; } //HinjiJointの設定(親子関係の記述に気をつけなければいけない可能性あり、要デバッグ) HingeJoint hinge = x.jointing[0].Men.AddComponent <HingeJoint>(); hinge.name = "Hingi" + count.ToString(); hinge.connectedBody = x.jointing[1].Men.GetComponent <Rigidbody>(); hinge.axis = x.direction; hinge.anchor = Vector2.Lerp(x.start.p, x.end.p, 0.5f); JointSpring hingeSpring = hinge.spring; hingeSpring.spring = SPRING; hingeSpring.damper = DAMPER; hingeSpring.targetPosition = deepness * CLEARANCE; hinge.spring = hingeSpring; hinge.useSpring = true; count++; } }
public void Registerface(params int[] v) { OriFace f = new OriFace(); f.CreateMesh(v, this.vertexs, face_count); face_count++; surface.Add(f); }
public void AddJointing(OriFace f) { if (joint_size != 2) { jointing[joint_size] = f; joint_size++; } }
public void Registerface(int[] v) { if (face_count == 0) { EdgesDP.init(vertex_count); } OriFace f = new OriFace(mat); f.CreateMesh(v, this.vertexs, face_count); face_count++; surface.Add(f); }
public static OriEdge SameEdge(OriFace f1, OriFace f2) { foreach (OriEdge i in f1.edges) { foreach (OriEdge j in f2.edges) { if (i.Equals(j)) { return(j); } } } return(null); }
public void Activete(int face) { Debug.Log("face:" + face); now_face = face; selectface = main.surface[face]; Debug.Log("face:" + main.surface[face]); Debug.Log("face:" + selectface); active = true; int temp = 0; for (int i = page; i < buttons[now_face].Count && page + 3 > i; i++) { buttons[now_face][i].SetActive(true); temp++; //buttons[now_face][i].GetComponent<SelectEdge>().SetNum(i+1); } page += temp; }
public void AddJointing(OriFace f, bool flag = false) { ways = flag; if (joint_size < 2) { jointing[joint_size] = f; joint_size++; thick = 0; } if (joint_size == 2) { isEnd = false; if (jointing[0].hight < jointing[1].hight) { var tmp = jointing[0]; jointing[0] = jointing[1]; jointing[1] = tmp; } } }
public void TouchRight() { if (page == buttons[now_face].Count) { return; } Debug.Log(buttons.Count); Debug.Log(page); for (int i = 1; i <= 3; i++) { Debug.Log(buttons[now_face][page - i]); buttons[now_face][page - i].SetActive(false); } int temp = 0; for (int i = 0; i < buttons.Count && i < 3; i++) { buttons[now_face][i].SetActive(true); tmp++; } page += temp; Debug.Log("Right"); selectface = null; }
public bool IsSameEdge(OriFace face) { return((SameEdge(this, face) == null) ? false : true); }
public void Init(DataSet.OriFace f, Material m1, Material m2) { face = f; var a = gameObject.transform.position; a.z = UNIT_THICK * f.hight; gameObject.transform.position = a; // Debug.Log(a.z); // Debug.Log(gameObject.transform.position); nomal_material = m1; mesh_material = m2; mesh = new Mesh(); mesh_collider = new Mesh(); Vector3[] v = new Vector3[f.vertexs.Count]; Vector3[] vo = new Vector3[f.vertexs.Count]; Vector3[] v_coll = new Vector3[f.vertexs.Count * 2]; List <int> tri = new List <int>(); List <int> tri_coll = new List <int>(); Vector3[] vec = new Vector3[2]; gameObject.name = f.number.ToString(); for (int i = 0; i < f.vertexs.Count; i++) { v[i] = f.vertexs[i].p; vo[i] = f.vertexs[i].p_origin; v_coll[i] = f.vertexs[i].p; v_coll[i + f.vertexs.Count] = f.vertexs[i].p; v_coll[i].z = UNIT_THICK / 2; v_coll[i + f.vertexs.Count].z = -UNIT_THICK / 2; /* * List<DataSet.OriEdge> edge = f.EdgesIncludeVertex(f.vertexs[i]); * v_coll[i] += new Vector3((f.vertexs[i].p - f.vertexs[(i - 1 + v.Length) % v.Length].p).normalized )* (edge[0].thick + 1) * UNIT_THICK); * v_coll[i + f.vertexs.Count] += (Vector3.Cross(new Vector3(0, 0, 1), f.vertexs[i].p - f.vertexs[(i - 1 + v.Length) % v.Length].p).normalized * (edge[0].thick + 1) * UNIT_THICK); * v_coll[i] += (Vector3.Cross(new Vector3(0, 0, 1), f.vertexs[(i + 1) % v.Length].p - f.vertexs[i].p).normalized * (edge[1].thick + 1) * UNIT_THICK); * v_coll[i + f.vertexs.Count] += (Vector3.Cross(new Vector3(0, 0, 1), f.vertexs[(i + 1) % v.Length].p - f.vertexs[i].p).normalized * (edge[1].thick + 1) * UNIT_THICK); * */} List <Vector2> uv = new List <Vector2>(); for (int i = 0; i < v.Length; i++) { uv.Add(new Vector2(v[i].x, v[i].y)); } mesh_collider.vertices = v_coll; mesh.vertices = v; mesh.name = "mesh" + f.number.ToString(); mesh_collider.name = "Cmesh" + f.number.ToString(); for (int i = 0; i < f.index.Length - 2; i++) { tri.Add(0); tri.Add(i + 1); tri.Add(i + 2); } tri_coll.AddRange(tri); tri_coll.Reverse(); tri_coll.AddRange(tri); for (int i = 0; i < f.vertexs.Count - 1; ++i) { tri_coll[i + f.vertexs.Count] += f.vertexs.Count; if (i == 0) { for (int j = 1; j < f.vertexs.Count; ++j) { tri_coll.Add(0); tri_coll.Add(f.vertexs.Count); tri_coll.Add(j); tri_coll.Add(j); tri_coll.Add(f.vertexs.Count + j); tri_coll.Add(f.vertexs.Count); } } else { tri_coll.Add(i); tri_coll.Add(f.vertexs.Count + i); tri_coll.Add(i + 1); tri_coll.Add(i + 1); tri_coll.Add(f.vertexs.Count + i + 1); tri_coll.Add(f.vertexs.Count + i); } } //Debug.Log(tri.Count); // Debug.Log(mesh.vertexCount - 1); tri_coll[mesh.vertexCount - 1] += f.vertexs.Count; mesh.triangles = tri.ToArray(); mesh_collider.triangles = tri_coll.ToArray(); mesh.RecalculateNormals(); mesh.RecalculateBounds(); mesh_collider.RecalculateNormals(); mesh_collider.RecalculateBounds(); gameObject.AddComponent <MeshFilter>().mesh = mesh; gameObject.AddComponent <MeshRenderer>().material = nomal_material; // Debug.Log(Resources.Load<Texture2D>("texture/sm")); // gameObject.AddComponent<MeshRenderer>().material.mainTexture = Resources.Load<Texture2D>("texture/sm"); MeshCollider coll = gameObject.AddComponent <MeshCollider>(); coll.sharedMesh = mesh_collider; coll.convex = true; coll.material = physic; // coll.isTrigger = true; for (int i = 0; i < face.edges.Count; i++) { if (face.edges[i].isEnd == false) { GameObject x = new GameObject(); x.transform.parent = gameObject.transform; var l = x.AddComponent <LineRenderer>(); l.SetVertexCount(2); l.SetPosition(0, transform.localToWorldMatrix * mesh.vertices[i]); l.SetPosition(1, transform.localToWorldMatrix * mesh.vertices[(i + 1) % mesh.vertexCount]); l.SetWidth(1f, 1f); l.SetColors(nomal_collor, nomal_collor); x.SetActive(false); lines.Add(x); linesfix.Add(false); } } if (GameObject.Find("Origami").GetComponent <OrigamiManager>().isCreateMeshWatcher == true) { Mesh mesho = new Mesh(); mesho.vertices = vo; mesho.triangles = tri.ToArray(); MeshWatcher.GetComponent <MeshFilter>().mesh = mesho; MeshWatcher.GetComponent <MeshRenderer>().material = nomal_material; MeshWatcher.transform.localPosition += new Vector3((f.number + 1) * SECTION, 0, 0); MeshWatcher.transform.parent = GameObject.Find("MeshWatcher").transform; } }