Esempio n. 1
0
        public ImportNode MockImportJson()
        {
            ImportNode root = jsonParser.Load();

            //_documentTypeImporter.Import(root.DocumentTypes);
            _dataTypeImporter.Import(root.DataTypes);

            _contentImporter.Import(root.Content);

            return(root);
        }
Esempio n. 2
0
        public void BlendAnimation()
        {
            SceneTests.InitializeScene();

            ContentImporter.Import(SceneManager.Scene, @"C:\Users\ansel\Documents\3dsmax\export\Lighting\armed.DAE")
            .OnSceneAttach(SceneManager.Scene);
            ContentImporter.ImportAnimation(SceneManager.Scene, @"C:\Users\ansel\Documents\3dsmax\export\Lighting\walk.DAE")
            .OnSceneAttach(SceneManager.Scene);

            var armed = SceneManager.Scene.AnimManager.Animations[0];
            var walk  = SceneManager.Scene.AnimManager.Animations[1];

            Frame root        = SceneManager.Scene.EnumerateNodesPosOrden().First(x => x.Type == FrameType.Bone);
            var   resetter    = new BonesResetter(root);
            var   translation = root.LocalPosition;

            var cursorArmed = armed.GetCursor(0);
            var cursorWalk  = walk.GetCursor(0);

            cursorArmed.Looping = AnimationLooping.Loop;
            cursorWalk.Looping  = AnimationLooping.Loop;

            SceneManager.Scene.Dynamics.Add(
                new Dynamic(deltaT =>
            {
                resetter.Reset();

                walk.Update(deltaT, 0, 1, true);
                armed.Update(deltaT, 0, 1, true);

                root.LocalPosition = translation;
                root.CommitChanges();
            })
                );
        }
Esempio n. 3
0
        public void TestPlanarReflection()
        {
            using (OpenFileDialog d = new OpenFileDialog())
            {
                if (d.ShowDialog() == DialogResult.OK)
                {
                    SceneTests.InitializeScene();
                    var content = ContentImporter.Import(SceneManager.Scene, d.FileName);
                    ReflectiveNodeTechnique technique = SceneManager.Scene.EnumerateNodesInPreOrden().Where(x => x.Technique is ReflectiveNodeTechnique).Select(x => (ReflectiveNodeTechnique)x.Technique).FirstOrDefault();
                    Engine.Presenter.Rendering += () =>
                    {
                        var untranformed = Service.Require <RenderQuadEffect>();
                        var sprite       = Service.Require <Sprite>();
                        GraphicDeviceFactory.Device.Ps.SetResource(0, technique.ReflectionTexture);

                        untranformed.U.alpha   = 1;
                        untranformed.Technique = 1;

                        sprite.Begin();
                        sprite.SetTrasform(untranformed, new Rectangle(0, 0, 256, 256), Matrix.Identity);
                        sprite.DrawQuad(untranformed);
                        sprite.End();
                    };
                }
            }
        }
        public void CreateThirdPersonController()
        {
            const float startTimeWalk = 34f / 30f;
            const float endTimeWalk   = 63f / 30f;
            const float durationWalk  = endTimeWalk - startTimeWalk;
            const float startTimeIdle = 0;
            const float endTimeIdle   = 0;
            const float durationIdle  = endTimeIdle;
            const float blendDuration = 0.25f;

            const float startTimeRun = 15f / 30f;
            const float endRunTime   = 80f / 30f;
            const float durationRun  = endRunTime - startTimeRun;

            SceneTests.InitializeScene();
            SceneManager.Scene.Physics.Enable  = true;
            SceneManager.Scene.Physics.Visible = false;

            CharacterControllerTagProcessor.ControllerCreated += CharacterControllerTagProcessor_ControllerCreated;

            ContentImporter.Import(SceneManager.Scene, @"C:\Users\ansel\Documents\3dsmax\export\game_level0\game_level0.DAE");
            ContentImporter.ImportAnimation(SceneManager.Scene, @"C:\Users\ansel\Documents\3dsmax\export\Lighting\walk.DAE");
            ContentImporter.ImportAnimation(SceneManager.Scene, @"C:\Users\ansel\Documents\3dsmax\export\Lighting\run.DAE");

            CharacterController controller = CharacterControllerManager.Instance.Controllers[0];
            var animationWalk = SceneManager.Scene.AnimManager.Animations[1];
            var animationRun  = SceneManager.Scene.AnimManager.Animations[2];

            var character = (((Frame)controller.Affectable)).FindNode((Frame x) => x.Type == FrameType.Bone);

            SceneManager.Scene.FindNode("camera1").BindTo(character);

            ThirdPersonControllerDesc desc = new ThirdPersonControllerDesc
            {
                CollitionController = controller,
                Character           = character,
                CameraMaxDistance   = 100,
                CameraMinDistance   = 20,
                CameraMaxPich       = Numerics.ToRadians(45),
                CameraMinPich       = Numerics.ToRadians(25),
                TransitionTime      = blendDuration,
                Camera = SceneManager.Scene.FindNode("camera1"),
                Idle   = new KeyFrameAnimationPlayback(animationWalk, startTimeIdle, durationIdle, AnimationLooping.Loop),
                Walk   = new KeyFrameAnimationPlayback(animationWalk, startTimeWalk, durationWalk, AnimationLooping.Loop, velocity: 1),
                //Walk = new AnimationPlayback(animationRun, startTimeRun, durationRun, AnimationLooping.Secuential),
            };
            ThirdPersonController characterController = new ThirdPersonController(desc);

            SceneManager.Scene.Dynamics.Add(characterController);

            //EngineState.Shadow.ShadowMapping.Bias = 0.9e-2f;
            FrameLight.CreateShadowMapForAllLights(SceneManager.Scene);
        }
 private void Import3DContent()
 {
     using (OpenFileDialog d = new OpenFileDialog())
     {
         if (d.ShowDialog() == DialogResult.OK)
         {
             var content = ContentImporter.Import(SceneManager.Scene, d.FileName);
             if (SceneManager.Scene.Physics != null)
             {
                 SceneManager.Scene.Physics.Enable = true;
             }
         }
     }
 }
Esempio n. 6
0
        ContentPackage ImportContent()
        {
            ContentPackage content = null;

            using (OpenFileDialog d = new OpenFileDialog())
            {
                if (d.ShowDialog() == DialogResult.OK)
                {
                    SceneTests.InitializeScene();
                    content = ContentImporter.Import(SceneManager.Scene, d.FileName);
                }
            }
            return(content);
        }
Esempio n. 7
0
        public void ImportScene2()
        {
            ContentImporter.Import(_scene, "Assets/sample2/sample2.dae");

            Assert.True(_scene.Root.Childrens.Count > 0);

            var visualRoot = _scene.Root.Childrens[0];

            Assert.Equal(5, visualRoot.Childrens.Count);
            Assert.Equal(3, _scene.Meshes.Count);
            Assert.Equal(1, _scene.Cameras.Count);
            Assert.Equal(1, _scene.Lights.Count);
            Assert.Equal(3, _scene.Materials.Count);
            Assert.NotEmpty(_scene.Textures);
        }
Esempio n. 8
0
        public void TestEnvironmentMap()
        {
            using (OpenFileDialog d = new OpenFileDialog())
            {
                if (d.ShowDialog() == DialogResult.OK)
                {
                    SceneTests.InitializeScene();
                    var content   = ContentImporter.Import(SceneManager.Scene, d.FileName);
                    var technique = SceneManager.Scene.EnumerateNodesInPreOrden().Where(x => x.Technique is EnvironmentMapTechnique).Select(x => (EnvironmentMapTechnique)x.Technique).FirstOrDefault();
                    Engine.Presenter.Rendering += () =>
                    {
                        if (_rastState == null)
                        {
                            _rastState = GraphicDeviceFactory.Device.CreateRasterizerState(new RasterizerDesc(true)
                            {
                                Fill = FillMode.Wireframe,
                                Cull = CullMode.None
                            });
                        }
                        var device = GraphicDeviceFactory.Device;
                        var effect = Service.Require <RenderMeshColorEffect>();

                        effect.U.ViewProj = SceneManager.Scene.ActiveCamera.ViewProj;
                        effect.U.Color    = new Vector4(1);

                        device.RasterizerStack.Push(_rastState);
                        device.PrimitiveTopology = IaPrimitive.TriangleList;
                        device.SetVertexBuffer(0, _vb, 0);
                        var oldtech = effect.Technique;
                        foreach (var pass in effect.Passes(1))
                        {
                            effect.Apply(pass);
                            foreach (var camera in technique.Cameras)
                            {
                                effect.U.World = camera.InvViewProjection;
                                device.Draw(_boxBuilder.Vertices.Length, 0);
                                //device.DrawIndexedUser(0, boxBuilder.Vertices.Length, boxBuilder.Indices.Length / 3, boxBuilder.Indices, boxBuilder.Vertices);
                            }
                        }
                        effect.EndPasses();

                        effect.Technique = oldtech;
                        device.RasterizerStack.Pop();
                    };
                }
            }
        }
Esempio n. 9
0
        public async Task <ActionResult <SceneDto> > Get(string name = "sample1")
        {
            var file = $"Assets/{name}/{name}.dae";

            if (!System.IO.File.Exists(file))
            {
                return(NotFound());
            }

            var dto = await Task.Run(() =>
            {
                Scene scene = new Scene(name);
                ContentImporter.Import(scene, file);
                return(scene.ToDto());
            });

            return(dto);
        }
Esempio n. 10
0
        private static void ConvertDae(FileInfo fi, string destination)
        {
            var   name  = Path.GetFileNameWithoutExtension(fi.Name);
            Scene scene = new Scene(name);

            ContentImporter.Import(scene, fi.FullName);
            var dto   = scene.ToDto();
            var json  = JsonConvert.SerializeObject(dto);
            var bytes = System.Text.Json.JsonSerializer.SerializeToUtf8Bytes(dto, new JsonSerializerOptions
            {
                PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
                IgnoreNullValues     = true
            });

            var filename = Path.Combine(destination ?? fi.DirectoryName, name + ".scene.json");

            File.WriteAllBytes(filename, bytes);
        }
        public void CreateControllerFromFile()
        {
            SceneTests.InitializeScene();

            SceneManager.Scene.Physics.Enable  = true;
            SceneManager.Scene.Physics.Visible = true;

            CharacterControllerTagProcessor.ControllerCreated += CharacterControllerTagProcessor_ControllerCreated;
            ContentImporter.Import(SceneManager.Scene, @"C:\Users\ansel\Documents\3dsmax\export\controller.DAE");
            CharacterController controller = CharacterControllerManager.Instance.Controllers[0];

            SceneManager.Scene.Dynamics.Add(new Dynamic(deltaT =>
            {
                var camera        = SceneManager.Scene.ActiveCamera;
                Vector3 direction = new Vector3();
                if (Engine.KeyBoard.IsKeyPressed(Keys.O))
                {
                    direction = camera.Front;
                }
                if (Engine.KeyBoard.IsKeyPressed(Keys.L))
                {
                    direction = -camera.Front;
                }
                if (Engine.KeyBoard.IsKeyPressed(Keys.K))
                {
                    direction = -camera.Right;
                }
                if (Engine.KeyBoard.IsKeyPressed(Keys.Semicolon))
                {
                    direction = camera.Right;
                }
                if (Engine.KeyBoard.IsKeyPressed(Keys.P))
                {
                    direction = camera.Up;
                }
                if (Engine.KeyBoard.IsKeyPressed(Keys.I))
                {
                    direction = -camera.Up;
                }

                CollitionResult result = controller.Move(direction * 100 * deltaT, (1 << (int)CollisionGroup.GroupNonCollidable) |
                                                         (1 << (int)CollisionGroup.GroupCollidableNonPushable), 0.000001f, 1.0f);
            }));
        }
Esempio n. 12
0
        public void Import()
        {
            EngineState.Lighting.TransparencyEnable = true;
            TestSettings.UseFrameLines = false;

            using (OpenFileDialog d = new OpenFileDialog())
            {
                if (d.ShowDialog() == DialogResult.OK)
                {
                    SceneTests.InitializeScene();
                    ContentImporter.Import(Engine.Scene, d.FileName);

                    if (Engine.Scene.Physics != null)
                    {
                        Engine.Scene.Physics.Enable = true;
                    }

                    var box       = Engine.Scene.Nodes.First().BoundingBox;
                    var boxMesh   = Mesh.CreateBox(2, 2, 2);
                    var rastState = GraphicDeviceFactory.Device.CreateRasterizerState(new RasterizerDesc(true)
                    {
                        Fill = FillMode.Wireframe,
                        Cull = CullMode.None
                    });

                    //Engine.Presenter.Rendering += () =>
                    //    {
                    //        var device = GraphicDeviceFactory.Device;
                    //        var effect = Service.Require<RenderMeshIdEffect>();
                    //        effect.Constants.World = Matrix.Scale(box.Extends) * box.GlobalPose;
                    //        effect.Constants.ViewProj = SceneManager.Scene.ActiveCamera.ViewProj;
                    //        effect.Constants.gId = new Vector4(1);

                    //        device.PushGraphicState<RasterizerState>(rastState);

                    //        boxMesh.Draw(device, effect);

                    //        device.PopGraphicState<RasterizerState>();
                    //    };
                }
            }
        }
Esempio n. 13
0
        public void Import()
        {
            TestSettings.UseFrameLines = false;
            SceneTests.InitializeScene();
            SceneManager.Scene.AmbientLight.SkyColor    = new Vector3(0.0f, 0.0f, 0.0f);
            SceneManager.Scene.AmbientLight.GroundColor = new Vector3(0, 0, 0);

            RenderManager.PushTechnique <DefferedLigthing <DefferedLightingEffect> >();
            DrawGBuffers <DefferedLightingEffect>();

            SceneManager.Scene.Create("boxMesh", new FrameMesh(new BasicMaterial[] { new BasicMaterial {
                                                                                         //Diffuse = new Vector3(0.2f , 0.2f, 0.2f)
                                                                                         Diffuse = new Vector3(1f, 1f, 1f)
                                                                                                   //SpecularIntensity = 1,
                                                                                     } }, Mesh.CreateBox(1000f, 0.1f, 1000f)), Matrix.Identity);

            CreateLights();

            //ContentImporter.Import(SceneManager.Scene, @"E:\Modelos\2PINCHA CASA\terreno.DAE");
            //ContentImporter.Import(SceneManager.Scene, @"I:\3D Media\Elementalist - Soul of the Ultimate Nation Character\Texture\rabbi.DAE");
            ContentImporter.Import(SceneManager.Scene, @"C:\Users\ansel\Documents\3dsmax\export\nissan2.DAE")
            .OnSceneAttach(SceneManager.Scene);
            //ContentImporter.Import(SceneManager.Scene, @"E:\Modelos\CITIZEN EXTRAS_FEMALE 02.dae");
        }
Esempio n. 14
0
        public void PlayFileAnimation()
        {
            using (System.Windows.Forms.OpenFileDialog d = new System.Windows.Forms.OpenFileDialog())
            {
                if (d.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    SceneTests.InitializeScene();
                    var pk = ContentImporter.Import(SceneManager.Scene, d.FileName);
                    pk.OnSceneAttach(SceneManager.Scene);

                    var animation = SceneManager.Scene.AnimManager.Animations[0];
                    var resetter  = new AnimationBonesResetter(animation); //  new HeirarchyPoseResetter(root);
                    var state     = animation.GetCursor(0);
                    state.Looping = AnimationLooping.Loop;
                    SceneManager.Scene.Dynamics.Add(new Dynamic(deltaT =>
                    {
                        resetter.Reset();

                        animation.Update(deltaT, state, 1, true);
                        resetter.CommitChanges();
                    }));
                }
            }
        }
Esempio n. 15
0
 public void MultipleImport()
 {
     SceneTests.InitializeScene();
     ContentImporter.Import(Engine.Scene, @"C:\Users\ansel\Documents\3dsmax\export\talia.DAE");
     ContentImporter.Import(Engine.Scene, @"E:\Modelos\2PINCHA CASA\terreno.DAE");
 }
Esempio n. 16
0
        public void Automata_Idle_Walk()
        {
            SceneTests.InitializeScene();

            const float startTimeWalk = 34f / 30f;
            const float endTimeWalk   = 63f / 30f;
            const float durationWalk  = endTimeWalk - startTimeWalk;
            const float startTimeIdle = 0;
            const float endTimeIdle   = 0;
            const float durationIdle  = endTimeIdle;
            const float blendDuration = 0.25f;

            Vector3 speedVector = new Vector3(0, 0, -1f);

            ContentImporter.Import(SceneManager.Scene, @"C:\Users\ansel\Documents\3dsmax\export\lighting_shadowed.DAE")
            .OnSceneAttach(SceneManager.Scene);
            Frame cameraNode = SceneManager.Scene.FindNode("camera1");

            Frame         root     = SceneManager.Scene.EnumerateNodesPosOrden().First(x => x.Type == FrameType.Bone);
            BonesResetter resetter = new BonesResetter(root);

            Vector3 translation = root.LocalPosition;
            var     iniHeading  = root.Heading;

            var animation = SceneManager.Scene.AnimManager.Animations[0];

            animation.Sample(startTimeWalk);
            var iniKeyValue = root.LocalPosition;

            animation.Sample(endTimeWalk);
            var lastKeyValue = root.LocalPosition;

            Vector3 lastAnimTrans = root.LocalPosition; //new Vector3();
            bool    update        = false;
            float   deltaH        = 0;

            KeyFrameAnimationPlayback idle     = new KeyFrameAnimationPlayback(animation, startTimeIdle, durationIdle, AnimationLooping.Loop);
            KeyFrameAnimationPlayback walk     = new KeyFrameAnimationPlayback(animation, startTimeWalk, durationWalk, AnimationLooping.Loop);
            AnimationTransition       idleWalk = new AnimationTransition(idle, walk, blendDuration);
            AnimationTransition       walkIdle = new AnimationTransition(walk, idle, blendDuration);

            var walkCursor = walk.GetCursor(animation);

            Action <float> updateAction = (deltaT) =>
            {
                walk.Update(deltaT);

                if (!update)
                {
                    lastAnimTrans = root.LocalPosition;
                    update        = true;
                    return;
                }

                var cursor = walkCursor;
                if (!cursor.TimeRestart)
                {
                    _disp = root.LocalPosition - lastAnimTrans;
                }
                else
                {
                    _disp = root.LocalPosition - (cursor.PlayDirection > 0 ? iniKeyValue : lastKeyValue);
                }

                _disp = Vector3.TransformCoordinates(_disp, Matrix.RotationY(deltaH));

                translation  += _disp;
                lastAnimTrans = root.LocalPosition;
            };

            Automata stateMachine = new Automata()
                                    .AddState("idle", x =>
                                              idle.Update(x))
                                    .AddState("idle-walk", dt =>
            {
                idleWalk.Update(dt);
                _disp = new Vector3();
                if (Engine.KeyBoard.IsKeyPressed(Keys.Uparrow))
                {
                    _disp = speedVector;
                }
                else
                {
                    _disp = -speedVector;
                }
                _disp = Vector3.TransformCoordinates(_disp, Matrix.RotationY(deltaH));
            })
                                    .AddState("walk", updateAction)
                                    .AddState("walk-idle", x =>
                                              walkIdle.Update(x))
                                    .AddTransition("idle", "idle-walk", x =>
            {
                if (Engine.KeyBoard.IsKeyPressed(Keys.Uparrow))
                {
                    walk.FirstPlayback.Cursor.PlayDirection = 1;
                    update = false;
                    return(true);
                }
                else if (Engine.KeyBoard.IsKeyPressed(Keys.Downarrow))
                {
                    walk.FirstPlayback.Cursor.PlayDirection = -1;
                    update = false;
                    return(true);
                }
                return(false);
            })
                                    .AddTransition("idle-walk", "walk", x =>
                                                   idleWalk.TransitionComplete)
                                    .AddTransition("walk", "walk-idle", x =>
                                                   !Engine.KeyBoard.IsKeyPressed(Keys.Uparrow) && !Engine.KeyBoard.IsKeyPressed(Keys.Downarrow))
                                    .AddTransition("walk-idle", "idle", x =>
                                                   walkIdle.TransitionComplete);

            SceneManager.Scene.Dynamics.Add(new Dynamic(deltaT =>
            {
                //store position previus animation
                var localPosition = root.LocalPosition;
                _disp             = new Vector3();

                float rotSpeed = Numerics.ToRadians(90f);

                if (Engine.KeyBoard.IsKeyPressed(Keys.Leftarrow))
                {
                    deltaH -= rotSpeed * deltaT;
                }
                else if (Engine.KeyBoard.IsKeyPressed(Keys.Rightarrow))
                {
                    deltaH += rotSpeed * deltaT;
                }

                resetter.Reset();
                stateMachine.Update(deltaT);

                //root.Tx = translation.X;
                //root.Tz = translation.Z;
                root.X       = localPosition.X + _disp.X;
                root.Z       = localPosition.Z + _disp.Z;
                root.Heading = iniHeading + deltaH;

                root.ComputeLocalPose();
                root.CommitChanges();

                //var displacement = root.GlobalPose.Translation - localPosition;
                //cameraNode.Tx += displacement.X;
                //cameraNode.Tz += displacement.Z;
                cameraNode.X += _disp.X;
                cameraNode.Z += _disp.Z;
                cameraNode.CommitChanges();
            }));
        }
Esempio n. 17
0
        public void EdgeFiltering()
        {
            SceneTests.InitializeScene();

            //var content = ImportContent();
            var content = ContentImporter.Import(SceneManager.Scene, @"C:\Users\ansel\Documents\3dsmax\export\shadowScene.DAE");

            EngineState.Shadow.ShadowMapping.PcfBlurSize = 5;
            content.OnSceneAttach(SceneManager.Scene);

            //ContentImporter.Import(SceneManager.Scene, @"C:\Users\ansel\Documents\3dsmax\export\nissan2.DAE");
            //ContentImporter.Import(SceneManager.Scene, @"C:\Users\ansel\Documents\3dsmax\export\talia.DAE");

            if (SceneManager.Scene.Physics != null)
            {
                SceneManager.Scene.Physics.Enable = true;
            }

            //if (SceneManager.Scene.Lights.Count == 0)
            //{
            //    var light = new Light()
            //    {
            //        Diffuse = new Vector3(1, 1, 1),
            //        Specular = new Vector3(1, 1, 1),
            //        Type = LightType.Directional,
            //        Enable = true
            //    };

            //    SceneManager.Scene.Create("DirectionalLight0", new LightInstance(light),
            //        localRotationEuler: new Euler(0, Numerics.ToRadians(70), 0));
            //}
            FrameLight.CreateShadowMapForAllLights(SceneManager.Scene);
            _technique    = SceneManager.Scene.Lights.Where(x => x.Node.Technique is ShadowMapTechnique).Select(x => (ShadowMapTechnique)x.Node.Technique).FirstOrDefault();
            _targetCamera = _technique.Camera;

            _technique.Bias = 0.9e-2f;

            SceneManager.Scene.AmbientLight.GroundColor = new Vector3(0, 0, 0);
            SceneManager.Scene.AmbientLight.SkyColor    = new Vector3(0.2f, 0.2f, 0.2f);

            EngineState.Shadow.ShadowMapping.PcfBlurSize = 3;
            var edgeTechnique = new EdgeShadowFilteringTechnique();

            RenderManager.PushTechnique(edgeTechnique);
            bool debug = true;

            if (debug)
            {
                Form form = new Form();
                form.BackColor     = Color.Blue;
                form.StartPosition = FormStartPosition.CenterScreen;
                form.Size          = new System.Drawing.Size(edgeTechnique.ShadowFactorTex.Width, edgeTechnique.ShadowFactorTex.Height);

                form.SuspendLayout();

                Canvas3D canvas = new Canvas3D()
                {
                    Width  = form.Width,
                    Height = form.Height
                };
                canvas.Dock = DockStyle.Fill;
                var presenter = canvas.CreateSwapChainPresenter();
                form.Controls.Add(canvas);
                form.ResumeLayout();

                Engine.RenderFrame += () =>
                {
                    presenter.Begin(new Color4(Color.Aqua.ToArgb()));

                    var device = GraphicDeviceFactory.Device;
                    device.Ps.SamplerStacks[0].Push(SamplerState.Linear);
                    device.Blend = SceneTechnique.NoBlend;

                    var texture = edgeTechnique.EdgeSrcTexture;
                    RenderTexture(device, texture, width: texture.Width, height: texture.Height);

                    device.Ps.SamplerStacks[0].Pop();

                    presenter.End();
                };

                form.Show();
            }
        }
Esempio n. 18
0
        public void Transitions_Idle_Walk()
        {
            SceneTests.InitializeScene();

            const float startTimeWalk = 34f / 30f;
            const float endTimeWalk   = 63f / 30f;
            const float durationWalk  = endTimeWalk - startTimeWalk;
            const float startTimeIdle = 0;
            const float endTimeIdle   = 0;
            const float durationIdle  = endTimeIdle;
            const float blendDuration = 0.25f;

            Vector3 speedVector = new Vector3(0, 0, -1f);

            var content = ContentImporter.Import(SceneManager.Scene, @"C:\Users\ansel\Documents\3dsmax\export\lighting_shadowed.DAE");

            content.OnSceneAttach(SceneManager.Scene);

            Frame cameraNode = SceneManager.Scene.FindNode("camera1");

            Frame         root     = SceneManager.Scene.EnumerateNodesPosOrden().First(x => x.Type == FrameType.Bone);
            BonesResetter resetter = new BonesResetter(root);

            Vector3 iniTrasnlation = root.LocalPosition;
            Vector3 translation    = root.LocalPosition;
            var     iniHeading     = root.Heading;

            var animation = SceneManager.Scene.AnimManager.Animations[0];

            animation.Sample(startTimeWalk);
            var iniKeyValue = root.LocalPosition;

            animation.Sample(endTimeWalk);
            var lastKeyValue = root.LocalPosition;

            Vector3 lastAnimTrans = root.LocalPosition; //new Vector3();
            bool    update        = false;
            float   deltaH        = 0;

            Action <SecuenceNode, float> updateAction = (node, deltaT) =>
            {
                if (!update)
                {
                    lastAnimTrans = root.LocalPosition;
                    update        = true;
                    return;
                }

                var     cursor = node.Animations[0].Cursor;
                Vector3 disp;
                if (!cursor.TimeRestart)
                {
                    disp = root.LocalPosition - lastAnimTrans;
                }
                else
                {
                    disp = root.LocalPosition - (cursor.PlayDirection > 0 ? iniKeyValue : lastKeyValue);
                }

                disp = Vector3.TransformCoordinates(disp, Matrix.RotationY(deltaH));

                translation  += disp;
                lastAnimTrans = root.LocalPosition;
            };

            SecuenceStateMachine states = new SecuenceStateMachine()
                                          .WithState(new SecuenceNode("idle", animation, startTimeIdle, durationIdle, AnimationLooping.Loop))
                                          .WithState(new SecuenceNode("walk", animation, startTimeWalk, durationWalk, AnimationLooping.Loop)
                                                     .Deactivating(node => update = false)
                                                     .AfterUpdate(updateAction))
                                          .WithTransition("idle", "walk", new SecuenceTransition(blendDuration)
                                                          .FiredWhen(t =>
            {
                var destNode = t.DestNode;
                if (Engine.KeyBoard.IsKeyPressed(Keys.Uparrow))
                {
                    destNode.PlayDirection = 1;
                    update = false;
                    return(true);
                }
                else if (Engine.KeyBoard.IsKeyPressed(Keys.Downarrow))
                {
                    destNode.PlayDirection = -1;
                    update = false;
                    return(true);
                }
                return(false);
            })
                                                          .WhenBlending((t, dt) =>
            {
                Vector3 disp = new Vector3();
                var cursor   = t.DestNode.Animations[0].Cursor;
                if (Engine.KeyBoard.IsKeyPressed(Keys.Uparrow))
                {
                    disp = speedVector;
                }
                else
                {
                    disp = -speedVector;
                }
                translation += Vector3.TransformCoordinates(disp, Matrix.RotationY(deltaH));
            }))
                                          .WithTransition("walk", "idle", new SecuenceTransition(blendDuration)
                                                          .FiredWhen(t =>
            {
                if (!Engine.KeyBoard.IsKeyPressed(Keys.Uparrow) && !Engine.KeyBoard.IsKeyPressed(Keys.Downarrow))
                {
                    update = false;
                    return(true);
                }
                return(false);
            })
                                                          .WhenBlending((t, dt) =>
            {
            }));

            SceneManager.Scene.Dynamics.Add(
                new Dynamic(deltaT =>
            {
                var oldposition = root.GlobalPosition;

                float rotSpeed = Numerics.ToRadians(90f);

                if (Engine.KeyBoard.IsKeyPressed(Keys.Leftarrow))
                {
                    deltaH -= rotSpeed * deltaT;
                }
                else if (Engine.KeyBoard.IsKeyPressed(Keys.Rightarrow))
                {
                    deltaH += rotSpeed * deltaT;
                }

                resetter.Reset();
                states.Update(deltaT);

                root.X       = translation.X;
                root.Z       = translation.Z;
                root.Heading = iniHeading + deltaH;

                root.ComputeLocalPose();
                root.CommitChanges();

                var displacement = root.GlobalPosition - oldposition;
                cameraNode.X    += displacement.X;
                cameraNode.Z    += displacement.Z;
                cameraNode.CommitChanges();
            })
                );
        }
Esempio n. 19
0
        public void Import()
        {
            using (OpenFileDialog d = new OpenFileDialog())
            {
                if (d.ShowDialog() == DialogResult.OK)
                {
                    SceneTests.InitializeScene();
                    EngineState.Shadow.ShadowMapping.Bias = 0.9e-2f;

                    ContentImporter.Import(SceneManager.Scene, d.FileName);
                    //var content = ContentImporter.Import(SceneManager.Scene, @"C:\Users\ansel\Documents\3dsmax\export\shadowScene.DAE");

                    if (SceneManager.Scene.Physics != null)
                    {
                        SceneManager.Scene.Physics.Enable = true;
                    }
                    var light = SceneManager.Scene.Lights.FirstOrDefault();
                    if (light != null)
                    {
                        light.Instance.Intensity = 3;
                        //light.Instance.Specular = new Vector3(5, 5, 5);
                    }

                    SceneManager.Scene.AmbientLight.GroundColor     = new Vector3(0, 0, 0);
                    SceneManager.Scene.AmbientLight.SkyColor        = new Vector3(1f, 1f, 1f);
                    EngineState.Lighting.Hdr.Enable                 = true;
                    EngineState.Lighting.Hdr.EnableBlueShift        = false;
                    EngineState.Lighting.Hdr.GlareType              = GlareLibType.Disable;
                    EngineState.Lighting.Hdr.MiddleGray             = 0.5f;
                    EngineState.Lighting.Hdr.BrightThreshold        = 0.8f;
                    EngineState.Lighting.Hdr.GaussianMultiplier     = 0.4f;
                    EngineState.Lighting.Hdr.GaussianDeviation      = 0.8f;
                    EngineState.Lighting.Hdr.StarBlendFactor        = 0.2f;
                    EngineState.Lighting.Hdr.CalculateEyeAdaptation = true;
                    EngineState.Lighting.TransparencyEnable         = true;
                    EngineState.Lighting.Hdr.Technique.ComputeSamples();

                    EngineState.Lighting.Reflection.UseDefaultTechnique = true;
                    EngineState.Lighting.Reflection.Enable = false;

                    Form form = new Form();
                    form.SuspendLayout();

                    form.BackColor     = Color.Blue;
                    form.StartPosition = FormStartPosition.CenterScreen;
                    form.Size          = new System.Drawing.Size(800, 600);
                    Canvas3D canvas = new Canvas3D()
                    {
                        Width  = form.Width,
                        Height = form.Height
                    };
                    canvas.Dock = DockStyle.Fill;
                    form.Controls.Add(canvas);
                    form.ResumeLayout();

                    int width  = form.Width / 3;
                    int height = form.Height / 4;

                    var untranformed  = Service.Require <RenderQuadEffect>();
                    var sprite        = Service.Require <Sprite>();
                    var device        = GraphicDeviceFactory.Device;
                    var hdrTechinique = EngineState.Lighting.Hdr.Technique;

                    SwapChainPresenter presenter = canvas.CreateSwapChainPresenter();

                    Texture2DDesc desc = hdrTechinique.ToneMaps[0].Texture.Description;
                    desc.Usage          = ResourceUsage.Staging;
                    desc.CpuAccessFlags = CPUAccessFlags.Read;
                    desc.BindFlags      = BindFlags.None;
                    ITexture2D tex = GraphicDeviceFactory.Device.CreateTexture2D(desc);

                    Action renderAction = () =>
                    {
                        presenter.Begin(new Color4(Color.Aqua.ToArgb()));
                        sprite.Begin();

                        var textures = new RenderTexture2D[4, 3]
                        {
                            { hdrTechinique.HdrScene, hdrTechinique.BrightPassFilter, hdrTechinique.Bloom[0] },
                            { hdrTechinique.ToneMaps[5], hdrTechinique.ToneMaps[4], hdrTechinique.ToneMaps[3] },
                            { hdrTechinique.ToneMaps[2], hdrTechinique.ToneMaps[1], hdrTechinique.ToneMaps[0] },
                            { hdrTechinique.StarSource, hdrTechinique.StarFinal, hdrTechinique.StarLines[1] }
                        };


                        //textures[0, 1].SetTexture(0);
                        //sprite.SetTrasform(untranformed, new Igneel.Rectangle(0, 0, width, height), Matrix.Identity);
                        //sprite.DrawQuad(untranformed);

                        GraphicDeviceFactory.Device.Ps.SetSampler(0, SamplerState.Point);

                        for (int i = 0; i < textures.GetLength(0); i++)
                        {
                            for (int j = 0; j < textures.GetLength(1); j++)
                            {
                                if (textures[i, j] != null)
                                {
                                    textures[i, j].SetTexture(0);
                                    sprite.SetTrasform(untranformed, new Igneel.Rectangle(width * j, height * i, width, height), Matrix.Identity);
                                    sprite.DrawQuad(untranformed);
                                }
                            }
                        }

                        sprite.End();
                        presenter.End();


                        //device.CopyTexture(tex, hdrTechinique.ToneMaps[0].Texture);
                        //var map =  tex.Map(0, MapType.Read);
                        //unsafe
                        //{
                        //    float* pter = (float*)map.DataPointer;
                        //    float[] data = new float[map.RowPitch];
                        //    Marshal.Copy(map.DataPointer, data, 0, data.Length);
                        //    float value = *pter;
                        //}
                        //tex.UnMap(0);
                    };
                    Engine.RenderFrame += renderAction;

                    form.Show();
                    form.FormClosing += (sender, arg) =>
                    {
                        Engine.RenderFrame -= renderAction;
                        presenter.Dispose();
                    };
                }
            }
        }