Apple Engine

Apple, iPhone, iOS, その周辺のことについて

iOS で SceneKit を試す(Swift 3) その24 - ビルトインジオメトリ SCNCylinder(円柱)

円柱のジオメトリ。

f:id:x67x6fx74x6f:20170711183215p:plain

 

Scene Editor でのパラメーター

オブジェクトライブラリの Cylinder を Scene Editor にドラッグ&ドロップして、Attributes Inspector を開く(Command + Option + 4)

1番上の Cylinder の項目で設定値が変更できる

f:id:x67x6fx74x6f:20170711183228p:plain

 

Dimensions

Radius

底の半径。
初期値は 0.5。

 

Height

円柱の高さ。
初期値は 1。

 

Segment Count

Radial

外周部分のポリゴンの分割数。
初期値は 48。

 

Height

円柱の高さの分割数。
初期値は 1。

 

コード

// シーン設定
let scnView = self.view as! SCNView
scnView.showsStatistics = true
scnView.allowsCameraControl = true
scnView.debugOptions = .showWireframe // ワイヤーフレーム表示

let scene = SCNScene()
scene.background.contents = UIColor.white
scnView.scene = scene

// カメラ設定
let cameraNode = SCNNode()
cameraNode.camera = SCNCamera()
cameraNode.position = SCNVector3(2.372,1.473,2.399)
cameraNode.eulerAngles = SCNVector3(-Float.pi * 0.125,Float.pi * 0.25,0)
scene.rootNode.addChildNode(cameraNode)

// ライト設定
let lightNode = SCNNode()
let omniLight = SCNLight()
omniLight.type = .omni
lightNode.light = omniLight
lightNode.position = SCNVector3(0,5,0)
scene.rootNode.addChildNode(lightNode)

// SCNCylinder
let cylinder = SCNCylinder(radius: 0.5, height: 1)

/*
cylinder.radius = 0.5
cylinder.height = 1
*/

cylinder.radialSegmentCount = 48
cylinder.heightSegmentCount = 1

cylinder.firstMaterial?.diffuse.contents = UIColor.black // ワイヤーフレームを見やすくするため黒色に。

let node = SCNNode(geometry: cylinder)
scene.rootNode.addChildNode(node)

 

今回はここまで。