问题
What is the correct way of implementing a loading bar in ColladaLoader
?
The source code shows that the loader takes three parameters. One which is a progressCallback
.
progressCallback( { total: length, loaded: request.responseText.length } );
If I call a function for the progressCallback
to display the values, The total
shows up as null and the loaded
goes up to 5,200,000.
function(callback){
console.log(callback.loaded + ' / ' + callback.total);
}
How can I attach some sort of a percentage of the loaded elements using the ColladaLoader
?
回答1:
Looking at the source code of ColladaLoader.js
, it looks like the progressCallback
function checks the total amount of characters in your collada file(5,200,000) and the amount of characters read.
You can get a percentage by using
var percent = Math.round(callback.loaded / callback.total) * 100;
Your percentage is jumping from one number to another most likely because it is being called locally or part of the data is cached. If you run this from a server, your percentage will be updated gradually.
WestLangley is correct that the total will only show up on a server or local server and as null
if opened as file. This is because Ajax sends a request to the server.
来源:https://stackoverflow.com/questions/21655100/colladaloader-and-progresscallback