Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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)
@duncanmak

This comment has been minimized.

Copy link

duncanmak commented Jul 1, 2014

Why use |> in CreateDiffuseLightNode, couldn't it be a lot more straight-forward to write it like this?

 let CreateDiffuseLightNode (color: UIColor, position: SCNVector3, lightType: NSString): SCNNode = 
        new SCNNode (
            Light = new SCNLight ( Color = color, LightType = lightType ), 
            Position = position )
@7sharp9

This comment has been minimized.

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
You can’t perform that action at this time.