我正在尝试放置一个图像画笔。WPF中的一个球体。我用来生成球体的代码是:
生成球体
如果我使用颜色作为画笔,效果非常好。但如果我试着用地球的平面图像。这篇文章的图片
我就是不能在球体上正确地绘制图像。能想到的我都试过了。我认为这与"TextureCoordinates"有关,但我能找到的唯一合适的例子是处理三角形。可我还是不知道该做什么。
我要编写的应用程序有几百张"平面"的全球地图。上面有各种信息图形。
这是我为页面准备的XAML代码,到目前为止还没有代码。
谢谢
<Page x:Class="GlobeViewer"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:Help3D="clr-namespace:Framework.Help3D"
mc:Ignorable="d"
d:DesignHeight="1080" d:DesignWidth="1920"
Title="GlobeViewer.xaml">
<Grid xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Background="Black">
<Grid.Resources>
<MeshGeometry3D x:Key="Globe" Positions="{Binding Path=Globe.Points, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=Page}}"
TriangleIndices="{Binding Path=Globe.TriangleIndices, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=Page}}"
TextureCoordinates="0,0 512,0 512,256 0,256 "/>
<MaterialGroup x:Key="GlobeTexture">
<DiffuseMaterial >
<DiffuseMaterial.Brush>
<ImageBrush ImageSource="D:_devGlobeViewerAssetsPagesglobeviewerearth.jpg"
ViewportUnits="Absolute"
AlignmentX="Left"
AlignmentY="Top"
/>
<!--<SolidColorBrush Color="Red"/>-->
</DiffuseMaterial.Brush>
</DiffuseMaterial>
<SpecularMaterial Brush="White" SpecularPower="20" />
</MaterialGroup>
</Grid.Resources>
<!--<Image Source="/Assets/Pages/globeviewer/World_3D_Grass.png" />-->
<Viewport3D>
<Viewport3D.Camera>
<PerspectiveCamera x:Name="myCamera" Position="60 40 0"
LookDirection="-50 -33 0"
UpDirection="0,1,0" FieldOfView="90"/>
</Viewport3D.Camera>
<ModelVisual3D>
<ModelVisual3D.Content>
<Model3DGroup>
<AmbientLight Color="White"/>
<DirectionalLight Color="White"
Direction="0 -30 0" />
<GeometryModel3D Geometry="{StaticResource Globe}" Material="{StaticResource GlobeTexture}"/>
</Model3DGroup>
</ModelVisual3D.Content>
</ModelVisual3D>
</Viewport3D>
</Grid>
</Page>
System.Drawing.Image image1 = new Bitmap(Server.MapPath(
""));
Bitmap imgBitmap = new Bitmap(image1);
for (int i = 0; i < imgBitmap.Width; i++)
{
for (int j = 0; j < imgBitmap.Height; j++)
{
// map the angles from image coordinates
double theta = Algebra.MapCoordinate(0.0, imgBitmap.Width - 1,
theta1, theta0, i);
double phi = Algebra.MapCoordinate( 0.0, imgBitmap.Height - 1,phi0,
phi1, j);
// find the cartesian coordinates
double x = radius * Math.Sin(phi) * Math.Cos(theta);
double y = radius * Math.Sin(phi) * Math.Sin(theta);
double z = radius * Math.Cos(phi);
// apply rotation around X and Y axis to reposition the sphere
RotX(1.5, ref y, ref z);
RotY(-2.5, ref x, ref z);
// plot only positive points
if (z > 0)
{
Color color = imgBitmap.GetPixel(i, j);
Brush brs = new SolidBrush(color);
int ix = (int)x + 100;
int iy = (int)y + 100;
graphics.FillRectangle(brs, ix, iy, 1, 1);
brs.Dispose();
}
}
}