Exemplo n.º 1
0
        public override void OnBeginDrag()
        {
            if (m_hitRegion == HitRegion.None)
            {
                return;
            }
            var selectionCntx      = DesignView.Context.As <ISelectionContext>();
            var selection          = selectionCntx.Selection;
            var transactionContext = DesignView.Context.As <ITransactionContext>();

            NodeList.Clear();

            IEnumerable <DomNode> rootDomNodes = DomNode.GetRoots(selection.AsIEnumerable <DomNode>());

            foreach (DomNode domNode in rootDomNodes)
            {
                ITransformable node = domNode.As <ITransformable>();

                if (node == null || (node.TransformationType & TransformationTypes.Rotation) == 0)
                {
                    continue;
                }

                IVisible vn = node.As <IVisible>();
                if (!vn.Visible)
                {
                    continue;
                }

                ILockable lockable = node.As <ILockable>();
                if (lockable.IsLocked)
                {
                    continue;
                }

                NodeList.Add(node);
                IManipulatorNotify notifier = node.As <IManipulatorNotify>();
                if (notifier != null)
                {
                    notifier.OnBeginDrag();
                }
            }

            m_rotations = new Matrix4F[NodeList.Count];

            for (int k = 0; k < NodeList.Count; k++)
            {
                ITransformable node = NodeList[k];
                Matrix4F       m    = new Matrix4F(node.Transform);
                m.Translation = new Vec3F(0, 0, 0);
                m.Normalize(m);
                m_rotations[k] = m;
            }

            if (NodeList.Count > 0)
            {
                transactionContext.Begin("Rotate".Localize());
            }
        }
Exemplo n.º 2
0
        public override void OnBeginDrag()
        {
            var selection          = DesignView.Context.As <ISelectionContext>().Selection;
            var transactionContext = DesignView.Context.As <ITransactionContext>();

            NodeList.Clear();

            m_isUniformScaling = false;

            IEnumerable <DomNode> rootDomNodes = DomNode.GetRoots(selection.AsIEnumerable <DomNode>());

            foreach (DomNode node in rootDomNodes)
            {
                ITransformable transNode = node.As <ITransformable>();
                if (transNode == null || (transNode.TransformationType & TransformationTypes.Scale) == 0)
                {
                    continue;
                }

                IVisible vn = node.As <IVisible>();
                if (!vn.Visible)
                {
                    continue;
                }

                ILockable lockable = node.As <ILockable>();
                if (lockable.IsLocked)
                {
                    continue;
                }

                // force uniform scaling if any node requires it
                if ((transNode.TransformationType & TransformationTypes.UniformScale) == TransformationTypes.UniformScale)
                {
                    m_isUniformScaling = true;
                }

                NodeList.Add(transNode);

                IManipulatorNotify notifier = transNode.As <IManipulatorNotify>();
                if (notifier != null)
                {
                    notifier.OnBeginDrag();
                }
            }


            m_originalValues = new Vec3F[NodeList.Count];
            int k = 0;

            foreach (ITransformable node in NodeList)
            {
                m_originalValues[k++] = node.Scale;
            }

            if (NodeList.Count > 0)
            {
                transactionContext.Begin("Scale".Localize());
            }
        }
Exemplo n.º 3
0
        public static Vec3F CalcSnapFromOffset(ITransformable node, SnapFromMode snapFrom)
        {
            // AABB in local space.
            AABB box = node.As <IBoundable>().LocalBoundingBox;

            Vec3F offsetLocal = box.Center;

            switch (snapFrom)
            {
            case SnapFromMode.Pivot:
                offsetLocal = node.Pivot;
                break;

            case SnapFromMode.Origin:
                offsetLocal = box.Center;
                break;

            case SnapFromMode.TopCenter:
                offsetLocal.Y = box.Max.Y;
                break;

            case SnapFromMode.BottomCenter:
                offsetLocal.Y = box.Min.Y;
                break;

            case SnapFromMode.FrontCenter:
                offsetLocal.Z = box.Max.Z;
                break;

            case SnapFromMode.BackCenter:
                offsetLocal.Z = box.Min.Z;
                break;

            case SnapFromMode.LeftCenter:
                offsetLocal.X = box.Min.X;
                break;

            case SnapFromMode.RightCenter:
                offsetLocal.X = box.Max.X;
                break;

            default:
                throw new ArgumentOutOfRangeException("Invalid snap-from node");
            }

            Path <DomNode> path    = new Path <DomNode>(node.Cast <DomNode>().GetPath());
            Matrix4F       toWorld = TransformUtils.CalcPathTransform(path, path.Count - 1);

            Vec3F offset;

            toWorld.TransformVector(offsetLocal, out offset); //local-to-world
            return(offset);                                   //world
        }
Exemplo n.º 4
0
 /// <summary>
 /// Computes world transformation matrix for the given 
 /// Transformable node.</summary>        
 public static Matrix4F ComputeWorldTransform(ITransformable xform)
 {
     Matrix4F world = new Matrix4F();
     DomNode node = xform.As<DomNode>();
     foreach (DomNode n in node.Lineage)
     {
         ITransformable xformNode = n.As<ITransformable>();
         if (xformNode != null)
         {
             world.Mul(world, xformNode.Transform);
         }
     }
     return world;
 }
Exemplo n.º 5
0
        /// <summary>
        /// Computes world transformation matrix for the given
        /// Transformable node.</summary>
        public static Matrix4F ComputeWorldTransform(ITransformable xform)
        {
            Matrix4F world = new Matrix4F();
            DomNode  node  = xform.As <DomNode>();

            foreach (DomNode n in node.Lineage)
            {
                ITransformable xformNode = n.As <ITransformable>();
                if (xformNode != null)
                {
                    world.Mul(world, xformNode.Transform);
                }
            }
            return(world);
        }
Exemplo n.º 6
0
        public static Vec3F CalcSnapFromOffset(ITransformable node, SnapFromMode snapFrom)
        {
            // AABB in local space.
            AABB box = node.As<IBoundable>().LocalBoundingBox;

            Vec3F offsetLocal = box.Center;
            switch (snapFrom)
            {
                case SnapFromMode.Pivot:
                    offsetLocal = node.Pivot;
                    break;
                case SnapFromMode.Origin:
                    offsetLocal = box.Center;
                    break;
                case SnapFromMode.TopCenter:
                    offsetLocal.Y = box.Max.Y;
                    break;
                case SnapFromMode.BottomCenter:
                    offsetLocal.Y = box.Min.Y;
                    break;
                case SnapFromMode.FrontCenter:
                    offsetLocal.Z = box.Max.Z;
                    break;
                case SnapFromMode.BackCenter:
                    offsetLocal.Z = box.Min.Z;
                    break;
                case SnapFromMode.LeftCenter:
                    offsetLocal.X = box.Min.X;
                    break;
                case SnapFromMode.RightCenter:
                    offsetLocal.X = box.Max.X;
                    break;
                default:
                    throw new ArgumentOutOfRangeException("Invalid snap-from node");
            }

            Path<DomNode> path = new Path<DomNode>(node.Cast<DomNode>().GetPath());
            Matrix4F toWorld = TransformUtils.CalcPathTransform(path, path.Count - 1);

            Vec3F offset;
            toWorld.TransformVector(offsetLocal, out offset); //local-to-world
            return offset; //world
        }
        public override void OnBeginDrag()
        {
            if (m_hitRegion == HitRegion.None)
            {
                return;
            }

            m_cancelDrag = false;
            Clear(); // cached values.

            var selectionContext   = DesignView.Context.As <ISelectionContext>();
            var selection          = selectionContext.Selection;
            var transactionContext = DesignView.Context.As <ITransactionContext>();

            IEnumerable <DomNode> rootDomNodes = DomNode.GetRoots(selection.AsIEnumerable <DomNode>());

            m_duplicating = Control.ModifierKeys == m_duplicateKey;

            if (m_duplicating)
            {
                List <DomNode> originals = new List <DomNode>();
                foreach (DomNode node in rootDomNodes)
                {
                    ITransformable transformable = node.As <ITransformable>();
                    if (!CanManipulate(transformable))
                    {
                        continue;
                    }

                    originals.Add(node);
                }
                if (originals.Count > 0)
                {
                    DomNode[] copies = DomNode.Copy(originals);

                    transactionContext.Begin("Copy And Move".Localize());

                    List <object> newSelection = new List <object>();
                    // re-parent copy
                    for (int i = 0; i < copies.Length; i++)
                    {
                        DomNode copy     = copies[i];
                        DomNode original = originals[i];

                        ChildInfo chInfo = original.ChildInfo;
                        if (chInfo.IsList)
                        {
                            original.Parent.GetChildList(chInfo).Add(copy);
                        }
                        else
                        {
                            original.Parent.SetChild(chInfo, copy);
                        }

                        newSelection.Add(Util.AdaptDomPath(copy));
                        copy.InitializeExtensions();
                    }

                    selectionContext.SetRange(newSelection);
                    NodeList.AddRange(copies.AsIEnumerable <ITransformable>());
                }
            }
            else
            {
                foreach (DomNode node in rootDomNodes)
                {
                    ITransformable transformable = node.As <ITransformable>();
                    if (!CanManipulate(transformable))
                    {
                        continue;
                    }
                    NodeList.Add(transformable);
                }

                if (NodeList.Count > 0)
                {
                    transactionContext.Begin("Move".Localize());
                }
            }

            m_originalValues    = new Vec3F[NodeList.Count];
            m_originalRotations = new Vec3F[NodeList.Count];
            for (int k = 0; k < NodeList.Count; k++)
            {
                ITransformable     node     = NodeList[k];
                IManipulatorNotify notifier = node.As <IManipulatorNotify>();
                if (notifier != null)
                {
                    notifier.OnBeginDrag();
                }
                m_originalValues[k]    = node.Translation;
                m_originalRotations[k] = node.Rotation;
            }
        }
Exemplo n.º 8
0
        public override void OnBeginDrag()
        {
            if (m_hitRegion == HitRegion.None)
            {
                return;
            }

            var selection          = DesignView.Context.As <ISelectionContext>().Selection;
            var transactionContext = DesignView.Context.As <ITransactionContext>();

            NodeList.Clear();

            m_isUniformScaling = false;

            IEnumerable <DomNode> rootDomNodes = DomNode.GetRoots(selection.AsIEnumerable <DomNode>());

            foreach (DomNode node in rootDomNodes)
            {
                ITransformable transNode = node.As <ITransformable>();
                if (transNode == null || (transNode.TransformationType & TransformationTypes.Scale) == 0)
                {
                    continue;
                }

                IVisible vn = node.As <IVisible>();
                if (!vn.Visible)
                {
                    continue;
                }

                ILockable lockable = node.As <ILockable>();
                if (lockable.IsLocked)
                {
                    continue;
                }

                // force uniform scaling if any node requires it
                if ((transNode.TransformationType & TransformationTypes.UniformScale) == TransformationTypes.UniformScale)
                {
                    m_isUniformScaling = true;
                }

                NodeList.Add(transNode);

                IManipulatorNotify notifier = transNode.As <IManipulatorNotify>();
                if (notifier != null)
                {
                    notifier.OnBeginDrag();
                }
            }


            // to compute offset use bounding box in local space.
            Vec3F offset = Vec3F.ZeroVector;// 0.5f; // use bounding box in local space

            switch (m_hitRegion)
            {
            case HitRegion.XAxis:
            case HitRegion.YAxis:
            case HitRegion.ZAxis:
                offset = new Vec3F(-1, -1, -1);
                break;

            case HitRegion.NegXAxis:
            case HitRegion.NegYAxis:
            case HitRegion.NegZAxis:
                offset = new Vec3F(1, 1, 1);
                break;

            default:
                break;
            }

            m_originalScales       = new Vec3F[NodeList.Count];
            m_originalTranslations = new Vec3F[NodeList.Count];
            m_pivotOffset          = new Vec3F[NodeList.Count];
            int k = 0;

            foreach (ITransformable node in NodeList)
            {
                IBoundable boundable = node.As <IBoundable>();
                Vec3F      pivot     = Vec3F.Mul(boundable.LocalBoundingBox.Radius, offset);
                m_pivotOffset[k] = pivot;

                m_originalScales[k] = node.Scale;

                Matrix4F mtrx = TransformUtils.CalcTransform(
                    Vec3F.ZeroVector,
                    node.Rotation,
                    node.Scale,
                    pivot
                    );

                m_originalTranslations[k] = node.Translation - mtrx.Translation;
                k++;
            }

            if (NodeList.Count > 0)
            {
                transactionContext.Begin("Extend".Localize());
            }
        }