public MainViewModel() { EffectsManager = new DefaultEffectsManager(); this.Title = "Line Shading Demo (HelixToolkitDX)"; this.SubTitle = null; // camera setup this.Camera = new PerspectiveCamera { Position = new Point3D(0, 5, 5), LookDirection = new Vector3D(-0, -5, -5), UpDirection = new Vector3D(0, 1, 0) }; // setup lighting this.AmbientLightColor = Colors.DimGray; this.DirectionalLightColor = Colors.White; this.DirectionalLightDirection = new Vector3D(-2, -5, -2); // floor plane grid this.Grid = LineBuilder.GenerateGrid(); this.GridColor = Media.Colors.Black; this.GridTransform = new 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); this.Model = b1.ToMeshGeometry3D(); // lines model3d var e1 = new LineBuilder(); e1.AddBox(new Vector3(0, 0, 0), 1, 0.5, 2); //this.Lines = e1.ToLineGeometry3D().ToUnshared(); this.Lines = e1.ToLineGeometry3D(true); this.Lines.Colors = new Color4Collection(); var linesCount = this.Lines.Indices.Count; var rnd = new Random(); while (linesCount-- > 0) { this.Lines.Colors.Add(rnd.NextColor()); } // lines params this.LineThickness = 2; this.LineSmoothness = 2.0; this.LinesEnabled = true; this.GridEnabled = true; // model trafos this.Model1Transform = new TranslateTransform3D(0, 0, 0); this.Model2Transform = new TranslateTransform3D(-2, 0, 0); this.Model3Transform = new TranslateTransform3D(+2, 0, 0); // model materials this.Material1 = PhongMaterials.PolishedGold; this.Material2 = PhongMaterials.Copper; this.Material3 = PhongMaterials.Glass; }
public MainViewModel() { // titles this.Title = "Deferred Shading Demo"; // camera setup this.Camera = new PerspectiveCamera { Position = new Point3D(3, 3, 5), LookDirection = new Vector3D(-3, -3, -5), UpDirection = new Vector3D(0, 1, 0) }; // clear color this.BackgroundColor = (Color4)Color.White; // default render technique this.RenderTechnique = Techniques.RenderDeferred; // setup lighting this.AmbientLightColor = new Color4(0.2f, 0.2f, 0.2f, 1.0f); this.DirectionalLightColor2 = Color.Red; this.DirectionalLightColor1 = Color.Green; this.DirectionalLightColor3 = Color.Blue; this.DirectionalLightDirection1 = new Vector3(-0, -50, -0); this.DirectionalLightDirection2 = new Vector3(-0, -50, -50); this.DirectionalLightDirection3 = new Vector3(-50, -50, -0); // 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(true, true, true); 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 = meshGeometry.TextureCoordinates.Select(x => x.ToColor4()).ToArray(); 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.White; this.RedMaterial.DiffuseMap = new BitmapImage(new System.Uri(@"TextureCheckerboard2.jpg", System.UriKind.RelativeOrAbsolute)); this.RedMaterial.NormalMap = new BitmapImage(new System.Uri(@"TextureCheckerboard2_dot3.jpg", System.UriKind.RelativeOrAbsolute)); this.GreenMaterial = PhongMaterials.DefaultVRML; //this.GreenMaterial.TextureMap = this.RedMaterial.TextureMap; this.BlueMaterial = PhongMaterials.Silver; //this.BlueMaterial.TextureMap = this.RedMaterial.TextureMap; }
private void Grbl_CoordinateChanged(object sender, EventArgs e) { var box = new LineBuilder(); box.AddBox(new Vector3((float)App.Grbl.MPOS.X, (float)App.Grbl.MPOS.Y, (float)App.Grbl.MPOS.Z + 10), 1, 1, 20); CurrentPosition = box.ToLineGeometry3D(); }
public override LineGeometry3D Build(double _startMarkerSize = 0.1) { LineBuilder b = new LineBuilder(); b.AddBox(this.Position, _startMarkerSize, _startMarkerSize, _startMarkerSize); return(b.ToLineGeometry3D()); }
static OcTreeManager() { LineBuilder b = new LineBuilder(); b.AddBox(Vector3.Zero, 1, 1, 1); CellFrame = b.ToLineGeometry3D(); EndPoint = LinesCutom.GetEndPointMarker(Vector3.Zero, (float)SNAPPOSMARKER_FACT * 0.8f); MidPoint = LinesCutom.GetMidPointMarker(Vector3.Zero, (float)SNAPPOSMARKER_FACT); IntPoint = LinesCutom.GetIntersectionMarker(Vector3.Zero, (float)SNAPPOSMARKER_FACT); ChamferedBoxMesh = MeshesCustom.GetChamferedBox(Vector3.Zero, 1f, 1f, 1f, 0.2f, 0.05f); MeshesCustom.CompressMesh(ref ChamferedBoxMesh); ChamferedBoxMesh_Normals = MeshesCustom.GetVertexNormalsAsLines(ChamferedBoxMesh, 0.15f); RedTransparent = new PhongMaterial(); RedTransparent.DiffuseColor = new Color4(0.8f, 0f, 0f, 0.25f); RedTransparent.AmbientColor = new Color4(0.6f, 0f, 0f, 1f); RedTransparent.SpecularColor = new Color4(1f, 0.75f, 0f, 1f); RedTransparent.SpecularShininess = 1; YellowTransparent = new PhongMaterial(); YellowTransparent.DiffuseColor = new Color4(1f, 0.93f, 0f, 0.5f); YellowTransparent.AmbientColor = new Color4(0.92f, 0.69f, 0f, 1f); YellowTransparent.SpecularColor = new Color4(1f, 1f, 1f, 1f); YellowTransparent.SpecularShininess = 3; }
public MainViewModel() { EffectsManager = new DefaultEffectsManager(); this.Title = "Manipulator Demo"; this.SubTitle = null; // camera setup this.Camera = new OrthographicCamera { Position = new Point3D(0, 0, 5), LookDirection = new Vector3D(0, 0, -5), UpDirection = new Vector3D(0, 1, 0) }; // setup lighting this.AmbientLightColor = Colors.DimGray; this.DirectionalLightColor = Colors.White; this.DirectionalLightDirection = new Vector3D(-2, -5, -2); // floor plane grid this.Grid = LineBuilder.GenerateGrid(); this.GridColor = Colors.Black; this.GridTransform = new 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, 1.5, BoxFaces.All); this.Model = b1.ToMeshGeometry3D(); var m1 = Load3ds("suzanne.3ds"); this.Model2 = m1[0].Geometry as MeshGeometry3D; //Manully set an offset for test for(int i=0; i < Model2.Positions.Count; ++i) { Model2.Positions[i] = Model2.Positions[i] + new Vector3(2, 3, 4); } Model2.UpdateBounds(); // lines model3d var e1 = new LineBuilder(); e1.AddBox(new Vector3(0, 0, 0), 1, 0.5, 1.5); this.Lines = e1.ToLineGeometry3D(); // model trafos this.Model1Transform = new TranslateTransform3D(0, 0, 0); this.Model2Transform = new TranslateTransform3D(-3, 0, 0); this.Model3Transform = new TranslateTransform3D(+3, 0, 0); // model materials this.Material1 = PhongMaterials.Orange; this.Material2 = PhongMaterials.Orange; this.Material3 = PhongMaterials.Red; var dr = Colors.DarkRed; Console.WriteLine(dr); ResetTransformsCommand = new RelayCommand((o) => { this.Model1Transform = new TranslateTransform3D(0, 0, 0); this.Model2Transform = new TranslateTransform3D(-3, 0, 0); this.Model3Transform = new TranslateTransform3D(+3, 0, 0); }); }
public override LineGeometry3D Build(double _startMarkerSize = 0.1) { this.ValidateGeometry(); if (!this.IsValid) { return(null); } int n = this.Coords0.Count; LineBuilder b1 = new LineBuilder(); b1.AddBox(this.Coords0[0].ToVector3(), _startMarkerSize, _startMarkerSize, _startMarkerSize); b1.AddLine(this.Coords0[0].ToVector3(), this.Coords1[0].ToVector3()); if (n == 1) { b1.AddBox(this.Coords1[0].ToVector3(), _startMarkerSize, _startMarkerSize, _startMarkerSize); } int nextInd = this.Connected[0]; if (nextInd == -1 && n > 1) { b1.AddBox(this.Coords1[0].ToVector3(), _startMarkerSize, _startMarkerSize, _startMarkerSize); } for (int i = 1; i < n; i++) { // next segment regardless of connectivity b1.AddLine(this.Coords0[i].ToVector3(), this.Coords1[i].ToVector3()); // mark end of connected segment nextInd = this.Connected[i]; if (nextInd == -1) { b1.AddBox(this.Coords1[i].ToVector3(), _startMarkerSize, _startMarkerSize, _startMarkerSize); if (i < (n - 1)) { b1.AddBox(this.Coords0[i + 1].ToVector3(), _startMarkerSize, _startMarkerSize, _startMarkerSize); } } } return(b1.ToLineGeometry3D()); }
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 MainViewModel() { // titles this.Title = "Simple Demo (Workitem 10043)"; this.SubTitle = "Please switch to Viewport 2 and then back to Viewport 1"; // camera setup this.Camera = new PerspectiveCamera { Position = new Point3D(3, 3, 5), LookDirection = new Vector3D(-3, -3, -5), UpDirection = new Vector3D(0, 1, 0) }; if (this.RenderTechniquesManager != null) { // default render technique this.RenderTechnique = RenderTechniquesManager.RenderTechniques.Get(DefaultRenderTechniqueNames.Blinn); } // 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; }
public override LineGeometry3D Build(double _startMarkerSize = 0.1) { List <Vector3> coords = this.OwnerPolygon.ExtractOpeningGeometry(this.idInOwner); LineBuilder b = new LineBuilder(); if (coords.Count > 1) { // show opening on polygon b.AddLine(coords[0], coords[1]); b.AddBox(coords[0], _startMarkerSize, _startMarkerSize, _startMarkerSize); b.AddBox(coords[1], _startMarkerSize, _startMarkerSize, _startMarkerSize); // show owner vertex b.AddBox(this.OwnerPolygon.Polygon_Coords[this.IndInOwner].ToVector3(), _startMarkerSize, _startMarkerSize, _startMarkerSize); } return(b.ToLineGeometry3D()); }
public MainViewModel() { RenderTechniquesManager = new DefaultRenderTechniquesManager(); RenderTechnique = RenderTechniquesManager.RenderTechniques[DefaultRenderTechniqueNames.Blinn]; EffectsManager = new DefaultEffectsManager(RenderTechniquesManager); this.Title = "Line Shading Demo (HelixToolkitDX)"; this.SubTitle = null; // camera setup this.Camera = new PerspectiveCamera { Position = new Point3D(0, 5, 5), LookDirection = new Vector3D(-0, -5, -5), UpDirection = new Vector3D(0, 1, 0) }; // 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 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); this.Model = b1.ToMeshGeometry3D(); // lines model3d var e1 = new LineBuilder(); e1.AddBox(new Vector3(0, 0, 0), 1, 0.5, 2); //e1.AddLine(new Vector3(-1, 0, 0), new Vector3(1, 0, 0)); this.Lines = e1.ToLineGeometry3D(); // lines params this.LineThickness = 2; this.LineSmoothness = 2.0; this.LinesEnabled = true; this.GridEnabled = true; // model trafos this.Model1Transform = new TranslateTransform3D(0, 0, 0); this.Model2Transform = new TranslateTransform3D(-2, 0, 0); this.Model3Transform = new TranslateTransform3D(+2, 0, 0); // model materials this.Material1 = PhongMaterials.PolishedGold; this.Material2 = PhongMaterials.Copper; this.Material3 = PhongMaterials.Glass; }
public MainViewModel() { RenderTechniquesManager = new DefaultRenderTechniquesManager(); RenderTechnique = RenderTechniquesManager.RenderTechniques[DefaultRenderTechniqueNames.Blinn]; EffectsManager = new DefaultEffectsManager(RenderTechniquesManager); this.Title = "Manipulator Demo"; this.SubTitle = null; // camera setup this.Camera = new OrthographicCamera { Position = new Point3D(0, 0, 5), LookDirection = new Vector3D(0, 0, -5), UpDirection = new Vector3D(0, 1, 0) }; // setup lighting this.AmbientLightColor = new Color4(0.2f, 0.2f, 0.2f, 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 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, 1.5, BoxFaces.All); this.Model = b1.ToMeshGeometry3D(); // lines model3d var e1 = new LineBuilder(); e1.AddBox(new Vector3(0, 0, 0), 1, 0.5, 1.5); this.Lines = e1.ToLineGeometry3D(); // model trafos this.Model1Transform = CreateAnimatedTransform(new Vector3D(0, 0, 0), new Vector3D(1, 1, 1), 20); this.Model2Transform = new TranslateTransform3D(-3, 0, 0); this.Model3Transform = new TranslateTransform3D(+3, 0, 0); // model materials this.Material1 = PhongMaterials.Orange; this.Material2 = PhongMaterials.Orange; this.Material3 = PhongMaterials.Red; var dr = Color.DarkRed; Console.WriteLine(dr); }
public MainViewModel() { // titles this.Title = ""; this.SubTitle = ""; // camera setup this.Camera = new PerspectiveCamera { Position = new Point3D(3, 3, 5), LookDirection = new Vector3D(-3, -3, -5), UpDirection = new Vector3D(0, 1, 0) }; EffectsManager = new DefaultEffectsManager(); // setup lighting this.AmbientLightColor = Colors.GhostWhite; this.DirectionalLightColor = Colors.White; // floor plane grid this.Grid = LineBuilder.GenerateGrid(); this.GridColor = SharpDX.Color.Blue; this.GridTransform = new Media3D.TranslateTransform3D(0, 0, 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())); 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; }
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 = meshGeometry.TextureCoordinates.Select(x => x.ToColor4()).ToArray(); 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; }
public MainViewModel() { Title = "Instancing Demo"; // camera setup Camera = new PerspectiveCamera { Position = new Point3D(3, 3, 5), LookDirection = new Vector3D(-3, -3, -5), UpDirection = new Vector3D(0, 1, 0) }; // setup lighting this.AmbientLightColor = new Color4(0.1f, 0.1f, 0.1f, 1.0f); this.DirectionalLightColor = (Color4)Color.White; this.DirectionalLightDirection = new Vector3(-2, -5, -2); // scene model3d var b1 = new MeshBuilder(); b1.AddBox(new Vector3(0, 0, 0), 0.8, 0.8, 0.5, BoxFaces.All); Model = b1.ToMeshGeometry3D(); var l1 = new LineBuilder(); l1.AddBox(new Vector3(0, 0, 0), 0.8, 0.8, 0.5); Lines = l1.ToLineGeometry3D(); int num = 10; var instances = new List <Matrix>(); for (int i = -num; i < num; i++) { for (int j = -num; j < num; j++) { instances.Add(Matrix.Translation(new Vector3(i / 1.0f, j / 1.0f, 0f))); } } ModelInstances = instances; SubTitle = "Number of Instances: " + instances.Count.ToString(); // model trafo ModelTransform = Media3D.Transform3D.Identity;// new Media3D.RotateTransform3D(new Media3D.AxisAngleRotation3D(new Vector3D(0, 0, 1), 45)); // model material ModelMaterial = PhongMaterials.Glass; RenderTechniquesManager = new DefaultRenderTechniquesManager(); RenderTechnique = RenderTechniquesManager.RenderTechniques[DefaultRenderTechniqueNames.Blinn]; EffectsManager = new DefaultEffectsManager(RenderTechniquesManager); }
public MainViewModel() { var lineBuilder = new LineBuilder(); lineBuilder.AddBox(new SharpDX.Vector3(), 1, 1, 1); BoundingLines = lineBuilder.ToLineGeometry3D(); LoadTexture(SelectedTextureIndex); var meshBuilder = new MeshBuilder(); meshBuilder.AddSphere(new SharpDX.Vector3(0, 0, 0), 0.5, 16, 16); Model = meshBuilder.ToMesh(); Camera = new PerspectiveCamera() { Position = new Media3D.Point3D(0, 0, 20), UpDirection = new Media3D.Vector3D(0, 1, 0), LookDirection = new Media3D.Vector3D(0, 0, -20) }; }
public MainViewModel() { Title = "Instancing Demo"; // camera setup Camera = new PerspectiveCamera { Position = new Point3D(40, 40, 40), LookDirection = new Vector3D(-40, -40, -40), UpDirection = new Vector3D(0, 1, 0) }; // setup lighting this.AmbientLightColor = new Color4(0.1f, 0.1f, 0.1f, 1.0f); this.DirectionalLightColor = (Color4)Color.White; this.DirectionalLightDirection = new Vector3(-2, -5, -2); // scene model3d var b1 = new MeshBuilder(true, true, true); b1.AddBox(new Vector3(0, 0, 0), 1, 1, 1, BoxFaces.All); Model = b1.ToMeshGeometry3D(); for (int i = 0; i < Model.TextureCoordinates.Count; ++i) { var tex = Model.TextureCoordinates[i]; Model.TextureCoordinates[i] = new Vector2(tex.X * 0.5f, tex.Y * 0.5f); } var l1 = new LineBuilder(); l1.AddBox(new Vector3(0, 0, 0), 1.1, 1.1, 1.1); Lines = l1.ToLineGeometry3D(); Lines.Colors = new HelixToolkit.Wpf.SharpDX.Core.Color4Collection(Enumerable.Repeat(Color.White.ToColor4(), Lines.Positions.Count)); // model trafo ModelTransform = Media3D.Transform3D.Identity;// new Media3D.RotateTransform3D(new Media3D.AxisAngleRotation3D(new Vector3D(0, 0, 1), 45)); // model material ModelMaterial = PhongMaterials.Glass; ModelMaterial.DiffuseMap = new FileStream(new System.Uri(@"TextureCheckerboard2.jpg", System.UriKind.RelativeOrAbsolute).ToString(), FileMode.Open); ModelMaterial.NormalMap = new FileStream(new System.Uri(@"TextureCheckerboard2_dot3.jpg", System.UriKind.RelativeOrAbsolute).ToString(), FileMode.Open); RenderTechniquesManager = new DefaultRenderTechniquesManager(); RenderTechnique = RenderTechniquesManager.RenderTechniques[DefaultRenderTechniqueNames.Blinn]; EffectsManager = new DefaultEffectsManager(RenderTechniquesManager); BillboardModel = new BillboardSingleImage3D(ModelMaterial.DiffuseMap, 20, 20); CreateModels(); timer.Interval = TimeSpan.FromMilliseconds(30); timer.Tick += Timer_Tick; timer.Start(); }
public MainViewModel() { Title = "Instancing Demo"; EffectsManager = new DefaultEffectsManager(); // camera setup Camera = new PerspectiveCamera { Position = new Point3D(40, 40, 40), LookDirection = new Vector3D(-40, -40, -40), UpDirection = new Vector3D(0, 1, 0) }; // setup lighting this.AmbientLightColor = Colors.DarkGray; this.DirectionalLightColor = Colors.White; this.DirectionalLightDirection = new Vector3D(-2, -5, -2); // scene model3d var b1 = new MeshBuilder(true, true, true); b1.AddBox(new Vector3(0, 0, 0), 1, 1, 1, BoxFaces.All); Model = b1.ToMeshGeometry3D(); for (int i = 0; i < Model.TextureCoordinates.Count; ++i) { var tex = Model.TextureCoordinates[i]; Model.TextureCoordinates[i] = new Vector2(tex.X * 0.5f, tex.Y * 0.5f); } var l1 = new LineBuilder(); l1.AddBox(new Vector3(0, 0, 0), 1.1, 1.1, 1.1); Lines = l1.ToLineGeometry3D(); Lines.Colors = new Color4Collection(Enumerable.Repeat(Colors.White.ToColor4(), Lines.Positions.Count)); // model trafo ModelTransform = Media3D.Transform3D.Identity;// new Media3D.RotateTransform3D(new Media3D.AxisAngleRotation3D(new Vector3D(0, 0, 1), 45)); // model material ModelMaterial = PhongMaterials.White; ModelMaterial.DiffuseMap = LoadFileToMemory(new System.Uri(@"TextureCheckerboard2.jpg", System.UriKind.RelativeOrAbsolute).ToString()); ModelMaterial.NormalMap = LoadFileToMemory(new System.Uri(@"TextureCheckerboard2_dot3.jpg", System.UriKind.RelativeOrAbsolute).ToString()); BillboardModel = new BillboardSingleImage3D(ModelMaterial.DiffuseMap.CompressedStream, 20, 20); Texture = LoadFileToMemory("Cubemap_Grandcanyon.dds"); CreateModels(); timer.Interval = TimeSpan.FromMilliseconds(30); timer.Tick += Timer_Tick; timer.Start(); }
////////////////////////////////////////////////////////////////////////////////////////////////////////////// // =========================================== GEOMETRY DEFINITIONS ======================================= // ////////////////////////////////////////////////////////////////////////////////////////////////////////////// #region GEOMETRY DEFINITIONS private void UpdateGeometry() { // show the defining polygons LineBuilder b = new LineBuilder(); int n = coords_polygons.Count; if (n > 0) { for (int i = 0; i < n; i++) { // transfer current polygon List <Point3D> cp = coords_polygons[i]; int m = cp.Count; if (m > 0) { // lines for (int j = 0; j < m; j++) { b.AddLine(cp[j % m].ToVector3(), cp[(j + 1) % m].ToVector3()); } // start maker b.AddBox(cp[0].ToVector3(), START_MARKER, 0, START_MARKER); } } } this.polygons.Geometry = b.ToLineGeometry3D(); // show the resulting volume Vector3[] ar1 = CommonExtensions.ConvertPoint3DArToVector3Ar(this.coords_polygons[0].ToArray()); Vector3[] ar2 = CommonExtensions.ConvertPoint3DArToVector3Ar(this.coords_polygons[1].ToArray()); List <List <Vector3> > coords_poly_asV3 = CommonExtensions.ConvertPoints3DListListToVector3ListList(this.coords_polygons); bool capBottom = false; bool capTop = true; HelixToolkit.SharpDX.Wpf.MeshGeometry3D volMesh = MeshesCustom.MeshFromNPolygons(coords_poly_asV3, this.reverse_polygons, capBottom, capTop); this.volume.Geometry = volMesh; this.volumeNormals.Geometry = MeshesCustom.GetVertexNormalsAsLines(volMesh, 0.25f); this.volumeEdges.Geometry = MeshesCustom.GetEdgesAsLines(volMesh); }
public MainViewModel() { EffectsManager = new DefaultEffectsManager(); var lineBuilder = new LineBuilder(); lineBuilder.AddBox(new SharpDX.Vector3(), 1, 1, 1); BoundingLines = lineBuilder.ToLineGeometry3D(); LoadTexture(SelectedTextureIndex); var meshBuilder = new MeshBuilder(); meshBuilder.AddSphere(new SharpDX.Vector3(0, 0, 0), 0.5, 16, 16); Model = meshBuilder.ToMesh(); Camera = new PerspectiveCamera() { Position = new Media3D.Point3D(0, 0, 20), UpDirection = new Media3D.Vector3D(0, 1, 0), LookDirection = new Media3D.Vector3D(0, 0, -20) }; Instances = new Matrix[] { Matrix.Identity, Matrix.Scaling(1, -1, 1) * Matrix.Translation(10, 0, 10), Matrix.Translation(-10, 0, 10), Matrix.Translation(10, 0, -10), Matrix.RotationAxis(new Vector3(1, 0, 0), 90) * Matrix.Translation(-10, 0, -10), }; }
////////////////////////////////////////////////////////////////////////////////////////////////////////////// // =============================================== CONSTRUCTORS =========================================== // ////////////////////////////////////////////////////////////////////////////////////////////////////////////// #region Initialization static LineManipulator3D() { var b1 = new MeshBuilder(); b1.AddSphere(Vector3.Zero, END_GRIP_SIZE, 8, 8); NodeGeometry = b1.ToMeshGeometry3D(); var b2 = new MeshBuilder(); b2.AddSphere(Vector3.Zero, MID_GRIP_SIZE, 8, 8); MidEdgeGeometry = b2.ToMeshGeometry3D(); var b3 = new MeshBuilder(); b3.AddCylinder(new Vector3(0f, 0f, 0f), new Vector3(1f, 0f, 0f), EDGE_GRIP_SIZE, 4); EdgeGeometry = b3.ToMeshGeometry3D(); var b4 = new LineBuilder(); b4.AddBox(new Vector3(0f, 0f, 0f), 1, 1, 1); LineGeometry = b4.ToLineGeometry3D(); }
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 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 MainViewModel() { EffectsManager = new DefaultEffectsManager(); // titles this.Title = "Mouse Drag Demo"; this.SubTitle = "WPF & SharpDX"; // camera setup this.Camera = new PerspectiveCamera { Position = new Point3D(0, 0, 9), LookDirection = new Vector3D(-0, -0, -9), UpDirection = new Vector3D(0, 1, 0) }; // setup lighting this.AmbientLightColor = Colors.DimGray; this.DirectionalLightColor = Colors.White; this.DirectionalLightDirection = new Vector3D(-2, -5, -2); // floor plane grid this.Grid = LineBuilder.GenerateGrid(Vector3.UnitZ, -5, 5); this.GridColor = Colors.Black; this.GridTransform = new Media3D.TranslateTransform3D(-0, -0, -0); // scene model3d var b1 = new MeshBuilder(); b1.AddSphere(new Vector3(0, 0, 0), 0.65); b1.AddBox(new Vector3(0, 0, 0), 1, 1, 1); var meshGeometry = b1.ToMeshGeometry3D(); meshGeometry.Colors = new Color4Collection(meshGeometry.TextureCoordinates.Select(x => x.ToColor4())); this.MeshGeometry = meshGeometry; this.Model1Instances = new List <Matrix>(); for (int i = 0; i < 5; i++) { this.Model1Instances.Add(Matrix.Translation(0, i, 0)); } // 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.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; // --- this.Shape3DCollection = new ObservableCollection <Shape3D> { new Shape3D() { Geometry = this.MeshGeometry, Material = this.BlueMaterial, Transform = this.Model3Transform, Instances = new List <Matrix> { Matrix.Identity }, DragZ = false, }, new Shape3D() { Geometry = this.MeshGeometry, Material = this.RedMaterial, Transform = this.Model1Transform, Instances = new List <Matrix> { Matrix.Identity }, DragZ = true, }, }; this.Element3DCollection = new ObservableCollection <Element3D>() { new DraggableGeometryModel3D() { Geometry = this.MeshGeometry, Material = this.BlueMaterial, Transform = this.Model3Transform, }, new DraggableGeometryModel3D() { Geometry = this.MeshGeometry, Material = this.RedMaterial, Transform = this.Model1Transform, }, }; this.AddCmd = new RelayCommand((o) => AddShape()); this.DelCmd = new RelayCommand((o) => DelShape()); }
/// <summary> /// Initializes a new instance of the MainViewModel class. /// </summary> public MainViewModel() { ////if (IsInDesignMode) ////{ //// // Code runs in Blend --> create design time data. ////} ////else ////{ //// // Code runs "for real" ////} //GenerateFibonacciSphereCommand = new RelayCommand(() => CreateFibonacciSphereMesh(),() => true,true); EffectsManager = new DefaultEffectsManager(); // titles // 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 = Color.White; DirectionalLightColor = Color.White; DirectionalLightDirection = new Vector3D(-2, -5, -2); //// 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); VertexColorMaterial = new VertColorMaterial(); RedMaterial = PhongMaterials.BlackPlastic; //var diffColor = this.RedMaterial.DiffuseColor; //diffColor.Alpha = 0.5f; //this.RedMaterial.DiffuseColor = diffColor; Points = new PointGeometry3D(); 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 = Color.DarkGray, Position = 0f }, new SharpDX.Direct2D1.GradientStop() { Color = Color.Black.ToColor4(), Position = 1.0f } }); SubdividedIcosahedronCommand = new RelayCommand(CreateSubdividedIcosahedron); }
public MainViewModel() { // 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 }; // default render technique RenderTechniquesManager = new DefaultRenderTechniquesManager(); RenderTechnique = RenderTechniquesManager.RenderTechniques[DefaultRenderTechniqueNames.Blinn]; EffectsManager = new DefaultEffectsManager(RenderTechniquesManager); // setup lighting AmbientLightColor = new Color4(0.1f, 0.1f, 0.1f, 1.0f); DirectionalLightColor = Color.White; DirectionalLightDirection = new Vector3(-2, -5, -2); // floor plane grid Grid = LineBuilder.GenerateGrid(); GridColor = SharpDX.Color.Black; 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())); Model = meshGeometry; // lines model3d var e1 = new LineBuilder(); e1.AddBox(new Vector3(0, 0, 0), 1, 0.5, 2); Lines = e1.ToLineGeometry3D(); // model trafos Model1Transform = new Media3D.TranslateTransform3D(0, 0, 0); Model2Transform = new Media3D.TranslateTransform3D(-2, 0, 0); Model3Transform = new Media3D.TranslateTransform3D(+2, 0, 0); // 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(); 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))); } } Billboard1Model = new BillboardSingleText3D() { TextInfo = new TextInfo("Model 1", new Vector3(0, 1, 0)), FontColor = Color.Blue, FontSize = 12, BackgroundColor = Color.Plum, FontStyle = System.Windows.FontStyles.Italic, Padding = new System.Windows.Thickness(2) }; var background = Color.Blue; background.A = (byte)120; Billboard2Model = new BillboardSingleText3D() { TextInfo = new TextInfo("Model 1", new Vector3(2, 1, 0)), FontSize = 12, FontColor = Color.Green, BackgroundColor = background, FontWeight = System.Windows.FontWeights.Bold, Padding = new System.Windows.Thickness(2) }; background = Color.Purple; background.A = (byte)50; Billboard3Model = new BillboardSingleText3D(2, 0.8f) { TextInfo = new TextInfo("Model 1", new Vector3(-2, 1, 0)), FontSize = 12, FontColor = Color.Red, BackgroundColor = background, FontFamily = new System.Windows.Media.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); BillboardImageModel.Center = new Vector3(2, 2, 0); }
private void InitializeScene() { camera = new PerspectiveCameraCore() { LookDirection = new Vector3(0, 0, 50), Position = new Vector3(0, 0, -50), FarPlaneDistance = 1000, NearPlaneDistance = 0.1f, FieldOfView = 45, UpDirection = new Vector3(0, 1, 0) }; viewport.CameraCore = camera; viewport.Items.Add(new DirectionalLightNode() { Direction = new Vector3(0, -1, 1), Color = Color.White }); viewport.Items.Add(new PointLightNode() { Position = new Vector3(0, 0, -20), Color = Color.Yellow, Range = 20, Attenuation = Vector3.One }); var builder = new MeshBuilder(true, true, true); builder.AddSphere(Vector3.Zero, 1, 12, 12); sphere = builder.ToMesh(); builder = new MeshBuilder(true, true, true); builder.AddBox(Vector3.Zero, 1, 1, 1); box = builder.ToMesh(); points = new PointGeometry3D() { Positions = sphere.Positions }; var lineBuilder = new LineBuilder(); lineBuilder.AddBox(Vector3.Zero, 2, 2, 2); lines = lineBuilder.ToLineGeometry3D(); groupSphere = new GroupNode(); groupBox = new GroupNode(); groupLines = new GroupNode(); groupPoints = new GroupNode(); InitializeMaterials(); materialList = materials.Values.ToArray(); var materialCount = materialList.Length; for (int i = 0; i < NumItems; ++i) { var transform = Matrix.Translation(new Vector3(rnd.NextFloat(-20, 20), rnd.NextFloat(-20, 20), rnd.NextFloat(-20, 20))); groupSphere.AddChildNode(new MeshNode() { Geometry = sphere, Material = materialList[i % materialCount], ModelMatrix = transform, CullMode = SharpDX.Direct3D11.CullMode.Back }); } for (int i = 0; i < NumItems; ++i) { var transform = Matrix.Translation(new Vector3(rnd.NextFloat(-50, 50), rnd.NextFloat(-50, 50), rnd.NextFloat(-50, 50))); groupBox.AddChildNode(new MeshNode() { Geometry = box, Material = materialList[i % materialCount], ModelMatrix = transform, CullMode = SharpDX.Direct3D11.CullMode.Back }); } //for(int i=0; i< NumItems; ++i) //{ // var transform = Matrix.Translation(new Vector3(rnd.NextFloat(-50, 50), rnd.NextFloat(-50, 50), rnd.NextFloat(-50, 50))); // groupPoints.AddChildNode(new PointNode() { Geometry = points, ModelMatrix = transform, Material = new PointMaterialCore() { PointColor = Color.Red } }); //} //for (int i = 0; i < NumItems; ++i) //{ // var transform = Matrix.Translation(new Vector3(rnd.NextFloat(-50, 50), rnd.NextFloat(-50, 50), rnd.NextFloat(-50, 50))); // groupLines.AddChildNode(new LineNode() { Geometry = lines, ModelMatrix = transform, Material = new LineMaterialCore() { LineColor = Color.LightBlue } }); //} viewport.Items.Add(groupSphere); groupSphere.AddChildNode(groupBox); groupSphere.AddChildNode(groupPoints); groupSphere.AddChildNode(groupLines); var viewbox = new ViewBoxNode(); viewport.Items.Add(viewbox); var imGui = new ImGuiNode(); viewport.Items.Add(imGui); imGui.UpdatingImGuiUI += ImGui_UpdatingImGuiUI; io.KeyMap[GuiKey.Tab] = (int)Keys.Tab; io.KeyMap[GuiKey.LeftArrow] = (int)Keys.Left; io.KeyMap[GuiKey.RightArrow] = (int)Keys.Right; io.KeyMap[GuiKey.UpArrow] = (int)Keys.Up; io.KeyMap[GuiKey.DownArrow] = (int)Keys.Down; io.KeyMap[GuiKey.PageUp] = (int)Keys.PageUp; io.KeyMap[GuiKey.PageDown] = (int)Keys.PageDown; io.KeyMap[GuiKey.Home] = (int)Keys.Home; io.KeyMap[GuiKey.End] = (int)Keys.End; io.KeyMap[GuiKey.Delete] = (int)Keys.Delete; io.KeyMap[GuiKey.Backspace] = (int)Keys.Back; io.KeyMap[GuiKey.Enter] = (int)Keys.Enter; io.KeyMap[GuiKey.Escape] = (int)Keys.Escape; }
public MainViewModel() { // 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 }; // Create a custom render techniques manager that // only supports Phong and Blinn RenderTechniquesManager = new CustomRenderTechniquesManager(); RenderTechnique = RenderTechniquesManager.RenderTechniques["RenderCustom"]; EffectsManager = new CustomEffectsManager(RenderTechniquesManager); // setup lighting AmbientLightColor = new Color4(0.1f, 0.1f, 0.1f, 1.0f); DirectionalLightColor = Color.White; DirectionalLightDirection = new Vector3(-2, -5, -2); // floor plane grid Grid = LineBuilder.GenerateGrid(); GridColor = Color.Black; 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())); Model = meshGeometry; // lines model3d var e1 = new LineBuilder(); e1.AddBox(new Vector3(0, 0, 0), 1, 0.5, 2); Lines = e1.ToLineGeometry3D(); // model transform Model1Transform = new Media3D.TranslateTransform3D(0, 0, 0); Model2Transform = new Media3D.TranslateTransform3D(-2, 0, 0); Model3Transform = new Media3D.TranslateTransform3D(+2, 0, 0); // model materials RedMaterial = PhongMaterials.Red; GreenMaterial = PhongMaterials.Green; BlueMaterial = PhongMaterials.Blue; Points = new PointGeometry3D(); var ptPos = new Vector3Collection(); var ptIdx = new IntCollection(); Text = new BillboardText3D(); for (int x = -5; x <= 5; x++) { for (int y = -5; y <= 5; y++) { ptIdx.Add(ptPos.Count); ptPos.Add(new Vector3(x, -1, y)); Text.TextInfo.Add(new TextInfo(string.Format("{0}:{1}", x, y), new Vector3(x, -1, y))); } } Points.Positions = ptPos; Points.Indices = ptIdx; }
public MainViewModel() { RenderTechniquesManager = new DefaultRenderTechniquesManager(); RenderTechnique = RenderTechniquesManager.RenderTechniques[DefaultRenderTechniqueNames.Blinn]; EffectsManager = new DefaultEffectsManager(RenderTechniquesManager); // titles this.Title = "Mouse Drag Demo"; this.SubTitle = "WPF & SharpDX"; // camera setup this.Camera = new PerspectiveCamera { Position = new Point3D(0, 0, 9), LookDirection = new Vector3D(-0, -0, -9), UpDirection = new Vector3D(0, 1, 0) }; // default render technique this.RenderTechnique = RenderTechniquesManager.RenderTechniques[DefaultRenderTechniqueNames.Blinn]; // 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(Vector3.UnitZ, -5, 5); this.GridColor = SharpDX.Color.Black; this.GridTransform = new Media3D.TranslateTransform3D(-0, -0, -0); // scene model3d var b1 = new MeshBuilder(); b1.AddSphere(new Vector3(0, 0, 0), 0.65); b1.AddBox(new Vector3(0, 0, 0), 1, 1, 1); var meshGeometry = b1.ToMeshGeometry3D(); meshGeometry.Colors = new Color4Collection(meshGeometry.TextureCoordinates.Select(x => x.ToColor4())); this.MeshGeometry = meshGeometry; this.Model1Instances = new List<Matrix>(); for (int i = 0; i < 5; i++) { this.Model1Instances.Add(Matrix.Translation(0, i, 0)); } // 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.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; // --- this.Shape3DCollection = new ObservableCollection<Shape3D> { new Shape3D() { Geometry = this.MeshGeometry, Material = this.BlueMaterial, Transform = this.Model3Transform, Instances = new List<Matrix>{Matrix.Identity}, DragZ = false, }, new Shape3D() { Geometry = this.MeshGeometry, Material = this.RedMaterial, Transform = this.Model1Transform, Instances = new List<Matrix>{Matrix.Identity}, DragZ = true, }, }; this.Element3DCollection = new ObservableCollection<Element3D>() { new DraggableGeometryModel3D() { Geometry = this.MeshGeometry, Material = this.BlueMaterial, Transform = this.Model3Transform, }, new DraggableGeometryModel3D() { Geometry = this.MeshGeometry, Material = this.RedMaterial, Transform = this.Model1Transform, }, }; this.AddCmd = new RelayCommand((o) => AddShape()); this.DelCmd = new RelayCommand((o) => DelShape()); }
/// <summary> /// Process point cloud as soon as it arrives /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ImagingPipeline_ImageDataProcessed(object sender, Rubedos.PointcloudProcessing.ImagingPipelineProcessedEventArgs e) { var rgbd = pointCloudViewModel.ImagingPipeline.RgbdOut; if (points == null) { points = new float[rgbd.Cols * rgbd.Rows * rgbd.NumberOfChannels]; } int w = rgbd.Cols, h = rgbd.Rows; // hint: working with data buffer is much faster than accessing individual points in Cv.Mat System.Runtime.InteropServices.Marshal.Copy(rgbd.DataPointer, points, 0, points.Length); float minZ = groundZ, maxX = -groundW, minX = groundW, minY = groundD, maxY = -groundD; for (int y = 1; y < h; y += 1) { for (int x = 1; x < w; x += 1) { var current = GetPoint(points, x, y, w, h); if (current.Z > groundZ || current.Z < 1.0f || current.X > groundW / 2 || current.X < -groundW / 2 || current.Y > groundD / 2 || current.Y < -groundD / 2) { continue; // Out of space of interest } if (current.X > maxX) { maxX = current.X; } if (current.X < minX) { minX = current.X; } if (current.Y > maxY) { maxY = current.Y; } if (current.Y < minY) { minY = current.Y; } if (current.Z < minZ) { minZ = current.Z; } } } Console.WriteLine("Boundaries: X ({0:0.00}; {1:0.00}) Y ({2:0.00}; {3:0.00}) Z ({4:0.00}; {5:0.00})", maxX, minX, maxY, minY, groundZ, minZ); // Synchronizing with 3D rendering thread pointCloudViewModel.Context.Send((o) => { boundingBoxGroup.Children.Clear(); MeshBuilder mb = new MeshBuilder(); var center = new Vector3((maxY + minY) / 2, (maxX + minX) / 2, (groundZ - minZ) / 2); float xlen = maxY - minY, ylen = maxX - minX, zlen = groundZ - minZ; mb.AddBox(center, xlen, ylen, zlen); MeshGeometryModel3D mmodel = new MeshGeometryModel3D(); boundingBoxGroup.Children.Add(mmodel); mmodel.Geometry = mb.ToMeshGeometry3D(); var boxColor = System.Windows.Media.Color.FromArgb(30, 50, 0, 255).ToColor4(); mmodel.Material = new PhongMaterial() { AmbientColor = boxColor, // System.Windows.Media.Colors.Gray.ToColor4(), DiffuseColor = boxColor, //System.Windows.Media.Colors.Yellow.ToColor4(), //System.Windows.Media.Color.FromArgb(100, 255, 0 , 0).ToColor4(), SpecularColor = boxColor, // System.Windows.Media.Colors.Gray.ToColor4(), SpecularShininess = 100f, }; LineGeometryModel3D linem = new LineGeometryModel3D(); var lb = new LineBuilder(); lb.AddBox(center, xlen, ylen, zlen); linem.Thickness = 1; linem.Color = System.Windows.Media.Colors.Yellow; //System.Windows.Media.Color.FromArgb(30, 50, 0, 255).ToColor4(); linem.Geometry = lb.ToLineGeometry3D(); boundingBoxGroup.Children.Add(linem); float scale = 1.0f; labels.TextInfo.Clear(); labels.TextInfo.Add(new TextInfo() { Text = String.Format("H = {0:0.0} m", zlen), Origin = new Vector3(xlen / 2 + 0.1f, -(ylen / 2 + 0.1f), zlen / 2) + center, Foreground = Colors.Black.ToColor4(), Scale = scale }); labels.TextInfo.Add(new TextInfo() { Text = String.Format("W = {0:0.0} m", xlen), Origin = new Vector3(0, ylen / 2 + 0.1f, zlen + 0.1f) + center, Foreground = Colors.Black.ToColor4(), Scale = scale }); labels.TextInfo.Add(new TextInfo() { Text = String.Format("D = {0:0.0} m", ylen), Origin = new Vector3(xlen / 2 + 0.1f, 0f, zlen + 0.1f) + center, Foreground = Colors.Black.ToColor4(), Scale = scale }); }, null); }
private void InitializeScene() { camera = new PerspectiveCameraCore() { LookDirection = new Vector3(0, 0, 50), Position = new Vector3(0, 0, -50), FarPlaneDistance = 1000, NearPlaneDistance = 0.1f, FieldOfView = 45, UpDirection = new Vector3(0, 1, 0) }; viewport.CameraCore = camera; viewport.Items.Add(new DirectionalLightNode() { Direction = new Vector3(0, -1, 1), Color = Color.White }); viewport.Items.Add(new PointLightNode() { Position = new Vector3(0, 0, -20), Color = Color.Yellow, Range = 20, Attenuation = Vector3.One }); var builder = new MeshBuilder(true, true, true); builder.AddSphere(Vector3.Zero, 1, 12, 12); sphere = builder.ToMesh(); builder = new MeshBuilder(true, true, true); builder.AddBox(Vector3.Zero, 1, 1, 1); box = builder.ToMesh(); points = new PointGeometry3D() { Positions = sphere.Positions }; var lineBuilder = new LineBuilder(); lineBuilder.AddBox(Vector3.Zero, 2, 2, 2); lines = lineBuilder.ToLineGeometry3D(); groupSphere = new GroupNode(); groupBox = new GroupNode(); groupLines = new GroupNode(); groupPoints = new GroupNode(); InitializeMaterials(); materialList = materials.Values.ToArray(); var materialCount = materialList.Length; for (int i = 0; i < NumItems; ++i) { var transform = Matrix.Translation(new Vector3(rnd.NextFloat(-20, 20), rnd.NextFloat(-20, 20), rnd.NextFloat(-20, 20))); groupSphere.AddChildNode(new MeshNode() { Geometry = sphere, Material = materialList[i % materialCount], ModelMatrix = transform, CullMode = SharpDX.Direct3D11.CullMode.Back }); } for (int i = 0; i < NumItems; ++i) { var transform = Matrix.Translation(new Vector3(rnd.NextFloat(-50, 50), rnd.NextFloat(-50, 50), rnd.NextFloat(-50, 50))); groupBox.AddChildNode(new MeshNode() { Geometry = box, Material = materialList[i % materialCount], ModelMatrix = transform, CullMode = SharpDX.Direct3D11.CullMode.Back }); } for (int i = 0; i < NumItems; ++i) { var transform = Matrix.Translation(new Vector3(rnd.NextFloat(-50, 50), rnd.NextFloat(-50, 50), rnd.NextFloat(-50, 50))); groupPoints.AddChildNode(new PointNode() { Geometry = points, ModelMatrix = transform, Color = Color.Red, Size = new Size2F(0.5f, 0.5f) }); } for (int i = 0; i < NumItems; ++i) { var transform = Matrix.Translation(new Vector3(rnd.NextFloat(-50, 50), rnd.NextFloat(-50, 50), rnd.NextFloat(-50, 50))); groupLines.AddChildNode(new LineNode() { Geometry = lines, ModelMatrix = transform, Color = Color.LightBlue, Thickness = 0.5f }); } viewport.Items.Add(groupSphere); groupSphere.AddChildNode(groupBox); groupSphere.AddChildNode(groupPoints); groupSphere.AddChildNode(groupLines); var viewbox = new ViewBoxNode(); viewport.Items.Add(viewbox); }