本文整理汇总了C#中System.Windows.Media.Media3D.MaterialGroup类的典型用法代码示例。如果您正苦于以下问题:C# MaterialGroup类的具体用法?C# MaterialGroup怎么用?C# MaterialGroup使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MaterialGroup类属于System.Windows.Media.Media3D命名空间,在下文中一共展示了MaterialGroup类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateMaterial
/// <summary>
/// Creates a material with the specifed brush as diffuse material.
/// This method will also add a white specular material.
/// </summary>
/// <param name="brush">The brush.</param>
/// <param name="specularPower">The specular power.</param>
/// <returns></returns>
public static Material CreateMaterial(Brush brush, double specularPower)
{
var mg = new MaterialGroup();
mg.Children.Add(new DiffuseMaterial(brush));
if (specularPower > 0)
mg.Children.Add(new SpecularMaterial(Brushes.White, specularPower));
return mg;
}
示例2: TrackballGrabber
public TrackballGrabber(FrameworkElement eventSource, Viewport3D viewport, double sphereRadius, Color hoverLightColor)
{
if (viewport.Camera == null || !(viewport.Camera is PerspectiveCamera))
{
throw new ArgumentException("This class requires a perspective camera to be tied to the viewport");
}
_eventSource = eventSource;
_viewport = viewport;
_camera = (PerspectiveCamera)viewport.Camera;
this.SyncedLights = new List<Model3D>();
this.HoverVisuals = new ObservableCollection<Visual3D>();
this.HoverVisuals.CollectionChanged += HoverVisuals_CollectionChanged;
_eventSource.MouseEnter += new System.Windows.Input.MouseEventHandler(EventSource_MouseEnter);
_eventSource.MouseLeave += new System.Windows.Input.MouseEventHandler(EventSource_MouseLeave);
_eventSource.MouseDown += new System.Windows.Input.MouseButtonEventHandler(EventSource_MouseDown);
_eventSource.MouseUp += new System.Windows.Input.MouseButtonEventHandler(EventSource_MouseUp);
_eventSource.MouseMove += new System.Windows.Input.MouseEventHandler(EventSource_MouseMove);
#region Sphere
// Material
_sphereMaterials = new MaterialGroup();
_sphereMaterials.Children.Add(new DiffuseMaterial(new SolidColorBrush(Color.FromArgb(25, 255, 255, 255))));
// This gets added/removed on mouse enter/leave
_sphereMaterialHover = new SpecularMaterial(new SolidColorBrush(Color.FromArgb(64, 128, 128, 128)), 33d);
// Geometry Model
GeometryModel3D geometry = new GeometryModel3D();
geometry.Material = _sphereMaterials;
geometry.BackMaterial = _sphereMaterials;
geometry.Geometry = UtilityWPF.GetSphere_LatLon(20, sphereRadius);
// Model Visual
_sphereModel = new ModelVisual3D();
_sphereModel.Content = geometry;
// Add it
_viewport.Children.Add(_sphereModel);
#endregion
#region Hover Light
// Light
PointLight hoverLight = new PointLight();
hoverLight.Color = hoverLightColor;
hoverLight.Range = sphereRadius * 10;
_hoverLight = new ModelVisual3D();
_hoverLight.Content = hoverLight;
#endregion
}
示例3: ThrustLine
public ThrustLine(Viewport3D viewport, SharedVisuals sharedVisuals, Vector3D forceDirection, Vector3D localOffset)
{
this.Viewport = viewport;
_forceDirection = forceDirection;
_forceStrength = forceDirection.Length; // this way they don't have to set this if they don't want
this.BodyOffset = new TranslateTransform3D(localOffset); // just setting it to something so it's not null
#region Create Visual
// I'll create the visual, but won't add it until they fire the thruster
// Material
MaterialGroup materials = new MaterialGroup();
materials.Children.Add(new DiffuseMaterial(Brushes.Coral));
materials.Children.Add(new SpecularMaterial(Brushes.Gold, 100d));
// Geometry Model
// Create a skinny 3D rectangle along the x axis
GeometryModel3D geometry = new GeometryModel3D();
geometry.Material = materials;
geometry.BackMaterial = materials;
geometry.Geometry = sharedVisuals.ThrustLineMesh;
// Figure out how much to rotate the cube to be along the opposite of the force line. I do the opposite, because
// thruster flames shoot in the opposite direction that they're pushing
Vector3D flameLine = forceDirection;
flameLine.Negate();
Vector3D axis;
double radians;
Math3D.GetRotation(out axis, out radians, new Vector3D(1, 0, 0), flameLine);
if (radians == 0d)
{
_initialRotate = null;
}
else
{
_initialRotate = new RotateTransform3D(new AxisAngleRotation3D(axis, Math1D.RadiansToDegrees(radians)));
}
//// Transform
//Transform3DGroup transform = new Transform3DGroup(); // rotate needs to be added before translate
//transform.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(axis, Math3D.RadiansToDegrees(radians))));
//transform.Children.Add(new TranslateTransform3D(from));
// Model Visual
_model = new ModelVisual3D();
_model.Content = geometry;
_model.Transform = new TranslateTransform3D(); // I won't do anything with this right now
#endregion
}
示例4: getSurfaceMaterial
//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;
}
示例5: SetColor
private void SetColor(Color color)
{
MaterialGroup unlitMaterial = new MaterialGroup();
unlitMaterial.Children.Add(new DiffuseMaterial(new SolidColorBrush(Colors.Black)));
unlitMaterial.Children.Add(new EmissiveMaterial(new SolidColorBrush(color)));
unlitMaterial.Freeze();
_model.Material = unlitMaterial;
_model.BackMaterial = unlitMaterial;
}
示例6: Egg
public Egg(Point3D position, World world, int materialID, ItemOptions itemOptions, ShipDNA dna)
{
// The radius should be 20% the size of the adult ship
this.Radius = dna.PartsByLayer.SelectMany(o => o.Value).
Max(o => o.Position.ToVector().Length + Math1D.Max(o.Scale.X, o.Scale.Y, o.Scale.Z))
* .2d;
Vector3D scale = new Vector3D(.75d, .75d, 1d);
#region WPF Model
// Material
MaterialGroup materials = new MaterialGroup();
materials.Children.Add(new DiffuseMaterial(new SolidColorBrush(WorldColors.EggColor)));
materials.Children.Add(WorldColors.EggSpecular);
// Geometry Model
GeometryModel3D geometry = new GeometryModel3D();
geometry.Material = materials;
geometry.BackMaterial = materials;
geometry.Geometry = UtilityWPF.GetSphere_LatLon(5, this.Radius);
geometry.Transform = new ScaleTransform3D(scale);
this.Model = geometry;
// Model Visual
ModelVisual3D model = new ModelVisual3D();
model.Content = geometry;
#endregion
#region Physics Body
Transform3DGroup transform = new Transform3DGroup();
transform.Children.Add(new RotateTransform3D(new QuaternionRotation3D(Math3D.GetRandomRotation())));
transform.Children.Add(new TranslateTransform3D(position.ToVector()));
double volume = (4d / 3d) * Math.PI * scale.X * this.Radius * scale.Y * this.Radius * scale.Z * this.Radius;
double mass = volume * itemOptions.Egg_Density;
using (CollisionHull hull = CollisionHull.CreateSphere(world, 0, scale * this.Radius, null))
{
this.PhysicsBody = new Body(hull, transform.Value, mass, new Visual3D[] { model });
this.PhysicsBody.MaterialGroupID = materialID;
this.PhysicsBody.LinearDamping = .01f;
this.PhysicsBody.AngularDamping = new Vector3D(.001f, .001f, .001f);
}
#endregion
this.CreationTime = DateTime.UtcNow;
}
示例7: GetBackShadow
/// <summary>
/// 获取纸张背面的半透明材质
/// </summary>
/// <returns></returns>
public MaterialGroup GetBackShadow()
{
transparentBackMaterial = backMaterial.Clone();
foreach (Material m in transparentBackMaterial.Children)
{
DiffuseMaterial dm = (DiffuseMaterial)m;
if (dm != null)
{
dm.Color = dm.AmbientColor = Color.FromArgb(100, 255, 255, 255);
}
}
return transparentBackMaterial;
}
示例8: MaterialLibrary
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;
}
}
}
示例9: Cartoon
/// <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);
}
}
示例10: ToMaterial
public static Material ToMaterial(this IfcSurfaceStyleRendering r)
{
MaterialGroup grp = new MaterialGroup();
if (r.DiffuseColour is IfcNormalisedRatioMeasure)
{
Brush brush = new SolidColorBrush(r.SurfaceColour.ToColor((IfcNormalisedRatioMeasure)r.DiffuseColour));
brush.Opacity = r.Transparency.HasValue ? 1.0 - r.Transparency.Value : 1.0;
grp.Children.Add(new DiffuseMaterial(brush));
}
else if (r.DiffuseColour is IfcColourRgb)
{
Brush brush = new SolidColorBrush(((IfcColourRgb)r.DiffuseColour).ToColor());
brush.Opacity = r.Transparency.HasValue ? 1.0 - r.Transparency.Value : 1.0;
grp.Children.Add(new DiffuseMaterial(brush));
}
else if (r.DiffuseColour == null)
{
Brush brush = new SolidColorBrush(r.SurfaceColour.ToColor());
brush.Opacity = r.Transparency.HasValue ? 1.0 - r.Transparency.Value : 1.0;
grp.Children.Add(new DiffuseMaterial(brush));
}
if (r.SpecularColour is IfcNormalisedRatioMeasure)
{
Brush brush = new SolidColorBrush(r.SurfaceColour.ToColor());
brush.Opacity = r.Transparency.HasValue ? 1.0 - r.Transparency.Value : 1.0;
grp.Children.Add(new SpecularMaterial(brush, (IfcNormalisedRatioMeasure)(r.SpecularColour)));
}
if (r.SpecularColour is IfcColourRgb)
{
Brush brush = new SolidColorBrush(((IfcColourRgb)r.SpecularColour).ToColor());
brush.Opacity = r.Transparency.HasValue ? 1.0 - r.Transparency.Value : 1.0;
grp.Children.Add(new SpecularMaterial(brush, 100.0));
}
if (grp.Children.Count == 1)
{
Material mat = grp.Children[0];
return mat;
}
else
{
return grp;
}
}
示例11: GetCylinder
public static Model3DGroup GetCylinder(MaterialGroup materialGroup, Point3D midPoint, double radius, double depth)
{
var cylinder = new Model3DGroup();
var nearCircle = new CircleAssitor();
var farCircle = new CircleAssitor();
var twoPi = Math.PI * 2;
var firstPass = true;
double x;
double y;
var increment = 0.1d;
for (double i = 0; i < twoPi + increment; i = i + increment)
{
x = (radius * Math.Cos(i));
y = (-radius * Math.Sin(i));
farCircle.CurrentTriangle.P0 = midPoint;
farCircle.CurrentTriangle.P1 = farCircle.LastPoint;
farCircle.CurrentTriangle.P2 = new Point3D(x + midPoint.X, y + midPoint.Y, midPoint.Z);
nearCircle.CurrentTriangle = farCircle.CurrentTriangle.Clone(depth, true);
if (!firstPass)
{
cylinder.Children.Add(FYDP_3Dobject_Util.CreateTriangleModel(materialGroup, farCircle.CurrentTriangle));
cylinder.Children.Add(FYDP_3Dobject_Util.CreateTriangleModel(materialGroup, nearCircle.CurrentTriangle));
cylinder.Children.Add(FYDP_3Dobject_Util.CreateTriangleModel(materialGroup, farCircle.CurrentTriangle.P2, farCircle.CurrentTriangle.P1, nearCircle.CurrentTriangle.P2));
cylinder.Children.Add(FYDP_3Dobject_Util.CreateTriangleModel(materialGroup, nearCircle.CurrentTriangle.P2, nearCircle.CurrentTriangle.P1, farCircle.CurrentTriangle.P2));
}
else
{
farCircle.FirstPoint = farCircle.CurrentTriangle.P1;
nearCircle.FirstPoint = nearCircle.CurrentTriangle.P1;
firstPass = false;
}
farCircle.LastPoint = farCircle.CurrentTriangle.P2;
nearCircle.LastPoint = nearCircle.CurrentTriangle.P2;
}
return cylinder;
}
示例12: GetImageMaterial
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;
}
示例13: WireBase
// Constructor
// -----------
public WireBase()
{
LineCollection = new Point3DCollection();
// Create MeshGeometry3D.
MeshGeometry3D mesh = new MeshGeometry3D();
// Create MaterialGroup.
MaterialGroup matgrp = new MaterialGroup();
matgrp.Children.Add(new DiffuseMaterial(Brushes.Black));
matgrp.Children.Add(new EmissiveMaterial(new SolidColorBrush(Color)));
// Create GeometryModel3D.
GeometryModel3D model = new GeometryModel3D(mesh, matgrp);
// Remove this later
model.BackMaterial = new DiffuseMaterial(Brushes.Red);
// Set the Content property to the GeometryModel3D.
Content = model;
// Add to collection.
listWireBases.Add(new WireBaseAndUltimateParent(this));
}
示例14: GetMaterial
public Material GetMaterial(string texturePath)
{
var mg = new MaterialGroup();
if (DiffuseMap == null)
{
var diffuseBrush = new SolidColorBrush(Diffuse) { Opacity = Dissolved };
mg.Children.Add(new DiffuseMaterial(diffuseBrush));
}
else
{
var path = Path.Combine(texturePath, DiffuseMap);
if (File.Exists(path))
{
var img = new BitmapImage(new Uri(path, UriKind.Relative));
var textureBrush = new ImageBrush(img) { Opacity = Dissolved };
mg.Children.Add(new DiffuseMaterial(textureBrush));
}
}
mg.Children.Add(new SpecularMaterial(new SolidColorBrush(Specular), SpecularCoefficient));
return mg;
}
示例15: CreateGeometry
private Model3DGroup CreateGeometry(bool isFinal)
{
int domeSegments = isFinal ? 2 : 10;
int cylinderSegments = isFinal ? 6 : 35;
Model3DGroup retVal = new Model3DGroup();
GeometryModel3D geometry;
MaterialGroup material;
DiffuseMaterial diffuse;
SpecularMaterial specular;
#region Insides
if (!isFinal)
{
ScaleTransform3D scaleTransform = new ScaleTransform3D(HEIGHT, HEIGHT, HEIGHT);
//TODO: This caps them to a sphere. It doesn't look too bad, but could be better
Model3D[] insideModels = BrainDesign.CreateInsideVisuals(.4, this.MaterialBrushes, base.SelectionEmissives, scaleTransform);
retVal.Children.AddRange(insideModels);
}
#endregion
#region Outer Shell
geometry = new GeometryModel3D();
material = new MaterialGroup();
Color shellColor = WorldColors.Brain;
if (!isFinal)
{
shellColor = UtilityWPF.AlphaBlend(shellColor, Colors.Transparent, .75d);
}
diffuse = new DiffuseMaterial(new SolidColorBrush(shellColor));
this.MaterialBrushes.Add(new MaterialColorProps(diffuse, shellColor));
material.Children.Add(diffuse);
specular = WorldColors.BrainSpecular;
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);
}
geometry.Material = material;
geometry.BackMaterial = material;
List<TubeRingBase> rings = new List<TubeRingBase>();
rings.Add(new TubeRingRegularPolygon(0, false, RADIUSPERCENTOFSCALE_NARROW, RADIUSPERCENTOFSCALE_NARROW, true));
rings.Add(new TubeRingRegularPolygon(HEIGHT, false, RADIUSPERCENTOFSCALE_WIDE, RADIUSPERCENTOFSCALE_WIDE, true));
geometry.Geometry = UtilityWPF.GetMultiRingedTube(cylinderSegments, rings, true, true);
retVal.Children.Add(geometry);
#endregion
retVal.Transform = GetTransformForGeometry(isFinal);
return retVal;
}