예제 #1
0
    /// <summary>
    /// Merges faces of the same side.
    /// </summary>
    /// <param name="o">pb_object to merge faces</param>
    /// <param name="side">Coordinate distance to side being used.</param>
    /// <param name="v">Vector value of the coordinate that indicates side</param>
    /// <param name="useRotation">Whether or not to merge all sides with same vector value v</param>
    /// <returns></returns>
    public static int MergeFacesOfSameSide(pb_Object o, float side, VectorValue v, bool useRotation = false)
    {
        List <pb_Face> mergeableFaces = new List <pb_Face>();

        foreach (pb_Face f in o.faces)
        {
            bool sameSide = true;
            if (useRotation)
            {
                switch (v)
                {
                case VectorValue.z:
                    side = o.vertices[f.indices[0]].z;
                    break;

                case VectorValue.y:
                    side = o.vertices[f.indices[0]].y;
                    break;

                case VectorValue.x:
                default:
                    side = o.vertices[f.indices[0]].x;
                    break;
                }
            }
            float delta = 0.01f;
            foreach (int index in f.indices)
            {
                switch (v)
                {
                case VectorValue.z:
                    sameSide = sameSide && Mathf.Abs(o.vertices[index].z - side) < delta;
                    break;

                case VectorValue.y:
                    sameSide = sameSide && Mathf.Abs(o.vertices[index].y - side) < delta;
                    break;

                case VectorValue.x:
                default:
                    sameSide = sameSide && Mathf.Abs(o.vertices[index].x - side) < delta;
                    break;
                }
            }

            if (sameSide)
            {
                mergeableFaces.Add(f);
            }
        }

        if (mergeableFaces.Count > 1)
        {
            pb_Face[] faces = mergeableFaces.ToArray();
            o.MergeFaces(faces);
            return(1);
        }

        return(0);
    }
예제 #2
0
    /// <summary>
    /// Merges the remaining faces of the given pb_object.
    /// </summary>
    public static void MergeRemainingFaces(pb_Object o, int mergedFaces)
    {
        List <pb_Face> mergeableFaces = new List <pb_Face>();

        for (int index = 0; index < o.faceCount - mergedFaces; ++index)
        {
            mergeableFaces.Add(o.faces[index]);
        }

        pb_Face[] faces = mergeableFaces.ToArray();
        o.MergeFaces(faces);
    }