Unity and Flash, the best of both worlds! - Unite presentation slides

Last Tuestday I presented at the pre-conference Unity for Flash developers day, at invitation of Unity. It was a very interesting day for every Flash developer who wants to get into Unity (which by the way is  very easy to get started with, as Unity Indy has been made a free product!). Other speakers that day were Mauricio Longoni, John Grden and Tom Higgins.

I think the day provided the visitors with a lot of essential information in order to get started with Unity. The feedback I received on my talk was very good, so hopefully I contributed to new Unity users getting started with Unity.

As promised in my presentation, I've posted my presentation online, which you'll find at the end of this post. In the next weeks when I've returned and recoverd from this conference, I'll start posting some of the examples as mentioned in my presentation. So you can expect the JSON, Google Analytics, XML loading and Parsing, image loading and posting variables examples on this page.

Speaking at Unite 2009 in San Fransisco - Unity for Flash developers

Unite 2009

I already twittered this while being on vacation, however I thought it would be nice to give this some extra attention, since I think the conference is going to rock. After investing a lot of time since last years Unite conference in Copenhagen, it would be very interesting to see where other developers have been into and join the very promising sessions that are scheduled (http://unity3d.com/unite/agenda).

If you don't have a ticket yet, you should really rush, as the conference already starts in a little more than 2 weeks on the 27th of October.

In my point of view, Unity made a very wise decision this year by organizing a special day for Flash developers. This day will give the conference a kick-start for Flash developers who want to get into Unity, as they will be introduced to everything they need to know to get along with the rest of the conference (and start themselves with some Unity development afterwards). I would have been so grateful when such conference day was available at the time I got into Unity.

I feel very honored that 'm invited by the people of Unity to come over and do a session for Flash developers. My talk will be about using best of both worlds and how to interact between the two. Unity for 3D content and Flash elements for 2D content. I have some very interesting cases in mind, which I'll work out in the next two weeks and present at my session.

John Grden from the Papervision3D team will host another session, as well as Mauricio Longoni who created u3dobject.

So to conclude this and be honest; if this is within your field of interest you just need to be there! So get your tickets today and see you in San Fransisco!

Papervision3D Essentials - Out now!

After more than 8 months of hard work, at least 1600 man-hours, writing 13 chapters and 428 pages, Jeff Winder and I are proud to let the world know that our book has finally been published!

With this book we had the goal to write a book for beginners. A book which we would like to read when we were starting with Papervision3D. Taking nothing for granted and gradually work to more advanced topics. Hopefully we have achieved that goal, which will become clear once the copies are sold and we will get feedback from our readers. Now the book is on sale we can finally get feedback from more people other than the very valuable reviewers Trevor Burton, Stuart Caunt and Patrick Rushton.

The book covers many topics in detail, which results to that the book could be used as a reference guide. More than once I've looked back to the chapters that we've written and see how things work. We have chapters dedicated to the following topics:

  • Setting up
  • Building your first application
  • Primitives
  • Materials
  • Cameras
  • Moving things around
  • Shading
  • External models
  • Z-sorting
  • Particles
  • Filters and effects
  • 3D Vector drawing and text
  • Optimizing performance

Together with releasing this book, our publisher posted an example chapter on their website. Which is chapter 8 about modeling. I think this chapter gives a good impression on how thouroughly we tried to explain certain topics.

More information about the topics of our book can be found on the website of our publisher. Make sure you'll check out:

In the next couple of weeks you can expect some articles here on my blog about subjects that have not made it to the book. So keep an eye on this blog.

But for now, I'm going to enjoy my vacation first and I want to say a big THANK YOU!, to those who have supported us during the writing. Our reviewers Trevor, Patrick and Stuart. The Flash community for posting valuable articles and last but not least the Papervision3D team for their help and answers while writing the book.

Papervision3D Essentials - A Book By Paul Tondeur and Jeff Winder Officially Announced

Papervision3D Essentials Book Cover

I'm very delighted to finally announce that I have been working on the first Papervision3D book that will be released ever. The book is in cooperation with my good friend and co-author Jeff Winder and will be published by Packt Publishing. Since the beginning of this year we have been working extremely hard on the writing of this book. We are ready with the writing of all chapters and are preparing all final drafts right now. So you can expect this book to be published really soon.

The result of our hard work is that we have a book that will be useful for both experienced as non-experienced Papervision3D users. The first few chapters take no knowledge for granted and guides the reader through all steps for getting started with Papervision3D. It describes how to get Flash CS3, Flash CS4, Flex Builder and Flash Builder correctly configured for running Papervision3D code. This includes downloading Papervision3D (SWC, ZIP and a step-by-step guide for downloading from SVN). Once an example project has been compiled, a short introduction to OOP and classes is given for those who have no experience in this. From there the reader book gradually works through more advanced topics, such as loading external models, shading, z-sorting, viewport layers, particles, filters and effects, vector drawing and performance optimizations.

As the book contains much information on a variety of topics it is also interesting for those who already have experience in Papervision3D, but want to extend their knowledge and understanding. It was not aimed to be a reference guide, however it turns out that many topics are thoroughly described and can be used for this purpose as well. (I personally already did this while working on commercial projects that make use of Papervision3D)

Today the book has been announced on the website of our publisher, Packt Publishing and will soon be announced on other websites, like Amazon for example. For both Jeff and myself this is the first book we have ever written. Seeing our book and names listed is already very exciting.

We can't wait to have our book finished and hold the final copy in our hands. We did our best (and still do) to make this a very good book and we are looking forward to hear responses from our readers.  But for now we will continue writing on the last bits. Once there's more news about the exact release date I will post it here on my blog.

[Update 2009-07-29] Papervision3D Essentials - Now listed on Amazon

AS3 clickTag case and popup blocker fix

Last week we've been struggling to get our AS3 banners ready for publication.
One of the more common problems anyway, is that some ad management systems requiress clickTag (lowercase "ag") and others requires clickTAG (uppercase "AG") in order to load the right URL. This is very annoying, especially when you have to make 2 versions for different publishers and you need to do a text change... When you have a big capaign with let's say 5 banner formats, and 3 banner variants, you already have to make 15 different banners. In case you need to deliver banners with a clickTag and a clickTAG, you'll end up with 30 banners. In case you've ever build banners yourself, you see my point. It's soo easy to lose the overview when you have so many files looking almost identical to each other.

A new problem with banner build using AS3, is that some browsers will block the navigateToURL requests. A trick for this is let javascript open the URL instead of actionscript.

Both of these things have been recently an issue, so that's why I decided this weekend to wrap this all up in a clickTag class, which is universal for all different case combinations of the word clickTag. Beside that, it will open URL's correctly without a browser which is blocking it. (at least, as far a I know).

Instead of adding a button on the stage, set up all the event listeners etc, you can now use:

 
var clickTag:ClickTag = new ClickTag(300,250);
clickTag.enableClickTag();
addChildAt(clickTag,0);

It's just as simple as that. In case you want a custom shaped button, you need to assign it to clickTag by using "clickTag.setButton(btn);".

In order to open the links correctly, you need to make sure that the parameter AllowScriptAccess is set to "always":

<param name="AllowScriptAccess" value="always">

Download this class and it's examples in Flash and Flex here!

Unity3D communication with browser and Flash

I've been using Unity3D for a while now and I would like to share some of my discoveries starting by this post. In case you don't know unity3D yet, you should check out their website: unity3d.com and make sure you'll see the tropical paradise and shadows demo. Unity3D is a very promising 3D engine with the possibility to publish for the web by using a browser plugin (just around 3MB) with extreme good results. Personally I'm not a big fan of using browser plugins which aren't as adopted as Flash is. Flash projects like Papervision3D/Away3D/Alternativa/etc are very impressive and I love to use them. But in case you want to go more advanced, this is all to limited and you have to look at a browser plugin. Unity3D is then the best option.

Okay, enough introduction. As a web oriented developer I want Unity3D elements on my page to completely integrate with other elements in an easy way. Basically, I want to be able to have cross communication between Unity3D, Flash and javascript on a page. Building GUI's using Unity3D is very limited when you compare it with Flash. So why not using best of both worlds together on a page?

While starting with this I found a chat demo build by FlashBangStudios which does cross communication between Unity3D, Flash and a browser. Unfortunately it isn't open sourced, so we can't see everything about what's going on under the hood. So I've build a Unity3D chat myself based on communication within the browser. (Source files are included in the download at the end of this article)

To achieve this I used something similar like SWFObject, called UnityObject, to embed unity files in a clean way on my page. The coded posted there seems to a bit out dated and showed some problems in Internet Explorer 7. So I've tweaked their version a little bit and it now should be working perfectly (Tested with Firefox 3.0.3, Internet Explorer 7, Safari 3.1.2 and Chrome).
With unityobject, embedding is very easy:

var uniObj = new UnityObject("UnityObject.unity3d", "Unity3D", "640", "480");
uniObj.setAttribute("altHTML", "Alternative content when player is not installed");
uniObj.write();

To call a function on a gameObject in unity we can use the following code:

uniObj.msg( "GameObjectName", "FunctionInGameObject", "ParameterToSendToUnity" );

All this does is calling a special function on the unityObject within your page called SendMessage(...); and delegates your call to the object and function which you described in the call. In case from above we will trigger FunctionInGameObject in GameObjectName. We can only pass 1 parameter to the triggered Unity function. The most advanced parameter you can use in this case is an array. Using an object isn't supported. So when you want to pass an object as a parameter you need to serialize and deserialize your object. This is however not supported by default in Unity. When you want to do this, you could use JSON for example, which is offcourse supported in javascript, but there are good C# libraries as well. Maybe I'll dedicate a future blog post to this.

Now we have successfully called a function in Unity, it's time to send something back to the browser. This is very simple as well:

//Unity3D js code:
Application.ExternalCall("javascriptFunction", "Parameter1");

//Javascript code in browser:
function javascriptFunction( param ){
 alert( param );
}

Instead of alerting the function call, we can send this parameter to Flash and show the value in a Flash text field for example. This requires just a 1 line more code compared to calling a Unity3D function. First we need to define in Flash which function are allowed to be called by the browser.

ExternalInterface.addCallback("functionNameInBrowser", functionNameInFlash );

Now we can call functionNameInBrowser by the browser on a Flash object, which calls functionNameInFlash in Flash. To achieve this I use the following code in javascript:

//Cross browser function to get a movie on a page.
function getFlashMovie(movieName) {
 var isIE = navigator.appName.indexOf("Microsoft") != -1;
 return (isIE) ? window[movieName] : document[movieName];
}

//Call function in flash
function javascriptFunction( param ){
 getFlashMovie('flashMovieIdOnPage').functionNameInBrowser( param );
}

By executing the code from above, the function functionNameInFlash will be called like a regular function call. A sample function might look like the following code:

function functionNameInFlash( param:String ):void{
 message.text = param;
}

This is all you need to communicate between a browser, Unity3D and Flash. Once you know this trick you can for example:

All examples are bundled in one download, which includes all the Unity3D, Flash, Flex, Actionscript and Javascript files.

I hope this will help anybody. Please let me know your feedback!

Sprite3D update

Since my last post about the Sprite3D object, I found out it wasn't working perfectly. It's behaviour wasn't constant when using different Papervision3D versions. Beside there where some small bugs in my code and I had to make it a bit more flexible to use.

  • Sprite3D doesn't correct rotations anymore by do3d.rotationX/Y/Z values, but based on Matrix3D information (Number one on my personal wish-list). Because of this change you're able to rotate the object on the x, y and z axis at the same time. Before, this would distort the sprite3D. This also solved some small unnoticed issues.
  • You're able to set it's "rotationAxis", which is the axis on which your materials in the materialsList are rotating. Before, this was only possible on the Y axis.
  • Compatible with all recent Papervision3D revisions. I've not tested this with all of them. It's developed using revision 651.
  • Compatible with new localRotationX/Y/Z, which is introduced since revision 651.

Wish-list:

  • Support animated textures.
  • Support multiple axis rotations with textures.
  • Support Sprite3D as a nested object (should be directly added to the scene right now).

It's probably gonna take a while, before these wishes can be implemented. So feel free to do it yourself :-)

Download the update here

Papervision3D “Sprite3D” object

[UPDATE] Added a yawing example to make more clear what's going on. [/UPDATE]

It's been quite a while since my last post. In between I've been on vacation for a couple of weeks and had some strong deadlines to deliver my daily work. I've many cool idea's to work out and write about on this blog. One of them is called a "Sprite3D", which name is based on Sprite 3D from Sandy.

The concept is that you'll have just a basic plane which is always faced up to the camera. Depending on the angle between a camera and a sprite3D object it will change it's texture. When you have for example 360 images of an object which rotates 360 degrees, you can show for each angle a different texture, which will give a 3D effect to this plane. This makes it possible to show advanced models without actually rendering them! Because it's all shown at a plane, it's all very light for your CPU.

I've put this all together in a class which extends DisplayObject3D. Working with this class is like working with standard objects like cubes or planes, so it's pretty straightforward like you will see in the following example.

 
var materialList:MaterialsList = new MaterialsList();
// angle range -45 (315)  - 45
materialList.addMaterial(new BitmapFileMaterial("assets/image1.png"));
// angle range 45 - 135
materialList.addMaterial(new BitmapFileMaterial("assets/image2.png"));
// angle range 135 - 225
materialList.addMaterial(new BitmapFileMaterial("assets/image3.png"));
// angle range 225 - 315
materialList.addMaterial(new BitmapFileMaterial("assets/image4.png")); 
 
//Just enter your materialList and dimensions
sprite3D = new Sprite3D(materialList,300,150);
//add sprite3D to the scene, like you would do with any object.
scene.addChild(sprite3D);

Depending on how many materials you'll add to the sprite3D it will automatically calculates on which angle it should change a texture. In case you'll add just one MovieMaterial to the materiallist, it will look at the number of frames within this MovieClip as your textures. This is especially useful when you have a 360 frames render of an object. You don't want to add 360 separate materials to the materiallist.

Below you'll find two working examples of a rotating car. You can change your position by using your arrow keys.


Same example, but with a yawing sprite3D:

I have to say this approach also has it's downsides:

  • You'll get bigger downloads, since you need to load image sequences.
  • You can't get too close with a camera, this will make it feel unnatural.
  • Only rotation on the Y axis is implemented. Implementing another axis will end up with an even bigger download (360*360 images if you want the best quality)
  • Animation of a texture should be possible, however you'll end up here as well with a big download.

Anyway, I think it's a very useful object type, below you'll find the source files. Hopefully it will also be useful for you. Let me know if you have any ideas of what to implement, how to improve performance or adjustments you did yourself. I would like to hear your feedback!

Downloads:


Example model used from Troyano

Alternativa3D 5.0 (Milestone 1)

A couple of months ago I accidentally found a demo of a AS 3D engine, called Alternativa. Alternativa is a project founded by the Russian company called “GRTOV Studio". Basically it is a full AS3 3D engine, with future multiplayer support.

They described Alternativa as:
Alternativa is a platform for creating, implementing and supporting multi-user browser media over the Internet. It consists of server core (data store and exchange, synchronizing, managing hardware load), clients part (3D-engine, GUI and other client apps), administrating part (integrated payment services, through user registration, statistics), documentation (”how to create and to manage projects” guide, public classes and methods description etc.), support system (developers portal, forum, FAQs etc.), and the applications made on a platform themself.

Alternativa Platform — simple and useful integrated development tools, world editors, free to use resources (game objects logic modules, textures, sounds etc.). Platform takes care of data storing and user data synchronizations, gives development methodology and hosting, shares its community, supports projects at all their stages.

Every company or end-user will be able to create personal 3D-world and to fine tune it according to own goals and preferences. We aim to give talents an opportunity to develop, to give developers tools to create great projects, to let business to market their goods and services through their own innovative personalized multy-user media.

Once in a while they post a new demo online, to show the world their progress. All of those demo's are pretty amazing, but their last demo (called Alternativa3D 5.0 (Milestone 1) ) which is posted today really rocks! It has a great performance and a good level of detail for this size of the scene!

Alternativa3D Bunker Alternativa3D Temple



Unfortunatly nothing can be found if the source code will go public soon, or if it will be open sourced at all. For now we just have to wait and see and be blown away by their impressing examples.

Paperworld 3D v0.1 released!

Go check out yourself: http://www.paperworld3d.com

Later on this weekend, I'll post my thoughts and examples about this very promising project!

[Update 2008-04-06]
During this weekend I've been looking into the source code. It's all well organized and Trevor Burton did an excellent job!
Since it's a first release, without any tutorials yet, it is kind of hard to get it all running right now. Errors found in the project could mean that I've misconfigured something, or that I've found a bug.
Trevor showed his will to help me out which I really appreciate. As soon as I have some working examples I'll write down my experiences on this blog.