internal static Model3D CreateGeometry(List <MaterialColorProps> materialBrushes, List <EmissiveMaterial> selectionEmissives, Transform3D transform, Color color, SpecularMaterial specular, bool isFinal) { // Material MaterialGroup material = new MaterialGroup(); DiffuseMaterial diffuse = new DiffuseMaterial(new SolidColorBrush(color)); materialBrushes.Add(new MaterialColorProps(diffuse, color)); material.Children.Add(diffuse); materialBrushes.Add(new MaterialColorProps(specular)); material.Children.Add(specular); if (!isFinal) { EmissiveMaterial selectionEmissive = new EmissiveMaterial(Brushes.Transparent); material.Children.Add(selectionEmissive); selectionEmissives.Add(selectionEmissive); } // Geometry Model GeometryModel3D retVal = new GeometryModel3D(); retVal.Material = material; retVal.BackMaterial = material; int domeSegments = isFinal ? 2 : 10; int cylinderSegments = isFinal ? 6 : 35; retVal.Geometry = UtilityWPF.GetCapsule_AlongZ(cylinderSegments, domeSegments, RADIUSPERCENTOFSCALE, 1d); // Transform retVal.Transform = transform; // Exit Function return(retVal); }
public BoneVisual3d(TransformPtrViewModel transform, SkeletonVisual3d skeleton, string name) { this.ViewModel = transform; this.Skeleton = skeleton; this.rotation = new RotateTransform3D(); this.position = new TranslateTransform3D(); Transform3DGroup transformGroup = new Transform3DGroup(); transformGroup.Children.Add(this.rotation); transformGroup.Children.Add(this.position); this.Transform = transformGroup; PaletteHelper ph = new PaletteHelper(); ITheme t = ph.GetTheme(); this.defaultMaterial = new DiffuseMaterial(new SolidColorBrush(WinColor.FromArgb(64, 0, 0, 0))); this.hoverMaterial = new EmissiveMaterial(new SolidColorBrush(t.PrimaryDark.Color)); this.selectedMaterial = new EmissiveMaterial(new SolidColorBrush(t.PrimaryMid.Color)); System.Windows.Media.Color c1 = System.Windows.Media.Color.FromArgb(200, 255, 255, 255); this.sphere = new Sphere(); this.sphere.Radius = 0.02; this.sphere.Material = this.defaultMaterial; this.Children.Add(this.sphere); this.OriginalBoneName = name; this.BoneName = name; this.Skeleton.PropertyChanged += this.OnSkeletonPropertyChanged; }
private static Material MaterialFromColour(XbimColour colour) { var col = Color.FromScRgb(colour.Alpha, colour.Red, colour.Green, colour.Blue); Brush brush = new SolidColorBrush(col); // build material Material mat; if (colour.SpecularFactor > 0) { mat = new SpecularMaterial(brush, colour.SpecularFactor * 100); } else if (colour.ReflectionFactor > 0) { mat = new EmissiveMaterial(brush); } else { mat = new DiffuseMaterial(brush); } // freeze and return mat.Freeze(); return(mat); }
public CircleFeatureVisual(CircleFeatureCurve featureCurve, double thickness = 0.01) { Contract.Requires(thickness > 0); Contract.Requires(featureCurve != null); Contract.Ensures(object.ReferenceEquals(featureCurve, FeatureCurve)); this.featureCurve = featureCurve; this.thickness = thickness; var emissiveMaterial = new EmissiveMaterial(); emissiveMaterial.Bind( EmissiveMaterial.BrushProperty, () => featureCurve.IsSelected, isSelected => isSelected ? Brushes.DarkOrange : Brushes.Black); var material = new MaterialGroup(); material.Children.Add(new DiffuseMaterial { Brush = Brushes.Black }); material.Children.Add(emissiveMaterial); model3d = new GeometryModel3D(); model3d.Material = model3d.BackMaterial = material; Content = model3d; Update(); }
internal override void MakeNewGeometryModel() { try { if (Emmissive) { EmissiveMaterial SolidMatE = new EmissiveMaterial(); SolidMatE.Brush = SetTextureImageBrush(); GeoMod.Material = SolidMatE; } else { DiffuseMaterial SolidMat = new DiffuseMaterial(); // SolidMat.Brush = Brushes.Blue; SolidMat.Brush = SetTextureImageBrush(); GeoMod.Material = SolidMat; } MakeSphericalModel(); // if( Surface == null ) GeoMod.Geometry = Surface; } catch (Exception Except) { ShowStatus("Exception in PlanetSphere.MakeNewGeometryModel(): " + Except.Message); } }
private static ModelVisual3D CreateVisual(MeshGeometry3D geometry, Brush brush) { var frontEmissivePart = new EmissiveMaterial { Brush = brush }; //CreateEmissiveMaterial(snappedPrimitive); var frontDiffusePart = new DiffuseMaterial { Brush = brush }; var frontMaterial = new MaterialGroup { Children = { frontEmissivePart, frontDiffusePart } }; // create wpf classes for displaying the geometry var model3d = new GeometryModel3D( geometry, frontMaterial); //model3d. var backEmissivePart = new EmissiveMaterial { Brush = brush }; //CreateEmissiveMaterial(snappedPrimitive); var backDiffusePart = new DiffuseMaterial { Brush = brush }; var backMaterial = new MaterialGroup { Children = { backEmissivePart, backDiffusePart } }; model3d.BackMaterial = backMaterial; var visual = new ModelVisual3D(); visual.Content = model3d; return(visual); }
public static GeometryModel3D Make3DGeometry_Over3Points(Point3D p1_, Point3D p2_, double thickness) { Point3D[] PointsToMesch = new Point3D[8]; MeshGeometry3D m = new MeshGeometry3D(); Vector3D v12 = new Vector3D(p2_.X - p1_.X, p2_.Y - p1_.Y, p2_.Z - p1_.Z);//vektro senkrecht auf die ebene in der der punkt Q liegen wird. es ist die Achse der Rotation Point3D Q1 = GetQ(v12, p1_, thickness); AxisAngleRotation3D rotation_90_1 = new AxisAngleRotation3D(v12, -90); RotateTransform3D rot3D_90_1 = new RotateTransform3D(rotation_90_1, p1_); Point3D resultatQ1_90 = new Point3D(); resultatQ1_90 = rot3D_90_1.Transform(Q1); AxisAngleRotation3D rotation_180_1 = new AxisAngleRotation3D(v12, -180); RotateTransform3D rot3D_180_1 = new RotateTransform3D(rotation_180_1, p1_); Point3D resultatQ1_180 = new Point3D(); resultatQ1_180 = rot3D_180_1.Transform(Q1); AxisAngleRotation3D rotation_270_1 = new AxisAngleRotation3D(v12, -270); RotateTransform3D rot3D_270_1 = new RotateTransform3D(rotation_270_1, p1_); Point3D resultatQ1_270 = new Point3D(); resultatQ1_270 = rot3D_270_1.Transform(Q1); Point3D Q2 = GetQ(v12, p2_, thickness); AxisAngleRotation3D rotation_90_2 = new AxisAngleRotation3D(v12, -90); RotateTransform3D rot3D_90_2 = new RotateTransform3D(rotation_90_2, p2_); Point3D resultatQ2_90 = new Point3D(); resultatQ2_90 = rot3D_90_2.Transform(Q2); AxisAngleRotation3D rotation_180_2 = new AxisAngleRotation3D(v12, -180); RotateTransform3D rot3D_180_2 = new RotateTransform3D(rotation_180_2, p2_); Point3D resultatQ2_180 = new Point3D(); resultatQ2_180 = rot3D_180_2.Transform(Q2); AxisAngleRotation3D rotation_270_2 = new AxisAngleRotation3D(v12, -270); RotateTransform3D rot3D_270_2 = new RotateTransform3D(rotation_270_2, p2_); Point3D resultatQ2_270 = new Point3D(); resultatQ2_270 = rot3D_270_2.Transform(Q2); PointsToMesch[0] = Q1; PointsToMesch[1] = resultatQ1_90; PointsToMesch[2] = resultatQ1_270; PointsToMesch[3] = resultatQ1_180; PointsToMesch[4] = Q2; PointsToMesch[5] = resultatQ2_90; PointsToMesch[6] = resultatQ2_270; PointsToMesch[7] = resultatQ2_180; DiffuseMaterial DiffuseMaterial = new DiffuseMaterial(System.Windows.Media.Brushes.White); MaterialGroup MaterialGroup = new MaterialGroup(); MaterialGroup.Children.Add(DiffuseMaterial); System.Windows.Media.Color c = new System.Windows.Media.Color(); c.ScA = 255; c.ScB = 255; c.ScR = 255; c.ScG = 255; EmissiveMaterial EmissiveMaterial = new EmissiveMaterial(new SolidColorBrush(c)); MaterialGroup.Children.Add(EmissiveMaterial); return(DrawCubus(PointsToMesch, MaterialGroup)); }
private Model3DGroup GetHighlightModel3D(Gesture g, List <GestureFrame> fs) { // Create material EmissiveMaterial material = new EmissiveMaterial(new SolidColorBrush() { Color = Colors.White, Opacity = 0.3 }); Model3DGroup modelGroup = new Model3DGroup(); foreach (GestureFrame f in fs) { foreach (GestureFrameCell fc in f.FrontCells.Where(fc => fc.IsHotspot == true)) { int fcIndex = Array.IndexOf(f.FrontCells, fc); foreach (GestureFrameCell sc in f.SideCells.Where( sc => sc.IsHotspot == true && (int)(Array.IndexOf(f.SideCells, sc) / 20) == (int)(fcIndex / 20))) { // Init mesh MeshBuilder meshBuilder = new MeshBuilder(false, false); // Make cube and add to mesh double y = (fc.LeftCM + fc.RightCM) / 2; double z = (fc.TopCM + fc.BottomCM) / 2; double x = (sc.LeftCM + sc.RightCM) / 2; Point3D cubeCenter = new Point3D(x, y, z); meshBuilder.AddBox(cubeCenter, 15, 15, 15); // Create and freeze mesh var mesh = meshBuilder.ToMesh(true); // Create models modelGroup.Children.Add(new GeometryModel3D(mesh, material)); } } } return(modelGroup); }
public StarfieldModel3D() { Material m = new EmissiveMaterial(new SolidColorBrush(Colors.White)); Random r = new Random(); for (int n = 0; n < 500; n++) { double theta = Math.PI * 2 * r.NextDouble(); double phi = Math.Acos(2 * r.NextDouble() - 1); double x = Math.Cos(theta) * Math.Sin(phi); double y = Math.Sin(theta) * Math.Sin(phi); double z = Math.Cos(phi); Vector3D normal = new Vector3D(x, y, z); normal.Normalize(); Vector3D v2 = Vector3D.CrossProduct(normal, new Vector3D(0, 1, 0)); v2.Normalize(); Vector3D v3 = Vector3D.CrossProduct(normal, v2); v3.Normalize(); v2 *= 0.003; v3 *= 0.003; Point3D p0 = new Point3D(normal.X, normal.Y, normal.Z); Point3D p1 = p0 + v2; Point3D p2 = p1 + v3; Point3D p3 = p2 - v2; AddRectangle(p0, p1, p2, p3, m); byte b = (byte)r.Next(); m = new EmissiveMaterial(new SolidColorBrush(Color.FromRgb(b, b, b))); } }
private void SerializeGeneratedWorkaround(Material material, string masterFileName, List <string> supportFiles) { // This is method is needed because of this issue: // ( if (material is MaterialGroup) { foreach (Material m in ((MaterialGroup)material).Children) { SerializeGeneratedWorkaround(m, masterFileName, supportFiles); } } else { Brush brush = null; if (material is DiffuseMaterial) { DiffuseMaterial dm = (DiffuseMaterial)material; brush = dm.Brush; } else if (material is EmissiveMaterial) { EmissiveMaterial em = (EmissiveMaterial)material; brush = em.Brush; } else if (material is SpecularMaterial) { SpecularMaterial sm = (SpecularMaterial)material; brush = sm.Brush; } if (brush is ImageBrush) { ImageBrush ib = (ImageBrush)brush; // NOTE: Other forms of memory-generated bitmaps may need the same treatment. if (ib.ImageSource is CachedBitmap) { CachedBitmap cb = (CachedBitmap)ib.ImageSource; // Generate new file Name int fileIndex = supportFiles.Count; string fileName = masterFileName.Replace(".xaml", "_support_") + fileIndex.ToString() + ".png"; // Save as an image file (PNG to keep transparency) PhotoConverter.SaveImageAs(cb, fileName); // Remember the name supportFiles.Add(fileName); // Now replace this in the old brush ib.ImageSource = new BitmapImage(new Uri(fileName, UriKind.RelativeOrAbsolute)); ib.ViewboxUnits = BrushMappingMode.RelativeToBoundingBox; } } // The default case is for this to be a NO-OP } }
public VideoSurface(string mediaSource) { this.ModelVisual3D = new ModelVisual3D(); var geometryModel = new GeometryModel3D(); this.ModelVisual3D.Content = geometryModel; this.geometry = new MeshGeometry3D(); geometryModel.Geometry = geometry; var positions = new Point3DCollection(); positions.Add(new Point3D(0, 0, 0)); positions.Add(new Point3D(640, 0, 0)); positions.Add(new Point3D(640, 480, 0)); positions.Add(new Point3D(0, 480, 0)); this.geometry.Positions = positions; var textureCoordinates = new PointCollection(); textureCoordinates.Add(new System.Windows.Point(0, 1)); textureCoordinates.Add(new System.Windows.Point(1, 1)); textureCoordinates.Add(new System.Windows.Point(1, 0)); textureCoordinates.Add(new System.Windows.Point(0, 0)); this.geometry.TextureCoordinates = textureCoordinates; var triangleIndices = new Int32Collection(); triangleIndices.Add(0); triangleIndices.Add(1); triangleIndices.Add(2); triangleIndices.Add(2); triangleIndices.Add(3); triangleIndices.Add(0); this.geometry.TriangleIndices = triangleIndices; var material = new EmissiveMaterial(); var brush = new VisualBrush(); this.border = new Border(); this.border.BorderBrush = Brushes.White; this.border.BorderThickness = new Thickness(10); this.border.Opacity = 0; this.mediaElement = new MediaElement(); mediaElement.LoadedBehavior = MediaState.Manual; mediaElement.Source = new Uri(mediaSource); this.border.Child = mediaElement; brush.Visual = border; material.Brush = brush; geometryModel.Material = material; this.mediaElement.MediaEnded += new RoutedEventHandler(mediaElement_MediaEnded); }
// // This is the only property that does not require a recalculation // of the MeshGeometry3D. static void ColorPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args) { WireBase wirebase = obj as WireBase; GeometryModel3D model = wirebase.Content as GeometryModel3D; MaterialGroup matgrp = model.Material as MaterialGroup; EmissiveMaterial mat = matgrp.Children[1] as EmissiveMaterial; mat.Brush = new SolidColorBrush((Color)args.NewValue); }
private static EmissiveMaterial CreateEmissiveMaterial(SnappedPrimitive snappedPrimitive) { var frontEmissivePart = new EmissiveMaterial(); frontEmissivePart.Bind( EmissiveMaterial.BrushProperty, () => snappedPrimitive.IsSelected, flag => flag ? Brushes.LightGray : Brushes.Gray); return(frontEmissivePart); }
/// <summary> /// Creates an emissive material from the specified image. /// </summary> /// <param name="image">The image.</param> /// <param name="diffuseBrush">The diffuse brush.</param> /// <returns>The image material</returns> public static Material CreateEmissiveImageMaterial(BitmapImage image, Brush diffuseBrush) { var brush = new ImageBrush(image); var em = new EmissiveMaterial(brush); var dm = new DiffuseMaterial(diffuseBrush); var mg = new MaterialGroup(); mg.Children.Add(dm); mg.Children.Add(em); return(mg); // new DiffuseMaterial(brush); }
public MaterialGroup GetSurfaceMaterial(Color colour) { var materialGroup = new MaterialGroup(); var emmMat = new EmissiveMaterial(new SolidColorBrush(colour)); materialGroup.Children.Add(emmMat); materialGroup.Children.Add(new DiffuseMaterial(new SolidColorBrush(colour))); var specMat = new SpecularMaterial(new SolidColorBrush(Colors.White), 30); materialGroup.Children.Add(specMat); return(materialGroup); }
private Model3D CreateGeometry(bool isFinal) { Model3DGroup retVal = new Model3DGroup(); #region box MaterialGroup material = new MaterialGroup(); Color ringColor = WorldColors.DirectionControllerRing_Color; DiffuseMaterial diffuse = new DiffuseMaterial(new SolidColorBrush(ringColor)); MaterialBrushes.Add(new MaterialColorProps(diffuse, ringColor)); material.Children.Add(diffuse); SpecularMaterial specular = WorldColors.DirectionControllerRing_Specular; MaterialBrushes.Add(new MaterialColorProps(specular)); material.Children.Add(specular); if (!isFinal) { EmissiveMaterial selectionEmissive = new EmissiveMaterial(Brushes.Transparent); material.Children.Add(selectionEmissive); SelectionEmissives.Add(selectionEmissive); } GeometryModel3D geometry = new GeometryModel3D { Material = material, BackMaterial = material, Geometry = ConverterMatterToFuelDesign.GetMesh(.36d * SCALE, .04d * SCALE, 3), }; retVal.Children.Add(geometry); #endregion #region brain ScaleTransform3D scaleTransform = new ScaleTransform3D(SCALE, SCALE, SCALE); if (!isFinal) { retVal.Children.AddRange(BrainDesign.CreateInsideVisuals(SCALE * .6, MaterialBrushes, SelectionEmissives, scaleTransform)); } retVal.Children.Add(BrainDesign.CreateShellVisual(isFinal, MaterialBrushes, SelectionEmissives, scaleTransform)); #endregion retVal.Transform = GetTransformForGeometry(isFinal); return(retVal); }
private GeometryModel3D CreateGeometry(bool isFinal) { MaterialGroup material = new MaterialGroup(); DiffuseMaterial diffuse = new DiffuseMaterial(new SolidColorBrush(WorldColors.EnergyTank_Color)); this.MaterialBrushes.Add(new MaterialColorProps(diffuse, WorldColors.EnergyTank_Color)); material.Children.Add(diffuse); SpecularMaterial specular = WorldColors.EnergyTank_Specular; this.MaterialBrushes.Add(new MaterialColorProps(specular)); material.Children.Add(specular); EmissiveMaterial emissive = WorldColors.EnergyTank_Emissive; this.MaterialBrushes.Add(new MaterialColorProps(emissive)); material.Children.Add(emissive); if (!isFinal) { EmissiveMaterial selectionEmissive = new EmissiveMaterial(Brushes.Transparent); material.Children.Add(selectionEmissive); base.SelectionEmissives.Add(selectionEmissive); } GeometryModel3D retVal = new GeometryModel3D(); retVal.Material = material; retVal.BackMaterial = material; int domeSegments = isFinal ? 2 : 10; int cylinderSegments = isFinal ? 6 : 35; List <TubeRingBase> rings = new List <TubeRingBase>(); rings.Add(new TubeRingDome(0, false, domeSegments)); rings.Add(new TubeRingRegularPolygon(.4, false, 1, 1, false)); rings.Add(new TubeRingRegularPolygon(2.5, false, 1, 1, false)); rings.Add(new TubeRingDome(.4, false, domeSegments)); // Scale this so the height is 1 double scale = 1d / rings.Sum(o => o.DistFromPrevRing); Transform3DGroup transformInitial = new Transform3DGroup(); transformInitial.Children.Add(new ScaleTransform3D(scale, scale, scale)); retVal.Geometry = UtilityWPF.GetMultiRingedTube(cylinderSegments, rings, true, true, transformInitial); // Transform retVal.Transform = GetTransformForGeometry(isFinal); // Exit Function return(retVal); }
private static bool CompareMaterials(Material firstMaterial, Material secondMaterial) { if (firstMaterial.GetType() != secondMaterial.GetType()) { return(false); } MaterialGroup materialGroup1 = firstMaterial as MaterialGroup; if (materialGroup1 != null) { MaterialGroup materialGroup2 = (MaterialGroup)secondMaterial; if (materialGroup1.Children.Count != materialGroup2.Children.Count) { return(false); } for (int index = 0; index < materialGroup1.Children.Count; ++index) { if (!PropertyUtilities.CompareMaterials(materialGroup1.Children[index], materialGroup2.Children[index])) { return(false); } } return(true); } DiffuseMaterial diffuseMaterial1 = firstMaterial as DiffuseMaterial; if (diffuseMaterial1 != null) { DiffuseMaterial diffuseMaterial2 = (DiffuseMaterial)secondMaterial; return(PropertyUtilities.CompareBrushes(diffuseMaterial1.Brush, diffuseMaterial2.Brush)); } EmissiveMaterial emissiveMaterial1 = firstMaterial as EmissiveMaterial; if (emissiveMaterial1 != null) { EmissiveMaterial emissiveMaterial2 = (EmissiveMaterial)secondMaterial; return(PropertyUtilities.CompareBrushes(emissiveMaterial1.Brush, emissiveMaterial2.Brush)); } SpecularMaterial specularMaterial1 = firstMaterial as SpecularMaterial; if (specularMaterial1 == null) { return(object.Equals((object)firstMaterial, (object)secondMaterial)); } SpecularMaterial specularMaterial2 = (SpecularMaterial)secondMaterial; if (specularMaterial1.SpecularPower == specularMaterial2.SpecularPower) { return(PropertyUtilities.CompareBrushes(specularMaterial1.Brush, specularMaterial2.Brush)); } return(false); }
/// <summary> /// Shows a thin, wire box around the piece. /// </summary> public void ShowWireFrame() { this.wireFrame.Color = Colors.Yellow; this.wireFrame.Thickness = .5; WireBase wirebase = wireFrame as WireBase; GeometryModel3D model = wirebase.Content as GeometryModel3D; MaterialGroup matgrp = model.Material as MaterialGroup; EmissiveMaterial mat = matgrp.Children[1] as EmissiveMaterial; SolidColorBrush brush = mat.Brush as SolidColorBrush; brush.Opacity = .7; }
public Window1() { InitializeComponent(); basePath = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName + "\\3D_Models\\"; /** Debug sphere to check in which point the joint is rotating**/ var builder = new MeshBuilder(true, true); var position = new Point3D(0, 0, 0); builder.AddSphere(position, 5, 15, 15); visualGrid = new GeometryModel3D(builder.ToMesh(), Materials.Brown); mvGrid = new ModelVisual3D(); mvGrid.Content = visualGrid; //add board ModelImporter import = new ModelImporter(); var link = import.Load(basePath + MODEL_PATH21); mvBoard = new ModelVisual3D(); mvBoard.Content = link; mvBoard.Transform = new TranslateTransform3D(basePoint); var materialGroup = new MaterialGroup(); Color mainColor = Colors.White; EmissiveMaterial emissMat = new EmissiveMaterial(new SolidColorBrush(mainColor)); DiffuseMaterial diffMat = new DiffuseMaterial(new SolidColorBrush(mainColor)); SpecularMaterial specMat = new SpecularMaterial(new SolidColorBrush(mainColor), 200); materialGroup.Children.Add(emissMat); materialGroup.Children.Add(diffMat); materialGroup.Children.Add(specMat); GeometryModel3D model = link.Children[0] as GeometryModel3D; model.Material = materialGroup; model.BackMaterial = materialGroup; // viewPort3d.RotateGesture = new MouseGesture(MouseAction.RightClick); viewPort3d.PanGesture = new MouseGesture(MouseAction.LeftClick); viewPort3d.Children.Add(mvGrid); viewPort3d.Children.Add(mvBoard); viewPort3d.Camera.LookDirection = new Vector3D(20, -52, -29); viewPort3d.Camera.UpDirection = new Vector3D(-0.145, 0.372, 0.917); viewPort3d.Camera.Position = new Point3D(-15, 48, 37); }
public MaterialColorProps(EmissiveMaterial emissive) { this.Emissive = emissive; SolidColorBrush brush = emissive.Brush as SolidColorBrush; if (brush == null) { throw new ApplicationException("The emissive was expected to be set up with a solid color brush. Expand this method"); } this.OrigBrush = brush; this.OrigColor = brush.Color; }
static void Add8Colors(Color color, int index) { for (int n = 0; n < 8; n++) { double scale = n / 7.0; byte r = (byte)Math.Round(color.R * scale); byte g = (byte)Math.Round(color.G * scale); byte b = (byte)Math.Round(color.B * scale); Color[index] = System.Windows.Media.Color.FromRgb(r, g, b); Brush[index] = new SolidColorBrush(Color[index]); DiffuseMaterial[index] = new DiffuseMaterial(Brush[index]); EmissiveMaterial[index] = new EmissiveMaterial(Brush[index]); index++; } }
private static MaterialGroup GetMaterial(Bitmap textureBitmap) { var materialGroup = new MaterialGroup(); if (textureBitmap != null) { var memoryStream = new MemoryStream(); textureBitmap.Save(memoryStream, ImageFormat.Bmp); // Create a BitmapImage with the Stream. var bitmapImage = new BitmapImage(); bitmapImage.BeginInit(); bitmapImage.StreamSource = memoryStream; bitmapImage.EndInit(); //use this as the texture image var brush = new ImageBrush(bitmapImage) { //mapping will go wrong without setting viewport units ViewportUnits = BrushMappingMode.Absolute }; var emissiveMaterial = new EmissiveMaterial(brush) {//Color = Color.FromArgb(255, 255, 255, 255) }; materialGroup.Children.Add(emissiveMaterial); var diffuseMaterial = new DiffuseMaterial(brush) { //Color = Color.FromArgb(255, 255, 255, 255), //AmbientColor = Color.FromArgb(255, 255, 255, 255) }; materialGroup.Children.Add(diffuseMaterial); //commenting out shiningness //var specularMaterial = new SpecularMaterial(brush, 185.33); //materialGroup.Children.Add(specularMaterial); return(materialGroup); } //return a solid color brush var solidColorBrush = new SolidColorBrush { Color = Color.FromRgb(200, 200, 200) }; materialGroup.Children.Add(new DiffuseMaterial(solidColorBrush)); return(materialGroup); }
/// <summary> /// Creates an emissive material from the specified image. /// </summary> /// <param name="image">The image.</param> /// <param name="diffuseBrush">The diffuse brush.</param> /// <param name="freeze">Freeze the material if set to <c>true</c>.</param> /// <returns>The image material</returns> public static Material CreateEmissiveImageMaterial(BitmapImage image, Brush diffuseBrush, bool freeze = true) { var brush = new ImageBrush(image); var em = new EmissiveMaterial(brush); var dm = new DiffuseMaterial(diffuseBrush); var mg = new MaterialGroup(); mg.Children.Add(dm); mg.Children.Add(em); if (freeze) { mg.Freeze(); } return(mg); }
private void PaintChildOntoHostMaterial(Material material, VisualBrush childVisual) { bool foundMaterialToSwap = false; Stack <Material> materialStack = new Stack <Material>(); materialStack.Push(material); //Stop searching for swappable material after first. This is how WPF logic behaves. while (materialStack.Count > 0 && !foundMaterialToSwap) { Material currMaterial = materialStack.Pop(); bool isChildHost = (Boolean)currMaterial.GetValue(Viewport2DVisual3D.IsVisualHostMaterialProperty); if (isChildHost) { if (currMaterial is DiffuseMaterial) { DiffuseMaterial diffMaterial = (DiffuseMaterial)currMaterial; diffMaterial.Brush = childVisual; } else if (currMaterial is EmissiveMaterial) { EmissiveMaterial emmMaterial = (EmissiveMaterial)currMaterial; emmMaterial.Brush = childVisual; } else if (currMaterial is SpecularMaterial) { SpecularMaterial specMaterial = (SpecularMaterial)currMaterial; specMaterial.Brush = childVisual; } foundMaterialToSwap = true; } if (currMaterial is MaterialGroup) { MaterialGroup matGroup = (MaterialGroup)currMaterial; foreach (Material m in matGroup.Children) { materialStack.Push(m); } } } }
public void CreateMaterial() { if (this.Material != null) { return; } byte[] data = this.Image.GetImageData(); if (data != null) { var bitmap = BitmapSource.Create(this.Image.Width, this.Image.Height, 96, 96, PixelFormats.Bgra32, null, data, this.Image.Width * 4); var material = new EmissiveMaterial(new ImageBrush(bitmap)); material.Freeze(); this.Material = material; } this.Image = null; }
public static Model3D CreateShellVisual(bool isFinal, List <MaterialColorProps> materialBrushes, List <EmissiveMaterial> selectionEmissives, ScaleTransform3D scaleTransform) { GeometryModel3D geometry = new GeometryModel3D(); MaterialGroup material = new MaterialGroup(); Color shellColor = WorldColors.Brain_Color; if (!isFinal) { shellColor = UtilityWPF.AlphaBlend(shellColor, Colors.Transparent, .75d); } DiffuseMaterial diffuse = new DiffuseMaterial(new SolidColorBrush(shellColor)); materialBrushes.Add(new MaterialColorProps(diffuse, shellColor)); material.Children.Add(diffuse); SpecularMaterial specular = WorldColors.Brain_Specular; materialBrushes.Add(new MaterialColorProps(specular)); material.Children.Add(specular); if (!isFinal) { EmissiveMaterial selectionEmissive = new EmissiveMaterial(Brushes.Transparent); material.Children.Add(selectionEmissive); selectionEmissives.Add(selectionEmissive); } geometry.Material = material; geometry.BackMaterial = material; Transform3DGroup transformGroup = new Transform3DGroup(); transformGroup.Children.Add(scaleTransform); transformGroup.Children.Add(new RotateTransform3D(new QuaternionRotation3D(Math3D.GetRandomRotation()))); // this is just so it's not obvious that the brains are shared visuals geometry.Geometry = SharedVisuals.BrainMesh; // SharedVisuals keeps track of which thread made the request geometry.Transform = transformGroup; return(geometry); }
private GeometryModel3D CreateGeometry(bool isFinal) { MaterialGroup material = new MaterialGroup(); DiffuseMaterial diffuse = new DiffuseMaterial(new SolidColorBrush(WorldColors.CargoBay_Color)); this.MaterialBrushes.Add(new MaterialColorProps(diffuse, WorldColors.CargoBay_Color)); material.Children.Add(diffuse); SpecularMaterial specular = WorldColors.CargoBay_Specular; this.MaterialBrushes.Add(new MaterialColorProps(specular)); material.Children.Add(specular); if (!isFinal) { EmissiveMaterial selectionEmissive = new EmissiveMaterial(Brushes.Transparent); material.Children.Add(selectionEmissive); base.SelectionEmissives.Add(selectionEmissive); } GeometryModel3D retVal = new GeometryModel3D(); retVal.Material = material; retVal.BackMaterial = material; if (isFinal) { retVal.Geometry = UtilityWPF.GetCube_IndependentFaces(new Point3D(-.5, -.5, -.5), new Point3D(.5, .5, .5)); } else { retVal.Geometry = GetMesh(); } // Transform retVal.Transform = GetTransformForGeometry(isFinal); // Exit Function return(retVal); }
/// <summary> /// 初始化3D模型 /// </summary> private void init3DModels(List <string> modelsNames) { //var modelsNames = System.IO.Directory.GetFiles(Utility.ConstValue.AppPath + @"3D_Models", "*.STL", SearchOption.TopDirectoryOnly).ToList(); //var modelsNames = System.IO.Directory.GetFiles(Utility.ConstValue.AppPath + @"3D_Models/工件/1号工件", "*.STL", SearchOption.TopDirectoryOnly).ToList(); HelixToolkit.Wpf.ModelImporter import = new HelixToolkit.Wpf.ModelImporter(); //joints = new List<Joint>(); Model3DGroup model3DGroup = new Model3DGroup(); foreach (string modelName in modelsNames) { var materialGroup = new MaterialGroup(); Color mainColor = Colors.White; EmissiveMaterial emissMat = new EmissiveMaterial(new SolidColorBrush(mainColor)); System.Windows.Media.Media3D.DiffuseMaterial diffMat = new System.Windows.Media.Media3D.DiffuseMaterial(new SolidColorBrush(mainColor)); SpecularMaterial specMat = new SpecularMaterial(new SolidColorBrush(mainColor), 200); materialGroup.Children.Add(emissMat); materialGroup.Children.Add(diffMat); materialGroup.Children.Add(specMat); var link = import.Load(modelName); System.Windows.Media.Media3D.GeometryModel3D model = link.Children[0] as System.Windows.Media.Media3D.GeometryModel3D; model.Material = materialGroup; model.BackMaterial = materialGroup; //joints.Add(new Joint(link)); model3DGroup.Children.Add(link); } ModelVisual3D modelVisual3D = new ModelVisual3D(); modelVisual3D.Content = model3DGroup; mainContent.Children.Add(modelVisual3D); mainContent.InputBindings.Add(new MouseBinding(this.PointSelectionCommand, new MouseGesture(MouseAction.LeftClick))); mainContent.ZoomExtents(); }
private Model3DGroup Initialize_Environment(List <string> modelsNames) { try { ModelImporter import = new ModelImporter(); joints = new List <Joint>(); foreach (string modelName in modelsNames) { var materialGroup = new MaterialGroup(); Color mainColor = Colors.White; EmissiveMaterial emissMat = new EmissiveMaterial(new SolidColorBrush(mainColor)); DiffuseMaterial diffMat = new DiffuseMaterial(new SolidColorBrush(mainColor)); SpecularMaterial specMat = new SpecularMaterial(new SolidColorBrush(mainColor), 200); materialGroup.Children.Add(emissMat); materialGroup.Children.Add(diffMat); materialGroup.Children.Add(specMat); var link = import.Load(basePath + modelName); GeometryModel3D model = link.Children[0] as GeometryModel3D; model.Material = materialGroup; model.BackMaterial = materialGroup; joints.Add(new Joint(link)); } RA.Children.Add(joints[0].model); RA.Children.Add(joints[1].model); RA.Children.Add(joints[2].model); RA.Children.Add(joints[3].model); RA.Children.Add(joints[4].model); RA.Children.Add(joints[5].model); RA.Children.Add(joints[6].model); RA.Children.Add(joints[7].model); RA.Children.Add(joints[8].model); RA.Children.Add(joints[9].model); RA.Children.Add(joints[10].model); #if IRB6700 RA.Children.Add(joints[11].model); RA.Children.Add(joints[12].model); RA.Children.Add(joints[13].model); RA.Children.Add(joints[14].model); RA.Children.Add(joints[15].model); RA.Children.Add(joints[16].model); RA.Children.Add(joints[17].model); RA.Children.Add(joints[18].model); RA.Children.Add(joints[19].model); #endif #if IRB6700 Color cableColor = Colors.DarkSlateGray; changeModelColor(joints[6], cableColor); changeModelColor(joints[7], cableColor); changeModelColor(joints[8], cableColor); changeModelColor(joints[9], cableColor); changeModelColor(joints[10], cableColor); changeModelColor(joints[11], cableColor); changeModelColor(joints[12], cableColor); changeModelColor(joints[13], cableColor); changeModelColor(joints[14], Colors.Gray); changeModelColor(joints[15], Colors.Red); changeModelColor(joints[16], Colors.Red); changeModelColor(joints[17], Colors.Red); changeModelColor(joints[18], Colors.Gray); changeModelColor(joints[19], Colors.Gray); joints[0].angleMin = -180; joints[0].angleMax = 180; joints[0].rotAxisX = 0; joints[0].rotAxisY = 0; joints[0].rotAxisZ = 1; joints[0].rotPointX = 0; joints[0].rotPointY = 0; joints[0].rotPointZ = 0; joints[1].angleMin = -100; joints[1].angleMax = 60; joints[1].rotAxisX = 0; joints[1].rotAxisY = 1; joints[1].rotAxisZ = 0; joints[1].rotPointX = 348; joints[1].rotPointY = -243; joints[1].rotPointZ = 775; joints[2].angleMin = -90; joints[2].angleMax = 90; joints[2].rotAxisX = 0; joints[2].rotAxisY = 1; joints[2].rotAxisZ = 0; joints[2].rotPointX = 347; joints[2].rotPointY = -376; joints[2].rotPointZ = 1923; joints[3].angleMin = -180; joints[3].angleMax = 180; joints[3].rotAxisX = 1; joints[3].rotAxisY = 0; joints[3].rotAxisZ = 0; joints[3].rotPointX = 60; joints[3].rotPointY = 0; joints[3].rotPointZ = 2125; joints[4].angleMin = -115; joints[4].angleMax = 115; joints[4].rotAxisX = 0; joints[4].rotAxisY = 1; joints[4].rotAxisZ = 0; joints[4].rotPointX = 1815; joints[4].rotPointY = 0; joints[4].rotPointZ = 2125; joints[5].angleMin = -180; joints[5].angleMax = 180; joints[5].rotAxisX = 1; joints[5].rotAxisY = 0; joints[5].rotAxisZ = 0; joints[5].rotPointX = 2008; joints[5].rotPointY = 0; joints[5].rotPointZ = 2125; #else changeModelColor(joints[6], Colors.Red); changeModelColor(joints[7], Colors.Black); changeModelColor(joints[8], Color.Black); changeModelColor(joints[9], Colors.Black); changeModelColor(joints[10], Colors.Gray); RA.Children.Add(joints[0].model); RA.Children.Add(joints[1].model); RA.Children.Add(joints[2].model); RA.Children.Add(joints[3].model); RA.Children.Add(joints[4].model); RA.Children.Add(joints[5].model); RA.Children.Add(joints[6].model); RA.Children.Add(joints[7].model); RA.Children.Add(joints[8].model); RA.Children.Add(joints[9].model); RA.Children.Add(joints[10].model); joints[0].angleMin = -180; joints[0].angleMax = 180; joints[0].rotAxisX = 0; joints[0].rotAxisY = 0; joints[0].rotAxisZ = 1; joints[0].rotPointX = 0; joints[0].rotPointY = 0; joints[0].rotPointZ = 0; joints[1].angleMin = -100; joints[1].angleMax = 60; joints[1].rotAxisX = 0; joints[1].rotAxisY = 1; joints[1].rotAxisZ = 0; joints[1].rotPointX = 175; joints[1].rotPointY = -200; joints[1].rotPointZ = 500; joints[2].angleMin = -90; joints[2].angleMax = 90; joints[2].rotAxisX = 0; joints[2].rotAxisY = 1; joints[2].rotAxisZ = 0; joints[2].rotPointX = 190; joints[2].rotPointY = -700; joints[2].rotPointZ = 1595; joints[3].angleMin = -180; joints[3].angleMax = 180; joints[3].rotAxisX = 1; joints[3].rotAxisY = 0; joints[3].rotAxisZ = 0; joints[3].rotPointX = 400; joints[3].rotPointY = 0; joints[3].rotPointZ = 1765; joints[4].angleMin = -115; joints[4].angleMax = 115; joints[4].rotAxisX = 0; joints[4].rotAxisY = 1; joints[4].rotAxisZ = 0; joints[4].rotPointX = 1405; joints[4].rotPointY = 50; joints[4].rotPointZ = 1765; joints[5].angleMin = -180; joints[5].angleMax = 180; joints[5].rotAxisX = 1; joints[5].rotAxisY = 0; joints[5].rotAxisZ = 0; joints[5].rotPointX = 1405; joints[5].rotPointY = 0; joints[5].rotPointZ = 1765; #endif } catch (Exception e) { MessageBox.Show("Exception Error:" + e.StackTrace); } return(RA); }