use of com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute in project libgdx by libgdx.
the class Basic3DTest method create.
@Override
public void create() {
modelBatch = new ModelBatch(new DefaultShaderProvider());
environment = new Environment();
environment.set(new ColorAttribute(ColorAttribute.AmbientLight, .4f, .4f, .4f, 1f));
environment.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(10f, 10f, 10f);
cam.lookAt(0, 0, 0);
cam.near = 1f;
cam.far = 30f;
cam.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(cam)));
}
use of com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute in project libgdx by libgdx.
the class Benchmark3DTest method randomizeLights.
protected void randomizeLights() {
int pointLights = MathUtils.random(5);
int directionalLights = MathUtils.random(5);
DefaultShader.Config config = new Config();
config.numDirectionalLights = directionalLights;
config.numPointLights = pointLights;
config.numSpotLights = 0;
modelBatch.dispose();
modelBatch = new ModelBatch(new DefaultShaderProvider(config));
environment = new Environment();
environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.4f, 0.4f, 0.4f, 1.f));
for (int i = 0; i < pointLights; i++) {
environment.add(new PointLight().set(randomColor(), randomPosition(), MathUtils.random(10f)));
}
for (int i = 0; i < directionalLights; i++) {
environment.add(new DirectionalLight().set(randomColor(), randomPosition()));
}
}
use of com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute in project libgdx by libgdx.
the class LightsTest method create.
@Override
public void create() {
super.create();
environment.clear();
environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.2f, 0.2f, 0.2f, 1.0f));
environment.add(dirLight = new DirectionalLight().set(0.8f, 0.2f, 0.2f, -1f, -2f, -0.5f));
environment.add(pointLight = new PointLight().set(0.2f, 0.8f, 0.2f, 0f, 0f, 0f, 100f));
ModelBuilder mb = new ModelBuilder();
lightModel = mb.createSphere(1, 1, 1, 10, 10, new Material(ColorAttribute.createDiffuse(1, 1, 1, 1)), Usage.Position);
lightModel.nodes.get(0).parts.get(0).setRenderable(pLight = new Renderable());
}
use of com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute in project libgdx by libgdx.
the class MeshBuilderTest method create.
@Override
public void create() {
super.create();
environment = new Environment();
environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.4f, 0.4f, 0.4f, 1.f));
environment.add(new DirectionalLight().set(0.8f, 0.8f, 0.8f, -0.5f, -1.0f, -0.8f));
modelsWindow.setVisible(false);
Texture texture = new Texture(Gdx.files.internal("data/badlogic.jpg"));
Material material = new Material(TextureAttribute.createDiffuse(texture));
MeshBuilder meshBuilder = new MeshBuilder();
meshBuilder.begin(Usage.Position | Usage.Normal | Usage.ColorPacked | Usage.TextureCoordinates, GL20.GL_TRIANGLES);
meshBuilder.box(1f, 1f, 1f);
Mesh mesh = new Mesh(true, meshBuilder.getNumVertices(), meshBuilder.getNumIndices(), meshBuilder.getAttributes());
mesh = meshBuilder.end(mesh);
ModelBuilder modelBuilder = new ModelBuilder();
modelBuilder.begin();
modelBuilder.manage(texture);
modelBuilder.node().id = "box";
MeshPartBuilder mpb = modelBuilder.part("box", GL20.GL_TRIANGLES, Usage.Position | Usage.Normal | Usage.TextureCoordinates | Usage.ColorPacked, material);
mpb.setColor(Color.RED);
mpb.box(1f, 1f, 1f);
modelBuilder.node().id = "sphere";
mpb = modelBuilder.part("sphere", GL20.GL_TRIANGLES, Usage.Position | Usage.Normal | Usage.TextureCoordinates | Usage.ColorPacked, material);
mpb.sphere(2f, 2f, 2f, 10, 5);
modelBuilder.node().id = "cone";
mpb = modelBuilder.part("cone", GL20.GL_TRIANGLES, Usage.Position | Usage.Normal | Usage.TextureCoordinates | Usage.ColorPacked, material);
mpb.setVertexTransform(new Matrix4().rotate(Vector3.X, -45f));
mpb.cone(2f, 3f, 1f, 8);
modelBuilder.node().id = "cylinder";
mpb = modelBuilder.part("cylinder", GL20.GL_TRIANGLES, Usage.Position | Usage.Normal | Usage.TextureCoordinates | Usage.ColorPacked, material);
mpb.setUVRange(1f, 1f, 0f, 0f);
mpb.cylinder(2f, 4f, 3f, 15);
modelBuilder.node().id = "mesh";
mpb = modelBuilder.part("mesh", GL20.GL_TRIANGLES, mesh.getVertexAttributes(), material);
Matrix4 transform = new Matrix4();
mpb.setVertexTransform(transform.setToTranslation(0, 2, 0));
mpb.addMesh(mesh);
mpb.setColor(Color.BLUE);
mpb.setVertexTransform(transform.setToTranslation(1, 1, 0));
mpb.addMesh(mesh);
mpb.setColor(null);
mpb.setVertexTransform(transform.setToTranslation(-1, 1, 0).rotate(Vector3.X, 45));
mpb.addMesh(mesh);
mpb.setVertexTransform(transform.setToTranslation(0, 1, 1));
mpb.setUVRange(0.75f, 0.75f, 0.25f, 0.25f);
mpb.addMesh(mesh);
model = modelBuilder.end();
instances.add(new ModelInstance(model, new Matrix4().trn(0f, 0f, 0f), "mesh", true));
instances.add(new ModelInstance(model, new Matrix4().trn(-5f, 0f, -5f), "box", true));
instances.add(new ModelInstance(model, new Matrix4().trn(5f, 0f, -5f), "sphere", true));
instances.add(new ModelInstance(model, new Matrix4().trn(-5f, 0f, 5f), "cone", true));
instances.add(new ModelInstance(model, new Matrix4().trn(5f, 0f, 5f), "cylinder", true));
}
use of com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute in project libgdx by libgdx.
the class ModelInstanceRenderer method update.
@Override
public void update() {
for (int i = 0, positionOffset = 0, c = controller.particles.size; i < c; ++i, positionOffset += renderData.positionChannel.strideSize) {
ModelInstance instance = renderData.modelInstanceChannel.data[i];
float scale = hasScale ? renderData.scaleChannel.data[i] : 1;
float qx = 0, qy = 0, qz = 0, qw = 1;
if (hasRotation) {
int rotationOffset = i * renderData.rotationChannel.strideSize;
qx = renderData.rotationChannel.data[rotationOffset + ParticleChannels.XOffset];
qy = renderData.rotationChannel.data[rotationOffset + ParticleChannels.YOffset];
qz = renderData.rotationChannel.data[rotationOffset + ParticleChannels.ZOffset];
qw = renderData.rotationChannel.data[rotationOffset + ParticleChannels.WOffset];
}
instance.transform.set(renderData.positionChannel.data[positionOffset + ParticleChannels.XOffset], renderData.positionChannel.data[positionOffset + ParticleChannels.YOffset], renderData.positionChannel.data[positionOffset + ParticleChannels.ZOffset], qx, qy, qz, qw, scale, scale, scale);
if (hasColor) {
int colorOffset = i * renderData.colorChannel.strideSize;
ColorAttribute colorAttribute = (ColorAttribute) instance.materials.get(0).get(ColorAttribute.Diffuse);
BlendingAttribute blendingAttribute = (BlendingAttribute) instance.materials.get(0).get(BlendingAttribute.Type);
colorAttribute.color.r = renderData.colorChannel.data[colorOffset + ParticleChannels.RedOffset];
colorAttribute.color.g = renderData.colorChannel.data[colorOffset + ParticleChannels.GreenOffset];
colorAttribute.color.b = renderData.colorChannel.data[colorOffset + ParticleChannels.BlueOffset];
if (blendingAttribute != null)
blendingAttribute.opacity = renderData.colorChannel.data[colorOffset + ParticleChannels.AlphaOffset];
}
}
super.update();
}
Aggregations