2013-05-08 88 views
0

正如我处理繁重的车型我想在加载JSON显示dynamicaly加载的百分比,所以我做了与loadAjaxJSON method一个粗略的测试...three.js所:JSONLoader + loadAjaxJSON

下装载的回报加载期间的百分比,但从未达到回调函数。

这是由于缺少声明,错误的上下文参数,到别的东西?我找不到有关这方面的文件。

var loader = new THREE.JSONLoader(true); 
loader.loadAjaxJSON(
      document,   // < context ?? 
      'try.js', 
      function (geometry, materials) { CreateScene(geometry, materials); }, 
      false,    // < texturePath 
      function(progress, result) { console.log((progress.loaded/progress.total * 100).toFixed());} 
      ) 

控制台:

7 13 20 .. 100 
TypeError: a.parse is not a function [three.min.js (ligne 204)] 

回答

4

有时候它的速度更快也窥视来源,而不是寻找文档。以下是JSONLoader的代码:https://github.com/mrdoob/three.js/blob/master/src/loaders/JSONLoader.js。 正如你所看到的上下文应该包含两种方法: parse和onLoadComplete。基本上你只需要发送loader作为上下文,查看loadAjaxJSON的快捷方式 - 方法加载。 关于texturePath,也是在方法的负载,你可以看到它看起来应该像:

texturePath = texturePath && (typeof texturePath === "string") ? texturePath : this.extractUrlBase(url); 

,如果你看的更深一些,你可以看到extractUrlBase将返回“./”所以你的情况你的代码应该是这样的:

var loader = new THREE.JSONLoader(true); 
loader.loadAjaxJSON(
     loader,   // context 
     'try.js', 
     function (geometry, materials) { CreateScene(geometry, materials); }, 
     './', // texturePath or loader.extractUrlBase('try.js'), 
     function(progress, result) { console.log((progress.loaded/progress.total * 100).toFixed());} 
     ) 
+0

那么我承认我还没有解码原型的水平..但这是一个很好的教训。非常感谢,它的工作原理。 – jeum 2013-05-08 11:11:05