Hello kids. Not too much action here – but training these stubborn animals is above all an excercise in patience and a way of meditation. As such it is no wonder that monks of Nga Phe Kyaung monastery in Burma devoted their lives to perfecting this laborious art.
Click the pic and go practice.
Click here to open in a new window.
Displacement map filter is a nice but hardly ever used flash feature. Sure it tends to be a bit CPU nasty, but the other problem is that getting a useful map other than a perlin noise or simple lens is a bit of pain in the back. I was getting down to writing a simple displacement editor in Flash, when I realized that Photoshop Liquify tool works very similar and it even allows you to save the output in a binary mesh file (.msh).
Now the only problem was making sense of the .msh format, which after a bit of toying with different simple meshes and peeping into hex editor turned out to be a rather simple array of x,y displacement values arranged row by row. ith this knowledge I was able to load msh into flash and generate BitmapData which I could use as input for DisplacementMapFilter.
Below is a simple practical joke using directly the .msh file and Gerda for demonstration purposes. It’s not very practical because .msh gets rather big fast (1,8 MB here). For real tasks it’s better to printscreen the bitmap and save it as a png for later use. Anyway, move your mouse to the center to see the original picture. In the lower right corner you’ll find the original Liquify effect and everywhere else the combination of different x, y scaling of the filter.
Click on image to open example (almost 2MB – may take a while ):
In the source files you’ll find a MSHLoader class, which loads .msh and converts it into bitmapdata. The usage should be mostly self-explanatory. The ‘scaling’ property is the value you put into scaleX nad scaleY properties of DisplacementMapFilter to get the deformation identical to the one in Photoshop. The componentX and componentY paramters in loadMSH () method are the 1, 2, 4, 8 color channel codes (they MUST be different for both channels) set to red and green by default. They work exactly as componentX, componentY parameters in the filter.