Exemple #1
0
 public static void Clip(IList <Plane> planes, dfRenderData source, dfRenderData dest)
 {
     dest.EnsureCapacity(dest.Vertices.Count + source.Vertices.Count);
     for (int i = 0; i < source.Triangles.Count; i += 3)
     {
         for (int j = 0; j < 3; j++)
         {
             int num3 = source.Triangles[i + j];
             dfClippingUtil.clipSource[0].corner[j] = source.Transform.MultiplyPoint(source.Vertices[num3]);
             dfClippingUtil.clipSource[0].uv[j]     = source.UV[num3];
             dfClippingUtil.clipSource[0].color[j]  = source.Colors[num3];
         }
         int count = 1;
         for (int k = 0; k < planes.Count; k++)
         {
             count = clipToPlane(planes[k], dfClippingUtil.clipSource, clipDest, count);
             ClipTriangle[] clipSource = dfClippingUtil.clipSource;
             dfClippingUtil.clipSource = clipDest;
             clipDest = clipSource;
         }
         for (int m = 0; m < count; m++)
         {
             dfClippingUtil.clipSource[m].CopyTo(dest);
         }
     }
 }
Exemple #2
0
 public static void Clip(IList <Plane> planes, dfRenderData source, dfRenderData dest)
 {
     dest.EnsureCapacity(dest.Vertices.Count + source.Vertices.Count);
     for (int i = 0; i < source.Triangles.Count; i = i + 3)
     {
         for (int j = 0; j < 3; j++)
         {
             int       item      = source.Triangles[i + j];
             Matrix4x4 transform = source.Transform;
             dfClippingUtil.clipSource[0].corner[j] = transform.MultiplyPoint(source.Vertices[item]);
             dfClippingUtil.clipSource[0].uv[j]     = source.UV[item];
             dfClippingUtil.clipSource[0].color[j]  = source.Colors[item];
         }
         int plane = 1;
         for (int k = 0; k < planes.Count; k++)
         {
             plane = dfClippingUtil.clipToPlane(planes[k], dfClippingUtil.clipSource, dfClippingUtil.clipDest, plane);
             dfClippingUtil.ClipTriangle[] clipTriangleArray = dfClippingUtil.clipSource;
             dfClippingUtil.clipSource = dfClippingUtil.clipDest;
             dfClippingUtil.clipDest   = clipTriangleArray;
         }
         for (int l = 0; l < plane; l++)
         {
             dfClippingUtil.clipSource[l].CopyTo(dest);
         }
     }
 }
Exemple #3
0
 public static void Clip(IList<Plane> planes, dfRenderData source, dfRenderData dest)
 {
     dest.EnsureCapacity(dest.Vertices.Count + source.Vertices.Count);
     for (int i = 0; i < source.Triangles.Count; i = i + 3)
     {
         for (int j = 0; j < 3; j++)
         {
             int item = source.Triangles[i + j];
             Matrix4x4 transform = source.Transform;
             dfClippingUtil.clipSource[0].corner[j] = transform.MultiplyPoint(source.Vertices[item]);
             dfClippingUtil.clipSource[0].uv[j] = source.UV[item];
             dfClippingUtil.clipSource[0].color[j] = source.Colors[item];
         }
         int plane = 1;
         for (int k = 0; k < planes.Count; k++)
         {
             plane = dfClippingUtil.clipToPlane(planes[k], dfClippingUtil.clipSource, dfClippingUtil.clipDest, plane);
             dfClippingUtil.ClipTriangle[] clipTriangleArray = dfClippingUtil.clipSource;
             dfClippingUtil.clipSource = dfClippingUtil.clipDest;
             dfClippingUtil.clipDest = clipTriangleArray;
         }
         for (int l = 0; l < plane; l++)
         {
             dfClippingUtil.clipSource[l].CopyTo(dest);
         }
     }
 }
        /// <summary>
        /// Render the given text as mesh data to the given destination buffer
        /// </summary>
        /// <param name="text">The text to be rendered</param>
        /// <param name="destination">The dfRenderData buffer that will hold the
        /// text mesh information</param>
        public override void Render(string text, dfRenderData destination)
        {
            //@Profiler.BeginSample( "Render dynamic font text" );

            textColors.Clear();
            textColors.Push(Color.white);

            // Ensure that the required characters can be found in the dynamic font's
            // character data.
            var font     = (dfDynamicFont)Font;
            var fontSize = Mathf.CeilToInt(font.FontSize * TextScale);

            font.RequestCharacters(text, fontSize, FontStyle.Normal);

            tokenize(text);
            var lines = calculateLinebreaks();

            destination.EnsureCapacity(getAnticipatedVertCount(tokens));

            var maxWidth  = 0;
            var maxHeight = 0;

            var position = (VectorOffset / PixelRatio).CeilToInt();

            for (int i = 0; i < lines.Count; i++)
            {
                var line             = lines[i];
                var lineStartIndex   = destination.Vertices.Count;
                var spriteStartIndex = (SpriteBuffer != null) ? SpriteBuffer.Vertices.Count : 0;

                renderLine(lines[i], textColors, position, destination);

                position.y -= line.lineHeight;

                maxWidth   = Mathf.Max((int)line.lineWidth, maxWidth);
                maxHeight += Mathf.CeilToInt(line.lineHeight);

                if (line.lineWidth > MaxSize.x)
                {
                    clipRight(destination, lineStartIndex);
                    clipRight(SpriteBuffer, spriteStartIndex);
                }

                clipBottom(destination, lineStartIndex);
                clipBottom(SpriteBuffer, spriteStartIndex);
            }

            this.RenderedSize = new Vector2(
                Mathf.Min(MaxSize.x, maxWidth),
                Mathf.Min(MaxSize.y, maxHeight)
                ) * TextScale;

            this.tokens.Release();
            this.tokens = null;

            //@Profiler.EndSample();
        }
	/// <summary>
	/// Clips a <see cref="dfRenderData"/> instance containing control rendering data
	/// against a list of <see cref="Plane"/> objects defined by the current clipping 
	/// region, and outputs the clipped data into <paramref name="dest"/>
	/// </summary>
	/// <param name="planes">The list of planes to clip against</param>
	/// <param name="source">The control rendering data to be clipped</param>
	/// <param name="dest">The output buffer that will hold the resulting clipped data</param>
	public static void Clip( IList<Plane> planes, dfRenderData source, dfRenderData dest )
	{

		dest.EnsureCapacity( dest.Vertices.Count + source.Vertices.Count );

		var triangleCount = source.Triangles.Count;
		var vertices = source.Vertices.Items;
		var triangles = source.Triangles.Items;
		var uvs = source.UV.Items;
		var colors = source.Colors.Items;
		var transform = source.Transform;

		var planeCount = planes.Count;

		for( int sourceIndex = 0; sourceIndex < triangleCount; sourceIndex += 3 )
		{

			for( int i = 0; i < 3; i++ )
			{

				var index = triangles[ sourceIndex + i ];

				clipSource[ 0 ].corner[ i ] = transform.MultiplyPoint( vertices[ index ] );
				clipSource[ 0 ].uv[ i ] = uvs[ index ];
				clipSource[ 0 ].color[ i ] = colors[ index ];

			}

			var count = 1;
			for( int planeIndex = 0; planeIndex < planeCount; planeIndex++ )
			{

				var clipPlane = planes[ planeIndex ];
				count = clipToPlane( ref clipPlane, clipSource, clipDest, count );

				var temp = clipSource;
				clipSource = clipDest;
				clipDest = temp;

			}

			for( int i = 0; i < count; i++ )
			{
				clipSource[ i ].CopyTo( dest );
			}

		}

	}
    /// <summary>
    /// Clips a <see cref="dfRenderData"/> instance containing control rendering data
    /// against a list of <see cref="Plane"/> objects defined by the current clipping
    /// region, and outputs the clipped data into <paramref name="dest"/>
    /// </summary>
    /// <param name="planes">The list of planes to clip against</param>
    /// <param name="source">The control rendering data to be clipped</param>
    /// <param name="dest">The output buffer that will hold the resulting clipped data</param>
    public static void Clip(IList <Plane> planes, dfRenderData source, dfRenderData dest)
    {
        dest.EnsureCapacity(dest.Vertices.Count + source.Vertices.Count);

        var triangleCount = source.Triangles.Count;
        var vertices      = source.Vertices.Items;
        var triangles     = source.Triangles.Items;
        var uvs           = source.UV.Items;
        var colors        = source.Colors.Items;
        var transform     = source.Transform;

        var planeCount = planes.Count;

        for (int sourceIndex = 0; sourceIndex < triangleCount; sourceIndex += 3)
        {
            for (int i = 0; i < 3; i++)
            {
                var index = triangles[sourceIndex + i];

                clipSource[0].corner[i] = transform.MultiplyPoint(vertices[index]);
                clipSource[0].uv[i]     = uvs[index];
                clipSource[0].color[i]  = colors[index];
            }

            var count = 1;
            for (int planeIndex = 0; planeIndex < planeCount; planeIndex++)
            {
                var clipPlane = planes[planeIndex];
                count = clipToPlane(ref clipPlane, clipSource, clipDest, count);

                var temp = clipSource;
                clipSource = clipDest;
                clipDest   = temp;
            }

            for (int i = 0; i < count; i++)
            {
                clipSource[i].CopyTo(dest);
            }
        }
    }
		/// <summary>
		/// Render the given text as mesh data to the given destination buffer
		/// </summary>
		/// <param name="text">The text to be rendered</param>
		/// <param name="destination">The dfRenderData buffer that will hold the 
		/// text mesh information</param>
		public override void Render( string text, dfRenderData destination )
		{

			//@Profiler.BeginSample( "Render dynamic font text" );

			textColors.Clear();
			textColors.Push( Color.white );

			// Ensure that the required characters can be found in the dynamic font's
			// character data.
			var font = (dfDynamicFont)Font;
			var fontSize = Mathf.CeilToInt( font.FontSize * TextScale );
			font.RequestCharacters( text, fontSize, FontStyle.Normal );

			tokenize( text );
			var lines = calculateLinebreaks();

			destination.EnsureCapacity( getAnticipatedVertCount( tokens ) );

			var maxWidth = 0;
			var maxHeight = 0;

			var position = ( VectorOffset / PixelRatio ).CeilToInt();

			for( int i = 0; i < lines.Count; i++ )
			{

				var line = lines[ i ];
				var lineStartIndex = destination.Vertices.Count;
				var spriteStartIndex = ( SpriteBuffer != null ) ? SpriteBuffer.Vertices.Count : 0;

				renderLine( lines[ i ], textColors, position, destination );

				position.y -= line.lineHeight;

				maxWidth = Mathf.Max( (int)line.lineWidth, maxWidth );
				maxHeight += Mathf.CeilToInt( line.lineHeight );

				if( line.lineWidth > MaxSize.x )
				{
					clipRight( destination, lineStartIndex );
					clipRight( SpriteBuffer, spriteStartIndex );
				}

				clipBottom( destination, lineStartIndex );
				clipBottom( SpriteBuffer, spriteStartIndex );

			}

			this.RenderedSize = new Vector2(
				Mathf.Min( MaxSize.x, maxWidth ),
				Mathf.Min( MaxSize.y, maxHeight )
			) * TextScale;

			this.tokens.Release();
			this.tokens = null;

			//@Profiler.EndSample();

		}