/** * \brief Duplicates and mirrors the passed pb_Object. * @param pb The donor pb_Object. * @param axe The axis to mirror the object on. * \returns The newly duplicated pb_Object. * \sa ProBuilder.Axis */ public static pb_Object Mirror(pb_Object pb, Vector3 scale) { pb_Object p = ProBuilder.CreateObjectWithObject(pb); p.MakeUnique(); p.transform.parent = pb.transform.parent; p.transform.position = pb.transform.position; p.transform.localRotation = pb.transform.localRotation; Vector3 lScale = p.gameObject.transform.localScale; p.transform.localScale = new Vector3(lScale.x * scale.x, lScale.y * scale.y, lScale.z * scale.z); // if flipping on an odd number of axes, flip winding order if ((scale.x * scale.y * scale.z) < 0) { p.ReverseWindingOrder(p.faces); } p.FreezeScaleTransform(); p.Refresh(); p.GenerateUV2(true); pb_Editor_Utility.InitObjectFlags(p, ColliderType.MeshCollider, pb.entity.entityType); return(p); }
public void OnEnable() { if (EditorApplication.isPlayingOrWillChangePlaymode) { return; } if (target is pb_Object) { pb = (pb_Object)target; } else { return; } ren = pb.gameObject.GetComponent <Renderer>(); // get all materials in use (as far as pb_Object knows) // if(Selection.activeTransform != pb.transform) //System.Array.IndexOf(Selection.transforms, pb.transform) < 0 ) // Unity drag and drop material always only sets the first sub-object material, so check that it's the same // if(ren.sharedMaterials.Length > 0) // { // Bugger.Log("OnEnable set face material"); // HashSet<Material> mats = new HashSet<Material>(); // foreach(pb_Face f in pb.faces) // mats.Add(f.material); // HashSet<Material> renMats = new HashSet<Material>(ren.sharedMaterials); // if(!renMats.SetEquals(mats)) // { // pbUndo.RecordObjects(pbUtil.GetComponents<pb_Object>(Selection.transforms), "Set Face Materials"); // foreach(pb_Object pbs in pbUtil.GetComponents<pb_Object>(Selection.transforms)) // pbs.SetFaceMaterial(pbs.faces, ren.sharedMaterials[0]); // } // } #if UNITY_4 EditorUtility.SetSelectedWireframeHidden(ren, true); #else EditorUtility.SetSelectedWireframeHidden(ren, false); #endif pb.Verify(); pb.GenerateUV2(true); }
/** * Optmizes the mesh geometry, and generates a UV2 channel (if automatic lightmap generation is enabled). * Also sets the pb_Object to 'Dirty' so that changes are stored. */ public static void Optimize(this pb_Object InObject) { EditorUtility.SetDirty(InObject); pb_MeshUtility.CollapseSharedVertices(InObject); ///< Merge compatible shared vertices to a single vertex. float time = Time.realtimeSinceStartup; InObject.GenerateUV2(); // If GenerateUV2() takes longer than 3 seconds (!), show a warning prompting user // to disable auto-uv2 generation. if ((Time.realtimeSinceStartup - time) > 3f) { Debug.LogWarning(string.Format("Generate UV2 for \"{0}\" took {1} seconds! You may want to consider disabling Auto-UV2 generation in the `Preferences > ProBuilder` tab.", InObject.name, (Time.realtimeSinceStartup - time).ToString("F2"))); } }
/** * \brief ProBuilder objects created in Editor need to be initialized with a number of additional Editor-only settings. * This method provides an easy method of doing so in a single call. #InitObjectFlags will set the Entity Type, generate * a UV2 channel, set the unwrapping parameters, and center the object in the screen. */ public static void InitObjectFlags(pb_Object pb, ColliderType col, EntityType et) { switch (col) { case ColliderType.BoxCollider: pb.gameObject.AddComponent <BoxCollider>(); break; case ColliderType.MeshCollider: pb.gameObject.AddComponent <MeshCollider>().convex = EditorPrefs.HasKey(pb_Constant.pbForceConvex) ? EditorPrefs.GetBool(pb_Constant.pbForceConvex) : false; break; } pb_Lightmap_Editor.SetObjectUnwrapParamsToDefault(pb); pb.GenerateUV2(true); pb_Editor_Utility.SetEntityType(et, pb.gameObject); pb_Editor_Utility.ScreenCenter(pb.gameObject); }
public void ApplyMaterial(pb_Object pb, pb_Face quad, Material mat) { if (mat == null) { return; } pbUndo.RecordObject(pb, "Apply Material + " + mat.name); if (mat) { pb.SetFaceMaterial(quad, mat); } pb.GenerateUV2(pb_Editor.show_NoDraw); OnSelectionUpdate(selection); OnFaceChanged(pb); }
private static bool ConnectEdges(pb_Object pb, pb_Edge[] edgesToConnect) { int len = edgesToConnect.Length; List <EdgeConnection> splits = new List <EdgeConnection>(); for (int i = 0; i < len; i++) { foreach (pb_Face face in pbMeshUtils.GetConnectedFaces(pb, edgesToConnect[i])) { if (!splits.Contains((EdgeConnection)face)) { List <pb_Edge> faceEdges = new List <pb_Edge>(); foreach (pb_Edge e in edgesToConnect) { int localEdgeIndex = face.edges.IndexOf(e, pb.sharedIndices); if (localEdgeIndex > -1) { faceEdges.Add(face.edges[localEdgeIndex]); } } if (faceEdges.Count > 1) { splits.Add(new EdgeConnection(face, faceEdges)); } } } } pb_Face[] faces; if (pb.ConnectEdges(splits, out faces)) { pb.SetSelectedFaces(faces); pb.GenerateUV2(true); pb.Refresh(); return(true); } return(false); }
private static bool ConnectEdges(pb_Object pb, pb_Edge[] edgesToConnect) { int len = edgesToConnect.Length; List<EdgeConnection> splits = new List<EdgeConnection>(); for(int i = 0; i < len; i++) { foreach(pb_Face face in pbMeshUtils.GetConnectedFaces(pb, edgesToConnect[i])) { if(!splits.Contains((EdgeConnection)face)) { List<pb_Edge> faceEdges = new List<pb_Edge>(); foreach(pb_Edge e in edgesToConnect) { int localEdgeIndex = face.edges.IndexOf(e, pb.sharedIndices); if(localEdgeIndex > -1) faceEdges.Add(face.edges[localEdgeIndex]); } if(faceEdges.Count > 1) splits.Add(new EdgeConnection(face, faceEdges)); } } } pb_Face[] faces; if(pb.ConnectEdges(splits, out faces)) { pb.SetSelectedFaces(faces); pb.GenerateUV2(true); pb.Refresh(); return true; } return false; }
/** * Editor-only extension to pb_Object generates lightmap UVs. */ public static void GenerateUV2(this pb_Object pb) { pb.GenerateUV2(false); }
public void ApplyMaterial(pb_Object pb, pb_Face quad, Material mat) { if(mat == null) return; pbUndo.RecordObject(pb, "Apply Material + " + mat.name); if(mat) pb.SetFaceMaterial(quad, mat); pb.GenerateUV2(pb_Editor.show_NoDraw); OnSelectionUpdate(selection); OnFaceChanged( pb ); }
/** * \brief ProBuilder objects created in Editor need to be initialized with a number of additional Editor-only settings. * This method provides an easy method of doing so in a single call. #InitObjectFlags will set the Entity Type, generate * a UV2 channel, set the unwrapping parameters, and center the object in the screen. */ public static void InitObjectFlags(pb_Object pb, ColliderType col, EntityType et) { switch(col) { case ColliderType.BoxCollider: pb.gameObject.AddComponent<BoxCollider>(); break; case ColliderType.MeshCollider: pb.gameObject.AddComponent<MeshCollider>().convex = EditorPrefs.HasKey(pb_Constant.pbForceConvex) ? EditorPrefs.GetBool(pb_Constant.pbForceConvex) : false; break; } pb_Lightmap_Editor.SetObjectUnwrapParamsToDefault(pb); pb.GenerateUV2(true); pb_Editor_Utility.SetEntityType(et, pb.gameObject); pb_Editor_Utility.ScreenCenter( pb.gameObject ); }