use of com.badlogic.gdx.graphics.Mesh in project commons-gdx by gemserk.
the class MeshUtils method createVerticalGradient.
public static Mesh createVerticalGradient(final float width, final float height, Color[] gradientColors, float[] gradientStops) {
if (gradientStops.length == 1) {
Color color = gradientColors[0];
Gdx2dMeshBuilder meshBuilder = new Gdx2dMeshBuilder(6, false, true, 0);
//
meshBuilder.color(color).vertex(0f, //
1f).color(color).vertex(1f, //
1f).color(color).vertex(0f, //
0f).color(color).vertex(1f, //
1f).color(color).vertex(0f, //
0f).color(color).vertex(1f, 0f);
Mesh mesh = meshBuilder.build();
mesh.scale(width, height, 1f);
return mesh;
}
Gdx2dMeshBuilder meshBuilder = new Gdx2dMeshBuilder((gradientStops.length - 1) * 6, false, true, 0);
for (int i = 0; i < gradientStops.length - 1; i++) {
float y0 = gradientStops[i];
float y1 = gradientStops[i + 1];
Color c0 = gradientColors[i];
Color c1 = gradientColors[i + 1];
//
meshBuilder.color(c0).vertex(0f, //
y0).color(c0).vertex(1f, //
y0).color(c1).vertex(0f, //
y1).color(c0).vertex(1f, //
y0).color(c1).vertex(0f, //
y1).color(c1).vertex(1f, y1);
}
Mesh mesh = meshBuilder.build();
mesh.scale(width, height, 1f);
return mesh;
}
use of com.badlogic.gdx.graphics.Mesh in project libgdx by libgdx.
the class SoftBodyTest method create.
@Override
public void create() {
super.create();
world.add("ground", 0f, 0f, 0f).setColor(0.25f + 0.5f * (float) Math.random(), 0.25f + 0.5f * (float) Math.random(), 0.25f + 0.5f * (float) Math.random(), 1f);
float x0 = -2f, y0 = 6f, z0 = -2f;
float x1 = 8f, y1 = 6f, z1 = 8f;
Vector3 patch00 = new Vector3(x0, y0, z0);
Vector3 patch10 = new Vector3(x1, y1, z0);
Vector3 patch01 = new Vector3(x0, y0, z1);
Vector3 patch11 = new Vector3(x1, y1, z1);
softBody = btSoftBodyHelpers.CreatePatch(worldInfo, patch00, patch10, patch01, patch11, 15, 15, 15, false);
softBody.takeOwnership();
softBody.setTotalMass(100f);
((btSoftRigidDynamicsWorld) (world.collisionWorld)).addSoftBody(softBody);
final int vertCount = softBody.getNodeCount();
final int faceCount = softBody.getFaceCount();
mesh = new Mesh(false, vertCount, faceCount * 3, new VertexAttribute(Usage.Position, 3, ShaderProgram.POSITION_ATTRIBUTE), new VertexAttribute(Usage.Normal, 3, ShaderProgram.NORMAL_ATTRIBUTE), new VertexAttribute(Usage.TextureCoordinates, 2, ShaderProgram.TEXCOORD_ATTRIBUTE + "0"));
final int vertSize = mesh.getVertexSize() / 4;
mesh.getVerticesBuffer().position(0);
mesh.getVerticesBuffer().limit(vertCount * vertSize);
mesh.getIndicesBuffer().position(0);
mesh.getIndicesBuffer().limit(faceCount * 3);
softBody.getVertices(mesh.getVerticesBuffer(), vertCount, mesh.getVertexSize(), 0);
softBody.getIndices(mesh.getIndicesBuffer(), faceCount);
final float[] verts = new float[vertCount * vertSize];
final int uvOffset = mesh.getVertexAttribute(Usage.TextureCoordinates).offset / 4;
final int normalOffset = mesh.getVertexAttribute(Usage.Normal).offset / 4;
mesh.getVertices(verts);
for (int i = 0; i < vertCount; i++) {
verts[i * vertSize + normalOffset] = 0f;
verts[i * vertSize + normalOffset + 1] = 1f;
verts[i * vertSize + normalOffset + 2] = 0f;
verts[i * vertSize + uvOffset] = (verts[i * vertSize] - x0) / (x1 - x0);
verts[i * vertSize + uvOffset + 1] = (verts[i * vertSize + 2] - z0) / (z1 - z0);
}
mesh.setVertices(verts);
texture = new Texture(Gdx.files.internal("data/badlogic.jpg"));
ModelBuilder builder = new ModelBuilder();
builder.begin();
builder.part(new MeshPart("", mesh, 0, mesh.getNumIndices(), GL20.GL_TRIANGLES), new Material(TextureAttribute.createDiffuse(texture), ColorAttribute.createSpecular(Color.WHITE), FloatAttribute.createShininess(64f), IntAttribute.createCullFace(0)));
model = builder.end();
instance = new ModelInstance(model);
world.add(new BulletEntity(instance, null));
}
use of com.badlogic.gdx.graphics.Mesh in project libgdx by libgdx.
the class ConvexHullDistanceTest method createConvexHullShape.
public static btConvexHullShape createConvexHullShape(final Model model, boolean optimize) {
final Mesh mesh = model.meshes.get(0);
final btConvexHullShape shape = new btConvexHullShape(mesh.getVerticesBuffer(), mesh.getNumVertices(), mesh.getVertexSize());
if (!optimize)
return shape;
// now optimize the shape
final btShapeHull hull = new btShapeHull(shape);
hull.buildHull(shape.getMargin());
final btConvexHullShape result = new btConvexHullShape(hull);
// delete the temporary shape
shape.dispose();
hull.dispose();
return result;
}
use of com.badlogic.gdx.graphics.Mesh in project libgdx by libgdx.
the class SpawnInfluencerPanel method onTemplateChecked.
@Override
public void onTemplateChecked(Model model, boolean isChecked) {
//Update the shapes
SpawnShapeValue shapeValue = null;
Mesh mesh = model.meshes.get(0);
weightMeshSpawnShapeValue.setMesh(mesh, model);
meshSpawnShapeValue.setMesh(mesh, model);
if (shapeCombo.getSelectedItem() == SPAWN_SHAPE_WEIGHT_MESH) {
SpawnInfluencer influencer = (SpawnInfluencer) editor.getEmitter().findInfluencer(SpawnInfluencer.class);
influencer.spawnShapeValue = weightMeshSpawnShapeValue;
} else if (shapeCombo.getSelectedItem() == SPAWN_SHAPE_MESH) {
SpawnInfluencer influencer = (SpawnInfluencer) editor.getEmitter().findInfluencer(SpawnInfluencer.class);
influencer.spawnShapeValue = meshSpawnShapeValue;
}
editor.restart();
}
use of com.badlogic.gdx.graphics.Mesh in project libgdx by libgdx.
the class DecalBatch method initialize.
/** Initializes the batch with the given amount of decal objects the buffer is able to hold when full.
*
* @param size Maximum size of decal objects to hold in memory */
public void initialize(int size) {
vertices = new float[size * Decal.SIZE];
Mesh.VertexDataType vertexDataType = Mesh.VertexDataType.VertexArray;
if (Gdx.gl30 != null) {
vertexDataType = Mesh.VertexDataType.VertexBufferObjectWithVAO;
}
mesh = new Mesh(vertexDataType, false, size * 4, size * 6, new VertexAttribute(VertexAttributes.Usage.Position, 3, ShaderProgram.POSITION_ATTRIBUTE), new VertexAttribute(VertexAttributes.Usage.ColorPacked, 4, ShaderProgram.COLOR_ATTRIBUTE), new VertexAttribute(VertexAttributes.Usage.TextureCoordinates, 2, ShaderProgram.TEXCOORD_ATTRIBUTE + "0"));
short[] indices = new short[size * 6];
int v = 0;
for (int i = 0; i < indices.length; i += 6, v += 4) {
indices[i] = (short) (v);
indices[i + 1] = (short) (v + 2);
indices[i + 2] = (short) (v + 1);
indices[i + 3] = (short) (v + 1);
indices[i + 4] = (short) (v + 2);
indices[i + 5] = (short) (v + 3);
}
mesh.setIndices(indices);
}
Aggregations