Geometry: Create a geometry model with geometric primitives

A geometry model has a part data generator that can be used to tessellate various geometric primitives.

In this tutorial you will create your own geometry model parts and apply some part settings.

Create the following parts:

  • A box

  • A sphere

  • A cylinder

../_images/tut_geometry_primitives.png
void TutorialRunnerMainWindow::createGeometryModelWithPrimitives()
{
    //--------------------------------------------------------------------------
    // Create a geometry model using the PartDataGenerator to tessellate 
    // a box, sphere and cylinder. Apply simple part settings.
    //--------------------------------------------------------------------------
    cee::vis::View* gcView = getTutorialView();
    cee::PtrRef<cee::geo::GeometryModel> geometryModel = new cee::geo::GeometryModel;
    gcView->setModelOpenGLCapabilitiesFromView(geometryModel.get());

    // Add a yellow box
    cee::PtrRef<cee::geo::Part> boxPart = new cee::geo::Part(cee::geo::DataGenerator::createBox(cee::Vec3d(1.0, 1.0, 1.0), cee::Vec3d(2.0, 2.0, 2.0)).get());
    geometryModel->addPart(boxPart.get());

    // Add a sphere with default color
    cee::PtrRef<cee::geo::Part> spherePart = new cee::geo::Part(cee::geo::DataGenerator::createSphere(cee::Vec3d(4.0, 2.0, 1.0), 1.0, 30).get());
    geometryModel->addPart(spherePart.get());

    // Add a red cylinder
    cee::PtrRef<cee::geo::Part> cylinderPart = new cee::geo::Part(cee::geo::DataGenerator::createCylinder(cee::Vec3d(6.0, 2.0, 1.0), 0.8, 0.0, cee::Vec3d(0,0,1), 3, 50).get());
    geometryModel->addPart(cylinderPart.get());

    // Settings
    boxPart->settings().addEffect(new cee::geo::EffectColor(cee::Color3f(1,1,0)));
    cylinderPart->settings().addEffect(new cee::geo::EffectColor(cee::Color3f(1,0,0)));


    // Add model to view. Ensure that old models are removed first
    gcView->removeAllModels();
    gcView->addModel(geometryModel.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();
}