README.md 2.93 KB
Newer Older
Christian Strømme's avatar
Christian Strømme committed
1
2
3
4
5
# Qt Quick 3D

This project contains everything necessary build Qt Quick 3D (against Qt 5.12 or greater)
Qt Quick 3D is a high level 3D API for Qt Quick. Qt Quick 3D enables anyone to introduce 3D content into their Qt Quick applications.  Rather than requiring the end user to know advanced details of the graphics rendering pipeline (building framegraphs and materials), it is now possible to simply build up a 3D scene using high level primitives.

6
7
8
9
10
11
12
## Clone 3rdparty modules

In the qtquick3d source folder run the following to get assimp source code
```
git submodule update --init --recursive
```

Christian Strømme's avatar
Christian Strømme committed
13
14
15
16
17
18
19
20
21
22
## Building
To build like any other Qt module:
```
qmake qtquick3d.pro
make
make install
```
You may also need the qtquicktimeline module if you want to convert existing projects or assets that use keyframe animations.  That is found [here](https://code.qt.io/cgit/qt/qtquicktimeline.git/)

```
23
import QtQuick 2.15
Christian Strømme's avatar
Christian Strømme committed
24
import QtQuick.Window 2.12
25
import QtQuick3D 1.15
Christian Strømme's avatar
Christian Strømme committed
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

Window {
    id: window
    visible: true
    width: 1280
    height: 720

    // Viewport for 3D content
    View3D {
        id: view
        anchors.fill: parent

        // Scene to view
        Node {
            id: scene

            // To render anything to a 3D viewport, you need 3 things
            // Light, Camera, Model
            Light {
                id: directionalLight
            }

            Camera {
                id: camera
                // It's important that your camera is not inside your model
                // So move it back a big along the z axis
                // The Camera is implicitly facing up the z axis, so we should be looking towards
                // (0, 0, 0)
                z: -600
            }

            Model {
                id: cubeModel
                // #Cube is one of the "built-in" primitive meshes
                // Other Options are #Cone, #Sphere, #Cylinder, #Rectangle
                source: "#Cube"

                // When using a Model, it is not enough to have a mesh source (ie "#Cube")
                // You also need to define what material to shade the mesh with. A Model can be
                // built up of multiple sub-meshes, so each mesh needs its own material
                // So materials are defined in an array, and order reflects which mesh to shade
                // All of the default primitive meshes contain one sub-mesh, so you only
                // need 1 material. 
                materials: [
                    DefaultMaterial {
                        // We are using the DefaultMaterial which dynamically generates a shader
                        // based on what properties are set.  This means you don't need to write
                        // any shader code yourself.  In this case we just want the cube to have
                        // a red color.
                        id: cubeMaterial
                        diffuseColor: "red"
                    }
                ]
            }
        }
    }
}
```