首页 技术 正文
技术 2022年11月13日
0 收藏 691 点赞 3,224 浏览 2519 个字

原文链接:http://amin-ahmadi.com/2018/01/28/viewing-3d-models-using-qt/

本文使用QT Quick中的Scene3D QML类型来查看3D模型文件,QT 3D使用assimp库来加载,支持如下3D文件格式:

3D, 3DS, 3MF, AC, AC3D, ACC, AMJ, ASE, ASK, B3D, BLEND (Blender), BVH, COB, CMS, DAE/Collada, DXF, ENFF, FBX, glTF 1.0 + GLB, glTF 2.0, HMB, IFC-STEP, IRR / IRRMESH, LWO, LWS, LXO, MD2, MD3, MD5, MDC, MDL, MESH / MESH.XML, MOT, MS3D, NDO, NFF, OBJ, OFF, OGEX, PLY, PMX, PRJ, Q3O, Q3S, RAW, SCN, SIB, SMD, STL, STP, TER, UC, VTA, X, X3D, XGL, ZGL等

我使用QT5.12+Qt Creator4.8.0测试,效果图如下:

QT QML 3D模型查看器

QML文件将包含ApplicationWindow,其中ToolBar(包含ToolButton)使用FileDialog打开3D模型文件,Scene3D将包含加载的模型:

 main.qml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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
84
85
86
87
88
89
90
91
92
93
94
95
 

ApplicationWindow
{
    visible: true
    width: 
    height: 
    title: qsTr(“3D Viewer”)
    
    header: ToolBar
    {
        ToolButton
        {
            text: “Open 3D Model”
            onPressed:
            {
                fileDialog.open()
            }
        }
    }
    
    FileDialog
    {
        id: fileDialog
        onAccepted:
        {
            sceneLoader.source = fileDialog.fileUrl
        }
    }
    
    Scene3D
    {
        anchors.fill: parent
        
        aspects: [“input”, “logic”]
        cameraAspectRatioMode: Scene3D.AutomaticAspectRatio
        
        Entity
        {
            id: sceneRoot
            
            Camera
            {
                id: camera
                projectionType: CameraLens.PerspectiveProjection
                fieldOfView: 
                aspectRatio: 
                nearPlane : 
                farPlane : 
                position: Qt.vector3d(  )
                upVector: Qt.vector3d(  )
                viewCenter: Qt.vector3d(  )
            }
            
            OrbitCameraController
            {
                camera: camera
            }
            
            components: [
                RenderSettings
                {
                    activeFrameGraph: ForwardRenderer
                    {
                        clearColor: Qt.rgba()
                        camera: camera
                    }
                },
                InputSettings
                {
                }
            ]
            
            Entity
            {
                id: monkeyEntity
                components: [
                    SceneLoader
                    {
                        id: sceneLoader
                    }
                ]
            }
        }
    }
}

例子比较简单,主要使用了SceneLoader来加载3D模型文件,只能实现3D模型文件简单的加载,以及鼠标滚轮缩放等,更详细的操控可在InputSettings中完善!

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,489
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,904
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,737
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,490
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,128
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,291