public static Cone Create(float topRadius, float bottomRadius, float height, int slicesCount, Vector3Class positionOffset) { var coneTriangles = new Cone(); coneTriangles.Normal = new Vector3Class(0, 0, 1); var topPoints = VectorHelper.CreateCircle(height, topRadius, slicesCount, false); var bottomPoints = VectorHelper.CreateCircle(0, bottomRadius, slicesCount, false); for (var middleRadiusPointIndex = 0; middleRadiusPointIndex < bottomPoints.Count; middleRadiusPointIndex++) { //create left triagle var leftTriangle = new Triangle(); leftTriangle.Vectors[0].Position = topPoints[middleRadiusPointIndex] + positionOffset; leftTriangle.Vectors[1].Position = bottomPoints[middleRadiusPointIndex] + positionOffset; if (middleRadiusPointIndex == bottomPoints.Count - 1) { leftTriangle.Vectors[2].Position = bottomPoints[0] + positionOffset; } else { leftTriangle.Vectors[2].Position = bottomPoints[middleRadiusPointIndex + 1] + positionOffset; } leftTriangle.CalcNormal(); coneTriangles[0].Add(leftTriangle); //right triangle var rightTriangle = new Triangle(); rightTriangle.Vectors[0].Position = topPoints[middleRadiusPointIndex] + positionOffset; if (middleRadiusPointIndex == bottomPoints.Count - 1) { rightTriangle.Vectors[1].Position = bottomPoints[0] + positionOffset; rightTriangle.Vectors[2].Position = topPoints[0] + positionOffset; } else { rightTriangle.Vectors[1].Position = bottomPoints[middleRadiusPointIndex + 1] + positionOffset; rightTriangle.Vectors[2].Position = topPoints[middleRadiusPointIndex + 1] + positionOffset; } rightTriangle.CalcNormal(); coneTriangles[0].Add(rightTriangle); } return(coneTriangles); }
internal SupportConeV2(float topHeight, float topRadius, float middleRadius, float bottomHeight, float bottomRadius, int slicesCount, TriangleIntersection modelIntersection, Color color, STLModel3D stlModel = null, bool groundSupport = true, bool useSupportPenetration = false, STLModel3D surfaceTriangles = null, TypeSupportCone supportConeType = TypeSupportCone.Normal, float bottomWidthCorrection = 0f, float aSegmentRadius = float.MinValue, float aSegmentHeight = float.MinValue, float bSegmentRadius = float.MinValue, float bSegmentHeight = float.MinValue, float cSegmentRadius = float.MinValue, float dSegmentRadius = float.MinValue, float dSegmentHeight = float.MinValue, bool calcSliceContours = true) { this._color = color; this.SupportConeVersion = TypeSupportConeVersion.Version2; this.ModelIntersection = modelIntersection; this.ASegmentHeight = aSegmentHeight; this.ASegmentRadius = aSegmentRadius; this.BSegmentHeight = bSegmentHeight; this.BSegmentRadius = bSegmentRadius; this.CSegmentRadius = cSegmentRadius; this.DSegmentHeight = dSegmentHeight; this.DSegmentRadius = dSegmentRadius; //supportcone properties this.TopRadius = topRadius; this.TopHeight = topHeight; this.MiddleRadius = middleRadius; this.BottomHeight = bottomHeight; this.BottomRadius = bottomRadius; this.MiddleRadius = bSegmentRadius; middleRadius = bSegmentRadius; //determine rotation angle float angleY; float angleZ; VectorHelper.CalcRotationAnglesYZFromVector(modelIntersection.Normal, false, out angleZ, out angleY); var aSegmentRotationY = 0f; this._rotationAngleY = angleY; this._rotationAngleZ = angleZ; if (angleZ < 0) { this._rotationAngleZ = 360 + angleZ; } if (this.RotationAngleY > 180 && this.RotationAngleY < 270f) { this._rotationAngleY = 225 - (((270f - this.RotationAngleY) / 90f) * 45f); aSegmentRotationY = 270 - (270f - angleY); } else if (this.RotationAngleY > 90 && this.RotationAngleY < 180) { this._rotationAngleY = 180 - (((180 - this.RotationAngleY) / 90f) * 45f); aSegmentRotationY = 180 - (180 - angleY); } //create segments this.ASegment = new Sphere(aSegmentRadius, new Vector3(), Sphere.eSubdivisions.Two, new Sphere.eDir[] { Sphere.eDir.All }, modelIntersection.IntersectionPoint, new Structs.Byte4Class(this.Color.A, color.R, color.G, color.B) ); this.RefPointCSegment = new Vector3Class(0, 0, aSegmentHeight + bSegmentHeight + cSegmentRadius); var refPointRotationVector = this.Rotate(this.RotationAngleY, this.RotationAngleZ, this.RefPointCSegment); this.RefPointCSegment = refPointRotationVector + modelIntersection.IntersectionPoint; var refPointCSegmentXY = new Vector3Class(this.RefPointCSegment.X, this.RefPointCSegment.Y, 0); refPointRotationVector.Normalize(); var middleHeight = this.RefPointCSegment.Z - cSegmentRadius - dSegmentHeight - topHeight - bottomHeight; //add bottom caps to b-seqment this.BSegment = Cone.Create(bSegmentRadius, aSegmentRadius - 0.1f, (aSegmentRadius / 2) + bSegmentHeight + cSegmentRadius, slicesCount, new Vector3Class()); //rotate B segment using normal this.BSegment.Rotate(this.RotationAngleY, this.RotationAngleZ); this.BSegment.Translate(modelIntersection.IntersectionPoint); this.BSegmentCap = new ConeCap(this.RefPointCSegment, this.BSegment.BottomPoints, false); //merge a and b-segments //var aSegmentBottomPoints = this.ASegment.BottomPoints; var bSegmentTopPoints = this.BSegment.TopPoints; //middle circle this.CSegment = (new Sphere(cSegmentRadius * 1.1f, new Vector3(), Sphere.eSubdivisions.Two, new Sphere.eDir[] { Sphere.eDir.All }, this.RefPointCSegment, new Structs.Byte4Class(this.Color.A, color.R, color.G, color.B))); if (middleHeight >= 0f) { this.DSegment = Cone.Create(dSegmentRadius, topRadius, dSegmentHeight + cSegmentRadius, slicesCount, this.RefPointCSegment - new Vector3Class(0, 0, (dSegmentHeight + cSegmentRadius))); this.TopSupportCone = Cone.Create(topRadius, middleRadius, topHeight, slicesCount, this.RefPointCSegment - new Vector3Class(0, 0, dSegmentHeight + cSegmentRadius + topHeight)); this.MiddleSupportCone = Cone.Create(middleRadius, middleRadius + (middleHeight * bottomWidthCorrection / 100f), middleHeight, slicesCount, refPointCSegmentXY + new Vector3Class(0, 0, bottomHeight)); } else { this.DSegment = new Cone(); this.TopSupportCone = new Cone(); this.MiddleSupportCone = Cone.Create(middleRadius, middleRadius, (this.RefPointCSegment.Z - this.BottomHeight), slicesCount, refPointCSegmentXY + new Vector3Class(0, 0, this.BottomHeight)); } this.BottomSupportCone = Cone.Create(middleRadius + (middleHeight * (bottomWidthCorrection / 100f)), bottomRadius + (middleHeight * (bottomWidthCorrection / 100f)), bottomHeight, slicesCount, refPointCSegmentXY); var capPoints = VectorHelper.CreateCircle(0, bottomRadius + (middleHeight * bottomWidthCorrection / 100f), slicesCount, false); var supportConeCap = base.CreateCap(capPoints, new Vector3Class(), new Vector3Class(), false); foreach (var supportConeCapPoint in supportConeCap[0]) { supportConeCapPoint.Vectors[0].Position += refPointCSegmentXY; supportConeCapPoint.Vectors[1].Position += refPointCSegmentXY; supportConeCapPoint.Vectors[2].Position += refPointCSegmentXY; } this.BottomSupportCone[0].AddRange(supportConeCap[0]); this.Triangles = new TriangleInfoList(); this.Triangles[0].AddRange(this.TotalTriangles); foreach (var triangle in this.Triangles[0]) { triangle.CalcMinMaxX(); triangle.CalcMinMaxY(); triangle.CalcMinMaxZ(); triangle.CalcCenter(); triangle.UpdateColor(this.ColorAsByte4, true); } this.UpdateBoundries(); if (this.VBOIndexes == null || this.VBOIndexes.Length == 0) { this.BindModel(); this.UpdateBinding(); } }