Posts Tagged ‘AS3’

Sunday, February 27th, 2011

Flash Molehill is coming and Unity will be targeting it for export.  Unity states that they will allow it as an export option just like there are mobile options for iOS and Android.

These are exciting times. Today, at the Flash Gaming Summit in San Francisco (of which we’re proud Gold Sponsors), Adobe has announced the public availability of a beta version of the Flash Player, codenamed Molehill, that has a very interesting new feature: hardware accelerated 3D support.

Molehill exposes a very low-level shader-based interface to the graphics hardware. Adobe has decided to focus on that low-level part, and do that really well. The molehill pre-release will not be shipping with a 3D engine, scene building tools, model and animation importers / exporters, physics, lighting or lightmap creation tools, etc.

The article states that Unity will be keeping the Unity Player and the developer will decide when to target Flash or Unity Players or other platforms like desktop, mobile that are currently available and use the rendering platforms that work best with each (DirectX/OpenGL/OpenGL ES/Molehill… maybe WebGL in the future).

There is no announcement of a date but Unity is pretty fast to add updates and new platform versions so if they take this on they will ship. Currently they mention using Unity and coding with AS3 within Unity script or using Mono.NET C#/Javascript/Boo as currently used. An intersting option is using Unity to create content and code in C#/Javascript over AS3.

Unity addresses these issues here:

Q. Is this the end of the Unity’s own Web Player?

Absolutely not. The Flash and Unity Web Players both have their strengths.  We’re excited by the opportunity to target the Flash Player and all of its features with Unity, but there will be plenty of experiences that the Unity plugin is better suited for. It will be up to developers in the end, to decide whether they want to target only the Flash Player, only the Unity Web Player, or some combination of the two (now things are getting interesting!)

Q. What programming language will I use?

You’ll have two options:

  1. For people with a Flash background:
    Target our ActionScript API directly from Flash. Think:
    var go:GameObject = new GameObject(“Just normal ActionScript 3 code”);
  2. For people with a Unity background:
    Script your content in C# / JavaScript / Boo, like you’re used to, and have Unity automatically translate it to ActionScript when you hit publish.

Adobe is good to move to a model where hardware acceleration is part of the platform.  Since Molehill is low level and competing products like Unity, WebGL, and others would take that in time, opening it so others can build tools on their platform will attract interesting new developments like this.

Sunday, July 25th, 2010

Alessandro Pignotti’s project looks to be the start of something good to come. Lightspark Open Source Flash Player [github]has some really nice features that should influence the Flash Player and maybe even draw some interest from Adobe?  Maybe it can be like the Moonlight player for Silverlight only broader.

One such awesome feature is OpenGL GLSL hardware rendered shaders for elements of flash. Flash has Pixel Bender which is pretty nice but having GLSL shaders and the use of OpenGL directly is great.

Features

  • JIT compilation of ActionScript to native x86 bytecode using LLVM
  • Hardware accelerated rendering using OpenGL Shaders (GLSL)
  • Very good and robust support for current-generation ActionScript 3
  • A new, clean, codebase exploiting multithreading and optimized for modern hardware. Designed from scratch after the official Flash documentation was released.
Wednesday, January 27th, 2010

Tim Knip, a papervision core developer, has brought a pipeline improvement for users of Blender to import blender files directly into papervision and as3. This allows you to get at the blender objects, or blender DNA as it is called, that construct the 3d scene within Blender.

Unity3D has a great workflow that includes this where you can update your .blend file and then it updates in the Unity IDE, this work by Tim creates a similar workflow for Flash (recompile would be needed to show if embedded).

Typically exporters are made from the 3d IDE SDKs such as Blender using Python to export to COLLADA or other formats.  But here Tim is parsing the source file directly.  This also opens up the possibility to make other exporters from more simplified Flash AS3 code rather than learning a new IDE SDK just for an exporter.

I am not sure how much people want to embed .blend files with their applications as there is more information in the .blend file for the Blender app and it will add to the download.  But what this might do it inspire others to create simplified exporters from Tim’s work for Blender to COLLADA, 3ds and more that work well with papervision and flash 3d engines, directly in Flash.  So instead of learning each IDE to build an exporter that is the same, this solution could act as a proxy or middle man to simplify exporter creation, pretty much any Flash coder that understands 3d could build one from .blend files at a minimum.  If it was made as a higher level abstraction so the 3d software source could be swapped out it may open up simplified exporter tools a bit.  Since it is really just reading the binary data in the file, in theory other formats could do the same (3dsmax, Maya, Milkshape, etc).

There is a whole host of opportunities with this new tool! It is definitely nice to have this as I use Blender for Flash 3D and Unity 3D most often.  It will be interesting to see how this evolves.

Note from Tim on the tool:

I created a library to read Blender files (.blend) directly. So no
more headaches with broken exporters!

Grab the code here:
http://github.com/timknip/asblender/tree/papervision3d

Here’s a first example:
https://dl.dropbox.com/u/438592/blender/PapervisionTest.swf

And its code:
http://github.com/timknip/asblender/blob/papervision3d/src/PapervisionTest.as

ASBlender is simply a library which reads *everything* in a .blend file. So in theory you could grab materials, animations, armatures, the works… But its up to *you* to grab the relevant bits, since *all* the data is accessible.

Of course: this means you need to study the .blend format, see
http://wiki.github.com/timknip/asblender/ for more information.

Sample Code Snippet posted by Tim:

[Embed (source="/assets/crystal_cube.blend", mimeType="application/octet-stream")]
public var BlenderData:Class;

var blend:BlendFile = new BlendFile();

blend.read(new BlenderData());

if (blend.scenes.length) {
    // Blender can have multiple scenes, don't know yet how to grab the "active" scene.
  buildScene(blend.scenes[0]);
}

/**
 * Prints out the DNA as contained in the .blend
 */
private function printDNA(blend:BlendFile):void {
  var struct:DNAStruct;
  var field:DNAField;

  for each (struct in blend.dna.structs) {
    var type:String = blend.dna.types[ struct.type ];

    trace(type);

    for each (field in struct.fields) {
      trace(field.type + " " + field.name);
    }
  }
}

private function buildScene(scene:Object):void {

  var obj:Object = scene.base.first;

  while (obj) {
    // grab the Blender Object.
    // The Blender Object defines rotation, scale, translation etc.
    var object:Object = obj.object; 

    trace("Object name: " + object.id.name + " type: " + object.type + " matrix: " + object.obmat);

    //for (var key:String in object) {
    //  trace(key);
    //}

    if (object.data) {
      switch (object.type) {
        case 1:  // Mesh
          trace (" - Mesh: " + object.data.id.name);
          buildMesh(object.data);
          break;
        case 10: // Lamp
          trace (" - Lamp: " + object.data.id.name);
          break;
        case 11: // Camera
          trace (" - Camera: " + object.data.id.name);
          break;
        default:
          break;
      }
    }

    obj = obj.next;
  }
}

private function buildMesh(mesh:Object):void {
  var numVertices:int = mesh.totvert;
  var numFaces:int = mesh.totface;
  var i:int;

  trace(" - #verts : " + numVertices);

  for (i = 0; i < numVertices; i++) {
    var v:Object = mesh.mvert[i];

    var x:Number = v.co[0];
    var y:Number = v.co[1];
    var z:Number = v.co[2];

    trace(" - - vertex: " + x + " " + y + " " + z);
  }

  trace(" - #faces : " + numFaces);

  for (i = 0; i < numFaces; i++) {
    var f:Object = mesh.mface[i];

    var v1:int = f.v1;
    var v2:int = f.v2;
    var v3:int = f.v3;
    var v4:int = f.v4;

    trace(" - indices: " + v1 + " " + v2 + " " + v3 + " " + v4);

    if (mesh.mtface) {
      // UV coords are defined
      var tf:Object = mesh.mtface[i];

      trace(" - - - uv: " + tf.uv);
    }
  }
}
Monday, October 5th, 2009

Well good news for Flash developers, Flash CS5 will finally compile to native iPhone and Touch Applications. This is great news for many developers out there who have stuck with the Flash platform.  I am sure there will still be limitations to what you can do with Flash on the iPhone and it will probably be mostly 2D games and apps but this is a great start to getting the Flash platform truly mobile and up to the rest of the industry.

Flash Professional CS5 will enable you to build applications for iPhone and iPod touch using ActionScript 3. These applications can be delivered to iPhone and iPod touch users through the Apple App Store.*

A public beta of Flash Professional CS5 with prerelease support for building applications for iPhone is planned for later this year. Sign up to be notified when the beta starts.

I have been questioning why they have not moved to this model before when others are doing so such as haXe, Unity3D and MonoTouch.  Getting Flash on the web browsers on a mobile is hard because Flash is pretty CPU intensive on embedded devices which is really where computers were in the late 90′s and close to 400-600 MHz processors.  Today these machines wouldn’t be able to run Flash very well and that is the same effect you get on a mobile phone.  But cross-compiling to native, similar to how Unity 3D does it or other solutions like MonoTouch and XNATouch, this is the best solution until mobile/embedded devices have 1GHz processors and more than 500MB of memory. Adobe is using LLVM, much like the Alchemy model, to achieve getting AS3 content onto an iPhone/Touch with AOT or Ahead of Time compilation rather than JIT compilation.

So how do you build an application for the iPhone? It’s simple, really. The forthcoming beta of Adobe Flash Professional CS5 incorporates the ability to create an iPhone application. You have access to nearly all the AIR 2.0 and Flash Player 10.1 APIs. For example, you can use APIs such as RTMP, Remote Shared Objects, and AMF as well as AIR APIs like SQLite and filesystem access. For more information see the developer FAQ on Adobe Labs.

I am glad to see Adobe finally moving on mobile platforms beyond Flashlite.  Flashlite is a poor solution in most cases on embedded devices because they really need native apps to perform, again due to the hardware limitations and it is a whole new platform to learn. Adobe is doing the hard work to make it easy to get developers content on the new embedded devices that are storming the world such as the iPhone and Touch.

Wednesday, September 9th, 2009

Claus Wahlers has a great post on some lower level Flash handling for shapes.  He posts about a tool called as3swf which helps to look into the raw shapes and vector drawing calls in the flash engine.

The output of this tool gives the raw machine code/assembly like procedural output that is very similar to other rendering engines. It actually makes me think of OpenGL a bit in the output switch based, procedural flow except this if for vector drawing rather than raster.

Sample output

[83:DefineShape4] ID: 1
  FillStyles:
    [1] [SWFFillStyle] Type: 0 (solid), Color: 666666
  LineStyles:
    [1] [SWFLineStyle2] Width: 200, Color: ff0000
  ShapeRecords:
    [SWFShapeRecordStyleChange] MoveTo: 400,400, FillStyle1: 1, LineStyle: 1
    [SWFShapeRecordStraightEdge] Horizontal: 2000
    [SWFShapeRecordStraightEdge] Vertical: 2000
    [SWFShapeRecordStraightEdge] Horizontal: -2000
    [SWFShapeRecordStraightEdge] Vertical: -2000
    [SWFShapeRecordEnd]

It is always good to know what is going on in lower levels to better code for projects that perform well.  Another great post on this is the Elastic Racetrack of the AS3 and AVM2 virtual machine which describes how the AVM2 handles drawing those low level shape calls in addition to handling script.

Wednesday, July 8th, 2009

AIR is very popular for creating twitter clients, Sönke Rohde just made it much easier to make AIR apps for twitter with an AS3 library for Twitter. This library is built on top of core oauth as3 library by iotashin.  Core OAuth as3 library is a standard OAuth library this can be used for your own OAuth backends or connecting to other OAuth services as well.

A very nice feature of this library, in addition to being coded cleanly and as3 style, is the ability to have the Twitter OAuth page render inside of Flash.

Instead of opening the Twitter authorization page in the browser the library also contains OAuthLoader which is a wrapper around HTMLLoader which enables to directly show the authorization page within an AIR window:

// use this in the requestTokenHandler instead of navigateToURL
var loader:OAuthLoader = new OAuthLoader();
loader.load(request);
loader.percentWidth = 100;
loader.percentHeight = 100;
var w:Window = new Window();
w.width = 800;
w.height = 400;
w.title = req.url;
w.addChild(loader);
w.open();
Friday, June 19th, 2009

haXe is an interesting programming language that allows abstracting the source from platform target.  It outputs for targets such as Actionscript and Javascript from haxe language source. But, haXe can also output to native code to run on Windows, Mac OSX, and Linux.

Well because of this it is possible to run haXe on the iPhone. The gamehaXe site has found a way to get haXe to compile to iPhone via hxcpp which creates a C++ output from haXe code very similar to Actionscript 3.

I am a bit late to the party but this is great news. It uses the NME library which will allows code to mostly be written to the Flash 9 API and create the C++ for XCode to compile and run on the iPhone and Touch. This creates a path to port Flash games to iPhone/Touch.

This project is one to watch and participate in.  Native compilation to the iPhone from haXe is a more simplified code to write in while providing lower level performance which is needed on mobile devices, as processors, cache and ram are much lower than desktop and below what is capable of running the Flash AVM2 currently.

If you have more interest in haXe there are some other great demos on as3/haXe at the game haXe site. Also, Tony at touchmypixel.com has posted some very useful information to help you get started with hxcpp.

The hxcpp project is a newer output target along with a java one but this could be interesting if actionscript like code and many libraries like Physaxe or AS3 libraries could be ported to haXe to output to the iPhone.

Sunday, June 14th, 2009

Rozengain or Dennis Ippel of AKQA updated probably one of the tools I use the most for flash 3d and that is the blender to as3 exporter.  This simplifies loading in the meshes you have and lessens the bulk of the COLLADA format.  COLLADA is great but flash is still client side and fairly memory intensive for 3d so loading in models directly to as3 is nice if flash is your presentation tool.

AS3 Blender exporter has been updated to allow multiple object export. Also in April is was updated to export quads and modifiers.

One concern you might have is statically binding the code within a main swf fileon compile and resulting file size compared to loading in the DAE dynamically.  But you can just load these in as you would external DAE COLLADA files as compiled swfs and since it is just code it is very compact.   This adds some duplication of code (such as tweening libraries or the 3d engine source as needed) but allows a more horizontal loading or lazy loading of meshes when needed.

This is just another option to get 3D models into the flash 3d engine of your choice in addition to COLLADA, some MD2 support and limited ASE support.

This is an awesome project that keeps getting better, thanks Rozengain.

Friday, May 22nd, 2009

Flash 10 will be ready for mainstream hopefully by the end of this year, or early ’10 when the penetration numbers will be up in or around the 90% range via zeh fernando based on previous trajectories.  

With that, Flash 10 has many great new things such as the Vector structure that allows a collection of a certain type, which results in a faster collection because of the known type.  So anywhere where Arrays are used, that is a possible candidate for a performance increase within some code because you are asking the virtual machine to do less work on each loop (not having to dynamically find out the type).

ByteArray (Thibault Imbert) has demonstrated that for the JPEG encoding in corelib it is up to 2.5 times faster using Vectors than Arrays.  Your mileage may vary heavily but it is almost a guaranteed speed boost due to less work.  This obviously has great possibilities for speeding up code that uses lots of arrays.  

Due to the performance boost the Vector does have some constraints in the typical give and take of coder flexibility with compiler and virtual machine overhead.  Vectors are more explicit and strongly typed which is why they are fast, but this is also limiting.

In addition to the data type restriction, the Vector class has other restrictions that distinguish it from the Array class:

  • A Vector is a dense array. Unlike an Array, which may have values in indices 0 and 7 even if there are no values in positions 1 through 6, a Vector must have a value (or null) in each index.
  • A Vector can optionally be fixed-length, meaning the number of elements it contains can’t change.
  • Access to a Vector’s elements is bounds-checked. You can never read a value from an index greater than the final element (length - 1). You can never set a value with an index more than one beyond the current final index (in other words, you can only set a value at an existing index or at index [length]).

 [ Vector docs  ]

ByteArray not only used Vectors heavily but did other optimizations that are always good to do, even though optimization is evil when you are working with precious client side resources ensuring an optimized base starting point can be a good thing.

So what did I do ?

  • I used bitwise operators as much as possible.
  • I replaced all Arrays with fixed length Vectors.
  • I used pre-incrementation rather than post-incrementation (thanks Joa for this one ;)).
  • I casted to int all my Vector indices access.
  • Other minor stuff you always do to optimize your code 

Other sources as well for even more optimization or shall I say efficient AS3:

Monday, May 18th, 2009

pyamf is pretty sweet for Flash remoting with Pythonic server side, but now we have two nicely done and integrated remoting kits for python on the server side.

amfast is a new remoting library  that looks to be as sweet as pyamf (where sweet == fast and useful).  I am checking out amfast now but the speed boost alone might be worth it.  For instance, working with real-time games, when you need static content you need to grab that quickly sometimes via a content service.  The faster that link the better. It also has Twisted integration which is great for networking and SQLAlchemy integration which is in my opinion the best ORM for python (pyamf has twisted, django, pylons, sqlalchemy as well)

amfast is well documented and has some great examples.  If you have the Python addiction, check it.

Description

  • AmFast is a Flash remoting framework for Python.
  • AmFast can use AMF to communicate between Python and Flash, Flex, and any other system that supports AMF.
  • AMF is a binary object serialization protocol used by Actionscript based applications.

Server Features

  • Support for NetConnection and RemoteObject RPC.
  • Support for Producer/Consumer ‘push’ messaging with HTTP polling, HTTP long-polling, and real-time HTTP streaming channels.
  • Support for authentication with NetConnection and RemoteObject.
  • Flexible Target mapping system to map message destinations to invokable Target objects.
  • Support for ChannelSets with multiple Channels to expose resources in different ways.
  • Built in Channels for CherryPy, Twisted Web, and plain WSGI.
  • Support for configurable Endpoints. Use AmFast’s built-in AMF encoder/decoder C-extension, or use an external AMF encoder/decoder, such as PyAmf for a pure-Python implementation.

AMF Encoder/Decoder Features

  • AMF0/AMF3 encoder/decoder written in C as a Python extension for speed.
  • More than 10x faster than the PyAmf encoder/decoder (even when using PyAmf’s optional C-extension).
  • Map custom classes with ClassDef objects for complete control over serialization/de-serialization.
  • Full support for IExternalizable objects.
  • Data persistence with SqlAlchemy including remotely-loadable lazy-loaded attributes.
  • Actionscript code generation from ClassDef objects.