之前的一篇博客是关于载入粗三维模型的,见http://blog.csdn.net/giser_whu/article/details/43452703,这个地方还存在着不能载入纹理的问题,一直没呢解决。那么WW怎样载入经常使用的三维模型格式(3ds、obj、skp)呢。通过一番搜索,了解到WW能够载入collada的dae格式的三维模型。而且还能够载入kml\kmz文件。那么WW载入三维模型的方法就出来了:首先将其它格式三维模型转换为kmz或kml文件,再载入。这里我是从su的三维模型库中下载的skp文件,在su中能够直接转换为kmz文件,通过測试,这种方法是可行的。先来看下效果图:

1.效果图

第一幅是德国标志性建筑——柏林奥林匹克体育场。能够看到效果还是能够的,只是没有使用lod技术,一旦模型数量增多,会卡顿。
第二幅是也是德国地标性建筑——柏林电视塔。

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvZ2lzZXJfd2h1/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />

第三幅是3D City DB上的德国柏林一些collada三维模型,须要的能够去下载做下測试

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvZ2lzZXJfd2h1/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />

2.实现方法

开头已经明白了WW载入三维模型的路线。WW又提供了载入kml/kmz文件的demo(KMLViewer),所以要实现这个是非常easy的了。仅仅需依据自己的须要修改原demo。整合到自己的project下就可以,这里我修改原demo,编写了SmartScopeKMLViewer,方法參见之前的博客。所用到的数据,整理完上传到CSDN资源,须要的能够去下载。下载地址:http://download.csdn.net/detail/liushuo_whu/8512739

3.源码

/*
Copyright (C) 2001, 2010 United States Government
as represented by the Administrator of the
National Aeronautics and Space Administration.
All Rights Reserved.
*/ package gov.nasa.worldwindx.examples.kml; import gov.nasa.worldwind.WorldWind;
import gov.nasa.worldwind.avlist.AVKey;
import gov.nasa.worldwind.awt.WorldWindowGLCanvas;
import gov.nasa.worldwind.layers.RenderableLayer;
import gov.nasa.worldwind.ogc.kml.KMLAbstractFeature;
import gov.nasa.worldwind.ogc.kml.KMLRoot;
import gov.nasa.worldwind.ogc.kml.impl.KMLController;
import gov.nasa.worldwind.render.Offset;
import gov.nasa.worldwind.retrieve.RetrievalService;
import gov.nasa.worldwind.util.WWIO;
import gov.nasa.worldwind.util.WWUtil;
import gov.nasa.worldwind.util.layertree.KMLLayerTreeNode;
import gov.nasa.worldwind.util.layertree.KMLNetworkLinkTreeNode;
import gov.nasa.worldwind.util.layertree.LayerTree;
import gov.nasa.worldwindx.examples.util.BalloonController;
import gov.nasa.worldwindx.examples.util.HotSpotController; import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.File;
import java.io.IOException;
import java.net.URL; import javax.swing.SwingUtilities;
import javax.xml.stream.XMLStreamException; /**
* 导入KML或KMZ文件,以图层形式查看。KML或KMZ文件的内容显示为一个要素树。在要素树上点击KML要素能够查看该要素
* 。在球上点击要素能够弹出要素的描写叙述信息框
*/
public class SmartScopeKMLViewer
{
public static class KMLUtil
{
protected LayerTree layerTree; // 图层树
protected RenderableLayer hiddenLayer; // 渲染图层(图层树) protected HotSpotController hotSpotController; // 热点controller
protected KMLApplicationController kmlAppController; // KMLcontroller
protected BalloonController balloonController; // BalloonController
protected WorldWindowGLCanvas wwd; // ww public KMLUtil(WorldWindowGLCanvas worldWindowGLCanvas)
{
this.wwd = worldWindowGLCanvas;
// 初始化图层树
this.layerTree = new LayerTree(new Offset(20d, 160d, AVKey.PIXELS,
AVKey.INSET_PIXELS));
// this.layerTree.getModel().refresh(this.wwd.getModel().getLayers()); // 图层树渲染图层
this.hiddenLayer = new RenderableLayer();
this.hiddenLayer.addRenderable(this.layerTree);
this.wwd.getModel().getLayers().add(this.hiddenLayer); // 注冊图层选择和气球热点选择事件监听
this.hotSpotController = new HotSpotController(this.wwd);
// 注冊kml事件监听
this.kmlAppController = new KMLApplicationController(this.wwd); this.balloonController = new BalloonController(this.wwd)
{
@Override
protected void addDocumentLayer(KMLRoot document)
{
addKMLLayer(document);
}
}; // 关联kml管理器和balloon管理器
this.kmlAppController.setBalloonController(balloonController); // Set up to receive SSLHandshakeExceptions that occur during
// resource retrieval.
WorldWind.getRetrievalService().setSSLExceptionListener(
new RetrievalService.SSLExceptionListener()
{
public void onException(Throwable e, String path)
{
System.out.println(path);
System.out.println(e);
}
});
} /**
*
* @方法名称: addKMLLayer 。
* @方法描写叙述: 加入KML图层: 。
* @參数 :@param kmlRoot
* @返回类型: void ;
* @创建人:bluce ;
* @创建时间:2015年3月17日 下午7:54:40。
* @throws
*/
protected void addKMLLayer(KMLRoot kmlRoot)
{
// Create a KMLController to adapt the KMLRoot to the World Wind
KMLController kmlController = new KMLController(kmlRoot); // 加入kml图层
RenderableLayer layer = new RenderableLayer();
layer.setName((String) kmlRoot.getField(AVKey.DISPLAY_NAME));
layer.addRenderable(kmlController);
this.wwd.getModel().getLayers().add(layer); // 加入kml图层树节点
KMLLayerTreeNode layerNode = new KMLLayerTreeNode(layer, kmlRoot);
this.layerTree.getModel().addLayer(layerNode);
this.layerTree.makeVisible(layerNode.getPath());
layerNode.expandOpenContainers(this.layerTree); // Listens to refresh property change events from KML network link
// nodes. Upon receiving such an event this
// expands any tree paths that represent open KML containers. When a
// KML network link refreshes, its tree
// node replaces its children with new nodes created from the
// refreshed content, then sends a refresh
// property change event through the layer tree. By expanding open
// containers after a network link refresh,
// we ensure that the network link tree view appearance is
// consistent with the KML specification.
layerNode.addPropertyChangeListener(
AVKey.RETRIEVAL_STATE_SUCCESSFUL,
new PropertyChangeListener()
{
public void propertyChange(
final PropertyChangeEvent event)
{
if (event.getSource() instanceof KMLNetworkLinkTreeNode)
{
// Manipulate the tree on the EDT.
SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
((KMLNetworkLinkTreeNode) event
.getSource())
.expandOpenContainers(layerTree);
wwd.redraw();
}
});
}
}
});
}
} /**
*
* @项目名称:worldwind-1.5.0
* @类名称:WorkerThread
* @类描写叙述:载入KML文件线程类
* @创建人:bluce 
* @创建时间:2015年3月17日 下午7:58:38
* @改动备注:
* @版本号:
*/
public static class WorkerThread extends Thread
{
/**
* 待载入kml文件,在构造函数中初始化
*/
protected Object kmlSource;
/**
* kmlapp
*/
protected KMLUtil KMLUtil; public WorkerThread(Object kmlSource, KMLUtil KMLUtil)
{
this.kmlSource = kmlSource;
this.KMLUtil = KMLUtil;
} /**
* Loads this worker thread's KML source into a new
* <code>{@link gov.nasa.worldwind.ogc.kml.KMLRoot}</code>, then adds
* the new <code>KMLRoot</code> to this worker thread's
* <code>AppFrame</code>. The <code>KMLRoot</code>'s
* <code>AVKey.DISPLAY_NAME</code> field contains a display name created
* from either the KML source or the KML root feature name.
* <p/>
* If loading the KML source fails, this prints the exception and its
* stack trace to the standard error stream, but otherwise does nothing.
*/
public void run()
{
try
{
KMLRoot kmlRoot = this.parse();
// 设置文档的显示名称
kmlRoot.setField(AVKey.DISPLAY_NAME,
formName(this.kmlSource, kmlRoot)); // 启动一个任务进程载入解析的kml文件
final KMLRoot finalKMLRoot = kmlRoot;
SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
KMLUtil.addKMLLayer(finalKMLRoot);
}
});
}
catch (Exception e)
{
e.printStackTrace();
}
} /**
*
* @方法名称: parse 。
* @方法描写叙述: 解析KML文档 。
* @參数 :@return 返回KMLRoot
* @參数 :@throws IOException:文档不可读
* @參数 :@throws XMLStreamException :文档解析出现错误
* @返回类型: KMLRoot 。
* @创建人:bluce  ;
* @创建时间:2015年3月17日 下午8:02:59;
* @throws
*/
protected KMLRoot parse() throws IOException, XMLStreamException
{
// KMLRoot.createAndParse will attempt to parse the document using a
// namespace aware parser, but if that
// fails due to a parsing error it will try again using a namespace
// unaware parser. Note that this second
// step may require the document to be read from the network again
// if the kmlSource is a stream.
return KMLRoot.createAndParse(this.kmlSource);
}
} protected static String formName(Object kmlSource, KMLRoot kmlRoot)
{
KMLAbstractFeature rootFeature = kmlRoot.getFeature(); if (rootFeature != null && !WWUtil.isEmpty(rootFeature.getName()))
return rootFeature.getName(); if (kmlSource instanceof File)
return ((File) kmlSource).getName(); if (kmlSource instanceof URL)
return ((URL) kmlSource).getPath(); if (kmlSource instanceof String
&& WWIO.makeURL((String) kmlSource) != null)
return WWIO.makeURL((String) kmlSource).getPath(); return "KML Layer";
} }

World Wind Java开发之十五——载入三维模型的更多相关文章

  1. World Wind Java开发之十五——加载三维模型(转)

    之前的一篇博客是关于加载粗三维模型的,见http://blog.csdn.net/giser_whu/article/details/43452703,这个地方还存在着不能加载纹理的问题,一直没呢解决 ...

  2. World Wind Java开发之十四——添加WMS地图服务资源(转)

    数据是GIS的核心,没有数据一切无从谈起,Internet上有很多在线WMS地图服务资源,我们可以好好利用这些数据资源,比如天地图.必应地图.NASA.OGC数据服务等等. 在我们国家常用的还是天地图 ...

  3. World Wind Java开发之十——AnalyticSurface栅格渲染(转)

    http://blog.csdn.net/giser_whu/article/details/43017881 1.AnalyticSurfaceDemo ArcGIS下对栅格的各种分级渲染效果是非常 ...

  4. Java开发学习(十五)----AOP入门案例及其工作流程解析

    一.AOP简介 1.1 什么是AOP AOP(Aspect Oriented Programming)面向切面编程,一种编程范式,指导开发者如何组织程序结构. OOP(Object Oriented ...

  5. World Wind Java开发之十二——加载粗制三维模型(ExtrudedPolygon)(转)

    ww可以根据DLG图批量生成假三维模型,这对于小区等特征相似的建筑物模型的构建是非常有用的.下面来看如何一步步实现假三维模型的加载: 1.Shp文件的制作 首先在arcmap下数字化几个建筑物,并新建 ...

  6. “全栈2019”Java多线程第二十五章:生产者与消费者线程详解

    难度 初级 学习时间 10分钟 适合人群 零基础 开发语言 Java 开发环境 JDK v11 IntelliJ IDEA v2018.3 文章原文链接 "全栈2019"Java多 ...

  7. “全栈2019”Java多线程第十五章:当后台线程遇到finally

    难度 初级 学习时间 10分钟 适合人群 零基础 开发语言 Java 开发环境 JDK v11 IntelliJ IDEA v2018.3 文章原文链接 "全栈2019"Java多 ...

  8. “全栈2019”Java异常第十五章:异常链详解

    难度 初级 学习时间 10分钟 适合人群 零基础 开发语言 Java 开发环境 JDK v11 IntelliJ IDEA v2018.3 文章原文链接 "全栈2019"Java异 ...

  9. “全栈2019”Java第八十五章:实现接口中的嵌套接口

    难度 初级 学习时间 10分钟 适合人群 零基础 开发语言 Java 开发环境 JDK v11 IntelliJ IDEA v2018.3 文章原文链接 "全栈2019"Java第 ...

随机推荐

  1. 部署hibernate框架项目时出现问题:The type java.lang.Object cannot be resolved. It is indirectly referenced from required .class files.

    基本情况: (这些其实关系不大)我是直接impor导入HibernateDemo项目到eclipse中的,该项目的hibernate版本是3.6.7.Final版,使用了Hibernate Tools ...

  2. MenuButton( 菜单按钮)

    一. 加载方式//class 加载方式<a href="javascript:void(0)" id="edit" class="easyui- ...

  3. SuperSocket快速入门(二):启动程序以及相关的配置

    如何快速启动第一个程序 既然是快速入门,所以,对于太深奥的知识点将不做讲解,会在后续的高级应用章节中,会对SS进行拆解.所有的实例90%都是来自SS的实例,外加本人的注释进行讲解. 一般应用而言,你只 ...

  4. C#socket通讯两个最经典错误解决方案

    1.经典错误之 无法访问已释放的对象. 对象名:“System.Net.Sockets.Socket”     (1).问题现场   (2).问题叙述 程序中的某个地方调用到了socket.close ...

  5. H3 BPM 笔记

    先通过流程设计器设计流程 注意  审批:1个人 会签: 多人用 同意时: 若为有一个同意就通过 则 审批选项卡 的同意出口 设为1 如果需要所有人同意才通过 则  审批选项卡 的同意出口 设为100% ...

  6. RecycleView 瀑布流滑动移位

    RecycleView StaggeredLayoutManager(瀑布流)滑动的时候,默认会出现item移动的问题,需以下来个步骤来解决: 附上StaggeredLayoutManager中的一段 ...

  7. 织梦 {dede:list}列表按多种排序显示

    orderby='sortrank' 文档排序方式 orderby='hot' 或 orderby='click' 表示按点击数排列 orderby='sortrank' 或 orderby='pub ...

  8. poj3685 二分套二分

    F - 二分二分 Crawling in process... Crawling failed Time Limit:6000MS     Memory Limit:65536KB     64bit ...

  9. C#使用itextsharp生成PDF文件

    项目需求需要生成一个PDF文档,使用的是VS2010,ASP.NET. 网络上多次搜索没有自己想要的,于是硬着头皮到itextpdf官网看英文文档,按时完成任务,以实用为主,共享一下: 使用HTML文 ...

  10. 分享8款精美的jQuery图片播放插件

    本文将和大家一起分享8款精美的jQuery图片播放插件,每一款插件均有演示和源码下载,有兴趣的朋友可以下载使用和研究.废话不多说了,直接上这些插件. 1.3D轮播相册 这款3D相册插件利用了HTML5 ...