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.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
449
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.6k
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.3k
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
839
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
674
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.1k
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
1.7k
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
722
Nov ’22
RoomPlan: Use the transform and dimensions to generate 4 corner points
I'm trying to use data returned from the RoomCaptureSession delegate to draw four corners of a door in SceneKit. The CapturedRoom.Surface class has Dimensions and Transform members. I was told in the WWDC 2022 RoomPlan Slack lounge: "You can use transform and dimensions parameters to draw lines. The 4 corners can be inferred from those 2 parameters: the first column of the transform is the "right" vector, and second is the "up" vector. The fourth column is the position of the wall/door/opening/window/object Combining those unit vectors with the dimensions vector will give you the corners." So I think this is a basic vector question. I'm not sure what is meant by "Combining those unit vectors with the dimensions vector". I've tried a few things, but I'm not sure how to go about this.
5
1
2.6k
Nov ’22
See through walls shader
Hi All I am developing a surveying application on a 3d model, finished developing the measuring module but am having a problem that the scntext added on the scnode root cannot see through the 3d model. I am using the SCNBillboardConstraint contraint to towards the current camera. So is there a way for the scntext to see through or overwrite the model like this? Thank
0
0
593
Oct ’22
Getting Started with Scene Kit
Hi all, I've got an idea for an interesting twist on a 3d aerial battle game, and so I'm taking the plunge on making my first 3d game. I've got the developer docs queued up and the WWDC videos ready to go, and I've bookmarked a Ray Wenderlich tutorial on SceneKit. Before I get started, since this is all so new to me, do any of y'all have any recommendations for good, up-to-date tutorials or hints and tips that might shortcut any of the process? If it helps, my proof of concept will just allow me to have the player chase a computer-controlled airplane around in 3d space, and view that opponent from the cockpit view. I've already done all my homework on the math of movement in 3d space. Had to dust off some trig, and I haven't worked with radians in a long, long time. But the next step is to get some basic visualizations in, and it looks a little daunting. I truly appreciate any guidance you can point towards!!
0
0
1.2k
Oct ’22
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
449
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
474
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.6k
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.3k
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
839
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
674
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
534
Activity
Jan ’23
Reality Converter is having trouble converting this glb file of mine.
[https://aaronwoods.info/blood-v1.glb) I've tried everything. I think it might be because I compressed it with a tool from this site, https://gltf.report/. But i need the usdz file as well, and i need that file to also be small.
Replies
0
Boosts
0
Views
905
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.3k
Activity
Jan ’23
how to reset node to default viewofpoint with animaiton after use camercontroller change viewofpoint
load scene with scenekit, and set allowsCameraControl to yes; after rotate node use gesutre, how can i reset node to defult with animation?
Replies
0
Boosts
0
Views
520
Activity
Dec ’22
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.1k
Activity
Dec ’22
Convert SCNGeometryElement -> MTKMesh
There's some stuff I want to do in rendering, which I SceneKit is not letting me do. So I want to build my own render pipeline.Is there a nice way from taking geometry loaded by SceneKit and pushing it into MetalKit for rendering?
Replies
3
Boosts
0
Views
1.4k
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
1.7k
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
722
Activity
Nov ’22
RoomPlan: Use the transform and dimensions to generate 4 corner points
I'm trying to use data returned from the RoomCaptureSession delegate to draw four corners of a door in SceneKit. The CapturedRoom.Surface class has Dimensions and Transform members. I was told in the WWDC 2022 RoomPlan Slack lounge: "You can use transform and dimensions parameters to draw lines. The 4 corners can be inferred from those 2 parameters: the first column of the transform is the "right" vector, and second is the "up" vector. The fourth column is the position of the wall/door/opening/window/object Combining those unit vectors with the dimensions vector will give you the corners." So I think this is a basic vector question. I'm not sure what is meant by "Combining those unit vectors with the dimensions vector". I've tried a few things, but I'm not sure how to go about this.
Replies
5
Boosts
1
Views
2.6k
Activity
Nov ’22
See through walls shader
Hi All I am developing a surveying application on a 3d model, finished developing the measuring module but am having a problem that the scntext added on the scnode root cannot see through the 3d model. I am using the SCNBillboardConstraint contraint to towards the current camera. So is there a way for the scntext to see through or overwrite the model like this? Thank
Replies
0
Boosts
0
Views
593
Activity
Oct ’22
Getting Started with Scene Kit
Hi all, I've got an idea for an interesting twist on a 3d aerial battle game, and so I'm taking the plunge on making my first 3d game. I've got the developer docs queued up and the WWDC videos ready to go, and I've bookmarked a Ray Wenderlich tutorial on SceneKit. Before I get started, since this is all so new to me, do any of y'all have any recommendations for good, up-to-date tutorials or hints and tips that might shortcut any of the process? If it helps, my proof of concept will just allow me to have the player chase a computer-controlled airplane around in 3d space, and view that opponent from the cockpit view. I've already done all my homework on the math of movement in 3d space. Had to dust off some trig, and I haven't worked with radians in a long, long time. But the next step is to get some basic visualizations in, and it looks a little daunting. I truly appreciate any guidance you can point towards!!
Replies
0
Boosts
0
Views
1.2k
Activity
Oct ’22
How to get Vertices of morphed geometry runtime?
I am trying to access vertices of model while changing blendshapes.
Replies
0
Boosts
0
Views
478
Activity
Oct ’22