Animation, 3D development
-
Just ask them. KDAB website, twitter, facebook.
-
Just ask them. KDAB website, twitter, facebook.
-
Hi!
@Naveen_D said in Animation, 3D development:
can anyone help me how to create and .obj object
You don't do that yourself but either buy ready-made models or pay a digital artist to create one specifically for you. Google "buy 3d models".
how to load it and display in Qml?
See Mesh QML Type,
Mesh { id: mesh source: "cars/BMW/i8.obj" }
-
Hi!
@Naveen_D said in Animation, 3D development:
can anyone help me how to create and .obj object
You don't do that yourself but either buy ready-made models or pay a digital artist to create one specifically for you. Google "buy 3d models".
how to load it and display in Qml?
See Mesh QML Type,
Mesh { id: mesh source: "cars/BMW/i8.obj" }
-
@Naveen_D said in Animation, 3D development:
is there any open source from where i can take 3D models
Maybe use google search?
-
I used from this place
https://www.turbosquid.com/Search/3D-Models/free/objMaybe this one :)
https://www.turbosquid.com/3d-models/3d-mercedes-benz-sls-amg-model/644946 -
Hi!
@Naveen_D said in Animation, 3D development:
can anyone help me how to create and .obj object
You don't do that yourself but either buy ready-made models or pay a digital artist to create one specifically for you. Google "buy 3d models".
how to load it and display in Qml?
See Mesh QML Type,
Mesh { id: mesh source: "cars/BMW/i8.obj" }
-
I used from this place
https://www.turbosquid.com/Search/3D-Models/free/objMaybe this one :)
https://www.turbosquid.com/3d-models/3d-mercedes-benz-sls-amg-model/644946 -
Here's an almost minimal example in QML:
GearEntity.qml
import Qt3D.Core 2.0 import Qt3D.Render 2.0 import Qt3D.Input 2.0 import Qt3D.Extras 2.0 Entity { id: gearEntity Mesh { id: gearMesh source: "qrc:///assets/gear.obj" } Transform { id: gearTransform scale3D: Qt.vector3d(45, 45, 45) rotation: fromAxisAndAngle(Qt.vector3d(1, 0, 0), 45) } PhongMaterial { id: gearMaterial } Entity { id: torusEntity components: [ gearMesh, gearTransform, gearMaterial ] } }
RootEntity.qml
import Qt3D.Core 2.0 import Qt3D.Render 2.0 import Qt3D.Input 2.0 import Qt3D.Extras 2.0 Entity { id: rootEntity Camera { id: camera projectionType: CameraLens.PerspectiveProjection fieldOfView: 45 nearPlane : 0.1 farPlane : 1000.0 position: Qt.vector3d( 0.0, 0.0, 40.0 ) upVector: Qt.vector3d( 0.0, 1.0, 0.0 ) viewCenter: Qt.vector3d( 0.0, 0.0, 0.0 ) } FirstPersonCameraController { camera: camera } components: [ RenderSettings { activeFrameGraph: ForwardRenderer { camera: camera clearColor: "transparent" } }, InputSettings {} ] GearEntity {} }
main.qml
import QtQuick 2.7 import QtQuick.Window 2.3 import QtQuick.Controls 2.0 import QtQuick.Layouts 1.3 import QtQuick.Scene3D 2.0 import Qt3D.Core 2.0 import Qt3D.Render 2.0 import Qt3D.Extras 2.0 ApplicationWindow { visible: true visibility: Window.Maximized Rectangle { anchors.fill: parent gradient: Gradient { GradientStop { position: 0.0; color: "blue" } GradientStop { position: 1.0; color: "grey" } } } Scene3D { id: scene3d anchors.fill: parent focus: true aspects: ["input", "logic"] cameraAspectRatioMode: Scene3D.AutomaticAspectRatio RootEntity {} } Button { text: "Exit" onClicked: Qt.quit() } }
-
Here's an almost minimal example in QML:
GearEntity.qml
import Qt3D.Core 2.0 import Qt3D.Render 2.0 import Qt3D.Input 2.0 import Qt3D.Extras 2.0 Entity { id: gearEntity Mesh { id: gearMesh source: "qrc:///assets/gear.obj" } Transform { id: gearTransform scale3D: Qt.vector3d(45, 45, 45) rotation: fromAxisAndAngle(Qt.vector3d(1, 0, 0), 45) } PhongMaterial { id: gearMaterial } Entity { id: torusEntity components: [ gearMesh, gearTransform, gearMaterial ] } }
RootEntity.qml
import Qt3D.Core 2.0 import Qt3D.Render 2.0 import Qt3D.Input 2.0 import Qt3D.Extras 2.0 Entity { id: rootEntity Camera { id: camera projectionType: CameraLens.PerspectiveProjection fieldOfView: 45 nearPlane : 0.1 farPlane : 1000.0 position: Qt.vector3d( 0.0, 0.0, 40.0 ) upVector: Qt.vector3d( 0.0, 1.0, 0.0 ) viewCenter: Qt.vector3d( 0.0, 0.0, 0.0 ) } FirstPersonCameraController { camera: camera } components: [ RenderSettings { activeFrameGraph: ForwardRenderer { camera: camera clearColor: "transparent" } }, InputSettings {} ] GearEntity {} }
main.qml
import QtQuick 2.7 import QtQuick.Window 2.3 import QtQuick.Controls 2.0 import QtQuick.Layouts 1.3 import QtQuick.Scene3D 2.0 import Qt3D.Core 2.0 import Qt3D.Render 2.0 import Qt3D.Extras 2.0 ApplicationWindow { visible: true visibility: Window.Maximized Rectangle { anchors.fill: parent gradient: Gradient { GradientStop { position: 0.0; color: "blue" } GradientStop { position: 1.0; color: "grey" } } } Scene3D { id: scene3d anchors.fill: parent focus: true aspects: ["input", "logic"] cameraAspectRatioMode: Scene3D.AutomaticAspectRatio RootEntity {} } Button { text: "Exit" onClicked: Qt.quit() } }
@Wieland thank you... i got the output.
I have one doubt, in the output when i try to rotate the object it is not rotating in the same place, instead the camera is rotating(i guess), is there any way to fix the camera and rotate the object in 360 deg ?
Thank you -
That's just how
FirstPersonCameraController
works. You could either implement your own camera controller or - instead of moving the camera - dynamically changegearTransform
. -
That's just how
FirstPersonCameraController
works. You could either implement your own camera controller or - instead of moving the camera - dynamically changegearTransform
. -
That's just how
FirstPersonCameraController
works. You could either implement your own camera controller or - instead of moving the camera - dynamically changegearTransform
. -
That's just how
FirstPersonCameraController
works. You could either implement your own camera controller or - instead of moving the camera - dynamically changegearTransform
.@Wieland
I have made few changes in the code shared by you, what i have done is, Using blender software i have sliced the car obj for few diff parts like door, wheel, window, bonet etc and i have rearranged the whole car by adding the car parts in the code.
Now when i try to add some animation for each of the part, for example i want the door to open and close as usual as it does normally, but what is happening,the door part is taking car body as the center and it is rotating inwards in the given angle. how can i change this to make it work properly.
here is the code,import Qt3D.Core 2.0 import Qt3D.Render 2.0 import Qt3D.Input 2.0 import Qt3D.Extras 2.0 import QtQuick 2.5 Entity { id: carFrontLeftDoorEntity Mesh { id: carFrontLeftDoorMesh source: "qrc:/Meshes/Car_FrontLeftDoor.obj" } Transform { id: carFrontLeftDoorMeshTransform scale3D: Qt.vector3d(1.5,1.5,1.5) rotation: fromAxisAndAngle(Qt.vector3d(1, 0, 1), 30) rotationY: 0 SequentialAnimation { loops: Animation.Infinite running: true NumberAnimation { target: carFrontLeftDoorMeshTransform property: "rotationY" from: 0; to: 15 duration: 2000 easing.type: Easing.InOutQuad } } } PhongMaterial { id: carFrontLeftDoorMeshMaterial ambient: Qt.rgba( 0.0,0.0,0.0, 0.6 ) diffuse: Qt.rgba( 0.3, 0.0, 128, 0.2 ) } Entity { id: carFrontLeftDoorMeshtorusEntity components: [ carFrontLeftDoorMesh, carFrontLeftDoorMeshTransform, carFrontLeftDoorMeshMaterial ] } }
this i have added in the gearentity.qml as separate part.
Entity { id: gearEntity CarRawBody{} CarFrontGlass{} CarBonet{} CarDikki{} CarFrontLeftWheel{} CarRearLeftWheel{} CarFrontLeftDoor{} CarRearLeftDoor{} CarFrontLeftWindow{} CarRearLeftWindow{} }
-
Hi! Sorry, that it already just too complex / incomplete for me to test and help with. Can you boil it down to a simpler question or a minimal runnable example that I - or anyone else who reads this - can use to reproduce the issue?
-
Hi! Sorry, that it already just too complex / incomplete for me to test and help with. Can you boil it down to a simpler question or a minimal runnable example that I - or anyone else who reads this - can use to reproduce the issue?
@Wieland ya sure.. i will reproduce it and post the example code..
Can you please guide in the following issue also
Thank you.
https://forum.qt.io/topic/84633/camera-rotation-around-a-mesh -
Hi! Sorry, that it already just too complex / incomplete for me to test and help with. Can you boil it down to a simpler question or a minimal runnable example that I - or anyone else who reads this - can use to reproduce the issue?
@Wieland Hi,
I have few doubts regarding rotating an object in 3D,
For ex, i have a car model, which i have sliced in blender, to get door as a separate object and whole car as a separate object, i have exported both as .obj files and i have assembled them in the code.
Now what is happening, when i try to rotate the door which is separate object using number animation, it is rotating with respect to car's origin not w.r.t to door's so, i want to rotate it based on it's own axis or origin. not w.r.t car's origin.
I have tried the following code but didn't get the excepted result.// Car front door // Mesh { id: carDoorMesh source: "qrc:/Meshes/CarFrontDoor_modified.obj" } PhongMaterial{ id: carDoorMaterial } Transform { id: carDoorTransform property real userAngle: 0.0 matrix: { var m= Qt.matrix4x4(); m.translate(Qt.vector3d(0.501096,1.5006,1.78036)) m.rotate(userAngle, Qt.vector3d(0,1,0)) m.translate(Qt.vector3d(-0.501096,-1.5006,-1.75036)) return m } NumberAnimation on rotationY { to: -45 duration: 1000 running: true } }
i got the respective values from blender.
Any guidance is appreciated
Thank you. -
@Wieland Hi,
I have few doubts regarding rotating an object in 3D,
For ex, i have a car model, which i have sliced in blender, to get door as a separate object and whole car as a separate object, i have exported both as .obj files and i have assembled them in the code.
Now what is happening, when i try to rotate the door which is separate object using number animation, it is rotating with respect to car's origin not w.r.t to door's so, i want to rotate it based on it's own axis or origin. not w.r.t car's origin.
I have tried the following code but didn't get the excepted result.// Car front door // Mesh { id: carDoorMesh source: "qrc:/Meshes/CarFrontDoor_modified.obj" } PhongMaterial{ id: carDoorMaterial } Transform { id: carDoorTransform property real userAngle: 0.0 matrix: { var m= Qt.matrix4x4(); m.translate(Qt.vector3d(0.501096,1.5006,1.78036)) m.rotate(userAngle, Qt.vector3d(0,1,0)) m.translate(Qt.vector3d(-0.501096,-1.5006,-1.75036)) return m } NumberAnimation on rotationY { to: -45 duration: 1000 running: true } }
i got the respective values from blender.
Any guidance is appreciated
Thank you.@Naveen_D No offense, but this has nothing to do with Qt really but only with your lack of a basic understanding of how transformation matrices work. Seriously, get a book on linear algebra or you'll never get this to work.