Пример #1
0
 public void Update()
 {
     BodyAnimation.GetComponent <RectTransform>().localScale = new Vector3(XMirror ? -1 : 1, 1, 1);
     BodyAnimation.Sheet = GetCurrentSheet();
     CheckShot();
     CheckInteractive();
 }
Пример #2
0
    void SetBodyAnimation(BodyAnimation animation)
    {
        if (animation != lastAnimation)
        {   //动画不同,切换
            lastAnimation = animation;
            //Debug.Log("animation state " + animation.ToString());
            switch (animation)
            {
            case BodyAnimation.Run:
                armatureComponent.animation.FadeIn(runAni, -1, -1, 0, bodyAniGroup);
                break;

            case BodyAnimation.Walk:
                armatureComponent.animation.FadeIn(walkAni, -1, -1, 0, bodyAniGroup);
                break;

            case BodyAnimation.Idle:
                armatureComponent.animation.FadeIn(idleAni, -1, -1, 0, bodyAniGroup);
                break;

            case BodyAnimation.Jump:
                armatureComponent.animation.FadeIn(jumpAni, 0, -1, 0, bodyAniGroup);
                break;

            case BodyAnimation.Fall:
                armatureComponent.animation.FadeIn(fallAni, 0.2f, -1, 0, bodyAniGroup);
                break;

            case BodyAnimation.Raise:
                armatureComponent.animation.FadeIn(raiseAni, 0.2f, -1, 0, bodyAniGroup);
                break;

            case BodyAnimation.Back:
                armatureComponent.animation.FadeIn(backAni, 0.2f, -1, 0, bodyAniGroup);
                break;

            case BodyAnimation.Climb:
                armatureComponent.animation.FadeIn(climbAni, -1, -1, 0, bodyAniGroup);
                break;

            case BodyAnimation.ClimbDown:
                armatureComponent.animation.FadeIn(climbDownAni, -1, -1, 0, bodyAniGroup);
                break;

            case BodyAnimation.IdleOnLadder:
                armatureComponent.animation.FadeIn(idleOnLadderAni, -1, -1, 0, bodyAniGroup);
                break;
            }
        }
    }
Пример #3
0
        public AnimationRenderer([NotNull] Game game,
                                 [NotNull] PrettyMesh bodyMesh, [NotNull] PrettyAvatar bodyAvatar, [NotNull, ItemNotNull] IReadOnlyList <BoneNode> bodyBoneList,
                                 [NotNull] PrettyMesh headMesh, [NotNull] PrettyAvatar headAvatar, [NotNull, ItemNotNull] IReadOnlyList <BoneNode> headBoneList,
                                 [NotNull] BodyAnimation animation)
        {
            _game         = game;
            _bodyMesh     = bodyMesh;
            _bodyAvatar   = bodyAvatar;
            _bodyBoneList = bodyBoneList;
            _headMesh     = headMesh;
            _headAvatar   = headAvatar;
            _headBoneList = headBoneList;
            _animation    = animation;

            #region Body

            var bodyVertexBuffer = new VertexBuffer();
            var bodyIndexBuffer  = new IndexBuffer();

            var bodyVertices = new PosNorm[bodyMesh.Vertices.Length];
            var bodyIndices  = new uint[bodyMesh.Indices.Length];

            for (var k = 0; k < bodyVertices.Length; ++k)
            {
                bodyVertices[k] = new PosNorm {
                    Position = bodyMesh.Vertices[k].ToOpenTK().FixCoordSystem(),
                    Normal   = bodyMesh.Normals[k].ToOpenTK().FixCoordSystem()
                };
            }

            _originalBodyVertices = bodyVertices;
            _bodyVertices         = (PosNorm[])bodyVertices.Clone();

            for (var k = 0; k < bodyIndices.Length; ++k)
            {
                bodyIndices[k] = bodyMesh.Indices[k];
            }

            bodyVertexBuffer.BufferData(bodyVertices, BufferUsageHint.StreamDraw);
            bodyIndexBuffer.BufferData(bodyIndices, BufferUsageHint.StaticDraw);

            _bodyVertexBuffer = bodyVertexBuffer;
            _bodyIndexBuffer  = bodyIndexBuffer;

            #endregion

            #region Head

            var headVertexBuffer = new VertexBuffer();
            var headIndexBuffer  = new IndexBuffer();

            var headVertices = new PosNorm[headMesh.Vertices.Length];
            var headIndices  = new uint[headMesh.Indices.Length];

            for (var k = 0; k < headVertices.Length; ++k)
            {
                headVertices[k] = new PosNorm {
                    Position = headMesh.Vertices[k].ToOpenTK().FixCoordSystem(),
                    Normal   = headMesh.Normals[k].ToOpenTK().FixCoordSystem()
                };
            }

            _originalHeadVertices = headVertices;
            _headVertices         = (PosNorm[])headVertices.Clone();

            for (var k = 0; k < headIndices.Length; ++k)
            {
                headIndices[k] = headMesh.Indices[k];
            }

            headVertexBuffer.BufferData(headVertices, BufferUsageHint.StreamDraw);
            headIndexBuffer.BufferData(headIndices, BufferUsageHint.StaticDraw);

            _headVertexBuffer = headVertexBuffer;
            _headIndexBuffer  = headIndexBuffer;

            #endregion
        }
 public BodyAnimation Convert()
 {
     return(BodyAnimation.CreateFrom(AnimationClip));
 }
Пример #5
0
        // Some heavy stuff
        private void Initialize1()
        {
            ResHelper.LoadHeadMesh();

            _bodyMesh   = ResHelper.LoadBodyMesh();
            _bodyAvatar = ResHelper.LoadBodyAvatar();
            _headMesh   = ResHelper.LoadHeadMesh();
            _headAvatar = ResHelper.LoadHeadAvatar();

            Debug.Assert(_bodyAvatar != null, nameof(_bodyAvatar) + " != null");
            Debug.Assert(_bodyMesh != null, nameof(_bodyMesh) + " != null");
            Debug.Assert(_headAvatar != null, nameof(_headAvatar) + " != null");
            Debug.Assert(_headMesh != null, nameof(_headMesh) + " != null");

            _bodyBoneList = ResHelper.BuildBoneHierachy(_bodyAvatar, _bodyMesh);
            _headBoneList = ResHelper.BuildBoneHierachy(_headAvatar, _headMesh);

            do
            {
                // Fix "KUBI" (neck) bone's parent
                var kubiParent = _bodyBoneList.SingleOrDefault(bn => bn.Path == "MODEL_00/BASE/MUNE1/MUNE2/KUBI");
                var kubiBone   = _headBoneList.SingleOrDefault(bn => bn.Path == "KUBI");

                Debug.Assert(kubiParent != null);
                Debug.Assert(kubiBone != null);

                kubiParent.AddChild(kubiBone);

                Debug.Assert(kubiBone.Parent != null);

                // Don't forget to remove it from its old parent (or it will be updated twice from two parents).
                // The original parents and grandparents of KUBI are not needed; they are just like model anchors and shouldn't be animated.
                // See decompiled model for more information.
                kubiBone.Parent.RemoveChild(kubiBone);

                kubiBone.Parent = kubiParent;

                // Set its new initial parameters.
                // Since the two bones (KUBI and MODEL_00/BASE/MUNE1/MUNE2/KUBI) actually share the exact same transforms,
                // set its local transform to identity (t=0, q=0).
                kubiBone.InitialPosition = Vector3.Zero;
                kubiBone.InitialRotation = Quaternion.Identity;
                kubiBone.LocalPosition   = Vector3.Zero;
                kubiBone.LocalRotation   = Quaternion.Identity;

                // Now inform the rest of the head bones the new bone hierarchy. Force them to do so.
                foreach (var bone in _headBoneList)
                {
                    bone.Initialize(true);
                }
            } while (false);

            (_danceData, _, _) = ResHelper.LoadDance();

#if DEBUG
            do
            {
                var influencingBones = _bodyBoneList.Where((_, i) => _bodyMesh.Skin.Any(sk => sk.Any(a => a.BoneIndex == i)));

                Debug.Print("Bones that influences the mesh:");

                foreach (var bone in influencingBones)
                {
                    Debug.Print("#{0} \"{1}\"", bone.Index, bone.Path);
                }
            } while (false);
#endif

            _animation = BodyAnimation.CreateFrom(_danceData);

#if DEBUG
            do
            {
                var animatedBoneNames = _animation.KeyFrames.Select(f => f.Path).Distinct();

                Debug.Print("Animated bone names:");

                foreach (var boneName in animatedBoneNames)
                {
                    Debug.Print(boneName);
                }
            } while (false);
#endif

            _initialized1 = true;
        }
Пример #6
0
 void Start()
 {
     ribo = GetComponent<Rigidbody>();
     locomotion = GetComponent<Locomotion>();
     bodyAnimation = GetComponent<BodyAnimation>();
 }
        private static IReadOnlyList <VmdBoneFrame> CreateBoneFrames([NotNull] CharacterImasMotionAsset bodyMotion, [NotNull] Avatar avatar, [NotNull] PmxModel pmx)
        {
            var mltdHierarchy = BoneUtils.BuildBoneHierarchy(avatar);
            var pmxHierarchy  = BoneUtils.BuildBoneHierarchy(pmx);

            if (ConversionConfig.Current.AppendIKBones || ConversionConfig.Current.AppendEyeBones)
            {
                throw new NotSupportedException("Character motion frames generation (from MLTD) is not supported when appending bones (eyes and/or IK) is enabled.");
            }
            else
            {
                Debug.Assert(mltdHierarchy.Count == pmxHierarchy.Count, "Hierarchy number should be equal between MLTD and MMD.");
            }

            foreach (var mltdBone in mltdHierarchy)
            {
                mltdBone.Initialize();
            }

            foreach (var pmxBone in pmxHierarchy)
            {
                pmxBone.Initialize();
            }

            var animation         = BodyAnimation.CreateFrom(bodyMotion);
            var boneCount         = mltdHierarchy.Count;
            var animatedBoneCount = animation.BoneCount;
            var keyFrameCount     = animation.KeyFrames.Count;

            do
            {
                void MarkNamedBone(string name)
                {
                    var bone = pmx.Bones.FirstOrDefault(b => b.Name == name);

                    if (bone != null)
                    {
                        bone.IsMltdKeyBone = true;
                    }
                    else
                    {
                        Debug.Print("Warning: trying to mark bone {0} as MLTD key bone but the bone is missing from the model.", name);
                    }
                }

                var names1 = animation.KeyFrames.Take(animatedBoneCount)
                             .Select(kf => kf.Path).ToArray();
                var names = names1.Select(BoneUtils.GetVmdBoneNameFromBonePath).ToArray();
                // Mark MLTD key bones.
                foreach (var name in names)
                {
                    MarkNamedBone(name);
                }

                // Special cases
                MarkNamedBone("KUBI");
                MarkNamedBone("頭");
            } while (false);

            Debug.Assert(keyFrameCount % animatedBoneCount == 0, "keyFrameCount % animatedBoneCount == 0");

            var iterationTimes = keyFrameCount / animatedBoneCount;
            var boneFrameList  = new List <VmdBoneFrame>();

            for (var i = 0; i < iterationTimes; ++i)
            {
                if (ConversionConfig.Current.Transform60FpsTo30Fps)
                {
                    if (i % 2 == 1)
                    {
                        continue;
                    }
                }

                var keyFrameIndexStart = i * animatedBoneCount;

                for (var j = 0; j < animatedBoneCount; ++j)
                {
                    var keyFrame     = animation.KeyFrames[keyFrameIndexStart + j];
                    var mltdBoneName = keyFrame.Path.Replace("BODY_SCALE/", string.Empty);
                    var targetBone   = mltdHierarchy.SingleOrDefault(bone => bone.Name == mltdBoneName);

                    if (targetBone == null)
                    {
                        //throw new ArgumentException("Bone not found.");
                        continue; // Shika doesn't have the "POSITION" bone.
                    }

                    BoneNode transferredBone = null;

                    foreach (var kv in BoneAttachmentMap)
                    {
                        if (kv.Key == mltdBoneName)
                        {
                            transferredBone = mltdHierarchy.SingleOrDefault(bone => bone.Name == kv.Value);

                            if (transferredBone == null)
                            {
                                throw new ArgumentException();
                            }

                            break;
                        }
                    }

                    if (keyFrame.HasPositions)
                    {
                        var x = keyFrame.PositionX.Value;
                        var y = keyFrame.PositionY.Value;
                        var z = keyFrame.PositionZ.Value;

                        var t = new Vector3(x, y, z);

                        t = t.FixUnityToOpenTK();

                        if (ConversionConfig.Current.ScaleToVmdSize)
                        {
                            t = t * ScalingConfig.ScaleUnityToPmx;
                        }

                        targetBone.LocalPosition = t;

                        //if (transferredBone != null) {
                        //    transferredBone.LocalPosition = t;
                        //}
                    }

                    if (keyFrame.HasRotations)
                    {
                        var x = keyFrame.AngleX.Value;
                        var y = keyFrame.AngleY.Value;
                        var z = keyFrame.AngleZ.Value;

                        var q = UnityRotation.EulerDeg(x, y, z);

                        q = q.FixUnityToOpenTK();

                        targetBone.LocalRotation = q;

                        if (transferredBone != null)
                        {
                            transferredBone.LocalRotation = q;
                        }
                    }
                }

                foreach (var mltdBone in mltdHierarchy)
                {
                    mltdBone.UpdateTransform();
                }

                for (var j = 0; j < boneCount; ++j)
                {
                    var pmxBone  = pmxHierarchy[j];
                    var mltdBone = mltdHierarchy[j];

                    {
                        var pb = pmx.Bones.FirstOrDefault(b => b.Name == pmxBone.Name);

                        Debug.Assert(pb != null, $"PMX bone with the name \"{pmxBone.Name}\" should exist.");

                        if (!pb.IsMltdKeyBone)
                        {
                            continue;
                        }
                    }

                    var skinMatrix      = mltdBone.SkinMatrix;
                    var mPmxBindingPose = pmxBone.BindingPose;
                    var mWorld          = pmxBone.Parent?.WorldMatrix ?? Matrix4.Identity;

                    // skinMatrix == inv(mPmxBindingPose) x mLocal x mWorld
                    var mLocal = mPmxBindingPose * skinMatrix * mWorld.Inverted();

                    // Here, translation is in... world coords? WTF?
                    var t = mLocal.ExtractTranslation();
                    var q = mLocal.ExtractRotation();

                    if (pmxBone.Parent != null)
                    {
                        t = t - (pmxBone.InitialPosition - pmxBone.Parent.InitialPosition);
                    }

                    int frameIndex;

                    if (ConversionConfig.Current.Transform60FpsTo30Fps)
                    {
                        frameIndex = i / 2;
                    }
                    else
                    {
                        frameIndex = i;
                    }

                    var vmdBoneName = BoneUtils.GetVmdBoneNameFromBoneName(mltdBone.Path);
                    var boneFrame   = new VmdBoneFrame(frameIndex, vmdBoneName);

                    boneFrame.Position = t;
                    boneFrame.Rotation = q;

                    boneFrameList.Add(boneFrame);

                    pmxBone.LocalPosition = t;
                    pmxBone.LocalRotation = q;
                    pmxBone.UpdateTransform();
                }
            }

            return(boneFrameList);
        }
Пример #8
0
    void Start()
    {
        audioSource = GetComponent<AudioSource> ();
        ribo = GetComponent<Rigidbody>();
        locomotion = GetComponent<Locomotion>();
        bodyAnimation = GetComponent<BodyAnimation>();
        emotion = GetComponent <SushiEmotion> ();
        currentState = SushiState.ALIVE;

        Invoke ("GenerateCheeringSound", Random.Range(1,10));
        MakeSound("spawning");
    }