Ejemplo n.º 1
0
        void rootEntities_CollectionChanged(object sender, TrackingCollectionChangedEventArgs e)
        {
            switch (e.Action)
            {
            case NotifyCollectionChangedAction.Add:
                EntitySystem.Add((Entity)e.Item);
                break;

            case NotifyCollectionChangedAction.Remove:
                EntitySystem.Remove((Entity)e.Item);
                break;

            default:
                throw new NotSupportedException();
            }
        }
Ejemplo n.º 2
0
        private void RefreshGizmos(GizmoAction currentGizmoAction)
        {
            var renderingSetup = RenderingSetup.Singleton;

            // Delay gizmo change until current action is finished
            if (currentActiveGizmoActionMode != ActiveGizmoActionMode &&
                currentGizmoAction == GizmoAction.None)
            {
                if (currentActiveGizmoEntity != null)
                {
                    editorEntitySystem.Entities.Remove(currentActiveGizmoEntity);
                }

                if (ActiveGizmoActionMode == GizmoAction.Translation)
                {
                    currentActiveGizmoEntity = translationGizmo;
                }
                else if (ActiveGizmoActionMode == GizmoAction.Rotation)
                {
                    currentActiveGizmoEntity = rotationGizmo;
                }
                else
                {
                    currentActiveGizmoEntity = null;
                }
                currentActiveGizmoActionMode = ActiveGizmoActionMode;
            }

            if (currentActiveGizmoEntity == null)
            {
                return;
            }

            TransformationComponent[] selectedTransformations;

            if (selectedEntities != null && (selectedTransformations = selectedEntities.Select(x => x.Entity.Transformation).Where(x => x != null && x.Value is TransformationTRS).ToArray()).Length > 0)
            {
                if (!editorEntitySystem.Entities.Contains(currentActiveGizmoEntity))
                {
                    editorEntitySystem.Add(currentActiveGizmoEntity);
                }

                // TODO: Only act on "current" gizmo?
                var gizmoTransformation = (TransformationTRS)currentActiveGizmoEntity.Transformation.Value;
                var translationSum      = Vector3.Zero;

                // Make average of selected objects origin to position gizmo
                foreach (var selectedTransformation in selectedTransformations)
                {
                    // Compensate scaling
                    // TODO: Negative/zero scaling?
                    var parentMatrix = selectedTransformation.WorldMatrix;
                    translationSum += parentMatrix.TranslationVector;
                }

                gizmoTransformation.Translation = translationSum / selectedTransformations.Length;

                // Make gizmo size constant (screen-space) -- only if not currently being used
                // TODO: Currently FOV-dependent
                if (currentGizmoAction == GizmoAction.None)
                {
                    var view      = renderingSetup.MainPlugin.ViewParameters.Get(TransformationKeys.View);
                    var worldView = view;
                    var position  = Vector3.TransformCoordinate(gizmoTransformation.Translation, worldView);
                    gizmoTransformation.Scaling = new Vector3(position.Z * 0.01f);
                }
            }
            else
            {
                if (editorEntitySystem.Entities.Contains(currentActiveGizmoEntity))
                {
                    editorEntitySystem.Entities.Remove(currentActiveGizmoEntity);
                }
            }
        }