public AddSphere ( System.Windows.Media.Media3D.Point3D center, double radius, int thetaDiv = 20, int phiDiv = 10 ) : void | ||
center | System.Windows.Media.Media3D.Point3D | /// The center of the sphere. /// |
radius | double | /// The radius of the sphere. /// |
thetaDiv | int | /// The number of divisions around the sphere. /// |
phiDiv | int | /// The number of divisions from top to bottom of the sphere. /// |
Результат | void |
public DemoElement3D() { var gm = new GeometryModel3D(); var mb = new MeshBuilder(); mb.AddSphere(new Point3D(0, 0, 0), 2, 100, 50); gm.Geometry = mb.ToMesh(); gm.Material = Materials.Blue; Visual3DModel = gm; }
public void AddGroup(List<int> selectedVertex) { MeshBuilder mesh = new MeshBuilder(false, false); foreach (int index in selectedVertex) mesh.AddSphere(this.Points[index], pointRaduis); var mesh1 = mesh.ToMesh(true); var redMaterial = MaterialHelper.CreateMaterial(Colors.Red); var insideMaterial = MaterialHelper.CreateMaterial(Colors.Yellow); // Add 3 models to the group (using the same mesh, that's why we had to freeze it) mg.Children.Add(new GeometryModel3D { Geometry = mesh1, Material = redMaterial, BackMaterial = insideMaterial }); }
//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.AddSphere(_bo.Position, _bo.Size.X); } this.Material = outsideMat; this.BackMaterial = insideMat; return(builder.ToMesh()); }
public MainWindow() { InitializeComponent(); var container = new ContainerUIElement3D(); var element = new ModelUIElement3D(); var geometry = new GeometryModel3D(); var meshBuilder = new MeshBuilder(); meshBuilder.AddSphere(new Point3D(0, 0, 0), 2, 100, 50); geometry.Geometry = meshBuilder.ToMesh(); geometry.Material = Materials.Green; element.Model = geometry; element.Transform = new TranslateTransform3D(5, 0, 0); element.MouseDown += this.ContainerElementMouseDown; container.Children.Add(element); view1.Children.Add(container); }
public Model3D ToModel3D() { var m = new Model3DGroup(); TriangleIndexToPanelIndex = new List<int>(); // Add the triangles var tm = new MeshBuilder(false, false); int panelIndex = 0; foreach (var p in Panels) { p.TriangleIndex = tm.Positions.Count; tm.AddTriangleFan(p.Points); for (int i = 0; i < p.Points.Length - 2; i++) TriangleIndexToPanelIndex.Add(panelIndex); panelIndex++; } var panelsGeometry = tm.ToMesh(); m.Children.Add(new GeometryModel3D(panelsGeometry, Materials.Red) { BackMaterial = Materials.Blue }); // Add the nodes var gm = new MeshBuilder(); foreach (var p in panelsGeometry.Positions) { gm.AddSphere(p, 0.05); } m.Children.Add(new GeometryModel3D(gm.ToMesh(), Materials.Gold)); // Add the edges var em = new MeshBuilder(); foreach (var p in Panels) { for (int i = 0; i < p.Points.Length; i += 1) { em.AddCylinder(p.Points[i], p.Points[(i + 1) % p.Points.Length], 0.05, 10); } } m.Children.Add(new GeometryModel3D(em.ToMesh(), Materials.Gray)); return m; }
public Sphere(Point3D center, double radius, IEnumerable<CutingPlane> cutingPlanes) { Center = center; Radius = radius; CutingPlanes = new List<CutingPlane>(); if (cutingPlanes != null) { CutingPlanes.AddRange(cutingPlanes); } var meshBuilder = new MeshBuilder(false, false); meshBuilder.AddSphere(center, radius, 25, 15); var m = meshBuilder.ToMesh(); foreach (var plane3D in CutingPlanes) { Point3D p = plane3D.Point; Vector3D n = -1*plane3D.Vector; m = MeshGeometryHelper.Cut(m, p, n); } Model = m; }
public void AddGroup(bool canShowFace) { MeshBuilder mesh = new MeshBuilder(false, false); if (canShowFace) { foreach (Point3D pt in this.Points) mesh.Positions.Add(pt); foreach (List<int> pts in this.faces) { if (pts != null) mesh.AddPolygon(pts); } } else { foreach (Point3D pt in this.Points) mesh.AddSphere(pt, pointRaduis); } var mesh1 = mesh.ToMesh(true); var redMaterial = MaterialHelper.CreateMaterial(Colors.Green); var insideMaterial = MaterialHelper.CreateMaterial(Colors.Yellow); // Add 3 models to the group (using the same mesh, that's why we had to freeze it) mg.Children.Add(new GeometryModel3D { Geometry = mesh1, Material = redMaterial, BackMaterial = insideMaterial }); }
/// <summary> /// Creates a rather ugly visual representatino of the polyline. /// Fixed in size with respect to the model. /// </summary> /// <param name="highlighted">The destination visual component to replace the content of.</param> internal void SetToVisual(MeshVisual3D highlighted) { if (_geomPoints == null) return; var lines = new LinesVisual3D { Color = Colors.Yellow }; var axesMeshBuilder = new MeshBuilder(); List<Point3D> path = new List<Point3D>(); foreach (var item in _geomPoints) { axesMeshBuilder.AddSphere(item.Point, 0.1); path.Add(item.Point); } if (_geomPoints.Count > 1) { double lineThickness = 0.05; axesMeshBuilder.AddTube(path, lineThickness, 9, false); } highlighted.Content = new GeometryModel3D(axesMeshBuilder.ToMesh(), Materials.Yellow); }
/// <summary> /// Build a joint for drawing /// </summary> /// <param name="joint">Joint</param> /// <returns>Joint created</returns> private GeometryModel3D BuildJoint(Joint joint) { MeshBuilder jointBuilder = new MeshBuilder(); jointBuilder.AddSphere(new Point3D(0, 0, 0), jointDiameter, thetaDiv, 10); GeometryModel3D jointModel = new GeometryModel3D(jointBuilder.ToMesh(), Materials.Red); jointModel.SetName(joint.Name); MatrixTransform3D transform = new MatrixTransform3D(joint.Matrix.ElementAtOrDefault(Session.CurrentSession.CurrentProject.CurrentModel3D.Animation.Tick)); jointModel.Transform = transform; return jointModel; }
/// <summary> /// This function creates the model /// </summary> /// <returns>A created plot model</returns> private Model3D CreateModel() { var plotModel = new Model3DGroup(); if (Points == null || Points.Count == 0) return plotModel; double minX = Points.Min(p => p.X); double maxX = Points.Max(p => p.X); double minY = Points.Min(p => p.Y); double maxY = Points.Max(p => p.Y); double minZ = Points.Min(p => p.Z); double maxZ = Points.Max(p => p.Z); double minValue = 0; double maxValue = 10000; var valueRange = maxValue - minValue; var scatterMeshBuilder = new MeshBuilder(true, true); var oldTCCount = 0; for (var i = 0; i < Points.Count; ++i) { scatterMeshBuilder.AddSphere(Points[i], SphereSize, 4, 4); var newTCCount = scatterMeshBuilder.TextureCoordinates.Count; oldTCCount = newTCCount; } var scatterModel = new GeometryModel3D(scatterMeshBuilder.ToMesh(), MaterialHelper.CreateMaterial(SurfaceBrush, null, null, 1, 0)); scatterModel.BackMaterial = scatterModel.Material; // create bounding box with axes indications var axesMeshBuilder = new MeshBuilder(); for (double x = minX; x <= maxX; x += IntervalX) { GeometryModel3D label = TextCreator.CreateTextLabelModel3D(x.ToString(), Brushes.White, true, FontSize, new Point3D(x, minY - FontSize * 2.5, minZ), new Vector3D(1, 0, 0), new Vector3D(0, 1, 0)); plotModel.Children.Add(label); } { GeometryModel3D label = TextCreator.CreateTextLabelModel3D("X-axis", Brushes.White, true, FontSize, new Point3D((minX + maxX) * 0.5, minY - FontSize * 6, minZ), new Vector3D(1, 0, 0), new Vector3D(0, 1, 0)); plotModel.Children.Add(label); } for (double y = minY; y <= maxY; y += IntervalY) { GeometryModel3D label = TextCreator.CreateTextLabelModel3D(y.ToString(), Brushes.White, true, FontSize, new Point3D(minX - FontSize * 3, y, minZ), new Vector3D(1, 0, 0), new Vector3D(0, 1, 0)); plotModel.Children.Add(label); } { GeometryModel3D label = TextCreator.CreateTextLabelModel3D("Y-axis", Brushes.White, true, FontSize, new Point3D(minX - FontSize * 10, (minY + maxY) * 0.5, minZ), new Vector3D(0, 1, 0), new Vector3D(-1, 0, 0)); plotModel.Children.Add(label); } double z0 = (int)(minZ / IntervalZ) * IntervalZ; for (double z = z0; z <= maxZ + double.Epsilon; z += IntervalZ) { GeometryModel3D label = TextCreator.CreateTextLabelModel3D(z.ToString(), Brushes.White, true, FontSize, new Point3D(minX - FontSize * 3, maxY, z), new Vector3D(1, 0, 0), new Vector3D(0, 0, 1)); plotModel.Children.Add(label); } { GeometryModel3D label = TextCreator.CreateTextLabelModel3D("Z-axis", Brushes.White, true, FontSize, new Point3D(minX - FontSize * 10, maxY, (minZ + maxZ) * 0.5), new Vector3D(0, 0, 1), new Vector3D(1, 0, 0)); plotModel.Children.Add(label); } var bb = new Rect3D(minX, minY, minZ, maxX - minX, maxY - minY, maxZ - minZ); axesMeshBuilder.AddBoundingBox(bb, LineThickness); var axesModel = new GeometryModel3D(axesMeshBuilder.ToMesh(), Materials.White); plotModel.Children.Add(scatterModel); plotModel.Children.Add(axesModel); return plotModel; }
/// <summary> /// The tessellate. /// </summary> /// <returns>The mesh.</returns> protected override MeshGeometry3D Tessellate() { var builder = new MeshBuilder(false, true); builder.AddSphere(new Point3D(0, 0, 0), 1.0, this.ThetaDiv, this.PhiDiv); builder.Scale(this.RadiusX, this.RadiusY, this.RadiusZ); return builder.ToMesh(); }
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; }
private void AddPoints(IEnumerable<SurveyPoint> surveyPoints) { ViewPort.Children.Remove(_pointsVisual); var meshBuilder = new MeshBuilder(); foreach (var current in surveyPoints) { var point = new Point3D { X = current.CalibrationPoint.X * ScaleFactor / _maxCoord, Y = current.CalibrationPoint.Y * ScaleFactor / _maxCoord, Z = current.CalibrationPoint.Z * ScaleFactor / _maxCoord }; meshBuilder.AddSphere(point, PointRadius); } var modelVisual = new ModelVisual3D { Content = new GeometryModel3D { Geometry = meshBuilder.ToMesh(), Material = PointVisual3DMaterial.BlackMaterial } }; ViewPort.Children.Add(modelVisual); _pointsVisual = modelVisual; }
/// <summary> /// Do the tesselation and return the <see cref="MeshGeometry3D"/>. /// </summary> /// <returns>A triangular mesh geometry.</returns> protected override MeshGeometry3D Tessellate() { var builder = new MeshBuilder(true, true); builder.AddSphere(this.Center, this.Radius, this.ThetaDiv, this.PhiDiv); return builder.ToMesh(); }
//TODO: refactor into more methods private void SkeletonFrameReady_Draw3D(ModelVisual3D modelVisual3D, SkeletonFrameReadyEventArgs e) { using (SkeletonFrame skeletonFrame = e.OpenSkeletonFrame()) { // Get tracked skeleton data from stream, return if no data if (skeletonFrame == null) { modelVisual3D.Content = null; return; } Skeleton[] skeletons = new Skeleton[kinect.SkeletonStream.FrameSkeletonArrayLength]; skeletonFrame.CopySkeletonDataTo(skeletons); Skeleton skeleton = skeletons.FirstOrDefault(s => s.TrackingState == SkeletonTrackingState.Tracked); if (skeleton == null) { modelVisual3D.Content = null; return; } // Waist coordinates will be origin SkeletonPoint centroid = skeleton.Joints[JointType.HipCenter].Position; // Init 3D stuff Model3DGroup modelGroup = new Model3DGroup(); MeshBuilder meshBuilder = new MeshBuilder(false, false); // Init dict to tidy up code Dictionary<JointType, Point3D> jd = new Dictionary<JointType, Point3D>(); // Add joints to mesh while populating the dict foreach (Joint j in skeleton.Joints) { // Helix3D has a different coordinate system int y = (int)((j.Position.X - centroid.X) * 100); int z = (int)((j.Position.Y - centroid.Y) * 100); int x = (int)((centroid.Z - j.Position.Z) * 100); Point3D center = new Point3D { X = x, Y = y, Z = z }; jd[j.JointType] = center; meshBuilder.AddSphere(center, 5); } // Add bones to mesh meshBuilder.AddCylinder(jd[JointType.Head], jd[JointType.ShoulderCenter], 6, 10); meshBuilder.AddCylinder(jd[JointType.ShoulderCenter], jd[JointType.Spine], 6, 10); meshBuilder.AddCylinder(jd[JointType.Spine], jd[JointType.HipCenter], 6, 10); meshBuilder.AddCylinder(jd[JointType.HipCenter], jd[JointType.HipLeft], 6, 10); meshBuilder.AddCylinder(jd[JointType.HipLeft], jd[JointType.KneeLeft], 6, 10); meshBuilder.AddCylinder(jd[JointType.KneeLeft], jd[JointType.AnkleLeft], 6, 10); meshBuilder.AddCylinder(jd[JointType.AnkleLeft], jd[JointType.FootLeft], 6, 10); meshBuilder.AddCylinder(jd[JointType.HipCenter], jd[JointType.HipRight], 6, 10); meshBuilder.AddCylinder(jd[JointType.HipRight], jd[JointType.KneeRight], 6, 10); meshBuilder.AddCylinder(jd[JointType.KneeRight], jd[JointType.AnkleRight], 6, 10); meshBuilder.AddCylinder(jd[JointType.AnkleRight], jd[JointType.FootRight], 6, 10); meshBuilder.AddCylinder(jd[JointType.ShoulderCenter], jd[JointType.ShoulderLeft], 6, 10); meshBuilder.AddCylinder(jd[JointType.ShoulderLeft], jd[JointType.ElbowLeft], 6, 10); meshBuilder.AddCylinder(jd[JointType.ElbowLeft], jd[JointType.WristLeft], 6, 10); meshBuilder.AddCylinder(jd[JointType.WristLeft], jd[JointType.HandLeft], 6, 10); meshBuilder.AddCylinder(jd[JointType.ShoulderCenter], jd[JointType.ShoulderRight], 6, 10); meshBuilder.AddCylinder(jd[JointType.ShoulderRight], jd[JointType.ElbowRight], 6, 10); meshBuilder.AddCylinder(jd[JointType.ElbowRight], jd[JointType.WristRight], 6, 10); meshBuilder.AddCylinder(jd[JointType.WristRight], jd[JointType.HandRight], 6, 10); var mesh = meshBuilder.ToMesh(true); // Create and freeze mesh Material blueMaterial = MaterialHelper.CreateMaterial(Colors.SteelBlue); // Create material modelGroup.Children.Add(new GeometryModel3D(mesh, blueMaterial)); // Create model // Draw modelVisual3D.Content = modelGroup; } }
private void UpdateModel() { // http://en.wikipedia.org/wiki/Lorenz_attractor Func<double[], double[]> lorenzAttractor = x => { var dx = new double[3]; dx[0] = sigma * (x[1] - x[0]); dx[1] = x[0] * (rho - x[2]) - x[1]; dx[2] = x[0] * x[1] - beta * x[2]; return dx; }; // solve the ODE var x0 = new[] { 0, 1, 1.05 }; IEnumerable<double[]> solution = EulerSolver(lorenzAttractor, x0, 25); // todo: should have a better ODE solver (R-K(4,5)? http://www.mathworks.com/help/techdoc/ref/ode45.html) List<Point3D> path = solution.Select(x => new Point3D(x[0], x[1], x[2])).ToList(); // create the WPF3D model var m = new Model3DGroup(); var gm = new MeshBuilder(); gm.AddTube(path, 0.8, 10, false); if (directionArrows) { // sphere at the initial point gm.AddSphere(path[0], 1); // arrow heads every 100 point for (int i = 100; i + 1 < path.Count; i += 100) { gm.AddArrow(path[i], path[i + 1], 0.8); } // arrow head at the end Point3D p0 = path[path.Count - 2]; Point3D p1 = path[path.Count - 1]; var d = new Vector3D(p1.X - p0.X, p1.Y - p0.Y, p1.Z - p0.Z); d.Normalize(); Point3D p2 = p1 + d * 2; gm.AddArrow(p1, p2, 0.8); } m.Children.Add(new GeometryModel3D(gm.ToMesh(), Materials.Gold)); Model = m; }
/// <summary> /// Add a sphere geometry object centred on (0,0,0). /// </summary> /// <param name="shapeName">The 3DView object.</param> /// <param name="radius">The sphere radius.</param> /// <param name="divisions">The sphere divisions, default 10 (affects number of triangles and smoothness).</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 AddSphere(Primitive shapeName, Primitive radius, Primitive divisions, 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); Point3D center = new Point3D(0, 0, 0); int phiDiv = divisions < 2 ? 10 : (int)divisions; int thetaDiv = 2 * phiDiv; builder.AddSphere(center, radius, thetaDiv, phiDiv); 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 ""; }