com.badlogic.gdx.graphics.g3d.attributes.TextureAttribute Java Examples
The following examples show how to use
com.badlogic.gdx.graphics.g3d.attributes.TextureAttribute.
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: 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 #2
Source File: Sky.java From gdx-proto with Apache License 2.0 | 6 votes |
public static void createSkyBox (Texture xpos, Texture xneg, Texture ypos, Texture yneg, Texture zpos, Texture zneg) { modelInstance = new ModelInstance(model, "Skycube"); // Set material textures modelInstance.materials.get(0).set(TextureAttribute.createDiffuse(xpos)); modelInstance.materials.get(1).set(TextureAttribute.createDiffuse(xneg)); modelInstance.materials.get(2).set(TextureAttribute.createDiffuse(ypos)); modelInstance.materials.get(3).set(TextureAttribute.createDiffuse(yneg)); modelInstance.materials.get(5).set(TextureAttribute.createDiffuse(zpos)); modelInstance.materials.get(4).set(TextureAttribute.createDiffuse(zneg)); //Disable depth test modelInstance.materials.get(0).set(new DepthTestAttribute(0)); modelInstance.materials.get(1).set(new DepthTestAttribute(0)); modelInstance.materials.get(2).set(new DepthTestAttribute(0)); modelInstance.materials.get(3).set(new DepthTestAttribute(0)); modelInstance.materials.get(4).set(new DepthTestAttribute(0)); modelInstance.materials.get(5).set(new DepthTestAttribute(0)); enabled = true; }
Example #3
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 #4
Source File: Terrain.java From gdx-proto with Apache License 2.0 | 6 votes |
/** * Return a heightmap chunk * TODO NOT IMPLEMENTED! * @param heightmap * @param tex * @param width * @param height * @return */ public static TerrainChunk CreateHeightMapChunk (FileHandle heightmap, Texture tex, int width, int height) { HeightMap hp = new HeightMap(heightmap, 10, 10, false, 3); HeightMapModel md = new HeightMapModel(hp); //Model model = md.ground; md.ground.materials.get(0).set(TextureAttribute.createDiffuse(tex)); //btCollisionObject obj = new btCollisionObject(); //btCollisionShape shape = new btBvhTriangleMeshShape(model.meshParts); //obj.setCollisionShape(shape); ////Physics.applyStaticGeometryCollisionFlags(obj); //Physics.inst.addStaticGeometryToWorld(obj); TerrainChunk ch = new TerrainChunk(); ch.setModelInstance(md.ground); return ch; }
Example #5
Source File: ModelFactory.java From GdxDemo3D with Apache License 2.0 | 5 votes |
public static Model buildBillboardModel(Texture texture, float width, float height) { TextureRegion textureRegion = new TextureRegion(texture, texture.getWidth(), texture.getHeight()); Material material = new Material(); material.set(new TextureAttribute(TextureAttribute.Diffuse, textureRegion)); material.set(new ColorAttribute(ColorAttribute.AmbientLight, Color.WHITE)); material.set(new BlendingAttribute()); return ModelFactory.buildPlaneModel(width, height, material, 0, 0, 1, 1); }
Example #6
Source File: Sky.java From gdx-proto with Apache License 2.0 | 5 votes |
public static void createSkyBox (Texture skybox) { modelInstance = new ModelInstance(model, "Skybox"); // Set material texutres and Disable depth test modelInstance.materials.get(0).set(TextureAttribute.createDiffuse(skybox)); modelInstance.materials.get(0).set(new DepthTestAttribute(0)); enabled = true; }
Example #7
Source File: Box.java From gdx-proto with Apache License 2.0 | 5 votes |
/** create some boxes to fill the level with some test geometry */ public static void createBoxes(int count) { ModelBuilder main = new ModelBuilder(); ModelBuilder mb = new ModelBuilder(); Material material = new Material(); if (Main.isClient()) { material.set(TextureAttribute.createDiffuse(Assets.manager.get("textures/marble.jpg", Texture.class))); } main.begin(); //float x = GameWorld.WORLD_WIDTH; //float y = GameWorld.WORLD_DEPTH; for (int i = 0; i < count; i++) { //float w = MathUtils.random(minW, maxW); float w = 8f; float d = 8f; float h = (i+1)*5f; tmp.set(10f + (w+2) * i, 0f, 10f + (d+2) * i); if (Main.isClient()) { mb.begin(); MeshPartBuilder mpb = mb.part("part-" + i, GL20.GL_TRIANGLES, Usage.Position | Usage.Normal | Usage.TextureCoordinates, material); mpb.box(w, h, d); Model boxModel = mb.end(); Node node = main.node("box-" + i, boxModel); node.translation.set(tmp); q.idt(); node.rotation.set(q); } //node.translation.set(MathUtils.random(x), 0f, MathUtils.random(y)); //q.set(Vector3.X, -90); mtx.set(q); mtx.setTranslation(tmp); btCollisionObject obj = Physics.inst.createBoxObject(tmp.set(w/2, h/2, d/2)); obj.setWorldTransform(mtx); Physics.applyStaticGeometryCollisionFlags(obj); Physics.inst.addStaticGeometryToWorld(obj); } Model finalModel = main.end(); instance = new ModelInstance(finalModel); }
Example #8
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 #9
Source File: CubesShaderProvider.java From Cubes with MIT License | 5 votes |
@Override public void begin(ShaderProgram program, Camera camera, RenderContext context) { TextureAttribute textureAttribute = AmbientOcclusion.getTextureAttribute(); ao_unit = context.textureBinder.bind(textureAttribute.textureDescription); program.setUniformi(u_aoTexture, ao_unit); program.setUniformf(u_aoUVTransform, textureAttribute.offsetU, textureAttribute.offsetV, textureAttribute.scaleU, textureAttribute.scaleV); program.setUniformf(u_aoStrength, AmbientOcclusion.getStrength().strength); }
Example #10
Source File: GameScene.java From GdxDemo3D with Apache License 2.0 | 5 votes |
private void setVColorBlendAttributes() { Array<String> modelsIdsInScene = assets.getPlaceholderIdsByType(BlenderModel.class); Array<BlenderModel> instancesWithId = new Array<BlenderModel>(); for (String id : modelsIdsInScene) { instancesWithId.clear(); assets.getPlaceholders(id, BlenderModel.class, instancesWithId); for (BlenderModel blenderModel : instancesWithId) { // Maybe check if // renderable.meshPart.mesh.getVertexAttribute(VertexAttributes.Usage.ColorUnpacked) != null if (blenderModel.custom_properties.containsKey("v_color_material_blend")) { Model model = assets.getAsset(id, Model.class); String redMaterialName = blenderModel.custom_properties.get("v_color_material_red"); String greenMaterialName = blenderModel.custom_properties.get("v_color_material_green"); String blueMaterialName = blenderModel.custom_properties.get("v_color_material_blue"); TextureAttribute redTexAttr = (TextureAttribute) model.getMaterial(redMaterialName).get(TextureAttribute.Diffuse); TextureAttribute greenTexAttr = (TextureAttribute) model.getMaterial(greenMaterialName).get(TextureAttribute.Diffuse); TextureAttribute blueTexAttr = (TextureAttribute) model.getMaterial(blueMaterialName).get(TextureAttribute.Diffuse); VertexColorTextureBlend redAttribute = new VertexColorTextureBlend(VertexColorTextureBlend.Red, redTexAttr.textureDescription.texture); VertexColorTextureBlend greenAttribute = new VertexColorTextureBlend(VertexColorTextureBlend.Green, greenTexAttr.textureDescription.texture); VertexColorTextureBlend blueAttribute = new VertexColorTextureBlend(VertexColorTextureBlend.Blue, blueTexAttr.textureDescription.texture); for (Node node : model.nodes) { for (NodePart nodePart : node.parts) { nodePart.material.set(redAttribute, greenAttribute, blueAttribute); } } break; } } } }
Example #11
Source File: MaterialAsset.java From Mundus with Apache License 2.0 | 5 votes |
/** * Applies this material asset to the libGDX material. * * @param material * @return */ public Material applyToMaterial(Material material) { if (diffuseColor != null) { material.set(new ColorAttribute(ColorAttribute.Diffuse, diffuseColor)); } if (diffuseTexture != null) { material.set(new TextureAttribute(TextureAttribute.Diffuse, diffuseTexture.getTexture())); } else { material.remove(TextureAttribute.Diffuse); } material.set(new FloatAttribute(FloatAttribute.Shininess, shininess)); return material; }
Example #12
Source File: ModelShader.java From Mundus with Apache License 2.0 | 5 votes |
@Override public void render(Renderable renderable) { final MundusEnvironment env = (MundusEnvironment) renderable.environment; setLights(env); set(UNIFORM_TRANS_MATRIX, renderable.worldTransform); // texture uniform TextureAttribute diffuseTexture = ((TextureAttribute) (renderable.material.get(TextureAttribute.Diffuse))); ColorAttribute diffuseColor = ((ColorAttribute) (renderable.material.get(ColorAttribute.Diffuse))); if (diffuseTexture != null) { set(UNIFORM_MATERIAL_DIFFUSE_TEXTURE, diffuseTexture.textureDescription.texture); set(UNIFORM_MATERIAL_DIFFUSE_USE_TEXTURE, 1); } else { set(UNIFORM_MATERIAL_DIFFUSE_COLOR, diffuseColor.color); set(UNIFORM_MATERIAL_DIFFUSE_USE_TEXTURE, 0); } // shininess float shininess = ((FloatAttribute)renderable.material.get(FloatAttribute.Shininess)).value; set(UNIFORM_MATERIAL_SHININESS, shininess); // Fog final Fog fog = env.getFog(); if (fog == null) { set(UNIFORM_FOG_DENSITY, 0f); set(UNIFORM_FOG_GRADIENT, 0f); } else { set(UNIFORM_FOG_DENSITY, fog.density); set(UNIFORM_FOG_GRADIENT, fog.gradient); set(UNIFORM_FOG_COLOR, fog.color); } // bind attributes, bind mesh & render; then unbinds everything renderable.meshPart.render(program); }
Example #13
Source File: GameRenderer.java From Radix with MIT License | 5 votes |
private void drawBlockSelection() { int curProgressInt = Math.round(RadixClient.getInstance().getPlayer().getBreakPercent() * 10) - 1; if ((blockBreakModel == null || blockBreakStage != curProgressInt) && curProgressInt >= 0) { if (blockBreakModel != null) blockBreakModel.dispose(); blockBreakStage = curProgressInt; ModelBuilder builder = new ModelBuilder(); blockBreakModel = builder.createBox(1f, 1f, 1f, new Material(TextureAttribute.createDiffuse(blockBreakStages[blockBreakStage]), new BlendingAttribute(), FloatAttribute.createAlphaTest(0.25f)), VertexAttributes.Usage.Position | VertexAttributes.Usage.TextureCoordinates); blockBreakModelInstance = new ModelInstance(blockBreakModel); } Vec3i curBlk = RadixClient.getInstance().getSelectedBlock(); if (curBlk != null && curProgressInt >= 0) { Gdx.gl.glPolygonOffset(100000, 2000000); blockOverlayBatch.begin(RadixClient.getInstance().getCamera()); blockBreakModelInstance.transform.translate(curBlk.x + 0.5f, curBlk.y + 0.5f, curBlk.z + 0.5f); blockOverlayBatch.render(blockBreakModelInstance); blockBreakModelInstance.transform.translate(-(curBlk.x + 0.5f), -(curBlk.y + 0.5f), -(curBlk.z + 0.5f)); blockOverlayBatch.end(); Gdx.gl.glPolygonOffset(100000, -2000000); } }
Example #14
Source File: EntityModel.java From Radix with MIT License | 5 votes |
private static ModelInstance getInstance(String objPath, String texturePath) { Model model = loader.loadModel(Gdx.files.internal(objPath), new ObjLoader.ObjLoaderParameters(true)); ModelInstance instance = new ModelInstance(model); Texture texture = new Texture(Gdx.files.internal(texturePath)); instance.materials.get(0).set(TextureAttribute.createDiffuse(texture)); return instance; }
Example #15
Source File: Entity.java From Radix with MIT License | 5 votes |
public void render(ModelBatch batch) { if (model != null) { // TODO: support subtle action. need to create instance every time? ModelInstance instance = new ModelInstance(model); instance.materials.get(0).set(TextureAttribute.createDiffuse(texture)); instance.transform.translate(position.getX(), position.getY(), position.getZ()); batch.render(instance); } }
Example #16
Source File: PBRShader.java From gdx-gltf with Apache License 2.0 | 4 votes |
@Override public void set (BaseShader shader, int inputID, Renderable renderable, Attributes combinedAttributes) { final int unit = shader.context.textureBinder.bind(((TextureAttribute)(combinedAttributes .get(PBRTextureAttribute.BaseColorTexture))).textureDescription); shader.set(inputID, unit); }
Example #17
Source File: AmbientOcclusion.java From Cubes with MIT License | 4 votes |
public static TextureAttribute getTextureAttribute() { if (!load()) return null; return loadedTextureAttribute; }
Example #18
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 #19
Source File: TerrainChunk.java From gdx-proto with Apache License 2.0 | 4 votes |
public TerrainChunk setNormalMap(Texture normal) { modelInstance.materials.get(0).set(TextureAttribute.createNormal(normal)); return this; }
Example #20
Source File: Chunk.java From Radix with MIT License | 4 votes |
private void updateModelInstances() { if(opaqueFaces != null) { if(opaqueModel != null) opaqueModel.dispose(); Mesh opaqueMesh = mesher.meshFaces(opaqueFaces, meshBuilder); modelBuilder.begin(); modelBuilder.part(String.format("c-%d,%d", startPosition.x, startPosition.z), opaqueMesh, GL20.GL_TRIANGLES, new Material(TextureAttribute.createDiffuse(NormalBlockRenderer.getBlockMap()))); opaqueModel = modelBuilder.end(); opaqueModelInstance = new ModelInstance(opaqueModel) { @Override public Renderable getRenderable(final Renderable out, final Node node, final NodePart nodePart) { super.getRenderable(out, node, nodePart); if(RadixClient.getInstance().isWireframe()) { out.primitiveType = GL20.GL_LINES; } else { out.primitiveType = GL20.GL_TRIANGLES; } return out; } }; opaqueFaces = null; } if(translucentFaces != null) { if(translucentModel != null) translucentModel.dispose(); Mesh translucentMesh = mesher.meshFaces(translucentFaces, meshBuilder); modelBuilder.begin(); modelBuilder.part(String.format("c-%d,%d-t", startPosition.x, startPosition.z), translucentMesh, GL20.GL_TRIANGLES, new Material(TextureAttribute.createDiffuse(NormalBlockRenderer.getBlockMap()), new BlendingAttribute(), FloatAttribute.createAlphaTest(0.25f))); translucentModel = modelBuilder.end(); translucentModelInstance = new ModelInstance(translucentModel) { @Override public Renderable getRenderable(final Renderable out, final Node node, final NodePart nodePart) { super.getRenderable(out, node, nodePart); if(RadixClient.getInstance().isWireframe()) { out.primitiveType = GL20.GL_LINES; } else { out.primitiveType = GL20.GL_TRIANGLES; } return out; } }; translucentFaces = null; } }
Example #21
Source File: PBRShader.java From gdx-gltf with Apache License 2.0 | 4 votes |
@Override public void set (BaseShader shader, int inputID, Renderable renderable, Attributes combinedAttributes) { final int unit = shader.context.textureBinder.bind(((TextureAttribute)(combinedAttributes .get(PBRTextureAttribute.OcclusionTexture))).textureDescription); shader.set(inputID, unit); }
Example #22
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); }
Example #23
Source File: PBRShader.java From gdx-gltf with Apache License 2.0 | 4 votes |
@Override public void set (BaseShader shader, int inputID, Renderable renderable, Attributes combinedAttributes) { final int unit = shader.context.textureBinder.bind(((TextureAttribute)(combinedAttributes .get(PBRTextureAttribute.MetallicRoughnessTexture))).textureDescription); shader.set(inputID, unit); }
Example #24
Source File: PBRShader.java From gdx-gltf with Apache License 2.0 | 4 votes |
@Override public void set (BaseShader shader, int inputID, Renderable renderable, Attributes combinedAttributes) { final int unit = shader.context.textureBinder.bind(((TextureAttribute)(combinedAttributes .get(PBRTextureAttribute.NormalTexture))).textureDescription); shader.set(inputID, unit); }
Example #25
Source File: PBRShader.java From gdx-gltf with Apache License 2.0 | 4 votes |
@Override public void set (BaseShader shader, int inputID, Renderable renderable, Attributes combinedAttributes) { final int unit = shader.context.textureBinder.bind(((TextureAttribute)(combinedAttributes .get(PBRTextureAttribute.EmissiveTexture))).textureDescription); shader.set(inputID, unit); }