0
votes

i created a scene in blender it contains some meshs with out materials then i exported it to collada, i load it to three.js scene with colladaloader everything is ok but when i put some materials to children using the following code :

        loader.load( "../models/islands/"+islandselected.getAttribute("data-model")+".dae", function(object){
        scene.remove("island");
        plane=object.scene;
        plane.name=islandselected.innerHTML;

        plane.traverse(function(child){
            if(child.children[0]){
                if(child.children[0].geometry){
                    console.log(child)
                    var t = new THREE.ImageUtils.loadTexture( '../models/islands/'+child.name+'.jpg' );
                    t.wrapS = t.wrapT = THREE.RepeatWrapping;
                    t.repeat.set( 50, 50 );
                    var ma= new THREE.MeshBasicMaterial( {map:t} );
                    child.children[0].material=ma
                }
            }
        });
        plane.scale.set(100,100,100);

        scene.add(plane);
    });

i get errors in console : [.WebGLRenderingContext]GL ERROR :GL_INVALID_OPERATION : glDrawElements: attempt to access out of range vertices in attribute 1 empcreator.jsp:1 WebGL: too many errors, no more errors will be reported to the console for this context.

1

1 Answers

0
votes
        var model,mat;

        var loader = new THREE.ColladaLoader();
        var lastTimestamp = 0;
        var progress = 0;

        loader.load( 'obj/mymodel.dae', function ( collada ) {

            model = collada.scene;

            model.children[3].children[0].material = new THREE.MeshPhongMaterial({map:THREE.ImageUtils.loadTexture('obj/images/myimage.jpg')}); 
            console.log(model.material);                
            model.scale.x = model.scale.y = model.scale.z = 0.10; 
            model.rotation.y = 0.80;
            scene.add( model );
         }

        //you will need to modify a little to work it, i took it from my old project