QML 3D 無邊框,背景透明

3ds max2018導出obj文件在Qt5.7.1會報錯

Qt3D.Renderer.IO: Missing position index

ASSERT failure in QVector<T>::operator[]: "index out of range", file c:\Users\qt\work\install\include\QtCore/qvector.h, line 433

換成Qt5.11.2或者使用3ds max2014就可以了,還有一種可能是模型太大,導出的時候需要按比例縮小

 

main.cpp

#include <Qt3DQuickExtras/qt3dquickwindow.h>
#include <QGuiApplication>
#include <QQuickView>
#include <QQmlEngine>
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include <QQuickItem>

int main(int argc, char* argv[])
{
    QGuiApplication app(argc, argv);

    QQuickView view;

    view.setFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
    view.setColor(QColor(Qt::transparent));
    view.setSource(QUrl("qrc:/main.qml"));
    view.show();

    return app.exec();
}

 用於顯示3d模型


import QtQuick 2.2 as QQ2
import QtQuick 2.0
import QtQuick.Scene3D 2.0
import Qt3D.Core 2.0
import Qt3D.Render 2.0
import Qt3D.Input 2.0
import Qt3D.Extras 2.0



Entity {
    id: sceneRoot
    property alias upperArmPos: upperArmTransform
    property alias wristClawPos: wristClawTransform

    property real wristClawRota: 0.0    //腕部旋轉度數Y
    property real upperArmRota: 0.0     //上臂旋轉度數Y
    property real lowerArmRota: 0.0     //下臂旋轉度數Y
    property real turretRota: 0.0       //塔臺旋轉度數Y
    property real baseRotaY: 0.0        //基座旋轉度數Y
    property real baseRotaZ: 0.0        //基座旋轉度數Z

    Component.onCompleted:{
        var upperArmPos = upperArmTransform.translation
        var wristClawPos = wristClawTransform.translation
        //console.log(upperArmPos,wristClawPos)
    }

    components: [
        RenderSettings {
            activeFrameGraph: ForwardRenderer {
                camera: camera
                clearColor: "transparent"

            }
        },
        // Event Source will be set by the Qt3DQuickWindow
        InputSettings {
        }
    ]



    Camera {
        id: camera
        projectionType: CameraLens.PerspectiveProjection
        fieldOfView: 25
        aspectRatio: 16/9
        nearPlane : 0.01
        farPlane : 1000.0
        position: Qt.vector3d( 0.0, 10.0, -40.0 )
        upVector: Qt.vector3d( 0.0, 1.0, 0.0 )
        viewCenter: Qt.vector3d( 0.0, 0.0, 0.0 )

    }

    OrbitCameraController {
        camera: camera
    }

    FirstPersonCameraController { camera: camera }

    Entity {
        id: base

        Transform {
            id: baseTransform

            translation:Qt.vector3d(-4.01445,-5.87275,0.02425)
        }

        PhongMaterial {
            id: materialBase
            ambient: Qt.rgba( 0.1, 0.2, 0.3, 1 )            //環境光
            diffuse: Qt.rgba( 0.1, 0.1, 0.1, 1 )            //漫反射
            specular: Qt.rgba( 0.2, 0.2, 0.1, 1 )           //高光反射
            //                shininess: 0.6
            shininess: 10.0
        }

        Mesh {
            id: meshBase
            source: "qrc:/obj/obj/Base.obj"
        }

        components: [meshBase, materialBase,baseTransform]
    }
}

 main.qml調用


import QtQuick 2.0
import QtQuick.Scene3D 2.0
import QtQuick.Controls 1.4

Rectangle {

    width: 600
    height: 400
    color: "transparent"
    focus: true


    Rectangle {
        id: scene
        anchors.fill: parent
        anchors.margins: 0
        color: "transparent"
        Scene3D {
            id: scene3d
            anchors.fill: parent
            anchors.margins: 0
            aspects: ["input", "logic"]
            cameraAspectRatioMode: Scene3D.AutomaticAspectRatio

            AnimatedEntity {
            id:unicorn
            }


        }


    }
}

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章