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

How I can change material, like diffuse, on 3D model (.usdz or .obj)?
Hi all. I am new to swift and AR. I'm trying a project on AR and ran into a problem that I can't change the material on the models. With geometry such as a sphere or a cube, everything is simple. Tell me what am I doing wrong? My simple code: @IBOutlet var sceneView: ARSCNView! var modelNode: SCNNode! override func viewDidLoad() { super.viewDidLoad() sceneView.delegate = self sceneView.showsStatistics = true let scene = SCNScene(named: "art.scnassets/jacket.usdz")! modelNode = scene.rootNode.childNode(withName: "jacket", recursively: true) let material = SCNMaterial() material.diffuse.contents = UIImage(named: "art.scnassets/58.png") modelNode.childNodes[0].geometry?.materials = [material] sceneView.scene = scene
0
0
817
Jul ’23
SceneKit - error Thread 1: "*** -[NSPathStore2 stringByAppendingPathExtension:]: nil argument
We are trying to save scene into usdz by using scene?.write method , which seems to work as expected until iOS 17. in iOS 17 we are getting error Thread 1: "*** -[NSPathStore2 stringByAppendingPathExtension:]: nil argument which seems to be because of scenekit issue attaching StackTrace screenshot for reference we have used updated method for url in scene?.write(to : url, delegate:nil) where url has been generated using .appending(path: String) method
2
3
1.2k
Jul ’23
SCNPhysicsBody contactTest not working
I am developing a game where users can use their finger to move objects, and when the user releases their finger the game checks for overlap between objects and move the moved object back to it's original position if there is overlap. I am using SCNScene.PhysicsWorld.contactTest(with: ) to check for overlap between my nodes. However, the method only works correctly when nodes have physicsbodys using .convexHull, when I change it to .concavePolyHedron everything stops working and no contact is reported. I have set the physicbodys to be static so I am at a loss of what to do. Here is my code configuring the physicsbody for each node parentNode.physicsBody = SCNPhysicsBody(type: .static, shape: SCNPhysicsShape(node: parentNode, options: [.type: SCNPhysicsShape.ShapeType.concavePolyhedron, .collisionMargin: 0.0, .scale: scaleVector])) Here is my code calling contact test : if let test = currentNode?.physicsBody { let list = view.scene!.physicsWorld.contactTest(with: test) { ... } }
0
0
664
Jul ’23
Xcode 15 Beta3 sceneKit templet
I am getting 4 warnings compiling the current template of sceneKit game /Users/helmut/Documents/spaceTime/scntool:1:1 Could not find bundle inside /Library/Developer/CommandLineTools any idea why the bundle is not installed I did a new download twice now still stuck getting these warnings about bundles not installed or not found any solution to correct the download install so the base dependencies are present thank you
0
0
976
Jul ’23
Adding an object to RoomPlan
A feature of my app I am in need of is to allow users to go through their room and mark specific positions, then be able to navigate these positions with a floor plan like a map. Think google maps but for your room, showing the user's position. I know it is possible to make a floor plan with RoomPlan, which could act as a map, but would it be possible after the plan is made to track a user's location in the room and show it? Is this too complex for RoomPlan? And if so how would I tackle this problem?
0
0
998
Jul ’23
Understanding and subclassing SCNCameraController
Understanding SCNCameraController TLDR; I'm able to create my own subclassed camera controller, but it only works for rotation, not translation. I made a demo repo here. Background I want to use SceneKit's camera controller to drive my scene's camera. The reason I want to subclass it is that my camera is on a rig where I apply rotation to the rig and translation to the camera. I do that because I animate the camera, and applying both translation and rotation to the camera node doesn't create the animation I want. Setting up Instantiate my own SCNCameraController Set its pointofView to my scene's pointOfView (or its parent node I guess) Using the camera controller We now want the new camera controller to drive the scene. When interactions begin (e.g. mouseDown), call beginInteraction(_ location: CGPoint, withViewport viewport: CGSize) When interactions update and end call the corresponding functions on the camera controller Actual behavior It works when I begin/update/end interactions from mouse down events. It ignores any other event types, like magnification, scrollwheel, which work in e.g. the SceneKit Editor in Xcode. See MySCNView.swift in the repo for a demo. By overriding the camera controller's rotate function, I can see that it is called with deltas. This is great. But when I override translateInCameraSpaceBy my print statements don't appear and the scene doesn't translate. Expected behavior I expected SCNCameraController to also apply translations and rolls to the pointOfView by inspecting the currentEvent and figuring out what to do. I'm inclined to think that I'm supposed to call translateInCameraSpaceBy myself, but that seems inconsistent with how Begin/Continue/End interaction seems to call rotate. Demo repo: https://github.com/mortenjust/Camera-Control-Demo
2
0
1k
Jul ’23
Texture in 3D model generated by SceneKit
I'm trying to create an app similar to PolyCam using Lidar . I'm using SceneKit mesh reconstruction and able to apply some random textures. But need real-world textures in generated output 3D Model. Found few examples available which are related to MetalKit and Point Cloud, which was not helpful. Can you help me out with any references/steps/tutorial to how to achieve it .
1
0
786
Jul ’23
advanced modules
Hello, does anyone know of any way to learn apple modules such as scene kit, uikit, reality kit etc? I have seen tutorials on the apple and swift playgrounds page but so far I have not found one that refers to these more advanced modules, I have seen the apple documentation but it is not the most optimal to learn by that means, so I wanted to ask if anyone knows means such as a playground or others to learn how to use these advanced modules
0
0
596
Jun ’23
SceneKit / renderNode override/ Metal / Instancing
Hello I am a bit stuck with a silly challenge I set myself : I want to have a node with a simple geometry ( let's say a triangle ) and I want to render those triangles N time with passing in some information per triangle. Let s say an offset to apply at shader time. I understand that may be I should create a sourcegeo and create multiple nodes to reflect that but here the point is to implement some Metal stuff in the renderNode override ( SCNode.rendererDelegate / SCNRenderNodeDelegate ). so I set up some vertex shader like this : vertex VertexOut brush_vertex_main(const VertexIn vertexIn [[stage_in]], constant BrushNodeBuffer& scn_node [[buffer(BufferNode)]], constant BrushInstances *instances [[buffer(BufferBrush)]], uint instanceID [[instance_id]]) { float4 vertexOffset = float4(instances[instanceID].offset.xyz,1.0) + float4(vertexIn.position.xyz,1.0); // float4 vertexOffset = float4(vertexIn.position.xyz,1.0); VertexOut out = { .position = scn_node.modelViewProjectionTransform * vertexOffset, .color = vertexIn.color }; return out; } Did some binding as well to declare a pipelinerenderState like for eg let defLib = wd.device!.makeDefaultLibrary() let vertFunc = defLib?.makeFunction(name: vertexFunctionName) let fragFunc = defLib?.makeFunction(name: fragmentFunctionName) // add geo desc ( geometries should be doing that underhood anyway let vertexDescriptor = MTLVertexDescriptor() // pos (SCNVertexSemanticPosition) vertexDescriptor.attributes[0].format = .float3 vertexDescriptor.attributes[0].bufferIndex = 0 vertexDescriptor.attributes[0].offset = 0 // color ( SCNVertexSemanticColor) vertexDescriptor.attributes[3].format = .float3 vertexDescriptor.attributes[3].bufferIndex = 0 vertexDescriptor.attributes[3].offset = MemoryLayout<simd_float3>.stride vertexDescriptor.layouts[0].stride = MemoryLayout<simd_float3>.stride * 2 let pipelineDescriptor = MTLRenderPipelineDescriptor() pipelineDescriptor.vertexFunction = vertFunc pipelineDescriptor.fragmentFunction = fragFunc pipelineDescriptor.vertexDescriptor = vertexDescriptor did some buffers creation, setting them properly in the rendering loop rendererCmdEnc.setRenderPipelineState(brushRenderPipelineState!) rendererCmdEnc.setVertexBuffer(vertBuff!, offset: 0, index: 0) // node info rendererCmdEnc.setVertexBuffer(nodeBuff! , offset: 0, index: Int(BufferNode.rawValue)) // per instance info rendererCmdEnc.setVertexBuffer(primBuff! , offset: 0, index: Int(BufferBrush.rawValue)) rendererCmdEnc.drawIndexedPrimitives(type: .triangle, indexCount: primitiveIdx.count, indexType: .uint16, indexBuffer: indexBuff!, indexBufferOffset: 0, instanceCount: 6) and I keep banging my head when this executes : I have a miss match between my renderpipelineState vs the RenderPassDescriptor. Either it s the colorAttachment or the sample count/rastersamplecount that is invalid. -[MTLDebugRenderCommandEncoder setRenderPipelineState:]:1604: failed assertion `Set Render Pipeline State Validation For depth attachment, the texture sample count (1) does not match the renderPipelineState rasterSampleCount (4). The color sample count (1) does not match the renderPipelineState's color sample count (4) The raster sample count (1) does not match the renderPipelineState's raster sample count (4) I used the passdescriptor collorattachment to be a close as possible when describing the renderpipelinestate. changed the rastersamplecount. Tried without any specific for collorattachment etc... Alas, either the API validation will tell me I have the wrong colorAttachment info when I set up the renderpipelinestate in the renderloop and if I fixed the colorattach info at renderStatePipeline creation, some invalid sample count. In a nutshell : is there any way to do this kind of geo instancing in a single node using SceneKit ? thanks in advance for any support you would find interesting to provide!
2
0
1.3k
Jun ’23
SceneKit Animation Export Issue to USD Format
I am writing to report an issue that I have been encountering while developing an iOS game using SceneKit. In my application, I have programmatically added various animations to my scene, which include position, blend shape, and rotation animations. When I attempt to export the scene to a "USD" type file, the export process fails. The error that I receive is as follows: 2 SceneKit 0x1b19d3528 USDKitConverter::processBlendShapeAnimation(USKNode*, CAAnimation*, std::__1::vector<double, std::__1::allocator<double>>&, std::__1::vector<std::__1::vector<float, std::__1::allocator<float>>, std::__1::allocator<std::__1::vector<float, std::__1::allocator<float>>>>&) + 484 Given the nature of the error, I suspect there may be an issue with SceneKit's handling of blend shape animations when converting to USD. As a test, I removed the blend shape animations, keeping only the position animations, and attempted to export again. The export process succeeded, however, when I tried to play the resulting USD file, none of the animations were present. Furthermore, I attempted a workaround by first exporting to an SCN file, which also succeeded. However, when I then tried to open this SCN file with SceneEditor and export it to USD using the application's menu, Xcode crashed. I am reaching out to request assistance in resolving this issue, or if this is indeed a bug, to bring it to your attention for further investigation. Please let me know if you require any additional information from my end.
0
0
999
Jun ’23
SCNNode not showing in snapshot
I am attempting to take a screenshot of a SCNScene using SCNView's snapshot() function. However, when I take a snapshot the image turns out to be just the background color and does not contain any nodes. let tempScene = try SCNScene(url: SceneUrl!) let tempView = SCNView() tempView.scene = tempScene tempView.frame = CGRect(x: 0, y: 0, width: 1000, height: 1200) let cameraNode = SCNNode() cameraNode.camera = SCNCamera() cameraNode.name = "Camera" tempScene.rootNode.addChildNode(cameraNode) // place the camera cameraNode.position = SCNVector3(x: 0, y: 0, z: 15) let list = tempView.scene!.rootNode.childNodes(passingTest: { (node, stop) -> Bool in if node.childNodes.count == 0 { return true; } else { return false; } }) cameraNode.constraints = [SCNLookAtConstraint(target: list.first)] //add a light to the scene let lightNode1 = SCNNode() lightNode1.light = SCNLight() lightNode1.light!.type = .ambient lightNode1.position = SCNVector3(x: 0, y: 30, z: 30) tempScene.rootNode.addChildNode(lightNode1) tempView.backgroundColor = UIColor.darkGray SCNTransaction.flush() let image = tempView.snapshot() code-block
0
0
748
Jun ’23
SCNodes disappear and then reappear
I can't post a video I don't think. But in the screen shots, I'm sightly making a circle with the phone and the green lines will disappear and then reappear. Those green lines are drawn via .addChildNode(). We're using RoomPlan to detect cabinets(.storage), and then we outline the cabinets with SCNNodes. We have other methods to capture cabinets that don't use RoomPlan. And the lines for those cabinets do not wink in and out. Perhaps there is a bug with visibility culling? We're pretty dang sure the nodes are not disappearing because we are calling .hide() anywhere. Perhaps object detection from RoomPlan running in the background is interfering?
2
0
782
Jun ’23
scntool Command Line Tool Issue (iOS 16 Xcode 14)
I am attempting to build an AR app using Storyboard and SceneKit. When I went to run an existing app I have already used it runs but nothing would happen. I thought this behavior was odd so I decided to start from scratch on a new project. I started with the default AR project for Storyboard and SceneKit and upon run it immediately fails with an unwrapping nil error on the scene. This scene file is obviously there. I am also given four build time warnings: Could not find bundle inside /Library/Developer/CommandLineTools failed to convert file with failure reason: *** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[0] Conversion failed, will simply copy input to output. Copy failed file:///Users/kruegerwilliams/Library/Developer/Xcode/DerivedData/ARtest-bjuwvdjoflchdaagofedfxpravsc/Build/Products/Debug-iphoneos/ARtest.app/art.scnassets/ship.scn -> file:///Users/kruegerwilliams/Library/Developer/Xcode/DerivedData/ARtest-bjuwvdjoflchdaagofedfxpravsc/Build/Products/Debug-iphoneos/ARtest.app/art.scnassets/ship.scn error:Error Domain=NSCocoaErrorDomain Code=516 "“ship.scn” couldn’t be copied to “art.scnassets” because an item with the same name already exists." UserInfo={NSSourceFilePathErrorKey=/Users/kruegerwilliams/Library/Developer/Xcode/DerivedData/ARtest-bjuwvdjoflchdaagofedfxpravsc/Build/Products/Debug-iphoneos/ARtest.app/art.scnassets/ship.scn, NSUserStringVariant=( I currently am unsure how to fix these errors? It appears as if they must be in the command line tools because after moving the device support files back to a stable version of Xcode the same issue is present. Is anyone else having these issues?
2
0
2.0k
Jun ’23
Box that crosses the ground by half
Hello, I'm trying to understand physics by placing objects but I have a positioning problem. In fact, I create a floor with static physics and then a static block as well. I position the two elements at position 0 but the block crosses the ground by half. Why? this is my playground 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 box let cube = SCNNode(geometry: SCNBox(width: 1, height: 1, length: 1, chamferRadius: 0)) cube.geometry?.firstMaterial?.diffuse.contents = UIColor.red cube.position = SCNVector3(0, 0, 0) cube.physicsBody = SCNPhysicsBody(type: .static, shape:SCNPhysicsShape(geometry: cube.geometry!, options: nil)) scene.rootNode.addChildNode(cube) thanks !
0
0
565
Jun ’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!
0
0
682
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
How I can change material, like diffuse, on 3D model (.usdz or .obj)?
Hi all. I am new to swift and AR. I'm trying a project on AR and ran into a problem that I can't change the material on the models. With geometry such as a sphere or a cube, everything is simple. Tell me what am I doing wrong? My simple code: @IBOutlet var sceneView: ARSCNView! var modelNode: SCNNode! override func viewDidLoad() { super.viewDidLoad() sceneView.delegate = self sceneView.showsStatistics = true let scene = SCNScene(named: "art.scnassets/jacket.usdz")! modelNode = scene.rootNode.childNode(withName: "jacket", recursively: true) let material = SCNMaterial() material.diffuse.contents = UIImage(named: "art.scnassets/58.png") modelNode.childNodes[0].geometry?.materials = [material] sceneView.scene = scene
Replies
0
Boosts
0
Views
817
Activity
Jul ’23
SceneKit - error Thread 1: "*** -[NSPathStore2 stringByAppendingPathExtension:]: nil argument
We are trying to save scene into usdz by using scene?.write method , which seems to work as expected until iOS 17. in iOS 17 we are getting error Thread 1: "*** -[NSPathStore2 stringByAppendingPathExtension:]: nil argument which seems to be because of scenekit issue attaching StackTrace screenshot for reference we have used updated method for url in scene?.write(to : url, delegate:nil) where url has been generated using .appending(path: String) method
Replies
2
Boosts
3
Views
1.2k
Activity
Jul ’23
AR Heat Map
How do I trace a map on the floor as the user walks through their house, like a trail or heatmap, and then save this trail to CoreData Would it be possible to load and view this map later in the same spot? Or rescan the trail in the same area?
Replies
0
Boosts
0
Views
668
Activity
Jul ’23
SCNPhysicsBody contactTest not working
I am developing a game where users can use their finger to move objects, and when the user releases their finger the game checks for overlap between objects and move the moved object back to it's original position if there is overlap. I am using SCNScene.PhysicsWorld.contactTest(with: ) to check for overlap between my nodes. However, the method only works correctly when nodes have physicsbodys using .convexHull, when I change it to .concavePolyHedron everything stops working and no contact is reported. I have set the physicbodys to be static so I am at a loss of what to do. Here is my code configuring the physicsbody for each node parentNode.physicsBody = SCNPhysicsBody(type: .static, shape: SCNPhysicsShape(node: parentNode, options: [.type: SCNPhysicsShape.ShapeType.concavePolyhedron, .collisionMargin: 0.0, .scale: scaleVector])) Here is my code calling contact test : if let test = currentNode?.physicsBody { let list = view.scene!.physicsWorld.contactTest(with: test) { ... } }
Replies
0
Boosts
0
Views
664
Activity
Jul ’23
Xcode 15 Beta3 sceneKit templet
I am getting 4 warnings compiling the current template of sceneKit game /Users/helmut/Documents/spaceTime/scntool:1:1 Could not find bundle inside /Library/Developer/CommandLineTools any idea why the bundle is not installed I did a new download twice now still stuck getting these warnings about bundles not installed or not found any solution to correct the download install so the base dependencies are present thank you
Replies
0
Boosts
0
Views
976
Activity
Jul ’23
Adding an object to RoomPlan
A feature of my app I am in need of is to allow users to go through their room and mark specific positions, then be able to navigate these positions with a floor plan like a map. Think google maps but for your room, showing the user's position. I know it is possible to make a floor plan with RoomPlan, which could act as a map, but would it be possible after the plan is made to track a user's location in the room and show it? Is this too complex for RoomPlan? And if so how would I tackle this problem?
Replies
0
Boosts
0
Views
998
Activity
Jul ’23
Understanding and subclassing SCNCameraController
Understanding SCNCameraController TLDR; I'm able to create my own subclassed camera controller, but it only works for rotation, not translation. I made a demo repo here. Background I want to use SceneKit's camera controller to drive my scene's camera. The reason I want to subclass it is that my camera is on a rig where I apply rotation to the rig and translation to the camera. I do that because I animate the camera, and applying both translation and rotation to the camera node doesn't create the animation I want. Setting up Instantiate my own SCNCameraController Set its pointofView to my scene's pointOfView (or its parent node I guess) Using the camera controller We now want the new camera controller to drive the scene. When interactions begin (e.g. mouseDown), call beginInteraction(_ location: CGPoint, withViewport viewport: CGSize) When interactions update and end call the corresponding functions on the camera controller Actual behavior It works when I begin/update/end interactions from mouse down events. It ignores any other event types, like magnification, scrollwheel, which work in e.g. the SceneKit Editor in Xcode. See MySCNView.swift in the repo for a demo. By overriding the camera controller's rotate function, I can see that it is called with deltas. This is great. But when I override translateInCameraSpaceBy my print statements don't appear and the scene doesn't translate. Expected behavior I expected SCNCameraController to also apply translations and rolls to the pointOfView by inspecting the currentEvent and figuring out what to do. I'm inclined to think that I'm supposed to call translateInCameraSpaceBy myself, but that seems inconsistent with how Begin/Continue/End interaction seems to call rotate. Demo repo: https://github.com/mortenjust/Camera-Control-Demo
Replies
2
Boosts
0
Views
1k
Activity
Jul ’23
Texture in 3D model generated by SceneKit
I'm trying to create an app similar to PolyCam using Lidar . I'm using SceneKit mesh reconstruction and able to apply some random textures. But need real-world textures in generated output 3D Model. Found few examples available which are related to MetalKit and Point Cloud, which was not helpful. Can you help me out with any references/steps/tutorial to how to achieve it .
Replies
1
Boosts
0
Views
786
Activity
Jul ’23
advanced modules
Hello, does anyone know of any way to learn apple modules such as scene kit, uikit, reality kit etc? I have seen tutorials on the apple and swift playgrounds page but so far I have not found one that refers to these more advanced modules, I have seen the apple documentation but it is not the most optimal to learn by that means, so I wanted to ask if anyone knows means such as a playground or others to learn how to use these advanced modules
Replies
0
Boosts
0
Views
596
Activity
Jun ’23
SceneKit / renderNode override/ Metal / Instancing
Hello I am a bit stuck with a silly challenge I set myself : I want to have a node with a simple geometry ( let's say a triangle ) and I want to render those triangles N time with passing in some information per triangle. Let s say an offset to apply at shader time. I understand that may be I should create a sourcegeo and create multiple nodes to reflect that but here the point is to implement some Metal stuff in the renderNode override ( SCNode.rendererDelegate / SCNRenderNodeDelegate ). so I set up some vertex shader like this : vertex VertexOut brush_vertex_main(const VertexIn vertexIn [[stage_in]], constant BrushNodeBuffer& scn_node [[buffer(BufferNode)]], constant BrushInstances *instances [[buffer(BufferBrush)]], uint instanceID [[instance_id]]) { float4 vertexOffset = float4(instances[instanceID].offset.xyz,1.0) + float4(vertexIn.position.xyz,1.0); // float4 vertexOffset = float4(vertexIn.position.xyz,1.0); VertexOut out = { .position = scn_node.modelViewProjectionTransform * vertexOffset, .color = vertexIn.color }; return out; } Did some binding as well to declare a pipelinerenderState like for eg let defLib = wd.device!.makeDefaultLibrary() let vertFunc = defLib?.makeFunction(name: vertexFunctionName) let fragFunc = defLib?.makeFunction(name: fragmentFunctionName) // add geo desc ( geometries should be doing that underhood anyway let vertexDescriptor = MTLVertexDescriptor() // pos (SCNVertexSemanticPosition) vertexDescriptor.attributes[0].format = .float3 vertexDescriptor.attributes[0].bufferIndex = 0 vertexDescriptor.attributes[0].offset = 0 // color ( SCNVertexSemanticColor) vertexDescriptor.attributes[3].format = .float3 vertexDescriptor.attributes[3].bufferIndex = 0 vertexDescriptor.attributes[3].offset = MemoryLayout<simd_float3>.stride vertexDescriptor.layouts[0].stride = MemoryLayout<simd_float3>.stride * 2 let pipelineDescriptor = MTLRenderPipelineDescriptor() pipelineDescriptor.vertexFunction = vertFunc pipelineDescriptor.fragmentFunction = fragFunc pipelineDescriptor.vertexDescriptor = vertexDescriptor did some buffers creation, setting them properly in the rendering loop rendererCmdEnc.setRenderPipelineState(brushRenderPipelineState!) rendererCmdEnc.setVertexBuffer(vertBuff!, offset: 0, index: 0) // node info rendererCmdEnc.setVertexBuffer(nodeBuff! , offset: 0, index: Int(BufferNode.rawValue)) // per instance info rendererCmdEnc.setVertexBuffer(primBuff! , offset: 0, index: Int(BufferBrush.rawValue)) rendererCmdEnc.drawIndexedPrimitives(type: .triangle, indexCount: primitiveIdx.count, indexType: .uint16, indexBuffer: indexBuff!, indexBufferOffset: 0, instanceCount: 6) and I keep banging my head when this executes : I have a miss match between my renderpipelineState vs the RenderPassDescriptor. Either it s the colorAttachment or the sample count/rastersamplecount that is invalid. -[MTLDebugRenderCommandEncoder setRenderPipelineState:]:1604: failed assertion `Set Render Pipeline State Validation For depth attachment, the texture sample count (1) does not match the renderPipelineState rasterSampleCount (4). The color sample count (1) does not match the renderPipelineState's color sample count (4) The raster sample count (1) does not match the renderPipelineState's raster sample count (4) I used the passdescriptor collorattachment to be a close as possible when describing the renderpipelinestate. changed the rastersamplecount. Tried without any specific for collorattachment etc... Alas, either the API validation will tell me I have the wrong colorAttachment info when I set up the renderpipelinestate in the renderloop and if I fixed the colorattach info at renderStatePipeline creation, some invalid sample count. In a nutshell : is there any way to do this kind of geo instancing in a single node using SceneKit ? thanks in advance for any support you would find interesting to provide!
Replies
2
Boosts
0
Views
1.3k
Activity
Jun ’23
SceneKit Animation Export Issue to USD Format
I am writing to report an issue that I have been encountering while developing an iOS game using SceneKit. In my application, I have programmatically added various animations to my scene, which include position, blend shape, and rotation animations. When I attempt to export the scene to a "USD" type file, the export process fails. The error that I receive is as follows: 2 SceneKit 0x1b19d3528 USDKitConverter::processBlendShapeAnimation(USKNode*, CAAnimation*, std::__1::vector<double, std::__1::allocator<double>>&, std::__1::vector<std::__1::vector<float, std::__1::allocator<float>>, std::__1::allocator<std::__1::vector<float, std::__1::allocator<float>>>>&) + 484 Given the nature of the error, I suspect there may be an issue with SceneKit's handling of blend shape animations when converting to USD. As a test, I removed the blend shape animations, keeping only the position animations, and attempted to export again. The export process succeeded, however, when I tried to play the resulting USD file, none of the animations were present. Furthermore, I attempted a workaround by first exporting to an SCN file, which also succeeded. However, when I then tried to open this SCN file with SceneEditor and export it to USD using the application's menu, Xcode crashed. I am reaching out to request assistance in resolving this issue, or if this is indeed a bug, to bring it to your attention for further investigation. Please let me know if you require any additional information from my end.
Replies
0
Boosts
0
Views
999
Activity
Jun ’23
SCNNode not showing in snapshot
I am attempting to take a screenshot of a SCNScene using SCNView's snapshot() function. However, when I take a snapshot the image turns out to be just the background color and does not contain any nodes. let tempScene = try SCNScene(url: SceneUrl!) let tempView = SCNView() tempView.scene = tempScene tempView.frame = CGRect(x: 0, y: 0, width: 1000, height: 1200) let cameraNode = SCNNode() cameraNode.camera = SCNCamera() cameraNode.name = "Camera" tempScene.rootNode.addChildNode(cameraNode) // place the camera cameraNode.position = SCNVector3(x: 0, y: 0, z: 15) let list = tempView.scene!.rootNode.childNodes(passingTest: { (node, stop) -> Bool in if node.childNodes.count == 0 { return true; } else { return false; } }) cameraNode.constraints = [SCNLookAtConstraint(target: list.first)] //add a light to the scene let lightNode1 = SCNNode() lightNode1.light = SCNLight() lightNode1.light!.type = .ambient lightNode1.position = SCNVector3(x: 0, y: 30, z: 30) tempScene.rootNode.addChildNode(lightNode1) tempView.backgroundColor = UIColor.darkGray SCNTransaction.flush() let image = tempView.snapshot() code-block
Replies
0
Boosts
0
Views
748
Activity
Jun ’23
Apply same animation to all characters
Hello With Unity you can import an animation and apply it to any character. For example, I import a walking animation and I can apply it to all my characters. Is there an equivalent with SceneKit? I would like to apply animations by programming without having to import for each character specifically Thanks
Replies
0
Boosts
0
Views
947
Activity
Jun ’23
SCNodes disappear and then reappear
I can't post a video I don't think. But in the screen shots, I'm sightly making a circle with the phone and the green lines will disappear and then reappear. Those green lines are drawn via .addChildNode(). We're using RoomPlan to detect cabinets(.storage), and then we outline the cabinets with SCNNodes. We have other methods to capture cabinets that don't use RoomPlan. And the lines for those cabinets do not wink in and out. Perhaps there is a bug with visibility culling? We're pretty dang sure the nodes are not disappearing because we are calling .hide() anywhere. Perhaps object detection from RoomPlan running in the background is interfering?
Replies
2
Boosts
0
Views
782
Activity
Jun ’23
scntool Command Line Tool Issue (iOS 16 Xcode 14)
I am attempting to build an AR app using Storyboard and SceneKit. When I went to run an existing app I have already used it runs but nothing would happen. I thought this behavior was odd so I decided to start from scratch on a new project. I started with the default AR project for Storyboard and SceneKit and upon run it immediately fails with an unwrapping nil error on the scene. This scene file is obviously there. I am also given four build time warnings: Could not find bundle inside /Library/Developer/CommandLineTools failed to convert file with failure reason: *** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[0] Conversion failed, will simply copy input to output. Copy failed file:///Users/kruegerwilliams/Library/Developer/Xcode/DerivedData/ARtest-bjuwvdjoflchdaagofedfxpravsc/Build/Products/Debug-iphoneos/ARtest.app/art.scnassets/ship.scn -> file:///Users/kruegerwilliams/Library/Developer/Xcode/DerivedData/ARtest-bjuwvdjoflchdaagofedfxpravsc/Build/Products/Debug-iphoneos/ARtest.app/art.scnassets/ship.scn error:Error Domain=NSCocoaErrorDomain Code=516 "“ship.scn” couldn’t be copied to “art.scnassets” because an item with the same name already exists." UserInfo={NSSourceFilePathErrorKey=/Users/kruegerwilliams/Library/Developer/Xcode/DerivedData/ARtest-bjuwvdjoflchdaagofedfxpravsc/Build/Products/Debug-iphoneos/ARtest.app/art.scnassets/ship.scn, NSUserStringVariant=( I currently am unsure how to fix these errors? It appears as if they must be in the command line tools because after moving the device support files back to a stable version of Xcode the same issue is present. Is anyone else having these issues?
Replies
2
Boosts
0
Views
2.0k
Activity
Jun ’23
Box that crosses the ground by half
Hello, I'm trying to understand physics by placing objects but I have a positioning problem. In fact, I create a floor with static physics and then a static block as well. I position the two elements at position 0 but the block crosses the ground by half. Why? this is my playground 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 box let cube = SCNNode(geometry: SCNBox(width: 1, height: 1, length: 1, chamferRadius: 0)) cube.geometry?.firstMaterial?.diffuse.contents = UIColor.red cube.position = SCNVector3(0, 0, 0) cube.physicsBody = SCNPhysicsBody(type: .static, shape:SCNPhysicsShape(geometry: cube.geometry!, options: nil)) scene.rootNode.addChildNode(cube) thanks !
Replies
0
Boosts
0
Views
565
Activity
Jun ’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
682
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