World Wind Java开发之十五——加载三维模型(转)
之前的一篇博客是关于加载粗三维模型的,见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.效果图



2.实现方法
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开发之十五——加载三维模型(转)的更多相关文章
- World Wind Java开发之十二——加载粗制三维模型(ExtrudedPolygon)(转)
ww可以根据DLG图批量生成假三维模型,这对于小区等特征相似的建筑物模型的构建是非常有用的.下面来看如何一步步实现假三维模型的加载: 1.Shp文件的制作 首先在arcmap下数字化几个建筑物,并新建 ...
- World Wind Java开发之十五——载入三维模型
之前的一篇博客是关于载入粗三维模型的,见http://blog.csdn.net/giser_whu/article/details/43452703,这个地方还存在着不能载入纹理的问题,一直没呢解决 ...
- World Wind Java开发之十四——添加WMS地图服务资源(转)
数据是GIS的核心,没有数据一切无从谈起,Internet上有很多在线WMS地图服务资源,我们可以好好利用这些数据资源,比如天地图.必应地图.NASA.OGC数据服务等等. 在我们国家常用的还是天地图 ...
- Java开发学习(十五)----AOP入门案例及其工作流程解析
一.AOP简介 1.1 什么是AOP AOP(Aspect Oriented Programming)面向切面编程,一种编程范式,指导开发者如何组织程序结构. OOP(Object Oriented ...
- World Wind Java开发之十——AnalyticSurface栅格渲染(转)
http://blog.csdn.net/giser_whu/article/details/43017881 1.AnalyticSurfaceDemo ArcGIS下对栅格的各种分级渲染效果是非常 ...
- Java进阶(二十五)Java连接mysql数据库(底层实现)
Java进阶(二十五)Java连接mysql数据库(底层实现) 前言 很长时间没有系统的使用java做项目了.现在需要使用java完成一个实验,其中涉及到java连接数据库.让自己来写,记忆中已无从搜 ...
- 马凯军201771010116《面向对象与程序设计Java》第十五周学习知识总结
实验十五 GUI编程练习与应用程序部署 一.知识学习部分 清单文件 每个JAR文件中包含一个用于描述归档特征的清单文件(manifest).清单文件被命名为MANIFEST.MF,它位于JAR文件的 ...
- “全栈2019”Java多线程第二十五章:生产者与消费者线程详解
难度 初级 学习时间 10分钟 适合人群 零基础 开发语言 Java 开发环境 JDK v11 IntelliJ IDEA v2018.3 文章原文链接 "全栈2019"Java多 ...
- “全栈2019”Java多线程第十五章:当后台线程遇到finally
难度 初级 学习时间 10分钟 适合人群 零基础 开发语言 Java 开发环境 JDK v11 IntelliJ IDEA v2018.3 文章原文链接 "全栈2019"Java多 ...
随机推荐
- express+vue-cli实现前后端分离交互小例
准备工作 1.Express 应用生成器 npm install express-generator -g 2.vue-cli手脚架 npm install -g vue-cli 3.项目结构 . ├ ...
- SQL中合并多行记录的方法总汇
-- =============================================================================-- Title: 在SQL中分类合并数 ...
- web综合案例01
web综合案例01 ... .... 内容待添加
- day23作业详解
1.题目 2.题目详解 点击查看详细内容 1. 1-1 封装 把功能封装到类中 class Message(object): def email(self):pass def msg(self):pa ...
- Angular学习笔记【如何正确使用第三方组件】
例如:ng-bootstrap的使用: 1.首先肯定是先要安装,参考官网给出的指令安装即可.(npm install --save @ng-bootstrap/ng-bootstrap) 2.在App ...
- Luogu P2973 [USACO10HOL]赶小猪Driving Out the Piggi 后效性DP
有后效性的DP:$f[u]$表示到$u$的期望次数,$f[u]=\Sigma_{(u,v)} (1-\frac{p}{q})*f[v]*deg[v]$,最后答案就是$f[u]*p/q$ 刚开始$f[1 ...
- Linux重新挂载磁盘
Linux下磁盘和目录的概念与WIN不同:比如,分了一个系统分区默认挂载了根(/)目录,根下还有其它目录,比如/user /lib等.如果系统分区不够用,可以再分出分支,把根下其它目录分别挂载出来,例 ...
- ACdream 1236 Burning Bridges 割边 + 去重边
题目就是求一副图的割边,然后对于那些有重复的边的,不能算做割边. 思路就是每次加入一条边的时候,判断这条边是否存在过,存在过的话,就把那条边设为inf,表示不能作为割边.于是有了这样的代码 #incl ...
- Spark编程模型(下)
创建Pair RDD 什么是Pair RDD 包含键值对类型的RDD类型被称作Pair RDD: Pair RDD通常用来进行聚合计算: Pair RDD通常由普通RDD做ETL转化而来. Pytho ...
- js执行上下文和执行栈
执行上下文就是JavaScript 在被解析和运行时环境的抽象概念,JavaScript 运行任何代码都是在执行上下文环境中运行的,执行上下文包括三个周期:创建——运行——销毁,重点说一下创建环节. ...