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);
        }
 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;
 }
Пример #3
0
        public void TestSerializeTileData()
        {
            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 simpleMeshFactory = new SimpleMeshFactory();

            simpleMeshFactory.AddMesh(meshWallInnerCorner);

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

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

            diskTileDataFactory.SerializeTileData(data, stream);

            stream.Close();

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

            TileData readData = diskTileDataFactory.DeserializeTileData(readStream);

            readStream.Close();
        }
Пример #4
0
        public void TestLoadWorldInScene()
        {
            var game            = new TestTWGame();
            var factory         = new DiskRenderingAssetFactory();
            var tileDataFactory = new DiskTileDataFactory(factory, new SimpleTileFaceTypeFactory());
            var serializer      = new WorldSerializer(factory, tileDataFactory,
                                                      game.Game, game.Renderer, new SimpleWorldObjectTypeFactory(),
                                                      new TileSnapInformationBuilder());



            var world          = new World();
            var worldXmlFile   = TWDir.Test.CreateSubdirectory("TileEngine").FullName + "\\WorldBig001Up.xml";
            var worldDirectory = TWDir.Test.CreateSubdirectory("TileEngine\\WorldBig001Up");

            factory.SaveDir         = worldDirectory;
            tileDataFactory.SaveDir = worldDirectory;
            using (var fs = File.Open(worldXmlFile, FileMode.Open))
                serializer.DeserializeWorld(world, fs);


            var scene = new Scene.Scene(game.Renderer, game.PhysicsFactory);

            game.Game.AddXNAObject(scene);

            var loader = new WorldSceneLoader(world, scene);

            loader.LoadIntoScene();

            var shooter = new TestSphereShooter(game.Game, game.PhysicsEngine, game.PhysicsTreeRoot,
                                                game.Game.SpectaterCamera);

            game.Game.AddXNAObject(shooter);

            game.Game.Run();
        }
Пример #5
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();
        }