ColladaLoader and progressCallback

故事扮演 提交于 2019-12-11 01:19:43

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!