Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vrm→bytes→string→bytes→gameobjectの変換 #37

Closed
shinyoshiaki opened this issue Sep 17, 2018 · 2 comments
Closed

vrm→bytes→string→bytes→gameobjectの変換 #37

shinyoshiaki opened this issue Sep 17, 2018 · 2 comments

Comments

@shinyoshiaki
Copy link

vrm→bytes→string→bytes→gameobjectの変換をするとマテリアルが反映されないです。
1

サンプルコード

///////////////////////////////

using System.Collections.Generic;
using UnityEngine;
using UniRx.Async;
using UniRx;
using VRM;
using System.Linq;

public static class Extensions
{
public static IEnumerable<IEnumerable> Chunks(this IEnumerable list, int size)
{
while (list.Any())
{
yield return list.Take(size);
list = list.Skip(size);
}
}
}

public class Vrmtest : MonoBehaviour
{

async void Start()
{
    var path = Application.streamingAssetsPath + "/" + "Inaba-Haneru.vrm";

    var www = new WWW(path);

    await www;

    Debug.Log(www.bytes);
    var go = await VRMImporter.LoadVrmAsync(www.bytes);

    go.transform.position = new Vector3(1, 1, 1);

    var data = bound(divide(www.bytes));
    var second = await VRMImporter.LoadVrmAsync(data);

     second.transform.position = new Vector3(0, 0, 0);
}

string[] divide(byte[] data)
{
    int length = data.Length / (20000);
    var list =new List<string>();
    foreach (var chunk in data.Chunks(20000))
    {
        var bytes = chunk.ToArray();
        list.Add(System.Text.Encoding.Unicode.GetString(bytes));
    }
    return list.ToArray();
}

byte[] bound(string[] arr)
{
    var list = new List<byte>();
    foreach (var str in arr)
    {
        var encode= System.Text.Encoding.Unicode.GetBytes(str);
        foreach(var bit in encode)
        {
            list.Add(bit);
        }
    }             
    return list.ToArray();
}

}

@ousttrue
Copy link
Contributor

var bytes = www.bytes;
var str = System.Text.Encoding.Unicode.GetString(bytes);
var bytesFromStr = System.Text.Encoding.Unicode.GetBytes(str);

using System.LINQ;
var isSame = bytes.SequenceEqual(bytesFromStr); // たぶんfalseになる

バイト列を文字列に変換して、バイト列に再変換すると元に戻らないデス。
Byte列のまま分割してみてください。

@shinyoshiaki
Copy link
Author

    var bytes = www.bytes;
    var str =Convert.ToBase64String (bytes);
    var bytesFromStr =Convert.FromBase64String(str);

base64だと上手くいきました。ありがとうございました。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants