Exemple #1
0
 public WorldObjectType(IMesh _mesh, Guid guid, TileSnapInformationBuilder builder)
 {
     mesh         = _mesh;
     BoundingBox  = CalculateBoundingBoxFromMesh(mesh);
     this.Guid    = guid;
     this.builder = builder;
 }
        private void SetGhostFaceAtFace(WorldObject target, TileFace resultFace)
        {
            var bb    = target.ObjectType.TileData.GetBoundingBox();
            var range = (bb.Max - bb.Min) * 0.5f;


            Vector3 right;
            Vector3 normal;
            Vector3 up;

            normal = TileSnapInformationBuilder.getFaceNormal(resultFace);
            up     = TileSnapInformationBuilder.getFaceUp(resultFace);
            right  = Vector3.Cross(up, normal);
            range *= 2f;
            Vector3 dim        = new Vector3();
            var     ghostWidth = 0.01f;


            dim += normal * ghostWidth;
            dim += up * Vector3.Dot(up, range);
            dim += right * Vector3.Dot(right, range);

            dim.X = Math.Abs(dim.X);
            dim.Y = Math.Abs(dim.Y);
            dim.Z = Math.Abs(dim.Z);


            ghostFace.Dimensions  = dim;
            ghostFace.PivotPoint  = Vector3.One * 0.5f;
            ghostFace.WorldMatrix = Matrix.CreateTranslation(normal * (Math.Abs(Vector3.Dot(normal, range * 0.5f)) + 0.01f)) * target.WorldMatrix;
        }
 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;
 }
 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;
 }
Exemple #5
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);
 }
        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;
        }
        private void createNewWorldObjectType(TileSnapInformationBuilder builder)
        {
            RAMMesh mesh = getMeshFromUser();

            if (mesh == null)
            {
                return;
            }
            var worldObjectType = new WorldObjectType(mesh, Guid.NewGuid(), builder);
            var tileData        = new TileData(Guid.NewGuid());

            tileData.Mesh = mesh;

            tileData.Dimensions      = new Vector3(1.5f, 2, 1.5f) - new Vector3(-1.5f, -2, -1.5f);
            worldObjectType.TileData = tileData;

            addType(worldObjectType);
        }
        private TileFace RaycastTileFace(IXNAGame _game, WorldObject target)
        {
            var bb    = target.ObjectType.TileData.GetBoundingBox();
            var range = (bb.Max - bb.Min) * 0.5f;

            Ray ray;
            var targetMatrix = Matrix.Invert(target.WorldMatrix);

            ray           = _game.GetWereldViewRay(_game.Mouse.CursorPositionVector);
            ray.Position  = Vector3.Transform(ray.Position, targetMatrix);
            ray.Direction = Vector3.TransformNormal(ray.Direction, targetMatrix);

            raycasterFace.Reset();
            Vector3 normal;
            Vector3 up;
            Vector3 right;


            for (int i = 0; i < 6; i++)
            {
                var face = (TileFace)(i + 1);
                normal = TileSnapInformationBuilder.getFaceNormal(face);
                up     = TileSnapInformationBuilder.getFaceUp(face);
                right  = Vector3.Cross(up, normal);
                var scaledNormal = normal * Math.Abs(Vector3.Dot(normal, range));
                var scaledUp     = up * Math.Abs(Vector3.Dot(up, range));
                var scaledRight  = right * Math.Abs(Vector3.Dot(right, range));
                var v1           = scaledNormal + scaledUp +
                                   scaledRight;
                var v2 = scaledNormal + scaledUp -
                         scaledRight;
                var v3 = scaledNormal - scaledUp +
                         scaledRight;
                var v4 = scaledNormal - scaledUp -
                         scaledRight;

                float?result;
                Functions.RayIntersectsSquare(ref ray, ref v1, ref v2, ref v3, ref v4, out result);
                raycasterFace.AddResult(result, face);
            }

            return(raycasterFace.ClosestObject);
        }
        public void TestSnapTo()
        {
            XNAGame game    = new XNAGame();
            var     snapper = new Snapper();

            snapper.AddSnapper(new SnapperPointPoint());
            var builder = new TileSnapInformationBuilder();

            var tileData1 = new TileData(Guid.NewGuid());

            tileData1.Dimensions = new Vector3(1, 2, 3);
            var tileData2 = new TileData(Guid.NewGuid());

            tileData2.Dimensions = new Vector3(2, 2, 5);

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

            tileData1.SetFaceType(TileFace.Front, faceSnapType1);
            tileData1.SetFaceType(TileFace.Right, faceSnapType2);

            tileData2.SetFaceType(TileFace.Front, faceSnapType1);
            tileData2.SetFaceType(TileFace.Back, faceSnapType1);

            var list = new List <ISnappableWorldTarget>();

            var worldTarget1 = new SimpleSnappableWorldTarget()
            {
                TileData        = tileData1,
                SnapInformation = builder.CreateFromTile(tileData1),
                Transformation  = new Transformation(Vector3.One, Quaternion.Identity, new Vector3(2, 1, 3))
            };
            var worldTarget2 = new SimpleSnappableWorldTarget()
            {
                TileData        = tileData2,
                SnapInformation = builder.CreateFromTile(tileData2),
                Transformation  = new Transformation(Vector3.One, Quaternion.Identity, new Vector3(-2, 1, 1))
            };

            list.Add(worldTarget1);
            list.Add(worldTarget2);

            var tileData1SnapInformation = builder.CreateFromTile(tileData1);

            var transformations = snapper.SnapTo(builder.CreateFromTile(tileData1), list);

            var colorTypeMap = new Dictionary <SnapType, Color>();

            colorTypeMap.Add(worldTarget1.SnapInformation.SnapList[0].SnapType, Color.Red);
            colorTypeMap.Add(worldTarget1.SnapInformation.SnapList[1].SnapType, Color.Green);

            game.DrawEvent += delegate
            {
                for (int i = 0; i < list.Count; i++)
                {
                    var iTarget = (SimpleSnappableWorldTarget)list[i];
                    renderTile(game, iTarget.Transformation.CreateMatrix(), iTarget.TileData, Color.White);

                    renderSnapInformation(game, iTarget.Transformation.CreateMatrix(), iTarget.SnapInformation, colorTypeMap);
                }

                for (int i = 0; i < transformations.Count; i++)
                {
                    var iTransformation = transformations[i];
                    renderTile(game, iTransformation.CreateMatrix(), tileData1, Color.Yellow);
                    renderSnapInformation(game, iTransformation.CreateMatrix(), tileData1SnapInformation, colorTypeMap);
                }
            };

            game.Run();
        }
Exemple #10
0
 public WorldTileSnapper(TileSnapInformationBuilder builder)
 {
     this.builder = builder;
     snapper      = new Snapper();
     snapper.AddSnapper(new SnapperPointPoint());
 }
Exemple #11
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();
        }
Exemple #12
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);
        }
Exemple #13
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();
        }
Exemple #14
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();
        }
Exemple #15
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();
        }
Exemple #16
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();
        }