//------------------------------------------------------ // // Public Properties // //------------------------------------------------------ private static void ColorPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { SpecularMaterial target = ((SpecularMaterial)d); target.PropertyChanged(ColorProperty); }
//Create a default material of the specified colour: public static 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; }
public MaterialLibrary(Loader l) { MaterialGroup group = null; DiffuseMaterial diffuse = null; SpecularMaterial specular = null; foreach (Instruction i in l.Parse()) { switch (i.Type) { case "newmtl": group = new MaterialGroup(); diffuse = new DiffuseMaterial(); group.Children.Add(diffuse); specular = new SpecularMaterial(); group.Children.Add(specular); Materials.Add(i.Arg, group); break; case "Ns": specular.SpecularPower = i.Double(); break; case "d": case "Tr": diffuse.Brush.Opacity = i.Float(); break; case "Ka": diffuse.AmbientColor = i.Color(); break; case "Kd": diffuse.Brush = new SolidColorBrush(i.Color()); break; case "Ks": specular.Brush = new SolidColorBrush(i.Color()); break; // TODO: UV Maps case "illum": case "Ni": // Index of Refraction // Unsupported, ignore break; default: // Unrecognized symbol break; } } }
/// <summary> /// Builds the 3D model for the cartoon view a the given residue. /// </summary> /// <param name="residue">A residue.</param> /// <param name="initialColor">The residue's current color.</param> internal Cartoon(Residue residue, Color initialColor) { this.residue = residue; this.materialGroup = new MaterialGroup(); this.diffuseMaterial = new DiffuseMaterial(new SolidColorBrush(initialColor)); this.materialGroup.Children.Add(diffuseMaterial); SpecularMaterial specularMaterial = new SpecularMaterial(); specularMaterial.Brush = new SolidColorBrush(Color.FromArgb(192, 255, 255, 255)); specularMaterial.SpecularPower = 50; this.materialGroup.Children.Add(specularMaterial); this.model = new Model3DGroup(); this.residue.Ribbon.GetResidueSpline(this.residue, out this.ribbonPoints, out this.torsionVectors, out this.normalVectors); if (this.residue.IsHelix) { this.AddTube(Cartoon.helixWidth, Cartoon.helixHeight); if (this.residue.IsStructureStart) this.AddTubeCap(Cartoon.helixWidth, Cartoon.helixHeight); if (this.residue.IsStructureEnd) this.AddTubeCap(Cartoon.helixWidth, Cartoon.helixHeight); } else if (this.residue.IsSheet) { this.AddSheet(); if (this.residue.IsStructureStart || this.residue.IsStructureEnd) this.AddSheetCap(); } else { this.AddTube(Cartoon.turnWidth, Cartoon.turnWidth); if (this.residue.IsStructureStart) this.AddTubeCap(Cartoon.turnWidth, Cartoon.turnWidth); if (this.residue.IsStructureEnd) this.AddTubeCap(Cartoon.turnWidth, Cartoon.turnWidth); } }
private static void BrushPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { // The first change to the default value of a mutable collection property (e.g. GeometryGroup.Children) // will promote the property value from a default value to a local value. This is technically a sub-property // change because the collection was changed and not a new collection set (GeometryGroup.Children. // Add versus GeometryGroup.Children = myNewChildrenCollection). However, we never marshalled // the default value to the compositor. If the property changes from a default value, the new local value // needs to be marshalled to the compositor. We detect this scenario with the second condition // e.OldValueSource != e.NewValueSource. Specifically in this scenario the OldValueSource will be // Default and the NewValueSource will be Local. if (e.IsASubPropertyChange && (e.OldValueSource == e.NewValueSource)) { return; } SpecularMaterial target = ((SpecularMaterial)d); Brush oldV = (Brush)e.OldValue; Brush newV = (Brush)e.NewValue; System.Windows.Threading.Dispatcher dispatcher = target.Dispatcher; if (dispatcher != null) { DUCE.IResource targetResource = (DUCE.IResource)target; using (CompositionEngineLock.Acquire()) { int channelCount = targetResource.GetChannelCount(); for (int channelIndex = 0; channelIndex < channelCount; channelIndex++) { DUCE.Channel channel = targetResource.GetChannel(channelIndex); Debug.Assert(!channel.IsOutOfBandChannel); Debug.Assert(!targetResource.GetHandle(channel).IsNull); target.ReleaseResource(oldV, channel); target.AddRefResource(newV, channel); } } } target.PropertyChanged(BrushProperty); }
public static Material GetImageMaterial(ImageSource imageSource, Brush specularBrush = null, double specularPower = 10) { var material = new MaterialGroup(); var diffuse = new DiffuseMaterial { Brush = new ImageBrush { ImageSource = imageSource, TileMode = TileMode.Tile } }; material.Children.Add(diffuse); if (!ReferenceEquals(null, specularBrush)) { var specular = new SpecularMaterial { Brush = specularBrush, SpecularPower = specularPower }; material.Children.Add(specular); } return material; }
private Model3D GetBall() { GeometryModel3D retVal = new GeometryModel3D(); MaterialGroup material = new MaterialGroup(); DiffuseMaterial diffuse = new DiffuseMaterial(new SolidColorBrush(this.EditorColors.DraggableModifier)); this.MaterialBrushes.Add(new MaterialColorProps(diffuse, diffuse.Brush, this.EditorColors.DraggableModifier)); material.Children.Add(diffuse); SpecularMaterial specular = new SpecularMaterial(new SolidColorBrush(this.EditorColors.DraggableModifier_SpecularColor), this.EditorColors.DraggableModifier_SpecularPower); this.MaterialBrushes.Add(new MaterialColorProps(specular)); material.Children.Add(specular); retVal.Material = material; retVal.BackMaterial = material; retVal.Geometry = UtilityWPF.GetSphere_LatLon(20, .1); Transform3DGroup transform = new Transform3DGroup(); transform.Children.Add(new TranslateTransform3D(_initialOffset * _radius)); retVal.Transform = transform; return retVal; }
/// <summary> /// Replaces any instances of the sentinal brush with the internal brush /// </summary> /// <param name="material">The material to look through</param> private void SwapInCyclicBrush(Material material) { int numMaterialsSwapped = 0; Stack <Material> materialStack = new Stack <Material>(); materialStack.Push(material); Brush internalBrush = (CacheMode as BitmapCache != null) ? (Brush)InternalBitmapCacheBrush : (Brush)InternalVisualBrush; while (materialStack.Count > 0) { Material currMaterial = materialStack.Pop(); if (currMaterial is DiffuseMaterial) { DiffuseMaterial diffMaterial = (DiffuseMaterial)currMaterial; if ((Boolean)diffMaterial.GetValue(Viewport2DVisual3D.IsVisualHostMaterialProperty)) { diffMaterial.Brush = internalBrush; numMaterialsSwapped++; } } else if (currMaterial is EmissiveMaterial) { EmissiveMaterial emmMaterial = (EmissiveMaterial)currMaterial; if ((Boolean)emmMaterial.GetValue(Viewport2DVisual3D.IsVisualHostMaterialProperty)) { emmMaterial.Brush = internalBrush; numMaterialsSwapped++; } } else if (currMaterial is SpecularMaterial) { SpecularMaterial specMaterial = (SpecularMaterial)currMaterial; if ((Boolean)specMaterial.GetValue(Viewport2DVisual3D.IsVisualHostMaterialProperty)) { specMaterial.Brush = internalBrush; numMaterialsSwapped++; } } else if (currMaterial is MaterialGroup) { MaterialGroup matGroup = (MaterialGroup)currMaterial; // the IsVisualHostMaterialProperty should not be set on a MaterialGroup - verify that if ((Boolean)matGroup.GetValue(Viewport2DVisual3D.IsVisualHostMaterialProperty)) { throw new ArgumentException(SR.Get(SRID.Viewport2DVisual3D_MaterialGroupIsInteractiveMaterial), "material"); } // iterate over the children and put them on the stack of materials to modify MaterialCollection children = matGroup.Children; if (children != null) { for (int i = 0, count = children.Count; i < count; i++) { Material m = children[i]; materialStack.Push(m); } } } else { Invariant.Assert(true, "Unexpected Material type encountered. V2DV3D handles DiffuseMaterial, EmissiveMaterial, SpecularMaterial, and MaterialGroup."); } } // throw if there is more than 1 interactive material if (numMaterialsSwapped > 1) { throw new ArgumentException(SR.Get(SRID.Viewport2DVisual3D_MultipleInteractiveMaterials), "material"); } }
internal static Model3DGroup CreateGeometry(List<MaterialColorProps> materialBrushes, List<EmissiveMaterial> selectionEmissives, Transform3D transform, Color baseColor, SpecularMaterial baseSpecular, EmissiveMaterial baseEmissive, Color colorColor, SpecularMaterial colorSpecular, bool isFinal) { const double SCALE = .5d; Model3DGroup retVal = new Model3DGroup(); GeometryModel3D geometry; MaterialGroup material; DiffuseMaterial diffuse; SpecularMaterial specular; EmissiveMaterial emissive; int numSegments = isFinal ? 3 : 20; #region Main Sphere geometry = new GeometryModel3D(); material = new MaterialGroup(); diffuse = new DiffuseMaterial(new SolidColorBrush(colorColor)); materialBrushes.Add(new MaterialColorProps(diffuse, colorColor)); material.Children.Add(diffuse); specular = colorSpecular; 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; geometry.Geometry = UtilityWPF.GetSphere_LatLon(numSegments, .9 * SCALE, .9 * SCALE, .65d * SCALE); retVal.Children.Add(geometry); #endregion #region Ring geometry = new GeometryModel3D(); material = new MaterialGroup(); diffuse = new DiffuseMaterial(new SolidColorBrush(baseColor)); materialBrushes.Add(new MaterialColorProps(diffuse, baseColor)); material.Children.Add(diffuse); specular = baseSpecular; materialBrushes.Add(new MaterialColorProps(specular)); material.Children.Add(specular); emissive = baseEmissive; materialBrushes.Add(new MaterialColorProps(emissive)); material.Children.Add(emissive); if (!isFinal) { EmissiveMaterial selectionEmissive = new EmissiveMaterial(Brushes.Transparent); material.Children.Add(selectionEmissive); selectionEmissives.Add(selectionEmissive); } geometry.Material = material; geometry.BackMaterial = material; geometry.Geometry = UtilityWPF.GetSphere_LatLon(numSegments, 1d * SCALE, 1d * SCALE, .15d * SCALE); retVal.Children.Add(geometry); #endregion #region Axis geometry = new GeometryModel3D(); material = new MaterialGroup(); diffuse = new DiffuseMaterial(new SolidColorBrush(baseColor)); materialBrushes.Add(new MaterialColorProps(diffuse, baseColor)); material.Children.Add(diffuse); specular = baseSpecular; materialBrushes.Add(new MaterialColorProps(specular)); material.Children.Add(specular); emissive = baseEmissive; materialBrushes.Add(new MaterialColorProps(emissive)); material.Children.Add(emissive); if (!isFinal) { EmissiveMaterial selectionEmissive = new EmissiveMaterial(Brushes.Transparent); material.Children.Add(selectionEmissive); selectionEmissives.Add(selectionEmissive); } geometry.Material = material; geometry.BackMaterial = material; geometry.Geometry = UtilityWPF.GetSphere_LatLon(numSegments, .25d * SCALE, .25d * SCALE, 1d * SCALE); retVal.Children.Add(geometry); #endregion // Transform retVal.Transform = transform; // Exit Function return retVal; }
internal static Model3DGroup CreateGeometry(List<MaterialColorProps> materialBrushes, List<EmissiveMaterial> selectionEmissives, Transform3D transform, Color baseColor, SpecularMaterial baseSpecular, Color colorColor, SpecularMaterial colorSpecular, bool isFinal) { Model3DGroup retVal = new Model3DGroup(); GeometryModel3D geometry; MaterialGroup material; DiffuseMaterial diffuse; SpecularMaterial specular; #region Main Cube geometry = new GeometryModel3D(); material = new MaterialGroup(); diffuse = new DiffuseMaterial(new SolidColorBrush(baseColor)); materialBrushes.Add(new MaterialColorProps(diffuse, baseColor)); material.Children.Add(diffuse); specular = baseSpecular; 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; geometry.Geometry = GetMeshBase(SCALE); retVal.Children.Add(geometry); #endregion #region Color Cube geometry = new GeometryModel3D(); material = new MaterialGroup(); diffuse = new DiffuseMaterial(new SolidColorBrush(colorColor)); materialBrushes.Add(new MaterialColorProps(diffuse, colorColor)); material.Children.Add(diffuse); specular = colorSpecular; 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; geometry.Geometry = GetMeshColor(SCALE); retVal.Children.Add(geometry); #endregion // Transform retVal.Transform = transform; // Exit Function return retVal; }
public MaterialColorProps(SpecularMaterial specular) { this.Specular = specular; SolidColorBrush brush = specular.Brush as SolidColorBrush; if (brush == null) { throw new ApplicationException("The specular was expected to be set up with a solid color brush. Expand this method"); } this.OrigBrush = brush; this.OrigColor = brush.Color; this.OrigSpecular = specular.SpecularPower; }
private static Model3D GetArrow(Axis axis, bool positiveDirection, DiffuseMaterial diffuse, SpecularMaterial specular, double cylinderRadius, double cylinderHeight, double coneRadius, double coneHeight, double coneOffset) { // Material MaterialGroup materials = new MaterialGroup(); materials.Children.Add(diffuse); materials.Children.Add(specular); Model3DGroup retVal = new Model3DGroup(); #region cylinder // Geometry Model GeometryModel3D geometry = new GeometryModel3D(); geometry.Material = materials; geometry.BackMaterial = materials; geometry.Geometry = UtilityWPF.GetCylinder_AlongX(20, cylinderRadius, cylinderHeight); geometry.Transform = new TranslateTransform3D(new Vector3D(cylinderHeight / 2d, 0, 0)); retVal.Children.Add(geometry); #endregion #region cone // Geometry Model geometry = new GeometryModel3D(); geometry.Material = materials; geometry.BackMaterial = materials; geometry.Geometry = UtilityWPF.GetCone_AlongX(10, coneRadius, coneHeight); geometry.Transform = new TranslateTransform3D(new Vector3D(coneOffset, 0, 0)); retVal.Children.Add(geometry); #endregion #region cap // Geometry Model geometry = new GeometryModel3D(); geometry.Material = materials; geometry.BackMaterial = materials; geometry.Geometry = UtilityWPF.GetSphere_LatLon(20, cylinderRadius); retVal.Children.Add(geometry); #endregion retVal.Transform = GetTransform(axis, positiveDirection); // Exit Function return retVal; }
// Creates new material void CreateMaterial() { // Creates materials material = new MaterialGroup(); diffuseMaterial = new DiffuseMaterial(new SolidColorBrush(diffuse.Value)){AmbientColor = ambient.Value}; if (bumpImage == null) bumpImage = new BitmapImage(new Uri("pack://application:,,,/NuGenBioChem;component/Images/Noise.png")); bumpMaterial = new DiffuseMaterial(new ImageBrush(bumpImage) { TileMode = TileMode.Tile, Opacity = bumpLevel.Value }) { Color = diffuse.Value, AmbientColor = ambient.Value }; if(reflectionImage==null) reflectionImage = new BitmapImage(new Uri("pack://application:,,,/NuGenBioChem;component/Images/Clouds.png")); enviromentMaterial = new DiffuseMaterial(new ImageBrush(reflectionImage) { TileMode = TileMode.Tile, Opacity = reflectionLevel.Value }) { Color = diffuse.Value, AmbientColor = ambient.Value }; emissiveMaterial = new EmissiveMaterial(new SolidColorBrush(emissive.Value){Opacity = emissiveLevel.Value}); specularMaterial = new SpecularMaterial(new SolidColorBrush(specular.Value){Opacity = glossiness.Value},specularPower.Value); // Fill group if (diffuse.Value.A > 5) // Only if diffuse is not transparent { if ((bumpLevel.Value < 1) && (reflectionLevel.Value < 1)) material.Children.Add(diffuseMaterial); if ((bumpLevel.Value > 0) && (reflectionLevel.Value < 1)) material.Children.Add(bumpMaterial); if (reflectionLevel.Value > 0) material.Children.Add(enviromentMaterial); if ((emissiveLevel.Value > 0) && (emissive.Value != Colors.Black)) material.Children.Add(emissiveMaterial); if ((glossiness.Value > 0) && (specular.Value != Colors.Black)) material.Children.Add(specularMaterial); } RaisePropertyChanged("VisualMaterial"); }
public static Model3D GetMinorDoubleArrow(Axis axis, DiffuseMaterial diffuse, SpecularMaterial specular) { return GetDoubleArrow(axis, diffuse, specular, .05d, 1d, .075d, .2d, .5d + .1d); }
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; }
internal static Model3DGroup CreateGeometry(List<MaterialColorProps> materialBrushes, List<EmissiveMaterial> selectionEmissives, Transform3D transform, Color cameraBase, SpecularMaterial cameraBaseSpecular, Color cameraLensColor, SpecularMaterial cameraLensSpecular, bool isFinal) { ScaleTransform3D scaleTransformLocal = new ScaleTransform3D(SCALE, SCALE, SCALE); int domeSegments = isFinal ? 2 : 10; int cylinderSegments = isFinal ? 6 : 35; Model3DGroup retVal = new Model3DGroup(); GeometryModel3D geometry; MaterialGroup material; DiffuseMaterial diffuse; SpecularMaterial specular; Transform3DGroup transformGroup = new Transform3DGroup(); transformGroup.Children.Add(new TranslateTransform3D(0, 0, (HEIGHT / 2d) - .15d)); transformGroup.Children.Add(scaleTransformLocal); #region Spotlight //// Even when I make it extreme, it doesn't seem to make the gradient brighter //SpotLight spotLight = new SpotLight(); //spotLight.Color = Colors.White; ////spotLight.LinearAttenuation = 1d; //spotLight.LinearAttenuation = .1d; //spotLight.Range = 10; //spotLight.InnerConeAngle = 66; //spotLight.OuterConeAngle = 80; //spotLight.Direction = new Vector3D(0, 0, -1); //spotLight.Transform = new TranslateTransform3D(0, 0, 1); //retVal.Children.Add(spotLight); #endregion #region Back Lens if (!isFinal) { geometry = new GeometryModel3D(); material = new MaterialGroup(); RadialGradientBrush eyeBrush = new RadialGradientBrush(); eyeBrush.GradientStops.Add(new GradientStop(UtilityWPF.ColorFromHex("#FFFFEA00"), 0d)); eyeBrush.GradientStops.Add(new GradientStop(UtilityWPF.ColorFromHex("#FFF5E100"), 0.0187702d)); eyeBrush.GradientStops.Add(new GradientStop(UtilityWPF.ColorFromHex("#FFECD800"), 0.0320388d)); eyeBrush.GradientStops.Add(new GradientStop(UtilityWPF.ColorFromHex("#FFD46C00"), 0.0485437d)); eyeBrush.GradientStops.Add(new GradientStop(UtilityWPF.ColorFromHex("#FFBC0000"), 0.104167d)); eyeBrush.GradientStops.Add(new GradientStop(UtilityWPF.ColorFromHex("#FF8E0000"), 0.267322d)); eyeBrush.GradientStops.Add(new GradientStop(UtilityWPF.ColorFromHex("#FF600000"), 0.486408d)); eyeBrush.GradientStops.Add(new GradientStop(UtilityWPF.ColorFromHex("#FF3E0000"), 0.61068d)); eyeBrush.GradientStops.Add(new GradientStop(UtilityWPF.ColorFromHex("#FF1D0000"), 0.713592d)); eyeBrush.GradientStops.Add(new GradientStop(UtilityWPF.ColorFromHex("#FF0E0000"), 0.760544d)); eyeBrush.GradientStops.Add(new GradientStop(UtilityWPF.ColorFromHex("#FF000000"), 1d)); diffuse = new DiffuseMaterial(eyeBrush); materialBrushes.Add(new MaterialColorProps(diffuse, cameraLensColor)); // using the final's lens color, because it's a solid color material.Children.Add(diffuse); //if (!isFinal) //{ EmissiveMaterial selectionEmissive = new EmissiveMaterial(Brushes.Transparent); material.Children.Add(selectionEmissive); selectionEmissives.Add(selectionEmissive); //} geometry.Material = material; geometry.BackMaterial = material; geometry.Geometry = UtilityWPF.GetCircle2D(cylinderSegments, transformGroup, transformGroup); retVal.Children.Add(geometry); } #endregion #region Glass Cover geometry = new GeometryModel3D(); material = new MaterialGroup(); if (isFinal) { material.Children.Add(new DiffuseMaterial(new SolidColorBrush(cameraLensColor))); // no need to add these to this.MaterialBrushes (those are only for editing) material.Children.Add(cameraLensSpecular); } else { //NOTE: Not using the world color, because that's for final. The editor has a HAL9000 eye, and this is a glass plate Color color = Color.FromArgb(26, 255, 255, 255); diffuse = new DiffuseMaterial(new SolidColorBrush(color)); materialBrushes.Add(new MaterialColorProps(diffuse, color)); material.Children.Add(diffuse); specular = new SpecularMaterial(new SolidColorBrush(Color.FromArgb(224, 255, 255, 255)), 95d); materialBrushes.Add(new MaterialColorProps(specular)); material.Children.Add(specular); EmissiveMaterial selectionEmissive = new EmissiveMaterial(Brushes.Transparent); material.Children.Add(selectionEmissive); selectionEmissives.Add(selectionEmissive); } geometry.Material = material; //NOTE: The position handed to the camera pool is the center of this camera. So need to leave the back material null, or it would //be like taking pictures with the lens cap on //geometry.BackMaterial = material; List<TubeRingBase> rings = new List<TubeRingBase>(); rings.Add(new TubeRingRegularPolygon(0, false, 1, 1, false)); rings.Add(new TubeRingDome(.15, false, domeSegments)); geometry.Geometry = UtilityWPF.GetMultiRingedTube(cylinderSegments, rings, true, false, transformGroup); retVal.Children.Add(geometry); #endregion #region Silver Ring if (!isFinal) { geometry = new GeometryModel3D(); material = new MaterialGroup(); Color color = Color.FromRgb(90, 90, 90); diffuse = new DiffuseMaterial(new SolidColorBrush(color)); materialBrushes.Add(new MaterialColorProps(diffuse, color)); material.Children.Add(diffuse); specular = new SpecularMaterial(Brushes.White, 100d); 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; geometry.Geometry = UtilityWPF.GetRing(cylinderSegments, .97, 1.03, .05, transformGroup); retVal.Children.Add(geometry); } #endregion #region Back Cover geometry = new GeometryModel3D(); material = new MaterialGroup(); diffuse = new DiffuseMaterial(new SolidColorBrush(cameraBase)); materialBrushes.Add(new MaterialColorProps(diffuse, cameraBase)); material.Children.Add(diffuse); specular = cameraBaseSpecular; 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; rings = new List<TubeRingBase>(); rings.Add(new TubeRingDome(0, false, domeSegments)); rings.Add(new TubeRingRegularPolygon(1.5, false, 1, 1, false)); transformGroup = new Transform3DGroup(); transformGroup.Children.Add(new TranslateTransform3D(0, 0, 1.65 / -2d)); transformGroup.Children.Add(scaleTransformLocal); geometry.Geometry = UtilityWPF.GetMultiRingedTube(cylinderSegments, rings, true, false, transformGroup); retVal.Children.Add(geometry); #endregion // Transform retVal.Transform = transform; // Exit Function return retVal; }
private Model3DGroup CreateTriangleModel(Point3D p0, Point3D p1, Point3D p2) { MeshGeometry3D mesh = new MeshGeometry3D(); mesh.Positions.Add(p0); mesh.Positions.Add(p1); mesh.Positions.Add(p2); mesh.TriangleIndices.Add(0); mesh.TriangleIndices.Add(1); mesh.TriangleIndices.Add(2); Vector3D normal = CalculateNormal(p0, p1, p2); mesh.Normals.Add(normal); mesh.Normals.Add(normal); mesh.Normals.Add(normal); Material material; if (!IsBlackKey) { material = new DiffuseMaterial( new SolidColorBrush(Colors.White)); } else { material = new DiffuseMaterial( new SolidColorBrush(Colors.Black)); } Material specMat = new SpecularMaterial(Brushes.Red, 100.0); MaterialGroup matGrp = new MaterialGroup(); //matGrp.Children.Add(specMat); //matGrp.Children.Add(material); // GeometryModel3D model = new GeometryModel3D( mesh,material); Model3DGroup group = new Model3DGroup(); group.Children.Add(model); return group; }
public static ModelResult LoadModel3DGroup(IConfigurationService configService, bool designMode) { if (designMode) { var mesh = new CubeMesh(); var model = new GeometryModel3D(mesh.Geometry, new DiffuseMaterial(new SolidColorBrush(Colors.Red))); var group = new Transform3DGroup(); group.Children.Add(new ScaleTransform3D(new Vector3D(20, 20, 20))); group.Children.Add(new RotateTransform3D( new AxisAngleRotation3D(new Vector3D(1, 1, 0), 30))); model.Transform = group; var designSesult = new ModelResult(); designSesult.Model3DGroup.Children.Add(model); return designSesult; } var result = new ModelResult(); var model3DGroup = new Model3DGroup(); var modelConfig = configService.GetModelConfiguration(); foreach (var letter in modelConfig.LetterModels) { var dictionary = new ResourceDictionary() { Source = new Uri(letter.ModelPath, UriKind.Relative) }; var mesh = (MeshGeometry3D)dictionary["mesh"]; if (mesh == null) { throw new InvalidOperationException("3D Mesh could not be read in XAML file '" + letter.ModelPath + "'"); } var brush = new SolidColorBrush( (Color)ColorConverter.ConvertFromString(letter.Color)); var materialGroup = new MaterialGroup(); var diffuse = new DiffuseMaterial(brush); var specular = new SpecularMaterial(new SolidColorBrush(Colors.White), 1000); materialGroup.Children.Add(diffuse); materialGroup.Children.Add(specular); var model = new GeometryModel3D(mesh, materialGroup); var transformGroup = new Transform3DGroup(); var scale = new ScaleTransform3D( new Vector3D(letter.Scale, letter.Scale, letter.Scale)); var translate = new TranslateTransform3D( new Vector3D(letter.OffsetX, letter.OffsetY, letter.OffsetZ)); transformGroup.Children.Add(translate); transformGroup.Children.Add(scale); model.Transform = transformGroup; model3DGroup.Children.Add(model); var wireframe = new ScreenLines(); for (var i = 0; i < mesh.Positions.Count; i++) { wireframe.Points.Add(mesh.Positions[i]); wireframe.Thickness = 1; wireframe.Color = Colors.White; } wireframe.Transform = transformGroup; result.Wireframes.Add(wireframe); } result.Model3DGroup = model3DGroup; return result; }
public Material MakeMaterial(MFnMesh fnMesh) { MaterialGroup matGroup =new MaterialGroup () ; MObjectArray shaders =new MObjectArray() ; MIntArray indices =new MIntArray () ; fnMesh.getConnectedShaders (0, shaders, indices) ; for ( int i =0 ; i < shaders.length ; i++ ) { MFnDependencyNode shaderGroup =new MFnDependencyNode (shaders [i]) ; MPlug shaderPlug =shaderGroup.findPlug ("surfaceShader") ; MPlugArray connections =new MPlugArray () ; shaderPlug.connectedTo (connections, true, false) ; for ( int u =0 ; u < connections.length ; u++ ) { MFnDependencyNode depNode =new MFnDependencyNode (connections [u].node) ; //MPlug colorPlug =depNode.findPlug ("color") ; //MColor mcolor =new MColor () ; ///*MPlugArray cc =new MPlugArray () ; //colorPlug.connectedTo (cc, true , false) ; //if ( cc.length > 0 ) { // // Plug is driven by an input connection. // for ( int v =0 ; v < cc.length ; v++ ) { // MPlug color2Plug =cc [v] ; // Console.WriteLine (color2Plug.numChildren) ; // color2Plug.child (0).getValue (mcolor.r) ; // color2Plug.child (1).getValue (mcolor.g) ; // color2Plug.child (2).getValue (mcolor.b) ; // //color2Plug.child (3).getValue (mcolor.a) ; // } //} else {*/ // mcolor.r =colorPlug.child (0).asFloat () ; // mcolor.g =colorPlug.child (1).asFloat () ; // mcolor.b =colorPlug.child (2).asFloat () ; // //colorPlug.child (3).getValue (mcolor.a) ; ////} //MPlug trPlug =depNode.findPlug ("transparency") ; //float transparency =1.0f - trPlug.child (0).asFloat () ; ////return new DiffuseMaterial (new SolidColorBrush (Color.FromScRgb (transparency, mcolor.r, mcolor.g, mcolor.b))) ; //DiffuseMaterial diffuse =new DiffuseMaterial (new SolidColorBrush (Color.FromScRgb (transparency, mcolor.r, mcolor.g, mcolor.b))) ; //colorPlug =depNode.findPlug ("ambientColor") ; //mcolor.r =colorPlug.child (0).asFloat () ; //mcolor.g =colorPlug.child (1).asFloat () ; //mcolor.b =colorPlug.child (2).asFloat () ; //diffuse.AmbientColor =Color.FromScRgb (transparency, mcolor.r, mcolor.g, mcolor.b) ; //matGroup.Children.Add (diffuse) ; //colorPlug =depNode.findPlug ("specularColor") ; //mcolor.r =colorPlug.child (0).asFloat () ; //mcolor.g =colorPlug.child (1).asFloat () ; //mcolor.b =colorPlug.child (2).asFloat () ; //MPlug powerPlug =depNode.findPlug ("cosinePower") ; //SpecularMaterial specular =new SpecularMaterial (new SolidColorBrush (Color.FromScRgb (1.0f, mcolor.r, mcolor.g, mcolor.b)), powerPlug.asDouble ()) ; //matGroup.Children.Add (specular) ; //EmissiveMaterial emissive =new EmissiveMaterial () ; //matGroup.Children.Add (emissive) ; try { MFnLambertShader lambert =new MFnLambertShader (connections [u].node) ; SolidColorBrush brush =new SolidColorBrush (Color.FromScRgb (1.0f - lambert.transparency.r, lambert.color.r, lambert.color.g, lambert.color.b)) ; brush.Opacity =1.0f - lambert.transparency.r ; DiffuseMaterial diffuse =new DiffuseMaterial (brush) ; diffuse.AmbientColor =Color.FromScRgb (1.0f - lambert.ambientColor.a, lambert.ambientColor.r, lambert.ambientColor.g, lambert.ambientColor.b) ; // no more attributes matGroup.Children.Add (diffuse) ; // No specular color EmissiveMaterial emissive =new EmissiveMaterial (new SolidColorBrush (Color.FromScRgb (1.0f - lambert.incandescence.a, lambert.incandescence.r, lambert.incandescence.g, lambert.incandescence.b))) ; // no more attributes matGroup.Children.Add (emissive) ; } catch { } //try { // MFnReflectShader reflect =new MFnReflectShader (connections [u].node) ; // SpecularMaterial specular =new SpecularMaterial (new SolidColorBrush (Color.FromScRgb (1.0f - reflect.specularColor.a, reflect.specularColor.r, reflect.specularColor.g, reflect.specularColor.b)), reflect.cosPower) ; // // no more attributes // matGroup.Children.Add (specular) ; //} catch { //} try { MFnPhongShader phong =new MFnPhongShader (connections [u].node) ; //See Lambert //SolidColorBrush brush =new SolidColorBrush (Color.FromScRgb (1.0f - phong.transparency.r, phong.color.r, phong.color.g, phong.color.b)) ; //brush.Opacity =1.0f - phong.transparency.r ; //DiffuseMaterial diffuse =new DiffuseMaterial (brush) ; //diffuse.AmbientColor =Color.FromScRgb (1.0f - phong.ambientColor.a, phong.ambientColor.r, phong.ambientColor.g, phong.ambientColor.b) ; //// no more attributes //matGroup.Children.Add (diffuse) ; SpecularMaterial specular =new SpecularMaterial (new SolidColorBrush (Color.FromScRgb (1.0f - phong.specularColor.a, phong.specularColor.r, phong.specularColor.g, phong.specularColor.b)), phong.cosPower) ; // no more attributes matGroup.Children.Add (specular) ; //See Lambert //EmissiveMaterial emissive =new EmissiveMaterial (new SolidColorBrush (Color.FromScRgb (1.0f - phong.incandescence.a, phong.incandescence.r, phong.incandescence.g, phong.incandescence.b))) ; //// no more attributes //matGroup.Children.Add (emissive) ; } catch { } // todo //try { // MFnBlinnShader phong =new MFnBlinnShader (connections [u].node) ; // //See Lambert // //SolidColorBrush brush =new SolidColorBrush (Color.FromScRgb (1.0f - phong.transparency.r, phong.color.r, phong.color.g, phong.color.b)) ; // //brush.Opacity =1.0f - phong.transparency.r ; // //DiffuseMaterial diffuse =new DiffuseMaterial (brush) ; // //diffuse.AmbientColor = Color.FromScRgb (1.0f - phong.ambientColor.a, phong.ambientColor.r, phong.ambientColor.g, phong.ambientColor.b) ; // //// no more attributes // //matGroup.Children.Add (diffuse) ; // //See Lambert // //EmissiveMaterial emissive =new EmissiveMaterial (new SolidColorBrush (Color.FromScRgb (1.0f - phong.incandescence.a, phong.incandescence.r, phong.incandescence.g, phong.incandescence.b))) ; // //// no more attributes // //matGroup.Children.Add (emissive) ; //} catch { //} } } // Default to Blue if ( matGroup.Children.Count == 0 ) matGroup.Children.Add (new DiffuseMaterial (new SolidColorBrush (Color.FromRgb (0, 0, 255)))) ; return (matGroup) ; }
private Model3D GetRing() { double size = UtilityCore.GetScaledValue_Capped(.025d, .15d, .1d, 10d, _radius); GeometryModel3D retVal = new GeometryModel3D(); MaterialGroup material = new MaterialGroup(); DiffuseMaterial diffuse = new DiffuseMaterial(new SolidColorBrush(this.EditorColors.DraggableModifier)); this.MaterialBrushes.Add(new MaterialColorProps(diffuse, diffuse.Brush, this.EditorColors.DraggableModifier)); material.Children.Add(diffuse); SpecularMaterial specular = new SpecularMaterial(new SolidColorBrush(this.EditorColors.DraggableModifier_SpecularColor), this.EditorColors.DraggableModifier_SpecularPower); this.MaterialBrushes.Add(new MaterialColorProps(specular)); material.Children.Add(specular); retVal.Material = material; retVal.BackMaterial = material; retVal.Geometry = UtilityWPF.GetRing(50, _radius - (size * .5d), _radius + (size * .5d), size, _initialRotateTransform); return retVal; }
public static Model3D GetMinorArrow(Axis axis, bool positiveDirection, DiffuseMaterial diffuse, SpecularMaterial specular) { return GetArrow(axis, positiveDirection, diffuse, specular, .05d, .5d, .075d, .2d, .5d + .1d); }
private GeometryModel3D GetArrow(Quaternion rotation) { GeometryModel3D retVal = new GeometryModel3D(); MaterialGroup material = new MaterialGroup(); DiffuseMaterial diffuse = new DiffuseMaterial(new SolidColorBrush(this.EditorColors.DraggableModifier)); this.MaterialBrushes.Add(new MaterialColorProps(diffuse, diffuse.Brush, this.EditorColors.DraggableModifier)); material.Children.Add(diffuse); SpecularMaterial specular = new SpecularMaterial(new SolidColorBrush(this.EditorColors.DraggableModifier_SpecularColor), this.EditorColors.DraggableModifier_SpecularPower); this.MaterialBrushes.Add(new MaterialColorProps(specular)); material.Children.Add(specular); retVal.Material = material; retVal.BackMaterial = material; List<TubeRingBase> rings = new List<TubeRingBase>(); rings.Add(new TubeRingDome(0, false, 10)); rings.Add(new TubeRingRegularPolygon(.025, false, .05, .05, false)); rings.Add(new TubeRingRegularPolygon(.3, false, .05, .05, false)); rings.Add(new TubeRingRegularPolygon(-.0375, false, .125, .125, false)); rings.Add(new TubeRingPoint(.2, false)); RotateTransform3D transform = new RotateTransform3D(new QuaternionRotation3D(rotation)); retVal.Geometry = UtilityWPF.GetMultiRingedTube(35, rings, true, true, transform); return retVal; }
public NetworkOutputs(string[] names) { this.Size = names.Length; this.Names = names; this.DistanceMult = 1.5d / Math.Sqrt(this.Size); // the 1.5 doesn't mean anything. It just helps push them apart a little more this.Hues = CreateHues(this.Size); #region Materials SpecularMaterial specular = new SpecularMaterial(new SolidColorBrush(UtilityWPF.ColorFromHex("50FFFFFF")), 2); // Colors this.DotColors = this.Hues.Select(o => { ColorHSV color = new ColorHSV(o, 75, 75); MaterialGroup material = new MaterialGroup(); material.Children.Add(new DiffuseMaterial(new SolidColorBrush(color.ToRGB()))); material.Children.Add(specular); return new Tuple<ColorHSV, Material>(color, material); }).ToArray(); // Gray this.ColorGray = new ColorHSV(0, 0, 50); MaterialGroup material_Gray = new MaterialGroup(); material_Gray.Children.Add(new DiffuseMaterial(new SolidColorBrush(this.ColorGray.ToRGB()))); material_Gray.Children.Add(specular); this.DotGray = material_Gray; #endregion }
private static GeometryModel3D BuildDot_Visual(Model3DGroup modelGroup, MeshGeometry3D dotGeometry, SortedList<string, MaterialGroup> dotMaterials, SpecularMaterial specular, Color color, TranslateTransform3D translate) { string colorKey = UtilityWPF.ColorToHex(color); // Material MaterialGroup material; if (!dotMaterials.TryGetValue(colorKey, out material)) { material = new MaterialGroup(); material.Children.Add(new DiffuseMaterial(new SolidColorBrush(color))); material.Children.Add(specular); dotMaterials.Add(colorKey, material); } // Geometry GeometryModel3D retVal = new GeometryModel3D() { Material = material, BackMaterial = material, Geometry = dotGeometry, Transform = translate, }; modelGroup.Children.Add(retVal); return retVal; }
private static Model3D GetDoubleArrow(Axis axis, DiffuseMaterial diffuse, SpecularMaterial specular, double cylinderRadius, double cylinderHeight, double coneRadius, double coneHeight, double coneOffset) { // Material MaterialGroup materials = new MaterialGroup(); materials.Children.Add(diffuse); materials.Children.Add(specular); Model3DGroup retVal = new Model3DGroup(); #region cylinder // Geometry Model GeometryModel3D geometry = new GeometryModel3D(); geometry.Material = materials; geometry.BackMaterial = materials; geometry.Geometry = UtilityWPF.GetCylinder_AlongX(20, cylinderRadius, cylinderHeight); retVal.Children.Add(geometry); #endregion #region cone + // Geometry Model geometry = new GeometryModel3D(); geometry.Material = materials; geometry.BackMaterial = materials; geometry.Geometry = UtilityWPF.GetCone_AlongX(10, coneRadius, coneHeight); Transform3DGroup transform = new Transform3DGroup(); // rotate needs to be added before translate //transform.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(Math3D.GetRandomVectorSpherical(_rand, 10), Math3D.GetNearZeroValue(_rand, 360d)))); transform.Children.Add(new TranslateTransform3D(new Vector3D(coneOffset, 0, 0))); geometry.Transform = transform; retVal.Children.Add(geometry); #endregion #region cone - // Geometry Model geometry = new GeometryModel3D(); geometry.Material = materials; geometry.BackMaterial = materials; geometry.Geometry = UtilityWPF.GetCone_AlongX(10, coneRadius, coneHeight); transform = new Transform3DGroup(); // rotate needs to be added before translate transform.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 1, 0), 180))); transform.Children.Add(new TranslateTransform3D(new Vector3D(-coneOffset, 0, 0))); geometry.Transform = transform; retVal.Children.Add(geometry); #endregion retVal.Transform = GetTransform(axis, true); // Exit Function return retVal; }
///<summary>Objects are added in this step as all gray. Colors are set in a separate step.</summary> public void AddObjectGroup(D3ObjectGroup group) { _model3Dgroup=new Model3DGroup(); DirectionalLight light=new DirectionalLight(Colors.WhiteSmoke,new Vector3D(-3,-3,-3)); _model3Dgroup.Children.Add(light); DirectionalLight light2=new DirectionalLight(Colors.LightGray,new Vector3D(2.8,-3,-3)); _model3Dgroup.Children.Add(light2); //AmbientLight ambientLight=new AmbientLight(Colors.DarkGray); //_model3Dgroup.Children.Add(ambientLight); objectNames=new List<string>(); objectNames.Add("light1"); objectNames.Add("light2");//to maintain 1:1 for(int i=0;i<group.D3Objects.Count;i++) { MeshGeometry3D meshGeometry3D=new MeshGeometry3D(); Point3DCollection points=group.D3Objects[i].GenerateVertices(); meshGeometry3D.Positions=points; PointCollection textures=group.D3Objects[i].GenerateTextures(); meshGeometry3D.TextureCoordinates=textures; Vector3DCollection vectors=group.D3Objects[i].GenerateNormals(); meshGeometry3D.Normals=vectors; Int32Collection indices=group.D3Objects[i].GenerateIndices(); meshGeometry3D.TriangleIndices=indices; GeometryModel3D geometryModel3D=new GeometryModel3D(); geometryModel3D.Geometry=meshGeometry3D; //materials MaterialGroup materialGroup=new MaterialGroup(); DiffuseMaterial diffuseMaterial=new DiffuseMaterial(); if(group.D3Objects[i].TextureMap!=null) { ImageBrush imageBrush=new ImageBrush(D3Helper.ConvertImage(group.D3Objects[i].TextureMap)); imageBrush.ViewportUnits=BrushMappingMode.Absolute; ScaleTransform scaleTransform=new ScaleTransform(1,-1);//scale y -1 to flip vertically TranslateTransform translateTransform=new TranslateTransform(0,1);//shift up one after flipping TransformGroup transformGroup=new TransformGroup(); transformGroup.Children.Add(scaleTransform); transformGroup.Children.Add(translateTransform); imageBrush.Transform=transformGroup; diffuseMaterial.Brush=imageBrush; } else if(group.TextureMap!=null && group.D3Objects[i].VertexNormals[0].Texture!=null) {//a group texture is specified and this object uses texture mapping ImageBrush imageBrush=new ImageBrush(D3Helper.ConvertImage(group.TextureMap)); imageBrush.ViewportUnits=BrushMappingMode.Absolute; ScaleTransform scaleTransform=new ScaleTransform(1,-1);//scale y -1 to flip vertically TranslateTransform translateTransform=new TranslateTransform(0,1);//shift up one after flipping TransformGroup transformGroup=new TransformGroup(); transformGroup.Children.Add(scaleTransform); transformGroup.Children.Add(translateTransform); imageBrush.Transform=transformGroup; diffuseMaterial.Brush=imageBrush; } else { diffuseMaterial.Brush=new SolidColorBrush(Colors.Gray); //diffuseMaterial.Color=Colors.Gray;//this didn't work. Needs brush. } materialGroup.Children.Add(diffuseMaterial); //specular material at 1 SpecularMaterial specularMaterial=new SpecularMaterial(); specularMaterial.Brush=new SolidColorBrush(Colors.White); specularMaterial.SpecularPower=150;//smaller numbers give more reflection. 150 is minimal specular. materialGroup.Children.Add(specularMaterial); geometryModel3D.Material=materialGroup; _model3Dgroup.Children.Add(geometryModel3D); objectNames.Add(group.D3Objects[i].Name); } ModelVisual3D modelVisual3D=new ModelVisual3D(); modelVisual3D.Content=_model3Dgroup; myViewport.Children.Add(modelVisual3D); }
private static Visual3D TestSamples_Draw(SketchSample[] sketches, double[] hues) { const double RADIUS = .5; const double DOTRADIUS = .035; #region Materials SpecularMaterial specular = new SpecularMaterial(new SolidColorBrush(UtilityWPF.ColorFromHex("50FFFFFF")), 2); var material_Color = hues.Select(o => { ColorHSV color = new ColorHSV(o, 75, 75); MaterialGroup material = new MaterialGroup(); material.Children.Add(new DiffuseMaterial(new SolidColorBrush(color.ToRGB()))); material.Children.Add(specular); return new { Color = color, Material = material }; }).ToArray(); ColorHSV color_Gray = new ColorHSV(0, 0, 50); MaterialGroup material_Gray = new MaterialGroup(); material_Gray.Children.Add(new DiffuseMaterial(new SolidColorBrush(color_Gray.ToRGB()))); material_Gray.Children.Add(specular); #endregion Model3DGroup group = new Model3DGroup(); foreach (SketchSample sketch in sketches) { int? matchIndex = UtilityEncog.IsMatch(sketch.NNOutput); Material material; if (matchIndex == null) { sketch.IsMatch = false; sketch.Color = color_Gray; material = material_Gray; } else { sketch.IsMatch = true; sketch.Color = material_Color[matchIndex.Value].Color; material = material_Color[matchIndex.Value].Material; } sketch.Position = Math3D.GetRandomVector_Spherical(RADIUS).ToPoint(); sketch.Translate_3DDot = new TranslateTransform3D(sketch.Position.ToVector()); // Geometry Model GeometryModel3D geometry = new GeometryModel3D(); geometry.Material = material; geometry.BackMaterial = material; geometry.Geometry = UtilityWPF.GetSphere_Ico(DOTRADIUS, 1, true); geometry.Transform = sketch.Translate_3DDot; group.Children.Add(geometry); } ModelVisual3D visual = new ModelVisual3D(); visual.Content = group; return visual; }