【问题标题】:Manipulating Indices in an ofMesh object在 ofMesh 对象中操作索引
【发布时间】:2015-02-28 21:02:48
【问题描述】:

仍在弄清楚如何正确使用ofMesh,我现在的目标是拥有一个点云,具有随机连接的点(使用索引),并能够在点击时随机播放索引。我被指出使用Fisher-Yates Shuffle 的方向,但是在我弄清楚索引之前这不会起作用。

目前我只是通过添加具有随机坐标的顶点来创建网格,但没有明确定义任何索引。当我使用ofSetupIndicesAuto() 时,它连接索引太有序,而ofClearIndices() 没有做任何事情,除非我以some 方式实际设置索引。

我不明白的是,当我没有为顶点明确定义索引时,它们是如何连接的。我假设索引是按照顶点的顺序自动设置的,但我猜不是。

这是我试图对索引执行的洗牌(放置在ofApp::mousePressed()):

    for (int i = numVerts - 1; i >= 0; i --) {
        int index = (int)ofRandom(i);
        int tempIndex = mesh.getIndex(index);
        mesh.setIndex(index, mesh.getIndex(i));
        mesh.setIndex(i, tempIndex);
    }

【问题讨论】:

  • 我发现在创建我的顶点的 foreach 中使用 setupIndicesAuto() 可以在启动时定义索引。我现在似乎无法得到的是 Fisher Yates Shuffle ...,它没有返回错误,也没有设置任何新索引。编辑原始帖子以显示随机播放的 sn-p。

标签: c++ mesh openframeworks indices


【解决方案1】:

您可以使用洗牌向量来设置索引。例如:

vector<int> indices(numVerts);
// Init indices vector
int acc = 0;
for(vector<int>::iterator it = indices.begin(); it != indices.end(); ++it){
    *it = acc;
    ++acc;
}
// Shuffle
random_shuffle(indices.begin(), indices.end());
// Update indices for the mesh
mesh.clearIndices();
mesh.addIndices(indices);

您可以看到here 索引是如何工作的。基本上,它们会帮助您告诉显卡如何连接ofMesh 的顶点。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多