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


C++ VertexElement::getSizeInByte方法代码示例

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


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

示例1: mLoad

    //--------------------------------------------------------------------
    Status MeshManager::mLoad(std::shared_ptr<Mesh> mesh, const std::string &sid,
                              std::vector<glm::vec3> &positions,
                              std::vector<glm::vec2> &uvs,
                              std::vector<glm::vec3> &flatNormals,
                              std::vector<VertexIndices> &vertexIndices) const {

        bool hasUv, hasFlat, hasSmooth;
        hasUv = !uvs.empty();
        if (!hasUv) {
            Log::trace(TAG, "no UV mapping found for mesh \"%s\"", sid.c_str());
        }

        hasFlat = !flatNormals.empty();
        if (!hasFlat) {
            Log::trace(TAG, "no Flat normal mapping found for mesh \"%s\"", sid.c_str());
        }

        // generates normals
        std::vector<glm::vec3> smoothNormals;
        if (!hasFlat) {
            generateFlatNormals(flatNormals, positions, vertexIndices);
        }
        generateSmoothNormals(smoothNormals, flatNormals, positions, vertexIndices, hasFlat);
        hasSmooth = true; //TODO metadata

        if(!hasFlat) { //TODO handle it with metadata
            flatNormals.clear(); //no need from there
        }

        std::vector<U16> indices;
        std::vector<Vertex> vertices;
        // map one Vertex object to one or many VertexIndices
        std::map<VertexIndices, U16> indexMap;

        U16 currentVertexIndex = 0;
        //create Vertex objects out of VertexIndices.
        for (const VertexIndices& vi : vertexIndices) {

            // if Vertex object of this indices doesn't exist already
            if (indexMap.find(vi) == indexMap.end()) {
                //create it & refer to it.
                indexMap[vi] = currentVertexIndex;
                indices.push_back(currentVertexIndex);
                currentVertexIndex++;

                Vertex v;
                v.setPosition(positions[vi.p]);
                if (hasUv) {
                    v.setUv(uvs[vi.uv]);
                }
                if (hasFlat) {
                    v.setFlatNormal(flatNormals[vi.fn]);
                }
                if (hasSmooth) {
                    v.setSmoothNormal(smoothNormals[vi.sn]);
                }
                vertices.push_back(v);
            } else {
                indices.push_back(indexMap[vi]);
            }
        }

        U32 vertexSize = 0;
        U32 vertexCount = (U32) vertices.size();

        //Positions
        VertexElement positionElement(VertexElement::Semantic::POSITION, 3, GL_FLOAT, vertexSize);
        vertexSize += positionElement.getSizeInByte();
        mesh->addVertexElement(positionElement);


        //Normals
        if (hasFlat) {
            VertexElement flatNormalElement(VertexElement::Semantic::FLAT_NORMAL, 3, GL_FLOAT, vertexSize);
            vertexSize += flatNormalElement.getSizeInByte();
            mesh->addVertexElement(flatNormalElement);
        }
        if (hasSmooth) {
            VertexElement smoothNormalElement(VertexElement::Semantic::SMOOTH_NORMAL, 3, GL_FLOAT, vertexSize);
            vertexSize += smoothNormalElement.getSizeInByte();
            mesh->addVertexElement(smoothNormalElement);
        }

        // UVs
        if (hasUv) {
            VertexElement uvElement(VertexElement::Semantic::UV, 2, GL_FLOAT, vertexSize);
            vertexSize += uvElement.getSizeInByte();
            mesh->addVertexElement(uvElement);
        }

        mesh->mVertexSize = vertexSize;
        mesh->mVertexCount = vertexCount;
        //Log::debug(TAG, "vertexSize=%d vertexCount=%d", vertexSize, vertexCount);
        //Log::debug(TAG, "indices=%d", indices.size());

        BYTE* data = new BYTE[vertexSize * vertexCount];

        /////////////////////////////////////////////////////////////////////////
        // Generate vertex buffer
//.........这里部分代码省略.........
开发者ID:e-biz,项目名称:arpi-gl,代码行数:101,代码来源:MeshManager.cpp


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