Exemplo n.º 1
0
 public void Paint(P3D_Brush brush, Vector2 uv)
 {
     if (this.painter != null)
     {
         this.painter.Paint(brush, uv);
     }
 }
Exemplo n.º 2
0
    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();
        }
    }
Exemplo n.º 3
0
    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();
        }
    }
Exemplo n.º 4
0
    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);
            }
        }
    }
Exemplo n.º 5
0
    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);
        }
    }
Exemplo n.º 6
0
    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);
        }
    }
Exemplo n.º 7
0
 // 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;
 }
Exemplo n.º 8
0
    // 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);
            }
        }
    }
Exemplo n.º 9
0
    // 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);
    }
Exemplo n.º 10
0
    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;
                }
            }
        }
    }
Exemplo n.º 11
0
 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);
     }
 }
Exemplo n.º 12
0
 // 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();
 }
Exemplo n.º 13
0
    // 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);
    }
Exemplo n.º 14
0
 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);
 }
Exemplo n.º 15
0
    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));
    }
Exemplo n.º 16
0
 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);
         }
     }
 }
Exemplo n.º 17
0
    // 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);
        }
    }
Exemplo n.º 18
0
    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));
    }
Exemplo n.º 19
0
 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);
         }
     }
 }
Exemplo n.º 20
0
 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);
         }
     }
 }
Exemplo n.º 21
0
 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]);
 }
Exemplo n.º 22
0
    // 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);
    }
Exemplo n.º 23
0
 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);
         }
     }
 }
Exemplo n.º 24
0
    // 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);
    }
Exemplo n.º 25
0
    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);
    }
Exemplo n.º 26
0
 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));
             }
         }
     }
 }
Exemplo n.º 27
0
 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);
             }
         }
     }
 }
Exemplo n.º 28
0
    // 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);
    }
Exemplo n.º 29
0
    // 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);
                }
            }
        }
    }
Exemplo n.º 30
0
    // 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));
                }
            }
        }
    }