当前位置: 首页>>代码示例>>C++>>正文


C++ MeshData::GetIndexCount方法代码示例

本文整理汇总了C++中MeshData::GetIndexCount方法的典型用法代码示例。如果您正苦于以下问题:C++ MeshData::GetIndexCount方法的具体用法?C++ MeshData::GetIndexCount怎么用?C++ MeshData::GetIndexCount使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MeshData的用法示例。


在下文中一共展示了MeshData::GetIndexCount方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: WriteOBJ

void WriteOBJ(MeshData const& meshData, std::ostream* stream, IImportExportCallbacks* callbacks)
{
    auto posStream = meshData.GetVertexStream(ElementType::Position);
    auto uvStream = meshData.GetVertexStream(ElementType::TextureUV);
    auto normalStream = meshData.GetVertexStream(ElementType::Normal);
    auto indexData = meshData.GetRawIndexData();
    size_t indexCount = meshData.GetIndexCount();
    
    // streams must all have same size
    DebugAssert(posStream);
    DebugAssert(uvStream==nullptr || uvStream->Count == posStream->Count);
    DebugAssert(normalStream==nullptr || normalStream->Count == posStream->Count);

    // index buffer assumed to be triangles
    DebugAssert(indexCount % 3 == 0);

    struct Vec3
    {
        float x,y,z;
    };
    struct Vec2
    {
        float x,y;
    };

    size_t totalLines =
        posStream->Count +
        (uvStream ? uvStream->Count : 0) + 
        (normalStream ? normalStream->Count : 0) + 
        indexCount / 3;
    size_t numLines = 0;

    for (size_t i = 0; i < posStream->Count; i++)
    {
        HANDLE_PROGRESS;

        Vec3 v = posStream->GetElement<Vec3>(i);
        (*stream) << "v " << v.x << " " << v.y << " " << v.z << std::endl;
    }

    if( uvStream )
    {
        for (size_t i = 0; i < uvStream->Count; i++)
        {
            HANDLE_PROGRESS;

            Vec2 v = uvStream->GetElement<Vec2>(i);
            (*stream) << "vt " << v.x << " " << v.y << std::endl;
        }
    }

    if( normalStream )
    {
        for (size_t i = 0; i < normalStream->Count; i++)
        {
            HANDLE_PROGRESS;

            Vec3 v = normalStream->GetElement<Vec3>(i);
            (*stream) << "vn " << v.x << " " << v.y << " " << v.z << std::endl;
        }
    }

    for (size_t i = 0; i < indexCount; i += 3)
    {
        HANDLE_PROGRESS;

        (*stream) << "f ";
        WriteSlashedIndex(stream, indexData[i], uvStream != nullptr, normalStream != nullptr, false );
        WriteSlashedIndex(stream, indexData[i+1], uvStream != nullptr, normalStream != nullptr, false );
        WriteSlashedIndex(stream, indexData[i+2], uvStream != nullptr, normalStream != nullptr, true );
    }
}
开发者ID:mpj500,项目名称:creepy-capsicum,代码行数:72,代码来源:OBJWriter.cpp


注:本文中的MeshData::GetIndexCount方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。