Qt3D: Show Edges for 3D Cuboids
-
I am using Qt3D and C++ to draw intersecting cuboids.Every thing is fine expect for the edges as they don't appear.I checked for properties in QCuboidMesh and QPhongAlphaMaterial but I couldn't find such one.
The output image
The code:SceneModifier::SceneModifier(Qt3DCore::QEntity *rootEntity) : m_rootEntity(rootEntity) { //Outer Cuboid shape data cuboid = new Qt3DExtras::QCuboidMesh(); cuboid->setXExtent(4); cuboid->setYExtent(4); cuboid->setZExtent(8); // CuboidMesh Transform Qt3DCore::QTransform *cuboidTransform = new Qt3DCore::QTransform(); Qt3DExtras::QPhongAlphaMaterial *cuboidMaterial = new Qt3DExtras::QPhongAlphaMaterial(); cuboidMaterial->setDiffuse(QColor(QRgb(0xff0ff0))); cuboidMaterial->setAlpha(0.5); //Cuboid m_cuboidEntity = new Qt3DCore::QEntity(m_rootEntity); m_cuboidEntity->addComponent(cuboid); m_cuboidEntity->addComponent(cuboidMaterial); // Inner Cuboid shape data cuboid2 = new Qt3DExtras::QCuboidMesh(); cuboid2->setXExtent(2); cuboid2->setYExtent(2); cuboid2->setZExtent(8); Qt3DExtras::QPhongMaterial *cuboidMaterial2 = new Qt3DExtras::QPhongMaterial(); cuboidMaterial2->setDiffuse(QColor(QRgb(0xffffff))); //Cuboid m_cuboidEntity2 = new Qt3DCore::QEntity(m_rootEntity); m_cuboidEntity2->addComponent(cuboid2); m_cuboidEntity2->addComponent(cuboidMaterial2); Qt3DCore::QTransform* cuboidTransform3 = new Qt3DCore::QTransform(); cuboidTransform3->setRotation(QQuaternion::fromAxisAndAngle(QVector3D(0.1f, -0.1f, 0.0f), 45.0f)); m_rootEntity->addComponent(cuboidTransform3); }
-
Hi, and welcome to the Qt forum!
@Youssef-Emad said:
Every thing is fine expect for the edges as they don't appear.
That's because only facets (triangles) are rendered, and not edges. and when the facets along an edge have the same color (because of your lighting model etc.) then you can't tell where they meet. If you want to render the edges you'll need to use different shaders.
-
I meet the same problem, I show my custom mesh(construct with QGeometry and QGeometryRenderer,with QPhongMaterial),there is no light and shade effect,i think i can solve the problem with GLSL(shader),I found a shader example in qt document: Qt3D:Defferred Renderer C++ Example,I can not run the example,Even I can not find the main.cpp in the example,Is there any one show me a example about how to custom my material use shader.Thank you very much.