コード例 #1
0
ファイル: SelectTool.cs プロジェクト: valera6285/sledge
        /// <summary>
        /// Runs the transform on all the currently selected objects
        /// </summary>
        /// <param name="transformationName">The name of the transformation</param>
        /// <param name="transform">The transformation to apply</param>
        /// <param name="clone">True to create a clone before transforming the original.</param>
        private void ExecuteTransform(string transformationName, IUnitTransformation transform, bool clone)
        {
            if (clone)
            {
                transformationName += "-clone";
            }
            var objects = Document.Selection.GetSelectedParents().ToList();
            var name    = String.Format("{0} {1} object{2}", transformationName, objects.Count, (objects.Count == 1 ? "" : "s"));

            var action = new CreateEditDelete();

            if (clone)
            {
                // Copy the selection before transforming
                var copies = ClipboardManager.CloneFlatHeirarchy(Document, Document.Selection.GetSelectedObjects()).ToList();
                action.Create(Document.Map.WorldSpawn.ID, copies);
            }

            // Transform the selection
            var keepVisgroups = Sledge.Settings.Select.KeepVisgroupsWhenCloning;

            action.Edit(objects, new TransformEditOperation(transform, Document.Map.GetTransformFlags())
            {
                ClearVisgroups = !keepVisgroups
            });

            // Execute the action
            Document.PerformAction(name, action);
        }
コード例 #2
0
 public virtual void Transform(IUnitTransformation transform, TransformFlags flags)
 {
     foreach (var mo in GetChildren())
     {
         mo.Transform(transform, flags);
     }
     UpdateBoundingBox();
 }
コード例 #3
0
        public virtual void Transform(IUnitTransformation transform, TransformFlags flags)
        {
            foreach (var t in Vertices)
            {
                t.Location = transform.Transform(t.Location);
            }
            Plane  = new Plane(Vertices[0].Location, Vertices[1].Location, Vertices[2].Location);
            Colour = Colour;
            if (flags.HasFlag(TransformFlags.TextureScalingLock) && Texture.Texture != null)
            {
                // Make a best-effort guess of retaining scaling. All bets are off during skew operations.
                // Transform the current texture axes
                var origin = transform.Transform(Coordinate.Zero);
                var ua     = transform.Transform(Texture.UAxis) - origin;
                var va     = transform.Transform(Texture.VAxis) - origin;
                // Multiply the scales by the magnitudes (they were normals before the transform operation)
                Texture.XScale *= ua.VectorMagnitude();
                Texture.YScale *= va.VectorMagnitude();
            }
            {
                // Transform the texture axes and move them back to the origin
                var origin = transform.Transform(Coordinate.Zero);
                var ua     = transform.Transform(Texture.UAxis) - origin;
                var va     = transform.Transform(Texture.VAxis) - origin;

                // Only do the transform if the axes end up being not perpendicular
                // Otherwise just make a best-effort guess, same as the scaling lock
                if (Math.Abs(ua.Dot(va)) < 0.0001m && DMath.Abs(Plane.Normal.Dot(ua.Cross(va).Normalise())) > 0.0001m)
                {
                    Texture.UAxis = ua;
                    Texture.VAxis = va;
                }
                else
                {
                    AlignTextureToFace();
                }

                if (flags.HasFlag(TransformFlags.TextureLock) && Texture.Texture != null)
                {
                    // Check some original reference points to see how the transform mutates them
                    var scaled   = (transform.Transform(Coordinate.One) - transform.Transform(Coordinate.Zero)).VectorMagnitude();
                    var original = (Coordinate.One - Coordinate.Zero).VectorMagnitude();

                    // Ignore texture lock when the transformation contains a scale
                    if (DMath.Abs(scaled - original) <= 0.01m)
                    {
                        // Calculate the new shift values based on the UV values of the vertices
                        var vtx = Vertices[0];
                        Texture.XShift = Texture.Texture.Width * vtx.TextureU - (vtx.Location.Dot(Texture.UAxis)) / Texture.XScale;
                        Texture.YShift = Texture.Texture.Height * vtx.TextureV - (vtx.Location.Dot(Texture.VAxis)) / Texture.YScale;
                    }
                }
            }
            CalculateTextureCoordinates(true);
            UpdateBoundingBox();
        }
コード例 #4
0
 public override void Transform(IUnitTransformation transform, TransformFlags flags)
 {
     foreach (var p in Points)
     {
         p.InitialPosition          = transform.Transform(p.InitialPosition);
         p.CurrentPosition.Location = transform.Transform(p.CurrentPosition.Location);
     }
     CalculateNormals();
     base.Transform(transform, flags);
 }
コード例 #5
0
        public void Transform()
        {
            if (_document.Selection.IsEmpty() || _document.Selection.InFaceSelection)
            {
                return;
            }
            var box = _document.Selection.GetSelectionBoundingBox();

            using (var td = new TransformDialog(box))
            {
                if (td.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                var value = td.TransformValue;
                IUnitTransformation transform = null;
                switch (td.TransformType)
                {
                case TransformType.Rotate:
                    var mov = Matrix.Translation(-box.Center);                                 // Move to zero
                    var rot = Matrix.Rotation(Quaternion.EulerAngles(value * DMath.PI / 180)); // Do rotation
                    var fin = Matrix.Translation(box.Center);                                  // Move to final origin
                    transform = new UnitMatrixMult(fin * rot * mov);
                    break;

                case TransformType.Translate:
                    transform = new UnitTranslate(value);
                    break;

                case TransformType.Scale:
                    transform = new UnitScale(value, box.Center);
                    break;
                }

                if (transform == null)
                {
                    return;
                }

                var selected = _document.Selection.GetSelectedParents();
                _document.PerformAction("Transform selection", new Edit(selected, new TransformEditOperation(transform, _document.Map.GetTransformFlags())));
            }
        }
コード例 #6
0
ファイル: SelectTool.cs プロジェクト: NCC-Lykos/Chisel
        /// <summary>
        /// Runs the transform on all the currently selected objects
        /// </summary>
        /// <param name="transformationName">The name of the transformation</param>
        /// <param name="transform">The transformation to apply</param>
        /// <param name="clone">True to create a clone before transforming the original.</param>
        private void ExecuteTransform(string transformationName, IUnitTransformation transform, bool clone)
        {
            if (clone)
            {
                transformationName += "-clone";
            }
            var objects = Document.Selection.GetSelectedParents().ToList();
            var name    = String.Format("{0} {1} object{2}", transformationName, objects.Count, (objects.Count == 1 ? "" : "s"));

            var cad    = new CreateEditDelete();
            var action = new ActionCollection(cad);

            if (clone)
            {
                // Copy the selection, transform it, and reselect
                var copies = ClipboardManager.CloneFlatHeirarchy(Document, Document.Selection.GetSelectedObjects()).ToList();
                foreach (var mo in copies)
                {
                    mo.Transform(transform, Document.Map.GetTransformFlags());
                    if (Chisel.Settings.Select.KeepVisgroupsWhenCloning)
                    {
                        continue;
                    }
                    foreach (var o in mo.FindAll())
                    {
                        o.Visgroups.Clear();
                    }
                }
                cad.Create(Document.Map.WorldSpawn.ID, copies);
                var sel = new ChangeSelection(copies.SelectMany(x => x.FindAll()), Document.Selection.GetSelectedObjects());
                action.Add(sel);
            }
            else //NOTE(SVK): This is Move????
            {
                // Transform the selection
                TransformFlags Flags = Document.Map.GetTransformFlags();

                cad.Edit(objects, new TransformEditOperation(transform, Flags));
            }

            // Execute the action
            Document.PerformAction(name, action);
        }
コード例 #7
0
ファイル: Face.cs プロジェクト: silky/sledge
        public virtual void Transform(IUnitTransformation transform, TransformFlags flags)
        {
            foreach (var t in Vertices)
            {
                t.Location = transform.Transform(t.Location);
            }
            Plane = new Plane(Vertices[0].Location, Vertices[1].Location, Vertices[2].Location);
            Colour = Colour;
            if (flags.HasFlag(TransformFlags.TextureScalingLock) && Texture.Texture != null)
            {
                // Make a best-effort guess of retaining scaling. All bets are off during skew operations.
                // Transform the current texture axes
                var origin = transform.Transform(Coordinate.Zero);
                var ua = transform.Transform(Texture.UAxis) - origin;
                var va = transform.Transform(Texture.VAxis) - origin;
                // Multiply the scales by the magnitudes (they were normals before the transform operation)
                Texture.XScale *= ua.VectorMagnitude();
                Texture.YScale *= va.VectorMagnitude();
            }
            {
                // Transform the texture axes and move them back to the origin
                var origin = transform.Transform(Coordinate.Zero);
                var ua = transform.Transform(Texture.UAxis) - origin;
                var va = transform.Transform(Texture.VAxis) - origin;

                // Only do the transform if the axes end up being not perpendicular
                // Otherwise just make a best-effort guess, same as the scaling lock
                if (Math.Abs(ua.Dot(va)) < 0.0001m && DMath.Abs(Plane.Normal.Dot(ua.Cross(va).Normalise())) > 0.0001m)
                {
                    Texture.UAxis = ua;
                    Texture.VAxis = va;
                }
                else
                {
                    AlignTextureToFace();
                }

                if (flags.HasFlag(TransformFlags.TextureLock) && Texture.Texture != null)
                {
                    // Check some original reference points to see how the transform mutates them
                    var scaled = (transform.Transform(Coordinate.One) - transform.Transform(Coordinate.Zero)).VectorMagnitude();
                    var original = (Coordinate.One - Coordinate.Zero).VectorMagnitude();

                    // Ignore texture lock when the transformation contains a scale
                    if (DMath.Abs(scaled - original) <= 0.01m)
                    {
                        // Calculate the new shift values based on the UV values of the vertices
                        var vtx = Vertices[0];
                        Texture.XShift = Texture.Texture.Width * vtx.TextureU - (vtx.Location.Dot(Texture.UAxis)) / Texture.XScale;
                        Texture.YShift = Texture.Texture.Height * vtx.TextureV - (vtx.Location.Dot(Texture.VAxis)) / Texture.YScale;
                    }
                }
            }
            CalculateTextureCoordinates(true);
            UpdateBoundingBox();
        }
コード例 #8
0
 public BoxF Transform(IUnitTransformation transform)
 {
     return(new BoxF(GetBoxPoints().Select(transform.Transform)));
 }
コード例 #9
0
 public Line Transform(IUnitTransformation transform)
 {
     return(new Line(transform.Transform(Start), transform.Transform(End)));
 }
コード例 #10
0
ファイル: Entity.cs プロジェクト: KonstantinUb/sledge
 public override void Transform(IUnitTransformation transform, TransformFlags flags)
 {
     Origin = transform.Transform(Origin);
     base.Transform(transform, flags);
 }
コード例 #11
0
ファイル: SelectTool.cs プロジェクト: silky/sledge
        /// <summary>
        /// Runs the transform on all the currently selected objects
        /// </summary>
        /// <param name="transformationName">The name of the transformation</param>
        /// <param name="transform">The transformation to apply</param>
        /// <param name="clone">True to create a clone before transforming the original.</param>
        private void ExecuteTransform(string transformationName, IUnitTransformation transform, bool clone)
        {
            if (clone) transformationName += "-clone";
            var objects = Document.Selection.GetSelectedParents().ToList();
            var name = String.Format("{0} {1} object{2}", transformationName, objects.Count, (objects.Count == 1 ? "" : "s"));

            var cad = new CreateEditDelete();
            var action = new ActionCollection(cad);

            if (clone)
            {
                // Copy the selection, transform it, and reselect
                var copies = ClipboardManager.CloneFlatHeirarchy(Document, Document.Selection.GetSelectedObjects()).ToList();
                foreach (var mo in copies)
                {
                    mo.Transform(transform, Document.Map.GetTransformFlags());
                    if (Sledge.Settings.Select.KeepVisgroupsWhenCloning) continue;
                    foreach (var o in mo.FindAll()) o.Visgroups.Clear();
                }
                cad.Create(Document.Map.WorldSpawn.ID, copies);
                var sel = new ChangeSelection(copies.SelectMany(x => x.FindAll()), Document.Selection.GetSelectedObjects());
                action.Add(sel);
            }
            else
            {
                // Transform the selection
                cad.Edit(objects, new TransformEditOperation(transform, Document.Map.GetTransformFlags()));
            }

            // Execute the action
            Document.PerformAction(name, action);
        }
コード例 #12
0
ファイル: MapObject.cs プロジェクト: KonstantinUb/sledge
 public virtual void Transform(IUnitTransformation transform, TransformFlags flags)
 {
     foreach (var mo in GetChildren())
     {
         mo.Transform(transform, flags);
     }
     UpdateBoundingBox();
 }
コード例 #13
0
ファイル: Face.cs プロジェクト: jpiolho/sledge
 public virtual void Transform(IUnitTransformation transform, TransformFlags flags)
 {
     foreach (var t in Vertices)
     {
         t.Location = transform.Transform(t.Location);
     }
     Plane = new Plane(Vertices[0].Location, Vertices[1].Location, Vertices[2].Location);
     Colour = Colour;
     if (flags.HasFlag(TransformFlags.TextureScalingLock) && Texture.Texture != null)
     {
         // Make a best-effort guess of retaining scaling. All bets are off during skew operations.
         // Transform the current texture axes
         var origin = transform.Transform(Coordinate.Zero);
         var ua = transform.Transform(Texture.UAxis) - origin;
         var va = transform.Transform(Texture.VAxis) - origin;
         // Multiply the scales by the magnitudes (they were normals before the transform operation)
         Texture.XScale *= ua.VectorMagnitude();
         Texture.YScale *= va.VectorMagnitude();
     }
     if (flags.HasFlag(TransformFlags.TextureLock) && Texture.Texture != null)
     {
         // Transform the texture axes and move them back to the origin
         var origin = transform.Transform(Coordinate.Zero);
         var ua = transform.Transform(Texture.UAxis) - origin;
         var va = transform.Transform(Texture.VAxis) - origin;
         // Only do the transform if the axes end up being not perpendicular
         // Otherwise just make a best-effort guess, same as the scaling lock
         if (Math.Abs(ua.Dot(va)) < 0.0001m)
         {
             Texture.UAxis = ua;
             Texture.VAxis = va;
         }
         // Calculate the new shift values based on the UV values of the vertices
         var vtx = Vertices[0];
         Texture.XShift = Texture.Texture.Width * vtx.TextureU - (vtx.Location.Dot(Texture.UAxis)) / Texture.XScale;
         Texture.YShift = Texture.Texture.Height * vtx.TextureV - (vtx.Location.Dot(Texture.VAxis)) / Texture.YScale;
     }
     else
     {
         // During rotate/skew operations we'll mess up the texture axes, just reset them.
         AlignTextureToFace();
     }
     CalculateTextureCoordinates();
     UpdateBoundingBox();
 }
コード例 #14
0
ファイル: Displacement.cs プロジェクト: jpiolho/sledge
 public override void Transform(IUnitTransformation transform, TransformFlags flags)
 {
     foreach (var p in Points)
     {
         p.InitialPosition = transform.Transform(p.InitialPosition);
         p.CurrentPosition.Location = transform.Transform(p.CurrentPosition.Location);
     }
     CalculateNormals();
     base.Transform(transform, flags);
 }
コード例 #15
0
 public TransformEditOperation(IUnitTransformation transformation, TransformFlags transformFlags)
 {
     _transformation = transformation;
     _transformFlags = transformFlags;
 }
コード例 #16
0
ファイル: Face.cs プロジェクト: NCC-Lykos/Chisel
        public virtual void Transform(IUnitTransformation transform, TransformFlags flags)
        {
            foreach (var t in Vertices)
            {
                t.Location = transform.Transform(t.Location);
            }
            Plane  = new Plane(Vertices[0].Location, Vertices[1].Location, Vertices[2].Location);
            Colour = Colour;

            var origin = transform.Transform(Coordinate.Zero);
            var ua     = transform.Transform(Texture.UAxis) - origin;
            var va     = transform.Transform(Texture.VAxis) - origin;

            if (flags.HasFlag(TransformFlags.TextureScalingLock) && Texture.Texture != null)
            {
                // Make a best-effort guess of retaining scaling. All bets are off during skew operations.
                // Transform the current texture axes
                // Multiply the scales by the magnitudes (they were normals before the transform operation)
                Texture.XScale *= ua.VectorMagnitude();
                Texture.YScale *= va.VectorMagnitude();
            }
            {
                //NOTE(SVK):Only edit solids not entities. //do entities have faces??
                if (this.Parent.Parent.GetType().Name == "World" && this.Parent.GetType().Name == "Solid")
                {
                    if (Texture.Flags.HasFlag(FaceFlags.TextureLocked))
                    {
                        Coordinate     Center = this.Parent.Parent.SelCenter;
                        Matrix         Xfrm   = transform.GetMatrix();
                        TransformFlags f      = (TransformFlags)0;
                        if (Xfrm != Matrix.Zero)
                        {
                            f = GetTransformFlags(Xfrm);
                        }
                        else
                        {
                            f = flags;
                        }


                        if (f.HasFlag(TransformFlags.Translate))
                        {
                            Texture.PositionRF = transform.Transform(Texture.PositionRF);
                        }

                        if (f.HasFlag(TransformFlags.Rotation))
                        {
                            Xfrm = ToRF(Xfrm);

                            Texture.TransformAngleRF = Xfrm * Texture.TransformAngleRF;
                            Texture.PositionRF       = Texture.PositionRF - Center;
                            Texture.PositionRF       = RotateRF(Xfrm, ToRF(Texture.PositionRF));
                            Texture.PositionRF       = ToChisel(Texture.PositionRF);
                            Texture.PositionRF       = Texture.PositionRF + Center;
                        }
                    }
                }
                else //entities etc...
                {
                    // Transform the texture axes and move them back to the origin
                    // Only do the transform if the axes end up being not perpendicular
                    // Otherwise just make a best-effort guess, same as the scaling lock

                    if (Math.Abs(ua.Dot(va)) < 0.0001m && DMath.Abs(Plane.Normal.Dot(ua.Cross(va).Normalise())) > 0.0001m)
                    {
                        Texture.UAxis = ua;
                        Texture.VAxis = va;
                    }
                    else
                    {
                        AlignTextureToWorld();
                    }
                    if (flags.HasFlag(TransformFlags.TextureLock) && Texture.Texture != null)
                    {
                        // Check some original reference points to see how the transform mutates them
                        var scaled   = (transform.Transform(Coordinate.One) - transform.Transform(Coordinate.Zero)).VectorMagnitude();
                        var original = (Coordinate.One - Coordinate.Zero).VectorMagnitude();
                        // Ignore texture lock when the transformation contains a scale
                        if (DMath.Abs(scaled - original) <= 0.01m)
                        {
                            // Calculate the new shift values based on the UV values of the vertices
                            var vtx = Vertices[0];
                            Texture.XShift = Texture.Texture.Width * vtx.TextureU - (vtx.Location.Dot(Texture.UAxis)) / Texture.XScale;
                            Texture.YShift = Texture.Texture.Height * vtx.TextureV - (vtx.Location.Dot(Texture.VAxis)) / Texture.YScale;
                        }
                    }
                }
            }

            AlignTexture();
            UpdateBoundingBox();
        }
コード例 #17
0
ファイル: Box.cs プロジェクト: silky/sledge
 public Box Transform(IUnitTransformation transform)
 {
     return new Box(GetBoxPoints().Select(transform.Transform));
 }
コード例 #18
0
ファイル: Line.cs プロジェクト: silky/sledge
 public Line Transform(IUnitTransformation transform)
 {
     return new Line(transform.Transform(Start), transform.Transform(End));
 }
コード例 #19
0
ファイル: Entity.cs プロジェクト: Bananaman043/cbre
 public override void Transform(IUnitTransformation transform, TransformFlags flags)
 {
     Origin = transform.Transform(Origin);
     base.Transform(transform, flags);
 }
コード例 #20
0
ファイル: SelectTool.cs プロジェクト: jpiolho/sledge
        /// <summary>
        /// Runs the transform on all the currently selected objects
        /// </summary>
        /// <param name="transformationName">The name of the transformation</param>
        /// <param name="transform">The transformation to apply</param>
        /// <param name="clone">True to create a clone before transforming the original.</param>
        private void ExecuteTransform(string transformationName, IUnitTransformation transform, bool clone)
        {
            var action = new ActionCollection();

            if (clone) transformationName += "-clone";
            var objects = Document.Selection.GetSelectedParents().ToList();
            var name = String.Format("{0} {1} object{2}", transformationName, objects.Count, (objects.Count == 1 ? "" : "s"));

            if (clone)
            {
                // Copy the selection before transforming
                var copies = ClipboardManager.CloneFlatHeirarchy(Document, Document.Selection.GetSelectedObjects()).ToList();
                action.Add(new Create(copies));
            }

            // Transform the selection
            var keepVisgroups = Sledge.Settings.Select.KeepVisgroupsWhenCloning;
            action.Add(new Edit(objects, (d, x) =>
                                             {
                                                 x.Transform(transform, d.Map.GetTransformFlags());
                                                 if (!keepVisgroups)
                                                 {
                                                     foreach (var o in x.FindAll())
                                                     {
                                                         o.Visgroups.Clear();
                                                     }
                                                 }
                                             }));

            // Execute the action
            Document.PerformAction(name, action);
        }
コード例 #21
0
ファイル: MapObject.cs プロジェクト: ChristopherHaws/sledge
 public virtual void Transform(IUnitTransformation transform, TransformFlags flags)
 {
     Children.ForEach(c => c.Transform(transform, flags));
     UpdateBoundingBox();
 }
コード例 #22
0
ファイル: SelectTool.cs プロジェクト: 074769/sledge
        /// <summary>
        /// Runs the transform on all the currently selected objects
        /// </summary>
        /// <param name="transformationName">The name of the transformation</param>
        /// <param name="transform">The transformation to apply</param>
        /// <param name="clone">True to create a clone before transforming the original.</param>
        private void ExecuteTransform(string transformationName, IUnitTransformation transform, bool clone)
        {
            if (clone) transformationName += "-clone";
            var objects = Document.Selection.GetSelectedParents().ToList();
            var name = String.Format("{0} {1} object{2}", transformationName, objects.Count, (objects.Count == 1 ? "" : "s"));

            var action = new CreateEditDelete();

            if (clone)
            {
                // Copy the selection before transforming
                var copies = ClipboardManager.CloneFlatHeirarchy(Document, Document.Selection.GetSelectedObjects()).ToList();
                action.Create(copies);
            }

            // Transform the selection
            var keepVisgroups = Sledge.Settings.Select.KeepVisgroupsWhenCloning;
            action.Edit(objects, new TransformEditOperation(transform, Document.Map.GetTransformFlags()) { ClearVisgroups = !keepVisgroups });

            // Execute the action
            Document.PerformAction(name, action);
        }
コード例 #23
0
ファイル: Polygon.cs プロジェクト: valera6285/sledge
 /// <summary>
 /// Transforms all the points in the polygon.
 /// </summary>
 /// <param name="transform">The transformation to perform</param>
 public void Transform(IUnitTransformation transform)
 {
     Vertices = Vertices.Select(transform.Transform).ToList();
     Plane    = new Plane(Vertices[0], Vertices[1], Vertices[2]);
 }
コード例 #24
0
ファイル: Polygon.cs プロジェクト: jpiolho/sledge
 /// <summary>
 /// Transforms all the points in the polygon.
 /// </summary>
 /// <param name="transform">The transformation to perform</param>
 public void Transform(IUnitTransformation transform)
 {
     Vertices = Vertices.Select(transform.Transform).ToList();
     Plane = new Plane(Vertices[0], Vertices[1], Vertices[2]);
 }
コード例 #25
0
 public TransformEditOperation(IUnitTransformation transformation, TransformFlags transformFlags)
 {
     _transformation = transformation;
     _transformFlags = transformFlags;
 }