Skip to content

Commit cd7927e

Browse files
authored
Merge pull request #5 from kirurobo/develop
Update VRM viewer
2 parents d2b44af + a73e6c2 commit cd7927e

8 files changed

Lines changed: 145 additions & 12 deletions

File tree

Assets/StreamingAssets/default_vrm.Textures.meta

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
-18.2 KB
Loading

Assets/StreamingAssets/default_vrm.Textures/icon.png.meta

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
-30.4 KB
Binary file not shown.

Assets/StreamingAssets/default_vrm.vrm.meta

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/UniWinApi/Examples/99_VrmViewerSample/VrmSample.cs

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ public class VrmSample : MonoBehaviour {
2626

2727
private CameraController.WheelMode originalWheelMode;
2828

29+
public AudioSource audioSource;
30+
2931

3032
// Use this for initialization
3133
void Start () {
@@ -43,6 +45,11 @@ void Start () {
4345
}
4446
}
4547

48+
if (!audioSource)
49+
{
50+
audioSource = FindObjectOfType<AudioSource>();
51+
}
52+
4653
// Load the initial motion.
4754
LoadMotion(Application.streamingAssetsPath + "/default_bvh.txt");
4855

@@ -119,14 +126,24 @@ private void Window_OnFilesDropped(string[] files)
119126
if (ext == ".vrm")
120127
{
121128
LoadModel(path);
122-
break;
129+
continue;
123130
}
124131

125132
// Open the motion file if its extension is ".bvh" or ".txt".
126133
if (ext == ".bvh" || ext == ".txt")
127134
{
128135
LoadMotion(path);
129-
break;
136+
continue;
137+
}
138+
139+
// Open the audio file.
140+
// mp3はライセンスの関係でWindowsスタンドアローンでは読み込めないよう。
141+
// 参考 https://docs.unity3d.com/jp/460/ScriptReference/WWW.GetAudioClip.html
142+
// 参考 https://answers.unity.com/questions/433428/load-mp3-from-harddrive-on-pc-again.html
143+
if (ext == ".ogg" || ext == ".wav")
144+
{
145+
LoadAudio(path);
146+
continue;
130147
}
131148
}
132149
}
@@ -213,4 +230,37 @@ private void LoadModel(string path)
213230
}
214231
}
215232
}
233+
234+
/// <summary>
235+
/// Load the audio clip
236+
/// Reference: http://fantom1x.blog130.fc2.com/blog-entry-299.html
237+
/// </summary>
238+
/// <param name="path"></param>
239+
private void LoadAudio(string path)
240+
{
241+
StartCoroutine(LoadAudioCoroutine(path));
242+
}
243+
244+
private System.Collections.IEnumerator LoadAudioCoroutine(string path)
245+
{
246+
if (!File.Exists(path)) yield break;
247+
248+
using (WWW www = new WWW("file://" + path))
249+
{
250+
while (!www.isDone) {
251+
yield return null;
252+
}
253+
254+
AudioClip audioClip = www.GetAudioClip(false, false);
255+
if (audioClip.loadState != AudioDataLoadState.Loaded)
256+
{
257+
Debug.Log("Failed to load audio: " + path);
258+
yield break;
259+
}
260+
261+
audioSource.clip = audioClip;
262+
audioSource.Play();
263+
Debug.Log("Audio: " + path);
264+
}
265+
}
216266
}

Assets/UniWinApi/Examples/99_VrmViewerSample/VrmViewerSample.unity

Lines changed: 83 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ MonoBehaviour:
211211
m_Script: {fileID: 11500000, guid: 13bcdf69fdb73ac4388722569c356a3f, type: 3}
212212
m_Name:
213213
m_EditorClassIdentifier:
214-
_isTransparent: 0
214+
_isTransparent: 1
215215
_isTopmost: 1
216216
_isMaximized: 0
217217
_isMinimized: 0
@@ -1824,6 +1824,7 @@ GameObject:
18241824
- component: {fileID: 1787938563}
18251825
- component: {fileID: 1787938568}
18261826
- component: {fileID: 1787938567}
1827+
- component: {fileID: 1787938569}
18271828
m_Layer: 5
18281829
m_Name: Canvas
18291830
m_TagString: Untagged
@@ -1942,6 +1943,87 @@ MonoBehaviour:
19421943
uiController: {fileID: 0}
19431944
cameraController: {fileID: 0}
19441945
cameraTransform: {fileID: 0}
1946+
audioSource: {fileID: 0}
1947+
--- !u!82 &1787938569
1948+
AudioSource:
1949+
m_ObjectHideFlags: 0
1950+
m_PrefabParentObject: {fileID: 0}
1951+
m_PrefabInternal: {fileID: 0}
1952+
m_GameObject: {fileID: 1787938562}
1953+
m_Enabled: 1
1954+
serializedVersion: 4
1955+
OutputAudioMixerGroup: {fileID: 0}
1956+
m_audioClip: {fileID: 0}
1957+
m_PlayOnAwake: 0
1958+
m_Volume: 1
1959+
m_Pitch: 1
1960+
Loop: 0
1961+
Mute: 0
1962+
Spatialize: 0
1963+
SpatializePostEffects: 0
1964+
Priority: 128
1965+
DopplerLevel: 1
1966+
MinDistance: 1
1967+
MaxDistance: 500
1968+
Pan2D: 0
1969+
rolloffMode: 0
1970+
BypassEffects: 0
1971+
BypassListenerEffects: 0
1972+
BypassReverbZones: 0
1973+
rolloffCustomCurve:
1974+
serializedVersion: 2
1975+
m_Curve:
1976+
- serializedVersion: 2
1977+
time: 0
1978+
value: 1
1979+
inSlope: 0
1980+
outSlope: 0
1981+
tangentMode: 0
1982+
- serializedVersion: 2
1983+
time: 1
1984+
value: 0
1985+
inSlope: 0
1986+
outSlope: 0
1987+
tangentMode: 0
1988+
m_PreInfinity: 2
1989+
m_PostInfinity: 2
1990+
m_RotationOrder: 4
1991+
panLevelCustomCurve:
1992+
serializedVersion: 2
1993+
m_Curve:
1994+
- serializedVersion: 2
1995+
time: 0
1996+
value: 0
1997+
inSlope: 0
1998+
outSlope: 0
1999+
tangentMode: 0
2000+
m_PreInfinity: 2
2001+
m_PostInfinity: 2
2002+
m_RotationOrder: 0
2003+
spreadCustomCurve:
2004+
serializedVersion: 2
2005+
m_Curve:
2006+
- serializedVersion: 2
2007+
time: 0
2008+
value: 0
2009+
inSlope: 0
2010+
outSlope: 0
2011+
tangentMode: 0
2012+
m_PreInfinity: 2
2013+
m_PostInfinity: 2
2014+
m_RotationOrder: 0
2015+
reverbZoneMixCustomCurve:
2016+
serializedVersion: 2
2017+
m_Curve:
2018+
- serializedVersion: 2
2019+
time: 0
2020+
value: 1
2021+
inSlope: 0
2022+
outSlope: 0
2023+
tangentMode: 0
2024+
m_PreInfinity: 2
2025+
m_PostInfinity: 2
2026+
m_RotationOrder: 0
19452027
--- !u!1 &1898265829
19462028
GameObject:
19472029
m_ObjectHideFlags: 0

Assets/UniWinApi/Examples/99_VrmViewerSample/readme_jp.txt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@
88

99
## 使い方
1010

11-
解像度を選んで起動後、[End]キーを押してみてください
12-
ウィンドウが透過されれば正常に動作しています。
11+
解像度を選んで起動後、ウィンドウが透過されれば正常に動作しています
12+
1313

1414
### ファイルの読み込み
1515

1616
* VRMファイルをドロップするとモデルを差し替えます。
17-
* BVHファイル(拡張子は .txt でも可)をドロップするとモーションを差し替えます。
17+
* BVHファイル(拡張子は .bvh または .txt で受付)をドロップするとモーションを差し替えます。
18+
* .ogg または .wav のファイルをドロップすると音声を再生します。ただしモーションと同期はしていません。
1819

1920

2021
### ウィンドウ操作
@@ -33,7 +34,7 @@
3334

3435
### 照明操作
3536

36-
* [Shift]を押しながらマウスの右ボタンドラッグでカメラが回転します
37+
* [Shift]を押しながらマウスの右ボタンドラッグでライトが回転します
3738

3839

3940
## ソースおよび配布元

0 commit comments

Comments
 (0)