OpenSubdiv.OPENSUBDIV_VERSION.Bfr
OpenSubdiv.OPENSUBDIV_VERSION.Far
OpenSubdiv.OPENSUBDIV_VERSION.Osd
OpenSubdiv.OPENSUBDIV_VERSION.Sdc
OpenSubdiv.OPENSUBDIV_VERSION.Vtr

OpenSubdiv.OPENSUBDIV_VERSION.Bfr.Tessellation

该功能是 OpenSubdiv 库的一部分,用于在细分和渲染三角形曲面时采用缓冲区化(buffering)技术。Bfr.Tessellation 类实现了基于缓冲区的细分,并且支持边界条件和最大细分级别。

使用方法

创建 Bfr.Tessellation 的实例:

OpenSubdiv::Bfr<T> bfr;
OpenSubdiv::BfrTessellation<T> tess;
tess.Initialize(bfr, maxLevel, boundaryMode);

其中,T 表示顶点数据类型,bfr 是顶点缓冲区,maxLevel 是最大细分级别,boundaryMode 是边界条件,可以是 OpenSubdiv::BILINEAR_BASISOpenSubdiv::LOOP_BASIS

通过 tess 实例细分三角形曲面:

void Tessellate(OpenSubdiv::FarMesh<OpenSubdiv::Bilinear> const &farMesh, int patchIndex, T *vertexBuffer);

其中,farMesh 是经过预处理的三角形曲面基础数据,patchIndex 是要细分的三角形索引,vertexBuffer 是顶点缓冲区。细分的结果将写入 vertexBuffer

示例

以下是一个示例程序:

#include <opensubdiv/buffer.h>
#include <opensubdiv/far.h>
#include <opensubdiv/bilinear.h>
#include <opensubdiv/buf/tessellator.h>

typedef OpenSubdiv::OsdVertexDescriptor Descriptor;
typedef OpenSubdiv::OsdVertexBufferDescriptor VertexBufferDescriptor;
typedef float Vertex;

int main()
{
    // 创建顶点缓冲区,包含 4 个顶点
    OpenSubdiv::OsdCpuVertexBuffer * vertexBuffer = new OpenSubdiv::OsdCpuVertexBuffer(4, 3);

    // 初始化顶点数据
    Vertex *vertices = (Vertex *)vertexBuffer->BindCpuBuffer();

    vertices[0] = 0.0f; vertices[1] = 0.0f; vertices[2] = 0.0f;
    vertices[3] = 0.0f; vertices[4] = 1.0f; vertices[5] = 0.0f;
    vertices[6] = 1.0f; vertices[7] = 1.0f; vertices[8] = 0.0f;
    vertices[9] = 1.0f; vertices[10] = 0.0f; vertices[11] = 0.0f;

    // 创建 Bfr 对象
    OpenSubdiv::Bfr<Vertex> bfr;

    // 创建 Bfr.Tessellation 对象
    OpenSubdiv::BfrTessellation<Vertex> tess;
    tess.Initialize(bfr, 2, OpenSubdiv::BILINEAR_BASIS);

    // 细分三角形曲面
    OpenSubdiv::FarMesh<OpenSubdiv::Bilinear> farMesh;
    farMesh.Initialize(Descriptor(VertexBufferDescriptor(vertexBuffer)), bfr);

    OpenSubdiv::BilinearBasis basis;
    basis.CreateComponentMask(true, true, true);
    OpenSubdiv::FarPatchTables patchTables(farMesh, basis, 4);
    patchTables.Validate();

    for (int i = 0; i < patchTables.GetNumPatches(); ++i) {
        OpenSubdiv::BilinearPatchTable const &patchTable = patchTables.GetBilinearPatchTable();
        tess.Tessellate(patchTable, i, vertices);
    }

    return 0;
}

授权许可

OpenSubdiv 的代码遵循 Apache 2.0 许可。更多细节请查看官方文档。