I written a UV animation plane, but when I new more than 1000 plane, it become very slowly.

Software: Away3D 4.x

liuyi, Member
Posted: 31 August 2011 10:17 AM   Total Posts: 65

Hi guys,
I written a UV animation plane extends from Plane, but when I new more than 1000 plane, it become very slowly.

Every plane just have 2 triangles.
I think the reason is more plane object here.
How to solve this problem?

Here is my code:

UVPlane.aS

package  
{
 import away3d
.materials.MaterialBase;
 
import away3d.primitives.Plane;
 
 
/**
  * ...
  * @author liu yi
  */
 
public class UVPlane extends Plane 
 {
  
private var _maxU:uint;
  private var 
_maxV:uint;
  private var 
_uvIndex:uint;
  private var 
_uvLength:uint;
  private var 
_uvList:Vector.<Number>
  private var 
_nextUVMap:Vector.<Number>
  public var 
duration:Number;//0-1;
  
public var speed:Number;
  protected var 
_delta:Number 0;
  
//now use 1X1 segments first.
  
public function UVPlane(material MaterialBase nullwidth Number 100height Number 100,uvIndex:uint=0,materialU:uint=1,materialV:uint=1,yUp Boolean true
  
{
   super
(materialwidthheight1  1yUp);
   
_maxU materialU;
   
_maxV materialV;
   
_uvIndex uvIndex;
   
_uvLength = (_maxU 1) * (_maxV 1);
   
_nextUVMap = new Vector.<Number>(8,true);
   
duration 1;
   
speed 1;
   
createUVMap();//store uv data to an vector list.
   
moveUVTo(_uvIndex);
  
}
  
  
public function get maxU():uint {
   
return _maxU;
  
}
  
  
public function get maxV():uint {
   
return _maxV
  }
  
  
public function get uvIndex():uint {
   
return _uvIndex
  }
  
  
public function moveUVTo(id:uint):void {
   
if (id >= _uvLength{
    id 
_uvLength 1;

   
}
   
   _uvIndex 
id;
   
this.geometry.subGeometries[0].updateUVDatagetUVMap(_uvIndex));
   
  
}
  
  
public function nextUV():void {
   
   
if (_delta duration{
    _delta 
+= speed;
    return;
   
}
   _delta 
0;
   if(
_uvIndex>=_uvLength){
    _uvIndex 
0;
   
}else {
    _uvIndex
++;
   
}
   this
.geometry.subGeometries[0].updateUVDatagetUVMap(_uvIndex));
  
}
  
  
protected function createUVMap():void {
   
   
var u:Number 
   
var v:Number
   _uvList 
= new Vector.<Number>();
   for (var 
i:int 0<_uvLengthi++) {
      u
= (% (_maxU+1))/_maxU;
      
=  Math.floor(/ (_maxU+1))/_maxV;
    
_uvList.push(u,v);
   
}
   
    
   
  }
  
  
protected function getUVMap(id:uint):Vector.<Number{
  
//0,0,      0.25,0,      0.5,0,        0.75,0,      1,0,
  //0,0.25,  0.25,0.25,  0.5,0.25,   0.75,0.25,  1,0.25,
  //0,0.5,    0.25,0.5,   0.5,0.5,     0.75,0.5,    1,0.5,
  //0,0.75,   0.25,0.75,  0.5,0.75,   0.75,0.75,  1,0.75,
  //0,1,       0.25,1,      0.5,1,        0.75,1,      1,1
   
   //start from left bottom:
   //p1
    
_nextUVMap[0] _uvList[id + (_maxU+1)*2+0];
    
_nextUVMap[1] _uvList[id + (_maxU 1) * 1];
    
    
//p2
    
_nextUVMap[2] _uvList[id + (_maxU+1)*2+2];
    
_nextUVMap[3] _uvList[id + (_maxU+1)*2+3];
    
    
    
//p3
     
_nextUVMap[4] _uvList[id ];
    
_nextUVMap[5] _uvList[id 1];
    
//p4
     
_nextUVMap[6] _uvList[id 2];
    
_nextUVMap[7] _uvList[id 3];
    
    return 
_nextUVMap
  }
 
  
  
 }

Test.as

private function createUVPlaneList():void {
   
var mat:BitmapMaterial = new BitmapMaterial((new fireTexture() as Bitmap).bitmapData);
   
_particalList = new Vector.<UVPlane>();
  
  
   for (var 
i:int 010i++) {
   
    
var p:UVPlane = new UVPlane(mat1010044);
    
p.speed 0.5;
    
p.position = new Vector3D(Math.random() * 500Math.random() * 500Math.random() * 500);
    
p.lookAt(_camera.position);
    
_view.scene.addChild(p);
    
_particalList[i] p;
   
}
   trace
(_particalList.length);
  
}



 
function update(e:Event):void 

   
 
for (var i:int 010i++) {
     _particalList[i]
.nextUV();
 
}
 
....
   

Avatar
theMightyAtom, Sr. Member
Posted: 31 August 2011 01:41 PM   Total Posts: 669   [ # 1 ]

Two words for you, Merge and Clone

Read David Lenaert’s article on efficient geometry.
http://www.derschmale.com/2011/07/25/building-efficient-content-in-away3d-4-0-sharing-materials-geometries/

As all your objects have the same geometry you should be reusing it.
As the code stands you’re making an identical, yet separate mesh each time, meaning the GPU has to process each one separately. (i think!)

Good Luck!

 

   

liuyi, Member
Posted: 01 September 2011 08:15 AM   Total Posts: 65   [ # 2 ]

I have read this post and found that I already use the same material.
so I rewrite my code and use the same geometry.
But slowly yet. 1000 objects 25f/s
See my code.

private function createUVMesh():void {
   
//all objects use the same material and mesh below:
   
_particleMat = new BitmapMaterial((new fireTexture() as Bitmap).bitmapData);
   
_particleMat.blendMode BlendMode.ADD;
   
_particleMesh = new Plane(_particleMat4040);
 
   
_meshList = new Vector.<UVMesh>();
   var 
p:UVMesh;
   for (var 
i:int 0_maxFirei++) {
    p 
= new UVMesh(_particleMat,_particleMesh.geometry4040088);
    
    
p.speed 0.5;
    
p.position = new Vector3D(Math.random() * 500Math.random() * 500Math.random() * 500);
    
p.lookAt(_camera.position);
    
    
_view.scene.addChild(p);
    
_meshList[i] p;
   
}
  } 

 

   

Avatar
theMightyAtom, Sr. Member
Posted: 01 September 2011 12:22 PM   Total Posts: 669   [ # 3 ]

I tried for 10 minutes to run ur code, but there’s just too much missing,
and your class and test code don’t match.

 

   

Avatar
Ringo Blanken, Administrator
Posted: 01 September 2011 12:58 PM   Total Posts: 120   [ # 4 ]

Liuyi, very cool that you are giving this a try.

Can you tell me what are you trying to achieve like:
Many planes with the same animation ?

I can try to make a example.

Cheers,
Ringo.

 

 Signature 

Freelancer: http://www.ringo.nl/en/
http://www.jiglibflash.com
http://www.awayphysics.com
http://www.away3d.com

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X