Java Code Examples for com.badlogic.gdx.graphics.g3d.Material#set()

The following examples show how to use com.badlogic.gdx.graphics.g3d.Material#set() . 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: Terrain.java    From Mundus with Apache License 2.0 6 votes vote down vote up
private Terrain(int vertexResolution) {
    this.transform = new Matrix4();
    this.attribs = MeshBuilder.createAttributes(VertexAttributes.Usage.Position | VertexAttributes.Usage.Normal
            | VertexAttributes.Usage.TextureCoordinates);
    this.posPos = attribs.getOffset(VertexAttributes.Usage.Position, -1);
    this.norPos = attribs.getOffset(VertexAttributes.Usage.Normal, -1);
    this.uvPos = attribs.getOffset(VertexAttributes.Usage.TextureCoordinates, -1);
    this.stride = attribs.vertexSize / 4;

    this.vertexResolution = vertexResolution;
    this.heightData = new float[vertexResolution * vertexResolution];

    this.terrainTexture = new TerrainTexture();
    this.terrainTexture.setTerrain(this);
    material = new Material();
    material.set(new TerrainTextureAttribute(TerrainTextureAttribute.ATTRIBUTE_SPLAT0, terrainTexture));
}
 
Example 2
Source File: ModelManager.java    From gdx-proto with Apache License 2.0 6 votes vote down vote up
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 3
Source File: Shadow.java    From gdx-proto with Apache License 2.0 6 votes vote down vote up
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 4
Source File: MaterialAsset.java    From Mundus with Apache License 2.0 5 votes vote down vote up
/**
 * 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 5
Source File: ModelFactory.java    From GdxDemo3D with Apache License 2.0 5 votes vote down vote up
public static void createOutlineModel(Model model, Color outlineColor, float fattenAmount) {
	fatten(model, fattenAmount);
	for (Material m : model.materials) {
		m.clear();
		m.set(new IntAttribute(IntAttribute.CullFace, Gdx.gl.GL_FRONT));
		m.set(ColorAttribute.createDiffuse(outlineColor));
	}
}
 
Example 6
Source File: ModelFactory.java    From GdxDemo3D with Apache License 2.0 5 votes vote down vote up
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 7
Source File: Box.java    From gdx-proto with Apache License 2.0 5 votes vote down vote up
/** 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: DemoMotionGdxAdapter.java    From thunderboard-android with Apache License 2.0 4 votes vote down vote up
public void turnOnLights() {
    for (Material mat : lightMaterials) {
        mat.set(new ColorAttribute(ColorAttribute.Emissive, this.ledColor));
    }
}