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

Written by:  • Edited by: Michele McDonough
Updated Jun 4, 2010
• Related Guides: Javascript

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.

Showing page 1 of 2

Comments

Showing all 2 comments
 
Matthew Casperson Aug 31, 2010 4:44 AM
RE: Flash and JavaScript 3D with Sandy-HX - Loading a Model
Yeah, the JavaScript versions have slowly stopped working in newer browsers. Unfortunately the JavaScript version of Sandy has not been kept up to date. It's a tick in Flash's box that those demos still work.
Another Dude Aug 31, 2010 4:12 AM
Nice but
Thank you for all the tutorials you have writtem, I've enjoyed most of them.

I've tested the JS version in Chrome and FF and it doesn't display mate. (Chrome 7, FF 3.6.8)

I can see the Flash version :)
 
blog comments powered by Disqus
Email to a friend