Post

Replies

Boosts

Views

Activity

When using ARImageTrackingConfiguration, the entity in the scene keeps shaking
When isAutoFocusEnabled is set to true, the entity in the scene keeps shaking. No focus when isAutoFocusEnabled is set to false. How to set up to solve this problem. override func viewDidLoad() { super.viewDidLoad() arView.session.delegate = self guard let arCGImage = UIImage(named: "111", in: .main, with: .none)?.cgImage else { return } let arReferenceImage = ARReferenceImage(arCGImage, orientation: .up, physicalWidth: CGFloat(0.1)) let arImages: Set<ARReferenceImage> = [arReferenceImage] let configuration = ARImageTrackingConfiguration() configuration.trackingImages = arImages configuration.maximumNumberOfTrackedImages = 1 configuration.isAutoFocusEnabled = false arView.session.run(configuration) } func session(_ session: ARSession, didAdd anchors: [ARAnchor]) { anchors.compactMap { $0 as? ARImageAnchor }.forEach { let anchor = AnchorEntity(anchor: $0) let mesh = MeshResource.generateBox(size: 0.1, cornerRadius: 0.005) let material = SimpleMaterial(color: .gray, roughness: 0.15, isMetallic: true) let model = ModelEntity(mesh: mesh, materials: [material]) model.transform.translation.y = 0.05 anchor.children.append(model) arView.scene.addAnchor(anchor) } }
0
0
562
Apr ’24
ARImageTrackingConfiguration Entity shaking
I use ARImageTrackingConfiguration to load the entity. In the scene the entity keeps shaking. Tracking images have been correcting the rootAnchor transform,which should be the cause of this problem. Is there any optimization plan? override func viewDidLoad() {     super.viewDidLoad()           arView.session.delegate = self           guard let anchorCGImage = UIImage(named: "anchor.png")?.cgImage else { return }     let arReferenceImage = ARReferenceImage(anchorCGImage, orientation: .up, physicalWidth: CGFloat(0.1))     let arImages: Set<ARReferenceImage> = [arReferenceImage]     imageConfiguration.trackingImages = arImages     imageConfiguration.maximumNumberOfTrackedImages = 1     arView.session.run(imageConfiguration)   } func session(_ session: ARSession, didAdd anchors: [ARAnchor])   {     anchors.compactMap { $0 as? ARImageAnchor }.forEach {       do {         let ey = try Entity.load(named: "c5nj3ibu_l1a", in: .main)         ey.scale = [0.4, 0.4, 0.4]         rootAnchor = AnchorEntity(anchor: $0)         rootAnchor.addChild(ey)         arView.scene.addAnchor(rootAnchor)       } catch {       }     }   }
0
0
564
Mar ’23
How to delete Entity memory in RealityKit
Although the model disappeared, the memory did not decrease. How to delete memory occupied by the model? // MARK: === viewDidLoad   override func viewDidLoad() {     super.viewDidLoad()           arView.renderOptions = [.disableMotionBlur, .disableDepthOfField, .disableCameraGrain, .disableHDR]     arView.environment.sceneUnderstanding.options.insert(.occlusion)           rootAnchor = AnchorEntity(plane: .horizontal)     arView.scene.addAnchor(rootAnchor)           var cancellable: AnyCancellable? = nil     cancellable = Entity.loadAsync(contentsOf: Bundle.main.url(forResource: "vyygabbj_afr", withExtension: "usdz")!)       .sink(receiveCompletion: { error in         DispatchQueue.main.async {          cancellable?.cancel()          cancellable = nil         }       }, receiveValue: { [weak self] ey in         guard let self = self else { return }         self.modelEy = ModelEntity()         self.modelEy.addChild(ey)                   self.rootAnchor.addChild(self.modelEy)         ey.availableAnimations.forEach {           ey.playAnimation($0.repeat())         }                   DispatchQueue.main.async {           cancellable?.cancel()           cancellable = nil         }     })   }   override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?)   {     modelEy.removeFromParent()   }
2
1
2k
Jun ’22
The camera is stuck for a moment when loading the model
I use Entity.loadAsync to load the USDZ. The camera is stuck for a moment when loading the model. var cancellable: AnyCancellable? = nil     cancellable = Entity.loadAsync(contentsOf: Bundle.main.url(forResource: "vyygabbj_afr", withExtension: "usdz")!)       .sink(receiveCompletion: { error in         DispatchQueue.main.async {          cancellable?.cancel()          cancellable = nil         }       }, receiveValue: { [weak self] ey in         guard let self = self else { return }         self.modelEy = ModelEntity()         self.modelEy.addChild(ey)         self.rootAnchor.addChild(self.modelEy)         ey.availableAnimations.forEach {           ey.playAnimation($0.repeat())         }         DispatchQueue.main.async {           cancellable?.cancel()           cancellable = nil         }     })
0
0
705
May ’22
Animation cannot be played in AR scene
Xcode:13.1 iOS:15.1 USDZ:https://sketchfab.com/3d-models/spartan-armour-mkv-halo-reach-57070b2fd9ff472c8988e76d8c5cbe66 The animation can be played in iOS14, but after I update to iOS15, the animation cannot be played. Thanks import UIKit import ARKit import RealityKit import Combine class ViewController: UIViewController {       @IBOutlet var arView: ARView!       var rootAnchor: AnchorEntity!           override func viewDidLoad() {     super.viewDidLoad()           rootAnchor = AnchorEntity(plane: .horizontal)     arView.scene.addAnchor(rootAnchor)           var cancellable: AnyCancellable? = nil     cancellable = Entity.loadAsync(contentsOf: Bundle.main.url(forResource: "Spartan_Armour_MKV_-_Halo_Reach", withExtension: "usdz")!)       .sink(receiveCompletion: { error in         DispatchQueue.main.async {          cancellable?.cancel()          cancellable = nil         }       }, receiveValue: { [weak self] ey in         guard let self = self else { return }         self.rootAnchor.addChild(ey)         ey.availableAnimations.forEach {           ey.playAnimation($0.repeat())         }         DispatchQueue.main.async {           cancellable?.cancel()           cancellable = nil         }     })   } }
2
0
1.6k
Mar ’22
USDZ Animations with RealityKit 2
init(_ path: String)   {     super.init()           self.name = "modelEy"           var cancellable: AnyCancellable? = nil     cancellable = Entity.loadAsync(contentsOf: URL(fileURLWithPath: path))       .sink(receiveCompletion: { error in                   DispatchQueue.main.async {           cancellable?.cancel()           cancellable = nil         }       }, receiveValue: { [weak self] ey in         guard let `self` = self else { return }                   ey.name = "animationEy"         self.addChild(ey)                   let entityBounds = ey.visualBounds(relativeTo: ey.parent)         let extents: SIMD3<Float> = [entityBounds.extents.x, entityBounds.extents.y, entityBounds.extents.z]         self.collision = CollisionComponent(shapes: [ShapeResource.generateBox(size: extents).offsetBy(translation: entityBounds.center)])                   DispatchQueue.main.async {           cancellable?.cancel()           cancellable = nil         }       })   } ey.availableAnimations.forEach {     if #available(iOS 15.0, *)     {       ey.playAnimation($0.repeat())     }   } The animation does not play. Skeletal animation!
2
0
1k
Sep ’21
Different display effects in AR
Xcode:12.5 iOS:14.5 I updated the latest version. In the previous version. I blocked the anchor image with my hand, audioEntity has been kept in the AR scene. But now, I blocked the anchor image with my hand, audioEntity will disappear. Why? How do I achieve the previous effect? func session(_ session: ARSession, didAdd anchors: [ARAnchor])   {     anchors.compactMap { $0 as? ARImageAnchor }.forEach {               rootAnchor = AnchorEntity(anchor: $0)       arView.scene.addAnchor(rootAnchor)               add()     }   }   fileprivate func add()   {     let audioPlane = MeshResource.generatePlane(width: 0.2, height: 0.2, cornerRadius: 0)     var audioMtl = SimpleMaterial()     do {       audioMtl.baseColor = try MaterialColorParameter.texture(TextureResource.load(named: "audio_play.png"))     } catch {     }     let audioEntity = ModelEntity(mesh: audioPlane, materials: [audioMtl])     audioEntity.position = [0, 0.1, 0]     rootAnchor.addChild(audioEntity)   }
2
0
1.3k
Apr ’21
When using ARImageTrackingConfiguration, the entity in the scene keeps shaking
When isAutoFocusEnabled is set to true, the entity in the scene keeps shaking. No focus when isAutoFocusEnabled is set to false. How to set up to solve this problem. override func viewDidLoad() { super.viewDidLoad() arView.session.delegate = self guard let arCGImage = UIImage(named: "111", in: .main, with: .none)?.cgImage else { return } let arReferenceImage = ARReferenceImage(arCGImage, orientation: .up, physicalWidth: CGFloat(0.1)) let arImages: Set<ARReferenceImage> = [arReferenceImage] let configuration = ARImageTrackingConfiguration() configuration.trackingImages = arImages configuration.maximumNumberOfTrackedImages = 1 configuration.isAutoFocusEnabled = false arView.session.run(configuration) } func session(_ session: ARSession, didAdd anchors: [ARAnchor]) { anchors.compactMap { $0 as? ARImageAnchor }.forEach { let anchor = AnchorEntity(anchor: $0) let mesh = MeshResource.generateBox(size: 0.1, cornerRadius: 0.005) let material = SimpleMaterial(color: .gray, roughness: 0.15, isMetallic: true) let model = ModelEntity(mesh: mesh, materials: [material]) model.transform.translation.y = 0.05 anchor.children.append(model) arView.scene.addAnchor(anchor) } }
Replies
0
Boosts
0
Views
562
Activity
Apr ’24
Reality Converter convert GLB to USDZ
I use Reality Converter to convert GLB to USDZ, the color becomes darker, I don't know why?Does anyone know the reason?Thanks
Replies
1
Boosts
0
Views
2.9k
Activity
Mar ’23
ARImageTrackingConfiguration Entity shaking
I use ARImageTrackingConfiguration to load the entity. In the scene the entity keeps shaking. Tracking images have been correcting the rootAnchor transform,which should be the cause of this problem. Is there any optimization plan? override func viewDidLoad() {     super.viewDidLoad()           arView.session.delegate = self           guard let anchorCGImage = UIImage(named: "anchor.png")?.cgImage else { return }     let arReferenceImage = ARReferenceImage(anchorCGImage, orientation: .up, physicalWidth: CGFloat(0.1))     let arImages: Set<ARReferenceImage> = [arReferenceImage]     imageConfiguration.trackingImages = arImages     imageConfiguration.maximumNumberOfTrackedImages = 1     arView.session.run(imageConfiguration)   } func session(_ session: ARSession, didAdd anchors: [ARAnchor])   {     anchors.compactMap { $0 as? ARImageAnchor }.forEach {       do {         let ey = try Entity.load(named: "c5nj3ibu_l1a", in: .main)         ey.scale = [0.4, 0.4, 0.4]         rootAnchor = AnchorEntity(anchor: $0)         rootAnchor.addChild(ey)         arView.scene.addAnchor(rootAnchor)       } catch {       }     }   }
Replies
0
Boosts
0
Views
564
Activity
Mar ’23
How to get Euler angles in RealityKit?
How to get Euler angles in RealityKit?
Replies
1
Boosts
0
Views
1.7k
Activity
Sep ’22
How to delete Entity memory in RealityKit
Although the model disappeared, the memory did not decrease. How to delete memory occupied by the model? // MARK: === viewDidLoad   override func viewDidLoad() {     super.viewDidLoad()           arView.renderOptions = [.disableMotionBlur, .disableDepthOfField, .disableCameraGrain, .disableHDR]     arView.environment.sceneUnderstanding.options.insert(.occlusion)           rootAnchor = AnchorEntity(plane: .horizontal)     arView.scene.addAnchor(rootAnchor)           var cancellable: AnyCancellable? = nil     cancellable = Entity.loadAsync(contentsOf: Bundle.main.url(forResource: "vyygabbj_afr", withExtension: "usdz")!)       .sink(receiveCompletion: { error in         DispatchQueue.main.async {          cancellable?.cancel()          cancellable = nil         }       }, receiveValue: { [weak self] ey in         guard let self = self else { return }         self.modelEy = ModelEntity()         self.modelEy.addChild(ey)                   self.rootAnchor.addChild(self.modelEy)         ey.availableAnimations.forEach {           ey.playAnimation($0.repeat())         }                   DispatchQueue.main.async {           cancellable?.cancel()           cancellable = nil         }     })   }   override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?)   {     modelEy.removeFromParent()   }
Replies
2
Boosts
1
Views
2k
Activity
Jun ’22
The camera is stuck for a moment when loading the model
I use Entity.loadAsync to load the USDZ. The camera is stuck for a moment when loading the model. var cancellable: AnyCancellable? = nil     cancellable = Entity.loadAsync(contentsOf: Bundle.main.url(forResource: "vyygabbj_afr", withExtension: "usdz")!)       .sink(receiveCompletion: { error in         DispatchQueue.main.async {          cancellable?.cancel()          cancellable = nil         }       }, receiveValue: { [weak self] ey in         guard let self = self else { return }         self.modelEy = ModelEntity()         self.modelEy.addChild(ey)         self.rootAnchor.addChild(self.modelEy)         ey.availableAnimations.forEach {           ey.playAnimation($0.repeat())         }         DispatchQueue.main.async {           cancellable?.cancel()           cancellable = nil         }     })
Replies
0
Boosts
0
Views
705
Activity
May ’22
Animation cannot be played in AR scene
Xcode:13.1 iOS:15.1 USDZ:https://sketchfab.com/3d-models/spartan-armour-mkv-halo-reach-57070b2fd9ff472c8988e76d8c5cbe66 The animation can be played in iOS14, but after I update to iOS15, the animation cannot be played. Thanks import UIKit import ARKit import RealityKit import Combine class ViewController: UIViewController {       @IBOutlet var arView: ARView!       var rootAnchor: AnchorEntity!           override func viewDidLoad() {     super.viewDidLoad()           rootAnchor = AnchorEntity(plane: .horizontal)     arView.scene.addAnchor(rootAnchor)           var cancellable: AnyCancellable? = nil     cancellable = Entity.loadAsync(contentsOf: Bundle.main.url(forResource: "Spartan_Armour_MKV_-_Halo_Reach", withExtension: "usdz")!)       .sink(receiveCompletion: { error in         DispatchQueue.main.async {          cancellable?.cancel()          cancellable = nil         }       }, receiveValue: { [weak self] ey in         guard let self = self else { return }         self.rootAnchor.addChild(ey)         ey.availableAnimations.forEach {           ey.playAnimation($0.repeat())         }         DispatchQueue.main.async {           cancellable?.cancel()           cancellable = nil         }     })   } }
Replies
2
Boosts
0
Views
1.6k
Activity
Mar ’22
USDZ Animations with RealityKit 2
init(_ path: String)   {     super.init()           self.name = "modelEy"           var cancellable: AnyCancellable? = nil     cancellable = Entity.loadAsync(contentsOf: URL(fileURLWithPath: path))       .sink(receiveCompletion: { error in                   DispatchQueue.main.async {           cancellable?.cancel()           cancellable = nil         }       }, receiveValue: { [weak self] ey in         guard let `self` = self else { return }                   ey.name = "animationEy"         self.addChild(ey)                   let entityBounds = ey.visualBounds(relativeTo: ey.parent)         let extents: SIMD3<Float> = [entityBounds.extents.x, entityBounds.extents.y, entityBounds.extents.z]         self.collision = CollisionComponent(shapes: [ShapeResource.generateBox(size: extents).offsetBy(translation: entityBounds.center)])                   DispatchQueue.main.async {           cancellable?.cancel()           cancellable = nil         }       })   } ey.availableAnimations.forEach {     if #available(iOS 15.0, *)     {       ey.playAnimation($0.repeat())     }   } The animation does not play. Skeletal animation!
Replies
2
Boosts
0
Views
1k
Activity
Sep ’21
Different display effects in AR
Xcode:12.5 iOS:14.5 I updated the latest version. In the previous version. I blocked the anchor image with my hand, audioEntity has been kept in the AR scene. But now, I blocked the anchor image with my hand, audioEntity will disappear. Why? How do I achieve the previous effect? func session(_ session: ARSession, didAdd anchors: [ARAnchor])   {     anchors.compactMap { $0 as? ARImageAnchor }.forEach {               rootAnchor = AnchorEntity(anchor: $0)       arView.scene.addAnchor(rootAnchor)               add()     }   }   fileprivate func add()   {     let audioPlane = MeshResource.generatePlane(width: 0.2, height: 0.2, cornerRadius: 0)     var audioMtl = SimpleMaterial()     do {       audioMtl.baseColor = try MaterialColorParameter.texture(TextureResource.load(named: "audio_play.png"))     } catch {     }     let audioEntity = ModelEntity(mesh: audioPlane, materials: [audioMtl])     audioEntity.position = [0, 0.1, 0]     rootAnchor.addChild(audioEntity)   }
Replies
2
Boosts
0
Views
1.3k
Activity
Apr ’21