London Escorts sunderland escorts 1v1.lol unblocked yohoho 76 https://www.symbaloo.com/mix/yohoho?lang=EN yohoho https://www.symbaloo.com/mix/agariounblockedpvp https://yohoho-io.app/ https://www.symbaloo.com/mix/agariounblockedschool1?lang=EN
10.2 C
New York
Friday, October 18, 2024

ios – The way to show the identify of a selected half od mannequin when clicking on that half


In RealityKit, how can I show a popup with the identify of a selected a part of a mannequin when clicking on that half?

I’m creating an iOS AR utility, and I’ve imported a USDZ mannequin of a tooth. I need to implement a characteristic the place, when a consumer faucets on a selected a part of the tooth mannequin, a small popup seems with some descriptive textual content about that half.

The principle problem I’m going through is figuring out which a part of the mannequin has been clicked. How can I obtain this? May you please information me by means of the steps and the interfaces that I have to name to implement this performance? Thanks very a lot in your assist!

Listed below are my code now:

import ARKit
import UIKit
import RealityKit

class ARViewController_plane: UIViewController {
    
    let arView = ARView()
    
    var modelEntity: ModelEntity?
    
    override func loadView() {
        tremendous.loadView()
        
        view = arView
        
        // create mannequin
        modelEntity = createModel()
        
        // 放置模型
        placeModel(mannequin: modelEntity!)
        
        // 设置手势
        installestures(on: modelEntity!)
        
        // 配置
        let configuration = ARWorldTrackingConfiguration()
        configuration.planeDetection = .horizontal
        
        // 运行
        arView.session.run(configuration)
        
    }
    
    func createModel() -> ModelEntity {
        let modelEntity = strive! ModelEntity.loadModel(named: "tsmile1.usdz")
        return modelEntity
    }
    
    func placeModel(mannequin:ModelEntity) {
        let planeAnchor = AnchorEntity(world: SIMD3(0, 0, 0))//(.airplane(.horizontal, classification: .any, minimumBounds: SIMD2<Float>(0.02, 0.02)))
        planeAnchor.addChild(modelEntity!)
        arView.scene.addAnchor(planeAnchor)
    }
    
    func installestures(on object: ModelEntity) {
        // scale
        object.generateCollisionShapes(recursive: true)
        arView.installGestures([.scale], for: object)
        // my rotation
        let rotationGesture = UIPanGestureRecognizer(goal: self, motion: #selector(handleRotationGesture(_:)))
        arView.addGestureRecognizer(rotationGesture)
    }
    @objc func handleRotationGesture(_ gesture: UIPanGestureRecognizer) {
        let translation = gesture.translation(in: arView)
        // 控制旋转速度
        let rotationAngle = Float(translation.x) * 0.001
        
        // 获取当前模型的变换
        var currentTransform = modelEntity!.rework

        // 创建新的四元数旋转(围绕模型的Z轴旋转)
        let newRotation = simd_quatf(angle: rotationAngle, axis: [0, 0, 1])

        // 将新的旋转与现有的旋转叠加
        currentTransform.rotation = simd_mul(currentTransform.rotation, newRotation)

        // 应用新的变换
        modelEntity!.rework = currentTransform
    }
}



Related Articles

Social Media Auto Publish Powered By : XYZScripts.com