three.js JsonAjaxloader回调无法正常工作

时间:2014-09-18 13:48:24

标签: three.js

这是json loader

的原始加载方法
THREE.JSONLoader.prototype.load = function ( url, callback, texturePath ) {

    var scope = this;

    // todo: unify load API to for easier SceneLoader use

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

    this.onLoadStart();
    this.loadAjaxJSON( this, url, callback, texturePath );

};

和jsonAjaxloader构造函数

THREE.JSONLoader.prototype.loadAjaxJSON = function ( context, url, callback, texturePath, callbackProgress )

这是我加载模型的代码:

this.loadModel = function()
    {   
        this.loader = new THREE.JSONLoader(true);
        //this.loader.loadAjaxJSON(this.loader, this.pathToFile, this.pathToFile, this.createMesh.bind(this), false, function( progress, result ) { console.log((progress.loaded / progress.total * 100).toFixed());}); 

        this.loader.load(this.pathToFile, this.createMesh.bind(this) ); 
        this.loader.onLoadComplete = this.createMeshComplete.bind(this);
    }

现在这就是问题所在: 我尝试使用JsonAjaxloader,因为我想创建loadinBar我想知道progres加载。

当我为此添加cament时

this.loader.load.......

并从此

删除coment
this.loader.loadAjaxJSON

我有错误

 callback is not a function

但我们可以看到,使用jsonajaxloader的load方法并给作为参数的回调没有改变,当我编辑load方法的代码并添加一个变量 这是编辑:我添加callbackProgress

THREE.JSONLoader.prototype.load = function ( url, callback, texturePath, callbackProgress ) {

    var scope = this;

    // todo: unify load API to for easier SceneLoader use

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

    this.onLoadStart();
    this.loadAjaxJSON( this, url, callback, texturePath, callbackProgress );

};

并在我的代码中更改一行 从这个

this.loader.load(this.pathToFile, this.createMesh.bind(this) ); 

到这个

一切正常。

this.loader.load(this.pathToFile, this.createMesh.bind(this), false, function( progress, result ) { console.log((progress.loaded / progress.total * 100).toFixed());} );

请帮助!!我对jsonajaxloader

做错了什么

0 个答案:

没有答案