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);
        }
        public static Vector3 CalculateRoomPosition(DefaultNamespace.VREM.Model.Room room)
        {
            // TODO exhibition-dependet calculation
            float x = room.position.x, y = room.position.y, z = room.position.z;
            var   off = Settings.RoomOffset;

            return(new Vector3(x * room.size.x + x * off, y * room.size.y + y * off, z * room.size.z + z * off));
        }
        private static ExhibitionWall CreateExhibitionWall(WallOrientation orientation,
                                                           DefaultNamespace.VREM.Model.Room room, GameObject anchor)
        {
            var wall = anchor.AddComponent <ExhibitionWall>();

            wall.Anchor    = anchor;
            wall.WallModel = null;
            wall.WallData  = room.GetWall(orientation);
            return(wall);
        }
        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);
        }