Hello,
I want to be able to tap on a previously-placed ModelEntity box and add a dot or a text at that location on the box (kind of like I'm adding an annotation on the box)
I have something like this, but not sure how I should do it correctly:
class MyARView: ARView {
// ...
private func didTap(_ gestureRecognizer: UITapGestureRecognizer) {
let pos = gestureRecognizer.location(in: self)
if !didPlaceCube {
placeCube(pos)
return
}
let hitTestResult = self.hitTest(pos)
guard let firstResult = hitTestResult.first else { return}
let entity = firstResult.entity
let textEntity = ModelEntity(mesh: .generateText("Hello there", extrusionDepth: 0.4, font: .boldSystemFont(ofSize: 0.05), containerFrame: .zero, alignment: .center, lineBreakMode: .byWordWrapping))
textEntity.setPosition(entity.position + firstResult.position, relativeTo: entity)
entity.addChild(textEntity)
}
// ...
}
Discuss spatial computing on Apple platforms and how to design and build an entirely new universe of apps and games for Apple Vision Pro.
Post
Replies
Boosts
Views
Activity
Hi,
I'm working on a simple visionOS app and I'm testing on device.
For one part of the app, I load an object in and place it on the user's hand. If I use a primitive shape, like a sphere or cylinder, this works fine. However, now I'm trying to load a an object from my RealityKitContent package. But everytime I try this, I get a an error message, resourceNotFound("Stone"), where "Stone" is one of my usda scenes.
This is what the guts of my function looks like that should return a ModelEntity:
do {
let entity = try await ModelEntity(named: "Stone", in: realityKitContentBundle)
entity.generateCollisionShapes(recursive: true)
return entity
} catch {
print("Error \(error)")
}
I can see the "Stone" in my Xcode sidebar as part of the RealityKitContent package and inside that scene, there is a simple sphere, but alas I always get this in the Xcode console, "Error resourceNotFound("Stone")"
I'm probably doing something pretty silly, hopefully it's obvious to someone else.
Thanks for the help.
Ian
I'd like to map a SwiftUI view (in my case: a map) onto a 3D curved plane in immersive view, so user can literally immersive themselves into the map. The user should also be able to interact with the map, by panning it around and selecting markers.
Is this possible?
I'm developing a vision pro application. However, when the user takes off the Apple Vision Pro device, the application goes into the background. How can I prevent this behavior programmatically?
Following this thread I'm able to render a simple picture in a Plane material, however, I'm unable to scale it to show bigger than the window itself, or move it behind the window.
Here's my relevant code so far.-
var body: some View {
ZStack {
RealityView { content in
var material = UnlitMaterial()
material.color = try! .init(tint: .white,
texture: .init(.load(named: "image",
in: nil)))
let entity = Entity()
let component = ModelComponent(
mesh: .generatePlane(width: 1, height: 1),
materials: [material]
)
entity.components.set(component)
let currentTransform = entity.transform
var newTransform = Transform(scale: currentTransform.scale,
rotation: currentTransform.rotation,
translation: SIMD3(0, 0, -0.2))
entity.move(to: newTransform, relativeTo: nil)
/*
let scalingPivot = Entity()
scalingPivot.position.y = entity.visualBounds(relativeTo: nil).center.y
scalingPivot.addChild(entity)
content.add(scalingPivot)
scalingPivot.scale *= .init(x: 1, y: 1, z: 1)
*/
}
}
}
It belongs to an ImmersiveSpace I'm opening directly from my main window, but I have several issues:
The texture shows always in front of the window
I'm unable to scale it (scaling seems to affect to the texture coordinates inside the material instead of scaling the mesh itself)
I can only see the texture in the canvas preview (not in simulator)
I am using the room plan api to implement the function of multiple space merging, but I found that after performing multiple space merging, the generated json would miss some of the newly added areas, but the usd file and plist file were complete.Does anyone have this problem? Look forward to official support
this is my code:
public func mergeScan(_ data:String,_ scanName:String,_ directoryName:String){
var capturedRoomArray: [CapturedRoom] = []
//解析主结构
let jsonURL = getRootURL().appending(path: "/\(directoryName)/\(scanName)/scan.json")
guard let mainStructureRoom = try?loadCapturedRoom(from: jsonURL) else { return }
capturedRoomArray.append(mainStructureRoom)
// 添加子结构
if let subStructureRoom = try? loadCapturedRoom(from: data) {
os_log("loadCapturedRoom string data success: %@", type: .error, String(describing: data))
capturedRoomArray.append(subStructureRoom)
}
os_log("merge scan capturedRoomArray: %@", type: .error, String(describing: capturedRoomArray.count))
//合并
Task {
do {
finalStructureResults = try await structureBuilder.capturedStructure(from: capturedRoomArray)
}catch {
print("Merging Error:\(error.localizedDescription)")
return
}
do{
//保存
//导出json
guard let finalStructureResults else { return }
try exportJson(from: finalStructureResults, to: jsonURL)
//导出usd
let meshDestinationURL = jsonURL.deletingPathExtension().appendingPathExtension("usdz")
//导出plist
let metadataDestinationURL = jsonURL.deletingPathExtension().appendingPathExtension("plist")
try finalStructureResults.export(to: meshDestinationURL,
metadataURL: metadataDestinationURL,
exportOptions: [.mesh])
} catch {
print("Merge Error:\(error.localizedDescription)")
return
}
}
}
func exportJson(from capturedStructure: CapturedStructure, to url: URL) throws {
let encoder = JSONEncoder()
encoder.outputFormatting = [.prettyPrinted, .sortedKeys]
let data = try encoder.encode(capturedStructure)
try data.write(to: url)
}
Note: Only json is missing the content of this or the next scan, usdz and plist are complete
I am new to visionOS development, just slowly figuring out the difference in immersion styles to figure out how I want my app to behave.
It seems that when you use a progressive immersive space the minimum immersion level (set via the digital crown) is not 0? Meaning, there is no way to go from mixed to full by using the Digital Crown. Even when I try to set it to 0 (such as in the Destination Video sample), it pops back up to around 30-40%, and I always see the background. Is this expected behavior, or are there some settings that allow me to change this minimum immersion level?
Further, in the video 'Meet ARKit for spatial computing', it is stated that to get access to ARKit tracking data you must use a 'Full Space', not the 'Shared Space'. This wording is confusing to me. Is an ImmersiveSpace set to the .mixed (or .progressive) immersion style still a 'Full Space' (because it isn't in the shared space, with other apps)? OR, is ARKit only available in an ImmersiveSpace with the .full immersion style? Just feels like maybe 'full' is being used in two different ways here...
Thanks in advance,
-pj
I am trying to implement a game where the character walks on the scene mesh. I am controlling the character with a game controller. I noticed there is a character controller component in Reality Composer Pro, I am aware that when this component is added, the player cannot have a collision or a physics component.
I need an example that covers adding an entity with the character controller component to the scene and then moving the character using the moveCharacter function.
I was also looking at the documentation https://developer.apple.com/documentation/realitykit/entity/movecharacter(by:deltatime:relativeto:collisionhandler:)
Here it is also looking for deltaTime. Where do we get the deltaTime from? does it come from a system's update function, does that also mean that the character controller needs to be moved in the update method?
Thanks,
Sarang
I am working on a sports training app for VisionOS that requires recognition of fast-moving objects. Currently, I am using ImageTrackingProvider to tag the objects I need. I have noticed that while recognition works well for stationary objects, it does not perform well in tracking moving objects. I assume there are a mix of factors at play:
I am not sure if ARKit is actually built for tracking moving objects, so there could be a refresh rate limit enforced to save battery.
My reference image could be suboptimal/too complex to recognize quickly.
While I can't do anything about #1, I am curious about recommendations for #2. Are there recommendations for the best size of a reference image, its color (would black and white work better?), and its complexity? Also, since the ARKit Resource Group seems to support JPEG & PNG, is there any specific preference for one over the other? Should I prepare the images in any special way to achieve the best possible performance?
Thanks.
I am working on a sports training app for VisionOS that requires recognition of fast-moving objects. Currently, I am using ImageTrackingProvider to tag the objects I need. I have noticed that while recognition works well for stationary objects, it does not perform well in tracking moving objects. I assume there are a mix of factors at play:
I am not sure if ARKit is actually built for tracking moving objects, so there could be a refresh rate limit enforced to save battery.
My reference image could be suboptimal/too complex to recognize quickly.
I am not sure if ARKit is actually built for tracking moving objects, so there could be a refresh rate limit enforced to save battery.
My reference image could be suboptimal/too complex to recognize quickly.
While I can't do anything about #1, I am curious about recommendations for #2. Are there recommendations for the best size of a reference image, its color (would black and white work better?), and its complexity? Also, since the ARKit Resource Group seems to support JPEG & PNG, is there any specific preference for one over the other? Should I prepare the images in any special way to achieve the best possible performance?
Thanks.
let apple = try Entity.load(named: "apple", in: realityKitContentBundle)
works, but
let apple = try Entity.loadModel(named: "apple", in: realityKitContentBundle)
does not work
ie. (error.localizedDescription = Failed to find resource with name "apple" in bundle)
I am unsure what is causing the problem, apple.usda was created in Reality Composer Pro from primitives and has a single apple object (no root). When I load with Entity.load and print apple, I get:
▿ 'apple' : Entity, children: 1
⟐ Transform
⟐ SynchronizationComponent
▿ 'apple' : ModelEntity
⟐ ModelComponent
⟐ Transform
⟐ CollisionComponent
⟐ PhysicsBodyComponent
⟐ SynchronizationComponent
This nested hierarchy seems redundant to me, is it preferred in AR kit to have such a structure? Why am I unable to load usda directly as a ModelEntity?
According to https://developer.apple.com/documentation/visionos/bringing-your-arkit-app-to-visionos#Isolate-ARKit-features-not-available-in-visionOS, Body Tracking and several other features are not available on VisionOS.
So is there any ETA for these ARKit's features to be supported in VisionOS? Thanks.
Hi,
I have a code that uses ImageTrackingProvider. I am experimenting with glyphs of various complexity and structure to understand which ones would be more superior for recognition. Due to the absence of a color printer, I am mostly experimenting with monochrome glyphs as well as some color-paper squares. I am getting mixed results and would like to validate whether what I got are the expected results for the current capabilities of ARKit & VisionPro, or if there is still an opportunity for improvement by selecting different glyphs.
So far, I have used a colored square of size 5x5 cm, as well as two glyphs provided below.
ARKit Glyph
Abstract Glyph
The ARKit Glyph is not recognizable by ARKit or VisionPro at all, no matter the lighting conditions or the angles from which I view it.
The Abstract Glyph is recognizable consistently at a 90-degree angle, and sometimes at other angles too. The maximum distance at which I was able to detect it was around 15cm, maybe less.
I am really curious if there is any specification that I can check against to understand whether my glyphs are good or not, and at what maximum distance such glyphs can be recognized if they were 5x5cm in size.
I am also curious whether ARKit is capable of recognizing images of 5x5cm size at a distance between 2 and 3 meters, and if so, how I should prepare the glyph for such requirements.
Thanks in advance,
Nikita
ps I am skipping a question about yaw angles of image, as well as angel between normal of an image & camera view but I guess they also have their impact on ability to recognize original image.
When I use LiDAR, AVCaptureDeviceTypeBuiltInLiDARDepthCamera is used.
As AVCaptureDeviceTypeBuiltInLiDARDepthCamera is A device that consists of two cameras, one LiDAR and one YUV.
I found that the LiDAR data is 30fps, even making the YUV data 30 fps. But I really need the 240fps YUV data.
Is there a way to utilize the 30fps LiDAR with 240fps YUV camera?
Any reply would be appreciated.
Hi folks!
I have been working with a team on a Vision Pro app using Reality Composer Pro. One thing we have found is that multiple developers editing the RCPro scene are a continuous problem, similar to when multiple developers edit a storyboard.
RC Pro maintains a SceneMetadataList.json file that indexes the file contents of the project that is updated even as the scene hierarchy is opened and closed, not to mention other changes to scene content. We are getting frequent continuous version control conflicts with this file as we each make changes and edits to the scene, or even browse the scene without making any substantive changes.
It seems like it would be safe to add the SceneMetadataList.json file in a RC Pro project to .gitignore. Is that recommended? Any downsides to that?
Hi, I want to develop an AR App for construction site on which i need to prove the calibration quality of the 3D model on plane.
For that i have already retrieve informations like TrackingState, points cloud, confidence map...
I would like to know if the ConfidenceLevel, that appears to be an enumeration, is available or if I need to analyse the points cloud to make my own confidence level.
And also if you have informations on how can I know the precision of the 3D map on real life.
I am running a modified RoomPllan app in my test environment I get two ARSessions active, sometimes more. It appears that the first one is created by Scene Kit because it is related go ARSCNView. Who controls that and what gets processed through it? I noticed that I get a lot of Session Interruptions from Sensor Failure when I am doing World Tracking and the first one happens almost immediately.
When I get the room capture delegates fired up I start getting images to the delegate via a second session that is collecting images. How do I tell which session is the scene kit session and which one is the RoomCapture session on thee fly when it comes through the delegate? Is there a difference in the object desciptor that I can use as a differentiator? Relying on the Address of the ARSession buffer being different is okay if you get your timing right. It wasn't clear from any of the documentation that there would be TWO or more AR Sessions delivering data through the delegates. The books on the use of ARKIT are not much help in determining the partition of responsibilities between the origins. The buffer arrivals at the functions supported by the delegates do not have a clear delineation of what function is delivered through which delegate discernible from the highly fragmented documentation provided by the Developer document library. Can someone give me some guidance here? Are there sources for CLEAR documentation of what is delivered via which delegate for the various interfaces?
I am very new to shaders, never used one of the large systems like Unity. However I have started exploring visionOS programming and that led me to create some effects for materials in Reality Composer Pro.
I have been overwhelmed with the possibilities, but also kind of lost. I understand that RCPs shaders are based on MaterialX, so maybe there are tutorials on the web that would cover how to create procedural effects (fire, wind, water, etc)? I’ve stumbled through…but it’s slow going. Are there any good resources that talk about how to use the various nodes to create procedural effects?
For example, it took me a while to figure out that using the “time” node allows me to animate cool color changes, especially when combined with various math and remap nodes.
Just looking for some basic resources I think. Would the shader graph tutorials about Unity, apply to using RCP? Are the node types similar enough?
I'd like to grab the current camera frame in visionOS. I have a Swift file (am new to Swift) that looks like this:
import ARKit
import SwiftUI
class ARSessionManager: NSObject, ObservableObject, ARSessionDelegate {
var arSession: ARSession
override init() {
arSession = ARSession()
super.init()
arSession.delegate = self
}
func startSession() {
let configuration = ARWorldTrackingConfiguration()
configuration.planeDetection = .horizontal
arSession.run(configuration)
}
// ARSessionDelegate method to capture frames
func session(_ session: ARSession, didUpdate frame: ARFrame) {
// Process the frame, e.g., capture image data
}
}
and I get errors including "Cannot find type 'ARSessionDelegate' in scope". Help? Is ARFrame called something different for Vision Pro?
I tried to show spatial photo on my application by swiftUI's Image but it just show flat version of it even I Use Vision Pro,
so, how can I show spatial photo to users,
does there any options for this?