コード例 #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
    // OnLoad() is called when the GameObject is added to the IGameObjectService.
    protected override void OnLoad()
    {
      // Load model.
      var contentManager = _services.GetInstance<ContentManager>();
      _modelNode = contentManager.Load<ModelNode>("Ground/Ground").Clone();
      _modelNode.ScaleLocal = new Vector3F(0.5f);

      foreach (var node in _modelNode.GetSubtree())
      {
        // Disable the CastsShadows flag for ground meshes. No need to render
        // this model into the shadow map. (This also avoids any shadow acne on 
        // the ground model.)
        node.CastsShadows = false;

        // If models will never move, set the IsStatic flag. This gives the engine 
        // more room for optimizations. Additionally, some effects, like certain 
        // decals, may only affect static geometry.
        node.IsStatic = true;
      }

      // Add model node to scene graph.
      var scene = _services.GetInstance<IScene>();
      scene.Children.Add(_modelNode);

      // Create rigid body.
      _rigidBody = new RigidBody(new PlaneShape(Vector3F.UnitY, 0))
      {
        MotionType = MotionType.Static,
      };

      // Add rigid body to the physics simulation.
      var simulation = _services.GetInstance<Simulation>();
      simulation.RigidBodies.Add(_rigidBody);
    }
コード例 #3
0
        public RedSquareObject(Vector3F position)
        {
            _position = position;
            _color = new Vector4(1.0f, 0.0f, 0.0f, 1.0f);

            var graphicsService = ServiceLocator.Current.GetInstance<IGraphicsService>();
            var screen = ((GameScreen)graphicsService.Screens["Default"]);
            var contentManager = ServiceLocator.Current.GetInstance<ContentManager>();

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

            screen.Scene.Children.Add(_model);

            _model.PoseWorld = new Pose(_position);

            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", _color);
                    ((BasicEffectBinding)effectBinding).LightingEnabled = false;
                }
            }

            InUse = true;
        }
コード例 #4
0
    // OnLoad() is called when the GameObject is added to the IGameObjectService.
    protected override void OnLoad()
    {
      // Load model.
      var contentManager = _services.GetInstance<ContentManager>();
      _modelNode = contentManager.Load<ModelNode>(_assetName).Clone();

      // Optional: Create rigid body using the triangle mesh of the model.
      if (_addRigidBody)
        CreateRigidBody();

      _modelNode.ScaleLocal = _scale;
      _modelNode.PoseLocal = _pose;

      foreach (var node in _modelNode.GetSubtree())
      {
        node.CastsShadows = _castsShadows;

        // If models will never move, set the IsStatic flag. This gives the engine 
        // more room for optimizations. Additionally, some effects, like certain 
        // decals, may only affect static geometry.
        node.IsStatic = true;
      }

      // Add model node to scene graph.
      var scene = _services.GetInstance<IScene>();
      scene.Children.Add(_modelNode);
    }
コード例 #5
0
    public ManualMeshRenderSample(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);

      _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;

      _model = ContentManager.Load<ModelNode>("Dude/Dude").Clone();
      var meshNode = _model.GetSubtree().OfType<MeshNode>().First();
      meshNode.ScaleLocal = new Vector3F(1, 2, 1);
      var mesh = meshNode.Mesh;
      var timeline = new TimelineClip(mesh.Animations.Values.First())
      {
        Duration = TimeSpan.MaxValue,
        LoopBehavior = LoopBehavior.Cycle,
      };
      AnimationService.StartAnimation(timeline, (IAnimatableProperty)meshNode.SkeletonPose);
    }
コード例 #6
0
ファイル: GameScreen.cs プロジェクト: HATtrick-games/ICT309
        public override void LoadContent()
        {
            _model = _graphicsService.Content.Load<ModelNode>("testmodel").Clone();

            // 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;
                }
            }

            base.LoadContent();
        }
コード例 #7
0
    // OnLoad() is called when the GameObject is added to the IGameObjectService.
    protected override void OnLoad()
    {
      // Load sandbox model.
      var contentManager = _services.GetInstance<ContentManager>();
      _modelNode = contentManager.Load<ModelNode>("Sandbox/Sandbox").Clone();

      foreach (var node in _modelNode.GetSubtree())
      {
        // Disable the CastsShadows flag. The inside of the box should be fully lit.
        node.CastsShadows = false;

        // If models will never move, set the IsStatic flag. This gives the engine 
        // more room for optimizations. Additionally, some effects, like certain 
        // decals, may only affect static geometry.
        node.IsStatic = true;
      }

      // Add the "Sandbox" model to the scene.
      var scene = _services.GetInstance<IScene>();
      scene.Children.Add(_modelNode);

      // Create rigid bodies for the sides of the sandbox.
      _floorRigidBody = new RigidBody(new PlaneShape(new Vector3F(0, 1, 0), 0))
      {
        Name = "Floor",
        MotionType = MotionType.Static,
      };
      _floorRigidBody.CollisionObject.CollisionGroup = 1;
      _leftWallRigidBody = new RigidBody(new PlaneShape(new Vector3F(1, 0, 0), -10))
      {
        Name = "WallLeft",
        MotionType = MotionType.Static,
      };
      _leftWallRigidBody.CollisionObject.CollisionGroup = 1;
      _rightWallRigidBody = new RigidBody(new PlaneShape(new Vector3F(-1, 0, 0), -10))
      {
        Name = "WallRight",
        MotionType = MotionType.Static,
      };
      _rightWallRigidBody.CollisionObject.CollisionGroup = 1;
      _backWallRigidBody = new RigidBody(new PlaneShape(new Vector3F(0, 0, 1), -10))
      {
        Name = "WallBack",
        MotionType = MotionType.Static,
      };
      _backWallRigidBody.CollisionObject.CollisionGroup = 1;
      _frontWallRigidBody = new RigidBody(new PlaneShape(new Vector3F(0, 0, -1), -10))
      {
        Name = "WallFront",
        MotionType = MotionType.Static,
      };
      _frontWallRigidBody.CollisionObject.CollisionGroup = 1;

      // Add rigid bodies to simulation.
      var simulation = _services.GetInstance<Simulation>();
      simulation.RigidBodies.Add(_floorRigidBody);
      simulation.RigidBodies.Add(_leftWallRigidBody);
      simulation.RigidBodies.Add(_rightWallRigidBody);
      simulation.RigidBodies.Add(_backWallRigidBody);
      simulation.RigidBodies.Add(_frontWallRigidBody);
    }
コード例 #8
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);
    }