/** * Do the thing. Return a pb_ActionResult indicating the success/failure of action. */ public override pb_ActionResult DoAction() { pbUndo.RecordObjects(selection, "Make Double-Sided Faces"); foreach (pb_Object pb in selection) { List <pb_FaceRebuildData> rebuild = new List <pb_FaceRebuildData>(); List <pb_Vertex> vertices = new List <pb_Vertex>(pb_Vertex.GetVertices(pb)); Dictionary <int, int> lookup = pb.sharedIndices.ToDictionary(); foreach (pb_Face face in pb.SelectedFaces) { pb_FaceRebuildData data = new pb_FaceRebuildData(); data.vertices = new List <pb_Vertex>(); data.face = new pb_Face(face); data.sharedIndices = new List <int>(); Dictionary <int, int> map = new Dictionary <int, int>(); int len = data.face.indices.Length; for (int i = 0; i < len; i++) { if (map.ContainsKey(face.indices[i])) { continue; } map.Add(face.indices[i], map.Count); data.vertices.Add(vertices[face.indices[i]]); data.sharedIndices.Add(lookup[face.indices[i]]); } for (int i = 0; i < len; i++) { data.face.indices[i] = map[data.face.indices[i]]; } data.face.ReverseIndices(); rebuild.Add(data); } pb_FaceRebuildData.Apply(rebuild, pb, vertices, null, lookup, null); pb.ToMesh(); pb.Refresh(); pb.Optimize(); } // This is necessary! Otherwise the pb_Editor will be working with caches from // outdated meshes and throw errors. pb_Editor.Refresh(); return(new pb_ActionResult(Status.Success, "Make Faces Double-Sided")); }
/** * Do the thing. Return a pb_ActionResult indicating the success/failure of action. */ public override pb_ActionResult DoAction() { pbUndo.RecordObjects(selection, "Make Double-Sided Faces"); foreach(pb_Object pb in selection) { List<pb_FaceRebuildData> rebuild = new List<pb_FaceRebuildData>(); List<pb_Vertex> vertices = new List<pb_Vertex>(pb_Vertex.GetVertices(pb)); Dictionary<int, int> lookup = pb.sharedIndices.ToDictionary(); foreach(pb_Face face in pb.SelectedFaces) { pb_FaceRebuildData data = new pb_FaceRebuildData(); data.vertices = new List<pb_Vertex>(); data.face = new pb_Face(face); data.sharedIndices = new List<int>(); Dictionary<int, int> map = new Dictionary<int, int>(); int len = data.face.indices.Length; for(int i = 0; i < len; i++) { if(map.ContainsKey(face.indices[i])) continue; map.Add(face.indices[i], map.Count); data.vertices.Add(vertices[face.indices[i]]); data.sharedIndices.Add(lookup[face.indices[i]]); } for(int i = 0; i < len; i++) data.face.indices[i] = map[data.face.indices[i]]; data.face.ReverseIndices(); rebuild.Add(data); } pb_FaceRebuildData.Apply(rebuild, pb, vertices, null, lookup, null); pb.ToMesh(); pb.Refresh(); pb.Optimize(); } // This is necessary! Otherwise the pb_Editor will be working with caches from // outdated meshes and throw errors. pb_Editor.Refresh(); return new pb_ActionResult(Status.Success, "Make Faces Double-Sided"); }