Qt Quick 3D - XR 공간 앵커 예시
Qt Quick 3D XR에서 공간 앵커를 사용하는 방법을 보여줍니다.
이 예시에서는 XrSpatialAnchorListModel 을 사용하여 환경의 실제 물리적 객체를 표시하고 상호 작용하는 방법을 보여줍니다. 패스스루 모드와 완전 몰입형 모드를 모두 지원합니다. 기본 구조는 xr_simple 예제를 따릅니다.
예제에서 가장 관련성이 높은 부분은 XrSpatialAnchorListModel 의 Repeater3D 입니다. 각 앵커에 대해 앵커의 볼륨을 색상으로 채우는 상자를 만듭니다. 색상 선택은 앵커의 분류에 따라 달라집니다. 이 상자는 패스스루 모드에서는 보이지 않습니다. 또한 작은 상자를 사용하여 앵커의 위치와 방향을 시각화합니다:
Repeater3D { id: spatialAnchors model: XrSpatialAnchorListModel { } delegate: Node { id: anchorNode required property XrSpatialAnchor anchor required property int index position: anchor.position rotation: anchor.rotation Model { pickable: true z: anchorNode.anchor.has3DBounds ? anchorNode.anchor.offset3D.z / 2 * 100 : 0 // Position is center of 2D surface also for 3D anchors scale: anchorNode.anchor.has3DBounds ? anchorNode.anchor.extent3D : Qt.vector3d(anchorNode.anchor.extent2D.x, anchorNode.anchor.extent2D.y, 0.01) materials: PrincipledMaterial { // Make anchor objects invisible in passthrough mode baseColor: xrView.passthroughEnabled ? Qt.rgba(0, 0, 0, 0) : anchorColor(anchor) alphaMode: xrView.passthroughEnabled ? PrincipledMaterial.Blend : PrincipledMaterial.Opaque roughness: 0.7 } source: anchorNode.anchor.has3DBounds ? "#Cube" : "#Rectangle" property string anchorInfo: "anchor #" + anchorNode.index + ", " + anchorNode.anchor.classificationString } Model { // Visualize anchor orientation materials: PrincipledMaterial { baseColor: anchorNode.anchor.has3DBounds ? anchorNode.anchor.has2DBounds ? "green" : "red" : "blue" } scale: Qt.vector3d(0.05, 0.05, 0.05) source: "#Cube" Model { materials: PrincipledMaterial { baseColor: "black" } scale: Qt.vector3d(0.1, 3, 0.1) source: "#Cube" y: 150 } Model { materials: PrincipledMaterial { baseColor: "white" } scale: Qt.vector3d(3, 0.1, 0.1) source: "#Cube" x: 150 } } visible: anchor.has2DBounds || anchor.has3DBounds } }
앵커 상자는 선택할 수 있으며 앵커의 classificationString 을 포함하는 문자열 속성 anchorInfo
을 가집니다. 그런 다음 컨트롤러의 위치에 따라 피킹을 수행합니다. (자세한 내용은 xr_input 예시를 참조하세요.) 앵커 상자 중 하나를 누르면 앵커 정보가 포함된 레이블이 표시됩니다:
Node { id: labelNode position: rightController.position rotation: rightController.rotation property int numAnchors: spatialAnchors.count property string anchorInfo: "(no anchor)" Node { y: 15 x: -15 scale: Qt.vector3d(0.1, 0.1, 0.1) Rectangle { width: 300 height: 100 color: Qt.rgba(1,0.9,0.8,0.7) radius: 10 border.width: 2 border.color: "blue" Text { anchors.fill: parent anchors.margins: 10 textFormat: Text.StyledText text: "Total anchors: " + labelNode.numAnchors + "<br>" + "Selected: " + labelNode.anchorInfo } } } }
© 2025 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.