Пример #1
0
        public GizmoLineSlider2D(Gizmo gizmo, int handleId, int capHandleId)
            : base(gizmo, handleId)
        {
            _segmentIndex = Handle.Add2DShape(_segment);
            _quadIndex    = Handle.Add2DShape(_quad);

            _controllerData.Gizmo        = Gizmo;
            _controllerData.Slider       = this;
            _controllerData.SliderHandle = Handle;
            _controllerData.Segment      = _segment;
            _controllerData.SegmentIndex = _segmentIndex;
            _controllerData.Quad         = _quad;
            _controllerData.QuadIndex    = _quadIndex;

            _controllers[(int)GizmoLine2DType.Thin] = new GizmoThinLineSlider2DController(_controllerData);
            _controllers[(int)GizmoLine2DType.Box]  = new GizmoBoxLineSlider2DController(_controllerData);

            _cap2D = new GizmoCap2D(gizmo, capHandleId);
            SetupSharedLookAndFeel();

            SetDragChannel(GizmoDragChannel.Offset);
            AddTargetTransform(Gizmo.Transform);
            AddTargetTransform(_transform);
            _cap2D.RegisterTransformAsDragTarget(_offsetDrag);
            _cap2D.RegisterTransformAsDragTarget(_rotationDrag);

            _transform.Changed += OnTransformChanged;
            _transform.SetParent(gizmo.Transform);

            Gizmo.PreUpdateBegin      += OnGizmoPreUpdateBegin;
            Gizmo.PreDragUpdate       += OnGizmoHandleDragUpdate;
            Gizmo.PreDragBeginAttempt += OnGizmoAttemptHandleDragBegin;
            Gizmo.PreHoverEnter       += OnGizmoHandleHoverEnter;
            Gizmo.PreHoverExit        += OnGizmoHandleHoverExit;
            Gizmo.PostEnabled         += OnGizmoPostEnabled;
        }
Пример #2
0
        private void UpdateTerrainBicubic(Gizmo gizmo)
        {
            var     data       = theTerrain.terrainData;
            Vector3 dragOffset = gizmo.RelativeDragOffset / data.heightmapScale.y;

            int gid = -1;

            gizmos.TryGetValue(gizmo, out gid);
            if (gid >= 0)
            {
                grid[gid] += dragOffset.y;
            }
            else
            {
                Debug.LogError("Gizmo is not found!");
            }

            int2 iidx = new int2(gid % gcount, gid / gcount);

            float[,] lerp_grid = new float[7, 7];
            for (int y = 0; y < 7; y++)
            {
                int _y = math.clamp(iidx.y - 3 + y, 0, gcount - 1);

                for (int x = 0; x < 7; x++)
                {
                    int _x = math.clamp(iidx.x - 3 + x, 0, gcount - 1);

                    lerp_grid[y, x] = grid[gcount * _y + _x];
                }
            }

            float2 heightmapScale = ((float3)data.heightmapScale).xz;
            float2 offset         = ((float3)transform.position).xz - new float2(size * 0.5f, size * 0.5f);
            float2 pos            = ((float3)gizmo.Transform.Position3D).xz - offset;

            int2 block_size = (int2)(new float2(spacing) / heightmapScale);

            int2 hPos = (int2)(pos / heightmapScale);

            hPos -= block_size * 2;

            int2    max_block = new int2(block_size.x * 4, block_size.y * 4);
            int     res       = data.heightmapResolution - 1;
            RectInt r         = new RectInt(hPos.x, hPos.y, max_block.x, max_block.y);

            r.xMin = math.clamp(r.xMin, 0, res);
            r.xMax = math.clamp(r.xMax, 0, res);
            r.yMin = math.clamp(r.yMin, 0, res);
            r.yMax = math.clamp(r.yMax, 0, res);

            // Get the current heights under the selected gizmo.
            float[,] hmap = data.GetHeights(r.x, r.y, r.width, r.height);

            for (int gy = 0; gy < 4; gy++)
            {
                int base_y = gy * block_size.y;

                for (int gx = 0; gx < 4; gx++)
                {
                    int base_x = gx * block_size.x;

#if false
                    interp.UpdateCoefficients(new float[4, 4] {
                        { lerp_grid[gy, gx], lerp_grid[gy + 1, gx], lerp_grid[gy + 2, gx], lerp_grid[gy + 3, gx] },
                        { lerp_grid[gy, gx + 1], lerp_grid[gy + 1, gx + 1], lerp_grid[gy + 2, gx + 1], lerp_grid[gy + 3, gx + 1] },
                        { lerp_grid[gy, gx + 2], lerp_grid[gy + 1, gx + 2], lerp_grid[gy + 2, gx + 2], lerp_grid[gy + 3, gx + 2] },
                        { lerp_grid[gy, gx + 3], lerp_grid[gy + 1, gx + 3], lerp_grid[gy + 2, gx + 3], lerp_grid[gy + 3, gx + 3] }
                    });
#else
                    interp.UpdateCoefficients(new float4x4(
                                                  lerp_grid[gy, gx], lerp_grid[gy, gx + 1], lerp_grid[gy, gx + 2], lerp_grid[gy, gx + 3],
                                                  lerp_grid[gy + 1, gx], lerp_grid[gy + 1, gx + 1], lerp_grid[gy + 1, gx + 2], lerp_grid[gy, gx + 3],
                                                  lerp_grid[gy + 2, gx], lerp_grid[gy + 2, gx + 1], lerp_grid[gy + 2, gx + 2], lerp_grid[gy, gx + 3],
                                                  lerp_grid[gy + 3, gx], lerp_grid[gy + 3, gx + 1], lerp_grid[gy + 3, gx + 2], lerp_grid[gy, gx + 3]
                                                  ));
#endif

                    for (int y = 0; y < block_size.y; y++)
                    {
                        int _y = hPos.y + base_y + y;
                        if (_y >= r.yMin && _y < r.yMax)
                        {
                            float ty = (float)y / block_size.y;

                            for (int x = 0; x < block_size.x; x++)
                            {
                                int _x = hPos.x + base_x + x;
                                if (_x >= r.xMin && _x < r.xMax)
                                {
                                    float tx = (float)x / block_size.x;

                                    try
                                    {
                                        hmap[_y - r.yMin, _x - r.xMin] = interp.GetValue(tx, ty);
                                    }
                                    catch
                                    {
                                        Debug.LogError("!!!!!!!!!!!!!!!!!!!")
                                        ;
                                    }
                                }
                            }
                        }
                    }
                }
            }

            // Set the new terrain heights
            data.SetHeights(r.x, r.y, hmap);
        }
Пример #3
0
 private void OnGizmoPostEnabled(Gizmo gizmo)
 {
     Refresh();
 }
Пример #4
0
        public float GetRealCircleRadius()
        {
            float scaleFactor = 1.0f;

            if (IsScaling)
            {
                float maxTotalDragScale = TotalDragScaleRight;
                if (Mathf.Abs(TotalDragScaleRight) < Mathf.Abs(TotalDragScaleUp))
                {
                    maxTotalDragScale = TotalDragScaleUp;
                }

                Vector3 realScaleAxis   = _scaleAxisUp * maxTotalDragScale;
                Vector2 screenScaleAxis = Vector3Ex.ConvertDirTo2D(ScaleDragOrigin, ScaleDragOrigin + realScaleAxis, Gizmo.GetWorkCamera());
                scaleFactor = (screenScaleAxis.magnitude / (LookAndFeel.CircleRadius * LookAndFeel.Scale)) * Mathf.Sign(maxTotalDragScale);
            }

            return(LookAndFeel.CircleRadius * LookAndFeel.Scale * scaleFactor);
        }
Пример #5
0
        /// <summary>
        /// This function traverses the handle's 2D and 3D shapes and decides which one is hovered
        /// by the specified ray. It then returns the hover information inside an instance of the
        /// 'GizmoHandleHoverData' class. The ray should be created using the 'Camera.ScreenPointToRay'
        /// function and it represents the ray which is cast out from the screen into the 3D scene.
        /// The function will always give priority to 2D shapes. So for example, if the handle has
        /// a 2D and a 3D shape, and the ray hovers both of them, only the 2D shape will be taken into
        /// account.
        /// </summary>
        /// <param name="hoverRay">
        /// The hover ray. This should be created using the 'Camera.ScreenPointToRay' function. The
        /// function will convert the origin of the ray in screen space to detect the 2D shapes which
        /// are hovered by the ray.
        /// </param>
        /// <returns>
        /// If a shape is hovered by the input ray, the function returns an instance of the
        /// 'GizmoHandleHoverData' class. Otherwise, it returns null. The function also returns
        /// null if there are any subscribers to the 'CanHover' event that don't allow the handle
        /// to be hovered.
        /// </returns>
        public GizmoHandleHoverData GetHoverData(Ray hoverRay)
        {
            float minDist = float.MaxValue;
            GizmoHandleHoverData handleHoverData = null;

            if (Is2DHoverable && Is2DVisible)
            {
                Vector2            screenRayOrigin = Gizmo.GetWorkCamera().WorldToScreenPoint(hoverRay.origin);
                GizmoHandleShape2D hovered2DShape  = null;
                foreach (var shape in _2DShapes)
                {
                    if (shape.IsVisible && shape.IsHoverable)
                    {
                        if (shape.Shape.ContainsPoint(screenRayOrigin))
                        {
                            float dist = (shape.Shape.GetEncapsulatingRect().center - screenRayOrigin).magnitude;
                            if (hovered2DShape == null || dist < minDist)
                            {
                                hovered2DShape = shape;
                                minDist        = dist;
                            }
                        }
                    }
                }

                if (hovered2DShape != null)
                {
                    handleHoverData = new GizmoHandleHoverData(hoverRay, this, screenRayOrigin);
                    if (CanHover != null)
                    {
                        var answer = new YesNoAnswer();
                        CanHover(Id, Gizmo, handleHoverData, answer);
                        if (answer.HasNo)
                        {
                            return(null);
                        }
                    }
                    return(handleHoverData);
                }
            }

            if (Is3DHoverable && Is3DVisible)
            {
                minDist = float.MaxValue;
                GizmoHandleShape3D hovered3DShape = null;
                foreach (var shape in _3DShapes)
                {
                    if (shape.IsVisible && shape.IsHoverable)
                    {
                        float t;
                        if (shape.Shape.Raycast(hoverRay, out t))
                        {
                            if (hovered3DShape == null || t < minDist)
                            {
                                hovered3DShape = shape;
                                minDist        = t;
                            }
                        }
                    }
                }

                if (hovered3DShape != null)
                {
                    handleHoverData = new GizmoHandleHoverData(hoverRay, this, minDist);
                    if (CanHover != null)
                    {
                        var answer = new YesNoAnswer();
                        CanHover(Id, Gizmo, handleHoverData, answer);
                        if (answer.HasNo)
                        {
                            return(null);
                        }
                    }

                    return(handleHoverData);
                }
            }

            return(null);
        }
Пример #6
0
 private void OnGizmoPostDisabled(Gizmo gizmo)
 {
     OverrideColor.IsActive        = false;
     _cap3D.OverrideColor.IsActive = false;
 }
 public GizmoHandleCollection(Gizmo gizmo)
 {
     _gizmo = gizmo;
 }
 private void OnGizmoDragEnd(Gizmo gizmo, int handleId)
 {
     _draggedGizmo = null;
 }
Пример #9
0
 private void OnTransformChanged(GizmoTransform transform, GizmoTransform.ChangeData changeData)
 {
     if (changeData.ChangeReason == GizmoTransform.ChangeReason.ParentChange ||
         changeData.TRSDimension == GizmoDimension.Dim3D)
     {
         _controllers[(int)LookAndFeel.CapType].UpdateTransforms(GetZoomFactor(Gizmo.GetWorkCamera()));
     }
 }
Пример #10
0
 public void CapSlider3DInvert(Vector3 sliderDirection, Vector3 sliderEndPt)
 {
     _controllers[(int)LookAndFeel.CapType].CapSlider3DInvert(sliderDirection, sliderEndPt, GetZoomFactor(Gizmo.GetWorkCamera()));
 }
Пример #11
0
 private void OnGizmoPreUpdateBegin(Gizmo gizmo)
 {
     _sceneGizmo.LookAndFeel.ConnectMidCapLookAndFeel(_cap);
 }
Пример #12
0
 public GizmoCap(Gizmo gizmo, int handleId)
 {
     _gizmo  = gizmo;
     _handle = Gizmo.CreateHandle(handleId);
 }
Пример #13
0
        public float GetRealLength()
        {
            float scaleFactor = 1.0f;

            if (IsScaling)
            {
                Vector3 realScaleAxis   = _scaleAxis * TotalDragScale;
                Vector2 screenScaleAxis = Vector3Ex.ConvertDirTo2D(ScaleDragOrigin, ScaleDragOrigin + realScaleAxis, Gizmo.GetWorkCamera());
                scaleFactor = (screenScaleAxis.magnitude / (LookAndFeel.Length * LookAndFeel.Scale)) * Mathf.Sign(TotalDragScale);
            }

            return(LookAndFeel.Length * LookAndFeel.Scale * scaleFactor);
        }
Пример #14
0
        private void OnAppInitialize()
        {
            interp = new CachedBicubicInterpolator();

            // Get the terrain component
            theTerrain = Terrain.activeTerrain;
            var data = theTerrain.terrainData;

            // Create gizmos arranged in a grid over the terrain.
            // Note: Having too many gizmos in the scene may cause performance issues?
            // Note: This pseudo code has multiple gizmos in the scene at once and alters TerrainData.
            //       But we could create more or fewer for a mesh vertices and use it to move multiple mesh control points at the same time.

            // This gizmo grid spacing is arbitrary for pseudo code, I don't know the granularity of the TerrainData or terrain mesh size for the final version.
            //??spacing = 20;

            gcount = size / spacing + 1;
            int numG = gcount * gcount;

            grid   = new float[numG];
            gizmos = new Dictionary <Gizmo, int>(numG);
            Vector3 offset = transform.position - new Vector3(size * 0.5f, 0.0f, size * 0.5f);

            for (int x = 0; x < gcount; ++x)
            {
                for (int z = 0; z < gcount; ++z)
                {
                    // Create the move gizmo.
                    // Note: We use the RTGizmosEngine.Get.CreateMoveGizmo function which returns a MoveGizmo instance.
                    //       The MoveGizmo class is a gizmo behaviour. A gizmo behaviour is like a MonoBehaviour. And each
                    //       gizmo behaviour is attached to a Gizmo. A Gizmo is like a GameObject in Unity.
                    MoveGizmo moveGizmo  = RTGizmosEngine.Get.CreateMoveGizmo();
                    Gizmo     ownerGizmo = moveGizmo.Gizmo;
                    gizmos.Add(ownerGizmo, z * gcount + x);

                    // Use the Transform property to set the position of the gizmo.
                    Vector3 gpos = new Vector3(x * spacing, 0.0f, z * spacing);
                    gpos.y = theTerrain.SampleHeight(gpos);
                    ownerGizmo.Transform.Position3D = gpos + offset;

                    // We need to listen to gizmo drag events in order to be able to move the TerrainData heights or mesh control points.
                    // For this reason we create a handle with the same signature as OnGizmoDragUpdate.
                    // Note: There are 2 drag update events: PreDragUpdate and PostDragUpdate. Always use the Post version.
                    ownerGizmo.PostDragUpdate += OnGizmoDragUpdate;

                    // We want all gizmos to share the same look and feel so we will assign our members to each gizmo that gets
                    // created. This is in a way similar to the concept of shared materials in Unity. After this assignment takes
                    // place, changing the properties of _sharedLookAndFeel2D or _sharedLookAndFeel3D will cause all gizmos to
                    // change how they look. We don't have to do this if we want each gizmo to have a unique look and feel. Also,
                    // we can set the SharedLookAndFeel2D and SharedLookAndFeel3D properties to null later if we wish to revert to
                    // unique look and feel.
                    moveGizmo.SharedLookAndFeel2D = _sharedLookAndFeel2D;
                    moveGizmo.SharedLookAndFeel3D = _sharedLookAndFeel3D;
                }
            }

            // Since we are dealing with heights of TerrainData or mesh control points on a terrain mesh, the gizmos will most likely just
            // move up/down on the Y axis. This means that you can hide the X and Z axes and just leave the Y axis visible.
            // Note: all axes could be visible, but they don't make much sense for the purposes of moving terrain patches up/down at this point
            //       unless those axes are needed to smooth or give more control to the terrain.
            _sharedLookAndFeel3D.SetSliderVisible(0, AxisSign.Positive, false);     // Hide the slider (the line)
            _sharedLookAndFeel3D.SetSliderCapVisible(0, AxisSign.Positive, false);  // Hide the slider cap (the cone)
            _sharedLookAndFeel3D.SetSliderVisible(2, AxisSign.Positive, false);
            _sharedLookAndFeel3D.SetSliderCapVisible(2, AxisSign.Positive, false);

            // Do the same for the rectangles that allow the gizmo to move along 2 axes at once
            _sharedLookAndFeel3D.SetDblSliderVisible(PlaneId.XY, false);
            _sharedLookAndFeel3D.SetDblSliderVisible(PlaneId.YZ, false);
            _sharedLookAndFeel3D.SetDblSliderVisible(PlaneId.ZX, false);
        }
 private void RegisterGizmo(Gizmo gizmo)
 {
     _gizmos.Add(gizmo);
     gizmo.PreDragBegin += OnGizmoDragBegin;
     gizmo.PreDragEnd   += OnGizmoDragEnd;
 }
Пример #16
0
        private void OnGizmoAttemptHandleDragBegin(Gizmo gizmo, int handleId)
        {
            if (handleId == HandleId)
            {
                if (_dragChannel == GizmoDragChannel.Offset)
                {
                    GizmoDblAxisOffsetDrag3D.WorkData workData = new GizmoDblAxisOffsetDrag3D.WorkData();
                    workData.Axis0      = Right;
                    workData.Axis1      = Up;
                    workData.DragOrigin = Position;
                    workData.SnapStep0  = Settings.OffsetSnapStepRight;
                    workData.SnapStep1  = Settings.OffsetSnapStepUp;
                    _dblAxisOffsetDrag.SetWorkData(workData);
                }
                else
                if (_dragChannel == GizmoDragChannel.Rotation)
                {
                    GizmoSglAxisRotationDrag3D.WorkData workData = new GizmoSglAxisRotationDrag3D.WorkData();
                    workData.Axis             = Normal;
                    workData.RotationPlanePos = Position;
                    workData.SnapMode         = Settings.RotationSnapMode;
                    workData.SnapStep         = Settings.RotationSnapStep;
                    _rotationDrag.SetWorkData(workData);

                    Vector3 arcStart = Plane.ProjectPoint(Gizmo.HoverInfo.HoverPoint);
                    _rotationArc.SetArcData(Normal, Position, arcStart, GetRealCircleRadius(GetZoomFactor(Gizmo.FocusCamera)));
                }
                else
                if (_dragChannel == GizmoDragChannel.Scale)
                {
                    float zoomFactor = GetZoomFactor(Gizmo.FocusCamera);

                    GizmoDblAxisScaleDrag3D.WorkData workData = new GizmoDblAxisScaleDrag3D.WorkData();
                    workData.Axis0      = Right;
                    workData.Axis1      = Up;
                    workData.DragOrigin = Position;
                    workData.AxisIndex0 = _scaleDragAxisIndexRight;
                    workData.AxisIndex1 = _scaleDragAxisIndexUp;
                    workData.ScaleMode  = Settings.ScaleMode;

                    if (workData.ScaleMode == GizmoDblAxisScaleMode.Independent)
                    {
                        workData.IndSnapStep0 = Settings.ScaleSnapStepRight;
                        workData.IndSnapStep1 = Settings.ScaleSnapStepUp;

                        if (LookAndFeel.PlaneType == GizmoPlane3DType.Quad)
                        {
                            workData.IndBaseSize0 = GetRealQuadWidth(zoomFactor) * 0.5f;
                            workData.IndBaseSize1 = GetRealQuadHeight(zoomFactor) * 0.5f;
                        }
                        else
                        if (LookAndFeel.PlaneType == GizmoPlane3DType.RATriangle)
                        {
                            workData.IndBaseSize0 = GetRealRATriXLength(zoomFactor);
                            workData.IndBaseSize1 = GetRealRATriYLength(zoomFactor);
                        }
                    }
                    else
                    {
                        if (LookAndFeel.PlaneType == GizmoPlane3DType.Quad)
                        {
                            workData.PropBaseSize = TriangleMath.CalcRATriangleHypotenuse(GetRealQuadSize(zoomFactor) * 0.5f);
                        }
                        else
                        if (LookAndFeel.PlaneType == GizmoPlane3DType.RATriangle)
                        {
                            workData.PropBaseSize = TriangleMath.CalcRATriangleAltitude(GetRealRATriSize(zoomFactor));
                        }

                        workData.PropSnapStep = Settings.ProportionalScaleSnapStep;
                        workData.PropAxis     = ((Right + Up) * 0.5f).normalized;
                    }

                    _scaleDrag.SetWorkData(workData);
                }
            }
        }
 private void OnGizmoDragBegin(Gizmo gizmo, int handleId)
 {
     _draggedGizmo = gizmo;
 }
Пример #18
0
 public void Init_SystemCall(GizmoBehaviorInitParams initParams)
 {
     _gizmo = initParams.Gizmo;
 }
 private void OnGizmoPreUpdateBegin(Gizmo gizmo)
 {
     _handle.Is2DVisible = _sceneGizmo.LookAndFeel.IsCamPrjSwitchLabelVisible;
     UpdateTransform();
 }
 private bool IsGizmoRegistered(Gizmo gizmo)
 {
     return(_allGizmos.FindAll(item => item.Gizmo == gizmo).Count != 0);
 }
Пример #21
0
 /// <summary>
 /// Returns the size (length and thickness) of the slider along the specified direction
 /// axis. The function will take into accoun the look and feel settings such as the slider
 /// type (line, box, cylinder), scale and whether or not a zoom factor should be applied.
 /// </summary>
 /// <param name="camera">
 /// This is the camera needed to calculate the slider zoom factor if necessary.
 /// </param>
 /// <param name="direction">
 /// The direction along which the slider size will be calculated.
 /// </param>
 public float GetRealSizeAlongDirection(Camera camera, Vector3 direction)
 {
     return(_controllers[(int)LookAndFeel.LineType].GetRealSizeAlongDirection(direction, GetZoomFactor(Gizmo.GetWorkCamera())));
 }
        private bool RegisterGizmo(int gizmoId, Gizmo gizmo)
        {
            if (IsGizmoRegistered(gizmoId) || IsGizmoRegistered(gizmo))
            {
                return(false);
            }
            _allGizmos.Add(new ObjectSelectionGizmo(gizmoId, gizmo));

            ObjectTransformGizmo transformGizmo = gizmo.GetFirstBehaviourOfType <ObjectTransformGizmo>();

            if (transformGizmo != null)
            {
                _objectTransformGizmos.Add(transformGizmo);
                transformGizmo.SetTargetObjects(_targetObjectCollection);
            }

            var moveGizmo = gizmo.GetFirstBehaviourOfType <MoveGizmo>();

            if (moveGizmo != null)
            {
                moveGizmo.SharedSettings2D    = MoveGizmoSettings2D;
                moveGizmo.SharedSettings3D    = MoveGizmoSettings3D;
                moveGizmo.SharedLookAndFeel2D = MoveGizmoLookAndFeel2D;
                moveGizmo.SharedLookAndFeel3D = MoveGizmoLookAndFeel3D;
                moveGizmo.SharedHotkeys       = MoveGizmoHotkeys;
                moveGizmo.SetVertexSnapTargetObjects(_targetObjectCollection);
                if (transformGizmo != null)
                {
                    transformGizmo.SharedSettings = ObjectMoveGizmoSettings;
                }
            }

            var rotationGizmo = gizmo.GetFirstBehaviourOfType <RotationGizmo>();

            if (rotationGizmo != null)
            {
                rotationGizmo.SharedSettings3D    = RotationGizmoSettings3D;
                rotationGizmo.SharedLookAndFeel3D = RotationGizmoLookAndFeel3D;
                rotationGizmo.SharedHotkeys       = RotationGizmoHotkeys;
                if (transformGizmo != null)
                {
                    transformGizmo.SharedSettings = ObjectRotationGizmoSettings;
                }
            }

            var scaleGizmo = gizmo.GetFirstBehaviourOfType <ScaleGizmo>();

            if (scaleGizmo != null)
            {
                scaleGizmo.SharedSettings3D    = ScaleGizmoSettings3D;
                scaleGizmo.SharedLookAndFeel3D = ScaleGizmoLookAndFeel3D;
                scaleGizmo.SharedHotkeys       = ScaleGizmoHotkeys;
                scaleGizmo.SetScaleGuideTargetObjects(_targetObjectCollection);
                if (transformGizmo != null)
                {
                    transformGizmo.SharedSettings = ObjectScaleGizmoSettings;
                }
            }

            var boxScaleGizmo = gizmo.GetFirstBehaviourOfType <BoxGizmo>();

            if (boxScaleGizmo != null)
            {
                boxScaleGizmo.SharedSettings3D    = BoxScaleGizmoSettings3D;
                boxScaleGizmo.SharedLookAndFeel3D = BoxScaleGizmoLookAndFeel3D;
                boxScaleGizmo.SharedHotkeys       = BoxScaleGizmoHotkeys;
            }

            var universalGizmo = gizmo.GetFirstBehaviourOfType <UniversalGizmo>();

            if (universalGizmo != null)
            {
                universalGizmo.SharedSettings2D    = UniversalGizmoSettings2D;
                universalGizmo.SharedSettings3D    = UniversalGizmoSettings3D;
                universalGizmo.SharedLookAndFeel2D = UniversalGizmoLookAndFeel2D;
                universalGizmo.SharedLookAndFeel3D = UniversalGizmoLookAndFeel3D;
                universalGizmo.SharedHotkeys       = UniversalGizmoHotkeys;
                universalGizmo.SetMvVertexSnapTargetObjects(_targetObjectCollection);
                universalGizmo.SetScaleGuideTargetObjects(_targetObjectCollection);
                if (transformGizmo != null)
                {
                    transformGizmo.SharedSettings = ObjectUniversalGizmoSettings;
                }
            }

            var extrudeGizmo = gizmo.GetFirstBehaviourOfType <ObjectExtrudeGizmo>();

            if (extrudeGizmo != null)
            {
                extrudeGizmo.SharedLookAndFeel3D = ExtrudeGizmoLookAndFeel3D;
                extrudeGizmo.SharedHotkeys       = ExtrudeGozmoHotkeys;
                extrudeGizmo.SetExtrudeTargets(_targetObjectCollection);
            }

            gizmo.PostEnabled += OnGizmoPostEnabled;
            return(true);
        }
Пример #23
0
 private void Update2DGizmoPosition()
 {
     Gizmo.Transform.Position2D = Gizmo.GetWorkCamera().WorldToScreenPoint(Gizmo.Transform.Position3D);
 }
Пример #24
0
 public override void OnGizmoAttemptHandleDragBegin(int handleId)
 {
     if (handleId == _rtMidCap.HandleId)
     {
         var workData = new GizmoDblAxisRotationDrag3D.WorkData();
         workData.Axis0       = Gizmo.FocusCamera.transform.up;
         workData.Axis1       = Gizmo.FocusCamera.transform.right;
         workData.ScreenAxis0 = -Vector3.right;
         workData.ScreenAxis1 = Vector3.up;
         workData.SnapMode    = Settings3D.RtSnapMode;
         workData.SnapStep0   = Settings3D.RtCamUpSnapStep;
         workData.SnapStep1   = Settings3D.RtCamRightSnapStep;
         _rtCamXYRotationDrag.SetWorkData(workData);
     }
     else if (handleId == _scMidCap.HandleId)
     {
         var workData = new GizmoUniformScaleDrag3D.WorkData();
         workData.BaseSize    = _scMidCap.GetRealBoxSize(_scMidCap.GetZoomFactor(Gizmo.GetWorkCamera())).magnitude;
         workData.DragOrigin  = _scMidCap.Position;
         workData.CameraRight = Gizmo.FocusCamera.transform.right;
         workData.CameraUp    = Gizmo.FocusCamera.transform.up;
         workData.SnapStep    = Settings3D.ScUniformSnapStep;
         _scUnformScaleDrag.SetWorkData(workData);
     }
 }
Пример #25
0
        public float GetRealQuadHeight()
        {
            float scaleFactor = 1.0f;

            if (IsScaling)
            {
                Vector3 realScaleAxis   = _scaleAxisUp * TotalDragScaleUp;
                Vector2 screenScaleAxis = Vector3Ex.ConvertDirTo2D(ScaleDragOrigin, ScaleDragOrigin + realScaleAxis, Gizmo.GetWorkCamera());
                scaleFactor = screenScaleAxis.magnitude / (LookAndFeel.QuadHeight * LookAndFeel.Scale * 0.5f) * Mathf.Sign(TotalDragScaleUp);
            }

            return(LookAndFeel.QuadHeight * LookAndFeel.Scale * scaleFactor);
        }
        public void Update_SystemCall()
        {
            foreach (var sceneGizmoCam in _sceneGizmoCameras)
            {
                sceneGizmoCam.Update_SystemCall();
            }

            _pipelineStage = GizmosEnginePipelineStage.Update;
            IInputDevice inputDevice      = RTInputDevice.Get.Device;
            bool         deviceHasPointer = inputDevice.HasPointer();
            Vector3      inputDevicePos   = inputDevice.GetPositionYAxisUp();

            bool isUIHovered        = RTScene.Get.IsAnyUIElementHovered();
            bool canUpdateHoverInfo = _draggedGizmo == null && !isUIHovered;

            if (canUpdateHoverInfo)
            {
                YesNoAnswer answer = new YesNoAnswer();
                if (CanDoHoverUpdate != null)
                {
                    CanDoHoverUpdate(answer);
                }
                if (answer.HasNo)
                {
                    canUpdateHoverInfo = false;
                }
            }

            if (canUpdateHoverInfo)
            {
                _hoveredGizmo = null;
                _gizmoHoverInfo.Reset();
            }

            bool isDeviceInsideFocusCamera  = deviceHasPointer && RTFocusCamera.Get.IsViewportHoveredByDevice(); //RTFocusCamera.Get.TargetCamera.pixelRect.Contains(inputDevicePos);
            bool focusCameraCanRenderGizmos = IsRenderCamera(RTFocusCamera.Get.TargetCamera);
            var  hoverDataCollection        = new List <GizmoHandleHoverData>(10);

            foreach (var gizmo in _gizmos)
            {
                gizmo.OnUpdateBegin_SystemCall();
                if (canUpdateHoverInfo && gizmo.IsEnabled &&
                    isDeviceInsideFocusCamera && deviceHasPointer && focusCameraCanRenderGizmos)
                {
                    var handleHoverData = GetGizmoHandleHoverData(gizmo);
                    if (handleHoverData != null)
                    {
                        hoverDataCollection.Add(handleHoverData);
                    }
                }
            }

            GizmoHandleHoverData hoverData = null;

            if (canUpdateHoverInfo && hoverDataCollection.Count != 0)
            {
                SortHandleHoverDataCollection(hoverDataCollection, inputDevicePos);

                hoverData                       = hoverDataCollection[0];
                _hoveredGizmo                   = hoverData.Gizmo;
                _gizmoHoverInfo.HandleId        = hoverData.HandleId;
                _gizmoHoverInfo.HandleDimension = hoverData.HandleDimension;
                _gizmoHoverInfo.HoverPoint      = hoverData.HoverPoint;
                _gizmoHoverInfo.IsHovered       = true;
            }

            foreach (var gizmo in _gizmos)
            {
                _gizmoHoverInfo.IsHovered = (gizmo == _hoveredGizmo);
                gizmo.UpdateHandleHoverInfo_SystemCall(_gizmoHoverInfo);

                gizmo.HandleInputDeviceEvents_SystemCall();
                gizmo.OnUpdateEnd_SystemCall();
            }

            _pipelineStage = GizmosEnginePipelineStage.PostUpdate;
        }
Пример #27
0
        private void OnGizmoAttemptHandleDragBegin(Gizmo gizmo, int handleId)
        {
            if (handleId == HandleId)
            {
                if (_dragChannel == GizmoDragChannel.Offset)
                {
                    GizmoDblAxisOffsetDrag3D.WorkData workData = new GizmoDblAxisOffsetDrag3D.WorkData();
                    workData.Axis0      = Vector2Ex.ConvertDirTo3D(_transform.Right2D, OffsetDragOrigin, Gizmo.FocusCamera).normalized;
                    workData.Axis1      = Vector2Ex.ConvertDirTo3D(_transform.Up2D, OffsetDragOrigin, Gizmo.FocusCamera).normalized;
                    workData.DragOrigin = OffsetDragOrigin;
                    workData.SnapStep0  = Settings.OffsetSnapStepRight;
                    workData.SnapStep1  = Settings.OffsetSnapStepUp;
                    _offsetDrag.SetWorkData(workData);
                }
                else
                if (_dragChannel == GizmoDragChannel.Rotation)
                {
                    GizmoSglAxisRotationDrag3D.WorkData workData = new GizmoSglAxisRotationDrag3D.WorkData();
                    workData.Axis     = Gizmo.FocusCamera.transform.forward;
                    workData.SnapMode = Settings.RotationSnapMode;
                    workData.SnapStep = Settings.RotationSnapStep;
                    if (LookAndFeel.PlaneType != GizmoPlane2DType.Polygon)
                    {
                        workData.RotationPlanePos = Gizmo.FocusCamera.ScreenToWorldPoint(new Vector3(Position.x, Position.y, Gizmo.FocusCamera.nearClipPlane));
                    }

                    if (LookAndFeel.PlaneType == GizmoPlane2DType.Circle)
                    {
                        _rotationArc.SetArcData(Position, Gizmo.HoverInfo.HoverPoint, GetRealCircleRadius());
                        _rotationArc.Type = GizmoRotationArc2D.ArcType.Standard;
                    }
                    else
                    if (LookAndFeel.PlaneType == GizmoPlane2DType.Polygon)
                    {
                        Vector3 polyCenter = PolyCenter;
                        workData.RotationPlanePos = Gizmo.FocusCamera.ScreenToWorldPoint(new Vector3(polyCenter.x, polyCenter.y, Gizmo.FocusCamera.nearClipPlane));
                        _rotationArc.SetArcData(PolyCenter, Gizmo.HoverInfo.HoverPoint, 1.0f);
                        _rotationArc.Type               = GizmoRotationArc2D.ArcType.PolyProjected;
                        _rotationArc.ProjectionPoly     = _polygon;
                        _rotationArc.NumProjectedPoints = 100;
                    }
                    _rotationDrag.SetWorkData(workData);
                }
                else
                if (_dragChannel == GizmoDragChannel.Scale)
                {
                    _scaleAxisRight = Vector2Ex.ConvertDirTo3D(Position, GetRealExtentPoint(Shape2DExtentPoint.Right), ScaleDragOrigin, Gizmo.FocusCamera);
                    _scaleAxisUp    = Vector2Ex.ConvertDirTo3D(Position, GetRealExtentPoint(Shape2DExtentPoint.Top), ScaleDragOrigin, Gizmo.FocusCamera);

                    GizmoDblAxisScaleDrag3D.WorkData workData = new GizmoDblAxisScaleDrag3D.WorkData();
                    workData.Axis0      = _scaleAxisRight.normalized;
                    workData.Axis1      = _scaleAxisUp.normalized;
                    workData.AxisIndex0 = _scaleDragAxisIndexRight;
                    workData.AxisIndex1 = _scaleDragAxisIndexUp;
                    workData.DragOrigin = ScaleDragOrigin;
                    workData.SnapStep   = Settings.ProportionalScaleSnapStep;

                    _scaleDrag.SetWorkData(workData);
                }
            }
        }
        public GizmoHandleHoverData GetGizmoHandleHoverData(Gizmo gizmo)
        {
            Camera focusCamera         = gizmo.FocusCamera;
            Ray    hoverRay            = RTInputDevice.Get.Device.GetRay(focusCamera);
            var    hoverDataCollection = gizmo.GetAllHandlesHoverData(hoverRay);

            Vector3 screenRayOrigin = focusCamera.WorldToScreenPoint(hoverRay.origin);

            hoverDataCollection.Sort(delegate(GizmoHandleHoverData h0, GizmoHandleHoverData h1)
            {
                var handle0 = gizmo.GetHandleById_SystemCall(h0.HandleId);
                var handle1 = gizmo.GetHandleById_SystemCall(h1.HandleId);

                // Same dimensions?
                bool sameDims = (h0.HandleDimension == h1.HandleDimension);
                if (sameDims)
                {
                    // 2D dimension?
                    if (h0.HandleDimension == GizmoDimension.Dim2D)
                    {
                        // If the priorities are equal, we sort by distance from screen ray origin.
                        // Otherwise, we sort by priority.
                        if (handle0.HoverPriority2D == handle1.HoverPriority2D)
                        {
                            float d0 = (screenRayOrigin - h0.HoverPoint).sqrMagnitude;
                            float d1 = (screenRayOrigin - h1.HoverPoint).sqrMagnitude;
                            return(d0.CompareTo(d1));
                        }
                        else
                        {
                            return(handle0.HoverPriority2D.CompareTo(handle1.HoverPriority2D));
                        }
                    }
                    // 3D dimension
                    else
                    {
                        // If the priorities are equal, we sort by hover enter. Otherwise, we sort by priority.
                        if (handle0.HoverPriority3D == handle1.HoverPriority3D)
                        {
                            return(h0.HoverEnter3D.CompareTo(h1.HoverEnter3D));
                        }
                        else
                        {
                            return(handle0.HoverPriority3D.CompareTo(handle1.HoverPriority3D));
                        }
                    }
                }
                else
                {
                    // When the dimensions differ, we will sort by the gizmo generic priority. If the priorities are equal,
                    // we will give priority to 2D handles.
                    if (handle0.GenericHoverPriority == handle1.GenericHoverPriority)
                    {
                        if (h0.HandleDimension == GizmoDimension.Dim2D)
                        {
                            return(-1);
                        }
                        return(1);
                    }
                    return(handle0.GenericHoverPriority.CompareTo(handle1.GenericHoverPriority));
                }
            });

            return(hoverDataCollection.Count != 0 ? hoverDataCollection[0] : null);
        }
 private void OnGizmoPreUpdateBegin(Gizmo gizmo)
 {
     _controllers[(int)_planeSlider.LookAndFeel.PolygonBorderType].UpdateHandles();
     _controllers[(int)_planeSlider.LookAndFeel.PolygonBorderType].UpdateEpsilons();
 }
Пример #30
0
        private void UpdateTerrainBilinear(Gizmo gizmo)
        {
            var     data       = theTerrain.terrainData;
            Vector3 dragOffset = gizmo.RelativeDragOffset / data.heightmapScale.y;

            int gid = -1;

            gizmos.TryGetValue(gizmo, out gid);
            if (gid >= 0)
            {
                grid[gid] += dragOffset.y;
            }
            else
            {
                Debug.LogError("Gizmo is not found!");
            }

            Vector2Int gizmo_pos = new Vector2Int(gid % gcount, gid / gcount);

            float[,] lerp_grid = new float[3, 3]
            {
                { grid[gid - gcount - 1], grid[gid - gcount], grid[gid - gcount + 1] },
                { grid[gid - 1], grid[gid], grid[gid + 1] },
                { grid[gid + gcount - 1], grid[gid + gcount], grid[gid + gcount + 1] }
            };

            Vector3 offset = transform.position - new Vector3(size * 0.5f, 0.0f, size * 0.5f);
            Vector3 pos    = gizmo.Transform.Position3D - offset;

            Vector2Int block_size = new Vector2Int(
                (int)(spacing / data.heightmapScale.x),
                (int)(spacing / data.heightmapScale.z));

            Vector2Int hPos = new Vector2Int(
                (int)(pos.x / data.heightmapScale.x),
                (int)(pos.z / data.heightmapScale.z));

            hPos -= block_size;

            // Get the current heights under the selected gizmo.
            float[,] heightsvalues = data.GetHeights(
                hPos.x, hPos.y,
                block_size.x * 2, block_size.y * 2);

            for (int gy = 0; gy < 2; gy++)
            {
                int base_y = gy * block_size.y;

                for (int gx = 0; gx < 2; gx++)
                {
                    int base_x = gx * block_size.x;

                    for (int y = 0; y < block_size.y; y++)
                    {
                        float ty = (float)y / block_size.y;
                        for (int x = 0; x < block_size.x; x++)
                        {
                            float tx = (float)x / block_size.x;
                            heightsvalues[base_y + y, base_x + x] =
                                Mathf.Lerp(
                                    Mathf.Lerp(lerp_grid[gy, gx], lerp_grid[gy, gx + 1], tx),
                                    Mathf.Lerp(lerp_grid[gy + 1, gx], lerp_grid[gy + 1, gx + 1], tx),
                                    ty);
                        }
                    }
                }
            }

            // Set the new terrain heights
            data.SetHeights(hPos.x, hPos.y, heightsvalues);
        }