public static GeometryModel3D[] GetModels(NViewMatch nvm) { List<GeometryModel3D> models = new List<GeometryModel3D>(); foreach (var cameraPosition in nvm.CameraPositions) { models.AddRange(GetCamera(cameraPosition)); } if(nvm.Patches.Count <= 0) return models.ToArray(); PointGeometryModel3D model = new PointGeometryModel3D(); model.Color = Color.White; model.Geometry = Pointcloud.ConvertToPointGeometry3D( nvm.Patches.Select(patch => new PclWrapper.Points() { x = patch.Position.X, y = patch.Position.Y, z = patch.Position.Z, r = (byte)patch.Color.Red, g = (byte)patch.Color.Green, b = (byte)patch.Color.Blue, a = 255 }).ToArray()); models.Add(model); return models.ToArray(); }
public void Setup() { closePoint = InitializePointWithId("closePoint"); farPoint = InitializePointWithId("farPoint", new Vector3(10000, 10000, 10000)); var builder = new MeshBuilder(); builder.AddBox(new Vector3(-10000, -10000, -5000), 5, 5, 5, BoxFaces.All); var boxGeom = builder.ToMeshGeometry3D(); cube = new MeshGeometryModel3D() { Geometry = boxGeom, Name = "cube" }; }
public static GeometryModel3D[] GetModels(PointGeometry3D pointcloud) { List<GeometryModel3D> models = new List<GeometryModel3D>(); PointGeometryModel3D model = new PointGeometryModel3D(); // This one is important, otherwise it will be just black model.Color = Color.White; model.Geometry = pointcloud; models.Add(model); return models.ToArray(); }
void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target) { switch (connectionId) { case 1: this.view1 = ((HelixToolkit.Wpf.SharpDX.Viewport3DX)(target)); return; case 2: this.grid = ((HelixToolkit.Wpf.SharpDX.LineGeometryModel3D)(target)); return; case 3: this.arrows = ((HelixToolkit.Wpf.SharpDX.LineGeometryModel3D)(target)); return; case 4: this.points = ((HelixToolkit.Wpf.SharpDX.PointGeometryModel3D)(target)); return; } this._contentLoaded = true; }
private void AggregateRenderPackages(PackageAggregationParams parameters) { //Clear the geometry values before adding the package. VisualizationManager_WorkspaceOpenedClosedHandled(); foreach (var rp in parameters.Packages) { //Node ID gets updated with a ":" everytime this function is called. //For example, if the same point node is called multiple times (CBN), the ID has a ":" //and this makes the dictionary to have multiple entries for the same node. var baseId = rp.Description; if (baseId.IndexOf(":", StringComparison.Ordinal) > 0) { baseId = baseId.Split(':')[0]; } var id = baseId; var p = rp.Points; if (p.Positions.Any()) { id = baseId + ":points"; PointGeometryModel3D pointGeometry3D; if (model3DDictionary.ContainsKey(id)) { pointGeometry3D = model3DDictionary[id] as PointGeometryModel3D; } else { pointGeometry3D = new PointGeometryModel3D { Geometry = HelixRenderPackage.InitPointGeometry(), Transform = Model1Transform, Color = SharpDX.Color.White, Figure = PointGeometryModel3D.PointFigure.Ellipse, Size = DefaultPointSize, IsHitTestVisible = true, IsSelected = rp.IsSelected }; model3DDictionary.Add(id, pointGeometry3D); } var points = pointGeometry3D.Geometry as PointGeometry3D; var startIdx = points.Positions.Count; points.Positions.AddRange(p.Positions); points.Colors.AddRange(p.Colors.Any() ? p.Colors : Enumerable.Repeat(defaultPointColor, points.Positions.Count)); points.Indices.AddRange(p.Indices.Select(i => i + startIdx)); if (rp.DisplayLabels) { var pt = p.Positions[0]; parameters.Text.TextInfo.Add(new TextInfo(HelixRenderPackage.CleanTag(rp.Description), new Vector3(pt.X + 0.025f, pt.Y + 0.025f, pt.Z + 0.025f))); Text = parameters.Text; } pointGeometry3D.Geometry = points; pointGeometry3D.Name = baseId; pointGeometry3D.MouseDown3D += meshGeometry3D_MouseDown3D; } var l = rp.Lines; if (l.Positions.Any()) { id = baseId + ":lines"; LineGeometryModel3D lineGeometry3D; if (model3DDictionary.ContainsKey(id)) { lineGeometry3D = model3DDictionary[id] as LineGeometryModel3D; } else { lineGeometry3D = new LineGeometryModel3D() { Geometry = HelixRenderPackage.InitLineGeometry(), Transform = Model1Transform, Color = SharpDX.Color.White, Thickness = 0.5, IsHitTestVisible = true, IsSelected = rp.IsSelected }; model3DDictionary.Add(id, lineGeometry3D); } var lineSet = lineGeometry3D.Geometry as LineGeometry3D; var startIdx = lineSet.Positions.Count; lineSet.Positions.AddRange(l.Positions); lineSet.Colors.AddRange(l.Colors.Any() ? l.Colors : Enumerable.Repeat(defaultLineColor, l.Positions.Count)); lineSet.Indices.AddRange(l.Indices.Any() ? l.Indices.Select(i => i + startIdx) : Enumerable.Range(startIdx, startIdx + l.Positions.Count)); if (rp.DisplayLabels) { var pt = lineSet.Positions[startIdx]; parameters.Text.TextInfo.Add(new TextInfo(HelixRenderPackage.CleanTag(rp.Description), new Vector3(pt.X + 0.025f, pt.Y + 0.025f, pt.Z + 0.025f))); Text = parameters.Text; } lineGeometry3D.Geometry = lineSet; lineGeometry3D.Name = baseId; lineGeometry3D.MouseDown3D += meshGeometry3D_MouseDown3D; } var m = rp.Mesh; if (!m.Positions.Any()) continue; id = ((rp.RequiresPerVertexColoration || rp.Colors != null) ? rp.Description : baseId) + ":mesh"; DynamoGeometryModel3D meshGeometry3D; if (model3DDictionary.ContainsKey(id)) { meshGeometry3D = model3DDictionary[id] as DynamoGeometryModel3D; } else { meshGeometry3D = new DynamoGeometryModel3D() { Transform = Model1Transform, Material = WhiteMaterial, IsHitTestVisible = true, RequiresPerVertexColoration = rp.RequiresPerVertexColoration, IsSelected = rp.IsSelected, }; if (rp.Colors != null) { var pf = PixelFormats.Bgra32; var stride = (rp.ColorsStride / 4 * pf.BitsPerPixel + 7) / 8; try { var diffMap = BitmapSource.Create(rp.ColorsStride/4, rp.Colors.Count()/rp.ColorsStride, 96.0, 96.0, pf, null, rp.Colors.ToArray(), stride); var diffMat = new PhongMaterial { Name = "White", AmbientColor = PhongMaterials.ToColor(0.1, 0.1, 0.1, 1.0), DiffuseColor = materialColor, SpecularColor = PhongMaterials.ToColor(0.0225, 0.0225, 0.0225, 1.0), EmissiveColor = PhongMaterials.ToColor(0.0, 0.0, 0.0, 1.0), SpecularShininess = 12.8f, DiffuseMap = diffMap }; meshGeometry3D.Material = diffMat; } catch (Exception ex) { Console.WriteLine(ex.Message); Console.WriteLine(ex.StackTrace); } } ((MaterialGeometryModel3D) meshGeometry3D).SelectionColor = selectionColor; model3DDictionary.Add(id, meshGeometry3D); } var mesh = meshGeometry3D.Geometry == null ? HelixRenderPackage.InitMeshGeometry() : meshGeometry3D.Geometry as MeshGeometry3D; var idxCount = mesh.Positions.Count; mesh.Positions.AddRange(m.Positions); mesh.Colors.AddRange(m.Colors); mesh.Normals.AddRange(m.Normals); mesh.TextureCoordinates.AddRange(m.TextureCoordinates); mesh.Indices.AddRange(m.Indices.Select(i => i + idxCount)); if (mesh.Colors.Any(c => c.Alpha < 1.0)) { meshGeometry3D.HasTransparency = true; } if (rp.DisplayLabels) { var pt = mesh.Positions[idxCount]; parameters.Text.TextInfo.Add(new TextInfo(HelixRenderPackage.CleanTag(rp.Description), new Vector3(pt.X + 0.025f, pt.Y + 0.025f, pt.Z + 0.025f))); Text = parameters.Text; } meshGeometry3D.Geometry = mesh; meshGeometry3D.Name = baseId; meshGeometry3D.MouseDown3D += meshGeometry3D_MouseDown3D; } Attach(); }
private void AddGeometryToExistingPoint(PointGeometryModel3D point, Vector3 location) { if (point == null || point.Geometry == null) return; point.Geometry.Positions.Add(location); point.Geometry.Colors.Add(new Color4()); point.Geometry.Indices.Add(point.Geometry.Indices.Any()? point.Geometry.Indices.Last() + 1: 0); }
private PointGeometryModel3D InitializePointWithId(string id, Vector3 location = new Vector3()) { var pointGeom = HelixRenderPackage.InitPointGeometry(); pointGeom.Positions.Add(location); pointGeom.Colors.Add(new Color4()); pointGeom.Indices.Add(0); var point = new PointGeometryModel3D { Geometry = pointGeom, Name = id }; return point; }
private PointGeometryModel3D CreatePointGeometryModel3D(HelixRenderPackage rp) { var pointGeometry3D = new PointGeometryModel3D { Geometry = HelixRenderPackage.InitPointGeometry(), Transform = Model1Transform, Color = Color.White, Figure = PointGeometryModel3D.PointFigure.Ellipse, Size = defaultPointSize, IsHitTestVisible = true, IsSelected = rp.IsSelected }; return pointGeometry3D; }