/// <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); }
/// <summary> /// /// </summary> /// <param name="args"></param> /// <param name="lines"></param> protected override void Generate(DependencyPropertyChangedEventArgs args, Point3DCollection lines) { Point3DCollection vertices = Positions; Int32Collection indices = TriangleIndices; lines.Clear(); if (vertices != null && vertices.Count > 0 && indices != null && indices.Count > 0) { // Check that this doesn't overflow !!!!!! // ----------------------------------------- // Special logic if there are no indices !!!! // ------------------------------------------- for (int i = 0; i < indices.Count; i += 3) { lines.Add(vertices[indices[i + 0]]); lines.Add(vertices[indices[i + 1]]); lines.Add(vertices[indices[i + 1]]); lines.Add(vertices[indices[i + 2]]); lines.Add(vertices[indices[i + 2]]); lines.Add(vertices[indices[i + 0]]); } } }
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); }
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; }
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); }
/* 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); }
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 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); } } }
public PlaneModel(GeometryModel3D plane, Color planeColor, Point3DCollection points) { this.plane = plane; this.planeColor = planeColor; this.points = points; this.crosses = 0; }
/// <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 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; }
protected override void Triangulate( DependencyPropertyChangedEventArgs args, Point3DCollection vertices, Vector3DCollection normals, Int32Collection indices, PointCollection textures) { // Clear all four collections. vertices.Clear(); normals.Clear(); indices.Clear(); textures.Clear(); // Convert TextGeometry to series of closed polylines. PathGeometry path = TextGeometry.GetFlattenedPathGeometry(0.001, ToleranceType.Relative); foreach (PathFigure fig in path.Figures) { list.Clear(); list.Add(fig.StartPoint); foreach (PathSegment seg in fig.Segments) { if (seg is LineSegment) { LineSegment lineseg = seg as LineSegment; list.Add(lineseg.Point); } else if (seg is PolyLineSegment) { PolyLineSegment polyline = seg as PolyLineSegment; for (int i = 0; i < polyline.Points.Count; i++) list.Add(polyline.Points[i]); } } // Figure is complete. Post-processing follows. if (list.Count > 0) { // Remove last point if it's the same as the first. if (list[0] == list[list.Count - 1]) list.RemoveAt(list.Count - 1); // Convert points to Y increasing up. for (int i = 0; i < list.Count; i++) { Point pt = list[i]; pt.Y = 2 * Origin.Y - pt.Y; list[i] = pt; } // For each figure, process the points. ProcessFigure(list, vertices, normals, indices, 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>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); }
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 RenderDescription() { points = new Point3DCollection(); lines = new Point3DCollection(); meshes = new List<Mesh3D>(); xAxisPoints = new Point3DCollection(); yAxisPoints = new Point3DCollection(); zAxisPoints = new Point3DCollection(); }
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 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; }
private GeometryModel3D Create3DModel() { _mesh = SimpleGeometry3D.CreateSphere(new Point3D(0, 0, 0), 0.2, 32, 32); _originalPoints = _mesh.Positions; var geometry = new GeometryModel3D(); geometry.Geometry = _mesh; geometry.Material = new DiffuseMaterial { Brush = Brushes.SaddleBrown, AmbientColor = Color.FromRgb(150,150,150)}; return geometry; }
/// <summary> /// Initializes a new instance of the <see cref="MeshBuilder"/> class. /// </summary> /// <param name="generateNormals">generate normals</param> /// <param name="generateTextureCoordinates">generate texture coordinates</param> public MeshBuilder(bool generateNormals, bool generateTextureCoordinates) { positions = new Point3DCollection(); triangleIndices = new Int32Collection(); if (generateNormals) normals = new Vector3DCollection(); if (generateTextureCoordinates) textureCoordinates = new PointCollection(); }
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; }
// ProcessFigure override. protected override void ProcessFigure(CircularList<Point> list, Point3DCollection vertices, Vector3DCollection normals, Int32Collection indices, PointCollection textures) { int k = Slices * list.Count; int offset = vertices.Count; for (int i = 0; i < list.Count; i++) { Point ptBefore = list[i - 1]; Point pt = list[i]; Point ptAfter = list[i + 1]; Vector v1 = pt - ptBefore; v1.Normalize(); Vector v1Rotated = new Vector(-v1.Y, v1.X); Vector v2 = ptAfter - pt; v2.Normalize(); Vector v2Rotated = new Vector(-v2.Y, v2.X); Line2D line1 = new Line2D(pt, ptBefore); Line2D line2 = new Line2D(pt, ptAfter); for (int slice = 0; slice < Slices; slice++) { // Angle ranges from 0 to 360 degrees. double angle = slice * 2 * Math.PI / Slices; double scale = EllipseWidth / 2 * Math.Sin(angle); double depth = -Depth / 2 * (1 - Math.Cos(angle)); Line2D line1Shifted = line1 + scale * v1Rotated; Line2D line2Shifted = line2 + scale * v2Rotated; Point ptIntersect = line1Shifted * line2Shifted; // Set vertex. vertices.Add(new Point3D(ptIntersect.X, ptIntersect.Y, depth)); // Set texture coordinate. textures.Add(new Point((double)i / list.Count, Math.Sin(angle / 2))); // Set triangle indices. indices.Add(offset + (Slices * i + slice + 0) % k); indices.Add(offset + (Slices * i + slice + 1) % k); indices.Add(offset + (Slices * i + slice + 0 + Slices) % k); indices.Add(offset + (Slices * i + slice + 0 + Slices) % k); indices.Add(offset + (Slices * i + slice + 1) % k); indices.Add(offset + (Slices * i + slice + 1 + Slices) % k); } } }
public Point3DCollection GetCurrentValue(Point3DCollection defaultOriginValue, Point3DCollection defaultDestinationValue, AnimationClock animationClock) { if (animationClock == null) { throw new ArgumentException("animationClock"); } return GetCurrentValueCore(defaultOriginValue, defaultDestinationValue, animationClock); }
public SphereCollectionVisual3D() { Positions = new Point3DCollection(); Fill = Brushes.Blue; Diameter = 0.1; ThetaDiv = 37; PhiDiv = 19; _element = new ModelVisual3D(); Children.Add(_element); }
public SegmentCollectionVisual3D() { Positions = new Point3DCollection(); SegmentIndices = new Int32Collection(); Fill = Brushes.Blue; Diameter = 0.1; ThetaDiv = 37; _element = new ModelVisual3D(); Children.Add(_element); }
protected override Point3DCollection GetCurrentValueCore(Point3DCollection defaultOriginValue, Point3DCollection defaultDestinationValue, AnimationClock animationClock) { double progress = animationClock.CurrentProgress.Value; if (progress <= 0.0) { Initialize(); } return GetMeshPositions(progress); }
/// <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 MeshGeometry3D Simplify(MeshGeometry3D mesh, double eps) { // Find common positions var dict = new Dictionary<int, int>(); // map position index to first occurence of same position for (int i = 0; i < mesh.Positions.Count; i++) { for (int j = i + 1; j < mesh.Positions.Count; j++) { if (dict.ContainsKey(j)) continue; double l2 = (mesh.Positions[i] - mesh.Positions[j]).LengthSquared; if (l2 < eps) { dict.Add(j, i); } } } var p = new Point3DCollection(); var ti = new Int32Collection(); // create new positions array var newIndex = new Dictionary<int, int>(); // map old index to new index for (int i = 0; i < mesh.Positions.Count; i++) { if (!dict.ContainsKey(i)) { newIndex.Add(i, p.Count); p.Add(mesh.Positions[i]); } } // Update triangle indices for (int i = 0; i < mesh.TriangleIndices.Count; i++) { int index = mesh.TriangleIndices[i]; int j; if (dict.TryGetValue(index, out j)) { ti.Add(newIndex[j]); } else { ti.Add(newIndex[index]); } } var result = new MeshGeometry3D(); result.Positions = p; result.TriangleIndices = ti; return result; }
/// <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; }
public VectorFieldVisual3D() { Positions = new Point3DCollection(); Directions = new Vector3DCollection(); Fill = Brushes.Blue; ThetaDiv = 37; Diameter = 1; HeadLength = 2; _element = new ModelVisual3D(); Children.Add(_element); }
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); }
public MainViewModel(MainWindow mainWindow) { // TODO: Complete member initialization this.mainWindow = mainWindow; Model3DGroup modelGroup = new Model3DGroup(); TubeVisual3D tube1 = GenerateTube(); RectangleVisual3D rectangle = GenerateRectangle(); SphereVisual3D sphere = new SphereVisual3D() { Center = new Point3D(1.5, 2.5, -0.7), Radius = 2 }; //modelGroup.Children.Add(tube1.Model); //modelGroup.Children.Add(rectangle.Model); //modelGroup.Children.Add(sphere.Model); /* * * Point3D point; * Point3D point2; * Point3D point3; * Point3D point4; * AddElementsPart2(modelGroup, out point, out point2, out point3, out point4); * * * TubeVisual3D path = new TubeVisual3D() * { * Path = new Point3DCollection(new List<Point3D>(){ * point + new Vector3D(0, 0, 20), * point2 + new Vector3D(0, 0, 19), * point3 + new Vector3D(0, 0, 18), * point4 + new Vector3D(0, 0, 17) * }), * Diameter = 0.5, * ThetaDiv = 20, * IsPathClosed = false, * Fill = Brushes.Green * //Fill = new Brush() { Colors.Blue} * }; * * modelGroup.Children.Add(path.Content); * */ //AddSolidBox(modelGroup); //AddRevolved(modelGroup); HelixVisual3D helixItem = new HelixVisual3D(); helixItem.Fill = new SolidColorBrush(Colors.Violet); helixItem.Origin = new Point3D(0, 0, -0.45); helixItem.Diameter = 0.1; helixItem.Turns = 2; helixItem.Length = 0.9; helixItem.Radius = 0.35; //modelGroup.Children.Add(helixItem.Content); //modelGroup.Children.Add(box.Content); //<helix:HelixVisual3D //Origin="0 0 -0.45" //Diameter="0.1" //Turns="2" //Length="0.9" //Radius="0.35" //Fill="Violet" //Visible="{Binding IsChecked, ElementName=HelixVisible}"/> numberOfPoints = 100; // wireLines = new WireLines { Color = Colors.Black, Thickness = 3, }; Points = new Point3DCollection(GeneratePoints(numberOfPoints, 7000 * 0.001)); //wireLines.Lines = Points; //modelGroup.Children.Add(wireLines.Content); var y0 = 0d; var theta = Math.PI / 180 * 30; var roofBuilder = new MeshBuilder(false, false); var y1 = y0 + Math.Tan(theta) * 5 / 2; var p0 = new Point(0, y1); var p1 = new Point(5 / 2 + 0.2 * Math.Cos(theta), y0 - 0.2 * Math.Sin(theta)); var p2 = new Point(p1.X + 0.1 * Math.Sin(theta), p1.Y + 0.1 * Math.Cos(theta)); var p3 = new Point(0, y1 + 0.1 / Math.Cos(theta)); var p4 = new Point(-p2.X, p2.Y); var p5 = new Point(-p1.X, p1.Y); IList <Point> roofSection = new List <Point>() { p0, p1, p1, p2, p2, p3, p3, p4, p4, p5, p5, p0 }; var roofAxisX = new Vector3D(0, -1, 0); var roofAxisY = new Vector3D(0, 0, 1); var roofOrigin = new Point3D(1, 1, 1); //roofBuilder.AddPolygon(roofSection, roofAxisX, roofAxisY, roofOrigin); Point3DCollection simplePoly = new System.Windows.Media.Media3D.Point3DCollection( new List <Point3D>() { new Point3D(1, 0, 1), new Point3D(1, 1, 1), new Point3D(0, 1, 1), new Point3D(0, 0, 1), /* * //new Point3D(1,0, 1), * new Point3D(0,0, -1), * new Point3D(1,0, -1), * new Point3D(1,1, -1), * new Point3D(0,1, -1), * //new Point3D(1,0, 1), * new Point3D(0,0, -1), * new Point3D(0,0, 1), */ } ); roofBuilder.AddPolygon(simplePoly); //roofBuilder.AddRectangularMesh() GeometryModel3D roofGeometry = new GeometryModel3D(); //var material = MaterialHelper.CreateMaterial(Brushes.LightBlue, ambient: 77, freeze: false); var material = MaterialHelper.CreateMaterial(Colors.LawnGreen, 0.25); roofGeometry.Material = material; roofGeometry.BackMaterial = material; roofGeometry.Geometry = roofBuilder.ToMesh(true); modelGroup.Children.Add(roofGeometry); //ScreenSpaceLines3D Wireframe = new ScreenSpaceLines3D(); //Wireframe.Thickness = 2; //Wireframe.Color = Colors.Black; //Wireframe.Points = simplePoly; ////Wireframe.MakeWireframe(roofGeometry); //modelGroup.Children.Add(Wireframe.Content); var Mesh = new MeshGeometry3D(); //var Material = MaterialHelper.CreateImageMaterial(image); var Damping = 0.98; var integrator = new VerletIntegrator() { Iterations = 4, Damping = 0.98 }; var WindSpeed = 6; var WindDirection = 180; var PoleHeight = 12; var Height = 3; var Length = 4; var Mass = 0.8; var m = 48; var n = 32; var pts = new Point3D[n, m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { pts[i, j] = new Point3D(-Length * j / (m - 1), 0, PoleHeight - Height * i / (n - 1)); } } var pts2 = new Point3D[2, 4]; for (int i = 0; i < 2; i++) { for (int j = 0; j < 4; j++) { double x = 0, z = 0; if (i == 0) { x = 0; z = 0; } if (i == 1) { x = 1; z = 0; } if (i == 2) { x = 1; z = 1; } if (i == 3) { x = 0; z = 1; } pts[i, j] = new Point3D(x, i, PoleHeight - z); } } var mb = new MeshBuilder(false, true); //mb.AddRectangularMesh(pts, null, false, false); mb.AddRectangularMesh(pts, null, false, false); Mesh = mb.ToMesh(); var gradientMaterial = CreateGradientBrushMaterial(); gradientMaterial = MaterialHelper.CreateMaterial(Colors.LightBlue, 0.25); GeometryModel3D meshGeometry = new GeometryModel3D(); meshGeometry.Geometry = Mesh; meshGeometry.Material = gradientMaterial; meshGeometry.BackMaterial = gradientMaterial; modelGroup.Children.Add(meshGeometry); this.Model = modelGroup; }
// // Hits the ray against the mesh // internal override void RayHitTestCore( RayHitTestParameters rayParams, FaceType hitTestableFaces) { Debug.Assert(hitTestableFaces != FaceType.None, "Caller should make sure we're trying to hit something"); Point3DCollection positions = Positions; if (positions == null) { return; } Point3D origin; Vector3D direction; rayParams.GetLocalLine(out origin, out direction); Int32Collection indices = TriangleIndices; // In the line case, we want to hit test all faces because we don't // have a direction. This may differ from what faces we want to // accept. FaceType facesToHit; if (rayParams.IsRay) { facesToHit = hitTestableFaces; } else { facesToHit = FaceType.Front | FaceType.Back; } // // This code duplication is unfortunate but necessary. Breaking it down into methods // further significantly impacts performance. About 5% improvement could be made // by unrolling this code below even more. // // If futher perf investigation is done with this code, be sure to test NGEN assemblies only // as JIT produces different, faster code than NGEN. // if (indices == null || indices.Count == 0) { FrugalStructList <Point3D> ps = positions._collection; int count = ps.Count - (ps.Count % 3); for (int i = count - 1; i >= 2; i -= 3) { int i0 = i - 2; int i1 = i - 1; int i2 = i; Point3D v0 = ps[i0]; Point3D v1 = ps[i1]; Point3D v2 = ps[i2]; double hitTime; Point barycentric; // The line hit test is equivalent to a double sided // triangle hit because it doesn't cull triangles based // on winding if (LineUtil.ComputeLineTriangleIntersection( facesToHit, ref origin, ref direction, ref v0, ref v1, ref v2, out barycentric, out hitTime ) ) { if (rayParams.IsRay) { ValidateRayHit( rayParams, ref origin, ref direction, hitTime, i0, i1, i2, ref barycentric ); } else { ValidateLineHit( rayParams, hitTestableFaces, i0, i1, i2, ref v0, ref v1, ref v2, ref barycentric ); } } } } else // indexed mesh { FrugalStructList <Point3D> ps = positions._collection; FrugalStructList <int> idcs = indices._collection; int count = idcs.Count; int limit = ps.Count; for (int i = 2; i < count; i += 3) { int i0 = idcs[i - 2]; int i1 = idcs[i - 1]; int i2 = idcs[i]; // Quit if we encounter an index out of range. // This is okay because the triangles we ignore are not rendered. // (see: CMilMeshGeometry3DDuce::Realize) if ((0 > i0 || i0 >= limit) || (0 > i1 || i1 >= limit) || (0 > i2 || i2 >= limit)) { break; } Point3D v0 = ps[i0]; Point3D v1 = ps[i1]; Point3D v2 = ps[i2]; double hitTime; Point barycentric; if (LineUtil.ComputeLineTriangleIntersection( facesToHit, ref origin, ref direction, ref v0, ref v1, ref v2, out barycentric, out hitTime ) ) { if (rayParams.IsRay) { ValidateRayHit( rayParams, ref origin, ref direction, hitTime, i0, i1, i2, ref barycentric ); } else { ValidateLineHit( rayParams, hitTestableFaces, i0, i1, i2, ref v0, ref v1, ref v2, ref barycentric ); } } } } }
//------------------------------------------------------ // // Internal Methods // //------------------------------------------------------ #region Internal Methods internal override void UpdateResource(DUCE.Channel channel, bool skipOnChannelCheck) { // If we're told we can skip the channel check, then we must be on channel Debug.Assert(!skipOnChannelCheck || _duceResource.IsOnChannel(channel)); if (skipOnChannelCheck || _duceResource.IsOnChannel(channel)) { base.UpdateResource(channel, skipOnChannelCheck); // Read values of properties into local variables Point3DCollection vPositions = Positions; Vector3DCollection vNormals = Normals; PointCollection vTextureCoordinates = TextureCoordinates; Int32Collection vTriangleIndices = TriangleIndices; // Store the count of this resource's contained collections in local variables. int PositionsCount = (vPositions == null) ? 0 : vPositions.Count; int NormalsCount = (vNormals == null) ? 0 : vNormals.Count; int TextureCoordinatesCount = (vTextureCoordinates == null) ? 0 : vTextureCoordinates.Count; int TriangleIndicesCount = (vTriangleIndices == null) ? 0 : vTriangleIndices.Count; // Pack & send command packet DUCE.MILCMD_MESHGEOMETRY3D data; unsafe { data.Type = MILCMD.MilCmdMeshGeometry3D; data.Handle = _duceResource.GetHandle(channel); data.PositionsSize = (uint)(sizeof(MilPoint3F) * PositionsCount); data.NormalsSize = (uint)(sizeof(MilPoint3F) * NormalsCount); data.TextureCoordinatesSize = (uint)(sizeof(Point) * TextureCoordinatesCount); data.TriangleIndicesSize = (uint)(sizeof(Int32) * TriangleIndicesCount); channel.BeginCommand( (byte *)&data, sizeof(DUCE.MILCMD_MESHGEOMETRY3D), (int)(data.PositionsSize + data.NormalsSize + data.TextureCoordinatesSize + data.TriangleIndicesSize) ); // Copy this collection's elements (or their handles) to reserved data for (int i = 0; i < PositionsCount; i++) { MilPoint3F resource = CompositionResourceManager.Point3DToMilPoint3F(vPositions.Internal_GetItem(i)); channel.AppendCommandData( (byte *)&resource, sizeof(MilPoint3F) ); } // Copy this collection's elements (or their handles) to reserved data for (int i = 0; i < NormalsCount; i++) { MilPoint3F resource = CompositionResourceManager.Vector3DToMilPoint3F(vNormals.Internal_GetItem(i)); channel.AppendCommandData( (byte *)&resource, sizeof(MilPoint3F) ); } // Copy this collection's elements (or their handles) to reserved data for (int i = 0; i < TextureCoordinatesCount; i++) { Point resource = vTextureCoordinates.Internal_GetItem(i); channel.AppendCommandData( (byte *)&resource, sizeof(Point) ); } // Copy this collection's elements (or their handles) to reserved data for (int i = 0; i < TriangleIndicesCount; i++) { Int32 resource = vTriangleIndices.Internal_GetItem(i); channel.AppendCommandData( (byte *)&resource, sizeof(Int32) ); } channel.EndCommand(); } } }
internal static bool Get3DPointFor2DCoordinate(Point point, out Point3D point3D, Point3DCollection positions, PointCollection textureCoords, Int32Collection triIndices) { point3D = new Point3D(); // walk through the triangles - and look for the triangles we care about Point3D[] p = new Point3D[3]; Point[] uv = new Point[3]; if (positions != null && textureCoords != null) { if (triIndices == null || triIndices.Count == 0) { int texCoordCount = textureCoords.Count; // in this case we have a non-indexed mesh int count = positions.Count; count = count - (count % 3); for (int i = 0; i < count; i += 3) { for (int j = 0; j < 3; j++) { p[j] = positions[i + j]; if (i + j < texCoordCount) { uv[j] = textureCoords[i + j]; } else { // In the case you have less texture coordinates than positions, MIL will set // missing ones to be 0,0. We do the same to stay consistent. // See CMILMesh3D::CopyTextureCoordinatesFromDoubles uv[j] = new Point(0, 0); } } if (M3DUtil.IsPointInTriangle(point, uv, p, out point3D)) { return(true); } } } else { // in this case we have an indexed mesh int posLimit = positions.Count; int texCoordLimit = textureCoords.Count; for (int i = 2, count = triIndices.Count; i < count; i += 3) { bool validTextureCoordinates = true; for (int j = 0; j < 3; j++) { // subtract 2 to take in to account we start i // at the high range of indices int index = triIndices[(i - 2) + j]; // if a point or texture coordinate is out of range, end early since this is an error if (index < 0 || index >= posLimit) { // no need to look anymore - see MeshGeometry3D RayHitTestIndexedList for // reasoning why we stop return(false); } if (index < 0 || index >= texCoordLimit) { validTextureCoordinates = false; break; } p[j] = positions[index]; uv[j] = textureCoords[index]; } if (validTextureCoordinates) { if (M3DUtil.IsPointInTriangle(point, uv, p, out point3D)) { return(true); } } } } } return(false); }