private static void GetMultiRingedTubeSprtBetweenRingsSprtTube_ORIG(ref int pointOffset, MeshGeometry3D geometry, int numSides, Point[] points, TubeRingDefinition_ORIG ring1, TubeRingDefinition_ORIG ring2, double z) { #region Add points and normals #region Determine 3D positions (they are referenced a lot, so just calculating them once Point3D[] sidePoints1 = new Point3D[numSides]; Point3D[] sidePoints2 = new Point3D[numSides]; for (int cntr = 0; cntr < numSides; cntr++) { sidePoints1[cntr] = new Point3D(ring1.RadiusX * points[cntr].X, ring1.RadiusY * points[cntr].Y, z); sidePoints2[cntr] = new Point3D(ring2.RadiusX * points[cntr].X, ring2.RadiusY * points[cntr].Y, z + ring2.DistFromPrevRing); } #endregion #region Determine normals Vector3D v1, v2; // The normal at 0 is for the face between 0 and 1. The normal at 1 is the face between 1 and 2, etc. Vector3D[] sideNormals = new Vector3D[numSides]; for (int cntr = 0; cntr < numSides; cntr++) { // (next1 - cur1) x (cur2 - cur1) if (cntr == numSides - 1) { v1 = sidePoints1[0] - sidePoints1[cntr]; } else { v1 = sidePoints1[cntr + 1] - sidePoints1[cntr]; } v2 = sidePoints2[cntr] - sidePoints1[cntr]; sideNormals[cntr] = Vector3D.CrossProduct(v1, v2); } #endregion #region Commit points/normals for (int ringCntr = 1; ringCntr <= 2; ringCntr++) // I want all the points in ring1 laid down before doing ring2 (this stays similar to the pyramid method's logic) { // Sides - adding the points twice, since 2 triangles will use each point (and each triangle gets its own point) for (int cntr = 0; cntr < numSides; cntr++) { // Even if (ringCntr == 1) { geometry.Positions.Add(sidePoints1[cntr]); } else { geometry.Positions.Add(sidePoints2[cntr]); } // even always selects the previous side's normal if (cntr == 0) { geometry.Normals.Add(sideNormals[numSides - 1]); } else { geometry.Normals.Add(sideNormals[cntr - 1]); } // Odd if (ringCntr == 1) { geometry.Positions.Add(sidePoints1[cntr]); } else { geometry.Positions.Add(sidePoints2[cntr]); } // odd always selects the current side's normal geometry.Normals.Add(sideNormals[cntr]); } } #endregion int ring2Start = numSides * 2; #endregion #region Add the triangles for (int cntr = 0; cntr < numSides; cntr++) //for (int cntr = 0; cntr < 1; cntr++) { //--------------Bottom Right Triangle // Ring 1, bottom left geometry.TriangleIndices.Add(pointOffset + ((cntr * 2) + 1)); // this will be the second of the pair of points at this location // Ring 1, bottom right if (cntr == numSides - 1) { geometry.TriangleIndices.Add(pointOffset); // on the last point, so loop back to point zero } else { geometry.TriangleIndices.Add(pointOffset + ((cntr + 1) * 2)); // this will be the first of the pair of points at the next location } // Ring 2, top right (adding twice, because it starts the next triangle) if (cntr == numSides - 1) { geometry.TriangleIndices.Add(pointOffset + ring2Start); // on the last point, so loop back to point zero geometry.TriangleIndices.Add(pointOffset + ring2Start); } else { geometry.TriangleIndices.Add(pointOffset + ring2Start + ((cntr + 1) * 2)); // this will be the first of the pair of points at the next location geometry.TriangleIndices.Add(pointOffset + ring2Start + ((cntr + 1) * 2)); } //--------------Top Left Triangle // Ring 2, top left geometry.TriangleIndices.Add(pointOffset + ring2Start + ((cntr * 2) + 1)); // this will be the second of the pair of points at this location // Ring 1, bottom left (same as the very first point added in this for loop) geometry.TriangleIndices.Add(pointOffset + ((cntr * 2) + 1)); // this will be the second of the pair of points at this location } #endregion pointOffset += numSides * 4; }
private static void GetMultiRingedTubeSprtBetweenRings_ORIG(ref int pointOffset, MeshGeometry3D geometry, int numSides, Point[] points, TubeRingDefinition_ORIG ring1, TubeRingDefinition_ORIG ring2, double z) { if (ring1.RingType == TubeRingType_ORIG.Point || ring2.RingType == TubeRingType_ORIG.Point) { GetMultiRingedTubeSprtBetweenRingsSprtPyramid_ORIG(ref pointOffset, geometry, numSides, points, ring1, ring2, z); } else { GetMultiRingedTubeSprtBetweenRingsSprtTube_ORIG(ref pointOffset, geometry, numSides, points, ring1, ring2, z); } #region OLD /* if (ring1.IsPoint) { } else if (ring2.IsPoint) { #region Pyramid 2 #region Add points and normals // Determine 3D positions (they are referenced a lot, so just calculating them once Point3D tipPoint = new Point3D(0, 0, z + ring2.DistFromPrevRing); Point3D[] sidePoints = new Point3D[numSides]; for (int cntr = 0; cntr < numSides; cntr++) { sidePoints[cntr] = new Point3D(ring1.SizeX * points[cntr].X, ring1.SizeY * points[cntr].Y, z); } Vector3D v1, v2; // Sides - adding the points twice, since 2 triangles will use each point (and each triangle gets its own point) for (int cntr = 0; cntr < numSides; cntr++) { // Even geometry.Positions.Add(sidePoints[cntr]); #region normal // (tip - cur) x (prev - cur) v1 = tipPoint.ToVector() - sidePoints[cntr].ToVector(); if (cntr == 0) { v2 = sidePoints[sidePoints.Length - 1].ToVector() - sidePoints[0].ToVector(); } else { v2 = sidePoints[cntr - 1].ToVector() - sidePoints[cntr].ToVector(); } geometry.Normals.Add(Vector3D.CrossProduct(v1, v2)); #endregion // Odd geometry.Positions.Add(sidePoints[cntr]); #region normal // (next - cur) x (tip - cur) if (cntr == sidePoints.Length - 1) { v1 = sidePoints[0].ToVector() - sidePoints[cntr].ToVector(); } else { v1 = sidePoints[cntr + 1].ToVector() - sidePoints[cntr].ToVector(); } v2 = tipPoint.ToVector() - sidePoints[cntr].ToVector(); geometry.Normals.Add(Vector3D.CrossProduct(v1, v2)); #endregion } int lastPoint = numSides * 2; // Top point (all triangles use this same one) geometry.Positions.Add(tipPoint); // This one is straight up geometry.Normals.Add(new Vector3D(0, 0, 1)); #endregion #region Add the triangles for (int cntr = 0; cntr < numSides; cntr++) { geometry.TriangleIndices.Add(pointOffset + ((cntr * 2) + 1)); // this will be the second of the pair of points at this location if (cntr == numSides - 1) { geometry.TriangleIndices.Add(pointOffset); // on the last point, so loop back to point zero } else { geometry.TriangleIndices.Add(pointOffset + ((cntr + 1) * 2)); // this will be the first of the pair of points at the next location } geometry.TriangleIndices.Add(pointOffset + lastPoint); // the tip } #endregion #endregion } else { } */ #endregion }
private static void GetMultiRingedTubeSprtBetweenRingsSprtPyramid_ORIG(ref int pointOffset, MeshGeometry3D geometry, int numSides, Point[] points, TubeRingDefinition_ORIG ring1, TubeRingDefinition_ORIG ring2, double z) { #region Add points and normals #region Determine 3D positions (they are referenced a lot, so just calculating them once Point3D tipPoint; Vector3D tipNormal; double sideZ, sizeX, sizeY; if (ring1.RingType == TubeRingType_ORIG.Point) { // Upside down pyramid tipPoint = new Point3D(0, 0, z); tipNormal = new Vector3D(0, 0, -1); sideZ = z + ring2.DistFromPrevRing; sizeX = ring2.RadiusX; sizeY = ring2.RadiusY; } else { // Rightside up pyramid tipPoint = new Point3D(0, 0, z + ring2.DistFromPrevRing); tipNormal = new Vector3D(0, 0, 1); sideZ = z; sizeX = ring1.RadiusX; sizeY = ring1.RadiusY; } Point3D[] sidePoints = new Point3D[numSides]; for (int cntr = 0; cntr < numSides; cntr++) { sidePoints[cntr] = new Point3D(sizeX * points[cntr].X, sizeY * points[cntr].Y, sideZ); } #endregion Vector3D v1, v2; // Sides - adding the points twice, since 2 triangles will use each point (and each triangle gets its own point) for (int cntr = 0; cntr < numSides; cntr++) { // Even geometry.Positions.Add(sidePoints[cntr]); #region normal // (tip - cur) x (prev - cur) v1 = tipPoint.ToVector() - sidePoints[cntr].ToVector(); if (cntr == 0) { v2 = sidePoints[sidePoints.Length - 1].ToVector() - sidePoints[0].ToVector(); } else { v2 = sidePoints[cntr - 1].ToVector() - sidePoints[cntr].ToVector(); } geometry.Normals.Add(Vector3D.CrossProduct(v1, v2)); #endregion // Odd geometry.Positions.Add(sidePoints[cntr]); #region normal // (next - cur) x (tip - cur) if (cntr == sidePoints.Length - 1) { v1 = sidePoints[0].ToVector() - sidePoints[cntr].ToVector(); } else { v1 = sidePoints[cntr + 1].ToVector() - sidePoints[cntr].ToVector(); } v2 = tipPoint.ToVector() - sidePoints[cntr].ToVector(); geometry.Normals.Add(Vector3D.CrossProduct(v1, v2)); #endregion } int lastPoint = numSides * 2; //TODO: This is wrong, each triangle should have its own copy of the point with the normal the same as the 2 base points // Top point (all triangles use this same one) geometry.Positions.Add(tipPoint); // This one is straight up geometry.Normals.Add(tipNormal); #endregion #region Add the triangles for (int cntr = 0; cntr < numSides; cntr++) { geometry.TriangleIndices.Add(pointOffset + ((cntr * 2) + 1)); // this will be the second of the pair of points at this location if (cntr == numSides - 1) { geometry.TriangleIndices.Add(pointOffset); // on the last point, so loop back to point zero } else { geometry.TriangleIndices.Add(pointOffset + ((cntr + 1) * 2)); // this will be the first of the pair of points at the next location } geometry.TriangleIndices.Add(pointOffset + lastPoint); // the tip } #endregion pointOffset += lastPoint + 1; }
private static void GetMultiRingedTubeSprtEndCap_ORIG(ref int pointOffset, MeshGeometry3D geometry, int numSides, Point[] points, TubeRingDefinition_ORIG ring, bool isFirst, double z) { #region Figure out the normal Vector3D normal; if (isFirst) { // The first is in the negative Z, so the normal points down // For some reason, it's backward from what I think it should be normal = new Vector3D(0, 0, 1); } else { normal = new Vector3D(0, 0, 1); } #endregion #region Add points and normals for (int cntr = 0; cntr < numSides; cntr++) { double x = ring.RadiusX * points[cntr].X; double y = ring.RadiusY * points[cntr].Y; geometry.Positions.Add(new Point3D(x, y, z)); geometry.Normals.Add(normal); } #endregion #region Add the triangles // Start with 0,1,2 geometry.TriangleIndices.Add(pointOffset + 0); geometry.TriangleIndices.Add(pointOffset + 1); geometry.TriangleIndices.Add(pointOffset + 2); int lowerIndex = 2; int upperIndex = numSides - 1; int lastUsedIndex = 0; bool shouldBumpLower = true; // Do the rest of the triangles while (lowerIndex < upperIndex) { geometry.TriangleIndices.Add(pointOffset + lowerIndex); geometry.TriangleIndices.Add(pointOffset + upperIndex); geometry.TriangleIndices.Add(pointOffset + lastUsedIndex); if (shouldBumpLower) { lastUsedIndex = lowerIndex; lowerIndex++; } else { lastUsedIndex = upperIndex; upperIndex--; } shouldBumpLower = !shouldBumpLower; } #endregion pointOffset += numSides; }