Example usage for com.badlogic.gdx.graphics.g3d.materials ColorAttribute ColorAttribute

List of usage examples for com.badlogic.gdx.graphics.g3d.materials ColorAttribute ColorAttribute

Introduction

In this page you can find the example usage for com.badlogic.gdx.graphics.g3d.materials ColorAttribute ColorAttribute.

Prototype

public ColorAttribute(Color color, String name) 

Source Link

Document

Creates a MaterialAttribute that is a pure Color .

Usage

From source file:com.badlogic.gdx.graphics.g3d.test.StillModelViewerGL20.java

License:Apache License

@Override
public void create() {
    long start = System.nanoTime();
    model = ModelLoaderRegistry.loadStillModel(Gdx.files.internal(fileName));
    Gdx.app.log("StillModelViewer", "loading took: " + (System.nanoTime() - start) / 1000000000.0f);

    if (textureFileNames.length != 0) {
        textures = new Texture[textureFileNames.length];
        for (int i = 0; i < textureFileNames.length; i++) {
            textures[i] = new Texture(Gdx.files.internal(textureFileNames[i]), i > 0 ? false : true);
        }//from  w  w  w . j a  v  a2 s. c om
    }

    model.getBoundingBox(bounds);
    float len = bounds.getDimensions().len();
    System.out.println("bounds: " + bounds);

    cam = new PerspectiveCamera(60, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    cam.position.set(bounds.getCenter().cpy().add(len / 2, len / 2, len / 2));
    cam.lookAt(bounds.getCenter().x, bounds.getCenter().y, bounds.getCenter().z);
    cam.near = 0.1f;
    cam.far = 64;

    batch = new SpriteBatch();
    font = new BitmapFont();

    // shader1 = ShaderLoader.createShader("light", "light");
    // shader2 = ShaderLoader.createShader("vertexpath", "vertexpath");

    lightManager = new LightManager(4, LightQuality.VERTEX);
    lightManager.dirLight = new DirectionalLight();
    lightManager.dirLight.color.set(0.09f, 0.07f, 0.09f, 0);
    lightManager.dirLight.direction.set(-.4f, -1, 0.03f).nor();

    for (int i = 0; i < 4; i++) {
        PointLight l = new PointLight();
        l.position.set(-MathUtils.random(8) + 4, MathUtils.random(3), -MathUtils.random(6) + 3);

        l.color.r = MathUtils.random();
        l.color.b = MathUtils.random();
        l.color.g = MathUtils.random();
        l.intensity = 3;
        lightManager.addLigth(l);
    }
    lightManager.ambientLight.set(.03f, 0.05f, 0.06f, 0);

    protoRenderer = new PrototypeRendererGL20(lightManager);
    protoRenderer.cam = cam;

    MaterialAttribute c1 = new ColorAttribute(new Color(0.5f, 0.51f, 0.51f, 1.0f), ColorAttribute.specular);
    MaterialAttribute c2 = new ColorAttribute(new Color(0.95f, 0.95f, 0.95f, 1.0f), ColorAttribute.diffuse);
    MaterialAttribute t0 = new TextureAttribute(textures[0], 0, TextureAttribute.diffuseTexture);
    Material material = new Material("basic", c1, c2, t0);

    model.setMaterial(material);
    instance = new StillModelNode();
    instance.getTransform().translate(-len / 2, -1, 2);
    instance.radius = bounds.getDimensions().len() / 2;

    instance2 = new StillModelNode();
    instance2.getTransform().translate(len / 2, -1, -7);

    instance2.radius = instance.radius;

}

From source file:com.badlogic.gdx.graphics.g3d.test.Viewer.java

License:Apache License

@Override
public void create() {

    Texture texture = new Texture(Gdx.files.internal("data/models/ninja.jpg"));
    Material mat = new Material("mat", new TextureAttribute(texture, 0, "s_tex"),
            new ColorAttribute(Color.CYAN, ColorAttribute.diffuse));
    model = new OgreXmlLoader().load(Gdx.files.internal("data/models/ninja.mesh.xml"),
            Gdx.files.internal("data/models/ninja.skeleton.xml"));
    model.setMaterial(mat);/*from w  w w  .ja  v  a 2  s.co m*/

    cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    BoundingBox bounds = model.subMeshes[0].mesh.calculateBoundingBox();
    cam.position.set(bounds.getCenter().cpy().add(100, 100, 100));
    cam.lookAt(bounds.getCenter().x, bounds.getCenter().y, bounds.getCenter().z);
    cam.near = 0.1f;
    cam.far = 1000;

    renderer = new ImmediateModeRenderer10();
    batch = new SpriteBatch();
    font = new BitmapFont();

    for (String name : model.skeleton.animations.keys())
        animNames.add(name);
    animation = animNames.get(0);

}