Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QT5-QT3D rotation transforms and drawing points/lines/triangles



  • Hello,
    For anyone interested I have been working on a project (a c++ G-Code renderer if anyone cares) using Qt3D. As part of this project I wrote some classes which others may find useful.

    1.) Freerotation
    Available from :http://glennpavlovic.com/freerotation.tar.gz
    This is a class and some operators that allow you to specify rotations for a QTransform in any sequence you like as opposed to the ordering defined by QT3D. You are not limited to 3 rotations, and you can rotate around the same axis multiple times, e.g. XYXZ if you wanted to...

    For example:

    //Qt order of rotations is ZXY I need XYZ so...
        Qt3DCore::QTransform* vectTrans=new Qt3DCore::QTransform;
          //see freeRotation for how this works (first rotation is last in product)
          (*vectTrans)*clearRotation()*zRotation(dest.theta())*yRotation(dest.phi())*xRotation(90);
          internal->addComponent(vectTrans);
    
    

    2.) PrimitiveMash et al
    Available from: http://glennpavlovic.com/primitivemesh.tar.gz
    This is a group of three classes that provide access to the point, line, line strip, line loop, triangle, triangle strip, and triangle fan primitives. They subclass QGeometryRenderer so they can be used just like any other component. All are based on the PrimitiveMesh class. The only problems I have had with these is points don't show up (frame graph issue I think), and lines (and probably triangles) are always black (haven't figured this one out yet but I don't think it is a geometry issue, preliminary research indicates it may be a shader issue.)

    PrimitiveMesh: stores vertices only. Useful if you know there are going to be very few duplicate vertices in your mesh
    PrimitiveIndexdMesh: as the name implies uses indexed vertices, for all the obvious reasons
    PrimitiveHybridMesh: starts life as a vertices only mesh, switches to indexed if it detects enough duplication to make it worthwhile.

    In addition there is a function GenerateWireframe which will load a provided PrimitiveMesh with the vertices from another QGeometryRenderer.

    For example:

      Qt3DExtras::QTorusMesh* aTorus=new Qt3DExtras::QTorusMesh;
        aTorus->setMinorRadius(15.0);
        aTorus->setRadius(30.0);
    
      PrimitiveIndexedMesh* wireFrame= new PrimitiveIndexedMesh(nullptr,Qt3DRender::QGeometryRenderer::PrimitiveType::Lines);
        wireFrame->defer_commit(true);
        GenerateWireframe(*wireFrame,*aTorus);
        wireFrame->commit();
    
      Qt3DCore::QEntity* lineEntity=new Qt3DCore::QEntity(workspaceEntity);
         lineEntity->addComponent(wireFrame);
    
    

    I am releasing these under the following terms:
    You give me credit where credit is due.
    If you make money off them you give me some.

    Other than that you can do with them as you like. I make no warranties or guarantees about them being free of bugs. They have worked as expected in every case I have used them.



  • I have confirmed that the color issue is related to the qt provided shaders. Probably because I don't provide normals and tangents for my geometry (they don't make any sense for points and lines and I am too lazy to do it for the single case of triangles.) In any case I wrote my own simple QMaterial sub class which just colors everything it is used on a fixed color, so no reflections, highlights, etc. The default color is black, it seemed appropriate. It is released under the same terms as the others.

    It is available from: http://glennpavlovic.com/fixedcolormaterial.tar.gz

    Usage:

      FixedColorMaterial* pmesh_mat=new FixedColorMaterial;
        pmesh_mat->color(QColor("cyan"));
    
    

Log in to reply