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:
- no matter how I try, I only end up with a single flat vertical quad (almost like a billboard) rather than a 3D shape.
- 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
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();
}
}