Skip to content

Instantly share code, notes, and snippets.

@mikebluestein
Last active August 29, 2015 14:03
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mikebluestein/f6a56e758fe307c25068 to your computer and use it in GitHub Desktop.
Save mikebluestein/f6a56e758fe307c25068 to your computer and use it in GitHub Desktop.
namespace FSHelloSceneKit
open System
open MonoTouch.UIKit
open MonoTouch.Foundation
open MonoTouch.SceneKit
type FSHelloSceneKitViewController () =
inherit UIViewController()
let CreateDiffuseLightNode (color: UIColor, position: SCNVector3, lightType: NSString): SCNNode =
new SCNLight ( Color = color, LightType = lightType )
|> fun lightNode -> new SCNNode ( Light = lightNode, Position = position )
override this.ViewDidLoad () =
let scene = new SCNScene ()
let view = new SCNView (this.View.Frame, Scene = scene, AutoresizingMask = UIViewAutoresizing.All, AllowsCameraControl = true)
new SCNCamera (XFov = 40.0, YFov = 40.0)
|> fun c -> new SCNNode (Camera = c, Position = new SCNVector3(0.0F, 0.0F, 40.0F))
|> scene.RootNode.AddChildNode
let material = new SCNMaterial ()
material.Diffuse.Contents <- UIImage.FromFile ("monkey.png")
material.Specular.Contents <- UIColor.White
new SCNNode( Geometry = SCNSphere.Create(10.0F), Position = new SCNVector3(0.0F, 0.0F, 0.0F) )
|> fun node -> node.Geometry.FirstMaterial <- material; node
|> scene.RootNode.AddChildNode
new SCNLight ( LightType = SCNLightType.Ambient, Color = UIColor.Purple)
|> fun lightNode -> new SCNNode ( Light = lightNode )
|> scene.RootNode.AddChildNode
[|
( UIColor.Blue, new SCNVector3 (-40.0F, 40.0F, 60.0F) );
( UIColor.Yellow, new SCNVector3 (20.0F, 20.0F, -70.0F) );
( UIColor.Red, new SCNVector3 (20.0F, -20.0F, 40.0F) );
( UIColor.Green, new SCNVector3 (20.0F, -40.0F, 70.0F) )
|]
|> Seq.map (fun (color, pos) -> CreateDiffuseLightNode(color, pos, SCNLightType.Omni))
|> Seq.iter scene.RootNode.AddChildNode
this.View.Add(view)
@7sharp9
Copy link

7sharp9 commented Jul 1, 2014

I dont like the lambda piping either, the functions are so short they can be inline as @duncanmak said.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment