Search in sources :

Example 11 with ModelBatch

use of com.badlogic.gdx.graphics.g3d.ModelBatch in project libgdx by libgdx.

the class Animation3DTest method create.

@Override
public void create() {
    super.create();
    lights = new Environment();
    lights.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.4f, 0.4f, 0.4f, 1.f));
    lights.add((shadowLight = new DirectionalShadowLight(1024, 1024, 30f, 30f, 1f, 100f)).set(0.8f, 0.8f, 0.8f, -.4f, -.4f, -.4f));
    lights.shadowMap = shadowLight;
    inputController.rotateLeftKey = inputController.rotateRightKey = inputController.forwardKey = inputController.backwardKey = 0;
    cam.position.set(25, 25, 25);
    cam.lookAt(0, 0, 0);
    cam.update();
    modelsWindow.setVisible(false);
    assets.load("data/g3d/skydome.g3db", Model.class);
    assets.load("data/g3d/concrete.png", Texture.class);
    assets.load("data/tree.png", Texture.class);
    assets.load("data/g3d/ship.obj", Model.class);
    loading = true;
    trForward.translation.set(0, 0, 8f);
    trBackward.translation.set(0, 0, -8f);
    trLeft.rotation.setFromAxis(Vector3.Y, 90);
    trRight.rotation.setFromAxis(Vector3.Y, -90);
    ModelBuilder builder = new ModelBuilder();
    builder.begin();
    builder.node().id = "floor";
    MeshPartBuilder part = builder.part("floor", GL20.GL_TRIANGLES, Usage.Position | Usage.TextureCoordinates | Usage.Normal, new Material("concrete"));
    ((MeshBuilder) part).ensureRectangles(1600);
    for (float x = -200f; x < 200f; x += 10f) {
        for (float z = -200f; z < 200f; z += 10f) {
            part.rect(x, 0, z + 10f, x + 10f, 0, z + 10f, x + 10f, 0, z, x, 0, z, 0, 1, 0);
        }
    }
    builder.node().id = "tree";
    part = builder.part("tree", GL20.GL_TRIANGLES, Usage.Position | Usage.TextureCoordinates | Usage.Normal, new Material("tree"));
    part.rect(0f, 0f, -10f, 10f, 0f, -10f, 10f, 10f, -10f, 0f, 10f, -10f, 0, 0, 1f);
    part.setUVRange(1, 0, 0, 1);
    part.rect(10f, 0f, -10f, 0f, 0f, -10f, 0f, 10f, -10f, 10f, 10f, -10f, 0, 0, -1f);
    floorModel = builder.end();
    shadowBatch = new ModelBatch(new DepthShaderProvider());
}
Also used : ModelBuilder(com.badlogic.gdx.graphics.g3d.utils.ModelBuilder) DirectionalShadowLight(com.badlogic.gdx.graphics.g3d.environment.DirectionalShadowLight) MeshBuilder(com.badlogic.gdx.graphics.g3d.utils.MeshBuilder) ModelBatch(com.badlogic.gdx.graphics.g3d.ModelBatch) Environment(com.badlogic.gdx.graphics.g3d.Environment) Material(com.badlogic.gdx.graphics.g3d.Material) MeshPartBuilder(com.badlogic.gdx.graphics.g3d.utils.MeshPartBuilder) ColorAttribute(com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute) DepthShaderProvider(com.badlogic.gdx.graphics.g3d.utils.DepthShaderProvider)

Example 12 with ModelBatch

use of com.badlogic.gdx.graphics.g3d.ModelBatch in project libgdx by libgdx.

the class BaseG3dTest method create.

@Override
public void create() {
    if (assets == null)
        assets = new AssetManager();
    modelBatch = new ModelBatch();
    cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    cam.position.set(10f, 10f, 10f);
    cam.lookAt(0, 0, 0);
    cam.near = 0.1f;
    cam.far = 1000f;
    cam.update();
    createAxes();
    Gdx.input.setInputProcessor(inputController = new CameraInputController(cam));
}
Also used : CameraInputController(com.badlogic.gdx.graphics.g3d.utils.CameraInputController) AssetManager(com.badlogic.gdx.assets.AssetManager) ModelBatch(com.badlogic.gdx.graphics.g3d.ModelBatch) PerspectiveCamera(com.badlogic.gdx.graphics.PerspectiveCamera)

Example 13 with ModelBatch

use of com.badlogic.gdx.graphics.g3d.ModelBatch in project libgdx by libgdx.

the class Basic3DSceneTest method create.

@Override
public void create() {
    modelBatch = new ModelBatch();
    lights = new Environment();
    lights.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.4f, 0.4f, 0.4f, 1.f));
    lights.add(new DirectionalLight().set(0.8f, 0.8f, 0.8f, -1f, -0.8f, -0.2f));
    cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    cam.position.set(0f, 7f, 10f);
    cam.lookAt(0, 0, 0);
    cam.near = 0.1f;
    cam.far = 300f;
    cam.update();
    camController = new CameraInputController(cam);
    Gdx.input.setInputProcessor(camController);
    assets = new AssetManager();
    assets.load("data/g3d/invaders.g3dj", Model.class);
    loading = true;
}
Also used : CameraInputController(com.badlogic.gdx.graphics.g3d.utils.CameraInputController) AssetManager(com.badlogic.gdx.assets.AssetManager) DirectionalLight(com.badlogic.gdx.graphics.g3d.environment.DirectionalLight) ModelBatch(com.badlogic.gdx.graphics.g3d.ModelBatch) Environment(com.badlogic.gdx.graphics.g3d.Environment) PerspectiveCamera(com.badlogic.gdx.graphics.PerspectiveCamera) ColorAttribute(com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute)

Example 14 with ModelBatch

use of com.badlogic.gdx.graphics.g3d.ModelBatch in project libgdx by libgdx.

the class KTXTest method create.

@Override
public void create() {
    // Cubemap test
    String cubemapVS = //
    "" + //
    "attribute vec3 a_position;\n" + //
    "uniform mat4 u_projViewTrans;\n" + //
    "uniform mat4 u_worldTrans;\n" + //
    "\n" + //
    "varying vec3 v_cubeMapUV;\n" + //
    "\n" + //
    "void main() {\n" + //
    "   vec4 g_position = vec4(a_position, 1.0);\n" + //
    "   g_position = u_worldTrans * g_position;\n" + //
    "   v_cubeMapUV = normalize(g_position.xyz);\n" + //
    "   gl_Position = u_projViewTrans * g_position;\n" + "}";
    String cubemapFS = //
    "" + //
    "#ifdef GL_ES\n" + //
    "precision mediump float;\n" + //
    "#endif\n" + //
    "uniform samplerCube u_environmentCubemap;\n" + //
    "varying vec3 v_cubeMapUV;\n" + //
    "void main() {\n" + //
    "	gl_FragColor = vec4(textureCube(u_environmentCubemap, v_cubeMapUV).rgb, 1.0);\n" + "}\n";
    modelBatch = new ModelBatch(new DefaultShaderProvider(new Config(cubemapVS, cubemapFS)));
    cubemap = new Cubemap(new KTXTextureData(Gdx.files.internal("data/cubemap.zktx"), true));
    cubemap.setFilter(TextureFilter.MipMapLinearLinear, TextureFilter.Linear);
    environment = new Environment();
    environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.1f, 0.1f, 0.1f, 1.f));
    environment.add(new DirectionalLight().set(0.8f, 0.8f, 0.8f, -0.5f, -1.0f, -0.8f));
    environment.set(new CubemapAttribute(CubemapAttribute.EnvironmentMap, cubemap));
    perspectiveCamera = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    perspectiveCamera.position.set(10f, 10f, 10f);
    perspectiveCamera.lookAt(0, 0, 0);
    perspectiveCamera.near = 0.1f;
    perspectiveCamera.far = 300f;
    perspectiveCamera.update();
    ModelBuilder modelBuilder = new ModelBuilder();
    model = modelBuilder.createBox(5f, 5f, 5f, new Material(ColorAttribute.createDiffuse(Color.GREEN)), Usage.Position | Usage.Normal);
    instance = new ModelInstance(model);
    Gdx.input.setInputProcessor(new InputMultiplexer(this, inputController = new CameraInputController(perspectiveCamera)));
    // 2D texture test
    String etc1aVS = //
    "" + //
    "uniform mat4 u_projTrans;\n" + //
    "\n" + //
    "attribute vec4 a_position;\n" + //
    "attribute vec2 a_texCoord0;\n" + //
    "attribute vec4 a_color;\n" + //
    "\n" + //
    "varying vec4 v_color;\n" + //
    "varying vec2 v_texCoord;\n" + //
    "\n" + //
    "void main() {\n" + //
    "   gl_Position = u_projTrans * a_position;\n" + //
    "   v_texCoord = a_texCoord0;\n" + //
    "   v_color = a_color;\n" + //
    "}\n";
    String etc1aFS = //
    "" + //
    "#ifdef GL_ES\n" + //
    "precision mediump float;\n" + //
    "#endif\n" + //
    "uniform sampler2D u_texture;\n" + //
    "\n" + //
    "varying vec4 v_color;\n" + //
    "varying vec2 v_texCoord;\n" + //
    "\n" + //
    "void main() {\n" + //
    "   vec3 col = texture2D(u_texture, v_texCoord.st).rgb;\n" + //
    "   float alpha = texture2D(u_texture, v_texCoord.st + vec2(0.0, 0.5)).r;\n" + //
    "   gl_FragColor = vec4(col, alpha) * v_color;\n" + //
    "}\n";
    etc1aShader = new ShaderProgram(etc1aVS, etc1aFS);
    orthoCamera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    image = new Texture("data/egg.zktx");
    batch = new SpriteBatch(100, etc1aShader);
}
Also used : DefaultShaderProvider(com.badlogic.gdx.graphics.g3d.utils.DefaultShaderProvider) Config(com.badlogic.gdx.graphics.g3d.shaders.DefaultShader.Config) CubemapAttribute(com.badlogic.gdx.graphics.g3d.attributes.CubemapAttribute) OrthographicCamera(com.badlogic.gdx.graphics.OrthographicCamera) Material(com.badlogic.gdx.graphics.g3d.Material) PerspectiveCamera(com.badlogic.gdx.graphics.PerspectiveCamera) KTXTextureData(com.badlogic.gdx.graphics.glutils.KTXTextureData) Texture(com.badlogic.gdx.graphics.Texture) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) ModelInstance(com.badlogic.gdx.graphics.g3d.ModelInstance) ModelBuilder(com.badlogic.gdx.graphics.g3d.utils.ModelBuilder) CameraInputController(com.badlogic.gdx.graphics.g3d.utils.CameraInputController) InputMultiplexer(com.badlogic.gdx.InputMultiplexer) ShaderProgram(com.badlogic.gdx.graphics.glutils.ShaderProgram) DirectionalLight(com.badlogic.gdx.graphics.g3d.environment.DirectionalLight) ModelBatch(com.badlogic.gdx.graphics.g3d.ModelBatch) Environment(com.badlogic.gdx.graphics.g3d.Environment) Cubemap(com.badlogic.gdx.graphics.Cubemap) ColorAttribute(com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute)

Example 15 with ModelBatch

use of com.badlogic.gdx.graphics.g3d.ModelBatch in project libgdx by libgdx.

the class FramebufferToTextureTest method create.

@Override
public void create() {
    texture = new Texture(Gdx.files.internal("data/badlogic.jpg"), true);
    texture.setFilter(TextureFilter.MipMap, TextureFilter.Linear);
    ObjLoader objLoader = new ObjLoader();
    mesh = objLoader.loadModel(Gdx.files.internal("data/cube.obj"));
    mesh.materials.get(0).set(new TextureAttribute(TextureAttribute.Diffuse, texture));
    modelInstance = new ModelInstance(mesh);
    modelBatch = new ModelBatch();
    cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    cam.position.set(3, 3, 3);
    cam.direction.set(-1, -1, -1);
    batch = new SpriteBatch();
    font = new BitmapFont();
}
Also used : ModelInstance(com.badlogic.gdx.graphics.g3d.ModelInstance) ModelBatch(com.badlogic.gdx.graphics.g3d.ModelBatch) ObjLoader(com.badlogic.gdx.graphics.g3d.loader.ObjLoader) PerspectiveCamera(com.badlogic.gdx.graphics.PerspectiveCamera) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) Texture(com.badlogic.gdx.graphics.Texture) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) TextureAttribute(com.badlogic.gdx.graphics.g3d.attributes.TextureAttribute)

Aggregations

ModelBatch (com.badlogic.gdx.graphics.g3d.ModelBatch)24 PerspectiveCamera (com.badlogic.gdx.graphics.PerspectiveCamera)18 ColorAttribute (com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute)16 ModelInstance (com.badlogic.gdx.graphics.g3d.ModelInstance)14 Environment (com.badlogic.gdx.graphics.g3d.Environment)13 Material (com.badlogic.gdx.graphics.g3d.Material)12 DirectionalLight (com.badlogic.gdx.graphics.g3d.environment.DirectionalLight)11 ModelBuilder (com.badlogic.gdx.graphics.g3d.utils.ModelBuilder)10 CameraInputController (com.badlogic.gdx.graphics.g3d.utils.CameraInputController)8 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)7 Texture (com.badlogic.gdx.graphics.Texture)5 DefaultShaderProvider (com.badlogic.gdx.graphics.g3d.utils.DefaultShaderProvider)5 InputMultiplexer (com.badlogic.gdx.InputMultiplexer)4 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)4 ObjLoader (com.badlogic.gdx.graphics.g3d.loader.ObjLoader)4 AssetManager (com.badlogic.gdx.assets.AssetManager)3 Model (com.badlogic.gdx.graphics.g3d.Model)3 TextureAttribute (com.badlogic.gdx.graphics.g3d.attributes.TextureAttribute)3 DirectionalShadowLight (com.badlogic.gdx.graphics.g3d.environment.DirectionalShadowLight)3 DepthShaderProvider (com.badlogic.gdx.graphics.g3d.utils.DepthShaderProvider)3