private void OnDrawGizmos() { Ray3 ray = CreateRay3(Ray); Triangle3 triangle = CreateTriangle3(V0, V1, V2); IntersectionTypes intersectionType; bool test = Intersection.TestRay3Triangle3(ref ray, ref triangle, out intersectionType); Ray3Triangle3Intr info; bool find = Intersection.FindRay3Triangle3(ref ray, ref triangle, out info); FiguresColor(); DrawRay(ref ray); DrawTriangle(ref triangle); if (find) { ResultsColor(); DrawPoint(info.Point); } LogInfo(info.IntersectionType); if (test != find) { LogError("test != find"); } if (intersectionType != info.IntersectionType) { LogError("intersectionType != info.IntersectionType"); } }
//from http://stackoverflow.com/a/17503268/931669 public static bool existsBetween(Bounds box, Triangle3 triangle) { double triangleMin, triangleMax; double boxMin, boxMax; // Test the box normals (x-, y- and z-axes) var boxNormals = new Vector3[] { new Vector3(1,0,0), new Vector3(0,1,0), new Vector3(0,0,1) }; //Get the box vertices as array for project() var boxVertices = new Vector3[] { box.center + new Vector3(box.extents.x, box.extents.y, box.extents.z), box.center + new Vector3(box.extents.x, -box.extents.y, box.extents.z), box.center + new Vector3(-box.extents.x, -box.extents.y, box.extents.z), box.center + new Vector3(-box.extents.x, box.extents.y, box.extents.z), box.center + new Vector3(box.extents.x, box.extents.y, -box.extents.z), box.center + new Vector3(box.extents.x, -box.extents.y, -box.extents.z), box.center + new Vector3(-box.extents.x, -box.extents.y, -box.extents.z), box.center + new Vector3(-box.extents.x, box.extents.y, -box.extents.z), }; for (int i = 0; i < 3; i++) { project(triangle.ABC, boxNormals[i], out triangleMin, out triangleMax); if (triangleMax < box.min[i] || triangleMin > box.max[i]) return false; // No intersection possible. } // Test the triangle normal double triangleOffset = Vector3.Dot(triangle.Normal, triangle.A); project(boxVertices, triangle.Normal, out boxMin, out boxMax); if (boxMax < triangleOffset || boxMin > triangleOffset) return false; // No intersection possible. // Test the nine edge cross-products Vector3[] triangleEdges = new Vector3[] { triangle.A - (triangle.B), triangle.B - (triangle.C), triangle.C - (triangle.A) }; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { // The box normals are the same as it's edge tangents Vector3 axis = Vector3.Cross(triangleEdges[i], boxNormals[j]); project(boxVertices, axis, out boxMin, out boxMax); project(triangle.ABC, axis, out triangleMin, out triangleMax); if (boxMax <= triangleMin || boxMin >= triangleMax) return false; // No intersection possible } } // No separating axis found. return true; }
/// <summary> /// Prepare the obstacles for further calculations /// </summary> /// <param name="position">Current position</param> /// <param name="desiredVel">Desired velocity</param> public void Prepare(Vector3 position, Vector3 desiredVel) { //prepare obstacles for (int i = 0; i < numCircles; i++) { //side Vector3 pa = position; Vector3 pb = circles[i].Position; Vector3 orig = new Vector3(0, 0, 0); circles[i].Dp = pb - pa; circles[i].Dp.Normalize(); Vector3 dv = circles[i].DesiredVel - desiredVel; float a = Triangle3.Area2D(orig, circles[i].Dp, dv); if (a < 0.01f) { circles[i].Np.X = -circles[i].Dp.Z; circles[i].Np.Z = circles[i].Dp.X; } else { circles[i].Np.X = circles[i].Dp.Z; circles[i].Np.Z = -circles[i].Dp.X; } } for (int i = 0; i < numSegments; i++) { //precalculate if the agent is close to the segment float r = 0.01f; float t; segments[i].Touch = Distance.PointToSegment2DSquared(ref position, ref segments[i].P, ref segments[i].Q, out t) < (r * r); } }
//public static string LogText = ""; public static void ShowTriangles() { for (int i = 0; i < navMeshInfo.triangle3s.Count; i++) { Triangle3 triangle3 = navMeshInfo.triangle3s[i]; Plane3 plane = navMeshInfo.planes[i]; //Vector3 point = target; //Vector3 closestPoint; //float dist0 = Distance.Point3Plane3(ref point, ref plane, out closestPoint); //Line3 line = new Line3(point, target); //Triangle3 triangle = triangle3; //Line3Triangle3Intr info; //bool find = Intersection.FindLine3Triangle3(ref line, ref triangle, out info); //if (find) //只有点在三角形内才有效 //{ // //Debug.Log(string.Format("[{0}]{1} {2} {3}", i, dist0, closestPoint, find)); // if (dist0 < distance) // { // distance = dist0; // r = closestPoint; // } //} } //TimeSpan time = DateTime.Now - start; //Log += (string.Format( // "GetClosetPointByTriangle,indices count:{0},distance:{1},closestPoint{2},target:{3},time:{4}ms ", // navMeshInfo.indicesCount, distance, r, target, time.TotalMilliseconds)); }
private void OnDrawGizmos() { Vector3 v0 = V0.position; Vector3 v1 = V1.position; Vector3 v2 = V2.position; Triangle3 triangle = CreateTriangle3(V0, V1, V2); Circle3 circumscribed; bool b0 = Circle3.CreateCircumscribed(v0, v1, v2, out circumscribed); Circle3 inscribed; bool b1 = Circle3.CreateInscribed(v0, v1, v2, out inscribed); FiguresColor(); DrawTriangle(ref triangle); ResultsColor(); if (b0) { DrawCircle(ref circumscribed); } if (b1) { DrawCircle(ref inscribed); } LogInfo("Circumscribed: " + b0 + " Inscribed: " + b1); }
private void OnDrawGizmos() { HashSet <Triangle2> grid = _GenerateMesh.GenerateGrid(width, cells); if (grid != null) { //But this will not display each triangle, so we don't know if the mesh is correct //Gizmos.DrawMesh(grid, Vector3.zero, Quaternion.identity); //Convert the triangles to a mesh //2d to 3d HashSet <Triangle3> grid_3d = new HashSet <Triangle3>(); foreach (Triangle2 t in grid) { Triangle3 t_3d = new Triangle3(t.p1.ToMyVector3_Yis3D(), t.p2.ToMyVector3_Yis3D(), t.p3.ToMyVector3_Yis3D()); grid_3d.Add(t_3d); } //Triangle to mesh //Will also test that the triangle->mesh is working //Mesh meshGrid = TransformBetweenDataStructures.Triangle3ToCompressedMesh(grid_3d); Mesh meshGrid = _TransformBetweenDataStructures.Triangle3ToMesh(grid_3d); TestAlgorithmsHelpMethods.DisplayMeshWithRandomColors(meshGrid, 0); } }
public void JsonNet_Test() { // Simple test to make sure that the JSON.Net library is working Triangle3 triangle = new Triangle3(new Vector3(3), new Vector3(4), new Vector3(5)); string output = JsonConvert.SerializeObject(triangle); }
public Model(Mesh source) { vertices = new List <Vertex>(); edges = new List <Edge3>(); this.triangles = new List <Triangle3>(); Vector3[] points = source.vertices; for (int i = 0, n = points.Length; i < n; i++) { Vertex v = new Vertex(points[i], i); vertices.Add(v); } int[] triangles = source.triangles; for (int i = 0, n = triangles.Length; i < n; i += 3) { int i0 = triangles[i], i1 = triangles[i + 1], i2 = triangles[i + 2]; Vertex v0 = vertices[i0], v1 = vertices[i1], v2 = vertices[i2]; Edge3 e0 = GetEdge(edges, v0, v1); Edge3 e1 = GetEdge(edges, v1, v2); Edge3 e2 = GetEdge(edges, v2, v0); Triangle3 f = new Triangle3(v0, v1, v2, e0, e1, e2); this.triangles.Add(f); v0.AddTriangle(f); v1.AddTriangle(f); v2.AddTriangle(f); e0.AddTriangle(f); e1.AddTriangle(f); e2.AddTriangle(f); } }
private void OnDrawGizmos() { Segment3 segment = CreateSegment3(P0, P1); Triangle3 triangle = CreateTriangle3(V0, V1, V2); IntersectionTypes intersectionType; bool test = Intersection.TestSegment3Triangle3(ref segment, ref triangle, out intersectionType); Segment3Triangle3Intr info; bool find = Intersection.FindSegment3Triangle3(ref segment, ref triangle, out info); FiguresColor(); DrawSegment(ref segment); DrawTriangle(ref triangle); if (find) { ResultsColor(); DrawPoint(info.Point); } LogInfo(info.IntersectionType + " " + info.SegmentParameter); if (test != find) { LogError("test != find"); } if (intersectionType != info.IntersectionType) { LogError("intersectionType != info.IntersectionType"); } }
public Mesh Build(bool weld = false) { Mesh mesh = new Mesh(); int[] triangles = new int[this.triangles.Count * 3]; Vector3[] vertices = new Vector3[this.triangles.Count * 3]; for (int i = 0, n = this.triangles.Count; i < n; i++) { Triangle3 f = this.triangles[i]; int i0 = i * 3, i1 = i * 3 + 1, i2 = i * 3 + 2; vertices[i0] = f.v0.p; vertices[i1] = f.v1.p; vertices[i2] = f.v2.p; triangles[i0] = i0; triangles[i1] = i1; triangles[i2] = i2; } mesh.vertices = vertices; mesh.indexFormat = mesh.vertexCount < 65535 ? IndexFormat.UInt16 : IndexFormat.UInt32; mesh.triangles = triangles; mesh.RecalculateNormals(); mesh.RecalculateBounds(); return(mesh); }
private void OnDrawGizmos() { Line3 line = new Line3(Line.position, Line.forward); Triangle3 triangle = CreateTriangle3(V0, V1, V2); IntersectionTypes intersectionType; bool test = Intersection.TestLine3Triangle3(ref line, ref triangle, out intersectionType); Line3Triangle3Intr info; bool find = Intersection.FindLine3Triangle3(ref line, ref triangle, out info); FiguresColor(); DrawLine(ref line); DrawTriangle(ref triangle); if (find) { ResultsColor(); DrawPoint(info.Point); } LogInfo(info.IntersectionType); if (test != find) { LogError("test != find"); } if (intersectionType != info.IntersectionType) { LogError("intersectionType != info.IntersectionType"); } }
public static bool IsPointInTriangle(double px, double py, ref Triangle3 triangle) { // Barycentric coordinates for PIP w/ triangle test http://blackpawn.com/texts/pointinpoly/ var ax = triangle.Points.A.X; var ay = triangle.Points.A.Y; var bx = triangle.Points.B.X; var by = triangle.Points.B.Y; var cx = triangle.Points.C.X; var cy = triangle.Points.C.Y; var v0x = cx - ax; var v0y = cy - ay; var v1x = bx - ax; var v1y = by - ay; var v2x = px - ax; var v2y = py - ay; var dot00 = v0x * v0x + v0y * v0y; var dot01 = v0x * v1x + v0y * v1y; var dot02 = v0x * v2x + v0y * v2y; var dot11 = v1x * v1x + v1y * v1y; var dot12 = v1x * v2x + v1y * v2y; var invDenom = 1.0 / (dot00 * dot11 - dot01 * dot01); var u = (dot11 * dot02 - dot01 * dot12) * invDenom; var v = (dot00 * dot12 - dot01 * dot02) * invDenom; return((u >= 0) && (v >= 0) && (u + v <= 1)); }
/// <summary> /// Rasterizes several triangles at once. /// </summary> /// <param name="tris">An array of triangles.</param> /// <param name="triOffset">An offset into the array.</param> /// <param name="triCount">The number of triangles to rasterize, starting from the offset.</param> /// <param name="area">The area flags for all of the triangles.</param> public void RasterizeTriangles(Triangle3[] tris, int triOffset, int triCount, Area area) { int triEnd = triOffset + triCount; if (tris == null) { throw new ArgumentNullException("verts"); } if (triOffset < 0) { throw new ArgumentOutOfRangeException("triOffset", "triOffset must be greater than or equal to 0."); } if (triCount < 0) { throw new ArgumentOutOfRangeException("triCount", "triCount must be greater than or equal to 0."); } if (triEnd > tris.Length) { throw new ArgumentOutOfRangeException("triCount", "The specified offset and count end outside the bounds of the provided array."); } int numBatches = 8; int threads = (triCount / numBatches) + 1; /*spanQueue = new ConcurrentQueue<Tuple<int, int, Span>>(); * bool allProcessed; * * var task = Task.Factory.StartNew(() => * { * while (true) * { * if (spanQueue.IsEmpty) * Thread.Sleep(1); * * Tuple<int, int, Span> spanEntry; * while (spanQueue.TryDequeue(out spanEntry)) * cells[spanEntry.Item2 * width + spanEntry.Item1].AddSpan(spanEntry.Item3); * } * });*/ Parallel.For(0, threads, i => { int start = triOffset + i * numBatches; int end = triOffset + (i + 1) * numBatches; if (end > triEnd) { end = triEnd; } for (int j = start; j < end; j++) { Triangle3 t = tris[j]; RasterizeTriangle(ref t.A, ref t.B, ref t.C, area); } }); }
public static void FillTriangle(this IDebugCanvas canvas, Triangle3 triangle, FillStyle fillStyle) { canvas.FillTriangle( new DoubleVector3((float)triangle.Points.A.X, (float)triangle.Points.A.Y, 0), new DoubleVector3((float)triangle.Points.B.X, (float)triangle.Points.B.Y, 0), new DoubleVector3((float)triangle.Points.C.X, (float)triangle.Points.C.Y, 0), fillStyle); }
public static float Vector3Triangle3( ref Vector3 point, ref Triangle3 triangle, out Vector3 closestPoint ) { return((float)System.Math.Sqrt(SquaredDistance.Vector3Triangle3(ref point, ref triangle, out closestPoint))); }
public static bool existsBetween(Collider collider, Triangle3 triangle) { RaycastHit info; return ( collider.Raycast(new Ray(triangle.A, triangle.B - triangle.A), out info, (triangle.B - triangle.A).magnitude) || collider.Raycast(new Ray(triangle.B, triangle.C - triangle.B), out info, (triangle.C - triangle.B).magnitude) || collider.Raycast(new Ray(triangle.C, triangle.A - triangle.C), out info, (triangle.A - triangle.C).magnitude) ); }
public static bool IntersectTriangle3Triangle3( ref Triangle3 triangle1, ref Triangle3 triangle2 ) { return(NoDivTriangleTriangleIntersection( ref triangle1.Vertex0, ref triangle1.Vertex1, ref triangle1.Vertex2, ref triangle2.Vertex0, ref triangle2.Vertex1, ref triangle2.Vertex2)); }
/// <summary>Determines where the range clips a triangle</summary> /// <param name="triangle">Triangle that will be checked for intersection</param> /// <returns>The times at which the range touches the triangle, if at all</returns> public LineContacts FindContacts(Triangle3 triangle) { LineContacts contacts = Collisions.Line3Triangle3Collider.FindContacts( Origin, Direction, triangle.A, triangle.B, triangle.C ); limitContactToRay(ref contacts); return(contacts); }
private static Vector3 GetClosetPointByTriangle1(Vector3 target) { //var triangleParent=CreatePoint(Vector3.zero,"TriangleParent",1,Color.black); DateTime start = DateTime.Now; Vector3 r = Vector3.zero; //if (vertices == null) { var distance = float.MaxValue; //NavMeshInfo navMeshInfo = null; if (navMeshInfo == null) { navMeshInfo = new NavMeshInfo(); } for (int i = 0; i < navMeshInfo.triangle3s.Count; i++) { Triangle3 triangle3 = navMeshInfo.triangle3s[i]; Plane3 plane = navMeshInfo.planes[i]; Vector3 point = target; Vector3 closestPoint; float dist0 = Distance.Point3Plane3(ref point, ref plane, out closestPoint); Line3 line = new Line3(target, closestPoint - target); Triangle3 triangle = triangle3; Line3Triangle3Intr info; bool find = Intersection.FindLine3Triangle3(ref line, ref triangle, out info); if (find) //只有点在三角形内才有效 { //Debug.Log(string.Format("[{0}]{1} {2} {3}", i, dist0, closestPoint, find)); if (dist0 < distance) { distance = dist0; r = closestPoint; //var tri=ShowTriangle(triangleParent, i, triangle3.V0, triangle3.V1, triangle3.V2); //var pt=CreatePoint(info.Point, i + "," + info.IntersectionType + "," + info.LineParameter + "," + info.TriBary0 + "," + info.TriBary1 + "," + info.TriBary2, 0.1f, Color.black); //pt.transform.parent = tri.transform; //var pt2 = CreatePoint(closestPoint, i+","+closestPoint+","+ dist0, 0.1f, Color.black); //pt2.transform.parent = tri.transform; } } } TimeSpan time = DateTime.Now - start; LogText += (string.Format( "GetClosetPointByTriangle,indices count:{0},distance:{1},closestPoint{2},target:{3},time:{4}ms ", navMeshInfo.indicesCount, distance, r, target, time.TotalMilliseconds)); } return(r); }
//Checks for containment first, then for intersection public static bool existsBetweenOrInside(Bounds box, Triangle3 triangle) { foreach (Vector3 p in triangle.ABC) { if(box.Contains(p)) return true; } return existsBetween(box, triangle); }
public const int VERTS_PER_POLYGON = 6; //max number of vertices /// <summary> /// Generate an accurate sample of random points in the convex polygon and pick a point. /// </summary> /// <param name="pts">The polygon's points data</param> /// <param name="s">A random float</param> /// <param name="t">Another random float</param> /// <param name="pt">The resulting point</param> public static void RandomPointInConvexPoly(Vector3[] pts, float s, float t, out Vector3 pt) { //Calculate triangle areas float[] areas = new float[pts.Length]; float areaSum = 0.0f; float area; for (int i = 2; i < pts.Length; i++) { Triangle3.Area2D(ref pts[0], ref pts[i - 1], ref pts[i], out area); areaSum += Math.Max(0.001f, area); areas[i] = area; } //Find sub triangle weighted by area float threshold = s * areaSum; float accumulatedArea = 0.0f; float u = 0.0f; int triangleVertex = 0; for (int i = 2; i < pts.Length; i++) { float currentArea = areas[i]; if (threshold >= accumulatedArea && threshold < (accumulatedArea + currentArea)) { u = (threshold - accumulatedArea) / currentArea; triangleVertex = i; break; } accumulatedArea += currentArea; } float v = (float)Math.Sqrt(t); float a = 1 - v; float b = (1 - u) * v; float c = u * v; if (triangleVertex > 0) { Vector3 pointA = pts[0]; Vector3 pointB = pts[triangleVertex - 1]; Vector3 pointC = pts[triangleVertex]; pt = a * pointA + b * pointB + c * pointC; } else { Console.WriteLine("triangleVertex<1"); Vector3 pointA = pts[0]; Vector3 pointB = pts[0]; Vector3 pointC = pts[0]; pt = a * pointA + b * pointB + c * pointC; } }
public Triangle3 Reflect(Triangle3 triangle) { if (!this.valid) { return(triangle); } return(new Triangle3(Reflect(triangle.A), Reflect(triangle.B), Reflect(triangle.C))); }
// generate a loat texture map which contains the XYZ(Valid) position of every triangle Texture GeneratePositionTextureMap(Mesh mesh, out Vector2[] VertexAtlasUvs, int TextureSize) { // generate atlas var MeshTriangles = new List <Triangle3>(); var Positions = mesh.vertices; var TriangleIndexes = mesh.triangles; if (Positions.Length != TriangleIndexes.Length) { throw new System.Exception("Mesh vertexes need to be unshared. To use shared vertexes we may need to split individual triangles depending on atlasing"); } System.Action <int, int, int> AddTriangleByVertexIndexes = (a, b, c) => { var Triangle = new Triangle3(); Triangle.a = Positions[a]; Triangle.b = Positions[b]; Triangle.c = Positions[c]; MeshTriangles.Add(Triangle); }; for (int t = 0; t < TriangleIndexes.Length; t += 3) { var ia = TriangleIndexes[t + 0]; var ib = TriangleIndexes[t + 1]; var ic = TriangleIndexes[t + 2]; AddTriangleByVertexIndexes(ia, ib, ic); } var AtlasTriangles = PopTrianglePacker.AllocateTriangleAtlases(MeshTriangles); var AtlasTexture = new RenderTexture(TextureSize, TextureSize, 0, RenderTextureFormat.ARGBFloat); AtlasTexture.filterMode = FilterMode.Point; RenderTriangleAtlas(ref AtlasTexture, AtlasTriangles, MeshTriangles); // need to give vertexes new uvs! one per vertex // one VertexAtlasUvs = new Vector2[Positions.Length]; for (int t = 0; t < TriangleIndexes.Length / 3; t++) { var TriangleIndex = t * 3; var VertexIndexa = TriangleIndexes[TriangleIndex + 0]; var VertexIndexb = TriangleIndexes[TriangleIndex + 1]; var VertexIndexc = TriangleIndexes[TriangleIndex + 2]; // get uvs of triangle var uva = AtlasTriangles[t].a; var uvb = AtlasTriangles[t].b; var uvc = AtlasTriangles[t].c; VertexAtlasUvs[VertexIndexa] = uva; VertexAtlasUvs[VertexIndexb] = uvb; VertexAtlasUvs[VertexIndexc] = uvc; } return(AtlasTexture); }
public Triangle3() { this.a = TVector3.Tzero; this.b = TVector3.Tzero; this.c = TVector3.Tzero; this.Tag = ""; this.Complement = null; }
/// <summary> /// Rasterizes several triangles at once. /// </summary> /// <param name="tris">A collection of triangles.</param> /// <param name="area">The area flags for all of the triangles.</param> public void RasterizeTriangles(IEnumerable <Triangle3> tris, Area area) { Triangle3 t = new Triangle3(); foreach (Triangle3 tri in tris) { t = tri; RasterizeTriangle(ref t, area); } }
/// <summary>Determines where the range clips a triangle</summary> /// <param name="triangle">Triangle that will be checked for intersection</param> /// <returns>The times at which the range touches the triangle, if at all</returns> public LineContacts FindContacts(Triangle3 triangle) { LineContacts contacts = Collisions.Line3Triangle3Collider.FindContacts( Start, End - Start, triangle.A, triangle.B, triangle.C ); limitContactToLineSegment(ref contacts); return(contacts); }
public Triangle3 Copy() { Triangle3 ret = new Triangle3(); ret.a = this.a.Copy(); ret.b = this.b.Copy(); ret.c = this.c.Copy(); ret.Tag = this.Tag; ret.SortOrder = this.SortOrder; ret.Complement = new Triangle3(); return(ret); }
public static bool IntersectTriangle3Triangle3( ref Triangle3 triangle1, ref Triangle3 triangle2, out bool coplanar, out Vector3 isectpt1, out Vector3 isectpt2 ) { return(TriangleTriangleIntersectionWithIntersectionLine( triangle1.Vertex0, triangle1.Vertex1, triangle1.Vertex2, triangle2.Vertex0, triangle2.Vertex1, triangle2.Vertex2, out coplanar, out isectpt1, out isectpt2 )); }
/// <summary> /// Rasterizes several triangles at once. /// </summary> /// <param name="tris">A collection of triangles.</param> /// <param name="area">The area flags for all of the triangles.</param> public void RasterizeTriangles(IEnumerable <Triangle3> tris, Area area) { foreach (var t in tris) { Triangle3 tref = t; RasterizeTriangle(ref tref, area); } /* * Parallel.ForEach(tris, t => * { * RasterizeTriangle(ref t, area); * }); */ }
private static void CollideLeafLeaf( Entity entity1, AlignedBox3TreeNode node1, Vector3[] positions1, ref Matrix worldTransform1, Entity entity2, AlignedBox3TreeNode node2, Vector3[] positions2, ref Matrix worldTransform2, ref Contact contact, bool reverse ) { Sphere3 sphere1, sphere2; node1.BoundingBox.CreateSphere3(ref worldTransform1, out sphere1); node2.BoundingBox.CreateSphere3(ref worldTransform2, out sphere2); if ((sphere1.Center - sphere2.Center).LengthSquared() > (sphere1.Radius + sphere2.Radius) * (sphere1.Radius + sphere2.Radius)) { return; } // "simple" tri<->tri test... for (int i = 0; i < node1.NumTriangles; ++i) { Triangle3 tri1 = node1.GetTriangle(positions1, i); tri1.Vertex0 = Vector3.Transform(tri1.Vertex0, worldTransform1); tri1.Vertex1 = Vector3.Transform(tri1.Vertex1, worldTransform1); tri1.Vertex2 = Vector3.Transform(tri1.Vertex2, worldTransform1); for (int j = 0; j < node2.NumTriangles; ++j) { Triangle3 tri2 = node2.GetTriangle(positions2, j); tri2.Vertex0 = Vector3.Transform(tri2.Vertex0, worldTransform2); tri2.Vertex1 = Vector3.Transform(tri2.Vertex1, worldTransform2); tri2.Vertex2 = Vector3.Transform(tri2.Vertex2, worldTransform2); //System.Console.WriteLine("performing triangle<->triangle test!"); bool coplanar; Vector3 isectpt1, isectpt2; if (Intersection.IntersectTriangle3Triangle3(ref tri1, ref tri2, out coplanar, out isectpt1, out isectpt2)) { Vector3 point = (isectpt1 + isectpt2) / 2.0f; if (!contact.ContainsPoint(ref point)) { Debug.Assert((reverse && contact.EntityA == entity2) || contact.EntityA == entity1); Vector3 normal = reverse ? tri2.Normal : tri1.Normal; contact.AddContactPoint(ref point, ref normal); } } } } }
public void SetUniforms(Material DrawTriangleMaterial, Triangle2 TriangleUvs, Triangle3 TriangleColours) { var Uvs = new List <Vector2>(); Uvs.Add(TriangleUvs.a); Uvs.Add(TriangleUvs.b); Uvs.Add(TriangleUvs.c); var Colours = new List <Color>(); Colours.Add(new Color(TriangleColours.a.x, TriangleColours.a.y, TriangleColours.a.z, 1)); Colours.Add(new Color(TriangleColours.b.x, TriangleColours.b.y, TriangleColours.b.z, 1)); Colours.Add(new Color(TriangleColours.c.x, TriangleColours.c.y, TriangleColours.c.z, 1)); SetUniforms(DrawTriangleMaterial, Uvs, Colours); }
private void OnDrawGizmos() { Triangle3 triangle0 = CreateTriangle3(V0, V1, V2); Triangle3 triangle1 = CreateTriangle3(P0, P1, P2); FiguresColor(); DrawTriangle(ref triangle0); DrawTriangle(ref triangle1); bool test = Intersection.TestTriangle3Triangle3(ref triangle0, ref triangle1); Triangle3Triangle3Intr info; bool find = Intersection.FindTriangle3Triangle3(ref triangle0, ref triangle1, out info, true); if (find) { ResultsColor(); if (info.IntersectionType == IntersectionTypes.Point) { DrawPoint(info.Point0); } else if (info.IntersectionType == IntersectionTypes.Segment) { DrawSegment(info.Point0, info.Point1); DrawPoint(info.Point0); DrawPoint(info.Point1); } else if (info.IntersectionType == IntersectionTypes.Plane) { for (int i = 0; i < info.Quantity; ++i) { DrawSegment(info[i], info[(i + 1) % info.Quantity]); DrawPoint(info[i]); } } } LogInfo("Type: " + info.IntersectionType + " CoplanarType: " + info.CoplanarIntersectionType + " Touching: " + info.Touching + " Quantity: " + info.Quantity); if (test != find) { LogError("test != find"); } }
public Triangle3[] GetTris(){ Triangle3[] tris = new Triangle3[2]; Triangle3 t1 = new Triangle3(); Triangle3 t2 = new Triangle3(); t1.a = a; t1.b = b; t1.c = c; t1.Tag = this.Tag; t2.a = a; t2.b = c; t2.c = d; t2.Tag = this.Tag; tris[0] = t1; tris[1] = t2; return tris; }
public Triangle3[] GetTris() { Triangle3[] tris = new Triangle3[2]; Triangle3 t1 = new Triangle3(); Triangle3 t2 = new Triangle3(); t1.a = a; t1.b = b; t1.c = c; t1.Tag = this.Tag; t2.a = a; t2.b = c; t2.c = d; t2.Tag = this.Tag; tris[0] = t1; tris[1] = t2; return(tris); }
void Start() { // triangle verticies triangle = new Triangle3 ( new Vec3(0, 0, .33f), new Vec3(0, 1.5f, 0), new Vec3(1, 0, -.12f) ); // create unity mesh triangleMesh = new Mesh(); triangleMesh.vertices = new Vector3[3] { triangle.point1.ToVector3(), triangle.point2.ToVector3(), triangle.point3.ToVector3() }; triangleMesh.SetIndices(new int[3] { 0, 1, 2 }, MeshTopology.Triangles, 0); }
public Triangle3 Copy() { Triangle3 ret = new Triangle3(); ret.a = this.a.Copy(); ret.b = this.b.Copy(); ret.c = this.c.Copy(); ret.Tag = this.Tag; ret.SortOrder = this.SortOrder; ret.Complement = new Triangle3(); return ret; }
public Shape3D GetRingGear() { System.Collections.Generic.List<Triangle3> tris = new List<Triangle3> (); float OuterWidth = 0.0f; float ToothBaseWidth = 0.0f; Shape3D ret; _origin.Tag = VERT_origin; ToothBaseWidth = (float)(_innerRadius * 2 * Mathf.PI / (((float)(_qtyTeeth)) * (_outerWidthPct + 1))); OuterWidth = ToothBaseWidth * _outerWidthPct; //Calc the angle to sweep... float inctheta = 2 * Mathf.PI / ((float)_qtyTeeth * (_outerWidthPct + 1)); float theta = 0.0f; float ToothRotAngle = _toothRot * Mathf.PI / 360.0f; float phi = (inctheta *_outerRadius - OuterWidth) / (2 *_outerRadius); for (int i = 0; i < _qtyTeeth * 2; i++) { TVector3 a; TVector3 b; TVector3 c; TVector3 ta; TVector3 tb; TVector3 tc; float adjAngle = 0.0f; float angleBuffera = 0; float angleBufferc = 0; Triangle3 t = new Triangle3(); if (i % 2 == 0) { adjAngle = inctheta; angleBuffera = inctheta / 2.0f; //LargePoints angleBufferc = inctheta + _outerWidthPct * inctheta / 2.0f; } else { adjAngle = _outerWidthPct * inctheta; angleBuffera = _outerWidthPct * inctheta / 2.0f; // Small points angleBufferc = inctheta / 2.0f + inctheta * _outerWidthPct; } b = new TVector3 (_innerRadius * Mathf.Cos (theta) +_origin.Value.x, _innerRadius * Mathf.Sin (theta) +_origin.Value.y,_origin.Value.z, VERT_OuterRingBorderTop); c = new TVector3 (_innerRadius * Mathf.Cos (theta + adjAngle) +_origin.Value.x, _innerRadius * Mathf.Sin (theta + adjAngle) +_origin.Value.y,_origin.Value.z, VERT_OuterRingBorderTop); a =_origin.Copy(); if (_ringRadius != 0) { if (_outerWidthPct != 0) { a = new TVector3(_ringRadius * Mathf.Cos(theta + angleBuffera) + a.Value.x, _ringRadius * Mathf.Sin(theta + angleBuffera) + a.Value.y, a.Value.z, VERT_InnerRingBorderTop); } else { a = new TVector3(_ringRadius * Mathf.Cos(theta + angleBuffera) + a.Value.x, _ringRadius * Mathf.Sin(theta + angleBuffera) + a.Value.y, a.Value.z, VERT_InnerRingBorderTop); } } t.a = a; t.b = b; t.c = c; t.SortOrder = _triOrder; _triOrder += 2; if (i % 2 == 0) { t.Tag = TRI_GearPlaneTopA1; }else{ t.Tag = TRI_GearPlaneTopA2; } tris.Add(t); t = new Triangle3(); if (_ringRadius != 0) { if (_outerWidthPct != 0) { Triangle3 tFill = new Triangle3(); tFill.a = a.Copy(); tFill.b = c.Copy(); tFill.c = new TVector3(_ringRadius * Mathf.Cos(theta + angleBufferc) + _origin.Value.x, _ringRadius * Mathf.Sin(theta + angleBufferc) + _origin.Value.y, _origin.Value.z, VERT_InnerRingBorderTop); tFill.Tag = TRI_GearPlaneTopB; tFill.SortOrder = _triOrder; _triOrder += 2; tris.Add(tFill); }else{ Triangle3 tFill = new Triangle3(); tFill.a = a.Copy(); tFill.b = c.Copy(); tFill.c = new TVector3(_ringRadius * Mathf.Cos(theta + angleBufferc) + _origin.Value.x, _ringRadius * Mathf.Sin(theta + angleBufferc) + _origin.Value.y, _origin.Value.z, VERT_InnerRingBorderTop); tFill.Tag = TRI_GearPlaneTopC; tFill.SortOrder = _triOrder; _triOrder += 2; tris.Add(tFill); } } if (_outerWidthPct == 0 && i % 2 != 0) { continue; //If no 'squared' teeth, then bail quickly. } if (i % 2 == 0) { Triangle3 t1 = new Triangle3(); Triangle3 t2 = new Triangle3(); ta = b.Copy(); //First corner of tooth. tb = new TVector3 (_outerRadius * Mathf.Cos (theta + phi + ToothRotAngle) +_origin.Value.x,_outerRadius * Mathf.Sin (theta + phi + ToothRotAngle) +_origin.Value.y,_origin.Value.z, VERT_ToothBorderTop); tc = c.Copy(); t1.a = ta; t1.b = tb; t1.c = tc; t1.Tag = TRI_GearPlaneTopD; t1.SortOrder = _triOrder; _triOrder += 2; tris.Add (t1); tb = new TVector3 (_outerRadius * Mathf.Cos (theta + inctheta - phi + ToothRotAngle) +_origin.Value.x,_outerRadius * Mathf.Sin (theta + inctheta - phi + ToothRotAngle) +_origin.Value.y,_origin.Value.z, VERT_ToothBorderTop); //Second Corner of Outer Tooth. ta = new TVector3 (_outerRadius * Mathf.Cos (theta + phi + ToothRotAngle) +_origin.Value.x,_outerRadius * Mathf.Sin (theta + phi + ToothRotAngle) +_origin.Value.y,_origin.Value.z, VERT_ToothBorderTop); //First corner of outer tooth. tc = c.Copy(); t2.a = ta; t2.b = tb; t2.c = tc; t2.Tag = TRI_GearPlaneTopE; t2.SortOrder = _triOrder; _triOrder += 2; tris.Add (t2); } theta += adjAngle; //If next to last tooth then set theta = 0 (for full circle...); if (i == (_qtyTeeth * 2 - 1)) { theta = 0; } } var opptris = BuildOppositePlane(tris.ToArray(), new string[] { TRI_GearPlaneTopA1 }, TRI_GearPlaneBottomA1, _topScale, _topRotation); tris.AddRange(opptris); opptris = BuildOppositePlane(tris.ToArray(), new string[] { TRI_GearPlaneTopA2 }, TRI_GearPlaneBottomA2, _topScale, _topRotation); tris.AddRange(opptris); opptris = BuildOppositePlane(tris.ToArray(), new string[] { TRI_GearPlaneTopE }, TRI_GearPlaneBottomE, _topScale, _topRotation); tris.AddRange(opptris); opptris = BuildOppositePlane(tris.ToArray(), new string[] { TRI_GearPlaneTopD }, TRI_GearPlaneBottomD, _topScale, _topRotation); tris.AddRange(opptris); opptris = BuildOppositePlane(tris.ToArray(), new string[] { TRI_GearPlaneTopB }, TRI_GearPlaneBottomB, _topScale, _topRotation); tris.AddRange(opptris); opptris = BuildOppositePlane(tris.ToArray(), new string[] { TRI_GearPlaneTopC }, TRI_GearPlaneBottomC, _topScale, _topRotation); tris.AddRange(opptris); tris.AddRange(GetSpokes()); //Stitch Teeth System.Collections.Generic.List<Triangle3> stitching = new List<Triangle3>(); System.Collections.Generic.SortedList<int, Triangle3> sortedTris = new SortedList<int, Triangle3>(); foreach (Triangle3 item in tris) { if(sortedTris.ContainsKey(item.SortOrder)){ Debug.Log("Item exists: " + item.SortOrder.ToString() + " " + item.Tag); } sortedTris.Add(item.SortOrder, item); } foreach (Triangle3 item in sortedTris.Values) { stitching.AddRange(StitchEdge(item, TRI_GearPlaneTopA2, TRI_GearPlaneBottomA2, "b", "c", "a", "b", TRI_SideOuterTop, TRI_SideOuterBottom)); stitching.AddRange(StitchEdge(item, TRI_GearPlaneTopD, TRI_GearPlaneBottomD, "a", "b", "b", "c", TRI_SideOuterTop, TRI_SideOuterBottom)); stitching.AddRange(StitchEdge(item, TRI_GearPlaneTopE, TRI_GearPlaneBottomE, "a", "b", "b", "c", TRI_SideOuterTop, TRI_SideOuterBottom)); stitching.AddRange(StitchEdge(item, TRI_GearPlaneTopE, TRI_GearPlaneBottomE, "b", "c", "a", "b", TRI_SideOuterTop, TRI_SideOuterBottom)); //Stitch Inner Ring. stitching.AddRange(StitchEdge(item, TRI_GearPlaneTopB, TRI_GearPlaneBottomB, "c", "a", "c", "a", TRI_SideInnerTop, TRI_SideInnerBottom)); stitching.AddRange(StitchEdge(item, TRI_GearPlaneTopC, TRI_GearPlaneBottomC, "c", "a", "c", "a", TRI_SideInnerTop, TRI_SideInnerBottom)); //Stitch Straight Spokes stitching.AddRange(StitchEdge(item, TRI_SpokeTop1, TRI_SpokeBottom1, "a", "b", "b", "c", TRI_SpokeSideTop, TRI_SpokeSideBottom)); stitching.AddRange(StitchEdge(item, TRI_SpokeTop2, TRI_SpokeBottom2, "b", "c", "a", "b", TRI_SpokeSideTop, TRI_SpokeSideBottom)); //Stitch Hub stitching.AddRange(StitchEdge(item, TRI_HubTop, TRI_HubBottom, "b", "c", "a", "b", TRI_HubSideTop, TRI_HubSideBottom)); } tris.AddRange(stitching.ToArray()); ret.UV = BuildUVs(tris); ret.tris = tris.ToArray(); return ret; }
/// <summary> /// Rasterizes several triangles at once. /// </summary> /// <param name="tris">An array of triangles.</param> public void RasterizeTriangles(Triangle3[] tris) { RasterizeTriangles(tris, 0, tris.Length, Area.Default); }
/// <summary> /// Rasterizes several triangles at once. /// </summary> /// <param name="tris">An array of triangles.</param> /// <param name="triOffset">An offset into the array.</param> /// <param name="triCount">The number of triangles to rasterize, starting from the offset.</param> /// <param name="area">The area flags for all of the triangles.</param> public void RasterizeTriangles(Triangle3[] tris, int triOffset, int triCount, Area area) { int triEnd = triOffset + triCount; if (tris == null) throw new ArgumentNullException("verts"); if (triOffset < 0) throw new ArgumentOutOfRangeException("triOffset", "triOffset must be greater than or equal to 0."); if (triCount < 0) throw new ArgumentOutOfRangeException("triCount", "triCount must be greater than or equal to 0."); if (triEnd > tris.Length) throw new ArgumentOutOfRangeException("triCount", "The specified offset and count end outside the bounds of the provided array."); int numBatches = 8; int threads = (triCount / numBatches) + 1; /*spanQueue = new ConcurrentQueue<Tuple<int, int, Span>>(); bool allProcessed; var task = Task.Factory.StartNew(() => { while (true) { if (spanQueue.IsEmpty) Thread.Sleep(1); Tuple<int, int, Span> spanEntry; while (spanQueue.TryDequeue(out spanEntry)) cells[spanEntry.Item2 * width + spanEntry.Item1].AddSpan(spanEntry.Item3); } });*/ Parallel.For(0, threads, i => { int start = triOffset + i * numBatches; int end = triOffset + (i + 1) * numBatches; if (end > triEnd) end = triEnd; for (int j = start; j < end; j++) { Triangle3 t = tris[j]; RasterizeTriangle(ref t.A, ref t.B, ref t.C, area); } }); }
public Triangle3[] GetHubPlane(TVector3 Origin, float zOffset, string Tag){ System.Collections.Generic.List<Triangle3> tris = new List<Triangle3> (); float inctheta = 2 * Mathf.PI / ((float) _hubSides); float theta = 0.0f; float adjAngle = 0.0f; float r = Mathf.Sqrt((_spokeWidthInner) * (_spokeWidthInner) + (_hubRadius * _hubRadius)); //Get dist to corner of spoke. for (int i = 0; i < (_hubSides); i++) { Triangle3 tri = new Triangle3(); adjAngle = inctheta; tri.a = new TVector3(Origin.Value.x, Origin.Value.y, Origin.Value.z + zOffset, VERT_origin); tri.b = new TVector3(r * Mathf.Cos(theta) + Origin.Value.x, r * Mathf.Sin(theta) + Origin.Value.y, Origin.Value.z + zOffset, VERT_HubPerimeterTop); tri.c = new TVector3(r * Mathf.Cos(theta + adjAngle) + Origin.Value.x, r * Mathf.Sin(theta + adjAngle) + Origin.Value.y, Origin.Value.z + zOffset, VERT_HubPerimeterTop); tri.SortOrder = _triOrder; _triOrder += 2; tri.Tag = Tag; tris.Add(tri); theta += (adjAngle); } return tris.ToArray(); }
/// <summary> /// Iterates over an array of <see cref="Triangle3"/> with a specified offset and length. /// </summary> /// <param name="triangles">An array of triangles.</param> /// <param name="triOffset">The index of the first triangle to be enumerated.</param> /// <param name="triCount">The number of triangles to enumerate.</param> /// <returns>An enumerable collection of triangles.</returns> public static IEnumerable<Triangle3> FromTriangle(Triangle3[] triangles, int triOffset, int triCount) { for (int i = 0; i < triCount; i++) yield return triangles[triOffset + i]; }
private void MirrorVertTags(Triangle3[] tris){ foreach (Triangle3 item in tris) { item.a.Tag = _VertMap[item.a.Tag]; item.b.Tag = _VertMap[item.b.Tag]; item.c.Tag = _VertMap[item.c.Tag]; } }
Triangle3[] GetSolidSpokes (string TagTop, string TagBottom) { TVector3 origin1 = new TVector3(0,0, ((-_spokeIndent/2)), GearRenderer.VERT_origin); TVector3 origin2 = new TVector3(0,0, ((-_height + _spokeIndent/2)), GearRenderer.VERT_origin); System.Collections.Generic.List<Triangle3> tris = new System.Collections.Generic.List<Triangle3>(); Triangle3 newtri; Triangle3[] p1tris = GetSolidSpokePlane(origin1, TagTop, 1.0f); Triangle3[] p2tris = GetSolidSpokePlane(origin2, TagBottom,1.0f); MirrorVertTags(p2tris); foreach(var tri in p1tris){ var t1 = tri.Copy(); newtri = new Triangle3(); newtri.a = t1.a; newtri.b = t1.b; newtri.c = t1.c; newtri.Tag = TagTop; newtri.SortOrder = _triOrder; _triOrder += 2; tris.Add(newtri); } foreach(var tri in p2tris){ var t2 = tri.Copy(); newtri = new Triangle3(); newtri.a = t2.c; newtri.b = t2.b; newtri.c = t2.a; newtri.Tag = TagBottom; newtri.SortOrder = tri.SortOrder + 1; tris.Add(newtri); } return tris.ToArray(); }
/// <summary> /// Rasterizes several triangles at once with per-triangle area flags. /// </summary> /// <param name="tris">An array of triangles.</param> /// <param name="triOffset">An offset into the array.</param> /// <param name="triCount">The number of triangles to rasterize, starting from the offset.</param> /// <param name="areas">An array of area flags, one for each triangle.</param> public void RasterizeTrianglesWithAreas(Triangle3[] tris, int triOffset, int triCount, Area[] areas) { int triEnd = triOffset + triCount; if (tris == null) throw new ArgumentNullException("verts"); if (triOffset < 0) throw new ArgumentOutOfRangeException("triOffset", "triOffset must be greater than or equal to 0."); if (triCount < 0) throw new ArgumentOutOfRangeException("triCount", "triCount must be greater than or equal to 0."); if (triEnd > tris.Length) throw new ArgumentOutOfRangeException("triCount", "The specified offset and count end outside the bounds of the provided array."); if (areas.Length < triCount) throw new ArgumentException("There must be at least as many AreaFlags as there are triangles.", "areas"); for (int i = triOffset, j = 0; i < triEnd; i++, j++) RasterizeTriangle(ref tris[i].A, ref tris[i].B, ref tris[i].C, areas[j]); }
private Triangle3[] StitchEdge(Triangle3 item, string TopTriTag, string BottomTriTag, string StitchTopVertName1, string StitchTopVertName2, string StitchBottomVertName1, string StitchBottomVertName2, string TopTag, string BottomTag) { System.Collections.Generic.List<Triangle3> ret = new List<Triangle3>(); //Get first tri from top, get first tri from bottom... int i = 0; Triangle3 topTri; Triangle3 bottomTri; i += 1; if (item.Complement != null && item.Complement.Tag == TopTriTag) { bottomTri = item; topTri = item.Complement; Quad3D q3 = new Quad3D(); TVector3 t1 = TVector3.Tzero.Copy(); TVector3 t2 = TVector3.Tzero.Copy(); TVector3 b1 = TVector3.Tzero.Copy(); TVector3 b2 = TVector3.Tzero.Copy(); switch (StitchTopVertName1.ToLower()) { case "a": t1 = topTri.a.Copy(); break; case "b": t1 = topTri.b.Copy(); break; case "c": t1 = topTri.c.Copy(); break; default: break; } switch (StitchTopVertName2.ToLower()) { case "a": t2 = topTri.a.Copy(); break; case "b": t2 = topTri.b.Copy(); break; case "c": t2 = topTri.c.Copy(); break; default: break; } switch (StitchBottomVertName1.ToLower()) { case "a": b1 = bottomTri.a.Copy(); break; case "b": b1 = bottomTri.b.Copy(); break; case "c": b1 = bottomTri.c.Copy(); break; default: break; } switch (StitchBottomVertName2.ToLower()) { case "a": b2 = bottomTri.a.Copy(); break; case "b": b2 = bottomTri.b.Copy(); break; case "c": b2 = bottomTri.c.Copy(); break; default: break; } q3.a = t1; q3.b = b2; q3.c = b1; q3.d = t2; q3.Tag = TopTag; var newtris = q3.GetTris(); newtris[0].SortOrder = _triOrder; _triOrder += 2; newtris[1].SortOrder = _triOrder; _triOrder += 2; newtris[1].Tag = BottomTag; ret.AddRange(newtris); } return ret.ToArray(); }
/// <summary> /// Rasterizes a triangle using conservative voxelization. /// </summary> /// <param name="tri">The triangle as a <see cref="Triangle3"/> struct.</param> /// <param name="area">The area flags for the triangle.</param> public void RasterizeTriangle(ref Triangle3 tri, Area area) { RasterizeTriangle(ref tri.A, ref tri.B, ref tri.C, area); }
/// <summary> /// Rasterizes a triangle using conservative voxelization. /// </summary> /// <param name="tri">The triangle as a <see cref="Triangle3"/> struct.</param> public void RasterizeTriangle(ref Triangle3 tri) { RasterizeTriangle(ref tri.A, ref tri.B, ref tri.C, Area.Default); }
public Triangle3[] GetSolidSpokePlane (TVector3 origin, string Tag, float scale) { System.Collections.Generic.List<Triangle3> tris = new List<Triangle3> (); //Calc the angle to sweep... float inctheta = 2 * Mathf.PI / ((float)_qtyTeeth * 2.0f); float theta = 0.0f; _origin.Tag = VERT_origin; float width = _ringRadius * 1.05f; for (int i = 0; i < (_qtyTeeth * 2); i++) { TVector3 a; TVector3 b; TVector3 c; float adjAngle = 0.0f; Triangle3 t = new Triangle3(); adjAngle = inctheta; a =origin.Copy(); b = new TVector3(width * Mathf.Cos(theta) + origin.Value.x, width * Mathf.Sin(theta) + origin.Value.y, a.Value.z, VERT_SpokePerimeterTop); b = new TVector3(b.Value.x * scale, b.Value.y * scale, b.Value.z, b.Tag); c = new TVector3(width * Mathf.Cos(theta + adjAngle) + origin.Value.x, width * Mathf.Sin(theta + adjAngle) + origin.Value.y, a.Value.z, VERT_SpokePerimeterTop); c = new TVector3(c.Value.x * scale, c.Value.y * scale, c.Value.z, c.Tag); t.a = a; t.b = b; t.c = c; t.Tag = Tag; t.SortOrder = _triOrder; _triOrder += 2; tris.Add (t); theta += adjAngle; //If next to last tooth then set theta = 0 (for full circle...); if (i == (_qtyTeeth * 2 - 1)) { theta = 0; } } return tris.ToArray (); }
/// <summary> /// Rasterizes several triangles at once. /// </summary> /// <param name="tris">An array of triangles.</param> /// <param name="triOffset">An offset into the array.</param> /// <param name="triCount">The number of triangles to rasterize, starting from the offset.</param> public void RasterizeTriangles(Triangle3[] tris, int triOffset, int triCount) { RasterizeTriangles(tris, triOffset, triCount, Area.Default); }
/// <summary> /// Create instance from specified triangles in array of tris from tris[triOffset] to tris[triOffset+triCount] with specified area. /// </summary> /// <param name="tris">An array of triangles.</param> /// <param name="triOffset">Tri offset.</param> /// <param name="triCount">Tri count.</param> /// <param name="area">Area of Triangle.</param> /// <returns>A new AreaIdGenerator.</returns> public static AreaGenerator From(Triangle3[] tris, int triOffset, int triCount, Area area) { return new AreaGenerator(TriangleEnumerable.FromTriangle(tris, triOffset, triCount), triCount, area); }
/// <summary> /// Rasterizes several triangles at once. /// </summary> /// <param name="tris">An array of triangles.</param> /// <param name="area">The area flags for all of the triangles.</param> public void RasterizeTriangles(Triangle3[] tris, Area area) { RasterizeTriangles(tris, 0, tris.Length, area); }
/// <summary> /// Create instance from every specified triangles in array of tris with specified area. /// </summary> /// <param name="tris">An array of triangles.</param> /// <param name="area">Area of Triangle.</param> /// <returns>A new AreaIdGenerator.</returns> public static AreaGenerator From(Triangle3[] tris, Area area) { return new AreaGenerator(TriangleEnumerable.FromTriangle(tris, 0, tris.Length), tris.Length, area); }
Triangle3[] GetStraightSpokes (string TagTop1,string TagTop2, string TagBottom1, string TagBottom2) { TVector3 origin1 = new TVector3(0,0, ((-_spokeIndent/2)), GearRenderer.VERT_origin); TVector3 origin2 = new TVector3(0, 0, ((-_height + _spokeIndent / 2)), GearRenderer.VERT_origin); System.Collections.Generic.List<Triangle3> tris = new System.Collections.Generic.List<Triangle3>(); Triangle3[] p1tris = GetStraightSpokePlane(origin1.Copy(), (+_spokeIndent / 2), TagTop1, TagTop2); Triangle3[] p2tris = GetStraightSpokePlane(origin2.Copy(), (-_spokeIndent / 2), TagBottom1, TagBottom2); MirrorVertTags(p2tris); Triangle3 trinew; for (int i = 0; i < p1tris.Length; i++) //Works since both arrays are same len. { var tri1 = p1tris[i].Copy(); var tri2 = p2tris[i].Copy(); trinew = new Triangle3(); trinew.a = tri1.a; trinew.b = tri1.b; trinew.c = tri1.c; trinew.Tag = tri1.Tag; trinew.SortOrder = _triOrder; _triOrder += 2; tris.Add(trinew); trinew = new Triangle3(); trinew.a = tri2.c; trinew.b = tri2.b; trinew.c = tri2.a; trinew.Tag = tri2.Tag; trinew.SortOrder = _triOrder + 1; trinew.Complement = tri1; tris.Add(trinew); } if(_hubRadius != 0){ Triangle3[] p3tris = GetHubPlane(origin1.Copy(), (+_hubHeight / 2.0f), TRI_HubTop); Triangle3[] p4tris = GetHubPlane(origin2.Copy(), (-_hubHeight / 2.0f), TRI_HubBottom); MirrorVertTags(p4tris); for (int i = 0; i < p3tris.Length; i++) //Works since both arrays are same len. { var tri1 = p3tris[i].Copy(); var tri2 = p4tris[i].Copy(); trinew = new Triangle3(); trinew.a = tri1.a; trinew.b = tri1.b; trinew.c = tri1.c; trinew.Tag = tri1.Tag; trinew.SortOrder = _triOrder; _triOrder += 2; tris.Add(trinew); trinew = new Triangle3(); trinew.a = tri2.c; trinew.b = tri2.b; trinew.c = tri2.a; trinew.Tag = tri2.Tag; trinew.Complement = tri1; trinew.SortOrder = _triOrder + 1; tris.Add(trinew); } } return tris.ToArray(); }
private Triangle3[] BuildOppositePlane (Triangle3[] tris, string[] TriTags, string Tag, float scaleFactor, float rotation) { float scale = 0.0f; float rot = rotation; System.Collections.Generic.List<Triangle3> ret = new List<Triangle3> (); var ScaleIgnoreList = new string[]{VERT_origin, VERT_InnerRingBorderTop, VERT_HubPerimeterTop, VERT_HubPerimeterBottom}; //Build other plane for extrusion... (Unwinding back to forwards) for (int j = tris.Length-1; j >= 0; j--) { var tri = tris[j].Copy(); var triOrig = tri.Copy(); if(TriTags.Contains(tri.Tag)){ var a = tri.a.Copy().Value; var b = tri.b.Copy().Value; var c = tri.c.Copy().Value; string aTag = tri.a.Tag; string bTag = tri.b.Tag; string cTag = tri.c.Tag; ///////////////////////////////////////////// if (! TagContains(triOrig.c.Tag, ScaleIgnoreList)){ scale = scaleFactor; }else{ scale = 1.0f; } tri.a = new TVector3(c.x*scale, c.y*scale, c.z - _height, cTag); tri.a = RotatePoint(rot, tri.a); ///////////////////////////////////////////// if (! TagContains(triOrig.b.Tag, ScaleIgnoreList)){ scale = scaleFactor;; }else{ scale = 1.0f; } tri.b = new TVector3(b.x * scale, b.y * scale, b.z - _height, bTag); tri.b = RotatePoint(rot, tri.b); ///////////////////////////////////////////// if (! TagContains(triOrig.a.Tag, ScaleIgnoreList)){ scale = scaleFactor; }else{ scale = 1.0f; } tri.c = new TVector3(a.x * scale, a.y * scale, a.z - _height, aTag); tri.c = RotatePoint(rot, tri.c); ///////////////////////////////////////////// tri.Tag = Tag; tri.SortOrder = triOrig.SortOrder + 1; tri.Complement = triOrig; ret.Add(tri); } } MirrorVertTags(ret); return ret.ToArray(); }
private Triangle3[] StitchEdges(Triangle3[] tris, string TopTriTag, string BottomTriTag, string StitchTopVertName1, string StitchTopVertName2, string StitchBottomVertName1, string StitchBottomVertName2, string TopTag, string BottomTag) { System.Collections.Generic.List<Triangle3> ret = new List<Triangle3>(); foreach (var item in tris) { ret.AddRange(StitchEdge(item, TopTriTag, BottomTriTag, StitchTopVertName1, StitchTopVertName2, StitchBottomVertName1, StitchBottomVertName2,TopTag, BottomTag)); } return ret.ToArray(); }
/// <summary> /// Rasterizes several triangles at once with per-triangle area flags. /// </summary> /// <param name="tris">An array of triangles.</param> /// <param name="areas">An array of area flags, one for each triangle.</param> public void RasterizeTrianglesWithAreas(Triangle3[] tris, Area[] areas) { RasterizeTrianglesWithAreas(tris, 0, tris.Length, areas); }