Пример #1
0
        void CreateMeasureCube(Vector2 startPoint, string text, double width, double height)
        {
            //outerbox
            var cubeModel = new STLModel3D(TypeObject.None, false);
            //cubeModel = (new Cube(12.8f, 8f, 5f)).AsSTLModel3D(Managers.MaterialManager.DefaultMaterial);

            var outerPath         = new Polygon(new PolygonPoint(-(width / 2), -(height / 2)), new PolygonPoint((width / 2), -(height / 2)), new PolygonPoint((width / 2), (height / 2)), new PolygonPoint(-(width / 2), (height / 2)));
            var textAsPolygonSet  = new PolygonSet();
            var letterPolygonsTop = FontTessellationEngine.ConvertStringToTrianglesWithOuterPath(text, FontStyle.Bold, outerPath, out textAsPolygonSet);

            outerPath = new Polygon(new PolygonPoint(-(width / 2), -(height / 2)), new PolygonPoint((width / 2), -(height / 2)), new PolygonPoint((width / 2), (height / 2)), new PolygonPoint(-(width / 2), (height / 2)));
            var letterPolygonsBottom = FontTessellationEngine.ConvertStringToTrianglesWithOuterPath(text, FontStyle.Bold, outerPath, out textAsPolygonSet);

            foreach (var t in letterPolygonsBottom[0])
            {
                t.Flip();
            }

            cubeModel.Triangles = letterPolygonsTop;
            foreach (var t in letterPolygonsTop[0])
            {
                t.Vectors[0].Position += new Vector3Class(0, 0, 5);
                t.Vectors[1].Position += new Vector3Class(0, 0, 5);
                t.Vectors[2].Position += new Vector3Class(0, 0, 5);
            }

            cubeModel.Triangles[0].AddRange(letterPolygonsBottom[0]);

            cubeModel._scaleFactorX = cubeModel._scaleFactorY = cubeModel._scaleFactorZ = 1;
            cubeModel.Scale(0.1f, 0.1f, 1f, Events.ScaleEventArgs.TypeAxis.ALL, true, true);

            CreateExtrudeTriangles(cubeModel, outerPath.Points);
            foreach (var polygon in outerPath.Holes)
            {
                CreateExtrudeTriangles(cubeModel, polygon.Points, true);

                foreach (var holePolygon in polygon.Holes)
                {
                    CreateExtrudeTriangles(cubeModel, holePolygon.Points, true);
                }
            }

            //center triangle
            cubeModel.UpdateBoundries();
            cubeModel.UpdateDefaultCenter();
            cubeModel.Triangles.UpdateWithMoveTranslation(new Vector3Class(startPoint.X, startPoint.Y, 0) - new Vector3Class(cubeModel.LeftPoint, cubeModel.BackPoint, -0.2f));

            //orient model properly
            cubeModel.HorizontalMirror(false, true);
            cubeModel.Rotate(0, 0, 180, Events.RotationEventArgs.TypeAxis.Z);
            cubeModel.UpdateTrianglesMinMaxZ();

            this.Triangles[0].AddRange(cubeModel.Triangles[0]);
        }