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


C++ MeshData3D::textureCoords2D方法代码示例

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


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

示例1: rs

Reflector::Reflector(Object3D* parent, SceneGraph::DrawableGroup3D* group): Object3D(parent), SceneGraph::Drawable3D(*this, group) {
    CubeMapResourceManager& resourceManager = CubeMapResourceManager::instance();

    /* Sphere mesh */
    if(!(_sphere = resourceManager.get<GL::Mesh>("sphere"))) {
        Trade::MeshData3D sphereData = Primitives::uvSphereSolid(16, 32, Primitives::UVSphereTextureCoords::Generate);

        GL::Buffer* buffer = new GL::Buffer;
        buffer->setData(MeshTools::interleave(sphereData.positions(0), sphereData.textureCoords2D(0)), GL::BufferUsage::StaticDraw);

        Containers::Array<char> indexData;
        MeshIndexType indexType;
        UnsignedInt indexStart, indexEnd;
        std::tie(indexData, indexType, indexStart, indexEnd) = MeshTools::compressIndices(sphereData.indices());

        GL::Buffer* indexBuffer = new GL::Buffer;
        indexBuffer->setData(indexData, GL::BufferUsage::StaticDraw);

        GL::Mesh* mesh = new GL::Mesh;
        mesh->setPrimitive(sphereData.primitive())
            .setCount(sphereData.indices().size())
            .addVertexBuffer(*buffer, 0, ReflectorShader::Position{}, ReflectorShader::TextureCoords{})
            .setIndexBuffer(*indexBuffer, 0, indexType, indexStart, indexEnd);

        resourceManager.set("sphere-buffer", buffer, ResourceDataState::Final, ResourcePolicy::Resident)
            .set("sphere-index-buffer", indexBuffer, ResourceDataState::Final, ResourcePolicy::Resident)
            .set(_sphere.key(), mesh, ResourceDataState::Final, ResourcePolicy::Resident);
    }

    /* Tarnish texture */
    if(!(_tarnishTexture = resourceManager.get<GL::Texture2D>("tarnish-texture"))) {
        Resource<Trade::AbstractImporter> importer = resourceManager.get<Trade::AbstractImporter>("jpeg-importer");
        Utility::Resource rs("data");
        importer->openData(rs.getRaw("tarnish.jpg"));

        Containers::Optional<Trade::ImageData2D> image = importer->image2D(0);
        CORRADE_INTERNAL_ASSERT(image);
        auto texture = new GL::Texture2D;
        texture->setWrapping(GL::SamplerWrapping::ClampToEdge)
            .setMagnificationFilter(GL::SamplerFilter::Linear)
            .setMinificationFilter(GL::SamplerFilter::Linear, GL::SamplerMipmap::Linear)
            .setStorage(Math::log2(image->size().min())+1, GL::TextureFormat::RGB8, image->size())
            .setSubImage(0, {}, *image)
            .generateMipmap();

        resourceManager.set<GL::Texture2D>(_tarnishTexture.key(), texture, ResourceDataState::Final, ResourcePolicy::Resident);
    }

    /* Reflector shader */
    if(!(_shader = resourceManager.get<GL::AbstractShaderProgram, ReflectorShader>("reflector-shader")))
        resourceManager.set<GL::AbstractShaderProgram>(_shader.key(), new ReflectorShader, ResourceDataState::Final, ResourcePolicy::Resident);

    /* Texture (created in CubeMap class) */
    _texture = resourceManager.get<GL::CubeMapTexture>("texture");
}
开发者ID:Squareys,项目名称:magnum-examples,代码行数:55,代码来源:Reflector.cpp

示例2: withTextureCoords

void UVSphereTest::withTextureCoords() {
    Trade::MeshData3D sphere = UVSphere::solid(3, 3, UVSphere::TextureCoords::Generate);

    CORRADE_COMPARE_AS(*sphere.positions(0), (std::vector<Vector3>{
        {0.0f, -1.0f, 0.0f},

        {0.0f, -0.5f, 0.866025f},
        {0.75f, -0.5f, -0.433013f},
        {-0.75f, -0.5f, -0.433013f},
        {0.0f, -0.5f, 0.866025f},

        {0.0f, 0.5f, 0.866025f},
        {0.75f, 0.5f, -0.433013f},
        {-0.75f, 0.5f, -0.433013f},
        {0.0f, 0.5f, 0.866025f},

        {0.0f, 1.0f, 0.0f}
    }), TestSuite::Compare::Container);

    CORRADE_COMPARE_AS(*sphere.textureCoords2D(0), (std::vector<Vector2>{
        {0.5f, 0.0f},

        {0.0f, 0.333333f},
        {0.333333f, 0.333333f},
        {0.666667f, 0.333333f},
        {1.0f, 0.333333f},

        {0.0f, 0.666667f},
        {0.333333f, 0.666667f},
        {0.666667f, 0.666667f},
        {1.0f, 0.666667f},

        {0.5f, 1.0f}
    }), TestSuite::Compare::Container);

    CORRADE_COMPARE_AS(*sphere.indices(), (std::vector<UnsignedInt>{
        0, 2, 1, 0, 3, 2, 0, 4, 3,
        1, 2, 6, 1, 6, 5, 2, 3, 7, 2, 7, 6, 3, 4, 8, 3, 8, 7,
        5, 6, 9, 6, 7, 9, 7, 8, 9
    }), TestSuite::Compare::Container);
}
开发者ID:respu,项目名称:magnum,代码行数:41,代码来源:UVSphereTest.cpp

示例3: withTextureCoordsAndCaps

void CylinderTest::withTextureCoordsAndCaps() {
    Trade::MeshData3D cylinder = Cylinder::solid(2, 3, 3.0f, Cylinder::Flag::GenerateTextureCoords|Cylinder::Flag::CapEnds);

    CORRADE_COMPARE_AS(*cylinder.positions(0), (std::vector<Vector3>{
        {0.0f, -1.5f, 0.0f},

        {0.0f, -1.5f, 1.0f},
        {0.866025f, -1.5f, -0.5f},
        {-0.866025f, -1.5f, -0.5f},
        {0.0f, -1.5f, 1.0f},

        {0.0f, -1.5f, 1.0f},
        {0.866025f, -1.5f, -0.5f},
        {-0.866025f, -1.5f, -0.5f},
        {0.0f, -1.5f, 1.0f},

        {0.0f, 0.0f, 1.0f},
        {0.866025f, 0.0f, -0.5f},
        {-0.866025f, 0.0f, -0.5f},
        {0.0f, 0.0f, 1.0f},

        {0.0f, 1.5f, 1.0f},
        {0.866025f, 1.5f, -0.5f},
        {-0.866025f, 1.5f, -0.5f},
        {0.0f, 1.5f, 1.0f},

        {0.0f, 1.5f, 1.0f},
        {0.866025f, 1.5f, -0.5f},
        {-0.866025f, 1.5f, -0.5f},
        {0.0f, 1.5f, 1.0f},

        {0.0f, 1.5f, 0.0f}
    }), Container);

    CORRADE_COMPARE_AS(*cylinder.normals(0), (std::vector<Vector3>{
        {0.0f, -1.0f, 0.0f},

        {0.0f, -1.0f, 0.0f},
        {0.0f, -1.0f, 0.0f},
        {0.0f, -1.0f, 0.0f},
        {0.0f, -1.0f, 0.0f},

        {0.0f, 0.0f, 1.0f},
        {0.866025f, 0.0f, -0.5f},
        {-0.866025f, 0.0f, -0.5f},
        {0.0f, 0.0f, 1.0f},

        {0.0f, 0.0f, 1.0f},
        {0.866025f, 0.0f, -0.5f},
        {-0.866025f, 0.0f, -0.5f},
        {0.0f, 0.0f, 1.0f},

        {0.0f, 0.0f, 1.0f},
        {0.866025f, 0.0f, -0.5f},
        {-0.866025f, 0.0f, -0.5f},
        {0.0f, 0.0f, 1.0f},

        {0.0f, 1.0f, 0.0f},
        {0.0f, 1.0f, 0.0f},
        {0.0f, 1.0f, 0.0f},
        {0.0f, 1.0f, 0.0f},

        {0.0f, 1.0f, 0.0f},
    }), Container);

    CORRADE_COMPARE_AS(*cylinder.textureCoords2D(0), (std::vector<Vector2>{
        {0.5f, 0.0f},

        {0.0f, 0.2f},
        {0.333333f, 0.2f},
        {0.666667f, 0.2f},
        {1.0f, 0.2f},

        {0.0f, 0.2f},
        {0.333333f, 0.2f},
        {0.666667f, 0.2f},
        {1.0f, 0.2f},

        {0.0f, 0.5f},
        {0.333333f, 0.5f},
        {0.666667f, 0.5f},
        {1.0f, 0.5f},

        {0.0f, 0.8f},
        {0.333333f, 0.8f},
        {0.666667f, 0.8f},
        {1.0f, 0.8f},

        {0.0f, 0.8f},
        {0.333333f, 0.8f},
        {0.666667f, 0.8f},
        {1.0f, 0.8f},

        {0.5f, 1.0f}
    }), Container);

    CORRADE_COMPARE_AS(*cylinder.indices(), (std::vector<UnsignedInt>{
        0, 2, 1, 0, 3, 2, 0, 4, 3,
        1, 2, 6, 1, 6, 5, 2, 3, 7, 2, 7, 6, 3, 4, 8, 3, 8, 7,
        5, 6, 10, 5, 10, 9, 6, 7, 11, 6, 11, 10, 7, 8, 12, 7,
//.........这里部分代码省略.........
开发者ID:JanDupal,项目名称:magnum,代码行数:101,代码来源:CylinderTest.cpp

示例4:

void CapsuleTest::solid3DWithTextureCoords() {
    Trade::MeshData3D capsule = Capsule3D::solid(2, 2, 3, 0.5f, Capsule3D::TextureCoords::Generate);

    CORRADE_COMPARE_AS(capsule.positions(0), (std::vector<Vector3>{
        {0.0f, -1.5f, 0.0f},

        {0.0f, -1.20711f, 0.707107f},
        {0.612372f, -1.20711f, -0.353553f},
        {-0.612373f, -1.20711f, -0.353553f},
        {0.0f, -1.20711f, 0.707107f},

        {0.0f, -0.5f, 1.0f},
        {0.866025f, -0.5f, -0.5f},
        {-0.866025f, -0.5f, -0.5f},
        {0.0f, -0.5f, 1.0f},

        {0.0f, 0.0f, 1.0f},
        {0.866025f, 0.0f, -0.5f},
        {-0.866025f, 0.0f, -0.5f},
        {0.0f, 0.0f, 1.0f},

        {0.0f, 0.5f, 1.0f},
        {0.866025f, 0.5f, -0.5f},
        {-0.866025f, 0.5f, -0.5f},
        {0.0f, 0.5f, 1.0f},

        {0.0f, 1.20711f, 0.707107f},
        {0.612372f, 1.20711f, -0.353553f},
        {-0.612372f, 1.20711f, -0.353553f},
        {0.0f, 1.20711f, 0.707107f},

        {0.0f, 1.5f, 0.0f}
    }), TestSuite::Compare::Container);

    CORRADE_COMPARE_AS(capsule.textureCoords2D(0), (std::vector<Vector2>{
        {0.5f, 0.0f},

        {0.0f, 0.166667f},
        {0.333333f, 0.166667f},
        {0.666667f, 0.166667f},
        {1.0f, 0.166667f},

        {0.0f, 0.333333f},
        {0.333333f, 0.333333f},
        {0.666667f, 0.333333f},
        {1.0f, 0.333333f},

        {0.0f, 0.5f},
        {0.333333f, 0.5f},
        {0.666667f, 0.5f},
        {1.0f, 0.5f},

        {0.0f, 0.666667f},
        {0.333333f, 0.666667f},
        {0.666667f, 0.666667f},
        {1.0f, 0.666667f},

        {0.0f, 0.833333f},
        {0.333333f, 0.833333f},
        {0.666667f, 0.833333f},
        {1.0f, 0.833333f},

        {0.5f, 1.0f}
    }), TestSuite::Compare::Container);

    CORRADE_COMPARE_AS(capsule.indices(), (std::vector<UnsignedInt>{
        0, 2, 1, 0, 3, 2, 0, 4, 3,
        1, 2, 6, 1, 6, 5, 2, 3, 7, 2, 7, 6, 3, 4, 8, 3, 8, 7,
        5, 6, 10, 5, 10, 9, 6, 7, 11, 6, 11, 10, 7, 8, 12, 7, 12, 11,
        9, 10, 14, 9, 14, 13, 10, 11, 15, 10, 15, 14, 11, 12, 16, 11, 16, 15,
        13, 14, 18, 13, 18, 17, 14, 15, 19, 14, 19, 18, 15, 16, 20, 15, 20, 19,
        17, 18, 21, 18, 19, 21, 19, 20, 21
    }), TestSuite::Compare::Container);
}
开发者ID:NextGenIntelligence,项目名称:magnum,代码行数:74,代码来源:CapsuleTest.cpp

示例5: make_tuple

std::tuple<Mesh, std::unique_ptr<Buffer>, std::unique_ptr<Buffer>> compile(const Trade::MeshData3D& meshData, const BufferUsage usage) {
    Mesh mesh;
    mesh.setPrimitive(meshData.primitive());

    /* Decide about stride and offsets */
    UnsignedInt stride = sizeof(Shaders::Generic3D::Position::Type);
    const UnsignedInt normalOffset = sizeof(Shaders::Generic3D::Position::Type);
    UnsignedInt textureCoordsOffset = sizeof(Shaders::Generic3D::Position::Type);
    if(meshData.hasNormals()) {
        stride += sizeof(Shaders::Generic3D::Normal::Type);
        textureCoordsOffset += sizeof(Shaders::Generic3D::Normal::Type);
    }
    if(meshData.hasTextureCoords2D())
        stride += sizeof(Shaders::Generic3D::TextureCoordinates::Type);

    /* Create vertex buffer */
    std::unique_ptr<Buffer> vertexBuffer{new Buffer{Buffer::TargetHint::Array}};

    /* Interleave positions */
    Containers::Array<char> data = MeshTools::interleave(
        meshData.positions(0),
        stride - sizeof(Shaders::Generic3D::Position::Type));
    mesh.addVertexBuffer(*vertexBuffer, 0,
        Shaders::Generic3D::Position(),
        stride - sizeof(Shaders::Generic3D::Position::Type));

    /* Add also normals, if present */
    if(meshData.hasNormals()) {
        MeshTools::interleaveInto(data,
            normalOffset,
            meshData.normals(0),
            stride - normalOffset - sizeof(Shaders::Generic3D::Normal::Type));
        mesh.addVertexBuffer(*vertexBuffer, 0,
            normalOffset,
            Shaders::Generic3D::Normal(),
            stride - normalOffset - sizeof(Shaders::Generic3D::Normal::Type));
    }

    /* Add also texture coordinates, if present */
    if(meshData.hasTextureCoords2D()) {
        MeshTools::interleaveInto(data,
            textureCoordsOffset,
            meshData.textureCoords2D(0),
            stride - textureCoordsOffset - sizeof(Shaders::Generic3D::TextureCoordinates::Type));
        mesh.addVertexBuffer(*vertexBuffer, 0,
            textureCoordsOffset,
            Shaders::Generic3D::TextureCoordinates(),
            stride - textureCoordsOffset - sizeof(Shaders::Generic3D::TextureCoordinates::Type));
    }

    /* Fill vertex buffer with interleaved data */
    vertexBuffer->setData(data, usage);

    /* If indexed, fill index buffer and configure indexed mesh */
    std::unique_ptr<Buffer> indexBuffer;
    if(meshData.isIndexed()) {
        Containers::Array<char> indexData;
        Mesh::IndexType indexType;
        UnsignedInt indexStart, indexEnd;
        std::tie(indexData, indexType, indexStart, indexEnd) = MeshTools::compressIndices(meshData.indices());

        indexBuffer.reset(new Buffer{Buffer::TargetHint::ElementArray});
        indexBuffer->setData(indexData, usage);
        mesh.setCount(meshData.indices().size())
            .setIndexBuffer(*indexBuffer, 0, indexType, indexStart, indexEnd);

    /* Else set vertex count */
    } else mesh.setCount(meshData.positions(0).size());

    return std::make_tuple(std::move(mesh), std::move(vertexBuffer), std::move(indexBuffer));
}
开发者ID:NextGenIntelligence,项目名称:magnum,代码行数:71,代码来源:Compile.cpp


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