Beispiel #1
0
    public ProxyNodeSample(Microsoft.Xna.Framework.Game game)
      : base(game)
    {
      SampleFramework.IsMouseVisible = false;
      var delegateGraphicsScreen = new DelegateGraphicsScreen(GraphicsService)
      {
        RenderCallback = Render,
      };
      GraphicsService.Screens.Insert(0, delegateGraphicsScreen);

      _renderer = new MeshRenderer();

      // Add a custom game object which controls the camera.
      _cameraObject = new CameraObject(Services);
      GameObjectService.Objects.Add(_cameraObject);

      _scene = new Scene();
      SceneSample.InitializeDefaultXnaLights(_scene);

      // For advanced users: Set this flag if you want to analyze the imported opaque data of
      // effect bindings.
      EffectBinding.KeepOpaqueData = true;

      // Original model in scene graph.
      var modelNode = ContentManager.Load<ModelNode>("Dude/Dude").Clone();
      modelNode.PoseLocal = new Pose(new Vector3F(-2, 0, 0));
      var meshNode = modelNode.GetSubtree().OfType<MeshNode>().First();
      _scene.Children.Add(modelNode);

      // Clone referenced by proxy node.
      var modelNode2 = modelNode.Clone();
      var meshNode2 = modelNode2.GetSubtree().OfType<MeshNode>().First();
      meshNode2.SkeletonPose = meshNode.SkeletonPose;
      _proxyNode = new ProxyNode(null)
      {
        Name = "Proxy",
        PoseLocal = new Pose(new Vector3F(2, 0, 0), Matrix33F.CreateRotationY(ConstantsF.Pi)),
        ScaleLocal = new Vector3F(0.5f),
      };
      _scene.Children.Add(_proxyNode);
      _proxyNode.Node = modelNode2;

      var spriteFont = UIContentManager.Load<SpriteFont>("UI Themes/BlendBlue/Default");
      _debugRenderer = new DebugRenderer(GraphicsService, spriteFont);

      var mesh = meshNode.Mesh;
      foreach (var m in mesh.Materials)
      {
        //((ConstParameterBinding<Vector3>)m["Default"].ParameterBindings["SpecularColor"]).Value = new Vector3();
        ((SkinnedEffectBinding)m["Default"]).PreferPerPixelLighting = true;
      }

      var timeline = new TimelineClip(mesh.Animations.Values.First())
      {
        Duration = TimeSpan.MaxValue,
        LoopBehavior = LoopBehavior.Cycle,
      };
      AnimationService.StartAnimation(timeline, (IAnimatableProperty)meshNode.SkeletonPose);
    }
Beispiel #2
0
        public ProxyNodeSample(Microsoft.Xna.Framework.Game game)
            : base(game)
        {
            SampleFramework.IsMouseVisible = false;
            var delegateGraphicsScreen = new DelegateGraphicsScreen(GraphicsService)
            {
                RenderCallback = Render,
            };

            GraphicsService.Screens.Insert(0, delegateGraphicsScreen);

            _renderer = new MeshRenderer();

            // Add a custom game object which controls the camera.
            _cameraObject = new CameraObject(Services);
            GameObjectService.Objects.Add(_cameraObject);

            _scene = new Scene();
            SceneSample.InitializeDefaultXnaLights(_scene);

            // For advanced users: Set this flag if you want to analyze the imported opaque data of
            // effect bindings.
            EffectBinding.KeepOpaqueData = true;

            // Original model in scene graph.
            var modelNode = ContentManager.Load <ModelNode>("Dude/Dude").Clone();

            modelNode.PoseLocal = new Pose(new Vector3(-2, 0, 0));
            var meshNode = modelNode.GetSubtree().OfType <MeshNode>().First();

            _scene.Children.Add(modelNode);

            // Clone referenced by proxy node.
            var modelNode2 = modelNode.Clone();
            var meshNode2  = modelNode2.GetSubtree().OfType <MeshNode>().First();

            meshNode2.SkeletonPose = meshNode.SkeletonPose;
            _proxyNode             = new ProxyNode(null)
            {
                Name       = "Proxy",
                PoseLocal  = new Pose(new Vector3(2, 0, 0), Matrix.CreateRotationY(ConstantsF.Pi)),
                ScaleLocal = new Vector3(0.5f),
            };
            _scene.Children.Add(_proxyNode);
            _proxyNode.Node = modelNode2;

            var spriteFont = UIContentManager.Load <SpriteFont>("UI Themes/BlendBlue/Default");

            _debugRenderer = new DebugRenderer(GraphicsService, spriteFont);

            var mesh = meshNode.Mesh;

            foreach (var m in mesh.Materials)
            {
                //((ConstParameterBinding<Vector3>)m["Default"].ParameterBindings["SpecularColor"]).Value = new Vector3();
                ((SkinnedEffectBinding)m["Default"]).PreferPerPixelLighting = true;
            }

            var timeline = new TimelineClip(mesh.Animations.Values.First())
            {
                Duration     = TimeSpan.MaxValue,
                LoopBehavior = LoopBehavior.Cycle,
            };

            AnimationService.StartAnimation(timeline, (IAnimatableProperty)meshNode.SkeletonPose);
        }