Beispiel #1
0
 public void OnClick(Vector3 mousePosition)
 {
     selectedTile = null;
     selectedStack.Clear();
     if (Physics.Raycast(Camera.main.ScreenPointToRay(mousePosition), out RaycastHit hit))
     {
         if (pointer != null)
         {
             pointer.SetActive(true);
             pointer.transform.position = hit.point;
         }
         var go = hit.collider.transform.gameObject;
         while (go != null)
         {
             var ti = go.GetComponent <TileInfo>();
             if (ti != null)
             {
                 selectedTile = ti.Tile;
                 break;
             }
             go = go.transform.parent != null ? go.transform.parent.gameObject : null;
         }
     }
     else
     {
         if (pointer != null)
         {
             pointer.SetActive(false);
         }
     }
 }
Beispiel #2
0
    public void OnClick(Vector3 mousePosition)
    {
        selectedTile = null;
        selectedStack.Clear();
        if (Physics.Raycast(Camera.main.ScreenPointToRay(mousePosition), out RaycastHit hit))
        {
            if (pointer != null)
            {
                pointer.SetActive(true);
                pointer.transform.position = hit.point;
            }
            var go = hit.collider.transform.gameObject;
            while (go != null)
            {
                var ti = go.GetComponent <Unity3DTileInfo>();
                if (ti != null)
                {
                    selectedTile = ti.Tile;
#if UNITY_EDITOR
                    if (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl))
                    {
                        UnityEditor.Selection.activeGameObject = go;
                    }
#endif
                    break;
                }
                go = go.transform.parent != null ? go.transform.parent.gameObject : null;
            }
        }
        else
        {
            if (pointer != null)
            {
                pointer.SetActive(false);
            }
        }
    }
Beispiel #3
0
    private void UpdateSelectedTileset()
    {
        if (tileset != null)
        {
            tileset.ClearForcedTiles();
        }

        if (selectedTile == null)
        {
            return;
        }

        float bv  = selectedTile.BoundingVolume.Volume();
        float cbv = -1;

        if (selectedTile.ContentBoundingVolume != null)
        {
            cbv = selectedTile.ContentBoundingVolume.Volume();
        }

        builder.Append("\n");

        if (tilesets.Count > 0)
        {
            var sts = selectedTile.Tileset;
            builder.Append("\nselected tileset " + sts.TilesetOptions.Name +
                           " (" + tilesets.FindIndex(ts => ts == sts) + ")");
        }

        builder.Append("\nselected tile " + selectedTile.Id + ", depth " + selectedTile.Depth);
        builder.Append(", " + selectedTile.Children.Count + " children");
        builder.Append(", geometric error " + selectedTile.GeometricError.ToString("F3"));

        builder.Append("\nbounds vol " + bv + ": " + selectedTile.BoundingVolume.SizeString());
        if (cbv >= 0 && cbv != bv)
        {
            builder.Append(", content vol " + cbv);
        }

        var tc = selectedTile.Content;

        if (tc != null && selectedTile.ContentState == Unity3DTileContentState.READY)
        {
            builder.Append("\n" + FmtKMG(tc.FaceCount) + " tris, " + FmtKMG(tc.PixelCount) + " pixels, ");
            builder.Append(tc.TextureCount + " textures, max " + tc.MaxTextureSize.x + "x" + tc.MaxTextureSize.y);
        }

        selectedTile.Tileset.GetRootTransform(out Vector3 translation, out Quaternion rotation, out Vector3 scale,
                                              convertToUnityFrame: false);
        if (translation != Vector3.zero)
        {
            builder.Append("\ntileset translation " + translation.ToString("f3"));
        }
        if (rotation != Quaternion.identity)
        {
            builder.Append("\ntileset rotation " + rotation.ToString("f3"));
        }
        if (scale != Vector3.one)
        {
            builder.Append("\ntileset scale " + scale.ToString("f3"));
        }

        if (selectedTile.Parent != null)
        {
            builder.Append("\npress up/left/right");
            if (selectedTile.Children.Count > 0)
            {
                builder.Append("/down");
            }
            builder.Append(" to select parent/sibling");
            if (selectedTile.Children.Count > 0)
            {
                builder.Append("/child");
            }
        }
        else if (selectedTile.Children.Count > 0)
        {
            builder.Append("\npress down to select child");
        }

        if (selectedTile.Parent != null && Input.GetKeyDown(KeyCode.UpArrow))
        {
            selectedStack.Push(selectedTile);
            selectedTile = selectedTile.Parent;
        }

        if (selectedTile.Children.Count > 0 && Input.GetKeyDown(KeyCode.DownArrow))
        {
            selectedTile = selectedStack.Count > 0 ? selectedStack.Pop() : selectedTile.Children.First();
        }

        int sibling = Input.GetKeyDown(KeyCode.LeftArrow) ? -1 : Input.GetKeyDown(KeyCode.RightArrow) ? 1 : 0;

        if (selectedTile.Parent != null && sibling != 0)
        {
            var siblings = selectedTile.Parent.Children;
            int idx      = siblings.FindIndex(c => c == selectedTile) + sibling;
            idx = idx < 0 ? siblings.Count - 1 : idx == siblings.Count ? 0 : idx;
            if (siblings[idx] != selectedTile)
            {
                selectedStack.Clear();
            }
            selectedTile = siblings[idx];
        }

        builder.Append("\npress b to toggle bounds");

        if (Input.GetKeyDown(KeyCode.B))
        {
            if (!drawSelectedBounds && !drawParentBounds)
            {
                drawSelectedBounds = true;
            }
            else if (drawSelectedBounds && !drawParentBounds)
            {
                drawParentBounds = true;
            }
            else
            {
                drawSelectedBounds = drawParentBounds = false;
            }
        }

        if (drawSelectedBounds)
        {
            selectedTile.BoundingVolume.DebugDraw(Color.magenta, selectedTile.Tileset.Behaviour.transform);
            if (cbv >= 0 && cbv != bv)
            {
                selectedTile.ContentBoundingVolume.DebugDraw(Color.red, selectedTile.Tileset.Behaviour.transform);
            }
        }

        if (drawParentBounds && selectedTile.Parent != null)
        {
            var   parent = selectedTile.Parent;
            float pbv    = parent.BoundingVolume.Volume();
            float pcbv   = parent.ContentBoundingVolume != null?parent.ContentBoundingVolume.Volume() : -1;

            parent.BoundingVolume.DebugDraw(Color.cyan, selectedTile.Tileset.Behaviour.transform);
            if (pcbv >= 0 && pcbv != pbv)
            {
                parent.ContentBoundingVolume.DebugDraw(Color.blue, selectedTile.Tileset.Behaviour.transform);
            }
        }

        if (tilesets != null && tilesets.Count > 0)
        {
            builder.Append("\npress i to hide tileset");
            if (Input.GetKeyDown(KeyCode.I))
            {
                selectedTile.Tileset.TilesetOptions.Show = false;
                showStack.Push(selectedTile.Tileset);
                selectedTile = null;
                selectedStack.Clear();
            }
        }

        builder.Append("\npress esc to clear selection");
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            selectedTile = null;
            selectedStack.Clear();
        }

        if (selectedTile != null)
        {
            selectedTile.Tileset.Traversal.ForceTiles.Add(selectedTile);
        }
    }
Beispiel #4
0
    private void UpdateTilesets()
    {
        if (tileset is MultiTilesetBehaviour)
        {
            tilesets = ((MultiTilesetBehaviour)tileset).GetTilesets().ToList();
        }

        if (tilesets != null && tilesets.Count > 1)
        {
            string mods = "";
            if (tilesets.Count > 10)
            {
                mods += "[shift]+";
            }
            if (tilesets.Count > 20)
            {
                mods = "[ctrl]" + mods;
            }
            if (tilesets.Count > 40)
            {
                mods = "[alt]" + mods;
            }
            builder.Append("\npress " + mods + "0-9 to hide/show a tileset");
            int offset = 0;
            if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift))
            {
                offset += 10;
            }
            if (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl))
            {
                offset += 20;
            }
            if (Input.GetKey(KeyCode.LeftAlt) || Input.GetKey(KeyCode.RightAlt))
            {
                offset += 40;
            }
            int idx = Mathf.Max(alphaNumerals.FindIndex(code => Input.GetKeyDown(code)),
                                keypadNumerals.FindIndex(code => Input.GetKeyDown(code)));
            if (idx >= 0)
            {
                idx += offset;
                if (idx < tilesets.Count)
                {
                    tilesets[idx].TilesetOptions.Show = !tilesets[idx].TilesetOptions.Show;
                    if (!tilesets[idx].TilesetOptions.Show)
                    {
                        showStack.Push(tilesets[idx]);
                        if (selectedTile != null && selectedTile.Tileset == tilesets[idx])
                        {
                            selectedTile = null;
                            selectedStack.Clear();
                        }
                    }
                }
            }
        }

        if (!showStack.Any(ts => !ts.TilesetOptions.Show))
        {
            showStack.Clear();
        }

        if (showStack.Count > 0)
        {
            builder.Append("\npress o to show last hidden tileset");
            if (Input.GetKeyDown(KeyCode.O))
            {
                while (showStack.Count > 0)
                {
                    var ts = showStack.Pop();
                    if (!ts.TilesetOptions.Show)
                    {
                        ts.TilesetOptions.Show = true;
                        break;
                    }
                }
            }
        }
    }
Beispiel #5
0
    private void UpdateSelectedTileset()
    {
        if (tileset != null)
        {
            tileset.ClearForcedTiles();
        }

        if (selectedTile == null)
        {
            return;
        }

        float bv  = selectedTile.BoundingVolume.Volume();
        float cbv = -1;

        if (selectedTile.ContentBoundingVolume != null)
        {
            cbv = selectedTile.ContentBoundingVolume.Volume();
        }

        builder.Append("\n");

        if (tilesets != null && tilesets.Count > 0)
        {
            var sts = selectedTile.Tileset;
            builder.Append("\nselected tileset " + sts.TilesetOptions.Name +
                           " (" + tilesets.FindIndex(ts => ts == sts) + ")");
        }

        var    opts   = selectedTile.Tileset.TilesetOptions;
        double maxSSE = opts.MaximumScreenSpaceError;

        builder.Append("\nmax SSE " + opts.MaximumScreenSpaceError.ToString("F3") + " (hit PageUp/Down to adjust)");
        if (Input.GetKeyDown(KeyCode.PageDown))
        {
            opts.MaximumScreenSpaceError = Math.Max(0, opts.MaximumScreenSpaceError - 1);
        }

        if (Input.GetKeyDown(KeyCode.PageUp))
        {
            opts.MaximumScreenSpaceError = opts.MaximumScreenSpaceError + 1;
        }

        double dist    = selectedTile.FrameState.DistanceToCamera;
        double ctrDist = selectedTile.FrameState.PixelsToCameraCenter;

        builder.Append("\nselected tile " + selectedTile.Id + ", depth " + selectedTile.Depth);
        builder.Append(", " + selectedTile.Children.Count + " children");
        builder.Append("\ngeometric error " + selectedTile.GeometricError.ToString("F3"));
        builder.Append(", distance " + (dist < float.MaxValue ? dist : -1).ToString("F3"));
        builder.Append(", SSE " + selectedTile.FrameState.ScreenSpaceError.ToString("F3"));
        builder.Append("\n" + ((int)ctrDist) + " pixels to view center");

        builder.Append("\nbounds vol " + bv + ": " + selectedTile.BoundingVolume.SizeString());
        if (cbv >= 0 && cbv != bv)
        {
            builder.Append(", content vol " + cbv);
        }

        var tc = selectedTile.Content;

        if (tc != null && selectedTile.ContentState == Unity3DTileContentState.READY)
        {
            builder.Append("\n" + FmtKMG(tc.FaceCount) + " tris, " + FmtKMG(tc.PixelCount) + " pixels, ");
            builder.Append(tc.TextureCount + " textures, max " + tc.MaxTextureSize.x + "x" + tc.MaxTextureSize.y);
            if (tc.Index != null)
            {
                builder.Append("\n" + tc.Index.Width + "x" + tc.Index.Height + " index, " +
                               tc.Index.NumNonzero + " nonzero");
            }
        }

        selectedTile.Tileset.GetRootTransform(out Vector3 translation, out Quaternion rotation, out Vector3 scale,
                                              convertToUnityFrame: false);
        if (translation != Vector3.zero)
        {
            builder.Append("\ntileset translation " + translation.ToString("f3"));
        }
        if (rotation != Quaternion.identity)
        {
            builder.Append("\ntileset rotation " + rotation.ToString("f3"));
        }
        if (scale != Vector3.one)
        {
            builder.Append("\ntileset scale " + scale.ToString("f3"));
        }

        if (selectedTile.Parent != null)
        {
            builder.Append("\npress up/left/right");
            if (selectedTile.Children.Count > 0)
            {
                builder.Append("/down");
            }
            builder.Append(" to select parent/sibling");
            if (selectedTile.Children.Count > 0)
            {
                builder.Append("/child");
            }
        }
        else if (selectedTile.Children.Count > 0)
        {
            builder.Append("\npress down to select child");
        }

        if (selectedTile.Parent != null && Input.GetKeyDown(KeyCode.UpArrow))
        {
            selectedStack.Push(selectedTile);
            selectedTile = selectedTile.Parent;
        }

        if (selectedTile.Children.Count > 0 && Input.GetKeyDown(KeyCode.DownArrow))
        {
            var child = selectedTile.Children
                        .Where(c => c.BoundingVolume.Contains(pointer.transform.position))
                        .FirstOrDefault();
            selectedTile = selectedStack.Count > 0 ? selectedStack.Pop() : (child ?? selectedTile.Children.First());
        }

        int sibling = Input.GetKeyDown(KeyCode.LeftArrow) ? -1 : Input.GetKeyDown(KeyCode.RightArrow) ? 1 : 0;

        if (selectedTile.Parent != null && sibling != 0)
        {
            var siblings = selectedTile.Parent.Children;
            int idx      = siblings.FindIndex(c => c == selectedTile) + sibling;
            idx = idx < 0 ? siblings.Count - 1 : idx == siblings.Count ? 0 : idx;
            if (siblings[idx] != selectedTile)
            {
                selectedStack.Clear();
            }
            selectedTile = siblings[idx];
        }

        if (Input.GetKeyDown(KeyCode.B))
        {
            var modes   = (DrawBoundsMode[])Enum.GetValues(typeof(DrawBoundsMode));
            int curMode = Math.Max(Array.IndexOf(modes, boundsMode), 0);
            boundsMode = modes[(curMode + 1) % modes.Length];
        }

        builder.Append("\ndrawing " + boundsMode + " bounds, press b to toggle");

        switch (boundsMode)
        {
        case DrawBoundsMode.No: break;

        case DrawBoundsMode.Selected:
        {
            selectedTile.BoundingVolume.DebugDraw(Color.magenta, selectedTile.Tileset.Behaviour.transform);
            if (cbv >= 0 && cbv != bv)
            {
                selectedTile.ContentBoundingVolume.DebugDraw(Color.red, selectedTile.Tileset.Behaviour.transform);
            }
            break;
        }

        case DrawBoundsMode.Parent:
        {
            var parent = selectedTile.Parent;
            if (parent != null)
            {
                float pbv  = parent.BoundingVolume.Volume();
                float pcbv = parent.ContentBoundingVolume != null?parent.ContentBoundingVolume.Volume() : -1;

                parent.BoundingVolume.DebugDraw(Color.cyan, selectedTile.Tileset.Behaviour.transform);
                if (pcbv >= 0 && pcbv != pbv)
                {
                    parent.ContentBoundingVolume.DebugDraw(Color.blue, selectedTile.Tileset.Behaviour.transform);
                }
            }
            break;
        }

        case DrawBoundsMode.Ancestor:
        {
            for (var ancestor = selectedTile; ancestor != null; ancestor = ancestor.Parent)
            {
                ancestor.BoundingVolume.DebugDraw(Color.magenta, ancestor.Tileset.Behaviour.transform);
            }
            break;
        }

        case DrawBoundsMode.All:
        {
            void drawBounds(Unity3DTile tile)
            {
                tile.BoundingVolume.DebugDraw(Color.magenta, tile.Tileset.Behaviour.transform);
                foreach (var child in tile.Children)
                {
                    drawBounds(child);
                }
            }

            drawBounds(selectedTile.Tileset.Root);
            break;
        }

        case DrawBoundsMode.Leaf:
        {
            void drawBounds(Unity3DTile tile)
            {
                if (tile.Children.Count == 0)
                {
                    tile.BoundingVolume.DebugDraw(Color.magenta, tile.Tileset.Behaviour.transform);
                }
                foreach (var child in tile.Children)
                {
                    drawBounds(child);
                }
            }

            drawBounds(selectedTile.Tileset.Root);
            break;
        }

        case DrawBoundsMode.Active:
        {
            void drawBounds(Unity3DTile tile)
            {
                if (tile.ContentActive)
                {
                    tile.BoundingVolume.DebugDraw(Color.magenta, tile.Tileset.Behaviour.transform);
                }
                foreach (var child in tile.Children)
                {
                    drawBounds(child);
                }
            }

            drawBounds(selectedTile.Tileset.Root);
            break;
        }

        default: Debug.LogWarning("unknown bounds mode: " + boundsMode); break;
        }

        if (tilesets != null && tilesets.Count > 0)
        {
            builder.Append("\npress i to hide tileset");
            if (Input.GetKeyDown(KeyCode.I))
            {
                selectedTile.Tileset.TilesetOptions.Show = false;
                showStack.Push(selectedTile.Tileset);
                selectedTile = null;
                selectedStack.Clear();
            }
        }

        builder.Append("\npress esc to clear selection");
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            selectedTile = null;
            selectedStack.Clear();
        }

        if (selectedTile != null)
        {
            if (forceSelectedTile)
            {
                builder.Append("\nforcing selected tile to render, hit r to toggle");
                selectedTile.Tileset.Traversal.ForceTiles.Add(selectedTile);
            }
            else
            {
                builder.Append("\nnot forcing selected tile to render, hit r to toggle");
            }
            if (Input.GetKeyDown(KeyCode.R))
            {
                forceSelectedTile = !forceSelectedTile;
            }
        }
    }