/** Convenience method to create a model with a single node containing a rectangle shape. The resources the Material might * contain are not managed, use {@link Model#manageDisposable(Disposable)} to add those to the model. * @param attributes bitwise mask of the {@link com.badlogic.gdx.graphics.VertexAttributes.Usage}, only Position, Color, Normal * and TextureCoordinates is supported. */ public Model createRect (float x00, float y00, float z00, float x10, float y10, float z10, float x11, float y11, float z11, float x01, float y01, float z01, float normalX, float normalY, float normalZ, int primitiveType, final Material material, final long attributes) { begin(); part("rect", primitiveType, attributes, material).rect(x00, y00, z00, x10, y10, z10, x11, y11, z11, x01, y01, z01, normalX, normalY, normalZ); return end(); }
/** Convenience method to create a model with a single node containing a cone shape. The resources the Material might contain * are not managed, use {@link Model#manageDisposable(Disposable)} to add those to the model. * @param attributes bitwise mask of the {@link com.badlogic.gdx.graphics.VertexAttributes.Usage}, only Position, Color, Normal * and TextureCoordinates is supported. */ public Model createCone (float width, float height, float depth, int divisions, int primitiveType, final Material material, final long attributes, float angleFrom, float angleTo) { begin(); part("cone", primitiveType, attributes, material).cone(width, height, depth, divisions, angleFrom, angleTo); return end(); }
/** Convenience method to create a model with a single node containing a sphere shape. The resources the Material might contain * are not managed, use {@link Model#manageDisposable(Disposable)} to add those to the model. * @param attributes bitwise mask of the {@link com.badlogic.gdx.graphics.VertexAttributes.Usage}, only Position, Color, Normal * and TextureCoordinates is supported. */ public Model createSphere (float width, float height, float depth, int divisionsU, int divisionsV, int primitiveType, final Material material, final long attributes, float angleUFrom, float angleUTo, float angleVFrom, float angleVTo) { begin(); part("cylinder", primitiveType, attributes, material).sphere(width, height, depth, divisionsU, divisionsV, angleUFrom, angleUTo, angleVFrom, angleVTo); return end(); }
/** Convenience method to create a model with a single node containing a capsule shape. The resources the Material might contain * are not managed, use {@link Model#manageDisposable(Disposable)} to add those to the model. * @param attributes bitwise mask of the {@link com.badlogic.gdx.graphics.VertexAttributes.Usage}, only Position, Color, Normal * and TextureCoordinates is supported. */ public Model createCapsule (float radius, float height, int divisions, int primitiveType, final Material material, final long attributes) { begin(); part("capsule", primitiveType, attributes, material).capsule(radius, height, divisions); return end(); }
/** Convenience method to create a model with a single node containing a cylinder shape. The resources the Material might * contain are not managed, use {@link Model#manageDisposable(Disposable)} to add those to the model. * @param attributes bitwise mask of the {@link com.badlogic.gdx.graphics.VertexAttributes.Usage}, only Position, Color, Normal * and TextureCoordinates is supported. */ public Model createCylinder (float width, float height, float depth, int divisions, int primitiveType, final Material material, final long attributes, float angleFrom, float angleTo) { begin(); part("cylinder", primitiveType, attributes, material).cylinder(width, height, depth, divisions, angleFrom, angleTo); return end(); }
/** Convenience method to create a model with a single node containing a box shape. The resources the Material might contain are * not managed, use {@link Model#manageDisposable(Disposable)} to add those to the model. * @param attributes bitwise mask of the {@link com.badlogic.gdx.graphics.VertexAttributes.Usage}, only Position, Color, Normal * and TextureCoordinates is supported. */ public Model createBox (float width, float height, float depth, int primitiveType, final Material material, final long attributes) { begin(); part("box", primitiveType, attributes, material).box(width, height, depth); return end(); }
/** Convenience method to create a model with a single node containing a cylinder shape. The resources the Material might * contain are not managed, use {@link Model#manageDisposable(Disposable)} to add those to the model. * @param attributes bitwise mask of the {@link com.badlogic.gdx.graphics.VertexAttributes.Usage}, only Position, Color, Normal * and TextureCoordinates is supported. */ public Model createCylinder (float width, float height, float depth, int divisions, int primitiveType, final Material material, final long attributes, float angleFrom, float angleTo) { begin(); part("cylinder", primitiveType, attributes, material).cylinder(width, height, depth, divisions, angleFrom, angleTo); return end(); }
/** Convenience method to create a model with an arrow. The resources the Material might contain are not managed, use * {@link Model#manageDisposable(Disposable)} to add those to the model. * @param material * @param capLength is the height of the cap in percentage, must be in (0,1) * @param stemThickness is the percentage of stem diameter compared to cap diameter, must be in (0,1] * @param divisions the amount of vertices used to generate the cap and stem ellipsoidal bases */ public Model createArrow (float x1, float y1, float z1, float x2, float y2, float z2, float capLength, float stemThickness, int divisions, int primitiveType, Material material, long attributes) { begin(); part("arrow", primitiveType, attributes, material).arrow(x1, y1, z1, x2, y2, z2, capLength, stemThickness, divisions); return end(); }
/** Convenience method to create a model with a single node containing a capsule shape. The resources the Material might contain * are not managed, use {@link Model#manageDisposable(Disposable)} to add those to the model. * @param attributes bitwise mask of the {@link com.badlogic.gdx.graphics.VertexAttributes.Usage}, only Position, Color, Normal * and TextureCoordinates is supported. */ public Model createCapsule (float radius, float height, int divisions, int primitiveType, final Material material, final long attributes) { begin(); part("capsule", primitiveType, attributes, material).capsule(radius, height, divisions); return end(); }
/** Convenience method to create a model with a single node containing a rectangle shape. The resources the Material might * contain are not managed, use {@link Model#manageDisposable(Disposable)} to add those to the model. * @param attributes bitwise mask of the {@link com.badlogic.gdx.graphics.VertexAttributes.Usage}, only Position, Color, Normal * and TextureCoordinates is supported. */ public Model createRect (float x00, float y00, float z00, float x10, float y10, float z10, float x11, float y11, float z11, float x01, float y01, float z01, float normalX, float normalY, float normalZ, int primitiveType, final Material material, final long attributes) { begin(); part("rect", primitiveType, attributes, material).rect(x00, y00, z00, x10, y10, z10, x11, y11, z11, x01, y01, z01, normalX, normalY, normalZ); return end(); }
/** Convenience method to create a model with a single node containing a cone shape. The resources the Material might contain * are not managed, use {@link Model#manageDisposable(Disposable)} to add those to the model. * @param attributes bitwise mask of the {@link com.badlogic.gdx.graphics.VertexAttributes.Usage}, only Position, Color, Normal * and TextureCoordinates is supported. */ public Model createCone (float width, float height, float depth, int divisions, int primitiveType, final Material material, final long attributes, float angleFrom, float angleTo) { begin(); part("cone", primitiveType, attributes, material).cone(width, height, depth, divisions, angleFrom, angleTo); return end(); }
/** Convenience method to create a model with a single node containing a sphere shape. The resources the Material might contain * are not managed, use {@link Model#manageDisposable(Disposable)} to add those to the model. * @param attributes bitwise mask of the {@link com.badlogic.gdx.graphics.VertexAttributes.Usage}, only Position, Color, Normal * and TextureCoordinates is supported. */ public Model createSphere (float width, float height, float depth, int divisionsU, int divisionsV, int primitiveType, final Material material, final long attributes, float angleUFrom, float angleUTo, float angleVFrom, float angleVTo) { begin(); part("cylinder", primitiveType, attributes, material).sphere(width, height, depth, divisionsU, divisionsV, angleUFrom, angleUTo, angleVFrom, angleVTo); return end(); }
/** Convenience method to create a model with an arrow. The resources the Material might contain are not managed, use * {@link Model#manageDisposable(Disposable)} to add those to the model. * @param material * @param capLength is the height of the cap in percentage, must be in (0,1) * @param stemThickness is the percentage of stem diameter compared to cap diameter, must be in (0,1] * @param divisions the amount of vertices used to generate the cap and stem ellipsoidal bases */ public Model createArrow (float x1, float y1, float z1, float x2, float y2, float z2, float capLength, float stemThickness, int divisions, int primitiveType, Material material, long attributes) { begin(); part("arrow", primitiveType, attributes, material).arrow(x1, y1, z1, x2, y2, z2, capLength, stemThickness, divisions); return end(); }
/** Convenience method to create a model with a single node containing a box shape. The resources the Material might contain are * not managed, use {@link Model#manageDisposable(Disposable)} to add those to the model. * @param attributes bitwise mask of the {@link com.badlogic.gdx.graphics.VertexAttributes.Usage}, only Position, Color, Normal * and TextureCoordinates is supported. */ public Model createBox (float width, float height, float depth, int primitiveType, final Material material, final long attributes) { begin(); part("box", primitiveType, attributes, material).box(width, height, depth); return end(); }
public static Model createFrustumModel (final Vector3... p) { ModelBuilder builder = new ModelBuilder(); builder.begin(); MeshPartBuilder mpb = builder.part("", GL20.GL_LINES, Usage.Position | Usage.Normal, new Material(new ColorAttribute(ColorAttribute.Diffuse, Color.WHITE))); mpb.vertex(p[0].x, p[0].y, p[0].z, 0, 0, 1, p[1].x, p[1].y, p[1].z, 0, 0, 1, p[2].x, p[2].y, p[2].z, 0, 0, 1, p[3].x, p[3].y, p[3].z, 0, 0, 1, // near p[4].x, p[4].y, p[4].z, 0, 0, -1, p[5].x, p[5].y, p[5].z, 0, 0, -1, p[6].x, p[6].y, p[6].z, 0, 0, -1, p[7].x, p[7].y, p[7].z, 0, 0, -1); mpb.index((short)0, (short)1, (short)1, (short)2, (short)2, (short)3, (short)3, (short)0); mpb.index((short)4, (short)5, (short)5, (short)6, (short)6, (short)7, (short)7, (short)4); mpb.index((short)0, (short)4, (short)1, (short)5, (short)2, (short)6, (short)3, (short)7); return builder.end(); }
/** Convenience method to create a model with three orthonormal vectors shapes. The resources the Material might contain are not * managed, use {@link Model#manageDisposable(Disposable)} to add those to the model. * @param axisLength Length of each axis. * @param capLength is the height of the cap in percentage, must be in (0,1) * @param stemThickness is the percentage of stem diameter compared to cap diameter, must be in (0,1] * @param divisions the amount of vertices used to generate the cap and stem ellipsoidal bases */ public Model createXYZCoordinates (float axisLength, float capLength, float stemThickness, int divisions, int primitiveType, Material material, long attributes) { begin(); MeshPartBuilder partBuilder; Node node = node(); partBuilder = part("xyz", primitiveType, attributes, material); partBuilder.setColor(Color.RED); partBuilder.arrow(0, 0, 0, axisLength, 0, 0, capLength, stemThickness, divisions); partBuilder.setColor(Color.GREEN); partBuilder.arrow(0, 0, 0, 0, axisLength, 0, capLength, stemThickness, divisions); partBuilder.setColor(Color.BLUE); partBuilder.arrow(0, 0, 0, 0, 0, axisLength, capLength, stemThickness, divisions); return end(); }
/** Convenience method to create a model with three orthonormal vectors shapes. The resources the Material might contain are not * managed, use {@link Model#manageDisposable(Disposable)} to add those to the model. * @param axisLength Length of each axis. * @param capLength is the height of the cap in percentage, must be in (0,1) * @param stemThickness is the percentage of stem diameter compared to cap diameter, must be in (0,1] * @param divisions the amount of vertices used to generate the cap and stem ellipsoidal bases */ public Model createXYZCoordinates (float axisLength, float capLength, float stemThickness, int divisions, int primitiveType, Material material, long attributes) { begin(); MeshPartBuilder partBuilder; Node node = node(); partBuilder = part("xyz", primitiveType, attributes, material); partBuilder.setColor(Color.RED); partBuilder.arrow(0, 0, 0, axisLength, 0, 0, capLength, stemThickness, divisions); partBuilder.setColor(Color.GREEN); partBuilder.arrow(0, 0, 0, 0, axisLength, 0, capLength, stemThickness, divisions); partBuilder.setColor(Color.BLUE); partBuilder.arrow(0, 0, 0, 0, 0, axisLength, capLength, stemThickness, divisions); return end(); }
private void createAxes () { ModelBuilder modelBuilder = new ModelBuilder(); modelBuilder.begin(); MeshPartBuilder builder = modelBuilder.part("grid", GL20.GL_LINES, Usage.Position | Usage.ColorUnpacked, new Material()); builder.setColor(Color.LIGHT_GRAY); for (float t = GRID_MIN; t <= GRID_MAX; t += GRID_STEP) { builder.line(t, 0, GRID_MIN, t, 0, GRID_MAX); builder.line(GRID_MIN, 0, t, GRID_MAX, 0, t); } builder = modelBuilder.part("axes", GL20.GL_LINES, Usage.Position | Usage.ColorUnpacked, new Material()); builder.setColor(Color.RED); builder.line(0, 0, 0, 100, 0, 0); builder.setColor(Color.GREEN); builder.line(0, 0, 0, 0, 100, 0); builder.setColor(Color.BLUE); builder.line(0, 0, 0, 0, 0, 100); axesModel = modelBuilder.end(); axesInstance = new ModelInstance(axesModel); }
@Override public void create () { texture = new Texture(Gdx.files.internal("data/badlogic.jpg"), true); // Create material attributes. Each material can contain x-number of attributes. textureAttribute = new TextureAttribute(TextureAttribute.Diffuse, texture); colorAttribute = new ColorAttribute(ColorAttribute.Diffuse, Color.ORANGE); blendingAttribute = new BlendingAttribute(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA); ModelBuilder builder = new ModelBuilder(); model = builder.createBox(1, 1, 1, new Material(), Usage.Position | Usage.Normal | Usage.TextureCoordinates); model.manageDisposable(texture); modelInstance = new ModelInstance(model); modelInstance.transform.rotate(Vector3.X, 45); material = modelInstance.materials.get(0); builder.begin(); MeshPartBuilder mpb = builder.part("back", GL20.GL_TRIANGLES, Usage.Position | Usage.TextureCoordinates, new Material( textureAttribute)); mpb.rect(-2, -2, -2, 2, -2, -2, 2, 2, -2, -2, 2, -2, 0, 0, 1); backModel = builder.end(); background = new ModelInstance(backModel); modelBatch = new ModelBatch(); camera = new PerspectiveCamera(45, 4, 4); camera.position.set(0, 0, 3); camera.direction.set(0, 0, -1); camera.update(); Gdx.input.setInputProcessor(this); }
@Override public void create () { modelBatch = new ModelBatch(); environment = new Environment(); environment.set(new ColorAttribute(ColorAttribute.AmbientLight, .4f, .4f, .4f, 1f)); environment.add((shadowLight = new DirectionalShadowLight(1024, 1024, 30f, 30f, 1f, 100f)).set(0.8f, 0.8f, 0.8f, -1f, -.8f, -.2f)); environment.shadowMap = shadowLight; cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); cam.position.set(0f, 7f, 10f); cam.lookAt(0, 0, 0); cam.near = 1f; cam.far = 50f; cam.update(); ModelBuilder modelBuilder = new ModelBuilder(); modelBuilder.begin(); MeshPartBuilder mpb = modelBuilder.part("parts", GL20.GL_TRIANGLES, Usage.Position | Usage.Normal | Usage.ColorUnpacked, new Material(ColorAttribute.createDiffuse(Color.WHITE))); mpb.setColor(1f, 1f, 1f, 1f); mpb.box(0, -1.5f, 0, 10, 1, 10); mpb.setColor(1f, 0f, 1f, 1f); mpb.sphere(2f, 2f, 2f, 10, 10); model = modelBuilder.end(); instance = new ModelInstance(model); shadowBatch = new ModelBatch(new DepthShaderProvider()); Gdx.input.setInputProcessor(camController = new CameraInputController(cam)); }