// [MenuItem("NPVox/Select All Instances &s", true)]
 static bool Validate()
 {
     UnityEngine.Object[] objects = Selection.objects;
     for (int i = 0; i < objects.Length; i++)
     {
         NPipeContainer o = objects[i] as NPipeContainer;
         if (o)
         {
             NPipeIImportable[] outputPipes = NPipelineUtils.FindOutputPipes(NPipelineUtils.GetImportables(AssetDatabase.LoadAllAssetsAtPath(AssetDatabase.GetAssetPath(o))));
             foreach (NPipeIImportable imp in outputPipes)
             {
                 if (imp is NPVoxMeshOutput)
                 {
                     return(true);
                 }
             }
         }
         NPVoxMeshInstance inst = objects[i] as NPVoxMeshInstance;
         if (inst)
         {
             return(true);
         }
     }
     return(false);
 }
    private static bool ImportVoxModel(string asset)
    {
        string filename = Path.GetFileNameWithoutExtension(asset);
        string basename = Path.GetDirectoryName(asset);

        EnsureDirectoriesExist(basename);
        string         pipelinePath  = Path.Combine(Path.Combine(basename, "Pipeline/"), filename + ".asset");
        NPipeContainer pipeContainer = NPipelineUtils.GetContainerForVoxPath(asset);

        if (!pipeContainer)
        {
            if (File.Exists(pipelinePath))
            {
                // We don't need this anymore, as assets are reimported by the NPipeImporter anyway
                // AssetDatabase.ImportAsset(asset, ImportAssetOptions.Default);
//                Debug.Log("Did not create Pipeline for asset '" + asset + "' due to pipeline not yet ready (no problem as will get imported by the NPipeContainer anyway)");
                return(false);
            }

            Debug.Log("Creating Pipeline for Voxmodel: " + asset);

            NPipeContainer template;
            bool           unavailable;
            NPVoxUtils.LoadTemplateMetadata(out template, out unavailable);
            if (template == null)
            {
                if (!unavailable)
                {
                    // We don't need this anymore, as assets are reimported by the NPipeImporter anyway
                    // AssetDatabase.ImportAsset(asset, ImportAssetOptions.Default);
                    // Debug.Log("Delay import of '" + asset + "' due to template not yet ready");
                    Debug.Log("did not import '" + asset + "' due to template not yet ready");
                }
                return(false);
            }

            pipeContainer = NPipelineUtils.ClonePipeContainer(template, pipelinePath);
        }

        NPipeIImportable[] importables = NPipelineUtils.GetImportables(pipeContainer);
        // NPipeIImportable[] outputPipes = NPipelineUtils.FindOutputPipes(importables);

        foreach (NPipeIImportable importable in importables)
        {
            if (importable is NPVoxMagickaSource)
            {
                ((NPVoxMagickaSource)importable).VoxModelUUID = AssetDatabase.AssetPathToGUID(asset);
            }

            importable.Invalidate();
            EditorUtility.SetDirty(importable as UnityEngine.Object);
        }

        AssetDatabase.SaveAssets();
        AssetDatabase.ImportAsset(pipelinePath, ImportAssetOptions.ForceSynchronousImport); // try ForceSynchronousImport
        return(true);
    }
    public static NPipeContainer ClonePipeContainer(NPipeContainer container, string path)
    {
        NPipeContainer newContainer = NPipeContainer.CreateInstance <NPipeContainer>();

        AssetDatabase.CreateAsset(newContainer, path);

        NPipeIImportable[] templateImportables = NPipelineUtils.GetImportables(container);
        foreach (NPipeIImportable pipe in NPipelineUtils.FindOutputPipes(templateImportables))
        {
            CloneRecursive(templateImportables, pipe, path);
        }
        return(newContainer);
    }
 static void MenuNew()
 {
     UnityEngine.Object[] objects = Selection.objects;
     for (int i = 0; i < objects.Length; i++)
     {
         NPipeContainer o = objects[i] as NPipeContainer;
         if (o)
         {
             NPipeIImportable[] outputPipes = NPipelineUtils.FindOutputPipes(NPipelineUtils.GetImportables(AssetDatabase.LoadAllAssetsAtPath(AssetDatabase.GetAssetPath(o))));
             foreach (NPipeIImportable imp in outputPipes)
             {
                 if (imp is NPVoxMeshOutput)
                 {
                     ((NPVoxMeshOutput)imp).Instatiate();
                 }
             }
         }
         NPVoxMeshInstance inst = objects[i] as NPVoxMeshInstance;
         if (inst)
         {
             ((NPVoxMeshOutput)inst.meshFactory).Instatiate();
         }
     }
 }
Esempio n. 5
0
    public override void OnInspectorGUI()
    {
        NPVoxMeshInstance instance = (NPVoxMeshInstance)target;
        string            path     = AssetDatabase.GetAssetPath(instance);
        bool isTemplate            = path.Length > 0 && AssetDatabase.AssetPathToGUID(path) == NPVoxConstants.GAMEPOBJECT_TEMPLATE;

        if (isTemplate)
        {
            GUILayout.Label("This is the Prefab used to construct new instances of your models.\nAdjust as your liking, but don't move or rename it!");
            return;
        }

        DrawDefaultInspector();

        if (instance.MeshFactory == null)
        {
            GUILayout.Label("NPVox: No NP Vox Mesh Factory assigned.");

            return;
        }

        if ((instance.MeshFactory is NPVoxProcessorBase <Mesh>) && ((NPVoxProcessorBase <Mesh>)instance.MeshFactory).StorageMode == NPipeStorageMode.ATTACHED)
        {
            if (instance.SharedMash != instance.MeshFactory.GetProduct())
            {
                Undo.RecordObject(instance, "Updated shared mesh");
                instance.SharedMash = instance.MeshFactory.GetProduct();
            }
        }
        else
        {
            GUILayout.Label(
                "NPVox: The Storage Mode is not set to ATTACHED, thus you are not able to preview the item in the editor, sorry");
            GUILayout.Label(" to see any preview during Editor time.\n", new GUILayoutOption[] { });
            if (instance.SharedMash != null)
            {
                Undo.RecordObject(instance, "Unset shared mesh");
            }
            instance.SharedMash = null;
        }

        bool isPrefab = PrefabUtility.GetPrefabParent(target) == null && PrefabUtility.GetPrefabObject(target) != null;

        if (!isPrefab)
        {
            if (GUILayout.Button("Align (Shortcut ALT+a)"))
            {
                Align(instance.transform);
            }
        }

        NPVoxCubeSimplifier[] simplifiers = NPipelineUtils.FindNextPipeOfType <NPVoxCubeSimplifier>(NPipelineUtils.GetImportables(AssetDatabase.GetAssetPath(instance.MeshFactory as UnityEngine.Object)), instance.MeshFactory);

        if (simplifiers.Length > 0)
        {
            if (GUILayout.Button("Switch to Cube Simplifier instance"))
            {
                NPVoxCubeSimplifierInstance cubeSimplifier = instance.gameObject.AddComponent <NPVoxCubeSimplifierInstance>();
                cubeSimplifier.CubeSimplifier = simplifiers[0];
                cubeSimplifier.UpdateMesh();
                DestroyImmediate(instance, true);
                return;
            }
        }
        else
        {
            if (GUILayout.Button("Create Cube Simplifier"))
            {
                string assetPath = AssetDatabase.GetAssetPath(instance.MeshFactory as UnityEngine.Object);
                NPVoxCubeSimplifier simplifier = (NPVoxCubeSimplifier)NPipelineUtils.CreateAttachedPipe(assetPath, typeof(NPVoxCubeSimplifier), instance.MeshFactory);
                simplifier.TextureAtlas   = (NPVoxTextureAtlas)UnityEditor.AssetDatabase.LoadAssetAtPath(UnityEditor.AssetDatabase.GUIDToAssetPath("b3ed00785c29642baae5806625c1d3c1"), typeof(NPVoxTextureAtlas));
                simplifier.SourceMaterial = instance.GetComponent <MeshRenderer>().sharedMaterial;
                AssetDatabase.SaveAssets();
            }
        }

        if (GUILayout.Button("Select Pipe Container (Edit Import Settings)"))
        {
            Selection.objects = new Object[] { AssetDatabase.LoadAssetAtPath(AssetDatabase.GetAssetPath(instance.meshFactory), typeof(NPipeContainer)) };
        }


        if (GUILayout.Button("Invalidate Pipe Container Deep "))
        {
            NPipelineUtils.InvalidateAndReimportAllDeep(AssetDatabase.LoadAssetAtPath(AssetDatabase.GetAssetPath(instance.meshFactory), typeof(NPipeContainer)));
        }
    }
Esempio n. 6
0
    static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
    {
        List <NPipeImportFile> listOfImportableAssets = new List <NPipeImportFile>();
        bool importedSomething = false;

        listOfImportableAssets.AddRange(RetryFiles.Values);
        RetryFiles.Clear();

        // gather list
        foreach (var asset in importedAssets)
        {
            if (!File.Exists(asset))
            {
                continue;
            }
            // string uuid = AssetDatabase.AssetPathToGUID(asset);
            string extension = Path.GetExtension(asset);

            if (extension == ".asset")
            {
                Object[]       allAssets = AssetDatabase.LoadAllAssetsAtPath(asset);
                NPipeContainer container = NPipelineUtils.GetContainer(allAssets);
                if (container)
                {
                    container.OnImport();
                }

                NPipeIImportable[] importables = NPipelineUtils.GetImportables(allAssets);
                NPipeIImportable[] ordered     = NPipelineUtils.FindOutputPipes(importables); // those should be sufficient as they will import all the pipes they depend on anyway

                if (ordered.Length > 0)
                {
                    NPipeImportFile file = new NPipeImportFile();
                    file.importables = ordered;
                    file.Path        = asset;
                    file.Container   = container;
                    listOfImportableAssets.Add(file);
                    importedSomething = true;
                }
            }
        }


        if (!importedSomething)
        {
            return;
        }

        if (importedSomething)
        {
            int lengthBefore = listOfImportableAssets.Count;
            listOfImportableAssets.Sort(new NPipeImportFileComparer());
            Assert.AreEqual(lengthBefore, listOfImportableAssets.Count);

            string plan  = "--------======== NPipeline Import Plan ( " + listOfImportableAssets.Count + " files ) =======-------\n";
            int    count = 1;
            foreach (NPipeImportFile importFile in listOfImportableAssets)
            {
                plan += string.Format(" - {0}. {1} ({2} Importables) \n", count++, importFile.Path, importFile.importables.Length);
            }
            Debug.Log(plan);

            foreach (NPipeImportFile importFile in listOfImportableAssets)
            {
                foreach (NPipeIImportable importable in importFile.importables)
                {
                    Assert.IsNotNull(importable);
                    if (((UnityEngine.Object)importable))
                    {
                        try
                        {
                            importable.Import();
                            importedSomething = true;
                        }
                        catch (NPipeException e)
                        {
                            Debug.LogWarning("Got Exception " + e.Message + " importing a pipe in " + importFile.Path + " (THIS IS ONLY A PROBLEM IF THERE IS NO SUCCESSFUL REPORT FOLLOWING) - ELSE RESTART UNITY");

                            NPipeImportFile file = RetryFiles.ContainsKey(importFile.Path) ? RetryFiles[importFile.Path] :  new NPipeImportFile();
                            file.Path      = importFile.Path;
                            file.Container = importFile.Container;
                            if (file.importables == null)
                            {
                                file.importables = new NPipeIImportable[0];
                            }
                            ArrayUtility.Add(ref file.importables, importable);
                            RetryFiles[file.Path] = file;
                        }
                    }
                }
            }

            AssetDatabase.SaveAssets();
//            AssetDatabase.Refresh();
        }
    }
Esempio n. 7
0
    public override void OnInspectorGUI()
    {
        GUIStyle boldStyle = new GUIStyle();

        boldStyle.fontStyle = FontStyle.Bold;

        NPVoxAnimation animation = (NPVoxAnimation)target;

        GUILayout.Label("NPVox Animation: " + animation.name);

        GUILayout.Label("Tools:");
        GUILayout.BeginHorizontal();
        if (GUILayout.Button("Invalidate & Reimport All"))
        {
            NPipelineUtils.InvalidateAndReimportAll(animation);
        }
        if (GUILayout.Button("Invalidate & Reimport All Deep"))
        {
            NPipelineUtils.InvalidateAndReimportAllDeep(animation);
        }
        GUILayout.EndHorizontal();

        if (GUILayout.Button("Edit Animation"))
        {
            OpenAnimationScene(animation);
        }

        if (animation.Frames != null && animation.Frames.Length > 0 && animation.Frames[0].Source != null)
        {
            NPVoxModel model = animation.Frames[0].Source.GetProduct();

            if (model != null && model.SocketNames.Length > 0)
            {
                EditorGUILayout.BeginHorizontal();
                selectedTargetSocket = NPipeGUILayout.Popup(model.SocketNames, model.SocketNames, selectedTargetSocket, true);
                selectedModelFactory = NPipelineUtils.DrawSourceSelector <NPVoxIModelFactory>("Input:", selectedModelFactory);

                if (selectedModelFactory != null && selectedModelFactory.GetProduct())
                {
                    selectedInputSocket = NPipeGUILayout.Popup(selectedModelFactory.GetProduct().SocketNames, selectedModelFactory.GetProduct().SocketNames, selectedInputSocket, true);
                }

                if (GUILayout.Button("Create Slave Animation") && selectedModelFactory != null)
                {
                    createSlaveAnimation(animation, selectedTargetSocket, selectedModelFactory, selectedInputSocket);
                }

                if (GUILayout.Button("Create Slave Animation From Preview") && selectedModelFactory != null)
                {
                    createSlaveAnimationFromPreview(animation, selectedModelFactory);
                }

                EditorGUILayout.EndHorizontal();
            }
        }

        EditorGUILayout.Space();
        EditorGUILayout.Space();

        GUILayout.Label("Animation Default Settings", boldStyle);
        DrawDefaultInspector();

        EditorGUILayout.Space();
        EditorGUILayout.Space();

        // Mesh Output Settings

        GUILayout.Label("Mesh Output Settings", boldStyle);
        if (animation.MeshFactory.DrawInspector(~NPipeEditFlags.TOOLS & ~NPipeEditFlags.INPUT))
        {
            // Cascade to all frames
            foreach (NPVoxFrame frame in animation.Frames)
            {
                frame.Output.BloodColorIndex         = animation.MeshFactory.BloodColorIndex;
                frame.Output.Cutout                  = animation.MeshFactory.Cutout;
                frame.Output.Loop                    = animation.MeshFactory.Loop;
                frame.Output.NormalMode              = animation.MeshFactory.NormalMode;
                frame.Output.NormalVariance          = animation.MeshFactory.NormalVariance;
                frame.Output.NormalVarianceSeed      = animation.MeshFactory.NormalVarianceSeed;
                frame.Output.VoxelSize               = animation.MeshFactory.VoxelSize;
                frame.Output.StorageMode             = animation.MeshFactory.StorageMode;
                frame.Output.MinVertexGroups         = animation.MeshFactory.MinVertexGroups;
                frame.Output.NormalModePerVoxelGroup = animation.MeshFactory.NormalModePerVoxelGroup;
            }
        }


        // Destroy unconnected things

        NPipeIImportable[] importables = NPipelineUtils.GetImportables(AssetDatabase.GetAssetPath(animation));
        foreach (NPipeIImportable importable in importables)
        {
            NPipeIImportable prev = NPipelineUtils.FindPreviousOfType <NPVoxIModelFactory>(importable);
            if ((importable as NPVoxMeshOutput) != animation.MeshFactory && (prev == null || prev == importable))
            {
                Debug.LogWarning("Destroying orphaning importable: " + importable);
                if (importable is  NPipeIComposite)
                {
                    ((NPipeIComposite)importable).Input = null;
                }
                importable.Destroy(); // destroy the product
                Undo.DestroyObjectImmediate((UnityEngine.Object)importable);
            }
        }
    }