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:

  1. don't forget end fill when you're done(e.g. s.graphics.endfill() after drawrect() call)
  2. cacheasbitmap works display objects without rotation applied if can remember
  3. 4000 (200*20) sprites 3d transformations applied might push display list bit.
  4. remember sort sprites

i recommend checking out these resources:

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

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -