private void PaintHeight(float hardness) { GameObject terrain = m_Editor.terrain.gameObject; Vector2 size = UEditorTools.GetSizeOfMesh(m_Editor.terrain.mesh, terrain.transform); float multiple; if (size.x > size.y) { multiple = size.y; } else { multiple = size.x; } Event e = Event.current; Ray ray = HandleUtility.GUIPointToWorldRay(e.mousePosition); RaycastHit[] hits = Physics.RaycastAll(ray); float bs = m_BrushSize; int fallOff = m_FallOff; foreach (RaycastHit hit in hits) { if (hit.collider.gameObject == terrain) { Vector3 relativePoint = terrain.transform.InverseTransformPoint(hit.point); DeformMesh(m_Editor.terrain.mesh, relativePoint, (float)(hardness * 30 * Time.deltaTime * multiple), bs, fallOff); } } }
void Paint(RaycastHit hit) { int texIndex = m_SelectedTex; float hardness = m_Hardness; int passIndex = m_SelectedPass; float brushSize = m_BrushSize; USubMesh sm = subMesh; UPass pass = sm[passIndex]; int texW = pass.mixTex.width; int texH = pass.mixTex.height; int centerX = Mathf.FloorToInt(hit.textureCoord.x * texW); int centerY = Mathf.FloorToInt(hit.textureCoord.y * texH); Vector2 bounds = UEditorTools.GetSizeOfMesh(sm.mesh, m_Editor.terrain.transform); int pixelSize = 0; if (texW > texH) { pixelSize = (int)((brushSize / bounds.x) * texW); } else { pixelSize = (int)((brushSize / bounds.y) * texH); } int x = Mathf.Clamp(centerX - pixelSize, 0, texW - 1); int y = Mathf.Clamp(centerY - pixelSize, 0, texH - 1); int width = Mathf.Clamp(2 * pixelSize, 0, texW - x); int height = Mathf.Clamp(2 * pixelSize, 0, texH - y); List <Color[]> srcPixels = new List <Color[]>(); sm.passes.ToList().ForEach(p => srcPixels.Add(p.mixTex.GetPixels(x, y, width, height, 0))); for (int i = 0, max = srcPixels.Count; i < max; i++) { Color[] pixels = srcPixels[i]; for (int h = 0; h < height; h++) { for (int w = 0; w < width; w++) { Color targetColor; if (i == passIndex) { targetColor = GetColor(texIndex); } else { targetColor = Color.clear; } int ix = (int)(w * 64 / width); int iy = (int)(h * 64 / height); int index = (h * width) + w; float blendFactor = m_Brush.GetStrengthInt(ix, iy) * hardness * 0.1f; pixels[index] = Color.Lerp(pixels[index], targetColor, blendFactor); } } sm[i].Paint(x, y, width, height, pixels); } }
void GetTexSize(ref int width, ref int height) { Vector2 size = UEditorTools.GetSizeOfMesh(subMesh.mesh, m_Editor.terrain.transform); if (size.x < size.y) { width = (int)(maxSize * size.x / size.y); height = maxSize; } else if (size.x >= size.y) { height = (int)(maxSize * size.y / size.x); width = maxSize; } }