コード例 #1
0
ファイル: BoardObject.cs プロジェクト: HATtrick-games/ICT309
        protected override void OnLoad()
        {
            var contentManager = ServiceLocator.Current.GetInstance<ContentManager>();
            var graphicsService = ServiceLocator.Current.GetInstance<IGraphicsService>();
            var screen = ((BasicScreen)graphicsService.Screens["Default"]);

            _model = contentManager.Load<ModelNode>(_modelFile);
            _model = _model.Clone();

            foreach (var meshNode in _model.GetSubtree().OfType<MeshNode>())
            {
                Mesh mesh = meshNode.Mesh;
                foreach (var material in mesh.Materials)
                {
                    var effectBinding = material["Default"];
                    effectBinding.Set("DiffuseColor", new Vector4(1.0f, 1.0f, 1.0f, 1));
                    ((BasicEffectBinding)effectBinding).LightingEnabled = false;
                }
            }

            screen.Scene.Children.Add(_model);

            _model.PoseWorld = new DigitalRune.Geometry.Pose(new Vector3F(0.0f, 0.0f, 0.0f));

            base.OnLoad();
        }
コード例 #2
0
    public MeshNodeSample(Microsoft.Xna.Framework.Game game)
      : base(game)
    {
      SampleFramework.IsMouseVisible = false;
      var delegateGraphicsScreen = new DelegateGraphicsScreen(GraphicsService)
      {
        RenderCallback = Render,
      };
      GraphicsService.Screens.Insert(0, delegateGraphicsScreen);

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

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

      // Load a model. The model is processed using the DigitalRune Model Processor - not 
      // the default XNA model processor!
      // In the folder that contains tank.fbx, there is an XML file tank.drmdl which defines 
      // properties of the model. These XML files are automatically processed by the 
      // DigitalRune Model Processor. 
      // Each model itself is a tree of scene nodes. The grid model contains one mesh 
      // node. The tank model contains several mesh nodes (turret, cannon, hatch, 
      // wheels, ...).
      _model = ContentManager.Load<ModelNode>("Tank/tank");

      // The XNA ContentManager manages a single instance of each model. We clone 
      // the model, to get a copy that we can modify without changing the original 
      // instance. Cloning is fast because it only duplicates the scene nodes - but 
      // not the mesh and material information.
      _model = _model.Clone();

      // _model is the root of a tree of scene nodes. The mesh nodes are the child 
      // nodes. When we scale or move the _model, we automatically scale and move 
      // all child nodes.
      _model.ScaleLocal = new Vector3F(0.8f);
      _model.PoseWorld = new Pose(new Vector3F(0, 0, -2), Matrix33F.CreateRotationY(-0.3f));

      // Let's loop through the mesh nodes of the model:
      foreach (var meshNode in _model.GetSubtree().OfType<MeshNode>())
      {
        // Each MeshNode references a Mesh.
        Mesh mesh = meshNode.Mesh;

        // The mesh consists of several submeshes and several materials - usually 
        // one material per submesh, but several submeshes could reference the same 
        // materials.

        // Let's loop through the materials of this mesh.
        foreach (var material in mesh.Materials)
        {
          // A material is a collection of EffectBindings - one EffectBinding for each
          // render pass. For example, a complex game uses several render passes, like
          // a pre-Z pass, a G-buffer pass, a shadow map pass, a deferred material pass, 
          // etc.In simple games there is only one pass which is called "Default".
          var effectBinding = material["Default"];

          // An EffectBinding references an Effect (the XNA Effect class) and it has
          // "parameter bindings" and "technique bindings". These bindings select the 
          // values for the shader parameters when the mesh node is rendered. 

          // Let's change the binding for the DiffuseColor of the shader to give tank 
          // a red color.
          effectBinding.Set("DiffuseColor", new Vector4(1, 0.7f, 0.7f, 1));

          // The tank uses the default effect binding which is a BasicEffectBinding - this
          // effect binding uses the XNA BasicEffect. 
          // In this sample we do not define any lights, therefore we disable the lighting
          // in the shader.
          ((BasicEffectBinding)effectBinding).LightingEnabled = false;
        }
      }

      _meshRenderer = new MeshRenderer();

      var spriteFont = UIContentManager.Load<SpriteFont>("UI Themes/BlendBlue/Default");
      _debugRenderer = new DebugRenderer(GraphicsService, spriteFont);
    }
コード例 #3
0
    public BasicEffectSample(Microsoft.Xna.Framework.Game game)
      : base(game)
    {
      SampleFramework.IsMouseVisible = false;
      GraphicsScreen.ClearBackground = true;
      GraphicsScreen.BackgroundColor = Color.CornflowerBlue;
      SetCamera(new Vector3F(8, 6, 8), ConstantsF.PiOver4, -0.4f);

      // Load the models. The models are processed using the DigitalRune Model 
      // Processor - not the default XNA model processor!
      // In the folder that contains tank.fbx, there is an XML file tank.drmdl which defines 
      // properties of the model. These XML files are automatically processed by 
      // the DigitalRune Model Processor. Please browse to the content folder and 
      // have a look at the *.drmdl file. For the grid model there is no such file but
      // the DigitalRune model content processor will create one automatically with the default
      // materials found in the model. 
      // Each model itself is a tree of scene nodes. The grid model 
      // contains one mesh node. The tank model contains several mesh nodes (turret, 
      // cannon, hatch, wheels, ...).
      _grid = ContentManager.Load<ModelNode>("Ground/Ground");
      _tank = ContentManager.Load<ModelNode>("Tank/tank");

      // The XNA ContentManager manages a single instance of each model. We clone 
      // the models, to get a copy that we can modify without changing the original 
      // instance. 
      // Cloning is fast because it only duplicates the scene nodes - but not the 
      // mesh and material information.
      _grid = _grid.Clone();
      _tank = _tank.Clone();

      // The grid is a bit too large. We can scale it to make it smaller.
      _grid.ScaleLocal = new Vector3F(0.3f);

      // No need to scale the tank model - the tank was already scaled by the 
      // DigitalRune Model Processor because a scale factor is defined in the 
      // Tank.drmdl file.

      // Add the models to the scene.
      GraphicsScreen.Scene.Children.Add(_grid);
      GraphicsScreen.Scene.Children.Add(_tank);

      /*
        // If you want to turn off some of the default lights, you can get them by 
        // their name and change IsEnabled flags.
        var keyLight = (LightNode)_graphicsScreen.Scene.GetSceneNode("KeyLight");
        var fillLight = (LightNode)_graphicsScreen.Scene.GetSceneNode("FillLight");
        fillLight.IsEnabled = false;
        var backLight = (LightNode)_graphicsScreen.Scene.GetSceneNode("BackLight");
        backLight.IsEnabled = false;
      */

      /*
        // If you want to change the material properties of the tank, you can do this:
        // Loop through all mesh nodes of the tank.
        foreach (var meshNode in _tank.GetSubtree().OfType<MeshNode>())
        {
          // Loop through all materials of this mesh (each mesh can consist of several 
          // submeshes with different materials).
          foreach (var material in meshNode.Mesh.Materials)
          {
            // Get all BasicEffectBindings which wrap the XNA BasicEffect. 
            // A material can consist of several effects - one effect for each render 
            // pass. (Per default there is only one render pass called "Default".)
            foreach (var effectBinding in material.EffectBindings.OfType<BasicEffectBinding>())
            {
              effectBinding.PreferPerPixelLighting = true;
              effectBinding.Set("SpecularColor", new Vector3(1, 0, 0));
            }
          }
        }
      */

      CreateAndStartAnimations();
    }