Exemple #1
0
        public Derpy(ThingBlock block, ThingDefinition def)
            : base(block, def)
        {
            bodyComponent = ModelComponents[0];
            flagComponent = ModelComponents[1];
            startLightComponent = ModelComponents[2];

            bodyFacing = new Euler(0, 0, 0);
            neckFacing = new Euler(0, 0, 0);

            Skeleton skeleton = bodyComponent.Entity.Skeleton;
            skeleton.BlendMode = SkeletonAnimationBlendMode.ANIMBLEND_CUMULATIVE;

            blinkState = bodyComponent.Entity.GetAnimationState("Blink2");
            blinkState.Enabled = true;
            blinkState.Loop = true;
            blinkState.Weight = 1f;
            blinkState.AddTime(ID);

            neckBone = skeleton.GetBone("Neck");
            neckBone.SetManuallyControlled(true);
            foreach (var state in bodyComponent.Entity.AllAnimationStates.GetAnimationStateIterator())
            {
                // don't add a blend mask to the blink state because we'll make a different one for it
                if (state == blinkState)
                    continue;

                state.CreateBlendMask(skeleton.NumBones);
                state.SetBlendMaskEntry(neckBone.Handle, 0f);
            }
            neckBone.InheritOrientation = false;

            blinkState.CreateBlendMask(skeleton.NumBones, 0f);
            ushort handle = skeleton.GetBone("EyeBrowTop.R").Handle;
            blinkState.SetBlendMaskEntry(handle, 1f);
            handle = skeleton.GetBone("EyeBrowBottom.R").Handle;
            blinkState.SetBlendMaskEntry(handle, 1f);
            handle = skeleton.GetBone("EyeBrowTop.L").Handle;
            blinkState.SetBlendMaskEntry(handle, 1f);
            handle = skeleton.GetBone("EyeBrowBottom.L").Handle;
            blinkState.SetBlendMaskEntry(handle, 1f);

            LKernel.GetG<AnimationManager>().Add(blinkState);

            interpNode = LKernel.GetG<SceneManager>().RootSceneNode.CreateChildSceneNode("DerpyInterpNode" + ID, Vector3.ZERO);

            anim = DerpyAnimation.Hover1;
        }
Exemple #2
0
        /// <summary>
        /// Update position and orientation of body and neck
        /// </summary>
        private bool FrameStarted(FrameEvent evt)
        {
            if (Pauser.IsPaused)
                return true;

            // update position
            Vector3 derivedInterp = interpNode._getDerivedPosition();
            Vector3 derivedDerpy = this.RootNode._getDerivedPosition();

            Vector3 displacement = derivedInterp - derivedDerpy;
            this.RootNode.Translate(displacement * 6 * evt.timeSinceLastFrame);

            // update orientation of derpy
            Vector3 lookat_body = this.RootNode.Position - followKart.ActualPosition;
            Euler temp_body = bodyFacing.GetRotationTo(lookat_body, true, false, true);
            Radian tempTime = new Radian(evt.timeSinceLastFrame * 3f);
            temp_body.LimitYaw(tempTime);

            bodyFacing = bodyFacing + temp_body;
            this.RootNode.Orientation = bodyFacing;

            // update orientation of neck
            Vector3 lookat_neck = this.RootNode.ConvertWorldToLocalPosition(followKart.ActualPosition);
            Euler temp_neck = neckFacing.GetRotationTo(-lookat_neck, true, true, true);
            tempTime *= 1.5f;
            temp_neck.LimitYaw(tempTime);
            temp_neck.LimitPitch(tempTime);

            neckFacing = neckFacing + temp_neck;
            neckFacing.LimitYaw(NECK_YAW_LIMIT);
            neckFacing.LimitPitch(NECK_PITCH_LIMIT);
            neckBone.Orientation = neckFacing;

            return true;
        }
        public BackgroundPony(string bgPonyName, ThingBlock block, ThingDefinition def)
            : base(block, def)
        {
            AnimPose = Pose.Standing;

            if (bgPonyName == null)
                nameOfPonyCharacter = loader.GetRandomLine();
            else
                nameOfPonyCharacter = bgPonyName;

            // get a line to parse
            string _line;
            if (!loader.BackgroundPonyDict.TryGetValue(nameOfPonyCharacter, out _line)) {
                // if the line doesn't exist, make a random one
                _line = loader.GetRandomLine();
                Launch.Log("[WARNING] The specified background pony (" + nameOfPonyCharacter + ") does not exist, using random one instead...");
            }
            // split up the data
            string[] _data = _line.Split(' ');
            // get our hairstyle ID number
            int hairstyleID = int.Parse(_data[1], culture);
            // set the pony type
            if (_data[2] == "pegasus")
                PonyType = Type.Pegasus;
            else if (_data[2] == "flyingpegasus")
                PonyType = Type.FlyingPegasus;
            else if (_data[2] == "earth")
                PonyType = Type.Earth;
            else if (_data[2] == "unicorn")
                PonyType = Type.Unicorn;

            // create nodes and stuff
            var sceneMgr = LKernel.Get<SceneManager>();

            #region creation
            bodyEnt = sceneMgr.CreateEntity("BgPonyBody.mesh");
            RootNode.AttachObject(bodyEnt);

            eyesEnt = sceneMgr.CreateEntity("BgPonyEyes.mesh");

            if (PonyType == Type.Unicorn)
                hornEnt = sceneMgr.CreateEntity("BgPonyHorn.mesh");
            else if (PonyType == Type.FlyingPegasus)
                wingsEnt = sceneMgr.CreateEntity("BgPonyWings.mesh");
            else if (PonyType == Type.Pegasus)
                foldedWingsEnt = sceneMgr.CreateEntity("BgPonyWingsFolded.mesh");

            // create hair
            hairEnt = sceneMgr.CreateEntity("BgPonyHair" + hairstyleID + ".mesh");
            maneEnt = sceneMgr.CreateEntity("BgPonyMane" + hairstyleID + ".mesh");
            tailEnt = sceneMgr.CreateEntity("BgPonyTail" + hairstyleID + ".mesh");

            // attach stuff
            bodyEnt.AttachObjectToBone("Eyes", eyesEnt);
            bodyEnt.AttachObjectToBone("Hair", hairEnt);
            bodyEnt.AttachObjectToBone("Mane", maneEnt);
            bodyEnt.AttachObjectToBone("Tail", tailEnt);
            if (PonyType == Type.Unicorn)
                bodyEnt.AttachObjectToBone("Horn", hornEnt);
            else if (PonyType == Type.Pegasus)
                bodyEnt.AttachObjectToBone("Wings", foldedWingsEnt);
            else if (PonyType == Type.FlyingPegasus)
                bodyEnt.AttachObjectToBone("Wings", wingsEnt);
            #endregion

            #region setting up colors in materials
            // body colour
            {
                ColourValue bodyColour = new ColourValue(float.Parse(_data[3], culture), float.Parse(_data[4], culture), float.Parse(_data[5], culture));
                ColourValue bodyAOColour = new ColourValue(float.Parse(_data[6], culture), float.Parse(_data[7], culture), float.Parse(_data[8], culture));

                MaterialPtr bodyMat = SetBodyPartMaterialColours("BgPony", bodyColour, bodyAOColour);
                bodyMat.GetTechnique(0).GetPass(1).GetTextureUnitState(1).SetTextureName(_data[18].Substring(1, _data[18].Length - 2));

                bodyEnt.SetMaterial(bodyMat);

                // extra body parts
                if (PonyType == Type.Unicorn) {
                    bodyMat = SetBodyPartMaterialColours("BgPonyHorn", bodyColour, bodyAOColour);
                    hornEnt.SetMaterial(bodyMat);
                }
                else if (PonyType == Type.Pegasus) {
                    bodyMat = SetBodyPartMaterialColours("BgPonyWingsFolded", bodyColour, bodyAOColour);
                    foldedWingsEnt.SetMaterial(bodyMat);
                }
                else if (PonyType == Type.FlyingPegasus) {
                    bodyMat = SetBodyPartMaterialColours("BgPonyWings", bodyColour, bodyAOColour);
                    wingsEnt.SetMaterial(bodyMat);
                }
            }

            // eye colours
            {
                ColourValue eyeColour1 = new ColourValue(float.Parse(_data[9], culture), float.Parse(_data[10], culture), float.Parse(_data[11], culture));
                ColourValue eyeColour2 = new ColourValue(float.Parse(_data[12], culture), float.Parse(_data[13], culture), float.Parse(_data[14], culture));
                ColourValue eyeHighlightColour = new ColourValue(float.Parse(_data[15], culture), float.Parse(_data[16], culture), float.Parse(_data[17], culture));

                MaterialPtr originalMat = MaterialManager.Singleton.GetByName("BgPonyEyes");
                MaterialPtr newMat = MaterialManager.Singleton.GetByName("BgPonyEyes" + nameOfPonyCharacter);
                if (newMat == null) {
                    newMat = originalMat.Clone("BgPonyEyes" + nameOfPonyCharacter);

                    var ps = newMat.GetTechnique(0).GetPass(0).GetFragmentProgramParameters();
                        ps.SetNamedConstant("TopIrisColour", eyeColour1);
                        ps.SetNamedConstant("BottomIrisColour", eyeColour2);
                        ps.SetNamedConstant("HighlightColour", eyeHighlightColour);
                    newMat.GetTechnique(0).GetPass(0).SetFragmentProgramParameters(ps);
                }

                eyesEnt.SetMaterial(newMat);
            }

            // hair colours
            {
                ColourValue hairColour1 = new ColourValue(float.Parse(_data[20], culture), float.Parse(_data[21], culture), float.Parse(_data[22], culture));
                ColourValue hairAOColour1 = new ColourValue(float.Parse(_data[23], culture), float.Parse(_data[24], culture), float.Parse(_data[25], culture));

                // two hair colours
                if (bool.Parse(_data[19])) {
                    ColourValue hairColour2 = new ColourValue(float.Parse(_data[26], culture), float.Parse(_data[27], culture), float.Parse(_data[28], culture));
                    ColourValue hairAOColour2 = new ColourValue(float.Parse(_data[29], culture), float.Parse(_data[30], culture), float.Parse(_data[31], culture));

                    MaterialPtr originalMat = MaterialManager.Singleton.GetByName("BgPonyHair_Double_" + hairstyleID);
                    MaterialPtr newMat = MaterialManager.Singleton.GetByName("BgPonyHair_Double_" + hairstyleID + nameOfPonyCharacter);
                    if (newMat == null) {
                        newMat = originalMat.Clone("BgPonyHair_Double_" + hairstyleID + nameOfPonyCharacter);

                        var ps = newMat.GetTechnique(0).GetPass(1).GetFragmentProgramParameters();
                            ps.SetNamedConstant("HairColour1", hairColour1);
                            ps.SetNamedConstant("AOColour1", hairAOColour1);
                            ps.SetNamedConstant("HairColour2", hairColour2);
                            ps.SetNamedConstant("AOColour2", hairAOColour2);
                        newMat.GetTechnique(0).GetPass(1).SetFragmentProgramParameters(ps);

                        if (int.Parse(_data[32], culture) == 2)
                            SetMaterialFragmentParameter(newMat, 0, "OutlineColour", hairAOColour2);
                        else if (int.Parse(_data[32], culture) == 1)
                            SetMaterialFragmentParameter(newMat, 0, "OutlineColour", hairAOColour1);
                    }
                    hairEnt.SetMaterial(newMat);
                    maneEnt.SetMaterial(newMat);
                    tailEnt.SetMaterial(newMat);
                }
                // one colour
                else {
                    MaterialPtr originalMat = MaterialManager.Singleton.GetByName("BgPonyHair_Single_" + hairstyleID);
                    MaterialPtr newMat = MaterialManager.Singleton.GetByName("BgPonyHair_Single_" + hairstyleID + nameOfPonyCharacter);
                    if (newMat == null) {
                        newMat = originalMat.Clone("BgPonyHair_Single_" + hairstyleID + nameOfPonyCharacter);

                        var ps = newMat.GetTechnique(0).GetPass(1).GetFragmentProgramParameters();
                            ps.SetNamedConstant("HairColour", hairColour1);
                            ps.SetNamedConstant("AOColour", hairAOColour1);
                        newMat.GetTechnique(0).GetPass(1).SetFragmentProgramParameters(ps);

                        SetMaterialFragmentParameter(newMat, 0, "OutlineColour", hairAOColour1);
                    }
                    hairEnt.SetMaterial(newMat);
                    maneEnt.SetMaterial(newMat);
                    tailEnt.SetMaterial(newMat);
                }
            }
            #endregion

            #region animation
            // make sure our animations add their weights and don't just average out. The AnimationBlender already handles averaging between two anims.
            Skeleton skeleton = bodyEnt.Skeleton;
            skeleton.BlendMode = SkeletonAnimationBlendMode.ANIMBLEND_CUMULATIVE;

            // set up the blink animation state with some stuff
            blinkState = bodyEnt.GetAnimationState("Blink2");
            blinkState.Enabled = true;
            blinkState.Loop = true;
            blinkState.Weight = 1;
            blinkState.AddTime(ID);

            // set up all of the animation states to not use the neck bone
            neckbone = skeleton.GetBone("Neck");
            neckbone.SetManuallyControlled(true);
            foreach (var state in bodyEnt.AllAnimationStates.GetAnimationStateIterator()) {
                // don't add a blend mask to the blink state because we'll make a different one for it
                if (state == blinkState)
                    continue;

                state.CreateBlendMask(skeleton.NumBones);
                state.SetBlendMaskEntry(neckbone.Handle, 0f);
            }
            neckbone.InheritOrientation = false;

            neckFacing = new Euler(0, 0, 0);

            // set up a blend mask so only the eyebrow bones have any effect on the blink animation
            blinkState.CreateBlendMask(skeleton.NumBones, 0f);
            ushort handle = skeleton.GetBone("EyeBrowTop.R").Handle;
            blinkState.SetBlendMaskEntry(handle, 1f);
            handle = skeleton.GetBone("EyeBrowBottom.R").Handle;
            blinkState.SetBlendMaskEntry(handle, 1f);
            handle = skeleton.GetBone("EyeBrowTop.L").Handle;
            blinkState.SetBlendMaskEntry(handle, 1f);
            handle = skeleton.GetBone("EyeBrowBottom.L").Handle;
            blinkState.SetBlendMaskEntry(handle, 1f);

            // add the blink state to the animation manager so it has time added to it
            AnimationManager animMgr = LKernel.GetG<AnimationManager>();
            animMgr.Add(blinkState);

            // set up other animated things
            bodyBlender = new AnimationBlender(bodyEnt);
            bodyBlender.Init("Stand1", true);
            animMgr.Add(bodyBlender);

            maneBlender = new AnimationBlender(maneEnt);
            maneBlender.Init("Stand1", true);
            animMgr.Add(maneBlender);

            tailBlender = new AnimationBlender(tailEnt);
            tailBlender.Init("Stand1", true);
            animMgr.Add(tailBlender);

            if (PonyType == Type.FlyingPegasus) {
                wingsBlender = new AnimationBlender(wingsEnt);
                wingsBlender.Init("Flap1", true);
                animMgr.Add(wingsBlender);
            }

            // set up some timers to handle animation changing
            animTimer = new Timer(new TimerCallback(AnimTimerTick), null, random.Next(ANIMATION_TIMESPAN_MINIMUM, ANIMATION_TIMESPAN_MAXIMUM), Timeout.Infinite);

            // add a bit of time to things so the animations aren't all synced at the beginning
            AddTimeToBodyManeAndTail();
            #endregion

            followKart = LKernel.GetG<PlayerManager>().MainPlayer.Kart;
            LKernel.GetG<Root>().FrameStarted += FrameStarted;
        }
        /// <summary>
        /// Rotate the neck bone to face the kart. Will eventually need to redo this when we have multiple karts, to face whichever's nearest, etc.
        /// </summary>
        bool FrameStarted(FrameEvent evt)
        {
            if (!Pauser.IsPaused) {
                Vector3 lookat = RootNode.ConvertWorldToLocalPosition(followKart.ActualPosition);
                // temp is how much you need to rotate to get from the current orientation to the new orientation
                // we use -lookat because our bone points towards +Z, whereas this code was originally made for things facing towards -Z
                Euler temp = neckFacing.GetRotationTo(-lookat, true, true, true);
                // limit the offset so the head turns at a maximum of 3 radians per second
                Radian tempTime = new Radian(evt.timeSinceLastFrame * 3);
                temp.LimitYaw(tempTime);
                temp.LimitPitch(tempTime);

                neckFacing = neckFacing + temp;
                neckFacing.LimitYaw(NECK_YAW_LIMIT);
                neckFacing.LimitPitch(NECK_PITCH_LIMIT);
                neckbone.Orientation = neckFacing;
            }

            return true;
        }
Exemple #5
0
        public Lyra(ThingBlock block, ThingDefinition def)
            : base(block, def)
        {
            foreach (ModelComponent mc in ModelComponents) {
                if (mc.Name.EndsWith("Body"))
                    bodyComponent = mc;
                else if (mc.Name.EndsWith("Mane"))
                    maneComponent = mc;
                else if (mc.Name.EndsWith("Tail"))
                    tailComponent = mc;
            }

            // make sure our animations add their weights and don't just average out. The AnimationBlender already handles averaging between two anims.
            Skeleton skeleton = bodyComponent.Entity.Skeleton;
            skeleton.BlendMode = SkeletonAnimationBlendMode.ANIMBLEND_CUMULATIVE;

            // set up the blink animation state with some stuff
            blinkState = bodyComponent.Entity.GetAnimationState("Blink2");
            blinkState.Enabled = true;
            blinkState.Loop = true;
            blinkState.Weight = 1;
            blinkState.AddTime(ID);

            // set up all of the animation states to not use the neck bone
            neckbone = skeleton.GetBone("Neck");
            neckbone.SetManuallyControlled(true);
            foreach (var state in bodyComponent.Entity.AllAnimationStates.GetAnimationStateIterator()) {
                // don't add a blend mask to the blink state because we'll make a different one for it
                if (state == blinkState)
                    continue;

                state.CreateBlendMask(skeleton.NumBones);
                state.SetBlendMaskEntry(neckbone.Handle, 0f);
            }
            neckbone.InheritOrientation = false;

            neckFacing = new Euler(0, 0, 0);

            // set up a blend mask so only the eyebrow bones have any effect on the blink animation
            blinkState.CreateBlendMask(skeleton.NumBones, 0f);
            ushort handle = skeleton.GetBone("EyeBrowTop.R").Handle;
            blinkState.SetBlendMaskEntry(handle, 1f);
            handle = skeleton.GetBone("EyeBrowBottom.R").Handle;
            blinkState.SetBlendMaskEntry(handle, 1f);
            handle = skeleton.GetBone("EyeBrowTop.L").Handle;
            blinkState.SetBlendMaskEntry(handle, 1f);
            handle = skeleton.GetBone("EyeBrowBottom.L").Handle;
            blinkState.SetBlendMaskEntry(handle, 1f);

            // add the blink state to the animation manager so it has time added to it
            LKernel.GetG<AnimationManager>().Add(blinkState);

            // set up some timers to handle animation changing
            random = new Random(IDs.Random);
            animTimer = new System.Threading.Timer(new TimerCallback(AnimTimerTick), null, random.Next(ANIMATION_TIMESPAN_MINIMUM, ANIMATION_TIMESPAN_MAXIMUM), Timeout.Infinite);

            // add a bit of time to things so the animations aren't all synced at the beginning
            float rand = (float) random.NextDouble();
            bodyComponent.AnimationBlender.AddTime(rand);
            tailComponent.AnimationState.AddTime(rand);

            followKart = LKernel.GetG<PlayerManager>().MainPlayer.Kart;
            LKernel.GetG<Root>().FrameStarted += FrameStarted;
        }