February 13, 2008 at 5:13 am
· Filed under Sandy3d, 3d, Graphics, BitmapData, Papervision3d, AS3
Uff… long time I don’t write here…
So… what I have been doing?
Actually… nothing interesting…
Then, couple days ago I started developing my own 3d engine.
I won’t make it public because it will take all my free time that I actually don’t have…
I didn’t run any benchmarks, I think it’s more heavy processing than Papervision3d.
anyway… here is it…
Permalink
January 24, 2008 at 2:52 am
· Filed under Graphics, source, BitmapData, AS3
It’s a gradient created from the corners of the square.
I was googling and I found the Diamond-Square on Wikipedia.
The idea is quite simple.
First you get the top left and bottom left corner colors of the square. Than, you get the half height of the edge and also the average color of those colors.
You repeat that until you have all pixels of the edge.
Note: The average color is not (color2 - color1) * .5.
It’s (color2.r - color1.r) * .5 << 16 + (color2.g - color1.g) * .5 << 8 + (color2.b - color1.b) * .5.
After that, you make the same with the right edge.
Than, you do it for each edge from the top to bottom.
If you work around more, you can create gradient spots from any pixel you wish easily.
Permalink
January 19, 2008 at 3:00 am
· Filed under Graphics, source, BitmapData, AS3
Answering to CK
1.
ck said,
January 14, 2008 @ 8:07 pm · Edit
… you mentioned to use BitmapData.paletteMap() to generate a grayscale image. Until now I didn’t get this working. How did you do that?
You can convert a BitmapData to Grayscale easily without using my ColorUtils class.
import br.
hellokeita.
utils.
ColorUtils;
…
var bmpData:BitmapData = new BitmapData(w, h);
…
var grayscaleArray:Array = new Array();
var c:Number;
for(var i = 0; i < 0xff; i++){
c = i * .3 + i * .59 + i * .11;
grayscaleArray[i] = (c<<16) + (c<<8) + c;
}
bmpData.paletteMap(bmpData, bmpData.rect, new Point(0,0), grayscaleArray, grayscaleArray, grayscaleArray);
Permalink
December 4, 2007 at 7:22 pm
· Filed under Benchmark, Sandy3d, BitmapData, Performance, AS3
Well, I don’t know if anybody read the Thomas Pfeiffer aka Kiroukou (the Sandy3D creator and project leader) commented on my previous post.
Here’s what he said.
Indeed Sandy does a clone of the original texture, for few reasons:
- avoid an unfortunate dispose call.
- allowing to have a setTransparency method to dynamically change the transparency without changing the original bitmapdata of the user.
Concerning the lock() and unclock() are you sure it has a performance impact?
as far I know, this can’t provide any performance boost since the bitmapdata isn’t attached to the flash display list. When the object is out of stage, there’s no advantage to lock it.
But I’d be interessted to have your feedback about that, and your performance test.
About the BitmapData.clone(), he got his point.
It just don’t work for me because I’m using too many 3d Objects with different BitmapMaterial for each, so, the system memory gets too high.
But, about the setTransparency method, he is right.
About the lock and unlock methods, I runned a little benchmark test, because I got curious too how much performance boost you can get.
Here’s the two test I made. (Clicking on the flash area it will re-run the benchmark test)
Using the lock and unlock methods.
Not using the lock and unlock methods.
It’s a really simple test, just to make a benchmark test.
Actually, it’s not a situation that uses any 3d framework.
Creating a BitmapData.
Creating 1000 Bitmaps.
Applying 1000 times a BlurFilter over the BitmapData.
On my PC I get about 150ms faster with locking the BitmapData.
keita
Permalink
November 28, 2007 at 5:05 pm
· Filed under Sandy3d, BitmapData, Performance, Papervision3d, AS3
I was making some experiments with Sandy3d and Papervision3d and I realized some tips to increase the performance.
Firstly, with Sandy3d 3.0, when you create a BitmapMaterial, the BitmapData that you used to create the Material, is cloned to create the BitmapMaterial.texture.
So, one think you can do is dispose the BitmapData that you used to create the Material after instantiating it and also, if you want to update your BitmapData use the BitmapMaterial.texture directly.
Something like this:
var bmpData:BitmapData =
new BitmapData
(100,
100,
true, 0×00000000
);
var bmpMaterial:BitmapMaterial =
new BitmapMaterial
(bmpData
);
bmpData.dispose();
bmpMaterial.texture.fillRect(new Rectangle(10,10,30,30), 0xffff0000);
This will not work with Papervision3d because it uses the same BitmapData instance (in my opinion, smarter).
Now for both, Sandy3d and Papervision3d.
As you make changes on your BitmapData, it’s updated on every poligon.
So, use the BitmapData.lock() and BitmapData.unlock() when you are redrawing your BitmapData texture.
var bmpData:BitmapData =
new BitmapData
(100,
100,
false, 0×00000000
);
var bmpMaterial:BitmapMaterial =
new BitmapMaterial
(bmpData
);
redrawBitmap();
…
function redrawBitmap(){
bmpData.lock();
bmpData.fillRect(bmpData.rect, 0×00000000);
bmpData.fillRect(new Rectangle(10,10,30,30), 0xffff0000);
var blurFilter:BlurFilter = new BlurFilter(16, 16, 3);
bmpData.applyFilter(bmpData, bmpData.rect, new Point(0,0), blurFilter);
bmpData.unlock();
}
Permalink
November 19, 2007 at 2:21 pm
· Filed under TextField, source, BitmapData, AS3
Actually, I didn’t show the source because I wanted to know how many people was reading it, and was interested about it… so let me reveal the little trick.
First, I create a TextField, selectable(obviously) and set the alpha to zero.
Than, create a BitmapData with the TextField size, and, just draw the TextField on BitmapData each time the selection changes.
When you draw the BitmapData, there is to ways to change the selection color, using the ColorTransform or PalleteMap methods.
After that, you just place the Bitmap behind the textField.
var color = 0xff0000;
var c = ColorUtils.
getRGB(color);
highlightBmpData.fillRect(highlightBmpData.rect, 0×00000000);
highlightBmpData.draw(textField);
highlightBmpData.colorTransform(highlightBmpData.rect, new ColorTransform(1, 1, 1, 1, c.r, c.g, c.b, 0));
One thing is that, using Color transform, you can change easily the smoothed fonts, and with PalleteMap is harder.
Just remember that the selection color is always black, so you need to change the black part of the BitmapData to any color you want.
Easy huh?
PS: weird thing is that some people couldn’t see the effect on Mac with Firefox… I didn’t try it yet, but I’ll try to find a way to make it work.
Permalink
November 8, 2007 at 1:12 am
· Filed under Benchmark, Graphics, BitmapData, Performance, AS3
Firstly… sorry for my poor English…
Working on Recyou.jp, I had to use many BitmapDatas, and so, I had to work out some way to make it lighter.
One thing I realized is that using Graphics.beginBitmapFill besides BitmapData.draw its much faster.
I made the benchmarks, drawing 10000 bitmapDatas, one using BitmapData.draw, and other using Graphics.beginBitmapFill.
First the benchmark with BitmapData.draw (Clicking on the flash it will re-run the benchmark):
The code is something like this:
var genericBmp:BitmapData = new BitmapData(100,100, false, 0×000000);
var bmp:BitmapData = new BitmapData(100,100, false, 0×000000);
for(var i = 0; i < 10000; i++){
bmp.draw(genericBmp);
}
Now the benchmark with Graphics.beginBitmapFill (Clicking on the flash it will re-run the benchmark):
The code is something like this:
var genericBmp:BitmapData = new BitmapData(100,100, false, 0×000000);
var bmp:BitmapData = new BitmapData(100,100, false, 0×000000);
for(var i = 0; i < 10000; i++){
graphics.beginBitmapFill(genericBmp);
graphics.drawRect(0,0,100,100);
}
So, if you are trying to create some bitmap pattens or attaching a Bitmap child and redrawing it’s BitmapData, try using the Graphics.beginBitmapFill.
Permalink
October 24, 2007 at 8:46 am
· Filed under Regexp, source, BitmapData, AS3
One think that I am really thankful is the addition of Regular Expression in AS3.
That’s really helping me around.
Here’s some cheatsheets that I always check:
http://krijnhoetmer.nl/stuff/regex/cheat-sheet/
http://regexlib.com/CheatSheet.aspx
http://www.ilovejackdaniels.com/cheat-sheets/regular-expressions-cheat-sheet/
Also, I uploaded my svn my StringUtils class
http://code.hellokeita.in/public/trunk/as3/br/hellokeita/utils/StringUtils.as
Actually, there’s just the trim method, but you see that’s it’s really easier than AS2.
\s|\n|\r|\t|\v <- I put all those characters to make sure every initial end final whitespace are trimmed.
Also, I uploaded my ColorUtils.as too.
You see that it's really easy to manage ARGB colors with it.
Also, there's a RGB -> Grayscale color converter.
Oh, don’t try converting a bitmapData pixel by pixel to generate a Grayscale image.
There’s an easier way to make it with the BitmapData.paletteMap() method.
but… I’ll keep it to the next post …. if anyone shows any interest.
Permalink
October 7, 2007 at 7:18 pm
· Filed under BitmapData, Performance, AS3
I’m working on a project that everything eats performance, using FLV videos, animated smooth Bitmaps, Papervision3D and everything else…
So I started desperately find a way to increase the flash performance.
So, I realized that using BitmapDatas instead using many sprites and FLV videos helped really much.
I mean, instead adding a full screen FLV streaming video on your background, add a Bitmap child on your background that draws the FLV child.
I didn’t make any benchmarks, but, at least on this project it’s helping me speeding up my heavy processing flash.
Permalink