How to render clipped surfaces as solid objects

怎甘沉沦 提交于 2019-11-27 14:11:39

You want to render a clipped surface as if it were a solid -- i.e., not hollow.

You can achieve that effect with MeshPhongMaterial -- or any three.js material for that matter -- with a simple hack to the material shader.

Replace this line in /src/renderers/shaders/ShaderLib/meshphong_frag.glsl:

gl_FragColor = vec4( outgoingLight, diffuseColor.a );

with

if ( gl_FrontFacing ) {

    gl_FragColor = vec4( outgoingLight, diffuseColor.a );

} else {

    gl_FragColor = diffuseColor;

}

This should look pretty good. It will require material.side = THREE.DoubleSide;

three.js r.76

I made a THREE.SectionHelper class which could be interesting if you want to set a different material/color for the inside of the mesh that you are clipping. Check a demo in this fiddle.

var sectionHelper = new THREE.SectionHelper( mesh, 0xffffff );
scene.add(sectionHelper);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!