Stack Exchange
geometry.materials[0][0].shading: Three JS property 0 is undefined
I would like to add some shading to my 3D model in Three JS.
I'm using this code:
var loader = new THREE.JSONLoader();
          loader.load("peer.js", createScene);

          function createScene( geometry ) {
            geometry.materials[0][0].shading = THREE.FlatShading;
            geometry.materials[0][0].morphTargets = true;

            var material = new THREE.MeshFaceMaterial();
            //var material =  new THREE.MeshLambertMaterial({color: 0|(0xffffff*Math.random())})                
            var cube = new THREE.Mesh( geometry, material );
            cube.scale.set(50, 50, 50);
            cube.position.z = -50;
            m.model.matrixAutoUpdate = false;
            m.model.add(cube);
            scene.add(m.model);
        }          

And I'm getting the error message 'Cannot read propery 0 of undefined'.
It has something to do wit this line:  geometry.materials[0][0].shading = THREE.FlatShading; 
And I think the [0][0] has to be changed in something else, only I don't know what because I don't know what [0][0] is standing for. Does someone know how to fix this problem?

Are you copying outdated code from the net -- or from an outdated book? Learn from the three.js examples that work with the current version of the library r.57.

Also you should create the material before modifying the shading or other properties. Now you are first setting properties, then creating a material and creating the mesh.
