mrdoob / three.js

JavaScript 3D Library.
https://threejs.org/
MIT License
99.63k stars 35.16k forks source link

JSON Loader - Texture Issue #1093

Closed yagiz closed 12 years ago

yagiz commented 12 years ago

Hi all,

This is my model: http://yagiz.me/model/zombi.js This is its texture: http://yagiz.me/model/zombi.png

And this is how I load it:

function loadModel() {
    var loader = new THREE.JSONLoader();
    var callback = function( geometry ) {
            var mesh = new THREE.Mesh( geometry, new THREE.MeshBasicMaterial( { map : new THREE.Texture( "models/zombi/zombi.png" ) } ));
        scene.addObject( mesh );
        };

    loader.load( "models/zombi/zombi.js", callback);
}

Model has a UV data but I can't see the texture. It's all black? What do you think?

chandlerprall commented 12 years ago

Are you calling renderer.render(); inside of a render loop (using setTimeout or requestAnimationFrame)? Three.js will show the model even as the material for it is being downloaded. During that time the model will appear black. The next call to render() after the texture is loaded will update the model.

yagiz commented 12 years ago

Yep.. BTW If I don't use any lights model couldn't be seen. You see it in action: http://yagiz.me/model/

alteredq commented 12 years ago
var texture = THREE.ImageUtils.loadTexture( "models/zombi/zombi.png" );
var material = new THREE.MeshBasicMaterial( { map : texture } ); 
var mesh = new THREE.Mesh( geometry, material );
chandlerprall commented 12 years ago

@yagiz what version of three are you running? Most recent (r46) now uses scene.add instead of scene.addObject. Using addObject can yield some interesting & non-desired results.

yagiz commented 12 years ago

@alteredq yay! It works now. But it doesn't seem to load the texture on local.

alteredq commented 12 years ago

https://github.com/mrdoob/three.js/wiki/How-to-run-things-locally