Creating walls with the LinearExtrusion class

The LinearExtrusion class is used to create solid rectangular 3D objects from a profile made up of one or more straight lines. This is useful for creating walls where a number of lines are used to define the "floor plan" of a structure. In the following LinearExtrusionDemo application, we will use the LinearExtrusion class to build a 3D object that could represent the walls in an L-shaped house.

package
{
  import away3d.extrusions.LinearExtrusion;
  import flash.events.Event;
  import flash.geom.Vector3D;

  public class LinearExtrusionDemo extends Away3DTemplate
  {
    protected var walls:LinearExtrusion;

    public function LinearExtrusionDemo() 
    {
      super();
    }

    protected override function initScene():void 
    {
      super.initScene();

      camera.position = new Vector3D(1000, 750, 1000);
      camera.lookAt(new Vector3D(0, 0, 0));

The wallPoints array is a collection of points that define a number of connected lines. These lines define the base outline of the walls that will make up our 3D object. The end point of the last line is used as the starting point of the next line. The points used in the following code define a profile that looks like the following image:

Creating walls with the LinearExtrusion class
      var wallPoints:Array = 	
        [ 
          new Vector3D( -250, 0, -250), 
          new Vector3D( 0, 0, -250), 
          new Vector3D(0, 0, 0), 
          new Vector3D(250, 0, 0), 
          new Vector3D(250, 0, 250),
          new Vector3D(-250, 0, 250),
          new Vector3D( -250, 0, -250)

        ];

Here we create a new LinearExtrusion object. The offset init object parameter defines the height of the walls, while the thickness parameter defines their width. The recenter parameter is used to ensure that the origin of the resulting 3D object is at its center.

      walls = new LinearExtrusion(
        wallPoints, 
        { 
          thickness:10,
          offset: 150,
          recenter:true
        }
      );

      scene.addChild(walls);
    }
  }

}

The following screenshot shows the output of this application:

Creating walls with the LinearExtrusion class
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.119.123.160