applyTexture derived from ygNode Example Source Header

Description: applies a texture to the existing texture on objects below it

Category: Attributes
Author: Alex Hill
Revision: 07/10/02

restore [bool] reset texture to state before last apply or clean
file file load the given texture file to apply
apply [two floats] apply texture file with optional position
position two floats set position to apply the texture
blend [bool] set the blend mode
threshold [integer] set the blend threshold
clean [bool] set the clean mode

constructor applyTexture

1 distribute the position to apply the texture
2 distribute the name of the texture to apply
3 distribute the mode of texture restore
4 distribute the reset mode
5 distribute the blend mode
6 distribute the blend threshold
7 distribute the clean mode

destructor ~applyTexture

method reset

1 set blend mode to false
2 set threshold to 255
3 set X and Y position to 0.0
4 clear the filename strings
5 initialize source size and components
6 initialize destination size and components
7 set reset mode to false

method message

1 reset texture to state before last apply or clean
2 load the given texture file to apply
3 apply texture file with optional position
4 set position to apply the texture
5 set the blend mode
6 set the blend threshold
7 set the clean mode

method loadFile

1 if filename loaded correctly then
1.1 get image size

method apply

1 if texture has been found and number of components are the same then
1.1 initialize source image data and texture object
1.2 set apply flag to true
1.3 set restore flag to true if clean is true
1.4 set the position and size of the texture to be loaded
1.5 if number of components if 4 and blend flag is true
1.5.1 for each Y element in source image do for each X element in source image do if alpha value is at or above threshold then update source image with corresponding destination image RGB values
1.6 indicate a change in the apply net message

method applyPreDraw

1 retrieve callback data
2 if reset flag is true then
2.1 restore whole destination image
3 if restore flag is true then
3.1 get destination texture image data and width
3.2 if clean is true then restore whole destination image
3.3 esle, restore last position and size
3.4 reset restore flag to false
4 if apply flag is true then
4.1 store destination position and size for later restoration
4.2 apply source texture at given position and size
4.3 applyData->texture->subload(PFTEX_SOURCE_IMAGE,(uint*)applyData->srceImage,applyData->xSrcePos,applyData->ySrcePos,applyData->srceWidth,applyData->xDestPos,applyData->yDestPos,applyData->xSrceSize,applyData->ySrceSize);
4.4 reset apply flag to false

method setChildrenTextures

1 if node type is pfGeode then set geoset textures
1.1 for each geode, call setGeosetTexture
2 else, if node type is pfGroup
2.1 call setChildrenTextures recursively on all children

method setGeosetTexture

1 get the geoset geostate
2 if the geostate has texturing enabled
2.1 set texture node to the geostate texture
2.2 configure the texture to allow subloading
2.3 retrieve the texture image data, size, and number of components

method app

1 if first frame then find a texture node from a child node