{{tag>dragonscript behavior}}
[[:start|Start Page]] >> [[main|DragonScript Scripting Language]] >> [[abstractions#behavior_elementsquick_and_easy_development|Behavior Elements: Quick and Easy Development]] >> **ECBehaviorRenderableCustomColor**
* [[behaviors_use_cases|Behaviors Explained: By Use-Case]]
* [[behaviors_a_to_z|Behaviors Explained: From A to Z]]
====== ECBehaviorRenderableCustomColor ======
{{youtube>Gte74Jte8A0?medium}}
Behavior in action
Behavior element behavior using [[behavior_customcolor|ECBehaviorCustomColor]] on [[behavior_dynamicskin|ECBehaviorDynamicSkin]]. This behavior applies the chosen color of an [[behavior_customcolor|ECBehaviorCustomColor]] either directly to a color type [[gamedev:renderables|renderable]] or indirectly to a canvas type [[gamedev:renderables|renderable]].
This behavior differs from using [[gamedev:textureproperties:color_tint|color.tint]] texture property. The [[gamedev:textureproperties:color_tint|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 [[behavior_renderablecanvas|ECBehaviorRenderableCanvas]] is provided a color type [[gamedev:renderables|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 [[behavior_renderablecanvas|ECBehaviorRenderableCanvas]] is provided a [[gamedev:canvassystem:image|canvas image]] is added to the [[gamedev:canvassystem:view|canvas view]]. The color transform of the [[gamedev:canvassystem:image|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 [[behavior_customcolor|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 [[behavior_renderablecustomcolor|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 [[behavior_renderablecanvas|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 [[gamedev:renderables|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 [[gamedev:renderables|renderable]] in the component skin to modify. This is used for the Multi Texture Mode. Requires a [[behavior_dynamicskin|ECBehaviorDynamicSkin]] assigned to the ECBehaviorRenderableCustomColor.
* Full name: "renderableCustomColor.renderable" or "renderableCustomColor(id).renderable"
* Type: string
* Default Value: "" (empty string)
* Example (*.deeclass): skin
===== image =====
Image to use for Single Texture Mode. Requires a [[behavior_renderablecanvas||ECBehaviorRenderableCanvas]] assigned to the ECBehaviorRenderableCustomColor. Image can be grayscale for flat mode or grayscale with alpha channel for colorized mode.
* Full name: "renderableCustomColor.image" or "renderableCustomColor(id).image"
* Type: string (path to image resource)
* Default value: empty string
* Example (*.deeclass): /content/model/player/colorBodyMask.png
====== Required Behaviors ======
* [[behavior_customcolor|ECBehaviorCustomColor]] for both modes
* [[behavior_dynamicskin|ECBehaviorDynamicSkin]] for Multi Texture Mode
* [[behavior_renderablecanvas|ECBehaviorRenderableCanvas]] for Single Texture Mode
====== Optional Behaviors ======
This behavior does not support optional behaviors.
====== Persistency ======
This behavior does not use persistency.
====== API Documentation ======
#@LinkApiDocDEDS2_HTML~classDragengine_1_1Scenery_1_1ECBehaviorRenderablePanel.html,ECBehaviorRenderablePanel~@#.
Since DragonScript Module Version **1.3**
====== Use Cases ======
* Apply custom colors chosen by player to his player actor.
====== 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 ======
* [[https://github.com/LordOfDragons/deexamples|DEExamples Repository]]: Element class adding 5 custom color slots to a box model. Player can interact with box to bring up a dialog to change the colors.
* [[https://github.com/LordOfDragons/deexamples/blob/master/exampleApp/data/scripts/CustomColorExampleClass.ds|CustomColorExampleClass.ds]]. Element class using 5 color slots
* [[https://github.com/LordOfDragons/deexamples/blob/master/exampleApp/data/scripts/PlayerActionCustomColor.ds|PlayerActionCustomColor.ds]]. Player action showing dialog to select color.
* [[https://github.com/LordOfDragons/deexamples/tree/master/exampleApp/data/content/models/customColor|customColor]]. Directory containing images to define the locations on the skin where each individual color applies to.