public static bool ElementInFrustum(GDMesh.Element element) { if ((frustum != null) && (rays != null)) { foreach (GDMesh.Face face in element.faces) { for (int i = 0; i < 3; i++) { if (PointInFrustum(face.vertices[i])) { return(true); } } } } return(false); }
public void DrawElements() { List <Vector3> list = new List <Vector3>(); foreach (int num in this.Controller.selection.selectedElements) { int num2 = 0; GDMesh.Element element = this.Controller.GDMesh.elements[num]; foreach (GDMesh.Face face in element.Faces) { foreach (GDMesh.Vertex vertex in face.Vertices) { list.Add(this.Controller.referencedGO.transform.TransformPoint(vertex.Traits.position)); num2++; } } } GLDrawUtility.DrawTriangle(Color.red, Color.red, Color.red, list.ToArray()); }
public void ProcessMesh(object obj) { ThreadData data = (ThreadData)obj; GDMesh.Element custom = data.custom as GDMesh.Element; GDMesh mesh = data._gdmesh as GDMesh; int[] numArray = data.custom2 as int[]; int num = (int)data.custom3; int num2 = (int)data.custom4; int start = data.start; int end = data.end; try { for (int i = start; i < end; i += 3) { if ((i + 2) < numArray.Length) { FaceTrait vt = new FaceTrait(num2 + (i / 3)); vt.ID = num2 + (i / 3); vt.subMeshIndex = num; vt.subMeshTriID = i; mesh.AddTriangle(vt, this.vertices[numArray[i]], this.vertices[numArray[i + 1]], this.vertices[numArray[i + 2]]).Element = custom; } } this.mutex.WaitOne(); this.finishedCount++; this.mutex.ReleaseMutex(); } catch (Exception exception) { this.ex = exception; this.finishedCount = -1; } }
public void BuildDataStructure(object num) { int num2 = 0; if ((this.subMeshCount == 1) || (this.subMeshCount == 0)) { int num3 = Mathf.Min(SystemInfo.processorCount * 30, this.triangles.Length); if (num3 <= 0) { num3 = 1; } int num4 = (this.triangles.Length / num3) - ((this.triangles.Length / num3) % 3); this.threads = new Thread[num3]; GDMesh.Element item = new GDMesh.Element(); int index = 0; while (index < (num3 - 1)) { ThreadData data = new ThreadData(num4 * index, num4 * (index + 1)); data.custom = item; data._gdmesh = this._gdmesh; data.custom2 = this.triangles; data.custom3 = 0; data.custom4 = 0; this.threads[index] = new Thread(new ParameterizedThreadStart(this.ProcessMesh)); this.threads[index].Priority = System.Threading.ThreadPriority.Highest; this.threads[index].Start(data); index++; } ThreadData parameter = new ThreadData(num4 * index, this.triangles.Length); parameter.custom = item; parameter._gdmesh = this._gdmesh; parameter.custom2 = this.triangles; parameter.custom3 = 0; parameter.custom4 = num2; this.threads[index] = new Thread(new ParameterizedThreadStart(this.ProcessMesh)); this.threads[index].Start(parameter); this.threads[index].Priority = System.Threading.ThreadPriority.Highest; foreach (Thread thread in this.threads) { thread.Join(); } this._gdmesh.faces.Sort(delegate(GDMesh.Face x, GDMesh.Face y) { if (x.Traits.ID < y.Traits.ID) { return(-1); } if (x.Traits.ID > y.Traits.ID) { return(1); } return(0); }); item.Index = 0; this._gdmesh.Elements.Add(item); } else { for (int i = 0; i < this.subMeshCount; i++) { int num7 = Mathf.Min(SystemInfo.processorCount * 30, this.subTriangles[i].Length); if (num7 <= 0) { num7 = 1; } int num8 = (this.subTriangles[i].Length / num7) - ((this.subTriangles[i].Length / num7) % 3); this.threads = new Thread[num7]; GDMesh.Element element2 = new GDMesh.Element(); int num9 = 0; while (num9 < (num7 - 1)) { ThreadData data3 = new ThreadData(num8 * num9, num8 * (num9 + 1)); data3.custom = element2; data3._gdmesh = this._gdmesh; data3.custom2 = this.subTriangles[i]; data3.custom3 = i; data3.custom4 = num2; this.threads[num9] = new Thread(new ParameterizedThreadStart(this.ProcessMesh)); this.threads[num9].Priority = System.Threading.ThreadPriority.Highest; this.threads[num9].Start(data3); num9++; } ThreadData data4 = new ThreadData(num8 * num9, this.subTriangles[i].Length); data4.custom = element2; data4._gdmesh = this._gdmesh; data4.custom2 = this.subTriangles[i]; data4.custom3 = i; data4.custom4 = num2; this.threads[num9] = new Thread(new ParameterizedThreadStart(this.ProcessMesh)); this.threads[num9].Start(data4); this.threads[num9].Priority = System.Threading.ThreadPriority.Highest; foreach (Thread thread2 in this.threads) { thread2.Join(); } num2 += this.subTriangles[i].Length / 3; element2.Index = i; this._gdmesh.Elements.Add(element2); } this._gdmesh.faces.Sort(delegate(GDMesh.Face x, GDMesh.Face y) { if (x.Traits.ID < y.Traits.ID) { return(-1); } if (x.Traits.ID > y.Traits.ID) { return(1); } return(0); }); } this.finishedCount++; }
public void TransformMesh() { if (this.transformed && !this.Controller.locked) { this.transformed = false; List <Vector3> verts = new List <Vector3>(this.Controller.mesh.vertices); if (this.Controller.selection.selectionType == MeshSelection.SelectionType.Vertex) { foreach (int num in this.Controller.selection.selectedVertices) { this.TransformVertex(this.Controller.GDMesh.relatedVertices[num].vert, this.Controller.GDMesh.relatedVertices[num][0]); foreach (int num2 in this.Controller.GDMesh.relatedVertices[num]) { this.TransformVertexReferences(this.Controller.GDMesh.relatedVertices[num].vert, num2, verts); } } } else if (this.Controller.selection.selectionType == MeshSelection.SelectionType.Triangle) { List <int> list2 = new List <int>(); foreach (int num3 in this.Controller.selection.selectedTriangles) { GDMesh.Face face = this.Controller.GDMesh.Faces[num3]; foreach (GDMesh.Vertex vertex in face.Vertices) { if (!list2.Contains(vertex.Traits.hashCode)) { this.TransformVertex(vertex, this.Controller.GDMesh.relatedVertices[vertex.Traits.hashCode][0]); foreach (int num4 in this.Controller.GDMesh.relatedVertices[vertex.Traits.hashCode]) { this.TransformVertexReferences(vertex, num4, verts); } list2.Add(vertex.Traits.hashCode); } } } } else if (this.Controller.selection.selectionType == MeshSelection.SelectionType.Edge) { List <int> list3 = new List <int>(); foreach (int num5 in this.Controller.selection.selectedEdges) { GDMesh.Edge edge = this.Controller.GDMesh.Edges[num5]; GDMesh.Vertex vert = edge.Vertex0; GDMesh.Vertex vertex3 = edge.Vertex1; if (!list3.Contains(vert.Traits.hashCode)) { this.TransformVertex(vert, this.Controller.GDMesh.relatedVertices[vert.Traits.hashCode][0]); foreach (int num6 in this.Controller.GDMesh.relatedVertices[vert.Traits.hashCode]) { this.TransformVertexReferences(vert, num6, verts); } list3.Add(vert.Traits.hashCode); } if (!list3.Contains(vertex3.Traits.hashCode)) { this.TransformVertex(vertex3, this.Controller.GDMesh.relatedVertices[vertex3.Traits.hashCode][0]); foreach (int num7 in this.Controller.GDMesh.relatedVertices[vertex3.Traits.hashCode]) { this.TransformVertexReferences(vertex3, num7, verts); } list3.Add(vertex3.Traits.hashCode); } } } else if (this.Controller.selection.selectionType == MeshSelection.SelectionType.Element) { List <int> list4 = new List <int>(); foreach (int num8 in this.Controller.selection.selectedElements) { GDMesh.Element element = this.Controller.GDMesh.elements[num8]; foreach (GDMesh.Face face2 in element.Faces) { foreach (GDMesh.Vertex vertex4 in face2.Vertices) { if (!list4.Contains(vertex4.Traits.hashCode)) { this.TransformVertex(vertex4, this.Controller.GDMesh.relatedVertices[vertex4.Traits.hashCode][0]); foreach (int num9 in this.Controller.GDMesh.relatedVertices[vertex4.Traits.hashCode]) { this.TransformVertexReferences(vertex4, num9, verts); } list4.Add(vertex4.Traits.hashCode); } } } } } this.Controller.mesh.vertices = verts.ToArray(); if (this.Controller.isSkinned) { this.Controller.referencedRenderer.sharedMesh = this.Controller.mesh; } else { this.Controller.referencedFilter.mesh = this.Controller.mesh; } this.Controller.mesh.RecalculateBounds(); this.Controller.referencedCollider.sharedMesh = null; this.Controller.referencedCollider.sharedMesh = this.Controller.mesh; } }
public static GDMesh Build(Mesh m, GDMesh GDMesh = null) { bool flag = false; bool flag2 = (m.normals != null) && (m.normals.Length == m.vertexCount); bool flag3 = (m.tangents != null) && (m.tangents.Length == m.vertexCount); bool flag4 = (m.colors != null) && (m.colors.Length == m.vertexCount); bool flag5 = (m.uv != null) && (m.uv.Length == m.vertexCount); if (m.uv2 != null) { Vector2[] vectorArray1 = m.uv2; int vertexCount = m.vertexCount; } bool flag6 = (m.uv2 != null) && (m.uv2.Length == m.vertexCount); bool flag7 = (m.boneWeights != null) && (m.boneWeights.Length == m.vertexCount); bool flag8 = (m.bindposes != null) && (m.bindposes.Length > 0); Vector3[] vertices = m.vertices; Vector3[] normals = m.normals; Vector4[] tangents = m.tangents; Color[] colors = m.colors; Vector2[] uv = m.uv; Vector2[] vectorArray6 = m.uv2; Vector2[] vectorArray5 = m.uv2; BoneWeight[] boneWeights = m.boneWeights; int[] triangles = m.triangles; if (GDMesh == null) { flag = true; GDMesh = new GDMesh(m); } GDMesh.vertexCount = m.vertexCount; GDMesh.Vertex[] collection = new GDMesh.Vertex[m.vertexCount]; SerializableDictionary <int, IndexBuffer> relatedVertices = GDMesh.relatedVertices; List <GDMesh.Vertex> list = GDMesh.Vertices; if (flag) { int num = m.vertexCount; for (int i = 0; i < num; i++) { VertexTrait trait = new VertexTrait(i); trait.position = vertices[i]; trait.hashCode = GDMesh.getHashforVector3(m.vertices[i]); trait.ID = i; if (flag2) { trait.Normal = normals[i]; } if (flag3) { trait.tangent = tangents[i]; } if (flag4) { trait.color = colors[i]; } if (flag5) { trait.uv = uv[i]; } if (flag6) { trait.uv2 = vectorArray5[i]; } if (flag7) { trait.boneWeight = boneWeights[i]; } GDMesh.Vertex item = new GDMesh.Vertex(); item.Traits = trait; if (!relatedVertices.ContainsKey(trait.hashCode)) { list.Add(item); AddRelatedVertex(item, GDMesh, false); } else { AddRelatedVertex(item, GDMesh, true); } collection[i] = item; } } else { if (GDController.vertexCount > 0) { collection = new GDMesh.Vertex[GDController.vertexCount]; } int count = list.Count; for (int j = 0; j < count; j++) { IndexBuffer buffer = relatedVertices[list[j].Traits.hashCode]; foreach (int num5 in buffer) { collection[num5] = list[j]; } } } if (!flag) { GDMesh.vertices = new List <GDMesh.Vertex>(collection); if (GDMesh.faces == null) { GDMesh.faces = new List <GDMesh.Face>(); } GDMesh.faces.Clear(); if (GDMesh.edges == null) { GDMesh.edges = new List <GDMesh.Edge>(); } GDMesh.edges.Clear(); if (GDMesh.elements == null) { GDMesh.elements = new List <GDMesh.Element>(); } GDMesh.elements.Clear(); } if (m.subMeshCount == 0) { GDMesh.Element element = new GDMesh.Element(); int length = m.triangles.Length; for (int k = 0; k < length; k += 3) { FaceTrait vt = new FaceTrait(k); vt.ID = k; vt.subMeshIndex = 0; GDMesh.AddTriangle(vt, relatedVertices[collection[triangles[k]].Traits.hashCode].vert, GDMesh.relatedVertices[collection[triangles[k + 1]].Traits.hashCode].vert, GDMesh.relatedVertices[collection[triangles[k + 2]].Traits.hashCode].vert).Element = element; } element.Index = 0; GDMesh.Elements.Add(element); } else { int id = 0; int subMeshCount = m.subMeshCount; for (int n = 0; n < subMeshCount; n++) { GDMesh.Element element2 = new GDMesh.Element(); int[] numArray2 = m.GetTriangles(n); int num11 = numArray2.Length; for (int num12 = 0; num12 < num11; num12 += 3) { FaceTrait trait3 = new FaceTrait(id); trait3.ID = id; trait3.subMeshIndex = n; trait3.subMeshTriID = num12; GDMesh.AddTriangle(trait3, relatedVertices[collection[numArray2[num12]].Traits.hashCode].vert, GDMesh.relatedVertices[collection[numArray2[num12 + 1]].Traits.hashCode].vert, GDMesh.relatedVertices[collection[numArray2[num12 + 2]].Traits.hashCode].vert).Element = element2; id++; } element2.Index = n; GDMesh.Elements.Add(element2); } } if (flag8) { GDMesh.bindposes = new List <Matrix4x4>(m.bindposes); } Quadrangulate(GDMesh, 90f, 5f, 5f, true, false); GDMesh.isBuilt = true; return(GDMesh); }