Esempio n. 1
0
 public SourceStudioModel GetModel(string modelName)
 {
     modelName = modelName.ToLower();
     if (models.ContainsKey(modelName))
     {
         return(models[modelName]);
     }
     else
     {
         SourceStudioModel tempModel = new SourceStudioModel().Load(modelName);
         models.Add(modelName, tempModel);
         return(tempModel);
     }
 }
 public SourceStudioModel GetModel(string modelName)
 {
     modelName = modelName.ToLower();
     if (models.ContainsKey(modelName))
     {
         //if(models[modelName]!=null)
         //	models[modelName].GetInstance(go);
         return(models[modelName]);
     }
     else
     {
         SourceStudioModel tempModel = new SourceStudioModel().Load(modelName);
         models.Add(modelName, tempModel);
         //if(tempModel!=null)
         //	tempModel.GetInstance(go);
         return(tempModel);
     }
 }
Esempio n. 3
0
        public void Load(string mapName)
        {
            if (loaded)
            {
                Debug.LogWarning("Already loaded");
                return;
            }
            LevelName = mapName;

            string path = "";

            path = ResourceManager.GetPath("maps/" + LevelName + ".bsp");

            if (path == null)
            {
                return;
            }

            BinaryReader BR = new BinaryReader(File.Open(path, FileMode.Open));

            map    = new BSPFile(BR, LevelName);
            loaded = true;

            if (uSrcSettings.Inst.entities)
            {
                ParseEntities(map.entitiesLump);
            }

            //===================================================
            mapObject          = new GameObject(LevelName);
            mapObject.isStatic = true;

            modelsObject = new GameObject("models");
            modelsObject.transform.SetParent(mapObject.transform);
            modelsObject.isStatic = true;

            if (uSrcSettings.Inst.displacements)
            {
                dispObject = new GameObject("displacements");
                dispObject.transform.SetParent(mapObject.transform);
            }

            if (uSrcSettings.Inst.props)
            {
                propsObject = new GameObject("props");
                propsObject.transform.SetParent(mapObject.transform);
                propsObject.isStatic = true;
            }

            switch (LoadType)
            {
            case Type.Full:
                Debug.Log("Start Loading World Faces");

                if (uSrcSettings.Inst.lightmaps & map.hasLightmaps)
                {
                    lightmapsData = new List <LightmapData>();
                    curLightmap   = 0;
                    lm_allocated  = new int[BLOCK_SIZE];
                    LM_InitBlock();
                }

                models = new GameObject[map.modelsLump.Length];
                for (int i = 0; i < map.modelsLump.Length; i++)
                {
                    CreateModelObject(i);
                }

                if (uSrcSettings.Inst.lightmaps & map.hasLightmaps)
                {
                    LM_UploadBlock();
                    Debug.Log("Loading " + lightmapsData.Count + " lightmap pages");
                    LightmapSettings.lightmaps = lightmapsData.ToArray();
                    lm_allocated = null;
                }
                Debug.Log("Finish World Faces");
                GC.Collect();

                if (uSrcSettings.Inst.entities)
                {
                    Debug.Log("Start Loading Entities");

                    entObject = new GameObject("entities");
                    entObject.transform.parent = mapObject.transform;

                    for (int i = 0; i < entities.Count; i++)
                    {
                        LoadEntity(i);
                    }
                    Debug.Log("Finish Entities");
                }

                if (uSrcSettings.Inst.displacements)
                {
                    for (int m = 0; m < map.modelsLump.Length; m++)
                    {
                        for (int i = map.modelsLump[m].firstface; i < map.modelsLump[m].firstface + map.modelsLump[m].numfaces; i++)
                        {
                            if (map.facesLump[i].dispinfo != -1)
                            {
                                GenerateDispFaceObject(i, m);
                            }
                        }
                    }
                    Debug.Log("Finish Displacements");
                }

                //Static props
                if (uSrcSettings.Inst.props && map.staticPropsReaded)
                {
                    Debug.Log("Start Loading Static props");
                    for (int i = 0; i < map.StaticPropCount; i++)
                    {
                        bspStaticPropLump prop = map.StaticPropLump[i];
                        //Debug.Log ("static prop "+i+" model number is ("+prop.PropType+")");
                        if (prop.PropType > map.staticPropDict.Length)
                        {
                            Debug.LogWarning("Static prop " + i + " model number is (" + prop.PropType + ")");
                            continue;
                        }
                        string modelName = map.staticPropDict[prop.PropType];
                        //Debug.Log ("static prop "+i+" model name is "+modelName);
                        GameObject go = new GameObject();
                        //GameObject go = GameObject.CreatePrimitive(PrimitiveType.Cube);
                        go.name             = "prop " + modelName;
                        go.transform.parent = propsObject.transform;

                        //GameObject testGo = (GameObject)MonoBehaviour.Instantiate(TempProp) as GameObject;
                        //testGo.transform.parent=go.transform;

                        go.transform.position = prop.Origin;
                        go.transform.rotation = Quaternion.Euler(prop.Angles);


                        SourceStudioModel tempModel = ResourceManager.Inst.GetModel(modelName);
                        if (tempModel == null)
                        {
                            //Debug.LogWarning("Error loading: "+modelName);
                            GameObject prim = GameObject.CreatePrimitive(PrimitiveType.Cube);
                            prim.transform.parent        = go.transform;
                            prim.transform.localPosition = Vector3.zero;
                        }
                        else
                        {
                            tempModel.GetInstance(go, false, 0);
                        }

                        go.isStatic = true;
                        Props.Add(go);
                    }
                    Debug.Log("Finish Static Props");
                }
                break;

            case Type.WithoutBatching:
                for (int i = 0; i < map.modelsLump.Length; i++)
                {
                    models[i] = new GameObject("*" + i);
                    models[i].transform.SetParent(modelsObject.transform);
                    for (int f = map.modelsLump[i].firstface; f < map.modelsLump[i].firstface + map.modelsLump[i].numfaces; f++)
                    {
                        GenerateFaceObject(f).transform.SetParent(models[i].transform);
                    }
                }
                break;

            case Type.OnlyDisplacements:
                if (uSrcSettings.Inst.displacements)
                {
                    for (int i = 0; i < map.dispinfoLump.Length; i++)
                    {
                        GenerateDispFaceObject((int)map.dispinfoLump[i].MapFace, 0);
                        Debug.Log("FaceId: " + map.dispinfoLump[i].MapFace + " DispInfoId: " + i +
                                  " DispVertStart: " + map.dispinfoLump[i].DispVertStart);
                    }
                }
                break;

            case Type.OneFace:
                if (uSrcSettings.Inst.displacements & map.facesLump[faceId].dispinfo != -1)
                {
                    GenerateDispFaceObject(faceId, 0);
                    Debug.Log("FaceId: " + faceId + " DispInfoId: " + map.facesLump[faceId].dispinfo +
                              " DispVertStart: " + map.dispinfoLump[map.facesLump[faceId].dispinfo].DispVertStart);
                }
                else
                {
                    GenerateFaceObject(faceId);
                }
                break;
            }

            BR.BaseStream.Dispose();
            GC.Collect();
        }
Esempio n. 4
0
        void LoadEntity(int index)
        {
            List <string> data    = new List <string> ();
            string        pattern = "\"[^\"]*\"";

            foreach (Match match in Regex.Matches(entities[index], pattern, RegexOptions.IgnoreCase))
            {
                data.Add(match.Value.Trim('"'));
            }

            int    classNameIndex = data.FindIndex(n => n == "classname");
            string className      = data[classNameIndex + 1];

            if (className == "worldspawn")
            {
                //WorldSpawn(data);
                return;
            }

            Vector3 angles = new Vector3(0, 0, 0);

            if (data[0] == "model")
            {
                int        modelIndex = int.Parse(data[data.FindIndex(n => n == "model") + 1].Substring(1));
                GameObject obj        = models[modelIndex];

                if (data.Contains("origin"))
                {
                    if (data.FindIndex(n => n == "origin") % 2 == 0)
                    {
                        obj.transform.position = ConvertUtils.StringToVector(data[data.FindIndex(n => n == "origin") + 1]);
                    }
                }

                if (data.Contains("angles"))
                {
                    string[] t = data[data.FindIndex(n => n == "angles") + 1].Split(' ');
                    angles = new Vector3(-float.Parse(t[2]), -float.Parse(t[1]), -float.Parse(t[0]));
                    obj.transform.eulerAngles = angles;
                }

                if (className == "func_illusionary")
                {
                    MeshRenderer[] renderers = obj.GetComponentsInChildren <MeshRenderer>();
                    for (int i = 0; i < renderers.Length; i++)
                    {
                        renderers[i].castShadows = false;
                    }
                }

                return;
            }
            string[] testEnts = new string[] { "info_player_start", "sky_camera", "point_camera",
                                               "light_environment", "prop_dynamic", "prop_dynamic_override" /*,"point_viewcontrol"*/, "info_target",
                                               "light_spot", "light", "info_survivor_position", "env_projectedtexture", "func_illusionary",
                                               "prop_button", "prop_floor_button", "prop_weighted_cube" };

            if (testEnts.Contains(className))
            {
                string targetname = null;

                if (data.Contains("targetname"))
                {
                    targetname = data[data.FindIndex(n => n == "targetname") + 1];
                }

                if (data.Contains("angles"))
                {
                    string[] t = data[data.FindIndex(n => n == "angles") + 1].Split(' ');
                    angles = new Vector3(-float.Parse(t[2]), -float.Parse(t[1]), -float.Parse(t[0]));
                }

                if (data.Contains("pitch"))
                {
                    angles.x = -float.Parse(data[data.FindIndex(n => n == "pitch") + 1]);
                }

                GameObject obj = new GameObject(targetname ?? className);
                //if(className.Contains("light"))
                obj.transform.parent      = entObject.transform;
                obj.transform.position    = ConvertUtils.StringToVector(data[data.FindIndex(n => n == "origin") + 1]);
                obj.transform.eulerAngles = angles;

                /*if(className=="light")
                 * {
                 *      Light l = obj.AddComponent<Light>();
                 *      l.color = ConvertUtils.stringToColor(data[data.FindIndex (n=>n=="_light")+1],255);
                 * }
                 * if(className=="light_spot")
                 * {
                 *      Light l = obj.AddComponent<Light>();
                 *      l.type=LightType.Spot;
                 *      l.color = ConvertUtils.stringToColor(data[data.FindIndex (n=>n=="_light")+1],255);
                 *      //float pitch = 0;
                 *      //if(data.Contains ("pitch"))
                 *      //	pitch = float.Parse (data[data.FindIndex (n=>n=="pitch")+1]);
                 *      if(data.Contains ("_cone"))
                 *      {
                 *              l.spotAngle = int.Parse (data[data.FindIndex (n=>n=="_cone")+1]);
                 *      }
                 *      //angles.y = pitch;
                 *      angles.y+=90;
                 *      //obj.transform.eulerAngles = angles;
                 * }*/

                if (className == "light_environment" & Test.Inst.light_environment != null)
                {
                    Light l = Test.Inst.light_environment;
                    l.color = ConvertUtils.stringToColor(data[data.FindIndex(n => n == "_light") + 1], 255);
                    //float pitch = 0;
                    //if(data.Contains ("pitch"))
                    //	pitch = float.Parse (data[data.FindIndex (n=>n=="pitch")+1]);
                    //angles.y = pitch;
                    angles.y += 90;
                    l.transform.eulerAngles = angles;
                }

                if (className == "sky_camera")
                {
                    Test.Inst.skyCameraOrigin = obj.transform.position;
                    if (Test.Inst.skyCamera != null)
                    {
                        //Test.Inst.skyCamera.transform.SetParent(obj.transform);
                        //Test.Inst.skyCamera.transform.localPosition=Vector3.zero;
                        Test.Inst.skyCamera.transform.localPosition = (Test.Inst.playerCamera.transform.position / 16) + Test.Inst.skyCameraOrigin;
                        Test.Inst.skyCamera.transform.rotation      = Test.Inst.playerCamera.transform.rotation;
                    }
                }

                if (!Test.Inst.isL4D2)
                {
                    if (className == "info_player_start")
                    {
                        Test.Inst.startPos = obj.transform.position;
                    }
                }
                else
                {
                    if (className == "info_survivor_position")
                    {
                        Test.Inst.startPos = obj.transform.position;
                    }
                }

                if ((className == "prop_dynamic" | className == "prop_dynamic_override" | className == "prop_weighted_cube" | className == "prop_floor_button" | className == "prop_button") && uSrcSettings.Inst.propsDynamic)
                {
                    string modelName = "";

                    if (data.Contains("model"))
                    {
                        modelName = data[data.FindIndex(n => n == "model") + 1];
                    }
                    else if (className == "prop_weighted_cube")
                    {
                        modelName = "models/props/metal_box.mdl";
                    }
                    else if (className == "prop_floor_button")
                    {
                        modelName = "models/props/portal_button.mdl";
                    }
                    else if (className == "prop_button")
                    {
                        modelName = "models/props/switch001.mdl";
                    }

                    //angles.y-=90;
                    //Kostyl
                    //if(modelName.Contains("signage_num0"))
                    //	angles.y+=90;
                    //======
                    obj.transform.eulerAngles = angles;

                    SourceStudioModel tempModel = ResourceManager.Inst.GetModel(modelName);
                    if (tempModel == null || !tempModel.loaded)
                    {
                        //Debug.LogWarning("Error loading: "+modelName);
                        GameObject prim = GameObject.CreatePrimitive(PrimitiveType.Cube);
                        prim.name                    = modelName;
                        prim.transform.parent        = obj.transform;
                        prim.transform.localPosition = Vector3.zero;
                    }
                    else
                    {
                        tempModel.GetInstance(obj, true, 0);
                    }
                }

                /*if(className=="prop_floor_button")
                 * {
                 *      string modelname="models/props/button_base_reference.mdl";
                 *      SourceStudioModel baseModel = ResourceManager.Inst.GetModel(modelName);
                 *      if(baseModel==null||!baseModel.loaded)
                 *      {
                 *              Debug.LogWarning("Error loading: "+modelName);
                 *      }
                 *      else
                 *      {
                 *              GameObject baseObj=new GameObject("button_base");
                 *              baseObj.transform.SetParent(go.transform);
                 *              baseModel.GetInstance(baseObj, true,0);
                 *      }
                 *
                 *      modelname="models/props/button_top_reference.mdl";
                 *      SourceStudioModel topModel = ResourceManager.Inst.GetModel(modelName);
                 *      if(topModel==null||!topModel.loaded)
                 *      {
                 *              Debug.LogWarning("Error loading: "+modelName);
                 *      }
                 *      else
                 *      {
                 *              GameObject topObj=new GameObject("button_base");
                 *              topObj.transform.SetParent(go.transform);
                 *              topModel.GetInstance(topObj, true,0);
                 *      }
                 *
                 *      obj.transform.eulerAngles = angles;
                 * }*/
            }
        }
		void LoadEntity (int index)
		{
			List<string> data = new List<string> ();
			string pattern = "\"[^\"]*\"";

			foreach (Match match in Regex.Matches (entities[index], pattern, RegexOptions.IgnoreCase))
				data.Add (match.Value.Trim ('"'));

			int classNameIndex = data.FindIndex (n => n == "classname");
			string className = data[classNameIndex + 1];

			if (className == "worldspawn")
			{
			    if(data.Contains("skyname")) // Skybox loading
			    {
			       string sky = data[data.FindIndex(n => n == "skyname") + 1];
			       Material SkyMaterial = new Material(Shader.Find("Skybox/6 Sided"));
			       
			       Texture FrontTex = VTFLoader.LoadFile("skybox/" + sky + "ft");
                               FrontTex.wrapMode = TextureWrapMode.Repeat;
			       
			       Texture BackTex = VTFLoader.LoadFile("skybox/" + sky + "bk");
                    	       BackTex.wrapMode = TextureWrapMode.Repeat;
			       
			       Texture LeftTex = VTFLoader.LoadFile("skybox/" + sky + "lf");
                    	       LeftTex.wrapMode = TextureWrapMode.Repeat;
			       
			       Texture RightTex = VTFLoader.LoadFile("skybox/" + sky + "rt");
                               RightTex.wrapMode = TextureWrapMode.Repeat;
			       
			       Texture DownTex = VTFLoader.LoadFile("skybox/" + sky + "dn");
                    	       DownTex.wrapMode = TextureWrapMode.Repeat;
			       
			       Texture UpTex = VTFLoader.LoadFile("skybox/" + sky + "up");
                               UpTex.wrapMode = TextureWrapMode.Repeat;
			       
			       //if any of you can code it so that the up texture of the skybox
			       //gets rotated by 90 that would be perfect -Jhrino
			       
			      SkyMaterial.SetTexture("_FrontTex", FrontTex);
                   	      SkyMaterial.SetTexture("_BackTex", BackTex);
                              SkyMaterial.SetTexture("_LeftTex", LeftTex);
                              SkyMaterial.SetTexture("_RightTex", RightTex);
                              SkyMaterial.SetTexture("_DownTex", DownTex);
                              SkyMaterial.SetTexture("_UpTex", UpTex);
			      
			      RenderSettings.skybox = SkyMaterial;	       
			    }
				return;
			}

			Vector3 angles = new Vector3 (0, 0, 0);
			if (data[0] == "model")
			{
				int modelIndex = int.Parse (data[data.FindIndex (n => n == "model") + 1].Substring (1));
				GameObject obj = models[modelIndex];

				if (data.Contains ("origin"))
				{
					if (data.FindIndex (n => n == "origin") % 2 == 0)
						obj.transform.position = ConvertUtils.StringToVector (data[data.FindIndex (n => n == "origin") + 1]);
				}

				if (data.Contains ("angles"))
				{
					string[] t = data[data.FindIndex (n => n == "angles") + 1].Split (' ');
					angles = new Vector3 (-ConvertUtils.floatParse(t[2]), ConvertUtils.floatParse(t[1]), ConvertUtils.floatParse(t[0]));
					obj.transform.eulerAngles = angles;
				}

				if (className == "func_illusionary")
				{
					MeshRenderer[] renderers = obj.GetComponentsInChildren<MeshRenderer> ();
					for (int i = 0; i < renderers.Length; i++)
					{
						renderers[i].shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
					}
				}

				return;
			}
			string[] testEnts = new string[]
			{
				"info_player_start",
				"sky_camera",
				"point_camera",
				"light_environment",
				"prop_dynamic",
				"prop_dynamic_override" /*,"point_viewcontrol"*/ ,
				"info_target",
				"light_spot",
				"light",
				"info_survivor_position",
				"env_projectedtexture",
				"func_illusionary",
				"prop_button",
				"prop_floor_button",
				"prop_weighted_cube",
				"prop_physics"
			};

			if (testEnts.Contains (className))
			{
				string targetname = null;

				if (data.Contains ("targetname"))
					targetname = data[data.FindIndex (n => n == "targetname") + 1];

				if (data.Contains ("angles"))
				{
					string[] t = data[data.FindIndex (n => n == "angles") + 1].Split (' ');
					angles = new Vector3 (-ConvertUtils.floatParse(t[2]), ConvertUtils.floatParse(t[1]), ConvertUtils.floatParse(t[0]));
				}

				if (data.Contains ("pitch"))
					angles.x = -ConvertUtils.floatParse(data[data.FindIndex (n => n == "pitch") + 1]);

				GameObject obj = new GameObject (targetname ?? className);
				//if(className.Contains("light"))
				obj.transform.parent = entObject.transform;
				obj.transform.position = ConvertUtils.StringToVector (data[data.FindIndex (n => n == "origin") + 1]);
				obj.transform.eulerAngles = angles;

				/*if(className=="light")
				{
					Light l = obj.AddComponent<Light>();
					l.color = ConvertUtils.stringToColor(data[data.FindIndex (n=>n=="_light")+1],255);
				}
				if(className=="light_spot")
				{
					Light l = obj.AddComponent<Light>();
					l.type=LightType.Spot;
					l.color = ConvertUtils.stringToColor(data[data.FindIndex (n=>n=="_light")+1],255);
					//float pitch = 0;
					//if(data.Contains ("pitch"))
					//	pitch = float.Parse (data[data.FindIndex (n=>n=="pitch")+1]);
					if(data.Contains ("_cone"))
					{
						l.spotAngle = int.Parse (data[data.FindIndex (n=>n=="_cone")+1]);
					}
					//angles.y = pitch;
					angles.y+=90;
					//obj.transform.eulerAngles = angles; 
				}*/

				if (className == "light_environment" & Test.Inst.light_environment != null)
				{
					Light l = Test.Inst.light_environment;
					l.color = ConvertUtils.stringToColor (data[data.FindIndex (n => n == "_light") + 1], 255);
					//float pitch = 0;
					//if(data.Contains ("pitch"))
					//	pitch = float.Parse (data[data.FindIndex (n=>n=="pitch")+1]);
					//angles.y = pitch;
					angles.y += 90;
					l.transform.eulerAngles = angles;
				}

				if (className == "sky_camera")
				{
					Test.Inst.skyCameraOrigin = obj.transform.position;
					if (Test.Inst.skyCamera != null)
					{
						//Test.Inst.skyCamera.transform.SetParent(obj.transform);
						//Test.Inst.skyCamera.transform.localPosition=Vector3.zero;
						Test.Inst.skyCamera.transform.localPosition = (Test.Inst.playerCamera.transform.position / 16) + Test.Inst.skyCameraOrigin;
						Test.Inst.skyCamera.transform.rotation = Test.Inst.playerCamera.transform.rotation;
					}
				}

				if (!Test.Inst.isL4D2)
				{
					if (className == "info_player_start")
					{
						Test.Inst.startPos = obj.transform.position;
					}
				}
				else
				{
					if (className == "info_survivor_position")
					{
						Test.Inst.startPos = obj.transform.position;
					}
				}
				if ((className == "prop_dynamic" | className == "prop_dynamic_override" | className == "prop_weighted_cube" | className == "prop_floor_button" | className == "prop_button" | className == "prop_physics") && uSrcSettings.Inst.propsDynamic)
				{
					string modelName = "";

					if (data.Contains ("model"))
						modelName = data[data.FindIndex (n => n == "model") + 1];
					else if (className == "prop_weighted_cube")
						modelName = "models/props/metal_box.mdl";
					else if (className == "prop_floor_button")
						modelName = "models/props/portal_button.mdl";
					else if (className == "prop_button")
						modelName = "models/props/switch001.mdl";

					//angles.y-=90;
					//Kostyl
					//if(modelName.Contains("signage_num0"))
					//	angles.y+=90;
					//======
					obj.transform.eulerAngles = angles;

					SourceStudioModel tempModel = ResourceManager.Inst.GetModel (modelName);
					if (tempModel == null || !tempModel.loaded)
					{
						//Debug.LogWarning("Error loading: "+modelName);
						GameObject prim = GameObject.CreatePrimitive (PrimitiveType.Cube);
						prim.name = modelName;
						prim.transform.parent = obj.transform;
						prim.transform.localPosition = Vector3.zero;
					}
					else
					{
						tempModel.GetInstance (obj, true, 0);
					}
					if(className == "prop_physics")
					{
						obj.GetComponent<MeshCollider>().convex = true;
						obj.AddComponent<Rigidbody>();
					}

				}

				/*if(className=="prop_floor_button")
				{
					string modelname="models/props/button_base_reference.mdl";
					SourceStudioModel baseModel = ResourceManager.Inst.GetModel(modelName);
					if(baseModel==null||!baseModel.loaded)
					{
						Debug.LogWarning("Error loading: "+modelName);
					}
					else
					{
						GameObject baseObj=new GameObject("button_base");
						baseObj.transform.SetParent(go.transform);
						baseModel.GetInstance(baseObj, true,0);
					}
					
					modelname="models/props/button_top_reference.mdl";
					SourceStudioModel topModel = ResourceManager.Inst.GetModel(modelName);
					if(topModel==null||!topModel.loaded)
					{
						Debug.LogWarning("Error loading: "+modelName);
					}
					else
					{
						GameObject topObj=new GameObject("button_base");
						topObj.transform.SetParent(go.transform);
						topModel.GetInstance(topObj, true,0);
					}
						
					obj.transform.eulerAngles = angles;
				}*/
			}
		}
Esempio n. 6
0
        public void Load(string mapName)
        {
            LevelName = mapName;

            string path = "";

            path = ResourceManager.GetPath("maps/" + LevelName + ".bsp");

            if (path == null)
            {
                Debug.Log("maps/" + LevelName + ".bsp: Not Found");
                return;
            }

            BinaryReader BR = new BinaryReader(File.Open(path, FileMode.Open));

            map = new BSPFile(BR, LevelName);
            if (uSrcSettings.Inst.entities)
            {
                ParseEntities(map.entitiesLump);
            }
            //ProcessFaces();

            /*for(int i=0;i<entities.Count;i++)
             * {
             *      LoadEntity (i);
             * }*/
            //===================================================
            mapObject = new GameObject(LevelName);

            modelsObject = new GameObject("models");
            modelsObject.transform.parent = mapObject.transform;

            if (uSrcSettings.Inst.displacements)
            {
                dispObject = new GameObject("disp");
                dispObject.transform.parent = mapObject.transform;
            }

            if (uSrcSettings.Inst.props)
            {
                propsObject = new GameObject("props");
                propsObject.transform.parent = mapObject.transform;
            }

            //for (int i=0; i<modelsLump.Length; i++)
            //{
            //	BuildModelObject(i);
            //}

            if (faceId == -1)
            {
                if (uSrcSettings.Inst.lightmaps && map.hasLightmaps)
                {
                    lightmapsData = new List <LightmapData>();
                }

                for (int i = 0; i < map.modelsLump.Length; i++)
                {
                    CreateModelObject(i);
                }
                //CreateModelObject(0);
                if (uSrcSettings.Inst.lightmaps && map.hasLightmaps)
                {
                    LightmapSettings.lightmaps = lightmapsData.ToArray();
                }

                Debug.Log("Finish World Faces");

                if (uSrcSettings.Inst.entities)
                {
                    entObject = new GameObject("entities");
                    entObject.transform.parent = mapObject.transform;
                    Debug.Log("Start Loading Entities");
                    for (int i = 0; i < entities.Count; i++)
                    {
                        LoadEntity(i);
                    }
                    Debug.Log("Finish Entities");
                }

                if (uSrcSettings.Inst.displacements)
                {
                    for (int m = 0; m < map.modelsLump.Length; m++)
                    {
                        for (int i = map.modelsLump[m].firstface; i < map.modelsLump[m].firstface + map.modelsLump[m].numfaces; i++)
                        {
                            if (map.facesLump[i].dispinfo != -1)
                            {
                                GenerateDispFaceObject(i, m);
                            }
                        }
                    }
                    Debug.Log("Finish Displacements");
                }

                //Static props
                if (uSrcSettings.Inst.props && map.staticPropsReaded)
                {
                    Debug.Log("Start Loading Static props");
                    for (int i = 0; i < map.StaticPropCount; i++)
                    {
                        bspStaticPropLump prop = map.StaticPropLump[i];
                        //Debug.Log ("static prop "+i+" model number is ("+prop.PropType+")");
                        if (prop.PropType > map.staticPropDict.Length)
                        {
                            Debug.LogWarning("Static prop " + i + " model number is (" + prop.PropType + ")");
                            continue;
                        }
                        string modelName = map.staticPropDict[prop.PropType];
                        //Debug.Log ("static prop "+i+" model name is "+modelName);
                        GameObject go = new GameObject();
                        //GameObject go = GameObject.CreatePrimitive(PrimitiveType.Cube);
                        go.name             = "prop " + modelName;
                        go.transform.parent = propsObject.transform;

                        //GameObject testGo = (GameObject)MonoBehaviour.Instantiate(TempProp) as GameObject;
                        //testGo.transform.parent=go.transform;

                        go.transform.position = prop.Origin;
                        go.transform.rotation = Quaternion.Euler(prop.Angles);


                        SourceStudioModel tempModel = ResourceManager.Inst.GetModel(modelName);
                        if (tempModel == null)
                        {
                            Debug.LogWarning("Error loading: " + modelName);
                            GameObject prim = GameObject.CreatePrimitive(PrimitiveType.Cube);
                            prim.transform.parent        = go.transform;
                            prim.transform.localPosition = Vector3.zero;
                        }
                        else
                        {
                            tempModel.GetInstance(go, false, 0);
                        }

                        go.isStatic = true;
                        Props.Add(go);
                    }
                    Debug.Log("Finish Static Props");
                }
            }
            //====================================================
            else if (faceId == -2 & uSrcSettings.Inst.displacements)
            {
                for (int i = 0; i < map.dispinfoLump.Length; i++)
                {
                    GenerateDispFaceObject((int)map.dispinfoLump[i].MapFace, 0);
                    Debug.Log("FaceId: " + map.dispinfoLump[i].MapFace + " DispInfoId: " + i +
                              " DispVertStart: " + map.dispinfoLump[i].DispVertStart);
                }
            }
            else if (faceId == -3)
            {
                for (int i = 0; i < map.modelsLump.Length; i++)
                {
                    Models.Add(new GameObject("*" + i));
                    Models[i].transform.SetParent(modelsObject.transform);
                    for (int f = map.modelsLump[i].firstface; f < map.modelsLump[i].firstface + map.modelsLump[i].numfaces; f++)
                    {
                        GenerateFaceObject(f, i);
                    }
                }
            }
            else
            {
                if (uSrcSettings.Inst.displacements)
                {
                    GenerateDispFaceObject(faceId, 0);
                    Debug.Log("FaceId: " + faceId + " DispInfoId: " + map.facesLump[faceId].dispinfo +
                              " DispVertStart: " + map.dispinfoLump[map.facesLump[faceId].dispinfo].DispVertStart);
                }
                else
                {
                    GenerateFaceObject(faceId, 0);
                }
            }
            BR.BaseStream.Dispose();
        }