Пример #1
0
		/// <summary>Sets the vertices of this box to that specified by the given block
		/// but clipped to fit within a boundary. At the same time, an image is applied
		/// to the block and its UV coordinates are also clipped.</summary>
		/// <param name="boundary">The clipping boundary. The vertices will be clipped to within this.</param>
		/// <param name="block">The position of the vertices.</param>
		/// <param name="renderer">The renderer that will render this block.</param>
		/// <param name="zIndex">The depth of the vertices.</param>
		/// <param name="imgLocation">The location of the image on the meshes atlas.</param>
		public UVBlock SetClipped(BoxRegion boundary,BoxRegion block,Renderman renderer,float zIndex,AtlasLocation imgLocation,UVBlock uvBlock){
			
			// Image defines how big we want the image to be in pixels on the screen.
			// So firstly we need to find the ratio of how scaled our image actually is:
			float originalHeight=block.Height;
			float scaleX=imgLocation.Width/block.Width;
			float scaleY=imgLocation.Height/originalHeight;
			
			// We'll need to clip block and make sure the image block is clipped too:
			float blockX=block.X;
			float blockY=block.Y;
			
			if(block.ClipByChecked(boundary)){
				
				// It actually got clipped - time to do some UV clipping too.
				
				// Apply the verts:
				ApplyVertices(block,renderer,zIndex);
				
				block.X-=blockX;
				block.Y-=blockY;
				block.MaxX-=blockX;
				block.MaxY-=blockY;
				
				// Flip the gaps (the clipped and now 'missing' sections) - UV's are inverted relative to the vertices.
				
				// Bottom gap is just block.Y:
				float bottomGap=block.Y;
				
				// Top gap is the original height - the new maximum; write it to the bottom gap:
				block.Y=originalHeight-block.MaxY;
				
				// Update the top gap:
				block.MaxY=originalHeight-bottomGap;
				
				// Image was in terms of real screen pixels, so now we need to scale it to being in 'actual image' pixels.
				// From there, the region 
				block.X*=scaleX;
				block.MaxX*=scaleX;
				
				block.Y*=scaleY;
				block.MaxY*=scaleY;
				
				if(uvBlock==null || uvBlock.Shared){
					
					// Create the UV block:
					uvBlock=new UVBlock();
					
				}
				
				// Get the new max/min values:
				uvBlock.MinX=imgLocation.GetU(block.X+0.2f);
				uvBlock.MaxX=imgLocation.GetU(block.MaxX-0.2f);
				uvBlock.MaxY=imgLocation.GetV(block.MaxY-0.2f);
				uvBlock.MinY=imgLocation.GetV(block.Y+0.2f);
				
			}else{
				
				// Apply the verts:
				ApplyVertices(block,renderer,zIndex);
				
				// Globally share the UV!
				uvBlock=imgLocation;
				
			}
			
			return uvBlock;
			
		}
Пример #2
0
        /// <summary>Sets the vertices of this box to that specified by the given block
        /// but clipped to fit within a boundary. At the same time, an image is applied
        /// to the block and its UV coordinates are also clipped.</summary>
        /// <param name="boundary">The clipping boundary. The vertices will be clipped to within this.</param>
        /// <param name="block">The position of the vertices.</param>
        /// <param name="renderer">The renderer that will render this block.</param>
        /// <param name="zIndex">The depth of the vertices.</param>
        /// <param name="imgLocation">The location of the image on the meshes atlas.</param>
        public UVBlock SetClipped(BoxRegion boundary, BoxRegion block, Renderman renderer, float zIndex, AtlasLocation imgLocation, UVBlock uvBlock)
        {
            // Image defines how big we want the image to be in pixels on the screen.
            // So firstly we need to find the ratio of how scaled our image actually is:
            float originalHeight = block.Height;
            float scaleX         = imgLocation.Width / block.Width;
            float scaleY         = imgLocation.Height / originalHeight;

            // We'll need to clip block and make sure the image block is clipped too:
            float blockX = block.X;
            float blockY = block.Y;

            if (block.ClipByChecked(boundary))
            {
                // It actually got clipped - time to do some UV clipping too.

                // Apply the verts:
                ApplyVertices(block, renderer, zIndex);

                block.X    -= blockX;
                block.Y    -= blockY;
                block.MaxX -= blockX;
                block.MaxY -= blockY;

                // Flip the gaps (the clipped and now 'missing' sections) - UV's are inverted relative to the vertices.

                // Bottom gap is just block.Y:
                float bottomGap = block.Y;

                // Top gap is the original height - the new maximum; write it to the bottom gap:
                block.Y = originalHeight - block.MaxY;

                // Update the top gap:
                block.MaxY = originalHeight - bottomGap;

                // Image was in terms of real screen pixels, so now we need to scale it to being in 'actual image' pixels.
                // From there, the region
                block.X    *= scaleX;
                block.MaxX *= scaleX;

                block.Y    *= scaleY;
                block.MaxY *= scaleY;

                if (uvBlock == null || uvBlock.Shared)
                {
                    // Create the UV block:
                    uvBlock = new UVBlock();
                }

                // Get the new max/min values:
                uvBlock.MinX = imgLocation.GetU(block.X + 0.2f);
                uvBlock.MaxX = imgLocation.GetU(block.MaxX - 0.2f);
                uvBlock.MaxY = imgLocation.GetV(block.MaxY - 0.2f);
                uvBlock.MinY = imgLocation.GetV(block.Y + 0.2f);
            }
            else
            {
                // Apply the verts:
                ApplyVertices(block, renderer, zIndex);

                // Globally share the UV!
                uvBlock = imgLocation;
            }

            return(uvBlock);
        }