Results 1 to 3 of 3

Thread: QML Mesh not Visible

  1. #1
    Join Date
    Feb 2018
    Posts
    24
    Thanks
    2
    Qt products
    Qt5
    Platforms
    Windows

    Default QML Mesh not Visible

    Good morning I'm Paul and I'm trying to show a mesh but it does not work, you have to put a texture on it?

    Main.cpp
    Qt Code:
    1. #include <Qt3DQuickExtras/qt3dquickwindow.h>
    2. #include <Qt3DQuick/QQmlAspectEngine>
    3.  
    4. #include <QGuiApplication>
    5. #include <QtQml>
    6.  
    7. int main(int argc, char **argv)
    8. {
    9. QGuiApplication app(argc, argv);
    10. Qt3DExtras::Quick::Qt3DQuickWindow view;
    11.  
    12. // Expose the window as a context property so we can set the aspect ratio
    13. view.engine()->qmlEngine()->rootContext()->setContextProperty("_window", &view);
    14. view.setSource(QUrl("qrc:/main.qml"));
    15. view.setWidth(800);
    16. view.setHeight(600);
    17. view.show();
    18.  
    19. return app.exec();
    20. }
    To copy to clipboard, switch view to plain text mode 

    Main.qml
    Qt Code:
    1. import Qt3D.Core 2.0
    2. import Qt3D.Render 2.0
    3. import Qt3D.Input 2.0
    4. import Qt3D.Extras 2.0
    5.  
    6. Entity {
    7. id: sceneRoot
    8.  
    9. Camera {
    10. id: camera
    11. projectionType: CameraLens.PerspectiveProjection
    12. fieldOfView: 25
    13. aspectRatio: _window.width / _window.height
    14. nearPlane : 0.1
    15. farPlane : 1000.0
    16. position: Qt.vector3d( 0, 0.0, 20.0 )
    17. upVector: Qt.vector3d( 0.0, 1.0, 0.0 )
    18. viewCenter: Qt.vector3d( 0.0, 0.0, 0.0 )
    19. }
    20.  
    21. OrbitCameraController {
    22. camera: camera
    23. }
    24.  
    25. components: [
    26. RenderSettings {
    27. activeFrameGraph: ForwardRenderer {
    28. clearColor: Qt.rgba(0, 0.5, 1, 1)
    29. camera: camera
    30. }
    31. },
    32. InputSettings { }
    33. ]
    34.  
    35. PhongMaterial {
    36. id: carMaterial
    37. }
    38.  
    39. Mesh {
    40. id: carMesh
    41. source: "SferaStl.stl"
    42. }
    43.  
    44. Entity {
    45. id: carEntity
    46. components: [ carMesh, carMaterial ]
    47. }
    48. }
    To copy to clipboard, switch view to plain text mode 

    File.pro

    Qt Code:
    1. QT += 3dextras widgets 3dcore 3drender 3dinput 3dquick qml quick 3dquickextras
    2. CONFIG += c++11
    3.  
    4. # The following define makes your compiler emit warnings if you use
    5. # any feature of Qt which as been marked deprecated (the exact warnings
    6. # depend on your compiler). Please consult the documentation of the
    7. # deprecated API in order to know how to port your code away from it.
    8. DEFINES += QT_DEPRECATED_WARNINGS
    9.  
    10. # You can also make your code fail to compile if you use deprecated APIs.
    11. # In order to do so, uncomment the following line.
    12. # You can also select to disable deprecated APIs only up to a certain version of Qt.
    13. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
    14.  
    15. SOURCES += main.cpp
    16.  
    17. RESOURCES += qml.qrc\
    18.  
    19.  
    20.  
    21. # Additional import path used to resolve QML modules in Qt Creator's code model
    22. QML_IMPORT_PATH =
    23.  
    24. # Additional import path used to resolve QML modules just for Qt Quick Designer
    25. QML_DESIGNER_IMPORT_PATH =
    26.  
    27. # Default rules for deployment.
    28. qnx: target.path = /tmp/$${TARGET}/bin
    29. else: unix:!android: target.path = /opt/$${TARGET}/bin
    30. !isEmpty(target.path): INSTALLS += target
    31.  
    32. DISTFILES += \
    33. main.qml \
    34.  
    35. SUBDIRS += \
    36. untitled1.pro
    To copy to clipboard, switch view to plain text mode 

    The program starts and the window appears but you do not see the mesh that is located on the root

  2. #2
    Join Date
    Feb 2019
    Posts
    2
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QML Mesh not Visible

    Hello! I am using almost the same setup (.ply instead of .stl) but the code is nearly identical, and I have the exact same problem. If I come up with something I will tell you.

  3. #3
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,229
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QML Mesh not Visible

    The first step when debugging code that loads data from a file using a relative path is to check what your program thinks the actual, absolute path is. That path is what the program will really use to find the file. QFile::exists() will tell you if the string you are using to try to load the file actually points to a file. QDir::currentPath() will give you the current working directory, which is where a program will look for a relative file name ("myfile.stl", without path qualifiers, for example).
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. QtOpenGL Module - load mesh into QGLWidget
    By fp13 in forum Qt Programming
    Replies: 1
    Last Post: 13th September 2012, 17:52
  2. Replies: 1
    Last Post: 9th February 2011, 08:30
  3. Draw a mesh using Qwt?
    By alex_sh in forum Qwt
    Replies: 2
    Last Post: 5th October 2010, 17:55
  4. opengl rendering mesh elements contour problem
    By sujan.dasmahapatra in forum Qt Programming
    Replies: 1
    Last Post: 2nd February 2010, 08:07

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.