简体   繁体   English

将多个样条转换为 3D Mesh

[英]Converting several splines into 3D Mesh

I'm sorry if its a repeated question, but I have the following input and want to generate the output like that.如果这是一个重复的问题,我很抱歉,但我有以下输入并希望生成这样的 output。

I'm confused about how the splines converted into quad mesh, can I know what terms should I search for?我对样条线如何转换为四边形网格感到困惑,我能知道我应该搜索哪些术语吗? What is that process is called in computer graphics?这个过程在计算机图形学中叫什么?

在此处输入图像描述

在此处输入图像描述

Sample files:示例文件:

Curve1 
https://pastebin.com/KUmk04pY
Curve2
https://pastebin.com/BrpbADE9
Curve3
https://pastebin.com/MX6vWMJg

Sample code to read the curves:读取曲线的示例代码:

std::vector<glm::vec3> read_cvs(std::string filename)
{
    vector<vector<string>> content;
    vector<string> row;
    string line, word;
    std::vector<glm::vec3> curve;
    fstream file(filename, ios::in);
    if (file.is_open())
    {
        while (getline(file, line))
        {
            row.clear();

            stringstream str(line);

            while (getline(str, word, ','))
                row.push_back(word);
            content.push_back(row);
        }
    }
    else
        cout << "Could not open the file\n";

    int c = 0;
    for (int i = 0; i < content.size(); i++)
    {
        vector<float> f;
        for (int j = 0; j < content[i].size(); j++)
        {
            f.push_back(std::stof(content[i][j]));
        }

        curve.push_back(glm::vec3(f[0], f[0 + 1], f[0 + 2]));

    }
    return curve;
}

You already have all the points you need.您已经拥有所需的所有积分。

  • Load the splines.加载样条曲线。
  • Walk the arrays, while summing the distance between consecutive points on each individual curve.走 arrays,同时计算每条曲线上连续点之间的距离。
  • When you have reached the required length for your quad's edge, elect the closest point as the next summit for your quad.当您达到四边形边缘所需的长度时,选择最近的点作为四边形的下一个顶点。 (you can also extrapolate to find a point in between points given if the exact distance is needed. (如果需要精确距离,您也可以推断以在给定的点之间找到一个点。

In the graph you uploaded, the 'quads' are actually lines.在您上传的图表中,“四边形”实际上是线条。 The lines on selected (by distance between each other) splines are made of many lines between the points given, to match the curve of the spline, and the lines across are drawn using glLine() or equivalent between points selected with the algorithm described above on every spline given.所选(按彼此之间的距离)样条曲线上的线由给定点之间的许多线组成,以匹配样条曲线,并且使用 glLine() 或使用上述算法选择的点之间的等效线绘制交叉线在给定的每个样条上。

It is plainly visible in the visual example given that additional points ("splines") were created by non-linear extrapolation, which does not really make the code more complex, but does indeed increase quite a bit the number of points needed to generate the graph.在视觉示例中可以清楚地看到附加点(“样条”)是由非线性外推法创建的,这并没有真正使代码更复杂,但确实增加了生成图形。

I suggest you start with only the points given.我建议你只从给定的要点开始。 The extrapolation can be added when that works.可以在可行时添加外推。 Whatever code you'll have written by then will be reusable as is with the extra splines added as input.届时您编写的任何代码都可以重复使用,因为添加了额外的样条作为输入。

Selecting all the points necessary for drawing sounds a bit tedious, and it is.选择绘图所需的所有点听起来有点乏味,事实确实如此。 That's par for the course for this kind of operation.对于这种操作来说,这是正常的。

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

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