Exemplo n.º 1
0
        private void setupWorldObjectTypes(XNAGame game, SimpleMeshRenderer renderer, TileSnapInformationBuilder builder)
        {
            OBJParser.ObjImporter importer = new OBJParser.ObjImporter();
            var c = new OBJToRAMMeshConverter(new RAMTextureFactory());

            importer.AddMaterialFileStream("WallInnerCorner.mtl", new FileStream(TWDir.GameData.CreateSubdirectory("Core\\TileEngine") + "/TileSet001/WallInnerCorner.mtl", FileMode.Open));
            importer.ImportObjFile(TWDir.GameData.CreateSubdirectory("Core\\TileEngine") + "/TileSet001/WallInnerCorner.obj");
            meshWallInnerCorner = c.CreateMesh(importer);
            importer.AddMaterialFileStream("WallStraight.mtl", new FileStream(TWDir.GameData.CreateSubdirectory("Core\\TileEngine") + "/TileSet001/WallStraight.mtl", FileMode.Open));
            importer.ImportObjFile(TWDir.GameData.CreateSubdirectory("Core\\TileEngine") + "/TileSet001/WallStraight.obj");
            meshWallStraight = c.CreateMesh(importer);

            wallInnerCornerType = new WorldObjectType(meshWallInnerCorner, Guid.NewGuid(), builder);
            wallStraightType    = new WorldObjectType(meshWallStraight, Guid.NewGuid(), builder);

            var tileDataInnerCorner = new TileData(Guid.NewGuid());
            var tileDataStraight    = new TileData(Guid.NewGuid());

            tileDataInnerCorner.Dimensions = wallInnerCornerType.BoundingBox.Max - wallInnerCornerType.BoundingBox.Min;
            tileDataInnerCorner.MeshOffset = Matrix.CreateTranslation(new Vector3(0, 0, 0));
            tileDataStraight.Dimensions    = wallStraightType.BoundingBox.Max - wallStraightType.BoundingBox.Min;
            tileDataStraight.MeshOffset    = Matrix.CreateTranslation(new Vector3(0, 0, 0));

            wallInnerCornerType.TileData = tileDataInnerCorner;
            wallStraightType.TileData    = tileDataStraight;

            typeList.Add(wallInnerCornerType);
            typeList.Add(wallStraightType);
        }
        public MainSceneEditor()
        {
            var texturePool           = new TexturePool();
            var meshpartPool          = new MeshPartPool();
            var vertexDeclarationPool = new VertexDeclarationPool();

            vertexDeclarationPool.SetVertexElements <TangentVertex>(TangentVertex.VertexElements);
            renderer = new SimpleMeshRenderer(texturePool, meshpartPool, vertexDeclarationPool);

            game.IsFixedTimeStep = false;
            game.DrawFps         = true;
            game.AddXNAObject(texturePool);
            game.AddXNAObject(meshpartPool);
            game.AddXNAObject(vertexDeclarationPool);
            game.AddXNAObject(renderer);

            renderingFactory = new DiskRenderingAssetFactory();


            placeTool     = new WorldObjectPlaceTool(game, world, renderer, builder, renderingFactory, tileFaceFactory);
            moveTool      = new WorldObjectMoveTool(game, world, builder, renderer);
            snapLearnTool = new SnapLearnTool(world, renderer, builder);

            game.AddXNAObject(placeTool);
            game.AddXNAObject(moveTool);
            game.AddXNAObject(snapLearnTool);

            diskTileDataFactory = new DiskTileDataFactory(renderingFactory, tileFaceTypeFactory);
            worldSerializer     = new WorldSerializer(renderingFactory, diskTileDataFactory, game, renderer, worldObjectTypeFactory,
                                                      builder);
        }
Exemplo n.º 3
0
 public WorldObject(IXNAGame game, WorldObjectType objectType, SimpleMeshRenderer renderer)
 {
     this.game     = game;
     ObjectType    = objectType;
     Renderer      = renderer;
     renderElement = Renderer.AddMesh(ObjectType.Mesh);
     updateWorldMatrix();
 }
 public SnapLearnTool(TheWizards.TileEngine.World world, SimpleMeshRenderer renderer, TileSnapInformationBuilder builder)
 {
     this.world    = world;
     raycaster     = new SimpleRaycaster <WorldObject>();
     raycasterFace = new SimpleRaycaster <TileFace>();
     this.renderer = renderer;
     this.builder  = builder;
 }
Exemplo n.º 5
0
        public void TestSyncOffline()
        {
            var serverpm = new SimpleServerPacketManager();
            var clientpm = serverpm.CreateClient();

            var vertexDeclarationPool = new VertexDeclarationPool();

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

            var texturePool  = new TexturePool();
            var meshPartPool = new MeshPartPool();

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

            var mesh =
                DefaultMeshes.CreateGuildHouseMesh(
                    new TheWizards.OBJParser.OBJToRAMMeshConverter(new RAMTextureFactory()));

            var meshFactory = new SimpleMeshFactory();

            meshFactory.AddMesh(mesh);

            var builder = new SimpleStaticWorldObjectFactory(renderer, meshFactory);

            var client = new ClientStaticWorldObjectSyncer(clientpm, builder);
            var server = new ServerStaticWorldObjectSyncer(serverpm);

            var game = new XNAGame();



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


            game.InitializeEvent += delegate
            {
            };

            game.UpdateEvent += delegate
            {
                if (game.Keyboard.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.F))
                {
                    var o   = server.CreateNew();
                    var obj = o;
                    obj.Mesh        = mesh;
                    obj.WorldMatrix = Matrix.CreateTranslation(game.SpectaterCamera.CameraPosition);
                }

                server.Update(game.Elapsed);

                client.Update(game.Elapsed);
            };

            game.Run();
        }
 public WorldSerializer(IMeshFactory meshFactory, DiskTileDataFactory diskTileDataFactory, IXNAGame game, SimpleMeshRenderer renderer, SimpleWorldObjectTypeFactory worldObjectTypeFactory, TileSnapInformationBuilder builder)
 {
     this.meshFactory         = meshFactory;
     this.diskTileDataFactory = diskTileDataFactory;
     this.game     = game;
     this.renderer = renderer;
     this.worldObjectTypeFactory = worldObjectTypeFactory;
     this.builder = builder;
 }
Exemplo n.º 7
0
 public WorldObjectPlaceTool(IXNAGame _game, World _world, SimpleMeshRenderer _renderer, TileSnapInformationBuilder _builder, IMeshFactory meshFactory, ITileFaceTypeFactory tileFaceTypeFactory)
 {
     game                     = _game;
     World                    = _world;
     renderer                 = _renderer;
     builder                  = _builder;
     this.meshFactory         = meshFactory;
     this.tileFaceTypeFactory = tileFaceTypeFactory;
     worldTileSnapper         = new WorldTileSnapper(builder);
 }
Exemplo n.º 8
0
        public void TestMeshRendererRenderCity()
        {
            var c = new OBJToRAMMeshConverter(new RAMTextureFactory());


            var importer = new ObjImporter();

            importer.AddMaterialFileStream("Town001.mtl", new FileStream("../../bin/GameData/Core/Town/OBJ03/Town001.mtl", FileMode.Open));
            importer.ImportObjFile("../../bin/GameData/Core/Town/OBJ03/Town001.obj");

            var mesh = 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);


            var game = new XNAGame();

            game.IsFixedTimeStep = false;
            game.DrawFps         = true;
            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();



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

            game.Run();
        }
        public static SimpleMeshRenderer InitDefaultMeshRenderer(XNAGame game)
        {
            var texturePool           = new TexturePool();
            var meshpartPool          = new MeshPartPool();
            var vertexDeclarationPool = new VertexDeclarationPool();

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

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

            vertexDeclarationPool.SetVertexElements <TangentVertex>(TangentVertex.VertexElements);
            return(renderer);
        }
Exemplo n.º 10
0
        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 WorldObjectMoveTool(XNAGame _game, World world, TileSnapInformationBuilder _builder, SimpleMeshRenderer _renderer)
        {
            game  = _game;
            World = world;
            translationGizmo.Position = new Vector3(0, 0, 0);
            translationGizmo.Enabled  = true;

            rotationGizmo.Position = new Vector3(0, 0, 0);
            rotationGizmo.Enabled  = true;



            //worldObjectList = world.WorldObjectList; DERIVED DATA!!!!!!!!
            snapper.AddSnapper(new SnapperPointPoint());
            builder          = _builder;
            worldTileSnapper = new WorldTileSnapper(builder);
            renderer         = _renderer;
        }
Exemplo n.º 12
0
        public void TestLoadObject()
        {
            XNAGame game = new XNAGame();

            OBJParser.ObjImporter importer = new OBJParser.ObjImporter();
            var c = new OBJToRAMMeshConverter(new RAMTextureFactory());

            importer.AddMaterialFileStream("Goblin02.mtl", new FileStream("../../../Assets/Goblin/Goblin02.mtl", FileMode.Open));
            importer.ImportObjFile("../../../Assets/Goblin/Goblin02.obj");

            var mesh = 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(new Vector3(0, 0, 0));


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

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

            game.InitializeEvent += delegate
            {
            };
            game.DrawEvent += delegate
            {
            };
            game.UpdateEvent += delegate
            {
            };
            game.Run();
        }
Exemplo n.º 13
0
        public void TestMeshRendererSimple()
        {
            var mesh = DefaultMeshes.CreateSimpleTestMesh();

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

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

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

            SimpleMeshRenderElement middle = null;

            for (int i = 0; i < 50; i++)
            {
                for (int j = 0; j < 50; j++)
                {
                    var el = renderer.AddMesh(mesh);
                    el.WorldMatrix = Matrix.CreateTranslation(Vector3.Right * i * 2 + Vector3.UnitZ * j * 2);

                    if (i > 20 && i < 30 && j > 20 && j < 30)
                    {
                        el.Delete();
                    }
                }
            }


            var game = new XNAGame();

            game.DrawFps = true;

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

            game.Run();
        }
Exemplo n.º 14
0
 public SimpleStaticWorldObject(SimpleMeshRenderer renderer)
 {
     this.renderer = renderer;
     WorldMatrix   = Matrix.Identity;
 }
Exemplo n.º 15
0
 public SimpleStaticWorldObjectFactory(SimpleMeshRenderer renderer, IMeshFactory meshFactory)
 {
     this.renderer    = renderer;
     this.meshFactory = meshFactory;
 }
Exemplo n.º 16
0
        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();
        }
Exemplo n.º 17
0
        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();
        }
Exemplo n.º 18
0
        public WorldObject CreateNewWorldObject(IXNAGame game, WorldObjectType objectType, SimpleMeshRenderer renderer)
        {
            var worldObject = new WorldObject(game, objectType, renderer);

            addWorldObject(worldObject);
            return(worldObject);
        }
Exemplo n.º 19
0
        public void TestSerializeWorld()
        {
            var game = new XNAGame();

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

            vertexDeclarationPool.SetVertexElements <TangentVertex>(TangentVertex.VertexElements);
            var renderer = new SimpleMeshRenderer(texturePool, meshpartPool, vertexDeclarationPool);

            TileData     data = new TileData(Guid.NewGuid());
            TileFaceType type = new TileFaceType(Guid.NewGuid());

            type.FlipWinding = true;
            TileFaceType root = new TileFaceType(Guid.NewGuid());

            type.SetParent(root);

            data.Dimensions = new Vector3(1, 2, 3);
            data.SetFaceType(TileFace.Front, type);

            OBJParser.ObjImporter importer = new OBJParser.ObjImporter();
            var c = new OBJToRAMMeshConverter(new RAMTextureFactory());

            importer.AddMaterialFileStream("WallInnerCorner.mtl", new FileStream(TWDir.GameData.CreateSubdirectory("Core\\TileEngine") + "/TileSet001/WallInnerCorner.mtl", FileMode.Open));
            importer.ImportObjFile(TWDir.GameData.CreateSubdirectory("Core\\TileEngine") + "/TileSet001/WallInnerCorner.obj");
            meshWallInnerCorner = c.CreateMesh(importer);

            data.Mesh = meshWallInnerCorner;

            var builder = new TileSnapInformationBuilder();

            var world   = new World();
            var objType = new WorldObjectType(data.Mesh, Guid.NewGuid(), builder);

            objType.TileData = data;

            var obj = world.CreateNewWorldObject(game, objType, renderer);

            obj.Position = Vector3.One * 3;



            var simpleMeshFactory = new SimpleMeshFactory();

            simpleMeshFactory.AddMesh(meshWallInnerCorner);

            DiskTileDataFactory diskTileDataFactory = new DiskTileDataFactory(simpleMeshFactory,
                                                                              new SimpleTileFaceTypeFactory());

            diskTileDataFactory.AddTileData(data);


            var typeFactory = new SimpleWorldObjectTypeFactory();



            var serializer = new WorldSerializer(simpleMeshFactory, diskTileDataFactory, game, renderer, typeFactory, builder);


            FileStream stream = File.OpenWrite(TWDir.Test.CreateSubdirectory("TileEngine").FullName + "\\TestWorld.xml");

            serializer.SerializeWorld(world, stream);

            stream.Close();

            FileStream readStream =
                File.OpenRead(TWDir.Test.CreateSubdirectory("TileEngine").FullName + "\\TestWorld.xml");

            var readWorld = new World();

            serializer.DeserializeWorld(readWorld, readStream);

            readStream.Close();
        }
Exemplo n.º 20
0
        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();
        }
Exemplo n.º 21
0
        public void TestLearnPlace()
        {
            XNAGame game = new XNAGame();

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

            vertexDeclarationPool.SetVertexElements <TangentVertex>(TangentVertex.VertexElements);
            var renderer = new SimpleMeshRenderer(texturePool, meshpartPool, vertexDeclarationPool);

            game.IsFixedTimeStep = false;
            game.DrawFps         = true;
            game.AddXNAObject(texturePool);
            game.AddXNAObject(meshpartPool);
            game.AddXNAObject(vertexDeclarationPool);
            game.AddXNAObject(renderer);

            EditorGrid grid;

            grid               = new EditorGrid();
            grid.Size          = new Vector2(100, 100);
            grid.Interval      = 1;
            grid.MajorInterval = 10;

            World world   = new World();
            var   builder = new TileSnapInformationBuilder();

            //var TileInnerCorner = factory.CreateNewWorldObject(game, wallInnerCornerType, renderer);
            //TileInnerCorner.Position = new Vector3(-7, 0, 0);
            //var TileStraight = factory.CreateNewWorldObject(game, wallStraightType, renderer);
            //TileStraight.Position = new Vector3(7, 0, 0);

            var placeTool     = new WorldObjectPlaceTool(game, world, renderer, builder, new SimpleMeshFactory(), new SimpleTileFaceTypeFactory());
            var moveTool      = new WorldObjectMoveTool(game, world, builder, renderer);
            var snapLearnTool = new SnapLearnTool(world, renderer, builder);

            game.AddXNAObject(placeTool);
            game.AddXNAObject(moveTool);
            game.AddXNAObject(snapLearnTool);


            setupWorldObjectTypes(game, renderer, builder);



            bool mouseEnabled = false;

            game.UpdateEvent += delegate
            {
                if (game.Keyboard.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.M))
                {
                    placeTool.Enabled     = false;
                    moveTool.Enabled      = true;
                    snapLearnTool.Enabled = false;
                }
                if (game.Keyboard.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.L))
                {
                    placeTool.Enabled     = false;
                    moveTool.Enabled      = false;
                    snapLearnTool.Enabled = true;
                }


                if (placeTool.Enabled)
                {
                    moveTool.Enabled      = false;
                    snapLearnTool.Enabled = false;

                    if (placeTool.ObjectsPlacedSinceEnabled() == 1)
                    {
                        placeTool.Enabled = false;
                    }
                }


                if (game.Keyboard.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.NumPad1))
                {
                    placeTool.PlaceType = typeList[0];
                    placeTool.Enabled   = true;
                }
                if (game.Keyboard.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.NumPad2))
                {
                    placeTool.PlaceType = typeList[1];
                    placeTool.Enabled   = true;
                }

                if (game.Keyboard.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.LeftAlt))
                {
                    mouseEnabled = !mouseEnabled;
                }
                if (mouseEnabled)
                {
                    game.Mouse.CursorEnabled     = true;
                    game.IsMouseVisible          = true;
                    game.SpectaterCamera.Enabled = false;
                }
                else
                {
                    game.Mouse.CursorEnabled     = false;
                    game.IsMouseVisible          = false;
                    game.SpectaterCamera.Enabled = true;
                    //activeWorldObject = null;
                }
            };

            game.DrawEvent += delegate
            {
                grid.Render(game);
            };

            game.Run();
        }
Exemplo n.º 22
0
        public void TestLearnSnap()
        {
            XNAGame game = new XNAGame();

            OBJParser.ObjImporter importer = new OBJParser.ObjImporter();
            var c = new OBJToRAMMeshConverter(new RAMTextureFactory());

            importer.AddMaterialFileStream("WallInnerCorner.mtl", new FileStream(TWDir.GameData.CreateSubdirectory("Core\\TileEngine") + "/TileSet001/WallInnerCorner.mtl", FileMode.Open));
            importer.ImportObjFile(TWDir.GameData.CreateSubdirectory("Core\\TileEngine") + "/TileSet001/WallInnerCorner.obj");
            var meshWallInnerCorner = c.CreateMesh(importer);

            importer.AddMaterialFileStream("WallStraight.mtl", new FileStream(TWDir.GameData.CreateSubdirectory("Core\\TileEngine") + "/TileSet001/WallStraight.mtl", FileMode.Open));
            importer.ImportObjFile(TWDir.GameData.CreateSubdirectory("Core\\TileEngine") + "/TileSet001/WallStraight.obj");
            var meshWallStraight = 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);

            World world = new World();
            TileSnapInformationBuilder builder = new TileSnapInformationBuilder();

            WorldObjectType type1 = new WorldObjectType(meshWallInnerCorner, Guid.NewGuid(), builder);
            WorldObjectType type2 = new WorldObjectType(meshWallStraight, Guid.NewGuid(), builder);

            var tileDataInnerCorner = new TileData(Guid.NewGuid());
            var tileDataStraight    = new TileData(Guid.NewGuid());

            tileDataInnerCorner.Dimensions = type1.BoundingBox.Max - type1.BoundingBox.Min;
            tileDataStraight.Dimensions    = type2.BoundingBox.Max - type2.BoundingBox.Min;


            type1.TileData = tileDataInnerCorner;
            type2.TileData = tileDataStraight;


            var TileInnerCorner = world.CreateNewWorldObject(game, type1, renderer);

            TileInnerCorner.Position = new Vector3(-7, 0, 0);
            var TileStraight = world.CreateNewWorldObject(game, type2, renderer);

            TileStraight.Position = new Vector3(7, 0, 0);

            game.IsFixedTimeStep = false;
            game.DrawFps         = true;
            game.AddXNAObject(texturePool);
            game.AddXNAObject(meshpartPool);
            game.AddXNAObject(vertexDeclarationPool);
            game.AddXNAObject(renderer);

            EditorGrid grid;

            grid               = new EditorGrid();
            grid.Size          = new Vector2(100, 100);
            grid.Interval      = 1;
            grid.MajorInterval = 10;

            var snapLearnTool = new SnapLearnTool(world, renderer, builder);

            game.AddXNAObject(snapLearnTool);

            bool mouseEnabled = false;

            var WallCornerBB = type1.TileData.GetBoundingBox();

            game.UpdateEvent += delegate
            {
                if (game.Keyboard.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.LeftAlt))
                {
                    mouseEnabled = !mouseEnabled;
                }
                if (mouseEnabled)
                {
                    game.Mouse.CursorEnabled     = true;
                    game.IsMouseVisible          = true;
                    game.SpectaterCamera.Enabled = false;
                }
                else
                {
                    game.Mouse.CursorEnabled     = false;
                    game.IsMouseVisible          = false;
                    game.SpectaterCamera.Enabled = true;
                    //activeWorldObject = null;
                }
            };
            game.DrawEvent += delegate
            {
                grid.Render(game);
                game.LineManager3D.WorldMatrix = TileInnerCorner.WorldMatrix;
                //game.LineManager3D.AddBox(WallCornerBB, Color.White);
            };

            game.Run();
        }
Exemplo n.º 23
0
        public void TestAddDeleteMeshToFromWorld()
        {
            XNAGame game = new XNAGame();

            OBJParser.ObjImporter importer = new OBJParser.ObjImporter();
            var c = new OBJToRAMMeshConverter(new RAMTextureFactory());

            importer.AddMaterialFileStream("WallInnerCorner.mtl", new FileStream(TWDir.GameData.CreateSubdirectory("Core\\TileEngine") + "/TileSet001/WallInnerCorner.mtl", FileMode.Open));
            importer.ImportObjFile(TWDir.GameData.CreateSubdirectory("Core\\TileEngine") + "/TileSet001/WallInnerCorner.obj");
            var meshWallInnerCorner = c.CreateMesh(importer);

            importer.AddMaterialFileStream("WallStraight.mtl", new FileStream(TWDir.GameData.CreateSubdirectory("Core\\TileEngine") + "/TileSet001/WallStraight.mtl", FileMode.Open));
            importer.ImportObjFile(TWDir.GameData.CreateSubdirectory("Core\\TileEngine") + "/TileSet001/WallStraight.obj");
            var meshWallStraight = c.CreateMesh(importer);

            importer.AddMaterialFileStream("WallOuterCorner.mtl", new FileStream(TWDir.GameData.CreateSubdirectory("Core\\TileEngine") + "/TileSet001/WallOuterCorner.mtl", FileMode.Open));
            importer.ImportObjFile(TWDir.GameData.CreateSubdirectory("Core\\TileEngine") + "/TileSet001/WallOuterCorner.obj");
            var meshWallOuterCorner = 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);

            World world = new World();
            TileSnapInformationBuilder builder = new TileSnapInformationBuilder();

            WorldObjectPlaceTool placeTool = new WorldObjectPlaceTool(game, world, renderer, builder, new SimpleMeshFactory(), new SimpleTileFaceTypeFactory());
            WorldObjectType      type1     = new WorldObjectType(meshWallInnerCorner, Guid.NewGuid(), builder);
            WorldObjectType      type2     = new WorldObjectType(meshWallStraight, Guid.NewGuid(), builder);
            WorldObjectType      type3     = new WorldObjectType(meshWallOuterCorner, Guid.NewGuid(), builder);

            var tileDataInnerCorner = new TileData(Guid.NewGuid());
            var tileDataStraight    = new TileData(Guid.NewGuid());
            var tileDataOuterCorner = new TileData(Guid.NewGuid());

            tileDataInnerCorner.Dimensions = type1.BoundingBox.Max - type1.BoundingBox.Min;
            tileDataStraight.Dimensions    = type2.BoundingBox.Max - type2.BoundingBox.Min;
            tileDataOuterCorner.Dimensions = type1.BoundingBox.Max - type1.BoundingBox.Min;

            var faceSnapType1 = new TileFaceType(Guid.NewGuid())
            {
                Name = "type1"
            };

            //var faceSnapType2 = new TileFaceType() { Name = "type2" };

            tileDataInnerCorner.SetFaceType(TileFace.Front, faceSnapType1);
            tileDataInnerCorner.SetLocalWinding(TileFace.Front, true);

            tileDataInnerCorner.SetFaceType(TileFace.Left, faceSnapType1);
            tileDataInnerCorner.SetLocalWinding(TileFace.Left, true);

            tileDataStraight.SetFaceType(TileFace.Back, faceSnapType1);
            tileDataStraight.SetLocalWinding(TileFace.Back, false);

            tileDataStraight.SetFaceType(TileFace.Front, faceSnapType1);
            tileDataStraight.SetLocalWinding(TileFace.Front, true);

            tileDataOuterCorner.SetFaceType(TileFace.Front, faceSnapType1);
            tileDataOuterCorner.SetLocalWinding(TileFace.Front, true);

            tileDataOuterCorner.SetFaceType(TileFace.Right, faceSnapType1);
            tileDataOuterCorner.SetLocalWinding(TileFace.Right, true);


            type1.TileData = tileDataInnerCorner;
            type2.TileData = tileDataStraight;
            type3.TileData = tileDataOuterCorner;


            type1.SnapInformation = builder.CreateFromTile(tileDataInnerCorner);
            type2.SnapInformation = builder.CreateFromTile(tileDataStraight);
            type3.SnapInformation = builder.CreateFromTile(tileDataOuterCorner);

            List <WorldObjectType> typeList = new List <WorldObjectType>();

            typeList.Add(type1);
            typeList.Add(type2);
            typeList.Add(type3);

            WorldObjectMoveTool moveTool = new WorldObjectMoveTool(game, world, builder, renderer);

            game.AddXNAObject(moveTool);
            game.AddXNAObject(placeTool);

            game.IsFixedTimeStep = false;
            game.DrawFps         = true;
            game.AddXNAObject(texturePool);
            game.AddXNAObject(meshpartPool);
            game.AddXNAObject(vertexDeclarationPool);
            game.AddXNAObject(renderer);

            EditorGrid grid;

            grid               = new EditorGrid();
            grid.Size          = new Vector2(100, 100);
            grid.Interval      = 1;
            grid.MajorInterval = 10;

            bool mouseEnabled = false;

            game.UpdateEvent += delegate
            {
                if (placeTool.Enabled)
                {
                    moveTool.Enabled = false;

                    if (placeTool.ObjectsPlacedSinceEnabled() == 1)
                    {
                        placeTool.Enabled = false;
                    }
                }
                else
                {
                    moveTool.Enabled = true;
                }

                if (game.Keyboard.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.NumPad1))
                {
                    placeTool.PlaceType = typeList[0];
                    placeTool.Enabled   = true;
                }
                if (game.Keyboard.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.NumPad2))
                {
                    placeTool.PlaceType = typeList[1];
                    placeTool.Enabled   = true;
                }
                if (game.Keyboard.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.NumPad3))
                {
                    placeTool.PlaceType = typeList[2];
                    placeTool.Enabled   = true;
                }

                if (game.Keyboard.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.LeftAlt))
                {
                    mouseEnabled = !mouseEnabled;
                }
                if (mouseEnabled)
                {
                    game.Mouse.CursorEnabled     = true;
                    game.IsMouseVisible          = true;
                    game.SpectaterCamera.Enabled = false;
                }
                else
                {
                    game.Mouse.CursorEnabled     = false;
                    game.IsMouseVisible          = false;
                    game.SpectaterCamera.Enabled = true;
                    //activeWorldObject = null;
                }
            };
            game.DrawEvent += delegate
            {
                grid.Render(game);
            };

            game.Run();
        }
Exemplo n.º 24
0
        public void TestMoveMesh()
        {
            XNAGame game = new XNAGame();

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

            //Import obj-files
            OBJParser.ObjImporter importer = new OBJParser.ObjImporter();
            var meshCreator = new OBJToRAMMeshConverter(new RAMTextureFactory());

            importer.AddMaterialFileStream("WallCorner.mtl", new FileStream("../../../Assets/WallCorner/WallCorner.mtl", FileMode.Open));
            importer.ImportObjFile("../../../Assets/WallCorner/WallCorner.obj");
            var meshWallCorner = meshCreator.CreateMesh(importer);

            importer.AddMaterialFileStream("WallStraight.mtl", new FileStream("../../../Assets/WallStraight/WallStraight.mtl", FileMode.Open));
            importer.ImportObjFile("../../../Assets/WallStraight/WallStraight.obj");
            var meshWallStraight = meshCreator.CreateMesh(importer);

            TexturePool           texturePool           = new TexturePool();
            MeshPartPool          meshpartPool          = new MeshPartPool();
            VertexDeclarationPool vertexDeclarationPool = new VertexDeclarationPool();
            SimpleMeshRenderer    renderer = new SimpleMeshRenderer(texturePool, meshpartPool, vertexDeclarationPool);

            vertexDeclarationPool.SetVertexElements <TangentVertex>(TangentVertex.VertexElements);
            game.AddXNAObject(texturePool);
            game.AddXNAObject(meshpartPool);
            game.AddXNAObject(vertexDeclarationPool);
            game.AddXNAObject(renderer);

            TileSnapInformationBuilder builder = new TileSnapInformationBuilder();



            //Create WorldObjectTypes
            WorldObjectType wallStraightType = new WorldObjectType(meshWallStraight, Guid.NewGuid(), builder);
            WorldObjectType wallCornerType   = new WorldObjectType(meshWallCorner, Guid.NewGuid(), builder);



            //Add some WorldObjects to the WorldSpace
            WorldObject wallStraight = new WorldObject(game, wallStraightType, renderer);
            WorldObject wallCorner   = new WorldObject(game, wallCornerType, renderer);

            List <WorldObject> WorldObjectList = new List <WorldObject>();

            WorldObjectList.Add(wallCorner);
            WorldObjectList.Add(wallStraight);

            World world = new World();

            world.WorldObjectList.AddRange(WorldObjectList);

            WorldObjectList[1].Position = new Vector3(30, 0, 0);


            WorldObjectMoveTool moveTool = new WorldObjectMoveTool(game, world, builder, renderer);

            game.AddXNAObject(moveTool);

            game.Run();
        }
Exemplo n.º 25
0
        public void TestOBJToRAMMeshConverterPerObjectVisual()
        {
            var c = new OBJToRAMMeshConverter(new RAMTextureFactory());


            var importer = new ObjImporter();

            importer.AddMaterialFileStream("Town001.mtl", new FileStream(TestFiles.TownMtl, FileMode.Open));
            importer.ImportObjFile(TestFiles.TownObj);

            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 builder = new MeshPhysicsActorBuilder(new MeshPhysicsPool());

            TheWizards.Client.ClientPhysicsQuadTreeNode root;

            int numNodes = 20;

            root = new ClientPhysicsQuadTreeNode(
                new BoundingBox(
                    new Vector3(-numNodes * numNodes / 2f, -100, -numNodes * numNodes / 2f),
                    new Vector3(numNodes * numNodes / 2f, 100, numNodes * numNodes / 2f)));

            QuadTree.Split(root, 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 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 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);
            };

            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 iSphere = new ClientPhysicsTestSphere(engine.Scene,
                                                              game.SpectaterCamera.CameraPosition + game.SpectaterCamera.CameraDirection
                                                              , 0.3f);

                    iSphere.InitDynamic();
                    iSphere.Actor.LinearVelocity = game.SpectaterCamera.CameraDirection * 10;

                    spheres.Add(iSphere);
                }



                for (int i = 0; i < spheres.Count; i++)
                {
                    spheres[i].Update(root, game);
                }
            };

            game.Run();
        }