1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

UnityでglTFを読み込む

Posted at

上記の記事のままなので特に書くこともないですが、触ってみた感想です。
また、すでにパッケージをインポートしていること前提です。

読み込むだけならノーコード

空のオブジェクトを作ったらGltfAssetをAddComponentして
image.png

適当なglTFをURLに入れて
image.png

実行すれば表示されます
image.png

プログラムからの読み込みも簡単

これだけです

using GLTFast;
using UnityEngine;

public class glTFLoader : MonoBehaviour
{
    [SerializeField] string url = "https://raw.githubusercontent.com/KhronosGroup/glTF-Sample-Models/master/2.0/Duck/glTF/Duck.gltf";

    // Start is called before the first frame update
    async void Start()
    {
        var gltfImport = new GltfImport();
        await gltfImport.Load(url);
        var instantiator = new GameObjectInstantiator(gltfImport, transform);
        var success = await gltfImport.InstantiateMainSceneAsync(instantiator);
    }

    // Update is called once per frame
    void Update()
    {
    }
}

ヒエラルキーも保存されているので、(構造や名前がわかっていれば)読み込んだglb中にあるオブジェクト毎にさわることも簡単です

image.png

UnrealEngoneでもこのくらい簡単に出来たらなあ、、

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?