3D модель не отображается - PullRequest
       8

3D модель не отображается

0 голосов
/ 01 февраля 2019

Я пишу свой проект, который будет отображать 3D-модели.Я написал следующий код:

#include <QGuiApplication>
#include <QUrl>
#include <QDebug>
#include <Qt3DExtras/Qt3DExtras>
#include <Qt3DExtras/Qt3DWindow>
#include <Qt3DCore/QEntity>
#include <Qt3DRender/Qt3DRender>
#include <Qt3DCore/Qt3DCore>
#include <QVector3D>
#include <memory>

int main(int argc, char *argv[])
{
    QGuiApplication a(argc, argv);
    QUrl data = QUrl::fromLocalFile("bun_zipper.ply");
    qDebug() << data.isValid() << data.toLocalFile() << QFileInfo(data.toLocalFile()).exists() << data.fileName();
    Qt3DExtras::Qt3DWindow view;
    std::shared_ptr<Qt3DCore::QEntity> rootEntity(new Qt3DCore::QEntity);
    std::shared_ptr<Qt3DCore::QEntity> flyingwedge(new Qt3DCore::QEntity(rootEntity.get()));
    std::shared_ptr<Qt3DRender::QMaterial> material(new Qt3DExtras::QMetalRoughMaterial(rootEntity.get()));
    std::shared_ptr<Qt3DRender::QMesh> flyingwedgeMesh(new Qt3DRender::QMesh);
    flyingwedgeMesh->setMeshName("FlyingWedge");
    flyingwedgeMesh->setSource(data);
    std::shared_ptr<Qt3DCore::QTransform> flyingWedgeTransform(new Qt3DCore::QTransform);
    flyingWedgeTransform->setScale3D(QVector3D(50.0, 50.0, 50.0));
    std::shared_ptr<Qt3DRender::QFrontFace> frontFace(new Qt3DRender::QFrontFace(rootEntity.get()));
    frontFace->setDirection(Qt3DRender::QFrontFace::CounterClockWise);
    flyingwedge->addComponent(flyingwedgeMesh.get());
    flyingwedge->addComponent(material.get());
    flyingwedge->addComponent(flyingWedgeTransform.get());
    Qt3DRender::QCamera* camera = view.camera();
    camera->lens()->setPerspectiveProjection(45.0f, 16.0f / 9.0f, 0.1f, 1000.0f);
    camera->setPosition(QVector3D(0, 0, 40.0f));
    camera->setViewCenter(QVector3D(0, 0, 0));
    view.setRootEntity(rootEntity.get());
    view.show();

    return a.exec();
}

В профиле я добавил 3декста и 3dcore

QT       += core gui 3dextras 3dcore

Работает нормально и отображается 3d модель.Но я хотел включить GTest и другие библиотеки, и я переписал свой проект, используя Conan Package Manager и CMake.

conanfile.txt

[requires]
Qt/5.11.1@bincrafters/stable

[options]
Qt:qt3d=True

[generators]
cmake 

CMakeLists.txt

cmake_minimum_required(VERSION 3.10)

project(test_project)

set(CMAKE_CXX_FLAGS -pthread)
set(CMAKE_CXX_STANDARD 14)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()

set(CMAKE_INCLUDE_CURRENT_DIR ON)
# Instruct CMake to run moc automatically when needed
set(CMAKE_AUTOMOC ON)
# Create code from a list of Qt designer ui files
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)

find_package(Qt5Core REQUIRED)
find_package(Qt5Widgets REQUIRED)
find_package(Qt53DCore REQUIRED)
find_package(Qt53DExtras REQUIRED)

add_executable(${PROJECT_NAME} main.cpp)

target_link_libraries(${PROJECT_NAME} Qt5::Widgets)
target_link_libraries(${PROJECT_NAME} Qt5::Core)
target_link_libraries(${PROJECT_NAME} Qt5::3DCore)
target_link_libraries(${PROJECT_NAME} Qt5::3DExtras)

Я создал свой проект без ошибок, но 3D-модель не отображается.

config.summary

Build type: linux-g++ (x86_64, CPU features: mmx sse sse2)
Configuration: use_gold_linker sse2 aesni sse3 ssse3 sse4_1 sse4_2 avx avx2 avx512f avx512bw avx512cd avx512dq avx512er avx512ifma avx512pf avx512vbmi avx512vl compile_examples enable_new_dtags f16c largefile precompile_header rdrnd shani silent x86SimdAlways shared rpath release c++11 c++14 c++1z concurrent dbus reduce_exports reduce_relocations stl
Build options:
  Mode ................................... release
  Optimize release build for size ........ no
  Building shared libraries .............. yes
  Using C++ standard ..................... C++1z
  Using ccache ........................... no
  Using gold linker ...................... yes
  Using new DTAGS ........................ yes
  Using precompiled headers .............. yes
  Using LTCG ............................. no
  Target compiler supports:
    SSE .................................. SSE2 SSE3 SSSE3 SSE4.1 SSE4.2
    AVX .................................. AVX AVX2
    AVX512 ............................... F ER CD PF DQ BW VL IFMA VBMI
    Other x86 ............................ AES F16C RDRAND SHA
    Intrinsics without -mXXX option ...... yes
  Build parts ............................ libs tools
Qt modules and options:
  Qt Concurrent .......................... yes
  Qt D-Bus ............................... yes
  Qt D-Bus directly linked to libdbus .... yes
  Qt Gui ................................. yes
  Qt Network ............................. yes
  Qt Sql ................................. yes
  Qt Testlib ............................. yes
  Qt Widgets ............................. yes
  Qt Xml ................................. yes
Support enabled for:
  Using pkg-config ....................... yes
  udev ................................... yes
  Using system zlib ...................... no
Qt Core:
  DoubleConversion ....................... yes
    Using system DoubleConversion ........ no
  GLib ................................... yes
  iconv .................................. no
  ICU .................................... yes
  Tracing backend ........................ <none>
  Logging backends:
    journald ............................. no
    syslog ............................... no
    slog2 ................................ no
  Using system PCRE2 ..................... no
Qt Network:
  getifaddrs() ........................... yes
  IPv6 ifname ............................ yes
  libproxy ............................... no
  Linux AF_NETLINK ....................... yes
  OpenSSL ................................ no
    Qt directly linked to OpenSSL ........ no
  OpenSSL 1.1 ............................ no
  SCTP ................................... no
  Use system proxies ..................... yes
Qt Gui:
  Accessibility .......................... yes
  FreeType ............................... yes
    Using system FreeType ................ yes
  HarfBuzz ............................... yes
    Using system HarfBuzz ................ yes
  Fontconfig ............................. yes
  Image formats:
    GIF .................................. yes
    ICO .................................. yes
    JPEG ................................. yes
      Using system libjpeg ............... yes
    PNG .................................. yes
      Using system libpng ................ no
  EGL .................................... yes
  OpenVG ................................. no
  OpenGL:
    Desktop OpenGL ....................... yes
    OpenGL ES 2.0 ........................ no
    OpenGL ES 3.0 ........................ no
    OpenGL ES 3.1 ........................ no
    OpenGL ES 3.2 ........................ no
  Vulkan ................................. no
  Session Management ..................... yes
Features used by QPA backends:
  evdev .................................. yes
  libinput ............................... no
  INTEGRITY HID .......................... no
  mtdev .................................. no
  tslib .................................. no
  xkbcommon-evdev ........................ no
QPA backends:
  DirectFB ............................... no
  EGLFS .................................. yes
  EGLFS details:
    EGLFS OpenWFD ........................ no
    EGLFS i.Mx6 .......................... no
    EGLFS i.Mx6 Wayland .................. no
    EGLFS RCAR ........................... no
    EGLFS EGLDevice ...................... yes
    EGLFS GBM ............................ no
    EGLFS VSP2 ........................... no
    EGLFS Mali ........................... no
    EGLFS Raspberry Pi ................... no
    EGL on X11 ........................... yes
  LinuxFB ................................ yes
  VNC .................................... yes
  Mir client ............................. no
  X11:
    Using system-provided XCB libraries .. no
    EGL on X11 ........................... yes
    Xinput2 .............................. yes
    XCB XKB .............................. yes
    XLib ................................. yes
    XCB render ........................... yes
    XCB GLX .............................. yes
    XCB Xlib ............................. yes
    Using system-provided xkbcommon ...... no
    Native painting (experimental) ....... yes
Qt Widgets:
  GTK+ ................................... no
  Styles ................................. Fusion Windows
Qt PrintSupport:
  CUPS ................................... yes
Qt Sql:
  DB2 (IBM) .............................. no
  InterBase .............................. no
  MySql .................................. yes
  OCI (Oracle) ........................... no
  ODBC ................................... no
  PostgreSQL ............................. yes
  SQLite2 ................................ yes
  SQLite ................................. yes
    Using system provided SQLite ......... no
  TDS (Sybase) ........................... yes
Qt Testlib:
  Tester for item models ................. yes
Qt 3D:
  Assimp ................................. yes
  System Assimp .......................... no
  Output Qt3D Job traces ................. no
  Output Qt3D GL traces .................. no
  Use SSE2 instructions .................. yes
  Use AVX2 instructions .................. no
  Aspects:
    Render aspect ........................ yes
    Input aspect ......................... yes
    Logic aspect ......................... yes
    Animation aspect ..................... yes
    Extras aspect ........................ yes
Qt 3D Renderers:
  OpenGL Renderer ........................ yes
Qt 3D GeometryLoaders:
  Autodesk FBX ........................... no

Note: Also available for Linux: linux-clang linux-icc

Note: Dropped compiler flags '-pthread' when detecting library 'glib'.

Note: Disabling X11 Accessibility Bridge: D-Bus or AT-SPI is missing.

Как решить эту проблему?

У меня была почти такая же проблема , когда я использовал QtMultimedia и звук не воспроизводился.Я решил эту проблему с установкой зависимостей для QtMultimedia.

...