Ejemplo n.º 1
0
        /**
         *	\brief Collapses all passed indices to a single shared index.
         *
         */
        public static bool MergeVertices(this pb_Object pb, int[] indices)
        {
            Vector3[] verts = pb.vertices;
            Vector3   cen   = Vector3.zero;

            foreach (int i in indices)
            {
                cen += verts[i];
            }

            cen /= (float)indices.Length;

            pb_IntArray[] sharedIndices = pb.sharedIndices;
            int           newIndex      = pb_IntArrayUtility.MergeSharedIndices(ref sharedIndices, indices);

            pb.SetSharedIndices(sharedIndices);

            int firstTriInSharedIndexArr = pb.sharedIndices[newIndex][0];

            pb.SetSharedVertexPosition(firstTriInSharedIndexArr, cen);

            int[] mergedSharedIndex = pb.GetSharedIndices()[newIndex].array;

            int[] removedIndices = pb.RemoveDegenerateTriangles();

            // get a non-deleted index to work with
            int ind = -1;

            for (int i = 0; i < mergedSharedIndex.Length; i++)
            {
                if (!removedIndices.Contains(mergedSharedIndex[i]))
                {
                    ind = mergedSharedIndex[i];
                }
            }


            int t = ind;

            for (int i = 0; i < removedIndices.Length; i++)
            {
                if (ind > removedIndices[i])
                {
                    t--;
                }
            }

            pb.ClearSelection();

            if (t > -1)
            {
                pb.SetSelectedTriangles(new int[1] {
                    t
                });
            }

            return(true);
        }
Ejemplo n.º 2
0
        /**
         *	\brief Collapses all passed indices to a single shared index.  Retains vertex normals.
         *
         */
        public static bool MergeVertices(this pb_Object pb, int[] indices, out int collapsedIndex)
        {
            Vector3[] verts = pb.vertices;
            Vector3   cen   = Vector3.zero;

            foreach (int i in indices)
            {
                cen += verts[i];
            }

            cen /= (float)indices.Length;

            pb_IntArray[] sharedIndices = pb.sharedIndices;
            int           newIndex      = pb_IntArrayUtility.MergeSharedIndices(ref sharedIndices, indices);

            pb.SetSharedIndices(sharedIndices);

            pb.SetSharedVertexPosition(newIndex, cen);

            int[] mergedSharedIndex = pb.GetSharedIndices()[newIndex].array;

            int[] removedIndices;
            pb.RemoveDegenerateTriangles(out removedIndices);

            // get a non-deleted index to work with
            int ind = -1;

            for (int i = 0; i < mergedSharedIndex.Length; i++)
            {
                if (!removedIndices.Contains(mergedSharedIndex[i]))
                {
                    ind = mergedSharedIndex[i];
                }
            }

            int t = ind;

            for (int i = 0; i < removedIndices.Length; i++)
            {
                if (ind > removedIndices[i])
                {
                    t--;
                }
            }

            if (t > -1)
            {
                collapsedIndex = t;
                return(true);
            }
            else
            {
                collapsedIndex = -1;
                return(false);
            }
        }
Ejemplo n.º 3
0
        static bool arch_endCaps      = true;           ///< Generate end cap faces of arch?

        void ArchGUI()
        {
            arch_radius = EditorGUILayout.FloatField("Radius", arch_radius);
            arch_radius = arch_radius <= 0f ? .01f : arch_radius;

            arch_width = EditorGUILayout.FloatField("Thickness", arch_width);
            arch_width = Mathf.Clamp(arch_width, 0.01f, 100f);

            arch_depth = EditorGUILayout.FloatField("Depth", arch_depth);
            arch_depth = Mathf.Clamp(arch_depth, 0.1f, 500.0f);

            arch_radialCuts = EditorGUILayout.IntField("Number of Sides", arch_radialCuts);
            arch_radialCuts = Mathf.Clamp(arch_radialCuts, 3, 200);

            arch_angle = EditorGUILayout.FloatField("Arch Degrees", arch_angle);
            arch_angle = Mathf.Clamp(arch_angle, 0.0f, 360.0f);

            // arch_insideFaces = EditorGUILayout.Toggle("Inner Faces", arch_insideFaces);

            // arch_outsideFaces = EditorGUILayout.Toggle("Outer Faces", arch_outsideFaces);

            // arch_frontFaces = EditorGUILayout.Toggle("Front Faces", arch_frontFaces);

            // arch_backFaces = EditorGUILayout.Toggle("Rear Faces", arch_backFaces);

            if (arch_angle < 360f)
            {
                arch_endCaps = EditorGUILayout.Toggle("End Caps", arch_endCaps);
            }

            if (showPreview && (GUI.changed || initPreview))
            {
                SetPreviewObject(pb_ShapeGenerator.ArchGenerator(arch_angle,
                                                                 arch_radius,
                                                                 Mathf.Clamp(arch_width, 0.01f, arch_radius),
                                                                 arch_depth,
                                                                 arch_radialCuts,
                                                                 arch_insideFaces,
                                                                 arch_outsideFaces,
                                                                 arch_frontFaces,
                                                                 arch_backFaces,
                                                                 arch_endCaps));
            }

            Color oldColor = GUI.backgroundColor;

            GUI.backgroundColor = COLOR_GREEN;

            EditorGUILayout.EndScrollView();

            if (GUILayout.Button("Build " + shape, GUILayout.MinHeight(28)))
            {
                pb_Object pb = pb_ShapeGenerator.ArchGenerator(
                    arch_angle,
                    arch_radius,
                    Mathf.Clamp(arch_width, 0.01f, arch_radius),
                    arch_depth,
                    arch_radialCuts,
                    arch_insideFaces,
                    arch_outsideFaces,
                    arch_frontFaces,
                    arch_backFaces,
                    arch_endCaps);

                int[] removed;
                // happens when radius and width are the same :/
                pb.RemoveDegenerateTriangles(out removed);

                pbUndo.RegisterCreatedObjectUndo(pb.gameObject, "Create Shape");

                if (userMaterial)
                {
                    pb.SetFaceMaterial(pb.faces, userMaterial);
                }

                pb_Editor_Utility.SetPivotAndSnapWithPref(pb, null);
                pb_Editor_Utility.InitObjectFlags(pb);

                AlignWithPreviewObject(pb.gameObject);
                DestroyPreviewObject();
                showPreview = false;

                if (prefClose)
                {
                    this.Close();
                }
            }

            GUI.backgroundColor = oldColor;
        }