ColladaLoader和progressCallback [英] ColladaLoader and progressCallback

查看:153
本文介绍了ColladaLoader和progressCallback的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ColladaLoader中实现加载栏的正确方法是什么?

What is the correct way of implementing a loading bar in ColladaLoader?

源代码显示加载器采用三个参数.一个是progressCallback.

The source code shows that the loader takes three parameters. One which is a progressCallback.

progressCallback( { total: length, loaded: request.responseText.length } );

如果我调用progressCallback的函数来显示值,则total会显示为空,而loaded会增加到520万.

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);
}

如何使用ColladaLoader附加某种所加载元素的百分比?

推荐答案

ColladaLoader.js的源代码,看起来progressCallback函数检查您的字符总数 collada文件(5,200,000)和读取的字符量.

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是正确的,总计将仅显示在服务器或本地服务器上,如果作为文件打开则显示为null.这是因为Ajax向服务器发送了一个请求.

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.

这篇关于ColladaLoader和progressCallback的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆