Esempio n. 1
0
        override public GrabWidget Clone()
        {
            StencilWidget clone = Instantiate(WidgetManager.m_Instance.GetStencilPrefab(this.Type));

            clone.transform.position = transform.position;
            clone.transform.rotation = transform.rotation;
            clone.m_SkipIntroAnim    = true;
            // We want to lie about our intro transition amount.
            clone.m_ShowTimer      = clone.m_ShowDuration;
            clone.transform.parent = transform.parent;
            clone.Show(true, false);
            clone.SetSignedWidgetSize(this.m_Size);
            clone.CloneInitialMaterials(this);
            clone.Extents = this.Extents;
            HierarchyUtils.RecursivelySetLayer(clone.transform, gameObject.layer);

            CanvasScript canvas = transform.parent.GetComponent <CanvasScript>();

            if (canvas != null)
            {
                var materials = clone.GetComponentsInChildren <Renderer>().SelectMany(x => x.materials);
                foreach (var material in materials)
                {
                    foreach (string keyword in canvas.BatchManager.MaterialKeywords)
                    {
                        material.EnableKeyword(keyword);
                    }
                }
            }

            return(clone);
        }
        public void MemorizeBrushStroke(
            BaseBrushScript brushScript, Color rColor, Guid brushGuid,
            float fBrushSize, float brushScale,
            List <PointerManager.ControlPoint> rControlPoints,
            StrokeFlags strokeFlags,
            StencilWidget stencil, float lineLength)
        {
            ClearRedo();

            Stroke rNewStroke = new Stroke();

            rNewStroke.m_Type                = Stroke.Type.BrushStroke;
            rNewStroke.m_Object              = brushScript.gameObject;
            rNewStroke.m_ControlPoints       = rControlPoints.ToArray();
            rNewStroke.m_ControlPointsToDrop = new bool[rNewStroke.m_ControlPoints.Length];
            rNewStroke.m_Color               = rColor;
            rNewStroke.m_BrushGuid           = brushGuid;
            rNewStroke.m_BrushSize           = fBrushSize;
            rNewStroke.m_BrushScale          = brushScale;
            rNewStroke.m_Flags               = strokeFlags;
            brushScript.Stroke               = rNewStroke;

            SketchMemoryScript.m_Instance.RecordCommand(
                new BrushStrokeCommand(rNewStroke, stencil, lineLength));

            MemoryListAdd(rNewStroke);

            TiltMeterScript.m_Instance.AdjustMeter(rNewStroke, up: true);
        }
        public void MemorizeBatchedBrushStroke(
            BatchSubset subset, Color rColor, Guid brushGuid,
            float fBrushSize, float brushScale,
            List <PointerManager.ControlPoint> rControlPoints, StrokeFlags strokeFlags,
            StencilWidget stencil, float lineLength, int seed)
        {
            // NOTE: PointerScript calls ClearRedo() in batch case

            Stroke rNewStroke = new Stroke();

            rNewStroke.m_Type                = Stroke.Type.BatchedBrushStroke;
            rNewStroke.m_BatchSubset         = subset;
            rNewStroke.m_ControlPoints       = rControlPoints.ToArray();
            rNewStroke.m_ControlPointsToDrop = new bool[rNewStroke.m_ControlPoints.Length];
            rNewStroke.m_Color               = rColor;
            rNewStroke.m_BrushGuid           = brushGuid;
            rNewStroke.m_BrushSize           = fBrushSize;
            rNewStroke.m_BrushScale          = brushScale;
            rNewStroke.m_Flags               = strokeFlags;
            rNewStroke.m_Seed                = seed;
            subset.m_Stroke = rNewStroke;

            SketchMemoryScript.m_Instance.RecordCommand(
                new BrushStrokeCommand(rNewStroke, stencil, lineLength));

            if (m_SanityCheckStrokes)
            {
                SanityCheckGeometryGeneration(rNewStroke);
                //SanityCheckVersusReplacementBrush(rNewObject);
            }
            MemoryListAdd(rNewStroke);

            TiltMeterScript.m_Instance.AdjustMeter(rNewStroke, up: true);
        }
Esempio n. 4
0
 public BrushStrokeCommand(Stroke stroke, StencilWidget widget = null,
                           float lineLength = -1, BaseCommand parent = null) : base(parent)
 {
     m_Stroke        = stroke;
     m_Widget        = widget;
     m_LineLength_CS = lineLength;
 }
Esempio n. 5
0
        public static void FromGuideIndex(Guides guide)
        {
            StencilType stencilType = guide.Type;

            foreach (var state in guide.States)
            {
                StencilWidget stencil = Instantiate(
                    WidgetManager.m_Instance.GetStencilPrefab(stencilType));

                stencil.m_SkipIntroAnim  = true;
                stencil.transform.parent = App.Instance.m_CanvasTransform;
                try {
                    stencil.SaveState = state;
                } catch (ArgumentException e) {
                    Debug.LogException(e, stencil);
                }
                stencil.Show(true, false);
            }
        }
Esempio n. 6
0
        /// Non-playback case:
        /// - Update the stroke based on the object's position.
        /// - Save off control points
        /// - Play audio.
        public void UpdateLineFromObject()
        {
            var xf_LS = GetTransformForLine(m_CurrentLine.transform, Coords.AsRoom[transform]);

            if (!PointerManager.m_Instance.IsMainPointerProcessingLine() && m_CurrentCreator != null)
            {
                var straightEdgeGuide = PointerManager.m_Instance.StraightEdgeGuide;

                if (straightEdgeGuide.SnapEnabled)
                {
                    // Snapping should be applied before symmetry, and lift is applied
                    // after symmetry, so redo both.

                    TrTransform xfMain_RS = Coords.AsRoom[PointerManager.m_Instance.MainPointer.transform];
                    xfMain_RS.translation = Coords.CanvasPose * straightEdgeGuide.GetTargetPos();
                    TrTransform xfSymmetry_RS = PointerManager.m_Instance.GetSymmetryTransformFor(
                        this, xfMain_RS);
                    xf_LS = GetTransformForLine(m_CurrentLine.transform, xfSymmetry_RS);
                }

                m_ControlPoints.Clear();
                m_ControlPoints.AddRange(m_CurrentCreator.GetPoints(xf_LS));
                float scale = xf_LS.scale;
                m_CurrentLine.ResetBrushForPreview(
                    TrTransform.TRS(m_ControlPoints[0].m_Pos, m_ControlPoints[0].m_Orient, scale));
                for (int i = 0; i < m_ControlPoints.Count; ++i)
                {
                    if (m_CurrentLine.IsOutOfVerts())
                    {
                        m_ControlPoints.RemoveRange(i, m_ControlPoints.Count - i);
                        break;
                    }
                    m_CurrentLine.UpdatePosition_LS(
                        TrTransform.TRS(m_ControlPoints[i].m_Pos, m_ControlPoints[i].m_Orient, scale),
                        m_ControlPoints[i].m_Pressure);
                }
                UpdateLineVisuals();
                return;
            }

            bool bQuadCreated = m_CurrentLine.UpdatePosition_LS(xf_LS, m_CurrentPressure);

            // TODO: let brush take care of storing control points, not us
            SetControlPoint(xf_LS, isKeeper: bQuadCreated);

            // TODO: Pointers should hold a reference to the stencil they're painting on.  This
            // is a hacky temporary check to ensure mirrored pointers don't add to the lift of
            // the active stencil.
            if (PointerManager.m_Instance.MainPointer == this)
            {
                // Increase stencil lift if we're painting on one.
                StencilWidget stencil = WidgetManager.m_Instance.ActiveStencil;
                if (stencil != null && m_CurrentCreator == null)
                {
                    float fPointerMovement_CS = GetMovementDelta() / Coords.CanvasPose.scale;
                    stencil.AdjustLift(fPointerMovement_CS);
                    m_LineLength_CS += fPointerMovement_CS;
                }
            }

            UpdateLineVisuals();

            /* Update desired brush audio
             * if (m_AudioSources.Length > 0) {
             * float fMovementSpeed = Vector3.Distance(m_PreviousPosition, transform.position) /
             *  Time.deltaTime;
             *
             * float fVelRangeRange = m_BrushAudioVolumeVelocityRange.y - m_BrushAudioVolumeVelocityRange.x;
             * float fVolumeRatio = Mathf.Clamp01((fMovementSpeed - m_BrushAudioVolumeVelocityRange.x) / fVelRangeRange);
             * m_AudioVolumeDesired = fVolumeRatio;
             *
             * float fPitchRangeRange = m_BrushAudioPitchVelocityRange.y - m_BrushAudioPitchVelocityRange.x;
             * float fPitchRatio = Mathf.Clamp01((fMovementSpeed - m_BrushAudioPitchVelocityRange.x) / fPitchRangeRange);
             * m_AudioPitchDesired = m_BrushAudioBasePitch + (fPitchRatio * m_BrushAudioMaxPitchShift);
             * } */
        }