PDA

View Full Version : QML Mesh not Visible



Nio74
6th February 2018, 13:04
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


#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 ]
}
}


File.pro



QT += 3dextras widgets 3dcore 3drender 3dinput 3dquick qml quick 3dquickextras
CONFIG += c++11

# The following define makes your compiler emit warnings if you use
# any feature of Qt which as been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS

# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0

SOURCES += main.cpp

RESOURCES += qml.qrc\



# Additional import path used to resolve QML modules in Qt Creator's code model
QML_IMPORT_PATH =

# Additional import path used to resolve QML modules just for Qt Quick Designer
QML_DESIGNER_IMPORT_PATH =

# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target

DISTFILES += \
main.qml \

SUBDIRS += \
untitled1.pro



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

MProstka
11th February 2019, 12:56
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.

d_stranz
11th February 2019, 17:06
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).