ИВ
6 июня 2021 г. 19:06

Не работает FirstPersonCameraController

3D

Добрый день. Осваиваю 3D, как говориться - первый блин комом.
Сделал окно в QML

  1. import QtQuick 2.15
  2. import QtQuick.Window 2.14
  3. import QtQuick3D 1.15
  4. import QtQuick.Scene3D 2.0
  5.  
  6. Window {
  7. width: 640
  8. height: 480
  9. visible: true
  10. title: qsTr("Hello World")
  11.  
  12. Scene3D {
  13. anchors.fill: parent
  14. Mega3DScene {}
  15. }
  16. }
  17.  

И файл Mega3DScene.qml

  1. import QtQuick 2.15
  2. import Qt3D.Core 2.0
  3. import Qt3D.Extras 2.15
  4. import Qt3D.Input 2.0
  5. import Qt3D.Render 2.0
  6. import Qt3D.Logic 2.0
  7. import QtQuick.Window 2.14
  8.  
  9.  
  10. Entity {
  11. id: rootEtity
  12.  
  13. Camera {
  14. id: mainCamera
  15. projectionType: CameraLens.PerspectiveProjection
  16. fieldOfView: 60.0
  17. aspectRatio: 16.0 / 9.0
  18. nearPlane: 0.1
  19. farPlane: 1000.0
  20. position: Qt.vector3d(0.0,0.0,50.0)
  21. upVector: Qt.vector3d(0.0,1.0,0.0)
  22. viewCenter: Qt.vector3d(0.0,0.0,0.0)
  23. }
  24.  
  25. FirstPersonCameraController{
  26. camera: mainCamera
  27. }
  28.  
  29. SkyboxEntity {
  30. baseName: "qrc:/Items/Item/skybox"
  31. extension: ".tga"
  32. }
  33.  
  34. components: [
  35. RenderSettings {
  36. activeFrameGraph: ForwardRenderer{
  37. clearColor: Qt.rgba(1,1,1,1)
  38. camera: mainCamera
  39. }
  40. },
  41. InputSettings{}
  42. ]
  43.  
  44. Entity{
  45. TorusMesh {
  46. id: torusMesh
  47. radius: 15.0
  48. minorRadius: 6.0
  49. slices: 16
  50. rings: 32
  51. }
  52.  
  53. PhongMaterial{
  54. id: torusMaterial
  55. diffuse: Qt.rgba(0,0,1,0)
  56. ambient: Qt.rgba(0.15,0,0,1)
  57. }
  58.  
  59. Transform {
  60. id: torusTransform
  61. translation: Qt.vector3d(0.0,0.0,0.0)
  62.  
  63. SequentialAnimation on rotationY {
  64. loops: Animation.Infinite
  65. NumberAnimation {
  66. duration: 3000
  67. to: -360
  68. from: 0
  69. easing.type:Easing.InQuad
  70. }
  71. }
  72. }
  73. id: torusEntity
  74. components: [torusMesh,torusMaterial,torusTransform]
  75. }
  76.  
  77. Entity{
  78. PointLight{
  79. id: pointLight01
  80. color: Qt.rgba(1,0.5,0.5,0)
  81. }
  82.  
  83. Transform{
  84. id: lightTransform01
  85. translation: Qt.vector3d(0.0,0.0,30.0)
  86. }
  87. id: pintLightEntity01
  88. components: [pointLight01,lightTransform01]
  89. }
  90.  
  91. Entity{
  92. PointLight{
  93. id: pointLight02
  94. color: Qt.rgba(1,0.5,0.5,0)
  95. }
  96.  
  97. Transform{
  98. id: lightTransform02
  99. translation: Qt.vector3d(0.0,0.0,-30.0)
  100. }
  101.  
  102. id: pintLightEntity
  103. components: [pointLight02,lightTransform02]
  104. }
  105.  
  106. Entity{
  107. SceneLoader{
  108. id: sceneLoader01
  109. source: "qrc:/Items/Item/teaPort.obj"
  110. }
  111. Transform{
  112. id: lightTransform03
  113. translation: Qt.vector3d(0.0,-5.0,-30.0)
  114. scale: 0.3
  115. }
  116. components: [sceneLoader01,lightTransform03]
  117. }
  118.  
  119. Entity{
  120. SceneLoader{
  121. id: sceneLoader02
  122. source: "qrc:/Items/Item/text.obj"
  123. }
  124. Transform{
  125. id: lightTransform04
  126. translation: Qt.vector3d(0.0,-5.0,30.0)
  127. scale: 0.3
  128. }
  129. components: [sceneLoader02,lightTransform04]
  130. }
  131. }
  132.  

Отрисовывает, хотя и не корректно (у тора пропадает материал, почему тоже не понятно), но при этом не работает FirstPersonCameraController - не реагирует на мышь и клавиатуру.
Не понятно почему, вроде все согласно руководству.

1

Вам это нравится? Поделитесь в социальных сетях!

1
ИВ
  • 6 июня 2021 г. 19:07

Если что вот весь проект https://cloud.mail.ru/public/RyWF/wQjtfNhDe

    Комментарии

    Только авторизованные пользователи могут публиковать комментарии.
    Пожалуйста, авторизуйтесь или зарегистрируйтесь