Esempio n. 1
0
        protected override void OnInspector()
        {
            if (P3dMaterial.CachedMaterials.Contains(Target) == false && P3dHelper.IsAsset(Target) == true)
            {
                P3dMaterial.CachedMaterials.Add(Target);
            }

            Draw("category");
            Draw("icon");
            DrawTextures();

            EditorGUILayout.Separator();

            var prefabIsOpen = PrefabStageUtility.GetPrefabStage(Target.gameObject) != null;

            if (prefabIsOpen == false)
            {
                EditorGUILayout.HelpBox("Open this material prefab to build the materials or icons.", MessageType.Info);
            }

            EditorGUI.BeginDisabledGroup(prefabIsOpen == false);
            EditorGUILayout.LabelField("Material Builder", EditorStyles.boldLabel);

            DrawMaterialBuilder();

            EditorGUILayout.Separator();

            EditorGUILayout.LabelField("Icon Builder", EditorStyles.boldLabel);

            DrawIconBuilder();
            EditorGUI.EndDisabledGroup();
        }
Esempio n. 2
0
        public void Generate()
        {
            Generate(source, ref mesh, channel, threshold, border);
#if UNITY_EDITOR
            if (P3dHelper.IsAsset(this) == true)
            {
                var assets = AssetDatabase.LoadAllAssetsAtPath(AssetDatabase.GetAssetPath(this));

                for (var i = 0; i < assets.Length; i++)
                {
                    var assetMesh = assets[i] as Mesh;

                    if (assetMesh != null && assetMesh != mesh)
                    {
                        DestroyImmediate(assetMesh, true);
                    }
                }

                if (P3dHelper.IsAsset(mesh) == false)
                {
                    AssetDatabase.AddObjectToAsset(mesh, this);
                }
            }
#endif
#if UNITY_EDITOR
            if (P3dHelper.IsAsset(this) == true)
            {
                P3dHelper.ReimportAsset(this);
            }
#endif
        }
Esempio n. 3
0
        protected override void OnInspector()
        {
            TARGET tgt; TARGET[] tgts; GetTargets(out tgt, out tgts);

            if (P3dMaterial.CachedMaterials.Contains(tgt) == false && P3dHelper.IsAsset(tgt) == true)
            {
                P3dMaterial.CachedMaterials.Add(tgt);
            }

            Draw("category");
            Draw("icon");
            DrawTextures();

            Separator();

            var prefabIsOpen = PrefabStageUtility.GetPrefabStage(tgt.gameObject) != null;

            if (prefabIsOpen == false)
            {
                Info("Open this material prefab to build the materials or icons.");
            }

            BeginDisabled(prefabIsOpen == false);
            EditorGUILayout.LabelField("Material Builder", EditorStyles.boldLabel);

            DrawMaterialBuilder(tgt);

            Separator();

            EditorGUILayout.LabelField("Icon Builder", EditorStyles.boldLabel);

            DrawIconBuilder(tgt);
            EndDisabled();
        }
Esempio n. 4
0
        protected override void OnInspector()
        {
            if (P3dTool.CachedTools.Contains(Target) == false && P3dHelper.IsAsset(Target) == true)
            {
                P3dTool.CachedTools.Add(Target);
            }

            Draw("category");
            Draw("icon");
        }
Esempio n. 5
0
        protected override void OnInspector()
        {
            TARGET tgt; TARGET[] tgts; GetTargets(out tgt, out tgts);

            if (P3dShape.CachedShapes.Contains(tgt) == false && P3dHelper.IsAsset(tgt) == true)
            {
                P3dShape.CachedShapes.Add(tgt);
            }

            Draw("category");
            Draw("icon");
        }
Esempio n. 6
0
        protected override void OnInspector()
        {
            if (P3dPreset.CachedPresets.Contains(Target) == false && P3dHelper.IsAsset(Target) == true)
            {
                P3dPreset.CachedPresets.Add(Target);
            }

            EditorGUILayout.HelpBox("You can use this preset from the Paint in 3D window after making an object paintable.", MessageType.Info);

            Draw("title", "This allows you to name this preset.\n\nNone/null = The GameObject name will be used.");
            Draw("addMaterialCloner", "Automatically add the P3dMaterialCloner.");

            if (AnyDrawInvalidIndex() == true)
            {
                EditorGUILayout.Separator();

                EditorGUILayout.HelpBox("P3dPaintableTexture slot index values should be 0 for presets, because they will be overwritten when added.", MessageType.Warning);
            }
        }
Esempio n. 7
0
        protected override void OnInspector()
        {
            TARGET tgt; TARGET[] tgts; GetTargets(out tgt, out tgts);

            if (P3dPreset.CachedPresets.Contains(tgt) == false && P3dHelper.IsAsset(tgt) == true)
            {
                P3dPreset.CachedPresets.Add(tgt);
            }

            Info("You can use this preset from the Paint in 3D window after making an object paintable.");

            Draw("title", "This allows you to name this preset.\n\nNone/null = The GameObject name will be used.");
            Draw("addMaterialCloner", "Automatically add the P3dMaterialCloner.");

            if (AnyDrawInvalidIndex(tgts) == true)
            {
                Separator();

                Warning("P3dPaintableTexture slot index values should be 0 for presets, because they will be overwritten when added.");
            }
        }
Esempio n. 8
0
        protected override void OnInspector()
        {
            if (P3dMaterial.CachedMaterials.Contains(Target) == false && P3dHelper.IsAsset(Target) == true)
            {
                P3dMaterial.CachedMaterials.Add(Target);
            }

            Draw("category");
            Draw("icon");

            EditorGUILayout.Separator();

            EditorGUILayout.LabelField("Material Builder", EditorStyles.boldLabel);

            DrawMaterialBuilder();

            EditorGUILayout.Separator();

            EditorGUILayout.LabelField("Icon Builder", EditorStyles.boldLabel);

            DrawIconBuilder();
        }
Esempio n. 9
0
        public void Generate()
        {
#if UNITY_EDITOR
            Undo.RecordObject(this, "Generate Seam Fix");
#endif


            if (meshes != null)
            {
                foreach (var pair in meshes)
                {
                    if (pair.Source != null)
                    {
                        if (pair.Output == null)
                        {
                            pair.Output = new Mesh();
                        }

                        pair.Output.name = pair.Source.name + " (Fixed Seams)";

                        Generate(pair.Source, pair.Output, coord, threshold, border);
                    }
                    else
                    {
                        DestroyImmediate(pair.Output);

                        pair.Output = null;
                    }
                }
            }
#if UNITY_EDITOR
            if (P3dHelper.IsAsset(this) == true)
            {
                var assets = AssetDatabase.LoadAllAssetsAtPath(AssetDatabase.GetAssetPath(this));

                for (var i = 0; i < assets.Length; i++)
                {
                    var assetMesh = assets[i] as Mesh;

                    if (assetMesh != null)
                    {
                        if (meshes == null || meshes.Exists(p => p.Output == assetMesh) == false)
                        {
                            DestroyImmediate(assetMesh, true);
                        }
                    }
                }

                if (meshes != null)
                {
                    foreach (var pair in meshes)
                    {
                        if (pair.Output != null && P3dHelper.IsAsset(pair.Output) == false)
                        {
                            AssetDatabase.AddObjectToAsset(pair.Output, this);

                            AssetDatabase.SaveAssets();
                        }
                    }
                }
            }

            if (P3dHelper.IsAsset(this) == true)
            {
                P3dHelper.ReimportAsset(this);
            }

            EditorUtility.SetDirty(this);
#endif
        }
Esempio n. 10
0
        public void Generate()
        {
            if (source != null)
            {
                if (mesh == null)
                {
                    mesh = new Mesh();
                }

                mesh.Clear(false);
                insertions.Clear();

                mesh.name         = source.name + " (Fixed Seams)";
                mesh.bindposes    = source.bindposes;
                mesh.bounds       = source.bounds;
                mesh.subMeshCount = source.subMeshCount;

                source.GetBoneWeights(boneWeights);
                source.GetColors(colors);
                source.GetNormals(normals);
                source.GetTangents(tangents);
                source.GetUVs(0, coords0);
                source.GetUVs(1, coords1);
                source.GetUVs(2, coords2);
                source.GetUVs(3, coords3);
                source.GetVertices(positions);

                DoGenerate();

                mesh.boneWeights = boneWeights.ToArray();
                mesh.SetColors(colors);
                mesh.SetNormals(normals);
                mesh.SetTangents(tangents);
                mesh.SetUVs(0, coords0);
                mesh.SetUVs(1, coords1);
                mesh.SetUVs(2, coords2);
                mesh.SetUVs(3, coords3);

                if (source.blendShapeCount > 0)
                {
                    var tempDeltaVertices = new Vector3[source.vertexCount];
                    var tempDeltaNormals  = new Vector3[source.vertexCount];
                    var tempDeltaTangents = new Vector3[source.vertexCount];

                    for (var i = 0; i < source.blendShapeCount; i++)
                    {
                        var shapeName  = source.GetBlendShapeName(i);
                        var frameCount = source.GetBlendShapeFrameCount(i);

                        for (var j = 0; j < frameCount; j++)
                        {
                            source.GetBlendShapeFrameVertices(i, j, tempDeltaVertices, tempDeltaNormals, tempDeltaTangents);

                            deltaVertices.Clear();
                            deltaNormals.Clear();
                            deltaTangents.Clear();

                            deltaVertices.AddRange(tempDeltaVertices);
                            deltaNormals.AddRange(tempDeltaNormals);
                            deltaTangents.AddRange(tempDeltaTangents);

                            for (var k = 0; k < insertions.Count; k++)
                            {
                                var insertion = insertions[k];

                                deltaVertices.Add(deltaVertices[insertion]);
                                deltaNormals.Add(deltaNormals[insertion]);
                                deltaTangents.Add(deltaTangents[insertion]);
                            }

                            mesh.AddBlendShapeFrame(shapeName, source.GetBlendShapeFrameWeight(i, j), deltaVertices.ToArray(), deltaNormals.ToArray(), deltaTangents.ToArray());
                        }
                    }
                }

#if UNITY_EDITOR
                if (P3dHelper.IsAsset(this) == true)
                {
                    var assets = AssetDatabase.LoadAllAssetsAtPath(AssetDatabase.GetAssetPath(this));

                    for (var i = 0; i < assets.Length; i++)
                    {
                        var assetMesh = assets[i] as Mesh;

                        if (assetMesh != null && assetMesh != mesh)
                        {
                            DestroyImmediate(assetMesh, true);
                        }
                    }

                    if (P3dHelper.IsAsset(mesh) == false)
                    {
                        AssetDatabase.AddObjectToAsset(mesh, this);
                    }
                }
#endif
            }

#if UNITY_EDITOR
            if (P3dHelper.IsAsset(this) == true)
            {
                P3dHelper.ReimportAsset(this);
            }
#endif
        }
Esempio n. 11
0
        private Texture DrawObject(P3dWindowPaintableTexture paintableTexture, Material material, Texture texture)
        {
            if (texture != null)
            {
                var texture2D = texture as Texture2D;

                if (texture2D != null)
                {
                    EditorGUI.BeginDisabledGroup(paintableTexture.Locked == true);
                    if (material.hideFlags != HideFlags.None)
                    {
                        EditorGUILayout.HelpBox("This may be a shared texture, so you should clone it before modification.", MessageType.Warning);
                    }

                    if (GUILayout.Button("Clone") == true)
                    {
                        texture = texture2D = Instantiate(texture2D);
                    }

                    var textureImporter = P3dHelper.GetAssetImporter <TextureImporter>(texture);

                    if (textureImporter != null)
                    {
                        if (textureImporter.isReadable == false)
                        {
                            EditorGUILayout.HelpBox("This texture's import settings does not have Read/Write Enabled.", MessageType.Error);

                            P3dHelper.BeginColor(Color.green);
                            if (GUILayout.Button("Enable Read/Write") == true)
                            {
                                textureImporter.isReadable = true;

                                textureImporter.SaveAndReimport();
                            }
                            P3dHelper.EndColor();
                        }
                    }
                    else
                    {
                        changeFormat = EditorGUILayout.Foldout(changeFormat, "Change Format");

                        if (changeFormat == true)
                        {
                            EditorGUI.BeginDisabledGroup(true);
                            EditorGUILayout.EnumPopup("Current Format", texture2D.format, EditorStyles.popup);
                            EditorGUI.EndDisabledGroup();

                            changeFormatNew = (TextureFormat)EditorGUILayout.EnumPopup("New Format", changeFormatNew, EditorStyles.popup);

                            P3dHelper.BeginColor(Color.green);
                            if (GUI.Button(P3dHelper.Reserve(), "Change Format") == true)
                            {
                                var newTexture2D = new Texture2D(texture2D.width, texture2D.height, changeFormatNew, texture2D.mipmapCount > 0);

                                changeFormatFailed = true;

                                if (CanReadWrite(newTexture2D) == true)
                                {
                                    var readableTexture = P3dHelper.GetReadableCopy(texture2D);
                                    var pixels          = readableTexture.GetPixels32();

                                    P3dHelper.Destroy(readableTexture);

                                    newTexture2D.name = texture2D.name;
                                    newTexture2D.SetPixels32(pixels);
                                    newTexture2D.Apply();

                                    texture            = texture2D = newTexture2D;
                                    changeFormat       = false;
                                    changeFormatFailed = false;
                                }
                            }
                            P3dHelper.EndColor();

                            if (changeFormatFailed == true)
                            {
                                EditorGUILayout.HelpBox("Failed to change format. This means the format you tried to use is not readable.", MessageType.Error);
                            }
                        }

                        changeSize = EditorGUILayout.Foldout(changeSize, "Change Size");

                        if (changeSize == true)
                        {
                            EditorGUI.BeginDisabledGroup(true);
                            EditorGUILayout.IntField("Current Width", texture2D.width);
                            EditorGUILayout.IntField("Current Height", texture2D.height);
                            EditorGUI.EndDisabledGroup();
                            changeWidth  = EditorGUILayout.IntField("Width", changeWidth);
                            changeHeight = EditorGUILayout.IntField("Height", changeHeight);

                            P3dHelper.BeginColor(Color.green);
                            if (GUILayout.Button("Change Size") == true)
                            {
                                var newTexture2D = new Texture2D(changeWidth, changeHeight, texture2D.format, texture2D.mipmapCount > 0);

                                changeSizeFailed = true;

                                if (CanReadWrite(newTexture2D) == true)
                                {
                                    var readableTexture = P3dHelper.GetReadableCopy(texture2D, TextureFormat.ARGB32, false, changeWidth, changeHeight);
                                    var pixels          = readableTexture.GetPixels32();

                                    P3dHelper.Destroy(readableTexture);

                                    newTexture2D.name = texture2D.name;
                                    newTexture2D.SetPixels32(pixels);
                                    newTexture2D.Apply();

                                    texture          = texture2D = newTexture2D;
                                    changeSize       = false;
                                    changeSizeFailed = false;
                                }
                            }
                            P3dHelper.EndColor();

                            if (changeSizeFailed == true)
                            {
                                EditorGUILayout.HelpBox("Failed to change size. Either the texture format is non-readable, or the texture size you chose is invalid.", MessageType.Error);
                            }
                        }
                    }

                    if (P3dHelper.IsAsset(material) == true && P3dHelper.IsAsset(texture) == false)
                    {
                        EditorGUILayout.HelpBox("This texture is stored in the scene, but it's applied to a material that's stored in an asset. You should save the texture as an asset too, otherwise it won't work properly.", MessageType.Warning);
                    }

                    if (P3dHelper.IsAsset(texture) == false)
                    {
                        if (GUILayout.Button("Save As Texture2D Asset") == true)
                        {
                            var path = P3dHelper.SaveDialog("Save Texture As Asset", "Assets", texture.name, "asset");

                            if (string.IsNullOrEmpty(path) == false)
                            {
                                AssetDatabase.CreateAsset(texture, path);
                            }
                        }

                        if (GUILayout.Button("Save As Png Asset") == true)
                        {
                            var path = P3dHelper.SaveDialog("Export Texture", "Assets", texture.name, "png");

                            if (string.IsNullOrEmpty(path) == false)
                            {
                                P3dHelper.SaveTextureAsset(texture, path, true);

                                var newTexture2D = (Texture2D)AssetDatabase.LoadAssetAtPath(path, typeof(Texture2D));

                                if (newTexture2D != null)
                                {
                                    //ClearUndo();

                                    var importer = P3dHelper.GetAssetImporter <TextureImporter>(newTexture2D);

                                    importer.isReadable         = true;
                                    importer.textureCompression = TextureImporterCompression.Uncompressed;
                                    importer.filterMode         = FilterMode.Trilinear;
                                    importer.anisoLevel         = 8;
                                    importer.SaveAndReimport();

                                    texture = texture2D = newTexture2D;

                                    P3dHelper.SetDirty(this);
                                }
                            }
                        }
                    }
                    EditorGUI.EndDisabledGroup();

                    if (paintableTexture.Locked == true)
                    {
                        EditorGUILayout.BeginHorizontal();
                        P3dHelper.BeginColor(Color.red);
                        if (GUILayout.Button("Unlock", GUILayout.Width(50.0f)) == true)
                        {
                            paintableTexture.Unlock();
                        }
                        P3dHelper.EndColor();
                        P3dGroup_Drawer.OnGUI(P3dHelper.Reserve(), paintableTexture);
                        paintableTexture.Channel = (P3dChannel)EditorGUILayout.EnumPopup(paintableTexture.Channel);
                        if (GUILayout.Button("Paint", GUILayout.Width(45.0f)) == true)
                        {
                            tab = 2;
                        }
                        EditorGUILayout.EndHorizontal();
                    }
                    else
                    {
                        var shared = false;

                        if (TextureAlreadyLocked(texture) == true)
                        {
                            EditorGUILayout.HelpBox("This texture has already been locked in another object, so you don't need to lock it again. Paint will automatically be applied as long as you keep this texture expanded.", MessageType.Info);

                            shared = true;
                        }

                        EditorGUILayout.BeginHorizontal();
                        EditorGUI.BeginDisabledGroup(shared);
                        P3dHelper.BeginColor(Color.green);
                        if (GUILayout.Button("Lock", GUILayout.Width(45.0f)) == true)
                        {
                            Repaint();

                            paintableTexture.Lock(this);
                        }
                        P3dHelper.EndColor();
                        P3dGroup_Drawer.OnGUI(P3dHelper.Reserve(), paintableTexture);
                        EditorGUI.EndDisabledGroup();
                        paintableTexture.Channel = (P3dChannel)EditorGUILayout.EnumPopup(paintableTexture.Channel);
                        P3dHelper.BeginColor(Color.green);
                        EditorGUI.BeginDisabledGroup(shared);
                        if (GUILayout.Button("Lock & Paint", GUILayout.Width(85.0f)) == true)
                        {
                            Repaint();

                            if (paintableTexture.Lock(this) == true)
                            {
                                tab = 2;
                            }
                        }
                        EditorGUI.EndDisabledGroup();
                        P3dHelper.EndColor();
                        EditorGUILayout.EndHorizontal();

                        if (paintableTexture.LockFailed == true)
                        {
                            EditorGUILayout.HelpBox("Failed to lock texture.\nThis may be because the texture is not readable, if so, try cloning it.\nThis may be because the texture format is not readable, if so, try changing the format.", MessageType.Error);
                        }
                    }
                }
                else
                {
                    EditorGUILayout.HelpBox("This texture isn't a Texture2D, so it cannot be painted.", MessageType.Error);
                }
            }
            else
            {
                EditorGUILayout.HelpBox("There is no texture in this slot. Either drag and drop one in, or create one below.", MessageType.Warning);

                createFormat  = (TextureFormat)EditorGUILayout.EnumPopup("Format", createFormat);
                createMipMaps = EditorGUILayout.Toggle("Mip Maps", createMipMaps);
                createLinear  = EditorGUILayout.Toggle("Linear", createLinear);
                createColor   = EditorGUILayout.ColorField("Color", createColor);
                createWidth   = EditorGUILayout.IntField("Width", createWidth);
                createHeight  = EditorGUILayout.IntField("Height", createHeight);

                P3dHelper.BeginColor(Color.green);
                if (GUILayout.Button("Create") == true)
                {
                    var newTexture2D = new Texture2D(createWidth, createHeight, createFormat, createMipMaps, createLinear);

                    createFailed = true;

                    if (CanReadWrite(newTexture2D) == true)
                    {
                        var pixels32 = new Color32[createWidth * createHeight];
                        var color32  = (Color32)createColor;

                        for (var i = createWidth * createHeight - 1; i >= 0; i--)
                        {
                            pixels32[i] = color32;
                        }

                        newTexture2D.SetPixels32(pixels32);
                        newTexture2D.Apply();

                        texture      = newTexture2D;
                        createFailed = false;
                    }
                }
                P3dHelper.EndColor();

                if (createFailed == true)
                {
                    EditorGUILayout.HelpBox("Failed to create texture. This means the format you tried to use is not readable, or the size is invalid.", MessageType.Error);
                }
            }

            return(texture);
        }
Esempio n. 12
0
        private Material DrawMaterial(P3dWindowPaintable paintable, Material material, int materialIndex)
        {
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Material " + materialIndex, EditorStyles.boldLabel, GUILayout.Width(120.0f));
            material = (Material)EditorGUILayout.ObjectField("", material, typeof(Material), false);
            EditorGUILayout.EndHorizontal();

            if (material != null)
            {
                if (material.hideFlags != HideFlags.None)
                {
                    EditorGUILayout.HelpBox("This may be a shared material, so you should clone it before modification.", MessageType.Warning);
                }

                if (GUILayout.Button("Clone") == true)
                {
                    material = Instantiate(material);
                }

                if (MaterialIsShared(material) == true && GUILayout.Button("Shared Clone") == true)
                {
                    var oldMaterial = material;

                    material = Instantiate(material);

                    MaterialIsShared(oldMaterial, material);
                }

                if (P3dHelper.IsAsset(material) == false && GUILayout.Button("Save As Asset") == true)
                {
                    var path = P3dHelper.SaveDialog("Save Material As Asset", "Assets", material.name, "mat");

                    if (string.IsNullOrEmpty(path) == false)
                    {
                        var textures = P3dHelper.CopyTextures(material);

                        AssetDatabase.CreateAsset(material, path);

                        P3dHelper.PasteTextures(material, textures);
                    }
                }

                var texEnvs = P3dHelper.GetTexEnvs(material);

                if (texEnvs.Count > 0)
                {
                    for (var j = 0; j < texEnvs.Count; j++)
                    {
                        var texEnv           = texEnvs[j];
                        var rect             = P3dHelper.Reserve();
                        var paintableTexture = paintable.PaintableTextures.Find(t => t.MaterialIndex == materialIndex && t.SlotName == texEnv.Name);

                        EditorGUI.BeginDisabledGroup(paintableTexture != null && paintableTexture.Locked == true);
                        var texture = EditorGUI.ObjectField(rect, default(string), material.GetTexture(texEnv.Name), typeof(Texture), true) as Texture;
                        EditorGUI.EndDisabledGroup();

                        // Make sure this is done after the texture field so it can be edited
                        var expand = EditorGUI.Foldout(rect, paintableTexture != null, new GUIContent(texEnv.Name, texEnv.Desc), false);

                        if (expand == true)
                        {
                            if (paintableTexture == null)
                            {
                                paintableTexture = new P3dWindowPaintableTexture(paintable, materialIndex, texEnv.Name); paintable.PaintableTextures.Add(paintableTexture);
                            }

                            paintableTexture.Revert();

                            paintableTexture.OldTexture = material.GetTexture(texEnv.Name) as Texture2D;

                            EditorGUILayout.BeginVertical("box");
                            texture = DrawObject(paintableTexture, material, texture);
                            EditorGUILayout.EndVertical();
                        }
                        else
                        {
                            if (paintableTexture != null)
                            {
                                paintableTexture.Unlock();

                                paintable.PaintableTextures.Remove(paintableTexture);
                            }
                        }

                        material.SetTexture(texEnv.Name, texture);
                    }
                }
                else
                {
                    EditorGUILayout.HelpBox("This material's shader has no texture slots.", MessageType.Info);
                }
            }
            else
            {
                EditorGUILayout.HelpBox("There is no material in this material slot.", MessageType.Info);
            }

            return(material);
        }
Esempio n. 13
0
        public void Generate()
        {
            if (source != null)
            {
                if (mesh == null)
                {
                    mesh = new Mesh();
                }

                mesh.Clear(false);
                mesh.name = source.name + " (Copied Coords)";

                mesh.bindposes    = source.bindposes;
                mesh.bounds       = source.bounds;
                mesh.subMeshCount = source.subMeshCount;

                source.GetBoneWeights(boneWeights);
                source.GetColors(colors);
                source.GetNormals(normals);
                source.GetTangents(tangents);
                source.GetUVs(0, coords0);
                source.GetUVs(1, coords1);
                source.GetUVs(2, coords2);
                source.GetUVs(3, coords3);
                source.GetVertices(positions);

                mesh.SetVertices(positions);

                for (var i = 0; i < source.subMeshCount; i++)
                {
                    source.GetTriangles(indices, i);

                    mesh.SetTriangles(indices, i);
                }

                mesh.boneWeights = boneWeights.ToArray();
                mesh.SetColors(colors);
                mesh.SetNormals(normals);
                mesh.SetTangents(tangents);

                mesh.SetUVs(0, GetCoords(first));
                mesh.SetUVs(1, GetCoords(second));
                mesh.SetUVs(2, GetCoords(third));
                mesh.SetUVs(3, GetCoords(fourth));

                if (source.blendShapeCount > 0)
                {
                    var deltaVertices = new Vector3[source.vertexCount];
                    var deltaNormals  = new Vector3[source.vertexCount];
                    var deltaTangents = new Vector3[source.vertexCount];

                    for (var i = 0; i < source.blendShapeCount; i++)
                    {
                        var shapeName  = source.GetBlendShapeName(i);
                        var frameCount = source.GetBlendShapeFrameCount(i);

                        for (var j = 0; j < frameCount; j++)
                        {
                            source.GetBlendShapeFrameVertices(i, j, deltaVertices, deltaNormals, deltaTangents);

                            mesh.AddBlendShapeFrame(shapeName, source.GetBlendShapeFrameWeight(i, j), deltaVertices, deltaNormals, deltaTangents);
                        }
                    }
                }

#if UNITY_EDITOR
                if (P3dHelper.IsAsset(this) == true)
                {
                    var assets = UnityEditor.AssetDatabase.LoadAllAssetsAtPath(UnityEditor.AssetDatabase.GetAssetPath(this));

                    for (var i = 0; i < assets.Length; i++)
                    {
                        var assetMesh = assets[i] as Mesh;

                        if (assetMesh != null && assetMesh != mesh)
                        {
                            DestroyImmediate(assetMesh, true);
                        }
                    }

                    if (P3dHelper.IsAsset(mesh) == false)
                    {
                        UnityEditor.AssetDatabase.AddObjectToAsset(mesh, this);

                        UnityEditor.AssetDatabase.SaveAssets();
                    }
                }
#endif
            }

#if UNITY_EDITOR
            if (P3dHelper.IsAsset(this) == true)
            {
                P3dHelper.ReimportAsset(this);
            }
#endif
        }
Esempio n. 14
0
        public void Generate()
        {
            if (source != null)
            {
                if (mesh == null)
                {
                    mesh = new Mesh();
                }

                mesh.Clear(false);
                mesh.name = source.name + " (Fixed Seams)";

                mesh.bindposes    = source.bindposes;
                mesh.bounds       = source.bounds;
                mesh.subMeshCount = source.subMeshCount;

                source.GetBoneWeights(boneWeights);
                source.GetColors(colors);
                source.GetNormals(normals);
                source.GetTangents(tangents);
                source.GetUVs(0, coords0);
                source.GetUVs(1, coords1);
                source.GetUVs(2, coords2);
                source.GetUVs(3, coords3);
                source.GetVertices(positions);

                DoGenerate();

                mesh.boneWeights = boneWeights.ToArray();
                mesh.SetColors(colors);
                mesh.SetNormals(normals);
                mesh.SetTangents(tangents);
                mesh.SetUVs(0, coords0);
                mesh.SetUVs(1, coords1);
                mesh.SetUVs(2, coords2);
                mesh.SetUVs(3, coords3);

#if UNITY_EDITOR
                if (P3dHelper.IsAsset(this) == true)
                {
                    var assets = AssetDatabase.LoadAllAssetsAtPath(AssetDatabase.GetAssetPath(this));

                    for (var i = 0; i < assets.Length; i++)
                    {
                        var assetMesh = assets[i] as Mesh;

                        if (assetMesh != null && assetMesh != mesh)
                        {
                            DestroyImmediate(assetMesh, true);
                        }
                    }

                    if (P3dHelper.IsAsset(mesh) == false)
                    {
                        AssetDatabase.AddObjectToAsset(mesh, this);
                    }
                }
#endif
            }

#if UNITY_EDITOR
            if (P3dHelper.IsAsset(this) == true)
            {
                P3dHelper.ReimportAsset(this);
            }
#endif
        }
Esempio n. 15
0
        protected override void OnInspector()
        {
            DrawNextPaint();

            if (scene == null)
            {
                scene = CreateInstance <P3dScene>();

                scene.name = "Temp";

                scene.AddLayer();

                scene.AddCloner("Mirror X", Vector3.zero, new Vector3(0.0f, 90.0f, 0.0f));
                scene.AddCloner("Mirror Y", Vector3.zero, new Vector3(90.0f, 0.0f, 0.0f));
                scene.AddCloner("Mirror Z", Vector3.zero, new Vector3(0.0f, 0.0f, 0.0f));
            }

            if (previewDrawn == true && Event.current.type == EventType.Repaint)
            {
                previewDrawn = false;

                foreach (var layer in scene.Layers)
                {
                    foreach (var images in layer.Images)
                    {
                        if (images.Preview != null)
                        {
                            images.Preview = P3dHelper.ReleaseRenderTexture(images.Preview);
                        }
                    }
                }

                pendingUpdate = true;
            }

            if (scene.Layers.Contains(currentLayer) == false)
            {
                currentLayer = null;

                if (scene.Layers.Count > 0)
                {
                    currentLayer = scene.Layers[scene.Layers.Count - 1];
                }
            }

            if (scene.Mats.Contains(currentMat) == false)
            {
                currentMat = null;

                if (scene.Mats.Count > 0)
                {
                    currentMat = scene.Mats[scene.Mats.Count - 1];
                }
            }

            if (scene.Objs.Contains(currentObj) == false)
            {
                currentObj = null;

                if (scene.Objs.Count > 0)
                {
                    currentObj = scene.Objs[scene.Objs.Count - 1];
                }
            }

            EditorGUILayout.BeginHorizontal(EditorStyles.toolbar);
            EditorGUI.BeginDisabledGroup(CanUndo == false);
            if (GUILayout.Button(new GUIContent("◄", "Undo"), EditorStyles.toolbarButton, GUILayout.Width(20)) == true)
            {
                Undo();
            }
            EditorGUI.EndDisabledGroup();
            EditorGUI.BeginDisabledGroup(CanRedo == false);
            if (GUILayout.Button(new GUIContent("►", "Redo"), EditorStyles.toolbarButton, GUILayout.Width(20)) == true)
            {
                Redo();
            }
            EditorGUI.EndDisabledGroup();

            if (GUILayout.Toggle(currentState == StateType.Scene, "Scene", EditorStyles.toolbarButton, GUILayout.Width(50)) == true)
            {
                currentState = StateType.Scene;
            }

            if (GUILayout.Toggle(currentState == StateType.Paint, "Paint", EditorStyles.toolbarButton, GUILayout.Width(50)) == true)
            {
                currentState = StateType.Paint;
            }

            if (GUILayout.Toggle(currentState == StateType.Layer, "Layer", EditorStyles.toolbarButton, GUILayout.Width(50)) == true)
            {
                currentState = StateType.Layer;
            }

            if (GUILayout.Toggle(currentState == StateType.Config, "Config", EditorStyles.toolbarButton, GUILayout.Width(50)) == true)
            {
                currentState = StateType.Config;
            }

            EditorGUILayout.Separator();

            EditorGUI.BeginDisabledGroup(P3dHelper.IsAsset(scene) == false);
            if (GUILayout.Button("Save", EditorStyles.toolbarButton, GUILayout.Width(40)) == true)
            {
                HandleSave();
            }
            EditorGUI.EndDisabledGroup();

            P3dHelper.BeginColor(Color.green, P3dHelper.IsAsset(scene) == false);
            if (GUILayout.Button("Save As", EditorStyles.toolbarButton, GUILayout.Width(55)) == true)
            {
                HandleSaveAs();
            }
            P3dHelper.EndColor();
            EditorGUILayout.EndHorizontal();

            if (Event.current.type == EventType.MouseUp)
            {
                dragId     = -1;
                dragHandle = -1;
            }

            switch (currentState)
            {
            case StateType.Scene:
            {
                GUILayout.BeginHorizontal(GUILayout.ExpandHeight(true));
                objectsScrollPosition = GUILayout.BeginScrollView(objectsScrollPosition, GUILayout.Width(200));
                UpdateObjectsPanel();
                GUILayout.EndScrollView();

                DrawViewport();

                materialsScrollPosition = GUILayout.BeginScrollView(materialsScrollPosition, GUILayout.Width(200));
                UpdateMaterialsPanel();
                GUILayout.EndScrollView();
                GUILayout.EndHorizontal();
            }
            break;

            case StateType.Paint:
            {
                GUILayout.BeginHorizontal(GUILayout.ExpandHeight(true));
                GUILayout.BeginVertical(GUILayout.Width(200));
                brushesScrollPosition = GUILayout.BeginScrollView(brushesScrollPosition, GUILayout.ExpandWidth(true));
                UpdatePaintBrushesPanel(200);
                GUILayout.EndScrollView();

                dynamicsScrollPosition = GUILayout.BeginScrollView(dynamicsScrollPosition, GUILayout.ExpandWidth(true), GUILayout.Height(200));
                UpdateDynamicsPanel();
                GUILayout.EndScrollView();
                GUILayout.EndVertical();

                DrawViewport();

                paintScrollPosition = GUILayout.BeginScrollView(paintScrollPosition, GUILayout.Width(200));
                UpdatePaintMaterialsPanel(200);
                GUILayout.EndScrollView();
                GUILayout.EndHorizontal();
            }
            break;

            case StateType.Layer:
            {
                GUILayout.BeginHorizontal(GUILayout.ExpandHeight(true));
                repeatersScrollPosition = GUILayout.BeginScrollView(repeatersScrollPosition, GUILayout.Width(200));
                UpdateClonersPanel();
                GUILayout.EndScrollView();

                DrawViewport();

                layersScrollPosition = GUILayout.BeginScrollView(layersScrollPosition, GUILayout.Width(200));
                UpdateLayersPanel();
                GUILayout.EndScrollView();
                GUILayout.EndHorizontal();
            }
            break;

            case StateType.Config:
            {
                GUILayout.BeginHorizontal(GUILayout.ExpandHeight(true));
                sceneScrollPosition = GUILayout.BeginScrollView(sceneScrollPosition, GUILayout.Width(200));
                UpdateScenePanel();
                GUILayout.EndScrollView();

                DrawViewport();

                settingsScrollPosition = GUILayout.BeginScrollView(settingsScrollPosition, GUILayout.Width(200));
                UpdateSettingsPanel();
                GUILayout.EndScrollView();
                GUILayout.EndHorizontal();
            }
            break;
            }

            EditorGUILayout.BeginHorizontal(EditorStyles.toolbar);
            EditorGUILayout.LabelField("Undo state " + stateIndex + " of " + states.Count, GUILayout.Width(135));

            EditorGUILayout.Separator();

            scene = (P3dScene)EditorGUILayout.ObjectField(scene, typeof(P3dScene), false, GUILayout.MinWidth(50));

            EditorGUI.BeginDisabledGroup(P3dHelper.IsAsset(scene) == false);
            if (GUILayout.Button("Export", EditorStyles.toolbarButton, GUILayout.Width(55)) == true)
            {
                HandleExport();
            }
            EditorGUI.EndDisabledGroup();
            EditorGUILayout.EndHorizontal();

            HandleDraw();

            if (pendingUpdate == true && Event.current.type == EventType.Repaint)
            {
                pendingUpdate = false;

                UpdatePaintedMats();
            }

            Repaint();
        }