public override void UpdateBackground(SynchronizationContext context)
        {
            if (snekStage == null)
            {
                return;
            }

            var tube           = CreateTube(snekStage.CurrentPosition, out var endPoint);
            var deflectionTube = CreateTube(snekStage.CurrentPosition + snekStage.TensionInput, out _, true);

            var lb = new LineBuilder();

            lb.AddLine(Vector3.Zero, new Vector3(0, 0, endPoint.Z));
            lb.AddLine(new Vector3(0, 0, endPoint.Z), new Vector3(0, endPoint.Y, endPoint.Z));
            lb.AddLine(new Vector3(0, endPoint.Y, endPoint.Z), new Vector3(endPoint.X, endPoint.Y, endPoint.Z));
            var lineGeom = lb.ToLineGeometry3D();

            lineGeom.Colors = new Color4Collection(new [] {
                Colors.Blue.ToColor4(),
                Colors.Blue.ToColor4(),
                Colors.Green.ToColor4(),
                Colors.Green.ToColor4(),
                Colors.Red.ToColor4(),
                Colors.Red.ToColor4(),
            });

            context.Send(_ => {
                _model.Geometry           = tube;
                _deflectionModel.Geometry = deflectionTube;
                _refLines.Geometry        = lineGeom;
            }, null);
        }
Example #2
0
        public void AddDisplayLines(ref LineBuilder _b)
        {
            if (_b == null)
            {
                return;
            }

            this.Update();

            int nrP = this.polygon.Count;

            for (int i = 0; i < nrP; i++)
            {
                _b.AddLine(this.polygon[i].ToVector3(), this.polygon[(i + 1) % nrP].ToVector3());
            }
            if (this.holes != null)
            {
                foreach (List <Point3D> hole in this.holes)
                {
                    int nrPH = hole.Count;
                    for (int j = 0; j < nrPH; j++)
                    {
                        _b.AddLine(hole[j].ToVector3(), hole[(j + 1) % nrPH].ToVector3());
                    }
                }
            }
        }
        private void CreateArrows(float gridMaxX, float gridMinX, float gridMaxY, float gridMinY, float gridMaxZ, float gridMinZ)
        {
            var offset = 20;
            var width  = 10;

            Vector3 p0 = new Vector3(gridMinX, gridMaxY, gridMinZ);

            //y
            Vector3 px1 = new Vector3(gridMinX, gridMinY, gridMinZ);
            Vector3 px2 = new Vector3(gridMinX + width, gridMinY + offset, gridMinZ);
            Vector3 px3 = new Vector3(gridMinX - width, gridMinY + offset, gridMinZ);

            //x
            Vector3 py1 = new Vector3(gridMaxX, gridMaxY, gridMinZ);
            Vector3 py2 = new Vector3(gridMaxX - offset, gridMaxY + width, gridMinZ);
            Vector3 py3 = new Vector3(gridMaxX - offset, gridMaxY - width, gridMinZ);

            //z
            Vector3 pz1 = new Vector3(gridMinX, gridMaxY, gridMaxZ);
            Vector3 pz2 = new Vector3(gridMinX + width, gridMaxY, gridMaxZ - offset);
            Vector3 pz3 = new Vector3(gridMinX - width, gridMaxY, gridMaxZ - offset);

            arrows.AddLine(p0, px1);
            arrows.AddLine(px1, px2);
            arrows.AddLine(px1, px3);

            arrows.AddLine(p0, py1);
            arrows.AddLine(py1, py2);
            arrows.AddLine(py1, py3);

            arrows.AddLine(p0, pz1);
            arrows.AddLine(pz1, pz2);
            arrows.AddLine(pz1, pz3);
        }
        public static LineGeometry3D GetIntersectionMarker(Vector3 _point, float _size)
        {
            Vector3 topL    = _point - Vector3.UnitX * _size * 0.5f + Vector3.UnitZ * _size * 0.5f;
            Vector3 topR    = _point + Vector3.UnitX * _size * 0.5f + Vector3.UnitZ * _size * 0.5f;
            Vector3 bottomL = _point - Vector3.UnitX * _size * 0.5f - Vector3.UnitZ * _size * 0.5f;
            Vector3 bottomR = _point + Vector3.UnitX * _size * 0.5f - Vector3.UnitZ * _size * 0.5f;

            LineBuilder b = new LineBuilder();

            b.AddLine(bottomL, topR);
            b.AddLine(bottomR, topL);

            return(b.ToLineGeometry3D());
        }
Example #5
0
        public static void CreateAxes(LineBuilder arrows, float gridMaxX, float gridMinX, float gridMaxY, float gridMinY, float gridMaxZ, float gridMinZ)
        {
            Vector3 p0 = new Vector3(0, 0, 0);
            //x
            Vector3 px1 = new Vector3(gridMaxX - gridMinX, 0, 0);
            //y
            Vector3 py1 = new Vector3(0, gridMaxY - gridMinY, 0);
            //z
            var     z   = (gridMaxX - gridMinX) > (gridMaxY - gridMinY) ? (gridMaxX - gridMinX) : (gridMaxY - gridMinY);
            Vector3 pz1 = new Vector3(0, 0, Math.Abs(z / 5));

            arrows.AddLine(p0, px1);
            arrows.AddLine(p0, py1);
            arrows.AddLine(p0, pz1);
        }
Example #6
0
 public static void CreateGrid(LineBuilder gridLines, double gridMaxX, double gridMinX, double gridMaxY, double gridMinY, double gridMinZ)
 {
     for (double i = 1; i < (int)(gridMaxY - gridMinY); i += 50)  // creating grid
     {
         Vector3 p1 = new Vector3(0, (float)i, 0);
         Vector3 p2 = new Vector3((float)(gridMaxX - gridMinX), (float)i, 0);
         gridLines.AddLine(p1, p2);
     }
     for (double i = 1; i < (int)(gridMaxX - gridMinX); i += 50)  // creating grid
     {
         Vector3 p1 = new Vector3((float)i, 0, 0);
         Vector3 p2 = new Vector3((float)i, (float)(gridMaxY - gridMinY), 0);
         gridLines.AddLine(p1, p2);
     }
 }
        public static LineGeometry3D GetMidPointMarker(Vector3 _point, float _size)
        {
            Vector3 top     = _point + Vector3.UnitZ * _size * 0.5f;
            Vector3 bottomL = _point - Vector3.UnitX * _size * 0.5f * (float)Math.Cos(Math.PI / 6)
                              - Vector3.UnitZ * _size * 0.5f * (float)Math.Sin(Math.PI / 6);
            Vector3 bottomR = _point + Vector3.UnitX * _size * 0.5f * (float)Math.Cos(Math.PI / 6)
                              - Vector3.UnitZ * _size * 0.5f * (float)Math.Sin(Math.PI / 6);

            LineBuilder b = new LineBuilder();

            b.AddLine(bottomL, bottomR);
            b.AddLine(bottomR, top);
            b.AddLine(top, bottomL);

            return(b.ToLineGeometry3D());
        }
Example #8
0
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            if ((values != null) && (values.Count() == 2) && (values[0] is MDB.Point p1) && (values[1] is MDB.Point p2))
            {
                var builder = new LineBuilder();
                var v1      = new SharpDX.Vector3((float)p1.X, (float)p1.Y, (float)p1.Z);
                var v2      = new SharpDX.Vector3((float)p2.X, (float)p2.Y, (float)p2.Z);
                var d       = v2 - v1;
                var n       = d.Normalized();
                var len     = d.Length();

                if ((parameter != null) && (len <= 10.0))
                {
                    v2 += n * 6.0f;
                    v1 -= n * 6.0f;
                }

                builder.AddLine(v1, v2);

                return(builder.ToLineGeometry3D());
            }
            else
            {
                return(null);
            }
        }
        public MainViewModel()
        {
            EffectsManager = new DefaultEffectsManager();
            Camera         = new PerspectiveCamera {
            };

            // 座標面の作成
            GridGeometry3D = LineBuilder.GenerateGrid(10);

            LineBuilder lineBuilderX = new LineBuilder();

            lineBuilderX.AddLine(new Vector3(0, 0, 0), new Vector3(1, 0, 0));
            AxisX = lineBuilderX.ToLineGeometry3D();

            LineBuilder lineBuilderY = new LineBuilder();

            lineBuilderY.AddLine(new Vector3(0, 0, 0), new Vector3(0, 1, 0));
            AxisY = lineBuilderY.ToLineGeometry3D();

            LineBuilder lineBuilderZ = new LineBuilder();

            lineBuilderZ.AddLine(new Vector3(0, 0, 0), new Vector3(0, 0, 1));
            AxisZ = lineBuilderZ.ToLineGeometry3D();

            // 座標面のトランスフォーム作成
            GridGeometry3DTransform = new System.Windows.Media.Media3D.TranslateTransform3D(-5, 0, -5);
        }
        public override LineGeometry3D Build(double _startMarkerSize = 0.1)
        {
            if (this.contour == null)
            {
                if (this.quad == null)
                {
                    this.contour = null;
                    return(null);
                }

                int n = this.quad.Count;
                if (n < 3)
                {
                    this.contour = null;
                    return(null);
                }

                LineBuilder b = new LineBuilder();
                for (int i = 0; i < n; i++)
                {
                    b.AddLine(this.quad[i], this.quad[(i + 1) % n]);
                }
                this.contour = b.ToLineGeometry3D();
            }
            return(this.contour);
        }
Example #11
0
        private void RenderPath()
        {
            LineBuilder lb      = new LineBuilder();
            var         startv3 = StartBall.Transform.ToVector3();
            var         endv3   = EndBall.Transform.ToVector3();

            var start = new DHVertex()
            {
                x = startv3.X, y = startv3.Y, z = startv3.Z
            };
            var end = new DHVertex()
            {
                x = endv3.X, y = endv3.Y, z = endv3.Z
            };
            DHPath path = new DHPath();

            if (dh.FindPath(true, start, end, path))
            {
                if (path.Length > 1)
                {
                    var vs = path.GetPathData();
                    for (int i = 0; i < path.Length - 1; i++)
                    {
                        Vector3 v  = new Vector3((float)vs[i].x, (float)vs[i].y, (float)vs[i].z);
                        Vector3 nv = new Vector3((float)vs[i + 1].x, (float)vs[i + 1].y, (float)vs[i + 1].z);
                        lb.AddLine(new Vector3(v.X, v.Y + 1, v.Z), new Vector3(nv.X, nv.Y + 1, nv.Z));
                    }
                }
                WayPath.Geometry = lb.ToLineGeometry3D();
            }
            //playersGroup.Children.Clear();
            //playersGroup.Children.Add(WayPath);
        }
        /// <summary>
        /// The on children changed.
        /// </summary>
        protected virtual void OnChildrenChanged()
        {
            this.translateXL.Length = 0.5;
            this.translateYL.Length = 0.5;
            this.translateZL.Length = 0.5;
            this.translateXR.Length = 0.5;
            this.translateYR.Length = 0.5;
            this.translateZR.Length = 0.5;

            this.Children.Clear();

            if (this.CanTranslateX)
            {
                this.Children.Add(this.translateXL);
                this.Children.Add(this.translateXR);
            }

            if (this.CanTranslateY)
            {
                this.Children.Add(this.translateYL);
                this.Children.Add(this.translateYR);
            }

            if (this.CanTranslateZ)
            {
                this.Children.Add(this.translateZL);
                this.Children.Add(this.translateZR);
            }


            {
                var g = new LineBuilder();
                g.AddLine(new Vector3(0, 0, 0), new Vector3(1, 0, 0));
                g.AddLine(new Vector3(1, 0, 0), new Vector3(1, 1, 0));
                g.AddLine(new Vector3(1, 1, 0), new Vector3(0, 1, 0));
                g.AddLine(new Vector3(0, 1, 0), new Vector3(0, 0, 0));
                this.selectionBounds = new LineGeometryModel3D()
                {
                    Thickness        = 3,
                    Smoothness       = 2,
                    Color            = System.Windows.Media.Colors.Red,
                    IsThrowingShadow = false,
                    Geometry         = g.ToLineGeometry3D(),
                };
                this.Children.Add(this.selectionBounds);
            }
        }
Example #13
0
        public MainViewModel()
        {
            EffectsManager = new DefaultEffectsManager();
            // titles
            this.Title    = "Post Processing Effects Demo";
            this.SubTitle = "WPF & SharpDX";

            // ----------------------------------------------
            // camera setup
            this.Camera = new PerspectiveCamera {
                Position      = new Point3D(0, -30, 0),
                LookDirection = new Vector3D(0, 30, 0),
                UpDirection   = new Vector3D(0, 0, 1)
            };

            var m1 = Load3ds("suzanne.obj").Select(x => x.Geometry).ToArray();

            MeshModel1 = m1[0];

            var m2 = Load3ds("skeleton.3ds").Select(x => x.Geometry).ToArray();

            MeshModel2 = m2[0];

            Model1Transform = new Media3D.TranslateTransform3D(new Vector3D(7, 0, 0));
            Model2Transform = new Media3D.TranslateTransform3D(new Vector3D(-5, 0, 0));

            var builder = new MeshBuilder();

            builder.AddBox(new Vector3(0, 0, -5), 15, 15, 0.2);
            FloorModel = builder.ToMesh();

            builder = new MeshBuilder();
            builder.AddSphere(new Vector3(0, 0, 0), 1);
            MeshModel3 = builder.ToMesh();

            var lineBuilder = new LineBuilder();

            lineBuilder.AddLine(Vector3.Zero, Vector3.UnitX * 5);
            lineBuilder.AddLine(Vector3.Zero, Vector3.UnitY * 5);
            lineBuilder.AddLine(Vector3.Zero, Vector3.UnitZ * 5);
            LineModel        = lineBuilder.ToLineGeometry3D();
            LineModel.Colors = new Color4Collection()
            {
                new Color4(1, 0, 0, 1), new Color4(1, 0, 0, 1), new Color4(0, 1, 0, 1), new Color4(0, 1, 0, 1), new Color4(0, 0, 1, 1), new Color4(0, 0, 1, 1),
            };
        }
        public override LineGeometry3D Build(double _startMarkerSize = 0.1)
        {
            this.ValidateGeometry();
            if (!this.IsValid)
            {
                return(null);
            }

            int n = this.Coords0.Count;

            LineBuilder b1 = new LineBuilder();

            b1.AddBox(this.Coords0[0].ToVector3(), _startMarkerSize, _startMarkerSize, _startMarkerSize);
            b1.AddLine(this.Coords0[0].ToVector3(), this.Coords1[0].ToVector3());
            if (n == 1)
            {
                b1.AddBox(this.Coords1[0].ToVector3(), _startMarkerSize, _startMarkerSize, _startMarkerSize);
            }

            int nextInd = this.Connected[0];

            if (nextInd == -1 && n > 1)
            {
                b1.AddBox(this.Coords1[0].ToVector3(), _startMarkerSize, _startMarkerSize, _startMarkerSize);
            }

            for (int i = 1; i < n; i++)
            {
                // next segment regardless of connectivity
                b1.AddLine(this.Coords0[i].ToVector3(), this.Coords1[i].ToVector3());

                // mark end of connected segment
                nextInd = this.Connected[i];
                if (nextInd == -1)
                {
                    b1.AddBox(this.Coords1[i].ToVector3(), _startMarkerSize, _startMarkerSize, _startMarkerSize);
                    if (i < (n - 1))
                    {
                        b1.AddBox(this.Coords0[i + 1].ToVector3(), _startMarkerSize, _startMarkerSize, _startMarkerSize);
                    }
                }
            }

            return(b1.ToLineGeometry3D());
        }
        private void InitializeCoordinates()
        {
            var builder = new LineBuilder();

            builder.AddLine(Vector3.Zero, Vector3.UnitX * 5);
            builder.AddLine(Vector3.Zero, Vector3.UnitY * 5);
            builder.AddLine(Vector3.Zero, Vector3.UnitZ * 5);
            Coordinate           = builder.ToLineGeometry3D();
            Coordinate.Colors    = new Color4Collection(Enumerable.Repeat <Color4>(Color.White, 6));
            Coordinate.Colors[0] = Coordinate.Colors[1] = Color.Red;
            Coordinate.Colors[2] = Coordinate.Colors[3] = Color.Green;
            Coordinate.Colors[4] = Coordinate.Colors[5] = Color.Blue;

            CoordinateText = new BillboardText3D();
            CoordinateText.TextInfo.Add(new TextInfo("X", Vector3.UnitX * 6));
            CoordinateText.TextInfo.Add(new TextInfo("Y", Vector3.UnitY * 6));
            CoordinateText.TextInfo.Add(new TextInfo("Z", Vector3.UnitZ * 6));
        }
 private void CreateGrid(double gridMaxX, double gridMinX, double gridMaxY, double gridMinY, double gridMinZ)
 {
     for (double i = gridMinY; i < gridMaxY - 10; i += (gridMaxY - gridMinY) / 10)  // tworzenie siatki
     {
         Vector3 p1 = new Vector3((float)gridMaxX, (float)i, (float)gridMinZ);
         Vector3 p2 = new Vector3((float)gridMinX, (float)i, (float)gridMinZ);
         lines.AddLine(p1, p2);
     }
 }
Example #17
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if ((value is MVMIH.IElementHandle eh) && (parameter is string str) && int.TryParse(str, out int idx))
            {
                GetPoints(eh, idx, out Vector3 p0, out Vector3 p1);

                var builder = new LineBuilder();

                builder.AddLine(p0, p1);

                return(builder.ToLineGeometry3D());
            }
Example #18
0
        public IKHexapod(Vector3 center_point)
        {
            var e1 = new LineBuilder();

            e1.Add(true,
                   new Vector3(-Config.HALF_X2LENGTH, 0, 0),
                   new Vector3(-Config.HALF_X1LENGTH, 0, Config.HALF_ZLENGTH),
                   new Vector3(Config.HALF_X1LENGTH, 0, Config.HALF_ZLENGTH),
                   new Vector3(Config.HALF_X2LENGTH, 0, 0),
                   new Vector3(Config.HALF_X1LENGTH, 0, -Config.HALF_ZLENGTH),
                   new Vector3(-Config.HALF_X1LENGTH, 0, -Config.HALF_ZLENGTH));
            e1.Add(true, new Vector3(-Config.HALF_X2LENGTH, Config.BODY_HIGH, 0),
                   new Vector3(-Config.HALF_X1LENGTH, Config.BODY_HIGH, Config.HALF_ZLENGTH),
                   new Vector3(Config.HALF_X1LENGTH, Config.BODY_HIGH, Config.HALF_ZLENGTH),
                   new Vector3(Config.HALF_X2LENGTH, Config.BODY_HIGH, 0),
                   new Vector3(Config.HALF_X1LENGTH, Config.BODY_HIGH, -Config.HALF_ZLENGTH),
                   new Vector3(-Config.HALF_X1LENGTH, Config.BODY_HIGH, -Config.HALF_ZLENGTH));

            e1.AddLine(
                new Vector3(Config.HALF_X1LENGTH, Config.BODY_HIGH, -Config.HALF_ZLENGTH),
                new Vector3(Config.HALF_X1LENGTH, 0, -Config.HALF_ZLENGTH));
            e1.AddLine(
                new Vector3(Config.HALF_X2LENGTH, Config.BODY_HIGH, 0),
                new Vector3(Config.HALF_X2LENGTH, 0, 0));
            e1.AddLine(
                new Vector3(Config.HALF_X1LENGTH, Config.BODY_HIGH, Config.HALF_ZLENGTH),
                new Vector3(Config.HALF_X1LENGTH, 0, Config.HALF_ZLENGTH));
            e1.AddLine(
                new Vector3(-Config.HALF_X1LENGTH, Config.BODY_HIGH, Config.HALF_ZLENGTH),
                new Vector3(-Config.HALF_X1LENGTH, 0, Config.HALF_ZLENGTH));
            e1.AddLine(
                new Vector3(-Config.HALF_X2LENGTH, Config.BODY_HIGH, 0),
                new Vector3(-Config.HALF_X2LENGTH, 0, 0));
            e1.AddLine(
                new Vector3(-Config.HALF_X1LENGTH, Config.BODY_HIGH, -Config.HALF_ZLENGTH),
                new Vector3(-Config.HALF_X1LENGTH, 0, -Config.HALF_ZLENGTH));
            //var leg = new IKLeg(0, new Vector3(), 1, 1, 1);
            Leg1 = new IKLeg(1,
                             new Vector3(Config.HALF_X1LENGTH, Config.TIBIA_LENGTH, -Config.HALF_ZLENGTH),
                             Config.COXA_LENGTH, Config.FEMUR_LENGTH, Config.TIBIA_LENGTH);
            Leg2 = new IKLeg(2,
                             new Vector3(Config.HALF_X2LENGTH, Config.TIBIA_LENGTH, 0),
                             Config.COXA_LENGTH, Config.FEMUR_LENGTH, Config.TIBIA_LENGTH);
            Leg3 = new IKLeg(3,
                             new Vector3(Config.HALF_X1LENGTH, Config.TIBIA_LENGTH, Config.HALF_ZLENGTH),
                             Config.COXA_LENGTH, Config.FEMUR_LENGTH, Config.TIBIA_LENGTH);
            Leg4 = new IKLeg(4,
                             new Vector3(-Config.HALF_X1LENGTH, Config.TIBIA_LENGTH, Config.HALF_ZLENGTH),
                             Config.COXA_LENGTH, Config.FEMUR_LENGTH, Config.TIBIA_LENGTH);
            Leg5 = new IKLeg(5,
                             new Vector3(-Config.HALF_X2LENGTH, Config.TIBIA_LENGTH, 0),
                             Config.COXA_LENGTH, Config.FEMUR_LENGTH, Config.TIBIA_LENGTH);
            Leg6 = new IKLeg(6,
                             new Vector3(-Config.HALF_X1LENGTH, Config.TIBIA_LENGTH, -Config.HALF_ZLENGTH),
                             Config.COXA_LENGTH, Config.FEMUR_LENGTH, Config.TIBIA_LENGTH);

            ModelSkeleton     = e1.ToLineGeometry3D();
            SkeletonTransform = new System.Windows.Media.Media3D.TranslateTransform3D(center_point.ToVector3D());
            Calculate();
        }
Example #19
0
        /// <summary>
        /// Generates a square grid with a step of 1.0
        /// </summary>
        /// <returns></returns>
        public static LineGeometry3D GenerateGrid(Vector3 plane, int min = 0, int max = 10)
        {
            var grid = new LineBuilder();

            //int width = max - min;
            if (plane == Vector3.UnitX)
            {
                for (int i = min; i <= max; i++)
                {
                    grid.AddLine(new Vector3(0, i, min), new Vector3(0, i, max));
                    grid.AddLine(new Vector3(0, min, i), new Vector3(0, max, i));
                }
            }
            else if (plane == Vector3.UnitY)
            {
                for (int i = min; i <= max; i++)
                {
                    grid.AddLine(new Vector3(i, 0, min), new Vector3(i, 0, max));
                    grid.AddLine(new Vector3(min, 0, i), new Vector3(max, 0, i));
                }
            }
            else
            {
                for (int i = min; i <= max; i++)
                {
                    grid.AddLine(new Vector3(i, min, 0), new Vector3(i, max, 0));
                    grid.AddLine(new Vector3(min, i, 0), new Vector3(max, i, 0));
                }
            }

            return(grid.ToLineGeometry3D());
        }
        public override LineGeometry3D BuildSelectionGeometry()
        {
            if (this.TextChanged)
            {
                this.TextToGeometry();
            }

            base.ValidateGeometry();
            if (!this.IsValid)
            {
                return(null);
            }

            LineBuilder b1 = new LineBuilder();

            b1.AddLine(TextBounds.Minimum, new Vector3(TextBounds.Maximum.X, TextBounds.Minimum.Y, TextBounds.Minimum.Z));
            b1.AddLine(new Vector3(TextBounds.Maximum.X, TextBounds.Minimum.Y, TextBounds.Minimum.Z), TextBounds.Maximum);
            b1.AddLine(TextBounds.Maximum, new Vector3(TextBounds.Minimum.X, TextBounds.Maximum.Y, TextBounds.Maximum.Z));
            b1.AddLine(new Vector3(TextBounds.Minimum.X, TextBounds.Maximum.Y, TextBounds.Maximum.Z), TextBounds.Minimum);

            return(b1.ToLineGeometry3D());
        }
        public MainViewModel()
        {
            EffectsManager = new DefaultEffectsManager();
            Camera         = new OrthographicCamera()
            {
                Position = new Point3D(0, 0, -5), LookDirection = new Vector3D(0, 0, 5), UpDirection = new Vector3D(0, 1, 0)
            };
            LoadTeapotCommand = new RelayCommand((o) => { Load(0); });
            LoadSkullCommand  = new RelayCommand((o) => { Load(1); });
            LoadCloudCommand  = new RelayCommand((o) => { Load(2); });
            LoadBeetleCommand = new RelayCommand((o) => { Load(3); });
            var builder = new MeshBuilder();

            //builder.AddBox(new Vector3(0, 0, 0), 2, 2, 0.001);
            builder.AddSphere(Vector3.Zero, 0.1);
            builder.AddBox(Vector3.UnitX, 0.2, 0.2, 0.2);
            MeshModel    = builder.ToMesh();
            MeshMaterial = PhongMaterials.Yellow;

            var lineBuilder = new LineBuilder();

            lineBuilder.AddLine(Vector3.Zero, Vector3.UnitX * 1.5f);
            lineBuilder.AddLine(Vector3.Zero, Vector3.UnitY * 1.5f);
            lineBuilder.AddLine(Vector3.Zero, Vector3.UnitZ * 1.5f);
            AxisModel        = lineBuilder.ToLineGeometry3D();
            AxisModel.Colors = new Color4Collection(AxisModel.Positions.Count);
            AxisModel.Colors.Add(Colors.Red.ToColor4());
            AxisModel.Colors.Add(Colors.Red.ToColor4());
            AxisModel.Colors.Add(Colors.Green.ToColor4());
            AxisModel.Colors.Add(Colors.Green.ToColor4());
            AxisModel.Colors.Add(Colors.Blue.ToColor4());
            AxisModel.Colors.Add(Colors.Blue.ToColor4());
            AxisModelMaterial = new LineArrowHeadMaterial()
            {
                Color = Colors.White, ArrowSize = 0.05
            };
            //Load(0);
        }
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            if ((values != null) && (values.Count() == 3) && (values[0] is double x) && (values[1] is double y) && (values[2] is double z))
            {
                var builder = new LineBuilder();
                var p0      = new SharpDX.Vector3();
                var p1      = new SharpDX.Vector3(0.0f, 0.0f, (float)(z / 2.0));
                var p2      = new SharpDX.Vector3(0.0f, (float)y, (float)(z / 2.0));
                var p3      = new SharpDX.Vector3((float)x, (float)y, (float)(z / 2.0));
                var p4      = new SharpDX.Vector3((float)x, (float)y, (float)z);

                builder.AddLine(p0, p1);
                builder.AddLine(p1, p2);
                builder.AddLine(p2, p3);
                builder.AddLine(p3, p4);

                return(builder.ToLineGeometry3D());
            }
            else
            {
                return(null);
            }
        }
        private static Geometry3D BuildGrid()
        {
            float spacing = 20;
            var   grid    = new LineBuilder();

            for (int x = -2; x <= 2; x++)
            {
                grid.AddLine(new Vector3(x, -2, 0) * spacing, new Vector3(x, 2, 0) * spacing);
                grid.AddLine(new Vector3(x, -2, 5) * spacing, new Vector3(x, -2, 0) * spacing);
            }

            for (int y = -2; y <= 2; y++)
            {
                grid.AddLine(new Vector3(-2, y, 0) * spacing, new Vector3(2, y, 0) * spacing);
            }

            for (int z = 1; z <= 5; z++)
            {
                grid.AddLine(new Vector3(-2, -2, z) * spacing, new Vector3(2, -2, z) * spacing);
            }

            return(grid.ToLineGeometry3D());
        }
Example #24
0
        public void LoadMap(string bytesFileName)
        {
            bool succ = false;

            if (dh.MapLoaded)
            {
                dh.Unload();
            }
            succ = dh.Load(bytesFileName);
            if (succ)
            {
                DHTriangle[] triangles = dh.GetTriangles();
                DHVertex[]   verts     = dh.GetVertexes();
                var          lb        = new LineBuilder();
                groundGroup.Children.Clear();
                mViewModel.ModelTransform = new TranslateTransform3D();
                for (int i = 0; i < triangles.Length; i++)
                {
                    var node = triangles[i];

                    lb.AddLine(MapReader.U2V(node.vertices0), MapReader.U2V(node.vertices1));
                    lb.AddLine(MapReader.U2V(node.vertices1), MapReader.U2V(node.vertices2));
                    lb.AddLine(MapReader.U2V(node.vertices2), MapReader.U2V(node.vertices0));

                    MeshGeometryModel3D mgm = MapReader.MakeMeshGeometryModel3DUnity(node, mViewModel.Material);

                    groundGroup.Children.Add(mgm);
                    mgm.Attach(mViewModel.modelView.RenderHost);
                }
                mViewModel.LineGeometry          = lb.ToLineGeometry3D();
                lineTriangulatedPolygon.Geometry = mViewModel.LineGeometry;
            }

            //icon = AddOrUpdatePlayerPosition("player", 0, 0, 0, 0.5f, 0, 0, 0);
            //icon.LastUpdateTime = DateTime.Now.AddSeconds(1);
            //Ray r = new Ray(mViewModel.Camera.Position,);
        }
Example #25
0
        private void Grbl_GcodeLineChanged(object sender, EventArgs e)
        {
            GcodeLine gcodeline = (GcodeLine)sender;

            Vector3 frompoint   = new Vector3((float)(X0 + gcodeline.Xfrom), (float)(Y0 + gcodeline.Yfrom), (float)(Z0 + gcodeline.Zfrom));
            Vector3 topoint     = new Vector3((float)(X0 + gcodeline.Xto), (float)(Y0 + gcodeline.Yto), (float)(Z0 + gcodeline.Zto));
            Vector3 centerpoint = new Vector3((float)(X0 + gcodeline.Xcenter), (float)(Y0 + gcodeline.Ycenter), (float)(Z0 + gcodeline.Zcenter));

            if (!float.IsNaN(frompoint.X) & !float.IsNaN(frompoint.Y) & !float.IsNaN(frompoint.Z) & !float.IsNaN(topoint.X) & !float.IsNaN(topoint.Y) & !float.IsNaN(topoint.Z))
            {
                if (gcodeline.IsCuttingMotion)
                {
                    if (gcodeline.IsLinearMotion)
                    {
                        localprocessed.AddLine(frompoint, topoint);
                    }
                    else
                    {
                        ArcPointSegment(ref localprocessed, frompoint, topoint, centerpoint, (bool)gcodeline.IsCW);
                    }
                }
                else
                {
                    if (gcodeline.IsLinearMotion)
                    {
                        localprocessed.AddLine(frompoint, topoint);
                    }
                    else
                    {
                        ArcPointSegment(ref localprocessed, frompoint, topoint, centerpoint, (bool)gcodeline.IsCW);
                    }
                }
            }

            Processed = localprocessed.ToLineGeometry3D();
        }
Example #26
0
        public void UpdateSLAMPointCloud()
        {
            int     Error        = 0;
            var     pose         = new List <HelixToolkit.Wpf.SharpDX.Geometry3D.Line>();
            var     line         = new LineBuilder();
            Vector3 previousPose = new Vector3(Convert.ToSingle(poseX), Convert.ToSingle(poseY), Convert.ToSingle(poseZ));

            while (IsSLAMOn)
            {
                var vc = new Vector3Collection();
                var id = new IntCollection();
                var cc = new Color4Collection();

                var     poseVect    = new List <double[]>();
                var     colorVect   = new List <double[]>();
                Vector3 currentPose = new Vector3(Convert.ToSingle(poseX), Convert.ToSingle(poseY), Convert.ToSingle(poseZ));

                line.AddLine(previousPose, currentPose);

                SLAMPoseInfo = line.ToLineGeometry3D();
                previousPose = currentPose;

                try
                {
                    RealsenseControl.GetSLAMPointCloud(ref poseVect, ref colorVect, T265ToLACCOffset.X, T265ToLACCOffset.Y, T265ToLACCOffset.Z);

                    for (int i = 0; i < poseVect.Count; i++)
                    {
                        vc.Add(new Vector3(Convert.ToSingle(poseVect[i][0]), Convert.ToSingle(poseVect[i][1]), Convert.ToSingle(poseVect[i][2])));
                        cc.Add(new Color4(0.1f, 0.1f, 0.1f, 0.5f));
                        //cc.Add(new Color4(Convert.ToSingle(colorVect[i][0]), Convert.ToSingle(colorVect[i][1]), Convert.ToSingle(colorVect[i][2]), 0.5f));
                        id.Add(i);
                    }
                    SLAMPointCloud = new PointGeometry3D()
                    {
                        Positions = vc, Indices = id, Colors = cc
                    };
                }
                catch
                {
                    Error++;
                    Trace.WriteLine("Error Count is " + Error);
                }
                Thread.Sleep(50);
            }
        }
Example #27
0
        private void ArcPointSegment(ref LineBuilder _routerpath, Vector3 startpoint, Vector3 endpoint, Vector3 centerpoint, bool clockwise)
        {
            int numberoflinesinsegment = 5;

            float radius     = Radius(centerpoint, startpoint);
            float startangle = Angle(centerpoint, startpoint, true);
            float endangle   = Angle(centerpoint, endpoint, true);

            endangle = endangle == 0 ? (float)Math.PI * 2 : endangle;

            float arclength = (!clockwise && endangle < startangle) ? (float)((Math.PI * 2 - startangle) + endangle) : ((clockwise && endangle > startangle) ? (float)((Math.PI * 2 - endangle) + startangle) : (float)Math.Abs(endangle - startangle));

            Vector3 endoflinesegment = endpoint;

            float angle;
            float dz = (endpoint.Z - startpoint.Z) / numberoflinesinsegment;


            List <Vector3> vectors = new List <Vector3>();

            for (int i = 0; i < numberoflinesinsegment; i++)
            {
                if (i > 1)
                {
                    vectors.Add(endoflinesegment);
                }

                angle = clockwise ? (startangle - i * arclength / numberoflinesinsegment) : (startangle + i * arclength / numberoflinesinsegment);
                angle = (angle >= Math.PI * 2) ? angle - (float)Math.PI * 2 : angle;

                endoflinesegment.X  = (float)Math.Cos(angle) * radius + centerpoint.X;
                endoflinesegment.Y  = (float)Math.Sin(angle) * radius + centerpoint.Y;
                endoflinesegment.Z += dz;

                vectors.Add(endoflinesegment);
            }

            vectors.Add(endoflinesegment);
            vectors.Add(endpoint);


            for (int x = 1; x < vectors.Count; x++)
            {
                _routerpath.AddLine(vectors[x - 1], vectors[x]);
            }
        }
        public virtual LineGeometry3D BuildSelectionGeometry()
        {
            this.ValidateGeometry();
            if (!this.IsValid)
            {
                return(null);
            }

            int         n  = this.Coords0.Count;
            LineBuilder b1 = new LineBuilder();

            for (int i = 0; i < n; i++)
            {
                b1.AddLine(this.Coords0[i].ToVector3(), this.Coords1[i].ToVector3());
            }

            return(b1.ToLineGeometry3D());
        }
Example #29
0
        public override LineGeometry3D Build(double _startMarkerSize = 0.1)
        {
            List <Vector3> coords = this.OwnerPolygon.ExtractOpeningGeometry(this.idInOwner);

            LineBuilder b = new LineBuilder();

            if (coords.Count > 1)
            {
                // show opening on polygon
                b.AddLine(coords[0], coords[1]);
                b.AddBox(coords[0], _startMarkerSize, _startMarkerSize, _startMarkerSize);
                b.AddBox(coords[1], _startMarkerSize, _startMarkerSize, _startMarkerSize);

                // show owner vertex
                b.AddBox(this.OwnerPolygon.Polygon_Coords[this.IndInOwner].ToVector3(),
                         _startMarkerSize, _startMarkerSize, _startMarkerSize);
            }
            return(b.ToLineGeometry3D());
        }
Example #30
0
        //////////////////////////////////////////////////////////////////////////////////////////////////////////////
        // =========================================== GEOMETRY DEFINITIONS ======================================= //
        //////////////////////////////////////////////////////////////////////////////////////////////////////////////

        #region GEOMETRY DEFINITIONS

        private void UpdateGeometry()
        {
            // show the defining polygons
            LineBuilder b = new LineBuilder();
            int         n = coords_polygons.Count;

            if (n > 0)
            {
                for (int i = 0; i < n; i++)
                {
                    // transfer current polygon
                    List <Point3D> cp = coords_polygons[i];
                    int            m  = cp.Count;
                    if (m > 0)
                    {
                        // lines
                        for (int j = 0; j < m; j++)
                        {
                            b.AddLine(cp[j % m].ToVector3(), cp[(j + 1) % m].ToVector3());
                        }
                        // start maker
                        b.AddBox(cp[0].ToVector3(), START_MARKER, 0, START_MARKER);
                    }
                }
            }
            this.polygons.Geometry = b.ToLineGeometry3D();

            // show the resulting volume
            Vector3[] ar1 = CommonExtensions.ConvertPoint3DArToVector3Ar(this.coords_polygons[0].ToArray());
            Vector3[] ar2 = CommonExtensions.ConvertPoint3DArToVector3Ar(this.coords_polygons[1].ToArray());
            List <List <Vector3> > coords_poly_asV3 = CommonExtensions.ConvertPoints3DListListToVector3ListList(this.coords_polygons);
            bool capBottom = false;
            bool capTop    = true;

            HelixToolkit.SharpDX.Wpf.MeshGeometry3D volMesh =
                MeshesCustom.MeshFromNPolygons(coords_poly_asV3, this.reverse_polygons, capBottom, capTop);

            this.volume.Geometry        = volMesh;
            this.volumeNormals.Geometry = MeshesCustom.GetVertexNormalsAsLines(volMesh, 0.25f);
            this.volumeEdges.Geometry   = MeshesCustom.GetEdgesAsLines(volMesh);
        }
        /// <summary>
        /// The on children changed.
        /// </summary>
        protected virtual void OnChildrenChanged()
        {
            this.translateXL.Length = 0.5;
            this.translateYL.Length = 0.5;
            this.translateZL.Length = 0.5;
            this.translateXR.Length = 0.5;
            this.translateYR.Length = 0.5;
            this.translateZR.Length = 0.5;

            this.Children.Clear();

            if (this.CanTranslateX)
            {
                this.Children.Add(this.translateXL);
                this.Children.Add(this.translateXR);
            }

            if (this.CanTranslateY)
            {
                this.Children.Add(this.translateYL);
                this.Children.Add(this.translateYR);
            }

            if (this.CanTranslateZ)
            {
                this.Children.Add(this.translateZL);
                this.Children.Add(this.translateZR);
            }

            {
                var g = new LineBuilder();
                g.AddLine(new Vector3(0, 0, 0), new Vector3(1, 0, 0));
                g.AddLine(new Vector3(1, 0, 0), new Vector3(1, 1, 0));
                g.AddLine(new Vector3(1, 1, 0), new Vector3(0, 1, 0));
                g.AddLine(new Vector3(0, 1, 0), new Vector3(0, 0, 0));
                this.selectionBounds = new LineGeometryModel3D()
                {
                    Thickness = 3,
                    Smoothness = 2,
                    Color = Color.Red,
                    IsThrowingShadow = false,
                    Geometry = g.ToLineGeometry3D(),
                };
                this.Children.Add(this.selectionBounds);
            }
        }