Example #1
0
    private void PopulateWalls(DefaultNamespace.VREM.Model.Wall[] walls)
    {
        foreach (var wall in walls)
        {
            if (wall.direction == "NORTH")
            {
                LoadExhibits(wall, WallOrientation.NORTH);
                GetWallForOrientation(WallOrientation.NORTH).LoadMaterial(TexturingUtility.Translate(wall.texture));
            }

            if (wall.direction == "EAST")
            {
                LoadExhibits(wall, WallOrientation.EAST);
                GetWallForOrientation(WallOrientation.EAST).LoadMaterial(TexturingUtility.Translate(wall.texture));
            }

            if (wall.direction == "SOUTH")
            {
                LoadExhibits(wall, WallOrientation.SOUTH);
                GetWallForOrientation(WallOrientation.SOUTH).LoadMaterial(TexturingUtility.Translate(wall.texture));
            }

            if (wall.direction == "WEST")
            {
                LoadExhibits(wall, WallOrientation.WEST);
                GetWallForOrientation(WallOrientation.WEST).LoadMaterial(TexturingUtility.Translate(wall.texture));
            }
        }
    }
        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);
        }
        private static Material GetMaterialForWallOrientation(WallOrientation orientation,
                                                              DefaultNamespace.VREM.Model.Room roomData)
        {
            foreach (DefaultNamespace.VREM.Model.Wall wallData in roomData.walls)
            {
                WallOrientation wor = (WallOrientation)Enum.Parse(typeof(WallOrientation), wallData.direction, true);
                if (wor.Equals(orientation))
                {
                    Debug.Log("Material " + wallData.texture + " for room " + roomData.position);
                    return(TexturingUtility.LoadMaterialByName(wallData.texture, true));
                }
            }

            throw new ArgumentException("Couldn't find material for orientation " + orientation + " in room at " +
                                        roomData.position);
        }
Example #4
0
        private void CreateAndAttachTeleporters(CuboidExhibitionRoom room)
        {
            var index = GetRoomIndex(room.RoomData);
            var next  = _rooms[GetNextRoomIndex(index)];
            var prev  = _rooms[GetPreviousRoomIndex(index)];

            var nd = next.GetEntryPoint();
            var pd = prev.GetEntryPoint();

            var backPos = new Vector3(-.25f, 0, .2f);
            var nextPos = new Vector3(.25f, 0, .2f);

            // TODO Configurable TPBtnModel
            var model = new SteamVRTeleportButton.TeleportButtonModel(0.1f, .02f, 1f,
                                                                      TexturingUtility.LoadMaterialByName("none"),
                                                                      TexturingUtility.LoadMaterialByName("NMetal"), TexturingUtility.LoadMaterialByName("NPlastic"));

            if (_exhibition.rooms.Length > 1)
            {
                // back teleporter
                var backTpBtn = SteamVRTeleportButton.Create(room.gameObject, backPos, pd, model
                                                             ,
                                                             Resources.Load <Sprite>("Sprites/UI/chevron-left"));

                backTpBtn.OnTeleportStart = room.OnRoomLeave;
                backTpBtn.OnTeleportEnd   = prev.OnRoomEnter;

                // back teleporter
                var nextTpBtn = SteamVRTeleportButton.Create(room.gameObject, nextPos, nd,
                                                             model,
                                                             Resources.Load <Sprite>("Sprites/UI/chevron-right"));

                nextTpBtn.OnTeleportStart = room.OnRoomLeave;
                nextTpBtn.OnTeleportEnd   = next.OnRoomEnter;
            }


            if (VREPController.Instance.Settings.StartInLobby)
            {
                var lobbyTpBtn = SteamVRTeleportButton.Create(room.gameObject, new Vector3(0, 0, .2f),
                                                              VREPController.Instance.LobbySpawn,
                                                              model,
                                                              "Lobby");
                lobbyTpBtn.OnTeleportStart = room.OnRoomLeave;
            }
        }
Example #5
0
        /// <summary>
        /// Returns the material (wall texture) for a specific wall orientation (= for 1 wall) as defined in the room model.
        /// </summary>
        /// <param name="orientation">The orientation of the wall to get the material for.</param>
        /// <param name="roomData">The room model object to take the data for the wall material from.</param>
        /// <returns>The resulting Material object.</returns>
        /// <exception cref="ArgumentException"></exception>
        private static Material GetMaterialForWallOrientation(Wall.DirectionEnum orientation, Room roomData)
        {
            foreach (var wallData in roomData.Walls)
            {
                if (!orientation.Equals(wallData.Direction))
                {
                    continue;
                }

                Debug.Log("Material " + wallData.Texture + " for room " + roomData.Position + ".");

                return(TexturingUtility.LoadMaterialByName(wallData.Texture, true));
            }

            throw new ArgumentException("Couldn't find material for orientation " + orientation + " in room at " +
                                        roomData.Position + ".");
        }
Example #6
0
    public void Populate(DefaultNamespace.VREM.Model.Room room)
    {
        Debug.Log(room);
        Debug.Log(room.walls);
        _roomModel = room;


        Debug.Log("adjusting ceiling and floor");
        // TODO Use new material loading code
        gameObject.transform.Find("Ceiling").gameObject.GetComponent <TexturedMonoBehaviour>()
        .LoadMaterial(TexturingUtility.Translate(room.ceiling));
        gameObject.transform.Find("Floor").gameObject.GetComponent <TexturedMonoBehaviour>()
        .LoadMaterial(TexturingUtility.Translate(room.floor));

        /*Debug.Log("add globe");
         * if(GlobePrefab != null){ //TODO: add a new check
         *  var globe = Instantiate(GlobePrefab) as GameObject;
         *  globe.transform.rotation = Quaternion.Euler(-90, -90, 0);
         *  globe.transform.position = new Vector3(-2.5f, 0, -2.5f);
         *  globe.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f);
         * }*/

        if (!string.IsNullOrEmpty(room.GetURLEncodedAudioPath()))
        {
            Debug.Log("add audio to room");

            if (audio == null)
            {
                audio = gameObject.AddComponent <AudioLoader>();
            }

            audio.ReloadAudio(room.GetURLEncodedAudioPath());
        }
        //

        PopulateWalls(room.walls);
        //PlaceExhibits(room.exhibits);


        // DEBUG TESTING TODO REMOVE this when done
        //Debug.Log("Test");
        //LoadAndPlaceModel(ServerSettings.SERVER_ID+"content/get/5bd3292c64aa33a460bcdade%2f1%2fexhibits%2fearth.obj", new Vector3(0,1,0));
    }
Example #7
0
 // Use this for initialization
 void Start()
 {
     text = SteamVRTeleportButton.Create(gameObject, new Vector3(0, 0, 4.5f), Vector3.zero,
                                         new SteamVRTeleportButton.TeleportButtonModel(0.1f, .02f, 1f, TexturingUtility.LoadMaterialByName("none"),
                                                                                       TexturingUtility.LoadMaterialByName("NMetal"), TexturingUtility.LoadMaterialByName("NPlastic")),
                                         "Text");
     next = SteamVRTeleportButton.Create(gameObject, new Vector3(.5f, 0, 4.5f), Vector3.zero,
                                         new SteamVRTeleportButton.TeleportButtonModel(0.1f, .02f, 1f, TexturingUtility.LoadMaterialByName("NWood"),
                                                                                       TexturingUtility.LoadMaterialByName("NMetal"), TexturingUtility.LoadMaterialByName("NPlastic")),
                                         Resources.Load <Sprite>("Sprites/UI/chevron-right"));
     wall = SteamVRTeleportButton.Create(gameObject, new Vector3(0, 1.5f, 4.98f), Vector3.zero,
                                         new SteamVRTeleportButton.TeleportButtonModel(0.2f, .02f, 2f, TexturingUtility.LoadMaterialByName("none"),
                                                                                       TexturingUtility.LoadMaterialByName("NMetal"), TexturingUtility.LoadMaterialByName("NPlastic"), hasPedestal: false),
                                         "Wall");
 }
        public void SetButtonReady()
        {
            var buttonRenderer = GetButtonRenderer();

            buttonRenderer.material = TexturingUtility.LoadMaterialByName("DefaultGreen");
        }
        public void SetButtonLoading()
        {
            var buttonRenderer = GetButtonRenderer();

            buttonRenderer.material = TexturingUtility.LoadMaterialByName("DefaultYellow");
        }
Example #10
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);
        }