Announcement

Collapse
No announcement yet.

3D Shapes and Airspaces

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • 3D Shapes and Airspaces

    Is there any roadmap for bringing in 3D shapes and Airspaces into Web Worldwind to match what exists in the WWJ implementation? Or is there an example of how I can create my own?


  • #2
    Here is how I did it for our app. Hope it helps.

    /*
    * This function builds a 3D polygon by echoing the polygon passed in at two altitudes and also builds the polygons to connect all the side edges.
    * Its not as cool as a true curved airspace, like we had in World Wind Java, but it works.
    * This function returns you a list of polygons (top, bottom, and edge polygons) that build your 3D polygon.
    * The returned list of polygons will need to be given shape attributes and added to your layer in order to show up.
    * This function is limited to 3D polygons where all its sides are vertical and the bottom polygon matches the top exactly.
    * Polygons where the bottom and top do not match or where you want skewed side edges is not possible with this code
    * as is unless you add some modifications for it to be able to do that.
    *
    * Parameters:
    * upperPolygon = The WorldWind.Polygon that defines the upper polygon.
    * lowerAlt = The altitude for the bottom of the 3D polygon that it will build from your top one.
    */
    var Build3DPolygon = function(upperPolygon, lowerAlt)
    {

    //Upper Polygon
    var polyList = [];
    polyList.push(upperPolygon); //Adds the upper polygon

    //Lower Polygon
    var lowerPolyPositions = [];
    for (var i=0; i<upperPolygon.boundaries.length; i++) //Loop through the upperPolygon's positions (so we can mirror them at a differnt alt for the lower polygon)
    {
    lowerPolyPositions.push(new WorldWind.Position(upperPolygon.boundari es[i].latitude, upperPolygon.boundaries[i].longitude, lowerAlt));
    }
    var lowerPolygon = new WorldWind.Polygon(lowerPolyPositions);
    polyList.push(lowerPolygon); //Adds the lower polygon

    //Side Polygons
    var sidePolyPositions = [];

    for (var i=0; i<upperPolygon.boundaries.length-1; i++) //Loop through the upperPolygon's positions so we can build all of our side polygons that will be needed to join the top polygon with the lower polygon.
    {
    sidePolyPositions = []; //Will hold our array of side poly positions

    //current position upper
    sidePolyPositions.push(new WorldWind.Position( upperPolygon.boundaries[i].latitude, upperPolygon.boundaries[i].longitude, upperPolygon.boundaries[i].altitude)); //Adds the previous upper position to our array of positions for our side polygon.

    //Next position upper
    sidePolyPositions.push(new WorldWind.Position( upperPolygon.boundaries[i+1].latitude, upperPolygon.boundaries[i+1].longitude, upperPolygon.boundaries[i+1].altitude)); //Adds the current upper position to our array of positions for our side polygon.

    //Next position lower
    sidePolyPositions.push(new WorldWind.Position( lowerPolygon.boundaries[i+1].latitude, lowerPolygon.boundaries[i+1].longitude, lowerPolygon.boundaries[i+1].altitude)); //Adds the current lower position to our array of positions for our side polygon.

    //Current position lower
    sidePolyPositions.push(new WorldWind.Position( lowerPolygon.boundaries[i].latitude, lowerPolygon.boundaries[i].longitude, lowerPolygon.boundaries[i].altitude)); //Adds the previous lower position to our array of positions for our side polygon.

    var sidePoly = new WorldWind.Polygon(sidePolyPositions); //Builds a new side polygon from the side poly positions listed above.

    polyList.push(sidePoly);
    }

    //Final Side Polygon Segment - Manually add the final Side Polygon (since a polygon's positions do not specifically define the implied section from the last position back to the first that actually closes the polygon.) So, to build that side panel we just add it manually here.)

    sidePolyPositions = [];

    //First position upper
    sidePolyPositions.push(new WorldWind.Position( upperPolygon.boundaries[0].latitude, upperPolygon.boundaries[0].longitude, upperPolygon.boundaries[0].altitude));

    //Last position upper
    sidePolyPositions.push(new WorldWind.Position( upperPolygon.boundaries[upperPolygon.boundaries.length-1].latitude, upperPolygon.boundaries[upperPolygon.boundaries.length-1].longitude, upperPolygon.boundaries[upperPolygon.boundaries.length-1].altitude));

    //Last position lower
    sidePolyPositions.push(new WorldWind.Position( lowerPolygon.boundaries[upperPolygon.boundaries.length-1].latitude, lowerPolygon.boundaries[upperPolygon.boundaries.length-1].longitude, lowerPolygon.boundaries[upperPolygon.boundaries.length-1].altitude));

    //First position lower
    sidePolyPositions.push(new WorldWind.Position( lowerPolygon.boundaries[0].latitude, lowerPolygon.boundaries[0].longitude, lowerPolygon.boundaries[0].altitude));

    var sidePoly = new WorldWind.Polygon(sidePolyPositions); //Builds the final side polygon (from the positions we defined above)

    polyList.push(sidePoly); //Adds the final side polygon to the list of polygons.


    //And finally, return all the polygons (upper, lower, and all side polygons)
    return polyList; //Returns all the polygons (upper, lower, and all sides)

    }//End of the Build3DPolygon function
    Last edited by price5583; 08-03-2017, 04:15 PM.

    Comment


    • #3
      Then to call the Build3DPolygon function would look something like this:

      var polygon = new WorldWind.Polygon(positions);

      var polyList = Build3DPolygon(polygon, 0);

      for (var j=0; j<polyList.length; j++)
      {
      polyList[j].attributes = myAttributes;
      polyList[j].highlightAttributes = myHLAttributes;
      polyList[j].altitudeMode = WorldWind.ABSOLUTE; //Or CLAMP_TO_GROUND or RELATIVE_TO_GROUND

      layer.addRenderable(polyList[j]);
      }


      //Where layer is your WorldWind.RenderableLayer and myAttributes and myHLAttributes are your WorldWind.ShapeAttributes.

      Comment


      • #4
        Thank you! I'll take a look and try it out.

        Comment

        Working...
        X