如何在Three.js中构造空心圆柱体 [英] How do I construct a hollow cylinder in Three.js

查看:1070
本文介绍了如何在Three.js中构造空心圆柱体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很难在Three.js中构造空心圆柱体.

I'm having difficulties constructing a hollow cylinder in Three.js.

我应该使用CSG还是将顶点缝合在一起来构造它?

Should I go and construct it using CSG or by stitching the vertices together?

推荐答案

此解决方案使用ChandlerPrall的ThreeCSG.js项目: http://github.com/chandlerprall/ThreeCSG

This solution uses ChandlerPrall's ThreeCSG.js project: http://github.com/chandlerprall/ThreeCSG

(暂时,我建议使用支持材料的实验版本-uv分支- http ://github.com/chandlerprall/ThreeCSG/tree/uvs )

(For now, I recommend using the experimental version that supports materials - the uv branch - http://github.com/chandlerprall/ThreeCSG/tree/uvs)

这是您需要的代码:

// Cylinder constructor parameters:  
// radiusAtTop, radiusAtBottom, height, segmentsAroundRadius, segmentsAlongHeight

var smallCylinderGeom = new THREE.CylinderGeometry( 30, 30, 80, 20, 4 );
var largeCylinderGeom = new THREE.CylinderGeometry( 40, 40, 80, 20, 4 );

var smallCylinderBSP = new ThreeBSP(smallCylinderGeom);
var largeCylinderBSP = new ThreeBSP(largeCylinderGeom);
var intersectionBSP = largeCylinderBSP.subtract(smallCylinderBSP);      

var redMaterial = new THREE.MeshLambertMaterial( { color: 0xff0000 } );
var hollowCylinder = intersectionBSP.toMesh( redMaterial );
scene.add( hollowCylinder );

这篇关于如何在Three.js中构造空心圆柱体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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