For a simple 3D-a-like movement or interface, you don't necessarily need a 3D engine. Consider using a multiplane engine in fake 3D for simple things like these for example:
On Kirupa.com, this technique was introduced years ago, with source code and all.
Anyway, I quickly put the code in AS3-classes to make it up-to-date. Download the sources here.
[UPDATE 28 October] I've re-arranged the class responsibilities and I think things are a lot more logical now. A little explanation is also in place. To set up a simple3d world (check out the document class), you need 4 things:
- a camera
- a scene
- a cameracontroller
- a list of objects that can be added to the scene
The implementations of the camera, the cameracontroller and the displayable objects are replacable because these objects are typed to interfaces. A specific implementation of a IMultiplaneCamera determines the rendering of the IMultiplaneObjects in the scene. An ICameraController takes care of the control and the movements of the IMultiplaneCamera. By replacing one camera controller by another, you get a different kind of movement in the "world".
[UPDATE 7 November] Check out the document class (set via the properties panel) to find out how to setup a "3D" world (in the init function of the Simple3dTest class). Also note that the class be.novio.simple3d.Figure relates to a MovieClip symbol that comes from the library.
Objects that are being put in the scene shouldn't necessarily have to be all visual objects. For example, it's possible to put objects emitting sound in the scene and by playing with volume and pan, it's possible to simulate the distance of the sound to the camera.
Please note that this sample's merely a starting point, meaning to be elaborated in specific Flash projects with custom camera, camera-controllers, scene objects and stuff. Maybe I will expand the class package with the newly available 3d features in Flash 10. To make the objects rotateable for instance. Well, we'll see...
[UPDATE 8 November] You can make individual objects move in the "3d" scene by manipulating its properties xpos, ypos & zpos. By doing so, the camera will render the objects accordingly. This means that it's useless to adapt properties x, y, xscale or yscale because the camera will reset those properties everytime it renders.


9 Comments
I’ve been trying to adapt the kirupa as2 (beautiful descriptions and explanations) version for use in a as3 project I’m doing and was tearing my hair out when I finally decided to go see if there was anything new for this in as3 – VOILA –
BUT – just downloading the source files doesn’t create anything on my stage, even when I import “be.novio.simple3d.*” – I couldn’t find anything like the dosumentation yuo had on the as2 version, or the “little explanation” – do you have a little something for this AS3 version? At least enoughto get some objects on the stage and start figuring out how to move them around?
I’ll start regrowing my hair when I can actually move something in “3D” space as3.
Randy, take a look inside the Simple3dTest document class. The init function contains the necessary lines of code to setup the “3D” space.
Thanks for your remark, I’ll add some more explanations soon.
Thanks. I was experiencing some class path issues. But now I have another question for you.
My goal is to populate the scene with several different multiplane objects, but to be able to move them in “3D space” separately by toggling their 3D capability through a mouse click. I.e. if you click it you can move it. If you click somethng else, that’s what moves, etc. But I’m not seeing a place where I can target/isolate the objects individualy to the camera. Would I have to make several different camera/scenes (1 cam to 1 object) and “activate” them separately? Or is there a way to “switch” the camera “focus” from one object to another?
To Randy: see update of 8 November. Suggestion: if you want to make objects draggable, you could make the camera ignore that specific object while you’re dragging it around, no?
Again, thanks for that clarification. But I’m not looking to make an object “draggable” . More like I want to make that object the target of the move action in the 3D space while any other objects in the scene remain where they are. SO I guess I meant “activate/deactivate” for receiving/doing the 3d movement. If I click(select) object A, object A is what receives the movement directions from the pressed keys, all other objects sit still. If I click on Object B, object A is “deslected” and Object B is “selected” meaning it is now the object that receives the 3d movement.
Does that make more sense?
BTW – what did you mean by ” make the camera ignore”?
Addendum:
Maybe you’ve tumbled to the fact that I’m not at my strongest working with Classes, but Iit looks like it would be possible in the “MultiplaneScene” class to add a var to hold a number, so that instead of looping through the objecstInScene array during the refreshScene() function, it could take a number variable and use it to select the index number of the object so that only it was “seen” by the 3dCamera.
Like: just below the var to instaniate the objectsInScene array, another var could be added:
private var num:Number
and then, when user clicks/selects the object on the stage, it’s array index number could be retreived and then passed like “num=2″ ( 2 being the index of the “selected” object to be “moved” (i.e. the third item in the objectInScene array)
so when the function gets called it gets “num” passed in like
“refreshScene(num)” – so the renderObject would be calling:
cameraView.renderObject(objectsInScene[2] as IMultiplaneObject)
But I’m unsure about how to set/pass the num vasriable:
SInce “refreshScene()” is a protected function – how/where would I be able to establish the num var value and pass it to refresh scene?
Those bald spots are starting to grow back. And some things are starting to become clearer.
I tried a “hack” that seems to be working, but I’m sure there’s a more elegant way to do what I tried to explain in my last post. I’d love to see it, or if I figure one out, I’ll post it.
In the meantime:
The hack is simply to create another figure class (I used “figure2″, etc) for each different/new object that you want to be able to independently identify and add it to the array. Give it some coordinates and it shows up on the stage along with how ever many others you create. Since they’re part of the array and I haven’t figured out how to restrict the refreshScene() function to individual objects by their index, the directional buttons still control them all. You can disable that if you want to, and/or you can also add click “lsteners” to each when instantiated and set up some ID convention (I used .name) to pass the ID of the clicked object. Then you can tween or jump that object to a new set of coordinates with a button or whatever you want to trigger the move with. Like I said, it’s a hack and I’m pretty sure someone with better classes/scripting skills could do this more elegantly, but if anyone want’s to see what I did code-wise, just say so.
Meanwhile, Hans, any thoughts on passing the index to refreshScene()?
Hans,
where is the AS3 equivalent of the AS2 panCamera() function?
Do we just replace the cameraView.x += 5; with cameraView.rotation += .1 in CameraController.as?
Hi Hans. First up thanks for this taking the time to do this, great job on adapting the AS2 psuedo 3D engine to AS3!
I’m looking at the feasibility of implementing this engine in conjunction with a tweening library to create a navigation system and initial tests are looking good. I’ve just started the move to AS3 and am still getting my head around how to write/extend classes. One question if you have time:
How would you go about extending the class to allow the cameraView.y property to be manipulated?