protected void BeginEdit(string undoMessage) { if (m_IsEditing) { return; } // Disable iterative lightmapping Lightmapping.PushGIWorkflowMode(); var selection = MeshSelection.topInternal.ToArray(); UndoUtility.RegisterCompleteObjectUndo(selection, string.IsNullOrEmpty(undoMessage) ? "Modify Vertices" : undoMessage); if (beforeMeshModification != null) { beforeMeshModification(selection); } if (currentEvent.shift) { Extrude(); } m_IsEditing = true; m_WorldSnapEnabled = ProBuilderSnapSettings.snapMode == SnapMode.World; m_SnapAxisConstraint = ProBuilderSnapSettings.snapMethod == SnapAxis.ActiveAxis; ProGridsInterface.UseAxisConstraints(); m_MoveSnapValue = m_WorldSnapEnabled ? ProBuilderSnapSettings.worldSnapMoveValue : ProBuilderSnapSettings.incrementalSnapMoveValue; foreach (var mesh in selection) { mesh.ToMesh(); mesh.Refresh(); } OnToolEngaged(); }
void OnGUI() { GUILayout.Label("Lightmap UV Settings", EditorStyles.boldLabel); Lightmapping.autoUnwrapLightmapUV = EditorGUILayout.Toggle(m_AutoLightmapUVContent, Lightmapping.autoUnwrapLightmapUV); if (m_MissingLightmaps.Count > 0) { EditorGUILayout.HelpBox(GetMissingLightmapText(), MessageType.Warning); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button("Build Missing Lightmap UVs")) { // copy the missing lightmaps array so that MeshOptimized does not interfere with the rebuild iterator Lightmapping.RebuildMissingLightmapUVs(m_MissingLightmaps.ToArray()); EditorUtility.ShowNotification("Rebuild Missing Lightmap UVs"); } GUILayout.EndHorizontal(); } }
protected void BeginEdit(string undoMessage) { if (m_IsEditing) { return; } // Disable iterative lightmapping Lightmapping.PushGIWorkflowMode(); var selection = MeshSelection.topInternal.ToArray(); UndoUtility.RegisterCompleteObjectUndo(selection, string.IsNullOrEmpty(undoMessage) ? "Modify Vertices" : undoMessage); if (beforeMeshModification != null) { beforeMeshModification(selection); } if (currentEvent.shift) { Extrude(); } m_IsEditing = true; m_SnapAxisConstraint = EditorSnapping.snapMethod == SnapAxis.ActiveAxis; foreach (var mesh in selection) { mesh.ToMesh(); mesh.Refresh(); } OnToolEngaged(); }
void OnBeginVertexModification() { m_IsMoving = true; UndoUtility.RecordObject(m_Target, "Modify Bezier Spline"); Lightmapping.PushGIWorkflowMode(); }
/// <summary> /// Optmizes the mesh geometry, and generates a UV2 channel (if object is marked as LightmapStatic, or generateLightmapUVs is true). /// </summary> /// <remarks>This is only applicable to meshes with triangle topology. Quad meshes are not affected by this function.</remarks> /// <param name="mesh">The ProBuilder mesh component to be optimized.</param> /// <param name="generateLightmapUVs">If the Auto UV2 preference is disabled this parameter can be used to force UV2s to be built.</param> public static void Optimize(this ProBuilderMesh mesh, bool generateLightmapUVs = false) { if (mesh == null) { throw new ArgumentNullException("mesh"); } Mesh umesh = mesh.mesh; if (umesh == null || umesh.vertexCount < 1) { return; } bool skipMeshProcessing = false; // @todo Support mesh compression for topologies other than Triangles. for (int i = 0; !skipMeshProcessing && i < umesh.subMeshCount; i++) { if (umesh.GetTopology(i) != MeshTopology.Triangles) { skipMeshProcessing = true; } } if (!skipMeshProcessing) { bool autoLightmap = Lightmapping.autoUnwrapLightmapUV; #if UNITY_2019_2_OR_NEWER bool lightmapUVs = generateLightmapUVs || (autoLightmap && mesh.gameObject.HasStaticFlag(StaticEditorFlags.ContributeGI)); #else bool lightmapUVs = generateLightmapUVs || (autoLightmap && mesh.gameObject.HasStaticFlag(StaticEditorFlags.LightmapStatic)); #endif var usedInParticuleSystem = UnityEngine.ProBuilder.MeshUtility.IsUsedInParticuleSystem(mesh); // if generating UV2, the process is to manually split the mesh into individual triangles, // generate uv2, then re-assemble with vertex collapsing where possible. // if not generating uv2, just collapse vertices. if (lightmapUVs) { Vertex[] vertices = UnityEngine.ProBuilder.MeshUtility.GeneratePerTriangleMesh(umesh); float time = Time.realtimeSinceStartup; UnwrapParam unwrap = Lightmapping.GetUnwrapParam(mesh.unwrapParameters); Vector2[] uv2 = Unwrapping.GeneratePerTriangleUV(umesh, unwrap); // If GenerateUV2() takes longer than 3 seconds (!), show a warning prompting user to disable auto-uv2 generation. if ((Time.realtimeSinceStartup - time) > 3f) { Log.Warning(string.Format("Generate UV2 for \"{0}\" took {1} seconds! You may want to consider disabling Auto-UV2 generation in the `Preferences > ProBuilder` tab.", mesh.name, (Time.realtimeSinceStartup - time).ToString("F2"))); } if (uv2.Length == vertices.Length) { for (int i = 0; i < uv2.Length; i++) { vertices[i].uv2 = uv2[i]; } } else { Log.Warning("Generate UV2 failed. The returned size of UV2 array != mesh.vertexCount"); } UnityEngine.ProBuilder.MeshUtility.CollapseSharedVertices(umesh, vertices); } else { UnityEngine.ProBuilder.MeshUtility.CollapseSharedVertices(umesh); } if (usedInParticuleSystem) { UnityEngine.ProBuilder.MeshUtility.RestoreParticuleSystem(mesh); } } if (s_AutoResizeCollisions) { RebuildColliders(mesh); } if (meshOptimized != null) { meshOptimized(mesh, umesh); } if (Experimental.meshesAreAssets) { TryCacheMesh(mesh); } UnityEditor.EditorUtility.SetDirty(mesh); }