예제 #1
0
        private void RuntimeImport(ImporterContext context)
        {
            var animationClips = new AnimationClip[context.GLTF.animations.Count];

            // node extension animation
            for (int i = 0; i < context.GLTF.nodes.Count; i++)
            {
                var node = context.GLTF.nodes[i];
                if (node.extensions == null || node.extensions.VCAST_vci_animation == null)
                {
                    continue;
                }

                var vciAnimation = node.extensions.VCAST_vci_animation;
                var root         = context.Nodes[i];
                var animation    = root.gameObject.AddComponent <Animation>();

                foreach (var animationReference in vciAnimation.animationReferences)
                {
                    var           gltfAnimation = context.GLTF.animations[animationReference.animation];
                    AnimationClip clip          = null;
                    if (animationClips[animationReference.animation] == null)
                    {
                        clip = AnimationImporterUtil.ImportAnimationClip(context, gltfAnimation, node);
                        animationClips[animationReference.animation] = clip;
                    }
                    else
                    {
                        clip = animationClips[animationReference.animation];
                    }

                    if (clip != null)
                    {
                        animation.AddClip(clip, clip.name);
                    }
                }
            }

            // root animation
            var rootAnimation = context.Root.GetComponent <Animation>();

            if (rootAnimation == null)
            {
                rootAnimation = context.Root.AddComponent <Animation>();
            }

            for (int i = 0; i < animationClips.Length; i++)
            {
                if (animationClips[i] != null)
                {
                    continue;
                }

                var gltfAnimation = context.GLTF.animations[i];

                animationClips[i] = AnimationImporterUtil.ImportAnimationClip(context, gltfAnimation);
                rootAnimation.AddClip(animationClips[i], animationClips[i].name);
            }

            context.AnimationClips = new List <AnimationClip>(animationClips);
        }
예제 #2
0
파일: VCIImporter.cs 프로젝트: notargs/VCI
        public void ExtractAnimation(UnityPath prefabPath)
        {
#if UNITY_EDITOR
            if (GLTF.animations == null || GLTF.animations.Count == 0)
            {
                return;
            }

            var prefabParentDir = prefabPath.Parent;
            var folder          = prefabPath.GetAssetFolder(".Animation");
            folder.EnsureFolder();

            var animationClips = new AnimationClip[GLTF.animations.Count];
            for (int i = 0; i < GLTF.nodes.Count; i++)
            {
                var node = GLTF.nodes[i];
                if (node.extensions == null || node.extensions.VCAST_vci_animation == null)
                {
                    continue;
                }

                var vciAnimation = node.extensions.VCAST_vci_animation;

                foreach (var animationReference in vciAnimation.animationReferences)
                {
                    var           gltfAnimation = GLTF.animations[animationReference.animation];
                    AnimationClip clip          = null;
                    if (animationClips[animationReference.animation] == null)
                    {
                        clip = AnimationImporterUtil.ImportAnimationClip(this, gltfAnimation, node);
                        animationClips[animationReference.animation] = clip;
                    }
                }
            }

            // Import root animation clips.
            for (var i = 0; i < animationClips.Length; i++)
            {
                if (animationClips[i] != null)
                {
                    continue;
                }
                animationClips[i] = AnimationImporterUtil.ImportAnimationClip(this, GLTF.animations[i]);
            }

            var saveAnimationPath = new string[GLTF.animations.Count];
            for (int i = 0; i < animationClips.Count(); i++)
            {
                if (animationClips[i] != null)
                {
                    var path = string.Format("{0}/{1}.{2}", folder.Value, animationClips[i].name, "asset");
                    AssetDatabase.CreateAsset(animationClips[i], path);
                    saveAnimationPath[i] = path;
                }
            }

            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();

            var saveAnimationClips = new AnimationClip[GLTF.animations.Count];
            for (int i = 0; i < saveAnimationPath.Count(); i++)
            {
                if (!string.IsNullOrEmpty(saveAnimationPath[i]))
                {
                    saveAnimationClips[i] = AssetDatabase.LoadAssetAtPath(saveAnimationPath[i], typeof(AnimationClip)) as AnimationClip;
                }
            }

            AnimationClips = new List <AnimationClip>(saveAnimationClips);
#endif
        }
 public void Import(ImporterContext context)
 {
     AnimationImporterUtil.ImportAnimation(context);
 }