Hello all,
I’m working a project that uses Away3D with a 2D Starling layer rendered on top of it and it all works perfectly apart from a strange problem I’m having when the stage is resized.
When Event.RESIZE is triggered, I use Starlings RectangleUtil.fit to find the best fit rect for the stage size. I then set the stage3DProxy position and width to this rectangle and also set Starlings viewport to these coordinates too. I also change the width of the current Away3D view.
protected function onStageResize(e:Event):void
{
// get best fit rect for set stage size and new stage size
var bestRect:Rectangle = RectangleUtil.fit(new Rectangle(0, 0, BBDisplaySettings.stageWidth, BBDisplaySettings.stageHeight), new Rectangle(0, 0, stage.stageWidth, stage.stageHeight), ScaleMode.SHOW_ALL);
// resize Away3D viewport
if (_away3DView)
{
// this code sets the correct 3D View size, but the 3D coordinates //are incorrect. If these 2 lines are commented out, the 2d coordinates are //correct but the 3d view doesn't resize
_away3DView.width = bestRect.width;
_away3DView.height = bestRect.height;
}
// adjust stage3d proxy size
if (_starling)
{
_stage3DProxy.width = bestRect.width;
_stage3DProxy.height = bestRect.height;
_stage3DProxy.x = bestRect.x;
_stage3DProxy.y = bestRect.y;
_starling.viewPort = bestRect;
}
}
On first impression, this seems to work but when I try to project a 3D coordinate to 2D, the position is incorrect. However, if I don’t adjust the view3D size, the position IS correct BUT the view3D instance doesn’t scale to fit the screen and stays the same size in the top left corner.
Can anyone shed any light on this?