Hey there
In my project i load a bunch of models, place and remove them from the scene according to the player actions.
the thing is, the textures are mostly transparent, and i actually create a new texture each time by painting the transparent parts to different colors
then i crate a new bitmap material from it and apply it to the mesh.
eventually i get the “Resource limit for this resource type exceeded” error.
what am i doing wrong? what should i reuse or dispose of?
here’s the code that runs each time a place a mesh on the scene:
public function applyMaterial(model:ObjectContainer3D, originalBitmap:BitmapData, color:uint):void {
var mat:BitmapMaterial;
var coloredBitmapData:BitmapData = new BitmapData(originalBitmap.width, originalBitmap.height, true, color);
coloredBitmapData.draw(originalBitmap);
mat = new BitmapMaterial(coloredBitmapData);
mat.lights = (ghost)?[]:[light1, light2];
mat.ambientColor = 0xFFFFFF;
for (var i:int = 0; i < ObjectContainer3D(model).numChildren; i++) { //for multiple meshes like wheels
Mesh(model.getChildAt(i)).material = mat;
}
}
cheers