public void OnEnable() { if (m_brush == null) { m_brush = new IslandBrush(); } }
public override void Paint(Island island) { #if UNITY_EDITOR IslandBrush brush = new IslandBrush(); IslandBrush detailBrush = new IslandBrush(); brush.m_detailBrush = false; brush.m_solidBrush = false; brush.m_color = new Color(0.6f, 0.2f, 0.0f, 1.0f); brush.m_opacity = 1.0f; detailBrush.m_detailBrush = true; detailBrush.m_solidBrush = false; detailBrush.m_color = new Color(1.0f, 0.0f, 0.0f, 1.0f); detailBrush.m_opacity = 1.0f; brush.m_brushSizeX = (int)island.WorldSizeToTexel(transform.localScale.x) * 2; brush.Update(); detailBrush.m_brushSizeX = 40; //(int)island.WorldSizeToTexel(transform.localScale.x); detailBrush.Update(); island.PaintPixel(transform.position.x, transform.position.z, brush); island.PaintPixel(transform.position.x, transform.position.z, detailBrush); //island.PaintPixel(m_instancePositions[i].x, m_instancePositions[i].z, detailBrush); //island.PaintPixel(m_instancePositions[i].x, m_instancePositions[i].z, detailBrush); #endif }
/// plonk the brush down at the given point. /// More complicated than I would have liked thanks to the sliced terrain. /// TODO: Sort the importing so that read/write is disabled on the splat maps when building /// outside the editor. Re-enable compression so the splat-maps aren't a meg each. public void PaintPixel(float x, float y, IslandBrush brush) { m_sectionSize = (MaxBounds.x - MinBounds.x) / (float)SectionsX; if (x > MinBounds.x && y > MinBounds.y && x < MaxBounds.x && y < MaxBounds.y) { SectionPixelPair pair = GetPair(x, y); int xStart = pair.pixelX - brush.m_brushSizeX / 2; int xEnd = pair.pixelX + brush.m_brushSizeX / 2; int yStart = pair.pixelY - brush.m_brushSizeX / 2; int yEnd = pair.pixelY + brush.m_brushSizeX / 2; for (int currentX = xStart; currentX < xEnd; currentX++) { for (int currentY = yStart; currentY < yEnd; currentY++) { int sectionX = pair.sectionX; int sectionY = pair.sectionY; int pixelX = currentX; int pixelY = currentY; while (pixelX < 0) { sectionX--; pixelX += 512; } while (pixelX >= 512) { sectionX++; pixelX -= 512; } while (pixelY < 0) { sectionY--; pixelY += 512; } while (pixelY >= 512) { sectionY++; pixelY -= 512; } if (sectionX >= SectionsX || sectionY >= SectionsY || sectionX < 0 || sectionY < 0) { continue; } int index = (currentY - yStart) * brush.m_brushSizeX + (currentX - xStart); Color current = m_editTextures[sectionY * SectionsX + sectionX].colors[pixelY * 512 + pixelX]; if (brush.m_detailBrush) { // TODO: What a complete hack. // The brush's alpha channel is being used to store the brush dynamics, so when trying to write alpha I just // bung the target value into R. How shameful. float newColor = brush.m_brushPixels[index].r; m_editTextures[sectionY * SectionsX + sectionX].colors[pixelY * 512 + pixelX].a = Mathf.Lerp(current.a, newColor, brush.m_brushPixels[index].a); } else { float alpha = current.a; // Don't lerp alpha in this scenario, else you'll bugger t'detail Vector3 newColor = (Vector3)((Vector4)(brush.m_brushPixels[index])); m_editTextures[sectionY * SectionsX + sectionX].colors[pixelY * 512 + pixelX] = Vector4.Lerp(current, newColor, brush.m_brushPixels[index].a); m_editTextures[sectionY * SectionsX + sectionX].colors[pixelY * 512 + pixelX].a = alpha; } m_editTextures[sectionY * SectionsX + sectionX].dirty = true; m_editTextures[sectionY * SectionsX + sectionX].saveRequired = true; saveRequired = true; } } } }