private void AddMiterLimitsSample(double miterLimit, double zOffset) { var sampleModelVisual3D = new ModelVisual3D(); sampleModelVisual3D.Transform = new TranslateTransform3D(0, 0, zOffset); var positions = CreateSnakePositions(new Point3D(-100, 0, 0), 50, 20, 80); var polyLineVisual3D = new Ab3d.Visuals.PolyLineVisual3D() { Positions = positions, LineColor = Colors.White, LineThickness = 15, MiterLimit = miterLimit }; sampleModelVisual3D.Children.Add(polyLineVisual3D); var textBlockVisual3D = new TextBlockVisual3D() { Position = new Point3D(-120, 0, 0), PositionType = PositionTypes.Right, TextDirection = new Vector3D(1, 0, 0), UpDirection = new Vector3D(0, 0, -1), Size = new Size(200, 40), Foreground = Brushes.White, Text = string.Format("MiterLimit = {0}", miterLimit) }; sampleModelVisual3D.Children.Add(textBlockVisual3D); MainViewport.Children.Add(sampleModelVisual3D); }
private BaseLineVisual3D GenerateRandomLine(Color lineColor, int lineLength) { var positions = CreateRandomPositions(lineLength); BaseLineVisual3D createdLine; if (_rnd.Next(4) == 1) // 25% chance to return a simple Line instead of PolyLine { createdLine = new Ab3d.Visuals.LineVisual3D() { StartPosition = positions[0], EndPosition = positions[positions.Count - 1], LineColor = lineColor, LineThickness = _rnd.NextDouble() * 5 + 1, }; } else { createdLine = new Ab3d.Visuals.PolyLineVisual3D() { LineColor = lineColor, LineThickness = _rnd.NextDouble() * 5 + 1, Positions = positions }; } MainViewport.Children.Add(createdLine); return(createdLine); }
private void CreateRootModel() { bool show3DLine = false; switch (ObjectComboBox.SelectedIndex) { case 0: Ab3d.Meshes.SphereMesh3D sphere = new Ab3d.Meshes.SphereMesh3D(new Point3D(0, 0, 0), 80, 10); _rootMesh = sphere.Geometry; break; case 1: Ab3d.Meshes.SphereMesh3D sphere2 = new Ab3d.Meshes.SphereMesh3D(new Point3D(0, 0, 0), 80, 5); _rootMesh = sphere2.Geometry; break; case 2: // NOTE: Here we create an optimized version of sphere but it does not have texture coordinates // If we do not need texture coordinates (do not need to show texture), than we can slightly simplify the sphere model. // When we also need to create texture coordinates, the top most position that represent the same point in space is defined multiple times // - each time with slightly different texture coordinate (so that the whole top line on the texture is shown around the top sphere position). // Also there are x + 1 position around the sphere (in one row) - one additional position is added that the first and last position in the "row" are in the same space position, // but the first position has x texture coordinate 0, the last position has x texture coordinate 1 - this shows the whole texture nicely around the sphere. // If texture coordinates are not needed, than we do not need to define more than one upper and bottom positions, // and also do not need to add another position to the row. // Optimized sphere can be created only with SphereMesh3D object (not with SphereVisual3D) Ab3d.Meshes.SphereMesh3D sphere3 = new Ab3d.Meshes.SphereMesh3D(new Point3D(0, 0, 0), 80, 12, false); // false: generateTextureCoordinates _rootMesh = sphere3.Geometry; break; case 3: Ab3d.Meshes.BoxMesh3D box = new Ab3d.Meshes.BoxMesh3D(new Point3D(0, 0, 0), new Size3D(130, 60, 100), 1, 1, 1); _rootMesh = box.Geometry; break; case 4: Ab3d.Meshes.BoxMesh3D box2 = new Ab3d.Meshes.BoxMesh3D(new Point3D(0, 0, 0), new Size3D(130, 60, 100), 4, 4, 4); _rootMesh = box2.Geometry; break; case 5: Ab3d.Meshes.CylinderMesh3D cylinder = new Ab3d.Meshes.CylinderMesh3D(new Point3D(0, -50, 0), 60, 100, 12, true); _rootMesh = cylinder.Geometry; break; case 6: Ab3d.Meshes.ConeMesh3D cone = new Ab3d.Meshes.ConeMesh3D(new Point3D(0, -50, 0), 30, 60, 100, 12, true); _rootMesh = cone.Geometry; break; case 7: Ab3d.Meshes.ConeMesh3D cone2 = new Ab3d.Meshes.ConeMesh3D(new Point3D(0, -50, 0), 30, 60, 100, 6, false); _rootMesh = cone2.Geometry; break; case 8: var readerObj = new Ab3d.ReaderObj(); var teapotModel = readerObj.ReadModel3D(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Resources\ObjFiles\Teapot.obj")) as GeometryModel3D; if (teapotModel == null) { return; } // Get the teapot MeshGeometry3D _rootMesh = (MeshGeometry3D)teapotModel.Geometry; break; case 9: var line = new Ab3d.Visuals.LineVisual3D() { StartPosition = new Point3D(0, 0, 0), EndPosition = new Point3D(100, 0, 0), LineColor = Colors.Silver, LineThickness = 20 }; Show3DLines(line); show3DLine = true; break; case 10: var polyLineVisual3D = new Ab3d.Visuals.PolyLineVisual3D() { Positions = new Point3DCollection(new Point3D[] { new Point3D(-75, 50, 0), new Point3D(-25, 0, 0), new Point3D(25, 50, 0), new Point3D(75, 0, 0) }), LineThickness = 20 }; Show3DLines(polyLineVisual3D); show3DLine = true; break; case 11: // This is the same line as in the previous sample (PolyLineVisual3D), but this time // it is created as diconnected list of lines - note that this requires that the positions are duplicated. var multiLineVisual3D = new Ab3d.Visuals.MultiLineVisual3D() { Positions = new Point3DCollection(new Point3D[] { new Point3D(-75, 50, 0), new Point3D(-25, 0, 0), new Point3D(-25, 0, 0), new Point3D(25, 50, 0), new Point3D(25, 50, 0), new Point3D(75, 0, 0) }), LineThickness = 20 }; Show3DLines(multiLineVisual3D); show3DLine = true; break; default: _rootMesh = null; break; } // If we were looking at 3D lines before and now we are looking an standard 3D models, // we adjust the camera back to the side view (from direct front view) if (_isShowing3DLines && !show3DLine) { Camera1.Heading = 30; Camera1.Attitude = -20; Camera1.Distance = 300; } _isShowing3DLines = show3DLine; _rootModel = new GeometryModel3D(); _rootModel.Geometry = _rootMesh; _rootModel.Material = new DiffuseMaterial(Brushes.DarkBlue); ObjectModelVisual.Content = _rootModel; Ab3d.Utilities.ModelEventSource3D modelEventSource = new Ab3d.Utilities.ModelEventSource3D(); modelEventSource.TargetModel3D = _rootModel; modelEventSource.MouseClick += new Ab3d.Common.EventManager3D.MouseButton3DEventHandler(modelEventSource_MouseClick); _eventsManager.ResetEventSources3D(); _eventsManager.RegisterEventSource3D(modelEventSource); MainViewport.Cursor = Cursors.Hand; }