Table of Contents

,

Start Page » DragonScript Scripting Language » Behavior Elements: Quick and Easy Development » ECBehaviorRenderableCustomColor

ECBehaviorRenderableCustomColor

Behavior in action

Behavior element behavior using ECBehaviorCustomColor on ECBehaviorDynamicSkin. This behavior applies the chosen color of an ECBehaviorCustomColor either directly to a color type renderable or indirectly to a canvas type renderable.

This behavior differs from using color.tint texture property. The color.tint texture property colorizes one texture of an object and thus requires models to be split up into individual parts assigned to individual textures. The Single Texture Mode outlined below works similar to this texture property. This behavior though allows to colorize individual pixels of a single texture. Think of adding a tribal tattoo to an actor you would like to colorize independent of the skin tone.

Multi Texture Mode (Using Color Type Renderable

If no ECBehaviorRenderableCanvas is provided a color type renderable is created and the chosen collor assigned to it.

This mode of operation is best used for models using individual textures for each part to colorize. This is the fastest solution.

Single Texture Mode (Using [[behavior_renderablecanvas|ECBehaviorRenderableCanvas]])

If ECBehaviorRenderableCanvas is provided a canvas image is added to the canvas view. The color transform of the canvas image is set to the chosen color.

This mode of operation is best used for models with a single texture to colorized in a pixel-precise way. Multiple ECBehaviorCustomColor can then affect the same model texture each colorizing a precisely defined area of the texture.

The image has to be a grayscale image with optional alpha channel. Typically the image contains black-and-white pixels to enable or disable colorizing for in individual image parts but can be full grayscale to apply blending of chosen color. If the image also contains an alpha channel then the grayscale content of the image is multiplied by the color with the alpha channel defining how much the final color affects the result. Hence grayscale image without alpha channel apply flat colorization while grayscale images with alpha channel applied shaded colorization.

The order of adding ECBehaviorRenderableCustomColor to element classes is important. Behaviors added later are layered on top of behaviors added earlier. This is especially useful for blending custom colors to get good results.

It is recommended to set the background color or image of ECBehaviorRenderableCanvas. This ensures all pixels in the texture are properly set.

The advantage of using this mode is that you can layer any number of custom colors onto a texture easily.

The disadvantage is that graphic modules have to render the renderable from the canvas view before it can be used for rendering the component. If many elements use this kind of colorizing the GPU memory consumption can be high. Graphic modules know about this and can release dynamic texture content. Nevertheless it is good to keep this in mind.

Instance Counts

This behavior can be used multiple times on an element to add multiple custom colors affecting the element. Use the behavior identifier to tell them apart.

Element Class Properties

Element class properties have the prefix renderableCustomColor. or renderableCustomColor(id). if id is not empty.

renderable

Name of the renderable in the component skin to modify. This is used for the Multi Texture Mode. Requires a ECBehaviorDynamicSkin assigned to the ECBehaviorRenderableCustomColor.

image

Image to use for Single Texture Mode. Requires a |ECBehaviorRenderableCanvas assigned to the ECBehaviorRenderableCustomColor. Image can be grayscale for flat mode or grayscale with alpha channel for colorized mode.

Required Behaviors

Optional Behaviors

This behavior does not support optional behaviors.

Persistency

This behavior does not use persistency.

API Documentation

ECBehaviorRenderablePanel.

Since DragonScript Module Version 1.3

Use Cases

Element Class Example

The following example creates an element class with two custom colors each affecting an individual skin texture:

class MyElement extends BehaviorElementClass
  public func new()
    var ECBehaviorComponent component = ECBehaviorComponent.new(this)
    var ECBehaviorDynamicSkin dynamicSkin = ECBehaviorDynamicSkin.new(this, component)
    
    // Add first color tinting texture named "texture1"
    var ECBehaviorCustomColor color1 = ECBehaviorCustomColor.new(this, "color1", "Color 1", Color.blue)
    ECBehaviorRenderableCustomColor.new(this, "color1", color1, dynamicSkin, "texture1" )
    
    // Add second color tinting texture named "texture2"
    var ECBehaviorCustomColor color2 = ECBehaviorCustomColor.new(this, "color2", "Color 2", Color.red)
    ECBehaviorRenderableCustomColor.new(this, "color2", color2, dynamicSkin, "texture2" )
  end
end

The following example creates an element class with two custom colors each applying one layer of tint to a texture with:

class MyElement extends BehaviorElementClass
  public func new()
    var ECBehaviorComponent component = ECBehaviorComponent.new(this)
    var ECBehaviorDynamicSkin dynamicSkin = ECBehaviorDynamicSkin.new(this, component)
    
    // Add renderable canvas for texture named "texture"
    var ECBehaviorRenderableCanvas renderable = ECBehaviorRenderableCanvas.new(this, dynamicSkin)
    renderable.getRenderable().setValue("texture")
    
    // The background color is set to white which applies no tinting. Hence by default
    // the texture is not tinted unless any custom color is not white
    renderable.getBackgroundColor().setColor(Color.white)
    
    // Set the size of the renderable. This size usually matches the size of the mask
    images assigned to the custom colors
    renderable.getSize().setPoint(Point.new(512, 512))
    
    // Add first color
    var ECBehaviorCustomColor color1 = ECBehaviorCustomColor.new(this, "color1", "Color 1", Color.blue)
    ECBehaviorRenderableCustomColor.new(this, "color1", color1, renderable )
    
    // Add second color
    var ECBehaviorCustomColor color2 = ECBehaviorCustomColor.new(this, "color2", "Color 2", Color.red)
    ECBehaviorRenderableCustomColor.new(this, "color2", color2, renderable )
  end
end

Live Examples