From 2f970a200cd66dbeff3c923bd706f4c0853ab4dc Mon Sep 17 00:00:00 2001 From: Masataka SUMI Date: Mon, 19 Jul 2021 16:57:39 +0900 Subject: [PATCH] Add Nodes property. --- .../Runtime/UniGLTF/RuntimeGltfInstance.cs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/Assets/UniGLTF/Runtime/UniGLTF/RuntimeGltfInstance.cs b/Assets/UniGLTF/Runtime/UniGLTF/RuntimeGltfInstance.cs index e1de0da7e..5ec350bdb 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/RuntimeGltfInstance.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/RuntimeGltfInstance.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Linq; using UnityEngine; using VRMShaders; @@ -14,7 +15,12 @@ namespace UniGLTF /// /// this is UniGLTF root gameObject /// - public GameObject Root => this.gameObject; + public GameObject Root => (this != null) ? this.gameObject : null; + + /// + /// Transforms with gltf node index. + /// + public IReadOnlyList Nodes => _nodes; /// /// Runtime resources. @@ -58,6 +64,7 @@ namespace UniGLTF /// public IReadOnlyList SkinnedMeshRenderers => _skinnedMeshRenderers; + private readonly List _nodes = new List(); private readonly List<(SubAssetKey, UnityEngine.Object)> _resources = new List<(SubAssetKey, UnityEngine.Object)>(); private readonly List _materials = new List(); private readonly List _textures = new List(); @@ -70,12 +77,20 @@ namespace UniGLTF public static RuntimeGltfInstance AttachTo(GameObject go, ImporterContext context) { var loaded = go.AddComponent(); + + foreach (var node in context.Nodes) + { + // Maintain index order. + loaded._nodes.Add(node); + } + context.TransferOwnership((k, o) => { if (o == null) return; loaded._resources.Add((k, o)); + switch (o) { case Material material: