[away3d] Spelling in Loader3D

23 views
Skip to first unread message

j...@justinfront.net

unread,
May 1, 2011, 12:11:20 PM5/1/11
to away3d.dev
Hi away team noticed a spelling error in Loader3D

http://code.google.com/p/away3d/source/browse/trunk/fp10/Away3D/src/away3d/loaders/Loader3D.as


/**
* Constant value string representing the material file
loading mode of the 3d loader.
*/
public const LOADING_MATERIAL_FILE:String = "loading_mateiral";


in that intentional? Also not exactly sure of the difference between
Material and Texture, back on my sunday afternoon messing with 3d for
my friend, still having some issues with loading, but have some ideas
to make more obvious what's going wrong for us, maybe the features
would be good in the next iteration of the loaders, hopefully I can
post something later that might be interesting concept. Have you
finalized the loader approach for flash11 maybe let me know the plans
so I can comment if it seems useful to some real use and maybe add
some suggestions, not checked the flash11 repository yet but I am
guessing it may not have all details in there yet anyway, feel free to
email me direct, as I have said would like the next iteration of
loaders to be more adaptable - explicit.

Cheers

:j

Michael Iv

unread,
May 1, 2011, 12:21:12 PM5/1/11
to away3...@googlegroups.com
That is in French . Probably Fabrice's typo ;) ( just kidding )

Sent from my iPhone

Trevor Burton

unread,
May 1, 2011, 1:04:16 PM5/1/11
to away3...@googlegroups.com
that's a great example of why you should use references to a string for this sort of thing instead of putting the string everywhere...

it doesn't matter if there's a spelling mistake cause everything's referencing the same thing

:)
--
---------------------------
Trevor Burton

Fabrice3D

unread,
May 1, 2011, 3:00:17 PM5/1/11
to away3...@googlegroups.com
That's no French & I am innocent ( in this case) :)

Fabrice

j...@justinfront.net

unread,
May 1, 2011, 5:34:23 PM5/1/11
to away3...@googlegroups.com
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

Brian Bosak

unread,
May 1, 2011, 8:55:56 PM5/1/11
to away3...@googlegroups.com
The misspelling of Material looks like it was just a mistake. Sent from my Windows Phone

Michael Iv

unread,
May 2, 2011, 1:58:20 AM5/2/11
to away3...@googlegroups.com
״sent from my windows phone"
Nice ;)

Sent from my iPhone

richardolsson

unread,
May 2, 2011, 2:49:54 AM5/2/11
to Away3D.dev
@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, "j...@justinfront.net" <j...@justinfront.net>
wrote:
> ...
>
> read more »

j...@justinfront.net

unread,
May 2, 2011, 1:52:37 PM5/2/11
to away3...@googlegroups.com
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

>> return ( _bytesLoaded /_bytesTotal ) /
>> _loadQueue.numItems;
>>
>> }
>>

j...@justinfront.net

unread,
May 2, 2011, 1:54:18 PM5/2/11
to away3...@googlegroups.com
R

Anyway just some thoughts.

Cheers


justin L mills

>> return ( _bytesLoaded /_bytesTotal ) /
>> _loadQueue.numItems;
>>
>> }
>>

fredrik

unread,
May 19, 2011, 8:16:57 AM5/19/11
to Away3D.dev
Hi,

I have a suggestion on how to track the loading progress for more
complex situations, and where you really want the progress to be
calculated accurately.
My suggestion is to introduce a new XML format, containing the output
from an analysis of filesizes, locations and dependecies.
The xml data would be an argument to a new
AssetLibrary.loadFilesByScanResult(scanResult:XML).
The scanResult could be generated:
a) manually
b) by using Prefab
c) by using a special Away3dAntTask, which then easy could be used
for a build with continuous integration
d) by calling server side scripts in runtime
e) by the help from a few new Away3d Air utility classes.

What do you think? Do you need any help?

Kind regards,
Fredrik



Kind regards
Fredrik
> ...
>
> läs mer »

richardolsson

unread,
May 19, 2011, 8:43:15 AM5/19/11
to Away3D.dev
@fredrik:

I think it's an interesting idea, but tbh I think it might be a bit
too complex to become an engine feature (and definitely a feature
included in the AssetLibrary. If anything, it could be dealt with by a
standalone class.)

I can imagine adding a couple of events however, that are dispatched
as a dependency starts loading, so that a standalone system like this
can still be created. By listening for when each dependency starts and
finishes loading, the system can calculate the progress from it's
internal mapping of file sizes and dependencies (which may or may not
come from some XML file.)

Alternatively, we could add a simple measure to define the estimated
file size in the AssetLoaderContext, and that could be used to
calculate the total progress internally in AssetLoader (because even
though it has no idea of how many files might be referenced by the
next dependency, it can keep count of how many bytes has been loaded
and use that along with the user-estimated file size to calculate
progress.)

This would just require a single number, which makes the feature less
heavy on the engine-side. How that number is calculated (e.g.
manually, by prefab, or by a server at runtime) would still be up to
the user and all of your ideas would still work.

Could this serve as a good compromise?


Cheers
/R
> > >                                                                  ,    ...
>
> read more »

richardolsson

unread,
May 19, 2011, 8:44:32 AM5/19/11
to Away3D.dev
And just to be clear: Thanks a lot for thinking it through and
suggesting improvements! :)

/R
> > > >                      }...
>
> read more »

fredrik

unread,
May 19, 2011, 9:14:12 AM5/19/11
to Away3D.dev
Thanks for your reply!

I think you are absolutely right about that it is a too complex
solution to be a part of the engine.
It would be perfectly enough to be able to listen for when a
dependency starts loading and when it is complete - so that anyone can
build their own logics for the progress calculation.

/Fredrik
> ...
>
> läs mer »
Reply all
Reply to author
Forward
0 new messages