Apple Engine

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

iOS で SceneKit を試す(Swift 3) その28 - ビルトインジオメトリ SCNTorus(ドーナツ型)

ドーナツ型のジオメトリ。

f:id:x67x6fx74x6f:20170712155744p:plain

 

Scene Editor でのパラメーター

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

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

f:id:x67x6fx74x6f:20170712155804p:plain

 

Dimensions

Ring Radius

オブジェクト全体の半径。
初期値は 1。

球と同様に半径であるため倍の大きさになる。  

Pipe Radius

ドーナツのパイプ状になっている部分の半径。
初期値は 0.25。

値を大きくするとリング部分が大きくなり、穴は小さくなる。

 

Segment Count

Scene Editor では初期値が 0 になっている。

 

Ring

外周の分割数。
初期値は 48。

 

Pipe

ドーナツのパイプ状になっている部分の分割数。
初期値は 24。

 

外周を 16、パイブ部分を 8 の分割数を設定したもの。

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

// SCNTorus
let torus = SCNTorus(ringRadius: 1, pipeRadius: 0.25)

/*
torus.ringRadius = 1
torus.pipeRadius = 0.25
*/

torus.ringSegmentCount = 16
torus.pipeSegmentCount = 8

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

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

 

今回はここまで。