Graphics Reference
In-Depth Information
function
loadModelWithProgress(model) {
var deferred = Q.defer();
var jsonLoader = new
THREE.JSONLoader();
jsonLoader.loadAjaxJSON(jsonLoader,
model,
function(model) {
console.log("Loaded model
with progress: ", model);
deferred.resolve(model)
}, null,
function(progress) {
deferred.notify(progress)
});
return deferred.promise;
}
7. With these changes, we can now load the resources synchronously.
How it works...
To understand how this works, you have to understand what Q does. Q is a promises
library. With promises, you can replace the nested callbacks (also called the Pyramid
of doom at http://calculist.org/blog/2011/12/14/why-coroutines-wont-work-on-the-
web/ ) with simple steps. The following example for the Q site nicely shows what this
accomplishes:
step1(function (value1) {
step2(value1, function(value2) {
step3(value2, function(value3) {
step4(value3, function(value4) {
// Do something with value4
});
Search WWH ::




Custom Search