/// <summary> /// Adds Polygons to the argument PolyMesh that connect two cross sections /// matching this cross section definition; the first cross section vertex index /// is specified by crossSectionStartIdx0 and the second by crossSectionStartIdx1. /// </summary> public void AddConnectingPolygons(PolyMesh polyMesh, int crossSectionStartIdx0, int crossSectionStartIdx1) { var cs0 = crossSectionStartIdx0; var cs1 = crossSectionStartIdx1; for (int i = 0; i < numSegments; i++) { var poly = new Polygon(); poly.verts = Pool<List<int>>.Spawn(); poly.verts.Clear(); int iPlusOne = (i + 1) % numSegments; poly.verts.Add(cs0 + i); poly.verts.Add(cs0 + iPlusOne); poly.verts.Add(cs1 + iPlusOne); poly.verts.Add(cs1 + i); polyMesh.AddPolygon(poly); } }
private void refreshMesh() { if (outputToFilter == null) { return; } if (outputToFilter.sharedMesh == null) { outputToFilter.sharedMesh = new Mesh(); outputToFilter.sharedMesh.name = "PoseRibbonMesh Test"; } var mesh = outputToFilter.sharedMesh; mesh.Clear(); var pose0 = poseSource0.ToLocalPose(); var pose1 = poseSource1.ToLocalPose(); var pose2 = poseSource2.ToLocalPose(); var poses = Pool <List <Pose> > .Spawn(); poses.Clear(); try { poses.Add(pose0); poses.Add(pose1); poses.Add(pose2); if (!usePolyMeshMethod) { #region Non-PolyMesh Method var verts = Pool <List <Vector3> > .Spawn(); verts.Clear(); var indices = Pool <List <int> > .Spawn(); indices.Clear(); try { for (int i = 0; i < poses.Count; i++) { var p = poses[i]; verts.Add(left(p)); verts.Add(right(p)); } int vertsPerPose = 2; bool closeLoop = vertsPerPose != 2; for (int p = 0; p + 1 < poses.Count; p++) { for (int csi = 0; csi < vertsPerPose - (closeLoop ? 0 : 1); csi++) { var csRootIndex = p * vertsPerPose; var nextCSRootIndex = (p + 1) * vertsPerPose; var i0 = csRootIndex + csi; var i1 = nextCSRootIndex + csi; var i2 = nextCSRootIndex + ((csi + 1) % vertsPerPose); var i3 = csRootIndex + ((csi + 1) % vertsPerPose); indices.Add(i0); indices.Add(i1); indices.Add(i2); indices.Add(i0); indices.Add(i2); indices.Add(i3); } } mesh.SetVertices(verts); mesh.SetTriangles(indices, 0, true); mesh.RecalculateNormals(); } finally { verts.Clear(); Pool <List <Vector3> > .Recycle(verts); indices.Clear(); Pool <List <int> > .Recycle(indices); } #endregion } else { polyMesh.Clear(); // quad 0 polyMesh.AddPosition(left(pose0)); polyMesh.AddPosition(right(pose0)); polyMesh.AddPosition(left(pose1)); polyMesh.AddPosition(right(pose1)); var newPoly = Polygon.SpawnQuad(1, 0, 2, 3); polyMesh.AddPolygon(newPoly); // quad 1 polyMesh.AddPosition(left(pose2)); polyMesh.AddPosition(right(pose2)); var nextPoly = Polygon.SpawnQuad(3, 2, 4, 5); polyMesh.AddPolygon(nextPoly); // mark the edge between the two quads as smooth. polyMesh.MarkEdgeSmooth(new Edge(2, 3)); polyMesh.FillUnityMesh(mesh, doubleSided: true); } } finally { poses.Clear(); Pool <List <Pose> > .Recycle(poses); } }