07.12.2012 Views

Adobe Director Basics

Adobe Director Basics

Adobe Director Basics

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

ADOBE DIRECTOR BASICS<br />

3D: Controlling appearance<br />

Using a Bitmap member also gives you a simple way to define the origin point for the mesh resource: you can use the<br />

member.regPoint of the Bitmap member. A Bitmap member has a width and a height, measured in pixels. A bitmap<br />

of n x m pixels generates a rectangular terrain of (n - 1) columns and (m - 1) rows. Each pixel can store one of 256<br />

different values, from 0 to 255. To convert these numbers into world unit dimensions, you need to apply a different<br />

scale to each axis.<br />

Here is a handler that you can use to find what scale to use for each axis. It returns a list containing three floating-point<br />

values, in the format [, , ].<br />

-- Lingo syntax<br />

on GetScale(aBitmap, xUnits, yUnits, zUnits)<br />

vColumns = float(aBitmap.width - 1)<br />

vRows = float(aBitmap.height - 1)<br />

vScale = []<br />

vScale.append(xUnits / vColumns)<br />

vScale.append(yUnits / 255.0)<br />

vScale.append(zUnits / vRows)<br />

return vScale<br />

end GetScale<br />

Example usage:<br />

vScaleList = GetScale(member "HeightMap", 100, 39, 64)<br />

put vScaleList<br />

-- [6.6667, 0.1529, 3.3684]<br />

You can now use the Bitmap's grayscale image data, its regPoint, and the scale list that you have just created to generate<br />

a series of vertex points.<br />

on GetVertexListFromBitmap(aBitmap, aScale)<br />

vVertexList = []<br />

vScaleX = aScale[1]<br />

vScaleY = aScale[2]<br />

vScaleZ = aScale[3]<br />

vImage = aBitmap.image<br />

vColumns = vImage.width - 1<br />

vRows = vImage.height - 1<br />

vRegPoint = aBitmap.regPoint<br />

vOffsetX = vRegPoint.locH * vColumns / float(vColumns + 1)<br />

vOffsetZ = vRegPoint.locV * vRows / float(vRows + 1)<br />

repeat with zz = 0 to vRows<br />

repeat with xx = 0 to vColumns<br />

vX = (xx - vOffsetX) * vScaleX<br />

vPixel = vImage.getPixel(xx, zz).red<br />

vY = vPixel * vScaleY<br />

vZ = (zz - vOffsetZ) * vScaleZ<br />

vVector = vector(vX, vY, vZ)<br />

vVertexList.append(vVector)<br />

end repeat<br />

end repeat<br />

return vVertexList<br />

end GetVertexListFromBitmap<br />

Below is the output generated by a Bitmap member named “3x3” that displays 8 black pixels in a square around a<br />

central white pixel. The member's regPoint is at point(3, 0), on the top right edge of the black square. The scale has<br />

been chosen to create a mesh resource that will be 20 units wide along the xAxis and 30 units along the zAxis. The<br />

maximum height of the terrain will be 20 units. The output has been edited and arranged neatly in columns, so that<br />

you can see that the height of the eight outer vertices is 0 and the height of the central vertex is 10.<br />

Last updated 8/26/2011<br />

178

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!