ExtrudeGeometry+Shape实现由二维平面变为立体模型

Shape

使用路径以及可选的孔洞来定义一个二维形状平面。
方法一

const shape = new THREE.Shape();
shape.moveTo( 0,0 );
shape.lineTo( 0, width );
shape.lineTo( length, width );
shape.lineTo( length, 0 );
shape.lineTo( 0, 0 );

方法二

const vertexes = [
    new THREE.Vector2(x,y),
    new THREE.Vector2(x1,y1),
    new THREE.Vector2(x2,y2),
    new THREE.Vector2(x3,y3),
    new THREE.Vector2(x4,y4)]
    const shape = new THREE.Shape(vertexes);

你可以简单理解为这个类定义了二维多边形的边界。

挤压缓冲几何体(ExtrudeGeometry)

ExtrudeGeometry(shapes : Array, options : Object)
shapes — 形状或者一个包含形状的数组。
options — 一个包含有下列参数的对象:

  • curveSegments — int,曲线上点的数量,默认值是12。
  • steps — int,用于沿着挤出样条的深度细分的点的数量,默认值为1。
  • depth — float,挤出的形状的深度,默认值为1。
  • bevelEnabled — bool,对挤出的形状应用是否斜角,默认值为true。
  • bevelThickness — float,设置原始形状上斜角的厚度。默认值为0.2。
  • bevelSize — float。斜角与原始形状轮廓之间的延伸距离,默认值为bevelThickness-0.1。
  • bevelOffset — float. Distance from the shape outline that the bevel - starts. Default is 0.
  • bevelSegments — int。斜角的分段层数,默认值为3。
  • extrudePath — THREE.Curve对象。一条沿着被挤出形状的三维样条线。Bevels not supported for path extrusion.
  • UVGenerator — Object。提供了UV生成器函数的对象。
    该对象将一个二维形状挤出为一个三维几何体。

当使用这个几何体创建Mesh的时候,如果你希望分别对它的表面和它挤出的侧面使用单独的材质,你可以使用一个材质数组。 第一个材质将用于其表面;第二个材质则将用于其挤压出的侧面。
比如已经定义了一个二维多边形(Shape)

const extrudeSettings = {
	steps: 2,
	depth: 16,
	bevelEnabled: true,
	bevelThickness: 1,
	bevelSize: 1,
	bevelOffset: 0,
	bevelSegments: 1
};

const geometry = new THREE.ExtrudeGeometry( shape, extrudeSettings );
const material = new THREE.MeshBasicMaterial( { color: 0x00ff00 } );
const mesh = new THREE.Mesh( geometry, material ) ;
scene.add( mesh );

在这里插入图片描述
案例链接

  • 5
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值