Sign in to follow this  

Problems with textures in ThreeJs

Recommended Posts

Hey, I'm rather new to ThreeJS and OpenGL in general. I am trying to load textures on to my models but it isn't quite working. i discovered that it is because of the behavior of Threejs, it only creates an object once and the textures are finished loading after the object is created. the solution is using a callback function in the loader.load() function like this.

var texture = loader.load('images/metalbox_full.png',function(texture){
			var skin = new THREE.MeshPhongMaterial({map:texture});
		        var obj = new THREE.Mesh(shape, skin);
		        scene.add(obj);
		        animate();
		        }

i found that writing an anonymous function for every object in my scene would become cumbersome so  i thought that i would do this:

var texture = loader.load('images/metalbox.png',loadMaterials(texture,shape));
.
.
.
.
var loadMaterial = function(texture, shape){
		var skin = new THREE.MeshPhongMaterial({map:texture});
		var obj = new THREE.Mesh(shape, skin);
		cube = obj;
		scene.add(cube);
		animate();
	}

but for some reason, this does not work!? the console give a warning :"  'map' parameter not defined"

could some one tell me why I'm getting this error. or tell me a better way to make sure all of the assets are loaded before rendering a scene.

all of the tutorials I've found are using revision r60-67. im using r83. plz help, thanks

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this