In the previous section we implemented movement control of the model. This time we will implement material control of the model. First we find a model. In 3dmax it is as follows:
You can see that this model is complex. Divided into many layers. Let's leave it alone. After importing the SDK, it is as shown below:
It looks better with stickers. . Next, we use code to turn the entire building into a blue science fiction effect, and pull out one of the layers to view it individually using the method in the previous section:
private void Button_Click(object sender, RoutedEventArgs e)
{
GisObjectFor3DSFile va = (GisObjectFor3DSFile)IniRead.IniReadWrite.BiaoManage.BiaoList[0];//从当前场景中找到模型标号
var g1 = va.ModeTree["I:\\3D\\123.3DS"].ChildName[0];
foreach(var key in ((Model3DGroup)((g1.Value))).Children)
{
if (key is Model3DGroup)
ChuLi((Model3DGroup)key);
if (key is System.Windows.Media.Media3D.GeometryModel3D)
{
((GeometryModel3D)key).Material = new DiffuseMaterial(vaBrush);
((GeometryModel3D)key).BackMaterial = new DiffuseMaterial(vaBrush);
}
}
var aa = va.FindNode("D20");//从模型标号中找到二楼
TranslateTransform3D p1 = new TranslateTransform3D();
p1.OffsetX = aa.Value.Transform.Value.OffsetX + aa.Value.Bounds.SizeX;
p1.OffsetY = aa.Value.Transform.Value.OffsetY;
p1.OffsetZ = aa.Value.Transform.Value.OffsetZ;
//利用wpf中自带的移动器把它移出来,这里也可以加上动画
aa.Value.Transform = p1;
}
private ImageBrush vaBrush = new ImageBrush(new BitmapImage(new Uri(@"D:\MTOUCH GIS\res\house\30.png")));
private void ChuLi(System.Windows.Media.Media3D.Model3DGroup va)
{
foreach(var aa in va.Children)
{
if(aa is System.Windows.Media.Media3D.GeometryModel3D)
{
((GeometryModel3D)aa).Material = new DiffuseMaterial(vaBrush);
((GeometryModel3D)aa).BackMaterial= new DiffuseMaterial(vaBrush);
}
if (aa is Model3DGroup)
ChuLi((Model3DGroup)aa);
}
}
最终出来的效果如下图:
By the way, these materials can be replaced with different textures according to the user's own situation, so you can play freely. The SDK provides a basic panel. You can open a separate window to view a certain part of the model, or you can plot it separately as shown below:
————————————————
Copyright statement: This article is an original article by the CSDN blogger "Growing Melons" and follows CC 4.0 BY-SA copyright agreement, please attach the original source link and this statement when reprinting.
Original link: https://blog.csdn.net/xtgmd168/article/details/104695618