Author Topic: Trouble creating texture from camera feed  (Read 179 times)

Ryan Schaefer   «   on: July 25, 2012, 12:07:03 PM »
We've got a project at work that is utilizing Flare3d with a webcam feed.  It runs well enough for a few hours, but then we always get the following error:

 Error #3691: Resource limit for this resource type exceeded.
    at flash.display3D::Context3D/createTexture()
    at flare.core::Texture3D/uploadWithMipmaps()
    at flare.core::Texture3D/upload()

This seems reasonable enough.  We are creating a texture every frame so I'm not too surprised we're seeing this.  My question is: how can we avoid this issue?  I've tried calling dispose on the texture, but that makes it unusable again.  I've also tried setting the bitmapData property directly instead of recreating the texture3d object new every frame, but that didn't seem to work either.  Any ideas?  Below is the snippet of code that's causing the issue.

cameraFeed = new Texture3D(cam.videoFeed, true);
cameraFeed.mipMode = Texture3D.MIP_NONE;
tFilter = new TextureFilter( cameraFeed );
bgMat = new Shader3D("bgMat");
bg = bgModel.getMaterialByName("bgMat") as Shader3D;
bgMat.filters.push( tFilter );
bgMat.build();
bgModel.replaceMaterial(bg, bgMat);

tim b   «   Reply #1 on: July 25, 2012, 05:14:52 PM »
Hi, I had the same issue recently.  I'll post the code I ended up using
in my UpdateEvent function in case that helps.  Basically the solution I
 found was as follows:  I created a blank BitmapData and a blank
TextureFilter as follows:





public var blank_bmp:BitmapData = new BitmapData(floor_width,floor_length,false,0xffffffff)


public var t3d:Texture3D = new Texture3D(null)


public var tf:TextureFilter = new TextureFilter(t3d)





Then at the start of the UpdateEvent, I did the following:





private function updateEvent(e:Event):void


        {        


            shader.filters[0] = blank_tf


            t3d.bitmapData = blank_bmp





        // now it's safe to dispose the previous Texture3D


            t3d.dispose()





        // now I recreate the Texture3D


        t3d = new Texture3D(canvas)


            tf = new TextureFilter(t3d)


            //shader = new Shader3D("base")


            shader.filters[0] = tf


            shader.build()


            plane.setMaterial(shader)


           


...





Anyway, this worked and made it possible to render a new bitmap texture
every frame without running out of memory after 10-20 seconds.  You can
see the whole code <a
href="http://timbudds.info/bitmap/bitmap3d.as">here[/url] if it
helps and <a
href=http://timbudds.info/bitmap/Bitmap%20Scroll.html>here[/url]
is what I ended up making (just for fun, playing with something I found
on the Plastic Sturgeon website).

tim b   «   Reply #2 on: July 25, 2012, 05:15:31 PM »
uh html fail, oh well whatever

Ryan Schaefer   «   Reply #3 on: July 25, 2012, 06:24:35 PM »
Cool, I'll give that a shot.  Thanks!

Ryan Schaefer   «   Reply #4 on: July 27, 2012, 03:50:46 PM »
Hey Time, thanks a lot for the advice.  It seems to have solved the problem.

Ryan Schaefer   «   Reply #5 on: July 27, 2012, 03:51:08 PM »
I meant Tim. :(

Javier Cerdas   «   Reply #6 on: August 06, 2012, 11:19:39 AM »
I was wondering if you guys could help me out.  I'm doing a similar project, where I have a model, and I'm trying to apply an image (someone's face shot) to the model, by replacing a texture.  I have all that in place, but for some reason, my image is upside down on the model... How can I rotate the texture so it displays correctly?  or is there something I need to do before swapping the texture?  Thanks for any help.  Here's my code:



tim b   «   Reply #7 on: August 08, 2012, 03:10:57 AM »



               
                  
                     "I was wondering if you guys could help me out.  I'm doing a similar project, where I have a model, and I'm trying to apply an image (someone's face shot) to the model, by replacing a texture.  I have all that in place, but for some reason, my image is upside down on the model... How can I rotate the texture so it displays correctly?  or is there something I need to do before swapping the texture?  Thanks for any help.  Here's my code:


"
                     Javier C.
                  

               
               

Not seeing any code but the best thing I can think of is to turn the source BitmapData of the face upside down using Matrix transformations (either rotate or vertical flip), before then making a Texture3D out of it and then a TextureFilter and then adding that filter to the Material.