actionscript 3 - AS3 3D-Renders slowly -
good time.
as know,3d shapes in as3 flat surfaces , can make polyhedrons moving , rotating flat surfaces in 3 dimensions.
but......
what non-polyhedra shapes(spheres,cylinders)??
one way make surfaces using flat shapes.
an example make cylinder; can copy code see happens:
import flash.display.sprite; const angle:number=math.pi/180; var numofsides:uint=200; //number of sides around var pixwidth:uint=4; //width , height of sides var cldheight:uint=20; //height of cylinder var s:sprite=new sprite(); s.graphics.beginfill(0xffffff*math.random()); s.graphics.drawrect(0,0,pixwidth,pixwidth); addchild(s); this.cacheasbitmap=true; for(var n:uint=1;n<cldheight;n++){ for(var i:uint=1;i<numofsides;i++){ var prevs:sprite=s; s=new sprite(); s.graphics.beginfill(0xffffff*math.random()); s.graphics.drawrect(0,0,pixwidth,pixwidth); s.x= prevs.x + math.cos(-prevs.rotationy*angle)*s.width; s.y=n*pixwidth; s.z=prevs.z+math.sin(-prevs.rotationy*angle)*s.width; s.rotationy=-i*(360/numofsides); s.cacheasbitmap=true; addchild(s); } s=new sprite(); }
and problems:
flash renders extremely slow :-(
please improve code or suggest better one.
a few minor notes on code:
- don't forget end fill when you're done(e.g.
s.graphics.endfill()
afterdrawrect()
call) cacheasbitmap
works display objects without rotation applied if can remember- 4000 (200*20) sprites 3d transformations applied might push display list bit.
- remember sort sprites
i recommend checking out these resources:
- flash & math blog icosahedron 3d tutorial
- senocular's exhaustive fp10 drawing api article (using drawtriangles() more efficient since you'll have single sprite on display list)
- if want draw vertices, should pretty fast draw 3d points projected 2d on bitmap
all of above use flash player 10's features, might simpler use 3d api away3d provides easy ways draw cylinders (with textures) @ high speeds(especially newer versions use hardware acceleration)
Comments
Post a Comment