private void Play(AnimationQueue.ClipPlaybackParameters clipParameters, int bones) { _parameters = clipParameters; if (_parameters.Clip == null) throw new ArgumentNullException("clipParameters"); if (_parameters.Interpolator == null) _parameters.Interpolator = Interpolation.Linear(); Animation = clipParameters.Clip; _channelFrames = new int[Animation.ChannelCount]; _transforms = new Transform[Animation.ChannelCount]; Start(); }
public AnimatedDude(IKernel kernel, ContentManager content, GraphicsDevice device) : base("Animated Dude", kernel) { _scene = kernel.Get<Scene>(); var model = content.Load<ModelData>(@"models/zoe"); var dude = kernel.Get<EntityDescription>(); dude.AddProperty(new TypedName<ModelData>("model"), model); dude.AddProperty(new TypedName<Matrix>("transform"), Matrix.CreateScale(50f) * Matrix.CreateTranslation(0, 0, -150)); dude.AddProperty(new TypedName<bool>("is_static"), false); dude.AddBehaviour<ModelInstance>(); dude.AddBehaviour<Animated>(); dude.AddBehaviour<AnimationQueue>(); var dudeEntity = dude.Create(); _scene.Add(dudeEntity); _animationQueue = dudeEntity.GetBehaviour<AnimationQueue>(null); _animationQueue.EnableRootBoneTranslationY = false; _animationQueue.EnableRootBoneTranslationX = false; _animationQueue.EnableRootBoneTranslationZ = false; _animationQueue.EnableRootBoneScale = false; _dude = dudeEntity.GetBehaviour<ModelInstance>(null); _animationQueue.DefaultClip = new AnimationQueue.ClipPlaybackParameters { Clip = content.Load<Clip>("Models/ZoeAnimations/t-pose"), FadeInTime = TimeSpan.FromSeconds(0.25f), FadeOutTime = TimeSpan.FromSeconds(0.25f), Loop = true, }; foreach (var name in _sequence) { _animationQueue.EnqueueClip(new AnimationQueue.ClipPlaybackParameters { Clip = content.Load<Clip>("Models/ZoeAnimations/" + name), FadeInTime = TimeSpan.FromSeconds(0.1f), FadeOutTime = TimeSpan.FromSeconds(0.0f), Loop = false, }); } var camera = new Camera { NearClip = 1, FarClip = 7000, View = Matrix.CreateLookAt(new Vector3(100, 50, -200), new Vector3(0, 20, 0), Vector3.Up) }; camera.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(60), 16f / 9f, camera.NearClip, camera.FarClip); var cameraDesc = kernel.Get<EntityDescription>(); cameraDesc.AddProperty(new TypedName<Camera>("camera")); cameraDesc.AddProperty(new TypedName<Viewport>("viewport")); cameraDesc.AddBehaviour<View>(); var cameraEntity = cameraDesc.Create(); cameraEntity.GetProperty(new TypedName<Camera>("camera")).Value = camera; cameraEntity.GetProperty(new TypedName<Viewport>("viewport")).Value = new Viewport() { Width = device.PresentationParameters.BackBufferWidth, Height = device.PresentationParameters.BackBufferHeight }; _scene.Add(cameraEntity); var ambientLight = kernel.Get<EntityDescription>(); ambientLight.AddProperty(new TypedName<Vector3>("sky_colour"), new Vector3(0.44f, 0.44f, 0.74f)); ambientLight.AddProperty(new TypedName<Vector3>("ground_colour"), new Vector3(0.24f, 0.35f, 0.24f)); ambientLight.AddProperty(new TypedName<Vector3>("up"), Vector3.Up); ambientLight.AddBehaviour<AmbientLight>(); _scene.Add(ambientLight.Create()); var sponza = kernel.Get<EntityDescription>(); sponza.AddProperty(new TypedName<ModelData>("model"), content.Load<ModelData>(@"Sponza")); sponza.AddProperty(new TypedName<Matrix>("transform"), Matrix.CreateScale(0.5f) * Matrix.CreateTranslation(-350, 0, 0)); sponza.AddProperty(new TypedName<bool>("is_static"), true); sponza.AddBehaviour<ModelInstance>(); _scene.Add(sponza.Create()); var spotLight = kernel.Get<EntityDescription>(); spotLight.AddProperty(new TypedName<Vector3>("position"), new Vector3(150, 50, -50)); spotLight.AddProperty(new TypedName<Vector3>("colour"), new Vector3(1)); spotLight.AddProperty(new TypedName<Vector3>("direction"), new Vector3(-1, 0, 0.25f)); spotLight.AddProperty(new TypedName<float>("angle"), MathHelper.PiOver2); spotLight.AddProperty(new TypedName<float>("range"), 1000); spotLight.AddProperty(new TypedName<int>("shadow_resolution"), 1024); spotLight.AddBehaviour<SpotLight>(); var spotLightEntity = spotLight.Create(); _scene.Add(spotLightEntity); _scene.GetService<Renderer>().StartPlan() .Then<GeometryBufferComponent>() .Then<EdgeDetectComponent>() .Then<Ssao>() .Then<LightingComponent>() .Then<TranslucentComponent>() .Then<ToneMapComponent>() .Then<AntiAliasComponent>() .Apply(); }
internal static PlayingClip Create(AnimationQueue.ClipPlaybackParameters clip, int bones) { PlayingClip instance; lock (_pool) instance = _pool.Get(); instance.Play(clip, bones); return instance; }