Apple Engine

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

iOS で SceneKit を試す(Swift 3) その26 - ビルトインジオメトリ SCNPyramid(三角錐)

三角錐のジオメトリ。

f:id:x67x6fx74x6f:20170712150311p:plain

 

Scene Editor でのパラメーター

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

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

f:id:x67x6fx74x6f:20170712150329p:plain

 

Size

幅、高さ、奥行きが設定できる。 初期値は 1。

 

Segment Count

幅、高さ、奥行きの分割数。 初期値は 1。

 

幅、高さ、奥行きの分割数 4。

f:id:x67x6fx74x6f:20170712150348p: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)

// SCNPyramid
let pyramid = SCNPyramid(width: 1, height: 1, length: 1)

/*
pyramid.width = 1
pyramid.height = 1
pyramid.length = 1
*/

pyramid.widthSegmentCount = 4
pyramid.heightSegmentCount = 4
pyramid.lengthSegmentCount = 4

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

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

 

今回はここまで。