简体   繁体   English

如何从 Three.js 中的 3D 点创建 3D 表面?

[英]How can I create a 3D surface from 3D points in Three.js?

I'm making a project to make simple 3d models with dots and lines (curved or not).我正在制作一个项目,用点和线(弯曲或不弯曲)制作简单的 3d 模型。 For a first version I used SVG elements for simple render, smooth curves and mouse events.对于第一个版本,我使用 SVG 元素进行简单渲染、平滑曲线和鼠标事件。

Now I'm trying to use Three.js renderer instead of SVG.现在我正在尝试使用Three.js渲染器而不是 SVG。 I got to create 3d tubes to replace the curved lines, but I don't know how to create 3d surfaces based on multiple xyz coordinates .我必须创建 3d 管来替换曲线,但我不知道如何基于多个 xyz 坐标创建 3d 曲面

Here is an example of a model made of 4 points and 4 lines (3 straights and 1 curved):这是一个由 4 个点和 4 条线(3 条直线和 1 条曲线)组成的模型示例:

surface-3d-sample1

We could imagine that the curve is extruded to more points, to something like this:我们可以想象曲线被挤压成更多的点,像这样:

在此处输入图片说明

Then I would like to create a surface (or plane), just like the blue shape:然后我想创建一个表面(或平面),就像蓝色形状一样:

在此处输入图片说明

I got inspired of this topic: convert bezier into a plane road in three.js我受到了这个话题的启发: 在three.js中将贝塞尔曲线转换为平面道路

var material = new THREE.MeshBasicMaterial({ color: 0xc0c0c0 });
var path = new THREE.CatmullRomCurve3([
    new THREE.Vector3(dots[0].x, dots[0].y, -dots[0].z),
    new THREE.Vector3(dots[1].x, dots[1].y, -dots[1].z),
    new THREE.Vector3(dots[2].x, dots[2].y, -dots[2].z),
    new THREE.Vector3(dots[3].x, dots[3].y, -dots[3].z),
    new THREE.Vector3(dots[0].x, dots[0].y, -dots[0].z)
]);

var pts = [],
    a ;
for (var i = 0 ; i < 3 ; i++) {
    a = i / 3 * Math.PI;
    pts.push(new THREE.Vector2(Math.cos(a) * 1, Math.sin(a) * 1));
}
var shape = new THREE.Shape(pts);

var geometry = new THREE.ExtrudeGeometry(shape, {
    steps : 10,
    bevelEnabled : false,
    extrudePath : path
});

var mesh = new THREE.Mesh(geometry, material);
scene.add(mesh);

But this sample code only creates another tube-like shape.但是这个示例代码只创建了另一个管状形状。

Instead of using four (Bezier) curves to create a surface, use Bezier SURFACES or NURBS — they are mathematically designed for it.使用Bezier SURFACESNURBS ,而不是使用四条(贝塞尔)曲线来创建曲面,它们是专门为此而设计的。 Here is a demo with source code.这是一个带有源代码的演示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM