我只是想在从搅拌机导出的网格上获取材质。当我使用 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);
}
这只是使我的模型成为随机颜色。我也试过:
网格=新三.网格(几何,新三.MeshFaceMaterial(材料));
用于创建网格,但这给了我一个 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 错误?