Using SceneKit in Swift Playground -


i've looked everywhere i'm coming blank. how replicate chris lattner demonstrating playgrounds , scenekit @ wwdc? want have scenekit scene, animating, in playgrounds.

i tried cutting , pasting setup code scenekit project template, thinking magically start rendering, not.

i tried watching keynote , pausing , zooming on on lattner's screen looking hints @ source code, appeared importing code elsewhere in project, gave me no clues. there not seem in documentation, or i'm missing it.

since swift doesn't have source compatibility between versions, code in answer might not work in either future or previous versions of swift. has been updated work in xcode 7.0 playgrounds swift 2.0.


the xcplayground framework need, , it documented here.

here simple scene started scene kit in swift:

import cocoa        // (or uikit ios) import scenekit import quartzcore   // basic animation import xcplayground // live preview  // create scene view empty scene var sceneview = scnview(frame: cgrect(x: 0, y: 0, width: 300, height: 300)) var scene = scnscene() sceneview.scene = scene  // start live preview of view xcpshowview("the scene view", view: sceneview)  // default lighting sceneview.autoenablesdefaultlighting = true  // camera var cameranode = scnnode() cameranode.camera = scncamera() cameranode.position = scnvector3(x: 0, y: 0, z: 3) scene.rootnode.addchildnode(cameranode)  // geometry object var torus = scntorus(ringradius: 1, piperadius: 0.35) var torusnode = scnnode(geometry: torus) scene.rootnode.addchildnode(torusnode)  // configure geometry object torus.firstmaterial?.diffuse.contents  = nscolor.redcolor()   // (or uicolor on ios) torus.firstmaterial?.specular.contents = nscolor.whitecolor() // (or uicolor on ios)  // set rotation axis (no angle) able // use nicer keypath below , avoid needing // wrap in nsvalue torusnode.rotation = scnvector4(x: 1.0, y: 1.0, z: 0.0, w: 0.0)  // animate rotation of torus var spin = cabasicanimation(keypath: "rotation.w") // animate angle spin.tovalue = 2.0*m_pi spin.duration = 3 spin.repeatcount = huge // infinity torusnode.addanimation(spin, forkey: "spin around") 

when run it, looks this:

enter image description here


note run scene kit in ios playground, need check "run in full simulator" checkbox.

enter image description here

you find playground setting in utilities pane (0 hide or show)


Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -