天道酬勤,学无止境

realitykit

Implement a crosshair kind behaviour in RealityKit

What I want to achieve: Attach a sphere to the camera position (so that it always stay at the center of the screen as the device move) and detect when it is on top of other AR objects - to trigger other actions/behaviour on the AR objects. Approach: I have created the sphere and attached to the center of the screen as shown below @IBOutlet var arView: ARView! override func viewDidLoad() { super.viewDidLoad() let mesh = MeshResource.generateSphere(radius: 0.1) let sphere = ModelEntity(mesh: mesh) let anchor = AnchorEntity(.camera) sphere.setParent(anchor) arView.scene.addAnchor(anchor) sphere

2021-09-24 07:03:10    分类:问答    swift   augmented-reality   arkit   realitykit   reality-composer

Using ARKit anchor to place RealityKit Scene

I am currently struggling to add an RealityKit Scene to an ARKit anchor. As my previous question, it is not possible to directly add the RealityKit Scene to an ARKit Anchor Node. But how can I use the ARKit Anchor to place my Scene? For example, I want to find an object in the room, and depending on which object I found, I want to use different scenes and anchor them in the room depending on the recognised objects position. Thanks for the help. Current try: func makeUIView(context: Context) -> ARView { let arView = ARView(frame: .zero) // Load the "Box" scene from the "Experience" Reality File

2021-09-09 05:00:17    分类:问答    swift   swiftui   augmented-reality   arkit   realitykit

RealityKit – Asynchronous model loading doesn't work

This code works: let entity = try! Entity.load(named: "toy_robot_vintage") anchorEntity.addChild(entity) But this doesn't: _ = Entity.loadAsync(named: "toy_robot_vintage") .sink(receiveCompletion: { loadCompletion in print("This is never executed") }, receiveValue: { entity in print("This is never executed") anchorEntity.addChild(entity) }) What could be the issue?

2021-09-08 09:04:25    分类:问答    swift   asynchronous   augmented-reality   realitykit   usdz

how to re-render the scanned mesh content with realityKit's ARView?

I can modify the line color of the mesh using the following code. extension ARMeshClassification { var description: String { switch self { case .ceiling: return "Ceiling" case .door: return "Door" case .floor: return "Floor" case .seat: return "Seat" case .table: return "Table" case .wall: return "Wall" case .window: return "Window" case .none: return "None" @unknown default: return "Unknown" } } var color: UIColor { switch self { case .ceiling: return .red case .door: return .green case .floor: return .blue case .seat: return .cyan case .table: return .magenta case .wall: return .yellow case

2021-09-07 18:31:54    分类:问答    ios   arkit   realitykit   lidar

RealityKit – Stored Entities & Load the Scene Aynchronously from the URL

Here is Apple Documentation: 1.Loading Reality Composer Files Manually Without Generated Code and I used the "Load the Scene Aynchronously from the URL" code: func loadRealityComposerSceneAsync (filename: String, fileExtension: String, sceneName: String, completion: @escaping (Swift.Result<(Entity & HasAnchoring)?, Swift.Error>) -> Void) { guard let realityFileSceneURL = createRealityURL(filename: filename, fileExtension: fileExtension, sceneName: sceneName) else { print("Error: Unable to find specified file in application bundle") return } let loadRequest = Entity.loadAnchorAsync(contentsOf

2021-09-07 06:43:00    分类:问答    swift   asynchronous   arkit   realitykit   reality-composer

Loading .rcproject from iOS local directory

I am trying to load a rcproject from a local directory. My target is, to load it from an URL and then show it. If I load it like this: let modelScene = try? Entity.loadAnchor(named: "Experience") everything works fine. But if I do this: let url = URL(fileURLWithPath: "./Experience") or let url = URL(fileURLWithPath: "./Experience.rcproject") and let modelScene = try? Entity.loadAnchor(contentsOf: url, withName: "Experience") or let modelScene = try? Entity.loadAnchor(contentsOf: url) I get the following error: // [Pipeline] Failed to open scene 'Experience -- file:///'. I have no idea, what

2021-09-07 05:03:14    分类:问答    swift   xcode   swiftui   augmented-reality   realitykit

How do I access the model component of Reality Composer in RealityKit?

I'm trying to change the model component of a text entity created in Reality Composer in my code, but this as! casting the gui-created entity to a reference to an entity with a model component failed. self.entityReference = scene.realityComposerEntity as! HasModel textEntity.model!.mesh = MeshResource.generateText("New Text") The text entity in RealityKit should have a model property as it has a visual appearance in the ARView, but I don't know how to access it. Does anyone have any idea how? Are there any other easy ways to dynamically display different text in the same spot using RealityKit

2021-09-04 14:53:52    分类:问答    swift   augmented-reality   realitykit   reality-composer

How do I spin and add a linear force to an Entity loaded from Reality Composer?

I've constructed a scene in Reality Composer that has a ball that starts the scene floating in the air. I'm attempting to programmatically throw the ball while simultaneously spinning it. I tried to do this through behaviors in Reality Composer, but can't get both behaviors to work simultaneously, also, the ball immediately falls to the ground once I start the animation. My second attempt was to forgo the behavior route and I attempted to do this programmatically, but I can not add a force, because the loaded ball is an Entity and not a ModelEntity. What am I doing wrong? I want to spin the

2021-08-31 08:23:54    分类:问答    swift   augmented-reality   arkit   realitykit   reality-composer

SceneKit AR game fps getting low and the device getting hot with use

I'm developing a 3D game with ARKit and SceneKit. The game running smoothly at 60 fps but when I keep using it for a while the device get hot and the frame rate drop to 30 fps. The energy impact is very high and I noticed something in Instruments. I'll show the statistics and what I see in Instruments. This are the statistics when the game is running smoothly but I don't understand why I get 1.16K as the nodes count. I actually don't use so much nodes but it's just a simple level. This is what I get on Instruments, I don't know what it means. As you can see here the energy impact is very high

2021-08-30 06:42:30    分类:问答    swift   scenekit   augmented-reality   arkit   realitykit

Track camera position with RealityKit

How can you track the position of the camera using RealityKit? Several examples are using SceneKit, but I found none using RealityKit. I need a function such as: func session(_ session: ARSession, didUpdate frame: ARFrame) { // Do something with the new transform let currentTransform = frame.camera.transform doSomething(with: currentTransform) }

2021-08-01 11:06:17    分类:问答    ios   swift   augmented-reality   arkit   realitykit