应用了rotationY的MovieClip的BitmapData问题

时间:2013-10-10 16:25:57

标签: actionscript-3 flash rotation bitmapdata

所以我现在有一个简单的文件,最终将采用一个movieclip并将其保存为图像。我目前正在将剪辑的y旋转45°,以使其具有3D外观并将其添加回舞台。我尝试过谷歌搜索和一些不同的东西,但我不能让它工作。我尝试的第一件事是获取我旋转的动画片段的BitmapData。这使得剪辑变平了:

test_mc.response_mc.rotationY = 45;
var mc:MovieClip = test_mc.response_mc;
var bmp:BitmapData = new BitmapData(mc.width, mc.height);
bmp.draw(mc);

var output:Bitmap = new Bitmap(bmp);
output.x = 270;
output.y = 191;

addChild(output);

我接下来要做的就是获取父剪辑的BD。这给了它一个角度......只是错误的一个:

(same code as above with this line change)
var mc:MovieClip = test_mc;

这里的任何想法都会很好。我尝试用矩阵做事,但没有运气。我也有图像...只是不能发布它们:(

我尝试过的其他没有运气的东西:

var target:DisplayObject = test_mc as DisplayObject;
var targetTransform:Matrix = target.transform.concatenatedMatrix;
var targetGlobalBounds:Rectangle = target.getBounds(target.stage);
var targetGlobalPos:Point = target.localToGlobal(new Point());
var targetOriginOffset:Point = new Point(targetGlobalPos.x - targetGlobalBounds.left, targetGlobalPos.y - targetGlobalBounds.top);

targetTransform.tx = targetOriginOffset.x;
targetTransform.ty = targetOriginOffset.y;

var cloneData:BitmapData = new BitmapData(targetGlobalBounds.width, targetGlobalBounds.height, true, 0x00000000);
cloneData.draw(target, targetTransform);

var output:Bitmap = new Bitmap(cloneData);

**另一次更新** 所以希望这会有所帮助。我能够使用Matrix3D重新创建我正在做的事情。

test_mc.response_mc.rotationY = 45;

var matrix:Matrix3D = new Matrix3D();
matrix.prependRotation(45, Vector3D.Y_AXIS);
test2_mc.response_mc.transform.matrix3D = matrix;
test2_mc.response_mc.transform.matrix3D.appendTranslation(0, 0, 0);

我已经接近让位图看起来正确(感谢Mike Chambers的博客)。

var mcOffset:Matrix3D = test2_mc.response_mc.transform.matrix3D;
var rawMatrixData:Vector.<Number> = mcOffset.rawData;
var globalBounds:Rectangle = test2_mc.response_mc.getBounds(test2_mc);

var matrix:Matrix = new Matrix();
matrix.a = rawMatrixData[0];
matrix.c = rawMatrixData[1];
matrix.tx = test2_mc.response_mc.x - globalBounds.x;

matrix.b = rawMatrixData[4];
matrix.d = rawMatrixData[5];
matrix.ty = test2_mc.response_mc.y - globalBounds.y;

var bmp:BitmapData = new BitmapData(150, test2_mc.height);
test2_mc.response_mc.transform.matrix3D = null;
bmp.draw(test2_mc.response_mc, matrix);
test2_mc.response_mc.transform.matrix3D = mcOffset;

var output:Bitmap = new Bitmap(bmp);

1 个答案:

答案 0 :(得分:0)

嗯,我又向后退了一步,然后走上舞台。无论出于何种原因,尝试绘制旋转的影片剪辑(response_mc)的父(test_mc)都不起作用,但是绘制舞台并将边界设置为父DOES工作区域。这是我的代码(遗憾的是非常简单):

var bmp:BitmapData = new BitmapData(test_mc.width, test_mc.height);
bmp.draw(stage.getChildAt(0), new Matrix(1, 0, 0, 1, -test_mc.x, -test_mc.y));
var output:Bitmap = new Bitmap(bmp);