Posts

Post not yet marked as solved
8 Replies
2.9k Views
Hello, in this project https://developer.apple.com/documentation/arkit/content_anchors/tracking_and_visualizing_faces there is some sample code that describes how to map the camera feed to an object with SceneKit and a shader modifier. I would like know if there is an easy way to achieve the same thing with a CustomMaterial and RealityKit 2. Specifically I'm interested in what would be the best way to pass in the background of the RealityKit environment as a texture to the custom shader. In SceneKit this was really easy as one could just do the following: material.diffuse.contents = sceneView.scene.background.contents As the texture input for custom material requires a TextureResource I would probably need a way to create a CGImage from the background or camera feed on the fly. What I've tried so far is accessing the captured image from the camera feed and creating a CGImage from the pixel buffer like so: guard     let frame = arView.session.currentFrame,     let cameraFeedTexture = CGImage.create(pixelBuffer: frame.capturedImage),     let textureResource = try? TextureResource.generate(from: cameraFeedTexture, withName: "cameraFeedTexture", options: .init(semantic: .color)) else {     return } // assign texture customMaterial.custom.texture = .init(textureResource) extension CGImage {   public static func create(pixelBuffer: CVPixelBuffer) -> CGImage? {     var cgImage: CGImage?     VTCreateCGImageFromCVPixelBuffer(pixelBuffer, options: nil, imageOut: &cgImage)     return cgImage   } } This seems wasteful though and is also quite slow. Is there any other way to accomplish this efficiently or would I need to go the post processing route? In the sample code the displayTransform for the view is also being passed as a SCNMatrix4. CustomMaterial custom.value only accepts a SIMD4 though. Is there another way to pass in the matrix? Another idea I've had was to create a CustomMaterial from an OcclusionMaterial which already seems to contain information about the camera feed but so far had no luck with it. Thanks for the support!
Posted Last updated
.
Post not yet marked as solved
2 Replies
1.5k Views
Hello, PhysicallyBasedMaterial in RealityKit 2 contains a blending property to adjust the transparency of a material. Is there a way to animate this over time to fade entities in and out? I've tried the new FromToByAnimation API but could not figure out if there is a supported BindPath for the transparency. Ideally what I would like to achieve is something similar to SceneKits SCNAction.fadeIn(duration: …) which also worked on a whole node. I figured I could also go the route of a custom fragment shader here, though that seems overkill. As RealityComposer also supports fade actions I would assume that this is at least supported behind the scenes. Thanks for any help!
Posted Last updated
.
Post not yet marked as solved
3 Replies
989 Views
Hello, I would love to utilize the new Occlusion Feature that has been added to RealityKit. But as my app still requires a lot of features that RealityKit doesn't yet deliver I have to keep using SceneKit for now. I was wondering if I could convert the depth map provided by the SceneDepth API into an alpha matte that I could then feed into a SCNTechnique to achieve a 'poor mans' occlusion. Is there some kind of CIFilter or workflow that could help me with this? Maybe some kind of edge detection? Thankful for any hints!
Posted Last updated
.
Post marked as solved
2 Replies
3.3k Views
Hello, this might be a really basic question as I don’t have a lot of experience with Swift Package Manager yet. I would like to know what I need to do in order specify that the frameworks my package depends on, will also be imported and exposed within the file where I import my package. For example: I have a framework called »UIComponents« which internally imports UIKit to build custom components. Now in my app I import UIComponents and have its contents available. However there I can not reference things from UIKit. For that I would need to import UIKit separately. So how can I import my framework and then also have access to UIKit? Similarly to how UIKit also gives me access to stuff from Foundation. Thanks!
Posted Last updated
.