我只是想在我从blender导出的网格上获取一个材质。当我使用JSONLoader时,网格显示没有问题,但是我无法获得我导出的材质。我到处寻找答案,但没有运气。这是我的代码:
function init() {
renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild( renderer.domElement );
camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 1, 10000 );
camera.position.z = 10;
camera.position.y = 3;
scene = new THREE.Scene();
loader = new THREE.JSONLoader(true);
var texture = THREE.ImageUtils.loadTexture( 'bear_diffuse1.png' );
var material = new THREE.MeshBasicMaterial({map: texture});
loader.load( "bear_MODEL.js", createMesh, '' );
}
function createMesh(geometry, materials){
mesh = new THREE.Mesh(geometry, THREE.MeshFaceMaterial(materials));
mesh.scale.set( 5, 5, 5 );
scene.add( mesh );
camera.lookAt(mesh.position);
}
这只会使我的模型成为随机颜色。我也尝试过:
mesh = new THREE.Mesh(geometry,new THREE.MeshFaceMaterial(materials));
用于创建网格,但这给了我一个webgl错误:
.WebGLRenderingContext:GL错误:GL_INVALID_OPERATION:glDrawElements:尝试访问属性1中超出范围的顶点
我一直在寻找答案但是每个人似乎都在建议这些选项,而且没有一个能够正常运作。以下是从搅拌机中导出的材料
"materials" : [ {
"DbgColor" : 15658734,
"DbgIndex" : 0,
"DbgName" : "Material.001",
"blending" : "NormalBlending",
"colorAmbient" : [0.3838607966899872, 0.3780101239681244, 0.4000000059604645],
"colorDiffuse" : [0.3838607966899872, 0.3780101239681244, 0.4000000059604645],
"colorSpecular" : [0.0, 0.0, 0.0],
"depthTest" : true,
"depthWrite" : true,
"mapDiffuse" : "bear_diffuse1.png",
"mapDiffuseWrap" : ["repeat", "repeat"],
"shading" : "Basic",
"specularCoef" : 50,
"transparency" : 1.0,
"transparent" : false,
"vertexColors" : false
},
{
"DbgColor" : 15597568,
"DbgIndex" : 1,
"DbgName" : "Material.001",
"blending" : "NormalBlending",
"colorAmbient" : [0.3838607966899872, 0.3780101239681244, 0.4000000059604645],
"colorDiffuse" : [0.3838607966899872, 0.3780101239681244, 0.4000000059604645],
"colorSpecular" : [0.0, 0.0, 0.0],
"depthTest" : true,
"depthWrite" : true,
"mapDiffuse" : "bear_diffuse1.png",
"mapDiffuseWrap" : ["repeat", "repeat"],
"shading" : "Basic",
"specularCoef" : 50,
"transparency" : 1.0,
"transparent" : false,
"vertexColors" : false
},
不确定从这里去哪里或我做错了什么。 编辑我从材料中删除了纹理并且工作正常。任何人都知道如何使纹理不会引发webGL错误?
答案 0 :(得分:0)
我明白了。我的模型没有UV,所以纹理没有任何地图可以映射到webGL错误。抱歉这个毫无意义的问题。