# Geometry: Create a Geometry Model with Texture

The `geometry model` offers optimized part drawing with different parts and effects.

This example creates a simple triangle part and use texture effect to show scalar values.

    void TutorialRunnerMainWindow::createGeometryModelWithTexture()
    {
        //--------------------------------------------------------------------------
        // Create a geometry model and triangle part
        //--------------------------------------------------------------------------

        cee::vis::View* gcView = getTutorialView();
        gcView->removeAllModels();

        cee::PtrRef<cee::geo::GeometryModel> model = new cee::geo::GeometryModel;
        gcView->addModel(model.get());

        // Create the geometry part
        std::vector<cee::Vec3d> vertices;
        vertices.push_back(cee::Vec3d(0,0,0));
        vertices.push_back(cee::Vec3d(2,0,0));
        vertices.push_back(cee::Vec3d(0,1,0));
        vertices.push_back(cee::Vec3d(2,1,0));
        vertices.push_back(cee::Vec3d(2,2,0));

        std::vector<unsigned int> indices;
        indices.push_back(0); indices.push_back(1); indices.push_back(3);
        indices.push_back(0); indices.push_back(3); indices.push_back(2);
        indices.push_back(2); indices.push_back(3); indices.push_back(4);

        cee::PtrRef<cee::geo::Part> part = new cee::geo::Part;
        cee::PtrRef<cee::geo::DataIndexedTriangles> triangleData = new cee::geo::DataIndexedTriangles(vertices, indices);
        part->setData(triangleData.get());

        //--------------------------------------------------------------------------
        // Create the scalar mapper and the legend
        //--------------------------------------------------------------------------

        // Create a color legend and add to view
        cee::PtrRef<cee::vis::OverlayColorLegendContinuousDomain> legend = new cee::vis::OverlayColorLegendContinuousDomain(cee::vis::Font::createNormalFont().get());
        legend->setTitle("Results Test \nGeometry Model");
        legend->setSize(100,500);
        legend->setTextColor(cee::Color3f(1,1,1));
        gcView->overlay().addItem(legend.get(), cee::vis::OverlayItem::BOTTOM_LEFT, cee::vis::OverlayItem::VERTICAL);

        // Create scalar mapper with 16 uniform levels
        cee::PtrRef<cee::vis::ScalarMapperFilledContoursUniform> mapper = new cee::vis::ScalarMapperFilledContoursUniform;
        mapper->setColors(cee::vis::ColorTableFactory::NORMAL, 16);
        mapper->setRange(0, 100);
        legend->setupFromScalarMapper(mapper.get());

        //--------------------------------------------------------------------------
        // Map texture coordinates
        //--------------------------------------------------------------------------

        // Create texture coordinates from scalar values
        std::vector<cee::Vec2f> textureCoordinates;
        textureCoordinates.push_back(mapper->mapToTextureCoordinate(2.0));
        textureCoordinates.push_back(mapper->mapToTextureCoordinate(42.0));
        textureCoordinates.push_back(mapper->mapToTextureCoordinate(93.0));
        textureCoordinates.push_back(mapper->mapToTextureCoordinate(27.0));
        textureCoordinates.push_back(mapper->mapToTextureCoordinate(68.0));
        part->setTextureCoordinates(new cee::geo::TextureCoordinates(textureCoordinates));

        //--------------------------------------------------------------------------
        // Setup and add effects
        //--------------------------------------------------------------------------

        // Create texture image from mapper
        cee::PtrRef<cee::Image> textureImage = new cee::Image;
        mapper->updateTexture(textureImage.get());

        // Add triangle and texture effects
        part->settings().addEffect(cee::geo::EffectTexture::createResultMapping(textureImage.get()).get());

        //--------------------------------------------------------------------------
        // Add all parts to model
        //--------------------------------------------------------------------------
        model->addPart(part.get());

        cee::BoundingBox bb = gcView->boundingBox();
        gcView->camera().fitView(bb, cee::Vec3d(0, 0, -1), cee::Vec3d(0, 1, 0));
        gcView->camera().inputHandler()->setRotationPoint(bb.center());

        gcView->requestRedraw();
    }

Conversation saved
HOOPSY BETA

### Hello! I'm HOOPSY

Your multilingual generative AI assistant for documentation. Ask me anything about HOOPS Envision for Desktop in your own language, or choose a sample question below to start a conversation:

What is HOOPS Envision for Desktop?
What are the latest release notes for HOOPS Envision for Desktop?
How do I start evaluating HOOPS Envision for Desktop?
How do I write my first sample application?
How can I get assistance?

HOOPSY may store conversations according to OpenAI's policy. Responses may not always be accurate.

HOOPSY is thinking...