private void LightSettings()
    {
        Renderer [] renderers;
        if (myRootObj == null)
        {
            renderers = GameObject.FindObjectsOfType <Renderer>();
        }
        else
        {
            myRootObj.isStatic = true;
            renderers          = myRootObj.GetComponentsInChildren <Renderer>();
        }
        foreach (Renderer renderer in renderers)
        {
            renderer.gameObject.isStatic = true;
        }
        Lightmapping.giWorkflowMode                 = Lightmapping.GIWorkflowMode.OnDemand;
        LightmapEditorSettings.resolution           = lightRealtimeResolution;
        RenderSettings.ambientIntensity             = lightAmbientIntensity;
        RenderSettings.ambientMode                  = UnityEngine.Rendering.AmbientMode.Skybox;
        RenderSettings.skybox                       = mySkybox;
        myLightObj.GetComponent <Light>().intensity = lightDirectionalIntensity;

        Lightmapping.BakeAsync();
    }
Exemple #2
0
    void Update()
    {
        if (!_baking)
        {
            return;
        }

        if (!Lightmapping.isRunning)
        {
            _scenesBuilt.Add(_realPaths[_currentSceneBuildingIndex]);
            EditorSceneManager.OpenScene(_realPaths[_currentSceneBuildingIndex]);

            LightmapEditorSettings.maxAtlasSize  = int.Parse(_lightmapResolution[_lightMapResIndex]);
            LightmapEditorSettings.lightmapper   = LightmapEditorSettings.Lightmapper.Enlighten;
            LightmapEditorSettings.mixedBakeMode = MixedLightingMode.Shadowmask;
            LightmapEditorSettings.lightmapsMode = LightmapsMode.NonDirectional;
            LightmapEditorSettings.filteringMode = LightmapEditorSettings.FilterMode.Auto;
            Lightmapping.realtimeGI = false;
            Lightmapping.bakedGI    = true;


            Lightmapping.BakeAsync();
            _currentSceneBuildingIndex++;

            if (_realPaths.Length == _currentSceneBuildingIndex)
            {
                _baking = false;
            }
        }
    }
 private void OnGUI()
 {
     if (GUILayout.Button("BakeMain"))
     {
         worldState = WorldState.Main;
         SetBakeDirectionLight(true);
         Lightmapping.BakeAsync();
     }
     if (GUILayout.Button("BakeOther"))
     {
         worldState = WorldState.Other;
         SetBakeDirectionLight(true);
         Lightmapping.BakeAsync();
     }
     if (GUILayout.Button("ShowMain"))
     {
         worldState = WorldState.Main;
         SetBakeDirectionLight(false);
         LightMapTool.ApplyLightmaps(false);
     }
     if (GUILayout.Button("ShowOther"))
     {
         worldState = WorldState.Other;
         SetBakeDirectionLight(false);
         LightMapTool.ApplyLightmaps(true);
     }
     mainLight = EditorGUILayout.ObjectField("main light",
                                             mainLight,
                                             typeof(Light),
                                             true) as Light;
     otherLight = EditorGUILayout.ObjectField("other light",
                                              otherLight,
                                              typeof(Light),
                                              true) as Light;
 }
Exemple #4
0
 /**
  * Builds lighting if auto-generate lightmaps is turned off.
  */
 private static void BuildLighting()
 {
     if (Lightmapping.giWorkflowMode == Lightmapping.GIWorkflowMode.OnDemand)
     {
         Lightmapping.BakeAsync();
     }
 }
 static void BakeLightmap()
 {
     //		Lightmapping.ClearDiskCache();
     //		Lightmapping.Clear();
     Caching.CleanCache();
     startTime = Time.realtimeSinceStartup;
     Lightmapping.BakeAsync();
 }
Exemple #6
0
 //Bakes the lighting for your current open scene
 public static void GX_Skies_BakeLighting()
 {
     if (!Lightmapping.isRunning)
     {
         UnityEngine.RenderSettings.ambientMode = AmbientMode.Skybox;
         Lightmapping.BakeAsync();
     }
 }
Exemple #7
0
 /// <summary>
 /// Bakes global lighting
 /// </summary>
 public static void BakeGlobalLighting()
 {
     //Bakes the lightmaps
     if (!Application.isPlaying && !Lightmapping.isRunning)
     {
         Lightmapping.BakeAsync();
     }
 }
Exemple #8
0
        private void CreateSimulation()
        {
            if (string.IsNullOrEmpty(_simulationName))
            {
                EditorUtility.DisplayDialog("Error", "Insert a valid name for the new simulation", "Cancel");
                return;
            }

            _simulationName = _simulationName.Trim();
            var path = SimulationsBaseDir + _simulationName;

            // Check if simulation name exist
            if (Directory.Exists(path))
            {
                EditorUtility.DisplayDialog("Error", "Simulation " + _simulationName + " already Exist!", "Cancel");
                return;
            }
            // Create simulation base folder
            Directory.CreateDirectory(path);

            // Create Simulation Environment Prefab
            var newSimEnv = CreateInstance <SimulationEnvironment> ();

            newSimEnv.problem = _problem;
            newSimEnv.Initialize();
            var newSimEnvPath = AssetDatabase.GenerateUniqueAssetPath(path + "/" + _simulationName + " Environment.asset");

            AssetDatabase.CreateAsset(newSimEnv, newSimEnvPath);

            // Create Folder for Types Models
            Directory.CreateDirectory(path + "/Types Models");

            // Create Folder for Predicates Behaviours
            Directory.CreateDirectory(path + "/Predicates Behaviours");


            var newScene = EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Single);

            newScene.name = _simulationName;
            var simulationManagerAsset = AssetDatabase.LoadAssetAtPath <GameObject>("Assets/Prefabs/SimulationManager.prefab");
            var sceneElementsAsset     = AssetDatabase.LoadAssetAtPath <GameObject>("Assets/Prefabs/Scene Elements.prefab");

            Instantiate(sceneElementsAsset);
            var simulationManager = Instantiate(simulationManagerAsset);

            // Initialize simulation manager
            simulationManager.GetComponent <SimulationManager>().domain         = _domain;
            simulationManager.GetComponent <SimulationManager>().simulationName = _simulationName;
            simulationManager.GetComponent <SimulationManager>().Initialize();
            simulationManager.GetComponent <SimulationManager>().simulationEnvironment = newSimEnv;

            // Save changes
            EditorSceneManager.SaveScene(newScene, "Assets/Scenes/" + _simulationName + ".unity");
            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();
            Lightmapping.BakeAsync();
            Close();
        }
Exemple #9
0
        public static void BakeLights()
        {
            if (Lightmapping.isRunning)
            {
                return;
            }

            Lightmapping.BakeAsync();
        }
 private static void StartLightmapping(LightingSettings settings)
 {
     GenerateLightmapUVs();
     Lightmapping.lightingSettings = settings;
     if (Lightmapping.BakeAsync())
     {
         SceneView.duringSceneGui += SceneView_duringSceneGui;
     }
 }
    public void GenerateLighting()
    {
        Ceiling.SetActive(true);

        Lightmapping.BakeAsync();
        Lightmapping.completed = () =>
        {
            Ceiling.SetActive(false);
        };
    }
Exemple #12
0
        public IEnumerator DefaultUnwrapParamsDoNotOverlap()
        {
            var lightmapMode = Lightmapping.giWorkflowMode;

            try
            {
                Lightmapping.giWorkflowMode = Lightmapping.GIWorkflowMode.OnDemand;

                Lightmapping.started += LightmappingStarted;

                if (Lightmapping.completed == null)
                {
                    Lightmapping.completed = LightmappingCompleted;
                }
                else
                {
                    Lightmapping.completed += LightmappingCompleted;
                }

                Setup();

                float x = -10f;

                using (var shapes = new TestUtility.BuiltInPrimitives())
                {
                    SceneModeUtility.SetStaticFlags(shapes.Select(it => it.gameObject).ToArray(), (int)StaticEditorFlags.LightmapStatic, true);

                    foreach (ProBuilderMesh mesh in shapes)
                    {
                        mesh.transform.position = new Vector3(x, 0f, 0f);
                        x += mesh.mesh.bounds.size.x + .5f;
                        mesh.Optimize(true);
                    }

                    Lightmapping.BakeAsync();

                    while (!s_FinishedBaking)
                    {
                        yield return(null);
                    }

                    LogAssert.NoUnexpectedReceived();
                }
            }
            finally
            {
                Lightmapping.started       -= LightmappingStarted;
                Lightmapping.completed     -= LightmappingCompleted;
                Lightmapping.giWorkflowMode = lightmapMode;
                Cleanup();
            }
        }
    public IEnumerator ActivateDirectLighting_DuringABake_DoesNotFallback()
    {
        EditorSceneManager.OpenScene("Assets/Tests/Editor/Tests_Unit_Editmode/BakeRestartScene.unity", OpenSceneMode.Single);
        yield return(null);

        LightingSettings lightingSettings = null;

        Lightmapping.TryGetLightingSettings(out lightingSettings);

        Assert.That(lightingSettings, !Is.EqualTo(null), "LightingSettings is null");

        lightingSettings.lightmapper        = LightingSettings.Lightmapper.ProgressiveGPU;
        lightingSettings.mixedBakeMode      = MixedLightingMode.IndirectOnly;
        lightingSettings.directionalityMode = LightmapsMode.NonDirectional;

        GameObject dirLightGO = GameObject.FindGameObjectsWithTag("TheLight")[0];

        dirLightGO.SetActive(false);
        Light light = dirLightGO.GetComponent(typeof(Light)) as Light;

        light.lightmapBakeType = LightmapBakeType.Baked;

        Lightmapping.Clear();
        Lightmapping.BakeAsync();

        foreach (bool b in RunABake(0.2f))
        {
            yield return(null);
        }

        // Make sure it is still baking before we
        // switch the light on and restart the bake
        Assert.IsTrue(Lightmapping.isBaking);

        // Activate the light, cause the bake to restart
        dirLightGO.SetActive(true);

        foreach (bool b in RunABake(0.2f))
        {
            yield return(null);
        }

        // Check that baking is still running
        Assert.IsTrue(Lightmapping.isBaking);
        // Check that we did not fallback to CPULM
        Assert.AreEqual(lightingSettings.lightmapper, LightingSettings.Lightmapper.ProgressiveGPU);

        Lightmapping.Cancel();
        Lightmapping.Clear();
        Lightmapping.ClearLightingDataAsset();
    }
Exemple #14
0
    private IEnumerator BuildLightingAsync(string ScenarioName)
    {
        var newLightmapMode = new LightmapsMode();

        newLightmapMode = LightmapSettings.lightmapsMode;
        Lightmapping.BakeAsync();
        while (Lightmapping.isRunning)
        {
            yield return(null);
        }
        Lightmapping.lightingDataAsset = null;
        EditorSceneManager.SaveScene(EditorSceneManager.GetSceneByPath("Assets/Scenes/" + ScenarioName + ".unity"));
        EditorSceneManager.CloseScene(EditorSceneManager.GetSceneByPath("Assets/Scenes/" + ScenarioName + ".unity"), true);
        LightmapSettings.lightmapsMode = newLightmapMode;
    }
Exemple #15
0
    void OpenBakeAndSave()
    {
        fileName = "Assets/Scenes/Levels/" + levelNames[levelIndex] + ".unity";

        EditorSceneManager.OpenScene(fileName);

        Lightmapping.Clear();

        //  LightmapEditorSettings.maxAtlasHeight = 4096;
        //  LightmapEditorSettings.maxAtlasWidth = 4096;

        Lightmapping.BakeAsync();

        startedBaking = true;
    }
    private IEnumerator BuildLightingAsync(string ScenarioName)
    {
        var newLightmapMode = new LightmapsMode();

        newLightmapMode = LightmapSettings.lightmapsMode;
        Lightmapping.BakeAsync();
        while (Lightmapping.isRunning)
        {
            yield return(null);
        }
        Lightmapping.lightingDataAsset = null;
        EditorSceneManager.SaveScene(EditorSceneManager.GetSceneByPath("Assets/Scenes/MapData_1212/UPBR_daytime001.unity"));
        //   EditorSceneManager.SaveScene(EditorSceneManager.GetSceneByPath("Assets/Scenes/MapData_1122/UPBR001.unity"));
        LightmapSettings.lightmapsMode = newLightmapMode;
    }
Exemple #17
0
 // Loop through scenes to bake and update on progress
 private void BakeNewScene()
 {
     if (sceneIndex < scenes.Length)
     {
         EditorApplication.OpenScene(scenePath[sceneIndex]);
         timeStamp = System.DateTime.Now;
         Lightmapping.BakeAsync();
         UpdateBakeProgress();
         sceneIndex++;
     }
     else
     {
         DoneBaking("done");
     }
 }
Exemple #18
0
    private IEnumerator BuildLightingAsync(Scene lightingScene)
    {
        var newLightmapMode = new LightmapsMode();

        newLightmapMode = LightmapSettings.lightmapsMode;
        Lightmapping.BakeAsync();
        while (Lightmapping.isRunning)
        {
            yield return(null);
        }
        //Lightmapping.lightingDataAsset = null;
        EditorSceneManager.SaveScene(lightingScene);
        EditorSceneManager.CloseScene(lightingScene, true);
        LightmapSettings.lightmapsMode = newLightmapMode;
    }
Exemple #19
0
    private void LevelSetup()
    {
        var Level = GameObject.Find("Level");
        var oldl  = Level.transform.Find("level");

        if (oldl != null)
        {
            DestroyImmediate(oldl.gameObject);
        }
        string path = EditorApplication.currentScene.Split('.')[0] + "/";

        path = path.Substring("Assets/".Length);
        Debug.Log("setup level: " + path);
        var nl = (GameObject)EditorUtility.InstantiatePrefab(GetAssets <GameObject>(path, "*.FBX").FirstOrDefault());

        nl.transform.parent        = Level.transform;
        nl.name                    = "level";
        Selection.activeGameObject = nl;
        SetupLevel();
        Inits(cspath);
        _TimerA.AddMethod(delegate
        {
            if (bake)
            {
                var old = RenderSettings.ambientLight;
                RenderSettings.ambientLight = Color.white * lfactor;
                var en = new Queue <LightShadows>();
                var q  = new Queue <float>();
                foreach (Light a in GameObject.FindObjectsOfType(typeof(Light)))
                {
                    q.Enqueue(a.intensity);
                    en.Enqueue(a.shadows);
                    if (a.type == LightType.Directional)
                    {
                        a.intensity = dfactor;
                    }
                    a.shadows = LightShadows.Soft;
                }
                Lightmapping.BakeAsync();
                foreach (Light a in GameObject.FindObjectsOfType(typeof(Light)))
                {
                    a.intensity = q.Dequeue();
                    a.shadows   = en.Dequeue();
                }
                RenderSettings.ambientLight = old;
            }
        });
    }
Exemple #20
0
    private static void Bake()
    {
        if (currentSceneIndex >= stageData.param.Count)
        {
            return;
        }

        EditorApplication.SaveScene();
        string path = GetBakeScenePath(currentSceneIndex, stageData);

        EditorApplication.OpenScene(path);
        Lightmapping.BakeAsync();
        currentSceneIndex++;

        Lightmapping.completed = Bake;
    }
Exemple #21
0
    private IEnumerator BuildLightingAsync(LightingScenarioData scenarioData)
    {
        Scene lightingScene = SceneManager.GetSceneByName(scenarioData.lightingSceneName);
        Scene geometryScene = SceneManager.GetSceneByName(scenarioData.geometrySceneName);

        Lightmapping.BakeAsync();
        while (Lightmapping.isRunning)
        {
            yield return(null);
        }
        EditorSceneManager.SaveScene(geometryScene);
        EditorSceneManager.SaveScene(lightingScene);
        StoreLightingData();
        EditorSceneManager.CloseScene(lightingScene, true);
        AssetDatabase.SaveAssets();
    }
        void DrawBakeButton()
        {
            GUILayout.FlexibleSpace();

            EditorGUILayout.BeginHorizontal();
            EditorGUI.BeginDisabledGroup(Lightmapping.isRunning);
            if (GUILayout.Button("Load All Scenes In Set", GUILayout.ExpandWidth(true)))
            {
                LoadScenesInBakingSet(GetCurrentBakingSet());
            }
            if (GUILayout.Button("Clear Loaded Scenes Data"))
            {
                Lightmapping.Clear();
            }
            EditorGUI.EndDisabledGroup();
            if (Lightmapping.isRunning)
            {
                if (GUILayout.Button("Cancel", GUILayout.ExpandWidth(true)))
                {
                    Lightmapping.Cancel();
                }
            }
            else
            {
                if (GUILayout.Button("Generate Lighting", "DropDownButton", GUILayout.ExpandWidth(true)))
                {
                    var menu = new GenericMenu();
                    menu.AddItem(new GUIContent("Bake the set"), false, () =>
                    {
                        ProbeGIBaking.isBakingOnlyActiveScene = false;
                        BakeLightingForSet(GetCurrentBakingSet());
                    });
                    menu.AddItem(new GUIContent("Bake loaded scenes"), false, () =>
                    {
                        ProbeGIBaking.isBakingOnlyActiveScene = false;
                        Lightmapping.BakeAsync();
                    });
                    menu.AddItem(new GUIContent("Bake active scene"), false, () =>
                    {
                        ProbeGIBaking.isBakingOnlyActiveScene = true;
                        Lightmapping.BakeAsync();
                    });
                    menu.ShowAsContext();
                }
            }
            EditorGUILayout.EndHorizontal();
        }
Exemple #23
0
 static EditorHotkeysTracker()
 {
     SceneView.onSceneGUIDelegate += view =>
     {
         var e = Event.current;
         if (e != null && e.keyCode != KeyCode.None)
         {
             if (e.keyCode == KeyCode.B && e.shift)
             {
                 if (!Lightmapping.isRunning)
                 {
                     Lightmapping.BakeAsync();
                 }
             }
             if (e.keyCode == KeyCode.C && e.shift)
             {
                 if (Lightmapping.isRunning)
                 {
                     Lightmapping.Cancel();
                 }
             }
             if (e.keyCode == KeyCode.E && e.shift)
             {
                 if (!Lightmapping.isRunning)
                 {
                     Lightmapping.Clear();
                 }
             }
             if (e.keyCode == KeyCode.H && e.shift)
             {
                 EditorPrefs.SetInt(PlayerSettings.productName + SceneManager.GetActiveScene().name + "FirstTime", 0);
             }
             if (e.keyCode == KeyCode.F && e.alt && e.control)
             {
                 EditorApplication.ExecuteMenuItem("GameObject/Move To View");
             }
             if (e.keyCode == KeyCode.F && e.shift)
             {
                 EditorApplication.ExecuteMenuItem("Window/Lighting/Settings");
             }
             if (e.keyCode == KeyCode.E && e.shift)
             {
                 EditorApplication.ExecuteMenuItem("Lighting/Lighting Box");
             }
         }
     };
 }
    public IEnumerator ActivateAO_DuringABake_DoesNotFallback()
    {
        EditorSceneManager.OpenScene("Assets/Tests/Editor/Tests_Unit_Editmode/BakeRestartScene.unity", OpenSceneMode.Single);
        yield return(null);

        LightingSettings lightingSettings = null;

        Lightmapping.TryGetLightingSettings(out lightingSettings);

        Assert.That(lightingSettings, !Is.EqualTo(null), "LightingSettings is null");

        lightingSettings.lightmapper = LightingSettings.Lightmapper.ProgressiveGPU;
        GameObject dirLightGO = GameObject.FindGameObjectsWithTag("TheLight")[0];

        dirLightGO.SetActive(false);
        lightingSettings.ao = false;

        Lightmapping.Clear();
        Lightmapping.BakeAsync();

        foreach (bool b in RunABake(0.2f))
        {
            yield return(null);
        }

        // Make sure it is still baking before we
        // switch the AO on and restart the bake
        Assert.IsTrue(Lightmapping.isBaking);

        // Switch AO on, cause the bake to restart
        lightingSettings.ao = true;

        foreach (bool b in RunABake(0.2f))
        {
            yield return(null);
        }

        // Check that baking is still running
        Assert.IsTrue(Lightmapping.isBaking);
        // Check that we did not fallback to CPULM
        Assert.AreEqual(lightingSettings.lightmapper, LightingSettings.Lightmapper.ProgressiveGPU);

        Lightmapping.Cancel();
        Lightmapping.Clear();
        Lightmapping.ClearLightingDataAsset();
    }
Exemple #25
0
 // Loop through scenes to bake and update on progress
 private void BakeNewScene()
 {
     if (sceneIndex < scenes.Length)
     {
         EditorSceneManager.OpenScene(scenePath[sceneIndex]);
         EditorUtility.UnloadUnusedAssetsImmediate();
         System.GC.Collect();
         timeStamp = System.DateTime.Now;
         Lightmapping.BakeAsync();
         UpdateBakeProgress();
         sceneIndex++;
     }
     else
     {
         DoneBaking("done");
     }
 }
    void OnGUI()
    {
        GUILayout.Label("Base Settings", EditorStyles.boldLabel);
        GUILayout.Label("", EditorStyles.boldLabel);
        obj = GameObject.Find("specularDayLight");
        obj = (GameObject)EditorGUI.ObjectField(new Rect(3, 24, position.width - 6, 20), "Light to Ignore", obj, typeof(GameObject), true);

        if (GUILayout.Button("Build Lighting"))
        {
            Debug.Log("build lighting, ignore: " + obj);
            obj.GetComponent <Light>().enabled = false;

            myBool = Lightmapping.BakeAsync();
            Lightmapping.completed += onFinishBake;
        }
        myBool = EditorGUILayout.Toggle("bakeAsync", myBool);
    }
    public static void ImportProbes()
    {
        try
        {
            EditorUtility.DisplayProgressBar("Importing external probe data", "Parsing data", 0);
            DoImportProbePositions();

            EditorUtility.DisplayProgressBar("Importing external probe data", "Dummy bake job", 0.25f);
            Lightmapping.bakeCompleted -= OnBakeCompleted;
            Lightmapping.bakeCompleted += OnBakeCompleted;
            Lightmapping.BakeAsync();
        }
        catch
        {
            Debug.LogError("Light probe import failed");
            EditorUtility.ClearProgressBar();
            throw;
        }
    }
    public override void OnInspectorGUI()
    {
        var holder = target as LightmapHolder;

        if (holder.renderers != null && holder.scales != null)
        {
            EditorGUILayout.LabelField($"{holder.renderers.Length} renderers in {holder.scales.Length} indices");
        }
        if (GUILayout.Button("Clear Lightmaps"))
        {
            ClearHolder(holder);

            Lightmapping.Clear();
        }
        if (Lightmapping.isRunning)
        {
            EditorGUILayout.LabelField("Baking...");
        }
        else
        {
            if (GUILayout.Button("Bake"))
            {
                ClearHolder(holder);
                LightmapEditorSettings.maxAtlasSize  = MAX_SIZE;
                LightmapEditorSettings.filteringMode = LightmapEditorSettings.FilterMode.Auto;
                LightmapEditorSettings.lightmapper   = LightmapEditorSettings.Lightmapper.ProgressiveGPU;

                Lightmapping.BakeAsync();
            }
            if (GUILayout.Button("Combine Lightmaps"))
            {
                ClearHolder(holder);
                try
                {
                    Combine(holder);
                }
                finally
                {
                    EditorUtility.ClearProgressBar();
                }
            }
        }
    }
Exemple #29
0
        public static IEnumerator BakeCheckAndRun()
        {
            EditorUtility.DisplayProgressBar("Bake", "Baking...", 0);
            bool bakeFlag = Lightmapping.BakeAsync();

            if (!bakeFlag)
            {
                EditorUtility.DisplayDialog("Error", LocalizedMessage.Get("Main.Baker.LightBakeFailed"), "OK");
            }

            while (Lightmapping.isRunning)
            {
                EditorUtility.DisplayProgressBar("Bake", "Baking...", Lightmapping.buildProgress);
                yield return(null);
            }

            EditorUtility.ClearProgressBar();

            yield return(bakeFlag);
        }
Exemple #30
0
        public static void Start()
        {
            Debug.ClearDeveloperConsole();

            UpdateLightSettings( );

            // 1. Prepare objects for bake

            // Fetch PrefabVaker components from current active scene
            EditorUtils.GetAllPrefabs( ).ForEach(x => {
                // Set all nested object as static for bake
                EditorUtils.LockForBake(x.gameObject);
            });

            // 2. Display progress dialog and await for bake complete in `BakeCompelte()`
            BakeStart( );

            // 3. Start baking
            Lightmapping.BakeAsync( );
        }