public void Paint(P3D_Brush brush, Vector2 uv) { if (this.painter != null) { this.painter.Paint(brush, uv); } }
private void DrawSaveBrush() { EditorGUILayout.Separator(); var rect = P3D_Helper.Reserve(16.0f, true); var exists = PresetBrushes.Exists(b => b.Name == currentBrush.Name); if (GUI.Button(rect, exists == true ? "Overwrite Preset" : "Save Preset") == true) { var presetBrush = PresetBrushes.Find(b => b.Name == currentBrush.Name); if (presetBrush == null) { presetBrush = new P3D_Brush(); PresetBrushes.Add(presetBrush); } presetBrush.Name = currentBrush.Name.Replace("\n", ""); presetBrush.Blend = currentBrush.Blend; presetBrush.Color = currentBrush.Color; presetBrush.Direction = currentBrush.Direction; presetBrush.Shape = currentBrush.Shape; presetBrush.Size = currentBrush.Size; presetBrush.Detail = currentBrush.Detail; presetBrush.DetailScale = currentBrush.DetailScale; SavePresets(); } }
private void DrawSaveBrush() { EditorGUILayout.Separator(); var rect = P3D_Helper.Reserve(16.0f, true); var exists = PresetBrushes.Exists(b => b.Name == currentBrush.Name); if (GUI.Button(rect, exists == true ? "Overwrite Preset" : "Save Preset") == true) { var presetBrush = PresetBrushes.Find(b => b.Name == currentBrush.Name); if (presetBrush == null) { presetBrush = new P3D_Brush(); PresetBrushes.Add(presetBrush); } currentBrush.Name = currentBrush.Name.Replace("\n", ""); currentBrush.CopyTo(presetBrush); SavePresets(); } }
public static void ScenePaintBetweenNearest(P3D_Brush brush, Vector3 startPosition, Vector3 endPosition, int layerMask = -1, int groupMask = -1) { float num = Vector3.Distance(startPosition, endPosition); if (num != 0f) { P3D_Paintable paintable = null; P3D_Result result = null; for (int i = AllPaintables.Count - 1; i >= 0; i--) { P3D_Paintable paintable2 = AllPaintables[i]; if (P3D_Helper.IndexInMask(paintable2.gameObject.layer, layerMask)) { P3D_Tree tree = paintable2.GetTree(); if (tree != null) { Transform transform = paintable2.transform; Vector3 startPoint = transform.InverseTransformPoint(startPosition); P3D_Result result2 = tree.FindBetweenNearest(startPoint, startPoint + ((transform.InverseTransformPoint(endPosition) - startPoint).normalized * num)); if (result2 != null) { paintable = paintable2; result = result2; num *= result2.Distance01; } } } } if ((paintable != null) && (result != null)) { paintable.Paint(brush, result, groupMask); } } }
public void SendBrush(P3D_Brush localBrush) { // If we are connected to a session, broadcast our head info if (this.serverConnection != null && this.serverConnection.IsConnected()) { // Create an outgoing network message to contain all the info we want to send NetworkOutMessage msg = CreateMessage((byte)HoloPaintMessageID.UpdateBrush); // Color msg.Write(localBrush.Color.r); msg.Write(localBrush.Color.g); msg.Write(localBrush.Color.b); msg.Write(localBrush.Color.a); // Size msg.Write(localBrush.Size.x); msg.Write(localBrush.Size.y); // Send the message as a broadcast, which will cause the server to forward it to all other users in the session. this.serverConnection.Broadcast( msg, MessagePriority.Immediate, MessageReliability.ReliableOrdered, MessageChannel.Avatar); } }
public static void ScenePaintPerpedicularNearest(P3D_Brush brush, Vector3 position, float maxDistance, int layerMask = -1, int groupMask = -1) { P3D_Paintable paintable = null; P3D_Result result = null; for (int i = AllPaintables.Count - 1; i >= 0; i--) { P3D_Paintable paintable2 = AllPaintables[i]; if (P3D_Helper.IndexInMask(paintable2.gameObject.layer, layerMask)) { P3D_Tree tree = paintable2.GetTree(); if (tree != null) { Transform transform = paintable2.transform; if (P3D_Helper.GetUniformScale(transform) != 0f) { P3D_Result result2 = tree.FindPerpendicularNearest(transform.InverseTransformPoint(position), maxDistance); if (result2 != null) { paintable = paintable2; result = result2; maxDistance *= result2.Distance01; } } } } } if (paintable != null) { paintable.Paint(brush, result, groupMask); } }
// This method allows you to prepare painting using a brush public void SetBrush(P3D_Brush newBrush) { paintOperation = newBrush.Create(); Size = newBrush.Size; Angle = newBrush.Angle; Opacity = newBrush.Opacity; }
// This will paint the nearest surface between the start and end positions in world space, unless something is blocking it public static void ScenePaintBetweenNearest(P3D_Brush brush, Vector3 startPosition, Vector3 endPosition, int layerMask = -1, int groupMask = -1) { var maxDistance = Vector3.Distance(startPosition, endPosition); if (maxDistance == 0.0f) { return; } var nearestPaintable = default(P3D_Paintable); var nearestHit = default(RaycastHit); var nearestResult = default(P3D_Result); // Raycast scene to see if we hit a paintable if (Physics.Raycast(startPosition, endPosition - startPosition, out nearestHit, maxDistance, layerMask) == true) { nearestPaintable = nearestHit.collider.GetComponent <P3D_Paintable>(); maxDistance = nearestHit.distance; } // See if any paintables are closer (this happens if they have no collider, e.g. skinned meshes) for (var i = AllPaintables.Count - 1; i >= 0; i--) { var paintable = AllPaintables[i]; if (P3D_Helper.IndexInMask(paintable.gameObject.layer, layerMask) == true) { var tree = paintable.GetTree(); if (tree != null) { var transform = paintable.transform; var start = transform.InverseTransformPoint(startPosition); var end = transform.InverseTransformPoint(endPosition); var direction = (end - start).normalized; var result = tree.FindBetweenNearest(start, start + direction * maxDistance); if (result != null) { nearestPaintable = paintable; nearestResult = result; maxDistance *= result.Distance01; } } } } // Paint something? if (nearestPaintable != null) { if (nearestResult != null) { nearestPaintable.Paint(brush, nearestResult, groupMask); } else { nearestPaintable.Paint(brush, nearestHit, groupMask); } } }
// This causes the current paint operation to get applied to the specified result public bool Paint(P3D_Brush brush, P3D_Result result, P3D_CoordType coord = P3D_CoordType.UV1) { if (result != null) { return(Paint(brush, result.GetUV(coord))); } return(false); }
private void LoadPresets() { PresetBrushes.Clear(); var text = EditorPrefs.GetString("P3D_PresetBrushes", ""); var tokens = text.Split(new string[] { EntryDelimiter }, System.StringSplitOptions.RemoveEmptyEntries); var presetBrush = default(P3D_Brush); foreach (var token in tokens) { var bits = token.Split(new string[] { ValueDelimiter }, System.StringSplitOptions.RemoveEmptyEntries); if (bits.Length == 2) { switch (bits[0]) { case "Name": { presetBrush = new P3D_Brush(); presetBrush.Name = bits[1]; PresetBrushes.Add(presetBrush); } break; case "Blend": presetBrush.Blend = (P3D_BlendMode)System.Enum.Parse(typeof(P3D_BlendMode), bits[1]); break; case "Opacity": presetBrush.Opacity = float.Parse(bits[1]); break; case "ColorR": presetBrush.Color.r = float.Parse(bits[1]); break; case "ColorG": presetBrush.Color.g = float.Parse(bits[1]); break; case "ColorB": presetBrush.Color.b = float.Parse(bits[1]); break; case "ColorA": presetBrush.Color.a = float.Parse(bits[1]); break; case "DirectionX": presetBrush.Direction.x = float.Parse(bits[1]); break; case "DirectionY": presetBrush.Direction.y = float.Parse(bits[1]); break; case "Shape": presetBrush.Shape = Deserialize(bits[1]); break; case "SizeX": presetBrush.Size.x = float.Parse(bits[1]); break; case "SizeY": presetBrush.Size.y = float.Parse(bits[1]); break; case "Detail": presetBrush.Detail = Deserialize(bits[1]); break; case "DetailScaleX": presetBrush.DetailScale.x = float.Parse(bits[1]); break; case "DetailScaleY": presetBrush.DetailScale.y = float.Parse(bits[1]); break; } } } }
public void PaintBetweenNearest(P3D_Brush brush, Vector3 startPosition, Vector3 endPosition, int groupMask = -1) { if (this.CheckTree()) { Vector3 startPoint = base.transform.InverseTransformPoint(startPosition); P3D_Result result = this.tree.FindBetweenNearest(startPoint, base.transform.InverseTransformPoint(endPosition)); this.Paint(brush, result, groupMask); } }
// called by Messages.cs to make sure we have local id public void InitializeLocalBrush() { LocalBrush = new P3D_Brush(); LocalBrush.Color = DefaultBrush.Color; LocalBrush.Shape = DefaultBrush.Shape; LocalBrush.Size = DefaultBrush.Size; UsersBrushDictionary.Add(Messages.Instance.localUserID, LocalBrush); UpdateGlobalBrush(); }
// This causes the current paint operation to get applied to the specified u/v coordinate public bool Paint(P3D_Brush brush, Vector2 uv) { if (Canvas != null) { var xy = P3D_Helper.CalculatePixelFromCoord(uv, Tiling, Offset, Canvas.width, Canvas.height); return(Paint(brush, xy.x, xy.y)); } return(false); }
public bool Paint(P3D_Brush brush, P3D_Matrix matrix) { if ((this.Canvas == null) || (brush == null)) { return(false); } brush.Paint(this.Canvas, matrix); this.Dirty = true; return(true); }
public bool Paint(P3D_Brush brush, Vector2 uv) { if (this.Canvas == null) { return(false); } Vector2 vector = P3D_Helper.CalculatePixelFromCoord(uv, this.Tiling, this.Offset, this.Canvas.width, this.Canvas.height); return(this.Paint(brush, vector.x, vector.y)); }
public void Paint(P3D_Brush brush, List <P3D_Result> results, int groupMask = -1) { if (results != null) { for (int i = 0; i < results.Count; i++) { this.Paint(brush, results[i], groupMask); } } }
// This will paint all surfaces between the start and end positions in world space public void PaintBetweenAll(P3D_Brush brush, Vector3 startPosition, Vector3 endPosition, int groupMask = -1) { if (CheckTree() == true) { var start = transform.InverseTransformPoint(startPosition); var end = transform.InverseTransformPoint(endPosition); var results = tree.FindBetweenAll(start, end); Paint(brush, results, groupMask); } }
public bool Paint(P3D_Brush brush, float x, float y) { if (brush == null) { return(false); } Vector2 vector = new Vector2(x, y); P3D_Matrix matrix = P3D_Helper.CreateMatrix(vector + brush.Offset, brush.Size, brush.Angle); return(this.Paint(brush, matrix)); }
public static void ScenePaintPerpedicularAll(P3D_Brush brush, Vector3 position, float maxDistance, int layerMask = -1, int groupMask = -1) { for (int i = AllPaintables.Count - 1; i >= 0; i--) { P3D_Paintable paintable = AllPaintables[i]; if (P3D_Helper.IndexInMask(paintable.gameObject.layer, layerMask)) { paintable.PaintPerpendicularAll(brush, position, maxDistance, groupMask); } } }
public static void ScenePaintBetweenAll(P3D_Brush brush, Vector3 startPosition, Vector3 endPosition, int layerMask = -1, int groupMask = -1) { for (int i = AllPaintables.Count - 1; i >= 0; i--) { P3D_Paintable paintable = AllPaintables[i]; if (P3D_Helper.IndexInMask(paintable.gameObject.layer, layerMask)) { paintable.PaintBetweenAll(brush, startPosition, endPosition, groupMask); } } }
public P3D_Brush GetGlobalBrush(long userId) { if (!UsersBrushDictionary.ContainsKey(userId)) { P3D_Brush brush = new P3D_Brush(); brush.Color = DefaultBrush.Color; brush.Shape = DefaultBrush.Shape; brush.Size = DefaultBrush.Size; UsersBrushDictionary.Add(userId, brush); } return(UsersBrushDictionary[userId]); }
// This causes the current paint operation to get applied to the specified u/v coordinate public bool Paint(P3D_Brush brush, float x, float y) { if (brush != null) { var xy = new Vector2(x, y); var matrix = P3D_Helper.CreateMatrix(xy + brush.Offset, brush.Size, brush.Angle); return(Paint(brush, matrix)); } return(false); }
public void PaintPerpendicularNearest(P3D_Brush brush, Vector3 position, float maxDistance, int groupMask = -1) { if (this.CheckTree()) { float uniformScale = P3D_Helper.GetUniformScale(base.transform); if (uniformScale != 0f) { Vector3 point = base.transform.InverseTransformPoint(position); P3D_Result result = this.tree.FindPerpendicularNearest(point, maxDistance / uniformScale); this.Paint(brush, result, groupMask); } } }
// This causes the current paint operation to get applied to the specified matrix in pixel space public bool Paint(P3D_Brush brush, P3D_Matrix matrix) { if (Canvas != null && brush != null) { brush.Paint(Canvas, matrix); Dirty = true; return(true); } return(false); }
public bool Paint(P3D_Brush brush, List <P3D_Result> results, P3D_CoordType coord = 0) { bool flag = false; if (results != null) { for (int i = 0; i < results.Count; i++) { flag |= this.Paint(brush, results[i], coord); } } return(flag); }
public void Paint(P3D_Brush brush, P3D_Result result, int groupMask = -1) { if ((result != null) && (this.Textures != null)) { for (int i = this.Textures.Count - 1; i >= 0; i--) { P3D_PaintableTexture texture = this.Textures[i]; if ((texture != null) && P3D_Helper.IndexInMask((int)texture.Group, groupMask)) { texture.Paint(brush, result.GetUV(texture.Coord)); } } } }
public void Paint(P3D_Brush brush, Vector2 uv, int groupMask = -1) { if (this.Textures != null) { for (int i = this.Textures.Count - 1; i >= 0; i--) { P3D_PaintableTexture texture = this.Textures[i]; if ((texture != null) && P3D_Helper.IndexInMask((int)texture.Group, groupMask)) { texture.Paint(brush, uv); } } } }
// This causes the current paint operation to get applied to all the specified results public bool Paint(P3D_Brush brush, List <P3D_Result> results, P3D_CoordType coord = P3D_CoordType.UV1) { var painted = false; if (results != null) { for (var i = 0; i < results.Count; i++) { painted |= Paint(brush, results[i], coord); } } return(painted); }
// This will paint the current paintable at the specified UV public void Paint(P3D_Brush brush, Vector2 uv, int groupMask = -1) { if (Textures != null) { for (var i = Textures.Count - 1; i >= 0; i--) { var texture = Textures[i]; if (texture != null && P3D_Helper.IndexInMask(texture.Group, groupMask)) { texture.Paint(brush, uv); } } } }
// This will paint the current paintable at the raycast hit with the specified coord public void Paint(P3D_Brush brush, RaycastHit hit, int groupMask = -1) { if (Textures != null) { for (var i = Textures.Count - 1; i >= 0; i--) { var texture = Textures[i]; if (texture != null && P3D_Helper.IndexInMask(texture.Group, groupMask)) { texture.Paint(brush, P3D_Helper.GetUV(hit, texture.Coord)); } } } }