World Wind Java Development 15-load three-dimensional model

Source: Internet
Author: User
Tags event listener stack trace

A previous blog is about loading coarse three-dimensional model, see http://blog.csdn.net/giser_whu/article/details/43452703, this place still has the problem that can not load the texture, has not solved. So WW how to load the common three-dimensional model format (3DS, obj, SKP), through a search, understand that WW can load the Collada Dae format of the three-dimensional model, and can also load the Kml\kmz file, Then WW load three-dimensional model of the method is out: First, the other format three-dimensional model converted to KMZ or KML file, and then loaded. Here I was downloaded from Su's three-dimensional model library of SKP files, in the SU can be converted directly to KMZ file, pass the test, this method is feasible. First look at the following:

1.The first is the German iconic building, the Berlin Olympic Stadium, which can be seen to be effective, but without the use of LOD technology, once the number of models increases, it will be Leighton.

The second one is also the German landmark-the Berlin TV Tower.

The third is a collada three-dimensional model of Berlin, Germany, on 3D City DB, which you need to download and test.
2. Implementation method at the beginning of the WW loaded three-dimensional model of the route, WW also provides the load Kml/kmz file demo (kmlviewer), so to achieve this is very simple, just according to their needs to change the original demo, integrated into their own projects can be, Here I changed the original demo, wrote the Smartscopekmlviewer, the method see previous blog. The data used, after finishing upload to CSDN resources, you need to download. : http://download.csdn.net/detail/liushuo_whu/85127393. Source code
/*copyright (C) 2001, states Governmentas represented by the Administrator of Thenational Aeronautics and Spac e 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;/** * Importing KML or KMZ files, Viewed as a layer, the contents of a KML or KMZ file are displayed as a feature tree. Click on a KML feature on the feature tree to view the feature *, click on the feature on the ball to pop up the feature's description box */public class Smartscopekmlviewer{public static class kmlutil{protected Layertree Layertree; Layer tree protected Renderablelayer hiddenlayer; Render layer (layer tree) protected Hotspotcontroller hotspotcontroller; Hot controllerprotected Kmlapplicationcontroller Kmlappcontroller; kmlcontrollerprotected Ballooncontroller Ballooncontroller; ballooncontrollerprotected Worldwindowglcanvas WWD; Wwpublic Kmlutil (Worldwindowglcanvas worldwindowglcanvas) {THIS.WWD = worldwindowglcanvas;//initialize the layer tree This.layertree = New Layertree (New Offset (20d, 160d, avkey.pixels,avkey.inset_pixels));//This.layerTree.getModel (). Refresh ( This.wwd.getModel (). Getlayers ());//layer tree render layer This.hiddenlayer = new Renderablelayer (); this.hiddenlAyer.addrenderable (This.layertree); This.wwd.getModel (). Getlayers (). Add (This.hiddenlayer);// Register layer selection and balloon Hotspot selection Event listener This.hotspotcontroller = new Hotspotcontroller (THIS.WWD);//Register KML event Listener This.kmlappcontroller = new Kmlapplicationcontroller (THIS.WWD); this.ballooncontroller = new Ballooncontroller (THIS.WWD) {@Overrideprotected void Adddocumentlayer (Kmlroot document) {Addkmllayer (document);}};/ /associated KML manager and Balloon Manager 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);}}); /** * @ Method Name: Addkmllayer; * @ Method Description: Add KML layer:; * @ parameter: @param kmlroot * @ return type: void; * @ Creator: Liu Shuo; * @ creation Time: March 17, 2015 PM 7:54:40; * @throws */protected void Addkmllayer (Kmlroot kmlroot) {//Create a kmlcontroller to adapt T He kmlroot to the world WinDkmlcontroller Kmlcontroller = new Kmlcontroller (kmlroot);//Add KML layer renderablelayer layer = new Renderablelayer (); Layer.setname (String) Kmlroot.getfield (avkey.display_name)); layer.addrenderable (Kmlcontroller); This.wwd.getModel (). Getlayers (). Add (layer),//Adds a KML layer tree node Kmllayertreenode layernode = new Kmllayertreenode (layer, Kmlroot); This.layerTree.getModel (). AddLayer (Layernode); This.layerTree.makeVisible (Layernode.getpath ()); Layernode.expandopencontainers (This.layertree);//listens to refresh the events from KML network link//nodes . Upon receiving such an event this//expands any tree paths that represent open KML containers. When the a//KML network link refreshes, its tree//node replaces it children with the new nodes created from the//refreshed con Tent, 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//C Onsistent 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 ();}});}}) /** * @ Project Name: worldwind-1.5.0 * @ class Name: Workerthread * @ class Description: Load KML file Thread class * @ Creator: Liu Shuo * @ created: March 17, 2015 7:58:38 * @ Edit NOTE: * @ version : */public static Class Workerthread extends thread{/** * Ready to load KML file, initializing */protected Object in constructor kmlsource;/** * Kmlapp */p rotected 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}&LT;/CODE&G t;, then adds * The new <code>KMLRoot</code> to this worker thread ' s * &LT;CODE&GT 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 their * stack trace to the standard error stre AM, but otherwise does nothing. */public void Run () {Try{kmlroot kmlroot = This.parse ();//sets the display name of the document Kmlroot.setfield (Avkey.display_name,formname ( This.kmlsource, Kmlroot));//Start a task process to load the resolved KML file final kmlroot finalkmlroot = kmlroot; Swingutilities.invokelater (New Runnable () {public void run () {kmlutil.addkmllayer (finalkmlroot);}}); catch (Exception e) {e.printstacktrace ();}} /** * @ Method Name: Parse; * @ Method Description: Parse KML document; * @ parameter: @return return kmlroot * @ parameter: @throws ioexception: Document unreadable * @ parameter: @throws xmlstr Eamexception: Document Parsing Error * @ return type: kmlroot; * Creator: Liu Shuo; * @ creation Time: March 17, 2015 PM 8:02:59; * @throws */protected Kmlroot Parse () throws IOException, xmlstreamexception{//Kmlroot.cre AteanDparse would attempt to parse the document using a//namespace aware parser, but if that//fails due to a parsing error it Would try again using a namespace//unaware parser. Note that this second//step could require the document to being read from the network again//if the Kmlsource is a Stream.ret Urn 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 Development 15-load three-dimensional model

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.