Made Away3d 4.x create material 20 times faster

Software: Away3D 4.x

Zerone, Newbie
Posted: 25 October 2011 03:58 AM   Total Posts: 22

As I post a topic before
bugs in Light and ColorMaterial

I have found a way for made it faster for create more materials in one time

you need to update the the function [getUniqueName] in “MaterialLibrary.as” as below

private function getUniqueName(material MaterialBase) : String
  {
   
var space String material.materialNamespace;
   var 
name String material.name;
   var 
tryName String name;
   var 
append uint;
   var 
int;

   
/*
   do {
    i = _names.indexOf(space+"/"+tryName);
    if (i >= 0)
     tryName = name+"_"+(append++);
    else
     return tryName;
   } while (true);
   
   
   // can't occur
   return null;
   */

   
while( _names.indexOf(space+"/"+tryName) > i){
    tryName 
name+"_"+(append++);
   
}
   
   
return tryName;
  

Speed test result:

private function runTest():void
  {
   time 
getTimer();
   
   var 
c:ColorMaterial;

   
//for(var i:int=0;i<10000000;i++) 
   
for(var i:int=0;i<1000;i++) 
   
{
    c 
= new ColorMaterial(0x000000);
   
}

   trace
("Time: ", (getTimer()-time));
  

Before update: 7014
After update: 347

Wow it is 20 time fatser

   

Avatar
Choons, Sr. Member
Posted: 25 October 2011 04:25 AM   Total Posts: 281   [ # 1 ]

in the first piece of code i has no value?

 

   

Richard Olsson, Administrator
Posted: 25 October 2011 06:53 AM   Total Posts: 1192   [ # 2 ]

Thank you. I’m afraid the MaterialLibrary is going away, but your improvement might be useful in the AssetLibrary as well.

While on the subject of the MaterialLibrary. It is our experience that it’s not very useful, and that what it does could easily be reproduced using the general purpose AssetLibrary instead. For what purpose and in what way are you using the MaterialLibrary?

 

   

Zerone, Newbie
Posted: 26 October 2011 12:50 AM   Total Posts: 22   [ # 3 ]

There are a elevation mesh view of water in different level with different color. I have builded within Away3D 3.6 which is working fine.
But when there are too many face/triangle then it will slow down (10000+), so I am going to rebuild it in Away3D 4.x while molehill support.

in the old version each face/triangle have it own wireframeColorMaterial, so when I do it in the same way, it will have 15 second script error.

But now I found a way, as keep the same color triangle into a array list, so that I can only use few colorMaterial. And also I found a way of building wireframe as well which just adding LineSegment.

 

   

Richard Olsson, Administrator
Posted: 26 October 2011 07:03 AM   Total Posts: 1192   [ # 4 ]

I don’t think it sounds like a very good idea to have 10000 triangles with individual materials. But disregarding that, how are you using the MaterialLibrary?

 

   

Zerone, Newbie
Posted: 26 October 2011 07:55 AM   Total Posts: 22   [ # 5 ]

I use ColorMaterial, and it extends DefaultMaterialBase
and DefaultMaterialBase extends MaterialBase
and MaterialBase have _materialLibrary

and _materialLibrary use registerMaterial function

——————————-

in the above case each line has 2 or 1 triangle plus itself have about 3000 triangles

mesh triangles: about 3000
lines triangles: 3 side x each mesh triangle as (3x3000) = 9000

so 3000+9000 = 12000 triangles

so is there anyway for not using LineSegment as wireFrame so that atless I can less 9000 triangles

 

   

Richard Olsson, Administrator
Posted: 26 October 2011 08:11 AM   Total Posts: 1192   [ # 6 ]

Ok, so you’re not actually using MaterialLibrary explicitly. Then it won’t be a problem that we are removing it, which was all I wanted to know. I’m just looking to find if anyone is actually using the MaterialLibrary in such a way that it would affect them if it were to go away.

There are no real wireframe materials in Away3D 4.0, yet. But there are a couple of ways one can create wireframes. For a flat plane like the one you have, I would just use a bitmap material over the entire surface of the plane, and draw the lines on the texture.

 

   

Zerone, Newbie
Posted: 26 October 2011 08:22 AM   Total Posts: 22   [ # 7 ]

I can not use bitmap material for wireframe, because these need to vector.

for now use LineSegment as wireframe is ok, at less now Flash 11 is fast for hand out it.

now there is 2 more things I want to know:
1. how to made these line cleaner? when I move camera something these line become halfway and sometime is missing
2. looks like there are still not yet have vector 3D text function in Away3D 4.
any luck for it?

 

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X