Loading external Papervision3D Models, a Simple Robotlegs Example

Actually the title for this post was gonna be ‘Preoading external Papervision3D Models, a Simple Robotlegs Example” but unless I have some strong Coffe, I think it best to add the preoloader part in next update. Below is a really simple example of an external DAE model Loaded in, the classes structured within the Robotlegs framework.

Get Adobe Flash player

One of the many fun things with Robotlegs is that it helps us structure data and hand out single responsibilites for tasks to classes. For loading remote data we create a Service class which can connect to a webservice.

However for data that is loaded locally and not really said to be remote the word/concept of a Proxy meaning “Something that stands in for something else to achieve something” can be useful.
In this case our proxy is called DAELoaderProxy and looks like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package model.proxies
{
import model.data.DataLogic;

import org.papervision3d.events.FileLoadEvent;
import org.papervision3d.objects.parsers.DAE;
import org.robotlegs.mvcs.Actor;

public class DAELoaderProxy extends Actor
{
[Inject]
public var dataLogic:DataLogic;

private var mod:*;
private var _pathtomod:String;

public function DAELoaderProxy()
{
}

public function loadModel ():void {
mod = new DAE();
mod.load(this.pathtomod)
mod.addEventListener(FileLoadEvent.LOAD_ERROR, onModelLoadError);
mod.addEventListener(FileLoadEvent.LOAD_COMPLETE, onModelLoaded);
//TODO :PRELOADER THAT NOTIFIES MODEL OF PROGRESS, MODEL NOTIFIES PRELOADER MEDIATOR OF PROGRESS, PRELOADER VIEW UPDATES
}

private function onModelLoaded(event:FileLoadEvent):void
{
dataLogic.deemodel = mod;
}

private function onModelLoadError(event:FileLoadEvent):void
{
trace("error")
}

//get - set
public function set pathtomod (value:String):void {
_pathtomod = value;
}

public function get pathtomod ():String {
return _pathtomod;
}
}
}

The DAELoaderProxy does one thing: it (obviously) loads a DAE model for our cool Papervision3d. Once the 3D model is loaded the Proxy class calls a setter upon the data Model class (in this case called DataLogic.as) and passes the 3D model to it.

This way the responsibility of updating the framework is handed over to the Model. The Model dispatches an event with the DAE 3d model as payload and our ViewMediator catches the event and adds the model to our 3D View.

Proxies seem to me very single minded. We can in effect write an alternative KMZLoaderProxy class for google Sketchup models without needing to know more than the code that gets that particular job done. Of course we might as well call the DAELoaderProxy class for ‘DAELoader’ but for me personally I like the word proxy as it underlines the “Stand in” part.

And whereas a loader in not structured code often ends up notifying the Observers the proxy does not. It let’s Model do it’s part instead.

You can download project files here (Flashbuilder project). It should contain all needed to run locally.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Please leave these two fields as-is:

Protected by Invisible Defender. Showed 403 to 173,342 bad guys.