Example #1
0
        public bool Matches(EdgeFlags other, bool allowRotation, out int rotation)
        {
            rotation = 0;

            // Simple match of all edges
            if (!allowRotation)
            {
                return(Match(top, other.top) &&
                       Match(bottom, other.bottom) &&
                       Match(left, other.left) &&
                       Match(right, other.right));
            }

            // Try to match any rotation
            for (int i = 0; i < 4; i++)
            {
                rotation = i;
                if (this.RotatedClockwise(i).Matches(other))
                {
                    return(true);
                }
            }

            return(false);
        }
Example #2
0
 public TileInstance(TilesetRenderer renderer, Face face, int faceIndex, ProBuilderMesh mesh)
 {
     tilesetRenderer = renderer;
     this.face       = face;
     this.faceIndex  = faceIndex;
     this.mesh       = mesh;
     this.edgeFlags  = new EdgeFlags();
     this.vertices   = new Vector3[4];
     RefreshVertices();
 }
Example #3
0
 public bool Matches(EdgeFlags other, bool allowRotation = false)
 {
     return(Matches(other, allowRotation, out _));
 }
Example #4
0
        private void OnDrawGizmosSelected()
        {
            if (tiles == null)
            {
                return;
            }

#if UNITY_EDITOR
            var m = Handles.matrix;
            Handles.matrix = transform.localToWorldMatrix;
            var mg = Gizmos.matrix;
            Gizmos.matrix = transform.localToWorldMatrix;

            foreach (TileInstance t in tiles)
            {
                var selected = Mesh.selectedFaceIndexes.Contains(t.FaceIndex);
                Handles.color = selected ? Color.yellow : (Color) new Color32(94, 119, 155, 255);
                Gizmos.color  = Handles.color;

                // Color tileColor = t.IsRect ? new Color(0, 1, 0, 0.2f) : new Color(1, 1, 1, 0.1f);
                Color tileColor = t.IsRect ? new Color(1, 1, 1, 0.15f) : new Color(1, 0, 0, 0.05f);
                Handles.DrawSolidRectangleWithOutline(t.vertices, tileColor, Color.clear);

                Handles.DrawAAPolyLine(3f,
                                       t.vertices[0],
                                       t.vertices[1],
                                       t.vertices[2],
                                       t.vertices[3],
                                       t.vertices[0]);

                // Normal
                if (Visualization.drawNormals)
                {
                    Gizmos.DrawRay(t.position, t.normal * 0.2f);
                }

                // Edge flags
                if (Visualization.drawEdgeFlags)
                {
                    for (int i = 0; i < 4; i++)
                    {
                        var p1 = t.vertices[i];
                        var p2 = t.vertices[i + 1 >= 4 ? 0 : i + 1];
                        Gizmos.color = new Color32(94, 119, 155, 255);
                        if (t.edgeFlags[i] == EdgeFlag.ConcaveUp)
                        {
                            Gizmos.color = Color.green;
                        }
                        if (t.edgeFlags[i] == EdgeFlag.ConvexDown)
                        {
                            Gizmos.color = Color.red;
                        }
                        if (EdgeFlags.Match(t.edgeFlags[i], EdgeFlag.AnyTile))
                        {
                            Gizmos.DrawSphere((p1 + p2) * 0.5f, 0.02f);
                        }
                    }
                }

                // Pivot
                if (Visualization.drawPivot)
                {
                    var up    = t.vertices[1] - t.vertices[0];
                    var right = t.vertices[3] - t.vertices[0];
                    var s     = Mathf.Min(up.magnitude, right.magnitude);
                    up.Normalize();
                    right.Normalize();

                    var p = t.vertices[0] + up * s * 0.05f + right * s * 0.05f;
                    Handles.color = Color.green;
                    Handles.ArrowHandleCap(0, p, Quaternion.LookRotation(up), s * 0.1f, EventType.Repaint);
                    Handles.color = Color.red;
                    Handles.ArrowHandleCap(0, p, Quaternion.LookRotation(right), s * 0.1f, EventType.Repaint);
                }

                Gizmos.color = Color.white;
                GUI.color    = Color.white;

                // Debug vertex colors and indices
                // var quad = t.Face.ToQuad();
                // for (int i = 0; i < 4; i++)
                // {
                //     var color = (Vector4) Mesh.colors[quad[i]];
                //     GUI.color = color == Vector4.zero ? Color.white : Color.red;
                //     var text = $"{quad[i]} {color}";
                //     Handles.Label(t.position + (t.vertices[i] - t.position) * 0.8f, text);
                // }
            }

            Handles.color  = Color.white;
            Handles.matrix = m;
            Gizmos.matrix  = mg;
#endif
        }