Unsolved Importing a 3D object in to the window
-
Hi, I have created a window with buttons like forward and backward etc...so how can I import a 3D image(.obj from blender) so that I can control that robot in the same window.
import Qt3D.Core 2.0
import Qt3D.Render 2.0
import QtQuick 2.2 as QQ2Entity {
id: carMeshsource: "untitled.3ds"
}
Item3D {
Mesh: carMesh
}
}It's saying syntax error near Item3D. can someone help me please....
-
Hi @hareeshqt ,
Did you try these 3D models ?
-
@Ni.Sumi I have tried the wavefront model but I need the buttons and the 3D model in the same window...
-
@hareeshqt , you are talking some thing like in AudioVisualizer ? Like the stop , play and controlling the mesh ?
-
@Ni.Sumi Yes, we need to control a robotic arm here
-
@hareeshqt Hi! I've built a small demo for you, see a video here and get the sources here.
Looks like this:
Code is:
main.cpp
#include <QGuiApplication> #include <QQmlApplicationEngine> int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); QQmlApplicationEngine engine; engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); return app.exec(); }
main.qml
import QtQuick 2.5 import Qt3D.Core 2.0 import Qt3D.Render 2.0 import QtQuick.Scene3D 2.0 import QtQuick.Window 2.2 import QtQuick.Controls 1.4 ApplicationWindow { visible: true width: 640 height: 480 // Background Rectangle { id: backgroundRectangle anchors.fill: parent gradient: Gradient { GradientStop { position: 0.0; color: "#5A6B9B" } GradientStop { position: 1.0; color: "#E4E4E4" } } } // 3D scene Scene3D { id: scene3d anchors.fill: parent aspects: "input" Entity { id: root components: [ FrameGraph { activeFrameGraph: Viewport { rect: Qt.rect(0.0, 0.0, 1.0, 1.0) clearColor: "transparent" CameraSelector { camera: mainCamera ClearBuffer { buffers: ClearBuffer.ColorDepthBuffer } } } } ] Camera { id: mainCamera projectionType: CameraLens.PerspectiveProjection fieldOfView: 45.0 / 8.0 nearPlane: 0.1 farPlane: 1000.0 viewCenter: Qt.vector3d( 0.0, 0.0, 0.0 ) upVector: Qt.vector3d( 0.0, 1.0, 0.0 ) position: Qt.vector3d( 0.0, 0.0, 10.0 ) aspectRatio: scene3d.width / scene3d.height } Configuration { controlledCamera: mainCamera } Mesh { id: myMesh source: "qrc:/assets/gear.obj" } PhongMaterial { id: myMaterial ambient: Qt.rgba( 0.3, 0.3, 0.3, 1.0 ) diffuse: Qt.rgba( 0.7, 0.7, 0.7, 1.0 ) } Transform { id: myTransform property real userAngle: 0.0 property real userDistance: 0.0 matrix: { var m = Qt.matrix4x4(); m.rotate(userAngle, Qt.vector3d(1, 1, 0)); m.translate(Qt.vector3d(userDistance, 0, 0)); return m; } } Entity { id: myEntity components: [ myMesh, myMaterial, myTransform ] } } } // Controls overlay Row { Button { text: "Rotate XY+" onClicked: myTransform.userAngle += 10 } Button { text: "Rotate XY-" onClicked: myTransform.userAngle -= 10 } Button { text: "Transform X+" onClicked: myTransform.userDistance += 0.05 } Button { text: "Transform X-" onClicked: myTransform.userDistance -= 0.05 } Button { text: "Reset transformation" onClicked: { myTransform.userAngle = 0.0 myTransform.userDistance = 0.0 } } Button { text: "Exit" onClicked: Qt.quit() } } }
-
@Wieland OK Many Many thanks....I think you have completed majority of my task....trying the model now...
-
@Wieland HI, Thank you very much for the model,I have tried my 3d model and it's working perfectly fine but in my model I need to move only some specific parts like the arms or the gripper and I have selected the vertices of that parts from blender (X=0.2354,Y=0.3547,Z=2.3356) like this, so which command should I use to make that parts move.....
-
@hareeshqt You need to but each part into its own .obj file. In the demo the gear represents a single movable part. You need to create a mesh (in qml) from each .obj file and create a dedicated transformation (in qml) for each of these meshes. You can then control the parts individually. To form kinematic chains you need to concatenate the transformations.
-
@Wieland Yes I have created meshes for each part individually and they have different vertices.
// onClicked: myTransform.userAngle += 10 should I use those vertices here...
-
@hareeshqt Sorry dude, I really don't understand your question. Do you know how transformation matrices work?
-
@Wieland No, I don't have the idea. I thought that by using these vertices in the qml code we can move only those parts in the model. Is there any example to learn regarding this?
-
@hareeshqt I've sent you a link to a book on the chat.
-
Could you make an update to the code you just showed, I couldn't run it, it does not recognize Configurations, controlled camera, Thank you