예제 #1
0
        public static DrawPathObject Create(SVGPath svp)
        {
            DrawPathObject dp;

            try
            {
                string s = svp.PathData.Trim();
                s = s.Replace("\r", "");
                s = s.Replace("\n", " ");
                s = s.Trim();
                string[] arr = s.Split(' ');

                dp = new DrawPathObject(arr)
                {
                    Name = svp.ShapeName
                };
                dp.SetStyleFromSvg(svp);
            }
            catch (Exception ex)
            {
                SVGErr.Log("DrawPathObject", "Create", ex.ToString(), SVGErr._LogPriority.Info);
                dp = null;
            }

            return(dp);
        }
예제 #2
0
        /// <summary>
        /// 它创建了一个新的SVG路径元素。
        /// </summary>
        public SVGPath AddPath(SVGUnit parent, ref SVGUnit last)
        {
            SVGPath path = new SVGPath(this);

            AddElement(parent, path, ref last);

            return(path);
        }
예제 #3
0
        static void Main(string[] args)
        {
            // Validate arguments

            if (args.Length != 3)
            {
                Usage("nutrecess [flat-distance] [hole-diameter] [destination]");
            }
            if (!double.TryParse(args[0], out double flats))
            {
                Usage("Distance across flats must be digits with possible decimal point");
            }
            if (!double.TryParse(args[1], out double holeDiameter))
            {
                Usage("Hole diameter must be digits with possible decimal point");
            }
            if (flats <= 0)
            {
                Usage("Distance across flats must be non-zero and positive");
            }
            if (holeDiameter < 0)
            {
                Usage("Hole diameter must be positive, or set to zero for no hole");
            }
            if (!args[2].EndsWith(".svg", StringComparison.CurrentCultureIgnoreCase))
            {
                Usage("Destination file must have a '.svg' extension");
            }

            // Create the cutout and its centering crosshairs

            var svgCreator = new SVGCreator
            {
                DocumentDimensions     = NewSz(flats * 2, flats * 2),
                DocumentDimensionUnits = "mm",
                ViewBoxDimensions      = NewRect(-flats, -flats, 2 * flats, 2 * flats)
            };

            svgCreator.AddClosedPath(NutRecessPoints(flats), "black", 0.03, "gray");
            if (holeDiameter > 0)
            {
                svgCreator.AddClosedPath(Arc(0, 360, holeDiameter / 2, PointF.Empty), "black", 0.03, "darkgray");
            }
            var pathX = new SVGPath(Line(-2 * flats / 3.0, 0, 2 * flats / 3.0, 0), false);

            pathX.SetDrawingParams("black", 0.03, "");
            svgCreator.AddPath(pathX);
            var pathY = new SVGPath(Line(0, -2 * flats / 3.0, 0, 2 * flats / 3.0), false);

            pathY.SetDrawingParams("black", 0.03, "");
            svgCreator.AddPath(pathY);

            // Save out to the destination file

            using TextWriter tw = new StreamWriter(args[2]);
            tw.Write(svgCreator.ToString());
        }
예제 #4
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);


            //  Opacity
            m_OpacityPlusButton        = new Alt.GUI.Temporary.Gwen.Control.Button(m_OpacityControl);
            m_OpacityPlusButton.Text   = "+";
            m_OpacityPlusButton.Dock   = Pos.Top;
            m_OpacityPlusButton.Click += new EventHandler(OpacityPlusButton_Click);

            m_OpacityMinusButton        = new Alt.GUI.Temporary.Gwen.Control.Button(m_OpacityControl);
            m_OpacityMinusButton.Text   = "-";
            m_OpacityMinusButton.Dock   = Pos.Bottom;
            m_OpacityMinusButton.Click += new EventHandler(OpacityMinusButton_Click);

            m_OpacitySlider      = new Alt.GUI.Temporary.Gwen.Control.VerticalSlider(m_OpacityControl);
            m_OpacitySlider.Dock = Pos.Fill;
            m_OpacitySlider.SetRange(0.05f, 1);
            m_OpacitySlider.Value = (float)(m_Opacity = 0.05f);


            //
            m_SVGPath = new SVGPath();

            m_x        = ClientWidth / 2;
            m_y        = ClientHeight / 2;
            m_dx       = 0.0;
            m_dy       = 0.0;
            m_DragFlag = false;


            try
            {
                LoadSVG("AltData/SVG/lion.svg");
            }
            catch (SVGException)
            {
                //TEMP  message(.ToString(e.Message));

                return;
            }
        }
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);


            //  Transformation Type
            rbBilinear.Select();

            groupBox_TransformationType.SelectionChanged += new GwenEventHandler(groupBox_TransformationType_SelectionChanged);

            //  update groupBox_TransformationType location
            DrawingPanel_Resize(null, EventArgs.Empty);



            //
            m_PolygonElement           = new PolygonElement(4, 5.0);
            m_PolygonElement.Color     = Color.FromArgb(200, Color.Yellow);
            m_PolygonElement.LineWidth = 2;
            m_DrawingPanel.AddElement(m_PolygonElement);



            //
            m_SVGPath = new SVGPath();
            m_x       = m_DrawingPanel.ClientWidth / 2;
            m_y       = m_DrawingPanel.ClientHeight / 2;

            m_EllipsePen   = new Pen(Color.LightGreen, 3);
            m_EllipseBrush = new SolidColorBrush(ColorR.FromArgb(0.4, 0.5, 0.3, 0.0));


            try
            {
                LoadSVG("AltData/SVG/lion.svg");
            }
            catch (SVGException)
            {
                //TEMP  message(.ToString(e.Message));

                return;
            }
        }
예제 #6
0
        static void Main(string[] args)
        {
            var circle = new SVGCircle(new Point(250.0, 550.0), 20.0,
                                       new Color(100, 255, 56, 0),
                                       new Color(0, 0, 0, 0),
                                       2
                                       );

            var ellipse = new SVGEllipse(new Point(450.0, 550.0), 20.0, 10.0,
                                         new Color(100, 255, 56, 0),
                                         new Color(0, 0, 0, 0),
                                         2
                                         );

            var points = new List <Point>()
            {
                new Point(70, 5), new Point(90, 41), new Point(136, 48),
                new Point(103, 80), new Point(111, 126), new Point(70, 105), new Point(29, 126), new Point(36, 80), new Point(5, 48), new Point(48, 41)
            };

            var pathdata = new List <Point>()
            {
                new Point(200, 100), new Point(250, 210), new Point(16, 210)
            };

            var path = new SVGPath(pathdata, new Color(255, 100, 56, 0), new Color(0, 0, 0, 0), 2);

            var polygon = new SVGPolygon(points, new Color(100, 255, 56, 0), new Color(0, 0, 0, 0), 2);

            var rect = new SVGRect(50.0, 20.0, 50.0, 20.0, new Color(100, 255, 56, 0), new Color(0, 0, 0, 0), 2);

            SVGIO.export(new List <SVGShape>()
            {
                polygon, ellipse, circle, rect, path
            }, "Z:\\Sources\\VectorGraphicsEditor\\IO Tests\\output\\mix.svg", 1000, 1001);

            // SVGIO.import("Z:\\Sources\\VectorGraphicsEditor\\IO Tests\\output\\Freesample.svg");
        }
예제 #7
0
        public void StartProcess(SVGAsset asset)
        {
            if (UnityEditor.EditorApplication.isPlayingOrWillChangePlaymode)
            {
                return;
            }

            if (errors == null)
            {
                errors = new List <SVGError>();
            }
            else
            {
                errors.Clear();
            }
            _importingSVG = true;

            System.Reflection.FieldInfo _editor_runtimeMaterials = typeof(SVGAsset).GetField("_runtimeMaterials", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
            _editor_runtimeMaterials.SetValue(asset, null);

            System.Reflection.FieldInfo _editor_runtimeMesh = typeof(SVGAsset).GetField("_runtimeMesh", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
            _editor_runtimeMesh.SetValue(asset, null);

            UnityEditor.SerializedObject   svgAsset      = new UnityEditor.SerializedObject(asset);
            UnityEditor.SerializedProperty sharedMesh    = svgAsset.FindProperty("_sharedMesh");
            UnityEditor.SerializedProperty sharedShaders = svgAsset.FindProperty("_sharedShaders");

            Clear();
            SVGParser.Init();
            SVGGraphics.Init();
            atlasData = new SVGAtlasData();
            atlasData.Init(SVGAtlas.defaultAtlasTextureWidth * SVGAtlas.defaultAtlasTextureHeight);
            atlasData.AddGradient(SVGAtlasData.GetDefaultGradient());
            SVGElement _rootSVGElement = null;

#if IGNORE_EXCEPTIONS
            try {
#else
            Debug.LogWarning("Exceptions are turned on!");
#endif
                // Create new Asset
                CreateEmptySVGDocument();
                _rootSVGElement = this._svgDocument.rootElement;
#if IGNORE_EXCEPTIONS
            } catch (System.Exception exception) {
                _rootSVGElement = null;
                errors.Add(SVGError.Syntax);
                Debug.LogError("SVG Document Exception: " + exception.Message, asset);
            }
#endif

                if (_rootSVGElement == null)
                {
                    Debug.LogError("SVG Document is corrupted! " + UnityEditor.AssetDatabase.GetAssetPath(asset), asset);
                    _importingSVG = false;
                    return;
                }

#if IGNORE_EXCEPTIONS
                try {
#endif
                _rootSVGElement.Render();

                Rect viewport = _rootSVGElement.paintable.viewport;
                viewport.x    *= SVGAssetImport.meshScale;
                viewport.y    *= SVGAssetImport.meshScale;
                viewport.size *= SVGAssetImport.meshScale;

                Vector2 offset;
                SVGGraphics.CorrectSVGLayers(SVGGraphics.layers, viewport, asset, out offset);

                // Handle gradients
                bool hasGradients = false;

                // Create actual Mesh
                Shader[] outputShaders;
                Mesh mesh = new Mesh();
                SVGMesh.CombineMeshes(SVGGraphics.layers.ToArray(), mesh, out outputShaders, useGradients, format, compressDepth, asset.antialiasing);
                if (mesh == null)
                {
                    return;
                }

                if (useGradients == SVGUseGradients.Always)
                {
                    if (outputShaders != null)
                    {
                        for (int i = 0; i < outputShaders.Length; i++)
                        {
                            if (outputShaders[i] == null)
                            {
                                continue;
                            }
                            if (outputShaders[i].name == SVGShader.SolidColorOpaque.name)
                            {
                                outputShaders[i] = SVGShader.GradientColorOpaque;
                            }
                            else if (outputShaders[i].name == SVGShader.SolidColorAlphaBlended.name)
                            {
                                outputShaders[i] = SVGShader.GradientColorAlphaBlended;
                            }
                            else if (outputShaders[i].name == SVGShader.SolidColorAlphaBlendedAntialiased.name)
                            {
                                outputShaders[i] = SVGShader.GradientColorAlphaBlendedAntialiased;
                            }
                        }
                    }
                    hasGradients = true;
                }
                else
                {
                    if (outputShaders != null)
                    {
                        for (int i = 0; i < outputShaders.Length; i++)
                        {
                            if (outputShaders[i] == null)
                            {
                                continue;
                            }
                            if (outputShaders[i].name == SVGShader.GradientColorOpaque.name ||
                                outputShaders[i].name == SVGShader.GradientColorAlphaBlended.name ||
                                outputShaders[i].name == SVGShader.GradientColorAlphaBlendedAntialiased.name ||
                                outputShaders[i].name == SVGShader.GradientColorAlphaBlendedAntialiasedCompressed.name)
                            {
                                hasGradients = true;
                                break;
                            }
                        }
                    }
                }

                if (!asset.useLayers)
                {
                    sharedMesh.objectReferenceValue = AddObjectToAsset <Mesh>(mesh, asset, HideFlags.HideInHierarchy);
                }

//                Material sharedMaterial;
                if (outputShaders != null && outputShaders.Length > 0)
                {
                    sharedShaders.arraySize = outputShaders.Length;
                    if (hasGradients)
                    {
                        for (int i = 0; i < outputShaders.Length; i++)
                        {
                            sharedShaders.GetArrayElementAtIndex(i).stringValue = outputShaders[i].name;
                        }
                    }
                    else
                    {
                        for (int i = 0; i < outputShaders.Length; i++)
                        {
                            if (outputShaders[i].name == SVGShader.GradientColorAlphaBlended.name)
                            {
                                outputShaders[i] = SVGShader.SolidColorAlphaBlended;
                            }
                            else if (outputShaders[i].name == SVGShader.GradientColorOpaque.name)
                            {
                                outputShaders[i] = SVGShader.SolidColorOpaque;
                            }
                            sharedShaders.GetArrayElementAtIndex(i).stringValue = outputShaders[i].name;
                        }
                    }
                }

                // Serialize the Asset
                svgAsset.ApplyModifiedProperties();

                // Handle Canvas Rectangle
                System.Reflection.MethodInfo _editor_SetCanvasRectangle = typeof(SVGAsset).GetMethod("_editor_SetCanvasRectangle", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
                _editor_SetCanvasRectangle.Invoke(asset, new object[] { new Rect(viewport.x, viewport.y, viewport.size.x, viewport.size.y) });

                if (asset.generateCollider)
                {
                    // Create polygon contour
                    if (SVGGraphics.paths != null && SVGGraphics.paths.Count > 0)
                    {
                        List <List <Vector2> > polygons = new List <List <Vector2> >();
                        for (int i = 0; i < SVGGraphics.paths.Count; i++)
                        {
                            Vector2[] points = SVGGraphics.paths[i].points;
                            for (int j = 0; j < points.Length; j++)
                            {
                                points[j].x = points[j].x * SVGAssetImport.meshScale - offset.x;
                                points[j].y = (points[j].y * SVGAssetImport.meshScale + offset.y) * -1f;
                            }

                            polygons.Add(new List <Vector2>(points));
                        }

                        polygons = SVGGeom.MergePolygon(polygons);

                        SVGPath[] paths = new SVGPath[polygons.Count];
                        for (int i = 0; i < polygons.Count; i++)
                        {
                            paths[i] = new SVGPath(polygons[i].ToArray());
                        }

                        System.Reflection.MethodInfo _editor_SetColliderShape = typeof(SVGAsset).GetMethod("_editor_SetColliderShape", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
                        if (paths != null && paths.Length > 0)
                        {
                            _editor_SetColliderShape.Invoke(asset, new object[] { paths });
                        }
                        else
                        {
                            _editor_SetColliderShape.Invoke(asset, new object[] { null });
                        }
                    }
                }
                else
                {
                    System.Reflection.MethodInfo _editor_SetColliderShape = typeof(SVGAsset).GetMethod("_editor_SetColliderShape", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
                    _editor_SetColliderShape.Invoke(asset, new object[] { null });
                }

                System.Reflection.MethodInfo _editor_SetGradients = typeof(SVGAsset).GetMethod("_editor_SetGradients", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
                _editor_SetGradients.Invoke(asset, new object[] { null });
                if (hasGradients)
                {
                    if (atlasData.gradientCache != null && atlasData.gradientCache.Count > 0)
                    {
                        int          gradientsCount = SVGAssetImport.atlasData.gradientCache.Count;
                        CCGradient[] gradients      = new CCGradient[gradientsCount];
                        int          i = 0;
                        foreach (KeyValuePair <string, CCGradient> entry in SVGAssetImport.atlasData.gradientCache)
                        {
                            gradients[i++] = entry.Value;
                        }
                        _editor_SetGradients.Invoke(asset, new object[] { gradients });
                    }
                }

                System.Reflection.MethodInfo _editor_SetLayers = typeof(SVGAsset).GetMethod("_editor_SetLayers", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
                _editor_SetLayers.Invoke(asset, new object[] { null });
                if (asset.useLayers)
                {
                    if (SVGGraphics.layers != null && SVGGraphics.layers.Count > 0)
                    {
                        _editor_SetLayers.Invoke(asset, new object[] { SVGGraphics.layers.ToArray() });
                    }
                }

#if IGNORE_EXCEPTIONS
            } catch (System.Exception exception) {
                Debug.LogWarning("Asset: " + UnityEditor.AssetDatabase.GetAssetPath(asset) + " Failed to import\n" + exception.Message, asset);
                errors.Add(SVGError.CorruptedFile);
            }
#endif
                if (_svgDocument != null)
                {
                    _svgDocument.Clear();
                    _svgDocument = null;
                }
                Clear();

                UnityEditor.EditorUtility.SetDirty(asset);
                _importingSVG = false;
            }
예제 #8
0
 protected override void Awake()
 {
     base.Awake();
     m_Path         = SVGPath.Parse(m_SVGPath);
     m_Path.mirrorY = m_MirrorY;
 }
예제 #9
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);


            //  Opacity
            m_OpacityPlusButton        = new Alt.GUI.Temporary.Gwen.Control.Button(m_OpacityControl);
            m_OpacityPlusButton.Text   = "+";
            m_OpacityPlusButton.Dock   = Pos.Top;
            m_OpacityPlusButton.Click += new EventHandler(OpacityPlusButton_Click);

            m_OpacityMinusButton        = new Alt.GUI.Temporary.Gwen.Control.Button(m_OpacityControl);
            m_OpacityMinusButton.Text   = "-";
            m_OpacityMinusButton.Dock   = Pos.Bottom;
            m_OpacityMinusButton.Click += new EventHandler(OpacityMinusButton_Click);

            m_OpacitySlider      = new Alt.GUI.Temporary.Gwen.Control.VerticalSlider(m_OpacityControl);
            m_OpacitySlider.Dock = Pos.Fill;
            m_OpacitySlider.SetRange(0.05f, 1);
            m_OpacitySlider.Value = 1;


            //  Scale
            m_ScaleControl = new Alt.GUI.Temporary.Gwen.Control.Base(m_DrawingPanel);
            m_ScaleControl.SetBounds(10, 30, 20, 200);

            m_ScalePlusButton        = new Alt.GUI.Temporary.Gwen.Control.Button(m_ScaleControl);
            m_ScalePlusButton.Text   = "+";
            m_ScalePlusButton.Dock   = Pos.Top;
            m_ScalePlusButton.Click += new EventHandler(ScalePlusButton_Click);

            m_ScaleMinusButton        = new Alt.GUI.Temporary.Gwen.Control.Button(m_ScaleControl);
            m_ScaleMinusButton.Text   = "-";
            m_ScaleMinusButton.Dock   = Pos.Bottom;
            m_ScaleMinusButton.Click += new EventHandler(ScaleMinusButton_Click);

            m_ScaleSlider      = new Alt.GUI.Temporary.Gwen.Control.VerticalSlider(m_ScaleControl);
            m_ScaleSlider.Dock = Pos.Fill;
            m_ScaleSlider.SetRange(0.3f, 5);
            m_ScaleSlider.Value = 1;


            //  Rotate
            m_RotateControl = new Alt.GUI.Temporary.Gwen.Control.Base(m_DrawingPanel);
            m_RotateControl.SetBounds(30, 10, 200, 20);

            m_RotatePlusButton        = new Alt.GUI.Temporary.Gwen.Control.Button(m_RotateControl);
            m_RotatePlusButton.Text   = "+";
            m_RotatePlusButton.Dock   = Pos.Right;
            m_RotatePlusButton.Width  = m_RotateControl.Height;
            m_RotatePlusButton.Click += new EventHandler(RotatePlusButton_Click);

            m_RotateMinusButton        = new Alt.GUI.Temporary.Gwen.Control.Button(m_RotateControl);
            m_RotateMinusButton.Text   = "-";
            m_RotateMinusButton.Dock   = Pos.Left;
            m_RotateMinusButton.Width  = m_RotateControl.Height;
            m_RotateMinusButton.Click += new EventHandler(RotateMinusButton_Click);

            m_RotateSlider      = new Alt.GUI.Temporary.Gwen.Control.HorizontalSlider(m_RotateControl);
            m_RotateSlider.Dock = Pos.Fill;
            m_RotateSlider.SetRange(-180, 180);
            m_RotateSlider.Value = 0;


            m_OpacitySlider.ValueChanged += new GwenEventHandler(Slider_ValueChanged);
            m_ScaleSlider.ValueChanged   += new GwenEventHandler(Slider_ValueChanged);
            m_RotateSlider.ValueChanged  += new GwenEventHandler(Slider_ValueChanged);
            //  Preview
            m_OpacitySlider.ValueChanged += new GwenEventHandler(RotateAndOpacity_Slider_ValueChanged);
            m_RotateSlider.ValueChanged  += new GwenEventHandler(RotateAndOpacity_Slider_ValueChanged);



            //
            m_SVGPath = new SVGPath();

            int k = 30;

            m_x        = m_DrawingPanel.ClientWidth / 2 + k;
            m_y        = m_DrawingPanel.ClientHeight / 2 + k;
            m_dx       = 0.0;
            m_dy       = 0.0;
            m_DragFlag = false;


            try
            {
                LoadSVG("AltData/SVG/longhorn.svg");
                //LoadSVG("AltData/SVG/lion.svg");
            }
            catch (Exception)
            {
                return;
            }
        }
예제 #10
0
        public void StartProcess(SVGAsset asset)
        {
            if (UnityEditor.EditorApplication.isPlayingOrWillChangePlaymode)
            {
                return;
            }

            if (errors == null)
            {
                errors = new List <SVGError>();
            }
            else
            {
                errors.Clear();
            }
            _importingSVG = true;

            UnityEditor.SerializedObject   svgAsset      = new UnityEditor.SerializedObject(asset);
            UnityEditor.SerializedProperty sharedMesh    = svgAsset.FindProperty("_sharedMesh");
            UnityEditor.SerializedProperty sharedShaders = svgAsset.FindProperty("_sharedShaders");

            Clear();
            SVGParser.Init();
            SVGGraphics.Init();
            atlasData = new SVGAtlasData();
            SVGElement _rootSVGElement = null;

#if IGNORE_EXCEPTIONS
            try {
#else
            Debug.LogWarning("Exceptions are turned on!");
#endif
                // Create new Asset
                CreateEmptySVGDocument();
                _rootSVGElement = this._svgDocument.rootElement;
#if IGNORE_EXCEPTIONS
            } catch (System.Exception exception) {
                _rootSVGElement = null;
                errors.Add(SVGError.Syntax);
                Debug.LogError("SVG Document Exception: " + exception.Message, asset);
            }
#endif

                if (_rootSVGElement == null)
                {
                    Debug.LogError("SVG Document is corrupted! " + UnityEditor.AssetDatabase.GetAssetPath(asset), asset);
                    _importingSVG = false;
                    return;
                }

                SVGGraphics.depthTree = new SVGDepthTree(_rootSVGElement.paintable.viewport);

#if IGNORE_EXCEPTIONS
                try {
#endif
                _rootSVGElement.Render();

                // Handle gradients
                bool hasGradients = (useGradients == SVGUseGradients.Always);

                // Create actual Mesh
                Shader[] outputShaders;
                SVGLayer[] outputLayers;
                Mesh mesh = SVGMesh.CombineMeshes(SVGGraphics.meshes, out outputLayers, out outputShaders, useGradients, format, compressDepth);
                if (mesh == null)
                {
                    return;
                }

                if (outputShaders != null)
                {
                    for (int i = 0; i < outputShaders.Length; i++)
                    {
                        if (outputShaders[i] == null)
                        {
                            continue;
                        }
                        if (outputShaders[i].name == SVGShader.GradientColorOpaque.name ||
                            outputShaders[i].name == SVGShader.GradientColorAlphaBlended.name)
                        {
                            hasGradients = true;
                            break;
                        }
                    }
                }

                Vector3[] vertices = mesh.vertices;
                Vector2 offset;
                Bounds bounds = mesh.bounds;
                Rect viewport = _rootSVGElement.paintable.viewport;
                viewport.x    *= SVGAssetImport.meshScale;
                viewport.y    *= SVGAssetImport.meshScale;
                viewport.size *= SVGAssetImport.meshScale;

                if (asset.ignoreSVGCanvas)
                {
                    offset = new Vector2(bounds.min.x + bounds.size.x * asset.pivotPoint.x,
                                         bounds.min.y + bounds.size.y * asset.pivotPoint.y);
                }
                else
                {
                    offset = new Vector2(viewport.min.x + viewport.size.x * asset.pivotPoint.x,
                                         viewport.min.y + viewport.size.y * asset.pivotPoint.y);
                }

                // Apply pivot point and Flip Y Axis
                for (int i = 0; i < vertices.Length; i++)
                {
                    vertices[i].x = vertices[i].x - offset.x;
                    vertices[i].y = (vertices[i].y - offset.y) * -1f;
                }

                mesh.vertices = vertices;
                mesh.RecalculateBounds();
                sharedMesh.objectReferenceValue = AddObjectToAsset <Mesh>(mesh, asset, HideFlags.HideInHierarchy);

//                Material sharedMaterial;
                if (outputShaders != null && outputShaders.Length > 0)
                {
                    sharedShaders.arraySize = outputShaders.Length;
                    if (hasGradients)
                    {
                        for (int i = 0; i < outputShaders.Length; i++)
                        {
                            sharedShaders.GetArrayElementAtIndex(i).stringValue = outputShaders[i].name;
                        }
                    }
                    else
                    {
                        for (int i = 0; i < outputShaders.Length; i++)
                        {
                            if (outputShaders[i].name == SVGShader.GradientColorAlphaBlended.name)
                            {
                                outputShaders[i] = SVGShader.SolidColorAlphaBlended;
                            }
                            else if (outputShaders[i].name == SVGShader.GradientColorOpaque.name)
                            {
                                outputShaders[i] = SVGShader.SolidColorOpaque;
                            }
                            sharedShaders.GetArrayElementAtIndex(i).stringValue = outputShaders[i].name;
                        }
                    }
                }

                // Serialize the Asset
                svgAsset.ApplyModifiedProperties();

                // Handle Canvas Rectangle
                System.Reflection.MethodInfo _editor_SetCanvasRectangle = typeof(SVGAsset).GetMethod("_editor_SetCanvasRectangle", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
                _editor_SetCanvasRectangle.Invoke(asset, new object[] { new Rect(viewport.x, viewport.y, viewport.size.x, viewport.size.y) });

                if (asset.generateCollider)
                {
                    // Create polygon contour
                    if (SVGGraphics.paths != null && SVGGraphics.paths.Count > 0)
                    {
                        List <List <Vector2> > polygons = new List <List <Vector2> >();
                        for (int i = 0; i < SVGGraphics.paths.Count; i++)
                        {
                            Vector2[] points = SVGGraphics.paths[i].points;
                            for (int j = 0; j < points.Length; j++)
                            {
                                points[j].x = points[j].x * SVGAssetImport.meshScale - offset.x;
                                points[j].y = (points[j].y * SVGAssetImport.meshScale - offset.y) * -1f;
                            }

                            polygons.Add(new List <Vector2>(points));
                        }

                        polygons = SVGGeom.MergePolygon(polygons);

                        SVGPath[] paths = new SVGPath[polygons.Count];
                        for (int i = 0; i < polygons.Count; i++)
                        {
                            paths[i] = new SVGPath(polygons[i].ToArray());
                        }

                        System.Reflection.MethodInfo _editor_SetColliderShape = typeof(SVGAsset).GetMethod("_editor_SetColliderShape", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
                        if (paths != null && paths.Length > 0)
                        {
                            _editor_SetColliderShape.Invoke(asset, new object[] { paths });
                        }
                        else
                        {
                            _editor_SetColliderShape.Invoke(asset, new object[] { null });
                        }
                    }
                }
                else
                {
                    System.Reflection.MethodInfo _editor_SetColliderShape = typeof(SVGAsset).GetMethod("_editor_SetColliderShape", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
                    _editor_SetColliderShape.Invoke(asset, new object[] { null });
                }

                if (hasGradients)
                {
                    System.Reflection.MethodInfo _editor_SetGradients = typeof(SVGAsset).GetMethod("_editor_SetGradients", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
                    if (atlasData.gradients != null && atlasData.gradients.Count > 0)
                    {
                        _editor_SetGradients.Invoke(asset, new object[] { atlasData.gradients.ToArray() });
                    }
                    else
                    {
                        _editor_SetGradients.Invoke(asset, new object[] { null });
                    }
                }
#if IGNORE_EXCEPTIONS
            } catch (System.Exception exception) {
                Debug.LogWarning("Asset: " + UnityEditor.AssetDatabase.GetAssetPath(asset) + " Failed to import\n" + exception.Message, asset);
                errors.Add(SVGError.CorruptedFile);
            }
#endif
                if (_svgDocument != null)
                {
                    _svgDocument.Clear();
                    _svgDocument = null;
                }
                Clear();

                UnityEditor.EditorUtility.SetDirty(asset);
                _importingSVG = false;
            }
예제 #11
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);


            //  Opacity
            m_OpacityPlusButton        = new Alt.GUI.Temporary.Gwen.Control.Button(m_OpacityControl);
            m_OpacityPlusButton.Text   = "+";
            m_OpacityPlusButton.Dock   = Pos.Top;
            m_OpacityPlusButton.Click += new EventHandler(OpacityPlusButton_Click);

            m_OpacityMinusButton        = new Alt.GUI.Temporary.Gwen.Control.Button(m_OpacityControl);
            m_OpacityMinusButton.Text   = "-";
            m_OpacityMinusButton.Dock   = Pos.Bottom;
            m_OpacityMinusButton.Click += new EventHandler(OpacityMinusButton_Click);

            m_OpacitySlider      = new Alt.GUI.Temporary.Gwen.Control.VerticalSlider(m_OpacityControl);
            m_OpacitySlider.Dock = Pos.Fill;
            m_OpacitySlider.SetRange(0.05f, 1);
            m_OpacitySlider.Value = 1;


            //  Scale
            m_ScaleControl = new Base(m_DrawingPanel);
            m_ScaleControl.SetBounds(10, 30, 20, 200);

            m_ScalePlusButton        = new Alt.GUI.Temporary.Gwen.Control.Button(m_ScaleControl);
            m_ScalePlusButton.Text   = "+";
            m_ScalePlusButton.Dock   = Pos.Top;
            m_ScalePlusButton.Click += new EventHandler(ScalePlusButton_Click);

            m_ScaleMinusButton        = new Alt.GUI.Temporary.Gwen.Control.Button(m_ScaleControl);
            m_ScaleMinusButton.Text   = "-";
            m_ScaleMinusButton.Dock   = Pos.Bottom;
            m_ScaleMinusButton.Click += new EventHandler(ScaleMinusButton_Click);

            m_ScaleSlider      = new VerticalSlider(m_ScaleControl);
            m_ScaleSlider.Dock = Pos.Fill;
            m_ScaleSlider.SetRange(0.3f, 5);
            m_ScaleSlider.Value = 1;


            //  Rotate
            m_RotateControl = new Base(m_DrawingPanel);
            m_RotateControl.SetBounds(30, 10, 200, 20);

            m_RotatePlusButton        = new Alt.GUI.Temporary.Gwen.Control.Button(m_RotateControl);
            m_RotatePlusButton.Text   = "+";
            m_RotatePlusButton.Dock   = Pos.Right;
            m_RotatePlusButton.Width  = m_RotateControl.Height;
            m_RotatePlusButton.Click += new EventHandler(RotatePlusButton_Click);

            m_RotateMinusButton        = new Alt.GUI.Temporary.Gwen.Control.Button(m_RotateControl);
            m_RotateMinusButton.Text   = "-";
            m_RotateMinusButton.Dock   = Pos.Left;
            m_RotateMinusButton.Width  = m_RotateControl.Height;
            m_RotateMinusButton.Click += new EventHandler(RotateMinusButton_Click);

            m_RotateSlider      = new HorizontalSlider(m_RotateControl);
            m_RotateSlider.Dock = Pos.Fill;
            m_RotateSlider.SetRange(-180, 180);
            m_RotateSlider.Value = 0;


            //  Expand
            m_ExpandSlider      = new Alt.GUI.Temporary.Gwen.Control.HorizontalSlider(this);
            m_ExpandSlider.Dock = Pos.Bottom;
            m_ExpandSlider.SetRange(-1, 1.2f);
            m_ExpandSlider.ValueChanged += new GwenEventHandler(ExpandSlider_ValueChanged);
            m_ExpandSlider.Height        = 20;
            m_ExpandSlider.Margin        = new Margin(0, 3, 0, 0);

            m_ExpandLabel = new Alt.GUI.Temporary.Gwen.Control.Label(this);
            m_ExpandLabel.AutoSizeToContents = true;
            m_ExpandLabel.Dock = Pos.Bottom;

            m_ExpandSlider.Value = 0;


            m_OpacitySlider.ValueChanged += new GwenEventHandler(Slider_ValueChanged);
            m_ScaleSlider.ValueChanged   += new GwenEventHandler(Slider_ValueChanged);
            m_RotateSlider.ValueChanged  += new GwenEventHandler(Slider_ValueChanged);
            m_ExpandSlider.ValueChanged  += new GwenEventHandler(Slider_ValueChanged);



            //
            m_SVGPath = new SVGPath();

            m_x        = m_DrawingPanel.ClientWidth / 2;
            m_y        = m_DrawingPanel.ClientHeight / 2;
            m_dx       = 0.0;
            m_dy       = 0.0;
            m_DragFlag = false;


            try
            {
                LoadSVG("AltData/SVG/tiger.svg");
            }
            catch (Exception)
            {
                return;
            }
        }
예제 #12
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);


            //  Opacity
            m_OpacityPlusButton        = new Alt.GUI.Temporary.Gwen.Control.Button(m_OpacityControl);
            m_OpacityPlusButton.Text   = "+";
            m_OpacityPlusButton.Dock   = Pos.Top;
            m_OpacityPlusButton.Click += new EventHandler(OpacityPlusButton_Click);

            m_OpacityMinusButton        = new Alt.GUI.Temporary.Gwen.Control.Button(m_OpacityControl);
            m_OpacityMinusButton.Text   = "-";
            m_OpacityMinusButton.Dock   = Pos.Bottom;
            m_OpacityMinusButton.Click += new EventHandler(OpacityMinusButton_Click);

            m_OpacitySlider      = new Alt.GUI.Temporary.Gwen.Control.VerticalSlider(m_OpacityControl);
            m_OpacitySlider.Dock = Pos.Fill;
            m_OpacitySlider.SetRange(0.05f, 1);
            m_OpacitySlider.Value = 1;


            //  Scale
            m_ScaleControl = new Alt.GUI.Temporary.Gwen.Control.Base(m_DrawingPanel);
            m_ScaleControl.SetBounds(10, 30, 20, 200);

            m_ScalePlusButton        = new Alt.GUI.Temporary.Gwen.Control.Button(m_ScaleControl);
            m_ScalePlusButton.Text   = "+";
            m_ScalePlusButton.Dock   = Pos.Top;
            m_ScalePlusButton.Click += new EventHandler(ScalePlusButton_Click);

            m_ScaleMinusButton        = new Alt.GUI.Temporary.Gwen.Control.Button(m_ScaleControl);
            m_ScaleMinusButton.Text   = "-";
            m_ScaleMinusButton.Dock   = Pos.Bottom;
            m_ScaleMinusButton.Click += new EventHandler(ScaleMinusButton_Click);

            m_ScaleSlider      = new Alt.GUI.Temporary.Gwen.Control.VerticalSlider(m_ScaleControl);
            m_ScaleSlider.Dock = Pos.Fill;
            m_ScaleSlider.SetRange(0.3f, 5);
            m_ScaleSlider.Value = 1;


            //  Rotate
            m_RotateControl = new Alt.GUI.Temporary.Gwen.Control.Base(m_DrawingPanel);
            m_RotateControl.SetBounds(30, 10, 200, 20);

            m_RotatePlusButton        = new Alt.GUI.Temporary.Gwen.Control.Button(m_RotateControl);
            m_RotatePlusButton.Text   = "+";
            m_RotatePlusButton.Dock   = Pos.Right;
            m_RotatePlusButton.Width  = m_RotateControl.Height;
            m_RotatePlusButton.Click += new EventHandler(RotatePlusButton_Click);

            m_RotateMinusButton        = new Alt.GUI.Temporary.Gwen.Control.Button(m_RotateControl);
            m_RotateMinusButton.Text   = "-";
            m_RotateMinusButton.Dock   = Pos.Left;
            m_RotateMinusButton.Width  = m_RotateControl.Height;
            m_RotateMinusButton.Click += new EventHandler(RotateMinusButton_Click);

            m_RotateSlider      = new HorizontalSlider(m_RotateControl);
            m_RotateSlider.Dock = Pos.Fill;
            m_RotateSlider.SetRange(-180, 180);
            m_RotateSlider.Value = 0;


            //  Magnification
            m_MagnificationSlider      = new HorizontalSlider(this);
            m_MagnificationSlider.Dock = Pos.Bottom;
            m_MagnificationSlider.SetRange(0.01f, 4);
            m_MagnificationSlider.ValueChanged += new GwenEventHandler(MagnificationSlider_ValueChanged);
            m_MagnificationSlider.Height        = 20;
            m_MagnificationSlider.Margin        = new Margin(0, 3, 0, 0);

            m_MagnificationLabel = new Alt.GUI.Temporary.Gwen.Control.Label(this);
            m_MagnificationLabel.AutoSizeToContents = true;
            m_MagnificationLabel.Dock = Pos.Bottom;

            m_MagnificationSlider.Value = 3.2f;


            //  Radius
            m_RadiusSlider      = new HorizontalSlider(this);
            m_RadiusSlider.Dock = Pos.Bottom;
            m_RadiusSlider.SetRange(10, 200);
            m_RadiusSlider.ValueChanged += new GwenEventHandler(RadiusSlider_ValueChanged);
            m_RadiusSlider.Height        = 20;
            m_RadiusSlider.Margin        = new Margin(0, 3, 0, 0);

            m_RadiusLabel = new Alt.GUI.Temporary.Gwen.Control.Label(this);
            m_RadiusLabel.AutoSizeToContents = true;
            m_RadiusLabel.Dock   = Pos.Bottom;
            m_RadiusLabel.Margin = new Margin(0, 10, 0, 0);

            m_RadiusSlider.Value = 100;


            //  Sight
            m_ShowSightCheckBox               = new LabeledCheckBox(this);
            m_ShowSightCheckBox.Dock          = Pos.Bottom;
            m_ShowSightCheckBox.Text          = "Show Sight";
            m_ShowSightCheckBox.Margin        = new Margin(0, 3, 0, 0);
            m_ShowSightCheckBox.IsChecked     = true;
            m_ShowSightCheckBox.CheckChanged += new GwenEventHandler(ShowSightCheckBox_CheckChanged);



            m_OpacitySlider.ValueChanged       += new GwenEventHandler(Slider_ValueChanged);
            m_ScaleSlider.ValueChanged         += new GwenEventHandler(Slider_ValueChanged);
            m_RotateSlider.ValueChanged        += new GwenEventHandler(Slider_ValueChanged);
            m_MagnificationSlider.ValueChanged += new GwenEventHandler(Slider_ValueChanged);
            m_RadiusSlider.ValueChanged        += new GwenEventHandler(Slider_ValueChanged);
            //  Preview
            m_OpacitySlider.ValueChanged += new GwenEventHandler(RotateAndOpacity_Slider_ValueChanged);
            m_RotateSlider.ValueChanged  += new GwenEventHandler(RotateAndOpacity_Slider_ValueChanged);



            //
            m_RadiusPen = new Pen(
                Color.FromArgb(0.7, Color.LimeGreen * 1.2),
                //Color.FromArgb(0.7, Color.Red),
                3);



            //
            m_SVGPath = new SVGPath();

            m_x        = m_DrawingPanel.ClientWidth / 2;
            m_y        = m_DrawingPanel.ClientHeight / 2;
            m_dx       = 0.0;
            m_dy       = 0.0;
            m_DragFlag = false;


            try
            {
                LoadSVG("AltData/SVG/tiger.svg");
            }
            catch (SVGException)
            {
                //TEMP  message(.ToString(e.Message));

                return;
            }
        }