Apple Engine

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

iOS で SceneKit を試す(Swift 3) その23 - ビルトインジオメトリ SCNCone(円錐)

円錐のジオメトリ。

f:id:x67x6fx74x6f:20170711181712p:plain

 

Scene Editor でのパラメーター

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

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

f:id:x67x6fx74x6f:20170711181725p:plain

 

Dimensions

Top radius

上底の半径。
初期値は 0。

Bottom radius と同じ値にすると円柱になる

f:id:x67x6fx74x6f:20170711181751p:plain

 

Bottom radius

下底の半径
初期値は 0.5。

 

Height

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

 

Segment Count

Radial

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

 

Height

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

 

以下のコードのようにセグメント設定したもの

  • 外周部分 16
  • 高さ 2

f:id:x67x6fx74x6f:20170711181804p:plain

 

コード

// シーン設定
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)

// SCNCone
let cone = SCNCone(topRadius: 0, bottomRadius: 0.5, height: 1)

cone.topRadius = 0
cone.bottomRadius = 0.5
cone.height = 1

cone.radialSegmentCount = 16
cone.heightSegmentCount = 2

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

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

 

今回はここまで。