public override bool UpdateTilingFromMaterial(ShaderProperty.TextureValue fieldName, PlaytimePainter painter)
        {
            if (!painter.terrain)
            {
                return(false);
            }

            if (!fieldName.HasUsageTag(PainterDataAndConfig.TERRAIN_SPLAT_DIFFUSE))
            {
                return(false);
            }

            var no = fieldName.NameForDisplayPEGI()[0].CharToInt();

            var ls = painter.terrain.terrainData.terrainLayers;


            if (ls.Length <= no)
            {
                return(true);
            }

            var l = ls.TryGet(no);

            var terrainData = painter.terrain.terrainData;
            var width       = terrainData.size.x / l.tileSize.x;
            var length      = terrainData.size.z / l.tileSize.y;

            var id = painter.TexMeta;

            id.tiling = new Vector2(width, length);
            id.offset = l.tileOffset;

            return(true);
        }
        public override bool SetTextureOnMaterial(ShaderProperty.TextureValue field, TextureMeta id)
        {
            var tex = id.CurrentTexture();

            if (!painter.terrain)
            {
                return(false);
            }

            if (!field.HasUsageTag(PainterShaderVariables.TERRAIN_CONTROL_TEXTURE))
            {
                return(false);
            }

            var no = field.NameForDisplayPEGI()[0].CharToInt();

            if (no == 0)
            {
                PainterShaderVariables.TerrainControlMain.GlobalValue = tex;
            }

            painter.terrain.terrainData.alphamapTextures[no] = id.texture2D;

            return(true);
        }
 public override bool GetTexture(ShaderProperty.TextureValue field, ref Texture tex)
 {
     if (!painter.terrain || !field.HasUsageTag(PainterShaderVariables.TERRAIN_CONTROL_TEXTURE))
     {
         return(false);
     }
     tex = painter.terrain.terrainData.alphamapTextures[field.NameForDisplayPEGI()[0].CharToInt()];
     return(true);
 }
        public static bool IsGlobalVolume(this ShaderProperty.TextureValue field)
        {
            string name = field.NameForDisplayPEGI();

            if (name.Contains(PainterDataAndConfig.GlobalPropertyPrefix) &&
                name.Contains(VolumePaintingModule.VolumeTextureTag))
            {
                return(true);
            }
            return(false);
        }
Exemple #5
0
        public static bool edit(this Material mat, ShaderProperty.TextureValue property, string name = null)
        {
            var val = mat.Get(property);

            if (name.IsNullOrEmpty())
            {
                name = property.NameForDisplayPEGI();
            }

            if (name.edit(name.Length * pegi.letterSizeInPixels, ref val))
            {
                mat.Set(property, val);
                return(true);
            }

            return(false);
        }
        public override bool GetTexture(ShaderProperty.TextureValue field, ref Texture tex, PlaytimePainter painter)
        {
            if (!painter.terrain || (!field.HasUsageTag(PainterDataAndConfig.TERRAIN_SPLAT_DIFFUSE)))
            {
                return(false);
            }
            var no = field.NameForDisplayPEGI()[0].CharToInt();

            var l = painter.terrain.terrainData.terrainLayers;

            if (l.Length > no)
            {
                tex = l[no].diffuseTexture;
            }

            return(true);
        }
        public override bool UpdateTilingFromMaterial(ShaderProperty.TextureValue fieldName)
        {
            if (!painter.terrain)
            {
                return(false);
            }

            if (!fieldName.HasUsageTag(PainterShaderVariables.TERRAIN_SPLAT_DIFFUSE))
            {
                return(false);
            }

            var no = fieldName.NameForDisplayPEGI()[0].CharToInt();

            var id = painter.TexMeta;

            var terrainData = painter.terrain.terrainData;

#if UNITY_2019_1_OR_NEWER
            var ls = painter.terrain.terrainData.terrainLayers;


            if (ls.Length <= no)
            {
                return(true);
            }

            var l = ls.TryGet(no);
#else
            var l = parentComponent.terrain.terrainData.splatPrototypes.TryGet(no);
            if (l == null)
            {
                return(true);
            }
#endif

            var width  = terrainData.size.x / l.tileSize.x;
            var length = terrainData.size.z / l.tileSize.y;


            id.tiling = new Vector2(width, length);
            id.offset = l.tileOffset;

            return(true);
        }
        public override bool GetTexture(ShaderProperty.TextureValue field, ref Texture tex)
        {
            if (!painter.terrain || (!field.HasUsageTag(PainterShaderVariables.TERRAIN_SPLAT_DIFFUSE)))
            {
                return(false);
            }
            var no = field.NameForDisplayPEGI()[0].CharToInt();

#if UNITY_2019_1_OR_NEWER
            var l = painter.terrain.terrainData.terrainLayers;

            if (l.Length > no)
            {
                tex = l[no].diffuseTexture;
            }
#else
            tex = parentComponent.terrain.GetSplashPrototypeTexture(no);
#endif

            return(true);
        }
        public override bool SetTextureOnMaterial(ShaderProperty.TextureValue field, TextureMeta id)
        {
            var tex = id.CurrentTexture();

            if (!painter.terrain)
            {
                return(false);
            }
            if (!field.HasUsageTag(PainterShaderVariables.TERRAIN_SPLAT_DIFFUSE))
            {
                return(false);
            }
            var no = field.NameForDisplayPEGI()[0].CharToInt();

            painter.terrain.SetSplashPrototypeTexture(id.texture2D, no);
            if (tex.GetType() != typeof(Texture2D))
            {
                Debug.Log("Can only use Texture2D for Splat Prototypes. If using regular terrain may not see changes.");
            }
            else
            {
#if UNITY_EDITOR
                var texImporter = ((Texture2D)tex).GetTextureImporter();
                if (texImporter == null)
                {
                    return(true);
                }
                var needReimport = texImporter.WasClamped();
                needReimport |= texImporter.HadNoMipmaps();

                if (needReimport)
                {
                    texImporter.SaveAndReimport();
                }
#endif
            }
            return(true);
        }
Exemple #10
0
        public virtual bool Inspect()
        {
            "Works with PaintWithoutComponent script. This lets you configure how painting will be received".fullWindowDocumentationClickOpen("About Painting Receiver");

            var changes = false;

            if (icon.Refresh.Click("Find Components automatically"))
            {
                Refresh();
            }

            if ("Renderer GetBrushType:".editEnum(90, ref type).nl())
            {
                switch (type)
                {
                case RendererType.Skinned when(!skinnedMeshRenderer):
                    skinnedMeshRenderer = GetComponentInChildren <SkinnedMeshRenderer>();

                    break;

                case RendererType.Regular when(!meshFilter):
                    meshFilter = GetComponent <MeshFilter>();

                    meshRenderer = GetComponent <MeshRenderer>();
                    break;
                }
            }

            switch (type)
            {
            case RendererType.Skinned:
                "   Skinned Mesh Renderer".edit(90, ref skinnedMeshRenderer).nl(ref changes);
                break;

            case RendererType.Regular:
                "   Mesh Filter".edit(90, ref meshFilter).nl(ref changes);
                "   Renderer".edit(90, ref meshRenderer).nl(ref changes);
                break;
            }

            var r = Renderer;

            if ((r && r.sharedMaterials.Length > 1) || materialIndex != 0)
            {
                "   Material".select_Index(80, ref materialIndex, r.sharedMaterials).nl();
            }

            if (Material)
            {
                var lst = Material.MyGetTextureProperties();

                if ("   Property".select(80, ref _textureProperty, lst).nl())
                {
                    TexturePropertyName = _textureProperty.NameForDisplayPEGI();
                }
            }

            if (gameObject.isStatic && !originalMesh)
            {
                "For STATIC Game Objects original mesh is needed:".writeHint();

                pegi.nl();

                if (meshFilter && icon.Search.Click("Find mesh"))
                {
                    originalMesh = meshFilter.sharedMesh;
                }
            }

            if (gameObject.isStatic)
            {
                "  Original Mesh".edit("Static objects use Combined mesh, so original one will be needed for painting", 50, ref originalMesh).nl();
            }



            if ("  Use second texture coordinates".toggleIcon("If shader uses texcoord2 (Baked Light) to display damage, turn this ON.", ref useTexcoord2).nl() && texture)
            {
                texture.GetTextureData().useTexCoord2 = useTexcoord2;
            }

            if (Material)
            {
                if (!Material.Has(TextureId) && !Material.mainTexture)
                {
                    "No Material Property Selected and no MainTex on Material".nl();
                }
                else
                {
                    if (texture)
                    {
                        var t2D = texture as Texture2D;

                        if (t2D)
                        {
                            icon.Done.write();
                            "CPU brush will work if object has MeshCollider".nl();



                            if (originalTexture)
                            {
                                var ot2D = originalTexture as Texture2D;

                                if (ot2D)
                                {
                                    if ((ot2D.width == t2D.width) && (ot2D.height == t2D.height))
                                    {
                                        if (("Undo Changes".Click()).nl())
                                        {
                                            Restore();
                                        }
                                    }
                                    else
                                    {
                                        "Original and edited texture are not of the same size".nl();
                                    }
                                }
                                else
                                {
                                    "Original Texture is not a Texture 2D".nl();
                                }
                            }
                        }
                        else
                        {
                            if (Renderer)
                            {
                                icon.Done.write();
                                "Will paint if object has any collider".nl();
                                if (skinnedMeshRenderer)
                                {
                                    "Colliders should be placed close to actual mesh".nl();
                                    "Otherwise brush size may be too small to reach the mesh".nl();
                                }
                            }
                            else
                            {
                                "Render Texture Painting needs Skinned Mesh or Mesh Filter to work".nl();
                            }

                            if ((originalTexture) && ("Undo Changes".Click().nl()))
                            {
                                Restore();
                            }
                        }
                    }
                    else
                    {
                        var rtm = TexturesPool.inst;

                        if (rtm)
                        {
                            "Render Texture Pool will be used to get texture".nl();
                            if (!Renderer)
                            {
                                "! Renderer needs to be Assigned.".nl();
                            }
                            else
                            {
                                icon.Done.write();
                                "COMPONENT SET UP CORRECTLY".write();
                                if (fromRtManager && "Restore".Click())
                                {
                                    Restore();
                                }
                                pegi.nl();
                            }
                        }
                        else
                        {
                            "No Render Texture Pool found".write();
                            if ("Create".Click().nl())
                            {
                                (TexturesPool.Inst.gameObject.name + " created").showNotificationIn3D_Views();
                            }
                        }
                    }
                }
            }
            else
            {
                "No material found".nl();
            }

            if ("Advanced".foldout(ref _showOptional).nl())
            {
                if (texture || !MatTex)
                {
                    "Start Texture:".edit("Copy of this texture will be modified.", 110, ref originalTexture).nl(ref changes);
                }

                "Target Texture".edit("If not using Render Textures Pool", 120, ref texture);
                if (Renderer && Material && "Find".Click().nl())
                {
                    texture = MatTex;
                }

                if (!texture || texture.GetType() == typeof(RenderTexture))
                {
                    "Mesh UV Offset".edit("Some Meshes have UV coordinates with displacement for some reason. " +
                                          "If your object doesn't use a mesh collider to provide a UV offset, this will be used.", 80, ref meshUvOffset).nl();
                    if (Mesh && "Offset from Mesh".Click().nl())
                    {
                        var firstVertInSubmeshIndex = Mesh.GetTriangles(materialIndex)[0];
                        meshUvOffset = useTexcoord2 ? Mesh.uv2[firstVertInSubmeshIndex] : Mesh.uv[firstVertInSubmeshIndex];

                        meshUvOffset = new Vector2((int)meshUvOffset.x, (int)meshUvOffset.y);

                        ("Mesh Offset is " + meshUvOffset.ToString()).showNotificationIn3D_Views();
                    }
                }
            }


            return(changes);
        }
 public static bool IsAtlased(this Material mat, ShaderProperty.TextureValue property) => mat.IsAtlased() && property.NameForDisplayPEGI().Contains(PainterDataAndConfig.isAtlasableDisaplyNameTag);