private void CreateCylinderWithCircles(Point3D bottomCenterPosition, double radius, double height, DiffuseMaterial material) { var cylinderVisual3D = new CylinderVisual3D() { BottomCenterPosition = bottomCenterPosition, Radius = radius, Height = height, Material = material }; TestObjectsModelVisual3D.Children.Add(cylinderVisual3D); int circlesCount = 4; for (int i = 0; i < circlesCount; i++) { var lineArcVisual3D = new LineArcVisual3D() { CircleCenterPosition = bottomCenterPosition + Constants.UpVector * height * (double)i / (double)(circlesCount - 1), Radius = radius * 1.02, CircleNormal = Constants.UpVector, ZeroAngleDirection = Constants.XAxis, StartAngle = 0, EndAngle = 360, LineColor = Colors.Yellow, LineThickness = 3 }; TestObjectsModelVisual3D.Children.Add(lineArcVisual3D); } }
private CylinderVisual3D Lier([NotNull] CylinderVisual3D forme, [NotNull] CylindreWrapper source) { BindingOperations.SetBinding(forme, CylinderVisual3D.HeightProperty, new Binding(nameof(source.Hauteur)) { Source = source, Mode = BindingMode.TwoWay }); BindingOperations.SetBinding(forme, CylinderVisual3D.DiameterProperty, new Binding(nameof(source.Diametre)) { Source = source, Mode = BindingMode.TwoWay }); BindingOperations.SetBinding(forme, CylinderVisual3D.InnerDiameterProperty, new Binding(nameof(source.InnerDiametre)) { Source = source, Mode = BindingMode.TwoWay }); BindingOperations.SetBinding(forme, CylinderVisual3D.ThetaDivProperty, new Binding(nameof(source.ThetaDiv)) { Source = source, Mode = BindingMode.TwoWay }); return((CylinderVisual3D)_Lier(forme, source)); }
private void CreateCustomScene() { var blueMaterial = new DiffuseMaterial(Brushes.Blue); var sphereVisual3D = new SphereVisual3D(); sphereVisual3D.CenterPosition = new Point3D(200, 20, -80); sphereVisual3D.Radius = 20; sphereVisual3D.Material = blueMaterial; MainDXViewportView.Viewport3D.Children.Add(sphereVisual3D); var grayCylinder = new CylinderVisual3D(); grayCylinder.BottomCenterPosition = new Point3D(200, 0, 100); grayCylinder.Radius = 20; grayCylinder.Height = 100; grayCylinder.Material = new DiffuseMaterial(Brushes.LightGray); MainDXViewportView.Viewport3D.Children.Add(grayCylinder); for (int x = -300; x < 500; x += 100) { var yellowBox = new BoxVisual3D(); yellowBox.CenterPosition = new Point3D(x, 30, 0); yellowBox.Size = new Size3D(20, 60, 20); yellowBox.Material = new DiffuseMaterial(Brushes.Yellow); MainDXViewportView.Viewport3D.Children.Add(yellowBox); } var readerObj = new Ab3d.ReaderObj(); _teapotModel = readerObj.ReadModel3D(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Resources\Models\Teapot.obj")); var transform3DGroup = new Transform3DGroup(); transform3DGroup.Children.Add(new ScaleTransform3D(3, 3, 3)); transform3DGroup.Children.Add(new TranslateTransform3D(-100, -20, 200)); _teapotModel.Transform = transform3DGroup; var teapotVisual3D = new ModelVisual3D(); teapotVisual3D.Content = _teapotModel; MainDXViewportView.Viewport3D.Children.Add(teapotVisual3D); var imageBrush = new ImageBrush(); imageBrush.ImageSource = new BitmapImage(new Uri(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Resources/GrassTexture.jpg"))); var grassMaterial = new DiffuseMaterial(imageBrush); _greenBox3D = new BoxVisual3D(); _greenBox3D.CenterPosition = new Point3D(0, -2, 0); _greenBox3D.Size = new Size3D(SceneSize, 4, SceneSize); _greenBox3D.Material = grassMaterial; MainDXViewportView.Viewport3D.Children.Add(_greenBox3D); }
private void CreateScene() { // Create material with 10 x 10 numbers grid var imageBrush = new ImageBrush(new BitmapImage(new Uri(@"pack://application:,,,/Resources/10x10-texture.png"))); var material = new DiffuseMaterial(imageBrush); //var material = new DiffuseMaterial(Brushes.Silver); // Create box with 10 x 10 x 10 cells var boxVisual3D = new BoxVisual3D() { UseCachedMeshGeometry3D = false, // This will generate a new MeshGeometry3D for this BoxVisual3D, FreezeMeshGeometry3D = false, // This will allow us to change the TextureCoordinates CenterPosition = new Point3D(-150, 0, -50), Size = new Size3D(60, 60, 60), XCellsCount = 10, YCellsCount = 10, ZCellsCount = 10, Material = material, }; MainViewport.Children.Add(boxVisual3D); var cylinderVisual3D = new CylinderVisual3D() { BottomCenterPosition = new Point3D(-50, -30, -50), Radius = 30, Height = 60, Segments = 10, IsSmooth = false, Material = material }; MainViewport.Children.Add(cylinderVisual3D); var sphereVisual3D = new SphereVisual3D() { UseCachedMeshGeometry3D = false, // This will generate a new MeshGeometry3D for this BoxVisual3D, FreezeMeshGeometry3D = false, // This will allow us to change the TextureCoordinates CenterPosition = new Point3D(50, 0, -50), Radius = 30, Material = material }; MainViewport.Children.Add(sphereVisual3D); // Add dragon model string fileName = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Resources\\ObjFiles\\dragon_vrip_res3.obj"); var objModelVisual3D = new ObjModelVisual3D() { Source = new Uri(fileName, UriKind.Absolute), SizeX = 70, Position = new Point3D(-150, 0, 100), PositionType = ObjModelVisual3D.VisualPositionType.Center, DefaultMaterial = material, }; Ab3d.Utilities.ModelUtils.ChangeMaterial(objModelVisual3D.Content, material, newBackMaterial: null); MainViewport.Children.Add(objModelVisual3D); // Add simple extruded shape var extrudePositions = new Point[] { new Point(-1, 54), new Point(13, 35), new Point(8, 32), new Point(18, 13), new Point(11, 9), new Point(23, -13), new Point(6, -14), new Point(6, -29), new Point(-8, -30), new Point(-7, -13), new Point(-25, -9), new Point(-12, 9), new Point(-25, 16), new Point(-8, 31), new Point(-16, 38) }; var extrudedMesh = Mesh3DFactory.CreateExtrudedMeshGeometry(positions: extrudePositions.ToList(), isSmooth: false, modelOffset: new Vector3D(-50, -15, 100), extrudeVector: new Vector3D(0, 30, 0), shapeYVector: new Vector3D(0, 0, -1), textureCoordinatesGenerationType: ExtrudeTextureCoordinatesGenerationType.AddAdditionalPositions); var geometryModel3D = new GeometryModel3D(extrudedMesh, material); var modelVisual3D = new ModelVisual3D(); modelVisual3D.Content = geometryModel3D; MainViewport.Children.Add(modelVisual3D); }