Esempio n. 1
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();
        }
Esempio n. 2
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();
        }