Ejemplo n.º 1
0
        public void RenderRetainedMode(SharpGL.OpenGL openGL)
        {
            var axies = new Axies();

            axies.Render(openGL, RenderMode.Design);

            if (DrawAll == true)
            {
                foreach (var mesh in Meshes)
                {
                    mesh.Draw(openGL);
                }
                if (SelectedMesh != null)
                {
                    EditMesh();
                }
            }
            else
            {
                if (SelectedMesh != null)
                {
                    SelectedMesh.Draw(openGL);
                    EditMesh();
                }
            }
        }
Ejemplo n.º 2
0
 public void RedrawOnImage(Canvas canvas)
 {
     try
     {
         _3DViewModel.TranslateX = SelectedMesh.Transformation.TranslateX;
         _3DViewModel.TranslateY = SelectedMesh.Transformation.TranslateY;
         _3DViewModel.TranslateZ = SelectedMesh.Transformation.TranslateZ;
         _3DViewModel.RotateX    = SelectedMesh.Transformation.RotateX;
         _3DViewModel.RotateY    = SelectedMesh.Transformation.RotateY;
         _3DViewModel.RotateZ    = SelectedMesh.Transformation.RotateZ;
         _3DViewModel.Depth      = SelectedMesh.Transformation.Depth;
         canvas.Children.RemoveRange(1, 9);
         SelectedMesh.RedrawOnImage(canvas);
         i = -1;
     }
     catch (System.Exception)
     {
     }
 }
Ejemplo n.º 3
0
 public void RedrawOnImage(Canvas canvas)
 {
     try
     {
         TranslateX  = SelectedMesh.Transformation.TranslateX;
         TranslateY  = SelectedMesh.Transformation.TranslateY;
         TranslateZ  = SelectedMesh.Transformation.TranslateZ;
         RotateX     = SelectedMesh.Transformation.RotateX;
         RotateY     = SelectedMesh.Transformation.RotateY;
         RotateZ     = SelectedMesh.Transformation.RotateZ;
         Depth       = SelectedMesh.Transformation.Depth;
         TexturePath = SelectedMesh.TexturePath;
         canvas.Children.RemoveRange(1, 9);
         SelectedMesh.RedrawOnImage(canvas);
         i = -1;
     }
     catch (System.Exception)
     {
     }
 }
Ejemplo n.º 4
0
    private SelectedMesh GetMeshToAdd(Mesh mesh, bool isProjectAsset, Object _assoObj = null)
    {
        string meshPath  = AssetDatabase.GetAssetPath(mesh);
        Mesh   meshAsset = AssetDatabase.LoadAssetAtPath(meshPath, typeof(Mesh)) as Mesh;

        if (meshAsset == null)
        {
            return(null);
        }
        string meshName = mesh.name;

        if (!AssetDatabase.IsMainAsset(meshAsset))
        {
            Object main = AssetDatabase.LoadMainAssetAtPath(meshPath);
            meshName = main.name + " - " + meshName + "_" + mesh.GetInstanceID().ToString();
        }

        SelectedMesh sm = new SelectedMesh(mesh, meshName, isProjectAsset, _assoObj);

        return(sm);
    }
Ejemplo n.º 5
0
        private SelectedMesh GetMeshToAdd(Mesh mesh, bool isProjectAsset, Object _assoObj = null)
        {
            var meshPath  = AssetDatabase.GetAssetPath(mesh);
            var meshAsset = AssetDatabase.LoadAssetAtPath(meshPath, typeof(Mesh)) as Mesh;

            //If null, it can be a built-in Unity mesh
            if (meshAsset == null)
            {
                return(new SelectedMesh(mesh, mesh.name, isProjectAsset, _assoObj));
            }
            var meshName = mesh.name;

            if (!AssetDatabase.IsMainAsset(meshAsset))
            {
                var main = AssetDatabase.LoadMainAssetAtPath(meshPath);
                meshName = main.name + " - " + meshName + "_" + mesh.GetInstanceID();
            }

            var sm = new SelectedMesh(mesh, meshName, isProjectAsset, _assoObj);

            return(sm);
        }
Ejemplo n.º 6
0
        private Mesh CreateSmoothedMeshAsset(SelectedMesh originalMesh)
        {
            //Check if we are ok to overwrite
            var overwrite = true;

            var rootPath = mCustomDirectory ? Application.dataPath + "/" + mCustomDirectoryPath + "/" : Utils.FindReadmePath() + OUTPUT_FOLDER;

            if (!Directory.Exists(rootPath))
            {
                Directory.CreateDirectory(rootPath);
            }

#if UNITY_EDITOR_WIN
            rootPath = rootPath.Replace(mCustomDirectory ? Application.dataPath : Utils.ToSystemSlashPath(Application.dataPath), "").Replace(@"\", "/");
#else
            rootPath = rootPath.Replace(Application.dataPath, "");
#endif

            var originalMeshName = GetSafeFilename(originalMesh.name);
            var assetPath        = "Assets" + rootPath;
            var newAssetName     = string.Format("{0}{1}.asset", originalMeshName, string.IsNullOrEmpty(mFilenameSuffix) ? "" : " " + mFilenameSuffix);
            if (originalMeshName.Contains(mFilenameSuffix))
            {
                newAssetName = originalMeshName + ".asset";
            }
            assetPath += newAssetName;
            var existingAsset = AssetDatabase.LoadAssetAtPath(assetPath, typeof(Mesh)) as Mesh;
            var assetExists   = (existingAsset != null) && originalMesh.isAsset;
            if (assetExists)
            {
                if (!mAlwaysOverwrite)
                {
                    overwrite = EditorUtility.DisplayDialog("TCP2 : Smoothed Mesh", "The following smoothed mesh already exists:\n\n" + newAssetName + "\n\nOverwrite?", "Yes", "No");
                }

                if (!overwrite)
                {
                    return(null);
                }

                originalMesh.mesh = existingAsset;
                originalMesh.name = existingAsset.name;
            }

            var  channel = originalMesh.isSkinned ? Utils.SmoothedNormalsChannel.Tangents : smoothedNormalChannel;
            Mesh newMesh = Utils.CreateSmoothedMesh(originalMesh.mesh, mFormat, channel, smoothedNormalUVType, !originalMesh.isAsset || (originalMesh.isAsset && assetExists));

            if (newMesh == null)
            {
                ShowNotification(new GUIContent("Couldn't generate the mesh for:\n" + originalMesh.name));
            }
            else
            {
                if (originalMesh.associatedObjects != null)
                {
                    Undo.RecordObjects(originalMesh.associatedObjects, "Assign TCP2 Smoothed Mesh to Selection");

                    foreach (var o in originalMesh.associatedObjects)
                    {
                        if (o is SkinnedMeshRenderer)
                        {
                            (o as SkinnedMeshRenderer).sharedMesh = newMesh;
                        }
                        else if (o is MeshFilter)
                        {
                            (o as MeshFilter).sharedMesh = newMesh;
                        }
                        else
                        {
                            Debug.LogWarning("[TCP2 Smoothed Normals Utility] Unrecognized AssociatedObject: " + o + "\nType: " + o.GetType());
                        }
                        EditorUtility.SetDirty(o);
                    }
                }

                if (originalMesh.isAsset)
                {
                    if (overwrite && !assetExists)
                    {
                        AssetDatabase.CreateAsset(newMesh, assetPath);
                    }
                }
                else
                {
                    return(null);
                }
            }

            return(newMesh);
        }
Ejemplo n.º 7
0
    private Dictionary <Mesh, SelectedMesh> GetSelectedMeshes()
    {
        Dictionary <Mesh, SelectedMesh> meshDict = new Dictionary <Mesh, SelectedMesh>();

        foreach (Object o in Selection.objects)
        {
            bool isProjectAsset = !string.IsNullOrEmpty(AssetDatabase.GetAssetPath(o));

            //Assets from Project
            if (o is Mesh && !meshDict.ContainsKey(o as Mesh))
            {
                if ((o as Mesh) != null)
                {
                    SelectedMesh sm = GetMeshToAdd(o as Mesh, isProjectAsset);
                    if (sm != null)
                    {
                        meshDict.Add(o as Mesh, sm);
                    }
                }
            }
            else if (o is GameObject && isProjectAsset)
            {
                string   path      = AssetDatabase.GetAssetPath(o);
                Object[] allAssets = AssetDatabase.LoadAllAssetsAtPath(path);
                foreach (Object asset in allAssets)
                {
                    if (asset is Mesh && !meshDict.ContainsKey(asset as Mesh))
                    {
                        if ((asset as Mesh) != null)
                        {
                            SelectedMesh sm = GetMeshToAdd(asset as Mesh, isProjectAsset);
                            if (sm.mesh != null)
                            {
                                meshDict.Add(asset as Mesh, sm);
                            }
                        }
                    }
                }
            }
            //Assets from Hierarchy
            else if (o is GameObject && !isProjectAsset)
            {
                SkinnedMeshRenderer[] renderers = (o as GameObject).GetComponentsInChildren <SkinnedMeshRenderer>();
                foreach (SkinnedMeshRenderer r in renderers)
                {
                    if (r.sharedMesh != null)
                    {
                        if (meshDict.ContainsKey(r.sharedMesh))
                        {
                            SelectedMesh sm = meshDict[r.sharedMesh];
                            sm.AddAssociatedObject(r);
                        }
                        else
                        {
                            if (r.sharedMesh.name.Contains(MESH_SUFFIX))
                            {
                                meshDict.Add(r.sharedMesh, new SelectedMesh(r.sharedMesh, r.sharedMesh.name, false));
                            }
                            else
                            {
                                if (r.sharedMesh != null)
                                {
                                    SelectedMesh sm = GetMeshToAdd(r.sharedMesh, true, r);
                                    if (sm.mesh != null)
                                    {
                                        meshDict.Add(r.sharedMesh, sm);
                                    }
                                }
                            }
                        }
                    }
                }

                MeshFilter[] mfilters = (o as GameObject).GetComponentsInChildren <MeshFilter>();
                foreach (MeshFilter mf in mfilters)
                {
                    if (mf.sharedMesh != null)
                    {
                        if (meshDict.ContainsKey(mf.sharedMesh))
                        {
                            SelectedMesh sm = meshDict[mf.sharedMesh];
                            sm.AddAssociatedObject(mf);
                        }
                        else
                        {
                            if (mf.sharedMesh.name.Contains(MESH_SUFFIX))
                            {
                                meshDict.Add(mf.sharedMesh, new SelectedMesh(mf.sharedMesh, mf.sharedMesh.name, false));
                            }
                            else
                            {
                                if (mf.sharedMesh != null)
                                {
                                    SelectedMesh sm = GetMeshToAdd(mf.sharedMesh, true, mf);
                                    if (sm.mesh != null)
                                    {
                                        meshDict.Add(mf.sharedMesh, sm);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }

        return(meshDict);
    }
Ejemplo n.º 8
0
    //--------------------------------------------------------------------------------------------------

    private Mesh CreateSmoothedMeshAsset(SelectedMesh originalMesh)
    {
        //Check if we are ok to overwrite
        bool   overwrite = true;
        string rootPath  = TCP2_Utils.FindReadmePath() + OUTPUT_FOLDER;

        if (!System.IO.Directory.Exists(rootPath))
        {
            System.IO.Directory.CreateDirectory(rootPath);
        }

#if UNITY_EDITOR_WIN
        rootPath = rootPath.Replace(TCP2_Utils.UnityToSystemPath(Application.dataPath), "").Replace(@"\", "/");
#else
        rootPath = rootPath.Replace(Application.dataPath, "");
#endif

        string assetPath    = "Assets" + rootPath;
        string newAssetName = originalMesh.name + " " + MESH_SUFFIX + ".asset";
        if (originalMesh.name.Contains(MESH_SUFFIX))
        {
            newAssetName = originalMesh.name + ".asset";
        }
        assetPath += newAssetName;
        Mesh existingAsset = AssetDatabase.LoadAssetAtPath(assetPath, typeof(Mesh)) as Mesh;
        bool assetExists   = (existingAsset != null) && originalMesh.isAsset;
        if (assetExists)
        {
            if (!mAlwaysOverwrite)
            {
                overwrite = EditorUtility.DisplayDialog("TCP2 : Smoothed Mesh", "The following smoothed mesh already exists:\n\n" + newAssetName + "\n\nOverwrite?", "Yes", "No");
            }

            if (!overwrite)
            {
                return(null);
            }
            else
            {
                originalMesh.mesh = existingAsset;
                originalMesh.name = existingAsset.name;
            }
        }

        Mesh newMesh = null;
        if (originalMesh.isSkinned)
        {
            newMesh = TCP2_Utils.CreateSmoothedMesh(originalMesh.mesh, mFormat, false, true, false, !originalMesh.isAsset || (originalMesh.isAsset && assetExists));
        }
        else
        {
            newMesh = TCP2_Utils.CreateSmoothedMesh(originalMesh.mesh, mFormat, mVColors, mTangents, mUV2, !originalMesh.isAsset || (originalMesh.isAsset && assetExists));
        }

        if (newMesh == null)
        {
            ShowNotification(new GUIContent("Couldn't generate the mesh for:\n" + originalMesh.name));
        }
        else
        {
            if (originalMesh.associatedObjects != null)
            {
                Undo.RecordObjects(originalMesh.associatedObjects, "Assign TCP2 Smoothed Mesh to Selection");

                foreach (Object o in originalMesh.associatedObjects)
                {
                    if (o is SkinnedMeshRenderer)
                    {
                        (o as SkinnedMeshRenderer).sharedMesh = newMesh;
                    }
                    else if (o is MeshFilter)
                    {
                        (o as MeshFilter).sharedMesh = newMesh;
                    }
                    else
                    {
                        Debug.LogWarning("[TCP2 Smoothed Normals Utility] Unrecognized AssociatedObject: " + o + "\nType: " + o.GetType());
                    }
                    EditorUtility.SetDirty(o);
                }
            }

            if (originalMesh.isAsset)
            {
                if (overwrite && !assetExists)
                {
                    AssetDatabase.CreateAsset(newMesh, assetPath);
                }
            }
            else
            {
                return(null);
            }
        }

        return(newMesh);
    }
    //--------------------------------------------------------------------------------------------------
    private Mesh CreateSmoothedMeshAsset(SelectedMesh originalMesh)
    {
        //Check if we are ok to overwrite
        bool overwrite = true;
        string rootPath = TCP2_Utils.FindReadmePath() + OUTPUT_FOLDER;
        if(!System.IO.Directory.Exists(rootPath))
            System.IO.Directory.CreateDirectory(rootPath);

        #if UNITY_EDITOR_WIN
        rootPath = rootPath.Replace(TCP2_Utils.UnityToSystemPath( Application.dataPath ), "").Replace(@"\", "/");
        #else
        rootPath = rootPath.Replace(Application.dataPath, "");
        #endif

        string assetPath = "Assets" + rootPath;
        string newAssetName = originalMesh.name + " " + MESH_SUFFIX + ".asset";
        if(originalMesh.name.Contains(MESH_SUFFIX))
        {
            newAssetName = originalMesh.name + ".asset";
        }
        assetPath += newAssetName;
        Mesh existingAsset = AssetDatabase.LoadAssetAtPath(assetPath, typeof(Mesh)) as Mesh;
        bool assetExists = (existingAsset != null) && originalMesh.isAsset;
        if(assetExists)
        {
            if(!mAlwaysOverwrite)
                overwrite = EditorUtility.DisplayDialog("TCP2 : Smoothed Mesh", "The following smoothed mesh already exists:\n\n" + newAssetName + "\n\nOverwrite?", "Yes", "No");

            if(!overwrite)
            {
                return null;
            }
            else
            {
                originalMesh.mesh = existingAsset;
                originalMesh.name = existingAsset.name;
            }
        }

        Mesh newMesh = null;
        if(originalMesh.isSkinned)
        {
            newMesh = TCP2_Utils.CreateSmoothedMesh(originalMesh.mesh, mFormat, false, true, false, !originalMesh.isAsset || (originalMesh.isAsset && assetExists));
        }
        else
        {
            newMesh = TCP2_Utils.CreateSmoothedMesh(originalMesh.mesh, mFormat, mVColors, mTangents, mUV2, !originalMesh.isAsset || (originalMesh.isAsset && assetExists));
        }

        if(newMesh == null)
        {
            ShowNotification(new GUIContent("Couldn't generate the mesh for:\n" + originalMesh.name));
        }
        else
        {
            if(originalMesh.associatedObjects != null)
            {
                Undo.RecordObjects(originalMesh.associatedObjects, "Assign TCP2 Smoothed Mesh to Selection");

                foreach(Object o in originalMesh.associatedObjects)
                {
                    if(o is SkinnedMeshRenderer)
                    {
                        (o as SkinnedMeshRenderer).sharedMesh = newMesh;
                    }
                    else if(o is MeshFilter)
                    {
                        (o as MeshFilter).sharedMesh = newMesh;
                    }
                    else
                    {
                        Debug.LogWarning("[TCP2 Smoothed Normals Utility] Unrecognized AssociatedObject: " + o + "\nType: " + o.GetType());
                    }
                    EditorUtility.SetDirty(o);
                }
            }

            if(originalMesh.isAsset)
            {
                if(overwrite && !assetExists)
                {
                    AssetDatabase.CreateAsset(newMesh, assetPath);
                }
            }
            else
                return null;
        }

        return newMesh;
    }
    private SelectedMesh GetMeshToAdd(Mesh mesh, bool isProjectAsset, Object _assoObj = null)
    {
        string meshPath = AssetDatabase.GetAssetPath(mesh);
        Mesh meshAsset = AssetDatabase.LoadAssetAtPath(meshPath, typeof(Mesh)) as Mesh;
        //If null, it can be a built-in Unity mesh
        if(meshAsset == null)
        {
            return new SelectedMesh(mesh, mesh.name, isProjectAsset, _assoObj);
        }
        string meshName = mesh.name;
        if(!AssetDatabase.IsMainAsset(meshAsset))
        {
            Object main = AssetDatabase.LoadMainAssetAtPath(meshPath);
            meshName = main.name + " - " + meshName + "_" + mesh.GetInstanceID().ToString();
        }

        SelectedMesh sm = new SelectedMesh(mesh, meshName, isProjectAsset, _assoObj);
        return sm;
    }