public void OnPointerHover(Vector3 normalizedPosition)
        {
            // Set highlighted component
            GizmoComponent hitComponent = Raycast(normalizedPosition);

            if (hitComponent != GizmoComponent.None)
            {
                if (hitComponent != highlightedComponent)
                {
                    if (highlightedComponent != GizmoComponent.None)
                    {
                        gizmoComponents[(int)highlightedComponent].sharedMaterial = gizmoNormalMaterial;
                    }

                    if (hitComponent != fadingComponent)
                    {
                        highlightedComponent = hitComponent;
                        gizmoComponents[(int)highlightedComponent].sharedMaterial = gizmoHighlightMaterial;
                    }
                    else
                    {
                        highlightedComponent = GizmoComponent.None;
                    }
                }
            }
            else if (highlightedComponent != GizmoComponent.None)
            {
                gizmoComponents[(int)highlightedComponent].sharedMaterial = gizmoNormalMaterial;
                highlightedComponent = GizmoComponent.None;
            }
        }
        private void SetHiddenComponent(GizmoComponent component)
        {
            if (component != GizmoComponent.None)
            {
                if (component != fadingComponent)
                {
                    if (fadingComponent != GizmoComponent.None)
                    {
                        SetMaterialOf(fadingComponent, gizmoNormalMaterial);
                        SetAlphaOf(fadingComponent, 1f);

                        gizmoComponents[(int)fadingComponent].gameObject.SetActive(true);
                        gizmoComponents[(int)GetOppositeComponent(fadingComponent)].gameObject.SetActive(true);
                    }

                    fadingComponent = component;
                    SetMaterialOf(fadingComponent, gizmoFadeMaterial);
                    isFadingToZero = true;
                    fadeT          = 0f;
                }
            }
            else if (fadingComponent != GizmoComponent.None && fadeT >= 1f)
            {
                gizmoComponents[(int)fadingComponent].gameObject.SetActive(true);
                gizmoComponents[(int)GetOppositeComponent(fadingComponent)].gameObject.SetActive(true);

                isFadingToZero = false;
                fadeT          = 0f;
            }
        }
Exemplo n.º 3
0
        private void OnEnable()
        {
            if (highlightedComponent != GizmoComponent.None)
            {
                gizmoComponents[(int)highlightedComponent].sharedMaterial = gizmoNormalMaterial;
                highlightedComponent = GizmoComponent.None;
            }

            SetHiddenComponent(GizmoComponent.None);
        }
        void InitGizmo()
        {
            Gizmo = new GizmoComponent(GraphicsDevice, spriteBatch, font);
            Gizmo.SetSelectionPool(STATIC_EDITOR_MODE.LevelInstance.Entities);

            // Events
            Gizmo.TranslateEvent += OnGizmoTranslate;
            Gizmo.RotateEvent    += OnGizmoRotate;
            Gizmo.ScaleEvent     += OnGizmoScale;
        }
Exemplo n.º 5
0
 public EDScene(string name, GizmoComponent gizmo)
     : base(name)
 {
     _addList            = new List <string>();
     _removeList         = new List <GameObject>();
     _selectedObject     = new SceneObjectSelector();
     _editionSceneObject = new BasicEditionSceneObject();
     _gizmo = gizmo;
     _gizmo.TranslateEvent += GizmoTranslateEvent;
     _gizmo.RotateEvent    += GizmoRotateEvent;
     _gizmo.ScaleEvent     += GizmoScaleEvent;
 }
Exemplo n.º 6
0
        public void OnPointerClick(PointerEventData eventData)
        {
            if (eventData.dragging)
            {
                return;
            }

            GizmoComponent hitComponent = controller.Raycast(GetNormalizedPointerPosition(eventData));

            if (hitComponent != GizmoComponent.None)
            {
                m_onComponentClicked.Invoke(hitComponent);
            }
        }
Exemplo n.º 7
0
        protected override void LoadContent()
        {
            _spriteBatch = new SpriteBatch(GraphicsDevice);

            SpriteFont font = Content.Load <SpriteFont>("GizmoFont");

            _gizmo = new GizmoComponent(_graphics.GraphicsDevice, _spriteBatch, font);
            _gizmo.SetSelectionPool(Engine.Entities);

            _gizmo.TranslateEvent += GizmoTranslateEvent;
            _gizmo.RotateEvent    += GizmoRotateEvent;
            _gizmo.ScaleEvent     += GizmoScaleEvent;

            _grid = new GridComponent(GraphicsDevice, 8);

            Model boxModel = Content.Load <Model>("box");
            // add entity
            SceneEntity entity1 = new SceneEntity(boxModel)
            {
                Position = new Vector3(0, 0, 20)
            };

            Engine.Entities.Add(entity1);
            // and another
            SceneEntity entity2 = new SceneEntity(boxModel)
            {
                Position = new Vector3(0, 0, -20)
            };

            Engine.Entities.Add(entity2);

            #region Hotkey Explanation
            _helpTextBuilder = new StringBuilder();
            _helpTextBuilder.AppendLine("Hotkeys:");

            _helpTextBuilder.AppendLine("1,2,3,4 to switch Transformation Modes");
            _helpTextBuilder.AppendLine("O = Switch space (Local/World)");
            _helpTextBuilder.AppendLine("I = Toggle Snapping");
            _helpTextBuilder.AppendLine("P = Switch PivotTypes");
            _helpTextBuilder.AppendLine("Hold Control = Add to selection");
            _helpTextBuilder.AppendLine("Hold Shift = Precision Mode");
            _helpTextBuilder.AppendLine("Hold Alt = Remove from selection");

            _helpText = _helpTextBuilder.ToString();

            #endregion

            _font = Content.Load <SpriteFont>("SpriteFont");
        }
Exemplo n.º 8
0
        protected override void Initialize()
        {
            base.Initialize();

            _gameTime       = new GameTime(TimeSpan.Zero, TimeSpan.Zero);
            _gameComponents = new List <GameComponent>();

            _services = new GameServiceContainer();
            _services.AddService <IGraphicsDeviceService>(new GraphicsDeviceService(graphicsDevice));

            _content = new ContentManager(this);
            _content.RootDirectory = "Content";

            _projectContent = new ContentManager(this);
            _projectContent.RootDirectory = EDRegistry.ContentTempPath;

            AssetImporter.CreateFolderStructure("Temp");

            Application.Content        = _content;
            Application.GraphicsDevice = GraphicsDevice;

            _gameComponents.Add(EDRegistry.Mouse);
            _gameComponents.Add(EDRegistry.Keys);
            _gameComponents.Add(new Time());

            _renderer = new ForwardRenderer();
            _renderer.Initialize(_content);

            foreach (var component in _gameComponents)
            {
                component.Initialize();
            }

            gizmoComponent            = new GizmoComponent(GraphicsDevice);
            gizmoComponent.ActiveMode = GizmoMode.Translate;

            _scene = new EDScene("Root", gizmoComponent);
            _scene.Initialize();
            _scene.RenderSettings.Skybox.Generate();

            MouseDown += C3DEGameHost_MouseDown;
            MouseUp   += C3DEGameHost_MouseUp;

            if (EngineReady != null)
            {
                EngineReady();
            }
        }
Exemplo n.º 9
0
        private GizmoComponent GetOppositeComponent(GizmoComponent component)
        {
            if (component == GizmoComponent.None || component == GizmoComponent.Center)
            {
                return(component);
            }

            int val = (int)component;

            if (val % 2 == 0)
            {
                return((GizmoComponent)(val - 1));
            }

            return((GizmoComponent)(val + 1));
        }
Exemplo n.º 10
0
        private void SetMaterialOf(GizmoComponent component, Material material)
        {
            if (component == GizmoComponent.None)
            {
                return;
            }

            GizmoComponent oppositeComponent = GetOppositeComponent(component);

            if (component == highlightedComponent || oppositeComponent == highlightedComponent)
            {
                highlightedComponent = GizmoComponent.None;
            }

            gizmoComponents[(int)component].sharedMaterial         = material;
            gizmoComponents[(int)oppositeComponent].sharedMaterial = material;
        }
        public GizmoModeMenuBarViewModel(TransformToolViewModel transformToolViewModel, IComponentManager componentManager, ToolbarCommandFactory commandFactory)
        {
            _transformToolViewModel = transformToolViewModel;
            _commandFactory         = commandFactory;

            CursorCommand = _commandFactory.Register(new RelayCommand(Cursor), Key.Q, ModifierKeys.None);
            MoveCommand   = _commandFactory.Register(new RelayCommand(Move), Key.W, ModifierKeys.None);
            RotateCommand = _commandFactory.Register(new RelayCommand(Rotate), Key.E, ModifierKeys.None);
            ScaleCommand  = _commandFactory.Register(new RelayCommand(Scale), Key.R, ModifierKeys.None);

            ScaleGizmoUpCommand   = _commandFactory.Register(new RelayCommand(ScaleGizmoUp), Key.Add, ModifierKeys.None);
            ScaleGizmoDownCommand = _commandFactory.Register(new RelayCommand(ScaleGizmoDown), Key.Subtract, ModifierKeys.None);

            _gizmoComponent   = componentManager.GetComponent <GizmoComponent>();
            _selectionManager = componentManager.GetComponent <SelectionManager>();
            _selectionManager.SelectionChanged += OnSelectionChanged;
            _selectionComponent = componentManager.GetComponent <SelectionComponent>();
        }
Exemplo n.º 12
0
        private void SetAlphaOf(GizmoComponent component, float alpha)
        {
            if (component == GizmoComponent.None)
            {
                return;
            }

            gizmoFadeMaterial.SetFloat(gizmoMaterialFadeProperty, alpha);
            if (component == GizmoComponent.XNegative || component == GizmoComponent.XPositive)
            {
                labels[0].color = new Color(1f, 1f, 1f, alpha);
            }
            else if (component == GizmoComponent.ZNegative || component == GizmoComponent.ZPositive)
            {
                labels[2].color = new Color(1f, 1f, 1f, alpha);
            }
            else
            {
                labels[1].color = new Color(1f, 1f, 1f, alpha);
            }
        }
Exemplo n.º 13
0
        private void LateUpdate()
        {
            Vector3 forward = mainCamTR.forward;

            if (prevForward != forward)
            {
                float xAbs = forward.x < 0 ? -forward.x : forward.x;
                float yAbs = forward.y < 0 ? -forward.y : forward.y;
                float zAbs = forward.z < 0 ? -forward.z : forward.z;

                GizmoComponent facingDirection;
                float          facingDirectionCosine;
                if (xAbs > yAbs)
                {
                    if (xAbs > zAbs)
                    {
                        facingDirection       = forward.x > 0 ? GizmoComponent.XPositive : GizmoComponent.XNegative;
                        facingDirectionCosine = Vector3.Dot(forward, new Vector3(1f, 0f, 0f));
                    }
                    else
                    {
                        facingDirection       = forward.z > 0 ? GizmoComponent.ZPositive : GizmoComponent.ZNegative;
                        facingDirectionCosine = Vector3.Dot(forward, new Vector3(0f, 0f, 1f));
                    }
                }
                else if (yAbs > zAbs)
                {
                    facingDirection       = forward.y > 0 ? GizmoComponent.YPositive : GizmoComponent.YNegative;
                    facingDirectionCosine = Vector3.Dot(forward, new Vector3(0f, 1f, 0f));
                }
                else
                {
                    facingDirection       = forward.z > 0 ? GizmoComponent.ZPositive : GizmoComponent.ZNegative;
                    facingDirectionCosine = Vector3.Dot(forward, new Vector3(0f, 0f, 1f));
                }

                if (facingDirectionCosine < 0)
                {
                    facingDirectionCosine = -facingDirectionCosine;
                }

                if (facingDirectionCosine >= 0.92f)                  // cos(20)
                {
                    SetHiddenComponent(GetOppositeComponent(facingDirection));
                }
                else
                {
                    SetHiddenComponent(GizmoComponent.None);
                }

                Quaternion rotation = mainCamTR.rotation;
                gizmoCamParent.localRotation = rotation;

                // Adjust the labels
                float xLabelPos = (xAbs - 0.15f) * 0.65f;
                float yLabelPos = (yAbs - 0.15f) * 0.65f;
                float zLabelPos = (zAbs - 0.15f) * 0.65f;

                if (xLabelPos < 0f)
                {
                    xLabelPos = 0f;
                }
                if (yLabelPos < 0f)
                {
                    yLabelPos = 0f;
                }
                if (zLabelPos < 0f)
                {
                    zLabelPos = 0f;
                }

                labelsTR[0].localPosition = new Vector3(0f, 0f, xLabelPos);
                labelsTR[1].localPosition = new Vector3(0f, 0f, yLabelPos);
                labelsTR[2].localPosition = new Vector3(0f, 0f, zLabelPos);

                labelsTR[0].rotation = rotation;
                labelsTR[1].rotation = rotation;
                labelsTR[2].rotation = rotation;

                prevForward = forward;
            }

            if (fadeT < 1f)
            {
                fadeT += Time.unscaledDeltaTime * 4f;
                if (fadeT >= 1f)
                {
                    fadeT = 1f;
                }

                SetAlphaOf(fadingComponent, isFadingToZero ? 1f - fadeT : fadeT);
                if (fadeT >= 1f)
                {
                    if (!isFadingToZero)
                    {
                        SetMaterialOf(fadingComponent, gizmoNormalMaterial);
                        fadingComponent = GizmoComponent.None;
                    }
                    else
                    {
                        gizmoComponents[(int)fadingComponent].gameObject.SetActive(false);
                        gizmoComponents[(int)GetOppositeComponent(fadingComponent)].gameObject.SetActive(false);
                    }
                }
            }
        }