Example #1
0
        public bool AddBehaviour(IGizmoBehaviour behaviour)
        {
            if (behaviour == null || behaviour.Gizmo != null)
            {
                return(false);
            }

            GizmoBehaviorInitParams initParams = new GizmoBehaviorInitParams();

            initParams.Gizmo = this;

            behaviour.Init_SystemCall(initParams);
            if (!_behaviours.Add(behaviour))
            {
                return(false);
            }

            Type behaviourType = behaviour.GetType();

            if (behaviourType == typeof(MoveGizmo))
            {
                _moveGizmo = behaviour as MoveGizmo;
            }
            else if (behaviourType == typeof(RotationGizmo))
            {
                _rotationGizmo = behaviour as RotationGizmo;
            }
            else if (behaviourType == typeof(ScaleGizmo))
            {
                _scaleGizmo = behaviour as ScaleGizmo;
            }
            else if (behaviourType == typeof(UniversalGizmo))
            {
                _universalGizmo = behaviour as UniversalGizmo;
            }
            else if (behaviourType == typeof(SceneGizmo))
            {
                _sceneGizmo = behaviour as SceneGizmo;
            }
            else if (behaviourType == typeof(BoxGizmo))
            {
                _boxGizmo = behaviour as BoxGizmo;
            }
            else if (behaviourType == typeof(ObjectTransformGizmo))
            {
                _objectTransformGizmo = behaviour as ObjectTransformGizmo;
            }
            else if (behaviourType == typeof(ObjectExtrudeGizmo))
            {
                _objectExtrudeGizmo = behaviour as ObjectExtrudeGizmo;
            }

            behaviour.OnAttached();
            behaviour.OnEnabled();

            return(true);
        }
        public ObjectTransformGizmo CreateObjectMoveGizmo()
        {
            MoveGizmo moveGizmo      = CreateMoveGizmo();
            var       transformGizmo = moveGizmo.Gizmo.AddBehaviour <ObjectTransformGizmo>();

            transformGizmo.SetTransformChannelFlags(ObjectTransformGizmo.Channels.Position);

            return(transformGizmo);
        }
        public MoveGizmo CreateMoveGizmo()
        {
            Gizmo     gizmo     = CreateGizmo();
            MoveGizmo moveGizmo = new MoveGizmo();

            gizmo.AddBehaviour(moveGizmo);

            return(moveGizmo);
        }
Example #4
0
        public bool RemoveBehaviour(IGizmoBehaviour behaviour)
        {
            if (behaviour == null)
            {
                return(false);
            }

            if (behaviour == _moveGizmo)
            {
                _moveGizmo = null;
            }
            else if (behaviour == _rotationGizmo)
            {
                _rotationGizmo = null;
            }
            else if (behaviour == _scaleGizmo)
            {
                _scaleGizmo = null;
            }
            else if (behaviour == _universalGizmo)
            {
                _universalGizmo = null;
            }
            else if (behaviour == _sceneGizmo)
            {
                _sceneGizmo = null;
            }
            else if (behaviour == _boxGizmo)
            {
                _boxGizmo = null;
            }
            else if (behaviour == _objectTransformGizmo)
            {
                _objectTransformGizmo = null;
            }
            else if (behaviour == _objectExtrudeGizmo)
            {
                _objectExtrudeGizmo = null;
            }

            return(_behaviours.Remove(behaviour));
        }
Example #5
0
        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);
            }

            MoveGizmo 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;
                }
            }

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

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

            ScaleGizmo 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;
                }
            }

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

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

            UniversalGizmo 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;
                }
            }

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

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

            gizmo.PostEnabled += OnGizmoPostEnabled;
            return(true);
        }
Example #6
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);
        }