Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/438.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 将纹理添加到json不加载_Javascript_Json_Opengl Es_Webgl_Texture Mapping - Fatal编程技术网

Javascript 将纹理添加到json不加载

Javascript 将纹理添加到json不加载,javascript,json,opengl-es,webgl,texture-mapping,Javascript,Json,Opengl Es,Webgl,Texture Mapping,我试图将纹理添加到jsonloaded对象中,该对象由于某种原因未加载 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.MeshF

我试图将纹理添加到jsonloaded对象中,该对象由于某种原因未加载

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

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

要解决此问题,请填充
uvs
(或者不提供它们,然后编写着色器隐式生成它们)

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

@yellowsandred UV是二维u/v坐标,用于将每个顶点映射到纹理中的某个位置。