在建模软件中,往往会有一个作为参考的带网格的平面,现在我们利用PySide2+qml来实现这个效果。
创建窗口
main.qml中利用ApplicationWindow 新建了一个窗口用于显示,Scene3D组件用于创建一个三维场景
import QtQuick 2.7
import QtQuick.Controls 2.3
import QtQuick.Scene3D 2.0
ApplicationWindow {
id: rootWindow
title: "Grid3D Test"
width: 800
height: 600
visible: true
Scene3D {
id: scene3d
anchors.fill: parent
anchors.margins: 10
focus: true
aspects: ['input', 'logic']
cameraAspectRatioMode: Scene3D.AutomaticAspectRatio
hoverEnabled: true
Viewer3D {
}
}
}
创建场景根实体
Viewer3D.qml
import QtQuick 2.7
import Qt3D.Core 2.1
import Qt3D.Render 2.1
import Qt3D.Extras 2.1
import Qt3D.Input 2.1
Entity {
id: rootEntity
Camera {
id: mainCamera
projectionType: CameraLens.PerspectiveProjection
fieldOfView: 45
nearPlane: 0.01
farPlane: