Beispiel #1
0
        void OnGUI()
        {
            EditorGUIUtility.labelWidth = 80;

            Transform[] selection = Selection.transforms;

            // Selection
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Selection", GUILayout.Width(80));
            selectionScroll = EditorGUILayout.BeginScrollView(selectionScroll);
            foreach (Transform t in selection)
            {
                EditorGUILayout.LabelField(t.name);
            }
            EditorGUILayout.EndScrollView();
            EditorGUILayout.EndHorizontal();

            // Iterations
            iterations = (int)EditorGUILayout.Slider("Iterations", iterations, 1, 5);

            // Boundaries
            boundaryInterpolation = (CatmullClark.Options.BoundaryInterpolation)
                                    EditorGUILayout.EnumPopup("Boundaries", boundaryInterpolation);

            // Button
            if (GUILayout.Button("Subdivide"))
            {
                if (selection.Length == 0)
                {
                    throw new System.Exception("Nothing selected to subdivide");
                }
                var options = new CatmullClark.Options {
                    boundaryInterpolation = boundaryInterpolation,
                };
                foreach (Transform t in selection)
                {
                    // Add Undo record
                    MeshFilter mf = CatmullClark.CheckMeshFilter(t.gameObject);
                    Undo.RecordObject(mf, "Subdivide " + t.name);
                    // Subdivide
                    CatmullClark.Subdivide(t.gameObject, iterations, options);
                }
                if (selection.Length > 1)
                {
                    Undo.SetCurrentGroupName(string.Format("Subdivide {0} objects", selection.Length));
                }
            }
        }
Beispiel #2
0
//	    void Reset()
//	    {
//	        SubdivideMeshes();
//	    }

        public void SubdivideMeshes()
        {
            // delete previous children
            var oldChildren = Enumerable.Range(0, this.transform.childCount)
                              .Select(i => this.transform.GetChild(i)).ToArray();

            foreach (var c in oldChildren)
            {
                Object.Destroy(c.gameObject);
            }

            // create 4x4 array of subdivided objects

            //Mesh cube = CreatePrimitiveCube(holeCount: holes);
            //cube.name = string.Format("Cube_holes{0}", holes);

            // cube.RecalculateNormals();


//				Mesh mesh = CatmullClark.Subdivide(ClayMesh.mesh, 1, new CatmullClark.Options {
//	                  boundaryInterpolation = m_boundaryInterpolation});
            if (subCount <= 3)
            {
                CatmullClark.Subdivide(ClayMesh.gameObject, 1, new CatmullClark.Options {
                    boundaryInterpolation = m_boundaryInterpolation
                });
                subCount++;
            }

            //ClayMesh.sharedMesh = mesh2;
//	            string name = string.Format("Cube_holes{0}_subdiv{1}", holes, iter);
//	            var obj = new GameObject(name);
//	            obj.transform.SetParent(this.transform);
//	            obj.transform.position = new Vector3(iter * 3f, holes * 3f, 0);
//	            obj.AddComponent<MeshFilter>().sharedMesh = mesh;
//	            obj.AddComponent<MeshRenderer>().material = m_material;
//
        }