6

我在 Three.js 中构建空心圆柱体时遇到了困难。

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

4

4 回答 4

10
var extrudeSettings = {
    amount : 2,
    steps : 1,
    bevelEnabled: false,
    curveSegments: 8
};

var arcShape = new THREE.Shape();
arcShape.absarc(0, 0, 1, 0, Math.PI * 2, 0, false);

var holePath = new THREE.Path();
holePath.absarc(0, 0, 0.8, 0, Math.PI * 2, true);
arcShape.holes.push(holePath);

var geometry = new THREE.ExtrudeGeometry(arcShape, extrudeSettings);
于 2015-06-29T02:54:38.663 回答
7

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

(目前,我推荐使用支持材质的实验版本 - uv 分支 - 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 );
于 2012-08-07T19:05:31.690 回答
3

您不太可能必须将顶点缝合在一起。如果您的圆柱体没有厚度,您可以使用THREE.CylinderGeometry(). 如果它确实有厚度,您可以使用 CSG。

于 2012-08-06T12:23:07.810 回答
-1

使用SVGloader加载所需半径的圆(作为 SVG)。将几何体设置为ExtrudeBufferGeometry并在拉伸设置对象中为其指定所需的高度作为深度。

于 2018-10-03T11:01:42.357 回答