THREE.SmoothShading对几何没有影响 [英] THREE.SmoothShading has no effect on geometry

查看:282
本文介绍了THREE.SmoothShading对几何没有影响的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

平滑着色似乎对我的模型没有影响 - 多边形清晰可见,并且在三个.js检查器中的平滑着色和平面着色之间切换无效。 obj中有顶点法线数据,因此不需要使用geometry.computeVertexNormals(),就像其他一些帖子所建议的那样。



使用THREE.WebGLRenderer



任何潜在客户赞赏:)





如果您不想修复模型,可以使用如下模式重新计算平滑顶点法线:

  loader .load('model_mesh.obj',function(object){

var mesh = object.children [0];

mesh.geometry = new THREE.Geometry() .fromBufferGeometry(mesh.geometry);

mesh.geometry.mergeVertices();

mesh.geometry.computeVertexNormals();

//在渲染之前转换回BufferGeometry
mesh.geometry = new THREE.BufferGeometry()。fromGeometry(mesh.geometry);

scene.add(object);

});

three.js r.95


Smooth shading seems to have no effect on my model - the polygons are clearly visible and toggling between smooth and flat shading in the three.js inspector has no effect. There is vertex normal data in the obj so using geometry.computeVertexNormals() shouldn't be needed as has been suggested on a few other posts.

Using THREE.WebGLRenderer

Any leads appreciated :)

obj,mtl,img files

This is my loader function:

var mtlLoader = new THREE.MTLLoader();
        mtlLoader.setBaseUrl(pathToLoad);
        mtlLoader.setPath(pathToLoad);                       
        mtlLoader.load('model_mesh.obj.mtl', function (materials) {
            materials.preload();
            var objLoader = new THREE.OBJLoader();
            objLoader.setMaterials(materials);
            objLoader.setPath(pathToLoad);
            objLoader.load('model_mesh.obj', function (obj) {
                obj.name = pathToLoad.substring(12, 17);
                testArray.push(obj);
                scene.add(obj);  
                loadNextPath(); 
            });
        });

screenshot, polygons visible

解决方案

The problem is with your model. It has "flat" vertex normals.

If you don't want to fix your model, you can recompute smooth vertex normals by using a pattern like this one:

loader.load( 'model_mesh.obj', function( object ) {

    var mesh = object.children[ 0 ];

    mesh.geometry = new THREE.Geometry().fromBufferGeometry( mesh.geometry );

    mesh.geometry.mergeVertices();

    mesh.geometry.computeVertexNormals();

    // convert back to BufferGeometry prior to rendering
    mesh.geometry = new THREE.BufferGeometry().fromGeometry( mesh.geometry );

    scene.add( object );

});

three.js r.95

这篇关于THREE.SmoothShading对几何没有影响的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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