Exemple #1
0
 public void RemoveHeightMap()
 {
     if (heightMap != null)
     {
         GUtilities.DestroyObject(heightMap);
     }
 }
        private void OnGUISetShader()
        {
            DrawMaterialSettings();

            if (GUILayout.Button("Set Shader"))
            {
                RecordSetShaderAnalytics();
                RecordShadingAnalytics();
                Material mat = GGriffinSettings.Instance.WizardSettings.GetClonedMaterial();
                if (BulkSetShader)
                {
                    GCommon.ForEachTerrain(
                        BulkSetShaderGroupId,
                        (t) =>
                    {
                        if (t.TerrainData == null)
                        {
                            return;
                        }
                        t.TerrainData.Shading.MaterialToRender.shader = mat.shader;
                        t.TerrainData.Shading.UpdateMaterials();
                        t.TerrainData.SetDirty(GTerrainData.DirtyFlags.Shading);
                    });
                }
                else
                {
                    terrainData.Shading.MaterialToRender.shader = mat.shader;
                    terrainData.Shading.UpdateMaterials();
                }
                GUtilities.DestroyObject(mat);
                Close();
            }
        }
Exemple #3
0
 public void RemoveMetallicMap()
 {
     if (metallicMap != null)
     {
         GUtilities.DestroyObject(metallicMap);
     }
 }
Exemple #4
0
 public void RemoveMaskMap()
 {
     if (maskMap != null)
     {
         GUtilities.DestroyObject(maskMap);
     }
 }
Exemple #5
0
 public void RemoveAlbedoMap()
 {
     if (albedoMap != null)
     {
         GUtilities.DestroyObject(albedoMap);
     }
 }
Exemple #6
0
 public void CleanUp()
 {
     if (geometry != null && geometry.subDivisionMap != null)
     {
         GUtilities.DestroyObject(geometry.subDivisionMap);
     }
 }
Exemple #7
0
        public static void FillTexture(RenderTexture rt, Color c)
        {
            Texture2D tex = new Texture2D(1, 1, TextureFormat.ARGB32, false);

            tex.SetPixel(0, 0, c);
            tex.Apply();
            CopyToRT(tex, rt);
            GUtilities.DestroyObject(tex);
        }
Exemple #8
0
        public static void CopyTexture(Texture2D src, Texture2D des)
        {
            RenderTexture rt = new RenderTexture(des.width, des.height, 0, RenderTextureFormat.ARGBFloat, RenderTextureReadWrite.Linear);

            CopyToRT(src, rt);
            CopyFromRT(des, rt);
            rt.Release();
            GUtilities.DestroyObject(rt);
        }
        public void UpdateBillboardMesh(BillboardAsset billboard)
        {
            if (BillboardMeshes.ContainsKey(billboard) && BillboardMeshes[billboard] != null)
            {
                GUtilities.DestroyObject(BillboardMeshes[billboard]);
                BillboardMeshes.Remove(billboard);
            }

            Mesh m = CreateBillboardMesh(billboard);

            BillboardMeshes.Add(billboard, m);
        }
Exemple #10
0
 private void OnDisable()
 {
     if (Terrain != null)
     {
         Terrain.PreProcessHeightMap  -= OnPreProcessHeightMap;
         Terrain.PostProcessHeightMap -= OnPostProcessHeightMap;
     }
     if (heightMapBackup != null)
     {
         GUtilities.DestroyObject(heightMapBackup);
     }
 }
 public void DeleteMesh(string key)
 {
     if (GeneratedMeshes.ContainsKey(key))
     {
         Mesh m = GeneratedMeshes[key];
         if (m != null)
         {
             GUtilities.DestroyObject(m);
         }
         GeneratedMeshes.Remove(key);
         GCommon.SetDirty(this);
     }
 }
Exemple #12
0
 public void RemoveSplatControlMaps()
 {
     if (splatControls != null)
     {
         for (int i = 0; i < splatControls.Length; ++i)
         {
             if (splatControls[i] != null)
             {
                 GUtilities.DestroyObject(splatControls[i]);
             }
         }
     }
 }
 public void DeleteMesh(Vector3Int key)
 {
     if (Meshes.ContainsKey(key))
     {
         Mesh m = Meshes[key];
         if (m != null)
         {
             GUtilities.DestroyObject(m);
         }
         Meshes.Remove(key);
         GCommon.SetDirty(this);
     }
 }
        private void Export()
        {
            RenderTexture rt = new RenderTexture(resolution, resolution, 24, RenderTextureFormat.ARGB32);

            GCommon.FillTexture(rt, Color.clear);

            Vector2[] uv        = targetMesh.uv;
            int[]     tris      = targetMesh.triangles;
            int       trisCount = tris.Length / 3;

            CreateLineMaterial();
            // Apply the line material
            lineMaterial.SetPass(0);

            RenderTexture.active = rt;
            GL.PushMatrix();
            GL.LoadOrtho();
            // Draw lines
            GL.Begin(GL.LINES);
            for (int i = 0; i < trisCount; ++i)
            {
                GL.Color(Color.black);
                Vector2 p0 = uv[tris[i * 3 + 0]];
                Vector2 p1 = uv[tris[i * 3 + 1]];
                Vector2 p2 = uv[tris[i * 3 + 2]];

                GL.Vertex3(p0.x, p0.y, 0);
                GL.Vertex3(p1.x, p1.y, 0);

                GL.Vertex3(p1.x, p1.y, 0);
                GL.Vertex3(p2.x, p2.y, 0);

                GL.Vertex3(p2.x, p2.y, 0);
                GL.Vertex3(p0.x, p0.y, 0);
            }
            GL.End();
            GL.PopMatrix();

            Texture2D tex = new Texture2D(resolution, resolution, TextureFormat.ARGB32, false);

            tex.ReadPixels(new Rect(0, 0, resolution, resolution), 0, 0);
            tex.Apply();

            byte[] data = tex.EncodeToPNG();
            File.WriteAllBytes(string.Format("Assets/{0}_UV_{1}.png", targetMesh.name, resolution), data);
            GUtilities.DestroyObject(tex);

            RenderTexture.active = null;
            rt.Release();
            GUtilities.DestroyObject(rt);
        }
Exemple #15
0
 private void InitRtSize(Texture src, ref RenderTexture targetRt)
 {
     if (targetRt == null)
     {
         targetRt = new RenderTexture(src.width, src.height, 24, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear);
     }
     if (targetRt.width != src.width ||
         targetRt.height != src.height)
     {
         targetRt.Release();
         GUtilities.DestroyObject(targetRt);
         targetRt = new RenderTexture(src.width, src.height, 24, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear);
     }
 }
Exemple #16
0
 internal void CleanUpNonSerializedMeshes()
 {
     if (nonSerializedMeshes != null)
     {
         for (int i = 0; i < nonSerializedMeshes.Length; ++i)
         {
             Mesh m = nonSerializedMeshes[i];
             if (m != null)
             {
                 GUtilities.DestroyObject(m);
             }
         }
     }
 }
Exemple #17
0
 public void RemoveGradientLookupMaps()
 {
     if (colorByHeightMap != null)
     {
         GUtilities.DestroyObject(colorByHeightMap);
     }
     if (colorByNormalMap != null)
     {
         GUtilities.DestroyObject(colorByNormalMap);
     }
     if (colorBlendMap != null)
     {
         GUtilities.DestroyObject(colorBlendMap);
     }
 }
 public void SetMesh(string key, Mesh mesh)
 {
     if (GeneratedMeshes.ContainsKey(key))
     {
         Mesh oldMesh = GeneratedMeshes[key];
         if (oldMesh != null)
         {
             GUtilities.DestroyObject(oldMesh);
         }
         GeneratedMeshes.Remove(key);
     }
     GCommon.TryAddObjectToAsset(mesh, this);
     GeneratedMeshes.Add(key, mesh);
     GCommon.SetDirty(this);
 }
        public void ConvertSplatsToAlbedo()
        {
            if (Splats == null)
            {
                return;
            }
            RenderTexture albedoRt = new RenderTexture(AlbedoMapResolution, AlbedoMapResolution, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear);
            Material      mat      = GInternalMaterials.SplatsToAlbedoMaterial;

            for (int i = 0; i < SplatControlMapCount; ++i)
            {
                Texture2D controlMap = GetSplatControl(i);
                mat.SetTexture("_Control0", controlMap);
                for (int channel = 0; channel < 4; ++channel)
                {
                    int prototypeIndex = i * 4 + channel;
                    if (prototypeIndex < Splats.Prototypes.Count)
                    {
                        GSplatPrototype p = Splats.Prototypes[prototypeIndex];
                        mat.SetTexture("_Splat" + channel, p.Texture);
                        Vector2 terrainSize  = new Vector2(TerrainData.Geometry.Width, TerrainData.Geometry.Length);
                        Vector2 textureScale = new Vector2(
                            p.TileSize.x != 0 ? terrainSize.x / p.TileSize.x : 0,
                            p.TileSize.y != 0 ? terrainSize.y / p.TileSize.y : 0);
                        Vector2 textureOffset = new Vector2(
                            p.TileOffset.x != 0 ? terrainSize.x / p.TileOffset.x : 0,
                            p.TileOffset.y != 0 ? terrainSize.y / p.TileOffset.y : 0);
                        mat.SetTextureScale("_Splat" + channel, textureScale);
                        mat.SetTextureOffset("_Splat" + channel, textureOffset);
                    }
                    else
                    {
                        mat.SetTexture("_Splat" + channel, null);
                        mat.SetTextureScale("_Splat" + channel, Vector2.zero);
                        mat.SetTextureOffset("_Splat" + channel, Vector2.zero);
                    }
                }

                GCommon.DrawQuad(albedoRt, GCommon.FullRectUvPoints, mat, 0);
            }

            GCommon.CopyFromRT(AlbedoMap, albedoRt);
            albedoRt.Release();
            GUtilities.DestroyObject(albedoRt);
        }
        public static void DeleteTextures()
        {
            Object o = Selection.activeObject;

            if (o is GShading)
            {
                GShading shading = o as GShading;
                GUtilities.DestroyObject(shading.AlbedoMap);
                GUtilities.DestroyObject(shading.MetallicMap);
                Texture2D[] controls = shading.SplatControls;
                for (int i = 0; i < controls.Length; ++i)
                {
                    if (controls[i] != null)
                    {
                        GUtilities.DestroyObject(controls[i]);
                    }
                }
            }
        }
Exemple #21
0
        private void CreateStaticObstacles(GStylizedTerrain t)
        {
            if (t.TerrainData == null)
            {
                return;
            }
            if (t.TerrainData.Foliage.Trees == null)
            {
                return;
            }
            if (t.TerrainData.Foliage.Trees.Prototypes.Count == 0)
            {
                return;
            }

#if UNITY_EDITOR
            string title = "Creating static obstacles";
            string info  = t.name;
            GCommonGUI.CancelableProgressBar(title, info, 0);
#endif

            Vector3 terrainSize = new Vector3(
                t.TerrainData.Geometry.Width,
                t.TerrainData.Geometry.Height,
                t.TerrainData.Geometry.Length);

            Transform             root       = GUtilities.GetChildrenWithName(transform, string.Format("{0}_{1}", t.name, t.GetInstanceID()));
            List <GTreePrototype> prototypes = t.TerrainData.Foliage.Trees.Prototypes;

            GameObject[] templates = new GameObject[prototypes.Count];
            for (int i = 0; i < prototypes.Count; ++i)
            {
                if (!prototypes[i].IsValid)
                {
                    continue;
                }
                GameObject  template   = Instantiate(prototypes[i].Prefab) as GameObject;
                Component[] components = template.GetComponentsInChildren <Component>();
                for (int j = 0; j < components.Length; ++j)
                {
                    if (components[j] is Collider)
                    {
                        GUtilities.DestroyObject(components[j]);
                    }
                    if (components[j] is MeshRenderer)
                    {
                        MeshRenderer mr = components[j] as MeshRenderer;
                        mr.sharedMaterials   = new Material[] { GInternalMaterials.NavHelperDummyGameObjectMaterial };
                        mr.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
                        mr.receiveShadows    = false;
                    }
                }
#if UNITY_EDITOR
                GameObjectUtility.SetStaticEditorFlags(template, StaticEditorFlags.NavigationStatic);
#endif
                template.name = prototypes[i].Prefab.name;
                templates[i]  = template;
            }

            List <GTreeInstance> instances = t.TerrainData.Foliage.TreeInstances;
            for (int i = 0; i < instances.Count; ++i)
            {
#if UNITY_EDITOR
                GCommonGUI.CancelableProgressBar(title, info, i * 1.0f / instances.Count);
#endif
                GTreeInstance tree = instances[i];
                if (templates[tree.PrototypeIndex] == null)
                {
                    continue;
                }

                GameObject g = Instantiate(templates[tree.PrototypeIndex]) as GameObject;
                g.transform.parent = root;

                Vector3 localPos = new Vector3(
                    tree.Position.x * terrainSize.x,
                    tree.Position.y * terrainSize.y,
                    tree.Position.z * terrainSize.z);
                Vector3 worldPos = t.transform.TransformPoint(localPos);
                g.transform.position   = worldPos;
                g.transform.rotation   = tree.Rotation;
                g.transform.localScale = tree.Scale;
                g.name = templates[tree.PrototypeIndex].name;
            }

            for (int i = 0; i < templates.Length; ++i)
            {
                GUtilities.DestroyGameobject(templates[i]);
            }
#if UNITY_EDITOR
            GCommonGUI.ClearProgressBar();
#endif
        }