private void animationChanged(object sender, AnimationEventArgs e)
 {
     if (e is AnimationSkinnedEventArgs)
     {
         AnimationSkinnedEventArgs args = e as AnimationSkinnedEventArgs;
         m_animation = args.Source as AnimationPlayer;
     }
 }
        public override void doInitialize()
        {
            setModel();
            setMaterial();

            AnimationService animService = Owner.Game.Services.GetService(typeof(AnimationService)) as AnimationService;
            if (animService != null)
            {
                // test this should be done while loading the mesh
                //SkinningData skinData = m_model.Tag as SkinningData;
                //animService.addAnimation(new XnaScrapId(m_modelName), new AnimationPlayer.AnimationPlayerFactory(skinData));
                // end test
                m_animation = animService.getAnimation(new XnaScrapId(m_modelName)) as AnimationPlayer;

                //animService.animateMe(new XnaScrapId("template_run"), m_animation, new TimeSpan(),loop, animationChanged);
                //animService.animateMe(new XnaScrapId("template_fire_gun"), m_animation, new TimeSpan(),loop, animationChanged);

            }
            else
            {
                throw new ServiceNotFoundException("AnimationService not found", typeof(AnimationService));
            }

            // add to rendermanager
            RenderManager renderMan = Owner.Game.Services.GetService(typeof(RenderManager)) as RenderManager;
            renderMan.addRenderable(this, m_layer);

            // get position
            IPosition3D pos = Owner.getFirst(typeof(IPosition3D)) as IPosition3D;
            if (pos != null)
            {
                m_position = pos.Position;
                pos.PositionChanged += new XnaScrapCore.Core.Delegates.Position3DChangedEventHandler(PositionChanged);
            }

            // get orientation
            IOrientation3D orientation = Owner.getFirst(typeof(IOrientation3D)) as IOrientation3D;
            if (orientation != null)
            {
                m_orientation = orientation.Orientation;
                orientation.OrientationChanged += new XnaScrapCore.Core.Delegates.OrientationChangedEventHandler(OrientationChanged);
            }
            else
            {
                m_orientation = Quaternion.Identity;
            }

            // get dimension
            IScale3D scale = Owner.getFirst(typeof(IScale3D)) as IScale3D;
            if (scale != null)
            {
                m_scale = scale.Scale;
                scale.Changed += new Scale3DChangedEventHandler(scale_Changed);
            }

            // add to scenemanagement
            ISceneManager sceneManager = Owner.Game.Services.GetService(typeof(ISceneManager)) as ISceneManager;
            if (sceneManager != null)
            {
                BoundingBox bb = new BoundingBox();
                if (m_model != null)
                {
                    m_ModelBoundingBox = BoundingBox.CreateFromSphere(m_model.BoundingSphere);
                }
                bb.Min = m_ModelBoundingBox.Min + m_position;
                bb.Max = m_ModelBoundingBox.Max + m_position;
                m_sceneElement = sceneManager.insertElementVisual(bb, Owner);
            }

            base.doInitialize();
        }