Esempio n. 1
0
    public void reset()
    {
        // Please keep these in the same order and grouping as their declarations at the top.

        // Assets -------------------------------------------------------------------------------------------------------

        prControl = null;

        // Parameters -----------------------------------------------------------------------------------------------

        prEditable = true;

        prParmCount            = 0;
        prParmIntValueCount    = 0;
        prParmFloatValueCount  = 0;
        prParmStringValueCount = 0;
        prParmChoiceCount      = 0;

        prParms             = new HAPI_ParmInfo[0];
        prParmIntValues     = new int[0];
        prParmFloatValues   = new float[0];
        prParmStringHandles = new HAPI_StringHandle[0];
        prParmChoiceLists   = new HAPI_ParmChoiceInfo[0];

        myParmInfoStrings       = new HAPI_ParmInfoStrings[0];
        myParmChoiceInfoStrings = new HAPI_ParmChoiceInfoStrings[0];

        myParmStringValues = new string[0];

        prLastChangedParmId = -1;

        myParmsUndoInfo = null;

        prFolderListSelections   = new List <int>();
        prFolderListSelectionIds = new List <int>();
        prFolderListSelections.Add(0);
        prFolderListSelectionIds.Add(-1);

        // Control -------------------------------------------------------------------------------------------------

        myPostSerialization    = true;
        myValuesEqualToHoudini = false;
    }
Esempio n. 2
0
    public void getParameterValues()
    {
        if (prControl == null)
        {
            return;
        }
        if (prControl.prAsset == null)
        {
            return;
        }
        if (prControl.prAssetId < 0)
        {
            return;
        }

        if (myPostSerialization)
        {
            myValuesEqualToHoudini = areValuesEqualToHoudini();
        }
        else
        {
            myValuesEqualToHoudini = true;
        }

        // Create undo info if it hasn't been created already
        if (myParmsUndoInfo == null)
        {
            myParmsUndoInfo = ScriptableObject.CreateInstance <HoudiniParmsUndoInfo>();
        }

        // Get the node info again
        HAPI_NodeInfo node_info = HoudiniHost.getNodeInfo(prControl.prNodeId);

        prParmCount            = node_info.parmCount;
        prParmIntValueCount    = node_info.parmIntValueCount;
        prParmFloatValueCount  = node_info.parmFloatValueCount;
        prParmStringValueCount = node_info.parmStringValueCount;
        prParmChoiceCount      = node_info.parmChoiceCount;

        // Get all parameters.
        prParms           = new HAPI_ParmInfo[prParmCount];
        myParmInfoStrings = new HAPI_ParmInfoStrings[prParmCount];
        if (myParmInputs == null)
        {
            myParmInputs = new HAPI_ParmInput[prParmCount];
        }
        HoudiniAssetUtility.getArray1Id(prControl.prNodeId, HoudiniHost.getParameters, prParms, prParmCount);

        // Get parameter int values.
        prParmIntValues = new int[prParmIntValueCount];
        HoudiniAssetUtility.getArray1Id(
            prControl.prNodeId, HoudiniHost.getParmIntValues, prParmIntValues, prParmIntValueCount);

        myParmsUndoInfo.parmIntValues = new int[prParmIntValueCount];
        Array.Copy(prParmIntValues, myParmsUndoInfo.parmIntValues, prParmIntValueCount);

        // Get parameter float values.
        prParmFloatValues = new float[prParmFloatValueCount];
        HoudiniAssetUtility.getArray1Id(
            prControl.prNodeId, HoudiniHost.getParmFloatValues, prParmFloatValues, prParmFloatValueCount);

        myParmsUndoInfo.parmFloatValues = new float[prParmFloatValueCount];
        Array.Copy(prParmFloatValues, myParmsUndoInfo.parmFloatValues, prParmFloatValueCount);

        // Get parameter string (handle) values.
        prParmStringHandles = new int[prParmStringValueCount];
        myParmStringValues  = new string[prParmStringValueCount];
        HoudiniAssetUtility.getArray1Id(
            prControl.prNodeId, HoudiniHost.getParmStringValues, prParmStringHandles, prParmStringValueCount);

        // Get parameter choice lists.
        prParmChoiceLists       = new HAPI_ParmChoiceInfo[prParmChoiceCount];
        myParmChoiceInfoStrings = new HAPI_ParmChoiceInfoStrings[prParmChoiceCount];
        HoudiniAssetUtility.getArray1Id(
            prControl.prNodeId, HoudiniHost.getParmChoiceLists, prParmChoiceLists, prParmChoiceCount);

        cacheStringsFromHost();

        // Go through parameters and set index map and multiparm map for undo info
        myParmsUndoInfo.parmNames.Clear();
        myParmsUndoInfo.parmIndices.Clear();

        foreach (HAPI_ParmInfo parm in prParms)
        {
            if (parm.isNode() && parm.id >= myParmInputs.Length)
            {
                // For input node params, make sure they have an entry
                // in myParmInputs for their data. Fixes bug 85804
                setChangedNodeParameterIntoHost(parm.id);
            }

            // Need to check the index values are greater or equal to 0
            // for now because there is a bug where some parameters are
            // being set to have an integer parameter type, a size of
            // zero, and an index value of -1
            if (parm.isInt() && parm.intValuesIndex >= 0)
            {
                myParmsUndoInfo.parmIndices.Add(parm.intValuesIndex);
            }
            else if (parm.isFloat() && parm.floatValuesIndex >= 0)
            {
                myParmsUndoInfo.parmIndices.Add(parm.floatValuesIndex);
            }
            else if (parm.isString() && parm.stringValuesIndex >= 0)
            {
                myParmsUndoInfo.parmIndices.Add(parm.stringValuesIndex);
            }
            else
            {
                continue;
            }

            myParmsUndoInfo.parmNames.Add(parm.name);
        }
    }
    protected bool generateAssetControl(int index, ref bool join_last, ref bool no_label_toggle_last)
    {
        if (myParms.prParms == null)
        {
            return(false);
        }

        if (myParms.prParms[index].invisible)
        {
            return(false);
        }

        bool changed = false;

        HAPI_ParmInfo[]      parms        = myParms.prParms;
        HAPI_ParmInfo        parm         = parms[index];
        HAPI_ParmInfoStrings parm_strings = myParms.prParmInfoStrings[index];

        int[]   parm_int_values   = myParms.prParmIntValues;
        float[] parm_float_values = myParms.prParmFloatValues;

        HoudiniGUIParm gui_parm = new HoudiniGUIParm(parm, parm_strings);

        ///////////////////////////////////////////////////////////////////////
        // Integer Parameter
        if (parm.type == HAPI_ParmType.HAPI_PARMTYPE_MULTIPARMLIST)
        {
            changed = HoudiniGUI.multiparmField(
                ref gui_parm, ref myDelayBuild, ref parm_int_values,
                ref join_last, ref no_label_toggle_last);
        }
        else if (parm.type == HAPI_ParmType.HAPI_PARMTYPE_INT)
        {
            if (parm.choiceCount > 0 && parm.choiceIndex >= 0)
            {
                // Draw popup (menu) field.
                List <string> labels = new List <string>();
                List <int>    values = new List <int>();

                // Go through our choices.
                for (int i = 0; i < parm.choiceCount; ++i)
                {
                    if (myParms.prParmChoiceLists[parm.choiceIndex + i].parentParmId != parm.id)
                    {
                        Debug.LogError("Parm choice parent parm id ("
                                       + myParms.prParmChoiceLists[parm.choiceIndex + i].parentParmId
                                       + ") not matching current parm id (" + parm.id + ")!\n"
                                       + "Choice index: " + (parm.choiceIndex + i) + ", "
                                       + "Choice count: " + parm.choiceCount);
                    }

                    labels.Add(myParms.prParmChoiceInfoStrings[parm.choiceIndex + i].label);
                    values.Add(i);
                }

                changed = HoudiniGUI.dropdown(
                    ref gui_parm, ref parm_int_values,
                    labels.ToArray(), values.ToArray(),
                    ref join_last, ref no_label_toggle_last,
                    null, ref parm_int_values);
            }
            else
            {
                changed = HoudiniGUI.intField(
                    ref gui_parm, ref myDelayBuild, ref parm_int_values,
                    ref join_last, ref no_label_toggle_last, null,
                    ref parm_int_values);
            }     // if parm.choiceCount
        }         // if parm.type is INT
        ///////////////////////////////////////////////////////////////////////
        // Float Parameter
        else if (parm.type == HAPI_ParmType.HAPI_PARMTYPE_FLOAT)
        {
            changed = HoudiniGUI.floatField(
                ref gui_parm, ref myDelayBuild, ref parm_float_values,
                ref join_last, ref no_label_toggle_last, null,
                ref parm_float_values);
        }         // if parm.type is FLOAT
        ///////////////////////////////////////////////////////////////////////
        // String Parameter
        else if (parm.type == HAPI_ParmType.HAPI_PARMTYPE_STRING)
        {
            if (parm.choiceCount > 0 && parm.choiceIndex >= 0)
            {
                // Draw popup (menu) field.
                List <string> labels = new List <string>();
                List <string> values = new List <string>();

                // Go through our choices.
                for (int i = 0; i < parm.choiceCount; ++i)
                {
                    if (myParms.prParmChoiceLists[parm.choiceIndex + i].parentParmId != parm.id)
                    {
                        Debug.LogError(
                            "Parm choice parent parm id ("
                            + myParms.prParmChoiceLists[parm.choiceIndex + i].parentParmId
                            + ") not matching current parm id (" + parm.id + ")!\n"
                            + "Choice index: " + (parm.choiceIndex + i) + ", "
                            + "Choice count: " + parm.choiceCount);
                    }

                    labels.Add(myParms.prParmChoiceInfoStrings[parm.choiceIndex + i].label);
                    values.Add(myParms.prParmChoiceInfoStrings[parm.choiceIndex + i].value);
                }

                string[] values_temp = myParms.getParmStrings(parm);
                gui_parm.valuesIndex = 0;                 // Since we're piping a de-handled temp array.

                changed = HoudiniGUI.dropdown(
                    ref gui_parm, ref values_temp,
                    labels.ToArray(), values.ToArray(),
                    ref join_last, ref no_label_toggle_last,
                    null, ref values_temp);

                if (changed)
                {
                    myParms.setParmStrings(parm, values_temp);
                }
            }
            else
            {
                string[] values = myParms.getParmStrings(parm);

                // The given string array is only for this parm so we need to set the values index to 0.
                gui_parm.valuesIndex = 0;

                changed = HoudiniGUI.stringField(
                    ref gui_parm, ref myDelayBuild, ref values,
                    ref join_last, ref no_label_toggle_last, null,
                    ref values);

                // Set the to be changed strings into the cache
                if (changed)
                {
                    myParms.setParmStrings(parm, values);
                }
            }
        }
        ///////////////////////////////////////////////////////////////////////
        // File Path Field
        else if (parm.isPath())
        {
            string[] path = myParms.getParmStrings(parm);

            if (parm.type == HAPI_ParmType.HAPI_PARMTYPE_PATH_FILE_GEO)
            {
                gui_parm.label += " (geo)";
            }
            else if (parm.type == HAPI_ParmType.HAPI_PARMTYPE_PATH_FILE_IMAGE)
            {
                gui_parm.label += " (image)";
            }

            // Asset ID might still be invalid here so don't fail if it is.
            // It is invalid if the asset didn't cook yet after a scene load.
            try
            {
                string file_pattern = parm.typeInfo;
                if (file_pattern != "")
                {
                    gui_parm.label += " (" + file_pattern + ")";
                }
            }
            catch {}

            HAPI_Permissions permissions = parm.permissions;
            if (permissions == HAPI_Permissions.HAPI_PERMISSIONS_READ_ONLY)
            {
                gui_parm.label += " (read-only)";
                changed         = HoudiniGUI.fileOpenField(
                    ref gui_parm, ref myDelayBuild, ref path[0],
                    ref join_last, ref no_label_toggle_last);
            }
            else
            {
                if (permissions == HAPI_Permissions.HAPI_PERMISSIONS_WRITE_ONLY)
                {
                    gui_parm.label += " (write-only)";
                }

                changed = HoudiniGUI.fileSaveField(
                    ref gui_parm, ref myDelayBuild, ref path[0],
                    ref join_last, ref no_label_toggle_last);
            }

            if (changed)
            {
                myParms.setParmStrings(parm, path);
            }
        }
        ///////////////////////////////////////////////////////////////////////
        // Node Path Field
        else if (parm.isNode())
        {
            // Asset ID might still be invalid here so don't fail if it is.
            // It is invalid if the asset didn't cook yet after a scene load.
            try
            {
                string op_filter = parm.typeInfo;
                if (op_filter != "")
                {
                    gui_parm.label += " (" + op_filter + ")";
                }
            }
            catch {}

            HAPI_ParmInput     parm_input  = myParms.prParmInputs[parm.id];
            UnityEngine.Object temp_object = parm_input.inputObject;
            GameObject         undo_object = null;
            changed = HoudiniGUI.objectField(
                ref gui_parm, ref temp_object, typeof(GameObject),
                ref join_last, ref no_label_toggle_last, null, ref undo_object);

            if (changed)
            {
                parm_input.newInputObject   = (GameObject)temp_object;
                myParms.prParmInputs[index] = parm_input;
            }
        }
        ///////////////////////////////////////////////////////////////////////
        // Toggle Parameter
        else if (parm.type == HAPI_ParmType.HAPI_PARMTYPE_TOGGLE)
        {
            changed = HoudiniGUI.toggle(
                ref gui_parm, ref parm_int_values,
                ref join_last, ref no_label_toggle_last,
                null, ref parm_int_values);
        }
        ///////////////////////////////////////////////////////////////////////
        // Color Parameter
        else if (parm.type == HAPI_ParmType.HAPI_PARMTYPE_COLOR)
        {
            changed = HoudiniGUI.colourField(
                ref gui_parm, ref myDelayBuild, ref parm_float_values,
                ref join_last, ref no_label_toggle_last, null,
                ref parm_float_values);
        }
        ///////////////////////////////////////////////////////////////////////
        // Button Parameter
        else if (parm.type == HAPI_ParmType.HAPI_PARMTYPE_BUTTON)
        {
            if (parm.choiceCount > 0 && parm.choiceIndex >= 0)
            {
                // Draw popup (menu) field.
                List <string> labels = new List <string>();
                List <int>    values = new List <int>();

                // Go through our choices.
                for (int i = 0; i < parm.choiceCount; ++i)
                {
                    if (myParms.prParmChoiceLists[parm.choiceIndex + i].parentParmId != parm.id)
                    {
                        Debug.LogError(
                            "Parm choice parent parm id ("
                            + myParms.prParmChoiceLists[parm.choiceIndex + i].parentParmId
                            + ") not matching current parm id (" + parm.id + ")!\n"
                            + "Choice index: " + (parm.choiceIndex + i) + ", "
                            + "Choice count: " + parm.choiceCount);
                    }

                    labels.Add(myParms.prParmChoiceInfoStrings[parm.choiceIndex + i].label);
                    values.Add(i);
                }

                changed = HoudiniGUI.dropdown(
                    ref gui_parm, ref parm_int_values,
                    labels.ToArray(), values.ToArray(),
                    ref join_last, ref no_label_toggle_last,
                    null, ref parm_int_values);
            }
            else
            {
                changed = HoudiniGUI.button(ref gui_parm, ref join_last, ref no_label_toggle_last);
            }
        }
        ///////////////////////////////////////////////////////////////////////
        // Label
        else if (parm.type == HAPI_ParmType.HAPI_PARMTYPE_LABEL)
        {
            HoudiniGUI.label(ref gui_parm, ref join_last, ref no_label_toggle_last);
        }
        ///////////////////////////////////////////////////////////////////////
        // Separator
        else if (parm.type == HAPI_ParmType.HAPI_PARMTYPE_SEPARATOR)
        {
            HoudiniGUI.separator();
        }

        if (myAsset.hasProgressBarBeenUsed() && parm.id == myParms.prLastChangedParmId)
        {
            // TODO: Set the focus back to this control since the progress bar would have stolen it.
        }


        if (changed)
        {
            myParms.prLastChangedParmId = parm.id;
        }

        return(changed);
    }