SceneKit

RSS for tag

Create 3D games and add 3D content to apps using high-level scene descriptions using SceneKit.

Posts under SceneKit tag

200 Posts

Post

Replies

Boosts

Views

Activity

PhysicsShape moved when I add a mass to my character
Hello I try to understand the movement of a character with physics. To do this, I imported max into the fox2 file provided by Apple. I apply a .static physics to it and I have a floor with static physics and static blocks to test collisions everything works very well except that Max is above the ground. He doesn't touch my ground. I couldn't understand why until I had the physicsShapes displayed in the debug options. With that I see that if max does not touch the ground it is because the automatic shape is below Max and this shape touches the ground. So I would like to know why the shape is shifted downwards and how to correct this problem? I did tests and the problem seems to come from physicsBody?.mass. If I remove the mass, the shape is correct but when I move my character it crosses the walls and when I put it on it is well stopped by the static boxes... Someone with an idea of how to correct this problem? This is my simplify code import SceneKit import PlaygroundSupport // create a scene view with an empty scene var sceneView = SCNView(frame: CGRect(x: 0, y: 0, width: 300, height: 300)) var scene = SCNScene() sceneView.scene = scene // start a live preview of that view PlaygroundPage.current.liveView = sceneView // default lighting sceneView.autoenablesDefaultLighting = true sceneView.allowsCameraControl = true sceneView.debugOptions = [.showPhysicsShapes] // a camera var cameraNode = SCNNode() cameraNode.camera = SCNCamera() cameraNode.position = SCNVector3(x: 0, y: 0, z: 3) scene.rootNode.addChildNode(cameraNode) // Make floor node let floorNode = SCNNode() let floor = SCNFloor() floor.reflectivity = 0.25 floorNode.geometry = floor floorNode.physicsBody = SCNPhysicsBody(type: .static, shape: nil) scene.rootNode.addChildNode(floorNode) //add character guard let fichier = SCNScene(named: "max.scn") else { fatalError("failed to load Max.scn") } guard let character = fichier.rootNode.childNode(withName: "Max_rootNode", recursively: true) else { fatalError("Failed to find Max_rootNode") } scene.rootNode.addChildNode(character) character.position = SCNVector3(0, 0, 0) character.physicsBody = SCNPhysicsBody(type: .static, shape: nil) character.physicsBody?.mass = 5 Thank you!
0
0
856
Jun ’23
Xcode, 3D obj doesn't show up in Simulator
Hi everybody, I am an Engineering Student and at the University we have to create a little AR-App. Now, in Xcode I want to make an Image Tracking and above that Image, it should show my 3D Object. I followed this Video: "https://www.youtube.com/watch?v=VmPHE8M2GZI" until the minute 39:18. After that, it doesnt work. The simulator detects the Image and shows a light grey Plane above it, even if I move around. But the 3D Model doesn't show up. I imported the ns.obj file in art.scnassets Converted to SceneKit file .scn changed the texture "diffusion" to green I tried to scale it, but still no result I tried also with an 3D Object downloaded from the internet Long Story short.... it doesn't work. Does anyone knows what the Problem could be? Thank you very much. Greetings, Rosario PS: I use the Xcode Version 14.3. Thats my code in the ViewController.swift file: import SwiftUI import RealityKit import UIKit import SceneKit import ARKit class ViewController: UIViewController, ARSCNViewDelegate { @IBOutlet var sceneView: ARSCNView! var nsNode: SCNNode? override func viewDidLoad() { super.viewDidLoad() sceneView.delegate = self sceneView.autoenablesDefaultLighting = true let nsScene = SCNScene(named: "art.scnassets/ns.scn") nsNode = nsScene?.rootNode } override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) let configuration = ARImageTrackingConfiguration() if let trackingImages = ARReferenceImage.referenceImages(inGroupNamed: "AR Resources", bundle: Bundle.main) { configuration.trackingImages = trackingImages configuration.maximumNumberOfTrackedImages = 2 } sceneView.session.run(configuration) } override func viewWillDisappear(_ animated: Bool) { super.viewWillDisappear(animated) sceneView.session.pause() } func renderer(_ renderer: SCNSceneRenderer, nodeFor anchor: ARAnchor) -> SCNNode? { let node = SCNNode() if let imageAnchor = anchor as? ARImageAnchor { let size = imageAnchor.referenceImage.physicalSize let plane = SCNPlane(width: size.width, height: size.height) plane.firstMaterial?.diffuse.contents = UIColor.white.withAlphaComponent(0.5) plane.cornerRadius = 0.005 let planeNode = SCNNode(geometry: plane) planeNode.eulerAngles.x = -.pi / 2 node.addChildNode(planeNode) if let shapeNode = nsNode { node.addChildNode(shapeNode) } } return node } }
1
0
1.1k
May ’23
SceneKit.write to DAE(Collada) format output binary file instead of Collada XML
I am using Scenekit.write method to export a scene data to DAE(Collada) format. File is exported correctly but it's not a collada XML file rather a binary file. With more investigation I found an Apple binary pList file, And while renaming it's extension to pList, I can view geometry data as standard plist. This file is opening in XCode but not in any other DAE viewer. I am on Xcode 14.3 and IOS 16.
0
0
519
May ’23
Accessing SubViews in SwiftUI, as seen in UIKit
Is there a way to mimic this functionality found in UIKit in SwiftUI? Long story short, I am creating an interactive SceneKit view (currently in UIKit) that anchors 2D UIViews over nodes, for navigation and labelling. I would like to migrate over to SwiftUI, but I am having difficulties mimicking this functionality. let subViews = self.view.subviews.compactMap{$0 as? UIButton} if let view = subViews.first(where: {$0.currentTitle == label}) { view.center = self.getScreenPoint(renderer: renderer, node: node) } Can anyone help me with this? Thanks!
1
1
1.7k
Apr ’23
Exporting DAE animations for Scenekit
I checked out the FOX2 example for Scenekit that showcases the new animation protocol. I was rooting around in the character files trying todiscover how they were organizned, and noticed that the following files had no geometry only the rig for the animation and hence the animationdata as well.These are the files that I'm referring to:•max_idle.sc•max_jump.scn•max_spin.scnHow were these created and exported for Scenekit and with which exporter? Maya, Max, C4D? OpenCollada?What are the recommended settings? How do you export just rigs and animation data for Scenekit without the model? A shoutout to the Scenkit dev team: you guys are creating an amazing game engine(thank you), it's well organized and easy to use.However but you're neglecting a very important aspect. There are no tutorials on how to export authored content files(modles with rigs and animation) for Scenekit. This is super important information, and without putting some more thought into how to teach people how to do this, your framework will continue to see very little adoption.Please, please begin to address this. With ARKit combined with Scenekit you have good chance of seeing many people use this framework.
12
1
12k
Apr ’23
RoomPlan API
I am using RoomPlan API in my application. Working fine for small apartments but when I am trying to scan a bigger apartment which takes more time greater than 15 minutes the API automatically stopped and finished the scan even though part of the apartment is still pending scanning. I need the original structure like a point cloud in 3D, the USDZ model has a white mesh structure. Is there any way to get a real 3D view from RoomPlan API or USDZ model. How I can change the colour of scanning lines. I am getting RSFloorPlan class value when scanning finished. How I can get this Floor Plan, I mean I need its 2d structure as we what we are scanning. Thanks! Ramneet Singh (iOS developer)
2
1
2.5k
Apr ’23
SwiftUI version of centring multiple subviews at once, as seen in UIKit (SCNSceneRendererDelegate)
I have been using UIKit to build out a relatively complex SceneKit scene with 2D labels that are being composed over nodes in the scene. I am using the following to fetch the subview 'names' and projecting their 3D position as a 2D point, and then setting the centre of the label views as this point. Code is below: Project point: let projectedPoint = renderer.projectPoint(node.position) let screenPoint = CGPoint(x: CGFloat(projectedPoint.x), y: CGFloat(projectedPoint.y)) return screenPoint Absolute position update: viewTest.center = self.getScreenPoint(renderer: renderer, node: node) What is the SwiftUI version of this approach? I have used a published array containing all CGPoints, but it lags and becomes non-responsive after a few seconds of interactions. Thank you - happy to share more code is needed!
0
0
631
Apr ’23
SceneKit in XCode
Hello, I am developing a swift playground using XCode for the Swift Student Challenge and in my playground I will have a 3d scene. I opened a project that uses SceneKit from a previous year and used it to learn the program and everything works great in it. However, when I open a project and do everything from scratch (the code is exactly the same) the 3d scene does not appear. Is there an extra configuration that SceneKit needs? Thank you
2
0
873
Apr ’23
Creating Floor Plan with RoomPlan
Hi, I am trying to create a 2D floor plan from the 3D model that RoomPlan creates. This was a FAQ in the augmented-reality Apple Slack channel and the answer given was "RoomPlan outputs a 3D floor plan. You may set the z-coordinate to 0, which will flatten it and thus give you a 2D top-down floor plan." Does anyone know what this z-coordinate is and how to change it? Thank you
6
0
3.0k
Mar ’23
Crash inside SceneKit [SCNPhysicsField _removeOwner]
I'm seeing a decent number of crash reports from our app where SceneKit is crashing internally relating to SCNPhysicsField. The stack looks like: objc_msgSend -[SCNPhysicsField _removeOwner] -[SCNNode dealloc] AutoreleasePoolPage::releaseUntil(objc_object**) -[UIApplication _run] UIApplicationMain main start It must be that I am removing a node that has a physics field on it and it randomly crashes. Probably threading related? Anyone know if there is a workaround, maybe setting physicsField to nil first before trying to remove the node? Thanks
2
0
1.6k
Mar ’23
SCNScene(named: "art.scnassets/diceCollada_copy.scn") return nil and fatal error
The file path is the same and the target is set. But I keep getting errors. Please help me guard let scene = SCNScene(named: "art.scnassets/diceCollada_copy.scn") else { fatalError() return } Error 2023-03-28 08:56:55.650242+0900 ARDicee[42923:11318833] [SceneConfiguration] Info.plist contained no UIScene configuration dictionary (looking for configuration named "(no name)") 2023-03-28 08:56:55.660247+0900 ARDicee[42923:11318833] Metal GPU Frame Capture Enabled 2023-03-28 08:56:55.660395+0900 ARDicee[42923:11318833] Metal API Validation Enabled ARDicee/ViewController.swift:56: Fatal error 2023-03-28 08:56:55.768975+0900 ARDicee[42923:11318833] ARDicee/ViewController.swift:56: Fatal error
0
0
797
Mar ’23
Unable to render a point cloud in my SwiftUI app
The project is building without any errors or warnings and when I run the app I'm able to see the camera view. But when I click on the start scanning button the camera view freezes and nothing happens. It is supposed to start plotting red points in the environment when I tap the start scanning button and when I tap the stop scanning button it should direct me to another screen to display the point cloud itself. The following are the different files in my project. Please let me know what I'm doing incorrectly. ContentView.swift import AVFoundation import ARKit import RealityKit import SceneKit import SwiftUI import Foundation struct ContentView: View { @StateObject var scanner = ScannerViewController() var body: some View { NavigationView { VStack { ARViewContainer().edgesIgnoringSafeArea(.all) HStack { Spacer() Button(action: { scanner.startScanning() }, label: { Text("Start Scanning") }) .padding() Spacer() NavigationLink(destination: PointCloudView(pointCloud: scanner.pointCloud, pointSize: 5.0)) { Text("Stop Scanning") } .padding() Spacer() } } .navigationBarTitle(Text("Scan an Object")) } } struct ARViewContainer: UIViewRepresentable { func makeUIView(context: Context) -> ARView { let arView = ARView(frame: .zero) return arView } func updateUIView(_ uiView: ARView, context: Context) { } } } PointCloudView.swift import AVFoundation import ARKit import RealityKit import SceneKit import SwiftUI import Foundation struct PointCloudView: View { var pointCloud: [SIMD3<Float>] var pointSize: CGFloat var body: some View { ZStack { ForEach(pointCloud, id: \.self) { point in Sphere() .frame(width: pointSize, height: pointSize, alignment: .center) .position(CGPoint(x: CGFloat(point.x), y: CGFloat(point.y))) .foregroundColor(.red) } } } } struct Sphere: Shape { func path(in rect: CGRect) -> Path { let center = CGPoint(x: rect.width / 2, y: rect.height / 2) let radius = min(rect.width, rect.height) / 2 let path = Path { p in p.addArc(center: center, radius: radius, startAngle: .zero, endAngle: .degrees(360), clockwise: true) } return path } } ScannerViewController.swift import AVFoundation import ARKit import RealityKit import SceneKit import SwiftUI import Combine import Foundation class ScannerViewController: NSObject, ObservableObject { private var cancellables = Set<AnyCancellable>() @Published var isScanning = false @Published var pointCloud: [SIMD3<Float>] = [] private let arSession = ARSession() private var arConfiguration: ARConfiguration { let configuration = ARWorldTrackingConfiguration() configuration.planeDetection = .horizontal configuration.environmentTexturing = .automatic return configuration } func startScanning() { print("started scanning") isScanning = true arSession.run(arConfiguration) } func stopScanning() { print("stopped scanning") isScanning = false arSession.pause() } func renderer(_ renderer: SCNSceneRenderer, updateAtTime time: TimeInterval) { print("continusoyl called") guard isScanning else { return } // Get the current ARFrame guard let currentFrame = self.arSession.currentFrame else { return } // Generate the point cloud data from the ARFrame guard let pointCloud = currentFrame.rawFeaturePoints?.points else { return } // Convert the point cloud data to a format that can be displayed in the PointCloudView let convertedPointCloud = pointCloud.map { point in SIMD3<Float>(point.x, point.y, point.z) } // Pass the converted point cloud data to the PointCloudView DispatchQueue.main.async { self.pointCloud = convertedPointCloud } } } I've tried using both SceneKit and Metal to render the point cloud and referred to apple's documentation: https://developer.apple.com/documentation/arkit/environmental_analysis/displaying_a_point_cloud_using_scene_depth I've also tried building a storyboard project but storyboard and SceneKit have been creating a lot of errors. Using metal and swiftui builds without errors at the very least but still doesn't function.
1
0
882
Mar ’23
WKInterfaceSCNScene works fine on simulator, but delayed start on watch
I have a fairly simple WKInterfaceSCNScene in my Apple Watch app (the SCNScene contains only: camera, floor, cylinder). It runs a ~3-second animation. It works terrific on the simulator, but when I run it on my actual watch (series 7), it delays for about 6 seconds, then the animation displays properly. Is the watch's processor so much slower than the simulator on my laptop? I could probably deal with a 0.5 second delay, but 6 seconds? Thoughts?
1
0
1.1k
Mar ’23
Glb to USDZ losing normals
Hello, When I try to convert glb containing shape keys, I am losing normals in geometry sources. I need those shape keys so Is there a way to keep normals while keeping shape keys. Is there a problem with reality converter? the glb file: https://drive.google.com/file/d/17F5vIymfCJSy9zP9dI3oHcVcP8_5CWjd/view?usp=sharing the usdz file, created by reality converter: (https://drive.google.com/file/d/18AVnotD2_8UJvf1KpmK9Gw_oldRvlmIS/view) for visiual representation:
1
1
1.6k
Mar ’23
Pass interpolated values to SceneKit Fragment Shader
I have a SceneKit fragment shader where I need to make some decisions about the alpha value based on an interpolated value between the vertexes. At each vertex there is a value and I need to know what the interpolated value for the given position that the fragment shader is determining the color for. Is there a way to do this? This is what my shader looks like. #pragma arguments float myInterpolatedVlaue; #pragma transparent #pragma body //Sample logic.  The actual logic has more too it. if (myInterpolatedVlaue > 1.0 ) {     _output.color.a = 0; } I want to set a value at each vertex and then get the interpolated value in my fragment shader. I would like to have myInterpolatedVlaue be set based on the interpolated values from the value at each vertex.
1
0
908
Mar ’23
PhysicsShape moved when I add a mass to my character
Hello I try to understand the movement of a character with physics. To do this, I imported max into the fox2 file provided by Apple. I apply a .static physics to it and I have a floor with static physics and static blocks to test collisions everything works very well except that Max is above the ground. He doesn't touch my ground. I couldn't understand why until I had the physicsShapes displayed in the debug options. With that I see that if max does not touch the ground it is because the automatic shape is below Max and this shape touches the ground. So I would like to know why the shape is shifted downwards and how to correct this problem? I did tests and the problem seems to come from physicsBody?.mass. If I remove the mass, the shape is correct but when I move my character it crosses the walls and when I put it on it is well stopped by the static boxes... Someone with an idea of how to correct this problem? This is my simplify code import SceneKit import PlaygroundSupport // create a scene view with an empty scene var sceneView = SCNView(frame: CGRect(x: 0, y: 0, width: 300, height: 300)) var scene = SCNScene() sceneView.scene = scene // start a live preview of that view PlaygroundPage.current.liveView = sceneView // default lighting sceneView.autoenablesDefaultLighting = true sceneView.allowsCameraControl = true sceneView.debugOptions = [.showPhysicsShapes] // a camera var cameraNode = SCNNode() cameraNode.camera = SCNCamera() cameraNode.position = SCNVector3(x: 0, y: 0, z: 3) scene.rootNode.addChildNode(cameraNode) // Make floor node let floorNode = SCNNode() let floor = SCNFloor() floor.reflectivity = 0.25 floorNode.geometry = floor floorNode.physicsBody = SCNPhysicsBody(type: .static, shape: nil) scene.rootNode.addChildNode(floorNode) //add character guard let fichier = SCNScene(named: "max.scn") else { fatalError("failed to load Max.scn") } guard let character = fichier.rootNode.childNode(withName: "Max_rootNode", recursively: true) else { fatalError("Failed to find Max_rootNode") } scene.rootNode.addChildNode(character) character.position = SCNVector3(0, 0, 0) character.physicsBody = SCNPhysicsBody(type: .static, shape: nil) character.physicsBody?.mass = 5 Thank you!
Replies
0
Boosts
0
Views
856
Activity
Jun ’23
Can you use SceneKit with SwiftUI for spatial experiences
I’m wondering if it’s possible to use SceneKit or GamePlayKit to handle physics etc and having SwiftUI to create the 3D content?
Replies
0
Boosts
1
Views
1.3k
Activity
Jun ’23
visionOS and support for SceneKit
I am creating an AR app that uses ARKit and SceneKit. Will visionOS support SceneKit AR applications, or will I have to rewrite my app using RealityKit? Thanks for answering my question. : - )
Replies
1
Boosts
2
Views
1.4k
Activity
Jun ’23
Xcode, 3D obj doesn't show up in Simulator
Hi everybody, I am an Engineering Student and at the University we have to create a little AR-App. Now, in Xcode I want to make an Image Tracking and above that Image, it should show my 3D Object. I followed this Video: "https://www.youtube.com/watch?v=VmPHE8M2GZI" until the minute 39:18. After that, it doesnt work. The simulator detects the Image and shows a light grey Plane above it, even if I move around. But the 3D Model doesn't show up. I imported the ns.obj file in art.scnassets Converted to SceneKit file .scn changed the texture "diffusion" to green I tried to scale it, but still no result I tried also with an 3D Object downloaded from the internet Long Story short.... it doesn't work. Does anyone knows what the Problem could be? Thank you very much. Greetings, Rosario PS: I use the Xcode Version 14.3. Thats my code in the ViewController.swift file: import SwiftUI import RealityKit import UIKit import SceneKit import ARKit class ViewController: UIViewController, ARSCNViewDelegate { @IBOutlet var sceneView: ARSCNView! var nsNode: SCNNode? override func viewDidLoad() { super.viewDidLoad() sceneView.delegate = self sceneView.autoenablesDefaultLighting = true let nsScene = SCNScene(named: "art.scnassets/ns.scn") nsNode = nsScene?.rootNode } override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) let configuration = ARImageTrackingConfiguration() if let trackingImages = ARReferenceImage.referenceImages(inGroupNamed: "AR Resources", bundle: Bundle.main) { configuration.trackingImages = trackingImages configuration.maximumNumberOfTrackedImages = 2 } sceneView.session.run(configuration) } override func viewWillDisappear(_ animated: Bool) { super.viewWillDisappear(animated) sceneView.session.pause() } func renderer(_ renderer: SCNSceneRenderer, nodeFor anchor: ARAnchor) -> SCNNode? { let node = SCNNode() if let imageAnchor = anchor as? ARImageAnchor { let size = imageAnchor.referenceImage.physicalSize let plane = SCNPlane(width: size.width, height: size.height) plane.firstMaterial?.diffuse.contents = UIColor.white.withAlphaComponent(0.5) plane.cornerRadius = 0.005 let planeNode = SCNNode(geometry: plane) planeNode.eulerAngles.x = -.pi / 2 node.addChildNode(planeNode) if let shapeNode = nsNode { node.addChildNode(shapeNode) } } return node } }
Replies
1
Boosts
0
Views
1.1k
Activity
May ’23
SceneKit.write to DAE(Collada) format output binary file instead of Collada XML
I am using Scenekit.write method to export a scene data to DAE(Collada) format. File is exported correctly but it's not a collada XML file rather a binary file. With more investigation I found an Apple binary pList file, And while renaming it's extension to pList, I can view geometry data as standard plist. This file is opening in XCode but not in any other DAE viewer. I am on Xcode 14.3 and IOS 16.
Replies
0
Boosts
0
Views
519
Activity
May ’23
Accessing SubViews in SwiftUI, as seen in UIKit
Is there a way to mimic this functionality found in UIKit in SwiftUI? Long story short, I am creating an interactive SceneKit view (currently in UIKit) that anchors 2D UIViews over nodes, for navigation and labelling. I would like to migrate over to SwiftUI, but I am having difficulties mimicking this functionality. let subViews = self.view.subviews.compactMap{$0 as? UIButton} if let view = subViews.first(where: {$0.currentTitle == label}) { view.center = self.getScreenPoint(renderer: renderer, node: node) } Can anyone help me with this? Thanks!
Replies
1
Boosts
1
Views
1.7k
Activity
Apr ’23
Exporting DAE animations for Scenekit
I checked out the FOX2 example for Scenekit that showcases the new animation protocol. I was rooting around in the character files trying todiscover how they were organizned, and noticed that the following files had no geometry only the rig for the animation and hence the animationdata as well.These are the files that I'm referring to:•max_idle.sc•max_jump.scn•max_spin.scnHow were these created and exported for Scenekit and with which exporter? Maya, Max, C4D? OpenCollada?What are the recommended settings? How do you export just rigs and animation data for Scenekit without the model? A shoutout to the Scenkit dev team: you guys are creating an amazing game engine(thank you), it's well organized and easy to use.However but you're neglecting a very important aspect. There are no tutorials on how to export authored content files(modles with rigs and animation) for Scenekit. This is super important information, and without putting some more thought into how to teach people how to do this, your framework will continue to see very little adoption.Please, please begin to address this. With ARKit combined with Scenekit you have good chance of seeing many people use this framework.
Replies
12
Boosts
1
Views
12k
Activity
Apr ’23
RoomPlan API
I am using RoomPlan API in my application. Working fine for small apartments but when I am trying to scan a bigger apartment which takes more time greater than 15 minutes the API automatically stopped and finished the scan even though part of the apartment is still pending scanning. I need the original structure like a point cloud in 3D, the USDZ model has a white mesh structure. Is there any way to get a real 3D view from RoomPlan API or USDZ model. How I can change the colour of scanning lines. I am getting RSFloorPlan class value when scanning finished. How I can get this Floor Plan, I mean I need its 2d structure as we what we are scanning. Thanks! Ramneet Singh (iOS developer)
Replies
2
Boosts
1
Views
2.5k
Activity
Apr ’23
Reloading SceneKit scene after app goes to foreground
Hello, is it good practice to reload SceneKit 3D scene every time app goes to foreground from background? For example when app is for a long time in the background and then it goes to foreground, reload the app, to make sure everything is loaded? Is it necessary in normal circumstances? Thanks, Krzysztof
Replies
0
Boosts
0
Views
542
Activity
Apr ’23
how to draw/Place an arrow shape/annotation in all direction using Two Points, Start point vector and end point vector in SceneKit?
in sceneview how can we draw arrow in all direction using Two Points like Start point vector and end point vector (draw arrow like Up side , Downside , left side up and down, right side up and down ) see attachment for arrow shape
Replies
0
Boosts
0
Views
733
Activity
Apr ’23
SwiftUI version of centring multiple subviews at once, as seen in UIKit (SCNSceneRendererDelegate)
I have been using UIKit to build out a relatively complex SceneKit scene with 2D labels that are being composed over nodes in the scene. I am using the following to fetch the subview 'names' and projecting their 3D position as a 2D point, and then setting the centre of the label views as this point. Code is below: Project point: let projectedPoint = renderer.projectPoint(node.position) let screenPoint = CGPoint(x: CGFloat(projectedPoint.x), y: CGFloat(projectedPoint.y)) return screenPoint Absolute position update: viewTest.center = self.getScreenPoint(renderer: renderer, node: node) What is the SwiftUI version of this approach? I have used a published array containing all CGPoints, but it lags and becomes non-responsive after a few seconds of interactions. Thank you - happy to share more code is needed!
Replies
0
Boosts
0
Views
631
Activity
Apr ’23
SceneKit in XCode
Hello, I am developing a swift playground using XCode for the Swift Student Challenge and in my playground I will have a 3d scene. I opened a project that uses SceneKit from a previous year and used it to learn the program and everything works great in it. However, when I open a project and do everything from scratch (the code is exactly the same) the 3d scene does not appear. Is there an extra configuration that SceneKit needs? Thank you
Replies
2
Boosts
0
Views
873
Activity
Apr ’23
Creating Floor Plan with RoomPlan
Hi, I am trying to create a 2D floor plan from the 3D model that RoomPlan creates. This was a FAQ in the augmented-reality Apple Slack channel and the answer given was "RoomPlan outputs a 3D floor plan. You may set the z-coordinate to 0, which will flatten it and thus give you a 2D top-down floor plan." Does anyone know what this z-coordinate is and how to change it? Thank you
Replies
6
Boosts
0
Views
3.0k
Activity
Mar ’23
Crash inside SceneKit [SCNPhysicsField _removeOwner]
I'm seeing a decent number of crash reports from our app where SceneKit is crashing internally relating to SCNPhysicsField. The stack looks like: objc_msgSend -[SCNPhysicsField _removeOwner] -[SCNNode dealloc] AutoreleasePoolPage::releaseUntil(objc_object**) -[UIApplication _run] UIApplicationMain main start It must be that I am removing a node that has a physics field on it and it randomly crashes. Probably threading related? Anyone know if there is a workaround, maybe setting physicsField to nil first before trying to remove the node? Thanks
Replies
2
Boosts
0
Views
1.6k
Activity
Mar ’23
SCNScene(named: "art.scnassets/diceCollada_copy.scn") return nil and fatal error
The file path is the same and the target is set. But I keep getting errors. Please help me guard let scene = SCNScene(named: "art.scnassets/diceCollada_copy.scn") else { fatalError() return } Error 2023-03-28 08:56:55.650242+0900 ARDicee[42923:11318833] [SceneConfiguration] Info.plist contained no UIScene configuration dictionary (looking for configuration named "(no name)") 2023-03-28 08:56:55.660247+0900 ARDicee[42923:11318833] Metal GPU Frame Capture Enabled 2023-03-28 08:56:55.660395+0900 ARDicee[42923:11318833] Metal API Validation Enabled ARDicee/ViewController.swift:56: Fatal error 2023-03-28 08:56:55.768975+0900 ARDicee[42923:11318833] ARDicee/ViewController.swift:56: Fatal error
Replies
0
Boosts
0
Views
797
Activity
Mar ’23
Unable to render a point cloud in my SwiftUI app
The project is building without any errors or warnings and when I run the app I'm able to see the camera view. But when I click on the start scanning button the camera view freezes and nothing happens. It is supposed to start plotting red points in the environment when I tap the start scanning button and when I tap the stop scanning button it should direct me to another screen to display the point cloud itself. The following are the different files in my project. Please let me know what I'm doing incorrectly. ContentView.swift import AVFoundation import ARKit import RealityKit import SceneKit import SwiftUI import Foundation struct ContentView: View { @StateObject var scanner = ScannerViewController() var body: some View { NavigationView { VStack { ARViewContainer().edgesIgnoringSafeArea(.all) HStack { Spacer() Button(action: { scanner.startScanning() }, label: { Text("Start Scanning") }) .padding() Spacer() NavigationLink(destination: PointCloudView(pointCloud: scanner.pointCloud, pointSize: 5.0)) { Text("Stop Scanning") } .padding() Spacer() } } .navigationBarTitle(Text("Scan an Object")) } } struct ARViewContainer: UIViewRepresentable { func makeUIView(context: Context) -> ARView { let arView = ARView(frame: .zero) return arView } func updateUIView(_ uiView: ARView, context: Context) { } } } PointCloudView.swift import AVFoundation import ARKit import RealityKit import SceneKit import SwiftUI import Foundation struct PointCloudView: View { var pointCloud: [SIMD3<Float>] var pointSize: CGFloat var body: some View { ZStack { ForEach(pointCloud, id: \.self) { point in Sphere() .frame(width: pointSize, height: pointSize, alignment: .center) .position(CGPoint(x: CGFloat(point.x), y: CGFloat(point.y))) .foregroundColor(.red) } } } } struct Sphere: Shape { func path(in rect: CGRect) -> Path { let center = CGPoint(x: rect.width / 2, y: rect.height / 2) let radius = min(rect.width, rect.height) / 2 let path = Path { p in p.addArc(center: center, radius: radius, startAngle: .zero, endAngle: .degrees(360), clockwise: true) } return path } } ScannerViewController.swift import AVFoundation import ARKit import RealityKit import SceneKit import SwiftUI import Combine import Foundation class ScannerViewController: NSObject, ObservableObject { private var cancellables = Set<AnyCancellable>() @Published var isScanning = false @Published var pointCloud: [SIMD3<Float>] = [] private let arSession = ARSession() private var arConfiguration: ARConfiguration { let configuration = ARWorldTrackingConfiguration() configuration.planeDetection = .horizontal configuration.environmentTexturing = .automatic return configuration } func startScanning() { print("started scanning") isScanning = true arSession.run(arConfiguration) } func stopScanning() { print("stopped scanning") isScanning = false arSession.pause() } func renderer(_ renderer: SCNSceneRenderer, updateAtTime time: TimeInterval) { print("continusoyl called") guard isScanning else { return } // Get the current ARFrame guard let currentFrame = self.arSession.currentFrame else { return } // Generate the point cloud data from the ARFrame guard let pointCloud = currentFrame.rawFeaturePoints?.points else { return } // Convert the point cloud data to a format that can be displayed in the PointCloudView let convertedPointCloud = pointCloud.map { point in SIMD3<Float>(point.x, point.y, point.z) } // Pass the converted point cloud data to the PointCloudView DispatchQueue.main.async { self.pointCloud = convertedPointCloud } } } I've tried using both SceneKit and Metal to render the point cloud and referred to apple's documentation: https://developer.apple.com/documentation/arkit/environmental_analysis/displaying_a_point_cloud_using_scene_depth I've also tried building a storyboard project but storyboard and SceneKit have been creating a lot of errors. Using metal and swiftui builds without errors at the very least but still doesn't function.
Replies
1
Boosts
0
Views
882
Activity
Mar ’23
WKInterfaceSCNScene works fine on simulator, but delayed start on watch
I have a fairly simple WKInterfaceSCNScene in my Apple Watch app (the SCNScene contains only: camera, floor, cylinder). It runs a ~3-second animation. It works terrific on the simulator, but when I run it on my actual watch (series 7), it delays for about 6 seconds, then the animation displays properly. Is the watch's processor so much slower than the simulator on my laptop? I could probably deal with a 0.5 second delay, but 6 seconds? Thoughts?
Replies
1
Boosts
0
Views
1.1k
Activity
Mar ’23
Glb to USDZ losing normals
Hello, When I try to convert glb containing shape keys, I am losing normals in geometry sources. I need those shape keys so Is there a way to keep normals while keeping shape keys. Is there a problem with reality converter? the glb file: https://drive.google.com/file/d/17F5vIymfCJSy9zP9dI3oHcVcP8_5CWjd/view?usp=sharing the usdz file, created by reality converter: (https://drive.google.com/file/d/18AVnotD2_8UJvf1KpmK9Gw_oldRvlmIS/view) for visiual representation:
Replies
1
Boosts
1
Views
1.6k
Activity
Mar ’23
Pass interpolated values to SceneKit Fragment Shader
I have a SceneKit fragment shader where I need to make some decisions about the alpha value based on an interpolated value between the vertexes. At each vertex there is a value and I need to know what the interpolated value for the given position that the fragment shader is determining the color for. Is there a way to do this? This is what my shader looks like. #pragma arguments float myInterpolatedVlaue; #pragma transparent #pragma body //Sample logic.  The actual logic has more too it. if (myInterpolatedVlaue > 1.0 ) {     _output.color.a = 0; } I want to set a value at each vertex and then get the interpolated value in my fragment shader. I would like to have myInterpolatedVlaue be set based on the interpolated values from the value at each vertex.
Replies
1
Boosts
0
Views
908
Activity
Mar ’23
ARKit + SceneKit. Scaled triangles appear after applying depth video with alpha channel on SCNPlane
I am using ARKit + SceneKit. After applying depth video with alpha channel on SCNPlane, scaled triangles appear. How to remove these triangles and vertices that remained on the SCNPlane with depth 0.0. Result The video for videotexture
Replies
2
Boosts
1
Views
1.1k
Activity
Mar ’23