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)));
        }
    }
Esempio n. 2
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. 3
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);
            }
        }
    }
Esempio n. 4
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();
    }
Esempio n. 5
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);
    }