WW can generate false three-dimensional models in batches based on Dlg diagrams, which is very useful for building models with similar characteristics to the community. Here's how to implement the load of a fake three-dimensional model step-by-step:
1, SHP file production first digitized several buildings under ArcMap, and the new height field stores the height of the building.
2. Code implementation
/** * @ Method Name: Init3dmodel; * @ Method Description: Import simple three-dimensional model; * @ parameter: @param filepath:shp file path * @ return type: void; * @ Creator: Liu Shuo; * @ Created: February 3, 2015 PM 6:10:22; * @throws */private void Init3dmodel (String filePath) {shapefile shapefile = new Shapefile (fil Epath); Renderablelayer layer = new Renderablelayer (), Layer.setname ("simple three-dimensional model"); layer.setpickenabled (true); Try{while ( Shapefile.hasnext ()) {Shapefilerecord record = Shapefile.nextrecord (); Layer.addrenderable (Makeshape (Record));} Wwpanel.getworldwindowglcanvas (). Getmodel (). Getlayers (). Add (layer);} Finally{shapefile.close ();}} /** * @ Method Name: makeshape; * @ Method Description: Create a model from each record of shp file; * @ parameter: @param record * @ parameter: @return * @ return type: extrudedpolygon; * @ Creator: Liu Shuo; * @ creation Time: February 3, 2015 PM 6:11:08; * @throws */private Extrudedpolygon makeshape (Shapefilerecord record) {String image_path = "F : \\data\\wwj\\build123sm.jpg ";D ouble height = null; string[] Heightkeys = new string[]{"height", "height", "height"};for (String key:heightkeys) {Object o = record.getattr Ibutes (). GetValue (key);F (o! = null) {height = double.parsedouble (o.tostring ());}} Top properties Shapeattributes capattrs = new Basicshapeattributes (); capattrs.setoutlinematerial (Material.gray); Capattrs.setinteriormaterial (Material.cyan);//Edge property shapeattributes sideattributes = new Basicshapeattributes (); Sideattributes.setinteriormaterial (Material.light_gray); sideattributes.setoutlinematerial (Material.DARK_GRAY); Sideattributes.setimagesource (image_path);//Create stretched polygon Vecbuffer vb = record.getpointbuffer (0); Polygon pgonairspace = new Polygon (Vb.getlocations ()); Build polygon//texture arraylist<string> textures = new arraylist<string> () based on Dot 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);p olygon.setsideattributes (sideattributes);p Olygon.setaltitudemode ( Worldwind.clamp_to_ground); return polygon;}
The effect is as follows:
3, the problem found that the model can not load the texture Ah, check a few times do not know where the problem, I hope to understand the friends to see the message to the guide under Ah, greatly appreciated.
World Wind Java Development 12-load coarse three-dimensional model (Extrudedpolygon)