SceneKitでビルボードを使用する場合
板ポリゴンを常にカメラに向けたい場合がある。
主に
・簡易的なパーティクルを表示させたい
・テキストをキャラの上に表示させて常にカメラの向きにテキストを向けさせたい
これらの用途をすぐに思い浮かぶことができます。
SceneKitの情報特にビルボードの情報がほぼ見当たらなかったので
情報を公開します。
xxxxxx.m
//板ポリの作成
SCNPlane *plane = [SCNPlane planeWithWidth:6 height:6];
plane.firstMaterial.diffuse.contents = [UIColor redColor];
SCNNode *planeNode = [SCNNode node];
planeNode.geometry = plane;
planeNode.position = SCNVector3Make(0, 4, 0);
[scene.rootNode addChildNode:planeNode];
//ビルボードの設定
SCNBillboardConstraint *billboard = [SCNBillboardConstraint billboardConstraint];
planeNode.constraints = @[billboard];
余談:
SCNLookAtConstraint というのもある。
これは、あるノードに向きを向けるものでビルボードとは異なるので注意
xxxxxx.m
SCNLookAtConstraint *constraint = [SCNLookAtConstraint lookAtConstraintWithTarget:* 向きを向けたいSCNNode *];
SCNBillboardConstraint *billboard = [SCNBillboardConstraint billboardConstraint];
planeNode.constraints = @[constraint /*,billboard*/];