Three.js OBJLoader很慢

时间:2015-02-22 15:47:00

标签: javascript three.js

我使用OBJMTLLoader以obj格式加载一些模型,所有这些模型大约有8个模型,其中一些大小约为2.5 MB,这些模块需要很长时间才能加载到页面崩溃并按下等待多次加载,我在localhost上运行页面非常奇怪。 这是代码:

function loadobj(oid){
return function (object){
    var o=farr.filter(function(row){
        if(row.oid===oid){
            return true;
        }
        else return false;
    });
    for(var i=0;i<o.length;i++){
        var ob=object.clone();
        ob.position.x=o[i].x;
        ob.position.z=o[i].y;
        ob.position.y=0;
        ob.rotation.y=o[i].r;
        ob.userData.period=o[i].period;
        ob.userData.id=o[i].objid;
        ob.userData.oid=o[i].oid;
        ob.userData.level=o[i].level;
        ob.userData.status=o[i].status;
        ob.userData.consumedgold=o[i].consumedgold;
        for(var j=0; j<ob.children.length;j++){
            ob.children[j].userData.parent=ob;
        }
        scene.add(ob);
        objects.push(ob);
    }
    alert("loaded"+" / "+oid);
    document.getElementById("sload").innerHTML="Complete" ;
}
}

function setupobjects(){
    var ides=[];
    for(var i=0;i<farr.length;i++){
        var it=ides.filter(function(row){
            if(row===farr[i].oid){
                return true;
            }
            else return false;
        });
        if(it.length===0){
            ides.push(farr[i].oid);
        }
    }
    for(var i=0;i<ides.length;i++){
        var onProgress = function ( xhr ) {
            if (xhr.lengthComputable ) {
                var percentComplete = xhr.loaded / xhr.total * 100;
                document.getElementById("sload").innerHTML="All: "+ides.length+" Current Object: "+ (i)+" Percent: "+ Math.round(percentComplete, 2) + '% downloaded' ;
            }
        };
        var onError = function ( xhr ) {};
        THREE.Loader.Handlers.add( /\.dds$/i, new THREE.DDSLoader() );
        var loader = new THREE.OBJMTLLoader();
        loader.load( "resources/models/"+ides[i]+".obj", "resources/models/"+ides[i]+".mtl",  loadobj(ides[i]), onProgress, onError );
    }
}

另一个问题是:加载和渲染三种js Collada或Obj的最佳格式是什么?

0 个答案:

没有答案