private void Load(string Filename) { var Lines = File.ReadAllLines(Filename); foreach (var L in Lines) { var TL = L.Trim(); if (TL.Length == 0) { continue; } var Line = TL.Split(new char[] { ' ' }); switch (GetLineType(Line)) { case "v": Vertex.Add(GetVector3(Line)); break; case "vt": TexCoord.Add(GetVector2(Line)); break; case "vn": Normal.Add(GetVector3(Line)); break; case "f": LoadFace(Line); break; } } }
public Edge(Vertex start, Vertex end, EdgeType type) { Start = start; End = end; Type = type; Start.Add(this); End.Add(this); }
public void Add(SegTree S, long M) { if (l == null && r == null) { S.Add(p, count * M % Define.mod); } if (l != null) { l.Add(S, M); } if (r != null) { r.Add(S, M); } }
/// <summary> /// Creates a polygon with <see cref="PolygonVertex"/>, what allows colors hard coded. /// </summary> /// <param name="vertices"></param> public Polygon(ICollection <PolygonVertex> vertices) : base(PrimitiveType.TriangleFan) { foreach (var polygonVertex in vertices) { Color.Add(polygonVertex.Color); Vertex.Add(new Vector3(polygonVertex.Position.X, polygonVertex.Position.Y, 0)); } UpdateBoundingBox(); if (UVs.Active) { foreach (var vertex in vertices) { AddUV(vertex.Position); } } }
/// <summary> /// Creates a polygon with <see cref="Vector2"/>s. /// </summary> /// <param name="vertices"></param> public Polygon(ICollection <Vector2> vertices) : base(PrimitiveType.TriangleFan) { Color.Active = false; foreach (var vertex in vertices) { Vertex.Add(new Vector3(vertex)); } UpdateBoundingBox(); if (UVs.Active) { foreach (var vertex in vertices) { AddUV(vertex); } } }
public override void ProcessData(string[] data, float maxValue = default) { base.ProcessData(data, maxValue); var vCount = data.Length - 1; InitializeVertexes(vCount); for (var i = 0; i < vCount; i++) { var parts = data[i + 1].Split('/'); Vertex.Add(i, parts, 0); TextureVertex.Add(i, parts, 1); NormalVertex.Add(i, parts, 2); } }
internal bool parseVertex(TextReader tr) { while (true) { string str = tr.ReadLine().Trim(); if (str.EndsWith("}")) { return(true); } else { MatchCollection mc = MQORegex.Decimal.Matches(str); if (mc.Count != 3) { return(false); } Vertex.Add(new MQOVertex(Decimal.Parse(mc[0].Groups[0].Value), Decimal.Parse(mc[1].Groups[0].Value), Decimal.Parse(mc[2].Groups[0].Value))); continue; } } }
public void Add(SegTree S) { P.Add(S, M * S.rM % Define.mod); }
// Tessallate using loops subdivision public void Tessellate(MeshFilter meshFilter) { Mesh mesh = meshFilter.sharedMesh; MeshData tessMeshData = new MeshData(); int triangleCount = mesh.triangles.Length / 3; int newTriCount = triangleCount * 4; Dictionary <long, Edge> edgeMap = new Dictionary <long, Edge>(); // track the which vertices are adjacent to the original vertex // the original vertex position will be recomputed with weights to // control the shape of the tessellated object a weight of 1 is a hard shell // min wieght of 3/8 is a flexible shell Dictionary <int, HashSet <int> > controlPointAdj = new Dictionary <int, HashSet <int> >(); // new triangle list int[] triangleList = new int[newTriCount * 3]; // new point list add 3 new points per original triangle tessMeshData.Resize(mesh.vertices.Length); // for each face for (int i = 0; i < mesh.triangles.Length; i += 3) { // for each original point in the triangle for (int j = 0; j < 3; ++j) { int triIdx0 = i + j; int triIdx1 = i + ((j + 1) % 3); int triIdx2 = i + ((j + 2) % 3); int index0 = mesh.triangles[triIdx0]; int index1 = mesh.triangles[triIdx1]; int index2 = mesh.triangles[triIdx2]; // copy original point CopyVertex(tessMeshData, mesh, index0); CopyVertex(tessMeshData, mesh, index1); CopyVertex(tessMeshData, mesh, index2); // create or get edges always min/max the indices so we refer to the edges // in a consistent manner // edge 0 to 1 long edgeId0 = (Math.Min(index0, index1) << 16) + Math.Max(index0, index1); // edge 0 to 2 long edgeId1 = (Math.Min(index0, index2) << 16) + Math.Max(index0, index2); Edge edge0 = null; if (!edgeMap.TryGetValue(edgeId0, out edge0)) { edge0 = new Edge(); edge0.m_index = CreateVertex(tessMeshData, edge0.m_index, mesh, index0, index1, 0.5f); edgeMap.Add(edgeId0, edge0); } Edge edge1 = null; if (!edgeMap.TryGetValue(edgeId1, out edge1)) { edge1 = new Edge(); edge1.m_index = CreateVertex(tessMeshData, edge1.m_index, mesh, index0, index2, 0.5f); edgeMap.Add(edgeId1, edge1); } // create triangle using the same winding order as original triangle triangleList[i * 4 + j * 3] = index0; triangleList[i * 4 + j * 3 + 1] = edge0.m_index; triangleList[i * 4 + j * 3 + 2] = edge1.m_index; if (!controlPointAdj.ContainsKey(index0)) { controlPointAdj.Add(index0, new HashSet <int>()); } var hashSet = controlPointAdj[index0]; hashSet.Add(edge0.m_index); hashSet.Add(edge1.m_index); } // Debug.Log("index " + i/3 + " of " + mesh.triangles.Length/3 + ", added index" // + (newIndexOffset) + " verts total now " + (tessMeshData.m_position.Count)); // Loops subdivision is 1:4 tessellation, the previous loop created 3 new triangles from 1, now add the fourth { long index0 = mesh.triangles[i]; long index1 = mesh.triangles[i + 1]; long index2 = mesh.triangles[i + 2]; // edge 0 to 1 long edgeId0 = (Math.Min(index0, index1) << 16) + Math.Max(index0, index1); // edge 0 to 2 long edgeId1 = (Math.Min(index0, index2) << 16) + Math.Max(index0, index2); // edge 1 to 2 long edgeId2 = (Math.Min(index1, index2) << 16) + Math.Max(index1, index2); triangleList[i * 4 + 9] = edgeMap[edgeId0].m_index; triangleList[i * 4 + 10] = edgeMap[edgeId2].m_index; triangleList[i * 4 + 11] = edgeMap[edgeId1].m_index; } } // using the new points adjacent to the control point (the original vertex) compute the control points new position Vertex avgVert = new Vertex(); var controlIter = controlPointAdj.GetEnumerator(); while (controlIter.MoveNext()) { // if adjacencies are less than 6 we assume this control is on an edge // to preserve the shape of the object we do not reposition this point if (controlIter.Current.Value.Count < 6) { continue; } int ctlIdx = controlIter.Current.Key; int[] adj = new int[controlIter.Current.Value.Count]; controlIter.Current.Value.CopyTo(adj); float controlWieght = (3f / 8f) + Mathf.Pow((3f / 8f) + 0.25f * Mathf.Cos(2f * Mathf.PI / (float)adj.Length), 2f); // float controlWieght = (5f/8f); float influenceWeight = (1f - controlWieght); avgVert.Set(tessMeshData, adj[0]); for (int i = 1, k = adj.Length; i < k; ++i) { avgVert.Add(tessMeshData, adj[i]); } avgVert.ScalarMult(1f / adj.Length); InterpolatedVertex(tessMeshData, ctlIdx, avgVert, influenceWeight); } // output temporary mesh Mesh tessMesh = tessMeshData.GenerateMesh(); tessMesh.name = "test"; tessMesh.SetTriangles(triangleList, 0); AssetDatabase.CreateAsset(tessMesh, BakeData.kDaydreamPath + "/tessTestMesh.asset"); AssetDatabase.SaveAssets(); tessMesh = AssetDatabase.LoadAssetAtPath <Mesh>(BakeData.kDaydreamPath + "/tessTestMesh.asset"); GameObject go = new GameObject("TessMesh"); MeshFilter mf = go.AddComponent <MeshFilter>(); mf.mesh = tessMesh; go.AddComponent <MeshRenderer>(); EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene()); EditorSceneManager.SaveScene(EditorSceneManager.GetActiveScene()); }