List of usage examples for com.badlogic.gdx.graphics.g3d Material Material
public Material(final Material copyFrom)
From source file:com.andgate.ikou.render.PlayerRender.java
License:Open Source License
public PlayerRender() { tileMesh = new TileMesh(); tileMesh.addTile(Color.WHITE, 0, 0, 0); tileMesh.setNeedsRebuild();// w w w . j a va 2 s . co m material = new Material(TileStack.TILE_MATERIAL); setColor(new Color(1.0f, 1.0f, 1.0f, 1.0f)); }
From source file:com.badlogic.gdx.tests.dragome.examples.GearsDemo.java
@Override public void create() { environment = new Environment(); environment.set(new ColorAttribute(ColorAttribute.AmbientLight, .2f, .2f, .2f, 2f)); // environment.add(new DirectionalLight().set(0.8f, 0.8f, 0.8f, 0f, -0.5f, -0.5f)); sl = new PointLight().setPosition(-5, 10, -6).setColor(1, 1, 1, 1).setIntensity(150); // sl2 = new PointLight().setPosition(0, 7, 5).setColor(0.3f, 0.8f, 0.3f, 1) // .setIntensity(20); ///*from w ww. j a va 2 s .co m*/ // sl3 = new PointLight().setPosition(0, 9, 6).setColor(0.3f, 0.3f, 0.8f, 1) // .setIntensity(20); environment.add(sl); // environment.add(sl2); // environment.add(sl3); cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); cam.position.set(-10, 3, 10f); cam.lookAt(-3, 0, 0); cam.near = 1f; cam.far = 100f; cam.update(); cameraController = new CameraInputController(cam); cameraController.autoUpdate = false; cameraController.forwardTarget = false; cameraController.translateTarget = false; Gdx.input.setInputProcessor(new InputMultiplexer(cameraController)); time = TimeUtils.millis(); viewport = new ScreenViewport(cam); guiViewport = new ScreenViewport(); DefaultShaderProvider defaultShaderProvider = new DefaultShaderProvider(); modelBatch = new ModelBatch(defaultShaderProvider); ModelBuilder modelBuilder = new ModelBuilder(); model1 = gear(modelBuilder, 1.0f, 4.0f, 1.0f, 20, 0.7f, Color.RED); gear1 = new ModelInstance(model1); model2 = gear(modelBuilder, 0.5f, 2.0f, 2.0f, 10, 0.7f, Color.GREEN); gear2 = new ModelInstance(model2); model3 = gear(modelBuilder, 1.3f, 2.0f, 1.5f, 10, 0.7f, Color.BLUE); gear3 = new ModelInstance(model3); font = new BitmapFont(); batch = new SpriteBatch(); lightModel = modelBuilder.createSphere(1, 1, 1, 10, 10, new Material(ColorAttribute.createDiffuse(1, 1, 1, 1)), Usage.Position); lightModel.nodes.get(0).parts.get(0).setRenderable(pLight = new Renderable()); }
From source file:com.badlogic.gdx.tests.dragome.examples.GearsDemo.java
private static Model gear(ModelBuilder builder, float inner_radius, float outer_radius, float width, int teeth, float tooth_depth, Color color) { // Ported from https://github.com/jeffboody/gears2/blob/master/project/jni/gear.c by xpenatan int i;/*www . java 2s . co m*/ float r0, r1, r2, dz; float angle, da; float u, v, len; float[] ar = new float[4]; VertexInfo vertTmp1 = new VertexInfo(); r0 = inner_radius; r1 = outer_radius - tooth_depth / 2.0f; r2 = outer_radius + tooth_depth / 2.0f; dz = 0.5f * width; builder.begin(); MeshPartBuilder part = null; // draw front face // GL_TRIANGLE_STRIP part = builder.part("gear", GL20.GL_TRIANGLE_STRIP, Usage.Position | Usage.Normal, new Material(ColorAttribute.createDiffuse(color))); da = 2.0f * (float) Math.PI / teeth / 4.0f; for (i = 0; i < teeth; i++) { angle = i * 2.0f * (float) Math.PI / teeth; gear_angle(i, teeth, ar); part.index( part.vertex(vertTmp1.setPos(r0 * (float) Math.cos(ar[0]), r0 * (float) Math.sin(ar[0]), dz))); part.index( part.vertex(vertTmp1.setPos(r1 * (float) Math.cos(ar[0]), r1 * (float) Math.sin(ar[0]), dz))); part.index( part.vertex(vertTmp1.setPos(r0 * (float) Math.cos(ar[0]), r0 * (float) Math.sin(ar[0]), dz))); part.index( part.vertex(vertTmp1.setPos(r1 * (float) Math.cos(ar[3]), r1 * (float) Math.sin(ar[3]), dz))); } part.index(part.vertex(vertTmp1.setPos(r0 * (float) Math.cos(0.0f), r0 * (float) Math.sin(0.0f), dz))); part.index(part.vertex(vertTmp1.setPos(r1 * (float) Math.cos(0.0f), r1 * (float) Math.sin(0.0f), dz))); // draw front sides of teeth // GL_TRIANGLES part = builder.part("gear", GL20.GL_TRIANGLES, Usage.Position | Usage.Normal, new Material(ColorAttribute.createDiffuse(color))); for (i = 0; i < teeth; i++) { gear_angle(i, teeth, ar); part.index( part.vertex(vertTmp1.setPos(r1 * (float) Math.cos(ar[0]), r1 * (float) Math.sin(ar[0]), dz))); part.index( part.vertex(vertTmp1.setPos(r2 * (float) Math.cos(ar[1]), r2 * (float) Math.sin(ar[1]), dz))); part.index( part.vertex(vertTmp1.setPos(r2 * (float) Math.cos(ar[2]), r2 * (float) Math.sin(ar[2]), dz))); part.index( part.vertex(vertTmp1.setPos(r1 * (float) Math.cos(ar[0]), r1 * (float) Math.sin(ar[0]), dz))); part.index( part.vertex(vertTmp1.setPos(r2 * (float) Math.cos(ar[2]), r2 * (float) Math.sin(ar[2]), dz))); part.index( part.vertex(vertTmp1.setPos(r1 * (float) Math.cos(ar[3]), r1 * (float) Math.sin(ar[3]), dz))); } // draw back face // GL_TRIANGLE_STRIP part = builder.part("gear", GL20.GL_TRIANGLE_STRIP, Usage.Position | Usage.Normal, new Material(ColorAttribute.createDiffuse(color))); for (i = 0; i < teeth; i++) { gear_angle(i, teeth, ar); part.index( part.vertex(vertTmp1.setPos(r1 * (float) Math.cos(ar[0]), r1 * (float) Math.sin(ar[0]), -dz))); part.index( part.vertex(vertTmp1.setPos(r0 * (float) Math.cos(ar[0]), r0 * (float) Math.sin(ar[0]), -dz))); part.index( part.vertex(vertTmp1.setPos(r1 * (float) Math.cos(ar[3]), r1 * (float) Math.sin(ar[3]), -dz))); part.index( part.vertex(vertTmp1.setPos(r0 * (float) Math.cos(ar[0]), r0 * (float) Math.sin(ar[0]), -dz))); } part.index(part.vertex(vertTmp1.setPos(r1 * (float) Math.cos(0.0f), r1 * (float) Math.sin(0.0f), -dz))); part.index(part.vertex(vertTmp1.setPos(r0 * (float) Math.cos(0.0f), r0 * (float) Math.sin(0.0f), -dz))); // draw back sides of teeth // GL_TRIANGLES part = builder.part("gear", GL20.GL_TRIANGLES, Usage.Position | Usage.Normal, new Material(ColorAttribute.createDiffuse(color))); for (i = 0; i < teeth; i++) { gear_angle(i, teeth, ar); part.index( part.vertex(vertTmp1.setPos(r1 * (float) Math.cos(ar[3]), r1 * (float) Math.sin(ar[3]), -dz))); part.index( part.vertex(vertTmp1.setPos(r2 * (float) Math.cos(ar[2]), r2 * (float) Math.sin(ar[2]), -dz))); part.index( part.vertex(vertTmp1.setPos(r2 * (float) Math.cos(ar[1]), r2 * (float) Math.sin(ar[1]), -dz))); part.index( part.vertex(vertTmp1.setPos(r1 * (float) Math.cos(ar[3]), r1 * (float) Math.sin(ar[3]), -dz))); part.index( part.vertex(vertTmp1.setPos(r2 * (float) Math.cos(ar[1]), r2 * (float) Math.sin(ar[1]), -dz))); part.index( part.vertex(vertTmp1.setPos(r1 * (float) Math.cos(ar[0]), r1 * (float) Math.sin(ar[0]), -dz))); } // draw outward faces of teeth // GL_TRIANGLE_STRIP // repeated vertices are necessary to achieve flat shading in ES2 part = builder.part("gear", GL20.GL_TRIANGLE_STRIP, Usage.Position | Usage.Normal, new Material(ColorAttribute.createDiffuse(color))); for (i = 0; i < teeth; i++) { gear_angle(i, teeth, ar); vertTmp1.hasNormal = false; if (i > 0) { part.index(part .vertex(vertTmp1.setPos(r1 * (float) Math.cos(ar[0]), r1 * (float) Math.sin(ar[0]), dz))); part.index(part .vertex(vertTmp1.setPos(r1 * (float) Math.cos(ar[0]), r1 * (float) Math.sin(ar[0]), -dz))); } u = r2 * (float) Math.cos(ar[1]) - r1 * (float) Math.cos(ar[0]); v = r2 * (float) Math.sin(ar[1]) - r1 * (float) Math.sin(ar[0]); len = (float) Math.sqrt(u * u + v * v); u /= len; v /= len; vertTmp1.setNor(v, -u, 0.0f); part.index( part.vertex(vertTmp1.setPos(r1 * (float) Math.cos(ar[0]), r1 * (float) Math.sin(ar[0]), dz))); part.index( part.vertex(vertTmp1.setPos(r1 * (float) Math.cos(ar[0]), r1 * (float) Math.sin(ar[0]), -dz))); part.index( part.vertex(vertTmp1.setPos(r2 * (float) Math.cos(ar[1]), r2 * (float) Math.sin(ar[1]), dz))); part.index( part.vertex(vertTmp1.setPos(r2 * (float) Math.cos(ar[1]), r2 * (float) Math.sin(ar[1]), -dz))); vertTmp1.setNor((float) Math.cos(ar[0]), (float) Math.sin(ar[0]), 0.0f); part.index( part.vertex(vertTmp1.setPos(r2 * (float) Math.cos(ar[1]), r2 * (float) Math.sin(ar[1]), dz))); part.index( part.vertex(vertTmp1.setPos(r2 * (float) Math.cos(ar[1]), r2 * (float) Math.sin(ar[1]), -dz))); part.index( part.vertex(vertTmp1.setPos(r2 * (float) Math.cos(ar[2]), r2 * (float) Math.sin(ar[2]), dz))); part.index( part.vertex(vertTmp1.setPos(r2 * (float) Math.cos(ar[2]), r2 * (float) Math.sin(ar[2]), -dz))); u = r1 * (float) Math.cos(ar[3]) - r2 * (float) Math.cos(ar[2]); v = r1 * (float) Math.sin(ar[3]) - r2 * (float) Math.sin(ar[2]); vertTmp1.setNor(v, -u, 0.0f); part.index( part.vertex(vertTmp1.setPos(r2 * (float) Math.cos(ar[2]), r2 * (float) Math.sin(ar[2]), dz))); part.index( part.vertex(vertTmp1.setPos(r2 * (float) Math.cos(ar[2]), r2 * (float) Math.sin(ar[2]), -dz))); part.index( part.vertex(vertTmp1.setPos(r1 * (float) Math.cos(ar[3]), r1 * (float) Math.sin(ar[3]), dz))); part.index( part.vertex(vertTmp1.setPos(r1 * (float) Math.cos(ar[3]), r1 * (float) Math.sin(ar[3]), -dz))); vertTmp1.setNor((float) Math.cos(ar[0]), (float) Math.sin(ar[0]), 0.0f); part.index( part.vertex(vertTmp1.setPos(r1 * (float) Math.cos(ar[3]), r1 * (float) Math.sin(ar[3]), dz))); part.index( part.vertex(vertTmp1.setPos(r1 * (float) Math.cos(ar[3]), r1 * (float) Math.sin(ar[3]), -dz))); } vertTmp1.hasNormal = false; part.index(part.vertex(vertTmp1.setPos(r1 * (float) Math.cos(0.0f), r1 * (float) Math.sin(0.0f), dz))); part.index(part.vertex(vertTmp1.setPos(r1 * (float) Math.cos(0.0f), r1 * (float) Math.sin(0.0f), -dz))); // draw inside radius cylinder // GL_TRIANGLE_STRIP part = builder.part("gear", GL20.GL_TRIANGLE_STRIP, Usage.Position | Usage.Normal, new Material(ColorAttribute.createDiffuse(color))); for (i = 0; i < teeth; i++) { gear_angle(i, teeth, ar); vertTmp1.setNor(-(float) Math.cos(ar[0]), -(float) Math.sin(ar[0]), 0.0f); part.index( part.vertex(vertTmp1.setPos(r0 * (float) Math.cos(ar[0]), r0 * (float) Math.sin(ar[0]), -dz))); part.index( part.vertex(vertTmp1.setPos(r0 * (float) Math.cos(ar[0]), r0 * (float) Math.sin(ar[0]), dz))); } vertTmp1.setNor(-(float) Math.cos(0.0f), -(float) Math.sin(0.0f), 0.0f); part.index(part.vertex(vertTmp1.setPos(r0 * (float) Math.cos(0.0f), r0 * (float) Math.sin(0.0f), -dz))); part.index(part.vertex(vertTmp1.setPos(r0 * (float) Math.cos(0.0f), r0 * (float) Math.sin(0.0f), dz))); return builder.end(); }
From source file:com.badlogic.gdx.tests.g3d.voxel.VoxelWorld.java
License:Apache License
public VoxelWorld(TextureRegion[] tiles, int chunksX, int chunksY, int chunksZ) { this.tiles = tiles; this.chunks = new VoxelChunk[chunksX * chunksY * chunksZ]; this.chunksX = chunksX; this.chunksY = chunksY; this.chunksZ = chunksZ; this.numChunks = chunksX * chunksY * chunksZ; this.voxelsX = chunksX * CHUNK_SIZE_X; this.voxelsY = chunksY * CHUNK_SIZE_Y; this.voxelsZ = chunksZ * CHUNK_SIZE_Z; int i = 0;/*from w ww .j ava2 s .co m*/ for (int y = 0; y < chunksY; y++) { for (int z = 0; z < chunksZ; z++) { for (int x = 0; x < chunksX; x++) { VoxelChunk chunk = new VoxelChunk(CHUNK_SIZE_X, CHUNK_SIZE_Y, CHUNK_SIZE_Z); chunk.offset.set(x * CHUNK_SIZE_X, y * CHUNK_SIZE_Y, z * CHUNK_SIZE_Z); chunks[i++] = chunk; } } } int len = CHUNK_SIZE_X * CHUNK_SIZE_Y * CHUNK_SIZE_Z * 6 * 6 / 3; short[] indices = new short[len]; short j = 0; for (i = 0; i < len; i += 6, j += 4) { indices[i + 0] = (short) (j + 0); indices[i + 1] = (short) (j + 1); indices[i + 2] = (short) (j + 2); indices[i + 3] = (short) (j + 2); indices[i + 4] = (short) (j + 3); indices[i + 5] = (short) (j + 0); } this.meshes = new Mesh[chunksX * chunksY * chunksZ]; for (i = 0; i < meshes.length; i++) { meshes[i] = new Mesh(true, CHUNK_SIZE_X * CHUNK_SIZE_Y * CHUNK_SIZE_Z * 6 * 4, CHUNK_SIZE_X * CHUNK_SIZE_Y * CHUNK_SIZE_Z * 36 / 3, VertexAttribute.Position(), VertexAttribute.Normal()); meshes[i].setIndices(indices); } this.dirty = new boolean[chunksX * chunksY * chunksZ]; for (i = 0; i < dirty.length; i++) dirty[i] = true; this.numVertices = new int[chunksX * chunksY * chunksZ]; for (i = 0; i < numVertices.length; i++) numVertices[i] = 0; this.vertices = new float[VoxelChunk.VERTEX_SIZE * 6 * CHUNK_SIZE_X * CHUNK_SIZE_Y * CHUNK_SIZE_Z]; this.materials = new Material[chunksX * chunksY * chunksZ]; for (i = 0; i < materials.length; i++) { materials[i] = new Material(new ColorAttribute(ColorAttribute.Diffuse, MathUtils.random(0.5f, 1f), MathUtils.random(0.5f, 1f), MathUtils.random(0.5f, 1f), 1)); } }
From source file:com.badlogic.gdx.tests.ViewportTest3.java
License:Apache License
public void create() { modelBatch = new ModelBatch(); modelBuilder = new ModelBuilder(); environment = new Environment(); environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.3f, 0.3f, 0.3f, 1.f)); shadowLight = new DirectionalLight(); shadowLight.set(0.8f, 0.8f, 0.8f, -0.5f, -1f, 0.7f); environment.add(shadowLight);/*from w w w .j a v a 2 s . c o m*/ modelBatch = new ModelBatch(); camera = new PerspectiveCamera(); camera.fieldOfView = 67; camera.near = 0.1f; camera.far = 300f; camera.position.set(0, 0, 100); camera.lookAt(0, 0, 0); viewports = ViewportTest1.getViewports(camera); viewport = viewports.first(); names = ViewportTest1.getViewportNames(); 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); boxInstance.transform.rotate(1, 0, 0, 30); boxInstance.transform.rotate(0, 1, 0, 30); Gdx.input.setInputProcessor(new InputAdapter() { public boolean keyDown(int keycode) { if (keycode == Input.Keys.SPACE) { int index = (viewports.indexOf(viewport, true) + 1) % viewports.size; name = names.get(index); viewport = viewports.get(index); resize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); } return false; } }); }
From source file:com.barconr.games.marblegame.Maze3Drenderer.java
License:Apache License
private void addBox(Vector3 position, float width, float height, float depth, Color col) { Model model = modelBuilder.createBox(width, height, depth, new Material(ColorAttribute.createDiffuse(col)), Usage.Position | Usage.Normal); ModelInstance mis = new ModelInstance(model); mis.transform.setTranslation(position); instances.add(mis);//from w ww . ja v a2 s .c o m }
From source file:com.bladecoder.engine.util.Utils3D.java
License:Apache License
public static void createFloor() { ModelBuilder modelBuilder = new ModelBuilder(); modelBuilder.begin();//from w w w.j av a2s .c o m 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, -0.1f, 0, 10, .2f, 10); mpb.rect(-10, 0, -10, -10, 0, 10, 10, 0, 10, 10, 0, -10, 0, 1, 0); floorModel = modelBuilder.end(); floorInstance = new ModelInstance(floorModel); // TODO Set only when FBO is active floorInstance.materials.get(0).set(new BlendingAttribute(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA)); }
From source file:com.github.fauu.helix.editor.displayable.TilePermissionsGridDisplayable.java
License:Open Source License
public TilePermissionsGridDisplayable(Tile[][] tiles, TextureAtlas atlas) { this.atlas = atlas; MeshBuilder meshBuilder = new MeshBuilder(); meshBuilder.begin(VertexAttributes.Usage.Position | VertexAttributes.Usage.TextureCoordinates, GL20.GL_TRIANGLES);/*from w w w .j a v a 2 s .c o m*/ for (int y = 0; y < tiles.length; y++) { for (int x = 0; x < tiles[y].length; x++) { // TODO: Cache regions meshBuilder.setUVRange(atlas.findRegion(tiles[y][x].getPermissions().name())); meshBuilder.rect(x, y, 0, x + 1, y, 0, x + 1, y + 1, 0, x, y + 1, 0, 0, 0, 1); } } Mesh mesh = meshBuilder.end(); ModelBuilder modelBuilder = new ModelBuilder(); modelBuilder.begin(); TextureAttribute diffuse = TextureAttribute.createDiffuse(atlas.getTextures().first()); modelBuilder.part("grid", mesh, GL20.GL_TRIANGLES, new Material(diffuse)); instance = new ModelInstance(modelBuilder.end()); instance.transform.translate(0, 0, Z_OFFSET); }
From source file:com.mbrlabs.mundus.commons.skybox.Skybox.java
License:Apache License
private Model createModel() { ModelBuilder modelBuilder = new ModelBuilder(); Model model = modelBuilder.createBox(1, 1, 1, new Material(new CubemapAttribute(CubemapAttribute.EnvironmentMap, cubemap)), VertexAttributes.Usage.Position); return model; }
From source file:com.mbrlabs.mundus.editor.tools.ScaleTool.java
License:Apache License
public ScaleTool(ProjectManager projectManager, GameObjectPicker goPicker, ToolHandlePicker handlePicker, ShapeRenderer shapeRenderer, ModelBatch batch, CommandHistory history) { super(projectManager, goPicker, handlePicker, batch, history); this.shapeRenderer = shapeRenderer; ModelBuilder modelBuilder = new ModelBuilder(); Model xPlaneHandleModel = UsefulMeshs.createArrowStub(new Material(ColorAttribute.createDiffuse(COLOR_X)), Vector3.Zero, new Vector3(15, 0, 0)); Model yPlaneHandleModel = UsefulMeshs.createArrowStub(new Material(ColorAttribute.createDiffuse(COLOR_Y)), Vector3.Zero, new Vector3(0, 15, 0)); Model zPlaneHandleModel = UsefulMeshs.createArrowStub(new Material(ColorAttribute.createDiffuse(COLOR_Z)), Vector3.Zero, new Vector3(0, 0, 15)); Model xyzPlaneHandleModel = modelBuilder.createBox(3, 3, 3, new Material(ColorAttribute.createDiffuse(COLOR_XYZ)), VertexAttributes.Usage.Position | VertexAttributes.Usage.Normal); xHandle = new ScaleHandle(X_HANDLE_ID, xPlaneHandleModel); yHandle = new ScaleHandle(Y_HANDLE_ID, yPlaneHandleModel); zHandle = new ScaleHandle(Z_HANDLE_ID, zPlaneHandleModel); xyzHandle = new ScaleHandle(XYZ_HANDLE_ID, xyzPlaneHandleModel); handles = new ScaleHandle[] { xHandle, yHandle, zHandle, xyzHandle }; }