public static GameObject BuildRoom(DefaultNamespace.VREM.Model.Room roomData)
        {
            Material[] mats =
            {
                TexturingUtility.LoadMaterialByName(roomData.floor),
                TexturingUtility.LoadMaterialByName(roomData.ceiling),

                GetMaterialForWallOrientation(WallOrientation.NORTH,  roomData),
                GetMaterialForWallOrientation(WallOrientation.EAST,   roomData),
                GetMaterialForWallOrientation(WallOrientation.SOUTH,  roomData),
                GetMaterialForWallOrientation(WallOrientation.WEST,   roomData)
            };
            var modelData = new CuboidRoomModel(CalculateRoomPosition(roomData), roomData.size.x, roomData.size.y,
                                                mats[0], mats[1], mats[2], mats[3], mats[4], mats[5]);
            var room = ModelFactory.CreateCuboidRoom(modelData);
            var er   = room.AddComponent <CuboidExhibitionRoom>();

            er.RoomModel = modelData;
            er.Model     = room;
            er.RoomData  = roomData;
            var na = CreateAnchor(WallOrientation.NORTH, room, modelData);
            var ea = CreateAnchor(WallOrientation.EAST, room, modelData);
            var sa = CreateAnchor(WallOrientation.SOUTH, room, modelData);
            var wa = CreateAnchor(WallOrientation.WEST, room, modelData);

            var nw = CreateExhibitionWall(WallOrientation.NORTH, roomData, na);
            var ew = CreateExhibitionWall(WallOrientation.EAST, roomData, ea);
            var sw = CreateExhibitionWall(WallOrientation.SOUTH, roomData, sa);
            var ww = CreateExhibitionWall(WallOrientation.WEST, roomData, wa);

            er.Walls = new List <ExhibitionWall>(new[] { nw, ew, sw, ww });
            er.Populate();

            var light = new GameObject("RoomLight");
            var l     = light.AddComponent <Light>();

            l.type       = LightType.Point;
            l.range      = 8;
            l.color      = Color.white;
            l.intensity  = 1.5f;
            l.renderMode = LightRenderMode.ForcePixel;
            //l.lightmapBakeType = LightmapBakeType.Mixed; // Build fails with this line uncommented, even though unity automatically upgrades to this one.
            //l.lightmappingMode = LightmappingMode.Mixed; // Build fails with this line uncommented. it is obsolete
            // Results in mode Realtime (in Unity editor inspector)
            l.transform.parent        = room.transform;
            l.transform.localPosition = new Vector3(0, 2.5f, 0);
            room.name = "Room";

            var teleportArea = new GameObject("TeleportArea");
            var col          = teleportArea.AddComponent <BoxCollider>();

            col.size = new Vector3(modelData.Size, 0.01f, modelData.Size);
            teleportArea.AddComponent <MeshRenderer>();
            var tpa = teleportArea.AddComponent <TeleportArea>();

            tpa.transform.parent        = room.transform;
            tpa.transform.localPosition = new Vector3(0, 0.01f, 0);

            return(room);
        }
Exemple #2
0
        public static GameObject CreateCuboidRoom(CuboidRoomModel model)
        {
            GameObject root = new GameObject("CuboidRoom");

            float halfSize = model.Size / 2f;

            // North wall
            GameObject north = CreateWall(model.Size, model.Height, model.NorthMaterial);

            north.name               = "NorthWall";
            north.transform.parent   = root.transform;
            north.transform.position = new Vector3(-halfSize, 0, halfSize);
            // East wall
            GameObject east = CreateWall(model.Size, model.Height, model.EastMaterial);

            east.name               = "EastWall";
            east.transform.parent   = root.transform;
            east.transform.position = new Vector3(halfSize, 0, halfSize);
            east.transform.Rotate(Vector3.up, 90);
            // South wall
            GameObject south = CreateWall(model.Size, model.Height, model.SouthMaterial);

            south.name               = "SouthWall";
            south.transform.parent   = root.transform;
            south.transform.position = new Vector3(halfSize, 0, -halfSize);
            south.transform.Rotate(Vector3.up, 180);
            // West wall
            GameObject west = CreateWall(model.Size, model.Height, model.WestMaterial);

            west.name               = "WestWall";
            west.transform.parent   = root.transform;
            west.transform.position = new Vector3(-halfSize, 0, -halfSize);
            west.transform.Rotate(Vector3.up, 270);

            // Floor
            GameObject floorAnchor = new GameObject("FloorAnchor");

            floorAnchor.transform.parent = root.transform;

            GameObject floor = CreateWall(model.Size, model.Size, model.FloorMaterial);

            floor.name             = "Floor";
            floor.transform.parent = floorAnchor.transform;
            // North Aligned
            floorAnchor.transform.position = new Vector3(-halfSize, 0, -halfSize);
            floorAnchor.transform.Rotate(Vector3.right, 90);
            // East Aligned
            //floorAnchor.transform.position = new Vector3(-halfSize, 0, halfSize);
            //floorAnchor.transform.Rotate(Vector3f.back,90);

            // Ceiling
            GameObject ceilingAnchor = new GameObject("CeilingAnchor");

            ceilingAnchor.transform.parent = root.transform;

            GameObject ceiling = CreateWall(model.Size, model.Size, model.CeilingMaterial);

            ceiling.name             = "Ceiling";
            ceiling.transform.parent = ceilingAnchor.transform;


            // North Aligned
            ceilingAnchor.transform.position = new Vector3(-halfSize, model.Height, halfSize);
            ceilingAnchor.transform.Rotate(Vector3.right, -90);
            // East Aligned
            //ceilingAnchor.transform.position = new Vector3(halfSize, height, -halfSize);
            //ceilingAnchor.transform.Rotate( Vector3.back, -90);

            root.transform.position = model.Position;

            root.AddComponent <ModelContainer>().Model = model;
            return(root);
        }
Exemple #3
0
        /// <summary>
        /// Builds a room, i.e., creating and building its walls and exhibits as well as adding textures, lighting,
        /// teleports, etc.
        /// </summary>
        /// <param name="roomData">The room data that should be used to build this room (as received from VREM).</param>
        /// <returns>The GameObject for the created room.</returns>
        public static async Task <GameObject> BuildRoom(Room roomData)
        {
            // Create room model.
            var modelData = new CuboidRoomModel(
                new Vector3(roomData.Position.X, roomData.Position.Y, roomData.Position.Z),
                roomData.Size.X,
                roomData.Size.Y,
                TexturingUtility.LoadMaterialByName(roomData.Floor),
                TexturingUtility.LoadMaterialByName(roomData.Ceiling),
                GetMaterialForWallOrientation(Wall.DirectionEnum.NORTH, roomData),
                GetMaterialForWallOrientation(Wall.DirectionEnum.EAST, roomData),
                GetMaterialForWallOrientation(Wall.DirectionEnum.SOUTH, roomData),
                GetMaterialForWallOrientation(Wall.DirectionEnum.WEST, roomData)
                );

            // Create the actual GameObject for the room.
            var room = ModelFactory.CreateCuboidRoom(modelData);

            // Add exhibition room component, containing the room model.
            var er = room.AddComponent <CuboidExhibitionRoom>();

            er.RoomModel = modelData;
            er.Model     = room;
            er.RoomData  = roomData;

            // Add walls.
            var na = CreateAnchor(Wall.DirectionEnum.NORTH, room, modelData);
            var ea = CreateAnchor(Wall.DirectionEnum.EAST, room, modelData);
            var sa = CreateAnchor(Wall.DirectionEnum.SOUTH, room, modelData);
            var wa = CreateAnchor(Wall.DirectionEnum.WEST, room, modelData);

            var nw = CreateExhibitionWall(Wall.DirectionEnum.NORTH, roomData, na);
            var ew = CreateExhibitionWall(Wall.DirectionEnum.EAST, roomData, ea);
            var sw = CreateExhibitionWall(Wall.DirectionEnum.SOUTH, roomData, sa);
            var ww = CreateExhibitionWall(Wall.DirectionEnum.WEST, roomData, wa);

            er.Walls = new List <ExhibitionWall>(new[] { nw, ew, sw, ww });

            // Add exhibits to walls (this is expensive!).
            await er.Populate();

            // Light.
            var light = new GameObject("RoomLight");
            var l     = light.AddComponent <Light>();

            l.type       = LightType.Point;
            l.range      = 8;
            l.color      = Color.white;
            l.intensity  = 1.5f;
            l.renderMode = LightRenderMode.ForcePixel;

            var t = l.transform;

            t.parent        = room.transform; // Set room as parent for transform component.
            t.localPosition = new Vector3(0, 2.5f, 0);
            room.name       = RoomNamePrefix + roomData.Id;

            // Teleport.
            var teleportArea = new GameObject("TeleportArea");
            var col          = teleportArea.AddComponent <BoxCollider>();

            col.size = new Vector3(modelData.size, 0.01f, modelData.size);
            teleportArea.AddComponent <MeshRenderer>();

            var tpa = teleportArea.AddComponent <TeleportArea>();
            var t1  = tpa.transform;

            t1.parent        = room.transform;
            t1.localPosition = new Vector3(0, 0.01f, 0);

            return(room);
        }
Exemple #4
0
        /// <summary>
        /// Creates a GameObject for a wall to later act as a parent for the exhibits.
        /// Placed at the bottom left corner of a wall, acting as 0/0/0 for relative exhibit coordinates
        /// in the exhibition model from VREM.
        /// </summary>
        /// <param name="orientation">Wall orientation.</param>
        /// <param name="room">GameObject for the room of the wall, acting as parent for the created anchor.</param>
        /// <param name="model">The CuboidRoomModel holding details about size and textures of the room.</param>
        /// <returns>The GameObject of the newly created anchor (with its parent set).</returns>
        /// <exception cref="ArgumentOutOfRangeException"></exception>
        private static GameObject CreateAnchor(Wall.DirectionEnum orientation, GameObject room, CuboidRoomModel model)
        {
            var anchor = new GameObject(orientation + "Anchor");

            anchor.transform.parent = room.transform;

            Vector3 pos;
            float   a;
            var     sizeHalf = model.size / 2f; // This probably only supports square rooms (with varying height).

            switch (orientation)
            {
            case Wall.DirectionEnum.NORTH:
                pos = new Vector3(-sizeHalf, 0, sizeHalf);
                a   = 0;
                break;

            case Wall.DirectionEnum.EAST:
                pos = new Vector3(sizeHalf, 0, sizeHalf);
                a   = 90;
                break;

            case Wall.DirectionEnum.SOUTH:
                pos = new Vector3(sizeHalf, 0, -sizeHalf);
                a   = 180;
                break;

            case Wall.DirectionEnum.WEST:
                pos = new Vector3(-sizeHalf, 0, -sizeHalf);
                a   = 270;
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(orientation), orientation, null);
            }

            anchor.transform.Rotate(Vector3.up, a);
            anchor.transform.localPosition = pos;

            return(anchor);
        }
        private static GameObject CreateAnchor(WallOrientation orientation, GameObject room, CuboidRoomModel model)
        {
            GameObject anchor = new GameObject(orientation + "Anchor");

            anchor.transform.parent = room.transform;
            Vector3 pos      = Vector3.zero;
            var     a        = 0f;
            var     sizeHalf = model.Size / 2f;

            switch (orientation)
            {
            case WallOrientation.NORTH:
                pos = new Vector3(-sizeHalf, 0, sizeHalf);
                a   = 0;
                break;

            case WallOrientation.EAST:
                pos = new Vector3(sizeHalf, 0, sizeHalf);
                a   = 90;
                break;

            case WallOrientation.SOUTH:
                pos = new Vector3(sizeHalf, 0, -sizeHalf);
                a   = 180;
                break;

            case WallOrientation.WEST:
                pos = new Vector3(-sizeHalf, 0, -sizeHalf);
                a   = 270;
                break;

            default:
                throw new ArgumentOutOfRangeException("orientation", orientation, null);
            }
            anchor.transform.Rotate(Vector3.up, a);
            anchor.transform.localPosition = pos;
            return(anchor);
        }