public override void Read(BinaryReader br) { dataHead = new NodeBoundData(br); flag = br.ReadUInt32(); distance = br.ReadByte(); roadNum = br.ReadUInt32(); matNum = br.ReadUInt32(); startIndex = br.ReadUInt32(); endIndex = br.ReadUInt32(); dataRight = new RoadData(br); dataLeft = new RoadData(br); centerNum = br.ReadUInt16(); tangent = br.ReadSingle(); unknown = br.ReadUInt32(); signCount = br.ReadUInt32(); if (signCount > 0) { signs = new SignData[signCount]; for (int i = 0; i < signCount; i++) { signs[i] = new SignData(br); } } brushCount = br.ReadUInt32(); if (brushCount > 0) { brushs = new BrushData[brushCount]; for (int i = 0; i < brushCount; i++) { brushs[i] = new BrushData(br); } } }
public static void PaintWithSymmetry(ref float[,] texture, BrushData brush) { for (int i = 0; i < BrushGenerator.Current.PaintPositions.Length; i++) { Paint(ref texture, brush, i); } }
// this is the delegate we're going to return to apply a brush stamp. Your passed a paint job, // which contains important cached information to make painting fast, and hold the actual stream data. // the index is the index into the vertex array, the val is the brush data we supplied in GetBrushObject, // and r is a 0 to 1 with how far to tween the value towards the brush (brush pressure * deltatime) void LerpFunc(PaintJob j, int idx, ref object val, float r) { // retrieve our brush data and get the stream we're painting into BrushData bd = val as BrushData; var s = j.stream; // use our vertex position to generate noise. We use the get position function because it will // return a vert position from the original meshes cached verticies or modified verticies if // we've modified them. This makes it compatible with deformations, etc. Vector3 pos = j.GetPosition(idx); // convert into world space pos = j.renderer.localToWorldMatrix.MultiplyPoint(pos); // scale by frequency pos.x *= bd.frequency; pos.y *= bd.frequency; pos.z *= bd.frequency; float noise = 0.5f * (0.5f * JBooth.VertexPainterPro.SimplexNoise.Noise.Generate(pos.x, pos.y, pos.z) + 0.5f); noise += 0.25f * (0.5f * JBooth.VertexPainterPro.SimplexNoise.Noise.Generate(pos.y * 2.031f, pos.z * 2.031f, pos.x * 2.031f) + 0.5f); noise += 0.25f * (0.5f * JBooth.VertexPainterPro.SimplexNoise.Noise.Generate(pos.z * 4.01f, pos.x * 4.01f, pos.y * 4.01f) + 0.5f); noise *= bd.amplitude; // lerp the noise in Color c = s.colors[idx]; c.r = Mathf.Lerp(c.r, noise, r); c.g = Mathf.Lerp(c.g, noise, r); c.b = Mathf.Lerp(c.b, noise, r); s.colors[idx] = c; }
private void FillArray() { BrushData data = null; string savePath = UnityEditor.EditorUtility.OpenFilePanel("Choose brushes file", Application.dataPath, "json"); if (File.Exists(savePath)) { string json = File.ReadAllText(savePath); data = JsonUtility.FromJson <BrushData>(json); Debug.Log($"loaded from: {savePath}"); } else { string message = "You didn't choose file, all brush colors is white"; UnityEditor.EditorUtility.DisplayDialog("Error", message, "OK"); } var names = Enum.GetNames(typeof(CellType)); brushes = new Brush[names.Length]; for (int i = 0; i < brushes.Length; i++) { var brushName = names[i]; var type = (CellType)i; var color = data != null ? data.brushes[i].cellColor : Color.white; brushes[i] = new Brush(brushName, type, color); } }
public static void Open(BrushData brushData) { var win = GetWindow <BrushDataEditorWindow>(true, "BrushData"); win._brushData = brushData; win._brushEditor = UnityEditor.Editor.CreateEditor(brushData); }
private void ParseBrushPreset(BigEndianBinaryReader reader, uint count) { string presetName = null; BrushData brushData = null; for (uint i = 0; i < count; i++) { string key = ParseKey(reader); DescriptorTypes type = (DescriptorTypes)reader.ReadUInt32(); #if DEBUG System.Diagnostics.Debug.WriteLine(string.Format( CultureInfo.CurrentCulture, "brushPreset item {0}: {1} ({2}) at 0x{3:X8}", new object[] { i, key, type, reader.Position })); #endif if (key.Equals("Nm ", StringComparison.Ordinal)) { presetName = ParseString(reader); } else if (key.Equals("Brsh", StringComparison.Ordinal) && type == DescriptorTypes.Descriptor) { brushData = ParseBrushDescriptor(reader); } else { ParseType(reader, type); } } if (brushData != null && !string.IsNullOrEmpty(brushData.sampledDataTag)) { sampledBrushes.Add(new SampledBrush(presetName, brushData.sampledDataTag, brushData.diameter)); } }
//手动测试 private void button1_Click(object sender, EventArgs e) { BrushDialog dlg = new BrushDialog(brushData); if (dlg.ShowDialog() == DialogResult.OK) { brushData = dlg.BrushData; } panel1.Invalidate(); }
/// <summary> /// 鼠标创建控件时绘制图形 /// </summary> /// <param name="g"></param> public override void CreatingPaint(Graphics g) { List <PointF> ds = NodeDatas; if (ds != null && ds.Count > 1) { Brush br = BrushData.CreateBrush(Rect, Path); g.FillPolygon(br, ds.ToArray()); g.DrawPolygon(Pens.Black, ds.ToArray()); } }
public override void Init(string _Name, BrushData _Brush, Color _Color) { string playerName = m_StatsManager.GetNickname(); if (string.IsNullOrEmpty(playerName)) { playerName = Constants.c_DefaultPlayerName; } base.Init(playerName, _Brush, _Color); }
protected virtual void FillPath(Graphics g) { if (BasePath.PointCount > 1 && BrushHasValid) { Brush br = BrushData.CreateBrush(Rect, Path); if (br != null) { g.FillPath(br, BasePath); br.Dispose(); } } }
public void DrawingTestBrushDataConversion() { // Create a test brush var brush1 = new BrushData(Color.Yellow); // Convert to string var brush1String = brush1.ToString(); // Convert from string var brush2 = BrushData.Parse(brush1String); // Validate result Assert.AreEqual(brush1, brush2); }
public void DrawingTestBrushDataXmlSerialize() { // Create a test object and serialize var brush1 = new BrushData(Color.Black, Color.Blue, 45m); var brush1Xml = brush1.SerializeXml(); // De-serialize the brush and check contents match var brush2 = XmlSerializerExtensions.DeserializeXml <BrushData>(brush1Xml); Assert.AreEqual(brush1, brush2); // Serialize again and check the XML matches var brush2Xml = brush2.SerializeXml(); Assert.AreEqual(brush1Xml, brush2Xml); }
private BrushData ParseSampledBrush(BinaryReverseReader reader, uint count) { BrushData data = new BrushData(); for (uint i = 0; i < count; i++) { string key = ParseKey(reader); DescriptorTypes type = (DescriptorTypes)reader.ReadUInt32(); #if DEBUG System.Diagnostics.Debug.WriteLine(string.Format( CultureInfo.CurrentCulture, "sampledBrush item {0}: {1} ({2}) at 0x{3:X8}", new object[] { i, key, type, reader.BaseStream.Position })); #endif UnitFloat unitFloat; switch (key) { case "Dmtr": unitFloat = ParseUnitFloat(reader); if (unitFloat.type == UnitTypes.Pixel) { data.diameter = (int)unitFloat.value; } break; case "Spcn": unitFloat = ParseUnitFloat(reader); if (unitFloat.type == UnitTypes.Percent) { data.spacing = (int)unitFloat.value; } break; case "sampledData": data.sampledDataTag = ParseString(reader); break; default: ParseType(reader, type); break; } } return(data); }
private void SaveColors() { string savePath = UnityEditor.EditorUtility.OpenFolderPanel("Choose save path", Application.dataPath, string.Empty); if (string.IsNullOrEmpty(savePath)) { string message = "You didn't choose save path, saving process cancelled"; UnityEditor.EditorUtility.DisplayDialog("Error", message, "OK"); } else { savePath += "/brushes.json"; var data = new BrushData(brushes); string json = JsonUtility.ToJson(data, true); File.WriteAllText(savePath, json); UnityEditor.AssetDatabase.Refresh(); Debug.Log($"saved to: {savePath}"); } }
public override void CreatingPaint(Graphics g) { List <PointF> ds = NodeDatas; if (ds != null && ds.Count > 1) { Pen p = PenData.CreatePen(Rect, Path); Brush br = BrushData.CreateBrush(Rect, Path); List <PointF> list = MyTools.ConvertBeziers(ds, true); if (list.Count > 0) { GraphicsPath path = new GraphicsPath(); path.AddBeziers(list.ToArray()); g.FillPath(br, path); g.DrawPath(p, path); } p.Dispose(); br.Dispose(); } }
private BrushData ParseBrushDescriptor(BigEndianBinaryReader reader) { string name = ParseString(reader); string classId = ParseClassId(reader); uint count = reader.ReadUInt32(); #if DEBUG System.Diagnostics.Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "Parsing {0} ({1} items)", classId, count)); #endif BrushData data = null; if (classId.Equals("sampledBrush", StringComparison.Ordinal)) { data = ParseSampledBrush(reader, count); } else { for (uint i = 0; i < count; i++) { string key = ParseKey(reader); DescriptorTypes type = (DescriptorTypes)reader.ReadUInt32(); #if DEBUG System.Diagnostics.Debug.WriteLine(string.Format( CultureInfo.CurrentCulture, "{0} item {1}: {2} ({3}) at 0x{4:X8}", new object[] { classId, i, key, type, reader.Position })); #endif ParseType(reader, type); } } return(data); }
public virtual void Init(string _Name, BrushData _Brush, Color _Color) { m_SizeSecondaryBrush = Constants.c_SizeSecondaryMultipler; // Cache m_GameManager = GameManager.Instance; m_Transform = transform; m_Direction = Vector3.zero; m_TerrainManager = TerrainManager.Instance; m_DrawLines = new List <DrawLine>(1) { GetComponent <DrawLine>() }; m_BrushData = _Brush; // Buffers m_SearchBuffer = new List <GameObject> (); // Runtime GameObject brushObject = Instantiate(_Brush.m_Prefab, m_Transform) as GameObject; m_Brush = brushObject.GetComponent <Brush> (); m_DrawLines[0].Init(this, m_Brush); m_Color = _Color; m_ColorHash = PaintSurface.GetColorHash(_Color); m_Brush.Init(this, Brush.EBrushType.MAIN); m_PlayerName = _Name; m_WorldPercent = 0.0f; m_Level = 0; RegisterMap(); m_GameManager.onEndGame += OnEndGame; }
void LerpFunc(PaintJob j, int idx, ref object val, float r) { BrushData bd = val as BrushData; var s = j.stream; Vector3 pos = j.GetPosition(idx); pos = j.renderer.localToWorldMatrix.MultiplyPoint(pos); pos.x *= bd.frequency; pos.y *= bd.frequency; pos.z *= bd.frequency; float noise = 0.5f * (0.5f * ShaderLib.VertexPainter.SimplexNoise.Noise.Generate(pos.x, pos.y, pos.z) + 0.5f); noise += 0.25f * (0.5f * ShaderLib.VertexPainter.SimplexNoise.Noise.Generate(pos.y * 2.031f, pos.z * 2.031f, pos.x * 2.031f) + 0.5f); noise += 0.25f * (0.5f * ShaderLib.VertexPainter.SimplexNoise.Noise.Generate(pos.z * 4.01f, pos.x * 4.01f, pos.y * 4.01f) + 0.5f); noise *= bd.amplitude; // lerp the noise in Color c = s.colors[idx]; c.r = Mathf.Lerp(c.r, noise, r); c.g = Mathf.Lerp(c.g, noise, r); c.b = Mathf.Lerp(c.b, noise, r); s.colors[idx] = c; }
public static void Paint(ref float[,] texture, BrushData brush, int brushId = 0){ hmWidth = texture.GetLength (0); hmHeight = texture.GetLength (1); posXInTerrain = (int) (BrushGenerator.PaintPositions[brushId].x * hmWidth); posYInTerrain = (int) (BrushGenerator.PaintPositions[brushId].z * hmHeight); offset = (int)(brush.size / 2); // Horizontal Brush Offsets int OffsetLeft = 0; if(posXInTerrain-offset < 0) OffsetLeft = Mathf.Abs(posXInTerrain-offset); int OffsetRight = 0; if(posXInTerrain-offset + brush.size > hmWidth) OffsetRight = (int)(posXInTerrain-offset + brush.size - hmWidth); // Vertical Brush Offsets int OffsetDown = 0; if(posYInTerrain-offset < 0) OffsetDown = Mathf.Abs(posYInTerrain-offset); int OffsetTop = 0; if(posYInTerrain-offset + brush.size > hmHeight) OffsetTop = (int)(posYInTerrain-offset + brush.size - hmHeight); //float[,] heights = Map.Teren.terrainData.GetHeights(posXInTerrain-offset + OffsetLeft, posYInTerrain-offset + OffsetDown ,(brushSize - OffsetLeft) - OffsetRight, (brushSize - OffsetDown) - OffsetTop); float CenterHeight = 0; if(brush.BrushType == BrushTypes.Smooth || brush.BrushType == BrushTypes.Sharpen){ for (i = 0; i < (brush.size - OffsetDown) - OffsetTop; i++){ for (j = 0; j < (brush.size - OffsetLeft) - OffsetRight; j++){ tx = i + posXInTerrain - offset + OffsetLeft; ty = j + posYInTerrain-offset + OffsetDown; CenterHeight += texture[tx, ty]; } } CenterHeight /= brush.size * brush.size; } for (i = 0; i < (brush.size - OffsetDown) - OffsetTop; i++){ for (j = 0; j<(brush.size - OffsetLeft) - OffsetRight; j++){ tx = i + posXInTerrain - offset + OffsetLeft; ty = j + posYInTerrain-offset + OffsetDown; // Brush strength x = (int)(((i + OffsetDown) / (float)brush.size) * BrushGenerator.PaintImage[brushId].width); y = (int)(((j + OffsetLeft) / (float)brush.size) * BrushGenerator.PaintImage[brushId].height); BrushValue = BrushGenerator.PaintImage[brushId].GetPixel(y, x); SambleBrush = BrushValue.r; if(SambleBrush >= 0.02f) { switch (brush.BrushType) { case BrushTypes.Standard: texture[tx, ty] += SambleBrush * brush.strength * 0.0002f * (brush.Invert?(-1):1); break; case BrushTypes.Smooth: PixelPower = Mathf.Abs( texture[tx, ty] - CenterHeight); texture[tx, ty] = Mathf.Lerp(texture[tx, ty], CenterHeight, brush.strength * 0.4f * Mathf.Pow(SambleBrush, 2) * PixelPower); break; case BrushTypes.Sharpen: PixelPower = texture[tx, ty] - CenterHeight; texture[tx, ty] += Mathf.Lerp(PixelPower, 0, PixelPower * 10) * brush.strength * 0.01f * Mathf.Pow(SambleBrush, 2); break; } texture[tx, ty] = Mathf.Clamp(texture[tx, ty], brush.MinMax.x, brush.MinMax.y); } } } }
//Convert a DnaBrush to a System.Drawing.Brush private static System.Drawing.Brush GetGdiBrush(BrushData b) { return(new SolidBrush(Color.FromArgb(b.Alpha, b.Red, b.Green, b.Blue))); }
///======================================================================== /// Method : GetSteeringPixelBrush /// /// <summary> /// Get the brush for pixel-by-pixel editing of steering controls /// </summary> /// <param name="i"></param> /// <returns></returns> ///======================================================================== private Image GetSteeringPixelBrush(int i, out BrushData xoBrush) { Bitmap lRet = new Bitmap(4 * SCALE, 4 * SCALE); Graphics g = Graphics.FromImage(lRet); Pen p = new Pen(Color.Black, 1); Point lMidpoint = new Point(2 * SCALE, 2 * SCALE); if (i <= FlatChunk.STEERING_HIGHESTDIRECTION) { g.DrawRectangle(p, 0, 0, 63, 63); Utils.DrawArrow(g, p, lMidpoint, 4096 - (i * 256), (int)(mSubjectTileScaledWidth * 0.4), 1, true); xoBrush = new BrushData((byte)i, "Steering direction " + SteeringImageChunk.GetDirectionName((byte)i)); return lRet; } else { xoBrush = null; return null; } }
private Image GetRespawnBrush(int i, out BrushData xoBrush) { Bitmap lRet = new Bitmap(4 * SCALE, 4 * SCALE); Graphics g = Graphics.FromImage(lRet); Pen p = new Pen(Color.Red, 1); Point lMidpoint = new Point(2 * SCALE, 2 * SCALE); if (i == 0) { Utils.DrawCross(g, p, lMidpoint, (int)(mSubjectTileScaledWidth * 0.8)); xoBrush = new BrushData((byte)i, "No respawn (Warning: Corrupts Behaviours)"); return lRet; } else if (i <= FlatChunk.STEERING_HIGHESTDIRECTION + 1) { g.DrawRectangle(p, 0, 0, 63, 63); Utils.DrawArrow(g, p, lMidpoint, 4096 - ((i - 1) * 256), (int)(mSubjectTileScaledWidth * 0.4), 1, true); xoBrush = new BrushData((byte)i, "Respawn direction " + i.ToString() + " (Warning: Corrupts Steering)"); return lRet; } else { xoBrush = null; return null; } }
private Image GetWaypointBrush(int i, out BrushData xoBrush) { if (i > (int)eWaypointAction.Restart) { xoBrush = null; return null; } string lLabel = ""; switch (i) { case (int)eWaypointAction.AddPath: lLabel = "Add path"; break; default: lLabel = ((eWaypointAction)i).ToString(); break; } int lWidth = 4 * SCALE; int lHeight = 4 * SCALE; Bitmap lRet = new Bitmap(lWidth, lHeight); Graphics g = Graphics.FromImage(lRet); Font lFont = new Font(FontFamily.GenericMonospace, 10); int lTextWidth = (int)(g.MeasureString(lLabel, lFont).Width); if (lTextWidth > lWidth) { lWidth = (int)lTextWidth; lRet = new Bitmap(lWidth, lHeight); g = Graphics.FromImage(lRet); } Pen p = new Pen(Color.Red, 1); Point lMidpoint = new Point(lWidth / 2, lHeight / 2); g.DrawRectangle(p, 0, 0, lWidth - 1, lHeight - 1); Utils.DrawString(g, lLabel, lMidpoint); xoBrush = new BrushData((byte)i, lLabel); return lRet; }
private Image GetBehaviourBrush(int i, out BrushData xoBrush) { if (i >= FlatChunk.Behaviours.Length) { xoBrush = null; return null; } xoBrush = new BrushData((byte)i, FlatChunk.Behaviours[i].BehaviourTypes.ToString()); return FlatChunk.Behaviours[i].ToBitmap(); }
private Image GetCameraBrush(int i, out BrushData xoBrush) { if (i >= 1) { int lCameraIdx = i + 50; CameraPosChunk lCameraPos = mMainForm.CurrentLevel.GetCameraById(lCameraIdx); if (lCameraPos == null) { xoBrush = null; return null; } xoBrush = new BrushData((byte)lCameraIdx, "Camera pos " + lCameraIdx.ToString()); return lCameraPos.ToImage(); } //======================================================================= // Camera position 0 is the "default" camera position (in multi-player // mode, anyway) //======================================================================= string lLabel = "Default"; int lWidth = 4 * SCALE; int lHeight = 4 * SCALE; Bitmap lRet = new Bitmap(lWidth, lHeight); Graphics g = Graphics.FromImage(lRet); Font lFont = new Font(FontFamily.GenericMonospace, 10); int lTextWidth = (int)(g.MeasureString(lLabel, lFont).Width); if (lTextWidth > lWidth) { lWidth = (int)lTextWidth; lRet = new Bitmap(lWidth, lHeight); g = Graphics.FromImage(lRet); } Pen p = new Pen(Color.Black, 1); Point lMidpoint = new Point(lWidth / 2, lHeight / 2); g.DrawRectangle(p, 0, 0, lWidth - 1, lHeight - 1); Utils.DrawString(g, lLabel, lMidpoint); xoBrush = new BrushData(0, "Default camera"); return lRet; }
public static void PaintWithSymmetry(ref float[,] texture, BrushData brush){ for (int i = 0; i < BrushGenerator.PaintPositions.Length; i++) { Paint (ref texture, brush, i); } }
public static void Paint(ref float[,] texture, BrushData brush, int brushId = 0) { hmWidth = texture.GetLength(0); hmHeight = texture.GetLength(1); posXInTerrain = (int)(BrushGenerator.Current.PaintPositions[brushId].x * hmWidth); posYInTerrain = (int)(BrushGenerator.Current.PaintPositions[brushId].z * hmHeight); offset = (int)(brush.size / 2); // Horizontal Brush Offsets int OffsetLeft = 0; if (posXInTerrain - offset < 0) { OffsetLeft = Mathf.Abs(posXInTerrain - offset); } int OffsetRight = 0; if (posXInTerrain - offset + brush.size > hmWidth) { OffsetRight = (int)(posXInTerrain - offset + brush.size - hmWidth); } // Vertical Brush Offsets int OffsetDown = 0; if (posYInTerrain - offset < 0) { OffsetDown = Mathf.Abs(posYInTerrain - offset); } int OffsetTop = 0; if (posYInTerrain - offset + brush.size > hmHeight) { OffsetTop = (int)(posYInTerrain - offset + brush.size - hmHeight); } //float[,] heights = Map.Teren.terrainData.GetHeights(posXInTerrain-offset + OffsetLeft, posYInTerrain-offset + OffsetDown ,(brushSize - OffsetLeft) - OffsetRight, (brushSize - OffsetDown) - OffsetTop); float CenterHeight = 0; if (brush.BrushType == BrushTypes.Smooth || brush.BrushType == BrushTypes.Sharpen) { for (i = 0; i < (brush.size - OffsetDown) - OffsetTop; i++) { for (j = 0; j < (brush.size - OffsetLeft) - OffsetRight; j++) { tx = i + posXInTerrain - offset + OffsetLeft; ty = j + posYInTerrain - offset + OffsetDown; CenterHeight += texture[tx, ty]; } } CenterHeight /= brush.size * brush.size; } for (i = 0; i < (brush.size - OffsetDown) - OffsetTop; i++) { for (j = 0; j < (brush.size - OffsetLeft) - OffsetRight; j++) { tx = i + posXInTerrain - offset + OffsetLeft; ty = j + posYInTerrain - offset + OffsetDown; // Brush strength x = (int)(((i + OffsetDown) / (float)brush.size) * BrushGenerator.Current.PaintImage[brushId].width); y = (int)(((j + OffsetLeft) / (float)brush.size) * BrushGenerator.Current.PaintImage[brushId].height); BrushValue = BrushGenerator.Current.PaintImage[brushId].GetPixel(y, x); SambleBrush = BrushValue.r; if (SambleBrush >= 0.02f) { switch (brush.BrushType) { case BrushTypes.Standard: texture[tx, ty] += SambleBrush * brush.strength * 0.0002f * (brush.Invert ? (-1) : 1); break; case BrushTypes.Smooth: PixelPower = Mathf.Abs(texture[tx, ty] - CenterHeight); texture[tx, ty] = Mathf.Lerp(texture[tx, ty], CenterHeight, brush.strength * 0.4f * Mathf.Pow(SambleBrush, 2) * PixelPower); break; case BrushTypes.Sharpen: PixelPower = texture[tx, ty] - CenterHeight; texture[tx, ty] += Mathf.Lerp(PixelPower, 0, PixelPower * 10) * brush.strength * 0.01f * Mathf.Pow(SambleBrush, 2); break; } texture[tx, ty] = Mathf.Clamp(texture[tx, ty], brush.MinMax.x, brush.MinMax.y); } } } }