I update your addModel()
as below:
private void addModel(Model3DGroup model_group)
{
Model3DGroup globe_model = new Model3DGroup();
model_group.Children.Add(globe_model);
ImageBrush globe_brush = new ImageBrush(new BitmapImage(new Uri("Resource/map.jpg", UriKind.Relative)));
Material globe_material = new DiffuseMaterial(globe_brush);
MeshGeometry3D globe_mesh = null;
MakeSphere(globe_model, ref globe_mesh, globe_material, 1, 0, 0, 0, 20, 30);
}
private void MakeSphere(Model3DGroup model_group, ref MeshGeometry3D sphere_mesh, Material sphere_material,
double radius, double cx, double cy, double cz, int num_phi, int num_theta)
{
if (sphere_mesh == null)
{
sphere_mesh = new MeshGeometry3D();
GeometryModel3D new_model = new GeometryModel3D(sphere_mesh, sphere_material);
model_group.Children.Add(new_model);
}
double dphi = Math.PI / num_phi;
double dtheta = 2 * Math.PI / num_theta;
int pt0 = sphere_mesh.Positions.Count;
double phi1 = Math.PI / 2;
for (int p = 0; p <= num_phi; p++)
{
double r1 = radius * Math.Cos(phi1);
double y1 = radius * Math.Sin(phi1);
double theta = 0;
for (int t = 0; t <= num_theta; t++)
{
sphere_mesh.Positions.Add(new Point3D(
cx + r1 * Math.Cos(theta), cy + y1, cz + -r1 * Math.Sin(theta)));
sphere_mesh.TextureCoordinates.Add(new Point(
(double)t / num_theta, (double)p / num_phi));
theta += dtheta;
}
phi1 -= dphi;
}
int i1, i2, i3, i4;
for (int p = 0; p <= num_phi - 1; p++)
{
i1 = p * (num_theta + 1);
i2 = i1 + (num_theta + 1);
for (int t = 0; t <= num_theta - 1; t++)
{
i3 = i1 + 1;
i4 = i2 + 1;
sphere_mesh.TriangleIndices.Add(pt0 + i1);
sphere_mesh.TriangleIndices.Add(pt0 + i2);
sphere_mesh.TriangleIndices.Add(pt0 + i4);
sphere_mesh.TriangleIndices.Add(pt0 + i1);
sphere_mesh.TriangleIndices.Add(pt0 + i4);
sphere_mesh.TriangleIndices.Add(pt0 + i3);
i1 += 1;
i2 += 1;
}
}
}
The result picture is:
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.