mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-05-11 21:14:19 -05:00
add simple interface
This commit is contained in:
parent
4e310cd7f2
commit
e63de35a6b
|
|
@ -16,6 +16,22 @@ namespace VRM
|
|||
const string HUMANOID_KEY = "humanoid";
|
||||
const string MATERIAL_KEY = "materialProperties";
|
||||
|
||||
public static GameObject LoadFromPath(string path)
|
||||
{
|
||||
var context = new VRMImporterContext(path);
|
||||
var dataChunk = context.ParseVrm(File.ReadAllBytes(path));
|
||||
LoadFromBytes(context, dataChunk);
|
||||
return context.Root;
|
||||
}
|
||||
|
||||
public static GameObject LoadFromBytes(Byte[] bytes)
|
||||
{
|
||||
var context = new VRMImporterContext();
|
||||
var dataChunk = context.ParseVrm(bytes);
|
||||
LoadFromBytes(context, dataChunk);
|
||||
return context.Root;
|
||||
}
|
||||
|
||||
public static void LoadFromPath(VRMImporterContext context)
|
||||
{
|
||||
var dataChunk = context.ParseVrm(File.ReadAllBytes(context.Path));
|
||||
|
|
@ -456,6 +472,20 @@ namespace VRM
|
|||
yield return null;
|
||||
}
|
||||
|
||||
public static void LoadVrmAsync(string path, Action<GameObject> onLoaded)
|
||||
{
|
||||
var context = new VRMImporterContext(path);
|
||||
var dataChunk = context.ParseVrm(File.ReadAllBytes(path));
|
||||
LoadVrmAsync(context, dataChunk, onLoaded);
|
||||
}
|
||||
|
||||
public static void LoadVrmAsync(Byte[] bytes, Action<GameObject> onLoaded)
|
||||
{
|
||||
var context = new VRMImporterContext();
|
||||
var dataChunk = context.ParseVrm(bytes);
|
||||
LoadVrmAsync(context, dataChunk, onLoaded);
|
||||
}
|
||||
|
||||
public static void LoadVrmAsync(VRMImporterContext ctx, ArraySegment<Byte> chunkData, Action<GameObject> onLoaded)
|
||||
{
|
||||
var schedulable = Schedulable.Create();
|
||||
|
|
|
|||
|
|
@ -171,6 +171,52 @@ namespace VRM
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// メタが不要な場合のローダー
|
||||
/// </summary>
|
||||
void LoadVRMClicked_without_meta()
|
||||
{
|
||||
#if UNITY_STANDALONE_WIN
|
||||
var path = FileDialog("open VRM", ".vrm");
|
||||
#else
|
||||
var path = Application.dataPath + "/default.vrm";
|
||||
#endif
|
||||
if (string.IsNullOrEmpty(path))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
#if true
|
||||
var bytes = File.ReadAllBytes(path);
|
||||
// なんらかの方法でByte列を得た
|
||||
|
||||
if (m_loadAsync)
|
||||
{
|
||||
// ローカルファイルシステムからロードします
|
||||
VRMImporter.LoadVrmAsync(bytes, OnLoaded);
|
||||
}
|
||||
else
|
||||
{
|
||||
var root=VRMImporter.LoadFromBytes(bytes);
|
||||
OnLoaded(root);
|
||||
}
|
||||
|
||||
#else
|
||||
// ParseしたJSONをシーンオブジェクトに変換していく
|
||||
if (m_loadAsync)
|
||||
{
|
||||
// ローカルファイルシステムからロードします
|
||||
VRMImporter.LoadVrmAsync(path, OnLoaded);
|
||||
}
|
||||
else
|
||||
{
|
||||
var root=VRMImporter.LoadFromPath(path);
|
||||
OnLoaded(root);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void LoadAsync(VRMImporterContext context, ArraySegment<byte> dataChunk)
|
||||
{
|
||||
#if true
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user