Hello im trying to warp image using nurb mesh. I have some good results, but still need some help.
My first question is how to get image (bitmapData) from nurb plane to bitmap image or movie clip.
Second question : can i apply nurb to simple plane (not with nurb mesh), so i could have irregular nurb points (not in a grid like right now).
package {
import away3d.containers.View3D;
import away3d.events.MouseEvent3D;
import away3d.materials.BitmapMaterial;
import away3d.primitives.NURBS;
import away3d.primitives.data.WeightedVertex;
import flash.display.Bitmap;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.SecurityErrorEvent;
[SWF(backgroundColor="#1a1a1a", frameRate="31", width="870", height="470")]
public class MakeUp extends Sprite {
private var _view : View3D;
private var _material : BitmapMaterial;
private var nurbsMesh:NURBS;
private var controlNet:Array;
private var planeArray:Array = [];
private var mouseDown:Boolean = false;
private var activePlane:int;
private var resultBitmap:Bitmap;
public function MakeUp():void {
onImageReady();
}
private function onLoadError(event : SecurityErrorEvent) : void {
trace(event);
}
private function onImageReady() : void {
try{
_material = new BitmapMaterial(new BMPFox());
createScene();
}catch(e:Error){
trace("ERROR ", e);
}
}
private function createScene() : void {
_view = new View3D();
_view.x = stage.stageHeight / 2;
_view.y = stage.stageHeight / 2;
addChild(_view);
resultBitmap = new Bitmap (new BMPFox());
resultBitmap.x = 500;
addChild(resultBitmap);
createStuff();
addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
private function createStuff():void {
controlNet = getVertexs();
nurbsMesh = new NURBS(controlNet, 20, 20, { name:"xxx", uSegments:10, vSegments:10 });
nurbsMesh.bothsides = true;
nurbsMesh.material = _material;
_view.scene.addChild(nurbsMesh);
_view.scene.addEventListener(MouseEvent3D.MOUSE_UP,mouseOffPlane);
for(var i:int = 0 ; i<controlNet.length;i++){
var _newPlane:ControlPlane = new ControlPlane({x:controlNet[i].x,y:controlNet[i].y,width:10,height:10,rotationX:90});
_newPlane.myId = i;
_newPlane.addEventListener(MouseEvent3D.MOUSE_DOWN,mouseOnPlane);
planeArray[i] = _newPlane;
_view.scene.addChild(_newPlane);
}
}
private function mouseOffPlane(event:MouseEvent3D):void {
mouseDown = false;
}
private function mouseOnPlane(event:MouseEvent3D):void {
mouseDown = true;
activePlane = event.target.myId;
}
private function getVertexs() : Array { // creating nurb grid
var _returnArray:Array = [];
var pos:int = 20;
var step:int = 400 / pos;
for(var y:int = 0;y < pos;y++){
for(var x:int = 0;x < pos;x++){
_returnArray.push(new WeightedVertex( -200 + (x * step), -200 + (y * step), 0, 1));
}
}
return _returnArray;
}
private function onEnterFrame(event : Event) : void {
if(mouseDown){ // for draging planes
planeArray[activePlane].x = _view.mouseX - 20;
planeArray[activePlane].y = _view.mouseY * -1;
nurbsMesh.controlNet[activePlane].x = planeArray[activePlane].x;
nurbsMesh.controlNet[activePlane].y = planeArray[activePlane].y;
}
nurbsMesh.refreshNURBS();
_view.render();
}
}
}