SceneKit

RSS for tag

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

SceneKit Documentation

Posts under SceneKit subtopic

Post

Replies

Boosts

Views

Activity

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
1.2k
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
655
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
951
Jun ’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
538
May ’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
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.7k
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.8k
Mar ’23
SCNNode.position is sometimes not reflected on screen
The desired outcome of the code below is that both the red and yellow spheres should be at the same position at the center of the scene, (0, 0, 0), but instead the red sphere remains at its initial position (1, 0, 0). Commenting out any of the lines marked in the code, strangely, solves the issue. The code shows a simplified version of some other code, so it would be desirable to keep the order of the lines as they currently are. Am I doing something wrong? class GameViewController: NSViewController {          override func viewDidLoad() {         super.viewDidLoad()                  let scene = SCNScene(named: "art.scnassets/ship.scn")!                  let cameraNode = SCNNode()         cameraNode.camera = SCNCamera()         scene.rootNode.addChildNode(cameraNode)         cameraNode.position = SCNVector3(x: 0, y: 0, z: 15)                  let lightNode = SCNNode()         lightNode.light = SCNLight()         lightNode.light!.type = .omni         lightNode.position = SCNVector3(x: 0, y: 10, z: 10)         scene.rootNode.addChildNode(lightNode)                  let scnView = self.view as! SCNView         scnView.scene = scene                  let parent0 = SCNNode()         scene.rootNode.addChildNode(parent0)         let parent1 = SCNNode()         scene.rootNode.addChildNode(parent1)         let sphere0 = SCNNode(geometry: SCNSphere(radius: 1))         sphere0.geometry!.firstMaterial!.diffuse.contents = NSColor.red                  let sphere1 = SCNNode(geometry: SCNSphere(radius: 1))         sphere1.geometry!.firstMaterial!.diffuse.contents = NSColor.yellow                  sphere0.position = SCNVector3(x: -1, y: 0, z: 0) // commenting out this line solves the issue         parent1.addChildNode(sphere0) // or commenting out this line solves the issue         sphere0.position = SCNVector3(x: 0, y: 0, z: 0)         parent0.addChildNode(sphere1) // or commenting out this line solves the issue                  DispatchQueue.main.asyncAfter(deadline: .now() + 1) {             print(sphere0.worldPosition, sphere1.worldPosition)         }     } }
1
0
1k
Feb ’23
SCNCylinder shows mirrored texture for base and top elements
SCNBox renders the textures correctly, but SCNCylinder seems to mirror the base and top textures. The following code reproduces the issue (just set the image variable to the name of the image you're using, in this case an image with the number 2 in it): class GameViewController: NSViewController { let image = "art.scnassets/image.heic"          override func viewDidLoad() {         super.viewDidLoad()                  let scene = SCNScene(named: "art.scnassets/ship.scn")!                  let cameraNode = SCNNode()         cameraNode.camera = SCNCamera()         scene.rootNode.addChildNode(cameraNode)         cameraNode.position = SCNVector3(x: 0, y: 3, z: 3)         let scnView = self.view as! SCNView         scnView.scene = scene                  let node = SCNNode(geometry: SCNCylinder(radius: 0.5, height: 1))         node.geometry!.materials = [SCNMaterial(), SCNMaterial(), SCNMaterial()]         node.geometry!.materials[1].diffuse.contents = image         node.geometry!.materials[2].diffuse.contents = image         node.position.x = -1         node.runAction(.repeatForever(.rotate(by: 1, around: SCNVector3(x: 1, y: 0, z: 0), duration: 1)))         scene.rootNode.addChildNode(node)         let node2 = SCNNode(geometry: SCNBox(width: 1, height: 1, length: 1, chamferRadius: 0))         node2.geometry!.materials = [SCNMaterial(), SCNMaterial(), SCNMaterial(), SCNMaterial(), SCNMaterial(), SCNMaterial()]         node2.geometry!.materials[4].diffuse.contents = image         node2.geometry!.materials[5].diffuse.contents = image         node2.position.x = 1         node2.runAction(.repeatForever(.rotate(by: 1, around: SCNVector3(x: 1, y: 0, z: 0), duration: 1)))         scene.rootNode.addChildNode(node2)         cameraNode.look(at: SCNVector3(x: 0, y: 0, z: 0))     } }
0
0
760
Feb ’23
Export animation from .dae
Hello guys,In WWDC 2015 - Session 606 - Enhancements to SceneKit there was an Fox example project which is available to download.Can anyone say what is the correct collada file setttings when exporting model with skeletal animation from 3D tool into .dae file? For example in the demo project there is a "walk.scn".I used 3D tool (Cheetah3D) to make a simple model with simple skeletal animation and export it in .dae, but I can't get my model to be animated on the scene.If I use non skeletal animation in 3D tool and export it in .dae then model animation on the scene works perfect.Maybe someone succeed with exporting model with skeletal animation using another 3D tool like Blender?
14
0
14k
Jan ’23
PhysicsBody.applyForce() is not independent of speed, timeStep and FPS
I've setup a scene with SceneKit where a ball is rolling on a plan. I've simulated the grass friction with applyForce() in order to make it stop after a while (dampen & friction parameters do not reach that effect). Everything works well till I play with runtime parameters, like scnScene.physicsWorld.timeStep, sceneView.preferredFramesPerSecond and scnScene.physicsWorld.speed. I did a comparison with default gravity. Let's take a plan, with a light slope and launch a ball on it: let planSlope = (Float.pi/180.0)*3.0 planNode.rotation = SCNVector4(x:0, y:0, z:1, w: planSlope) ... let impulse =  Float(ballMass) * speed // N.s = m*v let forceVector = simd_float3(1.0, 0.0, 0.0) let force = SCNVector3(forceVector * impulse) ballNode.physicsBody?.applyForce(force, asImpulse: true) The ball will climb the slope up till a certain distance and come back after. If I change timeStep, FPS or speed, the ball is still reaching the same point. That's great. Now, I disable gravity and create a custom force to simulate it using applyForce(): scnScene.physicsWorld.gravity = SCNVector3(0.0, 0.0, 0.0) func physicsWorld(_ physicsWorld: SCNPhysicsWorld, didUpdate physicsContact: SCNPhysicsContact) { ... let gravity = simd_float3(0.0, -9.8, 0.0) let mass = (ballNode.physicsBody?.mass)! let force = SCNVector3(gravity * Float(mass)) ballNode.physicsBody?.applyForce(force, asImpulse: false) This gives exactly the same good result with default constants: scnScene.physicsWorld.speed = 1.0 scnScene.physicsWorld.timeStep = 1.0/60.0 sceneView.preferredFramesPerSecond = 60 But as soon as I change one of them, the distance changes: scnScene.physicsWorld.speed = 2.0 scnScene.physicsWorld.timeStep = 1.0/120.0 sceneView.preferredFramesPerSecond = 30 So, I needed to take them into account on the force: func physicsWorld(_ physicsWorld: SCNPhysicsWorld, didUpdate physicsContact: SCNPhysicsContact) { ... let gravity = simd_float3(0.0, -9.8, 0.0) // Compensate timeStep & FPS & Speed !? gravity *= Float(scnScene.physicsWorld.timeStep)/(1.0/60.0) gravity *= (1.0/60.0)/(1.0/Float(sceneView.preferredFramesPerSecond)) gravity *= 1.0/Float(scnScene.physicsWorld.speed) let mass = (ballNode.physicsBody?.mass)! let force = SCNVector3(gravity * Float(mass)) ballNode.physicsBody?.applyForce(force, asImpulse: false) That's weird, I guess I missed something? The risk is that if FPS changes dynamically due to GPU overload, the result will differ.
0
0
1.2k
Dec ’22
Converted OBJ to SCN and now the object won't load
let pathToBalloon = Bundle.main.path(forResource: "./Balloon2", ofType: "scn")!     let balloonAsset = MDLAsset(url: URL(fileURLWithPath: pathToBalloon))     let balloonObject: MDLObject? = balloonAsset.object(at: 0)     let balloon = SCNNode(mdlObject: balloonObject!) // Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value Using an .obj file with a balloon works great and displays in SCNView just fine. To use extra features Xcode asked me to convert to a .scn format. The model loads just fine in the Xcode editor, however balloonAsset.object(at: 0) now returns nil. I really wanted to smooth the geometry and other stuff so continuing to use .obj files is meh. What could the issue be?
1
1
2.1k
Nov ’22
SCNAction not triggering
I have a sequence where I have a SCNScene with one ship already in frame. The goal is to move a new ship in, pause, then smoothly move the camera to a new angle "over the shoulder" of the new ship and do the next step in the code. I get the new ship moving in then no next steps. The code is:     func startAttack() {         let moveAnime = SCNAction.move(to: SCNVector3(-20, 75, 75), duration: 0.5)         attShip.runAction(SCNAction.sequence([moveAnime, SCNAction.wait(duration: 0.5)])) { self.positionCamera() }     }          func positionCamera() {         print("got to position camera")         if Thread.isMainThread {              print("already main thread")             self.overwatchCamera.runAction(SCNAction.customAction(duration: 1, action: { node, timing in                 node.position = SCNVector3(-75, 300, 300)                 node.look(at: SCNVector3(20, 75, -75), up: self.rootNode.worldUp, localFront: self.rootNode.worldFront)             })) {                  self.doAttackRound()             }         } else {             DispatchQueue.main.async {                  print("reset to main thread")                 self.overwatchCamera.look(at: SCNVector3(20, 75, -75), up: self.rootNode.worldUp, localFront: self.rootNode.worldFront)                 self.overwatchCamera.runAction(SCNAction.move(to: SCNVector3(-75, 300, 300), duration: 1)) {                      self.doAttackRound()                 }             }         }      } I tried testing for whether it was on the main thread already, and in my testing it is showing that it gets to the position camera function but it is not on the main thread and tries the option with the DispatchQueue. I left in both of the ways I have tried to execute the camera movement animate, through a custom animation on both the position and look at for the camera, and through a static change to the look at and an animated move of the camera position. Neither one is triggering. Any help would be greatly appreciated. Thanks!
0
0
818
Nov ’22
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
1.2k
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
1.2k
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
655
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
951
Activity
Jun ’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
538
Activity
May ’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
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
562
Activity
Apr ’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.7k
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.8k
Activity
Mar ’23
SCNNode.position is sometimes not reflected on screen
The desired outcome of the code below is that both the red and yellow spheres should be at the same position at the center of the scene, (0, 0, 0), but instead the red sphere remains at its initial position (1, 0, 0). Commenting out any of the lines marked in the code, strangely, solves the issue. The code shows a simplified version of some other code, so it would be desirable to keep the order of the lines as they currently are. Am I doing something wrong? class GameViewController: NSViewController {          override func viewDidLoad() {         super.viewDidLoad()                  let scene = SCNScene(named: "art.scnassets/ship.scn")!                  let cameraNode = SCNNode()         cameraNode.camera = SCNCamera()         scene.rootNode.addChildNode(cameraNode)         cameraNode.position = SCNVector3(x: 0, y: 0, z: 15)                  let lightNode = SCNNode()         lightNode.light = SCNLight()         lightNode.light!.type = .omni         lightNode.position = SCNVector3(x: 0, y: 10, z: 10)         scene.rootNode.addChildNode(lightNode)                  let scnView = self.view as! SCNView         scnView.scene = scene                  let parent0 = SCNNode()         scene.rootNode.addChildNode(parent0)         let parent1 = SCNNode()         scene.rootNode.addChildNode(parent1)         let sphere0 = SCNNode(geometry: SCNSphere(radius: 1))         sphere0.geometry!.firstMaterial!.diffuse.contents = NSColor.red                  let sphere1 = SCNNode(geometry: SCNSphere(radius: 1))         sphere1.geometry!.firstMaterial!.diffuse.contents = NSColor.yellow                  sphere0.position = SCNVector3(x: -1, y: 0, z: 0) // commenting out this line solves the issue         parent1.addChildNode(sphere0) // or commenting out this line solves the issue         sphere0.position = SCNVector3(x: 0, y: 0, z: 0)         parent0.addChildNode(sphere1) // or commenting out this line solves the issue                  DispatchQueue.main.asyncAfter(deadline: .now() + 1) {             print(sphere0.worldPosition, sphere1.worldPosition)         }     } }
Replies
1
Boosts
0
Views
1k
Activity
Feb ’23
SCNCylinder shows mirrored texture for base and top elements
SCNBox renders the textures correctly, but SCNCylinder seems to mirror the base and top textures. The following code reproduces the issue (just set the image variable to the name of the image you're using, in this case an image with the number 2 in it): class GameViewController: NSViewController { let image = "art.scnassets/image.heic"          override func viewDidLoad() {         super.viewDidLoad()                  let scene = SCNScene(named: "art.scnassets/ship.scn")!                  let cameraNode = SCNNode()         cameraNode.camera = SCNCamera()         scene.rootNode.addChildNode(cameraNode)         cameraNode.position = SCNVector3(x: 0, y: 3, z: 3)         let scnView = self.view as! SCNView         scnView.scene = scene                  let node = SCNNode(geometry: SCNCylinder(radius: 0.5, height: 1))         node.geometry!.materials = [SCNMaterial(), SCNMaterial(), SCNMaterial()]         node.geometry!.materials[1].diffuse.contents = image         node.geometry!.materials[2].diffuse.contents = image         node.position.x = -1         node.runAction(.repeatForever(.rotate(by: 1, around: SCNVector3(x: 1, y: 0, z: 0), duration: 1)))         scene.rootNode.addChildNode(node)         let node2 = SCNNode(geometry: SCNBox(width: 1, height: 1, length: 1, chamferRadius: 0))         node2.geometry!.materials = [SCNMaterial(), SCNMaterial(), SCNMaterial(), SCNMaterial(), SCNMaterial(), SCNMaterial()]         node2.geometry!.materials[4].diffuse.contents = image         node2.geometry!.materials[5].diffuse.contents = image         node2.position.x = 1         node2.runAction(.repeatForever(.rotate(by: 1, around: SCNVector3(x: 1, y: 0, z: 0), duration: 1)))         scene.rootNode.addChildNode(node2)         cameraNode.look(at: SCNVector3(x: 0, y: 0, z: 0))     } }
Replies
0
Boosts
0
Views
760
Activity
Feb ’23
White screen with scenekit
I am very new to SceneKit and have been following online tutorials. When I use the scene editor and produce objects in the scene editor, when I run the app, all I can see is a blank screen. Am i missing something here?
Replies
0
Boosts
0
Views
619
Activity
Jan ’23
Export animation from .dae
Hello guys,In WWDC 2015 - Session 606 - Enhancements to SceneKit there was an Fox example project which is available to download.Can anyone say what is the correct collada file setttings when exporting model with skeletal animation from 3D tool into .dae file? For example in the demo project there is a "walk.scn".I used 3D tool (Cheetah3D) to make a simple model with simple skeletal animation and export it in .dae, but I can't get my model to be animated on the scene.If I use non skeletal animation in 3D tool and export it in .dae then model animation on the scene works perfect.Maybe someone succeed with exporting model with skeletal animation using another 3D tool like Blender?
Replies
14
Boosts
0
Views
14k
Activity
Jan ’23
Move a character with SceneKit
Hello I would like to move a character in swift with SceneKit. I use a gamePad to move the character. It works well at first but when the camera changes orientation, the character is not going in the right direction at all...
Replies
1
Boosts
0
Views
1.4k
Activity
Jan ’23
PhysicsBody.applyForce() is not independent of speed, timeStep and FPS
I've setup a scene with SceneKit where a ball is rolling on a plan. I've simulated the grass friction with applyForce() in order to make it stop after a while (dampen & friction parameters do not reach that effect). Everything works well till I play with runtime parameters, like scnScene.physicsWorld.timeStep, sceneView.preferredFramesPerSecond and scnScene.physicsWorld.speed. I did a comparison with default gravity. Let's take a plan, with a light slope and launch a ball on it: let planSlope = (Float.pi/180.0)*3.0 planNode.rotation = SCNVector4(x:0, y:0, z:1, w: planSlope) ... let impulse =  Float(ballMass) * speed // N.s = m*v let forceVector = simd_float3(1.0, 0.0, 0.0) let force = SCNVector3(forceVector * impulse) ballNode.physicsBody?.applyForce(force, asImpulse: true) The ball will climb the slope up till a certain distance and come back after. If I change timeStep, FPS or speed, the ball is still reaching the same point. That's great. Now, I disable gravity and create a custom force to simulate it using applyForce(): scnScene.physicsWorld.gravity = SCNVector3(0.0, 0.0, 0.0) func physicsWorld(_ physicsWorld: SCNPhysicsWorld, didUpdate physicsContact: SCNPhysicsContact) { ... let gravity = simd_float3(0.0, -9.8, 0.0) let mass = (ballNode.physicsBody?.mass)! let force = SCNVector3(gravity * Float(mass)) ballNode.physicsBody?.applyForce(force, asImpulse: false) This gives exactly the same good result with default constants: scnScene.physicsWorld.speed = 1.0 scnScene.physicsWorld.timeStep = 1.0/60.0 sceneView.preferredFramesPerSecond = 60 But as soon as I change one of them, the distance changes: scnScene.physicsWorld.speed = 2.0 scnScene.physicsWorld.timeStep = 1.0/120.0 sceneView.preferredFramesPerSecond = 30 So, I needed to take them into account on the force: func physicsWorld(_ physicsWorld: SCNPhysicsWorld, didUpdate physicsContact: SCNPhysicsContact) { ... let gravity = simd_float3(0.0, -9.8, 0.0) // Compensate timeStep & FPS & Speed !? gravity *= Float(scnScene.physicsWorld.timeStep)/(1.0/60.0) gravity *= (1.0/60.0)/(1.0/Float(sceneView.preferredFramesPerSecond)) gravity *= 1.0/Float(scnScene.physicsWorld.speed) let mass = (ballNode.physicsBody?.mass)! let force = SCNVector3(gravity * Float(mass)) ballNode.physicsBody?.applyForce(force, asImpulse: false) That's weird, I guess I missed something? The risk is that if FPS changes dynamically due to GPU overload, the result will differ.
Replies
0
Boosts
0
Views
1.2k
Activity
Dec ’22
Converted OBJ to SCN and now the object won't load
let pathToBalloon = Bundle.main.path(forResource: "./Balloon2", ofType: "scn")!     let balloonAsset = MDLAsset(url: URL(fileURLWithPath: pathToBalloon))     let balloonObject: MDLObject? = balloonAsset.object(at: 0)     let balloon = SCNNode(mdlObject: balloonObject!) // Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value Using an .obj file with a balloon works great and displays in SCNView just fine. To use extra features Xcode asked me to convert to a .scn format. The model loads just fine in the Xcode editor, however balloonAsset.object(at: 0) now returns nil. I really wanted to smooth the geometry and other stuff so continuing to use .obj files is meh. What could the issue be?
Replies
1
Boosts
1
Views
2.1k
Activity
Nov ’22
SCNAction not triggering
I have a sequence where I have a SCNScene with one ship already in frame. The goal is to move a new ship in, pause, then smoothly move the camera to a new angle "over the shoulder" of the new ship and do the next step in the code. I get the new ship moving in then no next steps. The code is:     func startAttack() {         let moveAnime = SCNAction.move(to: SCNVector3(-20, 75, 75), duration: 0.5)         attShip.runAction(SCNAction.sequence([moveAnime, SCNAction.wait(duration: 0.5)])) { self.positionCamera() }     }          func positionCamera() {         print("got to position camera")         if Thread.isMainThread {              print("already main thread")             self.overwatchCamera.runAction(SCNAction.customAction(duration: 1, action: { node, timing in                 node.position = SCNVector3(-75, 300, 300)                 node.look(at: SCNVector3(20, 75, -75), up: self.rootNode.worldUp, localFront: self.rootNode.worldFront)             })) {                  self.doAttackRound()             }         } else {             DispatchQueue.main.async {                  print("reset to main thread")                 self.overwatchCamera.look(at: SCNVector3(20, 75, -75), up: self.rootNode.worldUp, localFront: self.rootNode.worldFront)                 self.overwatchCamera.runAction(SCNAction.move(to: SCNVector3(-75, 300, 300), duration: 1)) {                      self.doAttackRound()                 }             }         }      } I tried testing for whether it was on the main thread already, and in my testing it is showing that it gets to the position camera function but it is not on the main thread and tries the option with the DispatchQueue. I left in both of the ways I have tried to execute the camera movement animate, through a custom animation on both the position and look at for the camera, and through a static change to the look at and an animated move of the camera position. Neither one is triggering. Any help would be greatly appreciated. Thanks!
Replies
0
Boosts
0
Views
818
Activity
Nov ’22