Laszlo Agocs

Get Started with Qt 3D Studio 2.0 beta 1

Published Friday May 18th, 2018
12 Comments on Get Started with Qt 3D Studio 2.0 beta 1
Posted in Dev Loop, Qt 3D, Qt 3D Studio, Qt Quick

Now that the beta 1 release of Qt 3D Studio 2.0 is out, let’s go through the steps involved in trying it out for real.

Pre-built runtime binaries

As outlined in last year’s post, the runtime component of Qt 3D Studio has undergone significant changes. This means that the Viewer application that is launched whenever pressing the green “Play” button in Qt 3D Studio and, more importantly, the C++ and QML APIs with the engine underneath, have all been rewritten in the familiar Qt-style C++ on top of Qt 3D. In practice the runtime is an ordinary Qt module, providing both C++ libraries with classes like Q3DSWidget, Q3DSPresentation, etc. and a QML plugin Studio3D and friends.

The releasing of the pre-built binaries for the runtime has improved a lot for version 2.0: there is now a dedicated entry in the Qt installer which will install the necessarily files alongside the normal Qt installation, so pulling in the runtime via QT += 3dstudioruntime2 or by import QtStudio3D 2.0 in QML will work out of the box in a fresh Qt installation. No more manual building from sources is needed (except when targeting certain platforms).

Let’s Install

At the moment Qt 3D Studio binaries are provided for Windows and macOS. Linux may be added in future releases. It is worth noting that this does not mean the runtime is not suitable for running on Linux (or Android or QNX or INTEGRITY, for that matter) – it, like the most of Qt, will build (cross-compile even) and run just fine, assuming a well-working OpenGL implementation is available for your platform. (however, glitches can naturally be expected with less stable and complete graphics stacks) So while we expect the design work in the Qt 3D Studio application done on Windows or macOS for now, Qt applications using the created 3D presentations can be developed on and deployed to all the typical Qt target platforms.

When launching the online installer, take note of the following entries. Note that the layout and the location of these items may change in the installer in beta 2 and beyond. What is shown here is how things look as of 2.0 beta 1.

The runtime depends on Qt 5.11, meaning it must be installed together with 5.11.0 (or a future release, here we will use the release candidate).

In the example run shown on the screenshots we opted for Visual Studio 2015, but choosing something else is an option too – the installer takes care of downloading and installing the right set of pre-built binaries for the Qt 3D Studio runtime.

q3dsb1inst1

q3dsb1inst2

Once installation is finished, you will have the Qt 5.11 RC, a recent version of Qt Creator, Qt 3D Studio 2.0 beta 1, and the necessary runtime libraries all in place.

Let’s Design

Launching Qt 3D Studio and opening the example project from <installation root>\Tools\Qt3DStudio-2.0.0\examples\studio3d\SampleProject should result in something like the following.

q3dsb1screenshot

For details on what can be done in the designer application, check the documentation. Speaking of which, the documentation for Qt 3D Studio has been split into two parts in version 2.0: the runtime has its own documentation set with the API references, introduction, system requirements, and other topics. (the links are currently to doc-snapshots, the contents will move to doc.qt.io later on)

Let’s Code

Designing the presentation is only half of the story. Let’s get it into a Qt application.

Here we will code an example from scratch. Regardless, you may want to look at the runtime’s examples first. These ship in <installation root>examples\Qt-5.11.0\3dstudioruntime2.

q3dsb1screenshot2
The qmldatainput example in action

For now, let’s start with an empty project. Launch Qt Creator and create a new, empty Qt Quick project targeting Qt 5.11.

q3dsb1screenshot3

The application template gives us a main QML file like this:

q3dsb1screenshot4

When the runtime is installed correctly alongside Qt, we can add the following to make our Qt Quick application load up a Qt 3D Studio presentation and compose it with the rest of the Qt Quick scene.

    ...
    import QtStudio3D 2.0
    
    Window {
        ...
        Studio3D {
            anchors.fill: parent
            anchors.margins: 10
            Presentation {
                source: "file:///c:/QtTest/Tools/Qt3DStudio-2.0.0/examples/studio3d/SampleProject/SampleProject.uip"
            }
        }
    }

(replace c:\QtTest as appropriate)

In many real world applications it is quite likely that you will want to place the presentation’s files and assets into the Qt resource system instead, but the raw file references will do as a first step.

Launching this gives us quite impressive results already:

q3dsb1screenshot5

What we see there is the live Qt 3D Studio presentation rendered by the new Qt3D-based engine into an OpenGL texture which is then used by the Qt Quick scenegraph when drawing a textured quad for the Studio3D element. The keyframe-based animations should all run as defined in the Qt 3D Studio application during the design phase.

Now, a common misconception is that Qt 3D Studio is merely a designer tool and the scenes created by it are static with no runtime modifications possible when loaded up in Qt applications. This is pretty incorrect since applications have full control over

Future versions of Qt 3D Studio are expected to extend the capabilities further, for example with adding APIs to spawn and destroy objects in the scene dynamically.

Let’s change that somewhat annoying text in the middle of the scene, using a button from Qt Quick Controls 2. Whenever the button is clicked, the attribute corresponding to the text rendered by the Text node in the Qt 3D Studio scene will be changed.

Option 1: Direct Attribute Access

q3dsb1screenshot6

When digging down the scene structure at the left of the timline pane, take note of the fact that the Text node has a convenient, unique name already (DateAndTime). This is good since it means we can refer to it without further ado in the application code:

...
import QtQuick.Controls 2.2

Window {
    ...

    Studio3D {
        anchors.fill: parent
        anchors.margins: 10
        Presentation {
            id: pres
            source: "file:///c:/QtTest/Tools/Qt3DStudio-2.0.0/examples/studio3d/SampleProject/SampleProject.uip"
        }

        Button {
            text: "Change text"
            anchors.bottom: parent.bottom
            anchors.horizontalCenter: parent.horizontalCenter
            onClicked: pres.setAttribute("DateAndTime", "textstring", "Hello World")
        }
    }
}

For details on this approach, check out the documentation for Presentation and the attribute name table.

q3dsb1screenshot7
Clicking the button results in changing the ‘textstring’ property of the Text node in the Qt 3D Studio presentation. The change is then picked up by the Qt 3D Studio engine, leading to changing the rendered text.

Option 2: Data Input

While changing properties via setAttribute & co. is simple and effective, Qt 3D Studio also supports another approach: the so-called data inputs. With data inputs, the designers of the 3D scene decide which attributes are controllable by the applications and assign custom names to these. This way a well-known, fixed interface is provided from the designers to the application developers. The example presentation we are using here exposes the following data inputs. (and note the orange-ish highlight for Text String in the Inspector Control in the bottom right corner)

q3dsb1screenshot8

The name dateAndTime is associated with the textstring property of the DateAndTime Text node. Let’s control the value via this approach:

...
import QtQuick.Controls 2.2

Window {
    ...

    Studio3D {
        anchors.fill: parent
        anchors.margins: 10
        Presentation {
            id: pres
            source: "file:///c:/QtTest/Tools/Qt3DStudio-2.0.0/examples/studio3d/SampleProject/SampleProject.uip"

            property string text: ""
            DataInput {
                name: "dateAndTime"
                value: pres.text
            }
        }

        Button {
            text: "Change text"
            anchors.bottom: parent.bottom
            anchors.horizontalCenter: parent.horizontalCenter
            onClicked: pres.text = "Hello World"
        }
    }

Here the Text node starts up with a textstring value of “” (but note there is no actual reference to “textstring” anywhere in the application code), while clicking the button results in changing it to “Hello World”. What’s more, we can now use the usual QML property binding methods to control the value.

That is all for now. Expect more Qt 3D Studio related posts in the near future.

Do you like this? Share it
Share on LinkedInGoogle+Share on FacebookTweet about this on Twitter

Posted in Dev Loop, Qt 3D, Qt 3D Studio, Qt Quick

12 comments

Eli says:

Thanks for this post!
Some questions:
-Is there a way to move in the scene like in any other 3d editor via a flying camera (with WASD)? The alt + mouse combination is rather annoying 🙂
– Why using the proprietary fbx when alternatives like gltf 2.0 are supported by more and more applications?

Laszlo Agocs Laszlo Agocs says:

glTF support may be added in the future. For now FBX is the primary import format since it tends to work well with the content creation tools that are typically used in combination with Qt 3D Studio.

Same goes for other ways of navigating the scene, WASD is not there atm but could well be added at some point in the future.

Jan says:

@Eli:
Every 3D Software should have fbx support and it is wide spreaded in use.
alt + mouse is not annoying. At least not for Maya users. 😉
In which software can you use WASD? These keys are often shortcuts. We are not in a ego shooter here. 😀

Eli says:

@Jan:

Well as a Blender user once you use flying controls you never want to go back (shift + f in blender). Moving in scenes is just so much easier like in Unity or Unreal.

The problem with FBX is that I have to manually install their SDK. Instead Qt3d Studo could use https://github.com/assimp/assimp

Aamer says:

Hello,

If Qt 5.11.0 was installed offline, how to setup Qt3DStudio examples with already installed Qt ?
Tried some instructions from qt3dstudio2/Tools/Qt3DStudio-2.0.0/doc/qt3dstudio/qtstudio3d-qml-examples.html, but not able to successfully run examples.

Are there any additional steps ?

Aamer says:

I guess the issue was that I had Qt MinGw 5.3 installed offline and the online default Qt 3D Studio binaries are built with MSVC 2015.
Will try again with fresh installation with MinGw 5.3 selected.

artemsyd artemsyd says:

As it is said in the documentation:

> Binaries provided by Qt 3D Studio installer are compiled with […] MSVC2015_64bit […] for other combinations you need to compile Qt 3D Studio yourself from sources

Laszlo Agocs Laszlo Agocs says:

That has been enhanced for 2.0, though. Now there are pre-built binaries for the runtime as a standalone item in the (online) installer. The instructions there are from 1.1 and do not apply to 2.0.

Now, it could be that some platforms like MinGW do not have pre-built binaries of the runtime yet. For Windows it’s MSVC2015 and 2017 that are covered right now. The key is to install the runtime together with Qt in the online installer, as shown in the screenshots above.

If that is not an option, with 2.0 building the runtime is pretty easy too. Just clone git://code.qt.io/qt3dstudio/qt3d-runtime.git, take the 2.0 branch, and do qmake and make.

Aamer says:

Thanks for the update and link to code.
Will try installing Qt with online installer along with Qt 3D Studio.

If it fails too, I guess manually building the runtime should work.

artemsyd artemsyd says:

> The instructions there are from 1.1 and do not apply to 2.0.

Docs that are installed together with 2.0.0-beta1 say the same 🙂 that’s why I linked the docs page for 1.1.

But it’s good of course that it is improved in 2.0 as I remember how I faced the same issue myself, having only MinGW binaries installed with version 1.1.

Laszlo Agocs Laszlo Agocs says:

Yes, work is still on-going. Beta 2 will hopefully bring some clean ups in the documentation.

Aamer says:

It would be good if we get an option to select the version of the Qt 3D studio runtime (for MSVC/Mingw/etc).

Normally with online installer, I was getting speed of 30-50KB/s. While downloading offline installer was 1-2 Mbps.
So downloading Qt 5.11 MinGw version with online installer took hours, and had to cancel. Later compiled Qt 3D runtime which was much easier. Now able to run 3d runtime examples. 🙂

Commenting closed.

Get started today with Qt Download now