1

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?

Marko Letic
  • 2,460
  • 2
  • 28
  • 34
  • Make sure you have UVs and read http://stackoverflow.com/questions/16531759/three-js-map-material-causes-webgl-warning/16533812#16533812. – WestLangley Dec 19 '13 at 17:06
  • As you can see from my question, I've read that post, because I've tried to do what you said (I quote): "Alternatively, you can begin with a textureless material, and then set the following flags when a texture is added..." And I don't have UVs because the code that generates my JSON file doesn't creates UVs, and that is something that I can't change. – Marko Letic Dec 20 '13 at 12:31
  • If you don't have UVs, then why are you trying to add a texture? – WestLangley Dec 20 '13 at 14:51

1 Answers1

0

You need to specify which material needs an update

materials[i].needsUpdate = true;
Gero3
  • 2,817
  • 1
  • 22
  • 21