Post

Replies

Boosts

Views

Activity

Reply to RealityView to show two screens of AR in iOS 18/macOS 15 using SwiftUI
import SwiftUI import RealityKit struct ContentView : View { let anchor1 = AnchorEntity(.camera) let anchor2 = AnchorEntity(.camera) var body: some View { HStack (spacing: 0){ MainView(anchor: anchor1) MainView(anchor: anchor2) } .background(.black) } } struct MainView : View { @State var anchor = AnchorEntity() var body: some View { RealityView { content in content.camera = .spatialTracking let item = ModelEntity(mesh: .generateBox(size: 0.25), materials: [SimpleMaterial()]) anchor.addChild(item) content.add(anchor) anchor.position.z = -1.0 anchor.orientation = .init(angle: .pi/4, axis:[0,1,1]) } } } credits for this solution goes to Andy Jazz The only issue about this is that the Entity on the left view is bit bigger aor to be precise it is more near than the one on the right I guess it is a bug so I did report it in a separate post and I will raise an issue to apple about it .
Nov ’24
Reply to Znear For RealityView to prevent Entity from Hiding an attachment SwiftUI Button in VisionOS
Thanks @Vision Pro Engineer for your reply, in fact I was always working with this method to use entity as a dashboard but I never knew there was a sort command like this, thanx again, Still I would recommend this action be also available for the Attachments because it is more easy to create as a buttons and monitors in games than to build it as 3d entities and also it takes very less memory than an entity dashboard so I would go for a recommend this to be added for the future versions of VisionOS, About the HIG I would really love to follow and not attach anything to the user head but it would be bit hard for an adventure games which the user need to go from a 3d place to another and imagine if he would like to check his life meter or score or click a button, I think it is not that bad to have a small items on the edge of the user view which is essential for some games like that. but anyway that was great answer and very perfect. P.S. I Have Added the Feedback as you suggested hoping it would be added to the next VisionOS Version and here is the feedback number: FB15257742 and here is the link to it https://feedbackassistant.apple.com/feedback/15257742
Sep ’24
Reply to Indicator of how much time left to fully load a RealityKit 3d Model
Thanx @Vision Pro Engineer Michael, I did follow your suggestion and filed a feedback report that apple may add this for the users to know the progress of loading the big 3d Models so far I guess most of the progress bars I have seen in other apps are dummy and not really accurately showing the loading progress of the model rather a timer with some random values or a timer with a delay bar evaluated by the developer him self and it might be different on the user real device.
Sep ’24
Reply to How can I reverse USDZ animation in realityKit
Thanks to @helpingtiger I could edit my code and make it possible to reverse the animation , and here is the edited working code import SwiftUI import RealityKit struct ImmersiveView: View { @State var entity = Entity() @State var openDoor: Bool = true var body: some View { RealityView { content in if let mainDoor = try? await Entity(named: "Door.usdz") { if let frame = mainDoor.findEntity(named: "DoorFrame") { frame.position = [0, 0, -8] frame.orientation = simd_quatf(angle: (270 * (.pi / 180)), axis: SIMD3(x: 1, y: 0, z: 0)) content.add(frame) entity = frame.findEntity(named: "Door")! entity.components.set(InputTargetComponent(allowedInputTypes: .indirect)) entity.components.set(HoverEffectComponent()) let entityModel = entity.children[0] entityModel.generateCollisionShapes(recursive: true) } } } .gesture( SpatialTapGesture() .targetedToEntity(entity) .onEnded { value in print(value) if openDoor == true { var playerDefinition = entity.availableAnimations[0].definition playerDefinition.speed = 1 playerDefinition.repeatMode = .none playerDefinition.trimDuration = 0 let playerAnimation = try! AnimationResource.generate(with: playerDefinition) entity.playAnimation(playerAnimation) openDoor = false } else { var playerDefinition = entity.availableAnimations[0].definition playerDefinition.speed = -1 playerDefinition.repeatMode = .none playerDefinition.trimDuration = 0 let playerAnimation = try! AnimationResource.generate(with: playerDefinition) entity.playAnimation(playerAnimation) openDoor = true } } ) } }
Mar ’24
Reply to How can I reverse USDZ animation in realityKit
As I expected In visionOS 1.1, the AnimationPlaybackController object is still not able to play back a reverse asset animation, as it was in iOS RealityKit. in iOS RealityKit you could reverse the animation by simply give speed negative value like -1 but if you try it in visionOS RealityKit it would stop the animation totally as you give a speed = 0 , the workaround so far is a bi complicated by making 2 animations one forward and the other reverse and apply each when needed. Hopefully Apply would resolve this issue in the next version of visionOS.
Feb ’24
Reply to If a USDZ file can play multiple animations?
Put the new animation in a separate USDZ file and load it to the code then apply each when needed on the desired entity, which should be identical to the entity that have the external animation. import SwiftUI import RealityKit struct ImmersiveView: View { @State var entity = Entity() @State var extEntity = Entity() var body: some View { RealityView { content in //Loading Main USDZ With Main Animation And Link it let mainAnim = try! await Entity(named: "main.usdz") if let item = mainAnim.findEntity(named: "SOME ENTITY") { entity = item // The Entity of the object you want to animate content.add(entity) } //Loading External Animation And Link it let extAnim = try! await Entity(named: "external.usdz") if let item = extAnim.findEntity(named: "SOME ENTITY") { externalEntity = item // The Entity Of the Object have the external Animation } Then somewhere in your code when you want to apply the external animation func playExtraAnimation() { entity.playAnimation(extEntity.availableAnimations[0], transitionDuration: duration , startsPaused: true) }
Feb ’24
Reply to A Game Controller For visionOS RealityView
I figure it out myself import SwiftUI import RealityKit import GameController struct ImmersiveView: View { @State var entity = ModelEntity() @State var z: Float = -4.0 @State var connected = false @State var controller = GCController() var body: some View { RealityView { content in if let cube = try? await ModelEntity(named: "am.usdz") { entity = cube entity.generateCollisionShapes(recursive: true) entity.name = "Cube" entity.position = [0, 0, -4] entity.components.set(InputTargetComponent(allowedInputTypes: .indirect)) entity.components.set(HoverEffectComponent()) content.add(entity) } } .gesture( SpatialTapGesture() .targetedToEntity(entity) .onEnded { value in print(value) z -= 1.0 entity.position = [0, 0, z] } ) .onAppear(perform: { // Start Using The Game Controller NotificationCenter.default.addObserver(forName: NSNotification.Name.GCControllerDidConnect, object: nil, queue: nil, using: didConnectController) NotificationCenter.default.addObserver(forName: NSNotification.Name.GCControllerDidDisconnect, object: nil, queue: nil, using: didDisconnectController) GCController.startWirelessControllerDiscovery{} }) } func didConnectController(_ notification: Notification) { connected = true controller = notification.object as! GCController print("◦ connected \(controller.productCategory)") controller.extendedGamepad?.buttonA.pressedChangedHandler = { (button, value, pressed) in self.button("X", pressed)} } func didDisconnectController(_ notification: Notification) { connected = false controller = notification.object as! GCController print("◦ disConnected \(controller.productCategory)") } func button(_ button: String, _ pressed: Bool){ if button == "X" && pressed { z -= 1.0 entity.position = [0, 0, z] } } }
Feb ’24
Reply to Xcode, Fold group of codes under certain method/ function with a simple click
Sorry I may have not expressed the question well, I'm not asking about this certain code, this codes are just a generic sample and it could be anything else, I'm asking about if this possible or not in Xcode cause so far until Xcode 14.3 it does not seem to happen and it is as simple as fold all Childs under one parent or fold all selected only ,may be apple could notice that and may be like to add it on the next update cause it really helps specially for 3D Physics Collision with different actions.
Apr ’23
Reply to Xcode watchOS 9 runtime issue
After Long time Of many repeated downloads of the simulators and delete the old one from settings I got the right solution According To Apple Xcode 14 Release Notes There was this issue: It Seems If you manually unmount or detach a simulator runtime disk image (such as by using diskutil eject or umount), Simulator and Xcode may not be able to determine whether the runtime is installed or not. Attempts to re-download the runtime results in failure with a duplicate runtime error. (89589210) Workaround: Restarting causes Simulator to re-mount the runtime disk image. But this might not work so I Open Terminal And Remount The Images Manually Using this Command xcrun simctl runtime add Alternately you can use xcrun simctl runtime to locate the affected runtime disk image, delete it, then use Xcode to re-download it.
Nov ’22
Reply to Xcode crash when importing Collada file
Although this answer may be delayed as I had this problem with Xcode 13.2 but my reason was My DAE file is large that even my M1 Latest Macbook cannot handle it on Xcode but I found the solution by using terminal command scntool xcrun scntool --convert INPUT.dae --format scn --output OUT.scn --asset-catalog-path . here is a complete answer for this problem Convert Large DAE to SCN Using Terminal You need: Xcode To Be Installed On Your Mac Now Open Terminal 1- Set The scntool to be Called From Anywhere  export PATH="/Applications/Xcode.app/Contents/Developer/usr/bin" Note : you can ignore last line is you add xcrun before scntool Example   xcrun scntool --convert INPUT.dae --format scn --output OUT.scn --asset-catalog-path . 2- Change Your Directory To where The DAE and The Resources are My Folder named Export cd THE_LOCATION_OF_YOUR_DAE_FILE Example cd /Users/YOURHOME/Desktop/Export 3- Use scntool to convert it like that (INPUT and OUTPUT is names of the file) The dot at the end of the command line is very important it means you will set resources to same location  scntool --convert INPUT.dae --format scn --output OUT.scn --asset-catalog-path . Or if you do not set scntool default path   xcrun scntool --convert INPUT.dae --format scn --output OUT.scn --asset-catalog-path . Example: scntool --convert ISS.dae --format scn --output ISS.scn --asset-catalog-path . If you don’t set the —asset-catalog-path . You will have no materials  By comparing 2 Output files, one with correct conversion and the other without  You will notice a missing line “path”, this line “path”, tells the SCN file to search the materials in the correct location  Mistaken Out.scn }, { "$class" = :false; NS.keys = ( :false ); NS.objects = ( :false ); }, "AMS02Coil.png", { "$classes" = ( "NSMutableDictionary", "NSDictionary", "NSObject" ); "$classname" = "NSMutableDictionary"; }, Correct Out.scn File }, { "$class" = :false; NS.keys = ( :false ); NS.objects = ( :false ); }, "path", "AMS02Coil.png", { "$classes" = ( "NSMutableDictionary", "NSDictionary", "NSObject" ); "$classname" = "NSMutableDictionary"; }, Here is a List Of scntool Command Options (I Got It From This Location  https://gist.github.com/matux/4a30c4b4b29d636fe6847b6a3234bc4f) $ xcrun scntool --verbose | Current SceneKit version is 4.560000 | Running scntool (compiled on Jul  1 2018 01:01:55) usage: scntool --convert file --format format [--output file] --convert: File to convert. Formats found to be supported: com.apple.scenekit.scene (scn), com.apple.scenekit.scene.zip (scnz), com.apple.scenekit.particlesystem (.scnp), org.khronos.collada.digital-asset-exchange (.dae), c3d, bplist --format: Format to convert to. Formats found to be supported: scn, c3d, dae. --output: Destination path and filename. -c (--compress) -d (--decompress) --uncompress --copy --target-platform= --target-version= --target-build-dir= --asset-catalog-path --resources-path-prefix --resources-folder-path= --force-y-up: Some documents use different up axis. When enabled, objects in a scene are converted to the Y-up orientation. --force-interleaved: Because most geometries use more than one geometry source and the GPU typically uses data from multiple sources together, you can achieve better rendering performance for custom geometries by interleaving the vertex data for multiple semantics in the same array. --prefer-compressed-textures: Use this option to prefer KTX, ASTC and PVRTC to other file formats. When enabled, if an image is referenced by a scene and exists within the asset catalog with the same name and the .astc or .pvrtc file extension, the compressed version will be used by SceneKit. --verbose: Always use verbose to get pretty error messages. With --verbose: scntool: error: No file at path /path/to/model/file.scn Same error, without --verbose:
Jul ’22
Reply to Convert dae to scn at runtime in iOS
To Convert DAE to SCN Using Terminal You need: Xcode To Be Installed On Your Mac, You Don't Need to Run It we gonna use scntool command line from Xcode app Now Open Terminal 1- Set The scntool to be Called From Anywhere  export PATH="/Applications/Xcode.app/Contents/Developer/usr/bin" 2- Change Your Directory To where The DAE and The Resources are My Folder named Export cd THE_LOCATION_OF_YOUR_DAE_FILE Example cd /Users/YOURHOME/Desktop/Export 3- Use scntool to convert it like that (INPUT and OUTPUT is names of the file) The dot at the end of the command line is very important it means you will set resources to same location  scntool --convert INPUT.dae --format scn --output OUT.scn --asset-catalog-path . Example: scntool --convert ISS.dae --format scn --output ISS.scn --asset-catalog-path . If you don’t set the —asset-catalog-path . You will have no materials  By comparing 2 Output files, one with correct conversion and the other without  You will notice a missing line “path”, this line “path”, tells the SCN file to search the materials in the correct location  Mistaken Out.scn }, { "$class" = :false; NS.keys = ( :false ); NS.objects = ( :false ); }, "AMS02Coil.png", { "$classes" = ( "NSMutableDictionary", "NSDictionary", "NSObject" ); "$classname" = "NSMutableDictionary"; }, Correct Out.scn File }, { "$class" = :false; NS.keys = ( :false ); NS.objects = ( :false ); }, "path", "AMS02Coil.png", { "$classes" = ( "NSMutableDictionary", "NSDictionary", "NSObject" ); "$classname" = "NSMutableDictionary"; }, List Of scntool Command Options (I Got It From This Location  https://gist.github.com/matux/4a30c4b4b29d636fe6847b6a3234bc4f) $ xcrun scntool --verbose | Current SceneKit version is 4.560000 | Running scntool (compiled on Jul  1 2018 01:01:55) usage: scntool --convert file --format format [--output file] --convert: File to convert. Formats found to be supported: com.apple.scenekit.scene (scn), com.apple.scenekit.scene.zip (scnz), com.apple.scenekit.particlesystem (.scnp), org.khronos.collada.digital-asset-exchange (.dae), c3d, bplist --format: Format to convert to. Formats found to be supported: scn, c3d, dae. --output: Destination path and filename. -c (--compress) -d (--decompress) --uncompress --copy --target-platform= --target-version= --target-build-dir= --asset-catalog-path --resources-path-prefix --resources-folder-path= --force-y-up: Some documents use different up axis. When enabled, objects in a scene are converted to the Y-up orientation. --force-interleaved: Because most geometries use more than one geometry source and the GPU typically uses data from multiple sources together, you can achieve better rendering performance for custom geometries by interleaving the vertex data for multiple semantics in the same array. --prefer-compressed-textures: Use this option to prefer KTX, ASTC and PVRTC to other file formats. When enabled, if an image is referenced by a scene and exists within the asset catalog with the same name and the .astc or .pvrtc file extension, the compressed version will be used by SceneKit. --verbose: Always use verbose to get pretty error messages. With --verbose: scntool: error: No file at path /path/to/model/file.scn Same error, without --verbose:
Jul ’22