Away3D 4.0 render to a Bitmap

575 views
Skip to first unread message

iiley Chen

unread,
Mar 2, 2011, 5:45:15 AM3/2/11
to Away3D.dev
Hi,

After some experiences, i realize that the Stage3D is under normal
DisplayObjects, but my project need to view the 3D content in front of
them.
I tried to do this:
add a bitmap in front of my other objects.
Then after view.render()
call
Stage3DManager.getInstance(stage).getStage3DProxy(0).context3D.drawToBitmapData(canvas.bitmapData);

But there is no effect.
Any help will be appreciated.

Michael Iv

unread,
Mar 2, 2011, 5:52:21 AM3/2/11
to away3...@googlegroups.com
Hi iiley .You can't bring the content of Stage3D to the front in a regular way because it resides on a different level from stage which is ALWAYS behind it. That is the architecture of Molehill Flash Player.Is there a solution ? I don't know. One thing I can think about is to render the 3d view to a bitmapdata (if it is possible )and then put it at whatever depth you need in the regular stage.
--
Michael Ivanov ,Programmer
Neurotech Solutions Ltd.
Flex|Air |3D|Unity|
www.neurotechresearch.com
http://blog.alladvanced.net
Tel:054-4962254
mic...@neurotech.co.il
te...@neurotech.co.il

Alessandro Bianco

unread,
Mar 2, 2011, 6:14:39 AM3/2/11
to away3...@googlegroups.com, Michael Iv
hi iiley,
i had the same problem yesterday, while i was trying to use Broomstick
for some augmented reality

I solved it by creating a new renderer (BitmapRenderer) wich, after
rendering the content call drawToBitmapData on the Context3d just
before calling the present method.

In this way you can output the backbuffer to a bitmapdata, then i
figured that playing with the threshold method you can make it
transparent.

My solution it's not clean nor beautiful (extending the default
renderer was a bit tricky) so i'm not gonna share the code right now,
but you get the idea i hope :)

Bianco Alessandro

2011/3/2 Michael Iv <explo...@gmail.com>:

iiley Chen

unread,
Mar 2, 2011, 7:24:29 AM3/2/11
to Away3D.dev
Hi Alessandro, i am also very new to Away3D, but your idea make sense,
i will give it a try, hope i can fix it.
Thanks very much.

On 3月2日, 下午7时14分, Alessandro Bianco <cyberpun...@gmail.com> wrote:
> hi iiley,
> i had the same problem yesterday, while i was trying to use Broomstick
> for some augmented reality
>
> I solved it by creating a new renderer (BitmapRenderer) wich, after
> rendering the content call drawToBitmapData on the Context3d just
> before calling the present method.
>
> In this way you can output the backbuffer to a bitmapdata, then i
> figured that playing with the threshold method you can make it
> transparent.
>
> My solution it's not clean nor beautiful (extending the default
> renderer was a bit tricky) so i'm not gonna share the code right now,
> but you get the idea i hope :)
>
> Bianco Alessandro
>
> 2011/3/2 Michael Iv <explomas...@gmail.com>:
>
>
>
>
>
>
>
> > Hi iiley .You can't bring the content of Stage3D to the front in a regular
> > way because it resides on a different level from stage which is ALWAYS
> > behind it. That is the architecture of Molehill Flash Player.Is there a
> > solution ? I don't know. One thing I can think about is to render the 3d
> > view to a bitmapdata (if it is possible )and then put it at whatever depth
> > you need in the regular stage.
>
> > On Wed, Mar 2, 2011 at 12:45 PM, iiley Chen <iiley.c...@gmail.com> wrote:
>
> >> Hi,
>
> >> After some experiences, i realize that the Stage3D is under normal
> >> DisplayObjects, but my project need to view the 3D content in front of
> >> them.
> >> I tried to do this:
> >> add a bitmap in front of my other objects.
> >> Then after view.render()
> >> call
>
> >> Stage3DManager.getInstance(stage).getStage3DProxy(0).context3D.drawToBitmap Data(canvas.bitmapData);
>
> >> But there is no effect.
> >> Any help will be appreciated.
>
> > --
> > Michael Ivanov ,Programmer
> > Neurotech Solutions Ltd.
> > Flex|Air |3D|Unity|
> >www.neurotechresearch.com
> >http://blog.alladvanced.net
> > Tel:054-4962254
> > mich...@neurotech.co.il
> > t...@neurotech.co.il

Jeff

unread,
Apr 27, 2011, 6:38:45 PM4/27/11
to Away3D.dev
Hi all,

I had the same issue to solve, I added a flag ( View3D.as /
DefaultRenderer.as / RendererBase.as ) to disable present method or
not after render

To get the bitmapdata

var bitmapdata:BitmapData = new BitmapData( width, height, true,
0xFF0000 );
view3D.render(false);
view3D.renderer.context.drawToBitmapData(bitmapdata);

Here is the modifications :

********* [ View3D.as ]

Before
public function render() : void
...
context.present();
}
else _renderer.render(_entityCollector, null, 0, 7);
...

After
public function render(present:Boolean = true) : void
...
if (present) context.present();
}
else _renderer.render(_entityCollector, null, 0, 7, present);
...

********* [ DefaultRenderer.as ]

Before
arcane override function render(entityCollector : EntityCollector,
target : TextureBase = null, surfaceSelector : int = 0,
additionalClearMask : int = 7 ) : void
...
super.render(entityCollector, target, surfaceSelector,
additionalClearMask);
...

After
arcane override function render(entityCollector : EntityCollector,
target : TextureBase = null, surfaceSelector : int = 0,
additionalClearMask : int = 7, present:Boolean = true) : void
...
super.render(entityCollector, target, surfaceSelector,
additionalClearMask, present);
...

********* [ RendererBase.as ]

Before
protected function executeRender(entityCollector : EntityCollector,
target : TextureBase = null, surfaceSelector : int = 0,
additionalClearMask : int = 7 ) : void
...
if (_swapBackBuffer && !target ) _context.present();
...

After
protected function executeRender(entityCollector : EntityCollector,
target : TextureBase = null, surfaceSelector : int = 0,
additionalClearMask : int = 7, present: Boolean = true) : void
...
if (_swapBackBuffer && !target && present) _context.present();
...

Regards,

Li

unread,
Apr 27, 2011, 8:35:09 PM4/27/11
to away3...@googlegroups.com
What you are doing should work. Keep in mind that rendering to a bitmapData is much slower than rendering to the screen.

Jeff

unread,
Apr 28, 2011, 2:00:47 AM4/28/11
to Away3D.dev
Indeed, on my case the purpose was to create a scene snapshot.

tomihr

unread,
May 16, 2011, 10:34:28 AM5/16/11
to Away3D.dev
Hello,
can you please post a zipped files, for us not so familiar with Away4D
source,
so I dodn't mess up everithing.

Thanks

Özgür

unread,
May 16, 2011, 11:28:54 AM5/16/11
to away3...@googlegroups.com
ist possible?
with vray or mentalray render motor

2011/5/16 tomihr <tomi...@multi-design.biz>



--
Özgür Çimen
MM Developer & CG Arts
0090 535 766 33 14
http://www.cimenozgur.com/

Reply all
Reply to author
Forward
0 new messages