Exemplo n.º 1
0
        protected void Emit(List <PrintVertex> printVertices, int layerIndex, int startPointCount)
        {
            List <ToolpathPreviewVertex> vertices = new List <ToolpathPreviewVertex>();
            List <int> triangles = new List <int>();

            ToolpathPreviewJoint[] joints = new ToolpathPreviewJoint[printVertices.Count];

            joints[joints.Length - 1] = GenerateMiterJoint(printVertices, joints.Length - 1, layerIndex, startPointCount, vertices);

            for (int i = joints.Length - 2; i > 0; i--)
            {
                Vector3d a        = printVertices[i - 1].Position;
                Vector3d b        = printVertices[i].Position;
                Vector3d c        = printVertices[i + 1].Position;
                Vector3d ab       = b - a;
                Vector3d bc       = c - b;
                var      angleRad = SignedAngleRad(ab.xy, bc.xy);
                if (Math.Abs(angleRad) > 0.698132)
                {
                    if (angleRad < 0)
                    {
                        joints[i] = GenerateRightBevelJoint(printVertices, i, layerIndex, startPointCount, vertices, triangles);
                    }
                    else
                    {
                        joints[i] = GenerateLeftBevelJoint(printVertices, i, layerIndex, startPointCount, vertices, triangles);
                    }
                }
                else
                {
                    joints[i] = GenerateMiterJoint(printVertices, i, layerIndex, startPointCount, vertices);
                }
            }

            joints[0] = GenerateMiterJoint(printVertices, 0, layerIndex, startPointCount, vertices);

            AddEdges(joints, triangles);

            var mesh = new Tuple <ToolpathPreviewVertex[], int[]>(vertices.ToArray(), triangles.ToArray());

            EndEmit(mesh, layerIndex);
        }
Exemplo n.º 2
0
        protected ToolpathPreviewJoint GenerateLeftBevelJoint(List <PrintVertex> toolpath, int toolpathIndex,
                                                              int layerIndex, int startPointCount, List <ToolpathPreviewVertex> vertices, List <int> triangles)
        {
            Vector3d a            = toolpath[toolpathIndex - 1].Position;
            Vector3d b            = toolpath[toolpathIndex].Position;
            Vector3d c            = toolpath[toolpathIndex + 1].Position;
            Vector3d ab           = (b - a).Normalized;
            Vector3d bc           = (c - b).Normalized;
            Vector3d miterNormal  = GetNormalAndSecant(ab, bc, out double miterSecant);
            Vector3d miterTangent = ab + bc;

            var pointCount             = startPointCount + toolpathIndex;
            var point                  = toolpath[toolpathIndex].Position;
            var dimensions             = toolpath[toolpathIndex].Dimensions;
            var fillType               = (FillTypeFlags)toolpath[toolpathIndex].Source;
            var feedRate               = toolpath[toolpathIndex].FeedRate;
            ToolpathPreviewJoint joint = new ToolpathPreviewJoint();

            joint.in0 = joint.out0 = AddVertex(vertices, layerIndex, point, fillType, dimensions, feedRate, miterNormal, new Vector2d(0.5f, -0.5f), miterSecant, 0, pointCount);
            joint.in1 = joint.out1 = AddVertex(vertices, layerIndex, point, fillType, dimensions, feedRate, miterNormal, new Vector2d(0, 0), miterSecant, 1, pointCount);

            var bevelNormalIn = GetNormalAndSecant(ab, miterTangent, out double bevelSecantIn);

            joint.in2 = AddVertex(vertices, layerIndex, point, fillType, dimensions, feedRate, bevelNormalIn, new Vector2d(-0.5f, -0.5f), bevelSecantIn, 0, pointCount);

            var bevelNormalOut = GetNormalAndSecant(miterTangent, bc, out double bevelSecantOut);

            joint.out2 = AddVertex(vertices, layerIndex, point, fillType, dimensions, feedRate, bevelNormalOut, new Vector2d(-0.5f, -0.5f), bevelSecantOut, 0, pointCount);

            joint.in3 = joint.out3 = AddVertex(vertices, layerIndex, point, fillType, dimensions, feedRate, miterNormal, new Vector2d(0, -1), miterSecant, 1, pointCount);

            triangles.Add(joint.in2);
            triangles.Add(joint.in3);
            triangles.Add(joint.out2);

            triangles.Add(joint.in2);
            triangles.Add(joint.out2);
            triangles.Add(joint.in1);

            return(joint);
        }
Exemplo n.º 3
0
        protected ToolpathPreviewJoint GenerateMiterJoint(List <PrintVertex> toolpath, int toolpathIndex, int layerIndex, int startPointCount, List <ToolpathPreviewVertex> vertices)
        {
            double   miterSecant = 1;
            Vector3d miterNormal;

            if (toolpathIndex == 0)
            {
                Vector3d miterTangent = toolpath[1].Position - toolpath[0].Position;
                miterNormal = new Vector3d(-miterTangent.y, miterTangent.x, 0).Normalized;
            }
            else if (toolpathIndex == toolpath.Count - 1)
            {
                Vector3d miterTangent = toolpath[toolpathIndex].Position - toolpath[toolpathIndex - 1].Position;
                miterNormal = new Vector3d(-miterTangent.y, miterTangent.x, 0).Normalized;
            }
            else
            {
                Vector3d a  = toolpath[toolpathIndex - 1].Position;
                Vector3d b  = toolpath[toolpathIndex].Position;
                Vector3d c  = toolpath[toolpathIndex + 1].Position;
                Vector3d ab = (b - a).Normalized;
                Vector3d bc = (c - b).Normalized;
                miterNormal = GetNormalAndSecant(ab, bc, out miterSecant);
            }

            var pointCount             = startPointCount + toolpathIndex;
            var point                  = toolpath[toolpathIndex].Position;
            var dimensions             = toolpath[toolpathIndex].Dimensions;
            var fillType               = (FillTypeFlags)(toolpath[toolpathIndex].Source ?? FillTypeFlags.Unknown);
            var feedRate               = toolpath[toolpathIndex].FeedRate;
            ToolpathPreviewJoint joint = new ToolpathPreviewJoint();

            joint.in0 = joint.out0 = AddVertex(vertices, layerIndex, point, fillType, dimensions, feedRate, miterNormal, new Vector2d(0.5f, -0.5f), miterSecant, 0, pointCount);
            joint.in1 = joint.out1 = AddVertex(vertices, layerIndex, point, fillType, dimensions, feedRate, miterNormal, new Vector2d(0, 0), miterSecant, 1, pointCount);
            joint.in2 = joint.out2 = AddVertex(vertices, layerIndex, point, fillType, dimensions, feedRate, miterNormal, new Vector2d(-0.5f, -0.5f), miterSecant, 0, pointCount);
            joint.in3 = joint.out3 = AddVertex(vertices, layerIndex, point, fillType, dimensions, feedRate, miterNormal, new Vector2d(0, -1), miterSecant, 1, pointCount);

            return(joint);
        }