Example #1
0
        protected override async Task LoadContent()
        {
            await base.LoadContent();

            var knightModel = Asset.Load <Model>("knight Model");

            knight = new Entity {
                new ModelComponent {
                    Model = knightModel
                }
            };
            knight.Transform.Position = new Vector3(0, 0f, 0f);
            var animationComponent = knight.GetOrCreate <AnimationComponent>();

            animationComponent.Animations.Add("Run", Asset.Load <AnimationClip>("knight Run"));
            animationComponent.Animations.Add("Idle", Asset.Load <AnimationClip>("knight Idle"));

            // We will test both non-optimized and optimized clips
            megalodonClip = CreateModelChangeAnimation(new ProceduralModelDescriptor(new CubeProceduralModel {
                Size = Vector3.One, MaterialInstance = { Material = knightModel.Materials[0].Material }
            }).GenerateModel(Services));
            knightOptimizedClip = CreateModelChangeAnimation(Asset.Load <Model>("knight Model"));
            knightOptimizedClip.Optimize();

            animationComponent.Animations.Add("ChangeModel1", megalodonClip);
            animationComponent.Animations.Add("ChangeModel2", knightOptimizedClip);

            Scene.Entities.Add(knight);

            camera          = new TestCamera();
            CameraComponent = camera.Camera;
            Script.Add(camera);

            LightingKeys.EnableFixedAmbientLight(GraphicsDevice.Parameters, true);
            GraphicsDevice.Parameters.Set(EnvironmentLightKeys.GetParameterKey(LightSimpleAmbientKeys.AmbientLight, 0), (Color3)Color.White);

            camera.Position = new Vector3(6.0f, 2.5f, 1.5f);
            camera.SetTarget(knight, true);
        }
Example #2
0
        protected override async Task LoadContent()
        {
            await base.LoadContent();

            spriteBatch = new SpriteBatch(GraphicsDevice);
            font        = Asset.Load <SpriteFont>("Font");

            wireframeState = RasterizerState.New(GraphicsDevice, new RasterizerStateDescription(CullMode.Back)
            {
                FillMode = FillMode.Wireframe
            });

            materials.Add(Asset.Load <Material>("NoTessellation"));
            materials.Add(Asset.Load <Material>("FlatTessellation"));
            materials.Add(Asset.Load <Material>("PNTessellation"));
            materials.Add(Asset.Load <Material>("PNTessellationAE"));
            materials.Add(Asset.Load <Material>("FlatTessellationDispl"));
            materials.Add(Asset.Load <Material>("FlatTessellationDisplAE"));
            materials.Add(Asset.Load <Material>("PNTessellationDisplAE"));

            var cube = new Entity("Cube")
            {
                new ModelComponent(new ProceduralModelDescriptor(new CubeProceduralModel {
                    Size = new Vector3(80), MaterialInstance = { Material = materials[0] }
                }).GenerateModel(Services))
            };
            var sphere = new Entity("Sphere")
            {
                new ModelComponent(new ProceduralModelDescriptor(new SphereProceduralModel {
                    Radius = 50, Tessellation = 5, MaterialInstance = { Material = materials[0] }
                }).GenerateModel(Services))
            };

            var megalodon = new Entity {
                new ModelComponent {
                    Model = Asset.Load <Model>("megalodon Model")
                }
            };

            megalodon.Transform.Position = new Vector3(0, -30f, -10f);

            var knight = new Entity {
                new ModelComponent {
                    Model = Asset.Load <Model>("knight Model")
                }
            };

            knight.Transform.RotationEulerXYZ = new Vector3(-MathUtil.Pi / 2, MathUtil.Pi / 4, 0);
            knight.Transform.Position         = new Vector3(0, -50f, 20f);
            knight.Transform.Scale            = new Vector3(0.6f);

            entities.Add(sphere);
            entities.Add(cube);
            entities.Add(megalodon);
            entities.Add(knight);

            camera          = new TestCamera();
            CameraComponent = camera.Camera;
            Script.Add(camera);

            LightingKeys.EnableFixedAmbientLight(GraphicsDevice.Parameters, true);
            GraphicsDevice.Parameters.Set(EnvironmentLightKeys.GetParameterKey(LightSimpleAmbientKeys.AmbientLight, 0), (Color3)Color.White);

            ChangeModel(0);
            SetWireframe(true);

            camera.Position = new Vector3(25, 45, 80);
            camera.SetTarget(currentEntity, true);
        }