THREE.js加载程序回调无法在真实服务器上运行

时间:2017-01-01 15:50:31

标签: javascript callback three.js

首先,这是我所指的代码:

    ObjMtlLoad: function (path, objName, mtlName, context, rotateRads = 0) {
    console.log("Loading...");
    //declare callback function for printing out download progress
    var onProgress = function (xhr) {
        if (xhr.lengthComputable) {
            //calculate and output progress
            var percentComplete = (xhr.loaded / xhr.total) * 100;
            console.log(Math.round(percentComplete, 2) + "% downloaded " + objName);
            if (xhr.loaded == xhr.total) {
                console.log("loaded");
                $("#loadingDisplay").css({
                    opacity: 0
                });
            }
        }
    };
    //declare callback function for when an error occurs
    var onError = function (xhr) {
        console.log("Error: " + xhr);
    };

        //instantiate a MTLLoader object
    var mtlLoader = new THREE.MTLLoader();
    //set the base path
    mtlLoader.setPath(path);
    //load the mtl file
    mtlLoader.load(mtlName, function (materials) {
        materials.preload();
        //instantiate a OBJLoader object
        var objLoader = new THREE.OBJLoader();
        //apply the mtl file to the obj
        objLoader.setMaterials(materials);
        //set the base path
        objLoader.setPath(path);
        //load the objfile
        objLoader.load(objName, function (object) {
            //set position to the center
            object.position.set(0, 0, 0);
            //rotate if requested
            object.rotateX(rotateRads);
            //add to scene
            context.scene.add(object);
        }, onProgress, onError);
    });
}

应该发生的是onProgress函数被加载器调用并打印出当前进度,如果完成,则删除'加载'覆盖。在Brackets创建的本地调试服务器上运行时,这一切都正常,并生成以下输出: correct output

但是,当上传到我的Web服务器时,没有发生这种情况,所有内容实际上都是异步加载但没有任何内容被打印出来,并且回调看似根本没有被调用。即使内容已加载到其下方,也会导致“加载”叠加层保留。这是在服务器上查看时的控制台输出:

unexpected output

0 个答案:

没有答案