LoginSignup
2

More than 5 years have passed since last update.

UnityのVRTKでアウトラインを表示する。

Last updated at Posted at 2018-04-24

VRTKのVRTK_OutlineObjectCopyHighlighterを使う。

開発環境

・Unity2017.1.0f3
・SteamVR
・VRTK

はじめに

プロジェクトを作成後、SteamVRとVRTKをインポートしておく。
VRTKのセットアップが面倒な場合、適当なサンプルシーンから
[VRTK_Scripts]と[VRTK_SDKManager]を使うシーンにコピペすればVRTKが使えて楽。

アウトラインの表示

表示したいオブジェクトをシーンに配置した後
VRTK_OutlineObjectCopyHighlighterをアタッチ。(Add Componentから"outline"を検索ですぐ出てくる)
2018-04-24 20_00_52-Unity 2017.1.0f3 Personal (64bit) - Outline.unity - WhiteVR - PC, Mac & Linux St.png

その後アウトラインを表示するスクリプトを書く。

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using VRTK.Highlighters;  //usingは忘れがちなので忘れずに

public class SetOutline : MonoBehaviour {

  VRTK_OutlineObjectCopyHighlighter vrtk_outline;

  void Start ()
  {
    vrtk_outline = GetComponent<VRTK_OutlineObjectCopyHighlighter>();
    vrtk_outline.Initialise();
    Color color = Color.black;
    vrtk_outline.Highlight(color);
  }
}

vrtk_outline.Initialise()を実行してvrtk_outline.Highlight()で表示する。

2018-04-24 20_22_56-Unity 2017.1.0f3 Personal (64bit) - Outline.unity - WhiteVR - PC, Mac & Linux St.png

こんな感じで表示されます。(Ticknessの値は左が1、右が0.5)

今回はStart()に書いたので最初から表示されるが、任意のタイミングで表示、非表示も可能。

※"アウトラインを適用したオブジェクト同士"が重なる部分は、アウトラインが表示されない。
なので一度に複数のモデルに適用するのは避けたほうがいいかもしれない。

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2