Working on a video game, I am encountering memory issues. Specifically, when loading 8 object models, I find that I am repeating them throughout the game map. This results in me having to load the same model multiple times in different locations on the map like this:
new THREE.MTLLoader().setPath( './Tree/' ).load( 'untitled.mtl', function ( materials ) {
materials.preload();
new THREE.OBJLoader().setMaterials( materials ).setPath( './Tree/' ).load( 'tree.obj', function ( object ) {
object.scale.set(2, 2, 2);
object.position.set(10, 0, 30);
scene.add( object );
}, undefined, undefined );
});
By doing it this way, I realize that I am creating multiple instances of the same object in memory, leading to excessive memory usage. Is there a method to save only one instance in memory and call upon it whenever needed?
I tried looking for solutions online but could not find or understand any suitable fix.