protected override void DoToolGUI() { if (showHandleInfo && isEditing) { DrawDeltaInfo("Scale: " + m_Scale.ToString("0.00")); } if (!isEditing) { m_Scale = Vector3.one; } EditorGUI.BeginChangeCheck(); var size = HandleUtility.GetHandleSize(m_HandlePosition); EditorHandleUtility.PushMatrix(); Handles.matrix = Matrix4x4.TRS(m_HandlePosition, m_HandleRotation, Vector3.one); m_Scale = Handles.ScaleHandle(m_Scale, Vector3.zero, Quaternion.identity, size); EditorHandleUtility.PopMatrix(); if (EditorGUI.EndChangeCheck()) { if (!isEditing) { BeginEdit("Scale Selection"); } Apply(Matrix4x4.Scale(m_Scale)); } }
protected override void DoTool(Vector3 handlePosition, Quaternion handleRotation) { base.DoTool(handlePosition, handleRotation); if (!isEditing) { m_Scale = Vector3.one; } EditorGUI.BeginChangeCheck(); var size = HandleUtility.GetHandleSize(handlePosition); EditorHandleUtility.PushMatrix(); Handles.matrix = Matrix4x4.TRS(handlePosition, handleRotation, Vector3.one); m_Scale = Handles.ScaleHandle(m_Scale, Vector3.zero, Quaternion.identity, size); EditorHandleUtility.PopMatrix(); if (EditorGUI.EndChangeCheck()) { if (!isEditing) { BeginEdit("Scale Selection"); } Apply(Matrix4x4.Scale(m_Scale)); } }
protected override void DoTool(Vector3 handlePosition, Quaternion handleRotation) { if (!isEditing) { m_Rotation = 0f; } EditorGUI.BeginChangeCheck(); var size = HandleUtility.GetHandleSize(handlePosition); EditorHandleUtility.PushMatrix(); Handles.matrix = Matrix4x4.TRS(handlePosition, handleRotation, Vector3.one); Handles.color = Color.blue; m_Euler.z = m_Rotation; m_Quaternion = Quaternion.Euler(m_Euler); m_Quaternion = Handles.Disc(m_Quaternion, Vector3.zero, Vector3.forward, size, relativeSnapEnabled, relativeSnapRotation); m_Euler = m_Quaternion.eulerAngles; m_Rotation = m_Euler.z; EditorHandleUtility.PopMatrix(); if (EditorGUI.EndChangeCheck()) { if (!isEditing) { BeginEdit("Rotate Textures"); } if (relativeSnapEnabled) { m_Rotation = Snapping.SnapValue(m_Rotation, relativeSnapX); } else if (progridsSnapEnabled) { m_Rotation = Snapping.SnapValue(m_Rotation, progridsSnapValue); } foreach (var mesh in elementSelection) { if (!(mesh is MeshAndTextures)) { continue; } var mat = (MeshAndTextures)mesh; var origins = mat.origins; var positions = mat.textures; foreach (var group in mat.elementGroups) { foreach (var index in group.indices) { positions[index] = mat.postApplyMatrix.MultiplyPoint( Math.RotateAroundPoint( mat.preApplyMatrix.MultiplyPoint3x4(origins[index]), Vector2.zero, -m_Rotation)); } } mesh.mesh.mesh.SetUVs(k_TextureChannel, positions); } } }
protected override void DoTool(Vector3 handlePosition, Quaternion handleRotation) { if (!isEditing) { m_Scale.x = 1f; m_Scale.y = 1f; m_UniformScale = 1f; } EditorGUI.BeginChangeCheck(); var size = HandleUtility.GetHandleSize(handlePosition); EditorHandleUtility.PushMatrix(); Handles.matrix = Matrix4x4.TRS(handlePosition, handleRotation, Vector3.one); var snap = relativeSnapEnabled ? relativeSnapScale : progridsSnapEnabled ? progridsSnapValue : 0f; Handles.color = Color.red; m_Scale.x = Handles.ScaleSlider(m_Scale.x, Vector3.zero, Vector3.right, Quaternion.identity, size, snap); Handles.color = Color.green; m_Scale.y = Handles.ScaleSlider(m_Scale.y, Vector3.zero, Vector3.up, Quaternion.identity, size, snap); Handles.color = Color.blue; m_UniformScale = Handles.ScaleValueHandle(m_UniformScale, Vector3.zero, Quaternion.identity, size, Handles.CubeHandleCap, snap); EditorHandleUtility.PopMatrix(); if (EditorGUI.EndChangeCheck()) { if (!isEditing) { BeginEdit("Scale Textures"); } var delta = m_Scale * m_UniformScale; delta.x = 1f / delta.x; delta.y = 1f / delta.y; foreach (var mesh in elementSelection) { if (!(mesh is MeshAndTextures)) { continue; } var mat = (MeshAndTextures)mesh; var origins = mat.origins; var positions = mat.textures; foreach (var group in mesh.elementGroups) { foreach (var index in group.indices) { positions[index] = mat.postApplyMatrix.MultiplyPoint( Vector2.Scale(mat.preApplyMatrix.MultiplyPoint3x4(origins[index]), delta)); } } mesh.mesh.mesh.SetUVs(k_TextureChannel, positions); } } }
protected override void DoTool(Vector3 handlePosition, Quaternion handleRotation) { if (!isEditing) { m_Position = Vector3.zero; } EditorHandleUtility.PushMatrix(); Handles.matrix = Matrix4x4.TRS(handlePosition, handleRotation, Vector3.one); EditorGUI.BeginChangeCheck(); Handles.color = Color.blue; m_Position = Handles.Slider2D(m_Position, Vector3.forward, Vector3.right, Vector3.up, HandleUtility.GetHandleSize(m_Position) * .2f, Handles.RectangleHandleCap, 0f, false); Handles.color = Color.green; m_Position = Handles.Slider(m_Position, Vector3.up); Handles.color = Color.red; m_Position = Handles.Slider(m_Position, Vector3.right); Handles.color = Color.white; if (EditorGUI.EndChangeCheck()) { if (!isEditing) { BeginEdit("Translate Textures"); } if (relativeSnapEnabled) { m_Position.x = ProGridsSnapping.SnapValue(m_Position.x, relativeSnapX); m_Position.y = ProGridsSnapping.SnapValue(m_Position.y, relativeSnapY); } else if (progridsSnapEnabled) { m_Position.x = ProGridsSnapping.SnapValue(m_Position.x, progridsSnapValue); m_Position.y = ProGridsSnapping.SnapValue(m_Position.y, progridsSnapValue); } // invert `y` because to users it's confusing that "up" in UV space visually moves the texture down var delta = new Vector4(m_Position.x, -m_Position.y, 0f, 0f); foreach (var value in elementSelection) { var selection = value as TranslateTextureSelection; if (selection == null) { continue; } // Account for object scale delta *= k_Vector3Magnitude / selection.mesh.transform.lossyScale.magnitude; var origins = selection.origins; var positions = selection.textures; // Translating faces is treated as a special case because we want the textures in scene to visually // match the movement of the translation handle. When UVs are scaled, they have the appearance of // moving faster or slower (even though they are translating the correct distances). To avoid this, // we cache the UV scale of each face and modify the translation delta accordingly. This isn't perfect, // as it will not be able to find the scale for sheared or otherwise distorted face UVs. However, for // most cases it maps quite well. if (ProBuilderEditor.selectMode == SelectMode.TextureFace) { foreach (var face in selection.faceAndScale) { var faceDelta = new Vector4(delta.x / face.item2.x, delta.y / face.item2.y, 0f, 0f); foreach (var index in face.item1.distinctIndexes) { positions[index] = origins[index] + faceDelta; } } } else { foreach (var group in value.elementGroups) { foreach (var index in group.indices) { positions[index] = origins[index] + delta; } } } selection.mesh.mesh.SetUVs(k_TextureChannel, positions); } } EditorHandleUtility.PopMatrix(); }
protected override void DoTool(Vector3 handlePosition, Quaternion handleRotation) { if (!isEditing) { m_Position = Vector3.zero; } EditorHandleUtility.PushMatrix(); Handles.matrix = Matrix4x4.TRS(handlePosition, handleRotation, Vector3.one); EditorGUI.BeginChangeCheck(); Handles.color = Color.blue; m_Position = Handles.Slider2D(m_Position, Vector3.forward, Vector3.right, Vector3.up, HandleUtility.GetHandleSize(m_Position) * .2f, Handles.RectangleHandleCap, 0f, false); Handles.color = Color.green; m_Position = Handles.Slider(m_Position, Vector3.up); Handles.color = Color.red; m_Position = Handles.Slider(m_Position, Vector3.right); Handles.color = Color.white; if (EditorGUI.EndChangeCheck()) { if (!isEditing) { BeginEdit("Translate Textures"); } if (relativeSnapEnabled) { m_Position.x = Snapping.SnapValue(m_Position.x, relativeSnapX); m_Position.y = Snapping.SnapValue(m_Position.y, relativeSnapY); } else if (progridsSnapEnabled) { m_Position.x = Snapping.SnapValue(m_Position.x, progridsSnapValue); m_Position.y = Snapping.SnapValue(m_Position.y, progridsSnapValue); } // invert `y` because to users it's confusing that "up" in UV space visually moves the texture down var delta = new Vector4(m_Position.x, -m_Position.y, 0f, 0f); foreach (var mesh in elementSelection) { if (!(mesh is MeshAndTextures)) { continue; } delta *= 1f / mesh.mesh.transform.lossyScale.magnitude; var origins = ((MeshAndTextures)mesh).origins; var positions = ((MeshAndTextures)mesh).textures; foreach (var group in mesh.elementGroups) { foreach (var index in group.indices) { positions[index] = origins[index] + delta; } } mesh.mesh.mesh.SetUVs(k_TextureChannel, positions); } } EditorHandleUtility.PopMatrix(); }