Ejemplo n.º 1
0
    override public bool DrawInspector(NPipeEditFlags flags)
    {
        bool changed = base.DrawInspector(flags);

        NPVoxIModelFactory modelFactory = Input as NPVoxIModelFactory;

        if (modelFactory != null)
        {
            string[] socketNames = modelFactory.GetProduct().SocketNames;
            if (socketNames == null || socketNames.Length == 0)
            {
                GUILayout.Label("No Socket");
            }
            else
            {
                string newSocketName = NPipeGUILayout.Toolbar(socketNames, socketNames, SocketName);
                if (SocketName != newSocketName)
                {
                    SocketName = newSocketName;
                    changed    = true;
                }
            }
        }

        if (changed && (string.IsNullOrEmpty(InstanceName) || InstanceName.StartsWith("SocketT ")))
        {
            InstanceName = "SocketT " + SocketName;
        }

        return(changed);
    }
Ejemplo n.º 2
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();
    }
Ejemplo n.º 3
0
    void OnGUI()
    {
        if (m_context != null && m_context.IsValid)
        {
            EnableSceneObjects(true);

            // store previous UI states to process state switches later
            int cameraTypePrevious = m_cameraType;

            // Setup styles
            GUIStyle noStretch = new GUIStyle();
            noStretch.stretchWidth  = false;
            noStretch.stretchHeight = false;
            GUILayoutOption[] noFill          = { GUILayout.ExpandWidth(false), GUILayout.ExpandHeight(false) };
            GUILayoutOption[] fill            = { GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true) };
            float             widthWideButton = 203f;

            // Draw GUI
            GUILayout.BeginHorizontal(GUILayout.ExpandWidth(false));

            // Draw navigation tool bar
            GUILayout.BeginVertical(noStretch, noFill);
            GUILayout.Label(m_title, noFill);
            GUILayout.Space(8.0f);
            m_cameraType = NPipeGUILayout.Toolbar("Camera: ", m_cameraType, new string[] { "Free", "Orbit" }, noFill);
            GUILayout.Space(8.0f);
            GUILayout.Label("Sensitivity:", noFill);
            float fLabelWidthSliders = 50.0f;
            m_sensitivityOrient = NPipeGUILayout.HorizontalSlider("Rotate:", fLabelWidthSliders, m_sensitivityOrient, 0.01f, 1.0f, GUILayout.Width(100.0f)); GUILayout.Space(-6);
            m_sensitivityDrag   = NPipeGUILayout.HorizontalSlider("Pan:", fLabelWidthSliders, m_sensitivityDrag, 0.01f, 0.1f, GUILayout.Width(100.0f)); GUILayout.Space(-6);
            m_sensitivityZoom   = NPipeGUILayout.HorizontalSlider("Zoom:", fLabelWidthSliders, m_sensitivityZoom, 0.01f, 1.0f, GUILayout.Width(100.0f)); GUILayout.Space(-6);

            GUILayout.Space(16.0f);

            GUILayout.BeginHorizontal(noStretch, GUILayout.ExpandWidth(false));
            if (GUILayout.Button(m_previewGUIDrawOutlines ? "Hide Outlines" : "Show Outlines", GUILayout.Width(widthWideButton * 0.5f - 2)))
            {
                m_previewGUIDrawOutlines = !m_previewGUIDrawOutlines;
            }
            if (GUILayout.Button(m_previewGUIDrawNormals ? "Hide Normals" : "Show Normals", GUILayout.Width(widthWideButton * 0.5f - 2)))
            {
                m_previewGUIDrawNormals = !m_previewGUIDrawNormals;
            }
            GUILayout.EndHorizontal();

            // Draw internal gui
            OnGUIInternal();

            GUILayout.EndVertical();

            // Draw preview
            GUILayout.Box("", fill);
            m_sceneRect = GUILayoutUtility.GetLastRect();
            DrawScene(m_sceneRect);
            GUILayout.EndHorizontal();

            EnableSceneObjects(false);

            UpdateInput();

            // Process GUI state switches
            if (cameraTypePrevious != m_cameraType)
            {
                InitCamera();
            }
        }
        else
        {
            GUILayout.Label("Invalid preview context!");
        }
    }
Ejemplo n.º 4
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);
            }
        }
    }
Ejemplo n.º 5
0
    protected override void OnGUIInternal()
    {
        GUIStyle noStretch = new GUIStyle();

        noStretch.stretchWidth  = false;
        noStretch.stretchHeight = false;
        GUILayoutOption widthSmallButton = GUILayout.Width(65);
        GUILayoutOption widthWideButton  = GUILayout.Width(203);

        GUILayoutOption[] noFill         = { GUILayout.ExpandWidth(false), GUILayout.ExpandHeight(false) };
        GUILayoutOption[] fill           = { GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true) };
        Color             bgColorWarning = new Color(0.8f, 0.3f, 0.3f);
        Color             bgColorTarget  = new Color(0.9f, 0.4f, 0.4f);
        Color             bgColorInput   = new Color(0.5f, 0.7f, 0.9f);

        if (m_context.ViewedProcessor.IsOutputValid())
        {
            if (GUILayout.Button(m_previewHighlightOverrides ? "Unhighlight Overrides" : "Highlight Overrides", widthWideButton))
            {
                m_previewHighlightOverrides = !m_previewHighlightOverrides;
            }

            GUILayout.Space(8.0f);

            // Last selected voxel info
            GUILayout.Space(12.0f);
            string selectedCoord   = "-";
            string selectedNormalX = "-";
            string selectedNormalY = "-";
            string selectedNormalZ = "-";
            string selectedVIndex  = "-";

            if (m_lastSelected.Valid && m_lastSelectedData != null)
            {
                selectedCoord  = m_lastSelected.X + " " + m_lastSelected.Y + " " + m_lastSelected.Z;
                selectedVIndex = m_lastSelectedData.vertexIndexOffsetBegin.ToString();
                Vector3 normal = m_context.PreviewMesh.normals[m_lastSelectedData.vertexIndexOffsetBegin];
                selectedNormalX = normal.x.ToString();
                selectedNormalY = normal.y.ToString();
                selectedNormalZ = normal.z.ToString();
            }

            int labelWidth = 65, columnWidth = 150, columnSpace = -5;
            GUILayout.Label("Last Selected:", noFill);
            NPipeGUILayout.TableRow("Coord:", labelWidth, columnSpace, new NPipeGUILayout.TableColumn(selectedCoord, columnWidth));
            NPipeGUILayout.TableRow("v-Index:", labelWidth, columnSpace, new NPipeGUILayout.TableColumn(selectedVIndex, columnWidth));
            NPipeGUILayout.TableRow("Normal X:", labelWidth, columnSpace, new NPipeGUILayout.TableColumn(selectedNormalX, columnWidth));
            NPipeGUILayout.TableRow("Normal Y:", labelWidth, columnSpace, new NPipeGUILayout.TableColumn(selectedNormalY, columnWidth));
            NPipeGUILayout.TableRow("Normal Z:", labelWidth, columnSpace, new NPipeGUILayout.TableColumn(selectedNormalZ, columnWidth));
            GUILayout.Space(12.0f);

            // General selection related controls
            if (GUILayout.Button("RESET SELECTION (Esc)", widthWideButton))
            {
                ResetSelection();
            }

            // Input field related controls
            Color currentColor = GUI.backgroundColor;
            GUI.backgroundColor = bgColorInput;
            GUILayout.Label("INPUT:", noFill);
            GUILayout.Space(-3);
            m_normalField = EditorGUILayout.Vector3Field("", m_normalField, noFill);
            GUILayout.Space(-3);
            GUILayout.BeginHorizontal(noStretch, noFill);
            if (GUILayout.Button("RIGHT", widthSmallButton))
            {
                m_normalField = Vector3.right;
            }
            if (GUILayout.Button("UP", widthSmallButton))
            {
                m_normalField = Vector3.up;
            }
            if (GUILayout.Button("FWD", widthSmallButton))
            {
                m_normalField = Vector3.forward;
            }
            GUILayout.EndHorizontal();
            GUILayout.Space(-4);
            GUILayout.BeginHorizontal(noStretch, noFill);
            if (GUILayout.Button("LEFT", widthSmallButton))
            {
                m_normalField = Vector3.left;
            }
            if (GUILayout.Button("DOWN", widthSmallButton))
            {
                m_normalField = Vector3.down;
            }
            if (GUILayout.Button("BACK", widthSmallButton))
            {
                m_normalField = Vector3.back;
            }
            GUILayout.EndHorizontal();
            GUILayout.Space(-4);
            GUILayout.BeginHorizontal(noStretch, noFill);
            if (GUILayout.Button("Normalize", widthWideButton))
            {
                m_normalField = m_normalField.normalized;
            }
            GUILayout.EndHorizontal();
            GUILayout.Label("APPLY TO INPUT:", noFill);
            if (GUILayout.Button("Source (Q)", widthWideButton))
            {
                Handle_SourceToInput();
            }
            GUI.backgroundColor = currentColor;


            // Target selection related controls
            GUILayout.Space(12.0f);
            currentColor        = GUI.backgroundColor;
            GUI.backgroundColor = bgColorTarget;
            GUILayout.Label("APPLY TO TARGET:", noFill);

            if (GUILayout.Button("Input Field (W)", widthWideButton))
            {
                Handle_InputToTarget();
            }
            if (GUILayout.Button("Source (S)", widthWideButton))
            {
                Handle_SourceToTarget();
            }
            if (GUILayout.Button("Source + Input Field (X)", widthWideButton))
            {
                Handle_SourceInputToTarget();
            }

            GUI.backgroundColor = currentColor;
            GUILayout.Space(12.0f);



            // Reset override functions
            GUILayout.BeginVertical(GUILayout.ExpandWidth(false), GUILayout.ExpandHeight(true));
            GUILayout.EndVertical();

            if (GUILayout.Button("RESET SELECTED OVERRIDES", widthWideButton))
            {
                NPVoxNormalProcessor_UserOverride processor = ( NPVoxNormalProcessor_UserOverride )m_context.ViewedProcessor;

                foreach (NPVoxMeshData vox in m_context.MeshOutput.GetVoxMeshData())
                {
                    if (!vox.isHidden)
                    {
                        sbyte selection = GetSelection(vox.voxCoord);
                        if (selection == SELECTED_TARGET)
                        {
                            processor.m_overrideNormalsRT.Remove(vox.voxCoord);
                        }
                    }
                }

                ResetSelection();
                InitMeshNormals();
            }

            if (GUILayout.Button("RESET ALL OVERRIDES", widthWideButton))
            {
                NPVoxNormalProcessor_UserOverride processor = ( NPVoxNormalProcessor_UserOverride )m_context.ViewedProcessor;
                processor.m_overrideNormalsRT.Clear();
                InitMeshNormals();
            }

            GUILayout.Space(12.0f);
        }
        else
        {
            Color currentColor = GUI.backgroundColor;
            GUI.backgroundColor = bgColorWarning;
            if (GUILayout.Button("Recalculate normals", noFill))
            {
                InitMeshNormals();
            }
            GUI.backgroundColor = currentColor;
        }
    }