Package | away3d.materials.utils |
Class | public class NormalBumpMaker |
Inheritance | NormalBumpMaker Object |
Method | Defined By | ||
---|---|---|---|
NormalBumpMaker | |||
addBumpsToNormalMap(normalMapData:BitmapData, bumpMapData:BitmapData, amplitude:Number = 0.05, uRepeat:Boolean = false, vRepeat:Boolean = false):BitmapData
Add bumps to a normal Map. | NormalBumpMaker | ||
convertNormalChannels(sourceData:BitmapData, redSource:uint = 1, greenSource:uint = 2, blueSource:uint = 4, invertRed:Boolean = false, invertGreen:Boolean = false, invertBlue:Boolean = false):BitmapData
Method to change normal directions by 90 or 180 degrees so that, for example, a normal map created for a plane in the
xy plane can be used in an xz plane for which the rotation produces a mapping (x, y, z) -> (x, z, -y)
Quick method: rather than recalculating the normals just modify the red, green and blue channels of the normal map data. | NormalBumpMaker | ||
convertToNormalMap(bumpMapData:BitmapData, geometryFunction:Function = null, amplitude:Number = 0.05, uRepeat:Boolean = false, vRepeat:Boolean = false, coordinates:String = xzy):BitmapData
Function to convert bump map displacements into a normal map
Calculations are performed to calculate the vectors on the original bump map and from these the
normal is obtained. | NormalBumpMaker |
Method | Defined By | ||
---|---|---|---|
setNormal(normalMapData:BitmapData, i:uint, j:uint, normal:Vector3D, coordinates:String):void
Converts the calculated normal vector into RGB values and sets the pixel value. | NormalBumpMaker |
NormalBumpMaker | () | Constructor |
public function NormalBumpMaker()
addBumpsToNormalMap | () | method |
public function addBumpsToNormalMap(normalMapData:BitmapData, bumpMapData:BitmapData, amplitude:Number = 0.05, uRepeat:Boolean = false, vRepeat:Boolean = false):BitmapData
Add bumps to a normal Map. Bumps are initially converted to normal vectors (assuming that they are on a plane originally) and then a rotation is applied to align them with the original normal map data.
Parameters
normalMapData:BitmapData — BitmapData. Original normal map.
| |
bumpMapData:BitmapData — BitmapData. Original bump map.
| |
amplitude:Number (default = 0.05 ) — [optional] Number. Amplitude of bumps. Default is 0.05
| |
uRepeat:Boolean (default = false ) — [optional] Boolean. If the U coordinate should be repeated. Default false;
| |
vRepeat:Boolean (default = false ) — [optional] Boolean. If the V coordinate should be repeated. Default false;
|
BitmapData — BitmapData. Bumps applied to normal map.
|
convertNormalChannels | () | method |
public function convertNormalChannels(sourceData:BitmapData, redSource:uint = 1, greenSource:uint = 2, blueSource:uint = 4, invertRed:Boolean = false, invertGreen:Boolean = false, invertBlue:Boolean = false):BitmapData
Method to change normal directions by 90 or 180 degrees so that, for example, a normal map created for a plane in the xy plane can be used in an xz plane for which the rotation produces a mapping (x, y, z) -> (x, z, -y) Quick method: rather than recalculating the normals just modify the red, green and blue channels of the normal map data. In the above example, the blue channel is copied to the green channel. To account for vector components which are negated we use a inverted bitmap (255 - original value). In the above example we copy the inverted green channel to the blue channel.
Parameters
sourceData:BitmapData — BitmapData. The source bitmapdata;
| |
redSource:uint (default = 1 ) — [optional] uint. The uint representing the red channel. Default is BitmapDataChannel.RED.
| |
greenSource:uint (default = 2 ) — [optional] uint. The uint representing the green channel. Default BitmapDataChannel.GREEN.
| |
blueSource:uint (default = 4 ) — [optional] uint. The uint representing the blue channel. Default BitmapDataChannel.BLUE.
| |
invertRed:Boolean (default = false ) — [optional] Boolean. If the red channel needs to be inverted. Default false.
| |
invertGreen:Boolean (default = false ) — [optional] Boolean. If the green channel needs to be inverted. Default false.
| |
invertBlue:Boolean (default = false ) — [optional] Boolean. If the blue channel needs to be inverted. Default false.
|
BitmapData — A bitmapdata for the rotated normal map
|
convertToNormalMap | () | method |
public function convertToNormalMap(bumpMapData:BitmapData, geometryFunction:Function = null, amplitude:Number = 0.05, uRepeat:Boolean = false, vRepeat:Boolean = false, coordinates:String = xzy):BitmapData
Function to convert bump map displacements into a normal map Calculations are performed to calculate the vectors on the original bump map and from these the normal is obtained. Conversion utility allows for a geometrical function to map from the (u, v) coordinates of the bump map to (x, y, z) coordinates of a particular model. The amplitude of the bump can also be specified with relation to the maximum u and v values of the bumpmap (being equal to 1). If the bump map has repeated boundaries (for example with a sphere or torus) this can be specified as well. By default bump displacements are assumed to be in the "y" direction (for planes) but this can be specifying a coordinate value, for example "xyz" assumes u and v are in the x and y direction, displacements in the z. For example, for a sphere the geometry function would be: public function convertToSpherical(ui:Number, vi:Number, disp:Number):Vector3D { var theta:Number = ui 2 Math.PI; var phi:Number = vi Math.PI; var p:Vector3D = new Vector3D(Math.cos(theta)ath.sin(phi), Math.sin(theta)ath.sin(phi), Math.cos(phi)); var pScaled:Vector3D = new Vector3D(); pScaled.scale(p, 1 + disp); return pScaled; } The call to create a spherical normal map with bump map data having a max amplitude of 0.1, that is repeated along the u direction would be: convertToNormal(bumpMapData, convertToSpherical, 0.1, true, false);
Parameters
bumpMapData:BitmapData — BitmapData. The bitmapdata with the bump information.
| |
geometryFunction:Function (default = null ) — [optional] Function. The geometrical function to apply. Default null.
| |
amplitude:Number (default = 0.05 ) — [optional] Number. The amount of amplitude. Default 0.05.
| |
uRepeat:Boolean (default = false ) — [optional] Boolean. If the U coordinate should be repeated. Default false;
| |
vRepeat:Boolean (default = false ) — [optional] Boolean. If the V coordinate should be repeated. Default false;
| |
coordinates:String (default = xzy ) — [optional] String. Decides how pixel colours should be ordered. Default "xzy";
|
BitmapData — A bitmapdata
|
setNormal | () | method |
protected function setNormal(normalMapData:BitmapData, i:uint, j:uint, normal:Vector3D, coordinates:String):void
Converts the calculated normal vector into RGB values and sets the pixel value. Takes into account different coordinate systems. For example "xyz" is traditional left-handed coordinate system "xzy" is a righthanded coordinate system (such as in Away3D) For a bump map on a plane, the first two axes are the u-v coordinates, the last being the displacement direction
Parameters
normalMapData:BitmapData — BitmapData. The normalmap bitmapdata;
| |
i:uint — uint. pixel x position
| |
j:uint — uint. pixel y position
| |
normal:Vector3D — Vector3D. Calculated normal vector
| |
coordinates:String — String. Decides how pixel colours should be ordered
|