LoginSignup
7
4

More than 1 year has passed since last update.

VRM1.0を使うメモ(URP対応含む)

Posted at

はじめに

VRM1.0を使ってアバターを読み込む時のメモ書きです。

メモ

VRMの導入

https://github.com/vrm-c/UniVRM/releases/tag/v0.108.0 に従う。

パッケージマネージャーを使うのが楽。Packages/manifest.jsondependenciesに次を追記してEditorを開けば自動インポートが実行される。

ややこしいが、com.vrmc.univrmが0.x系、com.vrmc.vrmが1.x系。混在可能。

// Packages/manifest.json
{
  "dependencies": {
    // ...
    "com.vrmc.vrmshaders": "https://github.com/vrm-c/UniVRM.git?path=/Assets/VRMShaders#v0.108.0",
    "com.vrmc.gltf": "https://github.com/vrm-c/UniVRM.git?path=/Assets/UniGLTF#v0.108.0",
    // VRM 0.x系を使う場合
    "com.vrmc.univrm": "https://github.com/vrm-c/UniVRM.git?path=/Assets/VRM#v0.108.0",
    // VRM 1.x系を使う場合
    "com.vrmc.vrm": "https://github.com/vrm-c/UniVRM.git?path=/Assets/VRM10#v0.108.0",
    // ...
  }
}

VRMを読み込んで扱う

Vrm10.LoadPathAsyncまたはVrm10.LoadBytesAsyncを使えばOK。

pathを渡す場合
Vrm10Instance instance = await Vrm10.LoadPathAsync(@"vrmへのパス", ct: token);
byte[]を渡す場合
byte[] data = await File.ReadAllBytesAsync(@"vrmへのパス");
Vrm10Instance instance = await Vrm10.LoadBytesAsync(data, ct: token);

Vrm10InstanceからVRMの各種コンポーネントへのアクセスが可能。

// Vrm10Instanceから各種情報にアクセス可能
instance.gameObject;
instance.Vrm.Meta;
instance.Runtime;

// ちなみに Vrm10Instance は MonoBehaviourを継承してます

Universal Render PipelineでVRMを使う

URPの環境下でVRMを読み込む場合はマテリアルの設定を変更する必要あり。
とくにUnityEditor上で設定する必要はなく、ロード時にインタフェースへ実装を渡せば
自動でやってくれる。

var instance =
    await Vrm10.LoadPathAsync(path: @"vrmへのパス",
        // materialGeneratorを指定することでURP対応のマテリアルで読み込んでくれる
        materialGenerator: new UrpVrm10MaterialDescriptorGenerator(),
        ct: token);

VRM1.x系ライブラリでVRM0.xのデータを読み込む

VRM 1.0はVRM 0.x系のデータをマイグレーションして読み込むことができる。
ロード時にcanLoadVrm0Xtrueを指定すればよい(なおデフォルトtrue

var instance =
    await Vrm10.LoadPathAsync(path: @"vrmへのパス", 
        canLoadVrm0X: true,
        ct: token);
7
4
0

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
7
4