Example #1
0
        protected override Task LoadContent()
        {
            //Profiler.Enable(GameProfilingKeys.GameDrawFPS);
            ProfilerSystem.EnableProfiling(false, GameProfilingKeys.GameDrawFPS);

            model = Content.Load<Model>("Model");
            material1 = Content.Load<Material>("Material1");
            material2 = Content.Load<Material>("Material2");

            SetupScene();

            int cubeWidth = 8;

            //var skybox = Asset.Load<Skybox>("Skybox");
            //var skyboxEntity = new Entity { new SkyboxComponent { Skybox = skybox } };
            //Scene.Entities.Add(skyboxEntity);

            //var backgroundTexture = Asset.Load<Texture>("XenkoBackground");
            //var backgroundEntity = new Entity { new BackgroundComponent { Texture = backgroundTexture } };
            //Scene.Entities.Add(backgroundEntity);

            for (int i = 0; i < cubeWidth; ++i)
            {
                for (int j = 0; j < cubeWidth; ++j)
                {
                    for (int k = 0; k < cubeWidth; ++k)
                    {
                        var position = new Vector3((i - cubeWidth / 2) * 2.4f, (j - cubeWidth / 2) * 2.4f, (k - cubeWidth / 2) * 2.4f);
                        //var material = (k/4)%2 == 0 ? material1 : material2;
                        var isShadowReceiver = (k / 2) % 2 == 0;

                        var entity = new Entity
                        {
                            new ModelComponent { Model = model, Materials = { material1 }, IsShadowReceiver = isShadowReceiver },
                        };
                        entity.Transform.Position = position;
                        Scene.Entities.Add(entity);
                    }
                }
            }

            //var spriteSheet = Asset.Load<SpriteSheet>("SpriteSheet");
            //var spriteEntity = new Entity
            //{
            //    new SpriteComponent
            //    {
            //        SpriteProvider = new SpriteFromSheet { Sheet = spriteSheet },
            //    }
            //};
            //Scene.Entities.Add(spriteEntity);

            camera.Position = new Vector3(35.0f, 5.5f, 22.0f);
            camera.SetTarget(Scene.Entities.Last(), true);

            return base.LoadContent();
        }
        public override void Initialize()
        {
            graphicsDevice = Services.GetServiceAs<IGraphicsDeviceService>().GraphicsDevice;

            triggerMaterial = PhysicsDebugShapeMaterial.Create(graphicsDevice, Color.AdjustSaturation(Color.Purple, 0.77f), 1);
            staticMaterial = PhysicsDebugShapeMaterial.Create(graphicsDevice, Color.AdjustSaturation(Color.Red, 0.77f), 1);
            dynamicMaterial = PhysicsDebugShapeMaterial.Create(graphicsDevice, Color.AdjustSaturation(Color.Green, 0.77f), 1);
            kinematicMaterial = PhysicsDebugShapeMaterial.Create(graphicsDevice, Color.AdjustSaturation(Color.Blue, 0.77f), 1);
            characterMaterial = PhysicsDebugShapeMaterial.Create(graphicsDevice, Color.AdjustSaturation(Color.LightPink, 0.77f), 1);
        }
        public PhysicsDebugShapeRendering(GraphicsDevice device)
        {
            graphicsDevice = device;

            triggerMaterial = PhysicsDebugShapeMaterial.Create(graphicsDevice, Color.AdjustSaturation(Color.Purple, 0.77f), 1);
            staticMaterial = PhysicsDebugShapeMaterial.Create(graphicsDevice, Color.AdjustSaturation(Color.Red, 0.77f), 1);
            dynamicMaterial = PhysicsDebugShapeMaterial.Create(graphicsDevice, Color.AdjustSaturation(Color.Green, 0.77f), 1);
            kinematicMaterial = PhysicsDebugShapeMaterial.Create(graphicsDevice, Color.AdjustSaturation(Color.Blue, 0.77f), 1);
            characterMaterial = PhysicsDebugShapeMaterial.Create(graphicsDevice, Color.AdjustSaturation(Color.Yellow, 0.77f), 1);

            rasterizer = RasterizerState.New(graphicsDevice, new RasterizerStateDescription(CullMode.None) { FillMode = FillMode.Wireframe });

            triggerMaterial.Parameters.Set(Effect.RasterizerStateKey, rasterizer);
            staticMaterial.Parameters.Set(Effect.RasterizerStateKey, rasterizer);
            dynamicMaterial.Parameters.Set(Effect.RasterizerStateKey, rasterizer);
            kinematicMaterial.Parameters.Set(Effect.RasterizerStateKey, rasterizer);
            characterMaterial.Parameters.Set(Effect.RasterizerStateKey, rasterizer);
        }
Example #4
0
        public bool UpdateMaterial()
        {
            var materialIndex = Mesh.MaterialIndex;
            Material = RenderModel.GetMaterial(materialIndex);
            var materialInstance = RenderModel.GetMaterialInstance(materialIndex);
            HasTransparency = Material != null && Material.HasTransparency;

            var modelComponent = RenderModel.ModelComponent;
            IsShadowCaster = modelComponent.IsShadowCaster;
            IsShadowReceiver = modelComponent.IsShadowReceiver;
            if (materialInstance != null)
            {
                IsShadowCaster = IsShadowCaster && materialInstance.IsShadowCaster;
                IsShadowReceiver = IsShadowReceiver && materialInstance.IsShadowReceiver;
            }

            return Material != null;
        }
        private void ChangeMaterial(int i)
        {
            currentMaterialIndex = ((currentMaterialIndex + i + materials.Count) % materials.Count);
            currentMaterial = materials[currentMaterialIndex];

            if (currentEntity != null)
            {
                var modelComponent = currentEntity.Get<ModelComponent>();
                modelComponent.Materials.Clear();

                if (modelComponent.Model != null)
                {
                    // ensure the same number of materials than original model.
                    for (int j = 0; j < modelComponent.Model.Materials.Count; j++)
                        modelComponent.Materials[j] = currentMaterial;
                }
            }
        }
Example #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MaterialInstance"/> class.
 /// </summary>
 /// <param name="material">The material.</param>
 public MaterialInstance(Material material)
 {
     Material = material;
     IsShadowCaster = true;
     IsShadowReceiver = true;
 }