Ejemplo n.º 1
0
    GameObject Load(byte[] bytes)
    {
        Debug.LogFormat("[OnClick] {0}", path);
        var context = new ImporterContext();

        context.ParseGlb(bytes);

        gltfImporter.Load(context);
        context.Root.name = Path.GetFileNameWithoutExtension(path);
        context.ShowMeshes();

        return(context.Root);
    }
Ejemplo n.º 2
0
    GameObject Load(string path)
    {
        var bytes = File.ReadAllBytes(path);

        Debug.LogFormat("[OnClick] {0}", path);
        var context = new ImporterContext();

        var ext = Path.GetExtension(path).ToLower();

        switch (ext)
        {
        case ".gltf":
            context.ParseJson(Encoding.UTF8.GetString(bytes), new FileSystemStorage(Path.GetDirectoryName(path)));
            break;

        case ".zip":
        {
            var zipArchive = UniGLTF.Zip.ZipArchiveStorage.Parse(bytes);
            var gltf       = zipArchive.Entries.FirstOrDefault(x => x.FileName.ToLower().EndsWith(".gltf"));
            if (gltf == null)
            {
                throw new Exception("no gltf in archive");
            }
            var jsonBytes = zipArchive.Extract(gltf);
            var json      = Encoding.UTF8.GetString(jsonBytes);
            context.ParseJson(json, zipArchive);
        }
        break;

        case ".glb":
            context.ParseGlb(bytes);
            break;

        default:
            throw new NotImplementedException();
        }

        gltfImporter.Load(context);
        context.Root.name = Path.GetFileNameWithoutExtension(path);
        context.ShowMeshes();

        return(context.Root);
    }
Ejemplo n.º 3
0
    void GLB(string path)
    {
        var bytes   = File.ReadAllBytes(path);
        var context = new ImporterContext();

        context.ParseGlb(bytes);
        context.LoadAsync(() =>
        {
            context.ShowMeshes();

            var markerM      = Instantiate(MarkerM).transform;
            markerM.name     = "GLB_Root";
            markerM.position = new Vector3(0, -1, 0);
            markerM.gameObject.AddComponent <SaveSceneTarget>().Path = path;
            context.Root.transform.parent = markerM;

            LoadCount++;
        });

        DandD.SetActive(false);
    }