Away3D is an incredibly complete, simple to use and powerful real-time 3D engine for AS3 (yes there are others, including Papervision). We’ve been playing with some 3D within AS3 for some time now, creating a complete pipeline from 3D application (Blender!) to Flash Pro CS5 and finally to Flash Player (or AIR).
During all of this, I recently hit upon a most interesting of problems, and that is: dynamically updating the scale/rotate/translate properties of an Object3D.
Object3D is, according to Away3D’s API documentation the base class for ALL 3D objects.
If one creates a simple primitive – a cube, in this case – and then, in the render loop, increment the rotateY property of our cube, then it spins, merrily.
Try this on an Object3D (where you’ve imported a COLLADA file, in our case) and nothing will happen. Zip. Nada. Bupkiss.
After many hours screaming “WHY!?”, coupled with Google searches aplenty and looking at the documentation, we couldn’t fathom the problem, let alone the solution. Here we have a primitive, the cube, which inherits Object3D’s properties and yet, all of these properties update very happily… and yet, the Object3D in itself, does not!?
If you check the Away3D tutorials, they have this one that demonstrates rotating objects (and counter rotating a cube)… so how did they do it? And why does our imported object not move?
The solution is crazily simple!
Create an ObjectContainer3D.
Add the Object3D as a child of the ObjectContainer3D.
Now alter the properties of the container and watch that Object3D spin as happily as our cube did.
If anyone out there knows why the first method doesn’t work, please let us know! But even looking through all the mailing lists and Google groups postings for Away3D, we couldn’t spot others either with the problem, let alone a solution. Maybe there are others out there, also unable to solve this… and if so, you’re welcome!