Esempio n. 1
0
        // -------------------------------------------------------------------------------------------- //
        // Data Collection Helpers
        // -------------------------------------------------------------------------------------------- //

        /// Filters and returns geometry in a convenient format for export.
        /// Returns geometry for the main canvas
        public static ExportCanvas ExportMainCanvas()
        {
            // This is probably the more-useful one; it assumes we only have
            // one interesting canvas (true, from a user perspective) and merges
            // the selection canvas into its target canvas.
            //
            // It makes the assumption that the selection canvas is not playing
            // fast-and-loose, and keeps its transform identical to its target
            // canvas (ie, its transform is always identity).
            //
            // Of course, the selection canvas does play fast-and-loose, but
            // we smack the canvas into place (via a deselect/reselect) before
            // getting here.
            var allowedBrushGuids = new HashSet <Guid>(
                BrushCatalog.m_Instance.AllBrushes
                .Where(b => b.m_AllowExport)
                .Select(b => (Guid)b.m_Guid));
            var main        = App.Scene.MainCanvas;
            var selection   = App.Scene.SelectionCanvas;
            var mainStrokes = SketchMemoryScript.AllStrokes()
                              .Where(stroke => allowedBrushGuids.Contains(stroke.m_BrushGuid) &&
                                     stroke.IsGeometryEnabled &&
                                     (stroke.Canvas == main || stroke.Canvas == selection));

            return(new ExportCanvas(main, mainStrokes.ToList()));
        }
Esempio n. 2
0
        public void Test_SquashCurrentLayer()
        {
#if (UNITY_EDITOR || EXPERIMENTAL_ENABLED)
            if (Config.IsExperimental)
            {
                var layer = ActiveCanvas;
                if (layer == m_MainCanvas)
                {
                    return;
                }
                // TODO: this should defer updates to the batches until the end
                foreach (var stroke in SketchMemoryScript.AllStrokes())
                {
                    if (stroke.Canvas == layer)
                    {
                        stroke.SetParentKeepWorldPosition(m_MainCanvas);
                    }
                }
                // Hm. remove after squashing?
                OutputWindowScript.m_Instance.CreateInfoCardAtController(
                    InputManager.ControllerName.Brush,
                    string.Format("Squashed {0}", layer.gameObject.name));
                ActiveCanvas = m_MainCanvas;
            }
#endif
        }
Esempio n. 3
0
        void FloodSelectByColor()
        {
            var targetColor =
                StrokesForTransforms(Selection.transforms).First().m_Color;
            var selection = new HashSet <GameObject>(new ReferenceComparer <GameObject>());

            selection.UnionWith(from stroke in SketchMemoryScript.AllStrokes()
                                where stroke.m_Color == targetColor
                                select TransformForStroke(stroke).gameObject);
            Selection.objects = selection.Cast <UObject>().ToArray();
        }
Esempio n. 4
0
        //
        // Helpers
        //

        static IEnumerable <Transform> AllStrokeTransforms()
        {
            var transforms = new HashSet <Transform>(new ReferenceComparer <Transform>());

            foreach (var canvas in App.Scene.AllCanvases)
            {
                transforms.UnionWith(from batch in canvas.BatchManager.AllBatches()
                                     select batch.transform);
            }
            transforms.UnionWith(from mo in SketchMemoryScript.AllStrokes()
                                 select TransformForStroke(mo));
            return(transforms);
        }
Esempio n. 5
0
  static void WriteStrokes(JsonWriter json, out Dictionary<Guid, int> brushMap) {
    brushMap = new Dictionary<Guid, int>();

    json.WritePropertyName("strokes");
    json.WriteStartArray();
    var strokes = SketchMemoryScript.AllStrokes().ToList();
    for (int i = 0; i < strokes.Count; ++i) {
      if (strokes[i].IsGeometryEnabled) {
        WriteStroke(json, strokes[i], brushMap);
      }
    }
    json.WriteEnd();
  }
Esempio n. 6
0
        /// Filters and returns geometry in a convenient format for export.
        public static List <ExportCanvas> ExportAllCanvases()
        {
            var allowedBrushGuids = new HashSet <Guid>(
                BrushCatalog.m_Instance.AllBrushes
                .Where(b => b.m_AllowExport)
                .Select(b => (Guid)b.m_Guid));

            return(SketchMemoryScript.AllStrokes()
                   .Where(stroke => allowedBrushGuids.Contains(stroke.m_BrushGuid) &&
                          stroke.IsGeometryEnabled)
                   .GroupBy(stroke => stroke.Canvas)
                   .Select(canvasStrokes => new ExportCanvas(canvasStrokes))
                   .ToList());
        }
        void Awake()
        {
            m_OperationStack          = new Stack <BaseCommand>();
            m_LastOperationStackCount = 0;
            m_RedoStack             = new Stack <BaseCommand>();
            m_HasVisibleObjects     = false;
            m_MemoryExceeded        = false;
            m_MemoryWarningAccepted = false;
            m_LastCheckedVertCount  = 0;
            m_UndoBatchMesh         = GameObject.Instantiate(m_UndoBatchMeshPrefab);
            m_Instance           = this;
            m_xfSketchInitial_RS = TrTransform.identity;

            m_MemoryWarningVertCount = App.PlatformConfig.MemoryWarningVertCount;
        }
Esempio n. 8
0
        public static void JoinStrokes(int start, int end)
        {
            var strokesToJoin = SketchMemoryScript.GetStrokesBetween(start, end);
            var firstStroke   = strokesToJoin[0];

            firstStroke.m_ControlPoints = strokesToJoin.SelectMany(x => x.m_ControlPoints).ToArray();
            for (int i = 1; i < strokesToJoin.Count; i++)
            {
                var stroke = strokesToJoin[i];
                SketchMemoryScript.m_Instance.RemoveMemoryObject(stroke);
                stroke.DestroyStroke();
            }
            firstStroke.Uncreate();
            firstStroke.m_ControlPointsToDrop = Enumerable.Repeat(false, firstStroke.m_ControlPoints.Length).ToArray();
            firstStroke.Recreate(null, firstStroke.Canvas);
        }
Esempio n. 9
0
        /// Pushes non-identity transforms from GameObjects into strokes.
        /// Zeroes out the GameObject transforms as a side effect.
        public void BakeTransforms()
        {
            foreach (var mo in SketchMemoryScript.AllStrokes())
            {
                BakeGameObjTransform(mo);
            }

            // Zeroing can't happen during baking, because a single transform may affect
            // multiple strokes. Also, we should take care to zero transforms for batches
            // that may not currently have any strokes.
            foreach (var t in AllStrokeTransforms())
            {
                t.position   = Vector3.zero;
                t.rotation   = Quaternion.identity;
                t.localScale = Vector3.one;
            }

            SketchMemoryScript.m_Instance.Redraw(doSort: false);
        }
Esempio n. 10
0
 /// Applies selected mutations to all strokes
 public void ApplyToAll()
 {
     Apply(SketchMemoryScript.AllStrokes().ToArray());
 }
Esempio n. 11
0
        public static void SelectStrokes(int start, int end)
        {
            var strokes = SketchMemoryScript.GetStrokesBetween(start, end);

            SelectionManager.m_Instance.SelectStrokes(strokes);
        }