AddBox() public method

Adds a box aligned with the X, Y and Z axes.
public AddBox ( System.Windows.Media.Media3D.Point3D center, double xlength, double ylength, double zlength ) : void
center System.Windows.Media.Media3D.Point3D /// The center point of the box. ///
xlength double /// The length of the box along the X axis. ///
ylength double /// The length of the box along the Y axis. ///
zlength double /// The length of the box along the Z axis. ///
return void
Ejemplo n.º 1
3
 public MainViewModel()
 {
     var gm = new MeshBuilder();
     gm.AddBox(new Point3D(0, 0, 0.5), 1, 1, 1);
     gm.AddCylinder(new Point3D(5, 0, 0), new Point3D(5, 0, 5), 1, 36);
     this.Model = new GeometryModel3D(gm.ToMesh(true), Materials.Blue);
     this.Model.Freeze();
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MainViewModel"/> class.
        /// </summary>
        public MainViewModel()
        {
            // Create a model group
            var modelGroup = new Model3DGroup();

            // Create a mesh builder and add a box to it
            var meshBuilder = new MeshBuilder(false, false);
            meshBuilder.AddBox(new Point3D(0, 0, 1), 1, 2, 0.5);
            meshBuilder.AddBox(new Rect3D(0, 0, 1.2, 0.5, 1, 0.4));

            // Create a mesh from the builder (and freeze it)
            var mesh = meshBuilder.ToMesh(true);

            // Create some materials
            var greenMaterial = MaterialHelper.CreateMaterial(Colors.Green);
            var redMaterial = MaterialHelper.CreateMaterial(Colors.Red);
            var blueMaterial = MaterialHelper.CreateMaterial(Colors.Blue);
            var insideMaterial = MaterialHelper.CreateMaterial(Colors.Yellow);

            // Add 3 models to the group (using the same mesh, that's why we had to freeze it)
            modelGroup.Children.Add(new GeometryModel3D { Geometry = mesh, Material = greenMaterial, BackMaterial = insideMaterial });
            modelGroup.Children.Add(new GeometryModel3D { Geometry = mesh, Transform = new TranslateTransform3D(-2, 0, 0), Material = redMaterial, BackMaterial = insideMaterial });
            modelGroup.Children.Add(new GeometryModel3D { Geometry = mesh, Transform = new TranslateTransform3D(2, 0, 0), Material = blueMaterial, BackMaterial = insideMaterial });

            // Set the property, which will be bound to the Content property of the ModelVisual3D (see MainWindow.xaml)
            this.Model = modelGroup;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MainViewModel"/> class.
        /// </summary>
        public MainViewModel()
        {
            // Create a model group
            var modelGroup = new Model3DGroup();

            // Create a mesh builder and add a box to it
            var meshBuilder = new MeshBuilder(false, false);
            meshBuilder.AddBox(new Point3D(0, 0, 1), 1, 2, 0.5);
            meshBuilder.AddBox(new Rect3D(0, 0, 1.2, 0.5, 1, 0.4));

            // Create a mesh from the builder (and freeze it)
            var mesh = meshBuilder.ToMesh(true);

            // Create some materials
            var greenMaterial = MaterialHelper.CreateMaterial(Colors.Green);
            var redMaterial = MaterialHelper.CreateMaterial(Colors.Red);
            var blueMaterial = MaterialHelper.CreateMaterial(Colors.Blue);
            var insideMaterial = MaterialHelper.CreateMaterial(Colors.Yellow);

            // Add 3 models to the group (using the same mesh, that's why we had to freeze it)
            modelGroup.Children.Add(new GeometryModel3D { Geometry = mesh, Material = greenMaterial, BackMaterial = insideMaterial });
            modelGroup.Children.Add(new GeometryModel3D { Geometry = mesh, Transform = new TranslateTransform3D(-2, 0, 0), Material = redMaterial, BackMaterial = insideMaterial });
            modelGroup.Children.Add(new GeometryModel3D { Geometry = mesh, Transform = new TranslateTransform3D(2, 0, 0), Material = blueMaterial, BackMaterial = insideMaterial });

            //// Set the property, which will be bound to the Content property of the ModelVisual3D (see MainWindow.xaml)
            //AxisAngleRotation3D rotateAxis = new AxisAngleRotation3D(new Vector3D(0, 1, 0), 180/*or 360*/);
            //Rotation3DAnimation rotateAnimation = new Rotation3DAnimation(rotateAxis, TimeSpan.FromSeconds(2));

            //var rotateTransform = new RotateTransform3D();
            //rotateTransform.BeginAnimation(RotateTransform3D.RotationProperty, rotateAnimation);

            //modelGroup.Transform = rotateTransform;

            this.Model = modelGroup;
        }
Ejemplo n.º 4
0
        private void Initializer(Point3D location)
        {
            var geometryModel = new GeometryModel3D();

            var meshBuilder = new MeshBuilder();

            meshBuilder.AddBox(new Point3D(location.X, location.Y, location.Z + 3.5), 1.5, 1.5, 0.25);

            meshBuilder.AddBox(new Point3D(location.X, location.Y + 1, location.Z + 3.5), 0.25, 1.25, 0.25);
            meshBuilder.AddBox(new Point3D(location.X, location.Y - 1, location.Z + 3.5), 0.25, 1.25, 0.25);

            meshBuilder.AddBox(new Point3D(location.X + 1, location.Y , location.Z + 3.5), 1.25, 0.25, 0.25);
            meshBuilder.AddBox(new Point3D(location.X - 1, location.Y, location.Z + 3.5), 1.25, 0.25, 0.25);

            meshBuilder.AddBox(new Point3D(location.X, location.Y + 1.5, location.Z + 3), 0.25, 0.25, 0.75);
            meshBuilder.AddBox(new Point3D(location.X, location.Y - 1.5, location.Z + 3), 0.25, 0.25, 0.75);

            meshBuilder.AddBox(new Point3D(location.X + 1.5, location.Y, location.Z + 3), 0.25, 0.25, 0.75);
            meshBuilder.AddBox(new Point3D(location.X - 1.5, location.Y, location.Z + 3), 0.25, 0.25, 0.75);

            meshBuilder.AddBox(new Point3D(location.X, location.Y, location.Z + 4), 0.5, 0.5, 1);

            geometryModel.Geometry = meshBuilder.ToMesh();
            geometryModel.Material = Materials.Gold;

            Visual3DModel = geometryModel;
        }
Ejemplo n.º 5
0
        // Add all cubes to a ModelVisual3D, reuse geometry but create new visual for each cube - this is slow
        /*   GeometryModel3D AddGeometrySeparate(IEnumerable<Point3D> centers, double L)
           {
               var mv = new ModelVisual3D();

               var cubit = new CubeVisual3D { SideLength = L * 0.95, Fill = Brushes.Gold };
               var cuboidGeometry = cubit.Model.Geometry as MeshGeometry3D;
               var r = new Random();

               foreach (var center in centers)
               {
                   var tg = new Transform3DGroup();
                   tg.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(1, 0, 0), (r.NextDouble() - 0.5) * 10)));
                   tg.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 1, 0), (r.NextDouble() - 0.5) * 10)));
                   tg.Children.Add(new TranslateTransform3D(center.ToVector3D()));

                   var c = new ModelVisual3D
                               {
                                   Content =
                                       new GeometryModel3D
                                           {
                                               Geometry = cuboidGeometry,
                                               Material = cubit.Material,
                                               Transform = tg
                                           }
                               };
                   mv.Children.Add(c);
               }
              return mv;
           }*/

        // All cubes in one GeometryModel - much faster
        GeometryModel3D AddGeometry(IEnumerable<Point3D> centers, double L)
        {
            var w = new Stopwatch();
            w.Start();
            /*            var geometry = new MeshGeometry3D();
                        foreach (var center in centers)
                        {
                            MeshGeometryHelper.AddBox(geometry,center, L, L, L);
                        }
                        */

            var builder = new MeshBuilder();
            foreach (var center in centers)
            {
                builder.AddBox(center, L, L, L);
            }
            var geometry = builder.ToMesh();
            geometry.Freeze();

            Trace.WriteLine(Level + ": " + w.ElapsedMilliseconds + " ms");

            var mv = new GeometryModel3D
                             {
                                 Geometry = geometry,
                                 Material = MaterialHelper.CreateMaterial(Brushes.Gold)
                             };
            TriangleCount = geometry.TriangleIndices.Count / 3;

            return mv;
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Move the center of this point to here
        /// </summary>
        /// <param name="point"></param>
        public void MoveTo(Point3D point) {
            Center = point;
            GeometryModel3D g = (GeometryModel3D)ModelVisual3D.Content;
            MeshGeometry3D m = (MeshGeometry3D)g.Geometry;

            MeshBuilder meshBuilder = new MeshBuilder();
            meshBuilder.AddBox(Center, Radius, Radius, Radius);
            m.Positions = meshBuilder.Positions;
        }
Ejemplo n.º 7
0
        //private ht.TranslateManipulator translateModificator;

        /// <summary>
        /// The tessellate.
        /// </summary>
        /// <returns>The mesh.</returns>
        protected override MeshGeometry3D Tessellate()
        {
            var builder = new ht.MeshBuilder(true, true);
            var _bo     = (IpObject)this;

            if (_bo != null)
            {
                builder.AddBox(_bo.Position, _bo.Size.X, _bo.Size.Y, _bo.Size.Z);
            }
            this.Material     = outsideMat;
            this.BackMaterial = insideMat;
            return(builder.ToMesh());
        }
Ejemplo n.º 8
0
        public Cube(Point3D center, double radius, Action action) {
            Center = center;
            Radius = radius;
            Action = action;
            Notified = false;
            SolidColorBrush = new SolidColorBrush();
            SolidColorBrush.Opacity = _Constants.BaseOpacity;
            SolidColorBrush.Color = _Constants.DefaultCubeColour;
            Material = new DiffuseMaterial(SolidColorBrush);
            MeshBuilder meshBuilder = new MeshBuilder();
            meshBuilder.AddBox(center, radius, radius, radius);

            ModelVisual3D = Engine._3DUtil.WrapMeshAndMaterialIntoModelVisual3D(meshBuilder.ToMesh(), Material);
        }
Ejemplo n.º 9
0
        private ModelVisual3D CreateDice()
        {
            var diceMesh = new MeshBuilder();
            diceMesh.AddBox(new Point3D(0, 0, 0), 1, 1, 1);
            for (int i = 0; i < 2; i++)
                for (int j = 0; j < 2; j++)
                    for (int k = 0; k < 2; k++)
                    {
                        var points = new List<Point3D>();
                        diceMesh.ChamferCorner(new Point3D(i - 0.5, j - 0.5, k - 0.5), 0.1, 1e-6, points);
                        //foreach (var p in points)
                        //    b.ChamferCorner(p, 0.03);
                    }

            return new ModelVisual3D { Content = new GeometryModel3D { Geometry = diceMesh.ToMesh(), Material = Materials.White } };
        }
Ejemplo n.º 10
0
        private void AddCorners()
        {
            var a = Size / 2;
            var sideLength = a / 2;

            Point3D[] points =   {
                new Point3D(-1,-1,-1 ), new Point3D(1, -1, -1), new Point3D(1, 1, -1), new Point3D(-1, 1, -1),
                new Point3D(-1,-1,1 ),new Point3D(1,-1,1 ),new Point3D(1,1,1 ),new Point3D(-1,1,1 )};

            foreach (var p in points)
            {
                var builder = new MeshBuilder(false, true);

                Point3D center = p.Multiply(a);
                builder.AddBox(center, sideLength, sideLength, sideLength);
                var geometry = builder.ToMesh();
                geometry.Freeze();

                var model = new GeometryModel3D { Geometry = geometry, Material = MaterialHelper.CreateMaterial(Colors.Gold) };
                var element = new ModelUIElement3D { Model = model };

                faceNormals.Add(element, p.ToVector3D());
                faceUpVectors.Add(element, ModelUpDirection);

                element.MouseLeftButtonDown += FaceMouseLeftButtonDown;
                element.MouseEnter += CornersMouseEnters;
                element.MouseLeave += CornersMouseLeave;

                Children.Add(element);
            }
        }
Ejemplo n.º 11
0
        private void AppearanceChanged()
        {
            var y0 = 0d;
            var wallBuilder = new MeshBuilder(false, false);
            for (int i = 0; i < this.Stories; i++)
            {
                if (i > 0 && this.FloorThickness > 0)
                {
                    wallBuilder.AddBox(new Point3D(0, 0, y0 + this.FloorThickness / 2), this.Length + 0.2, this.Width + 0.2, this.FloorThickness);
                    y0 += this.FloorThickness;
                }

                wallBuilder.AddBox(new Point3D(0, 0, y0 + this.StoryHeight / 2), this.Length, this.Width, this.StoryHeight);
                y0 += this.StoryHeight;
            }

            var theta = Math.PI / 180 * this.RoofAngle;
            var roofBuilder = new MeshBuilder(false, false);
            var y1 = y0 + Math.Tan(theta) * this.Width / 2;
            var p0 = new Point(0, y1);
            var p1 = new Point(this.Width / 2 + 0.2 * Math.Cos(theta), y0 - 0.2 * Math.Sin(theta));
            var p2 = new Point(p1.X + this.RoofThickness * Math.Sin(theta), p1.Y + this.RoofThickness * Math.Cos(theta));
            var p3 = new Point(0, y1 + this.RoofThickness / Math.Cos(theta));
            var p4 = new Point(-p2.X, p2.Y);
            var p5 = new Point(-p1.X, p1.Y);
            var roofSection = new[] { p0, p1, p1, p2, p2, p3, p3, p4, p4, p5, p5, p0 };
            roofBuilder.AddExtrudedSegments(roofSection, new Vector3D(0, -1, 0), new Point3D(-this.Length / 2, 0, 0), new Point3D(this.Length / 2, 0, 0));
            var cap = new[] { p0, p1, p2, p3, p4, p5 };
            roofBuilder.AddPolygon(cap, new Vector3D(0, -1, 0), new Vector3D(0, 0, 1), new Point3D(-this.Length / 2, 0, 0));
            roofBuilder.AddPolygon(cap, new Vector3D(0, 1, 0), new Vector3D(0, 0, 1), new Point3D(this.Length / 2, 0, 0));
            var p6 = new Point(this.Width / 2, y0);
            var p7 = new Point(-this.Width / 2, y0);
            wallBuilder.AddPolygon(new[] { p0, p6, p7 }, new Vector3D(0, -1, 0), new Vector3D(0, 0, 1), new Point3D(-this.Length / 2, 0, 0));
            wallBuilder.AddPolygon(new[] { p0, p6, p7 }, new Vector3D(0, 1, 0), new Vector3D(0, 0, 1), new Point3D(this.Length / 2, 0, 0));
            this.walls.Geometry = wallBuilder.ToMesh(true);
            this.roof.Geometry = roofBuilder.ToMesh(true);
        }
Ejemplo n.º 12
0
        private Model3DGroup GetHighlightModel3D(Gesture g, List<GestureFrame> fs)
        {
            // Create material
              EmissiveMaterial material = new EmissiveMaterial(new SolidColorBrush() { Color = Colors.White, Opacity = 0.3 });

              Model3DGroup modelGroup = new Model3DGroup();
              foreach (GestureFrame f in fs)
              {
            foreach (GestureFrameCell fc in f.FrontCells.Where(fc => fc.IsHotspot == true))
            {
              int fcIndex = Array.IndexOf(f.FrontCells, fc);
              foreach (GestureFrameCell sc in f.SideCells.Where(
              sc => sc.IsHotspot == true && (int)(Array.IndexOf(f.SideCells, sc) / 20) == (int)(fcIndex / 20)))
              {
            // Init mesh
            MeshBuilder meshBuilder = new MeshBuilder(false, false);
            // Make cube and add to mesh
            double y = (fc.LeftCM + fc.RightCM) / 2;
            double z = (fc.TopCM + fc.BottomCM) / 2;
            double x = (sc.LeftCM + sc.RightCM) / 2;
            Point3D cubeCenter = new Point3D(x, y, z);
            meshBuilder.AddBox(cubeCenter, 15, 15, 15);
            // Create and freeze mesh
            var mesh = meshBuilder.ToMesh(true);
            // Create models
            modelGroup.Children.Add(new GeometryModel3D(mesh, material));
              }
            }
              }
              return modelGroup;
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Creates the maze geometry.
        /// </summary>
        /// <param name="themaze">
        /// The maze.
        /// </param>
        /// <param name="height">
        /// The height of the blocks.
        /// </param>
        /// <param name="size">
        /// The size of the blocks.
        /// </param>
        /// <returns>
        /// The geometry.
        /// </returns>
        private MeshGeometry3D CreateMazeGeometry(bool[,] themaze, double height = 2, double size = 0.995)
        {
            var builder = new MeshBuilder();
            int m = themaze.GetUpperBound(0) + 1;
            int n = themaze.GetUpperBound(1) + 1;
            for (int i = 0; i < m; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    if (themaze[i, j])
                    {
                        builder.AddBox(this.GetPosition(i, j, height * 0.5), size, size, height);
                    }
                }
            }

            return builder.ToMesh();
        }
Ejemplo n.º 14
0
        public void CreateBox(Point3D location, double xLen, double yLen, double zLen, string textureUri)
        {
            var geometryModel = new GeometryModel3D();

            var meshBuilder = new MeshBuilder();
            meshBuilder.AddBox(location, xLen, yLen, zLen);

            geometryModel.Geometry = meshBuilder.ToMesh();
            geometryModel.Material = MaterialHelper.CreateImageMaterial(textureUri);

            Visual3DModel = geometryModel;

            Initializer();
        }
Ejemplo n.º 15
0
        protected override MeshGeometry3D Tessellate()
        {
            double width = Columns*grid - margin*2;
            double length = Rows*grid - margin*2;
            double height = Height*plateThickness;
            var builder = new MeshBuilder(true, true);

            for (int i = 0; i < Columns; i++)
                for (int j = 0; j < Rows; j++)
                {
                    var o = new Point3D((i + 0.5)*grid, (j + 0.5)*grid, height);
                    builder.AddCone(o, new Vector3D(0, 0, 1), knobDiameter/2, knobDiameter/2, knobHeight, false, true,
                                    Divisions);
                    builder.AddPipe(new Point3D(o.X, o.Y, o.Z - wallThickness), new Point3D(o.X, o.Y, wallThickness),
                                    knobDiameter, outerDiameter, Divisions);
                }

            builder.AddBox(new Point3D(Columns * 0.5 * grid, Rows * 0.5 * grid, height - wallThickness / 2), width, length,
                          wallThickness,
                          MeshBuilder.BoxFaces.All);
            builder.AddBox(new Point3D(margin + wallThickness / 2, Rows * 0.5 * grid, height / 2 - wallThickness / 2),
                           wallThickness, length, height - wallThickness,
                           MeshBuilder.BoxFaces.All ^ MeshBuilder.BoxFaces.Top);
            builder.AddBox(
                new Point3D(Columns * grid - margin - wallThickness / 2, Rows * 0.5 * grid, height / 2 - wallThickness / 2),
                wallThickness, length, height - wallThickness,
                MeshBuilder.BoxFaces.All ^ MeshBuilder.BoxFaces.Top);
            builder.AddBox(new Point3D(Columns * 0.5 * grid, margin + wallThickness / 2, height / 2 - wallThickness / 2),
                           width, wallThickness, height - wallThickness,
                           MeshBuilder.BoxFaces.All ^ MeshBuilder.BoxFaces.Top);
            builder.AddBox(
                new Point3D(Columns * 0.5 * grid, Rows * grid - margin - wallThickness / 2, height / 2 - wallThickness / 2),
                width, wallThickness, height - wallThickness,
                MeshBuilder.BoxFaces.All ^ MeshBuilder.BoxFaces.Top);

            return builder.ToMesh();
        }
Ejemplo n.º 16
0
    /// <summary>
    /// Sync 3D Viewport with grids
    /// </summary>
    private void SyncEditorGrids_3D(Gesture g) //TODO: split into smaller methods
    {
      // Init 3D stuff
      Model3DGroup modelGroup = new Model3DGroup();
      foreach (GestureFrame f in g.Frames)
      {
        // Create material
        SolidColorBrush materialBrush = new SolidColorBrush()
        {
          Color = Colors.DarkSlateBlue,
          Opacity = 0.1 + ((double)(g.Frames.IndexOf(f) + 1) / (double)g.Frames.Count) * 0.8
        };
        DiffuseMaterial material = new DiffuseMaterial(materialBrush);

        foreach (GestureFrameCell fc in f.FrontCells.Where(fc => fc.IsHotspot == true))
        {
          int fcIndex = Array.IndexOf(f.FrontCells, fc);
          foreach (GestureFrameCell sc in f.SideCells.Where(
                   sc => sc.IsHotspot == true && (int)(Array.IndexOf(f.SideCells, sc) / 20) == (int)(fcIndex / 20)))
          {
            // Init mesh
            MeshBuilder meshBuilder = new MeshBuilder(false, false);
            // Make cube and add to mesh
            double y = (fc.LeftCM + fc.RightCM) / 2;
            double z = (fc.TopCM + fc.BottomCM) / 2;
            double x = (sc.LeftCM + sc.RightCM) / 2;
            Point3D cubeCenter = new Point3D(x, y, z);
            meshBuilder.AddBox(cubeCenter, 15, 15, 15);

            // Create and freeze mesh
            var mesh = meshBuilder.ToMesh(true);

            // Create model
            modelGroup.Children.Add(new GeometryModel3D(mesh, material));
          }
        }
      }

      // Suggest other gestures too
      foreach (Gesture gg in GestureCollection)
      {
        foreach (GestureFrame f in gg.Frames)
        {
          // Create material
          SolidColorBrush materialBrush = new SolidColorBrush()
          {
            Color = Visualizer_GestureColors[GestureCollection.IndexOf(gg) % Visualizer_GestureColors.Length].Color,
            Opacity = ((double)(gg.Frames.IndexOf(f) + 1) / (double)gg.Frames.Count) * 0.09
          };
          DiffuseMaterial material = new DiffuseMaterial(materialBrush);

          foreach (GestureFrameCell fc in f.FrontCells.Where(fc => fc.IsHotspot == true))
          {
            int fcIndex = Array.IndexOf(f.FrontCells, fc);
            foreach (GestureFrameCell sc in f.SideCells.Where(
                sc => sc.IsHotspot == true && (int)(Array.IndexOf(f.SideCells, sc) / 20) == (int)(fcIndex / 20)))
            {
              // Init mesh
              MeshBuilder meshBuilder = new MeshBuilder(false, false);

              // Make cube and add to mesh
              double y = (fc.LeftCM + fc.RightCM) / 2;
              double z = (fc.TopCM + fc.BottomCM) / 2;
              double x = (sc.LeftCM + sc.RightCM) / 2;
              Point3D cubeCenter = new Point3D(x, y, z);
              meshBuilder.AddBox(cubeCenter, 15, 15, 15);

              // Create and freeze mesh
              var mesh = meshBuilder.ToMesh(true);

              // Create model
              modelGroup.Children.Add(new GeometryModel3D(mesh, material));
            }
          }
        }
      }

      HotspotCellsModelVisual3D_Editor.Content = modelGroup;
    }
 private static GeometryModel3D CreateVoxelModel3D(Voxel v)
 {
     const double size = 0.98;
     var m = new GeometryModel3D();
     var mb = new MeshBuilder();
     mb.AddBox(new Point3D(0, 0, 0), size, size, size);
     m.Geometry = mb.ToMesh();
     m.Material = MaterialHelper.CreateMaterial(v.Colour);
     m.Transform = new TranslateTransform3D(v.Position.X, v.Position.Y, v.Position.Z);
     return m;
 }
Ejemplo n.º 18
0
        /**
         * Ceci ne marche pas encore
         * 
         * Cette méthode créée un cube à la position de la main droite de l'utilisateur
         * 
         */
        private void buildCube(object sender, RoutedEventArgs e)
        {
            Skeleton s = squelette;

                if (s != null)
                {
                    Joint main = s.Joints[JointType.HandRight];
                    Point3D point = new Point3D(main.Position.X, main.Position.Y, main.Position.Z);
                   
                    MeshBuilder mesh = new MeshBuilder(true, true);

                    mesh.AddBox(point, 1, 1, 1);
                    
                }
        }
Ejemplo n.º 19
0
        private void Worker4(object d)
        {
            var dispatcher = (Dispatcher)d;
            var m = MaterialHelper.CreateMaterial(Colors.Gold);
            Model3DGroup mg = null;
            dispatcher.Invoke(new Action(() => this.model4.Content = mg = new Model3DGroup()));

            Interlocked.Increment(ref this.runningWorkers);

            while (!this.source.IsCancellationRequested)
            {
                if (!this.AddToModelGroup || this.runningWorkers < 4)
                {
                    Thread.Yield();
                    continue;
                }

                for (int i = 1; i <= n; i++)
                {
                    var b = new MeshBuilder();
                    for (int j = 1; j <= n; j++)
                    {
                        for (int k = 1; k <= n; k++)
                        {
                            b.AddBox(new Point3D(-i, j, -k), 0.8, 0.8, 0.8);
                        }
                    }

                    var box = new GeometryModel3D { Geometry = b.ToMesh(false), Material = m };
                    box.Freeze();
                    dispatcher.Invoke(new Action(() => mg.Children.Add(box)));
                }
                dispatcher.Invoke((Action)(() => this.Count4++));
                dispatcher.Invoke((Action)(() => mg.Children.Clear()));
            }
        }
Ejemplo n.º 20
0
        /* HELIX3D SANITY CHECKS/SETTERS/GETTERS*/
        /// <summary>
        /// Sanity check.
        /// </summary>
        public void runDemoModel()
        {
            // Create a mesh builder and add a box to it
            var meshBuilder = new MeshBuilder(false, false);
            meshBuilder.AddBox(new Point3D(0, 0, 1), 1, 2, 0.5);
            meshBuilder.AddBox(new Rect3D(0, 0, 1.2, 0.5, 1, 0.4));

            // Create a mesh from the builder (and freeze it)
            var mesh = meshBuilder.ToMesh(true);

            // Create some materials
            var greenMaterial = MaterialHelper.CreateMaterial(Colors.Green);

            if (cloudList != null)
            {
                this.Model = new GeometryModel3D { Geometry = mesh, Transform = new TranslateTransform3D(0, 0, 0), Material = greenMaterial, BackMaterial = greenMaterial };
                this.Model2 = new GeometryModel3D { Geometry = mesh, Transform = new TranslateTransform3D(0, 0, 0), Material = greenMaterial, BackMaterial = greenMaterial };
                this.Model3 = new GeometryModel3D { Geometry = mesh, Transform = new TranslateTransform3D(0, 0, 0), Material = greenMaterial, BackMaterial = greenMaterial };
                this.Model4 = new GeometryModel3D { Geometry = mesh, Transform = new TranslateTransform3D(0, 0, 0), Material = greenMaterial, BackMaterial = greenMaterial };
                this.armLabel = new GeometryModel3D { Geometry = mesh, Transform = new TranslateTransform3D(0, 0, 0), Material = greenMaterial, BackMaterial = greenMaterial };
            }
            else
            {
                this.Model = new GeometryModel3D { Geometry = mesh, Transform = new TranslateTransform3D(0, 0, 0), Material = greenMaterial, BackMaterial = greenMaterial };
            }
        }
        private Model3DGroup CreateEnemyModel(string EnemyType, Color color)
        {
            Model3DGroup EnemyModel = null;
            if (EnemyType.Contains("#"))
            {
                MeshBuilder b = new MeshBuilder();
                if (EnemyType.Contains("box"))
                {
                    b.AddBox(new Point3D(1, 1, 1), 40, 40, 40);
                }
                else
                if (EnemyType.Contains("sphere"))
                {
                    b.AddSphere(new Point3D(1, 1, 1), 40);
                }

                var Mesh = b.ToMesh();
                var GeometryModel = new GeometryModel3D { Geometry = Mesh };

                ModelVisual3D ModelVisual = new ModelVisual3D();
                ModelVisual.Content = GeometryModel;
                EnemyModel = new Model3DGroup();
                EnemyModel.Children.Add(ModelVisual.Content);
            }
            else
            {
                EnemyModel = importer.Load(EnemyType.ToString(), null, false);
            }

            foreach (var Child in EnemyModel.Children)
            {
                var Model = ((GeometryModel3D)Child);
                Model.Material = MaterialHelper.CreateMaterial(color);
            }

            return EnemyModel;
        }
Ejemplo n.º 22
0
        private ModelVisual3D CreateLaser(double x, double y, double z)
        {
            MeshBuilder b = new MeshBuilder();
            b.AddBox(new Point3D(1, 1, 1), 5, 50, 5);
            var Mesh = b.ToMesh();
            Material MaterialForLaser = MaterialHelper.CreateMaterial(Colors.Red);

            ModelVisual3D Laser = new ModelVisual3D();

            var LaserModel = new GeometryModel3D { Geometry = Mesh, Material = MaterialForLaser };

            Laser.SetName("Laser");
            Laser.Content = LaserModel;

            Transform3DGroup Transforms = new Transform3DGroup();
            Transforms.Children.Add(new ScaleTransform3D(0.01, 0.01, 0.01));
            Transforms.Children.Add(new TranslateTransform3D(x, y, z));
            Laser.Transform = Transforms;

            return Laser;
        }
Ejemplo n.º 23
0
        public void CreateStation(Point3D location, string textureUri)
        {
            var geometryModel = new GeometryModel3D();
            var meshBuilder = new MeshBuilder();

            meshBuilder.AddBox(new Point3D(location.X - 2, location.Y - 3, location.Z), 4, 4, 0.35); //Inspector1
            meshBuilder.AddBox(new Point3D(location.X - 2, location.Y + 3, location.Z), 4, 4, 0.35); //Inspector2
            meshBuilder.AddBox(new Point3D(location.X - 2, location.Y + 20, location.Z), 5, 25, 0.35); // Queue

            geometryModel.Geometry = meshBuilder.ToMesh();
            //geometryModel.Material = MaterialHelper.CreateImageMaterial(textureUri);
            geometryModel.Material = Materials.Brown;

            Visual3DModel = geometryModel;

            Initializer();
        }
Ejemplo n.º 24
0
 private GeometryModel3D Box(double width, double length, double height)
 {
     var model = new GeometryModel3D();
     model.SetValue(FrameworkElement.NameProperty, "box");
     var mb = new MeshBuilder(false,false);
     mb.AddBox(new Point3D(0, 0, height*0.5), width, length, height);
     model.Geometry = mb.ToMesh();
     model.Material = material;
     return model;
 }
Ejemplo n.º 25
0
        private void Worker2(object d)
        {
            var dispatcher = (Dispatcher)d;
            Interlocked.Increment(ref this.runningWorkers);
            while (!this.source.IsCancellationRequested)
            {
                if (!this.AddFrozenGeometry || this.runningWorkers < 4)
                {
                    Thread.Yield();
                    continue;
                }

                for (int i = 1; i <= n; i++)
                {
                    var b = new MeshBuilder();
                    for (int j = 1; j <= n; j++)
                    {
                        for (int k = 1; k <= n; k++)
                        {
                            b.AddBox(new Point3D(i, j, k), 0.8, 0.8, 0.8);
                        }
                    }

                    dispatcher.Invoke(new Action<MeshGeometry3D, Material, ModelVisual3D>(this.Add), b.ToMesh(true), mat2, model2);
                }

                dispatcher.Invoke((Action)(() => this.Count2++));

                dispatcher.Invoke(new Action<ModelVisual3D>(this.Clear), this.model2);
            }
        }
Ejemplo n.º 26
0
        private void AppearanceChanged()
        {
            var builder = new MeshBuilder(false, false);
            var p0 = new Point(0, 0);
            var p1 = new Point(this.Diameter / 2, 0);
            var p2 = new Point(this.Diameter / 2, this.Height);
            var p3 = new Point(this.DomeDiameter / 2, this.Height);

            var section = new List<Point> { p0, p1, p1, p2, p2, p3 };
            var sectionIndices = new List<int> { 0, 1, 2, 3, 4, 5 };
            int n = 40;
            for (int i = n; i >= 0; i--)
            {
                double x = (double)i / n;
                double y = x * x;
                if (i < n)
                {
                    sectionIndices.Add(section.Count - 1);
                    sectionIndices.Add(section.Count);
                }

                section.Add(new Point(x * this.DomeDiameter / 2, this.Height + (this.DomeHeight * (1 - y))));
            }

            builder.AddSurfaceOfRevolution(new Point3D(0, 0, 0), new Vector3D(0, 0, 1), section, sectionIndices, 80);
            this.walls.Geometry = builder.ToMesh(true);

            var treadDepth = 0.3;
            var riseHeight = 0.15;
            var thickness = 0.05;
            var width = 1;
            var steps = (int)(this.Height / riseHeight);
            var r = (this.Diameter * 0.5) + (width * 0.5);
            var rp = (this.Diameter * 0.5) + (width * 0.95);
            var stairBuilder = new MeshBuilder(false, false);
            var railBases = new List<Point3D>();
            for (int i = 0; i < steps; i++)
            {
                var theta = treadDepth * i / r;
                var p = new Point3D(Math.Cos(theta) * r, Math.Sin(theta) * r, (riseHeight * i) + (thickness / 2));
                var x = new Vector3D(Math.Cos(theta), Math.Sin(theta), 0);
                var z = new Vector3D(0, 0, 1);
                var y = Vector3D.CrossProduct(z, x);
                stairBuilder.AddBox(p, x, y, width, treadDepth, thickness);
                railBases.Add(new Point3D(Math.Cos(theta) * rp, Math.Sin(theta) * rp, (riseHeight * i) + thickness));
            }

            var lastTheta = treadDepth * steps / r;

            // Railing along stairs
            var railingHeight = 0.8;
            var railingDiameter = 0.05;
            var railings = 3;
            var railingBuilder = new MeshBuilder(false, false);

            // Top railing
            var railingPostDistance = 0.5;
            int topRailingPosts = (int)(this.Diameter * Math.PI / railingPostDistance);
            var tr = (this.Diameter / 2) - railingDiameter;
            for (int i = 0; i < topRailingPosts; i++)
            {
                var theta = lastTheta + (2 * Math.PI * i / topRailingPosts);
                railBases.Add(new Point3D(Math.Cos(theta) * tr, Math.Sin(theta) * tr, this.Height));
            }

            BuildRailing(railingBuilder, railBases, railingHeight, railingDiameter, railings);

            this.stairs.Geometry = stairBuilder.ToMesh();
            this.railing.Geometry = railingBuilder.ToMesh();
        }
        //TODO: make method smaller (refactor into multiple methods)
        public void ShowVisualizer()
        {
            CollisionTimes = new List<List<DateTime>>();
              CollisionStates = new List<JointCollisionStates[]>();
              CollisionHighlights_3D = new Model3DGroup();
              CollisionHighlights_Front = new Model3DGroup();
              CollisionHighlights_Side = new Model3DGroup();

              foreach (Gesture g in GestureCollection)
              {
            CollisionTimes.Add(new List<DateTime>());
            foreach (GestureFrame f in g.Frames)
              CollisionTimes.Last().Add(new DateTime());
            CollisionStates.Add(new JointCollisionStates[2] { JointCollisionStates.OutThere, JointCollisionStates.OutThere });
            CollisionHighlights_3D.Children.Add(new Model3DGroup());
            CollisionHighlights_Front.Children.Add(new Model3DGroup());
            CollisionHighlights_Side.Children.Add(new Model3DGroup());
              }

              HotspotCellsModelVisual3D_Hit_Visualizer.Content = CollisionHighlights_3D;

              // Mark gesture cells in 3D Grid
              Model3DGroup modelGroup = new Model3DGroup();
              foreach (Gesture g in GestureCollection)
              {
            foreach (GestureFrame f in g.Frames)
            {
              // Create material
              SolidColorBrush materialBrush = new SolidColorBrush()
              {
            Color = Visualizer_GestureColors[GestureCollection.IndexOf(g) % Visualizer_GestureColors.Length].Color,
            Opacity = 0.1 + ((double)(g.Frames.IndexOf(f) + 1) / (double)g.Frames.Count) * 0.6
              };
              DiffuseMaterial material = new DiffuseMaterial(materialBrush);

              foreach (GestureFrameCell fc in f.FrontCells.Where(fc => fc.IsHotspot == true))
              {
            int fcIndex = Array.IndexOf(f.FrontCells, fc);
            foreach (GestureFrameCell sc in f.SideCells.Where(
                     sc => sc.IsHotspot == true && (int)(Array.IndexOf(f.SideCells, sc) / 20) == (int)(fcIndex / 20)))
            {
              // Init mesh
              MeshBuilder meshBuilder = new MeshBuilder(false, false);
              // Make cube and add to mesh
              double y = (fc.LeftCM + fc.RightCM) / 2;
              double z = (fc.TopCM + fc.BottomCM) / 2;
              double x = (sc.LeftCM + sc.RightCM) / 2;
              Point3D cubeCenter = new Point3D(x, y, z);
              meshBuilder.AddBox(cubeCenter, 15, 15, 15);
              // Create and freeze mesh
              var mesh = meshBuilder.ToMesh(true);
              // Create models
              modelGroup.Children.Add(new GeometryModel3D(mesh, material));
            }
              }
            }
            HotspotCellsModelVisual3D_Visualizer.Content = modelGroup;
              }

              VisualizerVisible = true;

              EnableKinect_Visualizer();
              DisableKeyboardControl_Visualizer(); //we don't want to consume emulated keyboard events
        }
Ejemplo n.º 28
0
        private void AddEdge(Point3D center, double x, double y, double z, Vector3D faceNormal)
        {
            var builder = new MeshBuilder(false, true);

            builder.AddBox(center, x, y, z);

            var geometry = builder.ToMesh();
            geometry.Freeze();

            var model = new GeometryModel3D { Geometry = geometry, Material = MaterialHelper.CreateMaterial(Colors.Silver) };
            var element = new ModelUIElement3D { Model = model };

            faceNormals.Add(element, faceNormal);
            faceUpVectors.Add(element, ModelUpDirection);

            element.MouseLeftButtonDown += FaceMouseLeftButtonDown;
            element.MouseEnter += EdggesMouseEnters;
            element.MouseLeave += EdgesMouseLeaves;

            Children.Add(element);
        }
Ejemplo n.º 29
0
        private void Worker3(object d)
        {
            var dispatcher = (Dispatcher)d;
            var m = MaterialHelper.CreateMaterial(Colors.Green);
            Interlocked.Increment(ref this.runningWorkers);
            while (!this.source.IsCancellationRequested)
            {
                if (!this.AddFrozenModel || this.runningWorkers < 4)
                {
                    Thread.Yield();
                    continue;
                }

                for (int i = 1; i <= n; i++)
                {
                    var b = new MeshBuilder();
                    for (int j = 1; j <= n; j++)
                    {
                        for (int k = 1; k <= n; k++)
                        {
                            b.AddBox(new Point3D(i, j, -k), 0.8, 0.8, 0.8);
                        }
                    }

                    var box = new GeometryModel3D { Geometry = b.ToMesh(false), Material = m };
                    box.Freeze();

                    dispatcher.Invoke(new Action<Model3D, ModelVisual3D>(this.Add), box, this.model3);
                }

                dispatcher.Invoke((Action)(() => this.Count3++));
                dispatcher.Invoke(new Action<ModelVisual3D>(this.Clear), model3);
            }
        }
Ejemplo n.º 30
0
 private static Geometry3D GetDefaultGeometry()
 {
     // The default geometry is a box
     var mb = new MeshBuilder(false,false);
     mb.AddBox(new Point3D(0, 0, 0.5), 0.8, 0.8, 1);
     return mb.ToMesh();
 }
Ejemplo n.º 31
0
        /// <summary>
        /// Add a cube geometry object centered on (0,0,0).
        /// </summary>
        /// <param name="shapeName">The 3DView object.</param>
        /// <param name="sideLength">The side length of the cube.</param>
        /// <param name="colour">A colour or gradient brush for the object.</param>
        /// <param name="materialType">A material for the object.
        /// The available options are:
        /// "E" Emmissive - constant brightness.
        /// "D" Diffusive - affected by lights.
        /// "S" Specular  - specular highlights.
        /// </param>
        /// <returns>The 3DView Geometry name.</returns>
        public static Primitive AddCube(Primitive shapeName, Primitive sideLength, Primitive colour, Primitive materialType)
        {
            UIElement obj;

            try
            {
                if (_objectsMap.TryGetValue((string)shapeName, out obj))
                {
                    InvokeHelperWithReturn ret = new InvokeHelperWithReturn(delegate
                    {
                        try
                        {
                            if (obj.GetType() == typeof(Viewport3D))
                            {
                                MeshBuilder builder = new MeshBuilder(true, true);
                                builder.AddBox(new Point3D(0, 0, 0), sideLength, sideLength, sideLength);
                                MeshGeometry3D mesh = builder.ToMesh();

                                Viewport3D viewport3D = (Viewport3D)obj;
                                return AddGeometry(viewport3D, mesh.Positions, mesh.TriangleIndices, mesh.Normals, mesh.TextureCoordinates, colour, materialType);
                            }
                        }
                        catch (Exception ex)
                        {
                            Utilities.OnError(Utilities.GetCurrentMethod(), ex);
                        }
                        return "";
                    });
                    return FastThread.InvokeWithReturn(ret).ToString();
                }
                else
                {
                    Utilities.OnShapeError(Utilities.GetCurrentMethod(), shapeName);
                }
            }
            catch (Exception ex)
            {
                Utilities.OnError(Utilities.GetCurrentMethod(), ex);
            }
            return "";
        }