scenekit

Tap / Select Node in SceneKit (Swift)

大兔子大兔子 提交于 2019-12-04 11:13:02
问题 I'm new to SceneKit and 3D spaces in iOS. I'm currently working on a simple game that shows a cube of 28 segments ("mini cubes" if you want). I want to move the mini cubes by tapping them, but I can't get my head around how to select specific nodes (childnodes of the big cube). Can anybody help me or post a link to SceneKit tutorials for dummies? I've been looking for days now, and haven't found what I'm looking for. Cheers 回答1: You can hit test the scene view (for example from the location

How to add SCNNodes without blocking main thread?

冷暖自知 提交于 2019-12-04 10:34:07
问题 I'm creating and adding a large number of SCNNodes to a SceneKit scene, which causes the app to freeze for a second or two. I thought I could fix this by putting all the action in a background thread using DispatchQueue.global(qos: .background).async() , but no dice. It behaves exactly the same. I saw this answer and put the nodes through SCNView.prepare() before adding them, hoping it would slow down the background thread and prevent blocking. It didn't. Here's a test function that

Using a Metal shader in SceneKit

Deadly 提交于 2019-12-04 09:59:54
I'd like to use a Metal shader to apply a toon/cell shading to materials used in the scene. The shader I'm trying to implement is Apple's own AAPLCelShader found in the MetalShaderShowcase . I'm a little new to implementing shaders in SceneKit so I could be doing everything completely wrong. From what I understand in the documentation a Metal or GL shader can be used to modify SceneKit rendering as of iOS 9 and Xcode 7. The documentation suggests that this is done in the same way as GL shaders. My method is to try and get the path for the .metal file and then load it into a string to be used

Custom Shader SCNProgram iOS 9 Scenekit

六眼飞鱼酱① 提交于 2019-12-04 08:32:11
问题 I am trying to mess around in SceneKit and teach myself it. Basically, I am creating a quad with 3 rectangular sides and 1 sloping slide. I want my texture on it to stretch and warp/deform across the surface. Reading some stuff online, it seems that I need to make an SCNProgram with custom vertex and fragment shaders to get the effect. But, I can't seem to get the texture to spread across the surface. Need help please. (I am new to graphics programming hence trying to teach it to myself). My

How to avoid roll in SceneKit camera controlled by Core Motion?

孤人 提交于 2019-12-04 07:29:24
I'm setting my SceneKit camera to the current CMDeviceMotion attitude using the CMDeviceMotion extension described in this answer : func deviceDidMove(motion: CMDeviceMotion?, error: NSError?) { if let motion = motion { let orientation = motion.gaze(atOrientation: UIApplication.sharedApplication().statusBarOrientation) cameraNode.orientation = orientation } } This works beautifully, however, I'd like to block the rotation (roll) and only allow the camera to turn around (yaw) and pitch. I tried to convert the quaternion back to Euler angles and simply leave roll at 0: cameraNode.eulerAngles =

swift/scenekit problems getting touch events from SCNScene and overlaySKScene

丶灬走出姿态 提交于 2019-12-04 06:52:10
Good afternoon, I'm trying to figure out how to get touch notifications from an SCNNode & a SKSpriteNode from an SCNScene overlayed with a SKScene. import UIKit import SceneKit class GameViewController: UIViewController { var scnView:SCNView! var scnScene:SCNScene! var sprite: spritekitHUD! var cameraNode: SCNNode! var shape: SCNNode! override func viewDidLoad() { super.viewDidLoad() setupScene() } func setupScene() { scnView = self.view as! SCNView scnView.delegate = self scnView.allowsCameraControl = true scnScene = SCNScene(named: "art.scnassets/scene.scn") scnView.scene = scnScene sprite

Simulating refraction in SceneKit

痞子三分冷 提交于 2019-12-04 06:51:05
I am trying to create an ios 9 app for a project which will visualise 3d scenes with these special kind of theoretical lenses called glenses . A ray tracing program called TIM has already been written from the ground up for simulating these glenses and more, but it's infeasable to simply port this to ios. My understanding from searching the site (i.e. this answer and many others on shaders) is that it should be possible but I'm having a hard time getting the desired effect. I decided that I would start by implementing a simpler form of refraction first before moving onto the more complex glens

Swift Scenekit - Centering SCNText - the getBoundingBoxMin:Max issue

微笑、不失礼 提交于 2019-12-04 06:41:35
Having fun with the alignmentMode option on SCNText. Been googling around and it looks like there is a problem with alignmentMode and containerFrame. The alternatives I've found suggest using the get bounding box function to find the text size and then manually adjust accordingly. Great except I cant get the function to work. When I try to get the two vectors I get an error: 'SCNVector3' is not convertible to 'UnsafeMutablePointer < SCNVector3>' I get that both on the geometry and the node. example of the code is below func setCounterValue(counterValue:Int) { var v1 = SCNVector3(x: 0,y: 0,z: 0

SceneKit load node with animation from separate scn file

我与影子孤独终老i 提交于 2019-12-04 06:41:32
I have a view that creates SCNView dynamically. It's scene is empty, but when I press a button I would like to add a node from separate scn file. This file contains animation, and I would like it to animate in main scene. The problem is that after adding object to the scene it's not animating. When I use this file as SCNView scene it works. isPlaying and loops are enabled. What else do I need to do to import such node with animation? Sample code below: override func viewDidLoad() { super.viewDidLoad() let scene = SCNScene() let sceneView = SCNView(frame: CGRect(x: 0, y: 0, width: 300, height:

Applying simple Physics to a .scn object in SceneKit XCODE SWIFT

会有一股神秘感。 提交于 2019-12-04 06:04:28
问题 Hey Below I have a normal sphere that I created just to test if my in game scene/world has physics. So I simply put the ball in the scene/world and it is perfect. It is affected by the gravity. So then I try to do the exact same thing to the .scn file. I give it physics the same as the test sphere that falls down do to gravity. but the man doesn't move. The gravity is set to -9.8 to simulate regular gravity Code: //----Test-Circle-here-------------------- var sphere1: SCNNode! let