AddQuad() public method

Adds a quadrilateral polygon.
See http://en.wikipedia.org/wiki/Quadrilateral.
public AddQuad ( System.Windows.Media.Media3D.Point3D p0, System.Windows.Media.Media3D.Point3D p1, System.Windows.Media.Media3D.Point3D p2, System.Windows.Media.Media3D.Point3D p3 ) : void
p0 System.Windows.Media.Media3D.Point3D /// The first point. ///
p1 System.Windows.Media.Media3D.Point3D /// The second point. ///
p2 System.Windows.Media.Media3D.Point3D /// The third point. ///
p3 System.Windows.Media.Media3D.Point3D /// The fourth point. ///
return void
 private static object buildQuad()
 {
     var mb = new MeshBuilder(true, false);
     var p0 = new Point3D(0, 0, 0);
     var p1 = new Point3D(1, 0, 0);
     var p2 = new Point3D(1, 1, 0);
     var p3 = new Point3D(0, 1, 0);
     mb.AddQuad(p0, p1, p2, p3);
     mb.Normals.ToList().ForEach(x => System.Diagnostics.Trace.WriteLine(x.ToString()));
     return mb.ToMesh();
 }
示例#2
0
        /// <summary>
        /// Called when the visual changed.
        /// </summary>
        private void VisualChanged()
        {
            if (this.Items == null)
            {
                this.Content = null;
                return;
            }

            var items = this.Items.Where(i => !string.IsNullOrEmpty(i.Text)).ToList();
            var group = new Model3DGroup();
            while (items.Count > 0)
            {
                Dictionary<string, FrameworkElement> elementMap;
                Dictionary<FrameworkElement, Rect> elementPositions;
                var material = CreateTextMaterial(items, this.CreateElement, this.Background, out elementMap, out elementPositions);

                var builder = new MeshBuilder(false, true);
                var addedChildren = new List<SpatialTextItem>();
                foreach (var item in items)
                {
                    var element = elementMap[item.Text];
                    var r = elementPositions[element];
                    double u0 = r.Left;
                    double v0 = r.Top;
                    double u1 = r.Right;
                    double v1 = r.Bottom;
                    if (v1 > 1)
                    {
                        break;
                    }

                    if (this.IsFlipped)
                    {
                        var tmp = u0;
                        u0 = u1;
                        u1 = tmp;
                    }

                    // Set horizontal alignment factor
                    var xa = -0.5;
                    if (item.HorizontalAlignment == HorizontalAlignment.Left)
                    {
                        xa = 0;
                    }

                    if (item.HorizontalAlignment == HorizontalAlignment.Right)
                    {
                        xa = -1;
                    }

                    // Set vertical alignment factor
                    var ya = -0.5;
                    if (item.VerticalAlignment == VerticalAlignment.Top)
                    {
                        ya = -1;
                    }

                    if (item.VerticalAlignment == VerticalAlignment.Bottom)
                    {
                        ya = 0;
                    }

                    var position = item.Position;
                    var textDirection = item.TextDirection;
                    var upDirection = item.UpDirection;
                    var height = this.Height;
                    var width = this.Height / element.ActualHeight * element.ActualWidth;
                    var p0 = position + ((xa * width) * textDirection) + ((ya * height) * upDirection);
                    var p1 = p0 + (textDirection * width);
                    var p2 = p0 + (upDirection * height) + (textDirection * width);
                    var p3 = p0 + (upDirection * height);
                    builder.AddQuad(p0, p1, p2, p3, new Point(u0, v1), new Point(u1, v1), new Point(u1, v0), new Point(u0, v0));

                    if (this.IsDoubleSided)
                    {
                        builder.AddQuad(p1, p0, p3, p2, new Point(u0, v1), new Point(u1, v1), new Point(u1, v0), new Point(u0, v0));
                    }

                    addedChildren.Add(item);
                }

                var mg = builder.ToMesh();
                group.Children.Add(new GeometryModel3D(mg, material));

                foreach (var c in addedChildren)
                {
                    items.Remove(c);
                }
            }

            this.Content = group;
        }
 /// <summary>
 /// Creates the ground geometry.
 /// </summary>
 /// <param name="themaze">
 /// The maze.
 /// </param>
 /// <param name="padding">
 /// The padding.
 /// </param>
 /// <param name="z">
 /// The z.
 /// </param>
 /// <returns>
 /// The geometry.
 /// </returns>
 private MeshGeometry3D CreateGroundGeometry(bool[,] themaze, int padding = 0, double z = 0)
 {
     int m = themaze.GetUpperBound(0) + 1;
     int n = themaze.GetUpperBound(1) + 1;
     var builder = new MeshBuilder();
     builder.AddQuad(
         this.GetPosition(-1 - padding, -1 - padding, z),
         this.GetPosition(m + padding, -1 - padding, z),
         this.GetPosition(m + padding, n + padding, z),
         this.GetPosition(-1 - padding, n + padding, z));
     return builder.ToMesh();
 }
示例#4
0
 /// <summary>
 /// Do the tessellation and return the <see cref="MeshGeometry3D"/>.
 /// </summary>
 /// <returns>A triangular mesh geometry.</returns>
 protected override MeshGeometry3D Tessellate()
 {
     var builder = new MeshBuilder(false, true);
     builder.AddQuad(
         this.Point1,
         this.Point2,
         this.Point3,
         this.Point4,
         new Point(0, 1),
         new Point(1, 1),
         new Point(1, 0),
         new Point(0, 0));
     return builder.ToMesh();
 }
示例#5
0
        private void AppearanceChanged()
        {
            var builder = new MeshBuilder(false, false);
            foreach (var p1 in DistributePoles(this.Positions, this.PoleDistance))
            {
                var p2 = p1 + new Vector3D(0, 0, this.Height);
                builder.AddCylinder(p1, p2, this.Diameter, 36);
            }

            this.postsModel.Geometry = builder.ToMesh();

            var fenceBuilder = new MeshBuilder(false, true);
            var w0 = 0d;
            for (int i = 0; i + 1 < this.Positions.Count; i++)
            {
                var p0 = this.Positions[i];
                var p1 = this.Positions[i + 1];
                var p2 = this.Positions[i + 1] + new Vector3D(0, 0, this.Height);
                var p3 = this.Positions[i] + new Vector3D(0, 0, this.Height);
                var h = this.Height / this.MeshSize;
                var dw = p0.DistanceTo(p1) / this.MeshSize;
                fenceBuilder.AddQuad(
                    p0,
                    p1,
                    p2,
                    p3,
                    new Point(w0, h),
                    new Point(w0 + dw, h),
                    new Point(w0 + dw, 0),
                    new Point(w0, 0));
                w0 += dw;
            }

            this.fenceModel.Geometry = fenceBuilder.ToMesh();
        }
      protected override MeshGeometry3D Tessellate()
      {
         // A quadrilateral defined by the four corner points.
         // tl              tr
         // +---------------+
         // |               |
         // |               |
         // +---------------+
         // bl              br

         // The texture coordinates are
         // (0,0)           (1,0)
         // +---------------+
         // |               |
         // |               |
         // +---------------+
         // (0,1)          (1,1)

         MeshBuilder builder = new MeshBuilder(false, true);
         // Initially use defaults
         Vector3D upVector = new Vector3D(0, 0, 1);
         Vector3D observerVector = new Vector3D(0, 1, 0);

         // Get the value from the camera if a camera exists.
         Viewport3D viewport = this.GetViewport3D();
         if (viewport != null) {
            ProjectionCamera camera = viewport.Camera as ProjectionCamera;
            if (camera != null) {
               Point3D cameraPosition = camera.Position;
               // Get direction to observer
               //upVector = camera.UpDirection;
               observerVector = Origin - camera.Position;
            }
         }
         observerVector.Normalize();
         upVector.Normalize();
         Vector3D widthVector = Vector3D.CrossProduct(upVector, observerVector);
         widthVector.Normalize();
         Vector3D heightVector = Vector3D.CrossProduct(widthVector, observerVector);
         heightVector.Normalize();
         

         Vector3D halfWidthVector = widthVector * Width * 0.5;
         Vector3D halfHeightVector = heightVector * Height * 0.5;
         // Centre of billboard
         Point3D centrePoint = Origin - (observerVector * OriginOffset);
         // Bottom-left corner to visual space
         Point3D bl = centrePoint + halfWidthVector + halfHeightVector;
         // Bottom-right corner to visual space
         Point3D br = centrePoint - halfWidthVector + halfHeightVector;
         // Top-right corner to visual space
         Point3D tr = centrePoint - halfWidthVector - halfHeightVector;
         // Top-left corner to visual space
         Point3D tl = centrePoint + halfWidthVector - halfHeightVector;
         builder.AddQuad(bl, br, tr, tl,
                  new Point(0, 1),
                new Point(1, 1),
                new Point(1, 0),
                new Point(0, 0)
                );
                //  new Point(0, 1),
                //new Point(1, 1),
                //new Point(1, 0),
                //new Point(0, 0));
         return builder.ToMesh();

      }
        public List<MeshIdandGeometry> VisualizeBimPlusDataAsGenericElements(List<GenericElement> baseElements, object sender)
        {
            if (InputPorts[0].Data == null)
                return null;

            var max = baseElements.Count;
            var m_i = 1;

            // Init some lists and containers
            var container = new ContainerUIElement3D();
            var geometry = new List<MeshIdandGeometry>();

            // Init the MeshBuilde
            var meshBuilder = new MeshBuilder(false, false);

            // Loop the items of each list
            foreach (var item in baseElements)
            {
                // Get the geometric data from the AttributeGroups
                var points = item.AttributeGroups["geometry"].Attributes["threejspoints"] as IList<Point3D>;
                var triangleindices = item.AttributeGroups["geometry"].Attributes["geometryindices"];
                var indices =
                    (from index in triangleindices as IList<uint> select Convert.ToInt32(index)).ToList();

                for (var i = 0; i < indices.Count; i++)
                {
                    if (indices[i] == 0)
                    {
                        meshBuilder.AddTriangle(points[indices[i + 1]], points[indices[i + 2]],
                            points[indices[i + 3]]);

                        i = i + 3;
                    }
                    else if (indices[i] == 1)
                    {
                        meshBuilder.AddQuad(points[indices[i + 1]], points[indices[i + 2]],
                            points[indices[i + 3]],
                            points[indices[i + 4]]);
                        i = i + 4;
                    }
                }

                // Get the color of each representation group
                var color = Convert.ToInt64(item.AttributeGroups["geometry"].Attributes["color"]);
                var tempcolor = Color.FromArgb((int)color);

                var col = new System.Windows.Media.Color
                {
                    A = tempcolor.A,
                    G = tempcolor.G,
                    R = tempcolor.R,
                    B = tempcolor.B
                };

                var myGeometryModel = new GeometryModel3D
                {
                    Material = new DiffuseMaterial(new SolidColorBrush(col)),
                    BackMaterial = new DiffuseMaterial(new SolidColorBrush(col)),
                    Geometry = meshBuilder.ToMesh(true),
                    Transform = new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(1, 0, 0), 90))
                };

                myGeometryModel.Freeze();

                var meshAndId = new MeshIdandGeometry
                {
                    Id = item.Id,
                    Model3D = myGeometryModel,
                    Material = myGeometryModel.Material
                };

                geometry.Add(meshAndId);

                // Save the parsed information in the elements attribute group
                item.AttributeGroups["geometry"].Attributes["parsedGeometry"] = meshAndId;

                // Refresh the builder so that we do not duplicate the meshes 
                meshBuilder = new MeshBuilder(false, false);

                m_i++;
                var progressPercentage = Convert.ToInt32(((double)m_i / max) * 100);
                var backgroundWorker = sender as BackgroundWorker;
                backgroundWorker?.ReportProgress(progressPercentage, item.Id);
            }

            container.Children.Clear();
            return geometry;
        }
        public MeshGeometry3D MeshObject(DtObject item, MeshBuilder meshBuilder)
        {
            var points = item.AttributeGroups["geometry"].GetProperty("threejspoints") as List<Point3D>;
            var indices = item.AttributeGroups["geometry"].GetProperty("geometryindices") as List<uint>;

            if (indices == null)
                return null;

            for (var i = 0; i < indices.Count; i++)
            {
                switch (indices[i])
                {
                    case 0:
                        meshBuilder.AddTriangle(points[(int)indices[i + 1]], points[(int)indices[i + 2]],
                            points[(int)indices[i + 3]]);

                        i = i + 3;
                        break;
                    case 1:
                        meshBuilder.AddQuad(points[(int)indices[i + 1]], points[(int)indices[i + 2]],
                            points[(int)indices[i + 3]],
                            points[(int)indices[i + 4]]);
                        i = i + 4;
                        break;
                }
            }
            return meshBuilder.ToMesh(true);
        }
示例#9
0
		public void GetModel(MeshGeometryVisual3D mesh)
		{
			MeshBuilder mb = new MeshBuilder(false, true);

			double Hdelta = MaxHeight - MinHeight;

			for (int x = 0; x < SizeX - 1; x++)
			{
				for (int y = 0; y < SizeY - 1; y++)
				{
					if (!Points[x, y].HasValue || !Points[x, y + 1].HasValue || !Points[x + 1, y].HasValue || !Points[x + 1, y + 1].HasValue)
						continue;

					mb.AddQuad(
						new Point3D(Min.X + (x + 1) * Delta.X / (SizeX - 1), Min.Y + (y) * Delta.Y / (SizeY - 1), Points[x + 1, y].Value),
						new Point3D(Min.X + (x + 1) * Delta.X / (SizeX - 1), Min.Y + (y + 1) * Delta.Y / (SizeY - 1), Points[x + 1, y + 1].Value),
						new Point3D(Min.X + (x) * Delta.X / (SizeX - 1), Min.Y + (y + 1) * Delta.Y / (SizeY - 1), Points[x, y + 1].Value),
						new Point3D(Min.X + (x) * Delta.X / (SizeX - 1), Min.Y + (y) * Delta.Y / (SizeY - 1), Points[x, y].Value),
						new Point(0, (Points[x + 1, y].Value - MinHeight) * Hdelta),
						new Point(0, (Points[x + 1, y + 1].Value - MinHeight) * Hdelta),
						new Point(0, (Points[x, y + 1].Value - MinHeight) * Hdelta),
						new Point(0, (Points[x, y].Value - MinHeight) * Hdelta)
						);
				}
			}

			mesh.MeshGeometry = mb.ToMesh();
		}