3

プロジェクトがあり、1 つの 3D オブジェクト (.obj ファイル) があり、このオブジェクトをクリックしたいと考えています。最初のテストでは、オブジェクトのテクスチャまたは色を変更できれば幸いです。私の知る限り、それはピッキングと呼ばれています。これをqt3dで管理する方法を知っていますか?私のプロジェクト全体はqmlで書かれているので、qmlで(c++なしで)ピッキングできれば素晴らしいと思いますが、必要に応じてその方法で試す準備もできています。

私のプロジェクトは次のように構成されています:

rootEntity と 3D-Entity としてエンティティがあり、メッシュが読み込まれます。この構造は、View3d.qml という独自の qml ファイルにあります。次に、main.qml に Scene3D を設定し、View3d のインスタンスをセットアップします。

必要に応じて、Windows 8.1 64Bit システムで qt3d を含む Qt 5.5 ベータ版を使用しています。

4

2 に答える 2

1

最も簡単な方法は、 blenderを使用して .obj ファイルにテクスチャを追加し、それをプロジェクトに追加することです。blender を使用してこれを行うには、多くのチュートリアルがあります。このHow to Add Textureおよびこのビデオを参照してください。

もう 1 つの方法は、TextureTexture2Dを使用することです。

例としてこのコードを見てください:

私は2つのqmlクラスを持っています

main.qmlで:

import QtQuick 2.12
import QtQuick.Window 2.12
import QtQuick.Scene3D 2.12

Window {
visible: true
width: 640
height: 480
title: qsTr("Hello World")

Scene3D
{
    id : scene3d
    anchors.fill: parent
    focus: true
    aspects: ["render", "logic", "input"]
    hoverEnabled: true
    cameraAspectRatioMode: Scene3D.AutomaticAspectRatio


    antialiasing: true

    RootEntity
    {
        id:root
    }

}
}

およびRootEntity.qmlで:

import QtQuick 2.12
import Qt3D.Core 2.12
import Qt3D.Render 2.12
import Qt3D.Input 2.12
import Qt3D.Extras 2.12

Entity {
id: sceneRoot

readonly property var textureModel: [texture1, texture2, texture3, texture4]

readonly property Texture texture1: TextureLoader {
    source: "qrc:/images/image.png"
}

readonly property Texture texture2: TextureLoader {
    source: "qrc:/images/wood.jpg"
}

readonly property Texture texture3: Texture2D {
    format: Texture.RGBA8_UNorm
    textureImages: TextureImage {
        source:"qrc:/images/image.png"
    }
}

readonly property Texture texture4: Texture2D {
    format: Texture.RGBA8_UNorm
    textureImages: TextureImage {
        source:"qrc:/images/wood.jpg"
    }
}

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

OrbitCameraController {
    camera: camera
}

components: [
    RenderSettings {
        activeFrameGraph: ForwardRenderer {
            clearColor: "#333339"
            camera: camera
        }
    },
    // Event Source will be set by the Qt3DQuickWindow
    InputSettings { }
]

CuboidMesh { id: mesh }

NodeInstantiator {
    id: instantiator
    model: sceneRoot.textureModel

    Entity {
        readonly property Transform transform: Transform {
            readonly property real angle: model.index / instantiator.count * Math.PI * 2
            translation: Qt.vector3d(Math.cos(angle) * 10, 0, Math.sin(angle) * 10)
            scale: 10
        }

        readonly property DiffuseMapMaterial material: DiffuseMapMaterial {
            diffuse: model.modelData
            ambient: "white"
        }
        components: [ mesh, material, transform ]
    }
}
}

出力は次のとおりです。

出力

于 2021-06-20T15:14:41.680 に答える
0

demos/qt3d/teaservice を参照してください。これは、ピッキング (つまり、マウスを使用したオブジェクトの選択) を行う方法を示しています。QML teaservice ではなく、qt3d デモが必要であることに注意してください。

于 2016-01-07T14:44:30.080 に答える