Framework / Presentation Layer / Graphics / Appearance Styles / Fill Styles / Texture Mapping Style

In This Topic
    Texture Mapping Style
    In This Topic

    In Nevron Graphics gradients, patterns, advanced gradients and images are treated as textures. Therefore its possible to control how these texture are mapped on the visualized objects. By default you'll not have to directly modify the properties related to texture mapping, because each fill style will automatically assign these properties for you. In certain cases however you may wish to alter the default behavior.

    The properties related to texture mapping are controlled by an instance of the NTextureMappingStyle class. You can assign such an object to every fill style derived from the NTextureFillStyle (gradient, hatch, image and advanced gradient), through its Mapping property:

    C#
    Copy Code
    NTextureMappingStyle newMappingStyle = new NTextureMappingStyle();
    newMappingStyle.MapLayout = MapLayout.Tiled;
    textureFillStyle.TextureMappingStyle = newMappingStyle; 
    
    Visual Basic
    Copy Code
    Dim newMappingStyle As NTextureMappingStyle = New NTextureMappingStyle() 
    newMappingStyle.MapLayout = MapLayout.Tiled
    textureFillStyle.TextureMappingStyle = newMappingStyle
    
     Texture Mapping Mode and Layout

    In a nut shell texture mapping is controlled by the MapLayout and MapMode properties of the NTextureMappingStyle object. There are three mapping modes:

    • MapMode.RelativeToViewer - in this mapping mode the texture coordinates are computed relatively to the viewer and this is why the texture appears to be moving inside the object when you rotate or scale it.
    • MapMode.RelativeToObject - in this mapping mode the texture coordinates are calculated relatively to the object position and this is why the texture mapping does not change when you rotate or move your objects. This is the most common mapping type.
    • MapMode.Sphere - this mapping mode can be used if you want to achieve special visual effects like mirror or reflection, however using it properly requires an appropriate texture. This is why sphere mapping is not described in this tutorial - if you want to use this feature you must have an in-depth understanding of 3D visualization.

    When the mapping mode is set to MapMode.RelativeToObject (which is the default) there are several map layout strategies:

    • MapLayout.Stretched - this mapping layout stretches the texture along the X and Y axes until it fits the object. It does not preserve the original texture dimensions ratio (aspect).
    • MapLayout.Fitted - stretches the texture until it fits along X or Y, by choosing the smaller stretch. This layout mode preserves the texture dimensions ratio (aspect).
    • MapLayout.Centered - similar to fitted. When used on the background object it also preserves the original texture dimensions.
    • MapLayout.Tiled - repeats the texture along the X and Y axes. This layout mode preserves the texture dimensions ratio (aspect).
    • MapLayout.StretchedToWidth - stretches the texture by width until it fits. This layout mode preserves the texture dimensions ratio (aspect).
    • MapLayout.StretchedToHeight - the same as StretchedToWidth except that it stretches along the Y axis. This layout mode preserves the texture dimensions ratio (aspect).
    • MapLayout.CropFitted - stretches the texture until it fits along X or Y by choosing the bigger stretch. This layout mode preserves the texture dimensions ratio (aspect).
     Texture Scaling
    You can also take advantage of the HorizontalScale and VerticalScale properties of the texture mapping style, allowing you to scale the texture along the X and Y direction.
     Example

    The following code example applies a tiled pattern, which is scaled 4 times in both the horizontal and vertical directions:

    C#
    Copy Code
    NHatchFillStyle hatchFillStyle = new NHatchFillStyle(HatchStyle.Divot, Color.White, Color.Blue);
    NTextureMappingStyle mapping = new NTextureMappingStyle(); 
    
    mapping.MapMode = MapMode.RelativeToViewer;
    mapping.MapLayout = MapLayout.Tiled;
    mapping.HorizontalScale = 4.0f;
    mapping.VerticalScale = 4.0f;
    hatchFillStyle.TextureMappingStyle = mapping;
    
    Visual Basic
    Copy Code
    Dim hatchFillStyle As NHatchFillStyle = New NHatchFillStyle(HatchStyle.Divot, Color.White, Color.Blue)
    Dim mapping As NTextureMappingStyle =  New NTextureMappingStyle() 
    
    mapping.MapMode = MapMode.RelativeToViewer
    mapping.MapLayout = MapLay.Tiled
    mapping.HorizontalScale = 4.0F
    mapping.VerticalScale = 4.0F
    hatchFillStyle.TextureMappingStyle = mapping
    
    See Also