Updating a skybox’s cubemap

Software: Away3D 4.x

julespong, Member
Posted: 12 July 2011 12:05 AM   Total Posts: 53

So I’ve setup a project where I’m attempting to update a scene’s skybox every frame. I’ve got six animating sprites that I’m taking snapshots of using BitmapData.draw(). I’m then applying those snapshots to a cubemap instance. Then I use that cubemap for my skybox. It seems to work for a few ticks, but then I get a resource exceeded error when I attempt to assign the skybox to my scene.

My assumption is that the scene doesn’t like me adding the skybox every frame. However, there doesn’t seem to be a removeChild call that will actually remove the skybox from a scene.

Can anyone recommend a different approach? Is there another way I can update the skybox?

   

Avatar
theMightyAtom, Sr. Member
Posted: 12 July 2011 05:59 AM   Total Posts: 669   [ # 1 ]

why not update the material?
MyBitmapMaterial.bitmapData = newSnapshot;
And don’t create a new BitmapData every cycle, re-use the same instance.
That should work without you running out of memory smile

   

julespong, Member
Posted: 12 July 2011 05:53 PM   Total Posts: 53   [ # 2 ]

So your opinion is that creating new instances of the BitmapData is what’s causing the error? I’ll go back in and clean that up. I was assuming that the problem was with me continually adding the SkyBox instance. I’ll post my results after I take another crack.

   

julespong, Member
Posted: 12 July 2011 06:07 PM   Total Posts: 53   [ # 3 ]

So it turns out I am using the same references for each of the cubemap’s bitmapdata objects. I’m assuming that’s not where the memory issues are coming from.

You mention that I should update the material on the SkyBox. However, I’m not sure how to go about doing that. I can easily update the materials for the CubeMap instance that the SkyBox uses. But how do I update the SkyBox’s CubeMap? There is no CubeMap getter/setter on the SkyBox object. So again, I think the problem is that I’m generating a new SkyBox instance every frame and trying to add it to the scene. Eventually, I’ll get errors, but only after adding the SkyBox repeatedly. Is there anyway to update the CubeMap of a SkyBox in a scene?

   

Avatar
theMightyAtom, Sr. Member
Posted: 12 July 2011 06:26 PM   Total Posts: 669   [ # 4 ]

try posting ur code. You shouldn’t be making new SkyBoxes either…

   

julespong, Member
Posted: 12 July 2011 07:12 PM   Total Posts: 53   [ # 5 ]

Here is my source (Be gentle I’m an Away3D nublet):

SkyBoxSwapTest.as
http://snipplr.com/view/56502/skyboxswaptestas/

AnimatedCubeMap.as
http://snipplr.com/view/56503/animatedcubemapas/

AnimatedCubeMapFace.as
http://snipplr.com/view/56504/animatedcubemapfaceas/

   

julespong, Member
Posted: 13 July 2011 05:22 PM   Total Posts: 53   [ # 6 ]

Got it. Turns out you can update the CubeMap of a SkyBox.

SkyBoxMaterial(__skyBox.material).cubeMap = __cubeMapRenderer.cubeMap;

   

inSertCodE, Sr. Member
Posted: 20 October 2011 06:13 PM   Total Posts: 105   [ # 7 ]

Hi,
I stumbled across the same problem and couldn’t find the solution. How do you update the cubeMap?

According to what you’ve written it has something to do with the SkyBoxMaterial. But where does the SkyBoxMaterial come in to play?
I create a skybox and upon creation I assign a cubeMap to it, it doesn’t accept SkyBoxMaterial. So where does it come in to play and how to update the new (next) BitmapData on to the cubeMap/skybox?

Even if I’ve connected the SkyBoxMaterial in the whole story I couldn’t find anything like

Thanks.

   

inSertCodE, Sr. Member
Posted: 20 October 2011 06:20 PM   Total Posts: 105   [ # 8 ]

PS. I red you’re line again and I figured out that the __cubeMapRenderer is your temp SkyBoxMaterial right? If that is the case then I only need to know how you connect the SkyBoxMaterial to the cubeMap and/or SkyMap.

   

inSertCodE, Sr. Member
Posted: 23 October 2011 01:00 AM   Total Posts: 105   [ # 9 ]

Ok I figured it out. All the time I was trying combinations which include switching the existing elements of the cubemap instead of declaring a new cubemap each update so that it takes the new BitmapDatas.

   

Rjgtav, Newbie
Posted: 04 August 2012 11:52 PM   Total Posts: 3   [ # 10 ]

Hello
Today I also came accross this problem, with the latest dev build of Away3d Gold available on GitHub.
I’ve already tried replacing the bitmapDatas of the cubeMap references with the new ones but with no success.
I even tried creating every frame a new instance of the cubeMap and update the one from the SkyBoxMaterial but that doesn’t seem to work with the latest build.

The only way I could find that really updated the skybox was by creating a new skyBox and adding it to the scene every frame, but of course that it then lead to the resource exceeded error mentioned on the 1st post.

Is there a bug with the latest build or this feature was removed?

Thanks,
rjgtav

[EDIT]
Well, It looks like I fixed the issue… I had to edit the cubeMap setter from the SkyBoxMaterial class, to mimic the constructor. At the end, it stayed like:

public function set cubeMap(value CubeTextureBase) : void
{
 _cubeMap 
value;
 
_skyboxPass.cubeTexture _cubeMap;//added this line
   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X