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

Mesh not Visible



  • Hi all, I'm trying to make my * .stl file appear in the same directory as the project but I do not see these are my fie:

    Main.cpp

    #include <Qt3DQuickExtras/qt3dquickwindow.h>
    #include <Qt3DQuick/QQmlAspectEngine>
    
    #include <QGuiApplication>
    #include <QtQml>
    
    int main(int argc, char **argv)
    {
        QGuiApplication app(argc, argv);
        Qt3DExtras::Quick::Qt3DQuickWindow view;
    
        // Expose the window as a context property so we can set the aspect ratio
        view.engine()->qmlEngine()->rootContext()->setContextProperty("_window", &view);
        view.setSource(QUrl("qrc:/main.qml"));
        view.setWidth(800);
        view.setHeight(600);
        view.show();
    
        return app.exec();
    }
    
    

    Main.qml

    import Qt3D.Core 2.0
    import Qt3D.Render 2.0
    import Qt3D.Input 2.0
    import Qt3D.Extras 2.0
    
    Entity {
        id: sceneRoot
    
        Camera {
            id: camera
            projectionType: CameraLens.PerspectiveProjection
            fieldOfView: 25
            aspectRatio: _window.width / _window.height
            nearPlane : 0.1
            farPlane : 1000.0
            position: Qt.vector3d( 0, 0.0, 20.0 )
            upVector: Qt.vector3d( 0.0, 1.0, 0.0 )
            viewCenter: Qt.vector3d( 0.0, 0.0, 0.0 )
        }
    
        OrbitCameraController {
            camera: camera
        }
    
        components: [
            RenderSettings {
                activeFrameGraph: ForwardRenderer {
                    clearColor: Qt.rgba(0, 0.5, 1, 1)
                    camera: camera
                }
            },
            InputSettings { }
        ]
    
        PhongMaterial {
            id: carMaterial
        }
    
        Mesh {
            id: carMesh
            source: "SferaStl.stl"
        }
    
        Entity {
            id: carEntity
            components: [ carMesh, carMaterial ]
        }
    }
    
    

    this is the result:
    alt text



  • @Nio74

    Is that possible because I have to apply a texture?

    Help, there's no one doing things like that?



  • I am having the exact same problem with nearly identical code as yours. The only difference is that I am loading a .PLY file. If (when!) I figure this out I will let you know immediately.



  • Ok, I was able to get it to work in C++ but I haven't tried it with QML yet. I THINK the problem lies in the path to the object file. When I gave it the explicit path with:

    m_suzanneMesh->setSource(QUrl::fromLocalFile("C:/Qt/Examples/Qt-5.10.1/qt3d/scene3d/Suzanne.ply"));

    instead of

    m_suzanneMesh->setSource(QUrl(QStringLiteral("qrc:/new/prefix1/Suzanne.ply")));

    it magically worked. My theory is that when the model loader has a problem finding the file it doesn't report anything to that effect, it just goes ahead and displays an empty mesh.

    Hope that helps!


Log in to reply