public ImmediateModeRenderer20 (int maxVertices, boolean hasNormals, boolean hasColors, int numTexCoords, ShaderProgram shader) { this.maxVertices = maxVertices; this.numTexCoords = numTexCoords; this.shader = shader; VertexAttribute[] attribs = buildVertexAttributes(hasNormals, hasColors, numTexCoords); mesh = new Mesh(false, maxVertices, 0, attribs); vertices = new float[maxVertices * (mesh.getVertexAttributes().vertexSize / 4)]; vertexSize = mesh.getVertexAttributes().vertexSize / 4; normalOffset = mesh.getVertexAttribute(Usage.Normal) != null ? mesh.getVertexAttribute(Usage.Normal).offset / 4 : 0; colorOffset = mesh.getVertexAttribute(Usage.ColorPacked) != null ? mesh.getVertexAttribute(Usage.ColorPacked).offset / 4 : 0; texCoordOffset = mesh.getVertexAttribute(Usage.TextureCoordinates) != null ? mesh .getVertexAttribute(Usage.TextureCoordinates).offset / 4 : 0; shaderUniformNames = new String[numTexCoords]; for (int i = 0; i < numTexCoords; i++) { shaderUniformNames[i] = "u_sampler" + i; } }
public void setMesh (Mesh mesh, Model model) { if (mesh.getVertexAttribute(Usage.Position) == null) throw new GdxRuntimeException("Mesh vertices must have Usage.Position"); this.model = model; this.mesh = mesh; }
public void setMesh (Mesh mesh, Model model) { if (mesh.getVertexAttribute(Usage.Position) == null) throw new GdxRuntimeException("Mesh vertices must have Usage.Position"); this.model = model; this.mesh = mesh; }
public ImmediateModeRenderer20 (int maxVertices, boolean hasNormals, boolean hasColors, int numTexCoords, ShaderProgram shader) { this.maxVertices = maxVertices; this.numTexCoords = numTexCoords; this.shader = shader; VertexAttribute[] attribs = buildVertexAttributes(hasNormals, hasColors, numTexCoords); mesh = new Mesh(false, maxVertices, 0, attribs); vertices = new float[maxVertices * (mesh.getVertexAttributes().vertexSize / 4)]; vertexSize = mesh.getVertexAttributes().vertexSize / 4; normalOffset = mesh.getVertexAttribute(Usage.Normal) != null ? mesh.getVertexAttribute(Usage.Normal).offset / 4 : 0; colorOffset = mesh.getVertexAttribute(Usage.ColorPacked) != null ? mesh.getVertexAttribute(Usage.ColorPacked).offset / 4 : 0; texCoordOffset = mesh.getVertexAttribute(Usage.TextureCoordinates) != null ? mesh .getVertexAttribute(Usage.TextureCoordinates).offset / 4 : 0; shaderUniformNames = new String[numTexCoords]; for (int i = 0; i < numTexCoords; i++) { shaderUniformNames[i] = "u_sampler" + i; } }
@Override public void create () { // @off String vertexShader = "uniform mat4 u_mvpMatrix; \n" + "attribute vec4 a_position; \n" + "void main() \n" + "{ \n" + " gl_Position = u_mvpMatrix * a_position; \n" + "} \n"; String fragmentShader = "#ifdef GL_ES\n" + "precision mediump float;\n" + "#endif\n" + "void main() \n" + "{ \n" + " gl_FragColor = vec4 ( 1.0, 0.0, 0.0, 1.0 );\n" + "}"; // @on shader = new ShaderProgram(vertexShader, fragmentShader); mesh = Shapes.genCube(); mesh.getVertexAttribute(Usage.Position).alias = "a_position"; }
final VertexAttribute posAttrib = getVertexAttribute(Usage.Position); final int offset = posAttrib.offset / 4; final int vertexSize = vertices.getAttributes().vertexSize / 4;
final VertexAttribute posAttrib = getVertexAttribute(Usage.Position); final int offset = posAttrib.offset / 4; final int vertexSize = vertices.getAttributes().vertexSize / 4;
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); }
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); }
final VertexAttribute posAttr = getVertexAttribute(Usage.Position); final int offset = posAttr.offset / 4; final int numComponents = posAttr.numComponents;
final VertexAttribute posAttr = getVertexAttribute(Usage.Position); final int offset = posAttr.offset / 4; final int numComponents = posAttr.numComponents;
/** 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 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); }
/** 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 VertexAttribute posAttrib = getVertexAttribute(Usage.Position); final int posoff = posAttrib.offset / 4; final int vertexSize = vertices.getAttributes().vertexSize / 4;
final VertexAttribute posAttrib = getVertexAttribute(Usage.Position); final int posoff = posAttrib.offset / 4; final int vertexSize = vertices.getAttributes().vertexSize / 4;
@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)); }