public IntermediateMeshGenerator Append(IntermediateMeshGenerator intermediate)
        {
            var count = Vertices.Count;

            Vertices.AddRange(intermediate.Vertices.Select(v => v.Copy()));
            Normals.AddRange(intermediate.Normals.Select(n => n.Copy()));
            Triangles.AddRange(intermediate.Triangles.Select(t => new Index3i(t.a + count, t.b + count, t.c + count)));

            return(this);
        }
Exemple #2
0
        void Complete(IntermediateMeshGenerator intermediate)
        {
            vertices  = new VectorArray3d(intermediate.Vertices.Count);
            normals   = new VectorArray3f(intermediate.Normals.Count);
            triangles = new IndexArray3i(intermediate.Triangles.Count);

            for (int idx = 0; idx < intermediate.Vertices.Count; idx++)
            {
                vertices[idx] = intermediate.Vertices[idx];
            }
            for (int idx = 0; idx < intermediate.Normals.Count; idx++)
            {
                normals[idx] = intermediate.Normals[idx];
            }
            for (int idx = 0; idx < intermediate.Triangles.Count; idx++)
            {
                triangles[idx] = intermediate.Triangles[idx];
            }
        }
Exemple #3
0
        public IntermediateMeshGenerator Generate(int segIdx)
        {
            var angle = Context.Config.SegmentAngle(segIdx);

            var plateSegmentGenerator = Context.Plate2d;

            InnerBendTopCorner     = plateSegmentGenerator.InnerBendCorner.rotate2d(angle).to3d(Context.Config.plateHeight / 2);
            OuterBendUpTopCorner   = plateSegmentGenerator.OuterUpCornerPoint.rotate2d(angle).to3d(Context.Config.plateHeight / 2);
            OuterBendDownTopCorner = plateSegmentGenerator.OuterDownCornerPoint.rotate2d(angle).to3d(Context.Config.plateHeight / 2);

            InnerBendBottomCorner     = plateSegmentGenerator.InnerBendCorner.rotate2d(angle).to3d(-Context.Config.plateHeight / 2);
            OuterBendUpBottomCorner   = plateSegmentGenerator.OuterUpCornerPoint.rotate2d(angle).to3d(-Context.Config.plateHeight / 2);
            OuterBendDownBottomCorner = plateSegmentGenerator.OuterDownCornerPoint.rotate2d(angle).to3d(-Context.Config.plateHeight / 2);

            var topSeg = new IntermediateMeshGenerator();

            topSeg.Append(plateSegmentGenerator.Intermediate);
            topSeg.Offset(new Vector3d(0, 0, Context.Config.plateHeight / 2));
            topSeg.Rotate(angle);
            Intermediate.Append(topSeg);

            var bottomSeg = new IntermediateMeshGenerator();

            bottomSeg.Append(plateSegmentGenerator.Intermediate);
            bottomSeg.Offset(new Vector3d(0, 0, -Context.Config.plateHeight / 2));
            bottomSeg.Rotate(angle);
            bottomSeg.ReverseTriagles();
            Intermediate.Append(bottomSeg);

            // build inner surfaces for bends
            var sets = new[]
            {
                plateSegmentGenerator.InnerBendPoints,
                plateSegmentGenerator.OuterUpBendPoints,
                plateSegmentGenerator.OuterDownBendPoints
            };

            foreach (var set in sets)
            {
                var setMesh = new IntermediateMeshGenerator();
                setMesh.Extrude(set, Context.Config.plateHeight);
                setMesh.Rotate(angle);

                Intermediate.Append(setMesh);
            }

            // outer surface


            var outerSurfaceMesh = new IntermediateMeshGenerator();

            outerSurfaceMesh.Extrude(plateSegmentGenerator.OuterSurfaceNearPoints, Context.Config.plateHeight);
            outerSurfaceMesh.Rotate(angle);

            Intermediate.Append(outerSurfaceMesh);

            var upSurfaceMesh = new IntermediateMeshGenerator();

            upSurfaceMesh.Extrude(new List <Vector2d>()
            {
                plateSegmentGenerator.OuterBendUpTouchPoint, plateSegmentGenerator.InnerBendUpTouchPoint
            }, Context.Config.plateHeight);
            upSurfaceMesh.Rotate(angle);

            Intermediate.Append(upSurfaceMesh);

            var downSurfaceMesh = new IntermediateMeshGenerator();

            downSurfaceMesh.Extrude(new List <Vector2d>()
            {
                plateSegmentGenerator.InnerBendDownTouchPoint, plateSegmentGenerator.OuterBendDownTouchPoint
            }, Context.Config.plateHeight);
            downSurfaceMesh.Rotate(angle);

            Intermediate.Append(downSurfaceMesh);

            return(Intermediate);
        }
        public IntermediateMeshGenerator Generate()
        {
            var plateSegmentGenerator = Context.Plate2d;

            var cornerPoints = Context
                               .SegmentIndexes
                               .Select(idx => plateSegmentGenerator.InnerBendCorner.rotate2d(Context.Config.SegmentAngle(idx)))
                               .ToList();

            if (Context.Config.spindelRadius == 0)
            {
                for (var idx = 0; idx < cornerPoints.Count; idx++)
                {
                    var nextIdx = (idx + 1) % cornerPoints.Count;

                    Intermediate.counterClockwiseSingleSidedFromFront(
                        Vector2d.Zero.to3d(Context.halfPlateHeight),
                        cornerPoints[idx].to3d(Context.halfPlateHeight),
                        cornerPoints[nextIdx].to3d(Context.halfPlateHeight)
                        );

                    Intermediate.counterClockwiseSingleSidedFromFront(
                        Vector2d.Zero.to3d(-Context.halfPlateHeight),
                        cornerPoints[nextIdx].to3d(-Context.halfPlateHeight),
                        cornerPoints[idx].to3d(-Context.halfPlateHeight)
                        );
                }

                return(Intermediate);
            }

            List <Vector2d> spindelPoints = new List <Vector2d>();

            if (Context.Config.spindelCut == 0)
            {
                spindelPoints = Generators.counterClockwiseCirclePoints(
                    Context.Config.spindelPoints,
                    Vector2d.Zero,
                    Context.Config.spindelRadius
                    );

                /*
                 * Intermediate.Extrude(spindelPoints, Context.Config.plateHeight, true);
                 *
                 * var nearestDistanceIndexes = cornerPoints.Select(point =>
                 * {
                 *  var distances = spindelPoints.Select(p => p.Distance(point)).ToList();
                 *  var nearestPointIndex = distances.FindIndex(d => d == distances.Min());
                 *  return nearestPointIndex;
                 * }).ToList();
                 *
                 * for (var idx = 0; idx < cornerPoints.Count; idx++)
                 * {
                 *  var nearestPointIndex = nearestDistanceIndexes[idx];
                 *
                 *  var nextIdx = (idx + 1) % cornerPoints.Count;
                 *  var nextNearestPointIndex = nearestDistanceIndexes[nextIdx];
                 *
                 *  var polygonPoints = new List<Vector2d>();
                 *  polygonPoints.AddRange(
                 *      new []
                 *      {
                 *          cornerPoints[idx],
                 *          cornerPoints[nextIdx]
                 *      });
                 *
                 *  var spindelPart = new List<Vector2d>();
                 *  var pointsToTake = nextNearestPointIndex < nearestPointIndex
                 *      ? nextNearestPointIndex + spindelPoints.Count - nearestPointIndex + 1
                 *      : nextNearestPointIndex - nearestPointIndex + 1;
                 *
                 *  spindelPart = Enumerable.Range(nearestPointIndex, pointsToTake)
                 *      .Select(i => spindelPoints[i % spindelPoints.Count])
                 *      .Reverse()
                 *      .ToList();
                 *
                 *  polygonPoints.AddRange(spindelPart);
                 *
                 *  var polygonizer = new TriangulatedPolygonGenerator()
                 *  {
                 *      Polygon = new GeneralPolygon2d( new Polygon2d(polygonPoints) )
                 *  };
                 *  polygonizer.Generate();
                 *
                 *  var polygonMesh = new IntermediateMeshGenerator();
                 *  polygonMesh.Append(polygonizer);
                 *
                 *  Intermediate.Append(new IntermediateMeshGenerator().Append(polygonMesh).Offset(new Vector3d(0, 0, Context.halfPlateHeight)));
                 *  Intermediate.Append(new IntermediateMeshGenerator().Append(polygonMesh).Offset(new Vector3d(0, 0, -Context.halfPlateHeight)).ReverseTriagles());
                 * }
                 */
            }
            else
            {
                var spindelCutX = Context.Config.spindelRadius - Context.Config.spindelCut;
                var cutItx      = Intersector.CircelLineIntersection(
                    Vector2d.Zero,
                    Context.Config.spindelRadius,
                    new Vector2d(spindelCutX, 0),
                    new Vector2d(spindelCutX, 1)
                    );

                spindelPoints = Generators.counterClockwiseCircleSegments(
                    Context.Config.spindelPoints,
                    Vector2d.Zero,
                    cutItx.Single(p => p.y > 0),
                    cutItx.Single(p => p.y < 0)
                    );

                //Intermediate.Extrude(spindelSegments, Context.Config.plateHeight, true);
            }


            Intermediate.Extrude(spindelPoints, Context.Config.plateHeight, true);

            var nearestDistanceIndexes = cornerPoints.Select(point =>
            {
                var distances         = spindelPoints.Select(p => p.Distance(point)).ToList();
                var nearestPointIndex = distances.FindIndex(d => d == distances.Min());
                return(nearestPointIndex);
            }).ToList();

            for (var idx = 0; idx < cornerPoints.Count; idx++)
            {
                var nearestPointIndex = nearestDistanceIndexes[idx];

                var nextIdx = (idx + 1) % cornerPoints.Count;
                var nextNearestPointIndex = nearestDistanceIndexes[nextIdx];

                var polygonPoints = new List <Vector2d>();
                polygonPoints.AddRange(
                    new[]
                {
                    cornerPoints[idx],
                    cornerPoints[nextIdx]
                });

                var spindelPart  = new List <Vector2d>();
                var pointsToTake = nextNearestPointIndex < nearestPointIndex
                    ? nextNearestPointIndex + spindelPoints.Count - nearestPointIndex + 1
                    : nextNearestPointIndex - nearestPointIndex + 1;

                spindelPart = Enumerable.Range(nearestPointIndex, pointsToTake)
                              .Select(i => spindelPoints[i % spindelPoints.Count])
                              .Reverse()
                              .ToList();

                polygonPoints.AddRange(spindelPart);

                var polygonizer = new TriangulatedPolygonGenerator()
                {
                    Polygon = new GeneralPolygon2d(new Polygon2d(polygonPoints))
                };
                polygonizer.Generate();

                var polygonMesh = new IntermediateMeshGenerator();
                polygonMesh.Append(polygonizer);

                Intermediate.Append(new IntermediateMeshGenerator().Append(polygonMesh).Offset(new Vector3d(0, 0, Context.halfPlateHeight)));
                Intermediate.Append(new IntermediateMeshGenerator().Append(polygonMesh).Offset(new Vector3d(0, 0, -Context.halfPlateHeight)).ReverseTriagles());
            }

            return(Intermediate);
        }