public HelixRenderPackage() { points = InitPointGeometry(); lines = InitLineGeometry(); mesh = InitMeshGeometry(); lineStripVertexCounts = new List <int>(); }
private void ClearView() { // floor plane grid var Maxreset = 100; var Minreset = -100; EffectsManager.Dispose(); EffectsManager = new DefaultEffectsManager(); var points = new PointGeometry3D(); var col = new Color4Collection(); // gradient na kolory var ptPos = new Vector3Collection(); // pozycje punktów var ptIdx = new IntCollection(); // indeksy punktów arrows = lines = new LineBuilder(); points.Positions = ptPos; points.Indices = ptIdx; points.Colors = col; PointsColor = Colors.White; // <- nie pamiętam po co to tutaj ale bez tego nie działa Points = points; PointsTransform = new Media3D.TranslateTransform3D(0, 0, Minreset); CreateGrid(Maxreset, Minreset, Maxreset, Maxreset, Minreset); Grid = lines.ToLineGeometry3D(); GridColor = new Color4(153 / 255.0f, 204 / 255.0f, 255 / 255.0f, (float)0.3).ToColor();; GridTransform = new Media3D.TranslateTransform3D(0, 0, Minreset); // strzałki CreateArrows(Maxreset, Minreset, Maxreset, Minreset, Maxreset, Minreset); Arrow = arrows.ToLineGeometry3D(); ArrowColor = new Color4(0, 255 / 255.0f, 255 / 255.0f, (float)0.5).ToColor();; ArrowTransform = new Media3D.TranslateTransform3D(0, 0, Minreset); }
public MainViewModel() { EffectsManager = new EffectsManager(); var builder = new MeshBuilder(); builder.AddSphere(new Vector3(), 2); builder.AddTorus(5, 1); MeshModel = builder.ToMesh(); var lineBuilder = new LineBuilder(); lineBuilder.AddGrid(BoxFaces.All, 10, 10, 10, 10); LineModel = lineBuilder.ToLineGeometry3D(); var offset = new Vector3(-4, 0, 0); PointModel = new PointGeometry3D() { Positions = new Vector3Collection(MeshModel.Positions.Select(x => x + offset)) }; ExportCommand = new RelayCommand((o) => { Export(); }); ImportCommand = new RelayCommand((o) => { Import(); }); ExportSingleTechnique = new RelayCommand((o) => { Export(SelectedTechnique); }); }
void DrawBPPointCloudToSLAMPointCloud() { Stopwatch sw = new Stopwatch(); sw.Start(); VMStatus = $"Reconing......SLAM! {elapsedTime} ms"; var vc = new Vector3Collection(); var cc = new Color4Collection(); var tempposeVect = new List <double[]>(); var tempColorVect = new List <double[]>(); RealsenseControl.GetReconSLAMPointCloud(ref tempposeVect, ref tempColorVect); for (int i = 0; i < tempposeVect.Count; i++) { vc.Add(new Vector3(Convert.ToSingle(tempposeVect[i][0]), Convert.ToSingle(tempposeVect[i][1]), Convert.ToSingle(tempposeVect[i][2]))); cc.Add(new Color4(Convert.ToSingle(tempColorVect[i][0]), Convert.ToSingle(tempColorVect[i][1]), Convert.ToSingle(tempColorVect[i][2]), 0.5f)); } SLAMReconPointCloud = new PointGeometry3D() { Positions = vc, Colors = cc }; sw.Stop(); elapsedTime = sw.ElapsedMilliseconds; VMStatus = "Reconing......SLAM Done!"; }
public HelixRenderPackage() { points = InitPointGeometry(); lines = InitLineGeometry(); mesh = InitMeshGeometry(); lineStripVertexCounts = new List <int>(); Transform = System.Windows.Media.Media3D.Matrix3D.Identity.ToArray(); }
private void CreateDefaultModels() { Material = PhongMaterials.White; var b2 = new MeshBuilder(true, true, true); b2.AddSphere(new Vector3(15f, 0f, 0f), 4, 64, 64); b2.AddSphere(new Vector3(25f, 0f, 0f), 2, 32, 32); b2.AddTube(new Vector3[] { new Vector3(10f, 5f, 0f), new Vector3(10f, 7f, 0f) }, 2, 12, false, true, true); DefaultModel = b2.ToMeshGeometry3D(); DefaultModel.OctreeParameter.RecordHitPathBoundingBoxes = true; PointsModel = new PointGeometry3D(); var offset = new Vector3(1, 1, 1); PointsModel.Positions = new Vector3Collection(DefaultModel.Positions.Select(x => x + offset)); PointsModel.Indices = new IntCollection(Enumerable.Range(0, PointsModel.Positions.Count)); PointsModel.OctreeParameter.RecordHitPathBoundingBoxes = true; for (int i = 0; i < 50; ++i) { for (int j = 0; j < 10; ++j) { Items.Add(new SphereModel(new Vector3(i - 50, j - 25, i + j - 75), rnd.NextDouble(1, 3))); } } var b3 = new LineBuilder(); for (int i = 0; i < 10; ++i) { for (int j = 0; j < 5; ++j) { for (int k = 0; k < 5; ++k) { b3.AddBox(new Vector3(-10 - i * 5, j * 5, k * 5), 5, 5, 5); } } } LinesModel = b3.ToLineGeometry3D(); LinesModel.OctreeParameter.RecordHitPathBoundingBoxes = true; PointsHitModel = new PointGeometry3D() { Positions = new Vector3Collection(), Indices = new IntCollection() }; //var landerItems = Load3ds("Car.3ds").Select(x => new DataModel() { Model = x.Geometry as MeshGeometry3D, Material = PhongMaterials.Copper }).ToList(); //var scale = new Vector3(0.007f); //var offset = new Vector3(15, 15, 15); //foreach (var item in landerItems) //{ // for (int i = 0; i < item.Model.Positions.Count; ++i) // { // item.Model.Positions[i] = item.Model.Positions[i] * scale + offset; // } // item.Model.UpdateOctree(); //} //LanderItems = landerItems; }
public SEVDataModel() { PointGeometry3D = new PointGeometry3D { Indices = new IntCollection(), Positions = new Vector3Collection(), Colors = new Color4Collection() }; }
/// <summary> /// Add axis in positive, 0.1 m /// </summary> private void AddAxisPoints() { Vector3Collection vector3s = new Vector3Collection(); Color4Collection color4s = new Color4Collection(); vector3s.Add(new SharpDX.Vector3()); color4s.Add(new SharpDX.Color4(0, 0, 0, 1)); for (int i = 1; i < 50; i++) { if (i % 10 == 0) { vector3s.Add(new SharpDX.Vector3() { X = 0.1f * i }); color4s.Add(new SharpDX.Color4(0, 1, 1, 1)); vector3s.Add(new SharpDX.Vector3() { Y = 0.1f * i }); color4s.Add(new SharpDX.Color4(1, 0, 1, 1)); vector3s.Add(new SharpDX.Vector3() { Z = 0.1f * i }); color4s.Add(new SharpDX.Color4(1, 1, 0, 1)); } else { vector3s.Add(new SharpDX.Vector3() { X = 0.1f * i }); color4s.Add(new SharpDX.Color4(1, 0, 0, 1)); vector3s.Add(new SharpDX.Vector3() { Y = 0.1f * i }); color4s.Add(new SharpDX.Color4(0, 1, 0, 1)); vector3s.Add(new SharpDX.Vector3() { Z = 0.1f * i }); color4s.Add(new SharpDX.Color4(0, 0, 1, 1)); } } AxisPoint = new PointGeometry3D() { Positions = vector3s, Colors = color4s }; }
internal static PointGeometry3D InitPointGeometry() { var points = new PointGeometry3D() { Positions = new Vector3Collection(), Indices = new IntCollection(), Colors = new Color4Collection() }; return(points); }
private void StartSLAM() { IsSLAMOn = true; string temp = ""; RealsenseControl.StartSLAM(ref temp); RealsenseState = temp; Thread.Sleep(2000); SLAMPointCloud = new PointGeometry3D(); SLAMPoseInfo = new LineGeometry3D(); UpdateSLAMPointCloudTask = Task.Run(() => UpdateSLAMPointCloud()); }
private async Task StartSLAM() { IsSLAMOn = true; string temp = ""; await Task.Run(() => RealsenseControl.StartSLAM(ref temp)).ConfigureAwait(false); RealsenseState = temp; SLAMPointCloud = new PointGeometry3D(); SLAMPoseInfo = new LineGeometry3D(); UpdateSLAMPointCloudTask = Task.Run(() => UpdateSLAMPointCloud()); SLAMReconTaskAsync = Task.Run(() => SLAMRecon()); }
public DynaShapeDisplay(Solver solver) { this.solver = solver; pointGeometry = new PointGeometry3D { Positions = new Vector3Collection(), Indices = new IntCollection(), Colors = new Color4Collection() }; lineGeometry = new LineGeometry3D() { Positions = new Vector3Collection(), Indices = new IntCollection(), Colors = new Color4Collection() }; DynaShapeViewExtension.DynamoWindow.Dispatcher.Invoke( () => { pointModel = new PointGeometryModel3D { Size = new Size(5, 5), Figure = PointGeometryModel3D.PointFigure.Ellipse, Color = Color.White, }; lineModel = new LineGeometryModel3D { Thickness = 0.5, Color = Color.White, }; List <string> info1 = new List <string>(); foo(DynaShapeViewExtension.DynamoWindow.Content, info1, 0); List <string> info2 = new List <string>(); ListContent(DynaShapeViewExtension.DynamoWindow.Content as Grid, 0, info2); }, DispatcherPriority.Send); DynaShapeViewExtension.ViewModel.RequestViewRefresh += RequestViewRefreshHandler; DynaShapeViewExtension.DynamoWindow.Closed += (sender, args) => { Dispose(); }; }
public void Clear() { points = null; mesh = null; lines = null; points = InitPointGeometry(); mesh = InitMeshGeometry(); lines = InitLineGeometry(); lineStripVertexCounts.Clear(); IsSelected = false; DisplayLabels = false; }
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; model.Name = "Points"; models.Add(model); return(models.ToArray()); }
/// <summary> /// Called when [build vertex array]. /// </summary> /// <param name="geometry">The geometry.</param> /// <returns></returns> protected override PointsVertex[] OnBuildVertexArray(PointGeometry3D geometry) { var positions = geometry.Positions; var vertexCount = geometry.Positions.Count; var array = vertexArrayBuffer != null && vertexArrayBuffer.Length >= vertexCount ? vertexArrayBuffer : new PointsVertex[vertexCount]; var colors = geometry.Colors != null?geometry.Colors.GetEnumerator() : Enumerable.Repeat(Color4.White, vertexCount).GetEnumerator(); vertexArrayBuffer = array; for (var i = 0; i < vertexCount; i++) { colors.MoveNext(); array[i].Position = new Vector4(positions[i], 1f); array[i].Color = colors.Current; } colors.Dispose(); return(array); }
private void LoadThreadFunction() { PCD wrapper = new PCD(); Points[] rawPoints = wrapper.LoadPointcloud(Location); var points = new PointGeometry3D(); var col = new Color4Collection(); var ptPos = new Vector3Collection(); var ptIdx = new IntCollection(); var ptNormals = new Vector3Collection(); var numberOfElements = rawPoints.Length; var additionalTurns = 0; foreach (var point in rawPoints) { ptIdx.Add(ptPos.Count); ptPos.Add(new Vector3(point.x, point.z, -point.y)); col.Add(new Color4(new Color3(point.r / (float)255, point.g / (float)255, point.b / (float)255))); ptNormals.Add(new Vector3(0, 1, 0)); } if ((rawPoints.Length / 3) * 3 != rawPoints.Length) { additionalTurns = ((rawPoints.Length / 3 + 1) * 3) - rawPoints.Length; } for (int i = 0; i < additionalTurns; i++) { ptIdx.Add(ptPos.Count); ptPos.Add(ptPos[ptPos.Count - 1]); col.Add(col[col.Count - 1]); ptNormals.Add(ptNormals[ptNormals.Count - 1]); } points.Positions = ptPos; points.Indices = ptIdx; points.Colors = col; //points.Normals = ptNormals; Data = points; }
private void DrawBP() { VMStatus = "Drawing BP"; Task.Run(() => { var bpData = ImageRecon.BPtoPointCloud(ImageSpace, binaryToLMData.LACC.ListedLMData, BPAngleThreshold, BPMinCountPercent); var bpVectors = bpData.Item1; var bpColor4s = bpData.Item2; ReconPoint = new PointGeometry3D() { Positions = bpVectors, Colors = bpColor4s }; VMStatus = "Drawing BP Done"; }); }
public void UpdateSLAMPointCloud() { int Error = 0; var pose = new List <HelixToolkit.Wpf.SharpDX.Geometry3D.Line>(); var line = new LineBuilder(); Vector3 previousPose = new Vector3(Convert.ToSingle(poseX), Convert.ToSingle(poseY), Convert.ToSingle(poseZ)); while (IsSLAMOn) { var vc = new Vector3Collection(); var id = new IntCollection(); var cc = new Color4Collection(); var poseVect = new List <double[]>(); var colorVect = new List <double[]>(); Vector3 currentPose = new Vector3(Convert.ToSingle(poseX), Convert.ToSingle(poseY), Convert.ToSingle(poseZ)); line.AddLine(previousPose, currentPose); SLAMPoseInfo = line.ToLineGeometry3D(); previousPose = currentPose; try { RealsenseControl.GetSLAMPointCloud(ref poseVect, ref colorVect, T265ToLACCOffset.X, T265ToLACCOffset.Y, T265ToLACCOffset.Z); for (int i = 0; i < poseVect.Count; i++) { vc.Add(new Vector3(Convert.ToSingle(poseVect[i][0]), Convert.ToSingle(poseVect[i][1]), Convert.ToSingle(poseVect[i][2]))); cc.Add(new Color4(0.1f, 0.1f, 0.1f, 0.5f)); //cc.Add(new Color4(Convert.ToSingle(colorVect[i][0]), Convert.ToSingle(colorVect[i][1]), Convert.ToSingle(colorVect[i][2]), 0.5f)); id.Add(i); } SLAMPointCloud = new PointGeometry3D() { Positions = vc, Indices = id, Colors = cc }; } catch { Error++; Trace.WriteLine("Error Count is " + Error); } Thread.Sleep(50); } }
public DynaShapeDisplay(Solver solver) { this.solver = solver; pointGeometry = new PointGeometry3D { Positions = new Vector3Collection(), Indices = new IntCollection(), Colors = new Color4Collection() }; lineGeometry = new LineGeometry3D() { Positions = new Vector3Collection(), Indices = new IntCollection(), Colors = new Color4Collection() }; billboardText = new BillboardText3D(); DynaShapeViewExtension.DynamoWindow.Dispatcher.Invoke( () => { pointModel = new PointGeometryModel3D { Size = new Size(5, 5), Figure = PointGeometryModel3D.PointFigure.Ellipse, Color = Color.White, }; lineModel = new LineGeometryModel3D { Thickness = 0.5, Color = Color.White, }; billboardTextModel = new BillboardTextModel3D() { }; }, DispatcherPriority.Send); DynaShapeViewExtension.ViewModel.RequestViewRefresh += RequestViewRefreshHandler; DynaShapeViewExtension.DynamoWindow.Closed += (sender, args) => Dispose(); }
public void Clear() { points = null; mesh = null; lines = null; points = InitPointGeometry(); mesh = InitMeshGeometry(); lines = InitLineGeometry(); lineStripVertexCounts.Clear(); Transform = System.Windows.Media.Media3D.Matrix3D.Identity.ToArray(); IsSelected = false; DisplayLabels = false; colors = null; }
private void LoadThreadFunction() { var pt = new PotreeNode(new Uri(Location)); var points = new PointGeometry3D(); var col = new Color4Collection(); var ptPos = new Vector3Collection(); var ptIdx = new IntCollection(); var j = 0; foreach (var p in pt.Compilation.Points) { ptPos.Add(new Vector3(p.x, p.y, p.z)); ptIdx.Add(j); col.Add(new Color4(p.r / 255f, p.g / 255f, p.b / 255f, p.a / 255f)); j++; } var additionalTurns = 0; if ((pt.Compilation.Points.Count / 3) * 3 != pt.Compilation.Points.Count) { additionalTurns = ((pt.Compilation.Points.Count / 3 + 1) * 3) - pt.Compilation.Points.Count; } for (int i = 0; i < additionalTurns; i++) { ptIdx.Add(ptPos.Count); ptPos.Add(ptPos[ptPos.Count - 1]); col.Add(col[col.Count - 1]); } points.Positions = ptPos; points.Indices = ptIdx; points.Colors = col; Data = points; }
public static PointGeometry3D ConvertToPointGeometry3D(Points[] points) { var geometry = new PointGeometry3D(); var col = new Color4Collection(); var ptPos = new Vector3Collection(); var ptIdx = new IntCollection(); var ptNormals = new Vector3Collection(); var additionalTurns = 0; foreach (var point in points) { ptIdx.Add(ptPos.Count); ptPos.Add(new Vector3(point.x, point.y, point.z)); col.Add(new Color4(new Color3(point.r / (float)255, point.g / (float)255, point.b / (float)255))); ptNormals.Add(new Vector3(0, 1, 0)); } if ((points.Length / 3) * 3 != points.Length) { additionalTurns = ((points.Length / 3 + 1) * 3) - points.Length; } for (int i = 0; i < additionalTurns; i++) { ptIdx.Add(ptPos.Count); ptPos.Add(ptPos[ptPos.Count - 1]); col.Add(col[col.Count - 1]); ptNormals.Add(ptNormals[ptNormals.Count - 1]); } geometry.Positions = ptPos; geometry.Indices = ptIdx; geometry.Colors = col; return(geometry); }
public void UpdateRealTimePointCloud() { int error = 0; while (IsRealsensePipelineOn) { var vc = new Vector3Collection(); var id = new IntCollection(); var cc = new Color4Collection(); var poseVect = new List <double[]>(); var colorVect = new List <double[]>(); //Debug.WriteLine("Start to get Reatime Data"); try { RealsenseControl.GetRealTimePointCloud(ref poseVect, ref colorVect, T265ToLACCOffset.X, T265ToLACCOffset.Y, T265ToLACCOffset.Z); for (int i = 0; i < poseVect.Count; i++) { vc.Add(new Vector3(Convert.ToSingle(poseVect[i][0]), Convert.ToSingle(poseVect[i][1]), Convert.ToSingle(poseVect[i][2]))); cc.Add(new Color4(Convert.ToSingle(colorVect[i][0]), Convert.ToSingle(colorVect[i][1]), Convert.ToSingle(colorVect[i][2]), 0.8f)); //id.Add(i); } RTPointCloud = new PointGeometry3D() { Positions = vc, Colors = cc }; } catch { error++; Trace.WriteLine("Error Count is " + error); } } }
public void UpdateSLAMPointCloud() { var line = new LineBuilder(); Vector3 previousPose = new Vector3(Convert.ToSingle(systemPoseX), Convert.ToSingle(systemPoseY), Convert.ToSingle(systemPoseZ)); var poseVect = new List <double[]>(); var colorVect = new List <double[]>(); Point3D lineVect = new Point3D(0, 0, 0.3); while (IsSLAMOn) { Thread.Sleep(500); var vc = new Vector3Collection(); var cc = new Color4Collection(); poseVect = new List <double[]>(); colorVect = new List <double[]>(); Vector3 currentPose = new Vector3(Convert.ToSingle(systemPoseX), Convert.ToSingle(systemPoseY), Convert.ToSingle(systemPoseZ)); line.AddLine(previousPose, currentPose); SLAMPoseInfo = line.ToLineGeometry3D(); previousPose = currentPose; RealsenseControl.GetSLAMPointCloud(ref poseVect, ref colorVect); for (int i = 0; i < poseVect.Count; i++) { vc.Add(new Vector3(Convert.ToSingle(poseVect[i][0]), Convert.ToSingle(poseVect[i][1]), Convert.ToSingle(poseVect[i][2]))); //cc.Add(new Color4(0.1f, 0.1f, 0.1f, 0.5f)); cc.Add(new Color4(Convert.ToSingle(colorVect[i][0]), Convert.ToSingle(colorVect[i][1]), Convert.ToSingle(colorVect[i][2]), 0.5f)); //id.Add(i); } for (int i = 0; i < 10; ++i) { var pointx = new Point3D(0.1 * i, 0, 0); var pointy = new Point3D(0, 0.1 * i, 0); var pointz = new Point3D(0, 0, 0.1 * i); vc.Add(new Vector3(Convert.ToSingle(pointx.X), Convert.ToSingle(pointx.Y), Convert.ToSingle(pointx.Z))); cc.Add(new Color4(1f, 0f, 0f, 1f)); vc.Add(new Vector3(Convert.ToSingle(pointy.X), Convert.ToSingle(pointy.Y), Convert.ToSingle(pointy.Z))); cc.Add(new Color4(0f, 1f, 0f, 1f)); vc.Add(new Vector3(Convert.ToSingle(pointz.X), Convert.ToSingle(pointz.Y), Convert.ToSingle(pointz.Z))); cc.Add(new Color4(0f, 0f, 1f, 1f)); } for (int i = 0; i < 10; ++i) { var pointx = currentSystemTranformation.Transform(new Point3D(0.1 * i, 0, 0)); var pointy = currentSystemTranformation.Transform(new Point3D(0, 0.1 * i, 0)); var pointz = currentSystemTranformation.Transform(new Point3D(0, 0, 0.1 * i)); vc.Add(new Vector3(Convert.ToSingle(pointx.X), Convert.ToSingle(pointx.Y), Convert.ToSingle(pointx.Z))); cc.Add(new Color4(1f, 0f, 0f, 1f)); vc.Add(new Vector3(Convert.ToSingle(pointy.X), Convert.ToSingle(pointy.Y), Convert.ToSingle(pointy.Z))); cc.Add(new Color4(0f, 1f, 0f, 1f)); vc.Add(new Vector3(Convert.ToSingle(pointz.X), Convert.ToSingle(pointz.Y), Convert.ToSingle(pointz.Z))); cc.Add(new Color4(0f, 0f, 1f, 1f)); } SLAMPointCloud = new PointGeometry3D() { Positions = vc, Colors = cc }; SLAMVector3s = vc; } Debug.WriteLine("SLAM Point Cloud Count is " + poseVect.Count); }
public MainViewModel() { // titles this.Title = "Simple Demo"; this.SubTitle = "WPF & SharpDX"; // camera setup this.Camera = new PerspectiveCamera { Position = new Point3D(3, 3, 5), LookDirection = new Vector3D(-3, -3, -5), UpDirection = new Vector3D(0, 1, 0) }; // default render technique this.RenderTechnique = Techniques.RenderBlinn; // setup lighting this.AmbientLightColor = new Color4(0.1f, 0.1f, 0.1f, 1.0f); this.DirectionalLightColor = Color.White; this.DirectionalLightDirection = new Vector3(-2, -5, -2); // floor plane grid this.Grid = LineBuilder.GenerateGrid(); this.GridColor = SharpDX.Color.Black; this.GridTransform = new Media3D.TranslateTransform3D(-5, -1, -5); // scene model3d var b1 = new MeshBuilder(); b1.AddSphere(new Vector3(0, 0, 0), 0.5); b1.AddBox(new Vector3(0, 0, 0), 1, 0.5, 2, BoxFaces.All); var meshGeometry = b1.ToMeshGeometry3D(); meshGeometry.Colors = new Color4Collection(meshGeometry.TextureCoordinates.Select(x => x.ToColor4())); this.Model = meshGeometry; // lines model3d var e1 = new LineBuilder(); e1.AddBox(new Vector3(0, 0, 0), 1, 0.5, 2); this.Lines = e1.ToLineGeometry3D(); // model trafos this.Model1Transform = new Media3D.TranslateTransform3D(0, 0, 0); this.Model2Transform = new Media3D.TranslateTransform3D(-2, 0, 0); this.Model3Transform = new Media3D.TranslateTransform3D(+2, 0, 0); // model materials this.RedMaterial = PhongMaterials.Red; this.GreenMaterial = PhongMaterials.Green; this.BlueMaterial = PhongMaterials.Blue; //var diffColor = this.RedMaterial.DiffuseColor; //diffColor.Alpha = 0.5f; //this.RedMaterial.DiffuseColor = diffColor; Points = new PointGeometry3D(); var ptPos = new Vector3Collection(); var ptIdx = new IntCollection(); for (int x = 0; x < 10; x++) { for (int y = 0; y < 10; y++) { for (int z = 0; z < 10; z++) { ptIdx.Add(ptPos.Count); ptPos.Add(new Vector3(x, y, z)); } } } Points.Positions = ptPos; Points.Indices = ptIdx; Text = new BillboardText3D(); for (var i = 0; i < 50; i++) { for (var j = 0; j < 50; j++) { Text.TextInfo.Add(new TextInfo("Hello World", new Vector3(i, j, 0))); } } }
public MainWindow() { DataContext = this; InitializeComponent(); #region Create planes var builder = new MeshBuilder(true, false, false); builder.AddRectangularMesh(BoxFaces.Front, 10, 10, 100, 100); PlaneGeometry = builder.ToMesh(); RedDiffuseMaterial = new hx.DiffuseMaterial() { DiffuseColor = new Color4(1f, 0f, 0f, 0.5f), }; BlueDiffuseMaterial = new hx.DiffuseMaterial() { DiffuseColor = new Color4(0f, 0f, 1f, 0.5f), }; RedPhongMaterial = new PhongMaterial() { AmbientColor = new Color4(1f, 0f, 0f, 0.5f), }; BluePhongMaterial = new PhongMaterial() { AmbientColor = new Color4(0f, 0f, 1f, 0.5f), }; var matrix = new Matrix3D(); matrix.Translate(new Vector3D(-125, -50, 0)); RedDiffusePlaneTransform = new MatrixTransform3D(matrix); matrix = new Matrix3D(); matrix.Translate(new Vector3D(-125, -50, 50)); BlueDiffusePlaneTransform = new MatrixTransform3D(matrix); matrix = new Matrix3D(); matrix.Translate(new Vector3D(25, -50, 0)); RedPhongPlaneTransform = new MatrixTransform3D(matrix); matrix = new Matrix3D(); matrix.Translate(new Vector3D(25, -50, 50)); BluePhongPlaneTransform = new MatrixTransform3D(matrix); #endregion #region Create points PointsGeometry = new PointGeometry3D() { Positions = new Vector3Collection(new Vector3[] { new Vector3(0, 0, 5), }), }; PointsInstances = new List <Matrix>(); for (var x = -50; x <= 50; x += 10) { var matrix2 = Matrix.Translation(x, x / 5f, x / 5f); PointsInstances.Add(matrix2); } matrix = new Matrix3D(); matrix.Translate(new Vector3D(-75, 0, 0)); DiffusePointsTransform = new MatrixTransform3D(matrix); matrix = new Matrix3D(); matrix.Translate(new Vector3D(75, 0, 0)); PhongPointsTransform = new MatrixTransform3D(matrix); #endregion if (viewport.Camera is hx.OrthographicCamera camera) { camera.NearPlaneDistance = -5000; camera.FarPlaneDistance = 5000; camera.LookDirection = new Vector3D(0, 0, -10); camera.Position = new Point3D(0, 0, 11); camera.UpDirection = new Vector3D(0, 1, 0); camera.Width = 300; } }
public MainPageViewModel() { EffectsManager = new DefaultEffectsManager(new Logger()); Camera = new PerspectiveCamera() { Position = new Vector3(40, 10, 100), LookDirection = new Vector3(0, -10, -100), UpDirection = UpDirection, FarPlaneDistance = 500, NearPlaneDistance = 0.1 }; Camera1 = new OrthographicCamera() { Position = new Vector3(60, 10, 100), LookDirection = new Vector3(0, -10, -100), UpDirection = upDirection, Width = 30, FarPlaneDistance = 500, NearPlaneDistance = 20 }; var builder = new MeshBuilder(true, true, true); builder.AddBox(new SharpDX.Vector3(0, 0, 0), 2, 2, 2); builder.AddSphere(new Vector3(0, 2, 0), 1.5); Geometry = builder.ToMesh(); Geometry.UpdateOctree(); builder = new MeshBuilder(); builder.AddSphere(new Vector3(0, 2, 0), 2); Sphere = builder.ToMesh(); Sphere.UpdateOctree(); Material = new PhongMaterial() { AmbientColor = Color.Gray, DiffuseColor = new Color4(0.75f, 0.75f, 0.75f, 1.0f), SpecularColor = Color.White, SpecularShininess = 10f, ReflectiveColor = new Color4(0.2f, 0.2f, 0.2f, 0.5f) }; Material.DiffuseMap = LoadTexture("TextureCheckerboard2.jpg"); Material.NormalMap = LoadTexture("TextureCheckerboard2_dot3.jpg"); Material1 = Material.Clone(); Material1.ReflectiveColor = Color.Silver; Material1.RenderDiffuseMap = false; Material1.RenderNormalMap = false; var lineBuilder = new LineBuilder(); lineBuilder.AddLine(Vector3.Zero, new Vector3(5, 0, 0)); lineBuilder.AddLine(Vector3.Zero, new Vector3(0, 5, 0)); lineBuilder.AddLine(Vector3.Zero, new Vector3(0, 0, 5)); LineGeometry = lineBuilder.ToLineGeometry3D(); LineGeometry.Colors = new HelixToolkit.UWP.Core.Color4Collection() { Color.Red, Color.Red, Color.Green, Color.Green, Color.Blue, Color.Blue }; builder = new MeshBuilder(); builder.AddSphere(new Vector3(), 3); var mesh = builder.ToMesh(); mesh.UpdateOctree(); PointGeometry = new PointGeometry3D() { Positions = mesh.Positions }; AxisLabelGeometry = new BillboardText3D(); AxisLabelGeometry.TextInfo.Add(new TextInfo("X", new Vector3(5.5f, 0, 0)) { Foreground = Color.Red }); AxisLabelGeometry.TextInfo.Add(new TextInfo("Y", new Vector3(0, 5.5f, 0)) { Foreground = Color.Green }); AxisLabelGeometry.TextInfo.Add(new TextInfo("Z", new Vector3(0, 0, 5.5f)) { Foreground = Color.Blue }); builder = new MeshBuilder(); builder.AddBox(new Vector3(0, -6, 0), 30, 0.5, 30); FloorModel = builder.ToMesh(); FloorMaterial = PhongMaterials.Obsidian; FloorMaterial.ReflectiveColor = Color.Silver; EnvironmentMap = LoadTexture("Cubemap_Grandcanyon.dds"); UpDirXCommand = new RelayCommand(() => { UpDirection = Vector3.UnitX; }, () => { return(UpDirection != Vector3.UnitX); }); UpDirYCommand = new RelayCommand(() => { UpDirection = Vector3.UnitY; }, () => { return(UpDirection != Vector3.UnitY); }); UpDirZCommand = new RelayCommand(() => { UpDirection = Vector3.UnitZ; }, () => { return(UpDirection != Vector3.UnitZ); }); timer = new DispatcherTimer(); timer.Tick += Timer_Tick; timer.Interval = new TimeSpan(0, 0, 0, 0, 16); timer.Start(); }
public MainViewModel() { EffectsManager = new DefaultEffectsManager(); // titles Title = "Simple Demo"; SubTitle = "WPF & SharpDX"; // camera setup Camera = new PerspectiveCamera { Position = new Point3D(3, 3, 5), LookDirection = new Vector3D(-3, -3, -5), UpDirection = new Vector3D(0, 1, 0), FarPlaneDistance = 5000000 }; // setup lighting AmbientLightColor = Colors.DimGray; DirectionalLightColor = Colors.White; DirectionalLightDirection = new Vector3D(-2, -5, -2); // floor plane grid Grid = LineBuilder.GenerateGrid(new Vector3(0, 1, 0), -5, 5, -5, 5); GridColor = Colors.Black; GridTransform = new Media3D.TranslateTransform3D(0, -3, 0); // scene model3d var b1 = new MeshBuilder(); b1.AddSphere(new Vector3(0, 0, 0), 0.5); b1.AddBox(new Vector3(0, 0, 0), 1, 0.5, 2, BoxFaces.All); var meshGeometry = b1.ToMeshGeometry3D(); meshGeometry.Colors = new Color4Collection(meshGeometry.TextureCoordinates.Select(x => x.ToColor4())); Model = meshGeometry; // lines model3d var e1 = new LineBuilder(); e1.AddBox(new Vector3(0, 0, 0), 1, 0.5, 2); Lines = e1.ToLineGeometry3D(); var textBuilder = new MeshBuilder(); textBuilder.ExtrudeText("HelixToolkit.SharpDX", "Arial", System.Windows.FontStyles.Normal, System.Windows.FontWeights.Bold, 14, new Vector3(1, 0, 0), new Vector3(0, 0, 0), new Vector3(0, 0, 1)); TextModel = textBuilder.ToMesh(); // model trafos Model1Transform = new Media3D.TranslateTransform3D(0, 0, 0); Model2Transform = new Media3D.TranslateTransform3D(-2, 0, 0); Model3Transform = new Media3D.TranslateTransform3D(+2, 0, 0); Model4Transform = new Media3D.TranslateTransform3D(-8, 0, -5); // model materials RedMaterial = PhongMaterials.Red; GreenMaterial = PhongMaterials.Green; BlueMaterial = PhongMaterials.Blue; //var diffColor = this.RedMaterial.DiffuseColor; //diffColor.Alpha = 0.5f; //this.RedMaterial.DiffuseColor = diffColor; Points = new PointGeometry3D(); var ptPos = new Vector3Collection(); var ptIdx = new IntCollection(); for (int x = 0; x < 10; x++) { for (int y = 0; y < 10; y++) { for (int z = 0; z < 10; z++) { ptIdx.Add(ptPos.Count); ptPos.Add(new Vector3(x, y, z)); } } } Points.Positions = ptPos; Points.Indices = ptIdx; Text = new BillboardText3D(); int numRows = 11; int numColumns = 11; string[] texts = new string[] { "HelixToolkit", "abcde", "random", "SharpDX", "DirectX" }; float angle = 0; for (var i = 0; i < numRows; i++) { for (var j = 0; j < numColumns; j++) { angle += (float)Math.PI / 10; Text.TextInfo.Add(new TextInfo(texts[(i + j) % texts.Length], new Vector3((i - numRows / 2), 0.0f, (j - numColumns / 2))) { Foreground = new Color4((float)i / numRows, 1 - (float)i / numRows, (float)(numColumns - j) / numColumns, 1f), Background = new Color4(1 - (float)i / numRows, (float)(numColumns - j) / numColumns, (float)i / numRows, 0.8f), Scale = Math.Max(0.01f, (float)i / numRows * 0.02f), Angle = angle }); } } Billboard1Model = new BillboardSingleText3D() { TextInfo = new TextInfo("Model 1", new Vector3(0, 1, 0)) { Angle = 0 }, FontColor = Colors.Blue.ToColor4(), FontSize = 12, BackgroundColor = Colors.Plum.ToColor4(), FontStyle = System.Windows.FontStyles.Italic, Padding = new System.Windows.Thickness(2), }; var background = Colors.Blue; background.A = (byte)120; Billboard2Model = new BillboardSingleText3D() { TextInfo = new TextInfo("Model 2", new Vector3(2, 1, 0)) { Angle = -(float)Math.PI / 3 }, FontSize = 12, FontColor = Colors.Green.ToColor4(), BackgroundColor = background.ToColor4(), FontWeight = System.Windows.FontWeights.Bold, Padding = new System.Windows.Thickness(2), }; background = Colors.Purple; background.A = (byte)50; Billboard3Model = new BillboardSingleText3D(2, 0.8f) { TextInfo = new TextInfo("Model 3", new Vector3(-2, 1, 0)) { Angle = -(float)Math.PI / 6 }, FontSize = 12, FontColor = Colors.Red.ToColor4(), BackgroundColor = background.ToColor4(), FontFamily = "Times New Roman", FontStyle = System.Windows.FontStyles.Italic, Padding = new System.Windows.Thickness(2), }; //BillboardImageModel = new BillboardSingleImage3D(CreateBitmapSample()) { MaskColor = Color.Black }; BillboardImageModel = new BillboardSingleImage3D(CreatePNGSample(), 1, 1) { Angle = -(float)Math.PI / 5 }; BillboardImageModel.Center = new Vector3(2, 2, 0); UpXCommand = new RelayCommand(x => { UpDirection = new Vector3D(1, 0, 0); }); UpYCommand = new RelayCommand(x => { UpDirection = new Vector3D(0, 1, 0); }); UpZCommand = new RelayCommand(x => { UpDirection = new Vector3D(0, 0, 1); }); BackgroundTexture = BitmapExtensions.CreateLinearGradientBitmapStream(EffectsManager, 128, 128, Direct2DImageFormat.Bmp, new Vector2(0, 0), new Vector2(0, 128), new SharpDX.Direct2D1.GradientStop[] { new SharpDX.Direct2D1.GradientStop() { Color = Colors.White.ToColor4(), Position = 0f }, new SharpDX.Direct2D1.GradientStop() { Color = Colors.DarkGray.ToColor4(), Position = 1f } }); }
public void OnMouseLeftButtonDownHandler(object sender, System.Windows.Input.MouseButtonEventArgs e) { foreach (var item in HighlightItems) { item.Highlight = false; } HighlightItems.Clear(); Material = PhongMaterials.White; var viewport = sender as Viewport3DX; if (viewport == null) { return; } var point = e.GetPosition(viewport); var hitTests = viewport.FindHits(point); if (hitTests != null && hitTests.Count > 0) { if (HitThrough) { foreach (var hit in hitTests) { if ((hit.ModelHit as Element3D).DataContext is DataModel) { var model = (hit.ModelHit as Element3D).DataContext as DataModel; model.Highlight = true; HighlightItems.Add(model); } else if ((hit.ModelHit as Element3D).DataContext == this) { if (hit.TriangleIndices != null) { Material = PhongMaterials.Yellow; } else { var v = new Vector3Collection(); v.Add(hit.PointHit); PointsHitModel.Positions = v; var idx = new IntCollection(); idx.Add(0); PointsHitModel = new PointGeometry3D() { Positions = v, Indices = idx }; } } } } else { var hit = hitTests[0]; if ((hit.ModelHit as Element3D).DataContext is DataModel) { var model = (hit.ModelHit as Element3D).DataContext as DataModel; model.Highlight = true; HighlightItems.Add(model); } else if ((hit.ModelHit as Element3D).DataContext == this) { if (hit.TriangleIndices != null) { Material = PhongMaterials.Yellow; } else { var v = new Vector3Collection(); v.Add(hit.PointHit); PointsHitModel.Positions = v; var idx = new IntCollection(); idx.Add(0); PointsHitModel = new PointGeometry3D() { Positions = v, Indices = idx }; } } } } }
public MainViewModel() { // titles this.Title = "DynamicTexture Demo"; this.SubTitle = "WPF & SharpDX"; EffectsManager = new DefaultEffectsManager(); this.Camera = new HelixToolkit.Wpf.SharpDX.PerspectiveCamera { Position = new Point3D(10, 10, 10), LookDirection = new Vector3D(-10, -10, -10), UpDirection = new Vector3D(0, 1, 0) }; this.Light1Color = Colors.White; this.Light1Direction = new Vector3D(-10, -10, -10); this.AmbientLightColor = Colors.Black; var b2 = new MeshBuilder(true, true, true); b2.AddSphere(new Vector3(0f, 0f, 0f), 4, 64, 64); this.Model = b2.ToMeshGeometry3D(); Model.IsDynamic = true; this.InnerModel = new MeshGeometry3D() { Indices = Model.Indices, Positions = Model.Positions, Normals = Model.Normals, TextureCoordinates = Model.TextureCoordinates, Tangents = Model.Tangents, BiTangents = Model.BiTangents, IsDynamic = true }; var image = TextureModel.Create(new System.Uri(@"test.png", System.UriKind.RelativeOrAbsolute).ToString()); this.ModelMaterial = new PhongMaterial { AmbientColor = Colors.Gray.ToColor4(), DiffuseColor = Colors.White.ToColor4(), SpecularColor = Colors.White.ToColor4(), SpecularShininess = 100f, DiffuseAlphaMap = image, DiffuseMap = TextureModel.Create(new System.Uri(@"TextureCheckerboard2.dds", System.UriKind.RelativeOrAbsolute).ToString()), NormalMap = TextureModel.Create(new System.Uri(@"TextureCheckerboard2_dot3.dds", System.UriKind.RelativeOrAbsolute).ToString()), }; this.InnerModelMaterial = new PhongMaterial { AmbientColor = Colors.Gray.ToColor4(), DiffuseColor = new Color4(0.75f, 0.75f, 0.75f, 1.0f), SpecularColor = Colors.White.ToColor4(), SpecularShininess = 100f, DiffuseAlphaMap = image, DiffuseMap = TextureModel.Create(new System.Uri(@"TextureNoise1.jpg", System.UriKind.RelativeOrAbsolute).ToString()), NormalMap = ModelMaterial.NormalMap }; initialPosition = Model.Positions; initialIndicies = Model.Indices; #region Point Model PointModel = new PointGeometry3D() { IsDynamic = true, Positions = Model.Positions }; int count = PointModel.Positions.Count; var colors = new Color4Collection(count); for (int i = 0; i < count / 2; ++i) { colors.Add(new Color4(0, 1, 1, 1)); } for (int i = 0; i < count / 2; ++i) { colors.Add(new Color4(0, 0, 0, 0)); } PointModel.Colors = colors; #endregion #region Line Model LineModel = new LineGeometry3D() { IsDynamic = true, Positions = new Vector3Collection(PointModel.Positions) }; LineModel.Positions.Add(Vector3.Zero); var indices = new IntCollection(count * 2); for (int i = 0; i < count; ++i) { indices.Add(count); indices.Add(i); } LineModel.Indices = indices; colors = new Color4Collection(LineModel.Positions.Count); for (int i = 0; i < count; ++i) { colors.Add(new Color4((float)i / count, 1 - (float)i / count, 0, 1)); } colors.Add(Colors.Blue.ToColor4()); LineModel.Colors = colors; LineMaterial = new LineArrowHeadMaterial() { Color = Colors.White, Thickness = 0.5, ArrowSize = 0.02 }; #endregion var token = cts.Token; Task.Run(() => { while (!token.IsCancellationRequested) { Timer_Tick(); Task.Delay(16).Wait(); } }, token); //timer.Interval = TimeSpan.FromMilliseconds(16); //timer.Tick += Timer_Tick; //timer.Start(); }