R

Thought about this deeper today...

I think the solution is to maybe provide a couple of modes for less complex structures. Then for more complex structures a macro could be run if your using the haXe version, I mentioned parsing XML to typed structures awhile back on haxe list, and the other Justin has already got some general xml to be typed in haxe, so collada would for instance be a simpler case in that you only need some of the nodes, so I think it is very viable but not so easy, for as3 if you can't mix then I guess prefab would construct the loader framework as as3 code. Obviously it may not be easy but normally you know just before the final deploy what the whole model is so running it through some code to build the loader that hooks into a linear feed out, and maybe some form of compromise structure... ie you tell flash what to expect but since you are running in a generic loader it can revise slightly the loading bar if needed. The structure would have to be flexible so you could hookup to a design to keep people amused.

Yer probably too complex, my friend knows the modelling side maybe its sensible to limit the structures I don't know, but I think Macro's might be the solution for complex cases, atleast for haXe they would probably work well.

Anyway just some thoughts.

Cheers


justin L mills


On 2 May 2011, at 08:49, richardolsson wrote:

@Jim:

That's a good idea, and I'm currently working on how Away4 should
report loading progress. But unfortunately what you are suggesting is
not a very reliable method because you can never know how many
textures (and other dependencies) are in a loaded file. Some file
formats can reference other files with lots of data so potentially the
"totalTextures" property you're suggesting might inrease infinitely.
Because of this, I'm not sure the approach is actually solving
anything (because the purpose of a loading bar is to reliably display
the progress of loading.)

Imagine two scenarios, for clarity:

1. An AWD file is loaded. It contains references to 5 external
textures and 4 external AWD files. That's ten files total, meaning
that when the master file and the five textures have been loaded it's
at 60 per cent, which is cool. However, as the four external AWD files
each are loaded (and status reaches 100% save the parsing) they are
found to contain one texture each. We realize there are 14 files, and
only ten of those are loaded. The user will see the progress bar
suddenly jump back to 70%.

2. A heavy collada file is loaded. After it's been read into memory
Away needs to parse it. Lets say this takes 5 seconds. During those
five seconds the progress will be almost 100% (save the parsing) but
during parsing the collada file is found to reference 19 external
textures. Progress jumps back to 5%.

As you can imagine, problems like these sort of defeat the purpose of
loading feedback. :(

I am continuing to think about this, and we are discussing it in the
team, but I would love your thoughts on the above. Should we have per-
dependency loading feedback but not even try to do the "total
progress" thing? Should we not care about the issues described above
because they're edge cases? Please let us know what you think.

Cheers
/R

On May 1, 11:34 pm, "[email protected]" <[email protected]>
wrote:
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 ยป

Reply via email to