THREEjs 初始化时不能使用 JSON 模型上的材料.给我 WebGL 错误 [英] THREEjs can't use the material on the JSON Model when initializing. Gives me WebGL errors

查看:29
本文介绍了THREEjs 初始化时不能使用 JSON 模型上的材料.给我 WebGL 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是想在我从搅拌机导出的网格上获取一种材料.当我使用 JSONLoader 时,网格显示没有问题,但我无法获得导出的材料.我到处寻找答案,但没有运气.这是我的代码:

I am simply trying to get a material on a mesh that I exported from blender. The mesh shows up no problem when I use the JSONLoader, but I cant get the material I exported. I looked everywhere for an answer but no luck. Here is my code:

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);
}

这只会让我的模型变成随机颜色.我也试过:

this just makes my model a random color. I have also tried:

mesh = new THREE.Mesh(geometry, new THREE.MeshFaceMaterial(materials));

mesh = new THREE.Mesh(geometry, new THREE.MeshFaceMaterial(materials));

用于创建网格,但这给了我一个 webgl 错误:

for creating the mesh, but this gives me a webgl error:

.WebGLRenderingContext:GL 错误:GL_INVALID_OPERATION:glDrawElements:尝试访问属性 1 中超出范围的顶点

.WebGLRenderingContext: GL ERROR :GL_INVALID_OPERATION : glDrawElements: attempt to access out of range vertices in attribute 1

我一直在寻找答案,但似乎每个人都在建议这些选项,但没有一个有效.这是从搅拌机导出的材料

Am have been looking for an answer but everyone seems to be suggesting these options and none of them are working. Here are the materials that were exported from blender

"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 错误吗?

Not sure where to go from here or what I am doing wrong. EDIT I Removed the texture from the material and it worked fine. Anyone know how to make the texture not throw a webGL error?

推荐答案

我想通了.我的模型没有 UV,所以纹理没有什么可映射的,因此出现了 webGL 错误.抱歉问了一个毫无意义的问题.

I figured it out. My model had no UVs so the texture had nothing to map out to and thus a webGL error. Sorry for the pointless question.

这篇关于THREEjs 初始化时不能使用 JSON 模型上的材料.给我 WebGL 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆