/// <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);
    }
 /// <summary>
 /// Create a Triangle object from 3 vertex indices of variable type.
 /// </summary>
 /// <param name="index0">
 /// A TriIndex struct representing 1 of 3 vertex index types and its value.
 /// </param>
 /// <param name="index1">
 /// A TriIndex struct representing 1 of 3 vertex index types and its value.
 /// </param>
 /// <param name="index2">
 /// A TriIndex struct representing 1 of 3 vertex index types and its value.
 /// </param>
 public Triangle(TriIndex index0, TriIndex index1, TriIndex index2)
 {
     this.type0   = index0.type;
     this.type1   = index1.type;
     this.type2   = index2.type;
     this.vertex0 = 0;
     this.vertex1 = 0;
     this.vertex2 = 0;
     this.vertex0 = TriIndex.EncodeIndex(index0);
     this.vertex1 = TriIndex.EncodeIndex(index1);
     this.vertex2 = TriIndex.EncodeIndex(index2);
 }
Beispiel #3
0
    private void DrawTriangleElement(Rect rect, int index, bool active, bool focus)
    {
        rect = VxlGUI.GetPaddedRect(rect, VxlGUI.SM_SPACE);
        //draw indexed label
        GUI.Label(
            VxlGUI.GetAboveElement(rect, 0, VxlGUI.MED_BAR, VxlGUI.SM_SPACE, 0),
            "Tri: " + index,
            GUI.skin.GetStyle("LeftListLabel")
            );
        EditorGUI.BeginChangeCheck();
        //draw triangle index 0
        TriIndex index0 = DrawTriangleEditElement(
            VxlGUI.GetAboveElement(rect, 1, VxlGUI.MED_BAR, VxlGUI.SM_SPACE, 0),
            _triangles[index].type0,
            _triangles[index].vertex0
            );
        //draw triangle index 1
        TriIndex index1 = DrawTriangleEditElement(
            VxlGUI.GetAboveElement(rect, 2, VxlGUI.MED_BAR, VxlGUI.SM_SPACE, 0),
            _triangles[index].type1,
            _triangles[index].vertex1
            );
        //draw triangle index 2
        TriIndex index2 = DrawTriangleEditElement(
            VxlGUI.GetAboveElement(rect, 3, VxlGUI.MED_BAR, VxlGUI.SM_SPACE, 0),
            _triangles[index].type2,
            _triangles[index].vertex2
            );

        if (EditorGUI.EndChangeCheck())
        {
            if (target != null)
            {
                if (target == null || target.triangles == null)
                {
                    return;
                }
                if (index < 0 || index >= target.triangles.Count)
                {
                    return;
                }
                Undo.RecordObject(target, "Update Triangle Build");
                target.triangles[index] = new Triangle(index0, index1, index2);
                _update_mesh            = true;
                _render_mesh            = true;
                _repaint_menu           = true;
                //dirty target object
                EditorUtility.SetDirty(target);
            }
        }
    }
Beispiel #4
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));
    }
Beispiel #5
0
 /// <summary>
 /// Encodes a TriIndex struct into a ushort representation based on
 /// its TriIndexType value.
 /// </summary>
 /// <param name="index"></param>
 /// <returns></returns>
 public static ushort EncodeIndex(TriIndex index)
 {
     return(EncodeIndex(index.axi_index, index.socket_index));
 }