Anima2D.SpriteMeshCache.InitFromOutline C# (CSharp) Method

InitFromOutline() public method

public InitFromOutline ( float detail, float alphaTolerance, bool holeDetection, float tessellation, string undoName ) : void
detail float
alphaTolerance float
holeDetection bool
tessellation float
undoName string
return void
		public void InitFromOutline(float detail, float alphaTolerance, bool holeDetection, float tessellation, string undoName)
		{
			Clear(undoName);
			
			float pixelsPerUnit = SpriteMeshUtils.GetSpritePixelsPerUnit(spriteMesh.sprite);
			float factor =  pixelsPerUnit / spriteMesh.sprite.pixelsPerUnit;
			Vector2 position = rect.position / factor;
			Vector2 size = rect.size / factor;
			
			Rect l_rect = new Rect(position.x,position.y,size.x,size.y);
			
			Texture2D texture = SpriteUtility.GetSpriteTexture(spriteMesh.sprite,false);
			Rect clampedRect = MathUtils.ClampRect(MathUtils.OrderMinMax(l_rect),new Rect(0f,0f,texture.width,texture.height));
			
			List<Vector2> l_texcoords;
			List<IndexedEdge> l_indexedEdges;
			List<int> l_indices;
			
			SpriteMeshUtils.InitFromOutline(texture,clampedRect,detail,alphaTolerance,holeDetection, out l_texcoords, out l_indexedEdges, out l_indices);
			SpriteMeshUtils.Tessellate(l_texcoords,l_indexedEdges,holes,l_indices,tessellation * 10f);
			
			nodes = l_texcoords.ConvertAll( v => Node.Create(l_texcoords.IndexOf(v)) );
			edges = l_indexedEdges.ConvertAll( e => Edge.Create(nodes[e.index1], nodes[e.index2]) );
			m_TexVertices = l_texcoords.ConvertAll( v => v * factor );
			boneWeights = l_texcoords.ConvertAll( v => BoneWeight.Create() );
			indices = l_indices;
			
			isDirty = true;

			m_DirtyVertices = true;
		}
		

Usage Example

示例#1
0
        protected override void DoWindow(int windowId)
        {
            EditorGUIUtility.labelWidth = 85f;
            EditorGUIUtility.fieldWidth = 32f;

            detail       = EditorGUILayout.Slider("Outline detail", detail, 0f, 1f);
            alpha        = EditorGUILayout.Slider("Alpha cutout", alpha, 0f, 1f);
            tessellation = EditorGUILayout.Slider("Tessellation", tessellation, 0f, 1f);
            holes        = EditorGUILayout.Toggle("Detect holes", holes);

            EditorGUILayout.BeginHorizontal();

            GUILayout.FlexibleSpace();

            if (GUILayout.Button("Apply", GUILayout.Width(70f)))
            {
                if (spriteMeshCache)
                {
                    spriteMeshCache.InitFromOutline(detail, alpha, holes, tessellation, "set outline");
                }
            }

            GUILayout.FlexibleSpace();

            EditorGUILayout.EndHorizontal();
        }