public void TestOBJToRAMMeshConverter()
        {
            var c = new OBJToRAMMeshConverter(new RAMTextureFactory());


            var fsMat = new FileStream(TestFiles.CrateMtl, FileMode.Open);


            var importer = new ObjImporter();

            importer.AddMaterialFileStream("Crate01.mtl", fsMat);
            importer.ImportObjFile(TestFiles.CrateObj);


            fsMat.Close();



            var mesh = c.CreateMesh(importer);

            importer = new ObjImporter();
            importer.AddMaterialFileStream("CollisionModelBoxes001.mtl",
                                           EmbeddedFile.GetStream("MHGameWork.TheWizards.Tests.Physics.Files.CollisionModelBoxes001.mtl",
                                                                  "CollisionModelBoxes001.mtl"));
            importer.ImportObjFile(EmbeddedFile.GetStream("MHGameWork.TheWizards.Tests.Physics.Files.CollisionModelBoxes001.obj", "CollisionModelBoxes001.obj"));

            mesh = c.CreateMesh(importer);
        }
示例#2
0
        private void loadSpriteFont()
        {
            // The spritefont is stored as an embedded assembly file. Since the dumb content manager does not support loading from stream
            //   we first have to store the file on disk before when can load it.

            //TODO: find a way to load directly from stream

            string filename = System.Windows.Forms.Application.StartupPath + "\\Content\\Calibri.xnb";

            if (!System.IO.Directory.Exists(System.Windows.Forms.Application.StartupPath + "\\Content"))
            {
                System.IO.Directory.CreateDirectory(System.Windows.Forms.Application.StartupPath + "\\Content");
            }

            if (!System.IO.File.Exists(filename))
            {
                Stream strm = EmbeddedFile.GetStream("MHGameWork.TheWizards.Core.Graphics.Files.Calibri.xnb", "Calibri.xnb");
                byte[] data = new byte[strm.Length];
                strm.Read(data, 0, (int)strm.Length);

                System.IO.File.WriteAllBytes(filename, data);

                data = null;
                strm.Close();
            }



            spriteFont = Content.Load <SpriteFont>("Content\\Calibri");
        }
示例#3
0
        private Stream GetStream(string filename)
        {
#if DEBUG
            return(File.OpenRead(Path.Combine(DebugResourcesDir, filename)));
#else
            return(EmbeddedFile.GetStream(filename));
#endif
        }
        public void TestImportAMC()
        {
            AMCParser parser = new AMCParser();

            using (var strm = EmbeddedFile.GetStream("MHGameWork.TheWizards.Tests.Features.Simulation.Animation.Files.TestAnimation01.amc"))
            {
                parser.ImportAMC(strm);
            }
        }
        public void TestImportAMCCreateRelativeMatrices()
        {
            AMCParser parser = new AMCParser();

            using (var strm = EmbeddedFile.GetStream("MHGameWork.TheWizards.Tests.Features.Simulation.Animation.Files.TestAnimation02.amc"))
            {
                parser.ImportAMC(strm);
            }

            // Import skeleton
            var asfParser = new ASFParser();

            using (var strm = EmbeddedFile.GetStream("MHGameWork.TheWizards.Tests.Features.Simulation.Animation.Files.TestSkeleton02.asf"))
            {
                asfParser.ImportASF(strm);
            }
            var skeleton = asfParser.ImportSkeleton();


            var game = new DX11Game();
            var vis  = new SkeletonVisualizer();

            for (int i = 0; i < skeleton.Joints.Count; i++)
            {
                skeleton.Joints[i].RelativeMatrix = Matrix.Identity;
            }

            float time  = 0;
            float speed = 1;

            game.GameLoopEvent += delegate
            {
                game.LineManager3D.DrawGroundShadows = true;

                time += game.Elapsed;
                var sampleNum = (int)(time * 120 * speed) % parser.Samples.Count;

                for (int i = 0; i < parser.Samples[sampleNum].Segments.Count; i++)
                {
                    var seg = parser.Samples[sampleNum].Segments[i];

                    var asfJoint = asfParser.Joints.Find(j => j.name == seg.JointName);
                    var joint    = skeleton.Joints.Find(j => j.Name == seg.JointName);

                    Matrix relativeMat = parser.CalculateRelativeMatrix(seg, asfJoint);

                    joint.RelativeMatrix = relativeMat;
                }
                skeleton.UpdateAbsoluteMatrices();

                vis.VisualizeSkeleton(game, skeleton, new Vector3(4, 0, 4));
            };

            game.Run();
        }
        public void TestImportSkeletonFromASF()
        {
            var parser = new ASFParser();


            var root = new ASFJoint();

            parser.RootJoint = root;

            var child1 = new ASFJoint();

            child1.length    = 4;
            child1.direction = MathHelper.Up;
            root.children.Add(child1);

            var child2 = new ASFJoint();

            child2.direction = MathHelper.Up;
            child1.children.Add(child2);

            var skeleton1 = parser.ImportSkeleton();

            skeleton1.UpdateAbsoluteMatrices();

            using (var strm = EmbeddedFile.GetStream("MHGameWork.TheWizards.Tests.Features.Simulation.Animation.Files.TestSkeleton01.asf"))
            {
                parser.ImportASF(strm);
            }
            var skeleton2 = parser.ImportSkeleton();

            skeleton2.UpdateAbsoluteMatrices();

            var game = new DX11Game();
            var vis  = new SkeletonVisualizer();

            game.GameLoopEvent += delegate
            {
                vis.VisualizeSkeleton(game, skeleton1, new Vector3(4, 0, 4));
                vis.VisualizeSkeleton(game, skeleton2, new Vector3(11, 0, 11));
            };

            game.Run();
        }
        public void TestImportASF()
        {
            var parser = new ASFParser();

            using (var strm = EmbeddedFile.GetStream("MHGameWork.TheWizards.Tests.Features.Simulation.Animation.Files.TestSkeleton01.asf"))
            {
                parser.ImportASF(strm);
            }

            var game = new DX11Game();


            game.GameLoopEvent += delegate
            {
                drawASFJoint(game, parser.RootJoint, new Vector3(4, 0, 4));
            };

            game.Run();
        }
示例#8
0
        public ShaderResourceView LoadTexture(ITexture tex)
        {
            TextureInfo ret;

            if (!cache.TryGetValue(tex, out ret))
            {
                var data = tex.GetCoreData();
                //var p =TextureCreationParameters.Default;

                Texture2D tx;

                switch (data.StorageType)
                {
                case TextureCoreData.TextureStorageType.Disk:
                    //ret = Texture2D.FromFile(game.GraphicsDevice, data.DiskFilePath,p);
                    tx = Texture2D.FromFile(game.Device, data.DiskFilePath);
                    break;

                case TextureCoreData.TextureStorageType.Assembly:
                    //ret = Texture2D.FromFile(game.GraphicsDevice,
                    //                         EmbeddedFile.GetStream(data.Assembly, data.AssemblyResourceName, null),p);
                    using (var strm = EmbeddedFile.GetStream(data.Assembly, data.AssemblyResourceName, null))
                        tx = Texture2D.FromStream(game.Device, strm, (int)strm.Length);

                    break;

                default:
                    throw new InvalidOperationException();
                }

                ret = new TextureInfo
                {
                    Texture2D    = tx,
                    ResourceView = new ShaderResourceView(game.Device, tx)
                };

                cache[tex] = ret;
            }
            return(ret.ResourceView);
        }
        public Texture2D LoadTexture(ITexture tex)
        {
            Texture2D ret;

            if (!cache.TryGetValue(tex, out ret))
            {
                var data = tex.GetCoreData();
                var p    = TextureCreationParameters.Default;

                switch (data.StorageType)
                {
                case TextureCoreData.TextureStorageType.Disk:
                    ret = Texture2D.FromFile(game.GraphicsDevice, data.DiskFilePath, p);
                    break;

                case TextureCoreData.TextureStorageType.Assembly:
                    ret = Texture2D.FromFile(game.GraphicsDevice,
                                             EmbeddedFile.GetStream(data.Assembly, data.AssemblyResourceName, null), p);
                    break;
                }
                cache[tex] = ret;
            }
            return(ret);
        }
示例#10
0
        public void Initialize(IXNAGame _game)
        {
            game = _game;

            checkerTexture = Texture2D.FromFile(game.GraphicsDevice,
                                                EmbeddedFile.GetStream(
                                                    "MHGameWork.TheWizards.Rendering.Files.Checker.png", "Checker.png"));


            baseShader                = new DefaultModelShader(_game, new EffectPool());
            baseShader.LightColor     = new Vector3(0.9f, 0.9f, 0.9f);
            baseShader.AmbientColor   = new Vector4(0.15f, 0.15f, 0.15f, 1f);
            baseShader.Shininess      = 100;
            baseShader.SpecularColor  = Color.Black.ToVector4();
            baseShader.LightDirection = Vector3.Normalize(new Vector3(1, -5, 1));
            baseShader.DiffuseTexture = checkerTexture;



            for (int i = 0; i < renderDatas.Count; i++)
            {
                initMeshRenderData(renderDatas[i]);
            }
        }
示例#11
0
        public void Initialize(IXNAGame _game)
        {
            game = _game;
            //get the sizes of the backbuffer, in order to have matching render targets
            int backBufferWidth  = _game.GraphicsDevice.PresentationParameters.BackBufferWidth;
            int backBufferHeight = _game.GraphicsDevice.PresentationParameters.BackBufferHeight;


            initializeDeferredRendering(_game, backBufferWidth, backBufferHeight);

            initializeDeferredShading(_game, backBufferWidth, backBufferHeight);


            ambientOcclusionRT = new RenderTarget2D(_game.GraphicsDevice, backBufferWidth,
                                                    backBufferHeight, 1, SurfaceFormat.Color);     //TODO: use better channel here
            blurRT = new RenderTarget2D(_game.GraphicsDevice, backBufferWidth,
                                        backBufferHeight, 1, SurfaceFormat.Color);                 //TODO: use better channel here



            downsampleSize        = new Point(backBufferWidth / 2, backBufferHeight / 2);
            downsampleHalfPixel.X = 0.5f / downsampleSize.X;
            downsampleHalfPixel.Y = 0.5f / downsampleSize.Y;
            downsampleRT          = new RenderTarget2D(_game.GraphicsDevice, downsampleSize.X,
                                                       downsampleSize.Y, 1, SurfaceFormat.Color);
            downsampleBlurYRT = new RenderTarget2D(_game.GraphicsDevice, downsampleSize.X,
                                                   downsampleSize.Y, 1, SurfaceFormat.Color);



            deferredShader = loadShader("DeferredShader.fx");



            ambientOcclusionShader = loadShader("AmbientOcclusion.fx");

            blurShader = loadShader("Blur.fx");

            downsampleShader = loadShader("Downsample.fx");


            fullScreenQuad           = new FullScreenQuad(GraphicsDevice);
            tangentVertexDeclaration = TangentVertexExtensions.CreateVertexDeclaration(game);


            mesh        = merchantsHouseMesh;
            texturePool = new Rendering.TexturePool();

            texturePool.Initialize(game);
            meshPartPool = new MeshPartPool();
            meshPartPool.Initialize(game);

            boxTexture  = Texture2D.FromFile(GraphicsDevice, new FileStream(woodPlanksBarePath, FileMode.Open, FileAccess.Read, FileShare.Read));
            halfPixel.X = 0.5f / GraphicsDevice.PresentationParameters.BackBufferWidth;
            halfPixel.Y = 0.5f / GraphicsDevice.PresentationParameters.BackBufferHeight;



            checkerTexture = Texture2D.FromFile(game.GraphicsDevice,
                                                EmbeddedFile.GetStream(
                                                    "MHGameWork.TheWizards.Rendering.Files.Checker.png", "Checker.png"));


            randomNormalsTexture = Texture2D.FromFile(game.GraphicsDevice,
                                                      EmbeddedFile.GetStream(
                                                          "MHGameWork.TheWizards.Rendering.Deferred.Files.RandomNormals.png", "RandomNormals.png"));

            initializeToneMap();
        }
        public void TestOBJToRAMMeshConverterVisual()
        {
            PhysicsEngine           engine        = new PhysicsEngine();
            PhysicsDebugRendererXNA debugRenderer = null;



            var texFactory = new RAMTextureFactory();
            var c          = new OBJToRAMMeshConverter(texFactory);


            var importer = new ObjImporter();

            importer.AddMaterialFileStream("CollisionModelBoxes001.mtl",
                                           EmbeddedFile.GetStream("MHGameWork.TheWizards.Tests.Physics.Files.CollisionModelBoxes001.mtl",
                                                                  "CollisionModelBoxes001.mtl"));
            importer.ImportObjFile(EmbeddedFile.GetStream("MHGameWork.TheWizards.Tests.Physics.Files.CollisionModelBoxes001.obj", "CollisionModelBoxes001.obj"));


            var mesh = c.CreateMesh(importer);

            importer = new ObjImporter();
            importer.AddMaterialFileStream("HouseTest.mtl", new FileStream("../GameData/Core/001-House01_BoxTest-OBJ/HouseTest.mtl", FileMode.Open));
            importer.ImportObjFile("../GameData/Core/001-House01_BoxTest-OBJ/HouseTest.obj");

            var mesh2 = c.CreateMesh(importer);

            importer = new ObjImporter();
            var fsMHouseMat = new FileStream(TestFiles.MerchantsHouseMtl, FileMode.Open);

            importer.AddMaterialFileStream("MerchantsHouse.mtl", fsMHouseMat);
            importer.ImportObjFile(TestFiles.MerchantsHouseObj);

            fsMHouseMat.Close();

            var mesh3 = c.CreateMesh(importer);

            var texturePool           = new TexturePool();
            var meshpartPool          = new MeshPartPool();
            var vertexDeclarationPool = new VertexDeclarationPool();

            var renderer = new SimpleMeshRenderer(texturePool, meshpartPool, vertexDeclarationPool);

            vertexDeclarationPool.SetVertexElements <TangentVertex>(TangentVertex.VertexElements);


            var el = renderer.AddMesh(mesh);

            el.WorldMatrix = Matrix.CreateTranslation(Vector3.Right * 0 * 2 + Vector3.UnitZ * 0 * 2);

            el             = renderer.AddMesh(mesh2);
            el.WorldMatrix = Matrix.CreateTranslation(new Vector3(0, 0, 80));

            el             = renderer.AddMesh(mesh3);
            el.WorldMatrix = Matrix.CreateTranslation(new Vector3(0, 0, -80));



            var game = new XNAGame();

            game.IsFixedTimeStep = false;
            game.DrawFps         = true;

            game.AddXNAObject(texturePool);
            game.AddXNAObject(meshpartPool);
            game.AddXNAObject(vertexDeclarationPool);
            game.AddXNAObject(renderer);



            game.InitializeEvent += delegate
            {
                engine.Initialize();
                debugRenderer = new PhysicsDebugRendererXNA(game, engine.Scene);
                debugRenderer.Initialize(game);


                var builder = new MeshPhysicsActorBuilder(new MeshPhysicsPool());
                builder.CreateActorStatic(engine.Scene, mesh.GetCollisionData(), Matrix.Identity);
                builder.CreateActorStatic(engine.Scene, mesh2.GetCollisionData(), Matrix.CreateTranslation(new Vector3(0, 0, 80)));
                builder.CreateActorStatic(engine.Scene, mesh3.GetCollisionData(), Matrix.CreateTranslation(new Vector3(0, 0, -80)));
            };

            game.DrawEvent += delegate
            {
                debugRenderer.Render(game);
            };
            game.UpdateEvent += delegate
            {
                engine.Update(game.Elapsed);
                if (game.Keyboard.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.F))
                {
                    Actor actor = PhysicsHelper.CreateDynamicSphereActor(engine.Scene, 0.3f, 1);
                    actor.GlobalPosition = game.SpectaterCamera.CameraPosition +
                                           game.SpectaterCamera.CameraDirection * 5;
                    actor.LinearVelocity = game.SpectaterCamera.CameraDirection * 5;
                }
            };



            game.Run();
        }
 public System.IO.Stream GetLineRenderingShaderStream()
 {
     return(EmbeddedFile.GetStream("MHGameWork.TheWizards.Core.Graphics.Files.LineRendering.fx", "LineRendering.fx"));
 }