このページでは

Qt Quick 3D - レイヤーの例

QtQuick3D におけるレイヤーの使用例を示します。

赤、緑、青の3つのQtロゴレイヤーを重ね、レイヤートグルチェックボックスで切り替える

この例では、異なる色のロゴモデルが異なるレイヤーに配置されています。設定パネルから、ユーザーはチェックボックスを切り替えることで、各レイヤーの可視性をコントロールできます。

シーンレイヤーの準備

レイヤー

便宜上、Layer の列挙型を、識別しやすいように別名を付けます。

readonly property int redModels: ContentLayer.Layer1
readonly property int greenModels: ContentLayer.Layer2
readonly property int blueModels: ContentLayer.Layer3
カメラ

レイヤーに基づいてカメラビューをフィルタリングしたいので、カメラがレンダリングするレイヤーを設定する必要があります。カメラのlayers プロパティを1つ以上のレイヤーに設定します。そうすると、カメラは指定されたlayers にあるオブジェクトのみをレンダリングします。デフォルトでは、カメラはすべてのlayers のノードをレンダリングします。

アクティブなレイヤを選択できるように、cameraFilter プロパティを作成し、カメラのlayers プロパティにバインドします。

property int cameraFilter: ContentLayer.LayerAll

camera: PerspectiveCamera {
    layers: v3d.cameraFilter
    position: Qt.vector3d(0, 400, 500)
    eulerRotation.x: -30
    clipFar: 2000
}

設定パネルのチェックボックスを切り替えると、cameraFilter プロパティが更新され、それぞれのレイヤーを含めるか、または除外します。このようにして、カメラはcameraFilter で指定されたレイヤーにあるオブジェクトのみをレンダリングします。

CheckBox {
    id: checkBoxRedLayer
    text: qsTr("Red Layer")
    checked: true
    onCheckedChanged: {
        v3d.cameraFilter = checked ? v3d.cameraFilter | v3d.redModels : v3d.cameraFilter & ~v3d.redModels;
    }
}
モデル

次に、3つの異なる色のモデルをそれぞれのレイヤーに割り当てる必要があります。カメラと同様に、モデルのlayers プロパティを使用して、レイヤーに割り当てることができます。赤のロゴモデルはredLayer に、緑はgreenLayer に、青はblueLayer に割り当てます。

Node {
    position: Qt.vector3d(0, 200, 0)
    Model {
        source: "qtlogo.mesh"
        layers: v3d.redModels
        scale: Qt.vector3d(5000, 5000, 5000)
        materials:[ PrincipledMaterial {
            baseColor: "red"
            roughness: 0.5
        } ]

        NumberAnimation on eulerRotation.y {
            from: 0
            to: 360
            duration: 15000
            loops: Animation.Infinite
        }
    }

    Model {
        position: Qt.vector3d(0, -50, 0)
        source: "#Cylinder"
        materials:[ PrincipledMaterial {
            baseColor: "red"
            roughness: 0.5
        } ]
    }
}

Node {
    position: Qt.vector3d(0, 100, 0)
    Model {
        source: "qtlogo.mesh"
        layers: v3d.greenModels
        scale: Qt.vector3d(5000, 5000, 5000)
        materials:[ PrincipledMaterial {
            baseColor: "green"
            roughness: 0.5
        } ]

        NumberAnimation on eulerRotation.y {
            from: 0
            to: 360
            duration: 20000
            loops: Animation.Infinite
        }
    }
    Model {
        position: Qt.vector3d(0, -50, 0)
        source: "#Cylinder"
        materials:[ PrincipledMaterial {
            baseColor: "green"
            roughness: 0.5
        } ]
    }
}
Node {
    Model {
        source: "qtlogo.mesh"
        layers: v3d.blueModels
        scale: Qt.vector3d(5000, 5000, 5000)
        materials:[ PrincipledMaterial {
            baseColor: "blue"
            roughness: 0.5
        } ]

        NumberAnimation on eulerRotation.y {
            from: 0
            to: 360
            duration: 12500
            loops: Animation.Infinite
        }
    }
    Model {
        position: Qt.vector3d(0, -50, 0)
        source: "#Cylinder"
        materials:[ PrincipledMaterial {
            baseColor: "blue"
            roughness: 0.5
        } ]
    }
}

レイヤーが設定されると、カメラはcameraFilter で指定されたレイヤーにあるモデルのみをレンダリングします。ユーザーは、設定パネルのチェックボックスをオンまたはオフにすることで、各レイヤーの可視性を切り替えることができます。

プロジェクト例 @ code.qt.io

© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.