在我的QML应用程序中,我正在显示从医学图像生成的自定义网格。现在我希望相机围绕这个网格的中心旋转。
根据answers in this question this,我必须将摄像机的viewCenter
设置为网格的平移。但是,我所拥有的网格已被翻译(质心不在[0,0,0]),因为它们位于CT / MR扫描仪的坐标系中。
如何获取导入网格的质心以便相应地设置viewCenter?
在我的QML文件中,我有:
import Qt3D.Core 2.0
import Qt3D.Render 2.0
import Qt3D.Input 2.0
import Qt3D.Extras 2.0
import QtQuick 2.0 as QQ2
Entity {
id: sceneRoot
Camera {
id: camera
projectionType: CameraLens.PerspectiveProjection
fieldOfView: 45
nearPlane : 0.1
farPlane : 1000.0
position: Qt.vector3d(0, 0, 20)
upVector: Qt.vector3d( 0.0, 1.0, 0.0 )
viewCenter: Qt.vector3d( 0.0, 0.0, 0.0 ) // here I should set the viewcenter to the centroid of "organModel"
}
OrbitCameraController { camera: camera }
components: [
RenderSettings {
activeFrameGraph: ForwardRenderer {
camera: camera
clearColor: "transparent"
}
},
InputSettings { }
]
PhongMaterial {
id: material
ambient: "darkRed"
}
Mesh {
id: organModel
source: "qrc:/organModel.obj"
}
Transform {
id: transformLiver
}
Entity {
id: torusEntity
components: [ liver, material, transformLiver ]
}
}