I have a JSON file (map.js) from which I load my geometry and material settings (this is a file I generated, and it is too large for me to manually edit it). It looks something like this:
"materials": [ {
"DbgColor" : 2632490,
"DbgIndex" : 0,
"DbgName" : "ASPHALT_0"
},
{
"DbgColor" : 16777215,
"DbgIndex" : 1,
"DbgName" : "ROAD_MARKING_DASHED_0"
}],
"vertices": [-370.412496,0.000000,120.194495...
"morphTargets": [],
"morphColors": [],
"normals": [],
"colors": [],
"uvs": [[]],
"faces": [2,0,1,2,0...
Note for faces format: triangle with material
I'm loading this file like this:
var loader = new THREE.JSONLoader();
loader.load("map.js", function(geometry, materials){
mesh = new THREE.Mesh( geometry, new THREE.MeshFaceMaterial(materials));
scene.add(mesh);
loadRestOfScene();
});
What I want to do is to add a texture to a specific material in my materials array. Something like:
materials[i].map = THREE.ImageUtils.loadTexture( 'road.jpg' );
But when I load my page I get this warning:
[.WebGLRenderingContext]GL ERROR :GL_INVALID_OPERATION : glDrawElements: attempt to access out of range vertices in attribute 2 index.html:1 WebGL: too many errors, no more errors will be reported to the console for this context.
I've read similar questions (and answers) here, and tried to do:
materials.needsUpdate = true;
geometry.buffersNeedUpdate = true;
geometry.uvsNeedUpdate = true;
But this doesn't change anything. Is it even posible to add a texture to a material that doesn't have it initially? Or am I doing something wrong here?