Java Code Examples for com.badlogic.gdx.graphics.g3d.attributes.TextureAttribute#createDiffuse()
The following examples show how to use
com.badlogic.gdx.graphics.g3d.attributes.TextureAttribute#createDiffuse() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ModelManager.java From gdx-proto with Apache License 2.0 | 6 votes |
public void createBillboardTest() { ModelBuilder mb = new ModelBuilder(); mb.begin(); long attr = Usage.TextureCoordinates | Usage.Position | Usage.Normal; TextureRegion region = Assets.getAtlas().findRegion("sprites/test-guy"); Material mat = new Material(TextureAttribute.createDiffuse(region.getTexture())); boolean blended = true; float opacity = 1f; mat.set(new BlendingAttribute(blended, GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA, opacity)); MeshPartBuilder mpb = mb.part("rect", GL20.GL_TRIANGLES, attr, mat); mpb.setUVRange(region); // the coordinates are offset so that we can easily set the center position to align with the entity's body float sz = 2f; // size float b = -sz/2; // base float max = sz/2; // max Vector3 bl = new Vector3(b, b, 0f); Vector3 br = new Vector3(b, max, 0f); Vector3 tr = new Vector3(max, max, 0f); Vector3 tl = new Vector3(max, b, 0f); Vector3 norm = new Vector3(0f, 0f, 1f); mpb.rect(bl, tl, tr, br, norm); billboardTestModel = mb.end(); }
Example 2
Source File: Shadow.java From gdx-proto with Apache License 2.0 | 6 votes |
public static void init() { list = new Array<>(); ModelBuilder mb = new ModelBuilder(); Vector3 norm = new Vector3(0f, 1f, 0f); Texture texture = Assets.manager.get("textures/shadow.png", Texture.class); Material material = new Material(TextureAttribute.createDiffuse(texture)); material.set(new BlendingAttribute(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA, 0.7f)); //material.set(new DepthTestAttribute(0)); // disable depth testing long attr = Usage.Position | Usage.TextureCoordinates; float s = 1f; model = mb.createRect( -s, 0f, -s,// bl -s, 0f, s, // tl s, 0f, s, // tr s, 0f, -s, // br norm.x, norm.y, norm.z, material, attr ); }
Example 3
Source File: HeightMapModel.java From gdx-proto with Apache License 2.0 | 5 votes |
public HeightMapModel(HeightMap hm) { this.heightMap = hm; String groundTexName = "textures/hm_paint.png"; groundTexture = new Texture(Gdx.files.internal(groundTexName), true); groundTexture.setWrap(Texture.TextureWrap.Repeat, Texture.TextureWrap.Repeat); groundTexture.setFilter(Texture.TextureFilter.MipMapLinearNearest, Texture.TextureFilter.Linear); groundMat = new Material(TextureAttribute.createDiffuse(groundTexture) , ColorAttribute.createSpecular(specular) ); createGround(); }
Example 4
Source File: Terrain.java From gdx-proto with Apache License 2.0 | 4 votes |
/** * Creates a plane, used for testing * @param size the size of the plane * @return */ public static TerrainChunk CreatePlaneChunk (float size) { TerrainChunk chunk = new TerrainChunk(); // graphical representation of the ground Log.debug("createLevel - create ground"); if (Main.isClient()) { ModelBuilder mb = new ModelBuilder(); mb.begin(); Vector3 bl = new Vector3(); Vector3 tl = new Vector3(); Vector3 tr = new Vector3(); Vector3 br = new Vector3(); Vector3 norm = new Vector3(0f, 1f, 0f); // the size of each rect that makes up the ground Texture groundTex = Assets.manager.get("textures/ground1.jpg", Texture.class); Material groundMat = new Material(TextureAttribute.createDiffuse(groundTex)); MeshPartBuilder mpb = mb.part("ground", GL20.GL_TRIANGLES, Usage.Position | Usage.Normal | Usage.TextureCoordinates, groundMat); float u1 = 0f; float v1 = 0f; float u2 = size / 5f; float v2 = size / 5f; mpb.setUVRange(u1, v1, u2, v2); bl.set(0, 0, 0); tl.set(0, 0, size); tr.set(size, 0, size); br.set(size, 0, 0); // mpb.rect(bl, tl, tr, br, norm); int divisions = ((int)size) / 4; mpb.patch(bl, tl, tr, br, norm, divisions, divisions); Model groundModel = mb.end(); chunk.modelInstance = new ModelInstance(groundModel); } // physical representation of the ground btCollisionObject groundObj = new btCollisionObject(); btCollisionShape groundShape = new btStaticPlaneShape(Vector3.Y, 0f); groundObj.setCollisionShape(groundShape); Physics.applyStaticGeometryCollisionFlags(groundObj); Physics.inst.addStaticGeometryToWorld(groundObj); chunk.body = groundObj; return chunk; }
Example 5
Source File: LevelBuilder.java From gdx-proto with Apache License 2.0 | 4 votes |
public static void createLevel() { // graphical representation of the ground Log.debug("createLevel - create ground"); if (Main.isClient()) { ModelBuilder mb = new ModelBuilder(); mb.begin(); Vector3 bl = new Vector3(); Vector3 tl = new Vector3(); Vector3 tr = new Vector3(); Vector3 br = new Vector3(); Vector3 norm = new Vector3(0f, 1f, 0f); // the size of each rect that makes up the ground Texture groundTex = Assets.manager.get("textures/ground1.jpg", Texture.class); Material groundMat = new Material(TextureAttribute.createDiffuse(groundTex)); MeshPartBuilder mpb = mb.part("ground", GL20.GL_TRIANGLES, Usage.Position | Usage.Normal | Usage.TextureCoordinates, groundMat); float u1 = 0f; float v1 = 0f; float u2 = groundPieceSize / 5f; float v2 = groundPieceSize / 5f; mpb.setUVRange(u1, v1, u2, v2); bl.set(0, 0, 0); tl.set(0, 0, groundPieceSize); tr.set(groundPieceSize, 0, groundPieceSize); br.set(groundPieceSize, 0, 0); //mpb.rect(bl, tl, tr, br, norm); int divisions = ((int) groundPieceSize) / 4; mpb.patch(bl, tl, tr, br, norm, divisions, divisions); Model groundModel = mb.end(); models.add(groundModel); groundPieces.clear(); int count = 0; for (int x = 0; x < GameWorld.WORLD_WIDTH; x += groundPieceSize) { for (int z = 0; z < GameWorld.WORLD_DEPTH; z += groundPieceSize) { count++; ModelInstance groundPiece = new ModelInstance(groundModel); groundPiece.transform.setToTranslation(x, 0f, z); groundPieces.add(groundPiece); } } Log.debug("createLevel - created " + count + " groundPieces"); } // physical representation of the ground btCollisionObject groundObj = new btCollisionObject(); btCollisionShape groundShape = new btStaticPlaneShape(Vector3.Y, 0f); groundObj.setCollisionShape(groundShape); Physics.applyStaticGeometryCollisionFlags(groundObj); Physics.inst.addStaticGeometryToWorld(groundObj); if (Main.isServer()) { Log.debug("createLevel - create static models"); // server creates static models here, client will create the models when received from server upon connection createStaticModels(25); } Log.debug("createLevel - create boxes"); Box.createBoxes(10); }