public void TestMeshRendererAdvanced() { var texFactory = new RAMTextureFactory(); var c = new OBJToRAMMeshConverter(texFactory); var game = new XNAGame(); game.IsFixedTimeStep = false; game.DrawFps = true; var importer = new ObjImporter(); importer.AddMaterialFileStream("Crate01.mtl", File.OpenRead(TestFiles.CrateMtl)); importer.ImportObjFile(TestFiles.CrateObj); var mesh = c.CreateMesh(importer); RAMMesh mesh2 = DefaultMeshes.CreateMerchantsHouseMesh(c); RAMMesh mesh3 = DefaultMeshes.CreateGuildHouseMesh(c); SimpleMeshRenderer renderer = InitDefaultMeshRenderer(game); 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)); for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { el = renderer.AddMesh(mesh3); el.WorldMatrix = Matrix.CreateTranslation(new Vector3(j * 30, 0, 70 + i * 30)); } } game.Run(); }
public EngineMeshFactory(RAMTextureFactory textureFactory) { converter = new OBJToRAMMeshConverter(textureFactory); }
public AssetsWrapper() { TextureFactory = new RAMTextureFactory(); MeshFactory = new EngineMeshFactory(TextureFactory); AssetFactory = new EngineAssetFactory(); }
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 void TestMeshRendererAdvanced() { var texFactory = new RAMTextureFactory(); var c = new OBJToRAMMeshConverter(texFactory); var game = new DX11Game(); game.InitDirectX(); var context = game.Device.ImmediateContext; var importer = new ObjImporter(); importer.AddMaterialFileStream("Crate01.mtl", File.OpenRead(TestFiles.CrateMtl)); importer.ImportObjFile(TestFiles.CrateObj); var mesh = c.CreateMesh(importer); RAMMesh mesh2 = RenderingTestsHelper.CreateMerchantsHouseMesh(c); RAMMesh mesh3 = RenderingTestsHelper.CreateGuildHouseMesh(c); var gBuffer = new GBuffer(game.Device, 800, 600); DeferredMeshesRenderer renderer = InitDefaultMeshRenderer(game, gBuffer); var el = renderer.AddMesh(mesh); el.WorldMatrix = Matrix.Translation(MathHelper.Right * 0 * 2 + Vector3.UnitZ * 0 * 2); el = renderer.AddMesh(mesh2); el.WorldMatrix = Matrix.Translation(new Vector3(0, 0, 80)); for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { el = renderer.AddMesh(mesh3); el.WorldMatrix = Matrix.Translation(new Vector3(j * 30, 0, 70 + i * 30)); } } game.GameLoopEvent += delegate { gBuffer.Clear(); gBuffer.SetTargetsToOutputMerger(); context.Rasterizer.State = game.HelperStates.RasterizerShowAll; renderer.Draw(); context.ClearState(); game.SetBackbuffer(); GBufferTest.DrawGBuffer(game, gBuffer); }; game.Run(); }
public void TestOBJToRAMMeshConverterPerObjectVisualCool() { var textureFactory = new RAMTextureFactory(); var c = new OBJToRAMMeshConverter(textureFactory); var importer = new ObjImporter(); importer.AddMaterialFileStream("Town001.mtl", new FileStream("../GameData/Town/OBJ03/Town001.mtl", FileMode.Open)); importer.ImportObjFile("../GameData/Town/OBJ03/Town001.obj"); var meshes = c.CreateMeshesFromObjects(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 spheres = new List <ClientPhysicsTestSphere>(); var engine = new PhysicsEngine(); PhysicsDebugRendererXNA debugRenderer = null; var root = CreatePhysicsQuadtree(20, 5); var physicsElementFactoryXNA = new MeshPhysicsFactoryXNA(engine, root); var physicsElementFactory = physicsElementFactoryXNA.Factory; var physicsElements = new List <MeshStaticPhysicsElement>(); for (int i = 0; i < 0 * 100 + 1 * meshes.Count; i++) { var mesh = meshes[i]; var el = renderer.AddMesh(mesh); el.WorldMatrix = Matrix.CreateTranslation(Vector3.Right * 0 * 2 + Vector3.UnitZ * 0 * 2); var pEl = physicsElementFactory.CreateStaticElement(mesh, Matrix.Identity); physicsElements.Add(pEl); } var gameMeshes = new List <OBJParserTest.TestGameMesh>(); var game = new XNAGame(); game.IsFixedTimeStep = false; game.DrawFps = true; game.SpectaterCamera.FarClip = 5000; game.Graphics1.PreparingDeviceSettings += delegate(object sender, PreparingDeviceSettingsEventArgs e) { DisplayMode displayMode = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode; e.GraphicsDeviceInformation.PresentationParameters.BackBufferFormat = displayMode.Format; e.GraphicsDeviceInformation.PresentationParameters.BackBufferWidth = displayMode.Width; e.GraphicsDeviceInformation.PresentationParameters.BackBufferHeight = displayMode.Height; game.SpectaterCamera.AspectRatio = displayMode.Width / (float)displayMode.Height; }; game.Graphics1.ToggleFullScreen(); var barrelMesh = OBJParserTest.GetBarrelMesh(c); var crateMesh = OBJParserTest.GetCrateMesh(c); var sphereMesh = new SphereMesh(0.3f, 20, Color.Green); var visualizer = new QuadTreeVisualizerXNA(); game.AddXNAObject(physicsElementFactoryXNA); 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); sphereMesh.Initialize(game); for (int i = 0; i < meshes.Count; i++) { var mesh = meshes[i]; var data = mesh.GetCollisionData(); /*if (data.TriangleMesh != null) * physicsElementFactory.MeshPhysicsPool.PreloadTriangleMesh(engine.Scene, data.TriangleMesh);*/ } }; bool showPhysics = true; game.DrawEvent += delegate { if (game.Keyboard.IsKeyPressed(Keys.P)) { showPhysics = !showPhysics; } if (showPhysics) { debugRenderer.Render(game); } /*visualizer.RenderNodeGroundBoundig(game, root, * delegate(ClientPhysicsQuadTreeNode node, out Color col) * { * col = Color.Green; * * return node.PhysicsObjects.Count == 0; * }); * * visualizer.RenderNodeGroundBoundig(game, root, * delegate(ClientPhysicsQuadTreeNode node, out Color col) * { * col = Color.Orange; * * return node.PhysicsObjects.Count > 0; * });*/ for (int i = 0; i < physicsElements.Count; i++) { var el = physicsElements[i]; //game.LineManager3D.AddBox(BoundingBox.CreateFromSphere( el.BoundingSphere), Color.Orange); } for (int i = 0; i < spheres.Count; i++) { sphereMesh.WorldMatrix = Matrix.CreateTranslation(spheres[i].Center); sphereMesh.Render(game); } }; game.UpdateEvent += delegate { engine.Update(game.Elapsed); sphereMesh.Update(game); if (game.Keyboard.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.F)) { var pEl = physicsElementFactory.CreateDynamicElement(crateMesh, Matrix.CreateTranslation( game.SpectaterCamera.CameraPosition + game.SpectaterCamera.CameraDirection)); pEl.Actor.LinearVelocity = game.SpectaterCamera.CameraDirection * 30; var rEl = renderer.AddMesh(crateMesh); gameMeshes.Add(new OBJParserTest.TestGameMesh(rEl, pEl)); } if (game.Keyboard.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.E)) { var pEl = physicsElementFactory.CreateDynamicElement(barrelMesh, Matrix.CreateTranslation( game.SpectaterCamera.CameraPosition + game.SpectaterCamera.CameraDirection)); pEl.Actor.LinearVelocity = game.SpectaterCamera.CameraDirection * 30; var rEl = renderer.AddMesh(barrelMesh); gameMeshes.Add(new OBJParserTest.TestGameMesh(rEl, pEl)); } for (int i = 0; i < gameMeshes.Count; i++) { var m = gameMeshes[i]; m.RenderElement.WorldMatrix = m.PhysicsElement.World; } }; game.Run(); }
public void TestThrowBarrels() { var texFactory = new RAMTextureFactory(); var c = new OBJToRAMMeshConverter(texFactory); RAMMesh mesh = OBJParserTest.GetBarrelMesh(c); 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 gameMeshes = new List <OBJParserTest.TestGameMesh>(); var engine = new PhysicsEngine(); PhysicsDebugRendererXNA debugRenderer = null; var root = CreatePhysicsQuadtree(16, 4); var physicsElementFactoryXNA = new MeshPhysicsFactoryXNA(engine, root); var physicsElementFactory = physicsElementFactoryXNA.Factory; var game = new XNAGame(); game.IsFixedTimeStep = false; game.DrawFps = true; var visualizer = new QuadTreeVisualizerXNA(); game.AddXNAObject(physicsElementFactoryXNA); 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); }; bool showPhysics = true; game.DrawEvent += delegate { if (game.Keyboard.IsKeyPressed(Keys.P)) { showPhysics = !showPhysics; } if (showPhysics) { debugRenderer.Render(game); } visualizer.RenderNodeGroundBoundig(game, root, delegate(ClientPhysicsQuadTreeNode node, out Color col) { col = Color.Green; return(node.PhysicsObjects.Count == 0); }); visualizer.RenderNodeGroundBoundig(game, root, delegate(ClientPhysicsQuadTreeNode node, out Color col) { col = Color.Orange; return(node.PhysicsObjects.Count > 0); }); }; game.UpdateEvent += delegate { engine.Update(game.Elapsed); if (game.Keyboard.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.F)) { var pEl = physicsElementFactory.CreateDynamicElement(mesh, Matrix.CreateTranslation( game.SpectaterCamera.CameraPosition + game.SpectaterCamera.CameraDirection)); pEl.Actor.LinearVelocity = game.SpectaterCamera.CameraDirection * 30; var rEl = renderer.AddMesh(mesh); gameMeshes.Add(new OBJParserTest.TestGameMesh(rEl, pEl)); } for (int i = 0; i < gameMeshes.Count; i++) { var m = gameMeshes[i]; m.RenderElement.WorldMatrix = m.PhysicsElement.World; } }; game.Run(); }