Ejemplo n.º 1
0
        /// <summary>
        /// Called from ProGrids.
        /// </summary>
        /// <param name="snapVal"></param>
        void PushToGrid(float snapVal)
        {
            UndoUtility.RecordSelection(selection.ToArray(), "Push elements to Grid");

            if (selectMode == SelectMode.Object || selectMode == SelectMode.None)
            {
                return;
            }

            for (int i = 0, c = MeshSelection.selectedObjectCount; i < c; i++)
            {
                ProBuilderMesh mesh = selection[i];
                if (mesh.selectedVertexCount < 1)
                {
                    continue;
                }

                var indexes = mesh.GetCoincidentVertices(mesh.selectedIndexesInternal);
                Snapping.SnapVertices(mesh, indexes, Vector3.one * snapVal);

                mesh.ToMesh();
                mesh.Refresh();
                mesh.Optimize();
            }

            UpdateSelection();
        }
Ejemplo n.º 2
0
        protected async void SetSnapping()
        {
            var myMap = MapView.Active.Map;

            //using ArcGIS.Desktop.Mapping
            //enable snapping
            Snapping.IsEnabled = true;

            //enable a snap mode, others are not changed.
            Snapping.SetSnapMode(SnapMode.Point, true);

            //set multiple snap modes exclusively. All others will be disabled.
            Snapping.SetSnapModes(SnapMode.Edge, SnapMode.Point);

            await QueuedTask.Run(() =>
            {
                //set snapping options via get/set options
                var snapOptions = Snapping.GetOptions(myMap);
                snapOptions.SnapToSketchEnabled = true;
                snapOptions.XYTolerance         = 100;
                Snapping.SetOptions(myMap, snapOptions);
            });


            var myFeatureLayer = MapView.Active.GetSelectedLayers().First() as FeatureLayer;

            //read snapping availability for a layer
            var canSnap = myFeatureLayer.IsSnappable;

            //set snapping availability for a layer
            var featLayerDef = myFeatureLayer.GetDefinition() as ArcGIS.Core.CIM.CIMGeoFeatureLayerBase;

            featLayerDef.Snappable = true;
            myFeatureLayer.SetDefinition(featLayerDef);
        }
Ejemplo n.º 3
0
        protected virtual void update_value(double newValue, bool bSendEvent)
        {
            double prev = current_value;

            current_value = newValue;

            snapped_value = current_value;

            if (TickSnapMode != TickSnapModes.NoSnapping && TickCount > 0)
            {
                if (TickSnapMode == TickSnapModes.AlwaysSnapToNearest)
                {
                    double fTickSpan = 1.0 / (TickCount - 1);
                    double fSnapped  = Snapping.SnapToIncrement(snapped_value, fTickSpan);
                    fSnapped      = MathUtil.Clamp(fSnapped, 0, 1);
                    snapped_value = fSnapped;
                }
                else
                {
                    double fTickSpan = 1.0 / (TickCount - 1);
                    double fSnapped  = Snapping.SnapToIncrement(snapped_value, fTickSpan);
                    if (Math.Abs(fSnapped - snapped_value) < TickSnapThreshold)
                    {
                        snapped_value = fSnapped;
                    }
                }
            }

            update_handle_position();

            if (bSendEvent)
            {
                FUtil.SafeSendEvent(OnValueChanged, this, prev, snapped_value);
            }
        }
 public void ResetToggles()
 {
     Snapping.Reset();
     FineSnapping.Reset();
     FineRotation.Reset();
     ToggleRotation.Reset();
 }
        internal static async Task ConfigureSnappingAsync()
        {
            //General Snapping
            Snapping.IsEnabled = true;
            Snapping.SetSnapMode(SnapMode.Edge, true);
            Snapping.SetSnapMode(SnapMode.End, true);
            Snapping.SetSnapMode(SnapMode.Intersection, true);

            //Snapping on any line Feature Layers
            var flayers = MapView.Active.Map.GetLayersAsFlattenedList().OfType <FeatureLayer>().Where(
                l => l.ShapeType == esriGeometryType.esriGeometryPolyline).ToList();

            if (flayers.Count() > 0)
            {
                //GetDefinition and SetDefinition must be called inside QueuedTask
                await QueuedTask.Run(() =>
                {
                    foreach (var fl in flayers)
                    {
                        var layerDef = fl.GetDefinition() as CIMGeoFeatureLayerBase;
                        if (!layerDef.Snappable)
                        {
                            layerDef.Snappable = true;
                            fl.SetDefinition(layerDef);
                        }
                    }
                });
            }
        }
Ejemplo n.º 6
0
        protected virtual void update_value(double newValue, bool bSendEvent)
        {
            double prev = current_value;

            current_value = newValue;

            snapped_value = current_value;

            if (EnableSnapToTicks && TickCount > 0)
            {
                double fTickSpan = 1.0 / (TickCount - 1);
                double fSnapped  = Snapping.SnapToIncrement(snapped_value, fTickSpan);
                fSnapped = MathUtil.Clamp(fSnapped, 0, 1);
                // [RMS] only snap when close enough to tick?
                //double fSnapT = fTickSpan * 0.25;
                //if (Math.Abs(fSnapped - snapped_value) < fSnapT)
                snapped_value = fSnapped;
            }

            update_handle_position();

            if (bSendEvent)
            {
                FUtil.SafeSendEvent(OnValueChanged, this, prev, snapped_value);
            }
        }
Ejemplo n.º 7
0
        // This is called for each window that your tool is active in. Put the functionality of your tool here.
        public override void OnToolGUI(EditorWindow window)
        {
            EditorGUI.BeginChangeCheck();

            Vector3 position = Tools.handlePosition;

            using (new Handles.DrawingScope())
            {
                float handleSize = HandleUtility.GetHandleSize(position);

                Handles.color = Handles.xAxisColor;
                position      = Handles.Slider(position, Vector3.right);

                Handles.color = Handles.zAxisColor;
                position      = Handles.Slider(position, Vector3.forward);

                Handles.color = Handles.yAxisColor;
                position      = Handles.Slider2D(position + new Vector3(1, 0, 1) * handleSize * slide2DSize, Vector3.up, Vector3.right, Vector3.forward, handleSize * slide2DSize, Handles.RectangleHandleCap, 0);
            }

            if (EditorGUI.EndChangeCheck())
            {
                Vector3 delta = Snapping.Snap(position - Tools.handlePosition, EditorSnapSettings.move);

                Undo.RecordObjects(Selection.transforms, "Move Platform");

                foreach (var transform in Selection.transforms)
                {
                    transform.position += delta;
                }
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Sets playback position to the time of first snap point holding the specified data.
        /// </summary>
        /// <param name="data">Data of a snap point to move to.</param>
        /// <returns><c>true</c> if playback position successfully changed to the time of first snap point
        /// with the specified data; otherwise, <c>false</c>.</returns>
        /// <exception cref="ObjectDisposedException">The current <see cref="Playback"/> is disposed.</exception>
        /// <exception cref="MidiDeviceException">An error occurred on device.</exception>
        public bool MoveToFirstSnapPoint <TData>(TData data)
        {
            EnsureIsNotDisposed();

            var snapPoint = Snapping.GetNextSnapPoint(TimeSpan.Zero, data);

            return(TryToMoveToSnapPoint(snapPoint));
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Sets playback position to the time of previous snap point (relative to the current
        /// time of playback).
        /// </summary>
        /// <returns><c>true</c> if playback position successfully changed to the time of a previous snap point;
        /// otherwise, <c>false</c>.</returns>
        /// <exception cref="ObjectDisposedException">The current <see cref="Playback"/> is disposed.</exception>
        /// <exception cref="MidiDeviceException">An error occurred on device.</exception>
        public bool MoveToPreviousSnapPoint()
        {
            EnsureIsNotDisposed();

            var snapPoint = Snapping.GetPreviousSnapPoint(_clock.CurrentTime);

            return(TryToMoveToSnapPoint(snapPoint));
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Sets playback position to the time of next snap point (relative to the current
        /// time of playback) holding the specified data.
        /// </summary>
        /// <returns><c>true</c> if playback position successfully changed to the time of a next snap point
        /// with the specified data; otherwise, <c>false</c>.</returns>
        /// <exception cref="ObjectDisposedException">The current <see cref="Playback"/> is disposed.</exception>
        /// <exception cref="MidiDeviceException">An error occurred on device.</exception>
        public bool MoveToNextSnapPoint <TData>(TData data)
        {
            EnsureIsNotDisposed();

            var snapPoint = Snapping.GetNextSnapPoint(_clock.CurrentTime, data);

            return(TryToMoveToSnapPoint(snapPoint));
        }
Ejemplo n.º 11
0
        protected override void OnEnable()
        {
            base.OnEnable();

            var mainTemplate = EditorGUIUtility.Load(k_GridSettingsWindowUxmlPath) as VisualTreeAsset;

            mainTemplate.CloneTree(rootVisualElement);

            rootVisualElement.Q <TextElement>("PaneTitle").text = L10n.Tr("Grid Visual");
            rootVisualElement.Q <Button>("PaneOption").clicked += PaneOptionMenu;

            m_GridPlane = rootVisualElement.Q <ButtonStripField>("GridPlane");

            foreach (var axis in m_Axes)
            {
                m_GridPlane.AddButton(axis.ToString());
            }

            m_GridPlane.label = L10n.Tr("Grid Plane");
            m_GridPlane.RegisterValueChangedCallback((evt) =>
            {
                m_SceneView.sceneViewGrids.gridAxis = m_Axes[evt.newValue];
                SceneView.RepaintAll();
            });

            m_GridOpacity       = rootVisualElement.Q <Slider>("Opacity");
            m_GridOpacity.label = L10n.Tr("Opacity");

            m_GridOpacity.RegisterValueChangedCallback(evt =>
            {
                m_SceneView.sceneViewGrids.gridOpacity = evt.newValue;
                SceneView.RepaintAll();
            });

            var toHandle = rootVisualElement.Q <Button>("ToHandle");

            toHandle.text     = L10n.Tr("To Handle");
            toHandle.clicked += () =>
            {
                foreach (var view in SceneView.sceneViews)
                {
                    ((SceneView)view).sceneViewGrids.SetAllGridsPivot(Snapping.Snap(Tools.handlePosition, GridSettings.size));
                }
                SceneView.RepaintAll();
            };

            var toOrigin = rootVisualElement.Q <Button>("ToOrigin");

            toOrigin.text     = L10n.Tr("To Origin");
            toOrigin.clicked += () =>
            {
                foreach (var view in SceneView.sceneViews)
                {
                    ((SceneView)view).sceneViewGrids.ResetPivot(SceneViewGrid.GridRenderAxis.All);
                }
                SceneView.RepaintAll();
            };
        }
Ejemplo n.º 12
0
        public override bool UpdateCapture(ITransformable target, Ray3f worldRay)
        {
            // ray-hit with plane perpendicular to rotateAxisW
            Vector3f planeHitW = raycastFrame.RayPlaneIntersection(worldRay.Origin, worldRay.Direction, 2);

            // find angle of hitpos in 2D plane perp to rotateAxis, and compute delta-angle
            Vector3f dv = planeHitW - rotateFrameW.Origin;
            int      iX = (nRotationAxis + 1) % 3;
            int      iY = (nRotationAxis + 2) % 3;
            float    fX = Vector3.Dot(dv, rotateFrameW.GetAxis(iX));
            float    fY = Vector3.Dot(dv, rotateFrameW.GetAxis(iY));

            float fNewAngle = (float)Math.Atan2(fY, fX);

            if (AbsoluteAngleConstraintF != null)
            {
                fNewAngle = AbsoluteAngleConstraintF(rotateFrameL, nRotationAxis, fNewAngle);
            }

            float fDeltaAngle = (fNewAngle - fRotateStartAngle);

            if (DeltaAngleConstraintF != null)
            {
                fDeltaAngle = DeltaAngleConstraintF(rotateFrameL, nRotationAxis, fDeltaAngle);
            }


            bool on_snap = false;

            if (EnableSnapping)
            {
                double dist = (planeHitW - rotateFrameW.Origin).Length;
                on_snap = Math.Abs(dist - gizmoRadiusW) < gizmoRadiusW * 0.15f;
                if (on_snap)
                {
                    fDeltaAngle = (float)Snapping.SnapToIncrement(fDeltaAngle, SnapIncrementDeg * MathUtil.Deg2Radf);
                }
                enable_snap_indicator(true);
                update_snap_indicator(-fDeltaAngle, on_snap);
            }

            // construct new frame for target that is rotated around axis
            Vector3f    rotateAxisL = rotateFrameL.GetAxis(nRotationAxis);
            Quaternionf q           = Quaternion.AngleAxis(fDeltaAngle * Mathf.Rad2Deg, rotateAxisL);
            Frame3f     newFrame    = rotateFrameL;

            newFrame.Rotation = q * newFrame.Rotation;                          // order matters here!

            // update target
            target.SetLocalFrame(newFrame, CoordSpace.ObjectCoords);

            if (EnableSnapping)
            {
                update_circle_indicator(on_snap);
            }

            return(true);
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Sets playback position to the time of next snap point (relative to the current
        /// time of playback) that belongs to the specified <see cref="SnapPointsGroup"/>.
        /// </summary>
        /// <param name="snapPointsGroup"><see cref="SnapPointsGroup"/> that defines snap points to
        /// select the one from.</param>
        /// <returns><c>true</c> if playback position successfully changed to the time of a next snap point
        /// within <paramref name="snapPointsGroup"/>; otherwise, <c>false</c>.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="snapPointsGroup"/> is <c>null</c>.</exception>
        /// <exception cref="ObjectDisposedException">The current <see cref="Playback"/> is disposed.</exception>
        /// <exception cref="MidiDeviceException">An error occurred on device.</exception>
        public bool MoveToNextSnapPoint(SnapPointsGroup snapPointsGroup)
        {
            ThrowIfArgument.IsNull(nameof(snapPointsGroup), snapPointsGroup);
            EnsureIsNotDisposed();

            var snapPoint = Snapping.GetNextSnapPoint(_clock.CurrentTime, snapPointsGroup);

            return(TryToMoveToSnapPoint(snapPoint));
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Snap a Vector3 to the nearest point on the current ProGrids grid if ProGrids is enabled.
        /// </summary>
        /// <param name="point"></param>
        /// <returns></returns>
        public static float ProGridsSnap(float point)
        {
            if (GetProGridsType() == null)
                return point;

            if (SnapEnabled())
                return Snapping.SnapValue(point, ProGridsInterface.SnapValue());

            return point;
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Sets playback position to the time of the next snap point (relative to the current
        /// time of playback).
        /// </summary>
        /// <exception cref="ObjectDisposedException">The current <see cref="Playback"/> is disposed.</exception>
        /// <exception cref="MidiDeviceException">An error occurred on device.</exception>
        public void MoveToNextSnapPoint()
        {
            EnsureIsNotDisposed();

            var snapPoint = Snapping.GetNextSnapPoint(_clock.CurrentTime);

            if (snapPoint != null)
            {
                MoveToTime((MetricTimeSpan)snapPoint.Time);
            }
        }
Ejemplo n.º 16
0
        public void TranslateSnapsAllAxes()
        {
            var cur = new Vector3(.15f, .28f, .15f);

            Assert.AreEqual(Snapping.Round(cur, .5f), new Vector3(0f, .5f, 0f));

            cur = new Vector3(.15f, .15f, .9f);
            Assert.AreEqual(Snapping.Round(cur, .5f), new Vector3(0f, 0f, 1f));

            cur = new Vector3(.15f, .3f, .9f);
            Assert.AreEqual(Snapping.Round(cur, .5f), new Vector3(0f, .5f, 1f));
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Sets playback position to the time of the next snap point (relative to the current
        /// time of playback) that belongs to the specified <see cref="SnapPointsGroup"/>.
        /// </summary>
        /// <param name="snapPointsGroup"><see cref="SnapPointsGroup"/> that defines snap points to
        /// select the one from.</param>
        /// <exception cref="ArgumentNullException"><paramref name="snapPointsGroup"/> is null.</exception>
        /// <exception cref="ObjectDisposedException">The current <see cref="Playback"/> is disposed.</exception>
        /// <exception cref="MidiDeviceException">An error occurred on device.</exception>
        public void MoveToNextSnapPoint(SnapPointsGroup snapPointsGroup)
        {
            ThrowIfArgument.IsNull(nameof(snapPointsGroup), snapPointsGroup);
            EnsureIsNotDisposed();

            var snapPoint = Snapping.GetNextSnapPoint(_clock.CurrentTime, snapPointsGroup);

            if (snapPoint != null)
            {
                MoveToTime((MetricTimeSpan)snapPoint.Time);
            }
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Snap a Vector3 to the nearest point on the current ProGrids grid if ProGrids is enabled, with mask.
        /// </summary>
        /// <param name="point"></param>
        /// <param name="mask"></param>
        /// <returns></returns>
        public static Vector3 ProGridsSnap(Vector3 point, Vector3 mask)
        {
            if (GetProGridsType() == null)
                return point;

            if (ProGridsInterface.SnapEnabled())
            {
                float snap = ProGridsInterface.SnapValue();
                return Snapping.SnapValue(point, mask * snap);
            }

            return point;
        }
        public void TranslateOnlySnapsChangedAxis()
        {
            var old = new Vector3(.15f, .15f, .15f);
            var cur = new Vector3(.15f, .28f, .15f);

            Assert.AreEqual(Snapping.Round(cur, cur - old, .5f), new Vector3(.15f, .5f, .15f));

            cur = new Vector3(.15f, .15f, .9f);
            Assert.AreEqual(Snapping.Round(cur, cur - old, .5f), new Vector3(.15f, .15f, 1f));

            cur = new Vector3(.15f, .3f, .9f);
            Assert.AreEqual(Snapping.Round(cur, cur - old, .5f), new Vector3(.15f, .5f, 1f));
        }
Ejemplo n.º 20
0
        internal static void SetPivotLocationAndSnap(ProBuilderMesh mesh)
        {
            if (ProGridsInterface.SnapEnabled())
            {
                mesh.transform.position = Snapping.SnapValue(mesh.transform.position, ProGridsInterface.SnapValue());
            }
            else if (s_SnapNewShapesToGrid)
            {
                mesh.transform.position = Snapping.SnapValue(mesh.transform.position, new Vector3(
                                                                 EditorPrefs.GetFloat("MoveSnapX"),
                                                                 EditorPrefs.GetFloat("MoveSnapY"),
                                                                 EditorPrefs.GetFloat("MoveSnapZ")));
            }

            mesh.Optimize();
        }
Ejemplo n.º 21
0
        void Update()
        {
            if (Context == null)
            {
                return;
            }

            // [TODO] need to consider camera distane here?


            Frame3f sceneFrameW = Context.Scene.SceneFrame;

            if (sceneFrameW.EpsilonEqual(lastSceneFrameW, 0.001f))
            {
                return;
            }
            lastSceneFrameW = sceneFrameW;

            if (AdjustShadowDistance)
            {
                // use vertical height of light to figure out appropriate shadow distance.
                // distance changes if we scale scene, and if we don't do this, shadow
                // map res gets very blurry.
                Vector3f thisW   = lights[0].transform.position;
                float    fHeight =
                    Vector3f.Dot((thisW - sceneFrameW.Origin), sceneFrameW.Y);
                float fShadowDist = fHeight * 1.5f;

                // lights need to be in-range
                if (fShadowDist < LightDistance)
                {
                    fShadowDist = LightDistance * 1.5f;
                }

                // need to be a multiple of eye distance
                float fEyeDist = sceneFrameW.Origin.Distance(Camera.main.transform.position);
                fShadowDist = Mathf.Max(fShadowDist, 1.5f * fEyeDist);

                int nShadowDist = (int)Snapping.SnapToIncrement(fShadowDist, 50);

                if (cur_shadow_dist != nShadowDist)
                {
                    QualitySettings.shadowDistance = nShadowDist;
                    cur_shadow_dist = nShadowDist;
                }
            }
        }
Ejemplo n.º 22
0
    // Update is called once per frame
    void Update()
    {
        if (!health.IsAlive())
        {
            if (currentEvolution == lastEvolution)
            {
                StartCoroutine(OnDeath());
            }

            else
            {
                switch (currentEvolution)
                {
                case TowerEvolutions.Evolution1:
                    StartCoroutine(EvolveTower(TowerEvolutions.Evolution2));
                    break;

                case TowerEvolutions.Evolution2:
                    StartCoroutine(EvolveTower(TowerEvolutions.Evolution3));
                    break;
                }
            }
        }
        else
        {
            Transform target = CheckTarget();
            if (target)
            {
                Vector2 direction = target.position - transform.position;
                targetAngle = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg;
                targetAngle = Snapping.Snap(targetAngle, 45f);
                targetX     = Mathf.Cos(targetAngle * Mathf.Deg2Rad);
                targetY     = Mathf.Sin(targetAngle * Mathf.Deg2Rad);
                if (timerActive)
                {
                    shootTimer -= Time.deltaTime;
                }
                if (shootTimer < 0)
                {
                    shootTimer = 0;
                }
                Shoot();
            }
        }
    }
Ejemplo n.º 23
0
        /// <summary>
        /// Return the last known grid pivot point.
        /// </summary>
        /// <param name="pivot"></param>
        /// <returns></returns>
        public static bool GetPivot(out Vector3 pivot)
        {
            pivot = Vector3.zero;

            if (s_GetPivotDelegate == null)
                s_GetPivotDelegate = (Func<Vector3>)ReflectionUtility.GetOpenDelegate<Func<Vector3>>(GetProGridsType(), "GetPivot");

            if (s_GetPivotDelegate != null)
            {
                pivot = s_GetPivotDelegate();

                // earlier version of progrids return a non-snapped pivot point
                pivot = Snapping.SnapValue(pivot, SnapValue());
                return true;
            }

            return false;
        }
Ejemplo n.º 24
0
    void Update()
    {
        if (!health.IsAlive())
        {
            StartCoroutine(OnDeath()); return;
        }



        movement.x = Input.GetAxisRaw("Horizontal");
        movement.y = Input.GetAxisRaw("Vertical");
        mousePos   = cam.ScreenToWorldPoint(Input.mousePosition);
        Vector2 characterDirection = mousePos - body.position;

        relativeAngle  = Mathf.Atan2(characterDirection.y, characterDirection.x) * Mathf.Rad2Deg;
        relativeAngle  = Snapping.Snap(relativeAngle, 45f);
        relativeMouseX = Mathf.Cos(relativeAngle * Mathf.Deg2Rad);
        relativeMouseY = Mathf.Sin(relativeAngle * Mathf.Deg2Rad);



        if ((relativeMouseX > 0) && !isFacingRight)
        {
            Flip();
        }
        else if ((relativeMouseX < 0) && isFacingRight)
        {
            Flip();
        }

        if (timerActive)
        {
            shootTimer -= Time.deltaTime;
        }
        if (shootTimer < 0)
        {
            shootTimer = 0;
        }
        if (Input.GetButtonDown("Fire1") && !EventSystem.current.IsPointerOverGameObject())
        {
            Shoot();
        }
    }
Ejemplo n.º 25
0
#pragma warning disable 618
        public static Vector3 Do(
            int id,
            Vector3 handlePos,
            Vector3 offset,
            Vector3 handleDir,
            Vector3 slideDir1,
            Vector3 slideDir2,
            float handleSize,
            Handles.DrawCapFunction drawFunc,
            Vector2 snap,
            bool drawHelper)
#pragma warning restore 618
        {
            bool orgGuiChanged = GUI.changed;

            GUI.changed = false;

            Vector2 delta = CalcDeltaAlongDirections(id, handlePos, offset, handleDir, slideDir1, slideDir2, handleSize, drawFunc, snap, drawHelper);

            if (GUI.changed)
            {
                handlePos = s_StartPosition + slideDir1 * delta.x + slideDir2 * delta.y;

                if (EditorSnapSettings.gridSnapActive)
                {
                    var normal = Vector3.Cross(slideDir1, slideDir2);

                    if (Snapping.IsCardinalDirection(normal))
                    {
                        var worldSpace = Handles.matrix.MultiplyPoint(handlePos);
                        worldSpace = Snapping.Snap(worldSpace, GridSettings.size, (SnapAxis) ~new SnapAxisFilter(normal));
                        handlePos  = Handles.inverseMatrix.MultiplyPoint(worldSpace);
                    }
                }
            }

            GUI.changed |= orgGuiChanged;
            return(handlePos);
        }
        void DoGridVisualSettings()
        {
            Vector3 grid   = GridSettings.size;
            bool    linked = gridValueLinked;

            EditorGUI.BeginChangeCheck();
            grid = EditorGUILayout.LinkedVector3Field(Contents.gridSize, grid, ref linked);
            if (EditorGUI.EndChangeCheck())
            {
                gridValueLinked   = linked;
                GridSettings.size = grid;
                SceneView.RepaintAll();
            }

            EditorGUI.BeginChangeCheck();

            GUILayout.BeginHorizontal();
            EditorGUILayout.PrefixLabel(Contents.movePivot);
            if (GUILayout.Button("Handle"))
            {
                foreach (var view in SceneView.sceneViews)
                {
                    ((SceneView)view).sceneViewGrids.SetAllGridsPivot(Snapping.Snap(Tools.handlePosition, GridSettings.size));
                }
            }
            if (GUILayout.Button("Reset"))
            {
                foreach (var view in SceneView.sceneViews)
                {
                    ((SceneView)view).sceneViewGrids.ResetPivot(SceneViewGrid.GridRenderAxis.All);
                }
            }
            GUILayout.EndHorizontal();
            if (EditorGUI.EndChangeCheck())
            {
                SceneView.RepaintAll();
            }
        }
Ejemplo n.º 27
0
        // Returns the new handlePos
        public static Vector3 Do(
            int id,
            Vector3 handlePos,
            Vector3 offset,
            Vector3 handleDir,
            Vector3 slideDir1,
            Vector3 slideDir2,
            float handleSize,
            Handles.CapFunction capFunction,
            Vector2 snap,
            bool drawHelper)
        {
            bool orgGuiChanged = GUI.changed;

            GUI.changed = false;

            Vector2 delta = CalcDeltaAlongDirections(id, handlePos, offset, handleDir, slideDir1, slideDir2, handleSize, capFunction, snap, drawHelper);

            if (GUI.changed)
            {
                handlePos = s_StartPosition + slideDir1 * delta.x + slideDir2 * delta.y;

                if (EditorSnapSettings.active && EditorSnapSettings.preferGrid)
                {
                    var normal = Vector3.Cross(slideDir1, slideDir2);

                    if (Snapping.IsCardinalDirection(normal))
                    {
                        var worldSpace = Handles.matrix.MultiplyPoint(handlePos);
                        worldSpace = Handles.SnapValue(worldSpace, (~new SnapAxisFilter(normal)) * snap);
                        handlePos  = Handles.inverseMatrix.MultiplyPoint(worldSpace);
                    }
                }
            }

            GUI.changed |= orgGuiChanged;
            return(handlePos);
        }
Ejemplo n.º 28
0
        void DoExistingPointsGUI()
        {
            Transform trs = polygon.transform;
            int       len = polygon.m_Points.Count;

            Vector3 up      = polygon.transform.up;
            Vector3 right   = polygon.transform.right;
            Vector3 forward = polygon.transform.forward;
            Vector3 center  = Vector3.zero;

            Event evt = Event.current;

            bool used = evt.type == EventType.Used;

            if (!used &&
                (evt.type == EventType.MouseDown &&
                 evt.button == 0 &&
                 !EditorHandleUtility.IsAppendModifier(evt.modifiers)))
            {
                m_SelectedIndex = -1;
                Repaint();
            }

            if (polygon.polyEditMode == PolyShape.PolyEditMode.Height)
            {
                if (!used && evt.type == EventType.MouseUp && evt.button == 0 && !EditorHandleUtility.IsAppendModifier(evt.modifiers))
                {
                    evt.Use();
                    SetPolyEditMode(PolyShape.PolyEditMode.Edit);
                }

                bool sceneInUse = EditorHandleUtility.SceneViewInUse(evt);
                Ray  r          = HandleUtility.GUIPointToWorldRay(evt.mousePosition);

                Vector3 origin  = polygon.transform.TransformPoint(Math.Average(polygon.m_Points));
                float   extrude = polygon.extrude;

                if (evt.type == EventType.MouseMove && !sceneInUse)
                {
                    Vector3 p = Math.GetNearestPointRayRay(origin, up, r.origin, r.direction);
                    extrude = ProGridsInterface.ProGridsSnap(s_HeightMouseOffset + Vector3.Distance(origin, p) * Mathf.Sign(Vector3.Dot(p - origin, up)));
                }

                Vector3 extrudePoint = origin + (extrude * up);

                Handles.color = k_HandleColor;
                Handles.DotHandleCap(-1, origin, Quaternion.identity, HandleUtility.GetHandleSize(origin) * k_HandleSize, evt.type);
                Handles.color = k_HandleColorGreen;
                Handles.DrawLine(origin, extrudePoint);
                Handles.DotHandleCap(-1, extrudePoint, Quaternion.identity, HandleUtility.GetHandleSize(extrudePoint) * k_HandleSize, evt.type);
                Handles.color = Color.white;

                if (!sceneInUse && polygon.extrude != extrude)
                {
                    OnBeginVertexMovement();
                    polygon.extrude = extrude;
                    RebuildPolyShapeMesh(false);
                }
            }
            else
            {
                // vertex dots
                for (int ii = 0; ii < len; ii++)
                {
                    Vector3 point = trs.TransformPoint(polygon.m_Points[ii]);

                    center.x += point.x;
                    center.y += point.y;
                    center.z += point.z;

                    float size = HandleUtility.GetHandleSize(point) * k_HandleSize;

                    Handles.color = ii == m_SelectedIndex ? k_HandleSelectedColor : k_HandleColor;

                    EditorGUI.BeginChangeCheck();

                    point = Handles.Slider2D(point, up, right, forward, size, Handles.DotHandleCap, Vector2.zero, true);

                    if (EditorGUI.EndChangeCheck())
                    {
                        UndoUtility.RecordObject(polygon, "Move Polygon Shape Point");

                        Vector3 snapMask = Snapping.GetSnappingMaskBasedOnNormalVector(m_Plane.normal);
                        polygon.m_Points[ii] = ProGridsInterface.ProGridsSnap(trs.InverseTransformPoint(point), snapMask);
                        OnBeginVertexMovement();
                        RebuildPolyShapeMesh(false);
                    }

                    // "clicked" a button
                    if (!used && evt.type == EventType.Used)
                    {
                        if (ii == 0 && polygon.m_Points.Count > 2 && polygon.polyEditMode == PolyShape.PolyEditMode.Path)
                        {
                            m_NextMouseUpAdvancesMode = true;
                            return;
                        }
                        else
                        {
                            used            = true;
                            m_SelectedIndex = ii;
                        }
                    }
                }

                Handles.color = Color.white;

                // height setting
                if (polygon.polyEditMode != PolyShape.PolyEditMode.Path && polygon.m_Points.Count > 2)
                {
                    center.x /= (float)len;
                    center.y /= (float)len;
                    center.z /= (float)len;

                    Vector3 extrude = center + (up * polygon.extrude);
                    m_DistanceFromHeightHandle = Vector2.Distance(HandleUtility.WorldToGUIPoint(extrude), evt.mousePosition);

                    EditorGUI.BeginChangeCheck();

                    Handles.color = k_HandleColor;
                    Handles.DotHandleCap(-1, center, Quaternion.identity, HandleUtility.GetHandleSize(center) * k_HandleSize, evt.type);
                    Handles.DrawLine(center, extrude);
                    Handles.color = k_HandleColorGreen;
                    extrude       = Handles.Slider(extrude, up, HandleUtility.GetHandleSize(extrude) * k_HandleSize, Handles.DotHandleCap, 0f);
                    Handles.color = Color.white;

                    if (EditorGUI.EndChangeCheck())
                    {
                        UndoUtility.RecordObject(polygon, "Set Polygon Shape Height");
                        polygon.extrude = ProGridsInterface.ProGridsSnap(Vector3.Distance(extrude, center) * Mathf.Sign(Vector3.Dot(up, extrude - center)));
                        OnBeginVertexMovement();
                        RebuildPolyShapeMesh(false);
                    }
                }
            }
        }
Ejemplo n.º 29
0
        protected override void DoTool(Vector3 handlePosition, Quaternion handleRotation)
        {
            if (!isEditing)
            {
                m_Rotation = 0f;
            }

            EditorGUI.BeginChangeCheck();

            var size = HandleUtility.GetHandleSize(handlePosition);

            EditorHandleUtility.PushMatrix();

            Handles.matrix = Matrix4x4.TRS(handlePosition, handleRotation, Vector3.one);

            Handles.color = Color.blue;
            m_Euler.z     = m_Rotation;
            m_Quaternion  = Quaternion.Euler(m_Euler);
            m_Quaternion  = Handles.Disc(m_Quaternion, Vector3.zero, Vector3.forward, size, relativeSnapEnabled, relativeSnapRotation);
            m_Euler       = m_Quaternion.eulerAngles;
            m_Rotation    = m_Euler.z;

            EditorHandleUtility.PopMatrix();

            if (EditorGUI.EndChangeCheck())
            {
                if (!isEditing)
                {
                    BeginEdit("Rotate Textures");
                }

                if (relativeSnapEnabled)
                {
                    m_Rotation = Snapping.SnapValue(m_Rotation, relativeSnapX);
                }
                else if (progridsSnapEnabled)
                {
                    m_Rotation = Snapping.SnapValue(m_Rotation, progridsSnapValue);
                }

                foreach (var mesh in elementSelection)
                {
                    if (!(mesh is MeshAndTextures))
                    {
                        continue;
                    }
                    var mat = (MeshAndTextures)mesh;

                    var origins   = mat.origins;
                    var positions = mat.textures;

                    foreach (var group in mat.elementGroups)
                    {
                        foreach (var index in group.indices)
                        {
                            positions[index] = mat.postApplyMatrix.MultiplyPoint(
                                Math.RotateAroundPoint(
                                    mat.preApplyMatrix.MultiplyPoint3x4(origins[index]), Vector2.zero, -m_Rotation));
                        }
                    }

                    mesh.mesh.mesh.SetUVs(k_TextureChannel, positions);
                }
            }
        }
Ejemplo n.º 30
0
        public void ScrollTo(int index, Snapping snap = Snapping.SnapLeft)
        {
            Initialize();

            // nothing to do
            if (Items.Count == 0)
                return;

            // animate to new position
            this.ScrollStart(index, snap, AnimationDuration);
        }
Ejemplo n.º 31
0
        private void ScrollStart(int index, Snapping snap, double milliseconds = 0)
        {
            Initialize();

            // positions
            double offsetBackground = 0.0;
            double offsetTitle = 0.0;
            double offsetItems = 0.0;

            //
            // adjust destination item positions
            //
            int index0 = 0;
            int indexN = Items.Count - 1;

            // scroll from first to last
            if (index < index0)
            {
                if (snap == Snapping.SnapLeft)
                    offsetItems = Items.GetItemPosition(index0) - Items.GetItemWidth(indexN);
                else
                    offsetItems = Items.GetItemPosition(index0) - Parent.DefaultItemWidth;
            }
            // scroll from last to first
            else if (index > indexN)
            {
                // since we're moving left to right, and only a item at a time
                // we can only snap to left here...
                offsetItems = Items.GetItemPosition(indexN) + Items.GetItemWidth(indexN);
            }
            // normal scroll
            else
            {
                if (snap == Snapping.SnapLeft)
                    offsetItems = Items.GetItemPosition(index);
                else
                    offsetItems = Items.GetItemPosition(index) + Items.GetItemWidth(index) - Parent.DefaultItemWidth;
            }

            //
            // adjust animation speed
            //
            double offset = Math.Abs(offsetItems - Position);
            if (offset < LayoutRoot.ActualWidth)
            {
                milliseconds *= offset / LayoutRoot.ActualWidth;
            }

            //
            // adjust positions
            //
            offsetBackground = offsetItems * BackgroundHost.Speed;
            offsetTitle = offsetItems * TitleHost.Speed;
            offsetItems = offsetItems * ItemsHost.Speed;

            // back to last
            if (offsetItems < 0)
            {
                offsetBackground = Items.GetLastItemPosition() - ItemsHost.Width;
                offsetTitle = offsetBackground * TitleHost.Speed - TitleHost.Padding;
                if (Items.Count == 1)
                {
                    // only 1 item : scroll the entire background
                    offsetBackground = -BackgroundHost.Width;
                }
            }
            // back to first
            else if (offsetItems >= Items.GetTotalWidth())
            {
                offsetBackground = BackgroundHost.Width;
                offsetTitle = TitleHost.Width + TitleHost.Padding;
            }

            //
            // start storyboard
            //
            Storyboard = new Storyboard();
            Storyboard.Completed += new EventHandler(Storyboard_Completed);
            Storyboard.Children.Add(CreateAnimation(BackgroundHost.Transform, TranslateTransform.XProperty,- offsetBackground, milliseconds));
            Storyboard.Children.Add(CreateAnimation(TitleHost.Transform, TranslateTransform.XProperty, -offsetTitle, milliseconds));
            Storyboard.Children.Add(CreateAnimation(ItemsHost.Transform, TranslateTransform.XProperty, -offsetItems, milliseconds));
            Storyboard.Begin();
        }
        static void SnapGridIntersection(UVSnapSettings snapSettings, SurfaceReference surfaceReference, Vector3 intersectionPoint, float preferenceFactor, ref Vector3 snappedPoint, ref float bestDist)
        {
            if ((snapSettings & UVSnapSettings.GeometryGrid) == UVSnapSettings.None)
            {
                return;
            }

            var grid             = UnitySceneExtensions.Grid.defaultGrid;
            var gridSnappedPoint = Snapping.SnapPoint(intersectionPoint, grid);

            var worldPlane = surfaceReference.WorldPlane.Value;

            var xAxis    = grid.Right;
            var yAxis    = grid.Up;
            var zAxis    = grid.Forward;
            var snapAxis = Axis.X | Axis.Y | Axis.Z;

            if (Mathf.Abs(Vector3.Dot(xAxis, worldPlane.normal)) >= kAlignmentEpsilon)
            {
                snapAxis &= ~Axis.X;
            }
            if (Mathf.Abs(Vector3.Dot(yAxis, worldPlane.normal)) >= kAlignmentEpsilon)
            {
                snapAxis &= ~Axis.Y;
            }
            if (Mathf.Abs(Vector3.Dot(zAxis, worldPlane.normal)) >= kAlignmentEpsilon)
            {
                snapAxis &= ~Axis.Z;
            }

            if (Mathf.Abs(worldPlane.GetDistanceToPoint(gridSnappedPoint)) < kDistanceEpsilon)
            {
                bestDist     = (gridSnappedPoint - intersectionPoint).magnitude * preferenceFactor;
                snappedPoint = gridSnappedPoint;
            }
            else
            {
                float dist;
                var   ray = new Ray(gridSnappedPoint, xAxis);
                if ((snapAxis & Axis.X) != Axis.None && worldPlane.UnsignedRaycast(ray, out dist))
                {
                    var planePoint = ray.GetPoint(dist);
                    var abs_dist   = (planePoint - intersectionPoint).magnitude * preferenceFactor;
                    if (abs_dist < bestDist)
                    {
                        bestDist     = abs_dist;
                        snappedPoint = planePoint;
                    }
                }
                ray.direction = yAxis;
                if ((snapAxis & Axis.Y) != Axis.None && worldPlane.UnsignedRaycast(ray, out dist))
                {
                    var planePoint = ray.GetPoint(dist);
                    var abs_dist   = (planePoint - intersectionPoint).magnitude * preferenceFactor;
                    if (abs_dist < bestDist)
                    {
                        bestDist     = abs_dist;
                        snappedPoint = planePoint;
                    }
                }
                ray.direction = zAxis;
                if ((snapAxis & Axis.Z) != Axis.None && worldPlane.UnsignedRaycast(ray, out dist))
                {
                    var planePoint = ray.GetPoint(dist);
                    var abs_dist   = (planePoint - intersectionPoint).magnitude * preferenceFactor;
                    if (abs_dist < bestDist)
                    {
                        bestDist     = abs_dist;
                        snappedPoint = planePoint;
                    }
                }
            }
        }
Ejemplo n.º 33
0
        public NoteRoll() {
            InitializeComponent();

            ImageBrush brush = new ImageBrush();
            brush.ImageSource = new BitmapImage(new Uri(System.AppDomain.CurrentDomain.BaseDirectory + "\\res\\01.PNG"));
            brush.TileMode = TileMode.Tile;
            brush.ViewportUnits = BrushMappingMode.Absolute;
            brush.Viewport = new Rect(0, 0, brush.ImageSource.Width, brush.ImageSource.Height);
            brush.Stretch = Stretch.None;
            bkgCanvas.Background = brush;

            otoRead = new OtoReader();
            wavMod = new wavmod.WavMod();

            setDefaultColors();
            PaintPianoKeys();

            scroller.ScrollToVerticalOffset(560);

            NoteSnapping = Snapping.Sixteenth;
            RollSnapping = Snapping.Sixteenth;
        }