Study on Qt 3D (III): Display 3D model, qt3d

Source: Internet
Author: User

Study on Qt 3D (III): Display 3D model, qt3d
Study on Qt 3D (III): Display 3D Models

The previous article introduced how to use the least code to create a Qt 3D application. Like glut, which we initially came into contact with, there are a lot of preparations for 3D applications. However, Qt 3D solves some trivial window-related things and the rest, it is up to us to complete the important rendering part. It can be said that it brings convenience to some extent.

Jiang caiyang's original article, first published at: http://blog.csdn.net/gamesdev/article/details/43964499. Welcome to the discussion.

We will use Qt 3D to display a model. Qt 3D has a built-in obj model parser that allows you to easily import models in obj format. If you want to use Qt 3D to import files in the format of ms3d and 3ds, you may need to put the Assimp model Parsing Library and Qt 3D together for compilation so that they can be used smoothly. Here, we use the built-in obj model toyplane of Qt 3D to load and display. The Code is as follows:

import Qt3D 2.0import Qt3D.Render 2.0Entity{    id: root    Camera    {        id: camera        position: Qt.vector3d( 0.0, 0.0, 40.0 )        projectionType: CameraLens.PerspectiveProjection        fieldOfView: 45        aspectRatio: 16.0 / 9.0        nearPlane : 0.1        farPlane : 1000.0        upVector: Qt.vector3d( 0.0, 1.0, 0.0 )        viewCenter: Qt.vector3d( 0.0, 0.0, 0.0 )    }    components: FrameGraph    {        ForwardRenderer        {            clearColor: Qt.rgba( 0, 0, 0, 1 )            camera: camera        }    }    //! [3]    Entity    {        Mesh        {            id: mesh            objectName: "cube"            source: "qrc:/toyplane.obj"        }        components: [ mesh ]    }    Configuration    {        controlledCamera: camera    }    //! [3]}

Here! [3] is the newly added part. We need another Entity to represent the Entity we want to render. The object contains the Mesh. The Mesh is loaded by the path "qrc:/toyplane. obj. Set components to [mesh], indicating that the component owned by Entity is the mesh component named Mesh. The final Configuration indicates the related Configuration of the program. We need to perform interactive operations on camera, so we set controlleedCamera as our camera, so that we can change the parameters of camera with the mouse, so that you can observe the model from different angles.

The program is as follows:

We did not specify the light and material. The paid rendering effect of our toy airplane model is brought to us by default by Qt 3D. The program can interact with each other through the mouse: The left button indicates that the camera is rotated Based on the vector axis up, and the right-click is the center point of the scene origin to rotate the camera.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.