Exemplo n.º 1
0
    private void createSlaveAnimationFromPreview(NPVoxAnimation animation, NPVoxIModelFactory inputModelFactory)
    {
        var path = NPipelineUtils.GetCreateScriptableObjectAssetPath <NPVoxAnimation>(AssetDatabase.LoadMainAssetAtPath(AssetDatabase.GetAssetPath(inputModelFactory as Object)).name + "_" + animation.name);

        if (path.Length != 0)
        {
            NPVoxAnimation slaveAnimation = NPipelineUtils.CreatePipeContainer <NPVoxAnimation>(path);
            foreach (NPVoxFrame sourceFrame in animation.Frames)
            {
                NPVoxFrame targetFrame = slaveAnimation.AppendFrame();

                NPVoxSocketAttachment attachment = sourceFrame.GetPreviewAttachmentForFactory(inputModelFactory);
                if (attachment == null)
                {
                    Debug.LogWarning("no attachment found for the given model factory");
                    continue;
                }

                targetFrame.Source = inputModelFactory;
                NPVoxModelSocketCombiner combiner = NPVoxModelSocketCombiner.CreateInstance <NPVoxModelSocketCombiner>();

                if (!sourceFrame.PreOutput)
                {
                    sourceFrame.FixStuff();
                }
                combiner.Target           = sourceFrame.PreOutput;
                combiner.InputSocketName  = attachment.sourceSocketName;
                combiner.TargetSocketName = attachment.targetSocketName;
                targetFrame.AppendTransformer(combiner);
            }

            Selection.objects = new Object[] { slaveAnimation };
        }
    }
Exemplo n.º 2
0
    private void createSlaveAnimation(NPVoxAnimation animation, string targetSocket, NPVoxIModelFactory inputModelFactory, string inputSocket)
    {
        var path = NPipelineUtils.GetCreateScriptableObjectAssetPath <NPVoxAnimation>(AssetDatabase.LoadMainAssetAtPath(AssetDatabase.GetAssetPath(inputModelFactory as Object)).name + "_" + targetSocket + "_" + animation.name);

        if (path.Length != 0)
        {
            NPVoxAnimation slaveAnimation = NPipelineUtils.CreatePipeContainer <NPVoxAnimation>(path);
            foreach (NPVoxFrame sourceFrame in animation.Frames)
            {
                NPVoxFrame targetFrame = slaveAnimation.AppendFrame();
                targetFrame.Source = inputModelFactory;
                NPVoxModelSocketCombiner combiner = NPVoxModelSocketCombiner.CreateInstance <NPVoxModelSocketCombiner>();

                if (!sourceFrame.PreOutput)
                {
                    sourceFrame.FixStuff();
                }
                combiner.Target           = sourceFrame.PreOutput;
                combiner.InputSocketName  = inputSocket;
                combiner.TargetSocketName = targetSocket;
                targetFrame.AppendTransformer(combiner);
            }

            Selection.objects = new Object[] { slaveAnimation };
        }
    }
Exemplo n.º 3
0
    private void UpdateCharacters()
    {
        if (Characters.Length != 128)
        {
            Characters = new Character[128];
        }
        for (int i = 0; i < 128; i++)
        {
            Character             character  = Characters[i];
            Object[]              allAssets  = UnityEditor.AssetDatabase.LoadAllAssetsAtPath(FontFolder + "/" + i + ".asset");
            NPVoxCubeSimplifier[] simplifier = NPipelineUtils.GetByType <NPVoxCubeSimplifier>(allAssets);
            if (simplifier.Length == 1)
            {
//                Debug.Log("found character: " + simplifier[0]);
                character.material = simplifier[0].GetAtlasMaterial();
                character.mesh     = simplifier[0].GetProduct();
                if (simplifier[0].InputMeshFactory)
                {
                    character.VoxelSize = simplifier[0].InputMeshFactory.VoxelSize;
                    character.Size      = simplifier[0].InputMeshFactory.GetVoxModel().Size;
                }
            }
            else
            {
                character.mesh     = null;
                character.material = null;
            }

            Characters[i] = character;
        }
    }
Exemplo n.º 4
0
    virtual public bool DrawInspector(NPipeEditFlags flags)
    {
        UnityEditor.Editor editor = UnityEditor.Editor.CreateEditor(this);
        bool changed = editor.DrawDefaultInspector();

        if ((flags & NPipeEditFlags.INPUT) == NPipeEditFlags.INPUT)
        {
            SOURCE_FACTORY newSource = NPipelineUtils.DrawSourceSelector <SOURCE_FACTORY>("Input", input as SOURCE_FACTORY);
            if (newSource as  NPVoxForwarderBase <SOURCE_FACTORY, PRODUCT> == this)
            {
                return(false);
            }
            changed = newSource != Input || changed;
            Input   = (NPipeIImportable)newSource;
        }

        // if((flags & NPVoxEditFlags.TOOLS) == NPVoxEditFlags.TOOLS)
        // {
        //     if(GUILayout.Button("Invalidate & Reimport Mesh Output Deep"))
        //     {
        //         NPVoxPipelineUtils.InvalidateAndReimportDeep( this );
        //     }
        // }

        return(changed);
    }
Exemplo n.º 5
0
    override public bool DrawInspector(NPipeEditFlags flags)
    {
        bool changed = base.DrawInspector(flags);

        if ((flags & NPipeEditFlags.INPUT) == NPipeEditFlags.INPUT)
        {
            SOURCE_FACTORY newSource = NPipelineUtils.DrawSourceSelector <SOURCE_FACTORY>("Input", input as SOURCE_FACTORY);
            if (newSource as NPVoxCompositeProcessorBase <SOURCE_FACTORY, PRODUCT> == this)
            {
                return(false);
            }
            changed = newSource != Input || changed;
            Input   = (NPipeIImportable)newSource;
        }

        if ((flags & NPipeEditFlags.TOOLS) == NPipeEditFlags.TOOLS)
        {
            if (GUILayout.Button("Invalidate & Reimport Deep"))
            {
                NPipelineUtils.InvalidateAndReimportDeep(this);
            }
        }

        return(changed);
    }
Exemplo n.º 6
0
 // [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);
 }
 public void DebugButton()
 {
     if (PreviewMeshOutput == null)
     {
         Debug.LogError("No PreviewMeshOutput!!!");
     }
     Debug.Log("PreviewMeshOutput: " + NPipelineUtils.GetPipelineDebugString(PreviewMeshOutput, true));
 }
Exemplo n.º 8
0
    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);
    }
    static void CreateAnimation()
    {
        var path = NPipelineUtils.GetCreateScriptableObjectAssetPath <NPVoxAnimation>();

        if (path.Length != 0)
        {
            Selection.objects = new Object[] { NPipelineUtils.CreatePipeContainer <NPVoxAnimation>(path) };
        }
    }
    public override void OnInspectorGUI()
    {
        NPVoxCubeSimplifierInstance instance = (NPVoxCubeSimplifierInstance)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;
        }

        instance.UpdateMesh();

        DrawDefaultInspector();

        if (instance.CubeSimplifier == null)
        {
            GUILayout.Label("NPVox: No NP Vox Cube Simplifier assigned.");
            return;
        }

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

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

        // NPVoxMeshOutput[] meshOutputs = NPipelineUtils.GetByType<NPVoxMeshOutput>(instance.CubeSimplifier as UnityEngine.Object);

        // if (meshOutputs.Length > 0)
        {
            if (GUILayout.Button("Switch to Mesh Output Instance"))
            {
                NPVoxMeshInstance meshOutputInstance = instance.gameObject.AddComponent <NPVoxMeshInstance>();
                meshOutputInstance.MeshFactory = (NPVoxMeshOutput)instance.CubeSimplifier.InputMeshFactory;
                meshOutputInstance.UpdateMesh();
                instance.gameObject.GetComponent <MeshRenderer>().sharedMaterial = instance.CubeSimplifier.SourceMaterial;
                DestroyImmediate(instance, true);
                return;
            }
        }

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

        if (GUILayout.Button("Invalidate Pipe Container Deep "))
        {
            NPipelineUtils.InvalidateAndReimportAllDeep(AssetDatabase.LoadAssetAtPath(AssetDatabase.GetAssetPath(instance.CubeSimplifier), typeof(NPipeContainer)));
        }
    }
Exemplo n.º 11
0
 static void MenuInvalidateAndImportSelectedDeep()
 {
     foreach (UnityEngine.Object target in Selection.objects)
     {
         NPipeIImportable[] allImportables = NPipelineUtils.FindOutputPipes(NPipelineUtils.GetByType <NPipeIImportable>(target));
         NPipelineUtils.InvalidateAll(allImportables, true);
         EditorUtility.SetDirty(target as UnityEngine.Object);
     }
     AssetDatabase.SaveAssets();
 }
Exemplo n.º 12
0
    static void CreateNPVoxFont()
    {
        var path = NPipelineUtils.GetCreateScriptableObjectAssetPath <NPVoxFont>();

        if (path.Length != 0)
        {
            NPVoxFont npVoxFont = (NPVoxFont)NPipeContainer.CreateInstance(typeof(NPVoxFont));
            UnityEditor.AssetDatabase.CreateAsset(npVoxFont, path);
            UnityEditor.AssetDatabase.SaveAssets();
            UnityEditor.Selection.objects = new Object[] { npVoxFont };
        }
    }
Exemplo n.º 13
0
    override public void OnAssetCreated()
    {
        base.OnAssetCreated();
        NPVoxMeshOutput output = NPipelineUtils.GetByType <NPVoxMeshOutput>(NPVoxUtils.GetTemplatePipeline())[0];

        MeshFactory              = (NPVoxMeshOutput)output.Clone();
        MeshFactory.StorageMode  = NPipeStorageMode.RESOURCE_CACHE;
        MeshFactory.Input        = null;
        MeshFactory.InstanceName = "_TEMPLATE_";
        NPipelineUtils.CreateAttachedPipe(UnityEditor.AssetDatabase.GetAssetPath(this), MeshFactory);
        UnityEditor.AssetDatabase.SaveAssets();
    }
Exemplo n.º 14
0
    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 CreateTextureAtlas()
    {
        var path = NPipelineUtils.GetCreateScriptableObjectAssetPath <NPVoxTextureAtlas>();

        if (path.Length != 0)
        {
            NPVoxTextureAtlas textureAtlas = (NPVoxTextureAtlas)NPVoxTextureAtlas.CreateInstance(typeof(NPVoxTextureAtlas));
            AssetDatabase.CreateAsset(textureAtlas, path);
            AssetDatabase.SaveAssets();
            textureAtlas.InitAssets();
            AssetDatabase.SaveAssets();
            Selection.objects = new Object[] { textureAtlas };
        }
    }
Exemplo n.º 16
0
    public static NPipeIImportable CloneRecursive(NPipeIImportable[] allImportables, NPipeIImportable sourcePipe, string targetPath)
    {
        NPipeIImportable clone = (NPipeIImportable)sourcePipe.Clone();

        NPipelineUtils.CreateAttachedPipe(targetPath, clone);

        if (clone is NPipeIComposite)
        {
            NPipeIImportable sourceOfSource = ((NPipeIComposite)clone).Input;
            if (ArrayUtility.IndexOf(allImportables, sourceOfSource) > -1)
            {
                ((NPipeIComposite)clone).Input = (NPipeIImportable)CloneRecursive(allImportables, sourceOfSource, targetPath);
            }
        }
        return(clone);
    }
Exemplo n.º 17
0
    static void MakeVoxPrefabs()
    {
        var path = EditorUtility.SaveFolderPanel(
            "Select target folder for the generated Prefabs ",
            "Prefabs",
            "Select Path for the generated Prefabs");

        path = path.Remove(0, path.LastIndexOf("Assets"));

        if (path.Length != 0)
        {
            Object[] SelectedObjects = Selection.objects;
            int      generatedCount  = 0;
            foreach (Object o in SelectedObjects)
            {
                NPipeContainer container = o as NPipeContainer;
                if (!container)
                {
                    continue;
                }
                NPVoxMeshOutput[] output = NPipelineUtils.GetByType <NPVoxMeshOutput>(container);
                foreach (NPVoxMeshOutput pipe in output)
                {
                    NPVoxMeshInstance instance = pipe.Instatiate().GetComponent <NPVoxMeshInstance>();

                    string prefabPath = Path.Combine(path, instance.name) + ".prefab";

                    PrefabUtility.CreatePrefab(prefabPath, instance.gameObject);
                    GameObject.DestroyImmediate(instance.gameObject);
                    generatedCount++;
                }
            }

            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();

            if (generatedCount > 0)
            {
                Debug.Log("Generated " + generatedCount + " Prefabs");
            }
            else
            {
                Debug.LogWarning("No NPVoxMetadata selected");
            }
        }
    }
Exemplo n.º 18
0
 public int Compare(NPipeImportFile x, NPipeImportFile y)
 {
     foreach (NPipeIImportable xImportable in x.importables)
     {
         foreach (NPipeIImportable yImportable in y.importables)
         {
             if (NPipelineUtils.IsPrevious(xImportable, yImportable, true))
             {
                 return(1);
             }
             if (NPipelineUtils.IsPrevious(yImportable, xImportable, true))
             {
                 return(-1);
             }
         }
     }
     return(0);
 }
Exemplo n.º 19
0
    public NPVoxFrame(NPVoxAnimation animation)
    {
        this.animation = animation;

        output           = (NPVoxMeshOutput)animation.MeshFactory.Clone();
        output.hideFlags = HideFlags.HideInHierarchy;

//        Debug.Log("invalidating");
#if UNITY_EDITOR
        AssetDatabase.AddObjectToAsset(output, AssetDatabase.GetAssetPath(animation));
        preOutput = (NPVoxModelForwarder)NPVoxModelForwarder.CreateInstance <NPVoxModelForwarder>();
        NPipelineUtils.CreateAttachedPipe(AssetDatabase.GetAssetPath(animation), preOutput);
        preOutput.Input = null;
#endif
        output.Input = preOutput;
        output.Invalidate();
        preOutput.Invalidate();
    }
Exemplo n.º 20
0
    private void DrawModelSelection()
    {
        if (viewModel.SelectedFrame == null)
        {
            return;
        }
        viewModel.SelectedFrame.Duration = EditorGUILayout.FloatField("Duration", viewModel.SelectedFrame.Duration);
        GUILayout.BeginHorizontal();
//        GUILayout.Label("Frame " + ( viewModel.SelectedFrameIndex + 1 ) + " : ");
        // NPVoxModelPipeBase modelFactory = (NPVoxModelPipeBase)EditorGUILayout.ObjectField(viewModel.SelectedFrame.Source, typeof(NPVoxModelPipeBase), false);
        NPVoxIModelFactory modelFactory = (NPVoxIModelFactory)NPipelineUtils.DrawSourceSelector <NPVoxIModelFactory>("Source", viewModel.SelectedFrame.Source);

        if (modelFactory != viewModel.SelectedFrame.Source)
        {
            viewModel.SetFrameModel(viewModel.SelectedFrameIndex, modelFactory);
        }



        GUILayout.EndHorizontal();
    }
Exemplo n.º 21
0
    //======================================================================================================================================
    // Socket Tools
    //======================================================================================================================================

    private void DrawSocketTools()
    {
        EditorGUILayout.BeginVertical();
        if (viewModel.DrawSockets != EditorGUILayout.Toggle("Show Socket Axes In View", viewModel.DrawSockets))
        {
            viewModel.SetDrawSockets(!viewModel.DrawSockets);
        }

        foreach (string targetSocketName in viewModel.GetPreviewTargetSocketNames())
        {
            EditorGUILayout.BeginHorizontal();
            if (viewModel.GetPreviewSocketEnabled(targetSocketName) != EditorGUILayout.Toggle(viewModel.GetPreviewSocketEnabled(targetSocketName)))
            {
                viewModel.SetPreviewSocketEnabled(targetSocketName, !viewModel.GetPreviewSocketEnabled(targetSocketName));
            }
            NPVoxIMeshFactory selectedFactory    = viewModel.GetPreviewFactoryForTargetSocket(targetSocketName);
            NPVoxIMeshFactory newSelectedFactory = NPipelineUtils.DrawSourceSelector(targetSocketName, selectedFactory);
            if (selectedFactory != newSelectedFactory)
            {
                viewModel.SetPreviewFactoryForTargetSocket(targetSocketName, newSelectedFactory);
            }

            string[] sourceSockets = viewModel.GetSourceSocketsForTargetSocket(targetSocketName);
            if (sourceSockets == null || sourceSockets.Length == 0)
            {
                GUILayout.Label("No Socket");
            }
            else
            {
                string selectedSourceSocket    = viewModel.GetSourceSocketForTargetSocket(targetSocketName);
                string newSelectedSourceSocket = NPipeGUILayout.Popup(sourceSockets, sourceSockets, selectedSourceSocket, true);
                if (selectedSourceSocket != newSelectedSourceSocket)
                {
                    viewModel.SetSourceSocketForTargetSocket(targetSocketName, newSelectedSourceSocket);
                }
            }
            EditorGUILayout.EndHorizontal();
        }
        EditorGUILayout.EndVertical();
    }
Exemplo n.º 22
0
    public override void OnInspectorGUI()
    {
        // try to re-open similar importable to the last one
        if (editingImportable == null && lastEditingImportable != null)
        {
            string             warningMessage = "";
            NPipeIImportable[] imp            = NPipelineUtils.GetSimiliarPipes(new UnityEngine.Object[] { this.target }, this.target as NPipeContainer, lastEditingImportable, out warningMessage);
            if (imp.Length != 1)
            {
                lastEditingImportable = null;
            }
            else
            {
                editingImportable = imp[0];
            }
        }

        isMultiInstance = targets.Length > 1;

        // main inspectorr
        DrawPipelineElements();
    }
Exemplo n.º 23
0
    override public bool DrawMultiInstanceEditor(NPipeEditFlags flags, UnityEngine.Object[] objects)
    {
        bool changed = base.DrawMultiInstanceEditor(flags, objects);

        if ((flags & NPipeEditFlags.INPUT) == NPipeEditFlags.INPUT)
        {
            // input not supported when editing multiple instances
        }

        if ((flags & NPipeEditFlags.TOOLS) == NPipeEditFlags.TOOLS)
        {
            if (GUILayout.Button("Invalidate & Reimport Deep"))
            {
                foreach (UnityEngine.Object o in objects)
                {
                    NPipelineUtils.InvalidateAndReimportDeep(o as NPipeIImportable);
                }
            }
        }

        return(changed);
    }
Exemplo n.º 24
0
 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();
         }
     }
 }
Exemplo n.º 25
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)));
        }
    }
Exemplo n.º 26
0
    protected bool DrawPipelineElements()
    {
        //==================================================================================================================================
        // setup colors
        //==================================================================================================================================
        normalStyle = new GUIStyle((GUIStyle)"helpbox");
        normalStyle.normal.textColor = Color.black;
        normalStyle.fontStyle        = FontStyle.Normal;
        boldStyle = new GUIStyle((GUIStyle)"helpbox");
        boldStyle.normal.textColor = Color.black;
        boldStyle.fontStyle        = FontStyle.Bold;
        thisContainerColor         = new Color(0.8f, 1.0f, 0.6f);
        thisContainerMultiColor    = new Color(0.8f, 0.6f, 1.0f);

        string assetPath = AssetDatabase.GetAssetPath(target);

        NPipeIImportable[] allImportables = NPipelineUtils.GetByType <NPipeIImportable>(target);
        NPipeIImportable[] outputPipes    = NPipelineUtils.FindOutputPipes(allImportables);

        //==================================================================================================================================
        // Tool Buttons (Select Me, Invalidation)
        //==================================================================================================================================

        GUILayout.BeginHorizontal();
        if (GUILayout.Button("Select Me"))
        {
            Selection.objects = this.targets;
        }

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

        //==================================================================================================================================
        // Single Instance Mode Only for Lazyness Tool Buttons (Deleta all Payload, Instantiate)
        //==================================================================================================================================

        if (!this.isMultiInstance)
        {
            if (GUILayout.Button("Delete all Payload"))
            {
                UnityEngine.Object[] allObjects = AssetDatabase.LoadAllAssetsAtPath(assetPath);
                foreach (UnityEngine.Object obj in allObjects)
                {
                    if (!(obj is NPipeIImportable) && !(obj is NPipeContainer))
                    {
                        DestroyImmediate(obj, true);
                    }
                }
                EditorUtility.SetDirty(target);
            }

            foreach (NPipeIImportable imp in allImportables)
            {
                if (imp is NPipeIInstantiable && GUILayout.Button("Instantiate " + imp.GetInstanceName() + " (" + imp.GetTypeName() + ")"))
                {
                    ((NPipeIInstantiable)imp).Instatiate();
                }
            }
        }

        //==================================================================================================================================
        // Draw Pipelines
        //==================================================================================================================================
        {
            GUILayout.Space(10f);

            // headline
            GUILayout.Label(string.Format("Pipelines", allImportables.Length), EditorStyles.boldLabel);

            // pipelines
            GUILayout.BeginHorizontal();
            HashSet <NPipeIImportable> visited = new HashSet <NPipeIImportable>();
            foreach (NPipeIImportable iimp in outputPipes)
            {
                DrawPipelineElements(assetPath, iimp, visited, false);
            }

            GUI.backgroundColor = isMultiInstance ? thisContainerMultiColor : thisContainerColor;

            if (!isMultiInstance)
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label("Add: ");
                {
                    GUILayout.BeginVertical();
                    foreach (Type factoryType in NPipeReflectionUtil.GetAllTypesWithAttribute(typeof(NPipeStartingAttribute)))
                    {
                        NPipeStartingAttribute attr = (NPipeStartingAttribute)factoryType.GetCustomAttributes(typeof(NPipeStartingAttribute), true)[0];
                        if (attr.attached && GUILayout.Button(attr.name))
                        {
                            NPipelineUtils.CreateAttachedPipe(assetPath, factoryType);
                        }
                    }

                    List <System.Type> allTypes  = new List <System.Type>(NPipeReflectionUtil.GetAllTypesWithAttribute(typeof(NPipeAppendableAttribute)));
                    List <string>      allLabels = new List <string>();
                    allLabels.Add("Other ...");
                    foreach (Type factoryType in allTypes)
                    {
                        NPipeAppendableAttribute attr = (NPipeAppendableAttribute)factoryType.GetCustomAttributes(typeof(NPipeAppendableAttribute), true)[0];
                        allLabels.Add(attr.name);
                    }
                    int selection = EditorGUILayout.Popup(0, allLabels.ToArray());
                    if (selection > 0)
                    {
                        NPipelineUtils.CreateAttachedPipe(assetPath, allTypes[selection - 1]);
                    }
                    GUILayout.EndVertical();
                }
                GUILayout.EndHorizontal();
            }
            GUILayout.EndHorizontal();
        }

        drawPipeEditor(assetPath);

        return(false);
    }
Exemplo n.º 27
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();
        }
    }
Exemplo n.º 28
0
    // ===================================================================================================
    // Inspector UI
    // ===================================================================================================

    public override void OnInspectorGUI()
    {
        if (!viewModel.IsPlaying && wasPreview)
        {
            // workaround for stupid "getting control 5" exception
            wasPreview = false;
            Repaint();
            return;
        }

        viewModel.ProcessInvalidations();

        NPVoxAnimationEditorSession session = ((NPVoxAnimationEditorSession)target);

        EditorGUILayout.BeginVertical();

        EditorGUILayout.BeginHorizontal();
        if (GUILayout.Button("Close Editor") || !session.animation)
        {
            NPVoxAnimationEditor.CloseAnimationEditor(session);
        }
        if (GUILayout.Button("Debug"))
        {
            viewModel.DebugButton();
        }
        if (GUILayout.Button("Invalidate & Reimport All"))
        {
            NPipelineUtils.InvalidateAndReimportAll(session.animation);
        }
        if (GUILayout.Button("Invalidate & Reimport All Deep"))
        {
            NPipelineUtils.InvalidateAndReimportAllDeep(session.animation);
        }
        if (GUILayout.Button("Help"))
        {
            NPVoxAnimHelpWindow.ShowWindow();
        }
        EditorGUILayout.EndHorizontal();

        GUILayout.Label("Preview: ", EditorStyles.boldLabel);
        DrawPreview();

        if (!viewModel.IsPlaying)
        {
            GUILayout.Space(10);

            GUILayout.Label("Frames: ", EditorStyles.boldLabel);

            DrawFrameSelection();
            GUILayout.Space(10);
            DrawModelSelection();
            DrawTransformationSelector();
            GUILayout.Space(10);

            GUILayout.Label("Presentation: ", EditorStyles.boldLabel);
            DrawModeToolbar();
            DrawSocketTools();
        }
        else
        {
//            Debug.Log("playing");
            DrawFrameList();
        }
        DrawMaterialSelection();

        session.groundplateOffset = EditorGUILayout.FloatField("Ground Offset", session.groundplateOffset);
        EditorGUILayout.EndVertical();

        if (meshRefreshRequested)
        {
            meshRefreshRequested = false;
            UpdateMeshes();
            SceneView.RepaintAll();
        }

        // unfocus by pressing escape
        Event e = Event.current;

        if (e.isKey && e.keyCode == KeyCode.Escape)
        {
            unfocus();
        }

        // ground plate
        if (viewModel.SelectedFrame != null && viewModel.SelectedFrame.Source != null && session.groundFilter)
        {
            NPVoxModel   model = viewModel.SelectedFrame.Source.GetProduct();
            NPVoxToUnity n2u   = new NPVoxToUnity(model, viewModel.Animation.MeshFactory.VoxelSize);
            Vector3      pos   = n2u.ToUnityPosition(new Vector3(model.BoundingBox.SaveCenter.x, model.BoundingBox.SaveCenter.y, model.BoundingBox.Forward + 1));
            session.groundFilter.transform.position = pos + Vector3.forward * session.groundplateOffset;
        }

        KeyboardShortcuts();
    }
Exemplo n.º 29
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);
            }
        }
    }
Exemplo n.º 30
0
    public void FixStuff()
    {
        #if UNITY_EDITOR
        if (!preOutput)
        {
            Debug.LogWarning("Added Preoutput");
            preOutput = (NPVoxModelForwarder)NPVoxModelForwarder.CreateInstance <NPVoxModelForwarder>();

            NPipelineUtils.CreateAttachedPipe(AssetDatabase.GetAssetPath(animation), preOutput);
//            AssetDatabase.AddObjectToAsset(preOutput, AssetDatabase.GetAssetPath(animation));
            preOutput.Invalidate();
            EditorUtility.SetDirty(animation);
        }

        if (output.Input == null || output.Input != preOutput as NPipeIImportable)
        {
            Debug.LogWarning("Fixed output");
            output.Input = preOutput;
            output.Invalidate();
            EditorUtility.SetDirty(animation);
        }

        int invalidateFrom = -1;
        for (int i = 0; i < this.transformers.Length; i++)
        {
            if (i == 0)
            {
                if (((NPipeIComposite)this.transformers[i]).Input != Source)
                {
                    ((NPipeIComposite)this.transformers[i]).Input = Source;
                    if (invalidateFrom == -1 || invalidateFrom > i)
                    {
                        invalidateFrom = i;
                    }
                    Debug.LogWarning("Fixed source of transformer 0");
                }
            }
            else
            {
                if (((NPipeIComposite)this.transformers[i]).Input != ((NPipeIComposite)this.transformers[i - 1]))
                {
                    ((NPipeIComposite)this.transformers[i]).Input = ((NPipeIComposite)this.transformers[i - 1]);
                    if (invalidateFrom == -1 || invalidateFrom > i)
                    {
                        invalidateFrom = i;
                    }
                    Debug.LogWarning("Fixed source of transformer " + i);
                }
            }
        }

        if (transformers.Length > 0)
        {
            if (preOutput.Input != ((NPipeIComposite)this.transformers[transformers.Length - 1]))
            {
                if (invalidateFrom == -1)
                {
                    invalidateFrom = transformers.Length;
                }
                preOutput.Input = ((NPipeIComposite)this.transformers[transformers.Length - 1]);
                Debug.LogWarning("Fixed source of preOutput");
            }
        }
        else if (preOutput.Input != Source)
        {
            preOutput.Input = Source;
            Debug.LogWarning("Fixed source of preOutput");
        }

        if (invalidateFrom > -1)
        {
            this.InvalidateFromStep(invalidateFrom);
        }
        #endif
    }