打开场景图 - DrawElementsUInt的用法:绘制布料而不复制顶点

问题描述 投票:0回答:1

我目前正致力于模拟布料,然后通过Open Scene Graph显示结果。我已经通过将所有顶点转储到1 Vec3Array然后使用标准的基于Point的DrawArrays显示它来获得显示布料的设置。但是我正在考虑在顶点之间添加面,以便我的应用程序的另一部分可以直观地看到布料。

这是我正在尝试的PrimitiveSet

    // create and add a DrawArray Primitive (see include/osg/Primitive).  The first
    // parameter passed to the DrawArrays constructor is the Primitive::Mode which
    // in this case is POINTS (which has the same value GL_POINTS), the second
    // parameter is the index position into the vertex array of the first point
    // to draw, and the third parameter is the number of points to draw.
    unsigned int k = CLOTH_SIZE_X;
    unsigned int n = CLOTH_SIZE_Y;
    osg::ref_ptr<osg::DrawElementsUInt> indices = new osg::DrawElementsUInt(GL_QUADS, (k) * (n));
    for (uint y_i = 0; y_i < n - 1; y_i++) {
        for (uint x_i = 0; x_i < k - 1; x_i++) {
            (*indices)[y_i * k + x_i] = y_i * k + x_i;
            (*indices)[y_i * (k + 1) + x_i] = y_i * (k + 1) + x_i;
            (*indices)[y_i * (k + 1) + x_i + 1] = y_i * (k + 1) + x_i + 1;
            (*indices)[y_i * k + x_i] = y_i * k + x_i + 1;
        }
    }

    geom->addPrimitiveSet(indices.get());

但是这确实会在运行时导致内存损坏,而且我在汇编代码中不够流利,无法解释当CLion给我反汇编代码时它试图做错的事情。

我的想法是,我会迭代布料的每个面,然后选择属于它的顶点的4个索引。顶点按顺序从左上到右下输入。所以:

0  1    2    3    ... k-1
k  k+1  k+2  k+3  ... 2k-1
2k 2k+1 2k+2 2k+3 ... 3k-1 
...

有没有人遇到过这个特定的用例,他/她是否有解决我的问题的方法?任何帮助将不胜感激。

openscenegraph cloth-simulation
1个回答
0
投票

您可能希望使用带有QUAD_STRIP(或TRIANGLE_STRIP)的DrawArrays,因为这些天四边形都是皱眉的。这里有一个例子:http://openscenegraph.sourceforge.net/documentation/OpenSceneGraph/examples/osggeometry/osggeometry.cpp

它的效率略低于Elements / indices,但管理两个相关容器(顶点和索引)之间的关系也不那么复杂。

如果你真的想做元素/索引路线,我们可能需要看到更多的重新编码才能看到发生了什么。

© www.soinside.com 2019 - 2024. All rights reserved.