Jump to content
  • Advertisement
Sign in to follow this  
davidqueen

Problems with textures in ThreeJs

This topic is 638 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!