/** 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, final Material material, final long attributes) { return createBox(width, height, depth, GL20.GL_TRIANGLES, material, attributes); }
/** Adds the nodes of the specified model to a new node of the model being build. After this method the given model can no * longer be used. Do not call the {@link Model#dispose()} method on that model. * @return The newly created node containing the nodes of the given model. */ public Node node (final String id, final Model model) { final Node node = new Node(); node.id = id; node.addChildren(model.nodes); node(node); for (final Disposable disposable : model.getManagedDisposables()) manage(disposable); return node; }
/** Creates a new MeshPart within the current Node and returns a {@link MeshPartBuilder} which can be used to build the shape of * the part. If possible a previously used {@link MeshPartBuilder} will be reused, to reduce the number of mesh binds. * Therefore you can only build one part at a time. The resources the Material might contain are not managed, use * {@link #manage(Disposable)} to add those to the model. * @return The {@link MeshPartBuilder} you can use to build the MeshPart. */ public MeshPartBuilder part (final String id, int primitiveType, final VertexAttributes attributes, final Material material) { final MeshBuilder builder = getBuilder(attributes); part(builder.part(id, primitiveType), material); return builder; }
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(); }
public void create () { modelBatch = new ModelBatch(); modelBuilder = new ModelBuilder(); name = names.first(); ModelBuilder modelBuilder = new ModelBuilder(); Model boxModel = modelBuilder.createBox(50f, 50f, 50f, new Material(ColorAttribute.createDiffuse(Color.GREEN)), Usage.Position | Usage.Normal); boxInstance = new ModelInstance(boxModel);
final long attributes = Usage.Position | Usage.Normal | Usage.TextureCoordinates; final Model sphere = modelBuilder.createSphere(4f, 4f, 4f, 24, 24, material, attributes); disposables.add(sphere); world.addConstructor("sphere", new BulletConstructor(sphere, 10f, new btSphereShape(2f))); final Model cylinder = modelBuilder.createCylinder(4f, 6f, 4f, 16, material, attributes); disposables.add(cylinder); world.addConstructor("cylinder", new BulletConstructor(cylinder, 10f, new btCylinderShape(tmpV1.set(2f, 3f, 2f)))); final Model capsule = modelBuilder.createCapsule(2f, 6f, 16, material, attributes); disposables.add(capsule); world.addConstructor("capsule", new BulletConstructor(capsule, 10f, new btCapsuleShape(2f, 2f))); final Model box = modelBuilder.createBox(4f, 4f, 2f, material, attributes); disposables.add(box); world.addConstructor("box2", new BulletConstructor(box, 10f, new btBoxShape(tmpV1.set(2f, 2f, 1f)))); final Model cone = modelBuilder.createCone(4f, 6f, 4f, 16, material, attributes); disposables.add(cone); world.addConstructor("cone", new BulletConstructor(cone, 10f, new btConeShape(2f, 6f)));
ModelBuilder builder = new ModelBuilder(); Model xyzModel = builder.createXYZCoordinates(10, new Material(), Usage.Position|Usage.ColorPacked), planeModel = builder.createLineGrid(10, 10, 1, 1, new Material(ColorAttribute.createDiffuse(Color.WHITE)), Usage.Position); models.add(xyzModel); models.add(planeModel);
/** Adds the specified mesh part to the current node. The Mesh will be managed by the model and disposed when the model is * disposed. The resources the Material might contain are not managed, use {@link #manage(Disposable)} to add those to the * model. * @return The added MeshPart. */ public MeshPart part (final String id, final Mesh mesh, int primitiveType, final Material material) { return part(id, mesh, primitiveType, 0, mesh.getNumIndices(), material); }
@Override public void create () { ModelBuilder builder = new ModelBuilder(); sphere = builder.createSphere(2f, 2f, 2f, 16, 16, new Material(new ColorAttribute(ColorAttribute.Diffuse, Color.WHITE)), Usage.Position | Usage.Normal); // cam = new PerspectiveCamera(45, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); cam = new OrthographicCamera(45, 45 * (Gdx.graphics.getWidth() / (float)Gdx.graphics.getHeight())); cam.near = 1; cam.far = 200; Random rand = new Random(); for (int i = 0; i < instances.length; i++) { pos.set(rand.nextFloat() * 100 - rand.nextFloat() * 100, rand.nextFloat() * 100 - rand.nextFloat() * 100, rand.nextFloat() * -100 - 3); instances[i] = new ModelInstance(sphere, pos); } modelBatch = new ModelBatch(); batch = new SpriteBatch(); font = new BitmapFont(); // Gdx.graphics.setVSync(true); // Gdx.app.log("CullTest", "" + Gdx.graphics.getBufferFormat().toString()); }
public TranslateTool(ProjectManager projectManager, GameObjectPicker goPicker, ToolHandlePicker handlePicker, ModelBatch batch, CommandHistory history) { super(projectManager, goPicker, handlePicker, batch, history); ModelBuilder modelBuilder = new ModelBuilder(); Model xHandleModel = modelBuilder.createArrow(0, 0, 0, 1, 0, 0, ARROW_CAP_SIZE, ARROW_THIKNESS, ARROW_DIVISIONS, GL20.GL_TRIANGLES, new Material(ColorAttribute.createDiffuse(COLOR_X)), VertexAttributes.Usage.Position); Model yHandleModel = modelBuilder.createArrow(0, 0, 0, 0, 1, 0, ARROW_CAP_SIZE, ARROW_THIKNESS, ARROW_DIVISIONS, GL20.GL_TRIANGLES, new Material(ColorAttribute.createDiffuse(COLOR_Y)), VertexAttributes.Usage.Position); Model zHandleModel = modelBuilder.createArrow(0, 0, 0, 0, 0, 1, ARROW_CAP_SIZE, ARROW_THIKNESS, ARROW_DIVISIONS, GL20.GL_TRIANGLES, new Material(ColorAttribute.createDiffuse(COLOR_Z)), VertexAttributes.Usage.Position); Model xzPlaneHandleModel = modelBuilder.createSphere(1, 1, 1, 20, 20, new Material(ColorAttribute.createDiffuse(COLOR_XZ)), VertexAttributes.Usage.Position); xHandle = new TranslateHandle(X_HANDLE_ID, xHandleModel); yHandle = new TranslateHandle(Y_HANDLE_ID, yHandleModel); zHandle = new TranslateHandle(Z_HANDLE_ID, zHandleModel); xzPlaneHandle = new TranslateHandle(XZ_HANDLE_ID, xzPlaneHandleModel); handles = new TranslateHandle[] { xHandle, yHandle, zHandle, xzPlaneHandle }; gameObjectModifiedEvent = new GameObjectModifiedEvent(null); }
/** 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) { return createSphere(width, height, depth, divisionsU, divisionsV, primitiveType, material, attributes, 0, 360, 0, 180); }
/** Add a node to the model. Use any of the part(...) method to add a NodePart. * @return The node being created. */ public Node node () { final Node node = new Node(); node(node); node.id = "node" + model.nodes.size; return node; }
final Model groundModel = modelBuilder.createRect( 20f, 0f, .createShininess(16f)), Usage.Position | Usage.Normal); disposables.add(groundModel); final Model boxModel = modelBuilder.createBox(1f, 1f, 1f, new Material(ColorAttribute.createDiffuse(Color.WHITE), ColorAttribute.createSpecular(Color.WHITE), FloatAttribute.createShininess(64f)), Usage.Position | Usage.Normal); disposables.add(boxModel);
final Model groundModel = modelBuilder.createRect( 20f, 0f, .createShininess(16f)), Usage.Position | Usage.Normal); models.add(groundModel); final Model sphereModel = modelBuilder.createSphere( 1f, 1f,
/** 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. */ public Model createArrow (Vector3 from, Vector3 to, Material material, long attributes) { return createArrow(from.x, from.y, from.z, to.x, to.y, to.z, 0.1f, 0.1f, 5, GL20.GL_TRIANGLES, material, attributes); }
public Model createXYZCoordinates (float axisLength, Material material, long attributes) { return createXYZCoordinates(axisLength, 0.1f, 0.1f, 5, GL20.GL_TRIANGLES, material, attributes); }
/** 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, final Material material, final long attributes) { return createCapsule(radius, height, divisions, GL20.GL_TRIANGLES, material, attributes); }
/** 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(); }
@Override public void create () { modelBatch = new ModelBatch(new DefaultShaderProvider()); environment = new Environment(); environment.set(new ColorAttribute(ColorAttribute.AmbientLight, .4f, .4f, .4f, 1f)); environment.add(new DirectionalLight().set(0.8f, 0.8f, 0.8f, -1f, -0.8f, -0.2f)); cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); cam.position.set(10f, 10f, 10f); cam.lookAt(0, 0, 0); cam.near = 1f; cam.far = 30f; cam.update(); ModelBuilder modelBuilder = new ModelBuilder(); model = modelBuilder.createBox(5f, 5f, 5f, new Material(ColorAttribute.createDiffuse(Color.GREEN)), Usage.Position | Usage.Normal); instance = new ModelInstance(model); Gdx.input.setInputProcessor(new InputMultiplexer(this, inputController = new CameraInputController(cam))); }