示例#1
0
    /// <summary>
    /// Determines if the vertex indices of the triangle are valid and inbounds.
    /// </summary>
    /// <param name="vertex_count">
    /// An integer representing the number of vertices of an object.
    /// </param>
    /// <param name="cornerplugs">
    /// A list of corner plugs from an object. Each element corresponds to an axi
    /// and the value at that element represents the number of vertices of a
    /// matching socket.
    /// </param>
    /// <param name="edgeplugs">
    /// A list of edge plugs from an object. Each element corresponds to an axi
    /// and the value at that element represents the number of vertices of a
    /// matching socket.
    /// </param>
    /// <returns>
    /// A boolean value where true represents that the triangle is properly formated
    /// and is in bounds of the given parameters.
    /// </returns>
    public bool IsValid(int vertex_count, List <int> cornerplugs, List <int> edgeplugs)
    {
        //vertex 0 validity check
        bool valid0       = (type0 == TriIndexType.Vertex && vertex0 < vertex_count);
        int  axis_index   = (int)TriIndex.DecodeAxiIndex(vertex0);
        int  vertex_index = TriIndex.DecodeIndex(vertex0);

        valid0 = valid0 || (type0 == TriIndexType.CornerPlug && cornerplugs != null && axis_index < cornerplugs.Count && vertex_index < cornerplugs[axis_index]);
        valid0 = valid0 || (type0 == TriIndexType.EdgePlug && edgeplugs != null && axis_index < edgeplugs.Count && vertex_index < edgeplugs[axis_index]);
        //vertex 1 validity check
        bool valid1 = (type1 == TriIndexType.Vertex && vertex1 < vertex_count);

        axis_index   = (int)TriIndex.DecodeAxiIndex(vertex1);
        vertex_index = TriIndex.DecodeIndex(vertex1);
        valid1       = valid1 || (type1 == TriIndexType.CornerPlug && cornerplugs != null && axis_index < cornerplugs.Count && vertex_index < cornerplugs[axis_index]);
        valid1       = valid1 || (type1 == TriIndexType.EdgePlug && edgeplugs != null && axis_index < edgeplugs.Count && vertex_index < edgeplugs[axis_index]);
        //vertex 2 validity check
        bool valid2 = (type2 == TriIndexType.Vertex && vertex2 < vertex_count);

        axis_index   = (int)TriIndex.DecodeAxiIndex(vertex2);
        vertex_index = TriIndex.DecodeIndex(vertex2);
        valid2       = valid2 || (type2 == TriIndexType.CornerPlug && cornerplugs != null && axis_index < cornerplugs.Count && vertex_index < cornerplugs[axis_index]);
        valid2       = valid2 || (type2 == TriIndexType.EdgePlug && edgeplugs != null && axis_index < edgeplugs.Count && vertex_index < edgeplugs[axis_index]);
        //difference validity check
        bool valid = valid0 && valid1 && valid2;

        valid = valid && !((type0 == type1) && (vertex0 == vertex1));
        valid = valid && !((type0 == type2) && (vertex0 == vertex2));
        valid = valid && !((type1 == type2) && (vertex1 == vertex2));
        //return validity results
        return(valid);
    }
示例#2
0
    private TriIndex DrawTriangleEditElement(Rect rect, TriIndexType type, ushort vertexcode)
    {
        rect = VxlGUI.GetRightColumn(rect, 0, 0.95f);
        float element_factor = 0.6f;
        float segment_width  = (rect.width - (2 * VxlGUI.SM_SPACE)) / 3;
        float unit_width     = (rect.width - (5 * VxlGUI.SM_SPACE)) / 6f;
        //Type Options
        Rect segrect = VxlGUI.GetRightElement(rect, 2, segment_width, VxlGUI.SM_SPACE, 0);

        EditorGUI.LabelField(
            VxlGUI.GetLeftColumn(segrect, 0, 1 - element_factor),
            "Type:",
            GUI.skin.GetStyle("RightDarkText")
            );
        int type_index = EditorGUI.Popup(
            VxlGUI.GetRightColumn(segrect, 0, element_factor),
            OptionIndex(type),
            _optionstrs,
            GUI.skin.GetStyle("DarkDropdown")
            );

        if (type_index >= 0 && type_index < _options.Length)
        {
            type = _options[type_index];
        }
        if (type == TriIndexType.CornerPlug || type == TriIndexType.EdgePlug)
        {
            //Axis Options
            segrect = VxlGUI.GetRightElement(rect, 1, segment_width, VxlGUI.SM_SPACE, 0);
            EditorGUI.LabelField(
                VxlGUI.GetLeftColumn(segrect, 0, 1 - element_factor),
                "Axis:",
                GUI.skin.GetStyle("RightDarkText")
                );
            string[] labels;
            if (type == TriIndexType.CornerPlug)
            {
                labels = _cornerplug_labels;
            }
            else
            {
                labels = _edgeplug_labels;
            }
            int axis_index = EditorGUI.Popup(
                VxlGUI.GetRightColumn(segrect, 0, element_factor),
                TriIndex.DecodeAxiIndex(vertexcode),
                labels,
                GUI.skin.GetStyle("DarkDropdown")
                );
            //Socket Options
            segrect = VxlGUI.GetRightElement(rect, 0, segment_width, VxlGUI.SM_SPACE, 0);
            EditorGUI.LabelField(
                VxlGUI.GetLeftColumn(segrect, 0, 1 - element_factor),
                "Socket:",
                GUI.skin.GetStyle("RightDarkText")
                );
            int socket_index = EditorGUI.IntField(
                VxlGUI.GetRightColumn(segrect, 0, element_factor),
                TriIndex.DecodeIndex(vertexcode),
                GUI.skin.GetStyle("DarkNumberField")
                );
            vertexcode = TriIndex.EncodeIndex((byte)axis_index, (byte)socket_index);
        }
        else
        {
            //Vertex Index Options
            segrect = VxlGUI.GetRightElement(rect, 0, segment_width, VxlGUI.SM_SPACE, 0);
            EditorGUI.LabelField(
                VxlGUI.GetLeftColumn(segrect, 0, 1 - element_factor),
                "Index:",
                GUI.skin.GetStyle("RightDarkText")
                );
            vertexcode = (ushort)EditorGUI.IntField(
                VxlGUI.GetRightColumn(segrect, 0, element_factor),
                vertexcode,
                GUI.skin.GetStyle("DarkNumberField")
                );
        }
        return(new TriIndex(type, vertexcode));
    }