ww可以根据DLG图批量生成假三维模型,这对于小区等特征相似的建筑物模型的构建是非常有用的。下面来看如何一步步实现假三维模型的加载:
/**
*
* @方法名称: init3DModel ;
* @方法描述: 导入简易三维模型 ;
* @参数 :@param filePath :shp文件路径
* @返回类型: void ;
* @创建人:刘硕;
* @创建时间:2015年2月3日 下午6:10:22;
* @throws
*/
private void init3DModel(String filePath)
{
Shapefile shapefile = new Shapefile(filePath);
RenderableLayer layer = new RenderableLayer();
layer.setName("简易三维模型");
layer.setPickEnabled(true);
try
{
while (shapefile.hasNext())
{
ShapefileRecord record = shapefile.nextRecord();
layer.addRenderable(makeShape(record));
}
wwPanel.getWorldWindowGLCanvas().getModel().getLayers()
.add(layer);
}
finally
{
shapefile.close();
}
}
/**
*
* @方法名称: makeShape ;
* @方法描述: 根据shp文件每条记录创建模型 ;
* @参数 :@param record
* @参数 :@return
* @返回类型: ExtrudedPolygon ;
* @创建人:刘硕;
* @创建时间:2015年2月3日 下午6:11:08;
* @throws
*/
private ExtrudedPolygon makeShape(ShapefileRecord record)
{
String IMAGE_PATH = "F:\\data\\wwj\\build123sm.jpg";
Double height = null;
String[] heightKeys = new String[]
{ "height", "Height", "HEIGHT" };
for (String key : heightKeys)
{
Object o = record.getAttributes().getValue(key);
if (o != null)
{
height = Double.parseDouble(o.toString());
}
}
// 顶部属性
ShapeAttributes capAttrs = new BasicShapeAttributes();
capAttrs.setOutlineMaterial(Material.GRAY);
capAttrs.setInteriorMaterial(Material.CYAN);
// 边属性
ShapeAttributes sideAttributes = new BasicShapeAttributes();
sideAttributes.setInteriorMaterial(Material.LIGHT_GRAY);
sideAttributes.setOutlineMaterial(Material.DARK_GRAY);
sideAttributes.setImageSource(IMAGE_PATH);
// 创建拉伸多边形
VecBuffer vb = record.getPointBuffer(0);
Polygon pgonAirspace = new Polygon(vb.getLocations()); // 根据点串构建多边形
//纹理
ArrayList<String> textures = new ArrayList<String>();
for (int i = 0; i < pgonAirspace.getLocations().size(); i++)
{
textures.add(IMAGE_PATH);
}
ExtrudedPolygon polygon = new ExtrudedPolygon(
pgonAirspace.getLocations(), height, textures);
polygon.setCapAttributes(capAttrs);
polygon.setSideAttributes(sideAttributes);
polygon.setAltitudeMode(WorldWind.CLAMP_TO_GROUND);
return polygon;
}World Wind Java开发之十二——加载粗制三维模型(ExtrudedPolygon)
原文:http://blog.csdn.net/giser_whu/article/details/43452703