use of com.badlogic.gdx.graphics.g3d.model.MeshPart in project libgdx by libgdx.
the class SoftMeshTest method render.
@Override
public void render() {
if (world.renderMeshes) {
MeshPart meshPart = model.nodes.get(0).parts.get(0).meshPart;
softBody.getVertices(meshPart.mesh.getVerticesBuffer(), meshPart.mesh.getVertexSize(), positionOffset, normalOffset, meshPart.mesh.getIndicesBuffer(), meshPart.offset, meshPart.size, indexMap, 0);
softBody.getWorldTransform(entity.transform);
}
super.render();
}
use of com.badlogic.gdx.graphics.g3d.model.MeshPart in project libgdx by libgdx.
the class Model method convertMesh.
protected void convertMesh(ModelMesh modelMesh) {
int numIndices = 0;
for (ModelMeshPart part : modelMesh.parts) {
numIndices += part.indices.length;
}
VertexAttributes attributes = new VertexAttributes(modelMesh.attributes);
int numVertices = modelMesh.vertices.length / (attributes.vertexSize / 4);
Mesh mesh = new Mesh(true, numVertices, numIndices, attributes);
meshes.add(mesh);
disposables.add(mesh);
BufferUtils.copy(modelMesh.vertices, mesh.getVerticesBuffer(), modelMesh.vertices.length, 0);
int offset = 0;
mesh.getIndicesBuffer().clear();
for (ModelMeshPart part : modelMesh.parts) {
MeshPart meshPart = new MeshPart();
meshPart.id = part.id;
meshPart.primitiveType = part.primitiveType;
meshPart.offset = offset;
meshPart.size = part.indices.length;
meshPart.mesh = mesh;
mesh.getIndicesBuffer().put(part.indices);
offset += meshPart.size;
meshParts.add(meshPart);
}
mesh.getIndicesBuffer().position(0);
for (MeshPart part : meshParts) part.update();
}
use of com.badlogic.gdx.graphics.g3d.model.MeshPart in project libgdx by libgdx.
the class ModelBuilder method part.
/** Adds the specified mesh part to the current node. The Mesh will be managed by the model and disposed when the model is
* disposed. The resources the Material might contain are not managed, use {@link #manage(Disposable)} to add those to the
* model.
* @return The added MeshPart. */
public MeshPart part(final String id, final Mesh mesh, int primitiveType, int offset, int size, final Material material) {
final MeshPart meshPart = new MeshPart();
meshPart.id = id;
meshPart.primitiveType = primitiveType;
meshPart.mesh = mesh;
meshPart.offset = offset;
meshPart.size = size;
part(meshPart, material);
return meshPart;
}
use of com.badlogic.gdx.graphics.g3d.model.MeshPart in project bdx by GoranM.
the class Mesh method vertTransformUV.
public void vertTransformUV(int materialSlot, Matrix3f matrix) {
Matrix3f m = matrix;
float[] vals = { m.m00, m.m10, m.m20, m.m01, m.m11, m.m21, m.m02, m.m12, m.m22 };
float[] verts = new float[getVertexCount() * Bdx.VERT_STRIDE];
model.meshes.first().getVertices(verts);
MeshPart mp = model.meshParts.get(materialSlot);
com.badlogic.gdx.graphics.Mesh.transformUV(new Matrix3(vals), verts, Bdx.VERT_STRIDE, 6, mp.offset, mp.size);
model.meshes.first().setVertices(verts);
}
use of com.badlogic.gdx.graphics.g3d.model.MeshPart 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));
}
Aggregations