manbu
manbu

Reputation: 11

Three.js load large scene and ram full with 98%,how to control the memory

I want create a big scene use three.js.and it contain lots of objeccts.I use THREE.OBJMTLLoader to load 30 objects.each size of them is 4M.so it all calculate may 120M.but my computer ram were consume with 98% of 4G ram,the scene may consume 1200M ram. how it spend so much.Are there have some way to control the memory of webgl? My app carry out a function that control object showing by conditions in the scene,but if use scene.remove(obj),It can't release its ram.

for(var j=0;j<30;j++){
                loads.push(new THREE.OBJMTLLoader());
            }
            for(var i=0;i<10;i++){
                (function(){
                    var index=i;
                    loads[i].addEventListener( 'load', function ( event ) {
                        var object = event.content;
                        var minX,minY,minZ,maxX,maxY,maxZ;

                        object.position.normalize();
                        object.position.y = 0;
                        object.position.x = 1000+2200*index;
                        object.position.z = 400;
                        object.rotation.y=Math.PI*0.5;

                        object.scale.x=object.scale.y=object.scale.z=600;
                        scene.matrixAutoUpdate = false;
                        scene.updateMatrix();
                        groupobjs.push(object);
                      //  scene.add(groupobjs[groupobjs.length-1]);
                       // scene.add( object );


                    });
                    loads[i].load( 'obj/bieshu2.obj', 'obj/beishuhou.mtl' );
                })();
            }

Upvotes: 1

Views: 727

Answers (1)

mrdoob
mrdoob

Reputation: 19592

OBJMTLLoader is not very efficient. Try with OBJLoader instead. Ideally from the dev branch.

Upvotes: 1

Related Questions