[转]在WorldWind中加入*.x格式的三维模型

 Nasa支持的WorldWind项目最近推出了1.4RC5版,可以加入三维模型,效果如下图所示:

[转]在WorldWind中加入*.x格式的三维模型


    WW1.4对XML配置文件增加了许多新的元素,其中ModelFeature就是用来增加三维模型的,如下所示:

<?xml version="1.0" encoding="utf-8"?>
<LayerSet Name="Clart Test" ShowOnlyOneLayer="false" ShowAtStartup="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="LayerSet.xsd">
  <ModelFeature ShowAtStartup="true">
    <Name>Tiny1</Name>
    <DistanceAboveSurface>160.0</DistanceAboveSurface>
    <Latitude>
      <Value>39.93</Value>
    </Latitude>
    <Longitude>
      <Value>116.400002</Value>
    </Longitude>
    <ScaleFactor>2</ScaleFactor>
    <MeshFilePath>Data\Model\tiny.x</MeshFilePath>
    <Orientation>
      <RotationX>0.0</RotationX>
      <RotationY>90.0</RotationY>
      <RotationZ>90.0</RotationZ>
    </Orientation>
    <MaxViewRange>10000.0</MaxViewRange>
    <MinViewRange>10</MinViewRange>
  </ModelFeature>

  <ModelFeature ShowAtStartup="true">
    <Name>Tiny2</Name>
    <DistanceAboveSurface>160.0</DistanceAboveSurface>
    <Latitude>
      <Value>39.93</Value>
    </Latitude>
    <Longitude>
      <Value>116.410002</Value>
    </Longitude>
    <ScaleFactor>2</ScaleFactor>
    <MeshFilePath>Data\Model\tiny.x</MeshFilePath>
    <Orientation>
      <RotationX>0.0</RotationX>
      <RotationY>-90.0</RotationY>
      <RotationZ>90.0</RotationZ>
    </Orientation>
    <MaxViewRange>10000.0</MaxViewRange>
    <MinViewRange>10</MinViewRange>
  </ModelFeature>
</LayerSet>

 本来在LayerSet.xsd中应该对其进行描术,不过我下载的最新版本中该文件还没有更新,所以在VS2005里对这个XML文件进行编辑时会提示找不到ModelFeature这个元素,不用管它,打开源代码在WorldWind项目里的ConfigurationLoader单元,找到getRenderableFromLayerFile函数,有这样一段代码:

addImageLayersFromXPathNodeIterator(iter.Current.Select("ImageLayer"), parentWorld, parentRenderable);
addQuadTileLayersFromXPathNodeIterator(iter.Current.Select("QuadTileSet"), parentWorld, parentRenderable, cache);
addPathList(iter.Current.Select("PathList"), parentWorld, parentRenderable);
addPolygonFeature(iter.Current.Select("PolygonFeature"), parentWorld, parentRenderable);
addLineFeature(iter.Current.Select("LineFeature"), parentWorld, parentRenderable);
addModelFeature(iter.Current.Select("ModelFeature"), parentWorld, parentRenderable);
addWater(iter.Current.Select("Water"), parentWorld, parentRenderable);
addTiledPlacenameSet(iter.Current.Select("TiledPlacenameSet"), parentWorld, parentRenderable);
addTiledWFSPlacenameSet(iter.Current.Select("TiledWFSPlacenameSet"), parentWorld, parentRenderable);
addIcon(iter.Current.Select("Icon"), parentWorld, parentRenderable, cache);
addScreenOverlays(iter.Current.Select("ScreenOverlay"), parentWorld, parentRenderable, cache);
addChildLayerSet(iter.Current.Select("ChildLayerSet"), parentWorld, parentRenderable, cache);

addExtendedInformation(iter.Current.Select("ExtendedInformation"), parentRenderable);

从这可以看出,源程序已经对ModelFeature提供了支持,而在addModelFeature函数中可以找到所有ModelFeature 的子元素,如“Name”、“Latitude”“Longitude”等。

private static void addModelFeature(XPathNodeIterator iter, World parentWorld, RenderableObjectList parentRenderable)
{
    if (iter.Count > 0)
    {
        while (iter.MoveNext())
        {
            string name = getInnerTextFromFirstChild(iter.Current.Select("Name"));
            string refreshurl = getInnerTextFromFirstChild(iter.Current.Select("RefreshURL"));
            float lat = Convert.ToSingle(getInnerTextFromFirstChild(iter.Current.Select("Latitude")));
            float lon = Convert.ToSingle(getInnerTextFromFirstChild(iter.Current.Select("Longitude")));
            float alt = Convert.ToSingle(getInnerTextFromFirstChild(iter.Current.Select("DistanceAboveSurface")));
            float scaleFactor = Convert.ToSingle(getInnerTextFromFirstChild(iter.Current.Select("ScaleFactor")));
            string meshFilePath = getInnerTextFromFirstChild(iter.Current.Select("MeshFilePath"));

            float rotX = Convert.ToSingle(getInnerTextFromFirstChild(iter.Current.SelectSingleNode("Orientation")
                .Select("RotationX")));
            float rotY = Convert.ToSingle(getInnerTextFromFirstChild(iter.Current.SelectSingleNode("Orientation")
                .Select("RotationY")));
            float rotZ = Convert.ToSingle(getInnerTextFromFirstChild(iter.Current.SelectSingleNode("Orientation")
                .Select("RotationZ")));

            ModelFeature model = new ModelFeature(name, parentWorld
                , meshFilePath, lat, lon, alt,scaleFactor,rotX,rotY,rotZ);
            model.RefreshURL = refreshurl;
            parentRenderable.Add(model);
        }
    }
}

 根据这些,我们只要生成一个XML文件放到相应模型(如Earth)的配置文件目录,就可以显示自己的三维模型啦! [转]在WorldWind中加入*.x格式的三维模型

    我做了一个例子,下载后,解压到WorldWind1.4的安装目录(如:D:\Program Files\NASA\World Wind 1.4 ),重新启动程序在图层管理里可以看到一个新的层,如下图所示:

[转]在WorldWind中加入*.x格式的三维模型


    再用菜单Edit->Place Finder跳转到相应的坐标就可以看到自己的模型了,如下图所示:

[转]在WorldWind中加入*.x格式的三维模型



例子下载地址:http://www.cnblogs.com/Files/reonlyrun/ClarkTest.rar

 

原文链接:在WorldWind中加入三维模型

[转]在WorldWind中加入*.x格式的三维模型

上一篇:在 Win7、Win10 家庭版中启用组策略(gpedit.msc)


下一篇:tp递归查找上下级