public static bool IsAtlased(this PlaytimePainter p)
        {
            if (p == null)
            {
                return(false);
            }
            var mat = p.GetMaterial(false);

            if (mat == null)
            {
                return(false);
            }
            return(p.GetMaterial(false).IsAtlased(p.MaterialTexturePropertyName));
        }
        public override bool BrushConfigPEGI()
        {
            PlaytimePainter p = PlaytimePainter.inspectedPainter;

            bool changed = false;

            if (p.IsAtlased())
            {
                var m = p.GetMaterial(false);
                if (p.IsOriginalShader)
                {
                    if (m.HasProperty(PainterDataAndConfig.atlasedTexturesInARow))
                    {
                        atlasRows = m.GetInt(PainterDataAndConfig.atlasedTexturesInARow);
                    }
                }

                ("Atlased Texture " + atlasRows + "*" + atlasRows).write("Shader has _ATLASED define");
                if ("Undo".Click(40).nl())
                {
                    m.DisableKeyword(PainterDataAndConfig.UV_ATLASED);
                }

                var id = p.ImgData;

                if (id.TargetIsRenderTexture())
                {
                    pegi.writeOneTimeHint("Watch out, Render Texture Brush can change neighboring textures on the Atlas.", "rtOnAtlas");
                }

                if (!id.TargetIsTexture2D())
                {
                    pegi.writeWarning("Render Texture painting does not yet support Atlas Editing");
                    pegi.newLine();
                }
            }
            return(changed);
        }
Beispiel #3
0
        /*
         * public void MirrorVerticlesAgainsThePlane(Vector3 ptdPos)
         * {
         *
         *  Vector3 Mirror = GridNavigator.inst().getGridPerpendicularVector();//new Vector3(0,0,0);
         *
         *  int Count = vertices.Count;
         *  for (int i = 0; i < Count; i++)
         *  {
         *      vertexpointDta vp;
         *      vertexpointDta newvp;
         *      Vector3 diff;
         *
         *      vp = vertices[i];
         *      diff = 2 * (Vector3.Scale(ptdPos - vp.localPos, Mirror));
         *
         *      newvp = vp.DeepCopy();
         *      newvp.localPos += diff;
         *
         *
         *      vertices.Add(newvp);
         *
         *  }
         *
         *
         *  Count = triangles.Count;
         *
         *  for (int i = 0; i < Count; i++)
         *      triangles.Add(triangles[i].NewForCopiedVerticles());
         *
         *  for (int i = Count; i < triangles.Count; i++)
         *      triangles[i].InvertNormal();
         *  Debug.Log("Dirty");
         *  dirty = true;
         *
         * }
         */



        public void Edit(PlaytimePainter pntr)
        {
            //Temporary
            submeshCount = 1;
            if (pntr.SavedEditableMesh != null)
            {
                Decode(pntr.SavedEditableMesh);
                if (triangles.Count == 0)
                {
                    BreakMesh(pntr.meshFilter.sharedMesh);
                }
            }
            else
            {
                BreakMesh(pntr.meshFilter.sharedMesh);
                pntr.selectedMeshProfile = pntr.GetMaterial(false).GetMeshProfileByTag();
            }

            // Temporary
            while (baseVertex.Count < submeshCount)
            {
                baseVertex.Add(0);
            }
        }
        public void ConvertToAtlased(PlaytimePainter painter)
        {
#if UNITY_EDITOR
            if (AtlasedMaterial == null)
            {
                AtlasedMaterial = painter.InstantiateMaterial(true);
            }

            painter.SetOriginalShaderOnThis();

            painter.UpdateOrSetTexTarget(TexTarget.Texture2D);

            Material      mat     = painter.GetMaterial(false);
            List <string> tfields = mat.GetTextures();

            int index = 0;
            List <FieldAtlas> passedFields   = new List <FieldAtlas>();
            List <Texture2D>  passedTextures = new List <Texture2D>();
            List <Color>      passedColors   = new List <Color>();

            foreach (var f in fields)
            {
                if ((f.enabled) && (f.AtlasCreator != null) && (tfields.Contains(originalTextures[f.originField])))
                {
                    string original = originalTextures[f.originField];

                    Texture tex = mat.GetTexture(original);

                    Texture2D texture = null;

                    if (tex == null)
                    {
                        var note = painter.name + " no " + original + " texture. Using Color.";
#if PEGI
                        note.showNotification();
#endif
                        Debug.Log(note);
                    }
                    else
                    {
                        if (tex.GetType() != typeof(Texture2D))
                        {
                            Debug.Log("Not a Texture 2D: " + original);
                            return;
                        }

                        texture = (Texture2D)tex;
                    }

                    var aTexes = f.AtlasCreator.textures;

                    bool added = false;

                    for (int i = index; i < aTexes.Count; i++)
                    {
                        if ((aTexes[i] == null) || (!aTexes[i].used) || (aTexes[i].texture == texture))
                        {
                            index = i;
                            passedFields.Add(f);
                            passedTextures.Add(texture);
                            passedColors.Add(f.col);
                            added = true;
                            break;
                        }
                    }

                    if (!added)
                    {
                        Debug.Log("Could not find a place for " + original);
                        return;
                    }
                }
            }

            if (passedFields.Count > 0)
            {
                bool firstAtlasing = false;

                var atlPlug = painter.GetPlugin <TileableAtlasingPainterPlugin>();

                if (atlPlug.preAtlasingMaterials == null)
                {
                    atlPlug.preAtlasingMaterials = painter.GetMaterials();
                    atlPlug.preAtlasingMesh      = painter.GetMesh();
                    firstAtlasing = true;
                }

                var MainField = passedFields[0];

                atlPlug.atlasRows = MainField.AtlasCreator.Row;

                Vector2 tyling = mat.GetTextureScale(originalTextures[MainField.originField]);
                Vector2 offset = mat.GetTextureOffset(originalTextures[MainField.originField]);

                for (int i = 0; i < passedFields.Count; i++)
                {// var f in passedFields){
                    var f  = passedFields[i];
                    var ac = f.AtlasCreator;

                    ac.textures[index] = new AtlasTextureField(passedTextures[i], passedColors[i]);

                    ac.AddTargets(f, originalTextures[f.originField]);
                    ac.ReconstructAsset();
                    AtlasedMaterial.SetTexture(f.atlasedField, ac.a_texture);
                }

                MeshManager.Inst.EditMesh(painter, true);

                if (firstAtlasing)
                {
                    atlPlug.preAtlasingSavedMesh = MeshManager.Inst.edMesh.Encode().ToString();
                }

                painter.selectedMeshProfile = matAtlasProfile;

                if ((tyling != Vector2.one) || (offset != Vector2.zero))
                {
                    MeshManager.Inst.edMesh.TileAndOffsetUVs(offset, tyling, 0);
                    Debug.Log("offsetting " + offset + " tyling " + tyling);
                }

                TriangleAtlasTool.Inst.SetAllTrianglesTextureTo(index, 0, painter.selectedSubmesh);
                MeshManager.Inst.Redraw();
                MeshManager.Inst.DisconnectMesh();

                AtlasedMaterial.SetFloat(PainterDataAndConfig.atlasedTexturesInARow, atlPlug.atlasRows);
                painter.Material = AtlasedMaterial;

                if (firstAtlasing)
                {
                    var m = painter.GetMesh();
                    m.name = m.name + "_Atlased_" + index;
                }
                //painter.getMaterial(false).SetTextureOffset(1,Vector2.zero);

                AtlasedMaterial.EnableKeyword(PainterDataAndConfig.UV_ATLASED);
            }
#endif
        }
 public static bool IsProjected(this PlaytimePainter p)
 {
     return(p.GetMaterial(false).IsProjected());
 }