Skip to content

Commit

Permalink
UniVRM 0.80対応
Browse files Browse the repository at this point in the history
  • Loading branch information
gpsnmeajp committed Aug 14, 2021
1 parent e8d6223 commit 8e55aef
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
2 changes: 1 addition & 1 deletion EVMC4U/Editor/Tutorial.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class Tutorial : EditorWindow
static GUIStyle style = new GUIStyle();
static int page = 1;
static AnimFloat anim = new AnimFloat(0.001f);
const bool check = VRMVersion.MAJOR != 0 || VRMVersion.MINOR != 57;
const bool check = VRMVersion.MAJOR != 0 || VRMVersion.MINOR != 80;

[InitializeOnLoadMethod]
static void InitializeOnLoad()
Expand Down
29 changes: 20 additions & 9 deletions EVMC4U/ExternalReceiver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,22 @@
using System;
using System.Reflection;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.Profiling;
using VRM;
using UniGLTF;

namespace EVMC4U
{
//[RequireComponent(typeof(uOSC.uOscServer))]
public class ExternalReceiver : MonoBehaviour, IExternalReceiver
{
[Header("ExternalReceiver v3.7")]
[Header("ExternalReceiver v3.8")]
public GameObject Model = null;
public bool Freeze = false; //すべての同期を止める(撮影向け)
public bool PacktLimiter = true; //パケットフレーム数が一定値を超えるとき、パケットを捨てる
Expand Down Expand Up @@ -152,8 +155,13 @@ public class ExternalReceiver : MonoBehaviour, IExternalReceiver
Vector3 scale;
Vector3 offset;

//同期コンテキスト
SynchronizationContext synchronizationContext;

public void Start()
{
synchronizationContext = SynchronizationContext.Current;

//nullチェック
if (NextReceivers == null)
{
Expand Down Expand Up @@ -663,14 +671,17 @@ public void LoadVRMFromData(byte[] VRMdata)
DestroyModel();

//読み込み
VRMImporterContext vrmImporter = new VRMImporterContext();
vrmImporter.ParseGlb(VRMdata);
GlbLowLevelParser glbLowLevelParser = new GlbLowLevelParser(null, VRMdata);
GltfData gltfData = glbLowLevelParser.Parse();
VRMImporterContext vrmImporter = new VRMImporterContext(gltfData);

isLoading = true;
vrmImporter.LoadAsync(() =>
{

synchronizationContext.Post(async (arg) => {
RuntimeGltfInstance instance = await vrmImporter.LoadAsync();
isLoading = false;
Model = vrmImporter.Root;
Model = instance.Root;
//ExternalReceiverの下にぶら下げる
LoadedModelParent = new GameObject();
Expand All @@ -679,13 +690,13 @@ public void LoadVRMFromData(byte[] VRMdata)
//その下にモデルをぶら下げる
Model.transform.SetParent(LoadedModelParent.transform, false);
vrmImporter.EnableUpdateWhenOffscreen();
vrmImporter.ShowMeshes();
instance.EnableUpdateWhenOffscreen();
instance.ShowMeshes();
//カメラなどの移動補助のため、頭の位置を格納する
animator = Model.GetComponent<Animator>();
HeadPosition = animator.GetBoneTransform(HumanBodyBones.Head).position;
});
}, null);
}

//ボーン位置をキャッシュテーブルに基づいて更新
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ UnityPackage1つで簡単導入、ランタイムでももちろん動作。プ

あなたのしたい表現、使いたい機能、アセットを邪魔しません。
~~Unity5.6.3p1 〜 Unity2019.3(beta)まで動作確認済み(~v3.6)~~
Unity2018.4.23f1 〜 Unity2020.1.2.f1まで動作確認済み(v3.7~)
~~Unity2018.4.23f1 〜 Unity2020.1.2.f1まで動作確認済み(v3.7)~~
Unity2019.4.29f1で動作確認済み(v3.8~)

[VMC Protocol 対応](https://sh-akira.github.io/VirtualMotionCaptureProtocol/)
<img src="https://github.com/gpsnmeajp/EasyVirtualMotionCaptureForUnity/blob/README-image/vmpc_logo_128x128.png?raw=true"></img>
Expand Down

0 comments on commit 8e55aef

Please sign in to comment.