在three.js中挤出几何 [英] Extrude Geometry in three.js

查看:84
本文介绍了在three.js中挤出几何的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我当前正在将STL onject加载到我的three.js场景中.

I'm currently loading an STL onject into my three.js scene.

由于某些原因,渲染/动画需要大量的GPU资源,从而降低了整个场景的速度,因此我一直在考虑替代方法.

For some reason, it takes a lot of GPU resources to render/animate, slowing the entire scene down so I've been considering alternatives.

由于它是一个非常简单的形状,我想我可以使用创建2D形状并将其拉伸.

As it's quite a simple shape, I thought I could use create the 2D shape and extrude it.

3D形状是一个方形框架(它是一个相框),没有曲线或任何其他聪明的几何形状.

The 3D shape is a square frame (it's a photo frame), no curves or any other clever geometry.

最初,我考虑过创建4个3D椭圆形,将每个椭圆形旋转90度,然后将它们恰好放置在场景中以使其看起来像一个框架-但这并不理想.

Initially, I thought about creating 4x 3D oblongs, rotating each one by 90 degrees and placing them just right in the scene to make it look like a frame - but that's not ideal.

作为将STL模型加载到场景中的一种替代方法,我该如何在three.js中创建此形状(中间留有空白),然后对其进行拉伸以使其具有一定的深度?

So as an alternative to loading the STL model into the scene, how can I create this shape in three.js (with empty space in the centre) and then extrude it to give it some depth?

推荐答案

基本挤出示例: ExtrudeGeometry -> Mesh

const { renderer, scene, camera } = initThree();


//Create a frame shape..
var frame = new THREE.Shape();
frame.moveTo(-4, -3);
frame.lineTo( 4, -3);
frame.lineTo( 4,  3);
frame.lineTo(-4,  3);

//..with a hole:
var hole = new THREE.Path();
hole.moveTo(-3, -2);
hole.lineTo( 3, -2);
hole.lineTo( 3,  2);
hole.lineTo(-3,  2);
frame.holes.push(hole);

//Extrude the shape into a geometry, and create a mesh from it:
var extrudeSettings = {
    steps: 1,
    depth: 1,
    bevelEnabled: false,
};
var geom = new THREE.ExtrudeGeometry(frame, extrudeSettings);
var mesh = new THREE.Mesh(geom, new THREE.MeshPhongMaterial({ color: 0xffaaaa }));


scene.add(mesh);
renderer.render(scene, camera);

body {
    margin: 0;
    overflow: hidden;
}
canvas {
    display: block;
}

<script src="//cdnjs.cloudflare.com/ajax/libs/three.js/102/three.min.js"></script>
<script src="//cdn.rawgit.com/Sphinxxxx/298702f070e34a5df30326cd9943260a/raw/16afc701da1ed8ed267a896907692d8acdce9b7d/init-three.js"></script>

这篇关于在three.js中挤出几何的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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