2014-11-04 60 views
0

我想添加纹理到jsonloaded对象,由于某种原因不加载。添加纹理json不加载

的JavaScript

// Load in the mesh and add it to the scene. 
var loader = new THREE.JSONLoader(true); 
loader.load(jsonPath, function (geometry, materials) { 
    skateboardBase = new THREE.Mesh(geometry, new THREE.MeshFaceMaterial(materials)); 
    scene.add(skateboardBase); 
}); 

如果我删除了部分材料,事情没有纹理

JSON

"materials" : [ { 
     "DbgColor" : 15658734, 
     "DbgIndex" : 0, 
     "DbgName" : "SVGMat.001", 
     "colorAmbient" : [0.3294117738218869, 0.6243137452649137, 0.3607843214390325], 
     "colorDiffuse" : [0.3294117738218869, 0.6243137452649137, 0.3607843214390325], 
     "colorSpecular" : [0.5, 0.5, 0.5], 
       "illumination" : 2, 
     "depthTest" : true, 
     "depthWrite" : true, 
     "specularCoef" : 50, 
     "transparency" : 1.0, 
     "transparent" : false, 
     "vertexColors" : false, 
       "mapDiffuse" : "../textures/dash.jpg", 
     "shading" : "Lambert" 
    }], 
"vertices" : [1.32997,1.125,-0.870963,1.34966,1.125, ... ], 
"uvs" : [], 
"faces" : [34,124,126,125,0,...], 

错误

做工精细
[.WebGLRenderingContext]GL ERROR :GL_INVALID_OPERATION : glDrawElements: attempt to access out of range vertices in attribute 2 

回答

0

我不太了解threejs,但乍一看你有一个空的uvs数组。没有纹理,我猜想threejs根本不使用这个数组,没有必要。当您突然添加具有纹理的材质时,它会尝试使用空的数组。因此,GL给出了越界错误(相当不错 - 桌面GL会崩溃:)),我会假设属性2是uv数组。

要修复此问题,请填入uvs(或者不要提供它们并编写着色器以隐式生成它们)。

GL不能为顶点属性使用单独的索引。 UV的数量必须与顶点的数量完全匹配。另外,faces数组中的索引不能引用不存在的顶点。

+0

这是什么UVS有..? – 2014-11-04 09:18:53

+0

@YellowandRed UV是[纹理坐标](https://www.google.com.au/search?q=texture+coordinates),2D u/v坐标将每个顶点映射到纹理中的某个位置。 – jozxyqk 2014-11-04 09:24:31