/// <summary> /// Sets the coordinates of all the individual lines in the visual. /// </summary> /// <param name="args"> /// The <c>DependencyPropertyChangedEventArgs</c> object associated /// with the property-changed event that resulted in this method /// being called. /// </param> /// <param name="lines"> /// The <c>Point3DCollection</c> to be filled. /// </param> /// <remarks> /// <para> /// Classes that derive from <c>WireBase</c> override this /// method to fill the <c>lines</c> collection. /// It is custmary for implementations of this method to clear /// the <c>lines</c> collection first before filling it. /// Each pair of successive members of the <c>lines</c> /// collection indicate one straight line. /// </para> /// <para> /// The <c>WireLine</c> class implements this method by /// clearing the <c>lines</c> collection and then adding /// <c>Point1</c> and <c>Point2</c> to the collection. /// </para> /// </remarks> protected override void Generate(DependencyPropertyChangedEventArgs args, Point3DCollection lines) { lines.Clear(); lines.Add(Point1); lines.Add(Point2); }
/* internal void drawLine(Point3D start, Point3D pt, bool hit) { TubeVisual3D line; lines.TryGetValue(start, out line); if (line != null) { this.Children.Remove(line); lines.Remove(start); } Point3DCollection contours = new Point3DCollection(); contours.Add(ToWorld(start)); contours.Add(ToWorld(pt)); line = new TubeVisual3D { Diameter = 0.5, Path = contours, Fill = Brushes.SandyBrown }; lines.Add(start,line); this.Children.Add(line); addBox(start); if(hit) addBox(pt); } */ internal void drawLine(Point3D start, Point3D end) { TubeVisual3D line; lines.TryGetValue(start, out line); if (line != null) { this.Children.Remove(line); lines.Remove(start); } Point3DCollection contours = new Point3DCollection(); contours.Add(ToWorld(start)); contours.Add(ToWorld(end)); line = new TubeVisual3D { Diameter = 0.3, Path = contours, Fill = Brushes.DarkOliveGreen}; lines.Add(start, line); this.Children.Add(line); string x = string.Format("{0:0.00}",end.X); string y = string.Format("{0:0.00}", end.Y); string z = string.Format("{0:0.00}", end.Z); string text = x + "," + y + "," + z; addBox(start); addBox(end); add3DText(end, text); }
public static MeshGeometry3D CreateRectangle(double height, double width) { var vertices = new Point3DCollection(); var normals = new Vector3DCollection(); var facets = new Int32Collection(); var textureCoords = new PointCollection(); vertices.Add(new Point3D(-width / 2, 0, -height / 2)); vertices.Add(new Point3D(-width / 2, 0, height / 2)); vertices.Add(new Point3D(width / 2, 0, -height / 2)); vertices.Add(new Point3D(width / 2, 0, height / 2)); normals.Add(new Vector3D(0, -1, 0)); normals.Add(new Vector3D(0, -1, 0)); normals.Add(new Vector3D(0, -1, 0)); normals.Add(new Vector3D(0, -1, 0)); textureCoords.Add(new Point(1,1)); textureCoords.Add(new Point(1, 0)); textureCoords.Add(new Point(0,1)); textureCoords.Add(new Point(0,0)); facets.Add(0); facets.Add(1); facets.Add(2); facets.Add(3); facets.Add(2); facets.Add(1); var rectangle = new MeshGeometry3D(); rectangle.Positions = vertices; rectangle.Normals = normals; rectangle.TriangleIndices = facets; rectangle.TextureCoordinates = textureCoords; return rectangle; }
protected override void ProcessFigure(CircularList<Point> list, Point3DCollection vertices, Vector3DCollection normals, Int32Collection indices, PointCollection textures) { int offset = vertices.Count; for (int i = 0; i <= list.Count; i++) { Point pt = list[i]; // Set vertices. vertices.Add(new Point3D(pt.X, pt.Y, 0)); vertices.Add(new Point3D(pt.X, pt.Y, -Depth)); // Set texture coordinates. textures.Add(new Point((double)i / list.Count, 0)); textures.Add(new Point((double)i / list.Count, 1)); // Set triangle indices. if (i < list.Count) { indices.Add(offset + i * 2 + 0); indices.Add(offset + i * 2 + 2); indices.Add(offset + i * 2 + 1); indices.Add(offset + i * 2 + 1); indices.Add(offset + i * 2 + 2); indices.Add(offset + i * 2 + 3); } } }
private static void OnNumberOfSidesChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { WheelMesh wheel = (WheelMesh)d; Point3DCollection points = new Point3DCollection(3 + wheel.NumberOfSides - 2); Int32Collection triangles = new Int32Collection(wheel.NumberOfSides); // Center points.Add(new Point3D(wheel.Radius, wheel.Radius, wheel.Height)); // Top points.Add(new Point3D(wheel.Radius, 0, 0)); for (int i = 1; i < wheel.NumberOfSides; i++) { double beta = 2 * Math.PI / wheel.NumberOfSides * i; double alpha = (Math.PI - beta) / 2; double length = 2 * wheel.Radius * Math.Sin(beta / 2); double x = length * Math.Cos(Math.PI / 2 - alpha); double y = length * Math.Sin(Math.PI / 2 - alpha); points.Add(new Point3D(wheel.Radius + x, y, 0)); triangles.Add(0); triangles.Add(i); triangles.Add(i+1); } triangles.Add(0); triangles.Add(wheel.NumberOfSides); triangles.Add(1); wheel.SetValue(PointsProperty, points); wheel.SetValue(TriangleIndicesProperty, triangles); }
private static void AddCircleInZCross(MeshBuilder mb, Point3D centre, double radius, int div) { var points = MeshBuilder.GetCircle(div); var vectors = new Point3DCollection(); var normals = new Vector3DCollection(); var textures = new PointCollection(); vectors.Add(new Point3D(centre.X, centre.Y, 0)); normals.Add(new Vector3D(0, 0, 1)); textures.Add(new Point(0.5, 0.5)); for (int i = 0; i < points.Count - 1; i++) { vectors.Add(new Point3D(points[i].X * radius + centre.X, points[i].Y * radius + centre.Y, centre.Z)); normals.Add(new Vector3D(0, 0, -1)); textures.Add(new Point(points[i].X * 0.5 + 0.5, points[i].Y * 0.5 + 0.5)); vectors.Add(new Point3D(points[i + 1].X * radius + centre.X, points[i + 1].Y * radius + centre.Y, centre.Z)); normals.Add(new Vector3D(0, 0, 01)); textures.Add(new Point(points[i + 1].X * 0.5 + 0.5, points[i + 1].Y * 0.5 + 0.5)); } mb.AddTriangleFan(vectors, normals, textures); }
/// <summary> /// Sets the coordinates of all the individual lines in the visual. /// </summary> /// <param name="args"> /// The <c>DependencyPropertyChangedEventArgs</c> object associated /// with the property-changed event that resulted in this method /// being called. /// </param> /// <param name="lines"> /// The <c>Point3DCollection</c> to be filled. /// </param> /// <remarks> /// <para> /// Classes that derive from <c>WireBase</c> override this /// method to fill the <c>lines</c> collection. /// It is custmary for implementations of this method to clear /// the <c>lines</c> collection first before filling it. /// Each pair of successive members of the <c>lines</c> /// collection indicate one straight line. /// </para> /// <para> /// The <c>WirePolyline</c> class implements this method by /// clearing the <c>lines</c> collection and then breaking /// down its <c>Points</c> collection into individual lines /// and then adding the start and end points to the collection. /// </para> /// </remarks> protected override void Generate(DependencyPropertyChangedEventArgs args, Point3DCollection lines) { Point3DCollection points = Points; lines.Clear(); for (int i = 0; i < points.Count - 1; i++) { lines.Add(points[i]); lines.Add(points[i + 1]); } }
public static Point3DCollection CombinePointCollection(Point3DCollection initialPOints, List<XbimPoint3D> points) { var ret = new Point3DCollection(initialPOints.Count + points.Count); foreach (var enumPoint in initialPOints) { ret.Add(enumPoint); } foreach (var enumPoint in points) { ret.Add(new Point3D(enumPoint.X, enumPoint.Y, enumPoint.Z)); } return ret; }
private Point3DCollection CreateMeshPositions() { double aspect = ElementWidth/ElementHeight; double reflectionFactor = HasReflection ? 1.0 : 0.5; Point3DCollection positions = new Point3DCollection(); positions.Add(new Point3D(-aspect/2, 1*reflectionFactor, 0)); positions.Add(new Point3D(aspect/2, 1*reflectionFactor, 0)); positions.Add(new Point3D(aspect/2, -1*reflectionFactor, 0)); positions.Add(new Point3D(-aspect/2, -1*reflectionFactor, 0)); return positions; }
public VideoSurface(string mediaSource) { this.ModelVisual3D = new ModelVisual3D(); var geometryModel = new GeometryModel3D(); this.ModelVisual3D.Content = geometryModel; this.geometry = new MeshGeometry3D(); geometryModel.Geometry = geometry; var positions = new Point3DCollection(); positions.Add(new Point3D(0, 0, 0)); positions.Add(new Point3D(640, 0, 0)); positions.Add(new Point3D(640, 480, 0)); positions.Add(new Point3D(0, 480, 0)); this.geometry.Positions = positions; var textureCoordinates = new PointCollection(); textureCoordinates.Add(new System.Windows.Point(0, 1)); textureCoordinates.Add(new System.Windows.Point(1, 1)); textureCoordinates.Add(new System.Windows.Point(1, 0)); textureCoordinates.Add(new System.Windows.Point(0, 0)); this.geometry.TextureCoordinates = textureCoordinates; var triangleIndices = new Int32Collection(); triangleIndices.Add(0); triangleIndices.Add(1); triangleIndices.Add(2); triangleIndices.Add(2); triangleIndices.Add(3); triangleIndices.Add(0); this.geometry.TriangleIndices = triangleIndices; var material = new EmissiveMaterial(); var brush = new VisualBrush(); this.border = new Border(); this.border.BorderBrush = Brushes.White; this.border.BorderThickness = new Thickness(10); this.border.Opacity = 0; this.mediaElement = new MediaElement(); mediaElement.LoadedBehavior = MediaState.Manual; mediaElement.Source = new Uri(mediaSource); this.border.Child = mediaElement; brush.Visual = border; material.Brush = brush; geometryModel.Material = material; this.mediaElement.MediaEnded += new RoutedEventHandler(mediaElement_MediaEnded); }
protected override void CalculateGeometry() { int e; double segmentRad = Math.PI / 2 / (n + 1); points = new Point3DCollection(); triangleIndices = new Int32Collection(); for (e = -n; e <= n; e++) { double r_e = r * Math.Cos(segmentRad * e); double y_e = r * Math.Sin(segmentRad * e); for (int s = 0; s <= (4 * n + 4 - 1); s++) { double z_s = r_e * Math.Sin(segmentRad * s) * (-1); double x_s = r_e * Math.Cos(segmentRad * s); points.Add(new Point3D(x_s, y_e, z_s)); } } points.Add(new Point3D(0, r, 0)); points.Add(new Point3D(0, -1 * r, 0)); for (e = 0; e < 2 * n; e++) { for (int i = 0; i < (4 * n + 4); i++) { triangleIndices.Add(e * (4 * n + 4) + i); triangleIndices.Add(e * (4 * n + 4) + i + (4 * n + 4)); triangleIndices.Add(e * (4 * n + 4) + (i + 1) % (4 * n + 4) + (4 * n + 4)); triangleIndices.Add(e * (4 * n + 4) + (i + 1) % (4 * n + 4) + (4 * n + 4)); triangleIndices.Add(e * (4 * n + 4) + (i + 1) % (4 * n + 4)); triangleIndices.Add(e * (4 * n + 4) + i); } } for (int i = 0; i < (4 * n + 4); i++) { triangleIndices.Add(e * (4 * n + 4) + i); triangleIndices.Add(e * (4 * n + 4) + (i + 1) % (4 * n + 4)); triangleIndices.Add((4 * n + 4) * (2 * n + 1)); } for (int i = 0; i < (4 * n + 4); i++) { triangleIndices.Add(i); triangleIndices.Add((i + 1) % (4 * n + 4)); triangleIndices.Add((4 * n + 4) * (2 * n + 1) + 1); } }
private Point3DCollection GeneratePoints() { int n = _geomPoints.Count; var result = new Point3DCollection(_geomPoints.Count); for (int i = 0; i < n; i++) { var pt = _geomPoints[i].Point; result.Add(pt); if (i > 0 && i < n - 1) result.Add(pt); } return result; }
private void sampleSelected(object sender, RoutedEventArgs args) { Point3DCollection points = new Point3DCollection(); double ratio = myScrollViewer.ActualWidth / myScrollViewer.ActualHeight; points.Add(new Point3D(5, -5 * ratio, 0)); points.Add(new Point3D(5, 5 * ratio, 0)); points.Add(new Point3D(-5, 5 * ratio, 0)); points.Add(new Point3D(-5, 5 * ratio, 0)); points.Add(new Point3D(-5, -5 * ratio, 0)); points.Add(new Point3D(5, -5 * ratio, 0)); points.Add(new Point3D(-5, 5 * ratio, 0)); points.Add(new Point3D(-5, -5 * ratio, 0)); points.Add(new Point3D(5, -5 * ratio, 0)); points.Add(new Point3D(5, -5 * ratio, 0)); points.Add(new Point3D(5, 5 * ratio, 0)); points.Add(new Point3D(-5, 5 * ratio, 0)); myGeometry.Positions = points; myViewport3D.Width = 100; myViewport3D.Height = 100 * ratio; scrollViewerBorder.Visibility = Visibility.Hidden; RadioButton button = sender as RadioButton; if (button != null) { if (button.Content.ToString() == "Geometry Usage") sampleIndex = 0; else if (button.Content.ToString() == "Shape Geometries") sampleIndex = 1; else if (button.Content.ToString() == "PathGeometry") sampleIndex = 2; else if (button.Content.ToString() == "Combining Geometries Example") sampleIndex = 3; else if (button.Content.ToString() == "Geometry Attribute Syntax Example") sampleIndex = 4; } }
private void CreateModel() { var points = new Point3DCollection(); var edges = new Int32Collection(); var triangles = new Int32Collection(); switch (CurrentModelType) { case ModelTypes.StellatedOctahedron: case ModelTypes.Tetrahedron: points.Add(+1, +1, +1); points.Add(-1, -1, 1); points.Add(-1, +1, -1); points.Add(+1, -1, -1); edges.Add(0, 1, 1, 2, 2, 0, 0, 3, 1, 3, 2, 3); triangles.Add(0, 1, 2, 0, 3, 1, 1, 3, 2, 2, 3, 0); break; } switch (CurrentModelType) { case ModelTypes.StellatedOctahedron: // http://en.wikipedia.org/wiki/Compound_of_two_tetrahedra points.Add(-1, +1, +1); points.Add(1, -1, 1); points.Add(1, +1, -1); points.Add(-1, -1, -1); edges.Add(4, 5, 5, 6, 6, 4, 4, 7, 5, 7, 6, 7); triangles.Add(4, 5, 6, 4, 7, 5, 5, 7, 6, 6, 7, 4); break; } var m = new Model3DGroup(); // Add the nodes var gm = new MeshBuilder(); foreach (var p in points) { gm.AddSphere(p, 0.1); } m.Children.Add(new GeometryModel3D(gm.ToMesh(), Materials.Gold)); // Add the triangles var tm = new MeshBuilder(); for (int i = 0; i < triangles.Count; i += 3) { tm.AddTriangle(points[triangles[i]], points[triangles[i + 1]], points[triangles[i + 2]]); } m.Children.Add(new GeometryModel3D(tm.ToMesh(), Materials.Red) { BackMaterial = Materials.Blue }); // Add the edges var em = new MeshBuilder(); for (int i = 0; i < edges.Count; i += 2) { em.AddCylinder(points[edges[i]], points[edges[i + 1]], 0.08, 10); } m.Children.Add(new GeometryModel3D(em.ToMesh(), Materials.Gray)); Model = m; }
public void receiveCurveFromMaya(string node_name, out Point3DCollection controlVertices, out List<double> weights, out List<double> knots, out int degree, out bool closed, out bool rational) { MPlug plLocal = getPlug(node_name, "local"); MObject oLocal = new MObject(); plLocal.getValue(oLocal); MFnNurbsCurve nc = new MFnNurbsCurve(oLocal); MPointArray p_aCVs = new MPointArray(); nc.getCVs(p_aCVs, MSpace.Space.kWorld); controlVertices = new Point3DCollection(); weights = new List<double>(); foreach (MPoint p in p_aCVs) { controlVertices.Add(new Point3D(p.x, p.y, p.z)); weights.Add(1.0); } double min = 0, max = 0; nc.getKnotDomain(ref min, ref max); MDoubleArray d_aKnots = new MDoubleArray(); nc.getKnots(d_aKnots); knots = new List<double>(); knots.Add(min); foreach (double d in d_aKnots) { knots.Add(d); } knots.Add(max); degree = nc.degree; closed = nc.form == MFnNurbsCurve.Form.kClosed ? true : false; rational = true; }
protected override void Triangulate(DependencyPropertyChangedEventArgs args, Point3DCollection vertices, Vector3DCollection normals, Int32Collection indices, PointCollection textures) { vertices.Clear(); normals.Clear(); indices.Clear(); textures.Clear(); MeshGeometry3D mesh = MeshGenerator.Geometry; foreach (Point3D vertex in mesh.Positions) vertices.Add(vertex); foreach (Vector3D normal in mesh.Normals) normals.Add(normal); foreach (int index in mesh.TriangleIndices) indices.Add(index); foreach (Point texture in mesh.TextureCoordinates) textures.Add(texture); }
public Point3DCollection FillMesh(int xVertices, int yVertices, double aspect) { LineEvaluator hLine = new LineEvaluator(); hLine.Point1 = new Point3D(-aspect/2, 0, 0); hLine.Point2 = new Point3D(aspect/2, 0, 0); LineEvaluator vLine = new LineEvaluator(); vLine.Point1 = new Point3D(0, 0.5, 0); vLine.Point2 = new Point3D(0, -0.5, 0); Point3DCollection positions = new Point3DCollection(); for (int y = 0; y < yVertices; y++) { double vT = (double) y/(yVertices - 1); Point3D vPoint = vLine.Evaluate(vT); for (int x = 0; x < xVertices; x++) { double hT = (double) x/(xVertices - 1); Point3D hPoint = hLine.Evaluate(hT); positions.Add(new Point3D(hPoint.X, vPoint.Y, 0)); } } return positions; }
/// <summary> /// Sets the coordinates of all the individual lines in the visual. /// </summary> /// <param name="args"> /// The <c>DependencyPropertyChangedEventArgs</c> object associated /// with the property-changed event that resulted in this method /// being called. /// </param> /// <param name="lines"> /// The <c>Point3DCollection</c> to be filled. /// </param> /// <remarks> /// <para> /// Classes that derive from <c>WireBase</c> override this /// method to fill the <c>lines</c> collection. /// It is custmary for implementations of this method to clear /// the <c>lines</c> collection first before filling it. /// Each pair of successive members of the <c>lines</c> /// collection indicate one straight line. /// </para> /// </remarks> protected override void Generate(DependencyPropertyChangedEventArgs args, Point3DCollection lines) { lines.Clear(); if (Data == null) return; Transform3D xform = Data.Transform; foreach (PathFigure3D fig in Data.Figures) { PathFigure3D figFlattened = fig.GetFlattenedPathFigure(); Point3D pointStart = xform.Transform(figFlattened.StartPoint); foreach (PathSegment3D seg in figFlattened.Segments) { PolyLineSegment3D segPoly = seg as PolyLineSegment3D; for (int i = 0; i < segPoly.Points.Count; i++) { lines.Add(pointStart); Point3D point = xform.Transform(segPoly.Points[i]); lines.Add(point); pointStart = point; } } } }
public override object ProvideValue(IServiceProvider serviceProvider) { var c = new Point3DCollection(); int m = 400; for (int i = 0; i + 1 < m; i++) { double t = 2 * Math.PI * i / (m - 2); c.Add(new Point3D( this.a * Math.Sign(Math.Cos(t)) * Math.Pow(Math.Abs(Math.Cos(t)), 2 / this.n), this.b * Math.Sign(Math.Sin(t)) * Math.Pow(Math.Abs(Math.Sin(t)), 2 / this.n), 0)); } c.Add(c[0]); return c; }
/// <summary> /// Sets the coordinates of all the individual lines in the visual. /// </summary> /// <param name="args"> /// The <c>DependencyPropertyChangedEventArgs</c> object associated /// with the property-changed event that resulted in this method /// being called. /// </param> /// <param name="lines"> /// The <c>Point3DCollection</c> to be filled. /// </param> /// <remarks> /// <para> /// Classes that derive from <c>WireBase</c> override this /// method to fill the <c>lines</c> collection. /// It is custmary for implementations of this method to clear /// the <c>lines</c> collection first before filling it. /// Each pair of successive members of the <c>lines</c> /// collection indicate one straight line. /// </para> /// <para> /// The <c>WireLines</c> class implements this method by /// clearing the <c>lines</c> collection and then copying /// its own <c>Lines</c> collection to it. /// </para> /// </remarks> protected override void Generate(DependencyPropertyChangedEventArgs args, Point3DCollection lines) { lines.Clear(); foreach (Point3D point in Lines) lines.Add(point); }
void contours(Brush b) { model = new Wire(); model.Brace1 = brace1.Model; model.Brace2 = brace2.Model; Point3D c1 = brace1.centroid(); Point3D c2 = brace2.centroid(); /* int n = 6; // Create the data to be fitted float[] x = new float[n]; float[] y = new float[n]; Random rand = new Random(1); float xf = (float)(c2.X - c1.X)/n; float yf = (float)(c2.Y - c1.Y) / n; for (int i = 0; i < n; i++) { x[i] = (float) c1.X + (i * xf); y[i] = (float) c1.Y + (i * yf); } int upsampleFactor = 10; int nInterpolated = n * upsampleFactor; float[] xs = new float[nInterpolated]; for (int i = 0; i < nInterpolated; i++) { xs[i] = (float)i * (n - 1) / (float)(nInterpolated - 1); } CubicSpline spline = new CubicSpline(); float[] ys = spline.FitAndEval(x, y, xs, true); */ Point3DCollection contours = new Point3DCollection(); contours.Add(brace1.ToWorld(c1)); /*for (int i = 0; i < xs.Length; i++) { contours.Add(new Point3D(xs[i], ys[i], c1.Z)); }*/ contours.Add(brace2.ToWorld(c2)); this.Children.Clear(); TubeVisual3D tube = new TubeVisual3D { Diameter = 1.02, Path = contours, Fill = b }; this.Children.Add(tube); }
protected override void CalculateGeometry() { int numberOfSeparators = 4 * n + 4; points = new Point3DCollection(numberOfSeparators + 1); triangleIndices = new Int32Collection((numberOfSeparators + 1) * 3); points.Add(new Point3D(0, 0, 0)); for (int divider = 0; divider < numberOfSeparators; divider++) { double alpha = Math.PI / 2 / (n + 1) * divider; points.Add(new Point3D(r * Math.Cos(alpha), 0, -1 * r * Math.Sin(alpha))); triangleIndices.Add(0); triangleIndices.Add(divider + 1); triangleIndices.Add((divider == (numberOfSeparators - 1)) ? 1 : (divider + 2)); } }
public static Point3DCollection GetPointCollection(List<XbimPoint3D> points) { var ret = new Point3DCollection(points.Count); foreach (var enumPoint in points) { ret.Add(new Point3D(enumPoint.X, enumPoint.Y, enumPoint.Z)); } return ret; }
public Point3DCollection GenerateVertices() { Point3DCollection points=new Point3DCollection(); Point3D point; for(int i=0;i<VertexNormals.Count;i++) { point=new Point3D(VertexNormals[i].Vertex.X,VertexNormals[i].Vertex.Y,VertexNormals[i].Vertex.Z); points.Add(point); } return points; }
public ArrayList decode() { ArrayList array = new ArrayList(); _mesh = new Point3DCollection(); _normals = new Vector3DCollection(); array.Add(_mesh); array.Add(_normals); for (int i = 0; i < _parser.numTriangles; i++) { ArrayList collection = _parser.index(i); _mesh.Add((Point3D)collection[INDEX_VERTEX0]); _mesh.Add((Point3D)collection[INDEX_VERTEX1]); _mesh.Add((Point3D)collection[INDEX_VERTEX2]); _normals.Add((Vector3D)collection[INDEX_NORMAL]); } return array; }
/// <summary> /// Updates the box. /// </summary> protected virtual void OnBoxChanged() { if (this.BoundingBox.IsEmpty) { this.Points = null; return; } var points = new Point3DCollection(); var bb = this.BoundingBox; var p0 = new Point3D(bb.X, bb.Y, bb.Z); var p1 = new Point3D(bb.X, bb.Y + bb.SizeY, bb.Z); var p2 = new Point3D(bb.X + bb.SizeX, bb.Y + bb.SizeY, bb.Z); var p3 = new Point3D(bb.X + bb.SizeX, bb.Y, bb.Z); var p4 = new Point3D(bb.X, bb.Y, bb.Z + bb.SizeZ); var p5 = new Point3D(bb.X, bb.Y + bb.SizeY, bb.Z + bb.SizeZ); var p6 = new Point3D(bb.X + bb.SizeX, bb.Y + bb.SizeY, bb.Z + bb.SizeZ); var p7 = new Point3D(bb.X + bb.SizeX, bb.Y, bb.Z + bb.SizeZ); Action<Point3D, Point3D> addEdge = (p, q) => { points.Add(p); points.Add(q); }; addEdge(p0, p1); addEdge(p1, p2); addEdge(p2, p3); addEdge(p3, p0); addEdge(p4, p5); addEdge(p5, p6); addEdge(p6, p7); addEdge(p7, p4); addEdge(p0, p4); addEdge(p1, p5); addEdge(p2, p6); addEdge(p3, p7); this.Points = points; }
private Point3DCollection CreateMeshPositions() { double eltHeight = HasReflection ? ElementHeight / 2 : ElementHeight; double aspect = ElementWidth / eltHeight; double reflectionFactor = HasReflection ? 1.0 : 0.5; Point3DCollection positions = new Point3DCollection(); positions.Add(new Point3D(-aspect / 2, 1 * reflectionFactor, 0)); positions.Add(new Point3D(aspect / 2, 1 * reflectionFactor, 0)); positions.Add(new Point3D(aspect / 2, -1 * reflectionFactor, 0)); positions.Add(new Point3D(-aspect / 2, -1 * reflectionFactor, 0)); // double x = 0.6; // double y = 1.2; // positions.Add(new Point3D(-x, y, 0)); // positions.Add(new Point3D(x, y, 0)); // positions.Add(new Point3D(x, -y, 0)); // positions.Add(new Point3D(-x, -y, 0)); return positions; }
/// <summary> /// Get a collection of points that represents a cube around this point /// </summary> /// <param name="center"></param> /// <param name="radius"></param> /// <returns></returns> public static Point3DCollection GetPoint3DCollectionFromCenterAndRadius(Point3D center, double radius) { Point3DCollection point3dCollection = new Point3DCollection(8); point3dCollection.Add(new Point3D(center.X - radius, center.Y - radius, center.Z + radius)); //0 point3dCollection.Add(new Point3D(center.X - radius, center.Y + radius, center.Z + radius)); //1 point3dCollection.Add(new Point3D(center.X + radius, center.Y - radius, center.Z + radius)); //2 point3dCollection.Add(new Point3D(center.X + radius, center.Y + radius, center.Z + radius)); //3 point3dCollection.Add(new Point3D(center.X - radius, center.Y - radius, center.Z - radius)); //4 point3dCollection.Add(new Point3D(center.X - radius, center.Y + radius, center.Z - radius)); //5 point3dCollection.Add(new Point3D(center.X + radius, center.Y - radius, center.Z - radius)); //6 point3dCollection.Add(new Point3D(center.X + radius, center.Y + radius, center.Z - radius)); //7 return point3dCollection; }
private Point3DCollection CreatePath(double min, double max, int n, Func<double, double> fx, Func<double, double> fy, Func<double, double> fz) { var list = new Point3DCollection(n); for (int i = 0; i < n; i++) { double u = min + (max - min) * i / n; list.Add(new Point3D(fx(u), fy(u), fz(u))); } return list; }
public static void AddGeometry(this ModelVisual3D visual, GeometryModel3D geometry) { if (visual.Content == null) visual.Content = geometry; else { if (visual.Content is Model3DGroup) { GeometryModel3D m3d = (GeometryModel3D)((Model3DGroup)visual.Content).Children.First(); MeshGeometry3D main = (MeshGeometry3D)(m3d.Geometry); MeshGeometry3D toAdd = (MeshGeometry3D)(geometry.Geometry); Point3DCollection pc = new Point3DCollection(main.Positions.Count + toAdd.Positions.Count); foreach (var pt in main.Positions) pc.Add(pt); foreach (var pt in toAdd.Positions) { pc.Add(geometry.Transform.Transform(pt)); } main.Positions = pc; Vector3DCollection vc = new Vector3DCollection(main.Normals.Count + toAdd.Normals.Count); foreach (var v in main.Normals) vc.Add(v); foreach (var norm in toAdd.Normals) vc.Add(norm); main.Normals = vc; int maxIndices = main.Positions.Count; //we need to increment all indices by this amount foreach (var i in toAdd.TriangleIndices) main.TriangleIndices.Add(i + maxIndices); Int32Collection tc = new Int32Collection(main.TriangleIndices.Count + toAdd.TriangleIndices.Count); foreach (var i in main.TriangleIndices) tc.Add(i); foreach (var i in toAdd.TriangleIndices) tc.Add(i + maxIndices); main.TriangleIndices = tc; } //it is not a group but now needs to be else { Model3DGroup m3dGroup = new Model3DGroup(); m3dGroup.Children.Add(visual.Content); m3dGroup.Children.Add(geometry); visual.Content = m3dGroup; } } }
[FriendAccessAllowed] // Built into Core, also used by Framework. internal static object DeserializeFrom(BinaryReader reader) { // Get the size. uint count = reader.ReadUInt32() ; Point3DCollection collection = new Point3DCollection( (int) count) ; for ( uint i = 0; i < count ; i ++ ) { Point3D point = new Point3D( XamlSerializationHelper.ReadDouble( reader ), XamlSerializationHelper.ReadDouble( reader ) , XamlSerializationHelper.ReadDouble( reader ) ) ; collection.Add( point ); } return collection ; }
/// <summary> /// Parse - returns an instance converted from the provided string /// using the current culture /// <param name="source"> string with Point3DCollection data </param> /// </summary> public static Point3DCollection Parse(string source) { IFormatProvider formatProvider = System.Windows.Markup.TypeConverterHelper.InvariantEnglishUS; TokenizerHelper th = new TokenizerHelper(source, formatProvider); Point3DCollection resource = new Point3DCollection(); Point3D value; while (th.NextToken()) { value = new Point3D( Convert.ToDouble(th.GetCurrentToken(), formatProvider), Convert.ToDouble(th.NextTokenRequired(), formatProvider), Convert.ToDouble(th.NextTokenRequired(), formatProvider)); resource.Add(value); } return(resource); }
public Point3DCollection GetCube(double x, double y, double z) { System.Windows.Media.Media3D.Point3DCollection points = new System.Windows.Media.Media3D.Point3DCollection(20); System.Windows.Media.Media3D.Point3D point; //top of the floor point = new System.Windows.Media.Media3D.Point3D(-x, 0, z); // Floor Index - 0 points.Add(point); point = new System.Windows.Media.Media3D.Point3D(x, 0, z); // Floor Index - 1 points.Add(point); point = new System.Windows.Media.Media3D.Point3D(x, 0, -z); // Floor Index - 2 points.Add(point); point = new System.Windows.Media.Media3D.Point3D(-x, 0, -z); // Floor Index - 3 points.Add(point); //front side point = new System.Windows.Media.Media3D.Point3D(-x, 0, z); // Floor Index - 4 points.Add(point); point = new System.Windows.Media.Media3D.Point3D(-x, y, z); // Floor Index - 5 points.Add(point); point = new System.Windows.Media.Media3D.Point3D(x, y, z); // Floor Index - 6 points.Add(point); point = new System.Windows.Media.Media3D.Point3D(x, 0, z); // Floor Index - 7 points.Add(point); //right side point = new System.Windows.Media.Media3D.Point3D(x, 0, z); // Floor Index - 8 points.Add(point); point = new System.Windows.Media.Media3D.Point3D(x, y, z); // Floor Index - 9 points.Add(point); point = new System.Windows.Media.Media3D.Point3D(x, y, -z); // Floor Index - 10 points.Add(point); point = new System.Windows.Media.Media3D.Point3D(x, 0, -z); // Floor Index - 11 points.Add(point); //back side point = new System.Windows.Media.Media3D.Point3D(x, 0, -z); // Floor Index - 12 points.Add(point); point = new System.Windows.Media.Media3D.Point3D(x, y, -z); // Floor Index - 13 points.Add(point); point = new System.Windows.Media.Media3D.Point3D(-x, y, -z); // Floor Index - 14 points.Add(point); point = new System.Windows.Media.Media3D.Point3D(-x, 0, -z); // Floor Index - 15 points.Add(point); //left side point = new System.Windows.Media.Media3D.Point3D(-x, 0, -z); // Floor Index - 16 points.Add(point); point = new System.Windows.Media.Media3D.Point3D(-x, y, -z); // Floor Index - 17 points.Add(point); point = new System.Windows.Media.Media3D.Point3D(-x, y, z); // Floor Index - 18 points.Add(point); point = new System.Windows.Media.Media3D.Point3D(-x, 0, z); // Floor Index - 19 points.Add(point); return(points); }