CreateAnimationState() public method

Create an AnimationState object for managing application of animations.

You can create Animation objects for animating SceneNode obejcts using the CreateAnimation method. However, in order to actually apply those animations you have to call methods on Node and Animation in a particular order (namely Node.ResetToInitialState and Animation.Apply). To make this easier and to help track the current time position of animations, the AnimationState object is provided.

So if you don't want to control animation application manually, call this method, update the returned object as you like every frame and let SceneManager apply the animation state for you.

Remember, AnimationState objects are disabled by default at creation time. Turn them on when you want them using their Enabled property.

Note that any SceneNode affected by this automatic animation will have it's state reset to it's initial position before application of the animation. Unless specifically modified using Node.SetInitialState the Node assumes it's initial state is at the origin. If you want the base state of the SceneNode to be elsewhere, make your changes to the node using the standard transform methods, then call SetInitialState to 'bake' this reference position into the node.

public CreateAnimationState ( string animationName ) : AnimationState
animationName string
return AnimationState
Beispiel #1
0
        protected void CreateRibbons()
        {
            viewport.BackgroundColor = ColorEx.Black;
            float scale = 100f;

            scene.AmbientLight = new ColorEx(0.5f, 0.5f, 0.5f);
            //scene.SetSkyBox(true, "Examples/SpaceSkyBox", 20f * oneMeter);
            Vector3 dir = new Vector3(-1f, -1f, 0.5f);

            dir.Normalize();
            Light light1 = scene.CreateLight("light1");

            light1.Type      = LightType.Directional;
            light1.Direction = dir;

            // Create a barrel for the ribbons to fly through
            Entity    barrel     = scene.CreateEntity("barrel", "barrel.mesh");
            SceneNode barrelNode = scene.RootSceneNode.CreateChildSceneNode();

            barrelNode.ScaleFactor = 5f * Vector3.UnitScale;
            barrelNode.AttachObject(barrel);

            RibbonTrail trail = new RibbonTrail("DemoTrail", "numberOfChains", 2, "maxElementsPerChain", 80);

            trail.MaterialName = "Examples/LightRibbonTrail";
            trail.TrailLength  = scale * 400f;
            scene.RootSceneNode.CreateChildSceneNode().AttachObject(trail);

            // Create 3 nodes for trail to follow
            SceneNode animNode = scene.RootSceneNode.CreateChildSceneNode();

            animNode.Position = scale * new Vector3(50f, 30f, 0);
            Animation anim = scene.CreateAnimation("an1", 14);

            anim.InterpolationMode = InterpolationMode.Spline;
            NodeAnimationTrack track = anim.CreateNodeTrack(1, animNode);
            TransformKeyFrame  kf    = track.CreateNodeKeyFrame(0);

            kf.Translate = scale * new Vector3(50f, 30f, 0f);
            kf           = track.CreateNodeKeyFrame(2);
            kf.Translate = scale * new Vector3(100f, -30f, 0f);
            kf           = track.CreateNodeKeyFrame(4);
            kf.Translate = scale * new Vector3(120f, -100f, 150f);
            kf           = track.CreateNodeKeyFrame(6);
            kf.Translate = scale * new Vector3(30f, -100f, 50f);
            kf           = track.CreateNodeKeyFrame(8);
            kf.Translate = scale * new Vector3(-50f, 30f, -50f);
            kf           = track.CreateNodeKeyFrame(10);
            kf.Translate = scale * new Vector3(-150f, -20f, -100f);
            kf           = track.CreateNodeKeyFrame(12);
            kf.Translate = scale * new Vector3(-50f, -30f, 0f);
            kf           = track.CreateNodeKeyFrame(14);
            kf.Translate = scale * new Vector3(50f, 30f, 0f);

            AnimationState animState = scene.CreateAnimationState("an1");

            //animState.Enabled = true;
            animStateList = new List <AnimationState>();
            animStateList.Add(animState);

            trail.SetInitialColor(0, 1.0f, 0.8f, 0f, 1.0f);
            trail.SetColorChange(0, 0.5f, 0.5f, 0.5f, 0.5f);
            trail.SetInitialWidth(0, scale * 5f);
            trail.AddNode(animNode);

            // Add light
            Light light2 = scene.CreateLight("light2");

            light2.Diffuse = trail.GetInitialColor(0);
            animNode.AttachObject(light2);

            // Add billboard
            BillboardSet bbs = scene.CreateBillboardSet("bb", 1);

            bbs.CreateBillboard(Vector3.Zero, trail.GetInitialColor(0));
            bbs.MaterialName = "flare";
            animNode.AttachObject(bbs);

            animNode          = scene.RootSceneNode.CreateChildSceneNode();
            animNode.Position = scale * new Vector3(-50f, 100f, 0f);
            anim = scene.CreateAnimation("an2", 10);
            anim.InterpolationMode = InterpolationMode.Spline;
            track        = anim.CreateNodeTrack(1, animNode);
            kf           = track.CreateNodeKeyFrame(0);
            kf.Translate = scale * new Vector3(-50f, 100f, 0f);
            kf           = track.CreateNodeKeyFrame(2);
            kf.Translate = scale * new Vector3(-100f, 150f, -30f);
            kf           = track.CreateNodeKeyFrame(4);
            kf.Translate = scale * new Vector3(-200f, 0f, 40f);
            kf           = track.CreateNodeKeyFrame(6);
            kf.Translate = scale * new Vector3(0f, -150f, 70f);
            kf           = track.CreateNodeKeyFrame(8);
            kf.Translate = scale * new Vector3(50f, 0f, 30f);
            kf           = track.CreateNodeKeyFrame(10);
            kf.Translate = scale * new Vector3(-50f, 100f, 0f);

            animState = scene.CreateAnimationState("an2");
            //animState.setEnabled(true);
            animStateList.Add(animState);

            trail.SetInitialColor(1, 0.0f, 1.0f, 0.4f, 1.0f);
            trail.SetColorChange(1, 0.5f, 0.5f, 0.5f, 0.5f);
            trail.SetInitialWidth(1, scale * 5f);
            trail.AddNode(animNode);


            // Add light
            Light light3 = scene.CreateLight("l3");

            light3.Diffuse = trail.GetInitialColor(1);
            animNode.AttachObject(light3);

            // Add billboard
            bbs = scene.CreateBillboardSet("bb2", 1);
            bbs.CreateBillboard(Vector3.Zero, trail.GetInitialColor(1));
            bbs.MaterialName = "flare";
            animNode.AttachObject(bbs);
        }