FAQ Database Discussion Community


Node group's position is reset at the start of SCNNode.runAction

ios,swift,scenekit,scnnode
I have some code that rotates several SCNNodes around the x axis when the screen is tapped like so: func handleTap(gestureRecognize: UIGestureRecognizer) { let sceneView = self.view as SCNView let slice = self.cubes[0...8] let container = SCNNode() for node: SCNNode in slice { container.addChildNode(node) } sceneView.scene!.rootNode.addChildNode(container) container.runAction(SCNAction.rotateByX(CGFloat(M_PI / 2), y:...

Can I use a PNG sequence as an animated material on a SceneKit object?

ios,animation,3d,scenekit
I'd like to programmatically change the material of an object rendered using SceneKit in iOS. But I would like to use animated image files. PNG sequences work great in iOS for stuff like UIImageViews -- how do I use them as a material in SceneKit? Something like this doesn't work:...

Xcode Scene Editor - How do you display entities list?

ios,xcode,scenekit,skscene
I cannot find a way to display the entities list on xcode as shown in this picture from Apple website:

SceneKit + Collada + animation

objective-c,animation,blender,scenekit,collada
I am trying to use Apple's SceneKit in order to load a model from Blender in Collada (dae) format, then apply animation on it from another Collada file, just like Apple did in their Banana example. I can do this with their models and animation files, however, if I open...

Is there a way to use height map with scene kit iOS?

ios,xcode,xcode6,scenekit
Can I use height map with scene kit? Is there a function or api that I can use to achieve that? I would like to make a game and it would really help me....

How can I zoom a camera in the direction it is facing?

swift,matrix,3d,camera,scenekit
I am making a 3d game in swift using scenekit. I have a pinch gesture recognizer so that the user can zoom in/out when they pinch. I can easily access the current x,y,z coordinates as well as the rotation around each axis. My problem is actually working out where to...

SCNNode material scale

scale,scenekit,material,scnnode
I have an SCNNode that has its geometry populated from a collada file (.dae) and displays correctly on screen. I can apply materials to the geometry easily enough, however I'd like to change the scale of the material. I currently populate it with nodeArray[0].geometry?.firstMaterial!.diffuse.contents="wood.png" but the scale of the material...

SceneKit – Display multiple scenes in same SCNView

ios,swift,scenekit,scene
Is there a way I can display multiple scenes in the same SCNView at the same time? So let's say I have a ball in ball.dae and a pyramid in pyramid.dae. So these are separate scenes and I would like to show both at the same time. Currently I only...

Using shader modifiers to animate texture in SceneKit leads to jittery textures over time

ios,objective-c,opengl-es,scenekit
I'm writing a scene in SceneKit for iOS. I'm trying to apply a texture to an object using a sprite sheet. I iterate through the images in that sheet with this code: happyMaterial = [SCNMaterial new]; happyMaterial.diffuse.contents = happyImage; happyMaterial.diffuse.wrapS = SCNWrapModeRepeat; happyMaterial.diffuse.wrapT = SCNWrapModeRepeat; happyMaterial.shaderModifiers = @{ SCNShaderModifierEntryPointGeometry :...

Have SCNCamera follow a node at a fixed distance?

ios,scenekit
I have a SCNNode, and an SCNCamera. The camera is located up and in front of the node, and looks down on the node via an SCNLookAtConstraint that I have setup. However when the node moves laterally, the camera only rotates, instead of moving with the it. Is there any...

Combining two or more SCNGeometries

ios,objective-c,xcode,scenekit
I made this method to grab a UIImage and turn it into a 3D model. However that means I add in a whole lot of nodes.. I was thinking maybe it could be optimized by adding all the geometries into a single node. Is there a way to accomplish that?...

SceneKit material being filled with random patterns, why?

ios,swift,scenekit
I have a simple touch detection method that should change the color of the node being touched. override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) { super.touchesBegan(touches, withEvent: event) let touch = touches.first as! UITouch let point = touch.locationInView(view) let options: [NSObject : AnyObject] = [ SCNHitTestFirstFoundOnlyKey: NSNumber(bool: true), SCNHitTestSortResultsKey: NSNumber(bool:...

SCNNode getBoundingBoxMin

objective-c,scenekit,scnnode
I have a node that I'm extracting from an SCNScene. I've got some information about it, but I'm confused about one thing - how the bounding box is calculated. The node is positioned once it is loaded at vector 0,0,0 using: [myNode setPosition: SCNVector3Make(0, 0, 0)]; However, the bounding box...

SCNTransaction not animating correctly in Scene Kit SWIFT

ios,swift,animation,translation,scenekit
I'm trying to move an object over a period of ten seconds from y coordinate 0 to y coordinate 10. the object is created at y coordinate 0. The problem is when the animation starts, the object pops to the end position for like one second or so then pops...

Cloning nodes and performance, geometry, and performance; IOS Scenekit

ios,scenekit
I'm writing a app using Scenekit where the client wishes to push the limits of animation in IOS. This particular app has requirements where I"m pushing out to the screen over 1,500 redraws. Even with this many redraws, I've locked down the FPS to 60, which is great, but when...

Accelerate/Scenekit Framework:: Where's the math matrix/vector lib for 3d and 4d vectors?

ios,swift,scenekit,accelerate-framework
I'm looking at this https://developer.apple.com/library/mac/documentation/SceneKit/Reference/SceneKit_Functions/index.html Aren't basic operations supported? var t:SCNVector3 = SCNVector3(x: 0,y: -1,z: 2) var a:SCNVector3 = SCNVector3(x: 1,y: -2,z: -2) var b:SCNVector3 = t + a or do I need to create my own operations C-style? Where are the math vector/matrix functions like transpose? inverse? add? blas?...

Recursion:: How to create a mini-view of 3d scenekit of self on top of self?

ios,swift,scenekit,hud
I have a 3d world with SceneKit, works great, can pan, zoom in/out but I want to create a mini-view of the 3d world on top of the larger 3d world. So if the user zooms in to a very fine resolution they still know where they are in space....

SceneKit camera rotation wrong although camera and nodes share origin

ios,swift,scenekit
I am playing with SceneKit trying to make a star field. Here are some sample stars with coordinates: Name: Alpheratz, X: 25.9746 Y: 0.951042 Z: 14.4613 Name: Caph, X: 8.60001 Y: 0.344589 Z: 14.4095 Name: Algenib, X: 115.664 Y: 6.68732 Z: 31.4421 Name: Ankaa, X: 19.0837 Y: 2.19828 Z: -17.4833...

Capturing screen with mixed view controllers, 3d scene kit, uiwebkit

ios,swift,uiviewcontroller,cgcontext,scenekit
My iPad app can do a screen capture of all view controllers displayed except for a 3d scenekit VC. Here is my code for capturing the screen @IBAction func screenImage(sender: UIBarButtonItem) { //Create the UIImage UIGraphicsBeginImageContext(view.frame.size) view.layer.renderInContext(UIGraphicsGetCurrentContext()) let screenshot: UIImage = UIGraphicsGetImageFromCurrentImageContext() UIGraphicsEndImageContext() //Save it to the camera roll UIImageWriteToSavedPhotosAlbum(screenshot,...

How to programmatically wrap png texture around cube in SceneKit

ios,osx,opengl,swift,scenekit
I'm new to SceneKit... trying to get some basic stuff working without much success so far. For some reason when I try to apply a png texture to a CNBox I end up with nothing but blackness. Here is the simple code snippet I have in viewDidLoad: let sceneView =...

Convert an image to a SceneKit Node

ios,objective-c,opengl-es,3d,scenekit
I have a bit-map image: ( However this should work with any arbitrary image ) I want to take my image and make it a 3D SCNNode. I've accomplished that much with this code. That takes each pixel in the image and creates a SCNNode with a SCNBox geometry. static...

How can I use OBJ file or CTM file instead of DAE file in SceneKit?

ios,3d,scenekit
I used to render 3d scene with openGL and metal on IOS, and the file format which I used was OBJ and CTM. These days I am trying Scene Kit. It seems that SceneKit only load DAE file. All the demos I can found on the Internet use DAE file...

How to convert from ModelIO MDLMesh to SceneKit SCNGeometry and back?

ios,objective-c,swift,scenekit,modelio
Apple have recently announced Model I/O Framework and, understandably, documentation is currently quite sparse with many classes still not fully documented. The Model I/O talk suggests a two-way link between SceneKit classes and Model I/O classes, but I can't find a way to do this in practice. SCNGeometry has a...

What is the difference of shaders with extensions .Shader, .vsh, .fsh?

ios,glkit,scenekit
What is the difference between files named "name. Shader" & "name. vsh" & "name. fsh" in scene kit ?when i call some shaders in my project my model would be like a purple mask. What should i do?

Toon.shader not finding _light var

ios,objective-c,opengl-es,glsl,scenekit
So I'm loading my custom shader in Apple's SceneKit by doing. - (NSDictionary *)celShading { NSMutableDictionary *shaders = [NSMutableDictionary new]; shaders[SCNShaderModifierEntryPointFragment] = [NSString stringWithContentsOfURL:[[NSBundle mainBundle] URLForResource:@"toon" withExtension:@"shader"] encoding:NSUTF8StringEncoding error:NULL]; return shaders; } My custom shader is toon.shader vec3 lDir = normalize(vec3(0.1,1.0,1.0)); float dotProduct = dot(_surface.normal,lDir); _lightingContribution.diffuse += (dotProduct * dotProduct...

Can't display 3d file from cache directory

ios,objective-c,xcode,scenekit,collada
Can you please help me determine the problem here? It seems that I can't display the 3d file from cache directory. I'm having this error SceneKit IO: error, COLLADA files are not supported on this platform. The zip file im saving in the cache directory contains .dae file and .png...

SceneKit crash on iPad Air 2

swift,ios8,scenekit
I am developing an iPad App using SceneKit. It is still under development, but I have a few users testing via TestFlight. One user has an iPad Air 2 which is consistently crashing. The App works OK on my iPad Air, a number of iPad 2 devices and the iPad...

How to update SceneKit nodes to 'automatically' reflect underlying model?

swift,cocoa-touch,scenekit,reactive-cocoa
What is the most sensible way of locating, updating, and/or adding or removing SceneKit nodes that correspond to an underlying model when that model is updated? I'm not sure how best to word this question, so it's probably easier to have a minimal example: I have something, let's say a...

Write text on sphere surface SceneKit?

ios,scenekit
I am wondering if there is a way to write text along a surface of a sphere object in SceneKit. I know I put a texture on the surface and achieve this kind of effect if I have an image, but I want to know if I can just add...

Color line in scene kit?

ios,scenekit
I am using the following code to draw a line between two nodes: class func lineBetweenNodeA(nodeA: SCNNode, nodeB: SCNNode) -> SCNNode { let positions: [Float32] = [nodeA.position.x, nodeA.position.y, nodeA.position.z, nodeB.position.x, nodeB.position.y, nodeB.position.z] let positionData = NSData(bytes: positions, length: sizeof(Float32)*positions.count) let indices: [Int32] = [0, 1] let indexData = NSData(bytes: indices,...

Apparent indices limit

ios,swift,scenekit
Using SceneKit in swift I trying to build a custom 3D object (a terrain). To build a terrain I build a plane that I've divided in a number of horizontal and vertical section. With a small number or section everything is fine but with not so large number the app...

when dynamic body falls down, its `_ball.position.y` value doesn't change

scenekit
I have pretty simple question - func setupScene() { let sceneView = view as SCNView sceneView.backgroundColor = SKColor.blackColor() _scene = SCNScene() sceneView.scene = _scene sceneView.showsStatistics = true // Scene gravity sceneView.scene?.physicsWorld.gravity = SCNVector3Make(0, -70, 0) sceneView.scene?.physicsWorld.speed = 2.0 sceneView.delegate = self } At some point of time have spawnBall method:...

Wall collisions in scene kit

objective-c,scenekit
I'm trying to write a game where a node can move about but is contained by a series of walls- basically a maze game. Just to get the basic thing going I pulled apart Apple's SceneKitVehicle project (https://developer.apple.com/library/ios/samplecode/SceneKitVehicle) to just the basic elements and put in a cube (the box...

How to setup camera to point at object

ios,3d,scenekit
In my app I load models from different files (format is the same) and they have different geometry: big, small, wide, etc. I have object and camera position hard coded and for some cases I don't see anything because camera not point to object. Maybe there is a way to...

DAE file specified in attribute inspector is not loaded by UIViewController

swift,xcode6,interface-builder,scenekit
I created a new project using the iOS game template on Xcode 6.1.1, the options were: Language: Swift Game Technology: SceneKit Device: Universal The app runs ok "as is", but now I want to specify the .dae file directly from the Interface Builder on Xcode, so I changed the method...

Is there a way to draw a SCNNode always in front of others?

swift,scenekit,scnnode
Good evening everyone,I've been trying to make a scene with scene kit in which an specified object is always in front of others, despite the fact that it's actually behind the other objects. A similar effect to this used in blender. Apparently, blender uses GUI and a lot of math...

Material only attaches to half of the textures on geometry

ios,swift,scenekit,scnnode
My materials are only applying to half of the faces. Here is my code: let boxGeometry = SCNBox(width: 10, height: 10, length: 10, chamferRadius: 0) let boxNode = SCNNode(geometry: boxGeometry) boxNode.position = SCNVector3Make(0, 0, -20) boxNode.runAction(SCNAction.repeatActionForever(SCNAction.rotateByX(1, y: 2, z: 0, duration: 1))) boxNode.geometry?.firstMaterial?.diffuse.magnificationFilter = SCNFilterMode.Nearest boxNode.geometry?.firstMaterial?.diffuse.minificationFilter = SCNFilterMode.Nearest var texture...

Get width/height of SCNText Geometry

ios,swift,scenekit
I'm looking for a possibility to calculate the size of an SCNText Geometry. I want to make a row of individual text nodes that have a frame around the text. Let's say the text has 5pt width. I want a SCNPlane as background with a width of 7pt and the...

Could someone explain why/how this sample scene kit code works?

ios,scenekit
I am working with scene kit and am trying to make a first person game. I found this sample code for making the first person camera with a pan gesture. Everything works but I do not understand what is going on here. Could someone explain what is happening? func lookGestureRecognized(gesture:...

Rotate a node so it points to a specific position in SceneKit

scenekit
I have a node and I want it's peak point to a specific position (coordinates). How can I do that? So far, I have tried noting because I have no clue how can I do that. Any suggestions?

SKScene becomes unresponsive while being idle

swift,sprite-kit,scenekit,skscene
Hello I have a SceneKit game. All the game play is in one scene and when the game is over the sprit kit overlay acts as a game over screen and when they hit play again the sprite kit labels disappear and the game resets all in the same scene....

Need help explain about normal vector SceneKit

ios,vector,opengl-es,scenekit
I follow this article to create a custom SCNGeometry http://ronnqvi.st/custom-scenekit-geometry/ I see it need normal vector for every vertex. I also see the document here https://developer.apple.com/library/prerelease/ios/documentation/SceneKit/Reference/SCNGeometrySource_Class/index.html In my knowledge, I think 3 vertices identify one plane and one plane need only 1 normal vector. So each 3 vertices we need...

SceneKit crash in unknown (internal?) method

ios,scenekit
I'm trying to integrate some third-party SceneKit code into my app, and I'm experiencing a mysterious crash. Oddly, the crash gives no error or log in Xcode, and the stack trace is just "UIApplicationMain". No helpful info there. The code works in the third-party app where I got it and...

How do you remove a node?

scenekit
May I get an example? To add a node, I do this: let thisNode = thisScene.rootNode.childNodeWithName("someGraphic", recursively: true) scene.rootNode.addChildNode(thisNode!) Now how do I remove it? I've read this backwards and forwards and still can't do it....

Make a line thicker in 3D?

ios,swift,opengl-es,scenekit
In reference to this question Drawing a line between two points using SceneKit I'm drawing a line in 3D and want to make it thicker by using this code func renderer(aRenderer: SCNSceneRenderer, willRenderScene scene: SCNScene, atTime time: NSTimeInterval) { //Makes the lines thicker glLineWidth(20) } but it doesn't work, iOS...

Get size of dae node

scenekit
Suppose I have a collada file which has a box in it and I import the dae file into the scene. Now after importing in the scene I know the dae object is a box. How can I get the dimensions of the box in scenekit after adding it to...

SceneKit camera shows extra space when it should not

ios,swift,scenekit
Update I have uploaded the project to GitHub for easy replication of the problem. Question I have a test scene, where I want to position an object (a SCNBox in this case) to be as wide as the screen. Here's the entirety of the code. let scene = SCNScene() let...

Unwrapping SCNVector3/SCNVector4 values to print?

ios,swift,scenekit
This should be an easy question import SceneKit import Accelerate var str:SCNVector3 = SCNVector3Make(1, 2, -8) println("vector \(str)" answer vector C.SCNVector3 How to unwrap and display the vector like [ 1, 2, -8]?...

How can I remove all nodes from a scenekit scene?

swift,nodes,reset,scenekit
Hi I am trying to remove all nodes from my Scenekit scene but I cannot for the life of me figure out a way. It seems logical to me that there must be a function for doing this automatically but I cannot find it. In context, I am trying to...

How do I run a segment of code every frame with Scene Kit?

ios,swift,scenekit
Scene kit doesn't have an update function, so how would I implement a simple if statement every frame. For instance, to see if an object is at rest before the frame is rendered? I'm programming in swift.

Adding and transitioning animations in SceneKit

swift,scenekit
I looked at Banana game from WWDC which is written in Objective - C was trying to convert the code to swift for importing animation and transitioning between them but I am having problems running the animations in swift from DAE files. I have exporter DAE files in both AutoDesk...

Interactive 3d model for iPad

ios,swift,3d,scenekit,metal
Similar to this question Interactive 3D model without WebGL for iOS I don't want to go down the webview/javascript path. I want something like this http://appserv.kfshrc.edu.sa/Default/Health/Anantomy.aspx in native Metal or Scenekit written in Swift. I've searched github but haven't come across anything. Is this even possible? Reading through the SDKs,...

I need help to draw an icosahedron 3D object in an UIKit app

ios,3d,scenekit
Although I am quite experienced with most frameworks in iOS, I have no clue when it comes to 3D modelling. I even worked with SpriteKit, but never with something like SceneKit. Now a customer wants a very ambitious menu involving a 3D object, an 'icosahedron' to be exact. I want...

Convert local coordinates to scene coordinates in SceneKit

global,local,scenekit,coordinate
I have a node attached to a node and I want to convert it's coordinates to coordinates of scene. I really don't know how to do that. I've been searching on Apple's documentation and I haven't found a method that fits my need. Any suggestions?

Animating a model in SCNScene using SCNMorpher

animation,scenekit
I have an SCNNode that I've created from a custom model mesh and a SCNGeometry. This custom model also includes a set of animations in the form of vertex target frames that I've converted into an NSArray of SCNGeometry. I'd like to now animate the parent node using the set...

How can I create SCNode with non-predefined number of vertices?

ios,objective-c,scenekit
I have an array with SCNVector3 vertices that describes trajectory path. And I want to draw its path. - (SCNNode *)lineNodeFromVertices:(SCNVector3 *)vertices count:(NSUInteger)count { NSInteger numberOfVertices = (count - 1) * 2; int *verticesSequence = calloc(numberOfVertices, sizeof(int)); for (int index = 0; index < count; index ++) { if (index...

Scene Kit: projectPoint calculated is displaced

ios,swift,uiview,scenekit
I am trying do draw an frame over a sphere on the parent view of the scene, but for some reason the points converted by SCNScene.projectPoint method are displaced. To make it simple, i created a sphere at the center of the scene with 2 radius. The sphere is attached...

How can I smoothly transition between two separate animations in SceneKit?

animation,scenekit
I am working with a 3d model that has one CAAnimationGroup per animation, with each group containing SCNMorpher weight animations with 2 CABasicAnimations per frame (to transition from weights of 1.0 to 0.0 and 0.0 to 1.0 for each frame and the next using interpolation). My animations are running smoothly,...