
Since the beginning of this year I got in touch with Robotlegs thanks to Erik van Nieuwburg. In case you have’t heard of Robotlegs or haven’t used it, you should really check it out sometime soon. It is a micro framework that helps separating your application tiers in a very elegant way. I’ve developed a couple of projects myself using Robotlegs and I really have to say that I’m loving it. Once you know the trick, it seems like a natural way develop your applications like this. It makes your life as a developer a lot easier.
Once I got this into my fingers I suddenly realized that how Robotlegs handles views with mediators is somehow similar to how Unity works with game objects (models aka views in Robotlegs) and components (scripts/predefined functionality aka mediators in Robotlegs). The big difference between Unity components and mediators in Robotlegs is that Unity can work with multiple components on an object and Robotlegs doesn’t.
With the recent public beta release of Flash Player 11 (Incubator) and SDK with the Molehill functionality (native 3D), the alpha release of Away3D 4 “Broomstick” and the announcement by Unity regarding Flash publishing, it became time to get started with this experiment.
Basically I wanted to achieve two seperate things:
- Marrying Robotlegs to Away3D
- Add multiple mediators to 3D objects similar to script components in Unity3D
In order to achieve this I had to make small adjustments to Away3D in order te get an event dispatched as soon as a model is added to the scene. By default no event is fired once a model is added to the Context3D (Aka 3D stage). This is because the 3D stage doesn’t have a display list. So I forked Away3D on GitHub and applied the needed changes and send out a pull request so that these changes could be implemented by the Away3D team. At time of writing this request is still pending, but I’m sure the Away3D team will merge this into their code anytime soon.
A new GitHub repository has been created under the name of “Robotlegs-Away3D-Extension“, which introduces several new classes. The most important once are
- Context3D (not to be confused with native Flash 11 Context3D)
You need to extend this class and use it as the context of your application - Mediator3D
Similar to a mediator as we normally use in Robotlegs, only this type is for 3D objects and not for view components. - Mediator3DMap
As you probably have guessed it, this is similar to the MediatorMap, but maps zer0, one or multiple Mediator3D instances to a 3D object that is present in a scene.
So with this available you can do things in your context like:
threeDeeMap.mapObject3D(Car3D, [BoxCollider, SimpleSteerBehaviour]);
Which says in fact that whenever a Car3D is added to the scene, we need to create an accompanying BoxCollider and a SimpleSteerBehaviour. The latter two are extended Mediator3D classes and are connected to the Car3D. This separates views from functionality and goes even a step further than Robotlegs does by default, as we can have multiple mediators for one single thing we want to display and is consistant with the “Single Responsibility Principle (SRP)” where one class is only responsible for doing one type of actions. In this case functionality of steering has nothing to do with detecting collisions. Although you possibly want to use both, they both do other types of operations and should not be merged into a single class. As this will make classes longer and harder to understand.
As I mentioned earlier, this work is available on GitHub, as well as an example project on how you could use this. The work is far from being perfect and should be improved when I decide to further develop on this (or when someone forks it and continues development
). What interests me the most at this stage is to hear from others whether this approach would make any sense or not and how it could be improved concept wise.
Besides, and here comes an extra wink at Unity, I hope that Unity gets inspired by this approach and possibly even adopt the use of Robotlegs. As if Unity publishing to Flash isn’t awesome enough, I think such approach has the potential to become a mind blowing awesome combination. This also means that I am voting for creating a code based build instead of just compiling a SWF file. With code publishing you leave so much more power in the hands of the developers to integrate the 3D content with 2D content. Also integrating external tools such as FDT, Flash Builder or Flex builder and the Flash IDE itself would an interesting approach.
So lets finally sum up some relevant links:
- Robotlegs Away3D Extension on GitHub
- Away3D Broomstick fork on GitHub (as long as my pull request isn’t implemented by the Away3D team)
- CarExample source on GitHub
- CarExample as included in the examples on GitHub (requires Flash Player 11 Incubator)
- CarExample screen-cast (for those without the beta player installed)
And again please, if you have any thoughts on this that you’d like to share. Please let me know. I think it would be good to get the debate going and find out what would be a powerful and elegant way to manage your 3D content with Robotlegs.
hey man forget unity,
check my car demo http://lo.chaman.free.fr/WEBPRIVATE/CarDriveLo.html
i use jiglibflash and away 4.0 on simple scripte in only one file
(source on there website).
why make complicated thing when it’s easy and logical
i don’t understand utility of Robotlegs in your demo
and don’t see any powerful and elegant in this
but maybe i’m wrong …
You are absolutely right that your car demo is much nicer and just for that demo you wouldn’t need the amount of code I have used in my example. My example is just to demo the concept of splitting application tiers for 3D content. It has nothing to do with the perfect solution for this car driving around, or a cool 3D demo like yours.
Bear in mind that once your 3D scenes are getting more complex, it would be wise to think thoroughly about the architecture of your applications. This is especially getting relevant with Molehill due to the “endless” possibilities as compared to software rendering.
By the way, do you use Robotlegs for your everyday projects? I’m just curious to know wether or not your opinion on this is based on your experience with this or not. I agree that while having no experience with Robotlegs, it looks like an overly complex solution at first sight.
Could please You make the source public? Many people can learn from it.
Sure, the source code is available on github. The links are mentioned in the article but maybe you’ve missed it. Check out https://github.com/PaulTondeur/Robotlegs-Away3D-Extension/ and you find all source you’re looking for.
Very interesting, i was in the process of doing the same by my side, as i’m used to work with robotlegs and love it, and i’m working with a project on away3d 4 / molehill, which involves lot of code, and an easy to evolve and maintain architecture.
Thanks for digging in this.
Now i got a question, did you do some tests regarding performances of 3d objects mediator creations ? It’s already a “bad point” of robotlegs about standard displaylist object mediators.
I did not do any performance testing in order to see what performance it takes to create mediators for 3D objects. I think it is similar to performance with standard RobotLegs, although I have no proof for that. When you have any findings, please share them with me!
Hello Paul,
First, i compiled with latest Away3D-FP11 code, and i was not able to make your example work as is. After some changes to allow compilation, the AC3DParser complains about the car model…
So i made another project from scratch based on your example. My goal was to make a simple test to allow benchmarking of a project with or without 3d mediators.
My tests so far consists of adding 500 Cubes to the scene, and benchmarking frame execution time / rendering time.
I made this test with and without adding a Mediator (Behaviour i like the concept) to my cubes.
The difference on the first frames where object instantiation occurs is about 200/300 ms.
What is funny is that when adding mediators, rendering time seems a little faster on average.
I will try to do more tests if can, but for what i can tell, this seems already pretty good results !
If i may ask, i got a question : how would you allow cloned mesh to be registered by mediators ?
I’m not very used to github, but if you want i can put the code of my tests there.
Thanks,
Eric
Awesome that you did this testing Eric! I appreciate sharing the results here! I’m glad to hear that it seems to be performing so well!
My example project has been created a couple of moths ago, so it could be that it is not in sync with the latest version of Away3D though…
I’m not sure whether your question regarding mediators on cloned meshes is in general, or for the purpose of benchmarking. Assuming the latter, can’t you map a mediator to ObjectContainer3D? When you in general want to clone a mesh and create a mediator for it, I guess you should do more than just cloning the mesh. You need to have an extended class instance of ObjectContainer3D that has been mapped to a mediator. See it as cloning BitmapData. That can only be mediated when it is used inside a DisplayObject (although this situation seems a bit useless).
Would be great when you can put your benchmarks on GitHub! I’m pretty new to it as well, so I know it has a bit of a learning curve. Especially when you are used to visual SVN clients and now you need to do everything by the command line…
Paul,
My question regarding mediating cloned meshes was in general.
Say i got a 3d scene with boxes on stands, each boxe with his specific data/text.
I surely would use cloning to instantiate the boxes, but how to efficiently manage mediator creation of thoses boxes (if not manually) ?
I will try to publish my tests as soon as i handle how to commit to a repository on github^^
Yay i finally succeed in pushing my sources to github : https://github.com/ricovitch/Robotlegs-Away3D-Extension-Test
I think i should need to create a fork of your extension to publish the modifications i made to it to make it work with latests away3d / flashplayer beta also… Don’t have the time right now, but i will try to do it, as it makes me learn a bit github by the way
Very cool Paul, I really like the idea !
I’ll try to build on this while relearning robotlegs
Cheers,
Ringo.
Thanks for your kind words Ringo! Good luck relearning RobotLegs. I’m sure you’ll love it!
Has anyone tried using this with Away3D v.3.6? It looks like the codebase would need to be slightly modified to use Scene3DEvent but before I dig in there I thought I’d ask to see if it’s been tried before?