Flash and JavaScript 3D with Sandy-HX - Loading a Model

Article by Matthew Casperson (4,877 pts ) , published Jul 9, 2009

This tutorial will show you how to load a 3D model and display it using Sandy-HX.

While it is possible to create a number of basic shapes like boxes, cones and spheres with Sandy-HX, anything more complicated is almost always going to have to be loaded from a file created by an external 3D modelling application. Fortunately, Sandy-HX has the ability to load these files and display them in the 3D scene.

This tutorial will look at the process of loading and displaying a Collada file. Collada is an open XML based 3D format, and Collada files have the dae extension.

First we need to load the Collada file. Loading is done asynchronously, meaning that the actual process of loading the file is done in the background while the main program continues on. Normally this allows you to set a file to be loaded, continue on with the application, and then perform an action when the loading is finished. We don’t really want to run our 3D application while the 3D models are being loaded in the background – the whole point of the application is to display the models held in these files, so until they are loaded and ready there isn’t much the application can do.

In practical terms this means that we don’t want to initialize the ApplicationManager or enter the render loop until the resources have been loaded. The EngineManager has been modified slightly to implement this.

EngineManager.hx

Previously the Sandy-HX engine was initialised, the ApplicationManager started and the set to run in the EngineManagers constructor. Now we initialise the Sandy-HX engine and then create a new instance of a class called ResourceManager. The ResourceManager is responsible for loading the resources, and when done it will call either the EngineMaangers resourcesLoaded or resourceLoadError functions, depending on whether or not all the resources successfully loaded. You will see that it is only once the resourcesLoaded function has been called that the ApplicationManager is started and the render loop set to run. [code]

This change ensures that any object created by the ApplicationManager can access the resources loaded by the ResourceManager without having to worry about the asynchronous nature of the loading process.

Subscribe to Web Development
RSS
Get free weekly updates, directly to your inbox.
Browse Web Development