Utilisation de Qt Quick 3D
Bonjour à tous !
Je suis un peu perdu et commence à perdre espoir en Qt Quick 3D.
Mon projet :
Afficher des éléments 3D et pouvoir repérer des matériaux et les animer.
Un exemple :
Mon logiciel récupère un fichier provenant de SolidWorks (un véhicule). Il l'affiche en 3D. On peut sélectionner une portière, une roue, ... Et on peut les animer (tourner la roue, ...)
Mon logiciel doit pouvoir ouvrir plusieurs type de véhicule mais ils auront toujours des éléments en commun (certaines 4 roues, d'autres 2 roues, ...)
Un peu comme ça en fait :
https://www.youtube.com/watch?v=VvQ_...hannel=QtGroup
1. Je me suis renseigner sur les différents traitement 3D sous Qt. J'en ai déduis d'utiliser Qt Quick 3D qui me semble être une solution pérenne pour mon projet.
2. J'ai transformé mes fichiers SolidWorks en fichier .obj et .gltf pour faire des tests.
Après des jours et des jours, je suis arrivé à ce code qui compile mais n'ouvre qu'une fenêtre grise :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
import QtQuick.Controls 2.15
import QtQuick.Dialogs
import QtQuick.Scene3D 2.15
import Qt3D.Core 2.15
import Qt3D.Render 2.15
import Qt3D.Input 2.15
import Qt3D.Extras 2.15
import QtQuick.Controls.Material 2.15
ApplicationWindow {
visible: true
width: 800
height: 600
Scene3D {
id: mainScene3d
anchors.fill: parent
focus: true
hoverEnabled: true
aspects: ["input", "logic", "render"]
cameraAspectRatioMode: Scene3D.AutomaticAspectRatio
Entity {
id: sceneRoot
Camera {
projectionType: CameraLens.PerspectiveProjection
fieldOfView: 45
aspectRatio: mainScene3d.width / mainScene3d.height
nearPlane: 0.1
farPlane: 1000.0
position: Qt.vector3d(0, 0, 5)
upVector: Qt.vector3d(0, 1, 0)
viewCenter: Qt.vector3d(0, 0, 0)
}
OrbitCameraController
{
camera: camera
}
RenderSettings {
activeFrameGraph: ForwardRenderer {
clearColor: "#333333"
camera: camera
}
}
Entity {
Mesh {
source: "file:///C:/Users/frigo/friog.gltf"
}
}
Entity {
Mesh {
source: "file:///C:/Users/frigo/porte.gltf"
}
}
}
}
} |
Avec un autre code, j'ai pu afficher mon fichier OBJ mais il s'affiche mal (comme si on regardait à travers une loupe)
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
|
import QtQuick.Controls 2.15
import QtQuick.Dialogs
import QtQuick.Scene3D 2.15
import Qt3D.Core 2.15
import Qt3D.Render 2.15
import Qt3D.Input 2.15
import Qt3D.Extras 2.15
import QtQuick.Controls.Material 2.15
ApplicationWindow {
visible: true
width: 640
height: 480
title: qsTr("3D Viewer")
header: ToolBar
{
Material.theme: Material.Dark
ToolButton
{
text: "Open 3D Model"
onPressed:
{
fileDialog.open()
}
}
}
FileDialog
{
id: fileDialog
onAccepted:
{
if (fileDialog.fileUrl) {
sceneLoader.source = fileDialog.fileUrl
print(fileDialog.fileUrl)
mainScene3d.forceActiveFocus()
}
}
}
Scene3D
{
id:mainScene3d
anchors.fill: parent
focus: true
hoverEnabled: true
aspects: ["input", "logic","render"]
cameraAspectRatioMode: Scene3D.AutomaticAspectRatio
Entity
{
id: sceneRoot
Camera
{
id: camera
projectionType: CameraLens.PerspectiveProjection
fieldOfView: 30
aspectRatio: 16/9
nearPlane : 0.1
farPlane : 100.0
position: Qt.vector3d( 10.0, 0.0, 10.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:"#333333"
camera: camera
}
},
InputSettings
{
}
]
Entity
{
id: monkeyEntity
components: [
SceneLoader
{
id: sceneLoader
}
]
}
}
}
} |
J'y suis depuis plusieurs semaines, je ne trouve aucun tuto récent (beaucoup sur Qt3D mais plus d'actualité ou d'autre impossible à faire fonctionner).
Ma solution pourrait-elle marcher ? Faut-il traiter les fichiers 3D en amont pour faire ce que je veux ?
Quelqu'un aurait un tuto sur Qt Quick 3D récent ?
Merci infiniment