use of com.badlogic.gdx.graphics.g3d.ModelBatch in project libgdx by libgdx.
the class CullTest method create.
@Override
public void create() {
ModelBuilder builder = new ModelBuilder();
sphere = builder.createSphere(2f, 2f, 2f, 16, 16, new Material(new ColorAttribute(ColorAttribute.Diffuse, Color.WHITE)), Usage.Position | Usage.Normal);
// cam = new PerspectiveCamera(45, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
cam = new OrthographicCamera(45, 45 * (Gdx.graphics.getWidth() / (float) Gdx.graphics.getHeight()));
cam.near = 1;
cam.far = 200;
Random rand = new Random();
for (int i = 0; i < instances.length; i++) {
pos.set(rand.nextFloat() * 100 - rand.nextFloat() * 100, rand.nextFloat() * 100 - rand.nextFloat() * 100, rand.nextFloat() * -100 - 3);
instances[i] = new ModelInstance(sphere, pos);
}
modelBatch = new ModelBatch();
batch = new SpriteBatch();
font = new BitmapFont();
// Gdx.graphics.setVSync(true);
// Gdx.app.log("CullTest", "" + Gdx.graphics.getBufferFormat().toString());
}
use of com.badlogic.gdx.graphics.g3d.ModelBatch in project libgdx by libgdx.
the class VoxelTest method create.
@Override
public void create() {
spriteBatch = new SpriteBatch();
font = new BitmapFont();
modelBatch = new ModelBatch();
DefaultShader.defaultCullFace = GL20.GL_FRONT;
camera = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
camera.near = 0.5f;
camera.far = 1000;
controller = new FirstPersonCameraController(camera);
Gdx.input.setInputProcessor(controller);
lights = new Environment();
lights.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.4f, 0.4f, 0.4f, 1.f));
lights.add(new DirectionalLight().set(1, 1, 1, 0, -1, 0));
Texture texture = new Texture(Gdx.files.internal("data/g3d/tiles.png"));
TextureRegion[][] tiles = TextureRegion.split(texture, 32, 32);
MathUtils.random.setSeed(0);
voxelWorld = new VoxelWorld(tiles[0], 20, 4, 20);
PerlinNoiseGenerator.generateVoxels(voxelWorld, 0, 63, 10);
float camX = voxelWorld.voxelsX / 2f;
float camZ = voxelWorld.voxelsZ / 2f;
float camY = voxelWorld.getHighest(camX, camZ) + 1.5f;
camera.position.set(camX, camY, camZ);
}
use of com.badlogic.gdx.graphics.g3d.ModelBatch in project libgdx by libgdx.
the class ShaderCollectionTest method create.
@Override
public void create() {
super.create();
environment = new Environment();
environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.1f, 0.1f, 0.1f, 1.f));
environment.add(dirLight = new DirectionalLight().set(0.8f, 0.8f, 0.8f, -0.5f, -1.0f, -0.8f));
shaderProvider = new TestShaderProvider();
shaderBatch = new ModelBatch(shaderProvider);
cam.position.set(1, 1, 1);
cam.lookAt(0, 0, 0);
cam.update();
showAxes = true;
onModelClicked("g3d/shapes/teapot.g3dj");
shaderRoot = (hotLoadFolder != null && Gdx.app.getType() == ApplicationType.Desktop) ? Gdx.files.absolute(hotLoadFolder) : Gdx.files.internal("data/g3d/shaders");
}
use of com.badlogic.gdx.graphics.g3d.ModelBatch in project libgdx by libgdx.
the class ShaderTest method create.
@Override
public void create() {
modelBatch = new ModelBatch(new DefaultShaderProvider() {
@Override
protected Shader createShader(Renderable renderable) {
if (renderable.material.has(TestAttribute.ID))
return new TestShader(renderable);
return super.createShader(renderable);
}
});
cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
cam.position.set(0f, 0f, 20f);
cam.lookAt(0, 0, 0);
cam.near = 1f;
cam.far = 300f;
cam.update();
camController = new CameraInputController(cam);
Gdx.input.setInputProcessor(camController);
Material testMaterial1 = new Material("TestMaterial1", new TestAttribute(1f));
Material redMaterial = new Material("RedMaterial", ColorAttribute.createDiffuse(Color.RED));
Material testMaterial2 = new Material("TestMaterial2", new TestAttribute(1f), ColorAttribute.createDiffuse(Color.BLUE));
ModelBuilder builder = new ModelBuilder();
Node node;
builder.begin();
node = builder.node();
node.id = "testCone1";
node.translation.set(-10, 0f, 0f);
builder.part("testCone", GL20.GL_TRIANGLES, Usage.Position, testMaterial1).cone(5, 5, 5, 20);
node = builder.node();
node.id = "redSphere";
builder.part("redSphere", GL20.GL_TRIANGLES, Usage.Position, redMaterial).sphere(5, 5, 5, 20, 20);
node = builder.node();
node.id = "testCone1";
node.translation.set(10, 0f, 0f);
builder.part("testCone", GL20.GL_TRIANGLES, Usage.Position, testMaterial2).cone(5, 5, 5, 20);
model = builder.end();
ModelInstance modelInstance;
modelInstance = new ModelInstance(model);
testAttribute1 = (TestAttribute) modelInstance.getMaterial("TestMaterial1").get(TestAttribute.ID);
testAttribute2 = (TestAttribute) modelInstance.getMaterial("TestMaterial2").get(TestAttribute.ID);
instances.add(modelInstance);
}
use of com.badlogic.gdx.graphics.g3d.ModelBatch in project libgdx by libgdx.
the class ShadowMappingTest method create.
@Override
public void create() {
modelBatch = new ModelBatch();
environment = new Environment();
environment.set(new ColorAttribute(ColorAttribute.AmbientLight, .4f, .4f, .4f, 1f));
environment.add((shadowLight = new DirectionalShadowLight(1024, 1024, 30f, 30f, 1f, 100f)).set(0.8f, 0.8f, 0.8f, -1f, -.8f, -.2f));
environment.shadowMap = shadowLight;
cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
cam.position.set(0f, 7f, 10f);
cam.lookAt(0, 0, 0);
cam.near = 1f;
cam.far = 50f;
cam.update();
ModelBuilder modelBuilder = new ModelBuilder();
modelBuilder.begin();
MeshPartBuilder mpb = modelBuilder.part("parts", GL20.GL_TRIANGLES, Usage.Position | Usage.Normal | Usage.ColorUnpacked, new Material(ColorAttribute.createDiffuse(Color.WHITE)));
mpb.setColor(1f, 1f, 1f, 1f);
mpb.box(0, -1.5f, 0, 10, 1, 10);
mpb.setColor(1f, 0f, 1f, 1f);
mpb.sphere(2f, 2f, 2f, 10, 10);
model = modelBuilder.end();
instance = new ModelInstance(model);
shadowBatch = new ModelBatch(new DepthShaderProvider());
Gdx.input.setInputProcessor(camController = new CameraInputController(cam));
}
Aggregations