Anyway no matters...
My suggestion which I said I would get back to you on was an idea is
for the general test loader - you can show a colored bar for each
texture loaded then very easy to adapt that for an animation and you
have better control of actual loading information than the current
away code provides.
Suggested changes in the Loader3D class...
public function get fractionTotalTextureLoaded(): Number
{
return _loadQueue.currentItemIndex * 1 /
_loadQueue.numItems + ( _bytesLoaded /_bytesTotal ) /
_loadQueue.numItems;
}
public function get fractionCurrentTextureLoad(): Number
{
return ( _bytesLoaded /_bytesTotal ) /
_loadQueue.numItems;
}
public function get totalTextures(): int
{
return _loadQueue.numItems ;
}
public function get textureIndex(): int
{
if( _loadQueue == null )
{
return 0;
}
return _loadQueue.currentItemIndex ;
}
Then currently I am using my own ColladaLoader that just wraps access
more like my normal approach.
package loaders
{
import flash.events.Event;
import flash.events.ProgressEvent;
import flash.display.Loader;
import flash.display.Sprite;
import away3d.loaders.Collada;
import away3d.core.base.Object3D;
import away3d.loaders.Loader3D;
import away3d.loaders.LoaderCube;
import away3d.core.base.Mesh;
import away3d.events.Loader3DEvent;
import org.osflash.signals.Signal;
import away3d.loaders.Loader3D;
import away3d.loaders.utils.*;
public class ColladaLoader
{
public var loader: Loader3D;
private var ratio: Number;
private var file: String;
public var content: Object3D;
public var finished: Signal = new Signal();
public var progressed: Signal = new Signal();
public var fraction: Number;
public var fractionGeometry: Number;
public var textureFractions: Array;
public function ColladaLoader( _file: String, _ratio:
Number )
{
ratio = _ratio;
file = _file;
}
public function load()
{
loader = Collada.load( file, { scaling: 1,
bothsides: false } );
loader.loaderSize = 0;
loader.addEventListener( Loader3DEvent.LOAD_SUCCESS,
loaded );
loader.addEventListener( Loader3DEvent.LOAD_ERROR,
onError );
loader.z = -2000;
fraction = 0;
loader.addEventListener( Loader3DEvent.LOAD_PROGRESS,
loaderProgress );
}
private function loaded( e: Loader3DEvent )
{
content = loader.handle as Object3D;
trace( content );
finished.dispatch();
}
private function onError( e: Loader3DEvent )
{
trace( 'error loading ' + file );
}
private function loaderProgress ( e : Loader3DEvent )
{
var textureIndex: int ;
var totalTextures: int;
fractionGeometry = 0 ;
if( loader.handle.bytesLoaded != 0 &&
loader.handle.bytesTotal != 0 )
{
if( loader.handle.mode == 'loading_textures' )
{
textureIndex = ( loader.handle as
Loader3D ).textureIndex ;
//trace( 'texture index '+ textureIndex );
totalTextures = ( loader.handle as
Loader3D ).totalTextures ;
//trace( 'totalTextures' + totalTextures );
if( textureFractions == null )
{
textureFractions = [];
}
if( textureIndex != 0 && textureIndex != null )
{
// populate already loaded sections
for( var i = 0; i < textureIndex - 1; i++ )
{
textureFractions[ i ] = 1/totalTextures ;
}
textureFractions[ textureIndex ] =
( loader.handle as Loader3D ).fractionCurrentTextureLoad ;
}
fraction = ( 1 - ratio ) + ratio*( loader.handle
as Loader3D ).fractionTotalTextureLoaded;
}
else if( loader.handle.mode == 'loading_geometry' )
{
fraction = ( 1 -
ratio )*loader.handle.bytesLoaded / loader.handle.bytesTotal;
fractionGeometry = loader.handle.bytesLoaded /
loader.handle.bytesTotal;
}
progressed.dispatch();
}
}
}
}
And to draw the bars I use some colors, based on some rainbow image
of
pencils so rather than using an equation they hopefully have a nice
feel to them
private static var rainbowPencilColors: Array =
[ 0xD2D0C1
,
0xCD8028
,
0xD29D11
,
0xE37128
,
0xF06771
,
0xD23931
,
0xAF2C31
,
0x90333E
,
0x863D50
,
0x584A5D
,
0x549EC3
,
0x2C709D
,
0x457AAE
,
0x364D6D
,
0x378C6D
,
0x6EA748
,
0x365DA4
,
0x456E42
,
0xC1882E
,
0x813424
,
0x402E24
,
0x292420
,
0x525751
,
0x1B1B19
];
so I wire up a listener to the loader, in the loaded part I put a
clear. I am using a Callback class but mainly because I have lots of
screens and it's easy maybe not good practice.
loada.progressed.add( Callback.create( progressBar,
loada ) );
and then render the bars...
public function progressBar( loada: ColladaLoader )
{
try
{
var textureFractions = loada.textureFractions ;
var dw: Number ;
var w: Number = 0;
var widTotal = 150 ;
bar.graphics.clear();
if( textureFractions != null )
{
for( var i: int = 0; i < textureFractions.length; i+
+ )
{
dw = textureFractions[i] * widTotal ;
if( isNaN( dw ) )
{
dw = 0;
}
drawColorSquare( rainbowPencilColors[ i %
rainbowPencilColors.length ], w, dw ) ;
w += dw;
}
}
}catch( d: Error )
{
trace( 'oops' );
}
progressBar.scaleX = loada.fraction ;
progressText.text =
String( Math.round( loada.fraction*100) ) +'%';
}
for actual rendering very simple drawing code..
private function drawColorSquare( c: int, _x: Number,
_width: Number )
{
var _y: Number = 0 ;
var _height: Number = 3 ;
bar.graphics.lineStyle( 0, 0xff0000, 0 );
bar.graphics.beginFill( c, 0.53 );
try
{
bar.graphics.drawRect( _x, _y, _width, _height );
}
catch( e: Error )
{
trace( 'oops ' + _x + ' ' + _width );
}
bar.graphics.endFill();
}
Anyway it's maybe a bit rough ( still have some try's in there ) but
as I have said before, I am helping a friend so he has accepted
that I
opensource generic bits of the code, the rainbow concept was to help
track down my bug and see what was really happening, but i think it's
quite a good concept for loading, you could swap the drawColorSquare
out for running a timeline/code animation from an array, anyway for
me
atleast this approach worked better than extending the LoaderCube,
maybe some good concepts in there for the away3d player11 project,
aware the code is not really perfect yet and is only really for
ideas,
but should be a good start for anyone with the same problem as I have
had.
Cheers
;j
On 1 May 2011, at 21:00, Fabrice3D wrote:
That's no French & I am
...
read more ยป