Using Extrusion

Hi all



I'm trying to use the Extrusion class to create a simple building model from a 2D outline.



It should be easy but I can't get it to work after several hours of fiddling.



There seems to be two issues:

  1. no matter how I try, I only end up with a single flat vertical quad (almost like a billboard) rather than a 3D shape.
  2. the rendering of said shape gives very wierd results (which I expect is related to the normals, see below).



    In the following code I've defined a simple square in the XZ plane, and then extruded that in the Y (up) direction.  I can't see how it could be easier :wink:



    Couple of things to note:



    I'm not sure what the normals are for that are supplied to the Extrusion class or how they are used - maybe this is part of the problem?  What are the normals of a line?



    The line mode is set to LOOP but I suspect this has nothing to do with it since the Extrusion code never references Line.getMode() as far as I can tell, and changing the line mode doesn't actually appear to do anything anyway.



    Any ideas anyone?



    Thanks in advance for any suggestions/pointers.


  • chris




import com.jme.app.SimpleGame;
import com.jme.math.Vector3f;
import com.jme.scene.Line;
import com.jme.scene.Spatial;
import com.jme.scene.shape.Extrusion;

import java.awt.geom.Point2D;
import java.util.ArrayList;
import java.util.List;

/**
 * @author csargent
 */
public class ExtrusionDemo extends SimpleGame
{
   private static Spatial createBuildingNode() {
      // Convert building model to polygon
      final Point2D.Float[] pts = new Point2D.Float[] {
         new Point2D.Float( 0, 0 ),
         new Point2D.Float( 10, 0 ),
         new Point2D.Float( 10, 10 ),
         new Point2D.Float( 0, 10 ),
      };

      final Vector3f[] vertices = new Vector3f[ pts.length ];
      for( int n = 0; n < pts.length; ++n ) {
         vertices[ n ] = new Vector3f();
         vertices[ n ].x = pts[ n ].x;
         vertices[ n ].y = 0;
         vertices[ n ].z = pts[n].y;
      }
      final Vector3f[] normals = new Vector3f[ pts.length ];
      for( int n = 0; n < pts.length; ++n ) {
         normals[ n ] = new Vector3f( 0, 1, 0 );
      }
      final Line shape = new Line( null, vertices, normals, null, null );
      shape.setMode( Line.Mode.Loop );

      // Define extrusion path as the height of the building
      final List< Vector3f > path = new ArrayList< Vector3f >();
      path.add( new Vector3f( 0, 0, 0 ) );
      path.add( new Vector3f( 0, 10, 0 ));

      // Extrude building
      final Extrusion ext = new Extrusion( "HMM_BuildingModel" );
      ext.updateGeometry( shape, path, true, Vector3f.UNIT_Y );
      return ext;
   }

   @Override
   protected void simpleInitGame() {
      rootNode.attachChild( createBuildingNode() );
      rootNode.updateRenderState();
        rootNode.updateGeometricState(0,true);
   }

   public static void main( String[] args ) {
      final ExtrusionDemo demo = new ExtrusionDemo();
      demo.start();
   }
}


Alternatively, can anyone point me at any example code that uses Extrusion, I can't find any test code within JME itself.

@Core-Dump thanks for the examples.



Unfortunately they only seem to use shapes defined by Line.appendCircle(), trying an arbitrary shape seems to screw it up (or rather I'm not sure how that shape should be defined).  A simple triangle results in an exception!



In any case the Extrusion class does not 'cap off' the ends of the extrusion, i.e. If I wanted a completely 3D shape extruded from an arbitrary 2D polygon, I would still need to tesselate the ends.



As it happens our requirements are a little more simple - I need to extrude an arbitrary building outline (i.e. a polygon) in the Y direction to a specified height.  For example, a square 2D shape should result in a cube.  This is a more degenerate problem than the Extrusion class is defined for.



I've written the (fairly trivial) code that extrudes the building outline upwards and generate quad/tris for the sides, but I'm still stuck with the top & bottom - does JME provide any tesselating/triangulating code that will generate triangles given some arbitrary polygon?  Should I use the GLU helper function?



Again, thanks for any pointers.


  • chris

there is a com.jmex.font3d.math.Triangulator which is used in Glyph3D



But i dont know much about that stuff  :confused:

I hope someone else can give you some hints.