/** Copies the specified vertices from the Mesh to the float array. The float array must be large enough to hold * destOffset+count vertices. * @param srcOffset the offset (in number of floats) of the vertices in the mesh to copy * @param count the amount of floats to copy * @param vertices the array to copy the vertices to * @param destOffset the offset (in floats) in the vertices array to start copying */ public float[] getVertices (int srcOffset, int count, float[] vertices, int destOffset) { // TODO: Perhaps this method should be vertexSize aware?? final int max = getNumVertices() * getVertexSize() / 4; if (count == -1) { count = max - srcOffset; if (count > vertices.length - destOffset) count = vertices.length - destOffset; } if (srcOffset < 0 || count <= 0 || (srcOffset + count) > max || destOffset < 0 || destOffset >= vertices.length) throw new IndexOutOfBoundsException(); if ((vertices.length - destOffset) < count) throw new IllegalArgumentException("not enough room in vertices array, has " + vertices.length + " floats, needs " + count); int pos = getVerticesBuffer().position(); getVerticesBuffer().position(srcOffset); getVerticesBuffer().get(vertices, destOffset, count); getVerticesBuffer().position(pos); return vertices; }
/** Copies the specified vertices from the Mesh to the float array. The float array must be large enough to hold * destOffset+count vertices. * @param srcOffset the offset (in number of floats) of the vertices in the mesh to copy * @param count the amount of floats to copy * @param vertices the array to copy the vertices to * @param destOffset the offset (in floats) in the vertices array to start copying */ public float[] getVertices (int srcOffset, int count, float[] vertices, int destOffset) { // TODO: Perhaps this method should be vertexSize aware?? final int max = getNumVertices() * getVertexSize() / 4; if (count == -1) { count = max - srcOffset; if (count > vertices.length - destOffset) count = vertices.length - destOffset; } if (srcOffset < 0 || count <= 0 || (srcOffset + count) > max || destOffset < 0 || destOffset >= vertices.length) throw new IndexOutOfBoundsException(); if ((vertices.length - destOffset) < count) throw new IllegalArgumentException("not enough room in vertices array, has " + vertices.length + " floats, needs " + count); int pos = getVerticesBuffer().position(); getVerticesBuffer().position(srcOffset); getVerticesBuffer().get(vertices, destOffset, count); getVerticesBuffer().position(pos); return vertices; }
protected void transformUV (final Matrix3 matrix, final int start, final int count) { final VertexAttribute posAttr = getVertexAttribute(Usage.TextureCoordinates); final int offset = posAttr.offset / 4; final int vertexSize = getVertexSize() / 4; final int numVertices = getNumVertices(); final float[] vertices = new float[numVertices * vertexSize]; // TODO: getVertices(vertices, start * vertexSize, count * vertexSize); getVertices(0, vertices.length, vertices); transformUV(matrix, vertices, vertexSize, offset, start, count); setVertices(vertices, 0, vertices.length); // TODO: setVertices(start * vertexSize, vertices, 0, vertices.length); }
protected void transformUV (final Matrix3 matrix, final int start, final int count) { final VertexAttribute posAttr = getVertexAttribute(Usage.TextureCoordinates); final int offset = posAttr.offset / 4; final int vertexSize = getVertexSize() / 4; final int numVertices = getNumVertices(); final float[] vertices = new float[numVertices * vertexSize]; // TODO: getVertices(vertices, start * vertexSize, count * vertexSize); getVertices(0, vertices.length, vertices); transformUV(matrix, vertices, vertexSize, offset, start, count); setVertices(vertices, 0, vertices.length); // TODO: setVertices(start * vertexSize, vertices, 0, vertices.length); }
@Override protected void renderWorld () { softBody.getVertices(mesh.getVerticesBuffer(), softBody.getNodeCount(), mesh.getVertexSize(), 0); softBody.getWorldTransform(instance.transform); super.renderWorld(); // modelBatch.begin(camera); // world.render(modelBatch, lights); // modelBatch.render(instance, lights); // modelBatch.end(); }
public void transform (final Matrix4 matrix, final int start, final int count) { final VertexAttribute posAttr = getVertexAttribute(Usage.Position); final int posOffset = posAttr.offset / 4; final int stride = getVertexSize() / 4; final int numComponents = posAttr.numComponents; final int numVertices = getNumVertices(); final float[] vertices = new float[count * stride]; getVertices(start * stride, count * stride, vertices); // getVertices(0, vertices.length, vertices); transform(matrix, vertices, stride, posOffset, numComponents, 0, count); // setVertices(vertices, 0, vertices.length); updateVertices(start * stride, vertices); }
public void transform (final Matrix4 matrix, final int start, final int count) { final VertexAttribute posAttr = getVertexAttribute(Usage.Position); final int posOffset = posAttr.offset / 4; final int stride = getVertexSize() / 4; final int numComponents = posAttr.numComponents; final int numVertices = getNumVertices(); final float[] vertices = new float[count * stride]; getVertices(start * stride, count * stride, vertices); // getVertices(0, vertices.length, vertices); transform(matrix, vertices, stride, posOffset, numComponents, 0, count); // setVertices(vertices, 0, vertices.length); updateVertices(start * stride, vertices); }
/** Convenience method to set this btIndexedMesh to the specified {@link Mesh} * The specified mesh must be indexed and triangulated and must outlive this btIndexedMesh. * The buffers for the vertices and indices are shared amonst both. */ public void set(final Object tag, final Mesh mesh, int offset, int count) { if ((count <= 0) || ((count % 3) != 0)) throw new com.badlogic.gdx.utils.GdxRuntimeException("Mesh must be indexed and triangulated"); VertexAttribute posAttr = mesh.getVertexAttribute(Usage.Position); if (posAttr == null) throw new com.badlogic.gdx.utils.GdxRuntimeException("Mesh doesn't have a position attribute"); set(tag, mesh.getVerticesBuffer(), mesh.getVertexSize(), mesh.getNumVertices(), posAttr.offset, mesh.getIndicesBuffer(), offset, count); }
final int numComponents = posAttr.numComponents; final int numVertices = getNumVertices(); final int vertexSize = getVertexSize() / 4;
final int numComponents = posAttr.numComponents; final int numVertices = getNumVertices(); final int vertexSize = getVertexSize() / 4;
/** Convenience method to set this btIndexedMesh to the specified {@link Mesh} * The specified mesh must be indexed and triangulated and must outlive this btIndexedMesh. * The buffers for the vertices and indices are shared amonst both. */ public void set(final Object tag, final Mesh mesh, int offset, int count) { if ((count <= 0) || ((count % 3) != 0)) throw new com.badlogic.gdx.utils.GdxRuntimeException("Mesh must be indexed and triangulated"); VertexAttribute posAttr = mesh.getVertexAttribute(Usage.Position); if (posAttr == null) throw new com.badlogic.gdx.utils.GdxRuntimeException("Mesh doesn't have a position attribute"); set(tag, mesh.getVerticesBuffer(), mesh.getVertexSize(), mesh.getNumVertices(), posAttr.offset, mesh.getIndicesBuffer(), offset, count); }
@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(); }
@Override public void setMesh (Mesh mesh, Model model) { super.setMesh(mesh, model); vertexSize = mesh.getVertexSize() / 4; positionOffset = mesh.getVertexAttribute(Usage.Position).offset / 4; int indicesCount = mesh.getNumIndices(); if (indicesCount > 0) { indices = new short[indicesCount]; mesh.getIndices(indices); triangleCount = indices.length / 3; } else indices = null; vertexCount = mesh.getNumVertices(); vertices = new float[vertexCount * vertexSize]; mesh.getVertices(vertices); }
@Override public void setMesh (Mesh mesh, Model model) { super.setMesh(mesh, model); vertexSize = mesh.getVertexSize() / 4; positionOffset = mesh.getVertexAttribute(Usage.Position).offset / 4; int indicesCount = mesh.getNumIndices(); if (indicesCount > 0) { indices = new short[indicesCount]; mesh.getIndices(indices); triangleCount = indices.length / 3; } else indices = null; vertexCount = mesh.getNumVertices(); vertices = new float[vertexCount * vertexSize]; mesh.getVertices(vertices); }
int vertexSize = mesh.getVertexSize() / 4; int currentTriangleFirstVertexIndex = currentTriangleIndex * 3;
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; }
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; } }
@Override public void create () { super.create(); world.maxSubSteps = 20; 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); // Note: not every model is suitable for a one on one translation with a soft body, a better model might be added later. model = objLoader.loadModel(Gdx.files.internal("data/wheel.obj")); MeshPart meshPart = model.nodes.get(0).parts.get(0).meshPart; meshPart.mesh.scale(6, 6, 6); indexMap = BufferUtils.newShortBuffer(meshPart.size); positionOffset = meshPart.mesh.getVertexAttribute(Usage.Position).offset; normalOffset = meshPart.mesh.getVertexAttribute(Usage.Normal).offset; softBody = new btSoftBody(worldInfo, meshPart.mesh.getVerticesBuffer(), meshPart.mesh.getVertexSize(), positionOffset, normalOffset, meshPart.mesh.getIndicesBuffer(), meshPart.offset, meshPart.size, indexMap, 0); // Set mass of the first vertex to zero so its unmovable, comment out this line to make it a fully dynamic body. softBody.setMass(0, 0); com.badlogic.gdx.physics.bullet.softbody.btSoftBody.Material pm = softBody.appendMaterial(); pm.setKLST(0.2f); pm.setFlags(0); softBody.generateBendingConstraints(2, pm); // Be careful increasing iterations, it decreases performance (but increases accuracy). softBody.setConfig_piterations(7); softBody.setConfig_kDF(0.2f); softBody.randomizeConstraints(); softBody.setTotalMass(1); softBody.translate(tmpV.set(1, 5, 1)); ((btSoftRigidDynamicsWorld)(world.collisionWorld)).addSoftBody(softBody); world.add(entity = new BulletEntity(model, (btCollisionObject)null, 1, 5, 1)); }
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);
binormalOffset = mesh.getVertexAttribute(Usage.BiNormal).offset / FLOAT_BYTES; int attributesSize = mesh.getVertexSize() / FLOAT_BYTES; int verticesOffset = 0; int verticesQuantity = 0;