v0.82.1 GlbImport GltfData

Load it in the following steps.

  1. Parse GLB / GLTF to get GltfData.

  2. Load the Unity Hierarchy from GltfData. Get a RuntimeGltfInstance.Destroy the loader.

  3. Use the loaded RuntimeGltfInstance. Destroy RuntimeGltfInstance.

1. パースする

Parse from glb file path

  • vrm also uses this function.

GltfData Load(string path)
{
    return new GlbFileParser(path).Parse();
}

parse glb bytes

  • vrm also uses this function.

GltfData Load(byte[] bytes)
{
    return new GlbBinaryParser(bytes, "LOAD_NAME").parse();
}

Parse from gltf file path

GltfData Load(string path)
{
    return new GltfFileWithResourceFilesParser(path).Parse();
}

Parse from zip archive

Can parse zip archives of gltf and related files (experimental).

GltfData Load(string path)
{
    return new ZipArchivedGltfFileParser(path).Parse();
}

Parse by file path extension

Please refer to the sample SimpleViewer.

GltfData Load(string path)
{
    // ファイル拡張子で自動判定します
    return new AutoGltfFileParser(path).Parse();
}

2. ロードする

sync

RuntimeGltfInstance Load(GltfData data)
{
    // ImporterContext は使用後に Dispose を呼び出してください。
    // using で自動的に呼び出すことができます。
    using(var loader = new UniGLTF.ImporterContext(data)
    {
        var instance = loader.Load();
        return instance;
    }
}

async

async RuntimeGltfInstance Load(GltfData data)
{
    // ImporterContext は使用後に Dispose を呼び出してください。
    // using で自動的に呼び出すことができます。
    using(var loader = new UniGLTF.ImporterContext(data)
    {
        var instance = await loader.LoadAsync();
        return instance;
    }
}

Load materials for URP with materialGenerator

Customizing Materials generated during Import

3. インスタンスを使用する

// SkinnedMeshRenderer に対する指示
instance.EnableUpdateWhenOffscreen();
// 準備ができたら表示する(デフォルトでは非表示)
instance.ShowMeshes();

Discard after use as follows. Associated Assets (Textures, Materials, Meshes, etc.) are also destroyed.

GameObject.Destroy(instance);